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