SBInstruction.cpp revision 5892856b0cd6591194c669afab5bf9ac19c5b3a0
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
19using namespace lldb;
20using namespace lldb_private;
21
22SBInstruction::SBInstruction ()
23{
24}
25
26SBInstruction::SBInstruction (const lldb::InstructionSP& inst_sp) :
27    m_opaque_sp (inst_sp)
28{
29}
30
31SBInstruction::SBInstruction(const SBInstruction &rhs) :
32    m_opaque_sp (rhs.m_opaque_sp)
33{
34}
35
36const SBInstruction &
37SBInstruction::operator = (const SBInstruction &rhs)
38{
39    if (this != &rhs)
40        m_opaque_sp = rhs.m_opaque_sp;
41    return *this;
42}
43
44SBInstruction::~SBInstruction ()
45{
46}
47
48bool
49SBInstruction::IsValid()
50{
51    return (m_opaque_sp.get() != NULL);
52}
53
54SBAddress
55SBInstruction::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
63size_t
64SBInstruction::GetByteSize ()
65{
66    if (m_opaque_sp)
67        return m_opaque_sp->GetByteSize();
68    return 0;
69}
70
71bool
72SBInstruction::DoesBranch ()
73{
74    if (m_opaque_sp)
75        return m_opaque_sp->DoesBranch ();
76    return false;
77}
78
79void
80SBInstruction::SetOpaque (const lldb::InstructionSP &inst_sp)
81{
82    m_opaque_sp = inst_sp;
83}
84
85bool
86SBInstruction::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
98void
99SBInstruction::Print (FILE *out)
100{
101    if (out == NULL)
102        return;
103
104    if (m_opaque_sp)
105    {
106        StreamFile out_stream (out, false);
107        m_opaque_sp->Dump (&out_stream, true, NULL, 0, NULL, false);
108    }
109}
110