Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- 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 Clayton | 5c4c746 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 12 | #include "lldb/API/SBStream.h" |
| 13 | #include "lldb/Core/Disassembler.h" |
| 14 | #include "lldb/Core/Stream.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 15 | |
| 16 | using namespace lldb; |
Greg Clayton | 5c4c746 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 17 | using namespace lldb_private; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 18 | |
| 19 | |
Greg Clayton | 5c4c746 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 20 | SBInstructionList::SBInstructionList () : |
| 21 | m_opaque_sp() |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 22 | { |
| 23 | } |
| 24 | |
| 25 | SBInstructionList::~SBInstructionList () |
| 26 | { |
| 27 | } |
| 28 | |
| 29 | size_t |
| 30 | SBInstructionList::GetSize () |
| 31 | { |
Greg Clayton | 5c4c746 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 32 | if (m_opaque_sp) |
| 33 | return m_opaque_sp->GetInstructionList().GetSize(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 34 | return 0; |
| 35 | } |
| 36 | |
| 37 | SBInstruction |
| 38 | SBInstructionList::GetInstructionAtIndex (uint32_t idx) |
| 39 | { |
| 40 | SBInstruction inst; |
Greg Clayton | 5c4c746 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 41 | if (m_opaque_sp && idx < m_opaque_sp->GetInstructionList().GetSize()) |
| 42 | inst.SetOpaque (m_opaque_sp->GetInstructionList().GetInstructionAtIndex (idx)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 43 | return inst; |
| 44 | } |
| 45 | |
| 46 | void |
| 47 | SBInstructionList::Clear () |
| 48 | { |
Greg Clayton | 5c4c746 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 49 | m_opaque_sp.reset(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | void |
| 53 | SBInstructionList::AppendInstruction (SBInstruction insn) |
| 54 | { |
| 55 | } |
| 56 | |
| 57 | void |
Greg Clayton | 5c4c746 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 58 | SBInstructionList::SetDisassembler (const lldb::DisassemblerSP &opaque_sp) |
| 59 | { |
| 60 | m_opaque_sp = opaque_sp; |
| 61 | } |
| 62 | |
| 63 | void |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 64 | SBInstructionList::Print (FILE *out) |
| 65 | { |
| 66 | if (out == NULL) |
| 67 | return; |
| 68 | } |
| 69 | |
Greg Clayton | 5c4c746 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 70 | |
| 71 | bool |
| 72 | SBInstructionList::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 | |