Correct literal format

This commit is contained in:
hiperiondev
2023-08-22 19:31:06 -03:00
parent 6b8e95d250
commit 52048f2466

View File

@@ -73,7 +73,7 @@ const char *OP_STR[] = {
EP(DIS_OP_POP_STACK), // EP(DIS_OP_POP_STACK), //
EP(DIS_OP_TERNARY), // EP(DIS_OP_TERNARY), //
EP(DIS_OP_FN_END), // EP(DIS_OP_FN_END), //
}; };
const char *LIT_STR[] = { const char *LIT_STR[] = {
EP(DIS_LITERAL_NULL), // EP(DIS_LITERAL_NULL), //
@@ -96,7 +96,7 @@ const char *LIT_STR[] = {
EP(DIS_LITERAL_FUNCTION_NATIVE), // EP(DIS_LITERAL_FUNCTION_NATIVE), //
EP(DIS_LITERAL_FUNCTION_HOOK), // EP(DIS_LITERAL_FUNCTION_HOOK), //
EP(DIS_LITERAL_INDEX_BLANK), // EP(DIS_LITERAL_INDEX_BLANK), //
}; };
enum DIS_ARG_TYPE { enum DIS_ARG_TYPE {
DIS_ARG_NONE, // DIS_ARG_NONE, //
@@ -169,9 +169,9 @@ typedef struct dis_program_s {
} dis_program_t; } dis_program_t;
typedef struct fun_code_s { typedef struct fun_code_s {
uint32_t start; uint32_t start;
uint32_t len; uint32_t len;
char *fun; char *fun;
} fun_code_t; } fun_code_t;
static void dis_print_opcode(uint8_t op); static void dis_print_opcode(uint8_t op);
@@ -231,7 +231,7 @@ static void dis_disassembler_deinit(dis_program_t **prg) {
free((*prg)); free((*prg));
} }
static uint8_t dis_load_file(const char *filename, dis_program_t **prg) { static uint8_t dis_load_file(const char *filename, dis_program_t **prg, bool alt_fmt) {
FILE *f; FILE *f;
size_t fsize, bytes; size_t fsize, bytes;
uint32_t count = 0; uint32_t count = 0;
@@ -252,18 +252,26 @@ static uint8_t dis_load_file(const char *filename, dis_program_t **prg) {
(*prg)->program[count++] = buf; (*prg)->program[count++] = buf;
(*prg)->len = fsize; (*prg)->len = fsize;
printf("\nFile: %s\nSize: %zu\n", filename, fsize);
if (!alt_fmt)
printf("\nFile: %s\nSize: %zu\n", filename, fsize);
else
printf("\n.comment File: %s, Size: %zu\n", filename, fsize);
fclose(f); fclose(f);
return 0; return 0;
} }
static void dis_read_header(dis_program_t **prg) { static void dis_read_header(dis_program_t **prg, bool alt_fmt) {
const unsigned char major = readByte((*prg)->program, &((*prg)->pc)); const unsigned char major = readByte((*prg)->program, &((*prg)->pc));
const unsigned char minor = readByte((*prg)->program, &((*prg)->pc)); const unsigned char minor = readByte((*prg)->program, &((*prg)->pc));
const unsigned char patch = readByte((*prg)->program, &((*prg)->pc)); const unsigned char patch = readByte((*prg)->program, &((*prg)->pc));
const char *build = readString((*prg)->program, &((*prg)->pc)); const char *build = readString((*prg)->program, &((*prg)->pc));
printf("[Header Version: %d.%d.%d (%s)]\n", major, minor, patch, build);
if (!alt_fmt)
printf("[Header Version: %d.%d.%d (%s)]\n", major, minor, patch, build);
else
printf(".comment Header Version: %d.%d.%d (%s)\n", major, minor, patch, build);
} }
static void dis_print_opcode(uint8_t op) { static void dis_print_opcode(uint8_t op) {
@@ -309,399 +317,435 @@ static void dis_print_opcode(uint8_t op) {
exit(1); \ exit(1); \
} }
static void dis_disassemble_section(dis_program_t **prg, uint32_t pc, static void dis_disassemble_section(dis_program_t **prg, uint32_t pc, uint32_t len, uint8_t spaces, bool is_function, bool alt_fmt) {
uint32_t len, uint8_t spaces, bool is_function, bool alt_fmt) { uint8_t opcode;
uint8_t opcode; uint32_t uint;
uint32_t uint; int32_t intg;
int32_t intg; float flt;
float flt; char *str;
char *str;
//first 4 bytes of the program section within a function are actually specifying the parameter and return lists //first 4 bytes of the program section within a function are actually specifying the parameter and return lists
if (is_function) { if (is_function) {
printf("\n"); printf("\n");
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);
if (!alt_fmt) { if (!alt_fmt) {
SPC(spaces); SPC(spaces);
printf("| "); printf("| ");
} else } else
printf(" .comment args [%d], rets [%d]", args, rets); printf(" .comment args [%d], rets [%d]", args, rets);
} }
uint32_t pc_start = pc; uint32_t pc_start = pc;
while (pc < len) { while (pc < len) {
opcode = (*prg)->program[pc]; opcode = (*prg)->program[pc];
if (alt_fmt && (opcode == 255 || opcode == 0)) { if (alt_fmt && (opcode == 255 || opcode == 0)) {
++pc; ++pc;
continue; continue;
} }
printf("\n"); printf("\n");
if (!alt_fmt) { if (!alt_fmt) {
SPC(spaces); SPC(spaces);
printf("| "); printf("| ");
} else printf("[%05d](%03d) ", (pc++) - pc_start, opcode);
printf(" "); } else {
printf(" ");
printf("[%05d] ", (pc++) - pc_start);
}
printf("[%05d](%03d) ", (pc++) - pc_start, opcode); dis_print_opcode(opcode);
dis_print_opcode(opcode);
if (opcode > DIS_OP_END_OPCODES) if (opcode > DIS_OP_END_OPCODES)
continue; continue;
S_OP(0); S_OP(0);
S_OP(1); S_OP(1);
} }
} }
#define LIT_ADD(a, b, c) b[c] = a; ++c; #define LIT_ADD(a, b, c) b[c] = a; ++c;
static void dis_read_interpreter_sections(dis_program_t **prg, uint32_t *pc, static void dis_read_interpreter_sections(dis_program_t **prg, uint32_t *pc, uint8_t spaces, char *tree, bool alt_fmt) {
uint8_t spaces, char *tree, bool alt_fmt) { uint32_t literal_count = 0;
uint32_t literal_count = 0; uint8_t literal_type[65536];
uint8_t literal_type[65536];
const unsigned short literalCount = readWord((*prg)->program, pc); const unsigned short literalCount = readWord((*prg)->program, pc);
printf("\n"); printf("\n");
if (!alt_fmt) { if (!alt_fmt) {
SPC(spaces); SPC(spaces);
printf("| "); printf("| ");
printf(" "); printf(" ");
printf("--- ( Reading %d literals from cache ) ---\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);
switch (literalType) { switch (literalType) {
case DIS_LITERAL_NULL: case DIS_LITERAL_NULL:
LIT_ADD(DIS_LITERAL_NULL, literal_type, literal_count) ; LIT_ADD(DIS_LITERAL_NULL, literal_type, literal_count);
if (!alt_fmt) { if (!alt_fmt) {
SPC(spaces); SPC(spaces);
printf("| | "); printf("| | ");
} else printf("[%05d] ( null )\n", i);
printf(" "); } else {
printf("[%05d] ( null )\n", i); printf(" ");
break; printf(".lit NULL\n");
}
case DIS_LITERAL_BOOLEAN: { break;
const bool b = readByte((*prg)->program, pc);
LIT_ADD(DIS_LITERAL_BOOLEAN, literal_type, literal_count);
if (!alt_fmt) {
SPC(spaces);
printf("| | ");
} else
printf(" ");
printf("[%05d] ( boolean %s )\n", i, b ? "true" : "false");
}
break;
case DIS_LITERAL_INTEGER: { case DIS_LITERAL_BOOLEAN: {
const int d = readInt((*prg)->program, pc); const bool b = readByte((*prg)->program, pc);
LIT_ADD(DIS_LITERAL_INTEGER, literal_type, literal_count); LIT_ADD(DIS_LITERAL_BOOLEAN, literal_type, literal_count);
if (!alt_fmt) { if (!alt_fmt) {
SPC(spaces); SPC(spaces);
printf("| | "); printf("| | ");
} else printf("[%05d] ( boolean %s )\n", i, b ? "true" : "false");
printf(" "); } else {
printf("[%05d] ( integer %d )\n", i, d); printf(" ");
} printf(".lit BOOLEAN %s\n", b ? "true" : "false");
break; }
}
break;
case DIS_LITERAL_FLOAT: { case DIS_LITERAL_INTEGER: {
const float f = readFloat((*prg)->program, pc); const int d = readInt((*prg)->program, pc);
LIT_ADD(DIS_LITERAL_FLOAT, literal_type, literal_count); LIT_ADD(DIS_LITERAL_INTEGER, literal_type, literal_count);
if (!alt_fmt) { if (!alt_fmt) {
SPC(spaces); SPC(spaces);
printf("| | "); printf("| | ");
} else printf("[%05d] ( integer %d )\n", i, d);
printf(" "); } else {
printf("[%05d] ( float %f )\n", i, f); printf(" ");
} printf(".lit INTEGER %d\n", d);
break; }
}
break;
case DIS_LITERAL_STRING: { case DIS_LITERAL_FLOAT: {
const char *s = readString((*prg)->program, pc); const float f = readFloat((*prg)->program, pc);
LIT_ADD(DIS_LITERAL_STRING, literal_type, literal_count); LIT_ADD(DIS_LITERAL_FLOAT, literal_type, literal_count);
if (!alt_fmt) { if (!alt_fmt) {
SPC(spaces); SPC(spaces);
printf("| | "); printf("| | ");
} else printf("[%05d] ( float %f )\n", i, f);
printf(" "); } else {
printf("[%05d] ( string \"%s\" )\n", i, s); printf(" ");
} printf(".lit FLOAT %f\n", f);
break; }
}
break;
case DIS_LITERAL_ARRAY_INTERMEDIATE: case DIS_LITERAL_STRING: {
case DIS_LITERAL_ARRAY: { const char *s = readString((*prg)->program, pc);
unsigned short length = readWord((*prg)->program, pc); LIT_ADD(DIS_LITERAL_STRING, literal_type, literal_count);
if (!alt_fmt) { if (!alt_fmt) {
SPC(spaces); SPC(spaces);
printf("| | "); printf("| | ");
} else printf("[%05d] ( string \"%s\" )\n", i, s);
printf(" "); } else {
printf("[%05d] ( array ", i); printf(" ");
for (int i = 0; i < length; i++) { printf(".lit STRING \"%s\"\n", s);
int index = readWord((*prg)->program, pc); }
printf("%d ", index); }
LIT_ADD(DIS_LITERAL_NULL, literal_type, literal_count); break;
if (!(i % 15) && i != 0) {
printf("\n");
if (!alt_fmt) {
SPC(spaces);
printf("| | ");
} else
printf(" ");
printf(" ");
}
}
printf(")\n");
LIT_ADD(DIS_LITERAL_ARRAY, literal_type, literal_count);
}
break;
case DIS_LITERAL_DICTIONARY_INTERMEDIATE: case DIS_LITERAL_ARRAY_INTERMEDIATE:
case DIS_LITERAL_DICTIONARY: { case DIS_LITERAL_ARRAY: {
unsigned short length = readWord((*prg)->program, pc); unsigned short length = readWord((*prg)->program, pc);
if (!alt_fmt) { if (!alt_fmt) {
SPC(spaces); SPC(spaces);
printf("| | "); printf("| | ");
} else printf("[%05d] ( array ", i);
printf(" "); } else {
printf("[%05d] ( dictionary ", i); printf(" ");
for (int i = 0; i < length / 2; i++) { printf(".lit ARRAY ");
int key = readWord((*prg)->program, pc); }
int val = readWord((*prg)->program, pc);
printf("(key: %d, val:%d) ", key, val);
if (!(i % 5) && i != 0) {
printf("\n");
if (!alt_fmt) {
SPC(spaces);
printf("| | ");
} else
printf(" ");
printf(" ");
}
}
printf(")\n");
LIT_ADD(DIS_LITERAL_DICTIONARY, literal_type, literal_count);
}
break;
case DIS_LITERAL_FUNCTION: { for (int i = 0; i < length; i++) {
unsigned short index = readWord((*prg)->program, pc); int index = readWord((*prg)->program, pc);
LIT_ADD(DIS_LITERAL_FUNCTION_INTERMEDIATE, literal_type, printf("%d ", index);
literal_count); LIT_ADD(DIS_LITERAL_NULL, literal_type, literal_count);
if (!alt_fmt) { if (!(i % 15) && i != 0) {
SPC(spaces); printf("\n");
printf("| | "); if (!alt_fmt) {
} else SPC(spaces);
printf(" "); printf("| | ");
printf("[%05d] ( function index: %d )\n", i, index); } else
} printf(" ");
break; printf(" ");
}
}
if (!alt_fmt)
printf(")");
printf("\n");
case DIS_LITERAL_IDENTIFIER: { LIT_ADD(DIS_LITERAL_ARRAY, literal_type, literal_count);
const char *str = readString((*prg)->program, pc); }
LIT_ADD(DIS_LITERAL_IDENTIFIER, literal_type, literal_count); break;
if (!alt_fmt) {
SPC(spaces);
printf("| | ");
} else
printf(" ");
printf("[%05d] ( identifier %s )\n", i, str);
}
break;
case DIS_LITERAL_TYPE: case DIS_LITERAL_DICTIONARY_INTERMEDIATE:
case DIS_LITERAL_TYPE_INTERMEDIATE: { case DIS_LITERAL_DICTIONARY: {
uint8_t literalType = readByte((*prg)->program, pc); unsigned short length = readWord((*prg)->program, pc);
uint8_t constant = readByte((*prg)->program, pc); if (!alt_fmt) {
if (!alt_fmt) { SPC(spaces);
SPC(spaces); printf("| | ");
printf("| | "); printf("[%05d] ( dictionary ", i);
} else } else {
printf(" "); printf(" ");
printf("[%05d] ( type %s: %d)\n", i, (LIT_STR[literalType] + 12), printf(".lit DICTIONARY ");
constant); }
if (literalType == DIS_LITERAL_ARRAY) { for (int i = 0; i < length / 2; i++) {
uint16_t vt = readWord((*prg)->program, pc); int key = readWord((*prg)->program, pc);
if (!alt_fmt) { int val = readWord((*prg)->program, pc);
SPC(spaces);
printf("| | ");
} else
printf(" ");
printf(" ( subtype: %d)\n", vt);
}
if (literalType == DIS_LITERAL_DICTIONARY) { if (!alt_fmt)
uint8_t kt = readWord((*prg)->program, pc); printf("(key: %d, val:%d) ", key, val);
uint8_t vt = readWord((*prg)->program, pc); else
if (!alt_fmt) { printf("%d,%d ", key, val);
SPC(spaces);
printf("| | ");
} else
printf(" ");
printf(" ( subtype: [%d, %d] )\n", kt, vt);
}
LIT_ADD(literalType, literal_type, literal_count);
}
break;
case DIS_LITERAL_INDEX_BLANK: if (!(i % 5) && i != 0) {
LIT_ADD(DIS_LITERAL_INDEX_BLANK, literal_type, literal_count); printf("\n");
if (!alt_fmt) { if (!alt_fmt) {
SPC(spaces); SPC(spaces);
printf("| | "); printf("| | ");
} else } else
printf(" "); printf(" ");
printf("[%05d] ( blank )\n", i); printf(" ");
break; }
} }
} if (!alt_fmt)
printf(")");
printf("\n");
LIT_ADD(DIS_LITERAL_DICTIONARY, literal_type, literal_count);
}
break;
consumeByte(DIS_OP_SECTION_END, (*prg)->program, pc); case DIS_LITERAL_FUNCTION: {
unsigned short index = readWord((*prg)->program, pc);
LIT_ADD(DIS_LITERAL_FUNCTION_INTERMEDIATE, literal_type, literal_count);
if (!alt_fmt) {
SPC(spaces);
printf("| | ");
printf("[%05d] ( function index: %d )\n", i, index);
} else {
printf(" ");
printf(".lit FUNCTION %d\n", index);
}
}
break;
if (!alt_fmt) { case DIS_LITERAL_IDENTIFIER: {
SPC(spaces); const char *str = readString((*prg)->program, pc);
printf("| "); LIT_ADD(DIS_LITERAL_IDENTIFIER, literal_type, literal_count);
printf("--- ( end literal section ) ---\n"); if (!alt_fmt) {
} SPC(spaces);
printf("| | ");
printf("[%05d] ( identifier %s )\n", i, str);
} else {
printf(" ");
printf(".lit IDENTIFIER %s\n", str);
}
}
break;
case DIS_LITERAL_TYPE:
case DIS_LITERAL_TYPE_INTERMEDIATE: {
uint8_t literalType = readByte((*prg)->program, pc);
uint8_t constant = readByte((*prg)->program, pc);
if (!alt_fmt) {
SPC(spaces);
printf("| | ");
printf("[%05d] ( type %s: %d)\n", i, (LIT_STR[literalType] + 12), constant);
} else {
printf(" ");
printf(".lit TYPE %s %d", (LIT_STR[literalType] + 12), constant);
}
int functionCount = readWord((*prg)->program, pc); if (literalType == DIS_LITERAL_ARRAY) {
int functionSize = readWord((*prg)->program, pc); uint16_t vt = readWord((*prg)->program, pc);
if (!alt_fmt) {
SPC(spaces);
printf("| | ");
printf("\n ( subtype: %d)", vt);
} else {
printf(" ");
printf(" SUBTYPE %d", vt);
}
}
printf("\n");
if (functionCount) { if (literalType == DIS_LITERAL_DICTIONARY) {
if (!alt_fmt) { uint8_t kt = readWord((*prg)->program, pc);
SPC(spaces); uint8_t vt = readWord((*prg)->program, pc);
printf("|\n"); if (!alt_fmt) {
SPC(spaces); SPC(spaces);
printf("| "); printf("| | ");
printf("--- ( fn count: %d, total size: %d ) ---\n", functionCount, functionSize); printf("\n ( subtype: [%d, %d] )", kt, vt);
} } else {
printf(" ");
printf(" SUBTYPE %d, %d", kt, vt);
}
}
printf("\n");
LIT_ADD(literalType, literal_type, literal_count);
}
break;
uint32_t fcnt = 0; case DIS_LITERAL_INDEX_BLANK:
char tree_local[2048]; LIT_ADD(DIS_LITERAL_INDEX_BLANK, literal_type, literal_count);
if (!alt_fmt) {
SPC(spaces);
printf("| | ");
printf("[%05d] ( blank )\n", i);
} else {
printf(" ");
printf(".lit BLANK\n");
}
break;
}
}
for (uint32_t i = 0; i < literal_count; i++) { consumeByte(DIS_OP_SECTION_END, (*prg)->program, pc);
if (literal_type[i] == DIS_LITERAL_FUNCTION_INTERMEDIATE) {
size_t size = (size_t) readWord((*prg)->program, pc);
uint32_t fpc_start = *pc; if (!alt_fmt) {
uint32_t fpc_end = *pc + size - 1; SPC(spaces);
printf("| ");
printf("--- ( end literal section ) ---\n");
}
tree_local[0] = '\0'; int functionCount = readWord((*prg)->program, pc);
if (!alt_fmt) { int functionSize = readWord((*prg)->program, pc);
sprintf(tree_local, "%s.%d", tree, fcnt);
if (tree_local[0] == '_')
memcpy(tree_local, tree_local + 1, strlen(tree_local));
} else {
sprintf(tree_local, "%s_%d", tree, fcnt);
if (tree_local[0] == '_')
memcpy(tree_local, tree_local + 1, strlen(tree_local));
}
if (!alt_fmt) { if (functionCount) {
SPC(spaces); if (!alt_fmt) {
printf("| |\n"); SPC(spaces);
SPC(spaces); printf("|\n");
printf("| | "); SPC(spaces);
printf("( fun %s [ start: %d, end: %d ] )", tree_local, fpc_start, fpc_end); printf("| ");
} else printf("--- ( fn count: %d, total size: %d ) ---\n", functionCount, functionSize);
printf("\nLIT_FUN_%s:", tree_local); }
uint32_t fcnt = 0;
char tree_local[2048];
for (uint32_t i = 0; i < literal_count; i++) {
if (literal_type[i] == DIS_LITERAL_FUNCTION_INTERMEDIATE) {
size_t size = (size_t) readWord((*prg)->program, pc);
if ((*prg)->program[*pc + size - 1] != DIS_OP_FN_END) { uint32_t fpc_start = *pc;
printf("\nERROR: Failed to find function end\n"); uint32_t fpc_end = *pc + size - 1;
exit(1);
}
dis_read_interpreter_sections(prg, &fpc_start, spaces + 4, tree_local, alt_fmt); tree_local[0] = '\0';
if (!alt_fmt) {
sprintf(tree_local, "%s.%d", tree, fcnt);
if (tree_local[0] == '_')
memcpy(tree_local, tree_local + 1, strlen(tree_local));
} else {
sprintf(tree_local, "%s_%d", tree, fcnt);
if (tree_local[0] == '_')
memcpy(tree_local, tree_local + 1, strlen(tree_local));
}
if (!alt_fmt) { if (!alt_fmt) {
SPC(spaces); SPC(spaces);
printf("| | |\n"); printf("| |\n");
SPC(spaces + 4); SPC(spaces);
printf("| "); printf("| | ");
printf("--- ( reading code for %s ) ---", tree_local); printf("( fun %s [ start: %d, end: %d ] )", tree_local, fpc_start, fpc_end);
dis_disassemble_section(prg, fpc_start, fpc_end, spaces + 4, true, alt_fmt); } else
printf("\n"); printf("\nLIT_FUN_%s:", tree_local);
SPC(spaces + 4);
printf("| ");
printf("--- ( end code section ) ---\n");
} else {
fun_code_t *fun = malloc(sizeof(struct fun_code_s));
fun->fun = malloc(strlen(tree_local) + 1);
strcpy(fun->fun, tree_local);
fun->start = fpc_start;
fun->len = fpc_end;
enqueue((void*) fun);
}
fcnt++; if ((*prg)->program[*pc + size - 1] != DIS_OP_FN_END) {
*pc += size; printf("\nERROR: Failed to find function end\n");
} exit(1);
} }
if (!alt_fmt) { dis_read_interpreter_sections(prg, &fpc_start, spaces + 4, tree_local, alt_fmt);
SPC(spaces);
printf("|\n");
SPC(spaces);
printf("| ");
printf("--- ( end fn section ) ---\n");
}
}
consumeByte(DIS_OP_SECTION_END, (*prg)->program, pc); if (!alt_fmt) {
SPC(spaces);
printf("| | |\n");
SPC(spaces + 4);
printf("| ");
printf("--- ( reading code for %s ) ---", tree_local);
dis_disassemble_section(prg, fpc_start, fpc_end, spaces + 4, true, alt_fmt);
printf("\n");
SPC(spaces + 4);
printf("| ");
printf("--- ( end code section ) ---\n");
} else {
fun_code_t *fun = malloc(sizeof(struct fun_code_s));
fun->fun = malloc(strlen(tree_local) + 1);
strcpy(fun->fun, tree_local);
fun->start = fpc_start;
fun->len = fpc_end;
enqueue((void*) fun);
}
fcnt++;
*pc += size;
}
}
if (!alt_fmt) {
SPC(spaces);
printf("|\n");
SPC(spaces);
printf("| ");
printf("--- ( end fn section ) ---\n");
}
}
consumeByte(DIS_OP_SECTION_END, (*prg)->program, pc);
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
void disassemble(const char *filename, bool alt_fmt) { void disassemble(const char *filename, bool alt_fmt) {
dis_program_t *prg; dis_program_t *prg;
queue_front = NULL; queue_front = NULL;
queue_rear = NULL; queue_rear = NULL;
dis_disassembler_init(&prg); dis_disassembler_init(&prg);
if (dis_load_file(filename, &prg)) if (dis_load_file(filename, &prg, alt_fmt))
exit(1); exit(1);
dis_read_header(&prg); dis_read_header(&prg, alt_fmt);
consumeByte(DIS_OP_SECTION_END, prg->program, &(prg->pc)); consumeByte(DIS_OP_SECTION_END, prg->program, &(prg->pc));
if (alt_fmt) if (alt_fmt)
printf("\nLIT_MAIN:"); printf("\nLIT_MAIN:");
dis_read_interpreter_sections(&prg, &(prg->pc), 0, "", alt_fmt); dis_read_interpreter_sections(&prg, &(prg->pc), 0, "", alt_fmt);
if (!alt_fmt) { if (!alt_fmt) {
printf("|\n| "); printf("|\n| ");
printf("--- ( reading main code ) ---"); printf("--- ( reading main code ) ---");
} else } else
printf("\nMAIN:"); printf("\nMAIN:");
dis_disassemble_section(&prg, prg->pc, prg->len, 0, false, alt_fmt); dis_disassemble_section(&prg, prg->pc, prg->len, 0, false, alt_fmt);
if (!alt_fmt) { if (!alt_fmt) {
printf("\n| "); printf("\n| ");
printf("--- ( end main code section ) ---"); printf("--- ( end main code section ) ---");
} else } else
printf("\n"); printf("\n");
if (alt_fmt) { if (alt_fmt) {
while (queue_front != NULL) { while (queue_front != NULL) {
fun_code_t *fun = (fun_code_t*)front(); fun_code_t *fun = (fun_code_t*) front();
printf("\nFUN_%s:", fun->fun); printf("\nFUN_%s:", fun->fun);
free(fun->fun); free(fun->fun);
dis_disassemble_section(&prg, fun->start, fun->len, 0, true, alt_fmt); dis_disassemble_section(&prg, fun->start, fun->len, 0, true, alt_fmt);
dequeue(); dequeue();
printf("\n"); printf("\n");
} }
} }
printf("\n"); printf("\n");
dis_disassembler_deinit(&prg); dis_disassembler_deinit(&prg);
} }