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
74 if (m_byte_order != eByteOrderInvalid)
80 case Opcode::eTypeInvalid: break;
83 case Opcode::eType16_2:
85 case Opcode::eType64: return lldb::endian::InlHostByteOrder();
86 case Opcode::eTypeBytes:
89 return eByteOrderInvalid;
93 Opcode::GetData (DataExtractor &data) const
95 uint32_t byte_size = GetByteSize ();
97 const void *buf = NULL;
101 if (!GetEndianSwap())
103 if (m_type == Opcode::eType16_2)
105 // 32 bit thumb instruction, we need to sizzle this a bit
106 swap_buf[0] = m_data.inst.bytes[2];
107 swap_buf[1] = m_data.inst.bytes[3];
108 swap_buf[2] = m_data.inst.bytes[0];
109 swap_buf[3] = m_data.inst.bytes[1];
114 buf = GetOpcodeDataBytes();
121 case Opcode::eTypeInvalid:
124 buf = GetOpcodeDataBytes();
126 case Opcode::eType16:
127 *(uint16_t *)swap_buf = llvm::ByteSwap_16(m_data.inst16);
130 case Opcode::eType16_2:
131 swap_buf[0] = m_data.inst.bytes[1];
132 swap_buf[1] = m_data.inst.bytes[0];
133 swap_buf[2] = m_data.inst.bytes[3];
134 swap_buf[3] = m_data.inst.bytes[2];
137 case Opcode::eType32:
138 *(uint32_t *)swap_buf = llvm::ByteSwap_32(m_data.inst32);
141 case Opcode::eType64:
142 *(uint32_t *)swap_buf = llvm::ByteSwap_64(m_data.inst64);
145 case Opcode::eTypeBytes:
146 buf = GetOpcodeDataBytes();
153 DataBufferSP buffer_sp;
155 buffer_sp.reset (new DataBufferHeap (buf, byte_size));
156 data.SetByteOrder(GetDataByteOrder());
157 data.SetData (buffer_sp);