Mercurial > projects > ldc
annotate gen/irstate.cpp @ 91:3f949c6e2e9d trunk
[svn r95] added support for mains like:
T main(string[] args)
fixed a bug with slicing a pointer that is an argument with no storage
author | lindquist |
---|---|
date | Wed, 07 Nov 2007 04:52:56 +0100 |
parents | fd32135dca3e |
children | 61615fa85940 |
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; |
82
d8dd47ef3973
[svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
81
diff
changeset
|
41 dwarfCompileUnit = 0; |
40 | 42 } |
43 | |
44 IRFunction& IRState::func() | |
45 { | |
46 assert(!functions.empty() && "Function stack is empty!"); | |
47 return functions.back(); | |
1 | 48 } |
49 | |
50 llvm::Function* IRState::topfunc() | |
51 { | |
40 | 52 assert(!functions.empty() && "Function stack is empty!"); |
53 return functions.back().func; | |
1 | 54 } |
55 | |
56 TypeFunction* IRState::topfunctype() | |
57 { | |
40 | 58 assert(!functions.empty() && "Function stack is empty!"); |
59 return functions.back().type; | |
1 | 60 } |
61 | |
62 llvm::Instruction* IRState::topallocapoint() | |
63 { | |
40 | 64 assert(!functions.empty() && "AllocaPoint stack is empty!"); |
65 return functions.back().allocapoint; | |
1 | 66 } |
67 | |
68 IRStruct& IRState::topstruct() | |
69 { | |
70 assert(!structs.empty() && "Struct vector is empty!"); | |
71 return structs.back(); | |
72 } | |
73 | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
74 IRExp* IRState::topexp() |
1 | 75 { |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
76 return exps.empty() ? NULL : &exps.back(); |
1 | 77 } |
78 | |
79 IRScope& IRState::scope() | |
80 { | |
81 assert(!scopes.empty()); | |
82 return scopes.back(); | |
83 } | |
84 | |
85 llvm::BasicBlock* IRState::scopebb() | |
86 { | |
87 return scopebegin(); | |
88 } | |
89 llvm::BasicBlock* IRState::scopebegin() | |
90 { | |
91 IRScope& s = scope(); | |
92 assert(s.begin); | |
93 return s.begin; | |
94 } | |
95 llvm::BasicBlock* IRState::scopeend() | |
96 { | |
97 IRScope& s = scope(); | |
98 assert(s.end); | |
99 return s.end; | |
100 } | |
101 bool IRState::scopereturned() | |
102 { | |
14
0e86428ee567
[svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
6
diff
changeset
|
103 //return scope().returned; |
0e86428ee567
[svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
6
diff
changeset
|
104 return !scopebb()->empty() && scopebb()->back().isTerminator(); |
1 | 105 } |
106 | |
107 ////////////////////////////////////////////////////////////////////////////////////////// | |
108 | |
109 IRStruct::IRStruct() | |
110 : recty(llvm::OpaqueType::get()) | |
111 { | |
112 type = 0; | |
31
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
14
diff
changeset
|
113 queueFuncs = true; |
1 | 114 } |
115 | |
6 | 116 IRStruct::IRStruct(Type* t) |
1 | 117 : recty(llvm::OpaqueType::get()) |
118 { | |
119 type = t; | |
31
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
14
diff
changeset
|
120 queueFuncs = true; |
1 | 121 } |
122 | |
40 | 123 ////////////////////////////////////////////////////////////////////////////////////////// |
124 | |
125 IRFinally::IRFinally() | |
126 { | |
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
|
127 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
|
128 retbb = 0; |
40 | 129 } |
130 | |
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
|
131 IRFinally::IRFinally(llvm::BasicBlock* b, llvm::BasicBlock* rb) |
1 | 132 { |
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
|
133 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
|
134 retbb = rb; |
1 | 135 } |
40 | 136 |
137 ////////////////////////////////////////////////////////////////////////////////////////// | |
138 | |
139 LLVMBuilder* IRBuilderHelper::operator->() | |
140 { | |
141 LLVMBuilder& b = state->scope().builder; | |
142 assert(b.GetInsertBlock() != NULL); | |
143 return &b; | |
144 } | |
145 | |
146 ////////////////////////////////////////////////////////////////////////////////////////// | |
147 | |
148 IRFunction::IRFunction(FuncDeclaration* fd) | |
149 { | |
150 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
|
151 Type* t = DtoDType(fd->type); |
40 | 152 assert(t->ty == Tfunction); |
153 type = (TypeFunction*)t; | |
154 func = NULL; | |
155 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
|
156 finallyretval = NULL; |
40 | 157 } |
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 ////////////////////////////////////////////////////////////////////////////////////////// |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
160 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
161 IRExp::IRExp() |
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 e1 = e2 = NULL; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
164 v = NULL; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
165 } |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
166 |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
82
diff
changeset
|
167 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
|
168 { |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
169 e1 = l; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
170 e2 = r; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
171 v = val; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
172 } |