Mercurial > projects > ldc
annotate gen/irstate.cpp @ 189:3aed08fb64f4 trunk
[svn r205] moved some local static variables used for memset and memcpy intrinsics to IrState
author | ChristianK |
---|---|
date | Sat, 10 May 2008 19:00:11 +0200 |
parents | 3a891cfcd249 |
children | 9d44ec83acd1 |
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 ////////////////////////////////////////////////////////////////////////////////////////// | |
145
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
34 IRLoopScope::IRLoopScope() |
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
35 { |
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
36 } |
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
37 |
148
86d3bb8ca33e
[svn r154] renaming enclosingtry to enclosingtryfinally to distinguish it from enclosingtrycatch, which will probably need to be added for exception handling
ChristianK
parents:
145
diff
changeset
|
38 IRLoopScope::IRLoopScope(Statement* s, TryFinallyStatement* enclosingtryfinally, llvm::BasicBlock* b, llvm::BasicBlock* e) |
145
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
39 { |
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
40 begin = b; |
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
41 end = e; |
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
42 builder.SetInsertPoint(b); |
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
43 this->s = s; |
148
86d3bb8ca33e
[svn r154] renaming enclosingtry to enclosingtryfinally to distinguish it from enclosingtrycatch, which will probably need to be added for exception handling
ChristianK
parents:
145
diff
changeset
|
44 this->enclosingtryfinally = enclosingtryfinally; |
145
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
45 } |
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
46 |
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
47 ////////////////////////////////////////////////////////////////////////////////////////// |
1 | 48 IRState::IRState() |
49 { | |
161
3a891cfcd249
[svn r177] moved variable for interface info type from being local static to being within IRState
ChristianK
parents:
148
diff
changeset
|
50 interfaceInfoType = NULL; |
1 | 51 dmodule = 0; |
52 module = 0; | |
53 emitMain = false; | |
54 mainFunc = 0; | |
40 | 55 ir.state = this; |
189
3aed08fb64f4
[svn r205] moved some local static variables used for memset and memcpy intrinsics to IrState
ChristianK
parents:
161
diff
changeset
|
56 llvm_DeclareMemSet32 = NULL; |
3aed08fb64f4
[svn r205] moved some local static variables used for memset and memcpy intrinsics to IrState
ChristianK
parents:
161
diff
changeset
|
57 llvm_DeclareMemSet64 = NULL; |
3aed08fb64f4
[svn r205] moved some local static variables used for memset and memcpy intrinsics to IrState
ChristianK
parents:
161
diff
changeset
|
58 llvm_DeclareMemCpy32 = NULL; |
3aed08fb64f4
[svn r205] moved some local static variables used for memset and memcpy intrinsics to IrState
ChristianK
parents:
161
diff
changeset
|
59 llvm_DeclareMemCpy64 = NULL; |
40 | 60 } |
61 | |
136
0e28624814e8
[svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents:
113
diff
changeset
|
62 IrFunction* IRState::func() |
40 | 63 { |
64 assert(!functions.empty() && "Function stack is empty!"); | |
65 return functions.back(); | |
1 | 66 } |
67 | |
68 llvm::Function* IRState::topfunc() | |
69 { | |
40 | 70 assert(!functions.empty() && "Function stack is empty!"); |
100 | 71 return functions.back()->func; |
1 | 72 } |
73 | |
74 TypeFunction* IRState::topfunctype() | |
75 { | |
40 | 76 assert(!functions.empty() && "Function stack is empty!"); |
100 | 77 return functions.back()->type; |
1 | 78 } |
79 | |
80 llvm::Instruction* IRState::topallocapoint() | |
81 { | |
40 | 82 assert(!functions.empty() && "AllocaPoint stack is empty!"); |
100 | 83 return functions.back()->allocapoint; |
1 | 84 } |
85 | |
136
0e28624814e8
[svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents:
113
diff
changeset
|
86 IrStruct* IRState::topstruct() |
1 | 87 { |
88 assert(!structs.empty() && "Struct vector is empty!"); | |
89 return structs.back(); | |
90 } | |
91 | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
92 IRExp* IRState::topexp() |
1 | 93 { |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
94 return exps.empty() ? NULL : &exps.back(); |
1 | 95 } |
96 | |
97 IRScope& IRState::scope() | |
98 { | |
99 assert(!scopes.empty()); | |
100 return scopes.back(); | |
101 } | |
102 | |
103 llvm::BasicBlock* IRState::scopebb() | |
104 { | |
105 IRScope& s = scope(); | |
106 assert(s.begin); | |
107 return s.begin; | |
108 } | |
109 llvm::BasicBlock* IRState::scopeend() | |
110 { | |
111 IRScope& s = scope(); | |
112 assert(s.end); | |
113 return s.end; | |
114 } | |
115 bool IRState::scopereturned() | |
116 { | |
14
0e86428ee567
[svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
6
diff
changeset
|
117 //return scope().returned; |
0e86428ee567
[svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
6
diff
changeset
|
118 return !scopebb()->empty() && scopebb()->back().isTerminator(); |
1 | 119 } |
120 | |
121 ////////////////////////////////////////////////////////////////////////////////////////// | |
122 | |
40 | 123 LLVMBuilder* IRBuilderHelper::operator->() |
124 { | |
125 LLVMBuilder& b = state->scope().builder; | |
126 assert(b.GetInsertBlock() != NULL); | |
127 return &b; | |
128 } | |
129 | |
130 ////////////////////////////////////////////////////////////////////////////////////////// | |
131 | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
132 IRExp::IRExp() |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
133 { |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
134 e1 = e2 = NULL; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
135 v = NULL; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
136 } |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
137 |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
82
diff
changeset
|
138 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
|
139 { |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
140 e1 = l; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
141 e2 = r; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
142 v = val; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
143 } |