summaryrefslogtreecommitdiff
path: root/src/wasm-binary.h
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-05-12 17:18:55 -0700
committerAlon Zakai <alonzakai@gmail.com>2016-05-12 17:18:55 -0700
commitf518f097c80c0659fbacf11fe12f89955093282b (patch)
treed26db91c5767989b3f824a0bbcf30a02259fb656 /src/wasm-binary.h
parentd84fd5be60d4ead6bc9fbb3f27a710bef0c688c8 (diff)
parentc8293a3f9112ad486f6f3639fc5680d73e7559ca (diff)
downloadbinaryen-f518f097c80c0659fbacf11fe12f89955093282b.tar.gz
binaryen-f518f097c80c0659fbacf11fe12f89955093282b.tar.bz2
binaryen-f518f097c80c0659fbacf11fe12f89955093282b.zip
Merge pull request #488 from WebAssembly/error_reporting
Better error reporting
Diffstat (limited to 'src/wasm-binary.h')
-rw-r--r--src/wasm-binary.h18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/wasm-binary.h b/src/wasm-binary.h
index 406be3ef7..1fe3ef26a 100644
--- a/src/wasm-binary.h
+++ b/src/wasm-binary.h
@@ -32,6 +32,7 @@
#include "asm_v_wasm.h"
#include "wasm-builder.h"
#include "ast_utils.h"
+#include "parsing.h"
#include "wasm-validator.h"
namespace wasm {
@@ -1164,14 +1165,13 @@ class WasmBinaryBuilder {
Module& wasm;
MixedArena& allocator;
std::vector<char>& input;
- std::function<void ()> onError;
bool debug;
size_t pos = 0;
int32_t startIndex = -1;
public:
- WasmBinaryBuilder(Module& wasm, std::vector<char>& input, std::function<void ()> onError, bool debug) : wasm(wasm), allocator(wasm.allocator), input(input), onError(onError), debug(debug) {}
+ WasmBinaryBuilder(Module& wasm, std::vector<char>& input, bool debug) : wasm(wasm), allocator(wasm.allocator), input(input), debug(debug) {}
void read() {
@@ -1226,7 +1226,7 @@ public:
}
uint8_t getInt8() {
- if (!more()) onError();
+ if (!more()) throw ParseException("unexpected end of input");
if (debug) std::cerr << "getInt8: " << (int)(uint8_t)input[pos] << " (at " << pos << ")" << std::endl;
return input[pos++];
}
@@ -1330,27 +1330,27 @@ public:
void verifyInt8(int8_t x) {
int8_t y = getInt8();
- if (x != y) onError();
+ if (x != y) throw ParseException("surprising value", 0, pos);
}
void verifyInt16(int16_t x) {
int16_t y = getInt16();
- if (x != y) onError();
+ if (x != y) throw ParseException("surprising value", 0, pos);
}
void verifyInt32(int32_t x) {
int32_t y = getInt32();
- if (x != y) onError();
+ if (x != y) throw ParseException("surprising value", 0, pos);
}
void verifyInt64(int64_t x) {
int64_t y = getInt64();
- if (x != y) onError();
+ if (x != y) throw ParseException("surprising value", 0, pos);
}
void verifyFloat32(float x) {
float y = getFloat32();
- if (x != y) onError();
+ if (x != y) throw ParseException("surprising value", 0, pos);
}
void verifyFloat64(double x) {
double y = getFloat64();
- if (x != y) onError();
+ if (x != y) throw ParseException("surprising value", 0, pos);
}
void ungetInt8() {