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