[PATCH] D98519: [M68k] Add support for Motorola literal syntax to AsmParser
Ricky Taylor via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 2 05:52:14 PDT 2021
ricky26 created this revision.
Herald added a subscriber: hiraditya.
ricky26 updated this revision to Diff 332005.
ricky26 added a comment.
ricky26 published this revision for review.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Run clang-format
================
Comment at: llvm/include/llvm/MC/MCAsmInfo.h:449
+ // If true, use Motorola-style integers in Assembly (ex. $0ac).
+ bool UseMotorolaIntegers = false;
+
----------------
My apologies for intruding into a draft patch :)
Firstly, I don't believe there is anything wrong with introducing a field in MCAsmInfo.h and setting it in the appropriate target inherited version of it.
However, there seems to be previous precedent within MCAsmLexer.h to support a different class of Integers (`LexMasmIntegers`). So maybe the field could go directly into MCAsmLexer and could be set in AsmLexer/AsmParser as appropriate?
================
Comment at: llvm/include/llvm/MC/MCAsmInfo.h:449
+ // If true, use Motorola-style integers in Assembly (ex. $0ac).
+ bool UseMotorolaIntegers = false;
+
----------------
anirudhp wrote:
> My apologies for intruding into a draft patch :)
>
> Firstly, I don't believe there is anything wrong with introducing a field in MCAsmInfo.h and setting it in the appropriate target inherited version of it.
>
> However, there seems to be previous precedent within MCAsmLexer.h to support a different class of Integers (`LexMasmIntegers`). So maybe the field could go directly into MCAsmLexer and could be set in AsmLexer/AsmParser as appropriate?
>
Hi, there's no problem there. I mostly uploaded this early since it's a dependency for one of my other patches. Feedback is always welcome. :)
I think I might've seen `LexMasmIntegers` when I was initially implementing this but having just followed it through the code again, I can't see how to make it the default (for example, I'd expect `clang -cc1as`/`llvm-mc`/etc to use Motorola-style integers by default for M68k but not anything else).
I'm lament to add specific logic to determine that default in all of the front-ends but it looks like that's what is done with `LexMasmIntegers`.
I'll open this up for review proper now anyway.
These look like $00A0cf for hex and %001010101 for binary. They are used in Motorola assembly syntax.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D98519
Files:
llvm/include/llvm/MC/MCAsmInfo.h
llvm/lib/MC/MCParser/AsmLexer.cpp
Index: llvm/lib/MC/MCParser/AsmLexer.cpp
===================================================================
--- llvm/lib/MC/MCParser/AsmLexer.cpp
+++ llvm/lib/MC/MCParser/AsmLexer.cpp
@@ -421,6 +421,32 @@
return intToken(Result, Value);
}
+ // Motorola hex integers: $[0-0a-fA-F]+
+ if (MAI.shouldUseMotorolaIntegers() && CurPtr[-1] == '$') {
+ const char *NumStart = CurPtr;
+ while (isHexDigit(CurPtr[0]))
+ ++CurPtr;
+
+ APInt Result(128, 0);
+ if (StringRef(NumStart, CurPtr - NumStart).getAsInteger(16, Result))
+ return ReturnError(TokStart, "invalid hexadecimal number");
+
+ return intToken(StringRef(TokStart, CurPtr - TokStart), Result);
+ }
+
+ // Motorola binary integers: %[01]+
+ if (MAI.shouldUseMotorolaIntegers() && CurPtr[-1] == '%') {
+ const char *NumStart = CurPtr;
+ while (*CurPtr == '0' || *CurPtr == '1')
+ ++CurPtr;
+
+ APInt Result(128, 0);
+ if (StringRef(NumStart, CurPtr - NumStart).getAsInteger(2, Result))
+ return ReturnError(TokStart, "invalid binary number");
+
+ return intToken(StringRef(TokStart, CurPtr - TokStart), Result);
+ }
+
// Decimal integer: [1-9][0-9]*
if (CurPtr[-1] != '0' || CurPtr[0] == '.') {
unsigned Radix = doHexLookAhead(CurPtr, 10, LexMasmIntegers);
@@ -775,7 +801,13 @@
case '}': return AsmToken(AsmToken::RCurly, StringRef(TokStart, 1));
case '*': return AsmToken(AsmToken::Star, StringRef(TokStart, 1));
case ',': return AsmToken(AsmToken::Comma, StringRef(TokStart, 1));
- case '$': return AsmToken(AsmToken::Dollar, StringRef(TokStart, 1));
+ case '$':
+ if (MAI.shouldUseMotorolaIntegers() && isDigit(CurPtr[1])) {
+ ++CurPtr;
+ return LexDigit();
+ }
+
+ return AsmToken(AsmToken::Dollar, StringRef(TokStart, 1));
case '@': return AsmToken(AsmToken::At, StringRef(TokStart, 1));
case '\\': return AsmToken(AsmToken::BackSlash, StringRef(TokStart, 1));
case '=':
@@ -810,6 +842,12 @@
}
return AsmToken(AsmToken::Exclaim, StringRef(TokStart, 1));
case '%':
+ if (MAI.shouldUseMotorolaIntegers() &&
+ (CurPtr[1] == '0' || CurPtr[1] == '1')) {
+ ++CurPtr;
+ return LexDigit();
+ }
+
if (MAI.hasMipsExpressions()) {
AsmToken::TokenKind Operator;
unsigned OperatorLength;
Index: llvm/include/llvm/MC/MCAsmInfo.h
===================================================================
--- llvm/include/llvm/MC/MCAsmInfo.h
+++ llvm/include/llvm/MC/MCAsmInfo.h
@@ -445,6 +445,9 @@
// %hi(), and similar unary operators.
bool HasMipsExpressions = false;
+ // If true, use Motorola-style integers in Assembly (ex. $0ac).
+ bool UseMotorolaIntegers = false;
+
// If true, emit function descriptor symbol on AIX.
bool NeedsFunctionDescriptors = false;
@@ -733,6 +736,7 @@
void setRelaxELFRelocations(bool V) { RelaxELFRelocations = V; }
bool hasMipsExpressions() const { return HasMipsExpressions; }
bool needsFunctionDescriptors() const { return NeedsFunctionDescriptors; }
+ bool shouldUseMotorolaIntegers() const { return UseMotorolaIntegers; }
};
} // end namespace llvm
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98519.332005.patch
Type: text/x-patch
Size: 3128 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210402/b2bb3855/attachment.bin>
More information about the llvm-commits
mailing list