Changed the fundemental architecture of Operands for Instructions. Now
[oota-llvm.git] / include / llvm / ConstPoolVals.h
1 //===-- llvm/ConstPoolVals.h - Constant Value nodes --------------*- C++ -*--=//
2 //
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
5 //
6 //===----------------------------------------------------------------------===//
7
8 #ifndef LLVM_CONSTPOOLVALS_H
9 #define LLVM_CONSTPOOLVALS_H
10
11 #include "llvm/User.h"
12 #include "llvm/SymTabValue.h"
13 #include "llvm/Tools/DataTypes.h"
14 #include <vector>
15
16 class ArrayType;
17 class StructType;
18
19 //===----------------------------------------------------------------------===//
20 //                            ConstPoolVal Class
21 //===----------------------------------------------------------------------===//
22
23 class ConstPoolVal : public User {
24   SymTabValue *Parent;
25
26   friend class ValueHolder<ConstPoolVal, SymTabValue>;
27   inline void setParent(SymTabValue *parent) { 
28     Parent = parent;
29   }
30
31 public:
32   inline ConstPoolVal(const Type *Ty, const string &Name = "") 
33     : User(Ty, Value::ConstantVal, Name) { Parent = 0; }
34
35   // Specialize setName to handle symbol table majik...
36   virtual void setName(const string &name);
37
38   // Static constructor to create a '0' constant of arbitrary type...
39   static ConstPoolVal *getNullConstant(const Type *Ty);
40
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
45   //
46   virtual ConstPoolVal *clone() const = 0;
47
48   virtual string getStrValue() const = 0;
49   virtual bool equals(const ConstPoolVal *V) const = 0;
50
51   inline const SymTabValue *getParent() const { return Parent; }
52   inline       SymTabValue *getParent()       { return Parent; }
53 };
54
55
56
57 //===----------------------------------------------------------------------===//
58 //              Classes to represent constant pool variable defs
59 //===----------------------------------------------------------------------===//
60
61 //===---------------------------------------------------------------------------
62 // ConstPoolBool - Boolean Values
63 //
64 class ConstPoolBool : public ConstPoolVal {
65   bool Val;
66   ConstPoolBool(const ConstPoolBool &CP);
67 public:
68   ConstPoolBool(bool V, const string &Name = "");
69
70   virtual string getStrValue() const;
71   virtual bool equals(const ConstPoolVal *V) const;
72
73   virtual ConstPoolVal *clone() const { return new ConstPoolBool(*this); }
74
75   inline bool getValue() const { return Val; }
76
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...
79   //
80   inline void setValue(bool v) { Val = v; } 
81 };
82
83
84 //===---------------------------------------------------------------------------
85 // ConstPoolSInt - Signed Integer Values [sbyte, short, int, long]
86 //
87 class ConstPoolSInt : public ConstPoolVal {
88   int64_t Val;
89   ConstPoolSInt(const ConstPoolSInt &CP);
90 public:
91   ConstPoolSInt(const Type *Ty, int64_t V, const string &Name = "");
92
93   virtual ConstPoolVal *clone() const { return new ConstPoolSInt(*this); }
94
95   virtual string getStrValue() const;
96   virtual bool equals(const ConstPoolVal *V) const;
97
98   static bool isValueValidForType(const Type *Ty, int64_t V);
99   inline int64_t getValue() const { return Val; }
100 };
101
102
103 //===---------------------------------------------------------------------------
104 // ConstPoolUInt - Unsigned Integer Values [ubyte, ushort, uint, ulong]
105 //
106 class ConstPoolUInt : public ConstPoolVal {
107   uint64_t Val;
108   ConstPoolUInt(const ConstPoolUInt &CP);
109 public:
110   ConstPoolUInt(const Type *Ty, uint64_t V, const string &Name = "");
111
112   virtual ConstPoolVal *clone() const { return new ConstPoolUInt(*this); }
113
114   virtual string getStrValue() const;
115   virtual bool equals(const ConstPoolVal *V) const;
116
117   static bool isValueValidForType(const Type *Ty, uint64_t V);
118   inline uint64_t getValue() const { return Val; }
119 };
120
121
122 //===---------------------------------------------------------------------------
123 // ConstPoolFP - Floating Point Values [float, double]
124 //
125 class ConstPoolFP : public ConstPoolVal {
126   double Val;
127   ConstPoolFP(const ConstPoolFP &CP);
128 public:
129   ConstPoolFP(const Type *Ty, double V, const string &Name = "");
130
131   virtual ConstPoolVal *clone() const { return new ConstPoolFP(*this); }
132   virtual string getStrValue() const;
133   virtual bool equals(const ConstPoolVal *V) const;
134
135   static bool isValueValidForType(const Type *Ty, double V);
136   inline double getValue() const { return Val; }
137 };
138
139
140 //===---------------------------------------------------------------------------
141 // ConstPoolType - Type Declarations
142 //
143 class ConstPoolType : public ConstPoolVal {
144   const Type *Val;
145   ConstPoolType(const ConstPoolType &CPT);
146 public:
147   ConstPoolType(const Type *V, const string &Name = "");
148
149   virtual ConstPoolVal *clone() const { return new ConstPoolType(*this); }
150   virtual string getStrValue() const;
151   virtual bool equals(const ConstPoolVal *V) const;
152
153   inline const Type *getValue() const { return Val; }
154 };
155
156
157 //===---------------------------------------------------------------------------
158 // ConstPoolArray - Constant Array Declarations
159 //
160 class ConstPoolArray : public ConstPoolVal {
161   ConstPoolArray(const ConstPoolArray &CPT);
162 public:
163   ConstPoolArray(const ArrayType *T, vector<ConstPoolVal*> &V, 
164                  const string &Name = "");
165   inline ~ConstPoolArray() { dropAllReferences(); }
166
167   virtual ConstPoolVal *clone() const { return new ConstPoolArray(*this); }
168   virtual string getStrValue() const;
169   virtual bool equals(const ConstPoolVal *V) const;
170
171   inline const vector<Use> &getValues() const { return Operands; }
172 };
173
174
175 //===---------------------------------------------------------------------------
176 // ConstPoolStruct - Constant Struct Declarations
177 //
178 class ConstPoolStruct : public ConstPoolVal {
179   ConstPoolStruct(const ConstPoolStruct &CPT);
180 public:
181   ConstPoolStruct(const StructType *T, vector<ConstPoolVal*> &V, 
182                   const string &Name = "");
183   inline ~ConstPoolStruct() { dropAllReferences(); }
184
185   virtual ConstPoolVal *clone() const { return new ConstPoolStruct(*this); }
186   virtual string getStrValue() const;
187   virtual bool equals(const ConstPoolVal *V) const;
188
189   inline const vector<Use> &getValues() const { return Operands; }
190 };
191
192 #endif