From 8ac323bb58c0e1891dea6492160939eb1b6bb1d2 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 29 Apr 2016 14:58:17 -0700 Subject: add wasm.cpp which does full type detection for blocks, and prepare for full type checking everywhere --- src/wasm.h | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/wasm.h') diff --git a/src/wasm.h b/src/wasm.h index b5dee81b8..b13011bae 100644 --- a/src/wasm.h +++ b/src/wasm.h @@ -833,11 +833,13 @@ public: Name name; ExpressionList list; - void finalize() { - if (list.size() > 0) { - type = list.back()->type; - } + // set the type of a block if you already know it + void finalize(WasmType type_) { + type = type; } + + // set the type of a block based on its contents. this scans the block, so it is not fast + void finalize(); }; class If : public SpecificExpression { @@ -877,6 +879,12 @@ public: Name name; Expression *value; Expression *condition; + + void finalize() { + if (condition) { + type = none; + } + } }; class Switch : public SpecificExpression { @@ -1022,7 +1030,6 @@ public: if (isRelational()) { type = i32; } else { - assert(left->type != unreachable && right->type != unreachable ? left->type == right->type : true); type = getReachableWasmType(left->type, right->type); } } -- cgit v1.2.3