MC/AsmParser: Add .macros_{off,on} support, not that makes sense since we don't

support macros.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@108649 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Daniel Dunbar
2010-07-18 18:38:02 +00:00
parent 275ce39794
commit 3c802de01a
2 changed files with 45 additions and 5 deletions

View File

@@ -38,6 +38,8 @@ namespace {
/// \brief The concrete assembly parser instance. /// \brief The concrete assembly parser instance.
class AsmParser : public MCAsmParser { class AsmParser : public MCAsmParser {
friend class GenericAsmParser;
AsmParser(const AsmParser &); // DO NOT IMPLEMENT AsmParser(const AsmParser &); // DO NOT IMPLEMENT
void operator=(const AsmParser &); // DO NOT IMPLEMENT void operator=(const AsmParser &); // DO NOT IMPLEMENT
private: private:
@@ -47,7 +49,7 @@ private:
SourceMgr &SrcMgr; SourceMgr &SrcMgr;
MCAsmParserExtension *GenericParser; MCAsmParserExtension *GenericParser;
MCAsmParserExtension *PlatformParser; MCAsmParserExtension *PlatformParser;
/// This is the current buffer index we're lexing from as managed by the /// This is the current buffer index we're lexing from as managed by the
/// SourceMgr object. /// SourceMgr object.
int CurBuffer; int CurBuffer;
@@ -60,6 +62,10 @@ private:
/// parsing and validating the rest of the directive. The handler is passed /// parsing and validating the rest of the directive. The handler is passed
/// in the directive name and the location of the directive keyword. /// in the directive name and the location of the directive keyword.
StringMap<std::pair<MCAsmParserExtension*, DirectiveHandler> > DirectiveMap; StringMap<std::pair<MCAsmParserExtension*, DirectiveHandler> > DirectiveMap;
/// Boolean tracking whether macro substitution is enabled.
unsigned MacrosEnabled : 1;
public: public:
AsmParser(const Target &T, SourceMgr &SM, MCContext &Ctx, MCStreamer &Out, AsmParser(const Target &T, SourceMgr &SM, MCContext &Ctx, MCStreamer &Out,
const MCAsmInfo &MAI); const MCAsmInfo &MAI);
@@ -150,6 +156,10 @@ class GenericAsmParser : public MCAsmParserExtension {
public: public:
GenericAsmParser() {} GenericAsmParser() {}
AsmParser &getParser() {
return (AsmParser&) this->MCAsmParserExtension::getParser();
}
virtual void Initialize(MCAsmParser &Parser) { virtual void Initialize(MCAsmParser &Parser) {
// Call the base implementation. // Call the base implementation.
this->MCAsmParserExtension::Initialize(Parser); this->MCAsmParserExtension::Initialize(Parser);
@@ -161,11 +171,20 @@ public:
&GenericAsmParser::ParseDirectiveLine)); &GenericAsmParser::ParseDirectiveLine));
Parser.AddDirectiveHandler(this, ".loc", MCAsmParser::DirectiveHandler( Parser.AddDirectiveHandler(this, ".loc", MCAsmParser::DirectiveHandler(
&GenericAsmParser::ParseDirectiveLoc)); &GenericAsmParser::ParseDirectiveLoc));
// Macro directives.
Parser.AddDirectiveHandler(this, ".macros_on",
MCAsmParser::DirectiveHandler(
&GenericAsmParser::ParseDirectiveMacrosOnOff));
Parser.AddDirectiveHandler(this, ".macros_off",
MCAsmParser::DirectiveHandler(
&GenericAsmParser::ParseDirectiveMacrosOnOff));
} }
bool ParseDirectiveFile(StringRef, SMLoc DirectiveLoc); // ".file" bool ParseDirectiveFile(StringRef, SMLoc DirectiveLoc);
bool ParseDirectiveLine(StringRef, SMLoc DirectiveLoc); // ".line" bool ParseDirectiveLine(StringRef, SMLoc DirectiveLoc);
bool ParseDirectiveLoc(StringRef, SMLoc DirectiveLoc); // ".loc" bool ParseDirectiveLoc(StringRef, SMLoc DirectiveLoc);
bool ParseDirectiveMacrosOnOff(StringRef, SMLoc DirectiveLoc);
}; };
} }
@@ -183,7 +202,7 @@ AsmParser::AsmParser(const Target &T, SourceMgr &_SM, MCContext &_Ctx,
MCStreamer &_Out, const MCAsmInfo &_MAI) MCStreamer &_Out, const MCAsmInfo &_MAI)
: Lexer(_MAI), Ctx(_Ctx), Out(_Out), SrcMgr(_SM), : Lexer(_MAI), Ctx(_Ctx), Out(_Out), SrcMgr(_SM),
GenericParser(new GenericAsmParser), PlatformParser(0), GenericParser(new GenericAsmParser), PlatformParser(0),
CurBuffer(0) { CurBuffer(0), MacrosEnabled(true) {
Lexer.setBuffer(SrcMgr.getMemoryBuffer(CurBuffer)); Lexer.setBuffer(SrcMgr.getMemoryBuffer(CurBuffer));
// Initialize the generic parser. // Initialize the generic parser.
@@ -1593,6 +1612,19 @@ bool GenericAsmParser::ParseDirectiveLoc(StringRef, SMLoc DirectiveLoc) {
return false; return false;
} }
/// ParseDirectiveMacrosOnOff
/// ::= .macros_on
/// ::= .macros_off
bool GenericAsmParser::ParseDirectiveMacrosOnOff(StringRef Directive,
SMLoc DirectiveLoc) {
if (getLexer().isNot(AsmToken::EndOfStatement))
return Error(getLexer().getLoc(),
"unexpected token in '" + Directive + "' directive");
getParser().MacrosEnabled = Directive == ".macros_on";
return false;
}
/// \brief Create an MCAsmParser instance. /// \brief Create an MCAsmParser instance.
MCAsmParser *llvm::createMCAsmParser(const Target &T, SourceMgr &SM, MCAsmParser *llvm::createMCAsmParser(const Target &T, SourceMgr &SM,

View File

@@ -0,0 +1,8 @@
// RUN: llvm-mc %s 2> %t.err
// RUN: FileCheck --check-prefix=CHECK-ERRORS %s < %t.err
.macros_on
.macros_off
// CHECK-ERRORS: .abort '"end"' detected
.abort "end"