1 //===-- llvm/InlineAsm.h - Class to represent inline asm strings-*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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(...).
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_INLINEASM_H
17 #define LLVM_INLINEASM_H
19 #include "llvm/Value.h"
28 class InlineAsm : public Value {
29 InlineAsm(const InlineAsm &); // do not implement
30 void operator=(const InlineAsm&); // do not implement
32 std::string AsmString, Constraints;
35 InlineAsm(const FunctionType *Ty, const std::string &AsmString,
36 const std::string &Constraints, bool hasSideEffects);
40 /// InlineAsm::get - Return the the specified uniqued inline asm string.
42 static InlineAsm *get(const FunctionType *Ty, const std::string &AsmString,
43 const std::string &Constraints, bool hasSideEffects);
45 bool hasSideEffects() const { return HasSideEffects; }
47 /// getType - InlineAsm's are always pointers.
49 const PointerType *getType() const {
50 return reinterpret_cast<const PointerType*>(Value::getType());
53 /// getFunctionType - InlineAsm's are always pointers to functions.
55 const FunctionType *getFunctionType() const;
57 const std::string &getAsmString() const { return AsmString; }
58 const std::string &getConstraintString() const { return Constraints; }
60 /// Verify - This static method can be used by the parser to check to see if
61 /// the specified constraint string is legal for the type. This returns true
62 /// if legal, false if not.
64 static bool Verify(const FunctionType *Ty, const std::string &Constraints);
66 // Constraint String Parsing
67 enum ConstraintPrefix {
73 struct ConstraintInfo {
74 /// Type - The basic type of the constraint: input/output/clobber
76 ConstraintPrefix Type;
78 /// isEarlyClobber - "&": output operand writes result before inputs are all
79 /// read. This is only ever set for an output operand.
82 /// MatchingInput - If this is not -1, this is an output constraint where an
83 /// input constraint is required to match it (e.g. "0"). The value is the
84 /// constraint number that matches this one (for example, if this is
85 /// constraint #0 and constraint #4 has the value "0", this will be 4).
86 signed char MatchingInput;
88 /// hasMatchingInput - Return true if this is an output constraint that has
89 /// a matching input constraint.
90 bool hasMatchingInput() const { return MatchingInput != -1; }
92 /// isCommutative - This is set to true for a constraint that is commutative
93 /// with the next operand.
96 /// isIndirect - True if this operand is an indirect operand. This means
97 /// that the address of the source or destination is present in the call
98 /// instruction, instead of it being returned or passed in explicitly. This
99 /// is represented with a '*' in the asm string.
102 /// Code - The constraint code, either the register name (in braces) or the
103 /// constraint letter/number.
104 std::vector<std::string> Codes;
106 /// Parse - Analyze the specified string (e.g. "=*&{eax}") and fill in the
107 /// fields in this structure. If the constraint string is not understood,
108 /// return true, otherwise return false.
109 bool Parse(const std::string &Str,
110 std::vector<InlineAsm::ConstraintInfo> &ConstraintsSoFar);
113 /// ParseConstraints - Split up the constraint string into the specific
114 /// constraints and their prefixes. If this returns an empty vector, and if
115 /// the constraint string itself isn't empty, there was an error parsing.
116 static std::vector<ConstraintInfo>
117 ParseConstraints(const std::string &ConstraintString);
119 /// ParseConstraints - Parse the constraints of this inlineasm object,
120 /// returning them the same way that ParseConstraints(str) does.
121 std::vector<ConstraintInfo>
122 ParseConstraints() const {
123 return ParseConstraints(Constraints);
126 // Methods for support type inquiry through isa, cast, and dyn_cast:
127 static inline bool classof(const InlineAsm *) { return true; }
128 static inline bool classof(const Value *V) {
129 return V->getValueID() == Value::InlineAsmVal;
132 /// getNumOperandRegisters - Extract the number of registers field from the
133 /// inline asm operand flag.
134 static unsigned getNumOperandRegisters(unsigned Flag) {
135 return (Flag & 0xffff) >> 3;
138 /// isUseOperandTiedToDef - Return true if the flag of the inline asm
139 /// operand indicates it is an use operand that's matched to a def operand.
140 static bool isUseOperandTiedToDef(unsigned Flag, unsigned &Idx) {
141 if ((Flag & 0x80000000) == 0)
143 Idx = (Flag & ~0x80000000) >> 16;
150 } // End llvm namespace