From c75dcab5988f5c0b5e0629015f384e5aa1440690 Mon Sep 17 00:00:00 2001 From: Wojciech Kosior Date: Mon, 21 Sep 2020 13:43:29 +0200 Subject: enable translation of few arithmetic operations (testbench included) --- tools/translate.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'tools/translate.c') diff --git a/tools/translate.c b/tools/translate.c index 4361d6f..bf13bd1 100644 --- a/tools/translate.c +++ b/tools/translate.c @@ -4,7 +4,9 @@ /* WebAssembly opcodes */ #define WASM_END 0x0B #define WASM_CALL 0x10 + #define WASM_LOCAL_GET 0x20 + #define WASM_I32_LOAD 0x28 #define WASM_I32_LOAD8_S 0x2C #define WASM_I32_LOAD8_U 0x2D @@ -14,8 +16,14 @@ #define WASM_I32_STORE8 0x3A #define WASM_I32_STORE16 0x3B #define WASM_I64_STORE32 0x3E + #define WASM_I32_CONST 0x41 + +#define WASM_I32_ADD 0x6A #define WASM_I32_SUB 0x6B +#define WASM_I32_MUL 0x6C +#define WASM_I32_DIV_U 0x6E + int translate(FILE *handle, struct function *function, struct module *module) { @@ -59,10 +67,25 @@ int translate(FILE *handle, struct function *function, struct module *module) // TODO: make a function for each instruction type, // call them through some table... - if (wasm_opcode == WASM_I32_SUB) { + if (wasm_opcode == WASM_I32_ADD) { + if (i_add(&expr)) + goto fail; + + matched = 1; + } else if (wasm_opcode == WASM_I32_SUB) { if (i_sub(&expr)) goto fail; + matched = 1; + } else if (wasm_opcode == WASM_I32_MUL) { + if (i_mul(&expr)) + goto fail; + + matched = 1; + } else if (wasm_opcode == WASM_I32_DIV_U) { + if (i_div(&expr)) + goto fail; + matched = 1; } else if (wasm_opcode == WASM_CALL) { uint32_t funcidx; -- cgit v1.2.3