Mercurial > projects > ldc
annotate 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 |
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; | |
18 llvm::TargetData* gTargetData = 0; | |
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 inLvalue = false; | |
39 emitMain = false; | |
40 mainFunc = 0; | |
40 | 41 ir.state = this; |
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 | |
74 llvm::Value* IRState::toplval() | |
75 { | |
76 assert(!lvals.empty() && "Lval vector is empty!"); | |
77 return lvals.back(); | |
78 } | |
79 | |
80 IRScope& IRState::scope() | |
81 { | |
82 assert(!scopes.empty()); | |
83 return scopes.back(); | |
84 } | |
85 | |
86 llvm::BasicBlock* IRState::scopebb() | |
87 { | |
88 return scopebegin(); | |
89 } | |
90 llvm::BasicBlock* IRState::scopebegin() | |
91 { | |
92 IRScope& s = scope(); | |
93 assert(s.begin); | |
94 return s.begin; | |
95 } | |
96 llvm::BasicBlock* IRState::scopeend() | |
97 { | |
98 IRScope& s = scope(); | |
99 assert(s.end); | |
100 return s.end; | |
101 } | |
102 bool IRState::scopereturned() | |
103 { | |
14
0e86428ee567
[svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
6
diff
changeset
|
104 //return scope().returned; |
0e86428ee567
[svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
6
diff
changeset
|
105 return !scopebb()->empty() && scopebb()->back().isTerminator(); |
1 | 106 } |
107 | |
108 ////////////////////////////////////////////////////////////////////////////////////////// | |
109 | |
110 IRStruct::IRStruct() | |
111 : recty(llvm::OpaqueType::get()) | |
112 { | |
113 type = 0; | |
31
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
14
diff
changeset
|
114 queueFuncs = true; |
1 | 115 } |
116 | |
6 | 117 IRStruct::IRStruct(Type* t) |
1 | 118 : recty(llvm::OpaqueType::get()) |
119 { | |
120 type = t; | |
31
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
14
diff
changeset
|
121 queueFuncs = true; |
1 | 122 } |
123 | |
40 | 124 ////////////////////////////////////////////////////////////////////////////////////////// |
125 | |
126 IRFinally::IRFinally() | |
127 : bb(NULL), ret(false), retval(NULL) | |
128 { | |
129 } | |
130 | |
131 IRFinally::IRFinally(llvm::BasicBlock* b) | |
132 : bb(b), ret(false), retval(NULL) | |
1 | 133 { |
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; | |
150 Type* t = LLVM_DtoDType(fd->type); | |
151 assert(t->ty == Tfunction); | |
152 type = (TypeFunction*)t; | |
153 func = NULL; | |
154 allocapoint = NULL; | |
155 } |