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 @@ -89,9 +89,8 @@ } bool isToken() const override { return Kind == Token; } - bool isImm() const override { - return Kind == Integer || Kind == Float || Kind == Symbol; - } + bool isImm() const override { return Kind == Integer || Kind == Symbol; } + bool isFPImm() const { return Kind == Float; } bool isMem() const override { return false; } bool isReg() const override { return false; } bool isBrList() const { return Kind == BrList; } @@ -118,12 +117,18 @@ assert(N == 1 && "Invalid number of operands!"); if (Kind == Integer) Inst.addOperand(MCOperand::createImm(Int.Val)); - else if (Kind == Float) - Inst.addOperand(MCOperand::createFPImm(Flt.Val)); else if (Kind == Symbol) Inst.addOperand(MCOperand::createExpr(Sym.Exp)); else - llvm_unreachable("Should be immediate or symbol!"); + llvm_unreachable("Should be integer immediate or symbol!"); + } + + void addFPImmOperands(MCInst &Inst, unsigned N) const { + assert(N == 1 && "Invalid number of operands!"); + if (Kind == Float) + Inst.addOperand(MCOperand::createFPImm(Flt.Val)); + else + llvm_unreachable("Should be float immediate!"); } void addBrListOperands(MCInst &Inst, unsigned N) const { Index: llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrInfo.td =================================================================== --- llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrInfo.td +++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrInfo.td @@ -118,6 +118,17 @@ // WebAssembly-specific Operands. //===----------------------------------------------------------------------===// +// Default Operand has AsmOperandClass "Imm" which is for integers (and +// symbols), so specialize one for floats: +def FPImmAsmOperand : AsmOperandClass { + let Name = "FPImm"; + let PredicateMethod = "isFPImm"; +} + +class FPOperand : Operand { + AsmOperandClass ParserMatchClass = FPImmAsmOperand; +} + let OperandNamespace = "WebAssembly" in { let OperandType = "OPERAND_BASIC_BLOCK" in @@ -136,10 +147,10 @@ def i64imm_op : Operand; let OperandType = "OPERAND_F32IMM" in -def f32imm_op : Operand; +def f32imm_op : FPOperand; let OperandType = "OPERAND_F64IMM" in -def f64imm_op : Operand; +def f64imm_op : FPOperand; let OperandType = "OPERAND_VEC_I8IMM" in def vec_i8imm_op : Operand; Index: llvm/trunk/test/MC/WebAssembly/basic-assembly-errors.s =================================================================== --- llvm/trunk/test/MC/WebAssembly/basic-assembly-errors.s +++ llvm/trunk/test/MC/WebAssembly/basic-assembly-errors.s @@ -1,5 +1,9 @@ # RUN: not llvm-mc -triple=wasm32-unknown-unknown -mattr=+simd128,+nontrapping-fptoint,+exception-handling < %s 2>&1 | FileCheck %s +# CHECK: invalid operand for instruction +# (must be 0.0 or similar) + f32.const 0 + # CHECK: End of block construct with no start: end_try end_try test0: