LLVM API Documentation
00001 //===-- llvm/InlineAsm.h - Class to represent inline asm strings-*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file was developed by Chris Lattner and is distributed under 00006 // the University of Illinois Open Source 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 struct AssemblyAnnotationWriter; 00025 class PointerType; 00026 class FunctionType; 00027 class Module; 00028 00029 class InlineAsm : public Value { 00030 InlineAsm(const InlineAsm &); // do not implement 00031 void operator=(const InlineAsm&); // do not implement 00032 00033 std::string AsmString, Constraints; 00034 bool HasSideEffects; 00035 00036 InlineAsm(const FunctionType *Ty, const std::string &AsmString, 00037 const std::string &Constraints, bool hasSideEffects); 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 virtual void print(std::ostream &O) const { print(O, 0); } 00061 void print(std::ostream &OS, AssemblyAnnotationWriter *AAW) const; 00062 00063 /// Verify - This static method can be used by the parser to check to see if 00064 /// the specified constraint string is legal for the type. This returns true 00065 /// if legal, false if not. 00066 /// 00067 static bool Verify(const FunctionType *Ty, const std::string &Constraints); 00068 00069 // Constraint String Parsing 00070 enum ConstraintPrefix { 00071 isInput, // 'x' 00072 isOutput, // '=x' 00073 isClobber // '~x' 00074 }; 00075 00076 struct ConstraintInfo { 00077 /// Type - The basic type of the constraint: input/output/clobber 00078 /// 00079 ConstraintPrefix Type; 00080 00081 /// isEarlyClobber - "&": output operand writes result before inputs are all 00082 /// read. This is only ever set for an output operand. 00083 bool isEarlyClobber; 00084 00085 /// isIndirectOutput - If this is true for an output constraint, the address 00086 /// to store the output result is passed as an operand to the call. 00087 bool isIndirectOutput; 00088 00089 /// hasMatchingInput - This is set to true for an output constraint iff 00090 /// there is an input constraint that is required to match it (e.g. "0"). 00091 bool hasMatchingInput; 00092 00093 /// isCommutative - This is set to true for a constraint that is commutative 00094 /// with the next operand. 00095 bool isCommutative; 00096 00097 /// Code - The constraint code, either the register name (in braces) or the 00098 /// constraint letter/number. 00099 std::vector<std::string> Codes; 00100 00101 /// Parse - Analyze the specified string (e.g. "==&{eax}") and fill in the 00102 /// fields in this structure. If the constraint string is not understood, 00103 /// return true, otherwise return false. 00104 bool Parse(const std::string &Str, 00105 std::vector<InlineAsm::ConstraintInfo> &ConstraintsSoFar); 00106 }; 00107 00108 /// ParseConstraints - Split up the constraint string into the specific 00109 /// constraints and their prefixes. If this returns an empty vector, and if 00110 /// the constraint string itself isn't empty, there was an error parsing. 00111 static std::vector<ConstraintInfo> 00112 ParseConstraints(const std::string &ConstraintString); 00113 00114 /// ParseConstraints - Parse the constraints of this inlineasm object, 00115 /// returning them the same way that ParseConstraints(str) does. 00116 std::vector<ConstraintInfo> 00117 ParseConstraints() const { 00118 return ParseConstraints(Constraints); 00119 } 00120 00121 // Methods for support type inquiry through isa, cast, and dyn_cast: 00122 static inline bool classof(const InlineAsm *) { return true; } 00123 static inline bool classof(const Value *V) { 00124 return V->getValueType() == Value::InlineAsmVal; 00125 } 00126 }; 00127 00128 } // End llvm namespace 00129 00130 #endif