Reorganize the lifetimes of the major objects SelectionDAGISel
[oota-llvm.git] / include / llvm / InlineAsm.h
1 //===-- llvm/InlineAsm.h - Class to represent inline asm strings-*- 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 // This class represents the inline asm strings, which are Value*'s that are
11 // used as the callee operand of call instructions.  InlineAsm's are uniqued
12 // like constants, and created via InlineAsm::get(...).
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_INLINEASM_H
17 #define LLVM_INLINEASM_H
18
19 #include "llvm/Value.h"
20 #include <vector>
21
22 namespace llvm {
23
24 class PointerType;
25 class FunctionType;
26 class Module;
27
28 class InlineAsm : public Value {
29   InlineAsm(const InlineAsm &);             // do not implement
30   void operator=(const InlineAsm&);         // do not implement
31
32   std::string AsmString, Constraints;
33   bool HasSideEffects;
34   
35   InlineAsm(const FunctionType *Ty, const std::string &AsmString,
36             const std::string &Constraints, bool hasSideEffects);
37   virtual ~InlineAsm();
38 public:
39
40   /// InlineAsm::get - Return the the specified uniqued inline asm string.
41   ///
42   static InlineAsm *get(const FunctionType *Ty, const std::string &AsmString,
43                         const std::string &Constraints, bool hasSideEffects);
44   
45   bool hasSideEffects() const { return HasSideEffects; }
46   
47   /// getType - InlineAsm's are always pointers.
48   ///
49   const PointerType *getType() const {
50     return reinterpret_cast<const PointerType*>(Value::getType());
51   }
52   
53   /// getFunctionType - InlineAsm's are always pointers to functions.
54   ///
55   const FunctionType *getFunctionType() const;
56   
57   const std::string &getAsmString() const { return AsmString; }
58   const std::string &getConstraintString() const { return Constraints; }
59
60   /// Verify - This static method can be used by the parser to check to see if
61   /// the specified constraint string is legal for the type.  This returns true
62   /// if legal, false if not.
63   ///
64   static bool Verify(const FunctionType *Ty, const std::string &Constraints);
65
66   // Constraint String Parsing 
67   enum ConstraintPrefix {
68     isInput,            // 'x'
69     isOutput,           // '=x'
70     isClobber           // '~x'
71   };
72   
73   struct ConstraintInfo {
74     /// Type - The basic type of the constraint: input/output/clobber
75     ///
76     ConstraintPrefix Type;
77     
78     /// isEarlyClobber - "&": output operand writes result before inputs are all
79     /// read.  This is only ever set for an output operand.
80     bool isEarlyClobber; 
81     
82     /// hasMatchingInput - This is set to true for an output constraint iff
83     /// there is an input constraint that is required to match it (e.g. "0").
84     bool hasMatchingInput;
85     
86     /// isCommutative - This is set to true for a constraint that is commutative
87     /// with the next operand.
88     bool isCommutative;
89     
90     /// isIndirect - True if this operand is an indirect operand.  This means
91     /// that the address of the source or destination is present in the call
92     /// instruction, instead of it being returned or passed in explicitly.  This
93     /// is represented with a '*' in the asm string.
94     bool isIndirect;
95     
96     /// Code - The constraint code, either the register name (in braces) or the
97     /// constraint letter/number.
98     std::vector<std::string> Codes;
99     
100     /// Parse - Analyze the specified string (e.g. "=*&{eax}") and fill in the
101     /// fields in this structure.  If the constraint string is not understood,
102     /// return true, otherwise return false.
103     bool Parse(const std::string &Str, 
104                std::vector<InlineAsm::ConstraintInfo> &ConstraintsSoFar);
105   };
106   
107   /// ParseConstraints - Split up the constraint string into the specific
108   /// constraints and their prefixes.  If this returns an empty vector, and if
109   /// the constraint string itself isn't empty, there was an error parsing.
110   static std::vector<ConstraintInfo> 
111     ParseConstraints(const std::string &ConstraintString);
112   
113   /// ParseConstraints - Parse the constraints of this inlineasm object, 
114   /// returning them the same way that ParseConstraints(str) does.
115   std::vector<ConstraintInfo> 
116   ParseConstraints() const {
117     return ParseConstraints(Constraints);
118   }
119   
120   // Methods for support type inquiry through isa, cast, and dyn_cast:
121   static inline bool classof(const InlineAsm *) { return true; }
122   static inline bool classof(const Value *V) {
123     return V->getValueID() == Value::InlineAsmVal;
124   }
125 };
126
127 } // End llvm namespace
128
129 #endif