summaryrefslogtreecommitdiff
path: root/private_include
diff options
context:
space:
mode:
Diffstat (limited to 'private_include')
-rw-r--r--private_include/interp.h29
-rw-r--r--private_include/interp_private.h14
-rw-r--r--private_include/leb128.h9
-rw-r--r--private_include/opcodes.h58
-rw-r--r--private_include/ops.h59
-rw-r--r--private_include/sections.h22
-rw-r--r--private_include/wasm_types.h40
7 files changed, 231 insertions, 0 deletions
diff --git a/private_include/interp.h b/private_include/interp.h
new file mode 100644
index 0000000..beafbb1
--- /dev/null
+++ b/private_include/interp.h
@@ -0,0 +1,29 @@
+#ifndef INTERP_H
+#define INTERP_H
+
+#include <opcodes.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <stdio.h>
+
+struct interp_cfg
+{
+ FILE *f;
+};
+
+struct interp_set
+{
+ const enum opcode *opcodes;
+ size_t n;
+};
+
+extern const struct interp_set interp_initexpr_set;
+
+struct interp *interp_alloc(const struct interp_cfg *cfg);
+int interp_run(struct interp *i);
+int interp_run_limited(struct interp *i, const struct interp_set *ops);
+const char *interp_get_exception(const struct interp *i);
+void interp_free(struct interp *i);
+int interp_check_opcode(uint8_t op, FILE *f);
+
+#endif
diff --git a/private_include/interp_private.h b/private_include/interp_private.h
new file mode 100644
index 0000000..9cc6289
--- /dev/null
+++ b/private_include/interp_private.h
@@ -0,0 +1,14 @@
+#ifndef INTERP_PRIVATE_H
+#define INTERP_PRIVATE_H
+
+#include <interp.h>
+#include <stdbool.h>
+
+struct interp
+{
+ struct interp_cfg cfg;
+ const char *exception;
+ bool exit;
+};
+
+#endif
diff --git a/private_include/leb128.h b/private_include/leb128.h
new file mode 100644
index 0000000..5550c91
--- /dev/null
+++ b/private_include/leb128.h
@@ -0,0 +1,9 @@
+#ifndef LEB128_H
+#define LEB128_H
+
+#include <stdio.h>
+
+int leb128_read_unsigned(FILE *f, unsigned maxbits, unsigned long long *out);
+int leb128_read_signed(FILE *f, unsigned maxbits, long long *out);
+
+#endif
diff --git a/private_include/opcodes.h b/private_include/opcodes.h
new file mode 100644
index 0000000..958c6d1
--- /dev/null
+++ b/private_include/opcodes.h
@@ -0,0 +1,58 @@
+#ifndef OPCODES_H
+#define OPCODES_H
+
+enum opcode
+{
+ OP_UNREACHABLE,
+ OP_NOP,
+ OP_BLOCK,
+ OP_LOOP,
+ OP_IF,
+ OP_ELSE,
+ OP_END = 0xb,
+ OP_BR,
+ OP_BR_IF,
+ OP_BR_TABLE,
+ OP_RETURN = 0xf,
+ OP_CALL,
+ OP_CALL_INDIRECT,
+ OP_DROP = 0x1a,
+ OP_SELECT,
+ OP_GET_LOCAL = 0x20,
+ OP_SET_LOCAL,
+ OP_TEE_LOCAL,
+ OP_GET_GLOBAL,
+ OP_SET_GLOBAL,
+ OP_I32_LOAD = 0x28,
+ OP_I64_LOAD,
+ OP_F32_LOAD,
+ OP_F64_LOAD,
+ OP_I32_LOAD8_S,
+ OP_I32_LOAD8_U,
+ OP_I32_LOAD16_S,
+ OP_I32_LOAD16_U,
+ OP_I64_LOAD8_S,
+ OP_I64_LOAD8_U,
+ OP_I64_LOAD16_S,
+ OP_I64_LOAD16_U,
+ OP_I64_LOAD32_S,
+ OP_I64_LOAD32_U,
+ OP_I32_STORE,
+ OP_I64_STORE,
+ OP_F32_STORE,
+ OP_F64_STORE,
+ OP_I32_STORE8,
+ OP_I32_STORE16,
+ OP_I64_STORE8,
+ OP_I64_STORE16,
+ OP_I64_STORE32,
+ OP_CURRENT_MEMORY,
+ OP_GROW_MEMORY,
+ OP_I32_CONST,
+ OP_I64_CONST,
+ OP_F32_CONST,
+ OP_F64_CONST,
+ OP_I32_SUB = 0x6b
+};
+
+#endif
diff --git a/private_include/ops.h b/private_include/ops.h
new file mode 100644
index 0000000..ed8bd20
--- /dev/null
+++ b/private_include/ops.h
@@ -0,0 +1,59 @@
+#ifndef OPS_H
+#define OPS_H
+
+#include <interp.h>
+#include <stdio.h>
+
+int op_unreachable(struct interp *i);
+int op_nop(struct interp *i);
+int op_block(struct interp *i);
+int op_loop(struct interp *i);
+int op_if(struct interp *i);
+int op_else(struct interp *i);
+int op_end(struct interp *i);
+int op_br(struct interp *i);
+int op_br_if(struct interp *i);
+int op_br_table(struct interp *i);
+int op_return(struct interp *i);
+int op_call(struct interp *i);
+int op_call_indirect(struct interp *i);
+int op_get_local(struct interp *i);
+int op_set_local(struct interp *i);
+int op_tee_local(struct interp *i);
+int op_get_global(struct interp *i);
+int op_set_global(struct interp *i);
+int op_i32_load(struct interp *i);
+int op_i32_store(struct interp *i);
+int op_i32_const(struct interp *i);
+int op_i64_const(struct interp *i);
+int op_f32_const(struct interp *i);
+int op_f64_const(struct interp *i);
+int op_i32_sub(struct interp *i);
+
+int check_unreachable(FILE *f);
+int check_nop(FILE *f);
+int check_block(FILE *f);
+int check_loop(FILE *f);
+int check_if(FILE *f);
+int check_else(FILE *f);
+int check_end(FILE *f);
+int check_br(FILE *f);
+int check_br_if(FILE *f);
+int check_br_table(FILE *f);
+int check_return(FILE *f);
+int check_call(FILE *f);
+int check_call_indirect(FILE *f);
+int check_get_local(FILE *f);
+int check_set_local(FILE *f);
+int check_tee_local(FILE *f);
+int check_get_global(FILE *f);
+int check_set_global(FILE *f);
+int check_i32_load(FILE *f);
+int check_i32_store(FILE *f);
+int check_i32_const(FILE *f);
+int check_i64_const(FILE *f);
+int check_f32_const(FILE *f);
+int check_f64_const(FILE *f);
+int check_i32_sub(FILE *f);
+
+#endif
diff --git a/private_include/sections.h b/private_include/sections.h
new file mode 100644
index 0000000..67e49ce
--- /dev/null
+++ b/private_include/sections.h
@@ -0,0 +1,22 @@
+#ifndef SECTIONS_H
+#define SECTIONS_H
+
+#include <wasm_types.h>
+#include <stdio.h>
+
+int section_custom(struct wasmfs *w, FILE *f, unsigned long len);
+int section_type(struct wasmfs *w, FILE *f, unsigned long len);
+int section_import(struct wasmfs *w, FILE *f, unsigned long len);
+int section_function(struct wasmfs *w, FILE *f, unsigned long len);
+int section_table(struct wasmfs *w, FILE *f, unsigned long len);
+int section_memory(struct wasmfs *w, FILE *f, unsigned long len);
+int section_global(struct wasmfs *w, FILE *f, unsigned long len);
+int section_export(struct wasmfs *w, FILE *f, unsigned long len);
+int section_start(struct wasmfs *w, FILE *f, unsigned long len);
+int section_element(struct wasmfs *w, FILE *f, unsigned long len);
+int section_code(struct wasmfs *w, FILE *f, unsigned long len);
+int section_data(struct wasmfs *w, FILE *f, unsigned long len);
+
+int check_resizable_limits(FILE *f);
+
+#endif
diff --git a/private_include/wasm_types.h b/private_include/wasm_types.h
new file mode 100644
index 0000000..dee0e70
--- /dev/null
+++ b/private_include/wasm_types.h
@@ -0,0 +1,40 @@
+#ifndef TYPES_H
+#define TYPES_H
+
+#include <stdbool.h>
+#include <stdio.h>
+
+struct wasmfs
+{
+ char *path;
+
+ struct
+ {
+ long type, import, function, table, memory, global, export,
+ start, element, code, data;
+ } sections;
+};
+
+struct wasmfs_inst
+{
+ const struct wasmfs *w;
+ FILE *f;
+};
+
+typedef bool varuint1;
+typedef signed char varint7;
+typedef unsigned char varuint7;
+typedef unsigned long varuint32;
+typedef long varint32;
+typedef unsigned long long varuint64;
+typedef long long varint64;
+
+int varuint1_read(FILE *f, varuint1 *out);
+int varint7_read(FILE *f, varint7 *out);
+int varuint7_read(FILE *f, varuint7 *out);
+int varuint32_read(FILE *f, varuint32 *out);
+int varint32_read(FILE *f, varint32 *out);
+int varuint64_read(FILE *f, varuint64 *out);
+int varint64_read(FILE *f, varint64 *out);
+
+#endif