[PATCH] D38029: [AVR] Override ParseDirective
Leslie Zhai via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 19 01:52:20 PDT 2017
xiangzhai created this revision.
Herald added subscribers: kristof.beyls, aemerson.
Hi LLVM developers,
Motivation:
- avr-ld supports directive, relax.s testcase <https://github.com/xiangzhai/binutils-gdb/blob/master/ld/testsuite/ld-avr/relax.s#L12>
- arm-linux-gnu-ld supports that too, tls-gdlerelax.s testcase <https://github.com/xiangzhai/binutils-gdb/blob/master/ld/testsuite/ld-arm/tls-gdlerelax.s>
But:
$ llvm-mc -filetype=obj -triple=avr-unknown-linux -mcpu=atmega328p relax.s -o relax.o
relax.s:12:2: error: unknown directive
.word L2 - L1
^
So I simply override ParseDirective for `llvm/lib/Target/AVR/AsmParser/AVRAsmParser.cpp`, please review it, thanks a lot!
Regards,
Leslie Zhai
Repository:
rL LLVM
https://reviews.llvm.org/D38029
Files:
lib/Target/AVR/AsmParser/AVRAsmParser.cpp
test/MC/AVR/relocations.s
Index: test/MC/AVR/relocations.s
===================================================================
--- test/MC/AVR/relocations.s
+++ test/MC/AVR/relocations.s
@@ -73,3 +73,24 @@
; CHECK-NEXT: R_AVR_HH8_LDI_PM_NEG
ldi r25, -pm_hh8(foo)
+
+; CHECK-NEXT: R_AVR_LO8_LDI_GS
+ldi r17, lo8(gs(foo))
+
+; CHECK-NEXT: R_AVR_HI8_LDI_GS
+ldi r18, hi8(gs(foo))
+
+; CHECK-NEXT: R_AVR_16_PM
+.short foo
+
+; CHECK-NEXT: R_AVR_8
+.byte foo
+
+; CHECK-NEXT: R_AVR_8_LO8
+.byte lo8(foo)
+
+; CHECK-NEXT: R_AVR_8_HI8
+.byte hi8(foo)
+
+; CHECK-NEXT: R_AVR_8_HLO8
+.byte hlo8(foo)
Index: lib/Target/AVR/AsmParser/AVRAsmParser.cpp
===================================================================
--- lib/Target/AVR/AsmParser/AVRAsmParser.cpp
+++ lib/Target/AVR/AsmParser/AVRAsmParser.cpp
@@ -80,6 +80,8 @@
uint64_t const &ErrorInfo);
bool missingFeature(SMLoc const &Loc, uint64_t const &ErrorInfo);
+ bool parseLiteralValues(unsigned Size, SMLoc L);
+
public:
AVRAsmParser(const MCSubtargetInfo &STI, MCAsmParser &Parser,
const MCInstrInfo &MII, const MCTargetOptions &Options)
@@ -432,6 +434,11 @@
if (ModifierKind != AVRMCExpr::VK_AVR_None) {
Parser.Lex();
Parser.Lex(); // Eat modifier name and parenthesis
+ // FIXME: Not support gs(foo) so just eat gs.
+ if (Parser.getTok().getString() == "gs" &&
+ Parser.getTok().getKind() == AsmToken::Identifier) {
+ Parser.Lex();
+ }
} else {
return Error(Parser.getTok().getLoc(), "unknown modifier");
}
@@ -580,7 +587,33 @@
return false;
}
-bool AVRAsmParser::ParseDirective(llvm::AsmToken DirectiveID) { return true; }
+bool AVRAsmParser::ParseDirective(llvm::AsmToken DirectiveID) {
+ StringRef IDVal = DirectiveID.getIdentifier();
+ if (IDVal == ".word")
+ parseLiteralValues(4, DirectiveID.getLoc());
+ else if (IDVal == ".short")
+ parseLiteralValues(2, DirectiveID.getLoc());
+ else if (IDVal == ".byte")
+ parseLiteralValues(1, DirectiveID.getLoc());
+ return true;
+}
+
+bool AVRAsmParser::parseLiteralValues(unsigned Size, SMLoc L) {
+ MCAsmParser &Parser = getParser();
+ if (Parser.getTok().getKind() == AsmToken::Identifier &&
+ Parser.getLexer().peekTok().getKind() == AsmToken::LParen) {
+ const MCExpr *Value;
+ return Parser.parseExpression(Value);
+ }
+ auto parseOne = [&]() -> bool {
+ const MCExpr *Value;
+ if (Parser.parseExpression(Value))
+ return true;
+ Parser.getStreamer().EmitValue(Value, Size, L);
+ return false;
+ };
+ return (parseMany(parseOne));
+}
extern "C" void LLVMInitializeAVRAsmParser() {
RegisterMCAsmParser<AVRAsmParser> X(getTheAVRTarget());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38029.115805.patch
Type: text/x-patch
Size: 2678 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170919/0de1e973/attachment.bin>
More information about the llvm-commits
mailing list