#ifdef ENABLE_DISASSEMBLER
-void Disassembler::Dump(FILE* f, byte* begin, byte* end) {
- for (byte* pc = begin; pc < end; pc++) {
- if (f == NULL) {
- PrintF("%" V8PRIxPTR " %4" V8PRIdPTR " %02x\n",
- reinterpret_cast<intptr_t>(pc),
- pc - begin,
- *pc);
- } else {
- PrintF(f, "%" V8PRIxPTR " %4" V8PRIdPTR " %02x\n",
- reinterpret_cast<uintptr_t>(pc), pc - begin, *pc);
- }
- }
-}
-
-
class V8NameConverter: public disasm::NameConverter {
public:
explicit V8NameConverter(Code* code) : code_(code) {}
}
-static void DumpBuffer(FILE* f, StringBuilder* out) {
- if (f == NULL) {
- PrintF("%s\n", out->Finalize());
- } else {
- PrintF(f, "%s\n", out->Finalize());
- }
+static void DumpBuffer(OStream* os, StringBuilder* out) {
+ (*os) << out->Finalize() << endl;
out->Reset();
}
static const int kOutBufferSize = 2048 + String::kMaxShortPrintLength;
static const int kRelocInfoPosition = 57;
-static int DecodeIt(Isolate* isolate,
- FILE* f,
- const V8NameConverter& converter,
- byte* begin,
- byte* end) {
+static int DecodeIt(Isolate* isolate, OStream* os,
+ const V8NameConverter& converter, byte* begin, byte* end) {
SealHandleScope shs(isolate);
DisallowHeapAllocation no_alloc;
ExternalReferenceEncoder ref_encoder(isolate);
// Comments.
for (int i = 0; i < comments.length(); i++) {
out.AddFormatted(" %s", comments[i]);
- DumpBuffer(f, &out);
+ DumpBuffer(os, &out);
}
// Instruction address and instruction offset.
out.AddPadding(' ', kRelocInfoPosition - out.position());
} else {
// Additional reloc infos are printed on separate lines.
- DumpBuffer(f, &out);
+ DumpBuffer(os, &out);
out.AddPadding(' ', kRelocInfoPosition);
}
out.AddFormatted(" ;; %s", RelocInfo::RelocModeName(rmode));
}
}
- DumpBuffer(f, &out);
+ DumpBuffer(os, &out);
}
// Emit comments following the last instruction (if any).
if (RelocInfo::IsComment(it->rinfo()->rmode())) {
out.AddFormatted(" %s",
reinterpret_cast<const char*>(it->rinfo()->data()));
- DumpBuffer(f, &out);
+ DumpBuffer(os, &out);
}
}
}
}
-int Disassembler::Decode(Isolate* isolate, FILE* f, byte* begin, byte* end) {
- V8NameConverter defaultConverter(NULL);
- return DecodeIt(isolate, f, defaultConverter, begin, end);
-}
-
-
-// Called by Code::CodePrint.
-void Disassembler::Decode(FILE* f, Code* code) {
- Isolate* isolate = code->GetIsolate();
- int decode_size = code->is_crankshafted()
- ? static_cast<int>(code->safepoint_table_offset())
- : code->instruction_size();
- // If there might be a back edge table, stop before reaching it.
- if (code->kind() == Code::FUNCTION) {
- decode_size =
- Min(decode_size, static_cast<int>(code->back_edge_table_offset()));
- }
-
- byte* begin = code->instruction_start();
- byte* end = begin + decode_size;
+int Disassembler::Decode(Isolate* isolate, OStream* os, byte* begin, byte* end,
+ Code* code) {
V8NameConverter v8NameConverter(code);
- DecodeIt(isolate, f, v8NameConverter, begin, end);
+ return DecodeIt(isolate, os, v8NameConverter, begin, end);
}
#else // ENABLE_DISASSEMBLER
-void Disassembler::Dump(FILE* f, byte* begin, byte* end) {}
-int Disassembler::Decode(Isolate* isolate, FILE* f, byte* begin, byte* end) {
+int Disassembler::Decode(Isolate* isolate, OStream* os, byte* begin, byte* end,
+ Code* code) {
return 0;
}
-
-void Disassembler::Decode(FILE* f, Code* code) {}
-
#endif // ENABLE_DISASSEMBLER
} } // namespace v8::internal
class Disassembler : public AllStatic {
public:
- // Print the bytes in the interval [begin, end) into f.
- static void Dump(FILE* f, byte* begin, byte* end);
-
// Decode instructions in the the interval [begin, end) and print the
- // code into f. Returns the number of bytes disassembled or 1 if no
+ // code into os. Returns the number of bytes disassembled or 1 if no
// instruction could be decoded.
- static int Decode(Isolate* isolate, FILE* f, byte* begin, byte* end);
-
- // Decode instructions in code.
- static void Decode(FILE* f, Code* code);
- private:
- // Decode instruction at pc and print disassembled instruction into f.
- // Returns the instruction length in bytes, or 1 if the instruction could
- // not be decoded. The number of characters written is written into
- // the out parameter char_count.
- static int Decode(FILE* f, byte* pc, int* char_count);
+ // the code object is used for name resolution and may be null.
+ static int Decode(Isolate* isolate, OStream* os, byte* begin, byte* end,
+ Code* code = NULL);
};
} } // namespace v8::internal
}
os << "Instructions (size = " << instruction_size() << ")\n";
- // TODO(svenpanne) The Disassembler should use streams, too!
{
- CodeTracer::Scope trace_scope(GetIsolate()->GetCodeTracer());
- Disassembler::Decode(trace_scope.file(), this);
+ Isolate* isolate = GetIsolate();
+ int decode_size = is_crankshafted()
+ ? static_cast<int>(safepoint_table_offset())
+ : instruction_size();
+ // If there might be a back edge table, stop before reaching it.
+ if (kind() == Code::FUNCTION) {
+ decode_size =
+ Min(decode_size, static_cast<int>(back_edge_table_offset()));
+ }
+ byte* begin = instruction_start();
+ byte* end = begin + decode_size;
+ Disassembler::Decode(isolate, &os, begin, end, this);
}
os << "\n";
assm.GetCode(&desc);
Handle<Code> code = isolate->factory()->NewCode(
desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
- // don't print the code - our disassembler can't handle cvttss2si
- // instead print bytes
- Disassembler::Dump(stdout,
- code->instruction_start(),
- code->instruction_start() + code->instruction_size());
+#ifdef OBJECT_PRINT
+ OFStream os(stdout);
+ code->Print(os);
+#endif
F3 f = FUNCTION_CAST<F3>(code->entry());
int res = f(static_cast<float>(-3.1415));
::printf("f() = %d\n", res);
assm.GetCode(&desc);
Handle<Code> code = isolate->factory()->NewCode(
desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
- // don't print the code - our disassembler can't handle cvttsd2si
- // instead print bytes
- Disassembler::Dump(stdout,
- code->instruction_start(),
- code->instruction_start() + code->instruction_size());
+#ifdef OBJECT_PRINT
+ OFStream os(stdout);
+ code->Print(os);
+#endif
F4 f = FUNCTION_CAST<F4>(code->entry());
int res = f(2.718281828);
::printf("f() = %d\n", res);
assm.GetCode(&desc);
Handle<Code> code = isolate->factory()->NewCode(
desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
-#ifdef DEBUG
- ::printf("\n---\n");
- // don't print the code - our disassembler can't handle SSE instructions
- // instead print bytes
- Disassembler::Dump(stdout,
- code->instruction_start(),
- code->instruction_start() + code->instruction_size());
+#ifdef OBJECT_PRINT
+ OFStream os(stdout);
+ code->Print(os);
#endif
F5 f = FUNCTION_CAST<F5>(code->entry());
double res = f(2.2, 1.1);