diff options
author | Alon Zakai <alonzakai@gmail.com> | 2015-11-06 19:52:03 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2015-11-06 19:52:03 -0800 |
commit | 80e27d2fcba39ef96f3043f79e0fd3fb9e92241d (patch) | |
tree | 4b02abe80f81839cd51030a88ceb5736e8785f14 | |
parent | 54cc7b3916c61a0fefd66455ed6de7efe6d317bd (diff) | |
download | binaryen-80e27d2fcba39ef96f3043f79e0fd3fb9e92241d.tar.gz binaryen-80e27d2fcba39ef96f3043f79e0fd3fb9e92241d.tar.bz2 binaryen-80e27d2fcba39ef96f3043f79e0fd3fb9e92241d.zip |
fix negative hex parsing
-rwxr-xr-x | check.py | 3 | ||||
-rw-r--r-- | src/wasm-s-parser.h | 34 |
2 files changed, 21 insertions, 16 deletions
@@ -82,9 +82,8 @@ print '\n[ checking wasm-shell spec testcases... ]\n' if len(requested) == 0: #spec_tests = [] # XXX [os.path.join('spec', t) for t in sorted(os.listdir(os.path.join('test', 'spec')))] # 'address' : filed issue, test looks invalid - # 'exports', 'int_literals' : has a "return" https://github.com/WebAssembly/spec/issues/164 # 'switch': todo once stable - spec_tests = [os.path.join('spec', t + '.wast') for t in ['conversions', 'endianness', 'f32_cmp', 'f32', 'f64_cmp', 'f64', 'float_exprs', 'forward', 'func_ptrs', 'functions', 'has_feature', 'i32', 'i64', 'imports', 'int_exprs', 'left-to-right', 'memory_redundancy', 'memory_trap', 'names', 'resizing', 'runaway-recursion', 'select', 'store_retval', 'traps']] + spec_tests = [os.path.join('spec', t + '.wast') for t in ['conversions', 'endianness', 'exports', 'f32_cmp', 'f32', 'f64_cmp', 'f64', 'float_exprs', 'forward', 'func_ptrs', 'functions', 'has_feature', 'i32', 'i64', 'imports', 'int_exprs', 'int_literals', 'left-to-right', 'memory_redundancy', 'memory_trap', 'names', 'resizing', 'runaway-recursion', 'select', 'store_retval', 'traps']] else: spec_tests = requested[:] diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index b9556bb3b..f3df437da 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -690,29 +690,35 @@ private: } switch (type) { case i32: { - std::istringstream istr(str); - int32_t temp; - if (str[0] == '0' && str[1] == 'x') { - uint32_t temp2; - istr >> std::hex >> temp2; - temp = temp2; + if ((str[0] == '0' && str[1] == 'x') || (str[0] == '-' && str[1] == '0' && str[2] == 'x')) { + bool negative = str[0] == '-'; + if (negative) str++; + std::istringstream istr(str); + uint32_t temp; + istr >> std::hex >> temp; + ret->value.i32 = negative ? -temp : temp; } else { + std::istringstream istr(str); + int32_t temp; istr >> temp; + ret->value.i32 = temp; } - ret->value.i32 = temp; break; } case i64: { - std::istringstream istr(str); - int64_t temp; - if (str[0] == '0' && str[1] == 'x') { - uint64_t temp2; - istr >> std::hex >> temp2; - temp = temp2; + if ((str[0] == '0' && str[1] == 'x') || (str[0] == '-' && str[1] == '0' && str[2] == 'x')) { + bool negative = str[0] == '-'; + if (negative) str++; + std::istringstream istr(str); + uint64_t temp; + istr >> std::hex >> temp; + ret->value.i64 = negative ? -temp : temp; } else { + std::istringstream istr(str); + int64_t temp; istr >> temp; + ret->value.i64 = temp; } - ret->value.i64 = temp; break; } case f32: { |