MCAsmParser.h revision f8cd708f14a7a172d51899b68809510ae0c4c4c8
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
15namespace llvm {
16class AsmToken;
17class MCAsmInfo;
18class MCAsmLexer;
19class MCAsmParserExtension;
20class MCContext;
21class MCExpr;
22class MCStreamer;
23class SMLoc;
24class SourceMgr;
25class StringRef;
26class Target;
27class TargetAsmParser;
28class Twine;
29
30/// MCAsmParser - Generic assembler parser interface, for use by target specific
31/// assembly parsers.
32class MCAsmParser {
33public:
34  typedef bool (*DirectiveHandler)(MCAsmParserExtension*, StringRef, SMLoc);
35
36private:
37  MCAsmParser(const MCAsmParser &);   // DO NOT IMPLEMENT
38  void operator=(const MCAsmParser &);  // DO NOT IMPLEMENT
39
40  TargetAsmParser *TargetParser;
41
42  unsigned ShowParsedOperands : 1;
43
44protected: // Can only create subclasses.
45  MCAsmParser();
46
47public:
48  virtual ~MCAsmParser();
49
50  virtual void AddDirectiveHandler(MCAsmParserExtension *Object,
51                                   StringRef Directive,
52                                   DirectiveHandler Handler) = 0;
53
54  virtual SourceMgr &getSourceManager() = 0;
55
56  virtual MCAsmLexer &getLexer() = 0;
57
58  virtual MCContext &getContext() = 0;
59
60  /// getStreamer - Return the output streamer for the assembler.
61  virtual MCStreamer &getStreamer() = 0;
62
63  TargetAsmParser &getTargetParser() const { return *TargetParser; }
64  void setTargetParser(TargetAsmParser &P);
65
66  bool getShowParsedOperands() const { return ShowParsedOperands; }
67  void setShowParsedOperands(bool Value) { ShowParsedOperands = Value; }
68
69  /// Run - Run the parser on the input source buffer.
70  virtual bool Run(bool NoInitialTextSection, bool NoFinalize = false) = 0;
71
72  /// Warning - Emit a warning at the location \arg L, with the message \arg
73  /// Msg.
74  ///
75  /// \return The return value is true, if warnings are fatal.
76  virtual bool Warning(SMLoc L, const Twine &Msg) = 0;
77
78  /// Error - Emit an error at the location \arg L, with the message \arg
79  /// Msg.
80  ///
81  /// \return The return value is always true, as an idiomatic convenience to
82  /// clients.
83  virtual bool Error(SMLoc L, const Twine &Msg) = 0;
84
85  /// Lex - Get the next AsmToken in the stream, possibly handling file
86  /// inclusion first.
87  virtual const AsmToken &Lex() = 0;
88
89  /// getTok - Get the current AsmToken from the stream.
90  const AsmToken &getTok();
91
92  /// \brief Report an error at the current lexer location.
93  bool TokError(const Twine &Msg);
94
95  /// ParseIdentifier - Parse an identifier or string (as a quoted identifier)
96  /// and set \arg Res to the identifier contents.
97  virtual bool ParseIdentifier(StringRef &Res) = 0;
98
99  /// \brief Parse up to the end of statement and return the contents from the
100  /// current token until the end of the statement; the current token on exit
101  /// will be either the EndOfStatement or EOF.
102  virtual StringRef ParseStringToEndOfStatement() = 0;
103
104  /// EatToEndOfStatement - Skip to the end of the current statement, for error
105  /// recovery.
106  virtual void EatToEndOfStatement() = 0;
107
108  /// ParseExpression - Parse an arbitrary expression.
109  ///
110  /// @param Res - The value of the expression. The result is undefined
111  /// on error.
112  /// @result - False on success.
113  virtual bool ParseExpression(const MCExpr *&Res, SMLoc &EndLoc) = 0;
114  bool ParseExpression(const MCExpr *&Res);
115
116  /// ParseParenExpression - Parse an arbitrary expression, assuming that an
117  /// initial '(' has already been consumed.
118  ///
119  /// @param Res - The value of the expression. The result is undefined
120  /// on error.
121  /// @result - False on success.
122  virtual bool ParseParenExpression(const MCExpr *&Res, SMLoc &EndLoc) = 0;
123
124  /// ParseAbsoluteExpression - Parse an expression which must evaluate to an
125  /// absolute value.
126  ///
127  /// @param Res - The value of the absolute expression. The result is undefined
128  /// on error.
129  /// @result - False on success.
130  virtual bool ParseAbsoluteExpression(int64_t &Res) = 0;
131};
132
133/// \brief Create an MCAsmParser instance.
134MCAsmParser *createMCAsmParser(const Target &, SourceMgr &, MCContext &,
135                               MCStreamer &, const MCAsmInfo &);
136
137} // End llvm namespace
138
139#endif
140