aboutsummaryrefslogtreecommitdiff
path: root/tools/wasm_compile.h
diff options
context:
space:
mode:
authorWojciech Kosior <kwojtus@protonmail.com>2020-10-03 21:45:24 +0200
committerWojciech Kosior <kwojtus@protonmail.com>2020-10-05 10:13:38 +0200
commit7a61f213fb9be8ab7f9bd0fb33940b21fa143b05 (patch)
tree1bd5beab68c778d4d3a2543cf3661bfcb23445c2 /tools/wasm_compile.h
parentc548c0ce5b2e7ca2784257966ebdd386e1f31218 (diff)
downloadAGH-engineering-thesis-7a61f213fb9be8ab7f9bd0fb33940b21fa143b05.tar.gz
AGH-engineering-thesis-7a61f213fb9be8ab7f9bd0fb33940b21fa143b05.zip
fixes, conditional if-not jump and translation of if-else instruction from wasm
Diffstat (limited to 'tools/wasm_compile.h')
-rw-r--r--tools/wasm_compile.h24
1 files changed, 23 insertions, 1 deletions
diff --git a/tools/wasm_compile.h b/tools/wasm_compile.h
index e223ec6..4cee1bb 100644
--- a/tools/wasm_compile.h
+++ b/tools/wasm_compile.h
@@ -1,8 +1,12 @@
+#ifndef WASM_COMPILE_H
+#define WASM_COMPILE_H
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdint.h>
+#include <stdbool.h>
#define STACK_FRAME_BACKUP_ADDR 0x0FFFFC
#define STACK_TOP_ADDR 0x0FFFFC
@@ -24,6 +28,8 @@
#define PRERR(...) fprintf(stderr, __VA_ARGS__)
+#define POW(n) (((int64_t) 1) << (n))
+
struct resulttype {
uint32_t count;
char *types;
@@ -40,6 +46,7 @@ struct function {
char *locals;
struct instruction *translated_body;
+ struct target *targets;
uint32_t start_addr;
};
@@ -62,12 +69,25 @@ struct module {
uint32_t mem_min, mem_max;
uint32_t exports_count;
struct export *exports;
+ struct target *targets;
};
-int leb_u32(FILE *handle, uint32_t *result);
+int leb_32(FILE *handle, uint32_t *result, bool with_sign);
+
+inline static int leb_u32(FILE *handle, uint32_t *result)
+{
+ return leb_32(handle, result, false);
+}
+
+inline static int leb_s32(FILE *handle, int32_t *result)
+{
+ return leb_32(handle, (uint32_t *) result, true);
+}
void free_expr(struct instruction *expr);
+void free_targets(struct target *top);
+
void free_module(struct module *module);
struct module *parse_module(FILE *handle);
@@ -76,3 +96,5 @@ int translate(FILE *handle, struct function *function, struct module *module);
int assemble(uint32_t memory_size, uint16_t memory[memory_size],
struct module *module);
+
+#endif /* WASM_COMPILE_H */