Mercurial > projects > ldc
annotate gen/irstate.c @ 54:28e99b04a132 trunk
[svn r58] Fixed cond expression resulting in a non-basic type.
Fixed identity expression for dynamic arrays.
Revamped the system to keep track of lvalues and rvalues and their relations.
Typedef declaration now generate the custom typeinfo.
Other bugfixes.
author | lindquist |
---|---|
date | Wed, 24 Oct 2007 01:37:34 +0200 |
parents | 8b0e809563df |
children | b706170e24a9 |
rev | line source |
---|---|
1 | 1 /* DMDFE backend stubs |
2 * This file contains the implementations of the backend routines. | |
3 * For dmdfe these do nothing but print a message saying the module | |
4 * has been parsed. Substitute your own behaviors for these routimes. | |
5 */ | |
6 | |
40 | 7 #include <cstdarg> |
8 | |
9 #include "gen/llvm.h" | |
10 | |
1 | 11 #include "mtype.h" |
40 | 12 #include "declaration.h" |
13 | |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
14 #include "gen/irstate.h" |
40 | 15 #include "tollvm.h" |
1 | 16 |
17 IRState* gIR = 0; | |
18 llvm::TargetData* gTargetData = 0; | |
19 | |
20 ////////////////////////////////////////////////////////////////////////////////////////// | |
21 IRScope::IRScope() | |
22 { | |
40 | 23 begin = end = NULL; |
1 | 24 } |
25 | |
26 IRScope::IRScope(llvm::BasicBlock* b, llvm::BasicBlock* e) | |
27 { | |
28 begin = b; | |
29 end = e; | |
40 | 30 builder.SetInsertPoint(b); |
1 | 31 } |
32 | |
33 ////////////////////////////////////////////////////////////////////////////////////////// | |
34 IRState::IRState() | |
35 { | |
36 dmodule = 0; | |
37 module = 0; | |
38 emitMain = false; | |
39 mainFunc = 0; | |
40 | 40 ir.state = this; |
41 } | |
42 | |
43 IRFunction& IRState::func() | |
44 { | |
45 assert(!functions.empty() && "Function stack is empty!"); | |
46 return functions.back(); | |
1 | 47 } |
48 | |
49 llvm::Function* IRState::topfunc() | |
50 { | |
40 | 51 assert(!functions.empty() && "Function stack is empty!"); |
52 return functions.back().func; | |
1 | 53 } |
54 | |
55 TypeFunction* IRState::topfunctype() | |
56 { | |
40 | 57 assert(!functions.empty() && "Function stack is empty!"); |
58 return functions.back().type; | |
1 | 59 } |
60 | |
61 llvm::Instruction* IRState::topallocapoint() | |
62 { | |
40 | 63 assert(!functions.empty() && "AllocaPoint stack is empty!"); |
64 return functions.back().allocapoint; | |
1 | 65 } |
66 | |
67 IRStruct& IRState::topstruct() | |
68 { | |
69 assert(!structs.empty() && "Struct vector is empty!"); | |
70 return structs.back(); | |
71 } | |
72 | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
73 IRExp* IRState::topexp() |
1 | 74 { |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
75 return exps.empty() ? NULL : &exps.back(); |
1 | 76 } |
77 | |
78 IRScope& IRState::scope() | |
79 { | |
80 assert(!scopes.empty()); | |
81 return scopes.back(); | |
82 } | |
83 | |
84 llvm::BasicBlock* IRState::scopebb() | |
85 { | |
86 return scopebegin(); | |
87 } | |
88 llvm::BasicBlock* IRState::scopebegin() | |
89 { | |
90 IRScope& s = scope(); | |
91 assert(s.begin); | |
92 return s.begin; | |
93 } | |
94 llvm::BasicBlock* IRState::scopeend() | |
95 { | |
96 IRScope& s = scope(); | |
97 assert(s.end); | |
98 return s.end; | |
99 } | |
100 bool IRState::scopereturned() | |
101 { | |
14
0e86428ee567
[svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
6
diff
changeset
|
102 //return scope().returned; |
0e86428ee567
[svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
6
diff
changeset
|
103 return !scopebb()->empty() && scopebb()->back().isTerminator(); |
1 | 104 } |
105 | |
106 ////////////////////////////////////////////////////////////////////////////////////////// | |
107 | |
108 IRStruct::IRStruct() | |
109 : recty(llvm::OpaqueType::get()) | |
110 { | |
111 type = 0; | |
31
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
14
diff
changeset
|
112 queueFuncs = true; |
1 | 113 } |
114 | |
6 | 115 IRStruct::IRStruct(Type* t) |
1 | 116 : recty(llvm::OpaqueType::get()) |
117 { | |
118 type = t; | |
31
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
14
diff
changeset
|
119 queueFuncs = true; |
1 | 120 } |
121 | |
40 | 122 ////////////////////////////////////////////////////////////////////////////////////////// |
123 | |
124 IRFinally::IRFinally() | |
125 : bb(NULL), ret(false), retval(NULL) | |
126 { | |
127 } | |
128 | |
129 IRFinally::IRFinally(llvm::BasicBlock* b) | |
130 : bb(b), ret(false), retval(NULL) | |
1 | 131 { |
132 } | |
40 | 133 |
134 ////////////////////////////////////////////////////////////////////////////////////////// | |
135 | |
136 LLVMBuilder* IRBuilderHelper::operator->() | |
137 { | |
138 LLVMBuilder& b = state->scope().builder; | |
139 assert(b.GetInsertBlock() != NULL); | |
140 return &b; | |
141 } | |
142 | |
143 ////////////////////////////////////////////////////////////////////////////////////////// | |
144 | |
145 IRFunction::IRFunction(FuncDeclaration* fd) | |
146 { | |
147 decl = fd; | |
148 Type* t = LLVM_DtoDType(fd->type); | |
149 assert(t->ty == Tfunction); | |
150 type = (TypeFunction*)t; | |
151 func = NULL; | |
152 allocapoint = NULL; | |
153 } | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
154 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
155 ////////////////////////////////////////////////////////////////////////////////////////// |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
156 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
157 IRExp::IRExp() |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
158 { |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
159 e1 = e2 = NULL; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
160 v = NULL; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
161 } |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
162 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
163 IRExp::IRExp(Expression* l, Expression* r, llvm::Value* val) |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
164 { |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
165 e1 = l; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
166 e2 = r; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
167 v = val; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
168 } |