forked from OSchip/llvm-project
[WebAssembly] Assembler: support negative float constants.
Reviewers: dschuff Subscribers: sbc100, jgravelle-google, aheejin, sunfish, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D64367 llvm-svn: 365802
This commit is contained in:
parent
af3dc759e7
commit
a617967d68
|
@ -349,6 +349,20 @@ public:
|
|||
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>(
|
||||
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 @@ public:
|
|||
}
|
||||
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 @@ public:
|
|||
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>(
|
||||
WebAssemblyOperand::Float, Tok.getLoc(), Tok.getEndLoc(),
|
||||
WebAssemblyOperand::FltOp{Val}));
|
||||
Parser.Lex();
|
||||
if (parseSingleFloat(false, Operands))
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
case AsmToken::LCurly: {
|
||||
|
|
|
@ -13,6 +13,7 @@ test0:
|
|||
# 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 @@ test0:
|
|||
# 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
|
||||
|
|
Loading…
Reference in New Issue