2008-09-09 20:08:45 +00:00
|
|
|
// Copyright 2007-2008 the V8 project authors. All rights reserved.
|
2008-07-03 15:10:15 +00:00
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following
|
|
|
|
// disclaimer in the documentation and/or other materials provided
|
|
|
|
// with the distribution.
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived
|
|
|
|
// from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
#ifndef V8_DISASM_H_
|
|
|
|
#define V8_DISASM_H_
|
|
|
|
|
|
|
|
namespace disasm {
|
|
|
|
|
|
|
|
typedef unsigned char byte;
|
|
|
|
|
|
|
|
// Interface and default implementation for converting addresses and
|
|
|
|
// register-numbers to text. The default implementation is machine
|
|
|
|
// specific.
|
|
|
|
class NameConverter {
|
|
|
|
public:
|
|
|
|
virtual ~NameConverter() {}
|
|
|
|
virtual const char* NameOfCPURegister(int reg) const;
|
|
|
|
virtual const char* NameOfXMMRegister(int reg) const;
|
|
|
|
virtual const char* NameOfAddress(byte* addr) const;
|
|
|
|
virtual const char* NameOfConstant(byte* addr) const;
|
|
|
|
virtual const char* NameInCode(byte* addr) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// A generic Disassembler interface
|
|
|
|
class Disassembler {
|
|
|
|
public:
|
|
|
|
// Caller deallocates converter.
|
|
|
|
explicit Disassembler(const NameConverter& converter);
|
|
|
|
|
|
|
|
virtual ~Disassembler();
|
|
|
|
|
|
|
|
// Writes one disassembled instruction into 'buffer' (0-terminated).
|
|
|
|
// Returns the length of the disassembled machine instruction in bytes.
|
2008-09-11 14:34:48 +00:00
|
|
|
int InstructionDecode(v8::internal::Vector<char> buffer, byte* instruction);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-07-30 08:49:36 +00:00
|
|
|
// Returns -1 if instruction does not mark the beginning of a constant pool,
|
|
|
|
// or the number of entries in the constant pool beginning here.
|
|
|
|
int ConstantPoolSizeAt(byte* instruction);
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Write disassembly into specified file 'f' using specified NameConverter
|
|
|
|
// (see constructor).
|
|
|
|
static void Disassemble(FILE* f, byte* begin, byte* end);
|
|
|
|
private:
|
|
|
|
const NameConverter& converter_;
|
2008-11-05 19:18:10 +00:00
|
|
|
|
|
|
|
DISALLOW_IMPLICIT_CONSTRUCTORS(Disassembler);
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace disasm
|
|
|
|
|
|
|
|
#endif // V8_DISASM_H_
|