blob: 13d68a1cd34e5f0fe95eac37f1482458278a5740 [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
Chris Lattner24943d22010-06-08 16:52:24 +000031SBInstruction::~SBInstruction ()
32{
33}
34
Greg Clayton5c4c7462010-10-06 03:09:58 +000035bool
36SBInstruction::IsValid()
37{
38 return (m_opaque_sp.get() != NULL);
39}
Chris Lattner24943d22010-06-08 16:52:24 +000040
Greg Clayton5c4c7462010-10-06 03:09:58 +000041SBAddress
42SBInstruction::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}
Chris Lattner24943d22010-06-08 16:52:24 +000049
Greg Clayton5c4c7462010-10-06 03:09:58 +000050size_t
51SBInstruction::GetByteSize ()
52{
53 if (m_opaque_sp)
54 return m_opaque_sp->GetByteSize();
55 return 0;
56}
Chris Lattner24943d22010-06-08 16:52:24 +000057
Greg Clayton5c4c7462010-10-06 03:09:58 +000058bool
59SBInstruction::DoesBranch ()
60{
61 if (m_opaque_sp)
62 return m_opaque_sp->DoesBranch ();
63 return false;
64}
65
66void
67SBInstruction::SetOpaque (const lldb::InstructionSP &inst_sp)
68{
69 m_opaque_sp = inst_sp;
70}
71
72bool
73SBInstruction::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}
Chris Lattner24943d22010-06-08 16:52:24 +000084
85void
86SBInstruction::Print (FILE *out)
87{
88 if (out == NULL)
89 return;
90
Greg Clayton5c4c7462010-10-06 03:09:58 +000091 if (m_opaque_sp)
92 {
93 StreamFile out_stream (out);
94 m_opaque_sp->Dump (&out_stream, true, NULL, 0, NULL, false);
95 }
Chris Lattner24943d22010-06-08 16:52:24 +000096}