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 ()
32 {
33 }
34 
35 bool
36 SBInstruction::IsValid()
37 {
38     return (m_opaque_sp.get() != NULL);
39 }
40 
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 }
49 
50 size_t
51 SBInstruction::GetByteSize ()
52 {
53     if (m_opaque_sp)
54         return m_opaque_sp->GetByteSize();
55     return 0;
56 }
57 
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 }
84 
85 void
86 SBInstruction::Print (FILE *out)
87 {
88     if (out == NULL)
89         return;
90 
91     if (m_opaque_sp)
92     {
93         StreamFile out_stream (out);
94         m_opaque_sp->Dump (&out_stream, true, NULL, 0, NULL, false);
95     }
96 }
97