blob: b27ddfa5011cf92aea7274b39e809be82128c2a4 [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- SBInstructionList.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/SBInstructionList.h"
11#include "lldb/API/SBInstruction.h"
Greg Clayton5c4c7462010-10-06 03:09:58 +000012#include "lldb/API/SBStream.h"
13#include "lldb/Core/Disassembler.h"
14#include "lldb/Core/Stream.h"
Chris Lattner24943d22010-06-08 16:52:24 +000015
16using namespace lldb;
Greg Clayton5c4c7462010-10-06 03:09:58 +000017using namespace lldb_private;
Chris Lattner24943d22010-06-08 16:52:24 +000018
19
Greg Clayton5c4c7462010-10-06 03:09:58 +000020SBInstructionList::SBInstructionList () :
21 m_opaque_sp()
Chris Lattner24943d22010-06-08 16:52:24 +000022{
23}
24
25SBInstructionList::~SBInstructionList ()
26{
27}
28
29size_t
30SBInstructionList::GetSize ()
31{
Greg Clayton5c4c7462010-10-06 03:09:58 +000032 if (m_opaque_sp)
33 return m_opaque_sp->GetInstructionList().GetSize();
Chris Lattner24943d22010-06-08 16:52:24 +000034 return 0;
35}
36
37SBInstruction
38SBInstructionList::GetInstructionAtIndex (uint32_t idx)
39{
40 SBInstruction inst;
Greg Clayton5c4c7462010-10-06 03:09:58 +000041 if (m_opaque_sp && idx < m_opaque_sp->GetInstructionList().GetSize())
42 inst.SetOpaque (m_opaque_sp->GetInstructionList().GetInstructionAtIndex (idx));
Chris Lattner24943d22010-06-08 16:52:24 +000043 return inst;
44}
45
46void
47SBInstructionList::Clear ()
48{
Greg Clayton5c4c7462010-10-06 03:09:58 +000049 m_opaque_sp.reset();
Chris Lattner24943d22010-06-08 16:52:24 +000050}
51
52void
53SBInstructionList::AppendInstruction (SBInstruction insn)
54{
55}
56
57void
Greg Clayton5c4c7462010-10-06 03:09:58 +000058SBInstructionList::SetDisassembler (const lldb::DisassemblerSP &opaque_sp)
59{
60 m_opaque_sp = opaque_sp;
61}
62
63void
Chris Lattner24943d22010-06-08 16:52:24 +000064SBInstructionList::Print (FILE *out)
65{
66 if (out == NULL)
67 return;
68}
69
Greg Clayton5c4c7462010-10-06 03:09:58 +000070
71bool
72SBInstructionList::GetDescription (lldb::SBStream &description)
73{
74 if (m_opaque_sp)
75 {
76 size_t num_instructions = GetSize ();
77 if (num_instructions)
78 {
79 // Call the ref() to make sure a stream is created if one deesn't
80 // exist already inside description...
81 Stream &sref = description.ref();
82 for (size_t i=0; i<num_instructions; ++i)
83 {
84 Instruction *inst = m_opaque_sp->GetInstructionList().GetInstructionAtIndex (i).get();
85 if (inst == NULL)
86 break;
87 inst->Dump (&sref, true, NULL, 0, NULL, false);
88 sref.EOL();
89 }
90 return true;
91 }
92 }
93 return false;
94}
95
96