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 
12 #include "lldb/API/SBAddress.h"
13 #include "lldb/API/SBInstruction.h"
14 #include "lldb/API/SBStream.h"
15 
16 #include "lldb/Core/Disassembler.h"
17 #include "lldb/Core/StreamFile.h"
18 
19 using namespace lldb;
20 using namespace lldb_private;
21 
22 SBInstruction::SBInstruction ()
23 {
24 }
25 
26 SBInstruction::SBInstruction (const lldb::InstructionSP& inst_sp) :
27     m_opaque_sp (inst_sp)
28 {
29 }
30 
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 
44 SBInstruction::~SBInstruction ()
45 {
46 }
47 
48 bool
49 SBInstruction::IsValid()
50 {
51     return (m_opaque_sp.get() != NULL);
52 }
53 
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 }
62 
63 size_t
64 SBInstruction::GetByteSize ()
65 {
66     if (m_opaque_sp)
67         return m_opaque_sp->GetByteSize();
68     return 0;
69 }
70 
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 }
97 
98 void
99 SBInstruction::Print (FILE *out)
100 {
101     if (out == NULL)
102         return;
103 
104     if (m_opaque_sp)
105     {
106         StreamFile out_stream (out);
107         m_opaque_sp->Dump (&out_stream, true, NULL, 0, NULL, false);
108     }
109 }
110