Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

199 lines
6.7 KiB

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