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/Support/DataTypes.h"
17 //===----------------------------------------------------------------------===//
19 //===----------------------------------------------------------------------===//
21 class ConstPoolVal : public User {
23 inline ConstPoolVal(const Type *Ty) : User(Ty, Value::ConstantVal) {}
27 // Specialize setName to handle symbol table majik...
28 virtual void setName(const string &name, SymbolTable *ST = 0);
30 virtual string getStrValue() const = 0;
32 // Static constructor to get a '0' constant of arbitrary type...
33 static ConstPoolVal *getNullConstant(const Type *Ty);
38 //===----------------------------------------------------------------------===//
39 // Classes to represent constant pool variable defs
40 //===----------------------------------------------------------------------===//
42 //===---------------------------------------------------------------------------
43 // ConstPoolBool - Boolean Values
45 class ConstPoolBool : public ConstPoolVal {
47 ConstPoolBool(const ConstPoolBool &); // DO NOT IMPLEMENT
48 ConstPoolBool(bool V);
51 static ConstPoolBool *True, *False; // The True & False values
53 // Factory objects - Return objects of the specified value
54 static ConstPoolBool *get(bool Value) { return Value ? True : False; }
55 static ConstPoolBool *get(const Type *Ty, bool Value) { return get(Value); }
57 // inverted - Return the opposite value of the current value.
58 inline ConstPoolBool *inverted() const { return (this==True) ? False : True; }
60 virtual string getStrValue() const;
61 inline bool getValue() const { return Val; }
65 //===---------------------------------------------------------------------------
66 // ConstPoolInt - Superclass of ConstPoolSInt & ConstPoolUInt, to make dealing
67 // with integral constants easier.
69 class ConstPoolInt : public ConstPoolVal {
75 ConstPoolInt(const ConstPoolInt &); // DO NOT IMPLEMENT
76 ConstPoolInt(const Type *Ty, uint64_t V);
79 // equalsInt - Provide a helper method that can be used to determine if the
80 // constant contained within is equal to a constant. This only works for very
81 // small values, because this is all that can be represented with all types.
83 bool equalsInt(unsigned char V) const {
85 "equals: Can only be used with very small positive constants!");
86 return Val.Unsigned == V;
89 // ConstPoolInt::get static method: return a constant pool int with the
90 // specified value. as above, we work only with very small values here.
92 static ConstPoolInt *get(const Type *Ty, unsigned char V);
96 //===---------------------------------------------------------------------------
97 // ConstPoolSInt - Signed Integer Values [sbyte, short, int, long]
99 class ConstPoolSInt : public ConstPoolInt {
100 ConstPoolSInt(const ConstPoolSInt &); // DO NOT IMPLEMENT
102 ConstPoolSInt(const Type *Ty, int64_t V);
105 static ConstPoolSInt *get(const Type *Ty, int64_t V);
107 virtual string getStrValue() const;
109 static bool isValueValidForType(const Type *Ty, int64_t V);
110 inline int64_t getValue() const { return Val.Signed; }
114 //===---------------------------------------------------------------------------
115 // ConstPoolUInt - Unsigned Integer Values [ubyte, ushort, uint, ulong]
117 class ConstPoolUInt : public ConstPoolInt {
118 ConstPoolUInt(const ConstPoolUInt &); // DO NOT IMPLEMENT
120 ConstPoolUInt(const Type *Ty, uint64_t V);
123 static ConstPoolUInt *get(const Type *Ty, uint64_t V);
125 virtual string getStrValue() const;
127 static bool isValueValidForType(const Type *Ty, uint64_t V);
128 inline uint64_t getValue() const { return Val.Unsigned; }
132 //===---------------------------------------------------------------------------
133 // ConstPoolFP - Floating Point Values [float, double]
135 class ConstPoolFP : public ConstPoolVal {
137 ConstPoolFP(const ConstPoolFP &); // DO NOT IMPLEMENT
139 ConstPoolFP(const Type *Ty, double V);
142 static ConstPoolFP *get(const Type *Ty, double V);
144 virtual string getStrValue() const;
146 static bool isValueValidForType(const Type *Ty, double V);
147 inline double getValue() const { return Val; }
151 //===---------------------------------------------------------------------------
152 // ConstPoolArray - Constant Array Declarations
154 class ConstPoolArray : public ConstPoolVal {
155 ConstPoolArray(const ConstPoolArray &); // DO NOT IMPLEMENT
157 ConstPoolArray(const ArrayType *T, const vector<ConstPoolVal*> &Val);
160 static ConstPoolArray *get(const ArrayType *T, const vector<ConstPoolVal*> &);
162 virtual string getStrValue() const;
164 inline const vector<Use> &getValues() const { return Operands; }
168 //===---------------------------------------------------------------------------
169 // ConstPoolStruct - Constant Struct Declarations
171 class ConstPoolStruct : public ConstPoolVal {
172 ConstPoolStruct(const ConstPoolStruct &); // DO NOT IMPLEMENT
174 ConstPoolStruct(const StructType *T, const vector<ConstPoolVal*> &Val);
175 ~ConstPoolStruct() {}
177 static ConstPoolStruct *get(const StructType *T,
178 const vector<ConstPoolVal*> &V);
180 virtual string getStrValue() const;
182 inline const vector<Use> &getValues() const { return Operands; }