diff options
author | Wojciech Kosior <kwojtus@protonmail.com> | 2020-10-08 19:18:43 +0200 |
---|---|---|
committer | Wojciech Kosior <kwojtus@protonmail.com> | 2020-10-08 19:18:43 +0200 |
commit | 5e04a9626e2986fc40825d15cb09a274223381e9 (patch) | |
tree | a52a96fa585247145cb521b9c6f7fe7946ba7997 /tools/wasm_compile.c | |
parent | 63a2cced4238af7d171e0b8807d887c435b4656b (diff) | |
download | AGH-engineering-thesis-5e04a9626e2986fc40825d15cb09a274223381e9.tar.gz AGH-engineering-thesis-5e04a9626e2986fc40825d15cb09a274223381e9.zip |
translate webasm block of instructions + put instruction names as comments in generated code
Diffstat (limited to 'tools/wasm_compile.c')
-rw-r--r-- | tools/wasm_compile.c | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/tools/wasm_compile.c b/tools/wasm_compile.c index 64988c8..c455541 100644 --- a/tools/wasm_compile.c +++ b/tools/wasm_compile.c @@ -1,24 +1,33 @@ #include "wasm_compile.h" +#include "stack_machine_instruction.h" -void print_instructions(uint32_t count, uint16_t instructions[count]) +void print_instructions(uint32_t count, + struct translated_word memory[count]) { uint32_t i; char binary[17]; - uint16_t instruction; + uint16_t bits; int j; binary[16] = '\0'; for (i = 0; i < count; i++) { - instruction = instructions[i]; + bits = memory[i].contents; j = 16; while (j--) { - binary[j] = (instruction & 1) ? '1' : '0'; - instruction >>= 1; + binary[j] = (bits & 1) ? '1' : '0'; + bits >>= 1; } - puts(binary); + printf(binary); + + if (memory[i].instr) { + printf(" // 0x%03lx %s", (long) i, + memory[i].instr->name); + } + + putchar('\n'); } } @@ -26,7 +35,7 @@ int main(int argc, char **argv) { FILE *handle = NULL; struct module *module = NULL; - uint16_t *translated_instructions = NULL; + struct translated_word *translated_instructions = NULL; char retval = -1; if (argc < 2) { @@ -46,7 +55,8 @@ int main(int argc, char **argv) if (!module) goto fail; - translated_instructions = calloc(1, CODE_TOP_ADDR); + translated_instructions = calloc(1, CODE_TOP_ADDR * + sizeof(struct translated_word)); if (!translated_instructions) { PRERR(MSG_ALLOC_FAIL(CODE_TOP_ADDR)); |