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