[llvm-commits] [llvm] r77739 - in /llvm/trunk: include/llvm/MC/MCAsmLexer.h test/MC/AsmParser/labels.s tools/llvm-mc/AsmParser.cpp
Daniel Dunbar
daniel at zuster.org
Fri Jul 31 14:55:09 PDT 2009
Author: ddunbar
Date: Fri Jul 31 16:55:09 2009
New Revision: 77739
URL: http://llvm.org/viewvc/llvm-project?rev=77739&view=rev
Log:
llvm-mc: Support quoted identifiers.
- Uses MCAsmToken::getIdentifier which returns the (sub)string representing the
meaningfull contents a string or identifier token.
- Directives aren't done yet.
Added:
llvm/trunk/test/MC/AsmParser/labels.s
Modified:
llvm/trunk/include/llvm/MC/MCAsmLexer.h
llvm/trunk/tools/llvm-mc/AsmParser.cpp
Modified: llvm/trunk/include/llvm/MC/MCAsmLexer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCAsmLexer.h?rev=77739&r1=77738&r2=77739&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCAsmLexer.h (original)
+++ llvm/trunk/include/llvm/MC/MCAsmLexer.h Fri Jul 31 16:55:09 2009
@@ -66,6 +66,22 @@
SMLoc getLoc() const;
+ /// getStringContents - Get the contents of a string token (without quotes).
+ StringRef getStringContents() const {
+ assert(Kind == String && "This token isn't a string!");
+ return Str.slice(1, Str.size() - 1);
+ }
+
+ /// getIdentifier - Get the identifier string for the current token, which
+ /// should be an identifier or a string. This gets the portion of the string
+ /// which should be used as the identifier, e.g., it does not include the
+ /// quotes on strings.
+ StringRef getIdentifier() const {
+ if (Kind == Identifier)
+ return getString();
+ return getStringContents();
+ }
+
/// getString - Get the string for the current token, this includes all
/// characters (for example, the quotes on strings) in the token.
///
@@ -77,7 +93,7 @@
// also not generally what we want (it is nicer for recovery etc. to lex 123br
// as a single token, then diagnose as an invalid number).
int64_t getIntVal() const {
- assert(Kind == Integer && "This token isn't an integer");
+ assert(Kind == Integer && "This token isn't an integer!");
return IntVal;
}
};
Added: llvm/trunk/test/MC/AsmParser/labels.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/labels.s?rev=77739&view=auto
==============================================================================
--- llvm/trunk/test/MC/AsmParser/labels.s (added)
+++ llvm/trunk/test/MC/AsmParser/labels.s Fri Jul 31 16:55:09 2009
@@ -0,0 +1,26 @@
+// RUN: llvm-mc -triple i386-unknown-unknown %s | FileCheck %s
+
+ .data:
+// CHECK: a:
+a:
+ .long 0
+// CHECK: b:
+"b":
+ .long 0
+// FIXME(quoting): CHECK: a$b:
+"a$b":
+ .long 0
+
+ .text:
+foo:
+// FIXME(quoting): CHECK: val:a$b
+ addl $24, "a$b"(%eax)
+// FIXME(quoting): CHECK: val:a$b + 10
+ addl $24, ("a$b" + 10)(%eax)
+
+// FIXME(quoting): CHECK: b$c = 10
+"b$c" = 10
+// FIXME(quoting): CHECK: val:10
+ addl "b$c", %eax
+
+
Modified: llvm/trunk/tools/llvm-mc/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/AsmParser.cpp?rev=77739&r1=77738&r2=77739&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmParser.cpp (original)
+++ llvm/trunk/tools/llvm-mc/AsmParser.cpp Fri Jul 31 16:55:09 2009
@@ -97,10 +97,11 @@
return true;
Res = new AsmUnaryExpr(AsmUnaryExpr::LNot, Res);
return false;
+ case AsmToken::String:
case AsmToken::Identifier: {
// This is a label, this should be parsed as part of an expression, to
// handle things like LFOO+4.
- MCSymbol *Sym = Ctx.GetOrCreateSymbol(Lexer.getTok().getString());
+ MCSymbol *Sym = Ctx.GetOrCreateSymbol(Lexer.getTok().getIdentifier());
// If this is use of an undefined symbol then mark it external.
if (!Sym->getSection() && !Ctx.GetSymbolValue(Sym))
@@ -112,7 +113,7 @@
}
case AsmToken::Integer:
Res = new AsmConstantExpr(Lexer.getTok().getIntVal());
- Lexer.Lex(); // Eat identifier.
+ Lexer.Lex(); // Eat token.
return false;
case AsmToken::LParen:
Lexer.Lex(); // Eat the '('.
@@ -309,6 +310,7 @@
Lexer.Lex();
return false;
case AsmToken::Identifier:
+ case AsmToken::String:
break;
// TODO: Recurse on local labels etc.
}
@@ -316,7 +318,7 @@
// If we have an identifier, handle it as the key symbol.
AsmToken ID = Lexer.getTok();
SMLoc IDLoc = ID.getLoc();
- StringRef IDVal = ID.getString();
+ StringRef IDVal = ID.getIdentifier();
// Consume the identifier, see what is after it.
switch (Lexer.Lex().getKind()) {
@@ -970,7 +972,7 @@
if (Lexer.isNot(AsmToken::Identifier))
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(Lexer.getTok().getString());
Lexer.Lex();
@@ -1172,7 +1174,7 @@
if (Lexer.isNot(AsmToken::Identifier))
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(Lexer.getTok().getString());
Lexer.Lex();
More information about the llvm-commits
mailing list