[PATCH] D57332: [RISCV] Allow parsing of bare symbols with offsets
Lewis Revill via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 28 08:19:23 PST 2019
lewis-revill created this revision.
lewis-revill added a reviewer: asb.
Herald added subscribers: llvm-commits, jocewei, PkmX, rkruppe, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, kito-cheng, niosHD, sabuasal, apazos, simoncook, johnrusso, rbar.
This patch allows symbols followed by an expression for an offset to be parsed as bare symbols.
Repository:
rL LLVM
https://reviews.llvm.org/D57332
Files:
lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
test/MC/RISCV/rvi-pseudos.s
Index: test/MC/RISCV/rvi-pseudos.s
===================================================================
--- test/MC/RISCV/rvi-pseudos.s
+++ test/MC/RISCV/rvi-pseudos.s
@@ -26,3 +26,8 @@
# CHECK: auipc a4, %pcrel_hi(f1)
# CHECK: addi a4, a4, %pcrel_lo(.Lpcrel_hi4)
lla a4, f1
+
+# CHECK: .Lpcrel_hi5:
+# CHECK: auipc a5, %pcrel_hi(a_symbol+2040)
+# CHECK: addi a5, a5, %pcrel_lo(.Lpcrel_hi5)
+lla a5, a_symbol + (0xFF << 3)
Index: lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
===================================================================
--- lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
+++ lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
@@ -1106,6 +1106,24 @@
MCSymbol *Sym = getContext().getOrCreateSymbol(Identifier);
Res = MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_None, getContext());
+
+ MCBinaryExpr::Opcode Opcode;
+ switch (getLexer().getKind()) {
+ default:
+ Operands.push_back(RISCVOperand::createImm(Res, S, E, isRV64()));
+ return MatchOperand_Success;
+ case AsmToken::Plus:
+ Opcode = MCBinaryExpr::Add;
+ break;
+ case AsmToken::Minus:
+ Opcode = MCBinaryExpr::Sub;
+ break;
+ }
+
+ const MCExpr *Expr;
+ if (getParser().parseExpression(Expr))
+ return MatchOperand_ParseFail;
+ Res = MCBinaryExpr::create(Opcode, Res, Expr, getContext());
Operands.push_back(RISCVOperand::createImm(Res, S, E, isRV64()));
return MatchOperand_Success;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57332.183871.patch
Type: text/x-patch
Size: 1416 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190128/bccc3b6d/attachment-0001.bin>
More information about the llvm-commits
mailing list