diff options
author | Oxore <oxore@protonmail.com> | 2023-05-22 21:11:50 +0300 |
---|---|---|
committer | Oxore <oxore@protonmail.com> | 2023-05-22 21:11:50 +0300 |
commit | cdabbbcfa0717b2253f79e04eb6ac14996cf9dca (patch) | |
tree | eeabbf96c41bbd23755ee13b3449690d194b5c5e | |
parent | e40ee76cdae5d85ef9f997d766956bbe179a1fc3 (diff) |
Impl --indent option in some way, use tab by default
-rw-r--r-- | common.h | 1 | ||||
-rw-r--r-- | disasm.cpp | 7 | ||||
-rw-r--r-- | disasm.h | 1 | ||||
-rw-r--r-- | main.cpp | 15 |
4 files changed, 17 insertions, 7 deletions
@@ -11,6 +11,7 @@ struct Settings { bool xrefs_to{}; bool xrefs_from{}; bool raw_data_comment{}; + const char *indent{"\t"}; }; using RefKindMask = unsigned; @@ -1930,6 +1930,7 @@ int Arg::SNPrint( int Op::FPrint( FILE *const stream, + const char *const indent, const RefKindMask ref_kinds, const uint32_t self_addr, const uint32_t ref1_addr, @@ -1954,12 +1955,12 @@ int Op::FPrint( char arg2_str[kArgsBufferSize]{}; const RefKindMask ref2_kinds = ref_kinds & (kRef2Mask | kRefPcRelFix2Bytes); arg2.SNPrint(arg2_str, kArgsBufferSize, false, ref2_kinds, self_addr, ref2_addr); - return fprintf(stream, " %s %s,%s", mnemonic_str, arg1_str, arg2_str); + return fprintf(stream, "%s%s %s,%s", indent, mnemonic_str, arg1_str, arg2_str); } else { - return fprintf(stream, " %s %s", mnemonic_str, arg1_str); + return fprintf(stream, "%s%s %s", indent, mnemonic_str, arg1_str); } } else { - return fprintf(stream, " %s", mnemonic_str); + return fprintf(stream, "%s%s", indent, mnemonic_str); } } @@ -353,6 +353,7 @@ struct Op { } int FPrint( FILE *, + const char *indent, RefKindMask ref_kinds = 0, uint32_t self_addr = 0, uint32_t ref1_addr = 0, @@ -274,7 +274,7 @@ static void RenderDisassembly( assert(node->op.opcode != OpCode::kNone); if (ShouldPrintAsRaw(node->op)) { auto raw = Op::Raw(GetU16BE(code.buffer + node->offset)); - raw.FPrint(output); + raw.FPrint(output, s.indent); uint32_t i = kInstructionSizeStepBytes; for (; i < node->size; i += kInstructionSizeStepBytes) { char arg_str[kArgsBufferSize]{}; @@ -303,7 +303,7 @@ static void RenderDisassembly( : 0) | ((s.imm_marks && ref1) ? (node->ref_kinds & kRef1ImmMask) : 0) | (node->ref_kinds & (kRefDataMask | kRefPcRelFix2Bytes)); - node->op.FPrint(output, ref_kinds, node->offset, ref1_addr, ref2_addr); + node->op.FPrint(output, s.indent, ref_kinds, node->offset, ref1_addr, ref2_addr); if (s.xrefs_to && ref1) { char ref_addr_str[12]{}; snprintf(ref_addr_str, sizeof(ref_addr_str), ".L%08x", ref1_addr); @@ -315,7 +315,7 @@ static void RenderDisassembly( fprintf(output, " | %s", ref_addr_str); } } else { - node->op.FPrint(output); + node->op.FPrint(output, s.indent); } } if (s.raw_data_comment) { @@ -326,7 +326,9 @@ static void RenderDisassembly( fprintf(output, "\n"); i += node->size; } else { - fprintf(output, " .short 0x%02x%02x\n", code.buffer[i], code.buffer[i + 1]); + auto raw = Op::Raw(GetU16BE(code.buffer + i)); + raw.FPrint(output, s.indent); + fprintf(output, "\n"); i += kInstructionSizeStepBytes; } } @@ -511,6 +513,7 @@ static void PrintUsage(FILE *s, const char *argv0) fprintf(s, " -h, --help, Show this message\n"); fprintf(s, " -o, --output, Where to write disassembly to (stdout if not set)\n"); fprintf(s, " -t, --pc-trace, File containing PC trace\n"); + fprintf(s, " --indent, Specify instruction indentation, e.g. \"\t\"\n"); fprintf(s, " -f, --feature=[no-]<feature>\n"); fprintf(s, " Enable or disable (with \"no-\" prefix) a feature\n"); fprintf(s, " Available features:\n"); @@ -537,6 +540,7 @@ int main(int, char* argv[]) {"output", 'o', OPTPARSE_REQUIRED}, {"pc-trace", 't', OPTPARSE_REQUIRED}, {"feature", 'f', OPTPARSE_OPTIONAL}, + {"indent", 80, OPTPARSE_REQUIRED}, {}, }; const char *trace_file_name = nullptr; @@ -566,6 +570,9 @@ int main(int, char* argv[]) } ApplyFeature(s, options.optarg); break; + case 80: + s.indent = options.optarg; + break; case '?': fprintf(stderr, "main: optparse_long: Error: \"%s\"\n", options.errmsg); return EXIT_FAILURE; |