1 //===-- llvm/MC/MCAsmParser.h - Abstract Asm Parser Interface ---*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_MC_MCPARSER_MCASMPARSER_H
11 #define LLVM_MC_MCPARSER_MCASMPARSER_H
13 #include "llvm/ADT/ArrayRef.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/MC/MCParser/AsmLexer.h"
16 #include "llvm/Support/DataTypes.h"
22 class MCAsmParserExtension;
27 class MCParsedAsmOperand;
29 class MCTargetAsmParser;
36 /// MCAsmParserSemaCallback - Generic Sema callback for assembly parser.
37 class MCAsmParserSemaCallback {
39 virtual ~MCAsmParserSemaCallback();
40 virtual void *LookupInlineAsmIdentifier(StringRef Name, void *Loc,
41 unsigned &Size, bool &IsVarDecl) = 0;
42 virtual bool LookupInlineAsmField(StringRef Base, StringRef Member,
43 unsigned &Offset) = 0;
47 /// MCAsmParser - Generic assembler parser interface, for use by target specific
51 typedef bool (*DirectiveHandler)(MCAsmParserExtension*, StringRef, SMLoc);
52 typedef std::pair<MCAsmParserExtension*, DirectiveHandler>
53 ExtensionDirectiveHandler;
56 MCAsmParser(const MCAsmParser &) LLVM_DELETED_FUNCTION;
57 void operator=(const MCAsmParser &) LLVM_DELETED_FUNCTION;
59 MCTargetAsmParser *TargetParser;
61 unsigned ShowParsedOperands : 1;
63 protected: // Can only create subclasses.
67 virtual ~MCAsmParser();
69 virtual void AddDirectiveHandler(StringRef Directive,
70 ExtensionDirectiveHandler Handler) = 0;
72 virtual SourceMgr &getSourceManager() = 0;
74 virtual MCAsmLexer &getLexer() = 0;
76 virtual MCContext &getContext() = 0;
78 /// getStreamer - Return the output streamer for the assembler.
79 virtual MCStreamer &getStreamer() = 0;
81 MCTargetAsmParser &getTargetParser() const { return *TargetParser; }
82 void setTargetParser(MCTargetAsmParser &P);
84 virtual unsigned getAssemblerDialect() { return 0;}
85 virtual void setAssemblerDialect(unsigned i) { }
87 bool getShowParsedOperands() const { return ShowParsedOperands; }
88 void setShowParsedOperands(bool Value) { ShowParsedOperands = Value; }
90 /// Run - Run the parser on the input source buffer.
91 virtual bool Run(bool NoInitialTextSection, bool NoFinalize = false) = 0;
93 virtual void setParsingInlineAsm(bool V) = 0;
94 virtual bool isParsingInlineAsm() = 0;
96 /// ParseMSInlineAsm - Parse ms-style inline assembly.
97 virtual bool ParseMSInlineAsm(void *AsmLoc, std::string &AsmString,
98 unsigned &NumOutputs, unsigned &NumInputs,
99 SmallVectorImpl<std::pair<void *, bool> > &OpDecls,
100 SmallVectorImpl<std::string> &Constraints,
101 SmallVectorImpl<std::string> &Clobbers,
102 const MCInstrInfo *MII,
103 const MCInstPrinter *IP,
104 MCAsmParserSemaCallback &SI) = 0;
106 /// Warning - Emit a warning at the location \p L, with the message \p Msg.
108 /// \return The return value is true, if warnings are fatal.
109 virtual bool Warning(SMLoc L, const Twine &Msg,
110 ArrayRef<SMRange> Ranges = ArrayRef<SMRange>()) = 0;
112 /// Error - Emit an error at the location \p L, with the message \p Msg.
114 /// \return The return value is always true, as an idiomatic convenience to
116 virtual bool Error(SMLoc L, const Twine &Msg,
117 ArrayRef<SMRange> Ranges = ArrayRef<SMRange>()) = 0;
119 /// Lex - Get the next AsmToken in the stream, possibly handling file
121 virtual const AsmToken &Lex() = 0;
123 /// getTok - Get the current AsmToken from the stream.
124 const AsmToken &getTok();
126 /// \brief Report an error at the current lexer location.
127 bool TokError(const Twine &Msg,
128 ArrayRef<SMRange> Ranges = ArrayRef<SMRange>());
130 /// ParseIdentifier - Parse an identifier or string (as a quoted identifier)
131 /// and set \p Res to the identifier contents.
132 virtual bool ParseIdentifier(StringRef &Res) = 0;
134 /// \brief Parse up to the end of statement and return the contents from the
135 /// current token until the end of the statement; the current token on exit
136 /// will be either the EndOfStatement or EOF.
137 virtual StringRef ParseStringToEndOfStatement() = 0;
139 /// EatToEndOfStatement - Skip to the end of the current statement, for error
141 virtual void EatToEndOfStatement() = 0;
143 /// ParseExpression - Parse an arbitrary expression.
145 /// @param Res - The value of the expression. The result is undefined
147 /// @result - False on success.
148 virtual bool ParseExpression(const MCExpr *&Res, SMLoc &EndLoc) = 0;
149 bool ParseExpression(const MCExpr *&Res);
151 /// ParseParenExpression - Parse an arbitrary expression, assuming that an
152 /// initial '(' has already been consumed.
154 /// @param Res - The value of the expression. The result is undefined
156 /// @result - False on success.
157 virtual bool ParseParenExpression(const MCExpr *&Res, SMLoc &EndLoc) = 0;
159 /// ParseAbsoluteExpression - Parse an expression which must evaluate to an
162 /// @param Res - The value of the absolute expression. The result is undefined
164 /// @result - False on success.
165 virtual bool ParseAbsoluteExpression(int64_t &Res) = 0;
167 /// CheckForValidSection - Ensure that we have a valid section set in the
168 /// streamer. Otherwise, report and error and switch to .text.
169 virtual void CheckForValidSection() = 0;
172 /// \brief Create an MCAsmParser instance.
173 MCAsmParser *createMCAsmParser(SourceMgr &, MCContext &,
174 MCStreamer &, const MCAsmInfo &);
176 } // End llvm namespace