Mercurial > projects > ldc
comparison gen/irstate.c @ 40:8b0e809563df trunk
[svn r44] Lots of bug fixes.
New array literal support
New array ~= operator support (for single element)
New with statement support
More...
author | lindquist |
---|---|
date | Fri, 19 Oct 2007 07:43:21 +0200 |
parents | 2841234d2aea |
children | 28e99b04a132 |
comparison
equal
deleted
inserted
replaced
39:fd5e8bbfcb25 | 40:8b0e809563df |
---|---|
2 * This file contains the implementations of the backend routines. | 2 * This file contains the implementations of the backend routines. |
3 * For dmdfe these do nothing but print a message saying the module | 3 * For dmdfe these do nothing but print a message saying the module |
4 * has been parsed. Substitute your own behaviors for these routimes. | 4 * has been parsed. Substitute your own behaviors for these routimes. |
5 */ | 5 */ |
6 | 6 |
7 #include <cstdarg> | |
8 | |
9 #include "gen/llvm.h" | |
10 | |
7 #include "mtype.h" | 11 #include "mtype.h" |
12 #include "declaration.h" | |
13 | |
8 #include "gen/irstate.h" | 14 #include "gen/irstate.h" |
15 #include "tollvm.h" | |
9 | 16 |
10 IRState* gIR = 0; | 17 IRState* gIR = 0; |
11 llvm::TargetData* gTargetData = 0; | 18 llvm::TargetData* gTargetData = 0; |
12 | 19 |
13 ////////////////////////////////////////////////////////////////////////////////////////// | 20 ////////////////////////////////////////////////////////////////////////////////////////// |
14 IRScope::IRScope() | 21 IRScope::IRScope() |
15 { | 22 { |
16 begin = end = 0; | 23 begin = end = NULL; |
17 returned = false; | |
18 } | 24 } |
19 | 25 |
20 IRScope::IRScope(llvm::BasicBlock* b, llvm::BasicBlock* e) | 26 IRScope::IRScope(llvm::BasicBlock* b, llvm::BasicBlock* e) |
21 { | 27 { |
22 begin = b; | 28 begin = b; |
23 end = e; | 29 end = e; |
24 returned = false; | 30 builder.SetInsertPoint(b); |
25 } | 31 } |
26 | 32 |
27 ////////////////////////////////////////////////////////////////////////////////////////// | 33 ////////////////////////////////////////////////////////////////////////////////////////// |
28 IRState::IRState() | 34 IRState::IRState() |
29 { | 35 { |
30 dmodule = 0; | 36 dmodule = 0; |
31 module = 0; | 37 module = 0; |
32 inLvalue = false; | 38 inLvalue = false; |
33 emitMain = false; | 39 emitMain = false; |
34 mainFunc = 0; | 40 mainFunc = 0; |
41 ir.state = this; | |
42 } | |
43 | |
44 IRFunction& IRState::func() | |
45 { | |
46 assert(!functions.empty() && "Function stack is empty!"); | |
47 return functions.back(); | |
35 } | 48 } |
36 | 49 |
37 llvm::Function* IRState::topfunc() | 50 llvm::Function* IRState::topfunc() |
38 { | 51 { |
39 assert(!funcs.empty() && "Function stack is empty!"); | 52 assert(!functions.empty() && "Function stack is empty!"); |
40 return funcs.top(); | 53 return functions.back().func; |
41 } | 54 } |
42 | 55 |
43 TypeFunction* IRState::topfunctype() | 56 TypeFunction* IRState::topfunctype() |
44 { | 57 { |
45 assert(!functypes.empty() && "TypeFunction stack is empty!"); | 58 assert(!functions.empty() && "Function stack is empty!"); |
46 return functypes.top(); | 59 return functions.back().type; |
47 } | 60 } |
48 | 61 |
49 llvm::Instruction* IRState::topallocapoint() | 62 llvm::Instruction* IRState::topallocapoint() |
50 { | 63 { |
51 assert(!functypes.empty() && "AllocaPoint stack is empty!"); | 64 assert(!functions.empty() && "AllocaPoint stack is empty!"); |
52 return functypes.top()->llvmAllocaPoint; | 65 return functions.back().allocapoint; |
53 } | 66 } |
54 | 67 |
55 IRStruct& IRState::topstruct() | 68 IRStruct& IRState::topstruct() |
56 { | 69 { |
57 assert(!structs.empty() && "Struct vector is empty!"); | 70 assert(!structs.empty() && "Struct vector is empty!"); |
106 { | 119 { |
107 type = t; | 120 type = t; |
108 queueFuncs = true; | 121 queueFuncs = true; |
109 } | 122 } |
110 | 123 |
111 IRStruct::~IRStruct() | 124 ////////////////////////////////////////////////////////////////////////////////////////// |
125 | |
126 IRFinally::IRFinally() | |
127 : bb(NULL), ret(false), retval(NULL) | |
112 { | 128 { |
113 } | 129 } |
130 | |
131 IRFinally::IRFinally(llvm::BasicBlock* b) | |
132 : bb(b), ret(false), retval(NULL) | |
133 { | |
134 } | |
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; | |
150 Type* t = LLVM_DtoDType(fd->type); | |
151 assert(t->ty == Tfunction); | |
152 type = (TypeFunction*)t; | |
153 func = NULL; | |
154 allocapoint = NULL; | |
155 } |