LLVM API Documentation
00001 //===-- llvm/InlineAsm.h - Class to represent inline asm strings-*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This class represents the inline asm strings, which are Value*'s that are 00011 // used as the callee operand of call instructions. InlineAsm's are uniqued 00012 // like constants, and created via InlineAsm::get(...). 00013 // 00014 //===----------------------------------------------------------------------===// 00015 00016 #ifndef LLVM_INLINEASM_H 00017 #define LLVM_INLINEASM_H 00018 00019 #include "llvm/Value.h" 00020 #include <vector> 00021 00022 namespace llvm { 00023 00024 class PointerType; 00025 class FunctionType; 00026 class Module; 00027 00028 class InlineAsm : public Value { 00029 InlineAsm(const InlineAsm &); // do not implement 00030 void operator=(const InlineAsm&); // do not implement 00031 00032 std::string AsmString, Constraints; 00033 bool HasSideEffects; 00034 00035 InlineAsm(const FunctionType *Ty, const std::string &AsmString, 00036 const std::string &Constraints, bool hasSideEffects); 00037 virtual ~InlineAsm(); 00038 public: 00039 00040 /// InlineAsm::get - Return the the specified uniqued inline asm string. 00041 /// 00042 static InlineAsm *get(const FunctionType *Ty, const std::string &AsmString, 00043 const std::string &Constraints, bool hasSideEffects); 00044 00045 bool hasSideEffects() const { return HasSideEffects; } 00046 00047 /// getType - InlineAsm's are always pointers. 00048 /// 00049 const PointerType *getType() const { 00050 return reinterpret_cast<const PointerType*>(Value::getType()); 00051 } 00052 00053 /// getFunctionType - InlineAsm's are always pointers to functions. 00054 /// 00055 const FunctionType *getFunctionType() const; 00056 00057 const std::string &getAsmString() const { return AsmString; } 00058 const std::string &getConstraintString() const { return Constraints; } 00059 00060 /// Verify - This static method can be used by the parser to check to see if 00061 /// the specified constraint string is legal for the type. This returns true 00062 /// if legal, false if not. 00063 /// 00064 static bool Verify(const FunctionType *Ty, const std::string &Constraints); 00065 00066 // Constraint String Parsing 00067 enum ConstraintPrefix { 00068 isInput, // 'x' 00069 isOutput, // '=x' 00070 isClobber // '~x' 00071 }; 00072 00073 struct ConstraintInfo { 00074 /// Type - The basic type of the constraint: input/output/clobber 00075 /// 00076 ConstraintPrefix Type; 00077 00078 /// isEarlyClobber - "&": output operand writes result before inputs are all 00079 /// read. This is only ever set for an output operand. 00080 bool isEarlyClobber; 00081 00082 /// MatchingInput - If this is not -1, this is an output constraint where an 00083 /// input constraint is required to match it (e.g. "0"). The value is the 00084 /// constraint number that matches this one (for example, if this is 00085 /// constraint #0 and constraint #4 has the value "0", this will be 4). 00086 signed char MatchingInput; 00087 00088 /// hasMatchingInput - Return true if this is an output constraint that has 00089 /// a matching input constraint. 00090 bool hasMatchingInput() const { return MatchingInput != -1; } 00091 00092 /// isCommutative - This is set to true for a constraint that is commutative 00093 /// with the next operand. 00094 bool isCommutative; 00095 00096 /// isIndirect - True if this operand is an indirect operand. This means 00097 /// that the address of the source or destination is present in the call 00098 /// instruction, instead of it being returned or passed in explicitly. This 00099 /// is represented with a '*' in the asm string. 00100 bool isIndirect; 00101 00102 /// Code - The constraint code, either the register name (in braces) or the 00103 /// constraint letter/number. 00104 std::vector<std::string> Codes; 00105 00106 /// Parse - Analyze the specified string (e.g. "=*&{eax}") and fill in the 00107 /// fields in this structure. If the constraint string is not understood, 00108 /// return true, otherwise return false. 00109 bool Parse(const std::string &Str, 00110 std::vector<InlineAsm::ConstraintInfo> &ConstraintsSoFar); 00111 }; 00112 00113 /// ParseConstraints - Split up the constraint string into the specific 00114 /// constraints and their prefixes. If this returns an empty vector, and if 00115 /// the constraint string itself isn't empty, there was an error parsing. 00116 static std::vector<ConstraintInfo> 00117 ParseConstraints(const std::string &ConstraintString); 00118 00119 /// ParseConstraints - Parse the constraints of this inlineasm object, 00120 /// returning them the same way that ParseConstraints(str) does. 00121 std::vector<ConstraintInfo> 00122 ParseConstraints() const { 00123 return ParseConstraints(Constraints); 00124 } 00125 00126 // Methods for support type inquiry through isa, cast, and dyn_cast: 00127 static inline bool classof(const InlineAsm *) { return true; } 00128 static inline bool classof(const Value *V) { 00129 return V->getValueID() == Value::InlineAsmVal; 00130 } 00131 }; 00132 00133 } // End llvm namespace 00134 00135 #endif
This web site is hosted by the Computer Science Department at the University of Illinois at Urbana-Champaign.