ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1 | // Copyright 2007-2008 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 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 | |
| 31 | namespace disasm { |
| 32 | |
| 33 | typedef 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. |
| 38 | class NameConverter { |
| 39 | public: |
| 40 | virtual ~NameConverter() {} |
| 41 | virtual const char* NameOfCPURegister(int reg) const; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 42 | virtual const char* NameOfByteCPURegister(int reg) const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 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; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 47 | |
| 48 | protected: |
| 49 | v8::internal::EmbeddedVector<char, 128> tmp_buffer_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | |
| 53 | // A generic Disassembler interface |
| 54 | class Disassembler { |
| 55 | public: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 56 | // Caller deallocates converter. |
| 57 | explicit Disassembler(const NameConverter& converter); |
| 58 | |
| 59 | virtual ~Disassembler(); |
| 60 | |
| 61 | // Writes one disassembled instruction into 'buffer' (0-terminated). |
| 62 | // Returns the length of the disassembled machine instruction in bytes. |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 63 | int InstructionDecode(v8::internal::Vector<char> buffer, byte* instruction); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 64 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 65 | // Returns -1 if instruction does not mark the beginning of a constant pool, |
| 66 | // or the number of entries in the constant pool beginning here. |
| 67 | int ConstantPoolSizeAt(byte* instruction); |
| 68 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 69 | // Write disassembly into specified file 'f' using specified NameConverter |
| 70 | // (see constructor). |
| 71 | static void Disassemble(FILE* f, byte* begin, byte* end); |
| 72 | private: |
| 73 | const NameConverter& converter_; |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 74 | |
| 75 | DISALLOW_IMPLICIT_CONSTRUCTORS(Disassembler); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | } // namespace disasm |
| 79 | |
| 80 | #endif // V8_DISASM_H_ |