summaryrefslogtreecommitdiff
path: root/src/parsing.h
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-02-01 14:08:54 -0800
committerAlon Zakai <alonzakai@gmail.com>2016-02-02 19:20:40 -0800
commit26e30285dd5b91742feb18dd6b924e359dae8901 (patch)
tree124020f46d4b298ddccc707cea71e71faee215cb /src/parsing.h
parent1eb620220ba91257d080721f194874960f4fb5fe (diff)
downloadbinaryen-26e30285dd5b91742feb18dd6b924e359dae8901.tar.gz
binaryen-26e30285dd5b91742feb18dd6b924e359dae8901.tar.bz2
binaryen-26e30285dd5b91742feb18dd6b924e359dae8901.zip
save int bits in Literals, only bitcast to float/double on explicit request
Diffstat (limited to 'src/parsing.h')
-rw-r--r--src/parsing.h39
1 files changed, 18 insertions, 21 deletions
diff --git a/src/parsing.h b/src/parsing.h
index 1ea0ec254..faa4ad8cb 100644
--- a/src/parsing.h
+++ b/src/parsing.h
@@ -29,12 +29,12 @@ namespace wasm {
Expression* parseConst(cashew::IString s, WasmType type, MixedArena& allocator) {
const char *str = s.str;
auto ret = allocator.alloc<Const>();
- ret->type = ret->value.type = type;
+ ret->type = type;
if (isWasmTypeFloat(type)) {
if (s == INFINITY_) {
switch (type) {
- case f32: ret->value.f32 = std::numeric_limits<float>::infinity(); break;
- case f64: ret->value.f64 = std::numeric_limits<double>::infinity(); break;
+ case f32: ret->value = Literal(std::numeric_limits<float>::infinity()); break;
+ case f64: ret->value = Literal(std::numeric_limits<double>::infinity()); break;
default: return nullptr;
}
//std::cerr << "make constant " << str << " ==> " << ret->value << '\n';
@@ -42,8 +42,8 @@ Expression* parseConst(cashew::IString s, WasmType type, MixedArena& allocator)
}
if (s == NEG_INFINITY) {
switch (type) {
- case f32: ret->value.f32 = -std::numeric_limits<float>::infinity(); break;
- case f64: ret->value.f64 = -std::numeric_limits<double>::infinity(); break;
+ case f32: ret->value = Literal(-std::numeric_limits<float>::infinity()); break;
+ case f64: ret->value = Literal(-std::numeric_limits<double>::infinity()); break;
default: return nullptr;
}
//std::cerr << "make constant " << str << " ==> " << ret->value << '\n';
@@ -51,8 +51,8 @@ Expression* parseConst(cashew::IString s, WasmType type, MixedArena& allocator)
}
if (s == NAN_) {
switch (type) {
- case f32: ret->value.f32 = std::nan(""); break;
- case f64: ret->value.f64 = std::nan(""); break;
+ case f32: ret->value = Literal(float(std::nan(""))); break;
+ case f64: ret->value = Literal(double(std::nan(""))); break;
default: return nullptr;
}
//std::cerr << "make constant " << str << " ==> " << ret->value << '\n';
@@ -80,8 +80,7 @@ Expression* parseConst(cashew::IString s, WasmType type, MixedArena& allocator)
}
if (negative) pattern |= 0x80000000U;
if (!isnan(bit_cast<float>(pattern))) pattern |= 1U;
- ret->value.f32 = bit_cast<float>(pattern);
- assert(isnan(ret->value.f32));
+ ret->value = Literal(bit_cast<float>(pattern)); // XXX
break;
}
case f64: {
@@ -95,8 +94,7 @@ Expression* parseConst(cashew::IString s, WasmType type, MixedArena& allocator)
}
if (negative) pattern |= 0x8000000000000000ULL;
if (!isnan(bit_cast<double>(pattern))) pattern |= 1ULL;
- ret->value.f64 = bit_cast<double>(pattern);
- assert(isnan(ret->value.f64));
+ ret->value = Literal(bit_cast<double>(pattern)); // XXX
break;
}
default: return nullptr;
@@ -106,8 +104,8 @@ Expression* parseConst(cashew::IString s, WasmType type, MixedArena& allocator)
}
if (s == NEG_NAN) {
switch (type) {
- case f32: ret->value.f32 = -std::nan(""); break;
- case f64: ret->value.f64 = -std::nan(""); break;
+ case f32: ret->value = Literal(float(-std::nan(""))); break;
+ case f64: ret->value = Literal(double(-std::nan(""))); break;
default: return nullptr;
}
//std::cerr << "make constant " << str << " ==> " << ret->value << '\n';
@@ -122,12 +120,12 @@ Expression* parseConst(cashew::IString s, WasmType type, MixedArena& allocator)
std::istringstream istr(str);
uint32_t temp;
istr >> std::hex >> temp;
- ret->value.i32 = negative ? -temp : temp;
+ ret->value = Literal(negative ? -temp : temp);
} else {
std::istringstream istr(str);
int32_t temp;
istr >> temp;
- ret->value.i32 = temp;
+ ret->value = Literal(temp);
}
break;
}
@@ -138,29 +136,28 @@ Expression* parseConst(cashew::IString s, WasmType type, MixedArena& allocator)
std::istringstream istr(str);
uint64_t temp;
istr >> std::hex >> temp;
- ret->value.i64 = negative ? -temp : temp;
+ ret->value = Literal(negative ? -temp : temp);
} else {
std::istringstream istr(str);
int64_t temp;
istr >> temp;
- ret->value.i64 = temp;
+ ret->value = Literal(temp);
}
break;
}
case f32: {
char *end;
- ret->value.f32 = strtof(str, &end);
- assert(!isnan(ret->value.f32));
+ ret->value = Literal(strtof(str, &end));
break;
}
case f64: {
char *end;
- ret->value.f64 = strtod(str, &end);
- assert(!isnan(ret->value.f64));
+ ret->value = Literal(strtod(str, &end));
break;
}
default: return nullptr;
}
+ assert(ret->value.type == type);
//std::cerr << "make constant " << str << " ==> " << ret->value << '\n';
return ret;
}