Merge pull request #81 from Saruta/master

Add comparison argument to disassembly output
This commit is contained in:
Michael Hansen
2016-07-13 20:52:25 -07:00
committed by GitHub
2 changed files with 15 additions and 0 deletions

View File

@@ -167,6 +167,10 @@ bool Pyc::IsJumpOffsetArg(int opcode)
(opcode == Pyc::FOR_LOOP_A);
}
bool Pyc::IsCompareArg(int opcode)
{
return (opcode == Pyc::COMPARE_OP_A);
}
void print_const(PycRef<PycObject> obj, PycModule* mod)
{
@@ -324,6 +328,10 @@ void bc_next(PycBuffer& source, PycModule* mod, int& opcode, int& operand, int&
void bc_disasm(PycRef<PycCode> code, PycModule* mod, int indent)
{
static const char *cmp_strings[] = {
"<", "<=", "==", "!=", ">", ">=", "in", "not in", "is", "is not",
"<EXCEPTION MATCH>", "<BAD>"
};
PycBuffer source(code->code()->value(), code->code()->length());
int opcode, operand;
@@ -349,6 +357,12 @@ void bc_disasm(PycRef<PycCode> code, PycModule* mod, int indent)
print_const(code->getCellVar(operand), mod);
} else if (Pyc::IsJumpOffsetArg(opcode)) {
fprintf(pyc_output, "%d (to %d)", operand, pos+operand);
} else if (Pyc::IsCompareArg(opcode)) {
ssize_t cmp_strings_len = sizeof(cmp_strings) / sizeof(cmp_strings[0]);
if (operand < cmp_strings_len)
fprintf(pyc_output, "%d: '%s'", operand, cmp_strings[operand]);
else
fprintf(pyc_output, "%d", operand);
} else {
fprintf(pyc_output, "%d", operand);
}

View File

@@ -60,6 +60,7 @@ bool IsNameArg(int opcode);
bool IsVarNameArg(int opcode);
bool IsCellArg(int opcode);
bool IsJumpOffsetArg(int opcode);
bool IsCompareArg(int opcode);
}