From f9f40bd158942f8cd1c3ed62106280f36a022cde Mon Sep 17 00:00:00 2001 From: Eli Bendersky Date: Wed, 16 Jan 2013 18:56:50 +0000 Subject: [PATCH] Now that GenericAsmParser was folded into AsmParser, some methods and types can return into the safe harbor of AsmParser's private areas. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@172637 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/MC/MCParser/MCAsmParser.h | 54 ------------------- lib/MC/MCParser/AsmParser.cpp | 74 ++++++++++++++++++++------ 2 files changed, 57 insertions(+), 71 deletions(-) diff --git a/include/llvm/MC/MCParser/MCAsmParser.h b/include/llvm/MC/MCParser/MCAsmParser.h index 8f54867ab8a..0b8ee0090da 100644 --- a/include/llvm/MC/MCParser/MCAsmParser.h +++ b/include/llvm/MC/MCParser/MCAsmParser.h @@ -44,25 +44,6 @@ public: }; -/// \brief Helper types for tracking macro definitions. -typedef std::vector MCAsmMacroArgument; -typedef std::vector MCAsmMacroArguments; -typedef std::pair MCAsmMacroParameter; -typedef std::vector MCAsmMacroParameters; - -struct MCAsmMacro { - StringRef Name; - StringRef Body; - MCAsmMacroParameters Parameters; - -public: - MCAsmMacro(StringRef N, StringRef B, const MCAsmMacroParameters &P) : - Name(N), Body(B), Parameters(P) {} - - MCAsmMacro(const MCAsmMacro& Other) - : Name(Other.Name), Body(Other.Body), Parameters(Other.Parameters) {} -}; - /// MCAsmParser - Generic assembler parser interface, for use by target specific /// assembly parsers. class MCAsmParser { @@ -159,41 +140,6 @@ public: /// recovery. virtual void EatToEndOfStatement() = 0; - /// \brief Are macros enabled in the parser? - virtual bool MacrosEnabled() = 0; - - /// \brief Control a flag in the parser that enables or disables macros. - virtual void SetMacrosEnabled(bool flag) = 0; - - /// \brief Lookup a previously defined macro. - /// \param Name Macro name. - /// \returns Pointer to macro. NULL if no such macro was defined. - virtual const MCAsmMacro* LookupMacro(StringRef Name) = 0; - - /// \brief Define a new macro with the given name and information. - virtual void DefineMacro(StringRef Name, const MCAsmMacro& Macro) = 0; - - /// \brief Undefine a macro. If no such macro was defined, it's a no-op. - virtual void UndefineMacro(StringRef Name) = 0; - - /// \brief Are we inside a macro instantiation? - virtual bool InsideMacroInstantiation() = 0; - - /// \brief Handle entry to macro instantiation. - /// - /// \param M The macro. - /// \param NameLoc Instantiation location. - virtual bool HandleMacroEntry(const MCAsmMacro *M, SMLoc NameLoc) = 0; - - /// \brief Handle exit from macro instantiation. - virtual void HandleMacroExit() = 0; - - /// ParseMacroArgument - Extract AsmTokens for a macro argument. If the - /// argument delimiter is initially unknown, set it to AsmToken::Eof. It will - /// be set to the correct delimiter by the method. - virtual bool ParseMacroArgument(MCAsmMacroArgument &MA, - AsmToken::TokenKind &ArgumentDelimiter) = 0; - /// ParseExpression - Parse an arbitrary expression. /// /// @param Res - The value of the expression. The result is undefined diff --git a/lib/MC/MCParser/AsmParser.cpp b/lib/MC/MCParser/AsmParser.cpp index 0db343049f3..838a5542d31 100644 --- a/lib/MC/MCParser/AsmParser.cpp +++ b/lib/MC/MCParser/AsmParser.cpp @@ -50,6 +50,25 @@ MCAsmParserSemaCallback::~MCAsmParserSemaCallback() {} namespace { +/// \brief Helper types for tracking macro definitions. +typedef std::vector MCAsmMacroArgument; +typedef std::vector MCAsmMacroArguments; +typedef std::pair MCAsmMacroParameter; +typedef std::vector MCAsmMacroParameters; + +struct MCAsmMacro { + StringRef Name; + StringRef Body; + MCAsmMacroParameters Parameters; + +public: + MCAsmMacro(StringRef N, StringRef B, const MCAsmMacroParameters &P) : + Name(N), Body(B), Parameters(P) {} + + MCAsmMacro(const MCAsmMacro& Other) + : Name(Other.Name), Body(Other.Body), Parameters(Other.Parameters) {} +}; + /// \brief Helper class for storing information about an active macro /// instantiation. struct MacroInstantiation { @@ -73,7 +92,6 @@ public: MemoryBuffer *I); }; -//struct AsmRewrite; struct ParseStatementInfo { /// ParsedOperands - The parsed operands from the last parsed statement. SmallVector ParsedOperands; @@ -205,25 +223,11 @@ public: virtual bool ParseParenExpression(const MCExpr *&Res, SMLoc &EndLoc); virtual bool ParseAbsoluteExpression(int64_t &Res); - bool ParseMacroArgument(MCAsmMacroArgument &MA, - AsmToken::TokenKind &ArgumentDelimiter); - /// ParseIdentifier - Parse an identifier or string (as a quoted identifier) /// and set \p Res to the identifier contents. virtual bool ParseIdentifier(StringRef &Res); virtual void EatToEndOfStatement(); - virtual bool MacrosEnabled() {return MacrosEnabledFlag;} - virtual void SetMacrosEnabled(bool flag) {MacrosEnabledFlag = flag;} - - virtual const MCAsmMacro* LookupMacro(StringRef Name); - virtual void DefineMacro(StringRef Name, const MCAsmMacro& Macro); - virtual void UndefineMacro(StringRef Name); - - virtual bool InsideMacroInstantiation() {return !ActiveMacros.empty();} - virtual bool HandleMacroEntry(const MCAsmMacro *M, SMLoc NameLoc); - void HandleMacroExit(); - virtual void CheckForValidSection(); /// } @@ -238,6 +242,44 @@ private: const MCAsmMacroArguments &A, const SMLoc &L); + /// \brief Are macros enabled in the parser? + bool MacrosEnabled() {return MacrosEnabledFlag;} + + /// \brief Control a flag in the parser that enables or disables macros. + void SetMacrosEnabled(bool Flag) {MacrosEnabledFlag = Flag;} + + /// \brief Lookup a previously defined macro. + /// \param Name Macro name. + /// \returns Pointer to macro. NULL if no such macro was defined. + const MCAsmMacro* LookupMacro(StringRef Name); + + /// \brief Define a new macro with the given name and information. + void DefineMacro(StringRef Name, const MCAsmMacro& Macro); + + /// \brief Undefine a macro. If no such macro was defined, it's a no-op. + void UndefineMacro(StringRef Name); + + /// \brief Are we inside a macro instantiation? + bool InsideMacroInstantiation() {return !ActiveMacros.empty();} + + /// \brief Handle entry to macro instantiation. + /// + /// \param M The macro. + /// \param NameLoc Instantiation location. + bool HandleMacroEntry(const MCAsmMacro *M, SMLoc NameLoc); + + /// \brief Handle exit from macro instantiation. + void HandleMacroExit(); + + /// \brief Extract AsmTokens for a macro argument. If the argument delimiter + /// is initially unknown, set it to AsmToken::Eof. It will be set to the + /// correct delimiter by the method. + bool ParseMacroArgument(MCAsmMacroArgument &MA, + AsmToken::TokenKind &ArgumentDelimiter); + + /// \brief Parse all macro arguments for a given macro. + bool ParseMacroArguments(const MCAsmMacro *M, MCAsmMacroArguments &A); + void PrintMacroInstantiations(); void PrintMessage(SMLoc Loc, SourceMgr::DiagKind Kind, const Twine &Msg, ArrayRef Ranges = ArrayRef()) const { @@ -259,8 +301,6 @@ private: /// location. void JumpToLoc(SMLoc Loc, int InBuffer=-1); - bool ParseMacroArguments(const MCAsmMacro *M, MCAsmMacroArguments &A); - /// \brief Parse up to the end of statement and a return the contents from the /// current token until the end of the statement; the current token on exit /// will be either the EndOfStatement or EOF. -- 2.34.1