10ae96273SGreg Clayton //===-- Baton.cpp -----------------------------------------------*- C++ -*-===// 20ae96273SGreg Clayton // 30ae96273SGreg Clayton // The LLVM Compiler Infrastructure 40ae96273SGreg Clayton // 50ae96273SGreg Clayton // This file is distributed under the University of Illinois Open Source 60ae96273SGreg Clayton // License. See LICENSE.TXT for details. 70ae96273SGreg Clayton // 80ae96273SGreg Clayton //===----------------------------------------------------------------------===// 90ae96273SGreg Clayton 100ae96273SGreg Clayton #include "lldb/Core/Opcode.h" 110ae96273SGreg Clayton 120ae96273SGreg Clayton // C Includes 130ae96273SGreg Clayton // C++ Includes 140ae96273SGreg Clayton // Other libraries and framework includes 150ae96273SGreg Clayton // Project includes 16*1080edbcSGreg Clayton #include "lldb/Core/Stream.h" 170ae96273SGreg Clayton 180ae96273SGreg Clayton using namespace lldb; 190ae96273SGreg Clayton using namespace lldb_private; 20*1080edbcSGreg Clayton 21*1080edbcSGreg Clayton 22*1080edbcSGreg Clayton int 23*1080edbcSGreg Clayton Opcode::Dump (Stream *s, uint32_t min_byte_width) 24*1080edbcSGreg Clayton { 25*1080edbcSGreg Clayton int bytes_written = 0; 26*1080edbcSGreg Clayton switch (m_type) 27*1080edbcSGreg Clayton { 28*1080edbcSGreg Clayton case Opcode::eTypeInvalid: 29*1080edbcSGreg Clayton bytes_written = s->PutCString ("<invalid>"); 30*1080edbcSGreg Clayton break; 31*1080edbcSGreg Clayton case Opcode::eType8: 32*1080edbcSGreg Clayton bytes_written = s->Printf ("0x%2.2x", m_data.inst8); 33*1080edbcSGreg Clayton break; 34*1080edbcSGreg Clayton case Opcode::eType16: 35*1080edbcSGreg Clayton bytes_written = s->Printf ("0x%4.4x", m_data.inst16); 36*1080edbcSGreg Clayton break; 37*1080edbcSGreg Clayton 38*1080edbcSGreg Clayton case Opcode::eType32: 39*1080edbcSGreg Clayton bytes_written = s->Printf ("0x%8.8x", m_data.inst32); 40*1080edbcSGreg Clayton break; 41*1080edbcSGreg Clayton 42*1080edbcSGreg Clayton case Opcode::eType64: 43*1080edbcSGreg Clayton bytes_written = s->Printf ("0x%16.16llx", m_data.inst64); 44*1080edbcSGreg Clayton break; 45*1080edbcSGreg Clayton 46*1080edbcSGreg Clayton case Opcode::eTypeBytes: 47*1080edbcSGreg Clayton { 48*1080edbcSGreg Clayton for (uint32_t i=0; i<m_data.inst.length; ++i) 49*1080edbcSGreg Clayton { 50*1080edbcSGreg Clayton if (i > 0) 51*1080edbcSGreg Clayton s->PutChar (' '); 52*1080edbcSGreg Clayton bytes_written += s->Printf ("%2.2x", m_data.inst.bytes[i]); 53*1080edbcSGreg Clayton } 54*1080edbcSGreg Clayton } 55*1080edbcSGreg Clayton break; 56*1080edbcSGreg Clayton } 57*1080edbcSGreg Clayton 58*1080edbcSGreg Clayton // Add spaces to make sure bytes dispay comes out even in case opcodes 59*1080edbcSGreg Clayton // aren't all the same size 60*1080edbcSGreg Clayton if (bytes_written < min_byte_width) 61*1080edbcSGreg Clayton bytes_written = s->Printf ("%*s", min_byte_width - bytes_written, ""); 62*1080edbcSGreg Clayton return bytes_written; 63*1080edbcSGreg Clayton } 64*1080edbcSGreg Clayton 65