summaryrefslogtreecommitdiffstats
path: root/lib/MC
diff options
context:
space:
mode:
authorEli Bendersky <eliben@google.com>2013-01-16 18:56:50 +0000
committerEli Bendersky <eliben@google.com>2013-01-16 18:56:50 +0000
commitf9f40bd158942f8cd1c3ed62106280f36a022cde (patch)
tree7e05f1d8b63e1df1480f24cd6d3f09ecab6e3bde /lib/MC
parent1e08165ae9ee3a7b654d9030bc5c86333fe6673f (diff)
downloadexternal_llvm-f9f40bd158942f8cd1c3ed62106280f36a022cde.zip
external_llvm-f9f40bd158942f8cd1c3ed62106280f36a022cde.tar.gz
external_llvm-f9f40bd158942f8cd1c3ed62106280f36a022cde.tar.bz2
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
Diffstat (limited to 'lib/MC')
-rw-r--r--lib/MC/MCParser/AsmParser.cpp74
1 files changed, 57 insertions, 17 deletions
diff --git a/lib/MC/MCParser/AsmParser.cpp b/lib/MC/MCParser/AsmParser.cpp
index 0db3430..838a554 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<AsmToken> MCAsmMacroArgument;
+typedef std::vector<MCAsmMacroArgument> MCAsmMacroArguments;
+typedef std::pair<StringRef, MCAsmMacroArgument> MCAsmMacroParameter;
+typedef std::vector<MCAsmMacroParameter> 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<MCParsedAsmOperand*, 8> 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<SMRange> Ranges = ArrayRef<SMRange>()) 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.