1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02:00

[M68k] Add support for Motorola literal syntax to AsmParser

These look like $00A0cf for hex and  %001010101 for binary. They are used in Motorola assembly syntax.

Differential Revision: https://reviews.llvm.org/D98519
This commit is contained in:
Ricky Taylor 2021-01-26 14:51:50 +00:00
parent 925535c5ef
commit fa9c348cc4
6 changed files with 62 additions and 1 deletions

View File

@ -449,6 +449,9 @@ protected:
// %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;
@ -740,6 +743,7 @@ public:
void setRelaxELFRelocations(bool V) { RelaxELFRelocations = V; }
bool hasMipsExpressions() const { return HasMipsExpressions; }
bool needsFunctionDescriptors() const { return NeedsFunctionDescriptors; }
bool shouldUseMotorolaIntegers() const { return UseMotorolaIntegers; }
};
} // end namespace llvm

View File

@ -53,6 +53,7 @@ protected: // Can only create subclasses.
bool LexMasmHexFloats = false;
bool LexMasmIntegers = false;
bool LexMasmStrings = false;
bool LexMotorolaIntegers = false;
bool UseMasmDefaultRadix = false;
unsigned DefaultRadix = 10;
AsmCommentConsumer *CommentConsumer = nullptr;
@ -171,6 +172,10 @@ public:
/// Set whether to lex masm-style string literals, such as 'Can''t find file'
/// and "This ""value"" not found".
void setLexMasmStrings(bool V) { LexMasmStrings = V; }
/// Set whether to lex Motorola-style integer literals, such as $deadbeef or
/// %01010110.
void setLexMotorolaIntegers(bool V) { LexMotorolaIntegers = V; }
};
} // end namespace llvm

View File

@ -33,6 +33,7 @@ using namespace llvm;
AsmLexer::AsmLexer(const MCAsmInfo &MAI) : MAI(MAI) {
AllowAtInIdentifier = !StringRef(MAI.getCommentString()).startswith("@");
LexMotorolaIntegers = MAI.shouldUseMotorolaIntegers();
}
AsmLexer::~AsmLexer() = default;
@ -422,6 +423,32 @@ AsmToken AsmLexer::LexDigit() {
return intToken(Result, Value);
}
// Motorola hex integers: $[0-9a-fA-F]+
if (LexMotorolaIntegers && 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 (LexMotorolaIntegers && 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);
@ -780,7 +807,12 @@ AsmToken AsmLexer::LexToken() {
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 (LexMotorolaIntegers && isHexDigit(*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 '=':
@ -815,6 +847,10 @@ AsmToken AsmLexer::LexToken() {
}
return AsmToken(AsmToken::Exclaim, StringRef(TokStart, 1));
case '%':
if (LexMotorolaIntegers && (*CurPtr == '0' || *CurPtr == '1')) {
return LexDigit();
}
if (MAI.hasMipsExpressions()) {
AsmToken::TokenKind Operator;
unsigned OperatorLength;

View File

@ -31,5 +31,6 @@ M68kELFMCAsmInfo::M68kELFMCAsmInfo(const Triple &T) {
// Exceptions handling
ExceptionsType = ExceptionHandling::DwarfCFI;
UseMotorolaIntegers = true;
CommentString = ";";
}

View File

@ -0,0 +1,10 @@
# RUN: llvm-mc -triple i386-unknown-unknown -motorola-integers %s | FileCheck %s
# CHECK: .set a, 2882400009
.set a, $aBcDeF09
# CHECK: .set b, 256
.set b, $0100
# CHECK: .set c, 10
.set c, %01010
# CHECK: .set d, 1
.set d, %1

View File

@ -173,6 +173,10 @@ static cl::opt<bool> LexMasmHexFloats(
"masm-hexfloats",
cl::desc("Enable MASM-style hex float initializers (3F800000r)"));
static cl::opt<bool> LexMotorolaIntegers(
"motorola-integers",
cl::desc("Enable binary and hex Motorola integers (%110 and $ABC)"));
static cl::opt<bool> NoExecStack("no-exec-stack",
cl::desc("File doesn't need an exec stack"));
@ -305,6 +309,7 @@ static int AssembleInput(const char *ProgName, const Target *TheTarget,
Parser->setTargetParser(*TAP);
Parser->getLexer().setLexMasmIntegers(LexMasmIntegers);
Parser->getLexer().setLexMasmHexFloats(LexMasmHexFloats);
Parser->getLexer().setLexMotorolaIntegers(LexMotorolaIntegers);
int Res = Parser->Run(NoInitialTextSection);