1 //===-- llvm/ConstPoolVals.h - Constant Value nodes --------------*- C++ -*--=//
3 // This file contains the declarations for the ConstPoolVal class and all of
4 // its subclasses, which represent the different type of constant pool values
6 //===----------------------------------------------------------------------===//
8 #ifndef LLVM_CONSTPOOLVALS_H
9 #define LLVM_CONSTPOOLVALS_H
11 #include "llvm/User.h"
12 #include "llvm/SymTabValue.h"
13 #include "llvm/Tools/DataTypes.h"
19 //===----------------------------------------------------------------------===//
21 //===----------------------------------------------------------------------===//
23 class ConstPoolVal : public User {
26 friend class ValueHolder<ConstPoolVal, SymTabValue>;
27 inline void setParent(SymTabValue *parent) {
32 inline ConstPoolVal(const Type *Ty, const string &Name = "")
33 : User(Ty, Value::ConstantVal, Name) { Parent = 0; }
35 // Specialize setName to handle symbol table majik...
36 virtual void setName(const string &name);
38 // Static constructor to create a '0' constant of arbitrary type...
39 static ConstPoolVal *getNullConstant(const Type *Ty);
41 // clone() - Create a copy of 'this' value that is identical in all ways
42 // except the following:
43 // * The value has no parent
44 // * The value has no name
46 virtual ConstPoolVal *clone() const = 0;
48 virtual string getStrValue() const = 0;
49 virtual bool equals(const ConstPoolVal *V) const = 0;
51 inline const SymTabValue *getParent() const { return Parent; }
52 inline SymTabValue *getParent() { return Parent; }
57 //===----------------------------------------------------------------------===//
58 // Classes to represent constant pool variable defs
59 //===----------------------------------------------------------------------===//
61 //===---------------------------------------------------------------------------
62 // ConstPoolBool - Boolean Values
64 class ConstPoolBool : public ConstPoolVal {
66 ConstPoolBool(const ConstPoolBool &CP);
68 ConstPoolBool(bool V, const string &Name = "");
70 virtual string getStrValue() const;
71 virtual bool equals(const ConstPoolVal *V) const;
73 virtual ConstPoolVal *clone() const { return new ConstPoolBool(*this); }
75 inline bool getValue() const { return Val; }
77 // setValue - Be careful... if there is more than one 'use' of this node, then
78 // they will ALL see the value that you set...
80 inline void setValue(bool v) { Val = v; }
84 //===---------------------------------------------------------------------------
85 // ConstPoolSInt - Signed Integer Values [sbyte, short, int, long]
87 class ConstPoolSInt : public ConstPoolVal {
89 ConstPoolSInt(const ConstPoolSInt &CP);
91 ConstPoolSInt(const Type *Ty, int64_t V, const string &Name = "");
93 virtual ConstPoolVal *clone() const { return new ConstPoolSInt(*this); }
95 virtual string getStrValue() const;
96 virtual bool equals(const ConstPoolVal *V) const;
98 static bool isValueValidForType(const Type *Ty, int64_t V);
99 inline int64_t getValue() const { return Val; }
103 //===---------------------------------------------------------------------------
104 // ConstPoolUInt - Unsigned Integer Values [ubyte, ushort, uint, ulong]
106 class ConstPoolUInt : public ConstPoolVal {
108 ConstPoolUInt(const ConstPoolUInt &CP);
110 ConstPoolUInt(const Type *Ty, uint64_t V, const string &Name = "");
112 virtual ConstPoolVal *clone() const { return new ConstPoolUInt(*this); }
114 virtual string getStrValue() const;
115 virtual bool equals(const ConstPoolVal *V) const;
117 static bool isValueValidForType(const Type *Ty, uint64_t V);
118 inline uint64_t getValue() const { return Val; }
122 //===---------------------------------------------------------------------------
123 // ConstPoolFP - Floating Point Values [float, double]
125 class ConstPoolFP : public ConstPoolVal {
127 ConstPoolFP(const ConstPoolFP &CP);
129 ConstPoolFP(const Type *Ty, double V, const string &Name = "");
131 virtual ConstPoolVal *clone() const { return new ConstPoolFP(*this); }
132 virtual string getStrValue() const;
133 virtual bool equals(const ConstPoolVal *V) const;
135 static bool isValueValidForType(const Type *Ty, double V);
136 inline double getValue() const { return Val; }
140 //===---------------------------------------------------------------------------
141 // ConstPoolType - Type Declarations
143 class ConstPoolType : public ConstPoolVal {
145 ConstPoolType(const ConstPoolType &CPT);
147 ConstPoolType(const Type *V, const string &Name = "");
149 virtual ConstPoolVal *clone() const { return new ConstPoolType(*this); }
150 virtual string getStrValue() const;
151 virtual bool equals(const ConstPoolVal *V) const;
153 inline const Type *getValue() const { return Val; }
157 //===---------------------------------------------------------------------------
158 // ConstPoolArray - Constant Array Declarations
160 class ConstPoolArray : public ConstPoolVal {
161 ConstPoolArray(const ConstPoolArray &CPT);
163 ConstPoolArray(const ArrayType *T, vector<ConstPoolVal*> &V,
164 const string &Name = "");
165 inline ~ConstPoolArray() { dropAllReferences(); }
167 virtual ConstPoolVal *clone() const { return new ConstPoolArray(*this); }
168 virtual string getStrValue() const;
169 virtual bool equals(const ConstPoolVal *V) const;
171 inline const vector<Use> &getValues() const { return Operands; }
175 //===---------------------------------------------------------------------------
176 // ConstPoolStruct - Constant Struct Declarations
178 class ConstPoolStruct : public ConstPoolVal {
179 ConstPoolStruct(const ConstPoolStruct &CPT);
181 ConstPoolStruct(const StructType *T, vector<ConstPoolVal*> &V,
182 const string &Name = "");
183 inline ~ConstPoolStruct() { dropAllReferences(); }
185 virtual ConstPoolVal *clone() const { return new ConstPoolStruct(*this); }
186 virtual string getStrValue() const;
187 virtual bool equals(const ConstPoolVal *V) const;
189 inline const vector<Use> &getValues() const { return Operands; }