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