Mercurial > projects > ldc
annotate gen/irstate.cpp @ 99:a676a7743642 trunk
[svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
author | lindquist |
---|---|
date | Thu, 15 Nov 2007 00:24:44 +0100 |
parents | 61615fa85940 |
children | 5071469303d4 |
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; | |
73 | 18 const llvm::TargetData* gTargetData = 0; |
1 | 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 { | |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
73
diff
changeset
|
126 bb = 0; |
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
73
diff
changeset
|
127 retbb = 0; |
40 | 128 } |
129 | |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
73
diff
changeset
|
130 IRFinally::IRFinally(llvm::BasicBlock* b, llvm::BasicBlock* rb) |
1 | 131 { |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
73
diff
changeset
|
132 bb = b; |
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
73
diff
changeset
|
133 retbb = rb; |
1 | 134 } |
40 | 135 |
136 ////////////////////////////////////////////////////////////////////////////////////////// | |
137 | |
138 LLVMBuilder* IRBuilderHelper::operator->() | |
139 { | |
140 LLVMBuilder& b = state->scope().builder; | |
141 assert(b.GetInsertBlock() != NULL); | |
142 return &b; | |
143 } | |
144 | |
145 ////////////////////////////////////////////////////////////////////////////////////////// | |
146 | |
147 IRFunction::IRFunction(FuncDeclaration* fd) | |
148 { | |
149 decl = fd; | |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
73
diff
changeset
|
150 Type* t = DtoDType(fd->type); |
40 | 151 assert(t->ty == Tfunction); |
152 type = (TypeFunction*)t; | |
153 func = NULL; | |
154 allocapoint = NULL; | |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
73
diff
changeset
|
155 finallyretval = NULL; |
40 | 156 } |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
157 |
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 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
160 IRExp::IRExp() |
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 e1 = e2 = NULL; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
163 v = NULL; |
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 |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
82
diff
changeset
|
166 IRExp::IRExp(Expression* l, Expression* r, DValue* val) |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
167 { |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
168 e1 = l; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
169 e2 = r; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
170 v = val; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
171 } |