1// Copyright 2007-2008 the V8 project authors. All rights reserved. 2// Redistribution and use in source and binary forms, with or without 3// modification, are permitted provided that the following conditions are 4// met: 5// 6// * Redistributions of source code must retain the above copyright 7// notice, this list of conditions and the following disclaimer. 8// * Redistributions in binary form must reproduce the above 9// copyright notice, this list of conditions and the following 10// disclaimer in the documentation and/or other materials provided 11// with the distribution. 12// * Neither the name of Google Inc. nor the names of its 13// contributors may be used to endorse or promote products derived 14// from this software without specific prior written permission. 15// 16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 28#ifndef V8_DISASM_H_ 29#define V8_DISASM_H_ 30 31namespace disasm { 32 33typedef unsigned char byte; 34 35// Interface and default implementation for converting addresses and 36// register-numbers to text. The default implementation is machine 37// specific. 38class NameConverter { 39 public: 40 virtual ~NameConverter() {} 41 virtual const char* NameOfCPURegister(int reg) const; 42 virtual const char* NameOfByteCPURegister(int reg) const; 43 virtual const char* NameOfXMMRegister(int reg) const; 44 virtual const char* NameOfAddress(byte* addr) const; 45 virtual const char* NameOfConstant(byte* addr) const; 46 virtual const char* NameInCode(byte* addr) const; 47}; 48 49 50// A generic Disassembler interface 51class Disassembler { 52 public: 53 // Caller deallocates converter. 54 explicit Disassembler(const NameConverter& converter); 55 56 virtual ~Disassembler(); 57 58 // Writes one disassembled instruction into 'buffer' (0-terminated). 59 // Returns the length of the disassembled machine instruction in bytes. 60 int InstructionDecode(v8::internal::Vector<char> buffer, byte* instruction); 61 62 // Returns -1 if instruction does not mark the beginning of a constant pool, 63 // or the number of entries in the constant pool beginning here. 64 int ConstantPoolSizeAt(byte* instruction); 65 66 // Write disassembly into specified file 'f' using specified NameConverter 67 // (see constructor). 68 static void Disassemble(FILE* f, byte* begin, byte* end); 69 private: 70 const NameConverter& converter_; 71 72 DISALLOW_IMPLICIT_CONSTRUCTORS(Disassembler); 73}; 74 75} // namespace disasm 76 77#endif // V8_DISASM_H_ 78