Mercurial > projects > ldc
annotate gen/irstate.cpp @ 1650:40bd4a0d4870
Update to work with LLVM 2.7.
Removed use of dyn_cast, llvm no compiles
without exceptions and rtti by
default. We do need exceptions for the libconfig stuff, but rtti isn't
necessary (anymore).
Debug info needs to be rewritten, as in LLVM 2.7 the format has
completely changed. To have something to look at while rewriting, the
old code has been wrapped inside #ifndef DISABLE_DEBUG_INFO , this means
that you have to define this to compile at the moment.
Updated tango 0.99.9 patch to include updated EH runtime code, which is
needed for LLVM 2.7 as well.
author | Tomas Lindquist Olsen |
---|---|
date | Wed, 19 May 2010 12:42:32 +0200 |
parents | 7f728c52e63c |
children |
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() | |
1535
61f12f4651b5
Don't use llvm::getGlobalContext() anymore
Benjamin Kramer <benny.kra@gmail.com>
parents:
1529
diff
changeset
|
25 : builder(gIR->context()) |
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); |
1586
7f728c52e63c
Fix several 'reaches end of function' warnings by making fatal noreturn.
Christian Kamm <kamm incasoftware de>
parents:
1535
diff
changeset
|
42 return *this; |
1 | 43 } |
44 | |
45 ////////////////////////////////////////////////////////////////////////////////////////// | |
1141
f99a3b393c03
Reorganize EnclosingHandlers to require less changes to the frontend and allow us to
Christian Kamm <kamm incasoftware de>
parents:
1013
diff
changeset
|
46 IRTargetScope::IRTargetScope() |
145
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 } |
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
49 |
1141
f99a3b393c03
Reorganize EnclosingHandlers to require less changes to the frontend and allow us to
Christian Kamm <kamm incasoftware de>
parents:
1013
diff
changeset
|
50 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
|
51 { |
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
52 this->s = s; |
309 | 53 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
|
54 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
|
55 this->continueTarget = continueTarget; |
145
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 |
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
58 ////////////////////////////////////////////////////////////////////////////////////////// |
946
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
493
diff
changeset
|
59 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
|
60 : module(m), difactory(*m) |
1 | 61 { |
161
3a891cfcd249
[svn r177] moved variable for interface info type from being local static to being within IRState
ChristianK
parents:
148
diff
changeset
|
62 interfaceInfoType = NULL; |
309 | 63 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
|
64 moduleRefType = NULL; |
309 | 65 |
1 | 66 dmodule = 0; |
67 emitMain = false; | |
68 mainFunc = 0; | |
40 | 69 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
|
70 asmBlock = NULL; |
252 | 71 |
72 dwarfCUs = NULL; | |
73 dwarfSPs = NULL; | |
74 dwarfGVs = NULL; | |
40 | 75 } |
76 | |
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
|
77 IrFunction* IRState::func() |
40 | 78 { |
79 assert(!functions.empty() && "Function stack is empty!"); | |
80 return functions.back(); | |
1 | 81 } |
82 | |
83 llvm::Function* IRState::topfunc() | |
84 { | |
40 | 85 assert(!functions.empty() && "Function stack is empty!"); |
100 | 86 return functions.back()->func; |
1 | 87 } |
88 | |
89 TypeFunction* IRState::topfunctype() | |
90 { | |
40 | 91 assert(!functions.empty() && "Function stack is empty!"); |
100 | 92 return functions.back()->type; |
1 | 93 } |
94 | |
95 llvm::Instruction* IRState::topallocapoint() | |
96 { | |
40 | 97 assert(!functions.empty() && "AllocaPoint stack is empty!"); |
100 | 98 return functions.back()->allocapoint; |
1 | 99 } |
100 | |
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
|
101 IrStruct* IRState::topstruct() |
1 | 102 { |
103 assert(!structs.empty() && "Struct vector is empty!"); | |
104 return structs.back(); | |
105 } | |
106 | |
107 IRScope& IRState::scope() | |
108 { | |
109 assert(!scopes.empty()); | |
110 return scopes.back(); | |
111 } | |
112 | |
113 llvm::BasicBlock* IRState::scopebb() | |
114 { | |
115 IRScope& s = scope(); | |
116 assert(s.begin); | |
117 return s.begin; | |
118 } | |
119 llvm::BasicBlock* IRState::scopeend() | |
120 { | |
121 IRScope& s = scope(); | |
122 assert(s.end); | |
123 return s.end; | |
124 } | |
125 bool IRState::scopereturned() | |
126 { | |
14
0e86428ee567
[svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
6
diff
changeset
|
127 //return scope().returned; |
0e86428ee567
[svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
6
diff
changeset
|
128 return !scopebb()->empty() && scopebb()->back().isTerminator(); |
1 | 129 } |
130 | |
1013
8c73ff5f69e0
Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents:
988
diff
changeset
|
131 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
|
132 { |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
133 LLSmallVector<LLValue*, 1> args; |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
134 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
|
135 } |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
136 |
1013
8c73ff5f69e0
Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents:
988
diff
changeset
|
137 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
|
138 { |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
139 LLSmallVector<LLValue*, 1> args; |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
140 args.push_back(Arg1); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
141 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
|
142 } |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
143 |
1013
8c73ff5f69e0
Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents:
988
diff
changeset
|
144 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
|
145 { |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
146 LLSmallVector<LLValue*, 2> args; |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
147 args.push_back(Arg1); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
148 args.push_back(Arg2); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
149 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
|
150 } |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
151 |
1013
8c73ff5f69e0
Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents:
988
diff
changeset
|
152 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
|
153 { |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
154 LLSmallVector<LLValue*, 3> args; |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
155 args.push_back(Arg1); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
156 args.push_back(Arg2); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
157 args.push_back(Arg3); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
158 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
|
159 } |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
160 |
1013
8c73ff5f69e0
Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents:
988
diff
changeset
|
161 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
|
162 { |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
163 LLSmallVector<LLValue*, 4> args; |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
164 args.push_back(Arg1); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
165 args.push_back(Arg2); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
166 args.push_back(Arg3); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
167 args.push_back(Arg4); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
168 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
|
169 } |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
170 |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
171 |
1 | 172 ////////////////////////////////////////////////////////////////////////////////////////// |
173 | |
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
|
174 IRBuilder<>* IRBuilderHelper::operator->() |
40 | 175 { |
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
|
176 IRBuilder<>& b = state->scope().builder; |
40 | 177 assert(b.GetInsertBlock() != NULL); |
178 return &b; | |
179 } |