[WebAssembly] Assembler: Allow offsets and p2align in symbol load.

Reviewers: sbc100

Subscribers: dschuff, jgravelle-google, aheejin, sunfish, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D63951

llvm-svn: 364682
This commit is contained in:
Wouter van Oortmerssen 2019-06-28 20:31:13 +00:00
parent 34f2e2f14b
commit d3dc642675
2 changed files with 12 additions and 6 deletions

View File

@ -344,9 +344,7 @@ public:
Parser.Lex();
}
bool parseOperandStartingWithInteger(bool IsNegative, OperandVector &Operands,
StringRef InstName) {
parseSingleInteger(IsNegative, Operands);
bool checkForP2AlignIfLoadStore(OperandVector &Operands, StringRef InstName) {
// FIXME: there is probably a cleaner way to do this.
auto IsLoadStore = InstName.find(".load") != StringRef::npos ||
InstName.find(".store") != StringRef::npos;
@ -471,11 +469,13 @@ public:
// Assume this identifier is a label.
const MCExpr *Val;
SMLoc End;
if (Parser.parsePrimaryExpr(Val, End))
if (Parser.parseExpression(Val, End))
return error("Cannot parse symbol: ", Lexer.getTok());
Operands.push_back(make_unique<WebAssemblyOperand>(
WebAssemblyOperand::Symbol, Id.getLoc(), Id.getEndLoc(),
WebAssemblyOperand::SymOp{Val}));
if (checkForP2AlignIfLoadStore(Operands, Name))
return true;
}
break;
}
@ -483,11 +483,13 @@ public:
Parser.Lex();
if (Lexer.isNot(AsmToken::Integer))
return error("Expected integer instead got: ", Lexer.getTok());
if (parseOperandStartingWithInteger(true, Operands, Name))
parseSingleInteger(true, Operands);
if (checkForP2AlignIfLoadStore(Operands, Name))
return true;
break;
case AsmToken::Integer:
if (parseOperandStartingWithInteger(false, Operands, Name))
parseSingleInteger(false, Operands);
if (checkForP2AlignIfLoadStore(Operands, Name))
return true;
break;
case AsmToken::Real: {

View File

@ -81,6 +81,8 @@ test0:
end_block
end_try
i32.const .L.str
i32.load8_u .L.str+2
i32.load16_u .L.str:p2align=0
throw 0
.LBB0_5:
#i32.trunc_sat_f32_s
@ -170,6 +172,8 @@ test0:
# CHECK-NEXT: end_block
# CHECK-NEXT: end_try
# CHECK-NEXT: i32.const .L.str
# CHECK-NEXT: i32.load8_u .L.str+2
# CHECK-NEXT: i32.load16_u .L.str:p2align=0
# CHECK-NEXT: throw 0
# CHECK-NEXT: .LBB0_5:
# CHECK-NEXT: global.get __stack_pointer