Support a common idiom on how to build an Attributes class with a single attribute.
[oota-llvm.git] / include / llvm / MC / MCTargetAsmParser.h
index 0bd4f25636ba9847b3faf9d97a1c53bc0c612b5a..a966a6b8b32cae12e42a7b83cfcd23ff62562a80 100644 (file)
@@ -18,15 +18,26 @@ class StringRef;
 class SMLoc;
 class AsmToken;
 class MCParsedAsmOperand;
+class MCInst;
 template <typename T> class SmallVectorImpl;
 
 /// MCTargetAsmParser - Generic interface to target specific assembly parsers.
 class MCTargetAsmParser : public MCAsmParserExtension {
-  MCTargetAsmParser(const MCTargetAsmParser &);   // DO NOT IMPLEMENT
-  void operator=(const MCTargetAsmParser &);  // DO NOT IMPLEMENT
+public:
+  enum MatchResultTy {
+    Match_InvalidOperand,
+    Match_MissingFeature,
+    Match_MnemonicFail,
+    Match_Success,
+    FIRST_TARGET_MATCH_RESULT_TY
+  };
+
+private:
+  MCTargetAsmParser(const MCTargetAsmParser &) LLVM_DELETED_FUNCTION;
+  void operator=(const MCTargetAsmParser &) LLVM_DELETED_FUNCTION;
 protected: // Can only create subclasses.
   MCTargetAsmParser();
+
   /// AvailableFeatures - The current set of available features.
   unsigned AvailableFeatures;
 
@@ -39,6 +50,12 @@ public:
   virtual bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc,
                              SMLoc &EndLoc) = 0;
 
+  /// MapAndConstraints - Map inline assembly operands to MCInst operands
+  /// and an associated constraint.
+  typedef std::pair< unsigned, std::string > MapAndConstraint;
+  typedef SmallVector<MapAndConstraint, 4> MatchInstMapAndConstraints;
+  typedef SmallVectorImpl<MapAndConstraint> MatchInstMapAndConstraintsImpl;
+
   /// ParseInstruction - Parse one assembly instruction.
   ///
   /// The parser is positioned following the instruction name. The target
@@ -66,18 +83,47 @@ public:
   ///
   /// \param DirectiveID - the identifier token of the directive.
   virtual bool ParseDirective(AsmToken DirectiveID) = 0;
-  
+
+  /// mnemonicIsValid - This returns true if this is a valid mnemonic and false
+  /// otherwise.
+  virtual bool mnemonicIsValid(StringRef Mnemonic) = 0;
+
+  /// MatchInstruction - Recognize a series of operands of a parsed instruction
+  /// as an actual MCInst.  This returns false on success and returns true on
+  /// failure to match.
+  ///
+  /// On failure, the target parser is responsible for emitting a diagnostic
+  /// explaining the match failure.
+  virtual bool
+  MatchInstruction(SMLoc IDLoc, 
+                   SmallVectorImpl<MCParsedAsmOperand*> &Operands,
+                   MCStreamer &Out, unsigned &Kind, unsigned &Opcode,
+                   MatchInstMapAndConstraintsImpl &MapAndConstraints,
+                   unsigned &OrigErrorInfo, bool matchingInlineAsm = false) {
+    OrigErrorInfo = ~0x0;
+    return true;
+  }
+
   /// MatchAndEmitInstruction - Recognize a series of operands of a parsed
   /// instruction as an actual MCInst and emit it to the specified MCStreamer.
   /// This returns false on success and returns true on failure to match.
   ///
   /// On failure, the target parser is responsible for emitting a diagnostic
   /// explaining the match failure.
-  virtual bool 
+  virtual bool
   MatchAndEmitInstruction(SMLoc IDLoc,
                           SmallVectorImpl<MCParsedAsmOperand*> &Operands,
                           MCStreamer &Out) = 0;
-  
+
+  /// checkTargetMatchPredicate - Validate the instruction match against
+  /// any complex target predicates not expressible via match classes.
+  virtual unsigned checkTargetMatchPredicate(MCInst &Inst) {
+    return Match_Success;
+  }
+
+  virtual void convertToMapAndConstraints(unsigned Kind,
+                           const SmallVectorImpl<MCParsedAsmOperand*> &Operands,
+                         MatchInstMapAndConstraintsImpl &MapAndConstraints) = 0;
 };
 
 } // End llvm namespace