summaryrefslogtreecommitdiff
path: root/tools/llvm-mc
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-06-24 04:43:34 +0000
committerChris Lattner <sabre@nondot.org>2009-06-24 04:43:34 +0000
commit9a023f70b4dc8fe456e074ac1402000fe02bb331 (patch)
treeeba550c28da72d639cdbe1c9a7a1b19f93058c2b /tools/llvm-mc
parentc69485e34d57e17fe2c3acab64e519d6a6945197 (diff)
downloadllvm-9a023f70b4dc8fe456e074ac1402000fe02bb331.tar.gz
llvm-9a023f70b4dc8fe456e074ac1402000fe02bb331.tar.bz2
llvm-9a023f70b4dc8fe456e074ac1402000fe02bb331.tar.xz
add support for parsing and emitting .section directives. We can now parse
things like: .section __TEXT,__cstring,cstring_literals git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74058 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-mc')
-rw-r--r--tools/llvm-mc/AsmParser.cpp35
-rw-r--r--tools/llvm-mc/AsmParser.h4
2 files changed, 38 insertions, 1 deletions
diff --git a/tools/llvm-mc/AsmParser.cpp b/tools/llvm-mc/AsmParser.cpp
index ca0b933841..37cb4aecf8 100644
--- a/tools/llvm-mc/AsmParser.cpp
+++ b/tools/llvm-mc/AsmParser.cpp
@@ -196,6 +196,10 @@ bool AsmParser::ParseStatement() {
// Otherwise, we have a normal instruction or directive.
if (IDVal[0] == '.') {
+ if (!strcmp(IDVal, ".section"))
+ return ParseDirectiveSection();
+
+
Lexer.PrintMessage(IDLoc, "warning: ignoring directive for now");
EatToEndOfStatement();
return false;
@@ -207,7 +211,7 @@ bool AsmParser::ParseStatement() {
return true;
if (Lexer.isNot(asmtok::EndOfStatement))
- return TokError("unexpected token in operand list");
+ return TokError("unexpected token in argument list");
// Eat the end of statement marker.
Lexer.Lex();
@@ -219,3 +223,32 @@ bool AsmParser::ParseStatement() {
// Skip to end of line for now.
return false;
}
+
+/// ParseDirectiveSection:
+/// ::= .section identifier
+bool AsmParser::ParseDirectiveSection() {
+ if (Lexer.isNot(asmtok::Identifier))
+ return TokError("expected identifier after '.section' directive");
+
+ std::string Section = Lexer.getCurStrVal();
+ Lexer.Lex();
+
+ // Accept a comma separated list of modifiers.
+ while (Lexer.is(asmtok::Comma)) {
+ Lexer.Lex();
+
+ if (Lexer.isNot(asmtok::Identifier))
+ return TokError("expected identifier in '.section' directive");
+ Section += ',';
+ Section += Lexer.getCurStrVal();
+ Lexer.Lex();
+ }
+
+ if (Lexer.isNot(asmtok::EndOfStatement))
+ return TokError("unexpected token in '.section' directive");
+ Lexer.Lex();
+
+ Out.SwitchSection(Ctx.GetSection(Section.c_str()));
+ return false;
+}
+
diff --git a/tools/llvm-mc/AsmParser.h b/tools/llvm-mc/AsmParser.h
index 95154485cd..9e432e861f 100644
--- a/tools/llvm-mc/AsmParser.h
+++ b/tools/llvm-mc/AsmParser.h
@@ -52,6 +52,10 @@ private:
bool ParseX86InstOperands(MCInst &Inst);
bool ParseX86Operand(X86Operand &Op);
bool ParseX86MemOperand(X86Operand &Op);
+
+ // Directive Parsing.
+ bool ParseDirectiveSection();
+
};
} // end namespace llvm