Commit ab1d270a authored by mtrofin's avatar mtrofin Committed by Commit bot

[assembler] Introduce proper AssemblerBase::Print() for improved debuggability.

While working on frame elision, I wanted to disassemble codegen in the
debugger, as the code generation is progressing. I discovered we had a
 "Print" member on the x64 assembler, without any implementation. I
pulled it up to AssemblerBase and gave it an implementation that
should work for the other architectures.

Also checked that ia32, x87, arm and arm64 assemblers didn't have
such an implementation - free Print.

Arm64 has a naming conflict with the v8::internal::Disassembler. I
renamed the arm64 type with a more specific name.

Opportunistically fixed a bug in the name converter. This debug-time
printer doesn't provide a Code object, which should be OK with the
name converters, by the looks of other APIs there. All this means is that
when using the Print() API, we just get addresses dumped without any
context (like what this address may be - a stub maybe, etc). This seems
fine for the scenario.

There may be other places that assume a Code object. Since this is
a diagnostics-only scenario, for codegen developers, I feel it is
reasonable to fix such other places as we find them.

Review URL: https://codereview.chromium.org/1431933003

Cr-Commit-Position: refs/heads/master@{#31869}
parent be4d1b19
......@@ -19,7 +19,7 @@ namespace v8 {
namespace internal {
Disassembler::Disassembler() {
DisassemblingDecoder::DisassemblingDecoder() {
buffer_size_ = 256;
buffer_ = reinterpret_cast<char*>(malloc(buffer_size_));
buffer_pos_ = 0;
......@@ -27,7 +27,7 @@ Disassembler::Disassembler() {
}
Disassembler::Disassembler(char* text_buffer, int buffer_size) {
DisassemblingDecoder::DisassemblingDecoder(char* text_buffer, int buffer_size) {
buffer_size_ = buffer_size;
buffer_ = text_buffer;
buffer_pos_ = 0;
......@@ -35,19 +35,17 @@ Disassembler::Disassembler(char* text_buffer, int buffer_size) {
}
Disassembler::~Disassembler() {
DisassemblingDecoder::~DisassemblingDecoder() {
if (own_buffer_) {
free(buffer_);
}
}
char* Disassembler::GetOutput() {
return buffer_;
}
char* DisassemblingDecoder::GetOutput() { return buffer_; }
void Disassembler::VisitAddSubImmediate(Instruction* instr) {
void DisassemblingDecoder::VisitAddSubImmediate(Instruction* instr) {
bool rd_is_zr = RdIsZROrSP(instr);
bool stack_op = (rd_is_zr || RnIsZROrSP(instr)) &&
(instr->ImmAddSub() == 0) ? true : false;
......@@ -92,7 +90,7 @@ void Disassembler::VisitAddSubImmediate(Instruction* instr) {
}
void Disassembler::VisitAddSubShifted(Instruction* instr) {
void DisassemblingDecoder::VisitAddSubShifted(Instruction* instr) {
bool rd_is_zr = RdIsZROrSP(instr);
bool rn_is_zr = RnIsZROrSP(instr);
const char *mnemonic = "";
......@@ -139,7 +137,7 @@ void Disassembler::VisitAddSubShifted(Instruction* instr) {
}
void Disassembler::VisitAddSubExtended(Instruction* instr) {
void DisassemblingDecoder::VisitAddSubExtended(Instruction* instr) {
bool rd_is_zr = RdIsZROrSP(instr);
const char *mnemonic = "";
Extend mode = static_cast<Extend>(instr->ExtendMode());
......@@ -177,7 +175,7 @@ void Disassembler::VisitAddSubExtended(Instruction* instr) {
}
void Disassembler::VisitAddSubWithCarry(Instruction* instr) {
void DisassemblingDecoder::VisitAddSubWithCarry(Instruction* instr) {
bool rn_is_zr = RnIsZROrSP(instr);
const char *mnemonic = "";
const char *form = "'Rd, 'Rn, 'Rm";
......@@ -212,7 +210,7 @@ void Disassembler::VisitAddSubWithCarry(Instruction* instr) {
}
void Disassembler::VisitLogicalImmediate(Instruction* instr) {
void DisassemblingDecoder::VisitLogicalImmediate(Instruction* instr) {
bool rd_is_zr = RdIsZROrSP(instr);
bool rn_is_zr = RnIsZROrSP(instr);
const char *mnemonic = "";
......@@ -255,7 +253,7 @@ void Disassembler::VisitLogicalImmediate(Instruction* instr) {
}
bool Disassembler::IsMovzMovnImm(unsigned reg_size, uint64_t value) {
bool DisassemblingDecoder::IsMovzMovnImm(unsigned reg_size, uint64_t value) {
DCHECK((reg_size == kXRegSizeInBits) ||
((reg_size == kWRegSizeInBits) && (value <= 0xffffffff)));
......@@ -284,7 +282,7 @@ bool Disassembler::IsMovzMovnImm(unsigned reg_size, uint64_t value) {
}
void Disassembler::VisitLogicalShifted(Instruction* instr) {
void DisassemblingDecoder::VisitLogicalShifted(Instruction* instr) {
bool rd_is_zr = RdIsZROrSP(instr);
bool rn_is_zr = RnIsZROrSP(instr);
const char *mnemonic = "";
......@@ -335,7 +333,7 @@ void Disassembler::VisitLogicalShifted(Instruction* instr) {
}
void Disassembler::VisitConditionalCompareRegister(Instruction* instr) {
void DisassemblingDecoder::VisitConditionalCompareRegister(Instruction* instr) {
const char *mnemonic = "";
const char *form = "'Rn, 'Rm, 'INzcv, 'Cond";
......@@ -350,7 +348,8 @@ void Disassembler::VisitConditionalCompareRegister(Instruction* instr) {
}
void Disassembler::VisitConditionalCompareImmediate(Instruction* instr) {
void DisassemblingDecoder::VisitConditionalCompareImmediate(
Instruction* instr) {
const char *mnemonic = "";
const char *form = "'Rn, 'IP, 'INzcv, 'Cond";
......@@ -365,7 +364,7 @@ void Disassembler::VisitConditionalCompareImmediate(Instruction* instr) {
}
void Disassembler::VisitConditionalSelect(Instruction* instr) {
void DisassemblingDecoder::VisitConditionalSelect(Instruction* instr) {
bool rnm_is_zr = (RnIsZROrSP(instr) && RmIsZROrSP(instr));
bool rn_is_rm = (instr->Rn() == instr->Rm());
const char *mnemonic = "";
......@@ -418,7 +417,7 @@ void Disassembler::VisitConditionalSelect(Instruction* instr) {
}
void Disassembler::VisitBitfield(Instruction* instr) {
void DisassemblingDecoder::VisitBitfield(Instruction* instr) {
unsigned s = instr->ImmS();
unsigned r = instr->ImmR();
unsigned rd_size_minus_1 =
......@@ -496,7 +495,7 @@ void Disassembler::VisitBitfield(Instruction* instr) {
}
void Disassembler::VisitExtract(Instruction* instr) {
void DisassemblingDecoder::VisitExtract(Instruction* instr) {
const char *mnemonic = "";
const char *form = "'Rd, 'Rn, 'Rm, 'IExtract";
......@@ -517,7 +516,7 @@ void Disassembler::VisitExtract(Instruction* instr) {
}
void Disassembler::VisitPCRelAddressing(Instruction* instr) {
void DisassemblingDecoder::VisitPCRelAddressing(Instruction* instr) {
switch (instr->Mask(PCRelAddressingMask)) {
case ADR: Format(instr, "adr", "'Xd, 'AddrPCRelByte"); break;
// ADRP is not implemented.
......@@ -526,7 +525,7 @@ void Disassembler::VisitPCRelAddressing(Instruction* instr) {
}
void Disassembler::VisitConditionalBranch(Instruction* instr) {
void DisassemblingDecoder::VisitConditionalBranch(Instruction* instr) {
switch (instr->Mask(ConditionalBranchMask)) {
case B_cond: Format(instr, "b.'CBrn", "'BImmCond"); break;
default: UNREACHABLE();
......@@ -534,7 +533,8 @@ void Disassembler::VisitConditionalBranch(Instruction* instr) {
}
void Disassembler::VisitUnconditionalBranchToRegister(Instruction* instr) {
void DisassemblingDecoder::VisitUnconditionalBranchToRegister(
Instruction* instr) {
const char *mnemonic = "unimplemented";
const char *form = "'Xn";
......@@ -554,7 +554,7 @@ void Disassembler::VisitUnconditionalBranchToRegister(Instruction* instr) {
}
void Disassembler::VisitUnconditionalBranch(Instruction* instr) {
void DisassemblingDecoder::VisitUnconditionalBranch(Instruction* instr) {
const char *mnemonic = "";
const char *form = "'BImmUncn";
......@@ -567,7 +567,7 @@ void Disassembler::VisitUnconditionalBranch(Instruction* instr) {
}
void Disassembler::VisitDataProcessing1Source(Instruction* instr) {
void DisassemblingDecoder::VisitDataProcessing1Source(Instruction* instr) {
const char *mnemonic = "";
const char *form = "'Rd, 'Rn";
......@@ -588,7 +588,7 @@ void Disassembler::VisitDataProcessing1Source(Instruction* instr) {
}
void Disassembler::VisitDataProcessing2Source(Instruction* instr) {
void DisassemblingDecoder::VisitDataProcessing2Source(Instruction* instr) {
const char *mnemonic = "unimplemented";
const char *form = "'Rd, 'Rn, 'Rm";
......@@ -609,7 +609,7 @@ void Disassembler::VisitDataProcessing2Source(Instruction* instr) {
}
void Disassembler::VisitDataProcessing3Source(Instruction* instr) {
void DisassemblingDecoder::VisitDataProcessing3Source(Instruction* instr) {
bool ra_is_zr = RaIsZROrSP(instr);
const char *mnemonic = "";
const char *form = "'Xd, 'Wn, 'Wm, 'Xa";
......@@ -687,7 +687,7 @@ void Disassembler::VisitDataProcessing3Source(Instruction* instr) {
}
void Disassembler::VisitCompareBranch(Instruction* instr) {
void DisassemblingDecoder::VisitCompareBranch(Instruction* instr) {
const char *mnemonic = "";
const char *form = "'Rt, 'BImmCmpa";
......@@ -702,7 +702,7 @@ void Disassembler::VisitCompareBranch(Instruction* instr) {
}
void Disassembler::VisitTestBranch(Instruction* instr) {
void DisassemblingDecoder::VisitTestBranch(Instruction* instr) {
const char *mnemonic = "";
// If the top bit of the immediate is clear, the tested register is
// disassembled as Wt, otherwise Xt. As the top bit of the immediate is
......@@ -719,7 +719,7 @@ void Disassembler::VisitTestBranch(Instruction* instr) {
}
void Disassembler::VisitMoveWideImmediate(Instruction* instr) {
void DisassemblingDecoder::VisitMoveWideImmediate(Instruction* instr) {
const char *mnemonic = "";
const char *form = "'Rd, 'IMoveImm";
......@@ -758,7 +758,7 @@ void Disassembler::VisitMoveWideImmediate(Instruction* instr) {
V(LDR_s, "ldr", "'St") \
V(LDR_d, "ldr", "'Dt")
void Disassembler::VisitLoadStorePreIndex(Instruction* instr) {
void DisassemblingDecoder::VisitLoadStorePreIndex(Instruction* instr) {
const char *mnemonic = "unimplemented";
const char *form = "(LoadStorePreIndex)";
......@@ -772,7 +772,7 @@ void Disassembler::VisitLoadStorePreIndex(Instruction* instr) {
}
void Disassembler::VisitLoadStorePostIndex(Instruction* instr) {
void DisassemblingDecoder::VisitLoadStorePostIndex(Instruction* instr) {
const char *mnemonic = "unimplemented";
const char *form = "(LoadStorePostIndex)";
......@@ -786,7 +786,7 @@ void Disassembler::VisitLoadStorePostIndex(Instruction* instr) {
}
void Disassembler::VisitLoadStoreUnsignedOffset(Instruction* instr) {
void DisassemblingDecoder::VisitLoadStoreUnsignedOffset(Instruction* instr) {
const char *mnemonic = "unimplemented";
const char *form = "(LoadStoreUnsignedOffset)";
......@@ -801,7 +801,7 @@ void Disassembler::VisitLoadStoreUnsignedOffset(Instruction* instr) {
}
void Disassembler::VisitLoadStoreRegisterOffset(Instruction* instr) {
void DisassemblingDecoder::VisitLoadStoreRegisterOffset(Instruction* instr) {
const char *mnemonic = "unimplemented";
const char *form = "(LoadStoreRegisterOffset)";
......@@ -816,7 +816,7 @@ void Disassembler::VisitLoadStoreRegisterOffset(Instruction* instr) {
}
void Disassembler::VisitLoadStoreUnscaledOffset(Instruction* instr) {
void DisassemblingDecoder::VisitLoadStoreUnscaledOffset(Instruction* instr) {
const char *mnemonic = "unimplemented";
const char *form = "'Wt, ['Xns'ILS]";
const char *form_x = "'Xt, ['Xns'ILS]";
......@@ -847,7 +847,7 @@ void Disassembler::VisitLoadStoreUnscaledOffset(Instruction* instr) {
}
void Disassembler::VisitLoadLiteral(Instruction* instr) {
void DisassemblingDecoder::VisitLoadLiteral(Instruction* instr) {
const char *mnemonic = "ldr";
const char *form = "(LoadLiteral)";
......@@ -873,7 +873,7 @@ void Disassembler::VisitLoadLiteral(Instruction* instr) {
V(STP_d, "stp", "'Dt, 'Dt2", "8") \
V(LDP_d, "ldp", "'Dt, 'Dt2", "8")
void Disassembler::VisitLoadStorePairPostIndex(Instruction* instr) {
void DisassemblingDecoder::VisitLoadStorePairPostIndex(Instruction* instr) {
const char *mnemonic = "unimplemented";
const char *form = "(LoadStorePairPostIndex)";
......@@ -887,7 +887,7 @@ void Disassembler::VisitLoadStorePairPostIndex(Instruction* instr) {
}
void Disassembler::VisitLoadStorePairPreIndex(Instruction* instr) {
void DisassemblingDecoder::VisitLoadStorePairPreIndex(Instruction* instr) {
const char *mnemonic = "unimplemented";
const char *form = "(LoadStorePairPreIndex)";
......@@ -901,7 +901,7 @@ void Disassembler::VisitLoadStorePairPreIndex(Instruction* instr) {
}
void Disassembler::VisitLoadStorePairOffset(Instruction* instr) {
void DisassemblingDecoder::VisitLoadStorePairOffset(Instruction* instr) {
const char *mnemonic = "unimplemented";
const char *form = "(LoadStorePairOffset)";
......@@ -915,7 +915,7 @@ void Disassembler::VisitLoadStorePairOffset(Instruction* instr) {
}
void Disassembler::VisitFPCompare(Instruction* instr) {
void DisassemblingDecoder::VisitFPCompare(Instruction* instr) {
const char *mnemonic = "unimplemented";
const char *form = "'Fn, 'Fm";
const char *form_zero = "'Fn, #0.0";
......@@ -931,7 +931,7 @@ void Disassembler::VisitFPCompare(Instruction* instr) {
}
void Disassembler::VisitFPConditionalCompare(Instruction* instr) {
void DisassemblingDecoder::VisitFPConditionalCompare(Instruction* instr) {
const char *mnemonic = "unimplemented";
const char *form = "'Fn, 'Fm, 'INzcv, 'Cond";
......@@ -946,7 +946,7 @@ void Disassembler::VisitFPConditionalCompare(Instruction* instr) {
}
void Disassembler::VisitFPConditionalSelect(Instruction* instr) {
void DisassemblingDecoder::VisitFPConditionalSelect(Instruction* instr) {
const char *mnemonic = "";
const char *form = "'Fd, 'Fn, 'Fm, 'Cond";
......@@ -959,7 +959,7 @@ void Disassembler::VisitFPConditionalSelect(Instruction* instr) {
}
void Disassembler::VisitFPDataProcessing1Source(Instruction* instr) {
void DisassemblingDecoder::VisitFPDataProcessing1Source(Instruction* instr) {
const char *mnemonic = "unimplemented";
const char *form = "'Fd, 'Fn";
......@@ -987,7 +987,7 @@ void Disassembler::VisitFPDataProcessing1Source(Instruction* instr) {
}
void Disassembler::VisitFPDataProcessing2Source(Instruction* instr) {
void DisassemblingDecoder::VisitFPDataProcessing2Source(Instruction* instr) {
const char *mnemonic = "";
const char *form = "'Fd, 'Fn, 'Fm";
......@@ -1011,7 +1011,7 @@ void Disassembler::VisitFPDataProcessing2Source(Instruction* instr) {
}
void Disassembler::VisitFPDataProcessing3Source(Instruction* instr) {
void DisassemblingDecoder::VisitFPDataProcessing3Source(Instruction* instr) {
const char *mnemonic = "";
const char *form = "'Fd, 'Fn, 'Fm, 'Fa";
......@@ -1030,7 +1030,7 @@ void Disassembler::VisitFPDataProcessing3Source(Instruction* instr) {
}
void Disassembler::VisitFPImmediate(Instruction* instr) {
void DisassemblingDecoder::VisitFPImmediate(Instruction* instr) {
const char *mnemonic = "";
const char *form = "(FPImmediate)";
......@@ -1043,7 +1043,7 @@ void Disassembler::VisitFPImmediate(Instruction* instr) {
}
void Disassembler::VisitFPIntegerConvert(Instruction* instr) {
void DisassemblingDecoder::VisitFPIntegerConvert(Instruction* instr) {
const char *mnemonic = "unimplemented";
const char *form = "(FPIntegerConvert)";
const char *form_rf = "'Rd, 'Fn";
......@@ -1099,7 +1099,7 @@ void Disassembler::VisitFPIntegerConvert(Instruction* instr) {
}
void Disassembler::VisitFPFixedPointConvert(Instruction* instr) {
void DisassemblingDecoder::VisitFPFixedPointConvert(Instruction* instr) {
const char *mnemonic = "";
const char *form = "'Rd, 'Fn, 'IFPFBits";
const char *form_fr = "'Fd, 'Rn, 'IFPFBits";
......@@ -1126,7 +1126,7 @@ void Disassembler::VisitFPFixedPointConvert(Instruction* instr) {
}
void Disassembler::VisitSystem(Instruction* instr) {
void DisassemblingDecoder::VisitSystem(Instruction* instr) {
// Some system instructions hijack their Op and Cp fields to represent a
// range of immediates instead of indicating a different instruction. This
// makes the decoding tricky.
......@@ -1187,7 +1187,7 @@ void Disassembler::VisitSystem(Instruction* instr) {
}
void Disassembler::VisitException(Instruction* instr) {
void DisassemblingDecoder::VisitException(Instruction* instr) {
const char *mnemonic = "unimplemented";
const char *form = "'IDebug";
......@@ -1206,23 +1206,23 @@ void Disassembler::VisitException(Instruction* instr) {
}
void Disassembler::VisitUnimplemented(Instruction* instr) {
void DisassemblingDecoder::VisitUnimplemented(Instruction* instr) {
Format(instr, "unimplemented", "(Unimplemented)");
}
void Disassembler::VisitUnallocated(Instruction* instr) {
void DisassemblingDecoder::VisitUnallocated(Instruction* instr) {
Format(instr, "unallocated", "(Unallocated)");
}
void Disassembler::ProcessOutput(Instruction* /*instr*/) {
void DisassemblingDecoder::ProcessOutput(Instruction* /*instr*/) {
// The base disasm does nothing more than disassembling into a buffer.
}
void Disassembler::Format(Instruction* instr, const char* mnemonic,
const char* format) {
void DisassemblingDecoder::Format(Instruction* instr, const char* mnemonic,
const char* format) {
// TODO(mcapewel) don't think I can use the instr address here - there needs
// to be a base address too
DCHECK(mnemonic != NULL);
......@@ -1237,7 +1237,7 @@ void Disassembler::Format(Instruction* instr, const char* mnemonic,
}
void Disassembler::Substitute(Instruction* instr, const char* string) {
void DisassemblingDecoder::Substitute(Instruction* instr, const char* string) {
char chr = *string++;
while (chr != '\0') {
if (chr == '\'') {
......@@ -1250,7 +1250,8 @@ void Disassembler::Substitute(Instruction* instr, const char* string) {
}
int Disassembler::SubstituteField(Instruction* instr, const char* format) {
int DisassemblingDecoder::SubstituteField(Instruction* instr,
const char* format) {
switch (format[0]) {
case 'R': // Register. X or W, selected by sf bit.
case 'F': // FP Register. S or D, selected by type field.
......@@ -1276,8 +1277,8 @@ int Disassembler::SubstituteField(Instruction* instr, const char* format) {
}
int Disassembler::SubstituteRegisterField(Instruction* instr,
const char* format) {
int DisassemblingDecoder::SubstituteRegisterField(Instruction* instr,
const char* format) {
unsigned reg_num = 0;
unsigned field_len = 2;
switch (format[1]) {
......@@ -1341,8 +1342,8 @@ int Disassembler::SubstituteRegisterField(Instruction* instr,
}
int Disassembler::SubstituteImmediateField(Instruction* instr,
const char* format) {
int DisassemblingDecoder::SubstituteImmediateField(Instruction* instr,
const char* format) {
DCHECK(format[0] == 'I');
switch (format[1]) {
......@@ -1452,8 +1453,8 @@ int Disassembler::SubstituteImmediateField(Instruction* instr,
}
int Disassembler::SubstituteBitfieldImmediateField(Instruction* instr,
const char* format) {
int DisassemblingDecoder::SubstituteBitfieldImmediateField(Instruction* instr,
const char* format) {
DCHECK((format[0] == 'I') && (format[1] == 'B'));
unsigned r = instr->ImmR();
unsigned s = instr->ImmS();
......@@ -1488,8 +1489,8 @@ int Disassembler::SubstituteBitfieldImmediateField(Instruction* instr,
}
int Disassembler::SubstituteLiteralField(Instruction* instr,
const char* format) {
int DisassemblingDecoder::SubstituteLiteralField(Instruction* instr,
const char* format) {
DCHECK(strncmp(format, "LValue", 6) == 0);
USE(format);
......@@ -1507,7 +1508,8 @@ int Disassembler::SubstituteLiteralField(Instruction* instr,
}
int Disassembler::SubstituteShiftField(Instruction* instr, const char* format) {
int DisassemblingDecoder::SubstituteShiftField(Instruction* instr,
const char* format) {
DCHECK(format[0] == 'H');
DCHECK(instr->ShiftDP() <= 0x3);
......@@ -1530,8 +1532,8 @@ int Disassembler::SubstituteShiftField(Instruction* instr, const char* format) {
}
int Disassembler::SubstituteConditionField(Instruction* instr,
const char* format) {
int DisassemblingDecoder::SubstituteConditionField(Instruction* instr,
const char* format) {
DCHECK(format[0] == 'C');
const char* condition_code[] = { "eq", "ne", "hs", "lo",
"mi", "pl", "vs", "vc",
......@@ -1551,8 +1553,8 @@ int Disassembler::SubstituteConditionField(Instruction* instr,
}
int Disassembler::SubstitutePCRelAddressField(Instruction* instr,
const char* format) {
int DisassemblingDecoder::SubstitutePCRelAddressField(Instruction* instr,
const char* format) {
USE(format);
DCHECK(strncmp(format, "AddrPCRel", 9) == 0);
......@@ -1572,8 +1574,8 @@ int Disassembler::SubstitutePCRelAddressField(Instruction* instr,
}
int Disassembler::SubstituteBranchTargetField(Instruction* instr,
const char* format) {
int DisassemblingDecoder::SubstituteBranchTargetField(Instruction* instr,
const char* format) {
DCHECK(strncmp(format, "BImm", 4) == 0);
int64_t offset = 0;
......@@ -1599,8 +1601,8 @@ int Disassembler::SubstituteBranchTargetField(Instruction* instr,
}
int Disassembler::SubstituteExtendField(Instruction* instr,
const char* format) {
int DisassemblingDecoder::SubstituteExtendField(Instruction* instr,
const char* format) {
DCHECK(strncmp(format, "Ext", 3) == 0);
DCHECK(instr->ExtendMode() <= 7);
USE(format);
......@@ -1626,8 +1628,8 @@ int Disassembler::SubstituteExtendField(Instruction* instr,
}
int Disassembler::SubstituteLSRegOffsetField(Instruction* instr,
const char* format) {
int DisassemblingDecoder::SubstituteLSRegOffsetField(Instruction* instr,
const char* format) {
DCHECK(strncmp(format, "Offsetreg", 9) == 0);
const char* extend_mode[] = { "undefined", "undefined", "uxtw", "lsl",
"undefined", "undefined", "sxtw", "sxtx" };
......@@ -1655,8 +1657,8 @@ int Disassembler::SubstituteLSRegOffsetField(Instruction* instr,
}
int Disassembler::SubstitutePrefetchField(Instruction* instr,
const char* format) {
int DisassemblingDecoder::SubstitutePrefetchField(Instruction* instr,
const char* format) {
DCHECK(format[0] == 'P');
USE(format);
......@@ -1670,8 +1672,8 @@ int Disassembler::SubstitutePrefetchField(Instruction* instr,
return 6;
}
int Disassembler::SubstituteBarrierField(Instruction* instr,
const char* format) {
int DisassemblingDecoder::SubstituteBarrierField(Instruction* instr,
const char* format) {
DCHECK(format[0] == 'M');
USE(format);
......@@ -1689,13 +1691,13 @@ int Disassembler::SubstituteBarrierField(Instruction* instr,
}
void Disassembler::ResetOutput() {
void DisassemblingDecoder::ResetOutput() {
buffer_pos_ = 0;
buffer_[buffer_pos_] = 0;
}
void Disassembler::AppendToOutput(const char* format, ...) {
void DisassemblingDecoder::AppendToOutput(const char* format, ...) {
va_list args;
va_start(args, format);
buffer_pos_ += vsnprintf(&buffer_[buffer_pos_], buffer_size_, format, args);
......@@ -1761,7 +1763,7 @@ const char* NameConverter::NameInCode(byte* addr) const {
//------------------------------------------------------------------------------
class BufferDisassembler : public v8::internal::Disassembler {
class BufferDisassembler : public v8::internal::DisassemblingDecoder {
public:
explicit BufferDisassembler(v8::internal::Vector<char> out_buffer)
: out_buffer_(out_buffer) { }
......
......@@ -14,11 +14,11 @@ namespace v8 {
namespace internal {
class Disassembler: public DecoderVisitor {
class DisassemblingDecoder : public DecoderVisitor {
public:
Disassembler();
Disassembler(char* text_buffer, int buffer_size);
virtual ~Disassembler();
DisassemblingDecoder();
DisassemblingDecoder(char* text_buffer, int buffer_size);
virtual ~DisassemblingDecoder();
char* GetOutput();
// Declare all Visitor functions.
......@@ -73,7 +73,7 @@ class Disassembler: public DecoderVisitor {
};
class PrintDisassembler: public Disassembler {
class PrintDisassembler : public DisassemblingDecoder {
public:
explicit PrintDisassembler(FILE* stream) : stream_(stream) { }
~PrintDisassembler() { }
......
......@@ -46,9 +46,11 @@
#include "src/counters.h"
#include "src/debug/debug.h"
#include "src/deoptimizer.h"
#include "src/disassembler.h"
#include "src/execution.h"
#include "src/ic/ic.h"
#include "src/ic/stub-cache.h"
#include "src/ostreams.h"
#include "src/profiler/cpu-profiler.h"
#include "src/regexp/jsregexp.h"
#include "src/regexp/regexp-macro-assembler.h"
......@@ -215,6 +217,12 @@ void AssemblerBase::FlushICacheWithoutIsolate(void* start, size_t size) {
}
void AssemblerBase::Print() {
OFStream os(stdout);
v8::internal::Disassembler::Decode(isolate(), &os, buffer_, pc_, nullptr);
}
// -----------------------------------------------------------------------------
// Implementation of PredictableCodeSizeScope
......
......@@ -100,6 +100,9 @@ class AssemblerBase: public Malloced {
// the assembler could clean up internal data structures.
virtual void AbortedCodeGeneration() { }
// Debugging
void Print();
static const int kMinimalBufferSize = 4*KB;
static void FlushICache(Isolate* isolate, void* start, size_t size);
......
......@@ -32,7 +32,9 @@ class V8NameConverter: public disasm::NameConverter {
const char* V8NameConverter::NameOfAddress(byte* pc) const {
const char* name = code_->GetIsolate()->builtins()->Lookup(pc);
const char* name =
code_ == NULL ? NULL : code_->GetIsolate()->builtins()->Lookup(pc);
if (name != NULL) {
SNPrintF(v8_buffer_, "%s (%p)", name, pc);
return v8_buffer_.start();
......
......@@ -1614,9 +1614,6 @@ class Assembler : public AssemblerBase {
void rorxl(Register dst, Register src, byte imm8);
void rorxl(Register dst, const Operand& src, byte imm8);
// Debugging
void Print();
// Check the code size generated from label to here.
int SizeOfCodeGeneratedSince(Label* label) {
return pc_offset() - label->pos();
......
......@@ -45,16 +45,16 @@ using namespace v8::internal;
#define EXP_SIZE (256)
#define INSTR_SIZE (1024)
#define SET_UP_CLASS(ASMCLASS) \
InitializeVM(); \
Isolate* isolate = Isolate::Current(); \
HandleScope scope(isolate); \
byte* buf = static_cast<byte*>(malloc(INSTR_SIZE)); \
uint32_t encoding = 0; \
ASMCLASS* assm = new ASMCLASS(isolate, buf, INSTR_SIZE); \
Decoder<DispatchingDecoderVisitor>* decoder = \
new Decoder<DispatchingDecoderVisitor>(); \
Disassembler* disasm = new Disassembler(); \
#define SET_UP_CLASS(ASMCLASS) \
InitializeVM(); \
Isolate* isolate = Isolate::Current(); \
HandleScope scope(isolate); \
byte* buf = static_cast<byte*>(malloc(INSTR_SIZE)); \
uint32_t encoding = 0; \
ASMCLASS* assm = new ASMCLASS(isolate, buf, INSTR_SIZE); \
Decoder<DispatchingDecoderVisitor>* decoder = \
new Decoder<DispatchingDecoderVisitor>(); \
DisassemblingDecoder* disasm = new DisassemblingDecoder(); \
decoder->AppendVisitor(disasm)
#define SET_UP() SET_UP_CLASS(Assembler)
......
......@@ -59,7 +59,7 @@ TEST(FUZZ_disasm) {
seed48(seed);
Decoder<DispatchingDecoderVisitor> decoder;
Disassembler disasm;
DisassemblingDecoder disasm;
Instruction buffer[kInstructionSize];
decoder.AppendVisitor(&disasm);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment