Index: llvm/trunk/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp =================================================================== --- llvm/trunk/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp +++ llvm/trunk/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp @@ -349,6 +349,20 @@ Parser.Lex(); } + bool parseSingleFloat(bool IsNegative, OperandVector &Operands) { + auto &Flt = Lexer.getTok(); + double Val; + if (Flt.getString().getAsDouble(Val, false)) + return error("Cannot parse real: ", Flt); + if (IsNegative) + Val = -Val; + Operands.push_back(make_unique( + WebAssemblyOperand::Float, Flt.getLoc(), Flt.getEndLoc(), + WebAssemblyOperand::FltOp{Val})); + Parser.Lex(); + return false; + } + bool checkForP2AlignIfLoadStore(OperandVector &Operands, StringRef InstName) { // FIXME: there is probably a cleaner way to do this. auto IsLoadStore = InstName.find(".load") != StringRef::npos || @@ -486,11 +500,17 @@ } case AsmToken::Minus: Parser.Lex(); - if (Lexer.isNot(AsmToken::Integer)) - return error("Expected integer instead got: ", Lexer.getTok()); - parseSingleInteger(true, Operands); - if (checkForP2AlignIfLoadStore(Operands, Name)) - return true; + if (Lexer.is(AsmToken::Integer)) { + parseSingleInteger(true, Operands); + if (checkForP2AlignIfLoadStore(Operands, Name)) + return true; + } else if(Lexer.is(AsmToken::Real)) { + if (parseSingleFloat(true, Operands)) + return true; + } else { + return error("Expected numeric constant instead got: ", + Lexer.getTok()); + } break; case AsmToken::Integer: parseSingleInteger(false, Operands); @@ -498,13 +518,8 @@ return true; break; case AsmToken::Real: { - double Val; - if (Tok.getString().getAsDouble(Val, false)) - return error("Cannot parse real: ", Tok); - Operands.push_back(make_unique( - WebAssemblyOperand::Float, Tok.getLoc(), Tok.getEndLoc(), - WebAssemblyOperand::FltOp{Val})); - Parser.Lex(); + if (parseSingleFloat(false, Operands)) + return true; break; } case AsmToken::LCurly: { Index: llvm/trunk/test/MC/WebAssembly/basic-assembly.s =================================================================== --- llvm/trunk/test/MC/WebAssembly/basic-assembly.s +++ llvm/trunk/test/MC/WebAssembly/basic-assembly.s @@ -13,6 +13,7 @@ # Immediates: i32.const -1 f64.const 0x1.999999999999ap1 + f32.const -1.0 v128.const 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 v128.const 0, 1, 2, 3, 4, 5, 6, 7 # Indirect addressing: @@ -112,6 +113,7 @@ # CHECK-NEXT: local.set 2 # CHECK-NEXT: i32.const -1 # CHECK-NEXT: f64.const 0x1.999999999999ap1 +# CHECK-NEXT: f32.const -0x1p0 # CHECK-NEXT: v128.const 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 # CHECK-NEXT: v128.const 0, 1, 2, 3, 4, 5, 6, 7 # CHECK-NEXT: local.get 0