John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1 | //===-- llvm/MC/MCTargetAsmParser.h - Target Assembly Parser ----*- 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_TARGETPARSER_H |
| 11 | #define LLVM_MC_TARGETPARSER_H |
| 12 | |
| 13 | #include "llvm/MC/MCParser/MCAsmParserExtension.h" |
| 14 | |
| 15 | namespace llvm { |
| 16 | class MCStreamer; |
| 17 | class StringRef; |
| 18 | class SMLoc; |
| 19 | class AsmToken; |
| 20 | class MCParsedAsmOperand; |
| 21 | class MCInst; |
| 22 | template <typename T> class SmallVectorImpl; |
| 23 | |
| 24 | /// MCTargetAsmParser - Generic interface to target specific assembly parsers. |
| 25 | class MCTargetAsmParser : public MCAsmParserExtension { |
| 26 | public: |
| 27 | enum MatchResultTy { |
| 28 | Match_ConversionFail, |
| 29 | Match_InvalidOperand, |
| 30 | Match_MissingFeature, |
| 31 | Match_MnemonicFail, |
| 32 | Match_Success, |
| 33 | FIRST_TARGET_MATCH_RESULT_TY |
| 34 | }; |
| 35 | |
| 36 | private: |
| 37 | MCTargetAsmParser(const MCTargetAsmParser &); // DO NOT IMPLEMENT |
| 38 | void operator=(const MCTargetAsmParser &); // DO NOT IMPLEMENT |
| 39 | protected: // Can only create subclasses. |
| 40 | MCTargetAsmParser(); |
| 41 | |
| 42 | /// AvailableFeatures - The current set of available features. |
| 43 | unsigned AvailableFeatures; |
| 44 | |
| 45 | public: |
| 46 | virtual ~MCTargetAsmParser(); |
| 47 | |
| 48 | unsigned getAvailableFeatures() const { return AvailableFeatures; } |
| 49 | void setAvailableFeatures(unsigned Value) { AvailableFeatures = Value; } |
| 50 | |
| 51 | virtual bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, |
| 52 | SMLoc &EndLoc) = 0; |
| 53 | |
| 54 | /// ParseInstruction - Parse one assembly instruction. |
| 55 | /// |
| 56 | /// The parser is positioned following the instruction name. The target |
| 57 | /// specific instruction parser should parse the entire instruction and |
| 58 | /// construct the appropriate MCInst, or emit an error. On success, the entire |
| 59 | /// line should be parsed up to and including the end-of-statement token. On |
| 60 | /// failure, the parser is not required to read to the end of the line. |
| 61 | // |
| 62 | /// \param Name - The instruction name. |
| 63 | /// \param NameLoc - The source location of the name. |
| 64 | /// \param Operands [out] - The list of parsed operands, this returns |
| 65 | /// ownership of them to the caller. |
| 66 | /// \return True on failure. |
| 67 | virtual bool ParseInstruction(StringRef Name, SMLoc NameLoc, |
| 68 | SmallVectorImpl<MCParsedAsmOperand*> &Operands) = 0; |
| 69 | |
| 70 | /// ParseDirective - Parse a target specific assembler directive |
| 71 | /// |
| 72 | /// The parser is positioned following the directive name. The target |
| 73 | /// specific directive parser should parse the entire directive doing or |
| 74 | /// recording any target specific work, or return true and do nothing if the |
| 75 | /// directive is not target specific. If the directive is specific for |
| 76 | /// the target, the entire line is parsed up to and including the |
| 77 | /// end-of-statement token and false is returned. |
| 78 | /// |
| 79 | /// \param DirectiveID - the identifier token of the directive. |
| 80 | virtual bool ParseDirective(AsmToken DirectiveID) = 0; |
| 81 | |
| 82 | /// MatchAndEmitInstruction - Recognize a series of operands of a parsed |
| 83 | /// instruction as an actual MCInst and emit it to the specified MCStreamer. |
| 84 | /// This returns false on success and returns true on failure to match. |
| 85 | /// |
| 86 | /// On failure, the target parser is responsible for emitting a diagnostic |
| 87 | /// explaining the match failure. |
| 88 | virtual bool |
| 89 | MatchAndEmitInstruction(SMLoc IDLoc, |
| 90 | SmallVectorImpl<MCParsedAsmOperand*> &Operands, |
| 91 | MCStreamer &Out) = 0; |
| 92 | |
| 93 | /// checkTargetMatchPredicate - Validate the instruction match against |
| 94 | /// any complex target predicates not expressible via match classes. |
| 95 | virtual unsigned checkTargetMatchPredicate(MCInst &Inst) { |
| 96 | return Match_Success; |
| 97 | } |
| 98 | |
| 99 | }; |
| 100 | |
| 101 | } // End llvm namespace |
| 102 | |
| 103 | #endif |