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 | |
Greg Clayton | 538eb82 | 2010-11-05 23:17:00 +0000 | [diff] [blame] | 31 | SBInstruction::SBInstruction(const SBInstruction &rhs) : |
| 32 | m_opaque_sp (rhs.m_opaque_sp) |
| 33 | { |
| 34 | } |
| 35 | |
| 36 | const SBInstruction & |
| 37 | SBInstruction::operator = (const SBInstruction &rhs) |
| 38 | { |
| 39 | if (this != &rhs) |
| 40 | m_opaque_sp = rhs.m_opaque_sp; |
| 41 | return *this; |
| 42 | } |
| 43 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 44 | SBInstruction::~SBInstruction () |
| 45 | { |
| 46 | } |
| 47 | |
Greg Clayton | 5c4c746 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 48 | bool |
| 49 | SBInstruction::IsValid() |
| 50 | { |
| 51 | return (m_opaque_sp.get() != NULL); |
| 52 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 53 | |
Greg Clayton | 5c4c746 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 54 | SBAddress |
| 55 | SBInstruction::GetAddress() |
| 56 | { |
| 57 | SBAddress sb_addr; |
| 58 | if (m_opaque_sp && m_opaque_sp->GetAddress().IsValid()) |
| 59 | sb_addr.SetAddress(&m_opaque_sp->GetAddress()); |
| 60 | return sb_addr; |
| 61 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 62 | |
Greg Clayton | 5c4c746 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 63 | size_t |
| 64 | SBInstruction::GetByteSize () |
| 65 | { |
| 66 | if (m_opaque_sp) |
| 67 | return m_opaque_sp->GetByteSize(); |
| 68 | return 0; |
| 69 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 70 | |
Greg Clayton | 5c4c746 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 71 | bool |
| 72 | SBInstruction::DoesBranch () |
| 73 | { |
| 74 | if (m_opaque_sp) |
| 75 | return m_opaque_sp->DoesBranch (); |
| 76 | return false; |
| 77 | } |
| 78 | |
| 79 | void |
| 80 | SBInstruction::SetOpaque (const lldb::InstructionSP &inst_sp) |
| 81 | { |
| 82 | m_opaque_sp = inst_sp; |
| 83 | } |
| 84 | |
| 85 | bool |
| 86 | SBInstruction::GetDescription (lldb::SBStream &s) |
| 87 | { |
| 88 | if (m_opaque_sp) |
| 89 | { |
| 90 | // Use the "ref()" instead of the "get()" accessor in case the SBStream |
| 91 | // didn't have a stream already created, one will get created... |
| 92 | m_opaque_sp->Dump (&s.ref(), true, NULL, 0, NULL, false); |
| 93 | return true; |
| 94 | } |
| 95 | return false; |
| 96 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 97 | |
| 98 | void |
| 99 | SBInstruction::Print (FILE *out) |
| 100 | { |
| 101 | if (out == NULL) |
| 102 | return; |
| 103 | |
Greg Clayton | 5c4c746 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 104 | if (m_opaque_sp) |
| 105 | { |
| 106 | StreamFile out_stream (out); |
| 107 | m_opaque_sp->Dump (&out_stream, true, NULL, 0, NULL, false); |
| 108 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 109 | } |