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"
20 #include "llvm/System/IncludeFile.h"
25 struct AssemblyAnnotationWriter;
30 class InlineAsm : public Value {
31 InlineAsm(const InlineAsm &); // do not implement
32 void operator=(const InlineAsm&); // do not implement
34 std::string AsmString, Constraints;
37 InlineAsm(const FunctionType *Ty, const std::string &AsmString,
38 const std::string &Constraints, bool hasSideEffects);
42 /// InlineAsm::get - Return the the specified uniqued inline asm string.
44 static InlineAsm *get(const FunctionType *Ty, const std::string &AsmString,
45 const std::string &Constraints, bool hasSideEffects);
47 bool hasSideEffects() const { return HasSideEffects; }
49 /// getType - InlineAsm's are always pointers.
51 const PointerType *getType() const {
52 return reinterpret_cast<const PointerType*>(Value::getType());
55 /// getFunctionType - InlineAsm's are always pointers to functions.
57 const FunctionType *getFunctionType() const;
59 const std::string &getAsmString() const { return AsmString; }
60 const std::string &getConstraintString() const { return Constraints; }
62 virtual void print(std::ostream &O) const { print(O, 0); }
63 void print(std::ostream &OS, AssemblyAnnotationWriter *AAW) const;
65 /// Verify - This static method can be used by the parser to check to see if
66 /// the specified constraint string is legal for the type. This returns true
67 /// if legal, false if not.
69 static bool Verify(const FunctionType *Ty, const std::string &Constraints);
71 // Constraint String Parsing
72 enum ConstraintPrefix {
78 struct ConstraintInfo {
79 /// Type - The basic type of the constraint: input/output/clobber
81 ConstraintPrefix Type;
83 /// isEarlyClobber - "&": output operand writes result before inputs are all
84 /// read. This is only ever set for an output operand.
87 /// isIndirectOutput - If this is true for an output constraint, the address
88 /// to store the output result is passed as an operand to the call.
89 bool isIndirectOutput;
91 /// hasMatchingInput - This is set to true for an output constraint iff
92 /// there is an input constraint that is required to match it (e.g. "0").
93 bool hasMatchingInput;
95 /// isCommutative - This is set to true for a constraint that is commutative
96 /// with the next operand.
99 /// Code - The constraint code, either the register name (in braces) or the
100 /// constraint letter/number.
101 std::vector<std::string> Codes;
103 /// Parse - Analyze the specified string (e.g. "==&{eax}") and fill in the
104 /// fields in this structure. If the constraint string is not understood,
105 /// return true, otherwise return false.
106 bool Parse(const std::string &Str,
107 std::vector<InlineAsm::ConstraintInfo> &ConstraintsSoFar);
110 /// ParseConstraints - Split up the constraint string into the specific
111 /// constraints and their prefixes. If this returns an empty vector, and if
112 /// the constraint string itself isn't empty, there was an error parsing.
113 static std::vector<ConstraintInfo>
114 ParseConstraints(const std::string &ConstraintString);
116 /// ParseConstraints - Parse the constraints of this inlineasm object,
117 /// returning them the same way that ParseConstraints(str) does.
118 std::vector<ConstraintInfo>
119 ParseConstraints() const {
120 return ParseConstraints(Constraints);
123 // Methods for support type inquiry through isa, cast, and dyn_cast:
124 static inline bool classof(const InlineAsm *) { return true; }
125 static inline bool classof(const Value *V) {
126 return V->getValueType() == Value::InlineAsmVal;
130 } // End llvm namespace
132 // Make sure the InlineAsm.cpp file is linked when this one is #included.
133 FORCE_DEFINING_FILE_TO_BE_LINKED(InlineAsm)