Mercurial > projects > ldc
annotate gen/irstate.cpp @ 109:5ab8e92611f9 trunk
[svn r113] Added initial support for associative arrays (AAs).
Fixed some problems with the string runtime support functions.
Fixed initialization of array of structs.
Fixed slice assignment where LHS is slice but RHS is dynamic array.
Fixed problems with result of assignment expressions.
Fixed foreach problems with key type mismatches.
author | lindquist |
---|---|
date | Wed, 21 Nov 2007 04:13:15 +0100 |
parents | 288fe1029e1f |
children | 27b9f749d9fe |
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 | |
100 | 43 IRFunction* IRState::func() |
40 | 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!"); |
100 | 52 return functions.back()->func; |
1 | 53 } |
54 | |
55 TypeFunction* IRState::topfunctype() | |
56 { | |
40 | 57 assert(!functions.empty() && "Function stack is empty!"); |
100 | 58 return functions.back()->type; |
1 | 59 } |
60 | |
61 llvm::Instruction* IRState::topallocapoint() | |
62 { | |
40 | 63 assert(!functions.empty() && "AllocaPoint stack is empty!"); |
100 | 64 return functions.back()->allocapoint; |
1 | 65 } |
66 | |
100 | 67 IRStruct* IRState::topstruct() |
1 | 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 IRScope& s = scope(); | |
87 assert(s.begin); | |
88 return s.begin; | |
89 } | |
90 llvm::BasicBlock* IRState::scopeend() | |
91 { | |
92 IRScope& s = scope(); | |
93 assert(s.end); | |
94 return s.end; | |
95 } | |
96 bool IRState::scopereturned() | |
97 { | |
14
0e86428ee567
[svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
6
diff
changeset
|
98 //return scope().returned; |
0e86428ee567
[svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
6
diff
changeset
|
99 return !scopebb()->empty() && scopebb()->back().isTerminator(); |
1 | 100 } |
101 | |
102 ////////////////////////////////////////////////////////////////////////////////////////// | |
103 | |
6 | 104 IRStruct::IRStruct(Type* t) |
103
855adfdb8d38
[svn r107] Getting .classinfo on a class instance now works (classinfo is stored in vtable)
lindquist
parents:
100
diff
changeset
|
105 : recty((t->llvmType != NULL) ? *t->llvmType : llvm::OpaqueType::get()) |
1 | 106 { |
107 type = t; | |
100 | 108 defined = false; |
109 constinited = false; | |
1 | 110 } |
111 | |
40 | 112 ////////////////////////////////////////////////////////////////////////////////////////// |
113 | |
114 IRFinally::IRFinally() | |
115 { | |
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
|
116 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
|
117 retbb = 0; |
40 | 118 } |
119 | |
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
|
120 IRFinally::IRFinally(llvm::BasicBlock* b, llvm::BasicBlock* rb) |
1 | 121 { |
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
|
122 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
|
123 retbb = rb; |
1 | 124 } |
40 | 125 |
126 ////////////////////////////////////////////////////////////////////////////////////////// | |
127 | |
128 LLVMBuilder* IRBuilderHelper::operator->() | |
129 { | |
130 LLVMBuilder& b = state->scope().builder; | |
131 assert(b.GetInsertBlock() != NULL); | |
132 return &b; | |
133 } | |
134 | |
135 ////////////////////////////////////////////////////////////////////////////////////////// | |
136 | |
137 IRFunction::IRFunction(FuncDeclaration* fd) | |
138 { | |
139 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
|
140 Type* t = DtoDType(fd->type); |
40 | 141 assert(t->ty == Tfunction); |
142 type = (TypeFunction*)t; | |
143 func = NULL; | |
144 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
|
145 finallyretval = NULL; |
100 | 146 defined = false; |
40 | 147 } |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
148 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
149 ////////////////////////////////////////////////////////////////////////////////////////// |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
150 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
151 IRExp::IRExp() |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
152 { |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
153 e1 = e2 = NULL; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
154 v = NULL; |
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 |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
82
diff
changeset
|
157 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
|
158 { |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
159 e1 = l; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
160 e2 = r; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
161 v = val; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
162 } |
100 | 163 |
164 ////////////////////////////////////////////////////////////////////////////////////////// | |
165 | |
166 IRGlobal::IRGlobal(VarDeclaration* v) : | |
167 type(llvm::OpaqueType::get()) | |
168 { | |
169 var = v; | |
170 } |