summaryrefslogtreecommitdiff
path: root/src/wasm-s-parser.h
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2015-11-08 15:36:35 -0800
committerAlon Zakai <alonzakai@gmail.com>2015-11-08 15:36:35 -0800
commit78a8208beb12e3a1640670dc9a8fc4ecbb4b6085 (patch)
tree92f41e100b6cadea544e02474296a481b83592c4 /src/wasm-s-parser.h
parentca0dc47b386a74e0493be77cfcbdcd7cd2fff61f (diff)
downloadbinaryen-78a8208beb12e3a1640670dc9a8fc4ecbb4b6085.tar.gz
binaryen-78a8208beb12e3a1640670dc9a8fc4ecbb4b6085.tar.bz2
binaryen-78a8208beb12e3a1640670dc9a8fc4ecbb4b6085.zip
nan fixes
Diffstat (limited to 'src/wasm-s-parser.h')
-rw-r--r--src/wasm-s-parser.h23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h
index 4f1cd09c7..672880fe0 100644
--- a/src/wasm-s-parser.h
+++ b/src/wasm-s-parser.h
@@ -709,16 +709,21 @@ private:
bool negative = str[0] == '-';
const char *positive = negative ? str + 1 : str;
if (positive[0] == '+') positive++;
- if (positive[0] == 'n' && positive[1] == 'a' && positive[2] == 'n' && positive[3] == ':') {
- assert(positive[4] == '0' && positive[5] == 'x');
+ if (positive[0] == 'n' && positive[1] == 'a' && positive[2] == 'n') {
+ const char * modifier = positive[3] == ':' ? positive + 4 : nullptr;
+ assert(modifier ? positive[4] == '0' && positive[5] == 'x' : 1);
switch (type) {
case f32: {
union {
uint32_t pattern;
float f;
} u;
- std::istringstream istr(positive+4);
- istr >> std::hex >> u.pattern;
+ if (modifier) {
+ std::istringstream istr(modifier);
+ istr >> std::hex >> u.pattern;
+ } else {
+ u.pattern = 0x7fc00000;
+ }
u.pattern |= 0x7f800000;
if (negative) u.pattern |= 0x80000000;
if (!isnan(u.f)) u.pattern |= 1;
@@ -731,8 +736,12 @@ private:
uint64_t pattern;
double d;
} u;
- std::istringstream istr(positive+4);
- istr >> std::hex >> u.pattern;
+ if (modifier) {
+ std::istringstream istr(modifier);
+ istr >> std::hex >> u.pattern;
+ } else {
+ u.pattern = 0x7ff8000000000000;
+ }
u.pattern |= 0x7ff0000000000000LL;
if (negative) u.pattern |= 0x8000000000000000LL;
if (!isnan(u.d)) u.pattern |= 1;
@@ -791,11 +800,13 @@ private:
case f32: {
char *end;
ret->value.f32 = strtof(str, &end);
+ assert(!isnan(ret->value.f32));
break;
}
case f64: {
char *end;
ret->value.f64 = strtod(str, &end);
+ assert(!isnan(ret->value.f64));
break;
}
default: onError();