aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/assemble.c10
-rw-r--r--tools/translate.c21
2 files changed, 25 insertions, 6 deletions
diff --git a/tools/assemble.c b/tools/assemble.c
index 07416fd..11bb7c9 100644
--- a/tools/assemble.c
+++ b/tools/assemble.c
@@ -163,14 +163,12 @@ int assemble(uint32_t memory_size, uint16_t memory[memory_size],
goto fail;
}
- // For now we're passing 2 numbers to main(): 0x32 and 0x14.
- // This is just a temporary way to check if our Wasm function
- // actually does anything. In the end - main() will be
- // a function, that doesn't require any arguments.
+ /*
+ * We're first writing some value at STACK_FRAME_BACKUP_ADDR to be able
+ * to check, if the functions we call restore frame address properly
+ */
if (i_const(im(0x23), &startup) ||
i_store(im(STACK_FRAME_BACKUP_ADDR), &startup) ||
- i_const(im(0x32), &startup) ||
- i_const(im(0x14), &startup) ||
i_call (ptr(&main_function->translated_body), &startup) ||
i_halt ( &startup))
goto fail;
diff --git a/tools/translate.c b/tools/translate.c
index ee6ea99..4361d6f 100644
--- a/tools/translate.c
+++ b/tools/translate.c
@@ -3,6 +3,7 @@
/* 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
@@ -63,6 +64,26 @@ int translate(FILE *handle, struct function *function, struct module *module)
goto fail;
matched = 1;
+ } else if (wasm_opcode == WASM_CALL) {
+ uint32_t funcidx;
+ struct instruction **target;
+
+ if (leb_u32(handle, &funcidx)) {
+ PRERR(MSG_BAD_NUM);
+ goto fail;
+ }
+
+ if (funcidx >= module->functions_count) {
+ PRERR(MSG_BAD_IDX("funcidx"));
+ goto fail;
+ }
+
+ target = &module->functions[funcidx].translated_body;
+
+ if (i_call(ptr(target), &expr))
+ goto fail;
+
+ matched = 1;
} else if (wasm_opcode <= WASM_I64_STORE32 &&
wasm_opcode >= WASM_I32_LOAD) {
uint32_t align, offset;