From 6be29ed8c58e390680b0adfa9f30972483e78c7d Mon Sep 17 00:00:00 2001 From: hiperiondev Date: Wed, 23 Aug 2023 20:48:06 -0300 Subject: [PATCH] Add implicit fn return --- tools/disassembler/disassembler.c | 7 +++++-- tools/disassembler/disassembler.h | 20 ++++++++++---------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/tools/disassembler/disassembler.c b/tools/disassembler/disassembler.c index d25ad0c..a576cb0 100644 --- a/tools/disassembler/disassembler.c +++ b/tools/disassembler/disassembler.c @@ -329,7 +329,7 @@ static void dis_disassemble_section(dis_program_t **prg, uint32_t pc, uint32_t l float flt = 0; char *str = NULL; - //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) { printf("\n"); uint16_t args = readWord((*prg)->program, &pc); @@ -409,7 +409,7 @@ static void dis_disassemble_section(dis_program_t **prg, uint32_t pc, uint32_t l dis_print_opcode(opcode); - if (opcode > DIS_OP_END_OPCODES) + if (opcode >= DIS_OP_END_OPCODES) continue; if (alt_fmt) { @@ -433,6 +433,9 @@ static void dis_disassemble_section(dis_program_t **prg, uint32_t pc, uint32_t l free(label_line); free(label_id); } + + if (alt_fmt && (*prg)->program[pc - 5] != DIS_OP_FN_RETURN) + printf("\n FN_RETURN w(0)"); } #define LIT_ADD(a, b, c) b[c] = a; ++c; diff --git a/tools/disassembler/disassembler.h b/tools/disassembler/disassembler.h index 6d01461..f30a6ea 100644 --- a/tools/disassembler/disassembler.h +++ b/tools/disassembler/disassembler.h @@ -22,8 +22,8 @@ typedef enum DIS_OPCODES { // data DIS_OP_LITERAL, // - DIS_OP_LITERAL_LONG, // for more than 256 literals in a chunk - DIS_OP_LITERAL_RAW, // forcibly get the raw value of the literal + DIS_OP_LITERAL_LONG, // + DIS_OP_LITERAL_RAW, // // arithmetic operators DIS_OP_NEGATE, // @@ -42,21 +42,21 @@ typedef enum DIS_OPCODES { DIS_OP_TYPE_DECL_removed, // deprecated DIS_OP_TYPE_DECL_LONG_removed, // deprecated - DIS_OP_VAR_DECL, // declare a variable to be used (as a literal) - DIS_OP_VAR_DECL_LONG, // declare a variable to be used (as a long literal) + DIS_OP_VAR_DECL, // + DIS_OP_VAR_DECL_LONG, // - DIS_OP_FN_DECL, // declare a function to be used (as a literal) - DIS_OP_FN_DECL_LONG, // declare a function to be used (as a long literal) + DIS_OP_FN_DECL, // + DIS_OP_FN_DECL_LONG, // - DIS_OP_VAR_ASSIGN, // assign to a literal + DIS_OP_VAR_ASSIGN, // DIS_OP_VAR_ADDITION_ASSIGN, // DIS_OP_VAR_SUBTRACTION_ASSIGN, // DIS_OP_VAR_MULTIPLICATION_ASSIGN, // DIS_OP_VAR_DIVISION_ASSIGN, // DIS_OP_VAR_MODULO_ASSIGN, // - DIS_OP_TYPE_CAST, // temporarily change a type of an atomic value - DIS_OP_TYPE_OF, // get the type of a variable + DIS_OP_TYPE_CAST, // + DIS_OP_TYPE_OF, // DIS_OP_IMPORT, // DIS_OP_EXPORT_removed, // deprecated @@ -74,7 +74,7 @@ typedef enum DIS_OPCODES { DIS_OP_COMPARE_LESS_EQUAL, // DIS_OP_COMPARE_GREATER, // DIS_OP_COMPARE_GREATER_EQUAL, // - DIS_OP_INVERT, // for booleans + DIS_OP_INVERT, // // logical operators DIS_OP_AND, //