From 69f0f91c03f593ea6b5c30515afdf33d5c7827fb Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 4 Nov 2015 21:46:48 -0800 Subject: infinity --- src/wasm-s-parser.h | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src/wasm-s-parser.h') diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index a49fa7bd5..26abdec8e 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -3,6 +3,7 @@ // Parses WebAssembly code in S-Expression format, as in .wast files. // +#include #include #include "wasm.h" @@ -30,7 +31,9 @@ IString MODULE("module"), TYPE("type"), CALL("call"), CALL_IMPORT("call_import"), - CALL_INDIRECT("call_indirect"); + CALL_INDIRECT("call_indirect"), + INFINITY_("infinity"), + NEG_INFINITY("-infinity"); // // An element in an S-Expression: a list or a string @@ -497,6 +500,24 @@ private: Expression* makeConst(Element& s, WasmType type) { auto ret = allocator.alloc(); ret->type = ret->value.type = type; + if (isWasmTypeFloat(type)) { + if (s[1]->str() == INFINITY_) { + switch (type) { + case f32: ret->value.f32 = std::numeric_limits::infinity(); break; + case f64: ret->value.f64 = std::numeric_limits::infinity(); break; + default: abort(); + } + return ret; + } + if (s[1]->str() == NEG_INFINITY) { + switch (type) { + case f32: ret->value.f32 = -std::numeric_limits::infinity(); break; + case f64: ret->value.f64 = -std::numeric_limits::infinity(); break; + default: abort(); + } + return ret; + } + } const char *str = s[1]->c_str(); std::istringstream istr(str); switch (type) { -- cgit v1.2.3