mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
Tweaked disassembler pretty printing, because I'm bored
This commit is contained in:
@@ -1,3 +1,13 @@
|
|||||||
|
fn f() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
fn g() {
|
||||||
|
fn i() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (var i: int = 0; i < 10; i++) print i;
|
fn h() {
|
||||||
|
//
|
||||||
|
}
|
||||||
@@ -320,7 +320,7 @@ static void dis_disassemble_section(dis_program_t **prg, uint32_t pc, uint32_t l
|
|||||||
uint16_t args = readWord((*prg)->program, &pc);
|
uint16_t args = readWord((*prg)->program, &pc);
|
||||||
uint16_t rets = readWord((*prg)->program, &pc);
|
uint16_t rets = readWord((*prg)->program, &pc);
|
||||||
SPC(spaces);
|
SPC(spaces);
|
||||||
printf("| ( args %d, rets %d )", args, rets);
|
printf("| ( args [%d], rets [%d] )", args, rets);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t pc_start = pc;
|
uint32_t pc_start = pc;
|
||||||
@@ -348,7 +348,7 @@ static void dis_read_interpreter_sections(dis_program_t **prg, uint32_t *pc, uin
|
|||||||
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
SPC(spaces);
|
SPC(spaces);
|
||||||
printf("| ( Reading %d literals )\n", literalCount);
|
printf("| --- ( Reading %d literals from cache ) ---\n", literalCount);
|
||||||
|
|
||||||
for (int i = 0; i < literalCount; i++) {
|
for (int i = 0; i < literalCount; i++) {
|
||||||
const unsigned char literalType = readByte((*prg)->program, pc);
|
const unsigned char literalType = readByte((*prg)->program, pc);
|
||||||
@@ -481,16 +481,16 @@ static void dis_read_interpreter_sections(dis_program_t **prg, uint32_t *pc, uin
|
|||||||
consumeByte(DIS_OP_SECTION_END, (*prg)->program, pc);
|
consumeByte(DIS_OP_SECTION_END, (*prg)->program, pc);
|
||||||
|
|
||||||
SPC(spaces);
|
SPC(spaces);
|
||||||
printf("| ( end literals )\n");
|
printf("| --- ( end literal section ) ---\n");
|
||||||
|
|
||||||
int functionCount = readWord((*prg)->program, pc);
|
int functionCount = readWord((*prg)->program, pc);
|
||||||
int functionSize = readWord((*prg)->program, pc);
|
int functionSize = readWord((*prg)->program, pc);
|
||||||
|
|
||||||
if (functionCount) {
|
if (functionCount) {
|
||||||
SPC(spaces);
|
SPC(spaces);
|
||||||
printf("| | \n");
|
printf("|\n");
|
||||||
SPC(spaces);
|
SPC(spaces);
|
||||||
printf("| | ( fun count: %d, total size: %d )\n", functionCount, functionSize);
|
printf("| --- ( fn count: %d, total size: %d ) ---\n", functionCount, functionSize);
|
||||||
|
|
||||||
uint32_t fcnt = 0;
|
uint32_t fcnt = 0;
|
||||||
char tree_local[2048];
|
char tree_local[2048];
|
||||||
@@ -507,9 +507,9 @@ static void dis_read_interpreter_sections(dis_program_t **prg, uint32_t *pc, uin
|
|||||||
if (tree_local[0] == '.')
|
if (tree_local[0] == '.')
|
||||||
memcpy(tree_local, tree_local + 1, strlen(tree_local));
|
memcpy(tree_local, tree_local + 1, strlen(tree_local));
|
||||||
SPC(spaces);
|
SPC(spaces);
|
||||||
printf("| | |\n");
|
printf("| |\n");
|
||||||
SPC(spaces);
|
SPC(spaces);
|
||||||
printf("| | | ( fun %s [ start: %d, end: %d ] )", tree_local, fpc_start, fpc_end);
|
printf("| | ( fun %s [ start: %d, end: %d ] )", tree_local, fpc_start, fpc_end);
|
||||||
if ((*prg)->program[*pc + size - 1] != DIS_OP_FN_END) {
|
if ((*prg)->program[*pc + size - 1] != DIS_OP_FN_END) {
|
||||||
printf("\nERROR: Failed to find function end\n");
|
printf("\nERROR: Failed to find function end\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
@@ -520,16 +520,22 @@ static void dis_read_interpreter_sections(dis_program_t **prg, uint32_t *pc, uin
|
|||||||
printf("| | |\n");
|
printf("| | |\n");
|
||||||
|
|
||||||
SPC(spaces + 4);
|
SPC(spaces + 4);
|
||||||
printf("| ------ ( code ) ------");
|
printf("| --- ( reading code for %s ) ---", tree_local);
|
||||||
dis_disassemble_section(prg, fpc_start, fpc_end, spaces + 4, true);
|
dis_disassemble_section(prg, fpc_start, fpc_end, spaces + 4, true);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
SPC(spaces + 4);
|
SPC(spaces + 4);
|
||||||
printf("| ---- ( end code ) ----\n");
|
printf("| --- ( end code section ) ---\n");
|
||||||
|
|
||||||
fcnt++;
|
fcnt++;
|
||||||
*pc += size;
|
*pc += size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SPC(spaces);
|
||||||
|
printf("|\n");
|
||||||
|
SPC(spaces);
|
||||||
|
printf("| --- ( end fn section ) ---\n");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
consumeByte(DIS_OP_SECTION_END, (*prg)->program, pc);
|
consumeByte(DIS_OP_SECTION_END, (*prg)->program, pc);
|
||||||
@@ -548,13 +554,11 @@ void disassemble(const char *filename) {
|
|||||||
|
|
||||||
consumeByte(DIS_OP_SECTION_END, prg->program, &(prg->pc));
|
consumeByte(DIS_OP_SECTION_END, prg->program, &(prg->pc));
|
||||||
|
|
||||||
printf("\n| ---- ( literals ) ----");
|
|
||||||
dis_read_interpreter_sections(&prg, &(prg->pc), 0, "");
|
dis_read_interpreter_sections(&prg, &(prg->pc), 0, "");
|
||||||
printf("| -- ( end literals) --\n|");
|
|
||||||
|
|
||||||
printf("\n| ---- ( main code ) ----");
|
printf("|\n| --- ( reading main code ) ---");
|
||||||
dis_disassemble_section(&prg, prg->pc, prg->len, 0, false);
|
dis_disassemble_section(&prg, prg->pc, prg->len, 0, false);
|
||||||
printf("\n| -- ( end main code ) --");
|
printf("\n| --- ( end main code section ) ---");
|
||||||
|
|
||||||
printf("\n\n");
|
printf("\n\n");
|
||||||
dis_disassembler_deinit(&prg);
|
dis_disassembler_deinit(&prg);
|
||||||
|
|||||||
Reference in New Issue
Block a user