mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-26 21:32:10 +00:00
llvm-mc: More quoted identifier support.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77761 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
c32304e56e
commit
a6b3c5db2e
@ -24,3 +24,28 @@ foo:
|
|||||||
addl "b$c", %eax
|
addl "b$c", %eax
|
||||||
|
|
||||||
|
|
||||||
|
// CHECK: set "a 0", 11
|
||||||
|
.set "a 0", 11
|
||||||
|
// CHECK: .long 11
|
||||||
|
.long "a 0"
|
||||||
|
|
||||||
|
// CHECK: .section "a 1,a 2"
|
||||||
|
.section "a 1", "a 2"
|
||||||
|
|
||||||
|
// CHECK: .globl "a 3"
|
||||||
|
.globl "a 3"
|
||||||
|
|
||||||
|
// CHECK: .weak "a 4"
|
||||||
|
.weak "a 4"
|
||||||
|
|
||||||
|
// CHECK: .desc "a 5",1
|
||||||
|
.desc "a 5", 1
|
||||||
|
|
||||||
|
// CHECK: .comm "a 6",1
|
||||||
|
.comm "a 6", 1
|
||||||
|
|
||||||
|
// CHECK: .lcomm "a 7",1
|
||||||
|
.lcomm "a 7", 1
|
||||||
|
|
||||||
|
// CHECK: .lsym "a 8",1
|
||||||
|
.lsym "a 8", 1
|
||||||
|
@ -303,25 +303,22 @@ bool AsmParser::ParseBinOpRHS(unsigned Precedence, AsmExpr *&Res) {
|
|||||||
/// ::= Label* Directive ...Operands... EndOfStatement
|
/// ::= Label* Directive ...Operands... EndOfStatement
|
||||||
/// ::= Label* Identifier OperandList* EndOfStatement
|
/// ::= Label* Identifier OperandList* EndOfStatement
|
||||||
bool AsmParser::ParseStatement() {
|
bool AsmParser::ParseStatement() {
|
||||||
switch (Lexer.getKind()) {
|
if (Lexer.is(AsmToken::EndOfStatement)) {
|
||||||
default:
|
|
||||||
return TokError("unexpected token at start of statement");
|
|
||||||
case AsmToken::EndOfStatement:
|
|
||||||
Lexer.Lex();
|
Lexer.Lex();
|
||||||
return false;
|
return false;
|
||||||
case AsmToken::Identifier:
|
|
||||||
case AsmToken::String:
|
|
||||||
break;
|
|
||||||
// TODO: Recurse on local labels etc.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we have an identifier, handle it as the key symbol.
|
// Statements always start with an identifier.
|
||||||
AsmToken ID = Lexer.getTok();
|
AsmToken ID = Lexer.getTok();
|
||||||
SMLoc IDLoc = ID.getLoc();
|
SMLoc IDLoc = ID.getLoc();
|
||||||
StringRef IDVal = ID.getIdentifier();
|
StringRef IDVal;
|
||||||
|
if (ParseIdentifier(IDVal))
|
||||||
// Consume the identifier, see what is after it.
|
return TokError("unexpected token at start of statement");
|
||||||
switch (Lexer.Lex().getKind()) {
|
|
||||||
|
// FIXME: Recurse on local labels?
|
||||||
|
|
||||||
|
// See what kind of statement we have.
|
||||||
|
switch (Lexer.getKind()) {
|
||||||
case AsmToken::Colon: {
|
case AsmToken::Colon: {
|
||||||
// identifier ':' -> Label.
|
// identifier ':' -> Label.
|
||||||
Lexer.Lex();
|
Lexer.Lex();
|
||||||
@ -603,15 +600,30 @@ bool AsmParser::ParseAssignment(const StringRef &Name, bool IsDotSet) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// ParseIdentifier:
|
||||||
|
/// ::= identifier
|
||||||
|
/// ::= string
|
||||||
|
bool AsmParser::ParseIdentifier(StringRef &Res) {
|
||||||
|
if (Lexer.isNot(AsmToken::Identifier) &&
|
||||||
|
Lexer.isNot(AsmToken::String))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
Res = Lexer.getTok().getIdentifier();
|
||||||
|
|
||||||
|
Lexer.Lex(); // Consume the identifier token.
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/// ParseDirectiveSet:
|
/// ParseDirectiveSet:
|
||||||
/// ::= .set identifier ',' expression
|
/// ::= .set identifier ',' expression
|
||||||
bool AsmParser::ParseDirectiveSet() {
|
bool AsmParser::ParseDirectiveSet() {
|
||||||
if (Lexer.isNot(AsmToken::Identifier))
|
StringRef Name;
|
||||||
return TokError("expected identifier after '.set' directive");
|
|
||||||
|
|
||||||
StringRef Name = Lexer.getTok().getString();
|
if (ParseIdentifier(Name))
|
||||||
|
return TokError("expected identifier after '.set' directive");
|
||||||
|
|
||||||
if (Lexer.Lex().isNot(AsmToken::Comma))
|
if (Lexer.isNot(AsmToken::Comma))
|
||||||
return TokError("unexpected token in '.set'");
|
return TokError("unexpected token in '.set'");
|
||||||
Lexer.Lex();
|
Lexer.Lex();
|
||||||
|
|
||||||
@ -623,21 +635,24 @@ bool AsmParser::ParseDirectiveSet() {
|
|||||||
/// FIXME: This should actually parse out the segment, section, attributes and
|
/// FIXME: This should actually parse out the segment, section, attributes and
|
||||||
/// sizeof_stub fields.
|
/// sizeof_stub fields.
|
||||||
bool AsmParser::ParseDirectiveDarwinSection() {
|
bool AsmParser::ParseDirectiveDarwinSection() {
|
||||||
if (Lexer.isNot(AsmToken::Identifier))
|
StringRef SectionName;
|
||||||
|
|
||||||
|
if (ParseIdentifier(SectionName))
|
||||||
return TokError("expected identifier after '.section' directive");
|
return TokError("expected identifier after '.section' directive");
|
||||||
|
|
||||||
std::string Section = Lexer.getTok().getString();
|
std::string Section = SectionName;
|
||||||
Lexer.Lex();
|
|
||||||
|
// FIXME: This doesn't work, we lose quoting on things
|
||||||
|
|
||||||
// Accept a comma separated list of modifiers.
|
// Accept a comma separated list of modifiers.
|
||||||
while (Lexer.is(AsmToken::Comma)) {
|
while (Lexer.is(AsmToken::Comma)) {
|
||||||
Lexer.Lex();
|
Lexer.Lex(); // Consume the comma.
|
||||||
|
|
||||||
if (Lexer.isNot(AsmToken::Identifier))
|
StringRef ModifierName;
|
||||||
|
if (ParseIdentifier(ModifierName))
|
||||||
return TokError("expected identifier in '.section' directive");
|
return TokError("expected identifier in '.section' directive");
|
||||||
Section += ',';
|
Section += ',';
|
||||||
Section += Lexer.getTok().getString().str();
|
Section += ModifierName;
|
||||||
Lexer.Lex();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Lexer.isNot(AsmToken::EndOfStatement))
|
if (Lexer.isNot(AsmToken::EndOfStatement))
|
||||||
@ -910,11 +925,12 @@ bool AsmParser::ParseDirectiveAlign(bool IsPow2, unsigned ValueSize) {
|
|||||||
bool AsmParser::ParseDirectiveSymbolAttribute(MCStreamer::SymbolAttr Attr) {
|
bool AsmParser::ParseDirectiveSymbolAttribute(MCStreamer::SymbolAttr Attr) {
|
||||||
if (Lexer.isNot(AsmToken::EndOfStatement)) {
|
if (Lexer.isNot(AsmToken::EndOfStatement)) {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (Lexer.isNot(AsmToken::Identifier))
|
StringRef Name;
|
||||||
|
|
||||||
|
if (ParseIdentifier(Name))
|
||||||
return TokError("expected identifier in directive");
|
return TokError("expected identifier in directive");
|
||||||
|
|
||||||
MCSymbol *Sym = Ctx.GetOrCreateSymbol(Lexer.getTok().getString());
|
MCSymbol *Sym = Ctx.GetOrCreateSymbol(Name);
|
||||||
Lexer.Lex();
|
|
||||||
|
|
||||||
// If this is use of an undefined symbol then mark it external.
|
// If this is use of an undefined symbol then mark it external.
|
||||||
if (!Sym->getSection() && !Ctx.GetSymbolValue(Sym))
|
if (!Sym->getSection() && !Ctx.GetSymbolValue(Sym))
|
||||||
@ -938,13 +954,12 @@ bool AsmParser::ParseDirectiveSymbolAttribute(MCStreamer::SymbolAttr Attr) {
|
|||||||
/// ParseDirectiveDarwinSymbolDesc
|
/// ParseDirectiveDarwinSymbolDesc
|
||||||
/// ::= .desc identifier , expression
|
/// ::= .desc identifier , expression
|
||||||
bool AsmParser::ParseDirectiveDarwinSymbolDesc() {
|
bool AsmParser::ParseDirectiveDarwinSymbolDesc() {
|
||||||
if (Lexer.isNot(AsmToken::Identifier))
|
StringRef Name;
|
||||||
|
if (ParseIdentifier(Name))
|
||||||
return TokError("expected identifier in directive");
|
return TokError("expected identifier in directive");
|
||||||
|
|
||||||
// handle the identifier as the key symbol.
|
// Handle the identifier as the key symbol.
|
||||||
SMLoc IDLoc = Lexer.getLoc();
|
MCSymbol *Sym = Ctx.GetOrCreateSymbol(Name);
|
||||||
MCSymbol *Sym = Ctx.GetOrCreateSymbol(Lexer.getTok().getString());
|
|
||||||
Lexer.Lex();
|
|
||||||
|
|
||||||
if (Lexer.isNot(AsmToken::Comma))
|
if (Lexer.isNot(AsmToken::Comma))
|
||||||
return TokError("unexpected token in '.desc' directive");
|
return TokError("unexpected token in '.desc' directive");
|
||||||
@ -969,13 +984,13 @@ bool AsmParser::ParseDirectiveDarwinSymbolDesc() {
|
|||||||
/// ParseDirectiveComm
|
/// ParseDirectiveComm
|
||||||
/// ::= ( .comm | .lcomm ) identifier , size_expression [ , align_expression ]
|
/// ::= ( .comm | .lcomm ) identifier , size_expression [ , align_expression ]
|
||||||
bool AsmParser::ParseDirectiveComm(bool IsLocal) {
|
bool AsmParser::ParseDirectiveComm(bool IsLocal) {
|
||||||
if (Lexer.isNot(AsmToken::Identifier))
|
SMLoc IDLoc = Lexer.getLoc();
|
||||||
|
StringRef Name;
|
||||||
|
if (ParseIdentifier(Name))
|
||||||
return TokError("expected identifier in directive");
|
return TokError("expected identifier in directive");
|
||||||
|
|
||||||
// Handle the identifier as the key symbol.
|
// Handle the identifier as the key symbol.
|
||||||
SMLoc IDLoc = Lexer.getLoc();
|
MCSymbol *Sym = Ctx.GetOrCreateSymbol(Name);
|
||||||
MCSymbol *Sym = Ctx.GetOrCreateSymbol(Lexer.getTok().getString());
|
|
||||||
Lexer.Lex();
|
|
||||||
|
|
||||||
if (Lexer.isNot(AsmToken::Comma))
|
if (Lexer.isNot(AsmToken::Comma))
|
||||||
return TokError("unexpected token in directive");
|
return TokError("unexpected token in directive");
|
||||||
@ -1027,6 +1042,8 @@ bool AsmParser::ParseDirectiveComm(bool IsLocal) {
|
|||||||
/// ::= .zerofill segname , sectname [, identifier , size_expression [
|
/// ::= .zerofill segname , sectname [, identifier , size_expression [
|
||||||
/// , align_expression ]]
|
/// , align_expression ]]
|
||||||
bool AsmParser::ParseDirectiveDarwinZerofill() {
|
bool AsmParser::ParseDirectiveDarwinZerofill() {
|
||||||
|
// FIXME: Handle quoted names here.
|
||||||
|
|
||||||
if (Lexer.isNot(AsmToken::Identifier))
|
if (Lexer.isNot(AsmToken::Identifier))
|
||||||
return TokError("expected segment name after '.zerofill' directive");
|
return TokError("expected segment name after '.zerofill' directive");
|
||||||
std::string Section = Lexer.getTok().getString();
|
std::string Section = Lexer.getTok().getString();
|
||||||
@ -1171,13 +1188,12 @@ bool AsmParser::ParseDirectiveAbort() {
|
|||||||
/// ParseDirectiveLsym
|
/// ParseDirectiveLsym
|
||||||
/// ::= .lsym identifier , expression
|
/// ::= .lsym identifier , expression
|
||||||
bool AsmParser::ParseDirectiveDarwinLsym() {
|
bool AsmParser::ParseDirectiveDarwinLsym() {
|
||||||
if (Lexer.isNot(AsmToken::Identifier))
|
StringRef Name;
|
||||||
|
if (ParseIdentifier(Name))
|
||||||
return TokError("expected identifier in directive");
|
return TokError("expected identifier in directive");
|
||||||
|
|
||||||
// Handle the identifier as the key symbol.
|
// Handle the identifier as the key symbol.
|
||||||
SMLoc IDLoc = Lexer.getLoc();
|
MCSymbol *Sym = Ctx.GetOrCreateSymbol(Name);
|
||||||
MCSymbol *Sym = Ctx.GetOrCreateSymbol(Lexer.getTok().getString());
|
|
||||||
Lexer.Lex();
|
|
||||||
|
|
||||||
if (Lexer.isNot(AsmToken::Comma))
|
if (Lexer.isNot(AsmToken::Comma))
|
||||||
return TokError("unexpected token in '.lsym' directive");
|
return TokError("unexpected token in '.lsym' directive");
|
||||||
|
@ -84,6 +84,10 @@ private:
|
|||||||
bool ParsePrimaryExpr(AsmExpr *&Res);
|
bool ParsePrimaryExpr(AsmExpr *&Res);
|
||||||
bool ParseBinOpRHS(unsigned Precedence, AsmExpr *&Res);
|
bool ParseBinOpRHS(unsigned Precedence, AsmExpr *&Res);
|
||||||
bool ParseParenExpr(AsmExpr *&Res);
|
bool ParseParenExpr(AsmExpr *&Res);
|
||||||
|
|
||||||
|
/// ParseIdentifier - Parse an identifier or string (as a quoted identifier)
|
||||||
|
/// and set \arg Res to the identifier contents.
|
||||||
|
bool ParseIdentifier(StringRef &Res);
|
||||||
|
|
||||||
// Directive Parsing.
|
// Directive Parsing.
|
||||||
bool ParseDirectiveDarwinSection(); // Darwin specific ".section".
|
bool ParseDirectiveDarwinSection(); // Darwin specific ".section".
|
||||||
|
Loading…
Reference in New Issue
Block a user