summaryrefslogtreecommitdiff
path: root/src/wast-parser.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/wast-parser.cc')
-rw-r--r--src/wast-parser.cc64
1 files changed, 36 insertions, 28 deletions
diff --git a/src/wast-parser.cc b/src/wast-parser.cc
index 00c95c81..79126431 100644
--- a/src/wast-parser.cc
+++ b/src/wast-parser.cc
@@ -223,8 +223,6 @@ bool IsCommand(TokenTypePair pair) {
case TokenType::AssertMalformed:
case TokenType::AssertReturn:
case TokenType::AssertReturnFunc:
- case TokenType::AssertReturnArithmeticNan:
- case TokenType::AssertReturnCanonicalNan:
case TokenType::AssertTrap:
case TokenType::AssertUnlinkable:
case TokenType::Get:
@@ -1654,7 +1652,7 @@ Result WastParser::ParsePlainInstr(std::unique_ptr<Expr>* out_expr) {
case TokenType::Const: {
Const const_;
- CHECK_RESULT(ParseConst(&const_));
+ CHECK_RESULT(ParseConst(&const_, ConstType::Normal));
out_expr->reset(new ConstExpr(const_, loc));
break;
}
@@ -2004,7 +2002,24 @@ Result WastParser::ParseSimdV128Const(Const* const_, TokenType token_type) {
return Result::Ok;
}
-Result WastParser::ParseConst(Const* const_) {
+Result WastParser::ParseExpectedNan(ExpectedNan* expected) {
+ WABT_TRACE(ParseExpectedNan);
+ TokenType token_type = Peek();
+ switch (token_type) {
+ case TokenType::NanArithmetic:
+ *expected = ExpectedNan::Arithmetic;
+ break;
+ case TokenType::NanCanonical:
+ *expected = ExpectedNan::Canonical;
+ break;
+ default:
+ return Result::Error;
+ }
+ Consume();
+ return Result::Ok;
+}
+
+Result WastParser::ParseConst(Const* const_, ConstType type) {
WABT_TRACE(ParseConst);
Token token = Consume();
Opcode opcode = token.opcode();
@@ -2027,6 +2042,9 @@ Result WastParser::ParseConst(Const* const_) {
end = sv.end();
break;
}
+ case TokenType::NanArithmetic:
+ case TokenType::NanCanonical:
+ break;
default:
return ErrorExpected({"a numeric literal"}, "123, -45, 6.7e8");
}
@@ -2048,11 +2066,21 @@ Result WastParser::ParseConst(Const* const_) {
case Opcode::F32Const:
const_->type = Type::F32;
+ if (type == ConstType::Expectation &&
+ ParseExpectedNan(&const_->expected) == Result::Ok) {
+ const_->is_expected_nan = true;
+ break;
+ }
result = ParseFloat(literal.type, s, end, &const_->f32_bits);
break;
case Opcode::F64Const:
const_->type = Type::F64;
+ if (type == ConstType::Expectation &&
+ ParseExpectedNan(&const_->expected) == Result::Ok) {
+ const_->is_expected_nan = true;
+ break;
+ }
result = ParseDouble(literal.type, s, end, &const_->f64_bits);
break;
@@ -2127,7 +2155,7 @@ Result WastParser::ParseHostRef(Const* const_) {
return Result::Ok;
}
-Result WastParser::ParseConstList(ConstVector* consts) {
+Result WastParser::ParseConstList(ConstVector* consts, ConstType type) {
WABT_TRACE(ParseConstList);
while (PeekMatchLpar(TokenType::Const) || PeekMatchLpar(TokenType::RefNull) ||
PeekMatchLpar(TokenType::RefHost)) {
@@ -2135,7 +2163,7 @@ Result WastParser::ParseConstList(ConstVector* consts) {
Const const_;
switch (Peek()) {
case TokenType::Const:
- CHECK_RESULT(ParseConst(&const_));
+ CHECK_RESULT(ParseConst(&const_, type));
break;
case TokenType::RefNull: {
auto token = Consume();
@@ -2435,12 +2463,6 @@ Result WastParser::ParseCommand(Script* script, CommandPtr* out_command) {
case TokenType::AssertReturnFunc:
return ParseAssertReturnFuncCommand(out_command);
- case TokenType::AssertReturnArithmeticNan:
- return ParseAssertReturnArithmeticNanCommand(out_command);
-
- case TokenType::AssertReturnCanonicalNan:
- return ParseAssertReturnCanonicalNanCommand(out_command);
-
case TokenType::AssertTrap:
return ParseAssertTrapCommand(out_command);
@@ -2487,7 +2509,7 @@ Result WastParser::ParseAssertReturnCommand(CommandPtr* out_command) {
EXPECT(AssertReturn);
auto command = MakeUnique<AssertReturnCommand>();
CHECK_RESULT(ParseAction(&command->action));
- CHECK_RESULT(ParseConstList(&command->expected));
+ CHECK_RESULT(ParseConstList(&command->expected, ConstType::Expectation));
EXPECT(Rpar);
*out_command = std::move(command);
return Result::Ok;
@@ -2504,20 +2526,6 @@ Result WastParser::ParseAssertReturnFuncCommand(CommandPtr* out_command) {
return Result::Ok;
}
-Result WastParser::ParseAssertReturnArithmeticNanCommand(
- CommandPtr* out_command) {
- WABT_TRACE(ParseAssertReturnArithmeticNanCommand);
- return ParseAssertActionCommand<AssertReturnArithmeticNanCommand>(
- TokenType::AssertReturnArithmeticNan, out_command);
-}
-
-Result WastParser::ParseAssertReturnCanonicalNanCommand(
- CommandPtr* out_command) {
- WABT_TRACE(ParseAssertReturnCanonicalNanCommand);
- return ParseAssertActionCommand<AssertReturnCanonicalNanCommand>(
- TokenType::AssertReturnCanonicalNan, out_command);
-}
-
Result WastParser::ParseAssertTrapCommand(CommandPtr* out_command) {
WABT_TRACE(ParseAssertTrapCommand);
EXPECT(Lpar);
@@ -2635,7 +2643,7 @@ Result WastParser::ParseAction(ActionPtr* out_action) {
auto action = MakeUnique<InvokeAction>(loc);
ParseVarOpt(&action->module_var, Var(last_module_index_, loc));
CHECK_RESULT(ParseQuotedText(&action->name));
- CHECK_RESULT(ParseConstList(&action->args));
+ CHECK_RESULT(ParseConstList(&action->args, ConstType::Normal));
*out_action = std::move(action);
break;
}