aboutsummaryrefslogtreecommitdiff
path: root/tools/wasm_compile.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/wasm_compile.c')
-rw-r--r--tools/wasm_compile.c26
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));