blob: 1fd55195aae96d834ee70aabd733a8d42382e450 [file] [log] [blame]
ager@chromium.org9258b6b2008-09-11 09:11:10 +00001// Copyright 2007-2008 the V8 project authors. All rights reserved.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002// 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* NameOfXMMRegister(int reg) const;
43 virtual const char* NameOfAddress(byte* addr) const;
44 virtual const char* NameOfConstant(byte* addr) const;
45 virtual const char* NameInCode(byte* addr) const;
46};
47
48
49// A generic Disassembler interface
50class Disassembler {
51 public:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000052 // Caller deallocates converter.
53 explicit Disassembler(const NameConverter& converter);
54
55 virtual ~Disassembler();
56
57 // Writes one disassembled instruction into 'buffer' (0-terminated).
58 // Returns the length of the disassembled machine instruction in bytes.
kasperl@chromium.orgb9123622008-09-17 14:05:56 +000059 int InstructionDecode(v8::internal::Vector<char> buffer, byte* instruction);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000060
kasper.lund7276f142008-07-30 08:49:36 +000061 // Returns -1 if instruction does not mark the beginning of a constant pool,
62 // or the number of entries in the constant pool beginning here.
63 int ConstantPoolSizeAt(byte* instruction);
64
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000065 // Write disassembly into specified file 'f' using specified NameConverter
66 // (see constructor).
67 static void Disassemble(FILE* f, byte* begin, byte* end);
68 private:
69 const NameConverter& converter_;
ager@chromium.org3bf7b912008-11-17 09:09:45 +000070
71 DISALLOW_IMPLICIT_CONSTRUCTORS(Disassembler);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000072};
73
74} // namespace disasm
75
76#endif // V8_DISASM_H_