1 //===-- Opcode.h ------------------------------------------------*- 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 //===----------------------------------------------------------------------===//
17 // Other libraries and framework includes
19 #include "lldb/lldb-public.h"
26 namespace lldb_private {
36 eType16_2, // a 32-bit Thumb instruction, made up of two words
42 Opcode () : m_type (eTypeInvalid)
46 Opcode (uint8_t inst) : m_type (eType8)
51 Opcode (uint16_t inst) : m_type (eType16)
56 Opcode (uint32_t inst) : m_type (eType32)
61 Opcode (uint64_t inst) : m_type (eType64)
66 Opcode (uint8_t *bytes, size_t length)
68 SetOpcodeBytes (bytes, length);
74 m_type = Opcode::eTypeInvalid;
83 GetOpcode8 (uint8_t invalid_opcode = UINT8_MAX) const
87 case Opcode::eTypeInvalid: break;
88 case Opcode::eType8: return m_data.inst8;
89 case Opcode::eType16: break;
90 case Opcode::eType16_2: break;
91 case Opcode::eType32: break;
92 case Opcode::eType64: break;
93 case Opcode::eTypeBytes: break;
96 return invalid_opcode;
100 GetOpcode16 (uint16_t invalid_opcode = UINT16_MAX) const
104 case Opcode::eTypeInvalid: break;
105 case Opcode::eType8: return m_data.inst8;
106 case Opcode::eType16: return m_data.inst16;
107 case Opcode::eType16_2: break;
108 case Opcode::eType32: break;
109 case Opcode::eType64: break;
110 case Opcode::eTypeBytes: break;
112 return invalid_opcode;
116 GetOpcode32 (uint32_t invalid_opcode = UINT32_MAX) const
120 case Opcode::eTypeInvalid: break;
121 case Opcode::eType8: return m_data.inst8;
122 case Opcode::eType16: return m_data.inst16;
123 case Opcode::eType16_2: // passthrough
124 case Opcode::eType32: return m_data.inst32;
125 case Opcode::eType64: break;
126 case Opcode::eTypeBytes: break;
128 return invalid_opcode;
132 GetOpcode64 (uint64_t invalid_opcode = UINT64_MAX) const
136 case Opcode::eTypeInvalid: break;
137 case Opcode::eType8: return m_data.inst8;
138 case Opcode::eType16: return m_data.inst16;
139 case Opcode::eType16_2: // passthrough
140 case Opcode::eType32: return m_data.inst32;
141 case Opcode::eType64: return m_data.inst64;
142 case Opcode::eTypeBytes: break;
144 return invalid_opcode;
148 SetOpcode8 (uint8_t inst)
155 SetOpcode16 (uint16_t inst)
158 m_data.inst16 = inst;
162 SetOpcode16_2 (uint32_t inst)
165 m_data.inst32 = inst;
169 SetOpcode32 (uint32_t inst)
172 m_data.inst32 = inst;
176 SetOpcode64 (uint64_t inst)
179 m_data.inst64 = inst;
183 SetOpcodeBytes (const void *bytes, size_t length)
185 if (bytes && length > 0)
188 m_data.inst.length = length;
189 assert (length < sizeof (m_data.inst.bytes));
190 memcpy (m_data.inst.bytes, bytes, length);
194 m_type = eTypeInvalid;
195 m_data.inst.length = 0;
200 Dump (Stream *s, uint32_t min_byte_width);
203 GetOpcodeBytes () const
205 if (m_type == Opcode::eTypeBytes)
206 return m_data.inst.bytes;
215 case Opcode::eTypeInvalid: break;
216 case Opcode::eType8: return sizeof(m_data.inst8);
217 case Opcode::eType16: return sizeof(m_data.inst16);
218 case Opcode::eType16_2: // passthrough
219 case Opcode::eType32: return sizeof(m_data.inst32);
220 case Opcode::eType64: return sizeof(m_data.inst64);
221 case Opcode::eTypeBytes: return m_data.inst.length;
226 // Get the opcode exactly as it would be laid out in memory.
228 GetData (DataExtractor &data) const;
232 friend class lldb::SBInstruction;
235 GetOpcodeDataBytes () const
239 case Opcode::eTypeInvalid: break;
240 case Opcode::eType8: return &m_data.inst8;
241 case Opcode::eType16: return &m_data.inst16;
242 case Opcode::eType16_2: // passthrough
243 case Opcode::eType32: return &m_data.inst32;
244 case Opcode::eType64: return &m_data.inst64;
245 case Opcode::eTypeBytes: return m_data.inst.bytes;
251 GetDataByteOrder () const;
262 uint8_t bytes[16]; // This must be big enough to handle any opcode for any supported target.
268 } // namespace lldb_private
270 #endif // lldb_Opcode_h