comparison gen/irstate.cpp @ 86:fd32135dca3e trunk

[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!! Lots of bugfixes. Added support for special foreach on strings. Added std.array, std.utf, std.ctype and std.uni to phobos. Changed all the .c files in the gen dir to .cpp (it *is* C++ after all)
author lindquist
date Sat, 03 Nov 2007 14:44:58 +0100
parents gen/irstate.c@d8dd47ef3973
children 61615fa85940
comparison
equal deleted inserted replaced
85:f869c636a113 86:fd32135dca3e
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
7 #include <cstdarg>
8
9 #include "gen/llvm.h"
10
11 #include "mtype.h"
12 #include "declaration.h"
13
14 #include "gen/irstate.h"
15 #include "tollvm.h"
16
17 IRState* gIR = 0;
18 const llvm::TargetData* gTargetData = 0;
19
20 //////////////////////////////////////////////////////////////////////////////////////////
21 IRScope::IRScope()
22 {
23 begin = end = NULL;
24 }
25
26 IRScope::IRScope(llvm::BasicBlock* b, llvm::BasicBlock* e)
27 {
28 begin = b;
29 end = e;
30 builder.SetInsertPoint(b);
31 }
32
33 //////////////////////////////////////////////////////////////////////////////////////////
34 IRState::IRState()
35 {
36 dmodule = 0;
37 module = 0;
38 emitMain = false;
39 mainFunc = 0;
40 ir.state = this;
41 dwarfCompileUnit = 0;
42 }
43
44 IRFunction& IRState::func()
45 {
46 assert(!functions.empty() && "Function stack is empty!");
47 return functions.back();
48 }
49
50 llvm::Function* IRState::topfunc()
51 {
52 assert(!functions.empty() && "Function stack is empty!");
53 return functions.back().func;
54 }
55
56 TypeFunction* IRState::topfunctype()
57 {
58 assert(!functions.empty() && "Function stack is empty!");
59 return functions.back().type;
60 }
61
62 llvm::Instruction* IRState::topallocapoint()
63 {
64 assert(!functions.empty() && "AllocaPoint stack is empty!");
65 return functions.back().allocapoint;
66 }
67
68 IRStruct& IRState::topstruct()
69 {
70 assert(!structs.empty() && "Struct vector is empty!");
71 return structs.back();
72 }
73
74 IRExp* IRState::topexp()
75 {
76 return exps.empty() ? NULL : &exps.back();
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 {
103 //return scope().returned;
104 return !scopebb()->empty() && scopebb()->back().isTerminator();
105 }
106
107 //////////////////////////////////////////////////////////////////////////////////////////
108
109 IRStruct::IRStruct()
110 : recty(llvm::OpaqueType::get())
111 {
112 type = 0;
113 queueFuncs = true;
114 }
115
116 IRStruct::IRStruct(Type* t)
117 : recty(llvm::OpaqueType::get())
118 {
119 type = t;
120 queueFuncs = true;
121 }
122
123 //////////////////////////////////////////////////////////////////////////////////////////
124
125 IRFinally::IRFinally()
126 {
127 bb = 0;
128 retbb = 0;
129 }
130
131 IRFinally::IRFinally(llvm::BasicBlock* b, llvm::BasicBlock* rb)
132 {
133 bb = b;
134 retbb = rb;
135 }
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;
151 Type* t = DtoDType(fd->type);
152 assert(t->ty == Tfunction);
153 type = (TypeFunction*)t;
154 func = NULL;
155 allocapoint = NULL;
156 finallyretval = NULL;
157 }
158
159 //////////////////////////////////////////////////////////////////////////////////////////
160
161 IRExp::IRExp()
162 {
163 e1 = e2 = NULL;
164 v = NULL;
165 }
166
167 IRExp::IRExp(Expression* l, Expression* r, DValue* val)
168 {
169 e1 = l;
170 e2 = r;
171 v = val;
172 }