add support for parsing and emitting .section directives. We can now parse

things like:
.section __TEXT,__cstring,cstring_literals

llvm-svn: 74058
This commit is contained in:
Chris Lattner 2009-06-24 04:43:34 +00:00
parent 3f5738d599
commit bedf6c2995
2 changed files with 38 additions and 1 deletions

View File

@ -196,6 +196,10 @@ bool AsmParser::ParseStatement() {
// Otherwise, we have a normal instruction or directive. // Otherwise, we have a normal instruction or directive.
if (IDVal[0] == '.') { if (IDVal[0] == '.') {
if (!strcmp(IDVal, ".section"))
return ParseDirectiveSection();
Lexer.PrintMessage(IDLoc, "warning: ignoring directive for now"); Lexer.PrintMessage(IDLoc, "warning: ignoring directive for now");
EatToEndOfStatement(); EatToEndOfStatement();
return false; return false;
@ -207,7 +211,7 @@ bool AsmParser::ParseStatement() {
return true; return true;
if (Lexer.isNot(asmtok::EndOfStatement)) 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. // Eat the end of statement marker.
Lexer.Lex(); Lexer.Lex();
@ -219,3 +223,32 @@ bool AsmParser::ParseStatement() {
// Skip to end of line for now. // Skip to end of line for now.
return false; 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;
}

View File

@ -52,6 +52,10 @@ private:
bool ParseX86InstOperands(MCInst &Inst); bool ParseX86InstOperands(MCInst &Inst);
bool ParseX86Operand(X86Operand &Op); bool ParseX86Operand(X86Operand &Op);
bool ParseX86MemOperand(X86Operand &Op); bool ParseX86MemOperand(X86Operand &Op);
// Directive Parsing.
bool ParseDirectiveSection();
}; };
} // end namespace llvm } // end namespace llvm