1 //===-- llvm/InlineAsm.h - Class to represent inline asm strings-*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
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.
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"
24 struct AssemblyAnnotationWriter;
29 class InlineAsm : public Value {
30 InlineAsm(const InlineAsm &); // do not implement
31 void operator=(const InlineAsm&); // do not implement
33 std::string AsmString, Constraints;
36 InlineAsm(const FunctionType *Ty, const std::string &AsmString,
37 const std::string &Constraints, bool hasSideEffects);
41 /// InlineAsm::get - Return the the specified uniqued inline asm string.
43 static InlineAsm *get(const FunctionType *Ty, const std::string &AsmString,
44 const std::string &Constraints, bool hasSideEffects);
46 bool hasSideEffects() const { return HasSideEffects; }
48 /// getType - InlineAsm's are always pointers.
50 const PointerType *getType() const {
51 return reinterpret_cast<const PointerType*>(Value::getType());
54 /// getFunctionType - InlineAsm's are always pointers to functions.
56 const FunctionType *getFunctionType() const;
58 const std::string &getAsmString() const { return AsmString; }
59 const std::string &getConstraintString() const { return Constraints; }
61 virtual void print(std::ostream &O) const { print(O, 0); }
62 void print(std::ostream &OS, AssemblyAnnotationWriter *AAW) const;
64 /// Verify - This static method can be used by the parser to check to see if
65 /// the specified constraint string is legal for the type. This returns true
66 /// if legal, false if not.
68 static bool Verify(const FunctionType *Ty, const std::string &Constraints);
70 // Constraint String Parsing
71 enum ConstraintPrefix {
77 struct ConstraintInfo {
78 /// Type - The basic type of the constraint: input/output/clobber
80 ConstraintPrefix Type;
82 /// isEarlyClobber - "&": output operand writes result before inputs are all
83 /// read. This is only ever set for an output operand.
86 /// isIndirectOutput - If this is true for an output constraint, the address
87 /// to store the output result is passed as an operand to the call.
88 bool isIndirectOutput;
90 /// hasMatchingInput - This is set to true for an output constraint iff
91 /// there is an input constraint that is required to match it (e.g. "0").
92 bool hasMatchingInput;
94 /// isCommutative - This is set to true for a constraint that is commutative
95 /// with the next operand.
98 /// Code - The constraint code, either the register name (in braces) or the
99 /// constraint letter/number.
100 std::vector<std::string> Codes;
102 /// Parse - Analyze the specified string (e.g. "==&{eax}") and fill in the
103 /// fields in this structure. If the constraint string is not understood,
104 /// return true, otherwise return false.
105 bool Parse(const std::string &Str,
106 std::vector<InlineAsm::ConstraintInfo> &ConstraintsSoFar);
109 /// ParseConstraints - Split up the constraint string into the specific
110 /// constraints and their prefixes. If this returns an empty vector, and if
111 /// the constraint string itself isn't empty, there was an error parsing.
112 static std::vector<ConstraintInfo>
113 ParseConstraints(const std::string &ConstraintString);
115 /// ParseConstraints - Parse the constraints of this inlineasm object,
116 /// returning them the same way that ParseConstraints(str) does.
117 std::vector<ConstraintInfo>
118 ParseConstraints() const {
119 return ParseConstraints(Constraints);
122 // Methods for support type inquiry through isa, cast, and dyn_cast:
123 static inline bool classof(const InlineAsm *) { return true; }
124 static inline bool classof(const Value *V) {
125 return V->getValueType() == Value::InlineAsmVal;
129 } // End llvm namespace