1 //===-- Baton.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/Core/Opcode.h" 11 12 // C Includes 13 // C++ Includes 14 // Other libraries and framework includes 15 // Project includes 16 #include "lldb/Core/Stream.h" 17 #include "lldb/Host/Endian.h" 18 19 using namespace lldb; 20 using namespace lldb_private; 21 22 23 int 24 Opcode::Dump (Stream *s, uint32_t min_byte_width) 25 { 26 int bytes_written = 0; 27 switch (m_type) 28 { 29 case Opcode::eTypeInvalid: 30 bytes_written = s->PutCString ("<invalid>"); 31 break; 32 case Opcode::eType8: 33 bytes_written = s->Printf ("0x%2.2x", m_data.inst8); 34 break; 35 case Opcode::eType16: 36 bytes_written = s->Printf ("0x%4.4x", m_data.inst16); 37 break; 38 39 case Opcode::eType32: 40 bytes_written = s->Printf ("0x%8.8x", m_data.inst32); 41 break; 42 43 case Opcode::eType64: 44 bytes_written = s->Printf ("0x%16.16llx", m_data.inst64); 45 break; 46 47 case Opcode::eTypeBytes: 48 { 49 for (uint32_t i=0; i<m_data.inst.length; ++i) 50 { 51 if (i > 0) 52 bytes_written += s->PutChar (' '); 53 bytes_written += s->Printf ("%2.2x", m_data.inst.bytes[i]); 54 } 55 } 56 break; 57 } 58 59 // Add spaces to make sure bytes dispay comes out even in case opcodes 60 // aren't all the same size 61 if (bytes_written < min_byte_width) 62 bytes_written = s->Printf ("%*s", min_byte_width - bytes_written, ""); 63 return bytes_written; 64 } 65 66 lldb::ByteOrder 67 Opcode::GetDataByteOrder () const 68 { 69 switch (m_type) 70 { 71 case Opcode::eTypeInvalid: break; 72 case Opcode::eType8: 73 case Opcode::eType16: 74 case Opcode::eType32: 75 case Opcode::eType64: return lldb::endian::InlHostByteOrder(); 76 case Opcode::eTypeBytes: 77 break; 78 } 79 return eByteOrderInvalid; 80 } 81 82