MCAsmParser.h revision d1e3b44d6c0094eda2e2a854d5fdb6a0d7ba327e
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 char *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  /// ParseExpression - Parse an arbitrary expression.
93  ///
94  /// @param Res - The value of the expression. The result is undefined
95  /// on error.
96  /// @result - False on success.
97  virtual bool ParseExpression(const MCExpr *&Res, SMLoc &EndLoc) = 0;
98  bool ParseExpression(const MCExpr *&Res);
99
100  /// ParseParenExpression - Parse an arbitrary expression, assuming that an
101  /// initial '(' has already been consumed.
102  ///
103  /// @param Res - The value of the expression. The result is undefined
104  /// on error.
105  /// @result - False on success.
106  virtual bool ParseParenExpression(const MCExpr *&Res, SMLoc &EndLoc) = 0;
107
108  /// ParseAbsoluteExpression - Parse an expression which must evaluate to an
109  /// absolute value.
110  ///
111  /// @param Res - The value of the absolute expression. The result is undefined
112  /// on error.
113  /// @result - False on success.
114  virtual bool ParseAbsoluteExpression(int64_t &Res) = 0;
115};
116
117/// \brief Create an MCAsmParser instance.
118MCAsmParser *createMCAsmParser(const Target &, SourceMgr &, MCContext &,
119                               MCStreamer &, const MCAsmInfo &);
120
121} // End llvm namespace
122
123#endif
124