Mercurial > projects > ldc
annotate gen/irstate.cpp @ 1533:d1652c8fb4f6
Get rid of USE_METADATA
author | Benjamin Kramer <benny.kra@gmail.com> |
---|---|
date | Sat, 11 Jul 2009 14:19:21 +0200 |
parents | ad7f2f1862d6 |
children | 61f12f4651b5 |
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" |
309 | 13 #include "statement.h" |
40 | 14 |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
15 #include "gen/irstate.h" |
40 | 16 #include "tollvm.h" |
1 | 17 |
18 IRState* gIR = 0; | |
988
2667e3a145be
- Fixed LLVM style CL args for D2.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
946
diff
changeset
|
19 llvm::TargetMachine* gTargetMachine = 0; |
73 | 20 const llvm::TargetData* gTargetData = 0; |
988
2667e3a145be
- Fixed LLVM style CL args for D2.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
946
diff
changeset
|
21 TargetABI* gABI = 0; |
1 | 22 |
23 ////////////////////////////////////////////////////////////////////////////////////////// | |
24 IRScope::IRScope() | |
1529
ad7f2f1862d6
Adjust LDC to work with the LLVMContext LLVM changes.
Christian Kamm <kamm incasoftware de>
parents:
1141
diff
changeset
|
25 : builder(llvm::getGlobalContext()) |
1 | 26 { |
40 | 27 begin = end = NULL; |
1 | 28 } |
29 | |
30 IRScope::IRScope(llvm::BasicBlock* b, llvm::BasicBlock* e) | |
1529
ad7f2f1862d6
Adjust LDC to work with the LLVMContext LLVM changes.
Christian Kamm <kamm incasoftware de>
parents:
1141
diff
changeset
|
31 : builder(b) |
1 | 32 { |
33 begin = b; | |
34 end = e; | |
1529
ad7f2f1862d6
Adjust LDC to work with the LLVMContext LLVM changes.
Christian Kamm <kamm incasoftware de>
parents:
1141
diff
changeset
|
35 } |
ad7f2f1862d6
Adjust LDC to work with the LLVMContext LLVM changes.
Christian Kamm <kamm incasoftware de>
parents:
1141
diff
changeset
|
36 |
ad7f2f1862d6
Adjust LDC to work with the LLVMContext LLVM changes.
Christian Kamm <kamm incasoftware de>
parents:
1141
diff
changeset
|
37 const IRScope& IRScope::operator=(const IRScope& rhs) |
ad7f2f1862d6
Adjust LDC to work with the LLVMContext LLVM changes.
Christian Kamm <kamm incasoftware de>
parents:
1141
diff
changeset
|
38 { |
ad7f2f1862d6
Adjust LDC to work with the LLVMContext LLVM changes.
Christian Kamm <kamm incasoftware de>
parents:
1141
diff
changeset
|
39 begin = rhs.begin; |
ad7f2f1862d6
Adjust LDC to work with the LLVMContext LLVM changes.
Christian Kamm <kamm incasoftware de>
parents:
1141
diff
changeset
|
40 end = rhs.end; |
ad7f2f1862d6
Adjust LDC to work with the LLVMContext LLVM changes.
Christian Kamm <kamm incasoftware de>
parents:
1141
diff
changeset
|
41 builder.SetInsertPoint(begin); |
1 | 42 } |
43 | |
44 ////////////////////////////////////////////////////////////////////////////////////////// | |
1141
f99a3b393c03
Reorganize EnclosingHandlers to require less changes to the frontend and allow us to
Christian Kamm <kamm incasoftware de>
parents:
1013
diff
changeset
|
45 IRTargetScope::IRTargetScope() |
145
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 } |
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
48 |
1141
f99a3b393c03
Reorganize EnclosingHandlers to require less changes to the frontend and allow us to
Christian Kamm <kamm incasoftware de>
parents:
1013
diff
changeset
|
49 IRTargetScope::IRTargetScope(Statement* s, EnclosingHandler* enclosinghandler, llvm::BasicBlock* continueTarget, llvm::BasicBlock* breakTarget) |
145
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
50 { |
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
51 this->s = s; |
309 | 52 this->enclosinghandler = enclosinghandler; |
1141
f99a3b393c03
Reorganize EnclosingHandlers to require less changes to the frontend and allow us to
Christian Kamm <kamm incasoftware de>
parents:
1013
diff
changeset
|
53 this->breakTarget = breakTarget; |
f99a3b393c03
Reorganize EnclosingHandlers to require less changes to the frontend and allow us to
Christian Kamm <kamm incasoftware de>
parents:
1013
diff
changeset
|
54 this->continueTarget = continueTarget; |
145
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
55 } |
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
56 |
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
57 ////////////////////////////////////////////////////////////////////////////////////////// |
946
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
493
diff
changeset
|
58 IRState::IRState(llvm::Module* m) |
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
493
diff
changeset
|
59 : module(m), difactory(*m) |
1 | 60 { |
161
3a891cfcd249
[svn r177] moved variable for interface info type from being local static to being within IRState
ChristianK
parents:
148
diff
changeset
|
61 interfaceInfoType = NULL; |
309 | 62 mutexType = NULL; |
323
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
315
diff
changeset
|
63 moduleRefType = NULL; |
309 | 64 |
1 | 65 dmodule = 0; |
66 emitMain = false; | |
67 mainFunc = 0; | |
40 | 68 ir.state = this; |
233
76ee1bbe487e
[svn r249] Changed inline asm clobbers to a set instead of a list so we don't get duplicate clobbers.
lindquist
parents:
232
diff
changeset
|
69 asmBlock = NULL; |
252 | 70 |
71 dwarfCUs = NULL; | |
72 dwarfSPs = NULL; | |
73 dwarfGVs = NULL; | |
40 | 74 } |
75 | |
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
|
76 IrFunction* IRState::func() |
40 | 77 { |
78 assert(!functions.empty() && "Function stack is empty!"); | |
79 return functions.back(); | |
1 | 80 } |
81 | |
82 llvm::Function* IRState::topfunc() | |
83 { | |
40 | 84 assert(!functions.empty() && "Function stack is empty!"); |
100 | 85 return functions.back()->func; |
1 | 86 } |
87 | |
88 TypeFunction* IRState::topfunctype() | |
89 { | |
40 | 90 assert(!functions.empty() && "Function stack is empty!"); |
100 | 91 return functions.back()->type; |
1 | 92 } |
93 | |
94 llvm::Instruction* IRState::topallocapoint() | |
95 { | |
40 | 96 assert(!functions.empty() && "AllocaPoint stack is empty!"); |
100 | 97 return functions.back()->allocapoint; |
1 | 98 } |
99 | |
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
|
100 IrStruct* IRState::topstruct() |
1 | 101 { |
102 assert(!structs.empty() && "Struct vector is empty!"); | |
103 return structs.back(); | |
104 } | |
105 | |
106 IRScope& IRState::scope() | |
107 { | |
108 assert(!scopes.empty()); | |
109 return scopes.back(); | |
110 } | |
111 | |
112 llvm::BasicBlock* IRState::scopebb() | |
113 { | |
114 IRScope& s = scope(); | |
115 assert(s.begin); | |
116 return s.begin; | |
117 } | |
118 llvm::BasicBlock* IRState::scopeend() | |
119 { | |
120 IRScope& s = scope(); | |
121 assert(s.end); | |
122 return s.end; | |
123 } | |
124 bool IRState::scopereturned() | |
125 { | |
14
0e86428ee567
[svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
6
diff
changeset
|
126 //return scope().returned; |
0e86428ee567
[svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
6
diff
changeset
|
127 return !scopebb()->empty() && scopebb()->back().isTerminator(); |
1 | 128 } |
129 | |
1013
8c73ff5f69e0
Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents:
988
diff
changeset
|
130 LLCallSite IRState::CreateCallOrInvoke(LLValue* Callee, const char* Name) |
315
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
131 { |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
132 LLSmallVector<LLValue*, 1> args; |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
133 return CreateCallOrInvoke(Callee, args.begin(), args.end(), Name); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
134 } |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
135 |
1013
8c73ff5f69e0
Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents:
988
diff
changeset
|
136 LLCallSite IRState::CreateCallOrInvoke(LLValue* Callee, LLValue* Arg1, const char* Name) |
315
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
137 { |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
138 LLSmallVector<LLValue*, 1> args; |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
139 args.push_back(Arg1); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
140 return CreateCallOrInvoke(Callee, args.begin(), args.end(), Name); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
141 } |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
142 |
1013
8c73ff5f69e0
Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents:
988
diff
changeset
|
143 LLCallSite IRState::CreateCallOrInvoke2(LLValue* Callee, LLValue* Arg1, LLValue* Arg2, const char* Name) |
315
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
144 { |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
145 LLSmallVector<LLValue*, 2> args; |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
146 args.push_back(Arg1); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
147 args.push_back(Arg2); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
148 return CreateCallOrInvoke(Callee, args.begin(), args.end(), Name); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
149 } |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
150 |
1013
8c73ff5f69e0
Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents:
988
diff
changeset
|
151 LLCallSite IRState::CreateCallOrInvoke3(LLValue* Callee, LLValue* Arg1, LLValue* Arg2, LLValue* Arg3, const char* Name) |
315
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
152 { |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
153 LLSmallVector<LLValue*, 3> args; |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
154 args.push_back(Arg1); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
155 args.push_back(Arg2); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
156 args.push_back(Arg3); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
157 return CreateCallOrInvoke(Callee, args.begin(), args.end(), Name); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
158 } |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
159 |
1013
8c73ff5f69e0
Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents:
988
diff
changeset
|
160 LLCallSite IRState::CreateCallOrInvoke4(LLValue* Callee, LLValue* Arg1, LLValue* Arg2, LLValue* Arg3, LLValue* Arg4, const char* Name) |
315
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
161 { |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
162 LLSmallVector<LLValue*, 4> args; |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
163 args.push_back(Arg1); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
164 args.push_back(Arg2); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
165 args.push_back(Arg3); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
166 args.push_back(Arg4); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
167 return CreateCallOrInvoke(Callee, args.begin(), args.end(), Name); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
168 } |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
169 |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
170 |
1 | 171 ////////////////////////////////////////////////////////////////////////////////////////// |
172 | |
493
017ca8645a1f
Make llvmdc work with llvm 2.4svn revision 54614. Breaks compatibility with llvm 2.3.
Christian Kamm <kamm incasoftware de>
parents:
334
diff
changeset
|
173 IRBuilder<>* IRBuilderHelper::operator->() |
40 | 174 { |
493
017ca8645a1f
Make llvmdc work with llvm 2.4svn revision 54614. Breaks compatibility with llvm 2.3.
Christian Kamm <kamm incasoftware de>
parents:
334
diff
changeset
|
175 IRBuilder<>& b = state->scope().builder; |
40 | 176 assert(b.GetInsertBlock() != NULL); |
177 return &b; | |
178 } |