comparison gen/dvalue.h @ 88:058d3925950e trunk

[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
author lindquist
date Tue, 06 Nov 2007 10:03:14 +0100
parents
children 4d1e9eb001e0
comparison
equal deleted inserted replaced
87:25d4fcce53f4 88:058d3925950e
1 #ifndef LLVMDC_GEN_DVALUE_H
2 #define LLVMDC_GEN_DVALUE_H
3
4 /*
5 These classes are used for generating the IR. They encapsulate D values and
6 provide a common interface to the most common operations. When more specialized
7 handling is necessary, they hold enough information to do-the-right-thing (TM)
8 */
9
10 #include <cassert>
11 #include "root.h"
12
13 struct Type;
14 struct Dsymbol;
15 struct VarDeclaration;
16 struct FuncDeclaration;
17
18 namespace llvm
19 {
20 class Value;
21 class Type;
22 class Constant;
23 }
24
25 struct DImValue;
26 struct DConstValue;
27 struct DNullValue;
28 struct DVarValue;
29 struct DFieldValue;
30 struct DThisValue;
31 struct DFuncValue;
32 struct DSliceValue;
33 struct DArrayLenValue;
34 struct DLValueCast;
35
36 // base class for d-values
37 struct DValue : Object
38 {
39 virtual Type* getType() = 0;
40
41 virtual llvm::Value* getLVal() { assert(0); return 0; }
42 virtual llvm::Value* getRVal() { assert(0); return 0; }
43
44 virtual DImValue* isIm() { return NULL; }
45 virtual DConstValue* isConst() { return NULL; }
46 virtual DNullValue* isNull() { return NULL; }
47 virtual DVarValue* isVar() { return NULL; }
48 virtual DFieldValue* isField() { return NULL; }
49 virtual DThisValue* isThis() { return NULL; }
50 virtual DSliceValue* isSlice() { return NULL; }
51 virtual DFuncValue* isFunc() { return NULL; }
52 virtual DArrayLenValue* isArrayLen() { return NULL; }
53 virtual DLValueCast* isLValueCast() { return NULL; }
54
55 virtual bool inPlace() { return false; }
56
57 protected:
58 DValue() {}
59 DValue(const DValue&) { }
60 DValue& operator=(const DValue&) { return *this; }
61 };
62
63 // immediate d-value
64 struct DImValue : DValue
65 {
66 Type* type;
67 llvm::Value* val;
68 bool inplace;
69
70 DImValue(Type* t, llvm::Value* v, bool i = false) { type = t; val = v; inplace = i; }
71
72 virtual llvm::Value* getRVal() { assert(val); return val; }
73
74 virtual Type* getType() { assert(type); return type; }
75 virtual DImValue* isIm() { return this; }
76
77 virtual bool inPlace() { return inplace; }
78 };
79
80 // constant d-value
81 struct DConstValue : DValue
82 {
83 Type* type;
84 llvm::Constant* c;
85
86 DConstValue(Type* t, llvm::Constant* con) { type = t; c = con; }
87
88 virtual llvm::Value* getRVal();
89
90 virtual Type* getType() { assert(type); return type; }
91 virtual DConstValue* isConst() { return this; }
92 };
93
94 // null d-value
95 struct DNullValue : DConstValue
96 {
97 DNullValue(Type* t, llvm::Constant* con) : DConstValue(t,con) {}
98 virtual DNullValue* isNull() { return this; }
99 };
100
101 // variable d-value
102 struct DVarValue : DValue
103 {
104 Type* type;
105 VarDeclaration* var;
106 llvm::Value* val;
107 llvm::Value* rval;
108 bool lval;
109
110 DVarValue(VarDeclaration* vd, llvm::Value* llvmValue, bool lvalue);
111 DVarValue(Type* vd, llvm::Value* lv, llvm::Value* rv);
112 DVarValue(Type* t, llvm::Value* llvmValue, bool lvalue);
113
114 virtual llvm::Value* getLVal();
115 virtual llvm::Value* getRVal();
116
117 virtual Type* getType() { assert(type); return type; }
118 virtual DVarValue* isVar() { return this; }
119 };
120
121 // field d-value
122 struct DFieldValue : DVarValue
123 {
124 DFieldValue(Type* t, llvm::Value* llvmValue, bool l) : DVarValue(t, llvmValue, l) {}
125 virtual DFieldValue* isField() { return this; }
126 };
127
128 // this d-value
129 struct DThisValue : DVarValue
130 {
131 DThisValue(VarDeclaration* vd, llvm::Value* llvmValue) : DVarValue(vd, llvmValue, true) {}
132 virtual DThisValue* isThis() { return this; }
133 };
134
135 // array length d-value
136 struct DArrayLenValue : DVarValue
137 {
138 DArrayLenValue(Type* t, llvm::Value* llvmValue) : DVarValue(t, llvmValue, true) {}
139 virtual DArrayLenValue* isArrayLen() { return this; }
140 };
141
142 // slice d-value
143 struct DSliceValue : DValue
144 {
145 Type* type;
146 llvm::Value* len;
147 llvm::Value* ptr;
148
149 DSliceValue(Type* t, llvm::Value* l, llvm::Value* p) { type=t; ptr=p; len=l; }
150
151 virtual Type* getType() { assert(type); return type; }
152 virtual DSliceValue* isSlice() { return this; }
153 };
154
155 // function d-value
156 struct DFuncValue : DValue
157 {
158 Type* type;
159 FuncDeclaration* func;
160 llvm::Value* val;
161 llvm::Value* vthis;
162 unsigned cc;
163
164 DFuncValue(FuncDeclaration* fd, llvm::Value* v, llvm::Value* vt = 0);
165
166 virtual llvm::Value* getLVal();
167 virtual llvm::Value* getRVal();
168
169 virtual Type* getType() { assert(type); return type; }
170 virtual DFuncValue* isFunc() { return this; }
171 };
172
173 // l-value cast d-value
174 struct DLValueCast : DValue
175 {
176 Type* type;
177 llvm::Value* lval;
178 llvm::Value* rval;
179
180 DLValueCast(Type* t, llvm::Value* l, llvm::Value* r) {
181 type = t;
182 lval = l;
183 rval = r;
184 }
185
186 virtual llvm::Value* getLVal() { assert(lval); return lval; }
187 virtual llvm::Value* getRVal() { assert(rval); return rval; }
188
189 virtual Type* getType() { assert(type); return type; }
190 virtual DLValueCast* isLValueCast() { return this; }
191 };
192
193 #endif // LLVMDC_GEN_DVALUE_H