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 //===----------------------------------------------------------------------===//
24 typedef UseTy<ConstPoolVal> ConstPoolUse;
26 class ConstPoolVal : public User {
29 friend class ValueHolder<ConstPoolVal, SymTabValue>;
30 inline void setParent(SymTabValue *parent) {
35 inline ConstPoolVal(const Type *Ty, const string &Name = "")
36 : User(Ty, Value::ConstantVal, Name) { Parent = 0; }
38 // Specialize setName to handle symbol table majik...
39 virtual void setName(const string &name);
41 // Static constructor to create a '0' constant of arbitrary type...
42 static ConstPoolVal *getNullConstant(const Type *Ty);
44 // clone() - Create a copy of 'this' value that is identical in all ways
45 // except the following:
46 // * The value has no parent
47 // * The value has no name
49 virtual ConstPoolVal *clone() const = 0;
51 virtual string getStrValue() const = 0;
52 virtual bool equals(const ConstPoolVal *V) const = 0;
54 inline const SymTabValue *getParent() const { return Parent; }
55 inline SymTabValue *getParent() { return Parent; }
57 // if i > the number of operands, then getOperand() returns 0, and setOperand
58 // returns false. setOperand() may also return false if the operand is of
61 // Note that some subclasses may change this default no argument behavior
63 virtual Value *getOperand(unsigned i) { return 0; }
64 virtual const Value *getOperand(unsigned i) const { return 0; }
65 virtual bool setOperand(unsigned i, Value *Val) { return false; }
66 virtual void dropAllReferences() {}
71 //===----------------------------------------------------------------------===//
72 // Classes to represent constant pool variable defs
73 //===----------------------------------------------------------------------===//
75 //===---------------------------------------------------------------------------
76 // ConstPoolBool - Boolean Values
78 class ConstPoolBool : public ConstPoolVal {
80 ConstPoolBool(const ConstPoolBool &CP);
82 ConstPoolBool(bool V, const string &Name = "");
84 virtual string getStrValue() const;
85 virtual bool equals(const ConstPoolVal *V) const;
87 virtual ConstPoolVal *clone() const { return new ConstPoolBool(*this); }
89 inline bool getValue() const { return Val; }
91 // setValue - Be careful... if there is more than one 'use' of this node, then
92 // they will ALL see the value that you set...
94 inline void setValue(bool v) { Val = v; }
98 //===---------------------------------------------------------------------------
99 // ConstPoolSInt - Signed Integer Values [sbyte, short, int, long]
101 class ConstPoolSInt : public ConstPoolVal {
103 ConstPoolSInt(const ConstPoolSInt &CP);
105 ConstPoolSInt(const Type *Ty, int64_t V, const string &Name = "");
107 virtual ConstPoolVal *clone() const { return new ConstPoolSInt(*this); }
109 virtual string getStrValue() const;
110 virtual bool equals(const ConstPoolVal *V) const;
112 static bool isValueValidForType(const Type *Ty, int64_t V);
113 inline int64_t getValue() const { return Val; }
117 //===---------------------------------------------------------------------------
118 // ConstPoolUInt - Unsigned Integer Values [ubyte, ushort, uint, ulong]
120 class ConstPoolUInt : public ConstPoolVal {
122 ConstPoolUInt(const ConstPoolUInt &CP);
124 ConstPoolUInt(const Type *Ty, uint64_t V, const string &Name = "");
126 virtual ConstPoolVal *clone() const { return new ConstPoolUInt(*this); }
128 virtual string getStrValue() const;
129 virtual bool equals(const ConstPoolVal *V) const;
131 static bool isValueValidForType(const Type *Ty, uint64_t V);
132 inline uint64_t getValue() const { return Val; }
136 //===---------------------------------------------------------------------------
137 // ConstPoolFP - Floating Point Values [float, double]
139 class ConstPoolFP : public ConstPoolVal {
141 ConstPoolFP(const ConstPoolFP &CP);
143 ConstPoolFP(const Type *Ty, double V, const string &Name = "");
145 virtual ConstPoolVal *clone() const { return new ConstPoolFP(*this); }
146 virtual string getStrValue() const;
147 virtual bool equals(const ConstPoolVal *V) const;
149 static bool isValueValidForType(const Type *Ty, double V);
150 inline double getValue() const { return Val; }
154 //===---------------------------------------------------------------------------
155 // ConstPoolType - Type Declarations
157 class ConstPoolType : public ConstPoolVal {
159 ConstPoolType(const ConstPoolType &CPT);
161 ConstPoolType(const Type *V, const string &Name = "");
163 virtual ConstPoolVal *clone() const { return new ConstPoolType(*this); }
164 virtual string getStrValue() const;
165 virtual bool equals(const ConstPoolVal *V) const;
167 inline const Type *getValue() const { return Val; }
171 //===---------------------------------------------------------------------------
172 // ConstPoolArray - Constant Array Declarations
174 class ConstPoolArray : public ConstPoolVal {
175 vector<ConstPoolUse> Val;
176 ConstPoolArray(const ConstPoolArray &CPT);
178 ConstPoolArray(const ArrayType *T, vector<ConstPoolVal*> &V,
179 const string &Name = "");
180 inline ~ConstPoolArray() { dropAllReferences(); }
182 virtual ConstPoolVal *clone() const { return new ConstPoolArray(*this); }
183 virtual string getStrValue() const;
184 virtual bool equals(const ConstPoolVal *V) const;
186 inline const vector<ConstPoolUse> &getValues() const { return Val; }
188 // Implement User stuff...
190 virtual Value *getOperand(unsigned i) {
191 return (i < Val.size()) ? Val[i] : 0;
193 virtual const Value *getOperand(unsigned i) const {
194 return (i < Val.size()) ? Val[i] : 0;
197 // setOperand fails! You can't change a constant!
198 virtual bool setOperand(unsigned i, Value *Val) { return false; }
199 virtual void dropAllReferences() { Val.clear(); }
203 //===---------------------------------------------------------------------------
204 // ConstPoolStruct - Constant Struct Declarations
206 class ConstPoolStruct : public ConstPoolVal {
207 vector<ConstPoolUse> Val;
208 ConstPoolStruct(const ConstPoolStruct &CPT);
210 ConstPoolStruct(const StructType *T, vector<ConstPoolVal*> &V,
211 const string &Name = "");
212 inline ~ConstPoolStruct() { dropAllReferences(); }
214 virtual ConstPoolVal *clone() const { return new ConstPoolStruct(*this); }
215 virtual string getStrValue() const;
216 virtual bool equals(const ConstPoolVal *V) const;
218 inline const vector<ConstPoolUse> &getValues() const { return Val; }
220 // Implement User stuff...
222 virtual Value *getOperand(unsigned i) {
223 return (i < Val.size()) ? Val[i] : 0;
225 virtual const Value *getOperand(unsigned i) const {
226 return (i < Val.size()) ? Val[i] : 0;
229 // setOperand fails! You can't change a constant!
230 virtual bool setOperand(unsigned i, Value *Val) { return false; }
231 virtual void dropAllReferences() { Val.clear(); }