blob: 01718a3d84427b8b4b271bf48c153c887c53b274 [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- 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 Clayton5c4c7462010-10-06 03:09:58 +000012#include "lldb/API/SBAddress.h"
13#include "lldb/API/SBInstruction.h"
14#include "lldb/API/SBStream.h"
15
Chris Lattner24943d22010-06-08 16:52:24 +000016#include "lldb/Core/Disassembler.h"
Greg Clayton5c4c7462010-10-06 03:09:58 +000017#include "lldb/Core/StreamFile.h"
Chris Lattner24943d22010-06-08 16:52:24 +000018
19using namespace lldb;
20using namespace lldb_private;
21
Chris Lattner24943d22010-06-08 16:52:24 +000022SBInstruction::SBInstruction ()
23{
24}
25
Greg Clayton5c4c7462010-10-06 03:09:58 +000026SBInstruction::SBInstruction (const lldb::InstructionSP& inst_sp) :
27 m_opaque_sp (inst_sp)
28{
29}
30
Greg Clayton538eb822010-11-05 23:17:00 +000031SBInstruction::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
Chris Lattner24943d22010-06-08 16:52:24 +000044SBInstruction::~SBInstruction ()
45{
46}
47
Greg Clayton5c4c7462010-10-06 03:09:58 +000048bool
49SBInstruction::IsValid()
50{
51 return (m_opaque_sp.get() != NULL);
52}
Chris Lattner24943d22010-06-08 16:52:24 +000053
Greg Clayton5c4c7462010-10-06 03:09:58 +000054SBAddress
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}
Chris Lattner24943d22010-06-08 16:52:24 +000062
Greg Clayton5c4c7462010-10-06 03:09:58 +000063size_t
64SBInstruction::GetByteSize ()
65{
66 if (m_opaque_sp)
67 return m_opaque_sp->GetByteSize();
68 return 0;
69}
Chris Lattner24943d22010-06-08 16:52:24 +000070
Greg Clayton5c4c7462010-10-06 03:09:58 +000071bool
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}
Chris Lattner24943d22010-06-08 16:52:24 +000097
98void
99SBInstruction::Print (FILE *out)
100{
101 if (out == NULL)
102 return;
103
Greg Clayton5c4c7462010-10-06 03:09:58 +0000104 if (m_opaque_sp)
105 {
106 StreamFile out_stream (out);
107 m_opaque_sp->Dump (&out_stream, true, NULL, 0, NULL, false);
108 }
Chris Lattner24943d22010-06-08 16:52:24 +0000109}