aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorWojciech Kosior <kwojtus@protonmail.com>2020-10-06 11:11:24 +0200
committerWojciech Kosior <kwojtus@protonmail.com>2020-10-06 11:11:24 +0200
commit1741bee182f115d899bd31642b32f70b0c7ed32f (patch)
tree792a261f01c25af2cba795bc78d25b8c5068efa0 /tools
parent7ddb4265d30ef30df6e7098c979334109378357c (diff)
downloadAGH-engineering-thesis-1741bee182f115d899bd31642b32f70b0c7ed32f.tar.gz
AGH-engineering-thesis-1741bee182f115d899bd31642b32f70b0c7ed32f.zip
add translation of br_if instruction
Diffstat (limited to 'tools')
-rw-r--r--tools/translate.c36
-rw-r--r--tools/translate_xmacro.h3
-rw-r--r--tools/wasm.h1
3 files changed, 39 insertions, 1 deletions
diff --git a/tools/translate.c b/tools/translate.c
index 64ed407..8b28aad 100644
--- a/tools/translate.c
+++ b/tools/translate.c
@@ -426,6 +426,42 @@ fail:
return -1;
}
+static int _translate_br_if(struct translation *data)
+{
+ struct target *br_end;
+ struct instruction **expr = &data->function->translated_body;
+ struct types *backed_stack = NULL;
+ int retval = -1;
+
+ br_end = add_target(data->module);
+
+ if (!br_end)
+ goto fail;
+
+ if (i_cond_jump_n(ptr_after(&br_end->instr), expr))
+ goto fail;
+
+ backed_stack = data->types_stack;
+ get_type(backed_stack);
+
+ if (_translate_br(data))
+ goto fail;
+
+ br_end->instr = data->function->translated_body->prev;
+ retval = 0;
+
+fail:
+ if (backed_stack) {
+ put_type(data->types_stack);
+ data->types_stack = backed_stack;
+ }
+
+ if (retval)
+ PRERR("Couldn't translate br_if instruction\n");
+
+ return retval;
+}
+
static int _translate_call(struct translation *data)
{
uint32_t funcidx;
diff --git a/tools/translate_xmacro.h b/tools/translate_xmacro.h
index f68f317..958d8d9 100644
--- a/tools/translate_xmacro.h
+++ b/tools/translate_xmacro.h
@@ -16,11 +16,12 @@ TLS(WASM_I32_STORE8, storeb_p, i32_i32, empty)
TLS(WASM_I32_STORE16, storew_p, i32_i32, empty)
/*
- * There are more checks to be performed in case of if, but we do them
+ * There are more checks to be performed in case of if and br_if, but we do them
* another way and only check for the i32 condition value here.
*/
TC (WASM_IF, if, i32, custom)
TC (WASM_BR, br, custom, custom)
+TC (WASM_BR_IF, br_if, i32, custom)
TC (WASM_CALL, call, custom, custom)
TC (WASM_LOCAL_GET, local_get, empty, custom)
TC (WASM_I32_CONST, const, empty, i32)
diff --git a/tools/wasm.h b/tools/wasm.h
index 0c36c11..476f892 100644
--- a/tools/wasm.h
+++ b/tools/wasm.h
@@ -26,6 +26,7 @@
#define WASM_ELSE 0x05
#define WASM_END 0x0B
#define WASM_BR 0x0C
+#define WASM_BR_IF 0x0D
#define WASM_CALL 0x10
#define WASM_LOCAL_GET 0x20