[llvm-commits] [llvm] r74208 - in /llvm/trunk: test/MC/AsmParser/assignment.s test/MC/AsmParser/directive_set.s tools/llvm-mc/AsmLexer.cpp tools/llvm-mc/AsmLexer.h tools/llvm-mc/AsmParser.cpp tools/llvm-mc/AsmParser.h
Daniel Dunbar
daniel at zuster.org
Thu Jun 25 14:56:12 PDT 2009
Author: ddunbar
Date: Thu Jun 25 16:56:11 2009
New Revision: 74208
URL: http://llvm.org/viewvc/llvm-project?rev=74208&view=rev
Log:
MC: Parse .set and assignments.
Added:
llvm/trunk/test/MC/AsmParser/assignment.s
llvm/trunk/test/MC/AsmParser/directive_set.s
Modified:
llvm/trunk/tools/llvm-mc/AsmLexer.cpp
llvm/trunk/tools/llvm-mc/AsmLexer.h
llvm/trunk/tools/llvm-mc/AsmParser.cpp
llvm/trunk/tools/llvm-mc/AsmParser.h
Added: llvm/trunk/test/MC/AsmParser/assignment.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/assignment.s?rev=74208&view=auto
==============================================================================
--- llvm/trunk/test/MC/AsmParser/assignment.s (added)
+++ llvm/trunk/test/MC/AsmParser/assignment.s Thu Jun 25 16:56:11 2009
@@ -0,0 +1,7 @@
+# RUN: llvm-mc %s > %t
+
+# RUN: grep -A 2 TEST0 %t > %t2
+# RUN: grep "a = 0" %t2
+TEST0:
+ a = 0
+
\ No newline at end of file
Added: llvm/trunk/test/MC/AsmParser/directive_set.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/directive_set.s?rev=74208&view=auto
==============================================================================
--- llvm/trunk/test/MC/AsmParser/directive_set.s (added)
+++ llvm/trunk/test/MC/AsmParser/directive_set.s Thu Jun 25 16:56:11 2009
@@ -0,0 +1,7 @@
+# RUN: llvm-mc %s > %t
+
+# RUN: grep -A 2 TEST0 %t > %t2
+# RUN: grep ".set a, 0" %t2
+TEST0:
+ .set a, 0
+
\ No newline at end of file
Modified: llvm/trunk/tools/llvm-mc/AsmLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/AsmLexer.cpp?rev=74208&r1=74207&r2=74208&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmLexer.cpp (original)
+++ llvm/trunk/tools/llvm-mc/AsmLexer.cpp Thu Jun 25 16:56:11 2009
@@ -262,6 +262,7 @@
case '*': return asmtok::Star;
case ',': return asmtok::Comma;
case '$': return asmtok::Dollar;
+ case '=': return asmtok::Equal;
case '|': return asmtok::Pipe;
case '^': return asmtok::Caret;
case '&': return asmtok::Amp;
Modified: llvm/trunk/tools/llvm-mc/AsmLexer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/AsmLexer.h?rev=74208&r1=74207&r2=74208&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmLexer.h (original)
+++ llvm/trunk/tools/llvm-mc/AsmLexer.h Thu Jun 25 16:56:11 2009
@@ -42,7 +42,7 @@
Plus, Minus, Tilde,
Slash, // '/'
LParen, RParen,
- Star, Comma, Dollar,
+ Star, Comma, Dollar, Equal,
Pipe, Caret, Amp, Exclaim,
Percent, LessLess, GreaterGreater
Modified: llvm/trunk/tools/llvm-mc/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/AsmParser.cpp?rev=74208&r1=74207&r2=74208&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmParser.cpp (original)
+++ llvm/trunk/tools/llvm-mc/AsmParser.cpp Thu Jun 25 16:56:11 2009
@@ -182,7 +182,8 @@
const char *IDVal = Lexer.getCurStrVal();
// Consume the identifier, see what is after it.
- if (Lexer.Lex() == asmtok::Colon) {
+ switch (Lexer.Lex()) {
+ case asmtok::Colon:
// identifier ':' -> Label.
Lexer.Lex();
@@ -192,6 +193,15 @@
Out.EmitLabel(Ctx.GetOrCreateSymbol(IDVal));
return ParseStatement();
+
+ case asmtok::Equal:
+ // identifier '=' ... -> assignment statement
+ Lexer.Lex();
+
+ return ParseAssignment(IDVal, false);
+
+ default: // Normal instruction or directive.
+ break;
}
// Otherwise, we have a normal instruction or directive.
@@ -209,7 +219,8 @@
if (!strcmp(IDVal, ".static_const"))
return ParseDirectiveSectionSwitch("__TEXT,__static_const");
if (!strcmp(IDVal, ".cstring"))
- return ParseDirectiveSectionSwitch("__TEXT,__cstring","cstring_literals");
+ return ParseDirectiveSectionSwitch("__TEXT,__cstring",
+ "cstring_literals");
if (!strcmp(IDVal, ".literal4"))
return ParseDirectiveSectionSwitch("__TEXT,__literal4", "4byte_literals");
if (!strcmp(IDVal, ".literal8"))
@@ -291,6 +302,10 @@
if (!strcmp(IDVal, ".objc_selector_strs"))
return ParseDirectiveSectionSwitch("__OBJC,__selector_strs");
+ // Assembler features
+ if (!strcmp(IDVal, ".set"))
+ return ParseDirectiveSet();
+
// Data directives
if (!strcmp(IDVal, ".ascii"))
@@ -336,6 +351,40 @@
return false;
}
+bool AsmParser::ParseAssignment(const char *Name, bool IsDotSet) {
+ int64_t Value;
+ if (ParseExpression(Value))
+ return true;
+
+ if (Lexer.isNot(asmtok::EndOfStatement))
+ return TokError("unexpected token in assignment");
+
+ // Eat the end of statement marker.
+ Lexer.Lex();
+
+ // Get the symbol for this name.
+ // FIXME: Handle '.'.
+ MCSymbol *Sym = Ctx.GetOrCreateSymbol(Name);
+ Out.EmitAssignment(Sym, MCValue::get(Value), IsDotSet);
+
+ return false;
+}
+
+/// ParseDirectiveSet:
+/// ::= .set identifier ',' expression
+bool AsmParser::ParseDirectiveSet() {
+ if (Lexer.isNot(asmtok::Identifier))
+ return TokError("expected identifier after '.set' directive");
+
+ const char *Name = Lexer.getCurStrVal();
+
+ if (Lexer.Lex() != asmtok::Comma)
+ return TokError("unexpected token in '.set'");
+ Lexer.Lex();
+
+ return ParseAssignment(Name, true);
+}
+
/// ParseDirectiveSection:
/// ::= .section identifier (',' identifier)*
/// FIXME: This should actually parse out the segment, section, attributes and
Modified: llvm/trunk/tools/llvm-mc/AsmParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/AsmParser.h?rev=74208&r1=74207&r2=74208&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmParser.h (original)
+++ llvm/trunk/tools/llvm-mc/AsmParser.h Thu Jun 25 16:56:11 2009
@@ -43,6 +43,7 @@
void EatToEndOfStatement();
+ bool ParseAssignment(const char *Name, bool IsDotSet);
bool ParseExpression(int64_t &Res);
bool ParsePrimaryExpr(int64_t &Res);
bool ParseBinOpRHS(unsigned Precedence, int64_t &Res);
@@ -61,6 +62,7 @@
bool ParseDirectiveValue(unsigned Size); // ".byte", ".long", ...
bool ParseDirectiveFill(); // ".fill"
bool ParseDirectiveSpace(); // ".space"
+ bool ParseDirectiveSet(); // ".set"
};
More information about the llvm-commits
mailing list