allow registering target lexers.
[oota-llvm.git] / include / llvm / Target / TargetAsmParser.h
1 //===-- llvm/Target/TargetAsmParser.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_TARGET_TARGETPARSER_H
11 #define LLVM_TARGET_TARGETPARSER_H
12
13 namespace llvm {
14 class MCInst;
15 class StringRef;
16 class Target;
17 class SMLoc;
18 class AsmToken;
19 class MCParsedAsmOperand;
20 template <typename T> class SmallVectorImpl;
21
22 /// TargetAsmParser - Generic interface to target specific assembly parsers.
23 class TargetAsmParser {
24   TargetAsmParser(const TargetAsmParser &);   // DO NOT IMPLEMENT
25   void operator=(const TargetAsmParser &);  // DO NOT IMPLEMENT
26 protected: // Can only create subclasses.
27   TargetAsmParser(const Target &);
28  
29   /// TheTarget - The Target that this machine was created for.
30   const Target &TheTarget;
31
32 public:
33   virtual ~TargetAsmParser();
34
35   const Target &getTarget() const { return TheTarget; }
36
37   /// ParseInstruction - Parse one assembly instruction.
38   ///
39   /// The parser is positioned following the instruction name. The target
40   /// specific instruction parser should parse the entire instruction and
41   /// construct the appropriate MCInst, or emit an error. On success, the entire
42   /// line should be parsed up to and including the end-of-statement token. On
43   /// failure, the parser is not required to read to the end of the line.
44   //
45   /// \param AP - The current parser object.
46   /// \param Name - The instruction name.
47   /// \param Operands [out] - The list of parsed operands, this returns
48   ///        ownership of them to the caller.
49   /// \return True on failure.
50   virtual bool ParseInstruction(const StringRef &Name, SMLoc NameLoc,
51                             SmallVectorImpl<MCParsedAsmOperand*> &Operands) = 0;
52
53   /// ParseDirective - Parse a target specific assembler directive
54   ///
55   /// The parser is positioned following the directive name.  The target
56   /// specific directive parser should parse the entire directive doing or
57   /// recording any target specific work, or return true and do nothing if the
58   /// directive is not target specific. If the directive is specific for
59   /// the target, the entire line is parsed up to and including the
60   /// end-of-statement token and false is returned.
61   ///
62   /// \param ID - the identifier token of the directive.
63   virtual bool ParseDirective(AsmToken DirectiveID) = 0;
64   
65   /// MatchInstruction - Recognize a series of operands of a parsed instruction
66   /// as an actual MCInst.  This returns false and fills in Inst on success and
67   /// returns true on failure to match.
68   virtual bool 
69   MatchInstruction(const SmallVectorImpl<MCParsedAsmOperand*> &Operands,
70                    MCInst &Inst) = 0;
71   
72 };
73
74 } // End llvm namespace
75
76 #endif