Home | History | Annotate | Download | only in src
      1 // Copyright 2007-2008 the V8 project authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef V8_DISASM_H_
      6 #define V8_DISASM_H_
      7 
      8 namespace disasm {
      9 
     10 typedef unsigned char byte;
     11 
     12 // Interface and default implementation for converting addresses and
     13 // register-numbers to text.  The default implementation is machine
     14 // specific.
     15 class NameConverter {
     16  public:
     17   virtual ~NameConverter() {}
     18   virtual const char* NameOfCPURegister(int reg) const;
     19   virtual const char* NameOfByteCPURegister(int reg) const;
     20   virtual const char* NameOfXMMRegister(int reg) const;
     21   virtual const char* NameOfAddress(byte* addr) const;
     22   virtual const char* NameOfConstant(byte* addr) const;
     23   virtual const char* NameInCode(byte* addr) const;
     24 
     25  protected:
     26   v8::internal::EmbeddedVector<char, 128> tmp_buffer_;
     27 };
     28 
     29 
     30 // A generic Disassembler interface
     31 class Disassembler {
     32  public:
     33   // Caller deallocates converter.
     34   explicit Disassembler(const NameConverter& converter);
     35 
     36   virtual ~Disassembler();
     37 
     38   // Writes one disassembled instruction into 'buffer' (0-terminated).
     39   // Returns the length of the disassembled machine instruction in bytes.
     40   int InstructionDecode(v8::internal::Vector<char> buffer, byte* instruction);
     41 
     42   // Returns -1 if instruction does not mark the beginning of a constant pool,
     43   // or the number of entries in the constant pool beginning here.
     44   int ConstantPoolSizeAt(byte* instruction);
     45 
     46   // Write disassembly into specified file 'f' using specified NameConverter
     47   // (see constructor).
     48   static void Disassemble(FILE* f, byte* begin, byte* end);
     49  private:
     50   const NameConverter& converter_;
     51 
     52   DISALLOW_IMPLICIT_CONSTRUCTORS(Disassembler);
     53 };
     54 
     55 }  // namespace disasm
     56 
     57 #endif  // V8_DISASM_H_
     58