OLD | NEW |
1 // Copyright 2007-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 // Decoder decodes and disassembles instructions into an output buffer. | 49 // Decoder decodes and disassembles instructions into an output buffer. |
50 // It uses the converter to convert register names and call destinations into | 50 // It uses the converter to convert register names and call destinations into |
51 // more informative description. | 51 // more informative description. |
52 class Decoder { | 52 class Decoder { |
53 public: | 53 public: |
54 Decoder(const disasm::NameConverter& converter, | 54 Decoder(const disasm::NameConverter& converter, |
55 v8::internal::Vector<char> out_buffer) | 55 v8::internal::Vector<char> out_buffer) |
56 : converter_(converter), | 56 : converter_(converter), |
57 out_buffer_(out_buffer), | 57 out_buffer_(out_buffer), |
58 out_buffer_pos_(0) { | 58 out_buffer_pos_(0) { |
59 ASSERT(out_buffer_size_ > 0); | |
60 out_buffer_[out_buffer_pos_] = '\0'; | 59 out_buffer_[out_buffer_pos_] = '\0'; |
61 } | 60 } |
62 | 61 |
63 ~Decoder() {} | 62 ~Decoder() {} |
64 | 63 |
65 // Writes one disassembled instruction into 'buffer' (0-terminated). | 64 // Writes one disassembled instruction into 'buffer' (0-terminated). |
66 // Returns the length of the disassembled machine instruction in bytes. | 65 // Returns the length of the disassembled machine instruction in bytes. |
67 int InstructionDecode(byte* instruction); | 66 int InstructionDecode(byte* instruction); |
68 | 67 |
69 private: | 68 private: |
(...skipping 19 matching lines...) Expand all Loading... |
89 void DecodeType3(Instr* instr); | 88 void DecodeType3(Instr* instr); |
90 void DecodeType4(Instr* instr); | 89 void DecodeType4(Instr* instr); |
91 void DecodeType5(Instr* instr); | 90 void DecodeType5(Instr* instr); |
92 void DecodeType6(Instr* instr); | 91 void DecodeType6(Instr* instr); |
93 void DecodeType7(Instr* instr); | 92 void DecodeType7(Instr* instr); |
94 }; | 93 }; |
95 | 94 |
96 | 95 |
97 // Append the ch to the output buffer. | 96 // Append the ch to the output buffer. |
98 void Decoder::PrintChar(const char ch) { | 97 void Decoder::PrintChar(const char ch) { |
99 ASSERT(out_buffer_pos_ < out_buffer_size_); | |
100 out_buffer_[out_buffer_pos_++] = ch; | 98 out_buffer_[out_buffer_pos_++] = ch; |
101 } | 99 } |
102 | 100 |
103 | 101 |
104 // Append the str to the output buffer. | 102 // Append the str to the output buffer. |
105 void Decoder::Print(const char* str) { | 103 void Decoder::Print(const char* str) { |
106 char cur = *str++; | 104 char cur = *str++; |
107 while (cur != 0 && (out_buffer_pos_ < (out_buffer_.length()-1))) { | 105 while (cur != 0 && (out_buffer_pos_ < (out_buffer_.length()-1))) { |
108 PrintChar(cur); | 106 PrintChar(cur); |
109 cur = *str++; | 107 cur = *str++; |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 void Decoder::Format(Instr* instr, const char* format) { | 421 void Decoder::Format(Instr* instr, const char* format) { |
424 char cur = *format++; | 422 char cur = *format++; |
425 while ((cur != 0) && (out_buffer_pos_ < (out_buffer_.length() - 1))) { | 423 while ((cur != 0) && (out_buffer_pos_ < (out_buffer_.length() - 1))) { |
426 if (cur == '\'') { // Single quote is used as the formatting escape. | 424 if (cur == '\'') { // Single quote is used as the formatting escape. |
427 format += FormatOption(instr, format); | 425 format += FormatOption(instr, format); |
428 } else { | 426 } else { |
429 out_buffer_[out_buffer_pos_++] = cur; | 427 out_buffer_[out_buffer_pos_++] = cur; |
430 } | 428 } |
431 cur = *format++; | 429 cur = *format++; |
432 } | 430 } |
433 ASSERT(out_buffer_pos_ < out_buffer_size_); | |
434 out_buffer_[out_buffer_pos_] = '\0'; | 431 out_buffer_[out_buffer_pos_] = '\0'; |
435 } | 432 } |
436 | 433 |
437 | 434 |
438 // For currently unimplemented decodings the disassembler calls Unknown(instr) | 435 // For currently unimplemented decodings the disassembler calls Unknown(instr) |
439 // which will just print "unknown" of the instruction bits. | 436 // which will just print "unknown" of the instruction bits. |
440 void Decoder::Unknown(Instr* instr) { | 437 void Decoder::Unknown(Instr* instr) { |
441 Format(instr, "unknown"); | 438 Format(instr, "unknown"); |
442 } | 439 } |
443 | 440 |
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
935 buffer[0] = '\0'; | 932 buffer[0] = '\0'; |
936 byte* prev_pc = pc; | 933 byte* prev_pc = pc; |
937 pc += d.InstructionDecode(buffer, pc); | 934 pc += d.InstructionDecode(buffer, pc); |
938 fprintf(f, "%p %08x %s\n", | 935 fprintf(f, "%p %08x %s\n", |
939 prev_pc, *reinterpret_cast<int32_t*>(prev_pc), buffer.start()); | 936 prev_pc, *reinterpret_cast<int32_t*>(prev_pc), buffer.start()); |
940 } | 937 } |
941 } | 938 } |
942 | 939 |
943 | 940 |
944 } // namespace disasm | 941 } // namespace disasm |
OLD | NEW |