From fc222e23cae5f975e5dd51c2a2ec52c7e6d187ae Mon Sep 17 00:00:00 2001 From: Wouter van Oortmerssen Date: Fri, 28 Jun 2019 20:31:13 +0000 Subject: [PATCH] [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 --- .../Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp | 14 ++++++++------ llvm/test/MC/WebAssembly/basic-assembly.s | 4 ++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp index b891f88..c0abd11 100644 --- a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp +++ b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp @@ -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::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: { diff --git a/llvm/test/MC/WebAssembly/basic-assembly.s b/llvm/test/MC/WebAssembly/basic-assembly.s index c579c5e..404fa44 100644 --- a/llvm/test/MC/WebAssembly/basic-assembly.s +++ b/llvm/test/MC/WebAssembly/basic-assembly.s @@ -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 -- 2.7.4