Move ParseMacroArgument to the MCAsmParser interfance.
[oota-llvm.git] / include / llvm / MC / MCParser / MCAsmParser.h
1 //===-- llvm/MC/MCAsmParser.h - Abstract Asm Parser Interface ---*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_MC_MCPARSER_MCASMPARSER_H
11 #define LLVM_MC_MCPARSER_MCASMPARSER_H
12
13 #include "llvm/ADT/ArrayRef.h"
14 #include "llvm/MC/MCParser/AsmLexer.h"
15 #include "llvm/Support/DataTypes.h"
16 #include <vector>
17
18 namespace llvm {
19 class MCAsmInfo;
20 class MCAsmLexer;
21 class MCAsmParserExtension;
22 class MCContext;
23 class MCExpr;
24 class MCInstPrinter;
25 class MCInstrInfo;
26 class MCParsedAsmOperand;
27 class MCStreamer;
28 class MCTargetAsmParser;
29 class SMLoc;
30 class SMRange;
31 class SourceMgr;
32 class StringRef;
33 class Twine;
34
35 /// MCAsmParserSemaCallback - Generic Sema callback for assembly parser.
36 class MCAsmParserSemaCallback {
37 public:
38   virtual ~MCAsmParserSemaCallback(); 
39   virtual void *LookupInlineAsmIdentifier(StringRef Name, void *Loc,
40                                           unsigned &Size, bool &IsVarDecl) = 0;
41   virtual bool LookupInlineAsmField(StringRef Base, StringRef Member,
42                                     unsigned &Offset) = 0;
43 };
44
45
46 typedef std::vector<AsmToken> MCAsmMacroArgument;
47
48
49 /// MCAsmParser - Generic assembler parser interface, for use by target specific
50 /// assembly parsers.
51 class MCAsmParser {
52 public:
53   typedef bool (*DirectiveHandler)(MCAsmParserExtension*, StringRef, SMLoc);
54
55 private:
56   MCAsmParser(const MCAsmParser &) LLVM_DELETED_FUNCTION;
57   void operator=(const MCAsmParser &) LLVM_DELETED_FUNCTION;
58
59   MCTargetAsmParser *TargetParser;
60
61   unsigned ShowParsedOperands : 1;
62
63 protected: // Can only create subclasses.
64   MCAsmParser();
65
66 public:
67   virtual ~MCAsmParser();
68
69   virtual void AddDirectiveHandler(MCAsmParserExtension *Object,
70                                    StringRef Directive,
71                                    DirectiveHandler Handler) = 0;
72
73   virtual SourceMgr &getSourceManager() = 0;
74
75   virtual MCAsmLexer &getLexer() = 0;
76
77   virtual MCContext &getContext() = 0;
78
79   /// getStreamer - Return the output streamer for the assembler.
80   virtual MCStreamer &getStreamer() = 0;
81
82   MCTargetAsmParser &getTargetParser() const { return *TargetParser; }
83   void setTargetParser(MCTargetAsmParser &P);
84
85   virtual unsigned getAssemblerDialect() { return 0;}
86   virtual void setAssemblerDialect(unsigned i) { }
87
88   bool getShowParsedOperands() const { return ShowParsedOperands; }
89   void setShowParsedOperands(bool Value) { ShowParsedOperands = Value; }
90
91   /// Run - Run the parser on the input source buffer.
92   virtual bool Run(bool NoInitialTextSection, bool NoFinalize = false) = 0;
93
94   virtual void setParsingInlineAsm(bool V) = 0;
95   virtual bool isParsingInlineAsm() = 0;
96
97   /// ParseMSInlineAsm - Parse ms-style inline assembly.
98   virtual bool ParseMSInlineAsm(void *AsmLoc, std::string &AsmString,
99                                 unsigned &NumOutputs, unsigned &NumInputs,
100                                 SmallVectorImpl<std::pair<void *, bool> > &OpDecls,
101                                 SmallVectorImpl<std::string> &Constraints,
102                                 SmallVectorImpl<std::string> &Clobbers,
103                                 const MCInstrInfo *MII,
104                                 const MCInstPrinter *IP,
105                                 MCAsmParserSemaCallback &SI) = 0;
106
107   /// Warning - Emit a warning at the location \p L, with the message \p Msg.
108   ///
109   /// \return The return value is true, if warnings are fatal.
110   virtual bool Warning(SMLoc L, const Twine &Msg,
111                        ArrayRef<SMRange> Ranges = ArrayRef<SMRange>()) = 0;
112
113   /// Error - Emit an error at the location \p L, with the message \p Msg.
114   ///
115   /// \return The return value is always true, as an idiomatic convenience to
116   /// clients.
117   virtual bool Error(SMLoc L, const Twine &Msg,
118                      ArrayRef<SMRange> Ranges = ArrayRef<SMRange>()) = 0;
119
120   /// Lex - Get the next AsmToken in the stream, possibly handling file
121   /// inclusion first.
122   virtual const AsmToken &Lex() = 0;
123
124   /// getTok - Get the current AsmToken from the stream.
125   const AsmToken &getTok();
126
127   /// \brief Report an error at the current lexer location.
128   bool TokError(const Twine &Msg,
129                 ArrayRef<SMRange> Ranges = ArrayRef<SMRange>());
130
131   /// ParseIdentifier - Parse an identifier or string (as a quoted identifier)
132   /// and set \p Res to the identifier contents.
133   virtual bool ParseIdentifier(StringRef &Res) = 0;
134
135   /// \brief Parse up to the end of statement and return the contents from the
136   /// current token until the end of the statement; the current token on exit
137   /// will be either the EndOfStatement or EOF.
138   virtual StringRef ParseStringToEndOfStatement() = 0;
139
140   /// EatToEndOfStatement - Skip to the end of the current statement, for error
141   /// recovery.
142   virtual void EatToEndOfStatement() = 0;
143
144   /// Control a flag in the parser that enables or disables macros.
145   virtual bool MacrosEnabled() = 0;
146   virtual void SetMacrosEnabled(bool flag) = 0;
147
148   /// ParseMacroArgument - Extract AsmTokens for a macro argument. If the
149   /// argument delimiter is initially unknown, set it to AsmToken::Eof. It will
150   /// be set to the correct delimiter by the method.
151   virtual bool ParseMacroArgument(MCAsmMacroArgument &MA,
152                                   AsmToken::TokenKind &ArgumentDelimiter) = 0;
153
154   /// ParseExpression - Parse an arbitrary expression.
155   ///
156   /// @param Res - The value of the expression. The result is undefined
157   /// on error.
158   /// @result - False on success.
159   virtual bool ParseExpression(const MCExpr *&Res, SMLoc &EndLoc) = 0;
160   bool ParseExpression(const MCExpr *&Res);
161
162   /// ParseParenExpression - Parse an arbitrary expression, assuming that an
163   /// initial '(' has already been consumed.
164   ///
165   /// @param Res - The value of the expression. The result is undefined
166   /// on error.
167   /// @result - False on success.
168   virtual bool ParseParenExpression(const MCExpr *&Res, SMLoc &EndLoc) = 0;
169
170   /// ParseAbsoluteExpression - Parse an expression which must evaluate to an
171   /// absolute value.
172   ///
173   /// @param Res - The value of the absolute expression. The result is undefined
174   /// on error.
175   /// @result - False on success.
176   virtual bool ParseAbsoluteExpression(int64_t &Res) = 0;
177 };
178
179 /// \brief Create an MCAsmParser instance.
180 MCAsmParser *createMCAsmParser(SourceMgr &, MCContext &,
181                                MCStreamer &, const MCAsmInfo &);
182
183 } // End llvm namespace
184
185 #endif