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 "llvm/System/IncludeFile.h" 00021 #include <vector> 00022 00023 namespace llvm { 00024 00025 struct AssemblyAnnotationWriter; 00026 class PointerType; 00027 class FunctionType; 00028 class Module; 00029 00030 class InlineAsm : public Value { 00031 InlineAsm(const InlineAsm &); // do not implement 00032 void operator=(const InlineAsm&); // do not implement 00033 00034 std::string AsmString, Constraints; 00035 bool HasSideEffects; 00036 00037 InlineAsm(const FunctionType *Ty, const std::string &AsmString, 00038 const std::string &Constraints, bool hasSideEffects); 00039 virtual ~InlineAsm(); 00040 public: 00041 00042 /// InlineAsm::get - Return the the specified uniqued inline asm string. 00043 /// 00044 static InlineAsm *get(const FunctionType *Ty, const std::string &AsmString, 00045 const std::string &Constraints, bool hasSideEffects); 00046 00047 bool hasSideEffects() const { return HasSideEffects; } 00048 00049 /// getType - InlineAsm's are always pointers. 00050 /// 00051 const PointerType *getType() const { 00052 return reinterpret_cast<const PointerType*>(Value::getType()); 00053 } 00054 00055 /// getFunctionType - InlineAsm's are always pointers to functions. 00056 /// 00057 const FunctionType *getFunctionType() const; 00058 00059 const std::string &getAsmString() const { return AsmString; } 00060 const std::string &getConstraintString() const { return Constraints; } 00061 00062 virtual void print(std::ostream &O) const { print(O, 0); } 00063 void print(std::ostream &OS, AssemblyAnnotationWriter *AAW) const; 00064 00065 /// Verify - This static method can be used by the parser to check to see if 00066 /// the specified constraint string is legal for the type. This returns true 00067 /// if legal, false if not. 00068 /// 00069 static bool Verify(const FunctionType *Ty, const std::string &Constraints); 00070 00071 // Constraint String Parsing 00072 enum ConstraintPrefix { 00073 isInput, // 'x' 00074 isOutput, // '=x' 00075 isClobber // '~x' 00076 }; 00077 00078 struct ConstraintInfo { 00079 /// Type - The basic type of the constraint: input/output/clobber 00080 /// 00081 ConstraintPrefix Type; 00082 00083 /// isEarlyClobber - "&": output operand writes result before inputs are all 00084 /// read. This is only ever set for an output operand. 00085 bool isEarlyClobber; 00086 00087 /// isIndirectOutput - If this is true for an output constraint, the address 00088 /// to store the output result is passed as an operand to the call. 00089 bool isIndirectOutput; 00090 00091 /// hasMatchingInput - This is set to true for an output constraint iff 00092 /// there is an input constraint that is required to match it (e.g. "0"). 00093 bool hasMatchingInput; 00094 00095 /// isCommutative - This is set to true for a constraint that is commutative 00096 /// with the next operand. 00097 bool isCommutative; 00098 00099 /// Code - The constraint code, either the register name (in braces) or the 00100 /// constraint letter/number. 00101 std::vector<std::string> Codes; 00102 00103 /// Parse - Analyze the specified string (e.g. "==&{eax}") and fill in the 00104 /// fields in this structure. If the constraint string is not understood, 00105 /// return true, otherwise return false. 00106 bool Parse(const std::string &Str, 00107 std::vector<InlineAsm::ConstraintInfo> &ConstraintsSoFar); 00108 }; 00109 00110 /// ParseConstraints - Split up the constraint string into the specific 00111 /// constraints and their prefixes. If this returns an empty vector, and if 00112 /// the constraint string itself isn't empty, there was an error parsing. 00113 static std::vector<ConstraintInfo> 00114 ParseConstraints(const std::string &ConstraintString); 00115 00116 /// ParseConstraints - Parse the constraints of this inlineasm object, 00117 /// returning them the same way that ParseConstraints(str) does. 00118 std::vector<ConstraintInfo> 00119 ParseConstraints() const { 00120 return ParseConstraints(Constraints); 00121 } 00122 00123 // Methods for support type inquiry through isa, cast, and dyn_cast: 00124 static inline bool classof(const InlineAsm *) { return true; } 00125 static inline bool classof(const Value *V) { 00126 return V->getValueType() == Value::InlineAsmVal; 00127 } 00128 }; 00129 00130 } // End llvm namespace 00131 00132 // Make sure the InlineAsm.cpp file is linked when this one is #included. 00133 FORCE_DEFINING_FILE_TO_BE_LINKED(InlineAsm) 00134 00135 #endif