Greg Clayton | 0ae9627 | 2011-03-24 23:53:38 +0000 | [diff] [blame] | 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 |
Greg Clayton | 1080edbc | 2011-03-25 18:03:16 +0000 | [diff] [blame^] | 16 | #include "lldb/Core/Stream.h" |
Greg Clayton | 0ae9627 | 2011-03-24 23:53:38 +0000 | [diff] [blame] | 17 | |
| 18 | using namespace lldb; |
Greg Clayton | 1080edbc | 2011-03-25 18:03:16 +0000 | [diff] [blame^] | 19 | using namespace lldb_private; |
| 20 | |
| 21 | |
| 22 | int |
| 23 | Opcode::Dump (Stream *s, uint32_t min_byte_width) |
| 24 | { |
| 25 | int bytes_written = 0; |
| 26 | switch (m_type) |
| 27 | { |
| 28 | case Opcode::eTypeInvalid: |
| 29 | bytes_written = s->PutCString ("<invalid>"); |
| 30 | break; |
| 31 | case Opcode::eType8: |
| 32 | bytes_written = s->Printf ("0x%2.2x", m_data.inst8); |
| 33 | break; |
| 34 | case Opcode::eType16: |
| 35 | bytes_written = s->Printf ("0x%4.4x", m_data.inst16); |
| 36 | break; |
| 37 | |
| 38 | case Opcode::eType32: |
| 39 | bytes_written = s->Printf ("0x%8.8x", m_data.inst32); |
| 40 | break; |
| 41 | |
| 42 | case Opcode::eType64: |
| 43 | bytes_written = s->Printf ("0x%16.16llx", m_data.inst64); |
| 44 | break; |
| 45 | |
| 46 | case Opcode::eTypeBytes: |
| 47 | { |
| 48 | for (uint32_t i=0; i<m_data.inst.length; ++i) |
| 49 | { |
| 50 | if (i > 0) |
| 51 | s->PutChar (' '); |
| 52 | bytes_written += s->Printf ("%2.2x", m_data.inst.bytes[i]); |
| 53 | } |
| 54 | } |
| 55 | break; |
| 56 | } |
| 57 | |
| 58 | // Add spaces to make sure bytes dispay comes out even in case opcodes |
| 59 | // aren't all the same size |
| 60 | if (bytes_written < min_byte_width) |
| 61 | bytes_written = s->Printf ("%*s", min_byte_width - bytes_written, ""); |
| 62 | return bytes_written; |
| 63 | } |
| 64 | |