LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MCAsmParser.h
Go to the documentation of this file.
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_MCPARSER_MCASMPARSER_H
11 #define LLVM_MC_MCPARSER_MCASMPARSER_H
12 
13 #include "llvm/ADT/ArrayRef.h"
14 #include "llvm/ADT/StringRef.h"
16 #include "llvm/Support/DataTypes.h"
17 
18 namespace llvm {
19 class MCAsmInfo;
20 class MCAsmLexer;
21 class MCAsmParserExtension;
22 class MCContext;
23 class MCExpr;
24 class MCInstPrinter;
25 class MCInstrInfo;
26 class MCStreamer;
27 class MCTargetAsmParser;
28 class SMLoc;
29 class SMRange;
30 class SourceMgr;
31 class Twine;
32 
33 /// MCAsmParserSemaCallback - Generic Sema callback for assembly parser.
35 public:
36  typedef struct {
37  void *OpDecl;
38  bool IsVarDecl;
39  unsigned Length, Size, Type;
40 
41  void clear() {
42  OpDecl = 0;
43  IsVarDecl = false;
44  Length = 1;
45  Size = 0;
46  Type = 0;
47  }
49 
50  virtual ~MCAsmParserSemaCallback();
51  virtual void *LookupInlineAsmIdentifier(StringRef &LineBuf,
53  bool IsUnevaluatedContext) = 0;
54 
55  virtual bool LookupInlineAsmField(StringRef Base, StringRef Member,
56  unsigned &Offset) = 0;
57 };
58 
61 
62 /// MCAsmParser - Generic assembler parser interface, for use by target specific
63 /// assembly parsers.
64 class MCAsmParser {
65 public:
67  typedef std::pair<MCAsmParserExtension*, DirectiveHandler>
69 
70 private:
72  void operator=(const MCAsmParser &) LLVM_DELETED_FUNCTION;
73 
74  MCTargetAsmParser *TargetParser;
75 
76  unsigned ShowParsedOperands : 1;
77 
78 protected: // Can only create subclasses.
79  MCAsmParser();
80 
81 public:
82  virtual ~MCAsmParser();
83 
84  virtual void addDirectiveHandler(StringRef Directive,
85  ExtensionDirectiveHandler Handler) = 0;
86 
87  virtual SourceMgr &getSourceManager() = 0;
88 
89  virtual MCAsmLexer &getLexer() = 0;
90 
91  virtual MCContext &getContext() = 0;
92 
93  /// getStreamer - Return the output streamer for the assembler.
94  virtual MCStreamer &getStreamer() = 0;
95 
96  MCTargetAsmParser &getTargetParser() const { return *TargetParser; }
98 
99  virtual unsigned getAssemblerDialect() { return 0;}
100  virtual void setAssemblerDialect(unsigned i) { }
101 
102  bool getShowParsedOperands() const { return ShowParsedOperands; }
103  void setShowParsedOperands(bool Value) { ShowParsedOperands = Value; }
104 
105  /// Run - Run the parser on the input source buffer.
106  virtual bool Run(bool NoInitialTextSection, bool NoFinalize = false) = 0;
107 
108  virtual void setParsingInlineAsm(bool V) = 0;
109  virtual bool isParsingInlineAsm() = 0;
110 
111  /// parseMSInlineAsm - Parse ms-style inline assembly.
112  virtual bool parseMSInlineAsm(void *AsmLoc, std::string &AsmString,
113  unsigned &NumOutputs, unsigned &NumInputs,
114  SmallVectorImpl<std::pair<void *, bool> > &OpDecls,
115  SmallVectorImpl<std::string> &Constraints,
117  const MCInstrInfo *MII,
118  const MCInstPrinter *IP,
119  MCAsmParserSemaCallback &SI) = 0;
120 
121  /// Warning - Emit a warning at the location \p L, with the message \p Msg.
122  ///
123  /// \return The return value is true, if warnings are fatal.
124  virtual bool Warning(SMLoc L, const Twine &Msg,
125  ArrayRef<SMRange> Ranges = None) = 0;
126 
127  /// Error - Emit an error at the location \p L, with the message \p Msg.
128  ///
129  /// \return The return value is always true, as an idiomatic convenience to
130  /// clients.
131  virtual bool Error(SMLoc L, const Twine &Msg,
132  ArrayRef<SMRange> Ranges = None) = 0;
133 
134  /// Lex - Get the next AsmToken in the stream, possibly handling file
135  /// inclusion first.
136  virtual const AsmToken &Lex() = 0;
137 
138  /// getTok - Get the current AsmToken from the stream.
139  const AsmToken &getTok();
140 
141  /// \brief Report an error at the current lexer location.
142  bool TokError(const Twine &Msg, ArrayRef<SMRange> Ranges = None);
143 
144  /// parseIdentifier - Parse an identifier or string (as a quoted identifier)
145  /// and set \p Res to the identifier contents.
146  virtual bool parseIdentifier(StringRef &Res) = 0;
147 
148  /// \brief Parse up to the end of statement and return the contents from the
149  /// current token until the end of the statement; the current token on exit
150  /// will be either the EndOfStatement or EOF.
152 
153  /// parseEscapedString - Parse the current token as a string which may include
154  /// escaped characters and return the string contents.
155  virtual bool parseEscapedString(std::string &Data) = 0;
156 
157  /// eatToEndOfStatement - Skip to the end of the current statement, for error
158  /// recovery.
159  virtual void eatToEndOfStatement() = 0;
160 
161  /// parseExpression - Parse an arbitrary expression.
162  ///
163  /// @param Res - The value of the expression. The result is undefined
164  /// on error.
165  /// @result - False on success.
166  virtual bool parseExpression(const MCExpr *&Res, SMLoc &EndLoc) = 0;
167  bool parseExpression(const MCExpr *&Res);
168 
169  /// parsePrimaryExpr - Parse a primary expression.
170  ///
171  /// @param Res - The value of the expression. The result is undefined
172  /// on error.
173  /// @result - False on success.
174  virtual bool parsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc) = 0;
175 
176  /// parseParenExpression - Parse an arbitrary expression, assuming that an
177  /// initial '(' has already been consumed.
178  ///
179  /// @param Res - The value of the expression. The result is undefined
180  /// on error.
181  /// @result - False on success.
182  virtual bool parseParenExpression(const MCExpr *&Res, SMLoc &EndLoc) = 0;
183 
184  /// parseAbsoluteExpression - Parse an expression which must evaluate to an
185  /// absolute value.
186  ///
187  /// @param Res - The value of the absolute expression. The result is undefined
188  /// on error.
189  /// @result - False on success.
190  virtual bool parseAbsoluteExpression(int64_t &Res) = 0;
191 
192  /// checkForValidSection - Ensure that we have a valid section set in the
193  /// streamer. Otherwise, report an error and switch to .text.
194  virtual void checkForValidSection() = 0;
195 };
196 
197 /// \brief Create an MCAsmParser instance.
198 MCAsmParser *createMCAsmParser(SourceMgr &, MCContext &,
199  MCStreamer &, const MCAsmInfo &);
200 
201 } // End llvm namespace
202 
203 #endif
virtual bool Warning(SMLoc L, const Twine &Msg, ArrayRef< SMRange > Ranges=None)=0
virtual void setAssemblerDialect(unsigned i)
Definition: MCAsmParser.h:100
MCTargetAsmParser - Generic interface to target specific assembly parsers.
virtual const AsmToken & Lex()=0
virtual SourceMgr & getSourceManager()=0
virtual void * LookupInlineAsmIdentifier(StringRef &LineBuf, InlineAsmIdentifierInfo &Info, bool IsUnevaluatedContext)=0
bool TokError(const Twine &Msg, ArrayRef< SMRange > Ranges=None)
Report an error at the current lexer location.
Definition: MCAsmParser.cpp:36
MCTargetAsmParser & getTargetParser() const
Definition: MCAsmParser.h:96
AsmToken - Target independent representation for an assembler token.
Definition: MCAsmLexer.h:21
virtual bool parseMSInlineAsm(void *AsmLoc, std::string &AsmString, unsigned &NumOutputs, unsigned &NumInputs, SmallVectorImpl< std::pair< void *, bool > > &OpDecls, SmallVectorImpl< std::string > &Constraints, SmallVectorImpl< std::string > &Clobbers, const MCInstrInfo *MII, const MCInstPrinter *IP, MCAsmParserSemaCallback &SI)=0
parseMSInlineAsm - Parse ms-style inline assembly.
virtual void addDirectiveHandler(StringRef Directive, ExtensionDirectiveHandler Handler)=0
virtual bool parseExpression(const MCExpr *&Res, SMLoc &EndLoc)=0
const AsmToken & getTok()
getTok - Get the current AsmToken from the stream.
Definition: MCAsmParser.cpp:32
void setShowParsedOperands(bool Value)
Definition: MCAsmParser.h:103
MCAsmParserSemaCallback::InlineAsmIdentifierInfo InlineAsmIdentifierInfo
Definition: MCAsmParser.h:60
virtual bool parseEscapedString(std::string &Data)=0
virtual void eatToEndOfStatement()=0
#define P(N)
virtual MCContext & getContext()=0
virtual bool isParsingInlineAsm()=0
const MCInstrInfo & MII
virtual bool parsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc)=0
virtual bool Run(bool NoInitialTextSection, bool NoFinalize=false)=0
Run - Run the parser on the input source buffer.
virtual MCAsmLexer & getLexer()=0
MCAsmParser * createMCAsmParser(SourceMgr &, MCContext &, MCStreamer &, const MCAsmInfo &)
Create an MCAsmParser instance.
Definition: AsmParser.cpp:4312
MCAsmParserSemaCallback - Generic Sema callback for assembly parser.
Definition: MCAsmParser.h:34
std::pair< MCAsmParserExtension *, DirectiveHandler > ExtensionDirectiveHandler
Definition: MCAsmParser.h:68
virtual StringRef parseStringToEndOfStatement()=0
Parse up to the end of statement and return the contents from the current token until the end of the ...
virtual bool Error(SMLoc L, const Twine &Msg, ArrayRef< SMRange > Ranges=None)=0
virtual bool LookupInlineAsmField(StringRef Base, StringRef Member, unsigned &Offset)=0
virtual void setParsingInlineAsm(bool V)=0
virtual MCStreamer & getStreamer()=0
getStreamer - Return the output streamer for the assembler.
virtual void checkForValidSection()=0
#define LLVM_DELETED_FUNCTION
Definition: Compiler.h:137
bool(* DirectiveHandler)(MCAsmParserExtension *, StringRef, SMLoc)
Definition: MCAsmParser.h:66
virtual bool parseAbsoluteExpression(int64_t &Res)=0
virtual unsigned getAssemblerDialect()
Definition: MCAsmParser.h:99
Generic interface for extending the MCAsmParser, which is implemented by target and object file assem...
LLVM Value Representation.
Definition: Value.h:66
void setTargetParser(MCTargetAsmParser &P)
Definition: MCAsmParser.cpp:26
virtual bool parseIdentifier(StringRef &Res)=0
bool getShowParsedOperands() const
Definition: MCAsmParser.h:102
Represents a location in source code.
Definition: SMLoc.h:23
virtual bool parseParenExpression(const MCExpr *&Res, SMLoc &EndLoc)=0