aboutsummaryrefslogtreecommitdiff
path: root/tools/parse_module.c
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/parse_module.c
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/parse_module.c')
-rw-r--r--tools/parse_module.c45
1 files changed, 12 insertions, 33 deletions
diff --git a/tools/parse_module.c b/tools/parse_module.c
index 75329f8..3f9895c 100644
--- a/tools/parse_module.c
+++ b/tools/parse_module.c
@@ -2,39 +2,11 @@
#include "wasm_compile.h"
#include "wasm.h"
-static inline int is_valid_valtype(char value_type)
-{
- if (value_type == VALTYPE_I32)
- return 1;
-
- if (value_type == VALTYPE_I64 ||
- value_type == VALTYPE_F32 ||
- value_type == VALTYPE_F64)
- PRERR("Only type i32 is recognized for now");
-
- return -1;
-
- /* return */
- /* value_type == VALTYPE_I32 || */
- /* value_type == VALTYPE_I64 || */
- /* value_type == VALTYPE_F32 || */
- /* value_type == VALTYPE_F64; */
-}
-
-static inline int is_valid_exportdesc(char desc)
-{
- return
- desc == EXPORT_FUNCIDX ||
- desc == EXPORT_TABLEIDX ||
- desc == EXPORT_MEMIDX ||
- desc == EXPORT_GLOBALIDX;
-}
-
-int leb_u32(FILE *handle, uint32_t *result)
+int leb_32(FILE *handle, uint32_t *result, bool with_sign)
{
int i, j;
int encoded[5];
- uint64_t decoded;
+ int64_t decoded;
for (i = 0; i < 5; i++) {
encoded[i] = fgetc(handle);
@@ -53,12 +25,17 @@ int leb_u32(FILE *handle, uint32_t *result)
}
}
- decoded = 0;
+ if (with_sign && encoded[i] & (1 << 6))
+ decoded = -1;
+ else
+ decoded = 0;
for (j = i; j >= 0; j--)
decoded = (decoded << 7) | (encoded[j] & 0x7F);
- if (decoded > UINT32_MAX) {
+ if ((with_sign && decoded > INT32_MAX) ||
+ (with_sign && decoded < INT32_MIN) ||
+ (!with_sign && decoded > UINT32_MAX)) {
PRERR(MSG_BAD_NUM_ENC);
return -1;
}
@@ -105,6 +82,8 @@ void free_module(struct module *module)
free(module->exports);
+ free_targets(module->targets);
+
free(module);
}
@@ -602,7 +581,7 @@ struct module *parse_module(FILE *handle)
/* check magic number */
if (memcmp(initial, magic, 4)) {
- PRERR("Bad magic number");
+ PRERR("Bad magic number\n");
goto fail;
}