blob: ce70d95b0ad7db3327fba2fe380feda03a088f55 [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
Greg Clayton538eb822010-11-05 23:17:00 +000025SBInstructionList::SBInstructionList(const SBInstructionList &rhs) :
26 m_opaque_sp (rhs.m_opaque_sp)
27{
28}
29
30const SBInstructionList &
31SBInstructionList::operator = (const SBInstructionList &rhs)
32{
33 if (this != &rhs)
34 m_opaque_sp = rhs.m_opaque_sp;
35 return *this;
36}
37
38
Chris Lattner24943d22010-06-08 16:52:24 +000039SBInstructionList::~SBInstructionList ()
40{
41}
42
43size_t
44SBInstructionList::GetSize ()
45{
Greg Clayton5c4c7462010-10-06 03:09:58 +000046 if (m_opaque_sp)
47 return m_opaque_sp->GetInstructionList().GetSize();
Chris Lattner24943d22010-06-08 16:52:24 +000048 return 0;
49}
50
51SBInstruction
52SBInstructionList::GetInstructionAtIndex (uint32_t idx)
53{
54 SBInstruction inst;
Greg Clayton5c4c7462010-10-06 03:09:58 +000055 if (m_opaque_sp && idx < m_opaque_sp->GetInstructionList().GetSize())
56 inst.SetOpaque (m_opaque_sp->GetInstructionList().GetInstructionAtIndex (idx));
Chris Lattner24943d22010-06-08 16:52:24 +000057 return inst;
58}
59
60void
61SBInstructionList::Clear ()
62{
Greg Clayton5c4c7462010-10-06 03:09:58 +000063 m_opaque_sp.reset();
Chris Lattner24943d22010-06-08 16:52:24 +000064}
65
66void
67SBInstructionList::AppendInstruction (SBInstruction insn)
68{
69}
70
71void
Greg Clayton5c4c7462010-10-06 03:09:58 +000072SBInstructionList::SetDisassembler (const lldb::DisassemblerSP &opaque_sp)
73{
74 m_opaque_sp = opaque_sp;
75}
76
77void
Chris Lattner24943d22010-06-08 16:52:24 +000078SBInstructionList::Print (FILE *out)
79{
80 if (out == NULL)
81 return;
82}
83
Greg Clayton5c4c7462010-10-06 03:09:58 +000084
85bool
86SBInstructionList::GetDescription (lldb::SBStream &description)
87{
88 if (m_opaque_sp)
89 {
90 size_t num_instructions = GetSize ();
91 if (num_instructions)
92 {
93 // Call the ref() to make sure a stream is created if one deesn't
94 // exist already inside description...
95 Stream &sref = description.ref();
96 for (size_t i=0; i<num_instructions; ++i)
97 {
98 Instruction *inst = m_opaque_sp->GetInstructionList().GetInstructionAtIndex (i).get();
99 if (inst == NULL)
100 break;
101 inst->Dump (&sref, true, NULL, 0, NULL, false);
102 sref.EOL();
103 }
104 return true;
105 }
106 }
107 return false;
108}
109
110