94d3bc86957f396ce89be8a8d633a30fee223392
[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 was developed by Chris Lattner and is distributed under
6 // the University of Illinois Open Source 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 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   virtual void print(std::ostream &O) const { print(O, 0); }
61   void print(std::ostream &OS, AssemblyAnnotationWriter *AAW) const;
62
63   /// Verify - This static method can be used by the parser to check to see if
64   /// the specified constraint string is legal for the type.  This returns true
65   /// if legal, false if not.
66   ///
67   static bool Verify(const FunctionType *Ty, const std::string &Constraints);
68
69   // Constraint String Parsing 
70   enum ConstraintPrefix {
71     isInput,            // 'x'
72     isOutput,           // '=x'
73     isClobber,          // '~x'
74   };
75   
76   struct ConstraintInfo {
77     /// Type - The basic type of the constraint: input/output/clobber
78     ///
79     ConstraintPrefix Type;
80     
81     /// isEarlyClobber - "&": output operand writes result before inputs are all
82     /// read.  This is only ever set for an output operand.
83     bool isEarlyClobber; 
84     
85     /// isIndirectOutput - If this is true for an output constraint, the address
86     /// to store the output result is passed as an operand to the call.
87     bool isIndirectOutput;
88     
89     /// Code - The constraint code, either the register name (in braces) or the
90     /// constraint letter/number.
91     std::vector<std::string> Codes;
92     
93     /// Parse - Analyze the specified string (e.g. "==&{eax}") and fill in the
94     /// fields in this structure.  If the constraint string is not understood,
95     /// return true, otherwise return false.
96     bool Parse(const std::string &Str);
97   };
98   
99   /// ParseConstraints - Split up the constraint string into the specific
100   /// constraints and their prefixes.  If this returns an empty vector, and if
101   /// the constraint string itself isn't empty, there was an error parsing.
102   static std::vector<ConstraintInfo> 
103     ParseConstraints(const std::string &ConstraintString);
104   
105   /// ParseConstraints - Parse the constraints of this inlineasm object, 
106   /// returning them the same way that ParseConstraints(str) does.
107   std::vector<ConstraintInfo> 
108   ParseConstraints() const {
109     return ParseConstraints(Constraints);
110   }
111   
112   // Methods for support type inquiry through isa, cast, and dyn_cast:
113   static inline bool classof(const InlineAsm *) { return true; }
114   static inline bool classof(const Value *V) {
115     return V->getValueType() == Value::InlineAsmVal;
116   }
117 };
118
119 } // End llvm namespace
120
121 #endif