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