aboutsummaryrefslogtreecommitdiff
path: root/tools/wasm_compile.h
diff options
context:
space:
mode:
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 */