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 161080edbcSGreg Clayton #include "lldb/Core/Stream.h" 170ae96273SGreg Clayton 180ae96273SGreg Clayton using namespace lldb; 190ae96273SGreg Clayton using namespace lldb_private; 201080edbcSGreg Clayton 211080edbcSGreg Clayton 221080edbcSGreg Clayton int 231080edbcSGreg Clayton Opcode::Dump (Stream *s, uint32_t min_byte_width) 241080edbcSGreg Clayton { 251080edbcSGreg Clayton int bytes_written = 0; 261080edbcSGreg Clayton switch (m_type) 271080edbcSGreg Clayton { 281080edbcSGreg Clayton case Opcode::eTypeInvalid: 291080edbcSGreg Clayton bytes_written = s->PutCString ("<invalid>"); 301080edbcSGreg Clayton break; 311080edbcSGreg Clayton case Opcode::eType8: 321080edbcSGreg Clayton bytes_written = s->Printf ("0x%2.2x", m_data.inst8); 331080edbcSGreg Clayton break; 341080edbcSGreg Clayton case Opcode::eType16: 351080edbcSGreg Clayton bytes_written = s->Printf ("0x%4.4x", m_data.inst16); 361080edbcSGreg Clayton break; 371080edbcSGreg Clayton 381080edbcSGreg Clayton case Opcode::eType32: 391080edbcSGreg Clayton bytes_written = s->Printf ("0x%8.8x", m_data.inst32); 401080edbcSGreg Clayton break; 411080edbcSGreg Clayton 421080edbcSGreg Clayton case Opcode::eType64: 431080edbcSGreg Clayton bytes_written = s->Printf ("0x%16.16llx", m_data.inst64); 441080edbcSGreg Clayton break; 451080edbcSGreg Clayton 461080edbcSGreg Clayton case Opcode::eTypeBytes: 471080edbcSGreg Clayton { 481080edbcSGreg Clayton for (uint32_t i=0; i<m_data.inst.length; ++i) 491080edbcSGreg Clayton { 501080edbcSGreg Clayton if (i > 0) 51*357132ebSGreg Clayton bytes_written += s->PutChar (' '); 521080edbcSGreg Clayton bytes_written += s->Printf ("%2.2x", m_data.inst.bytes[i]); 531080edbcSGreg Clayton } 541080edbcSGreg Clayton } 551080edbcSGreg Clayton break; 561080edbcSGreg Clayton } 571080edbcSGreg Clayton 581080edbcSGreg Clayton // Add spaces to make sure bytes dispay comes out even in case opcodes 591080edbcSGreg Clayton // aren't all the same size 601080edbcSGreg Clayton if (bytes_written < min_byte_width) 611080edbcSGreg Clayton bytes_written = s->Printf ("%*s", min_byte_width - bytes_written, ""); 621080edbcSGreg Clayton return bytes_written; 631080edbcSGreg Clayton } 641080edbcSGreg Clayton 65