From 52c18e60929b64285d4bb333f87482d954c9b2e0 Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Sun, 26 Nov 2023 22:43:30 +0100 Subject: First commit --- src/op/br_table.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/op/br_table.c (limited to 'src/op/br_table.c') 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 +#include +#include +#include +#include + +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); +} -- cgit v1.2.3