1 //===-- Opcode.cpp ----------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Core/Opcode.h"
14 // Other libraries and framework includes
15 #include "llvm/ADT/Triple.h"
17 #include "lldb/Core/ArchSpec.h"
18 #include "lldb/Core/DataBufferHeap.h"
19 #include "lldb/Core/DataExtractor.h"
20 #include "lldb/Core/Stream.h"
21 #include "lldb/Host/Endian.h"
25 using namespace lldb_private;
29 Opcode::Dump (Stream *s, uint32_t min_byte_width)
31 int bytes_written = 0;
34 case Opcode::eTypeInvalid:
35 bytes_written = s->PutCString ("<invalid>");
38 bytes_written = s->Printf ("0x%2.2x", m_data.inst8);
41 bytes_written = s->Printf ("0x%4.4x", m_data.inst16);
43 case Opcode::eType16_2:
45 bytes_written = s->Printf ("0x%8.8x", m_data.inst32);
49 bytes_written = s->Printf ("0x%16.16" PRIx64, m_data.inst64);
52 case Opcode::eTypeBytes:
54 for (uint32_t i=0; i<m_data.inst.length; ++i)
57 bytes_written += s->PutChar (' ');
58 bytes_written += s->Printf ("%2.2x", m_data.inst.bytes[i]);
64 // Add spaces to make sure bytes dispay comes out even in case opcodes
65 // aren't all the same size
66 if (bytes_written < min_byte_width)
67 bytes_written = s->Printf ("%*s", min_byte_width - bytes_written, "");
72 Opcode::GetDataByteOrder () const
76 case Opcode::eTypeInvalid: break;
79 case Opcode::eType16_2:
81 case Opcode::eType64: return lldb::endian::InlHostByteOrder();
82 case Opcode::eTypeBytes:
85 return eByteOrderInvalid;
89 Opcode::GetData (DataExtractor &data) const
91 uint32_t byte_size = GetByteSize ();
93 DataBufferSP buffer_sp;
98 case Opcode::eTypeInvalid:
101 case Opcode::eType8: buffer_sp.reset (new DataBufferHeap (&m_data.inst8, byte_size)); break;
102 case Opcode::eType16: buffer_sp.reset (new DataBufferHeap (&m_data.inst16, byte_size)); break;
103 case Opcode::eType16_2:
105 // 32 bit thumb instruction, we need to sizzle this a bit
107 buf[0] = m_data.inst.bytes[2];
108 buf[1] = m_data.inst.bytes[3];
109 buf[2] = m_data.inst.bytes[0];
110 buf[3] = m_data.inst.bytes[1];
111 buffer_sp.reset (new DataBufferHeap (buf, byte_size));
114 case Opcode::eType32:
115 buffer_sp.reset (new DataBufferHeap (&m_data.inst32, byte_size));
117 case Opcode::eType64: buffer_sp.reset (new DataBufferHeap (&m_data.inst64, byte_size)); break;
118 case Opcode::eTypeBytes:buffer_sp.reset (new DataBufferHeap (GetOpcodeBytes(), byte_size)); break;
125 data.SetByteOrder(GetDataByteOrder());
126 data.SetData (buffer_sp);