diff options
Diffstat (limited to 'src/op')
| -rw-r--r-- | src/op/CMakeLists.txt | 28 | ||||
| -rw-r--r-- | src/op/block.c | 29 | ||||
| -rw-r--r-- | src/op/br.c | 29 | ||||
| -rw-r--r-- | src/op/br_if.c | 29 | ||||
| -rw-r--r-- | src/op/br_table.c | 46 | ||||
| -rw-r--r-- | src/op/call.c | 28 | ||||
| -rw-r--r-- | src/op/call_indirect.c | 40 | ||||
| -rw-r--r-- | src/op/current_memory.c | 35 | ||||
| -rw-r--r-- | src/op/else.c | 12 | ||||
| -rw-r--r-- | src/op/end.c | 15 | ||||
| -rw-r--r-- | src/op/f32_const.c | 29 | ||||
| -rw-r--r-- | src/op/f64_const.c | 29 | ||||
| -rw-r--r-- | src/op/get_global.c | 29 | ||||
| -rw-r--r-- | src/op/get_local.c | 29 | ||||
| -rw-r--r-- | src/op/i32_const.c | 29 | ||||
| -rw-r--r-- | src/op/i32_load.c | 34 | ||||
| -rw-r--r-- | src/op/i32_store.c | 34 | ||||
| -rw-r--r-- | src/op/i32_sub.c | 16 | ||||
| -rw-r--r-- | src/op/i64_const.c | 29 | ||||
| -rw-r--r-- | src/op/if.c | 27 | ||||
| -rw-r--r-- | src/op/loop.c | 27 | ||||
| -rw-r--r-- | src/op/nop.c | 13 | ||||
| -rw-r--r-- | src/op/return.c | 13 | ||||
| -rw-r--r-- | src/op/set_global.c | 29 | ||||
| -rw-r--r-- | src/op/set_local.c | 29 | ||||
| -rw-r--r-- | src/op/tee_local.c | 29 | ||||
| -rw-r--r-- | src/op/unreachable.c | 17 |
27 files changed, 733 insertions, 0 deletions
diff --git a/src/op/CMakeLists.txt b/src/op/CMakeLists.txt new file mode 100644 index 0000000..a97b212 --- /dev/null +++ b/src/op/CMakeLists.txt @@ -0,0 +1,28 @@ +target_sources(${PROJECT_NAME} PRIVATE + unreachable.c + nop.c + block.c + loop.c + if.c + else.c + end.c + br.c + br_if.c + br_table.c + return.c + call.c + call_indirect.c + get_local.c + set_local.c + tee_local.c + get_global.c + set_global.c + i32_load.c + i32_store.c + current_memory.c + i32_const.c + i64_const.c + f32_const.c + f64_const.c + i32_sub.c +) diff --git a/src/op/block.c b/src/op/block.c new file mode 100644 index 0000000..c97879c --- /dev/null +++ b/src/op/block.c @@ -0,0 +1,29 @@ +#include <ops.h> +#include <interp.h> +#include <interp_private.h> +#include <wasm_types.h> +#include <stddef.h> +#include <stdio.h> + +static int op(FILE *const f, struct interp *const i) +{ + varint7 sig; + + if (varint7_read(f, &sig)) + { + fprintf(stderr, "%s: varint7_read failed\n", __func__); + return -1; + } + + return 0; +} + +int op_block(struct interp *const i) +{ + return op(i->cfg.f, i); +} + +int check_block(FILE *const f) +{ + return op(f, NULL); +} diff --git a/src/op/br.c b/src/op/br.c new file mode 100644 index 0000000..ef5c34f --- /dev/null +++ b/src/op/br.c @@ -0,0 +1,29 @@ +#include <ops.h> +#include <interp.h> +#include <interp_private.h> +#include <wasm_types.h> +#include <stddef.h> +#include <stdio.h> + +static int op(FILE *const f, struct interp *const i) +{ + varuint32 relative_depth; + + if (varuint32_read(f, &relative_depth)) + { + fprintf(stderr, "%s: varuint32_read failed\n", __func__); + return -1; + } + + return 0; +} + +int op_br(struct interp *const i) +{ + return op(i->cfg.f, i); +} + +int check_br(FILE *const f) +{ + return op(f, NULL); +} diff --git a/src/op/br_if.c b/src/op/br_if.c new file mode 100644 index 0000000..1711ada --- /dev/null +++ b/src/op/br_if.c @@ -0,0 +1,29 @@ +#include <ops.h> +#include <interp.h> +#include <interp_private.h> +#include <wasm_types.h> +#include <stddef.h> +#include <stdio.h> + +static int op(FILE *const f, struct interp *const i) +{ + varuint32 relative_depth; + + if (varuint32_read(f, &relative_depth)) + { + fprintf(stderr, "%s: varuint32_read failed\n", __func__); + return 1; + } + + return 0; +} + +int op_br_if(struct interp *const i) +{ + return op(i->cfg.f, i); +} + +int check_br_if(FILE *const f) +{ + return op(f, NULL); +} diff --git a/src/op/br_table.c b/src/op/br_table.c new file mode 100644 index 0000000..09ae8e4 --- /dev/null +++ b/src/op/br_table.c @@ -0,0 +1,46 @@ +#include <interp.h> +#include <interp_private.h> +#include <wasm_types.h> +#include <stddef.h> +#include <stdio.h> + +static int op(FILE *const f, struct interp *const i) +{ + varuint32 target_count, default_target; + + if (varuint32_read(f, &target_count)) + { + fprintf(stderr, "%s: varuint32_read target_count failed\n", __func__); + return -1; + } + + for (varuint32 i = 0; i < target_count; i++) + { + varuint32 target_table; + + if (varuint32_read(f, &target_table)) + { + fprintf(stderr, "%s: varuint32_read target_table failed\n", + __func__); + return -1; + } + } + + if (varuint32_read(f, &default_target)) + { + fprintf(stderr, "%s: varuint32_read default_target failed\n", __func__); + return -1; + } + + return 0; +} + +int op_br_table(struct interp *const i) +{ + return op(i->cfg.f, i); +} + +int check_br_table(FILE *const f) +{ + return op(f, NULL); +} diff --git a/src/op/call.c b/src/op/call.c new file mode 100644 index 0000000..62ff5c9 --- /dev/null +++ b/src/op/call.c @@ -0,0 +1,28 @@ +#include <ops.h> +#include <interp.h> +#include <interp_private.h> +#include <wasm_types.h> +#include <stdio.h> + +static int op(FILE *const f, struct interp *const i) +{ + varuint32 function_index; + + if (varuint32_read(f, &function_index)) + { + fprintf(stderr, "%s: varuint32_read failed\n", __func__); + return 1; + } + + return 0; +} + +int op_call(struct interp *const i) +{ + return op(i->cfg.f, i); +} + +int check_call(FILE *const f) +{ + return op(f, NULL); +} diff --git a/src/op/call_indirect.c b/src/op/call_indirect.c new file mode 100644 index 0000000..9cb831c --- /dev/null +++ b/src/op/call_indirect.c @@ -0,0 +1,40 @@ +#include <ops.h> +#include <interp.h> +#include <interp_private.h> +#include <wasm_types.h> +#include <stdio.h> + +static int op(FILE *const f, struct interp *const i) +{ + varuint32 type_index; + varuint1 reserved; + + if (varuint32_read(f, &type_index)) + { + fprintf(stderr, "%s: varuint32_read failed\n", __func__); + return 1; + } + else if (varuint1_read(f, &reserved)) + { + fprintf(stderr, "%s: varuint1_read failed\n", __func__); + return 1; + } + else if (reserved) + { + fprintf(stderr, "%s: unexpected non-zero reserved value %u\n", + __func__, (unsigned)reserved); + return 1; + } + + return 0; +} + +int op_call_indirect(struct interp *const i) +{ + return op(i->cfg.f, i); +} + +int check_call_indirect(FILE *const f) +{ + return op(f, NULL); +} diff --git a/src/op/current_memory.c b/src/op/current_memory.c new file mode 100644 index 0000000..4c1f26a --- /dev/null +++ b/src/op/current_memory.c @@ -0,0 +1,35 @@ +#include <ops.h> +#include <interp.h> +#include <interp_private.h> +#include <wasm_types.h> +#include <stddef.h> +#include <stdio.h> + +static int op(FILE *const f, struct interp *const i) +{ + varuint1 reserved; + + if (varuint1_read(f, &reserved)) + { + fprintf(stderr, "%s: varuint1_read failed\n", __func__); + return 1; + } + else if (reserved) + { + fprintf(stderr, "%s: unexpected non-zero reserved value %u\n", + __func__, (unsigned)reserved); + return 1; + } + + return 0; +} + +int op_current_memory(struct interp *const i) +{ + return op(i->cfg.f, i); +} + +int check_current_memory(FILE *const f) +{ + return op(f, NULL); +} diff --git a/src/op/else.c b/src/op/else.c new file mode 100644 index 0000000..4e4dcb6 --- /dev/null +++ b/src/op/else.c @@ -0,0 +1,12 @@ +#include <ops.h> +#include <interp.h> + +int op_else(struct interp *const i) +{ + return -1; +} + +int check_else(FILE *const f) +{ + return 0; +} diff --git a/src/op/end.c b/src/op/end.c new file mode 100644 index 0000000..93cdae7 --- /dev/null +++ b/src/op/end.c @@ -0,0 +1,15 @@ +#include <ops.h> +#include <interp.h> +#include <interp_private.h> +#include <stdbool.h> + +int op_end(struct interp *const i) +{ + i->exit = true; + return 0; +} + +int check_end(FILE *const f) +{ + return 0; +} diff --git a/src/op/f32_const.c b/src/op/f32_const.c new file mode 100644 index 0000000..e42f19f --- /dev/null +++ b/src/op/f32_const.c @@ -0,0 +1,29 @@ +#include <ops.h> +#include <interp.h> +#include <interp_private.h> +#include <wasm_types.h> +#include <stddef.h> +#include <stdio.h> + +static int op(FILE *const f, struct interp *const i) +{ + varuint32 value; + + if (varuint32_read(f, &value)) + { + fprintf(stderr, "%s: varuint32_read failed\n", __func__); + return -1; + } + + return 0; +} + +int op_f32_const(struct interp *const i) +{ + return op(i->cfg.f, i); +} + +int check_f32_const(FILE *const f) +{ + return op(f, NULL); +} diff --git a/src/op/f64_const.c b/src/op/f64_const.c new file mode 100644 index 0000000..01c3401 --- /dev/null +++ b/src/op/f64_const.c @@ -0,0 +1,29 @@ +#include <ops.h> +#include <interp.h> +#include <interp_private.h> +#include <wasm_types.h> +#include <stddef.h> +#include <stdio.h> + +static int op(FILE *const f, struct interp *const i) +{ + varuint64 value; + + if (varuint64_read(f, &value)) + { + fprintf(stderr, "%s: varuint64_read failed\n", __func__); + return -1; + } + + return 0; +} + +int op_f64_const(struct interp *const i) +{ + return op(i->cfg.f, i); +} + +int check_f64_const(FILE *const f) +{ + return op(f, NULL); +} diff --git a/src/op/get_global.c b/src/op/get_global.c new file mode 100644 index 0000000..6366c4e --- /dev/null +++ b/src/op/get_global.c @@ -0,0 +1,29 @@ +#include <ops.h> +#include <interp.h> +#include <interp_private.h> +#include <wasm_types.h> +#include <stddef.h> +#include <stdio.h> + +static int op(FILE *const f, struct interp *const i) +{ + varuint32 global_index; + + if (varuint32_read(f, &global_index)) + { + fprintf(stderr, "%s: varuint32_read failed\n", __func__); + return 1; + } + + return 0; +} + +int op_get_global(struct interp *const i) +{ + return op(i->cfg.f, i); +} + +int check_get_global(FILE *const f) +{ + return op(f, NULL); +} diff --git a/src/op/get_local.c b/src/op/get_local.c new file mode 100644 index 0000000..f1de025 --- /dev/null +++ b/src/op/get_local.c @@ -0,0 +1,29 @@ +#include <ops.h> +#include <interp.h> +#include <interp_private.h> +#include <wasm_types.h> +#include <stddef.h> +#include <stdio.h> + +static int op(FILE *const f, struct interp *const i) +{ + varuint32 local_index; + + if (varuint32_read(f, &local_index)) + { + fprintf(stderr, "%s: varuint32_read failed\n", __func__); + return 1; + } + + return 0; +} + +int op_get_local(struct interp *const i) +{ + return op(i->cfg.f, i); +} + +int check_get_local(FILE *const f) +{ + return op(f, NULL); +} diff --git a/src/op/i32_const.c b/src/op/i32_const.c new file mode 100644 index 0000000..722dab9 --- /dev/null +++ b/src/op/i32_const.c @@ -0,0 +1,29 @@ +#include <ops.h> +#include <interp.h> +#include <interp_private.h> +#include <wasm_types.h> +#include <stddef.h> +#include <stdio.h> + +static int op(FILE *const f, struct interp *const i) +{ + varint32 value; + + if (varint32_read(f, &value)) + { + fprintf(stderr, "%s: varint32_read failed\n", __func__); + return -1; + } + + return 0; +} + +int op_i32_const(struct interp *const i) +{ + return op(i->cfg.f, i); +} + +int check_i32_const(FILE *const f) +{ + return op(f, NULL); +} diff --git a/src/op/i32_load.c b/src/op/i32_load.c new file mode 100644 index 0000000..e00cc2d --- /dev/null +++ b/src/op/i32_load.c @@ -0,0 +1,34 @@ +#include <ops.h> +#include <interp.h> +#include <interp_private.h> +#include <wasm_types.h> +#include <stddef.h> +#include <stdio.h> + +static int op(FILE *const f, struct interp *const i) +{ + varint32 flags, offset; + + if (varint32_read(f, &flags)) + { + fprintf(stderr, "%s: varint32_read flags failed\n", __func__); + return 1; + } + else if (varint32_read(f, &offset)) + { + fprintf(stderr, "%s: varint32_read offset failed\n", __func__); + return 1; + } + + return 0; +} + +int op_i32_load(struct interp *const i) +{ + return op(i->cfg.f, i); +} + +int check_i32_load(FILE *const f) +{ + return op(f, NULL); +} diff --git a/src/op/i32_store.c b/src/op/i32_store.c new file mode 100644 index 0000000..207a394 --- /dev/null +++ b/src/op/i32_store.c @@ -0,0 +1,34 @@ +#include <ops.h> +#include <interp.h> +#include <interp_private.h> +#include <wasm_types.h> +#include <stddef.h> +#include <stdio.h> + +static int op(FILE *const f, struct interp *const i) +{ + varint32 flags, offset; + + if (varint32_read(f, &flags)) + { + fprintf(stderr, "%s: varint32_read flags failed\n", __func__); + return 1; + } + else if (varint32_read(f, &offset)) + { + fprintf(stderr, "%s: varint32_read offset failed\n", __func__); + return 1; + } + + return 0; +} + +int op_i32_store(struct interp *const i) +{ + return op(i->cfg.f, i); +} + +int check_i32_store(FILE *const f) +{ + return op(f, NULL); +} diff --git a/src/op/i32_sub.c b/src/op/i32_sub.c new file mode 100644 index 0000000..24a0834 --- /dev/null +++ b/src/op/i32_sub.c @@ -0,0 +1,16 @@ +#include <ops.h> +#include <interp.h> +#include <interp_private.h> +#include <wasm_types.h> +#include <stddef.h> +#include <stdio.h> + +int op_i32_sub(struct interp *const i) +{ + return -1; +} + +int check_i32_sub(FILE *const f) +{ + return 0; +} diff --git a/src/op/i64_const.c b/src/op/i64_const.c new file mode 100644 index 0000000..c2f1592 --- /dev/null +++ b/src/op/i64_const.c @@ -0,0 +1,29 @@ +#include <ops.h> +#include <interp.h> +#include <interp_private.h> +#include <wasm_types.h> +#include <stddef.h> +#include <stdio.h> + +static int op(FILE *const f, struct interp *const i) +{ + varint64 value; + + if (varint64_read(f, &value)) + { + fprintf(stderr, "%s: varint32_read failed\n", __func__); + return -1; + } + + return 0; +} + +int op_i64_const(struct interp *const i) +{ + return op(i->cfg.f, i); +} + +int check_i64_const(FILE *const f) +{ + return op(f, NULL); +} diff --git a/src/op/if.c b/src/op/if.c new file mode 100644 index 0000000..526c8f5 --- /dev/null +++ b/src/op/if.c @@ -0,0 +1,27 @@ +#include <ops.h> +#include <interp.h> +#include <interp_private.h> +#include <wasm_types.h> + +static int op(FILE *const f, struct interp *const i) +{ + varint7 sig; + + if (varint7_read(f, &sig)) + { + fprintf(stderr, "%s: varint7_read failed\n", __func__); + return -1; + } + + return 0; +} + +int op_if(struct interp *const i) +{ + return op(i->cfg.f, i); +} + +int check_if(FILE *const f) +{ + return op(f, NULL); +} diff --git a/src/op/loop.c b/src/op/loop.c new file mode 100644 index 0000000..b7ea2b3 --- /dev/null +++ b/src/op/loop.c @@ -0,0 +1,27 @@ +#include <ops.h> +#include <interp.h> +#include <interp_private.h> +#include <wasm_types.h> + +static int op(FILE *const f, struct interp *const i) +{ + varint7 sig; + + if (varint7_read(f, &sig)) + { + fprintf(stderr, "%s: varint7_read failed\n", __func__); + return -1; + } + + return 0; +} + +int op_loop(struct interp *const i) +{ + return op(i->cfg.f, i); +} + +int check_loop(FILE *const f) +{ + return op(f, NULL); +} diff --git a/src/op/nop.c b/src/op/nop.c new file mode 100644 index 0000000..89bd895 --- /dev/null +++ b/src/op/nop.c @@ -0,0 +1,13 @@ +#include <ops.h> +#include <interp.h> +#include <interp_private.h> + +int op_nop(struct interp *const i) +{ + return 0; +} + +int check_nop(FILE *const f) +{ + return 0; +} diff --git a/src/op/return.c b/src/op/return.c new file mode 100644 index 0000000..84ac408 --- /dev/null +++ b/src/op/return.c @@ -0,0 +1,13 @@ +#include <ops.h> +#include <interp.h> +#include <stdio.h> + +int op_return(struct interp *const i) +{ + return -1; +} + +int check_return(FILE *const f) +{ + return 0; +} diff --git a/src/op/set_global.c b/src/op/set_global.c new file mode 100644 index 0000000..9443323 --- /dev/null +++ b/src/op/set_global.c @@ -0,0 +1,29 @@ +#include <ops.h> +#include <interp.h> +#include <interp_private.h> +#include <wasm_types.h> +#include <stddef.h> +#include <stdio.h> + +static int op(FILE *const f, struct interp *const i) +{ + varuint32 global_index; + + if (varuint32_read(f, &global_index)) + { + fprintf(stderr, "%s: varuint32_read failed\n", __func__); + return 1; + } + + return 0; +} + +int op_set_global(struct interp *const i) +{ + return op(i->cfg.f, i); +} + +int check_set_global(FILE *const f) +{ + return op(f, NULL); +} diff --git a/src/op/set_local.c b/src/op/set_local.c new file mode 100644 index 0000000..8424713 --- /dev/null +++ b/src/op/set_local.c @@ -0,0 +1,29 @@ +#include <ops.h> +#include <interp.h> +#include <interp_private.h> +#include <wasm_types.h> +#include <stddef.h> +#include <stdio.h> + +static int op(FILE *const f, struct interp *const i) +{ + varuint32 local_index; + + if (varuint32_read(f, &local_index)) + { + fprintf(stderr, "%s: varuint32_read failed\n", __func__); + return 1; + } + + return 0; +} + +int op_set_local(struct interp *const i) +{ + return op(i->cfg.f, i); +} + +int check_set_local(FILE *const f) +{ + return op(f, NULL); +} diff --git a/src/op/tee_local.c b/src/op/tee_local.c new file mode 100644 index 0000000..8b11fd8 --- /dev/null +++ b/src/op/tee_local.c @@ -0,0 +1,29 @@ +#include <ops.h> +#include <interp.h> +#include <interp_private.h> +#include <wasm_types.h> +#include <stddef.h> +#include <stdio.h> + +static int op(FILE *const f, struct interp *const i) +{ + varuint32 local_index; + + if (varuint32_read(f, &local_index)) + { + fprintf(stderr, "%s: varuint32_read failed\n", __func__); + return 1; + } + + return 0; +} + +int op_tee_local(struct interp *const i) +{ + return op(i->cfg.f, i); +} + +int check_tee_local(FILE *const f) +{ + return op(f, NULL); +} diff --git a/src/op/unreachable.c b/src/op/unreachable.c new file mode 100644 index 0000000..c343052 --- /dev/null +++ b/src/op/unreachable.c @@ -0,0 +1,17 @@ +#include <ops.h> +#include <interp.h> +#include <interp_private.h> +#include <stdbool.h> +#include <stdio.h> + +int op_unreachable(struct interp *const i) +{ + i->exception = "Unreachable instruction"; + i->exit = true; + return 1; +} + +int check_unreachable(FILE *const f) +{ + return 0; +} |
