Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- SBInstruction.cpp ---------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "lldb/API/SBInstruction.h" |
| 11 | |
Greg Clayton | 5c4c746 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 12 | #include "lldb/API/SBAddress.h" |
| 13 | #include "lldb/API/SBInstruction.h" |
| 14 | #include "lldb/API/SBStream.h" |
| 15 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 16 | #include "lldb/Core/Disassembler.h" |
Greg Clayton | 5c4c746 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 17 | #include "lldb/Core/StreamFile.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 18 | |
| 19 | using namespace lldb; |
| 20 | using namespace lldb_private; |
| 21 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 22 | SBInstruction::SBInstruction () |
| 23 | { |
| 24 | } |
| 25 | |
Greg Clayton | 5c4c746 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 26 | SBInstruction::SBInstruction (const lldb::InstructionSP& inst_sp) : |
| 27 | m_opaque_sp (inst_sp) |
| 28 | { |
| 29 | } |
| 30 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 31 | SBInstruction::~SBInstruction () |
| 32 | { |
| 33 | } |
| 34 | |
Greg Clayton | 5c4c746 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 35 | bool |
| 36 | SBInstruction::IsValid() |
| 37 | { |
| 38 | return (m_opaque_sp.get() != NULL); |
| 39 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 40 | |
Greg Clayton | 5c4c746 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 41 | SBAddress |
| 42 | SBInstruction::GetAddress() |
| 43 | { |
| 44 | SBAddress sb_addr; |
| 45 | if (m_opaque_sp && m_opaque_sp->GetAddress().IsValid()) |
| 46 | sb_addr.SetAddress(&m_opaque_sp->GetAddress()); |
| 47 | return sb_addr; |
| 48 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 49 | |
Greg Clayton | 5c4c746 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 50 | size_t |
| 51 | SBInstruction::GetByteSize () |
| 52 | { |
| 53 | if (m_opaque_sp) |
| 54 | return m_opaque_sp->GetByteSize(); |
| 55 | return 0; |
| 56 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 57 | |
Greg Clayton | 5c4c746 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 58 | bool |
| 59 | SBInstruction::DoesBranch () |
| 60 | { |
| 61 | if (m_opaque_sp) |
| 62 | return m_opaque_sp->DoesBranch (); |
| 63 | return false; |
| 64 | } |
| 65 | |
| 66 | void |
| 67 | SBInstruction::SetOpaque (const lldb::InstructionSP &inst_sp) |
| 68 | { |
| 69 | m_opaque_sp = inst_sp; |
| 70 | } |
| 71 | |
| 72 | bool |
| 73 | SBInstruction::GetDescription (lldb::SBStream &s) |
| 74 | { |
| 75 | if (m_opaque_sp) |
| 76 | { |
| 77 | // Use the "ref()" instead of the "get()" accessor in case the SBStream |
| 78 | // didn't have a stream already created, one will get created... |
| 79 | m_opaque_sp->Dump (&s.ref(), true, NULL, 0, NULL, false); |
| 80 | return true; |
| 81 | } |
| 82 | return false; |
| 83 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 84 | |
| 85 | void |
| 86 | SBInstruction::Print (FILE *out) |
| 87 | { |
| 88 | if (out == NULL) |
| 89 | return; |
| 90 | |
Greg Clayton | 5c4c746 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 91 | if (m_opaque_sp) |
| 92 | { |
| 93 | StreamFile out_stream (out); |
| 94 | m_opaque_sp->Dump (&out_stream, true, NULL, 0, NULL, false); |
| 95 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 96 | } |