[ms-inline asm] Add a few new APIs to the AsmParser class in support of MS-Style
[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_MCASMPARSER_H
11 #define LLVM_MC_MCASMPARSER_H
12
13 #include "llvm/Support/DataTypes.h"
14 #include "llvm/ADT/ArrayRef.h"
15
16 namespace llvm {
17 class AsmToken;
18 class MCAsmInfo;
19 class MCAsmLexer;
20 class MCAsmParserExtension;
21 class MCContext;
22 class MCExpr;
23 class MCParsedAsmOperand;
24 class MCStreamer;
25 class MCTargetAsmParser;
26 class SMLoc;
27 class SMRange;
28 class SourceMgr;
29 class StringRef;
30 class Twine;
31
32 /// MCAsmParser - Generic assembler parser interface, for use by target specific
33 /// assembly parsers.
34 class MCAsmParser {
35 public:
36   typedef bool (*DirectiveHandler)(MCAsmParserExtension*, StringRef, SMLoc);
37
38 private:
39   MCAsmParser(const MCAsmParser &) LLVM_DELETED_FUNCTION;
40   void operator=(const MCAsmParser &) LLVM_DELETED_FUNCTION;
41
42   MCTargetAsmParser *TargetParser;
43
44   unsigned ShowParsedOperands : 1;
45
46 protected: // Can only create subclasses.
47   MCAsmParser();
48
49 public:
50   virtual ~MCAsmParser();
51
52   virtual void AddDirectiveHandler(MCAsmParserExtension *Object,
53                                    StringRef Directive,
54                                    DirectiveHandler Handler) = 0;
55
56   virtual SourceMgr &getSourceManager() = 0;
57
58   virtual MCAsmLexer &getLexer() = 0;
59
60   virtual MCContext &getContext() = 0;
61
62   /// getStreamer - Return the output streamer for the assembler.
63   virtual MCStreamer &getStreamer() = 0;
64
65   MCTargetAsmParser &getTargetParser() const { return *TargetParser; }
66   void setTargetParser(MCTargetAsmParser &P);
67
68   virtual unsigned getAssemblerDialect() { return 0;}
69   virtual void setAssemblerDialect(unsigned i) { }
70
71   bool getShowParsedOperands() const { return ShowParsedOperands; }
72   void setShowParsedOperands(bool Value) { ShowParsedOperands = Value; }
73
74   /// Run - Run the parser on the input source buffer.
75   virtual bool Run(bool NoInitialTextSection, bool NoFinalize = false) = 0;
76
77   virtual void setParsingInlineAsm(bool V) = 0;
78
79   /// ParseStatement - Parse the next statement.
80   virtual bool ParseStatement() = 0;
81
82   /// getNumParsedOperands - Returns the number of MCAsmParsedOperands from the
83   /// previously parsed statement.
84   virtual unsigned getNumParsedOperands() = 0;
85
86   /// getParsedOperand - Get a MCAsmParsedOperand.
87   virtual MCParsedAsmOperand &getParsedOperand(unsigned OpNum) = 0;
88
89   /// freeParsedOperands - Free the MCAsmParsedOperands.
90   virtual void freeParsedOperands() = 0;
91
92   /// isInstruction - Was the previously parsed statement an instruction?
93   virtual bool isInstruction() = 0;
94
95   /// getOpcode - Get the opcode from the previously parsed instruction.
96   virtual unsigned getOpcode() = 0;
97
98   /// Warning - Emit a warning at the location \p L, with the message \p Msg.
99   ///
100   /// \return The return value is true, if warnings are fatal.
101   virtual bool Warning(SMLoc L, const Twine &Msg,
102                        ArrayRef<SMRange> Ranges = ArrayRef<SMRange>()) = 0;
103
104   /// Error - Emit an error at the location \p L, with the message \p Msg.
105   ///
106   /// \return The return value is always true, as an idiomatic convenience to
107   /// clients.
108   virtual bool Error(SMLoc L, const Twine &Msg,
109                      ArrayRef<SMRange> Ranges = ArrayRef<SMRange>()) = 0;
110
111   /// Lex - Get the next AsmToken in the stream, possibly handling file
112   /// inclusion first.
113   virtual const AsmToken &Lex() = 0;
114
115   /// getTok - Get the current AsmToken from the stream.
116   const AsmToken &getTok();
117
118   /// \brief Report an error at the current lexer location.
119   bool TokError(const Twine &Msg,
120                 ArrayRef<SMRange> Ranges = ArrayRef<SMRange>());
121
122   /// ParseIdentifier - Parse an identifier or string (as a quoted identifier)
123   /// and set \p Res to the identifier contents.
124   virtual bool ParseIdentifier(StringRef &Res) = 0;
125
126   /// \brief Parse up to the end of statement and return the contents from the
127   /// current token until the end of the statement; the current token on exit
128   /// will be either the EndOfStatement or EOF.
129   virtual StringRef ParseStringToEndOfStatement() = 0;
130
131   /// EatToEndOfStatement - Skip to the end of the current statement, for error
132   /// recovery.
133   virtual void EatToEndOfStatement() = 0;
134
135   /// ParseExpression - Parse an arbitrary expression.
136   ///
137   /// @param Res - The value of the expression. The result is undefined
138   /// on error.
139   /// @result - False on success.
140   virtual bool ParseExpression(const MCExpr *&Res, SMLoc &EndLoc) = 0;
141   bool ParseExpression(const MCExpr *&Res);
142
143   /// ParseParenExpression - Parse an arbitrary expression, assuming that an
144   /// initial '(' has already been consumed.
145   ///
146   /// @param Res - The value of the expression. The result is undefined
147   /// on error.
148   /// @result - False on success.
149   virtual bool ParseParenExpression(const MCExpr *&Res, SMLoc &EndLoc) = 0;
150
151   /// ParseAbsoluteExpression - Parse an expression which must evaluate to an
152   /// absolute value.
153   ///
154   /// @param Res - The value of the absolute expression. The result is undefined
155   /// on error.
156   /// @result - False on success.
157   virtual bool ParseAbsoluteExpression(int64_t &Res) = 0;
158 };
159
160 /// \brief Create an MCAsmParser instance.
161 MCAsmParser *createMCAsmParser(SourceMgr &, MCContext &,
162                                MCStreamer &, const MCAsmInfo &);
163
164 } // End llvm namespace
165
166 #endif