Mercurial > projects > ldc
annotate gen/irstate.h @ 988:2667e3a145be
- Fixed LLVM style CL args for D2.
- Moved main() into its own file gen/main.cpp
- Fixed basic cross compilation
- removed the option for setting OS
- added support for llc's mattr, mcpu and mtriple switches
- added basic ABI abstraction for return value rewrites, it's not perfect and will probably be completely rewritten once I get to handling parameter rewrites as well.
- x86-64 extern(C) abi for cfloat returns now match (llvm-)gcc.
author | Tomas Lindquist Olsen <tomas.l.olsen@gmail.com> |
---|---|
date | Thu, 26 Feb 2009 14:11:49 +0100 |
parents | 985104c0f1db |
children | 8c73ff5f69e0 |
rev | line source |
---|---|
664
eef8ac26c66c
Some missed LLVMDC -> LDC.
Christian Kamm <kamm incasoftware de>
parents:
632
diff
changeset
|
1 #ifndef LDC_GEN_IRSTATE_H |
eef8ac26c66c
Some missed LLVMDC -> LDC.
Christian Kamm <kamm incasoftware de>
parents:
632
diff
changeset
|
2 #define LDC_GEN_IRSTATE_H |
1 | 3 |
4 #include <vector> | |
945
03d7c4aac654
SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
920
diff
changeset
|
5 #include <deque> |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
6 #include <list> |
920
545f54041d91
Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
797
diff
changeset
|
7 #include <sstream> |
1 | 8 |
9 #include "root.h" | |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
108
diff
changeset
|
10 #include "aggregate.h" |
1 | 11 |
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:
116
diff
changeset
|
12 #include "ir/irfunction.h" |
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:
116
diff
changeset
|
13 #include "ir/irstruct.h" |
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:
116
diff
changeset
|
14 #include "ir/irvar.h" |
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:
116
diff
changeset
|
15 |
988
2667e3a145be
- Fixed LLVM style CL args for D2.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
971
diff
changeset
|
16 namespace llvm { |
2667e3a145be
- Fixed LLVM style CL args for D2.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
971
diff
changeset
|
17 class TargetMachine; |
2667e3a145be
- Fixed LLVM style CL args for D2.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
971
diff
changeset
|
18 } |
2667e3a145be
- Fixed LLVM style CL args for D2.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
971
diff
changeset
|
19 |
1 | 20 // global ir state for current module |
21 struct IRState; | |
988
2667e3a145be
- Fixed LLVM style CL args for D2.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
971
diff
changeset
|
22 struct TargetABI; |
2667e3a145be
- Fixed LLVM style CL args for D2.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
971
diff
changeset
|
23 |
1 | 24 extern IRState* gIR; |
988
2667e3a145be
- Fixed LLVM style CL args for D2.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
971
diff
changeset
|
25 extern llvm::TargetMachine* gTargetMachine; |
73 | 26 extern const llvm::TargetData* gTargetData; |
988
2667e3a145be
- Fixed LLVM style CL args for D2.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
971
diff
changeset
|
27 extern TargetABI* gABI; |
1 | 28 |
29 struct TypeFunction; | |
30 struct TypeStruct; | |
31 struct ClassDeclaration; | |
32 struct FuncDeclaration; | |
33 struct Module; | |
34 struct TypeStruct; | |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
108
diff
changeset
|
35 struct BaseClass; |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
36 struct AnonDeclaration; |
309 | 37 struct EnclosingHandler; |
1 | 38 |
156
ccd07d9f2ce9
[svn r172] moving all IR state previously stored in Dsymbol into IrDsymbol and a Dsymbol->IrDsymbol map
ChristianK
parents:
155
diff
changeset
|
39 struct IrModule; |
ccd07d9f2ce9
[svn r172] moving all IR state previously stored in Dsymbol into IrDsymbol and a Dsymbol->IrDsymbol map
ChristianK
parents:
155
diff
changeset
|
40 |
1 | 41 // represents a scope |
42 struct IRScope | |
43 { | |
44 llvm::BasicBlock* begin; | |
45 llvm::BasicBlock* end; | |
493
017ca8645a1f
Make llvmdc work with llvm 2.4svn revision 54614. Breaks compatibility with llvm 2.3.
Christian Kamm <kamm incasoftware de>
parents:
477
diff
changeset
|
46 IRBuilder<> builder; |
1 | 47 |
48 IRScope(); | |
49 IRScope(llvm::BasicBlock* b, llvm::BasicBlock* e); | |
50 }; | |
51 | |
145
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
52 // scope for loops |
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
53 struct IRLoopScope : IRScope |
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
54 { |
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
55 // generating statement |
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
56 Statement* s; |
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
57 // the try of a TryFinally that encloses the loop |
309 | 58 EnclosingHandler* enclosinghandler; |
311
9967a3270837
[svn r332] Fix codegen for continue within switch.
ChristianK
parents:
309
diff
changeset
|
59 // if it is a switch, we are a possible target for break |
9967a3270837
[svn r332] Fix codegen for continue within switch.
ChristianK
parents:
309
diff
changeset
|
60 // but not for continue |
9967a3270837
[svn r332] Fix codegen for continue within switch.
ChristianK
parents:
309
diff
changeset
|
61 bool isSwitch; |
145
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
62 |
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
63 IRLoopScope(); |
311
9967a3270837
[svn r332] Fix codegen for continue within switch.
ChristianK
parents:
309
diff
changeset
|
64 IRLoopScope(Statement* s, EnclosingHandler* enclosinghandler, llvm::BasicBlock* b, llvm::BasicBlock* e, bool isSwitch = false); |
145
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
65 }; |
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
66 |
40 | 67 struct IRBuilderHelper |
68 { | |
69 IRState* state; | |
493
017ca8645a1f
Make llvmdc work with llvm 2.4svn revision 54614. Breaks compatibility with llvm 2.3.
Christian Kamm <kamm incasoftware de>
parents:
477
diff
changeset
|
70 IRBuilder<>* operator->(); |
40 | 71 }; |
72 | |
232
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
213
diff
changeset
|
73 struct IRAsmStmt |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
213
diff
changeset
|
74 { |
477
253f234eb80c
Make sure to initialize isBranchToLabel to zero.
Christian Kamm <kamm incasoftware de>
parents:
447
diff
changeset
|
75 IRAsmStmt() |
253f234eb80c
Make sure to initialize isBranchToLabel to zero.
Christian Kamm <kamm incasoftware de>
parents:
447
diff
changeset
|
76 : isBranchToLabel(NULL) {} |
253f234eb80c
Make sure to initialize isBranchToLabel to zero.
Christian Kamm <kamm incasoftware de>
parents:
447
diff
changeset
|
77 |
232
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
213
diff
changeset
|
78 std::string code; |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
213
diff
changeset
|
79 std::string out_c; |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
213
diff
changeset
|
80 std::string in_c; |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
213
diff
changeset
|
81 std::vector<LLValue*> out; |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
213
diff
changeset
|
82 std::vector<LLValue*> in; |
299
df8a7b8d5929
[svn r320] Begun work on branches out of asm blocks. Unfinished.
ChristianK
parents:
252
diff
changeset
|
83 |
302 | 84 // if this is nonzero, it contains the target label |
305
2b72433d5c8c
[svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents:
302
diff
changeset
|
85 Identifier* isBranchToLabel; |
232
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
213
diff
changeset
|
86 }; |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
213
diff
changeset
|
87 |
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
|
88 struct IRAsmBlock |
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
|
89 { |
945
03d7c4aac654
SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
920
diff
changeset
|
90 std::deque<IRAsmStmt*> s; |
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
|
91 std::set<std::string> clobs; |
971
985104c0f1db
Fix the problems exposed by the callingconv1.d test case.
Frits van Bommel <fvbommel wxs.nl>
parents:
959
diff
changeset
|
92 size_t outputcount; |
299
df8a7b8d5929
[svn r320] Begun work on branches out of asm blocks. Unfinished.
ChristianK
parents:
252
diff
changeset
|
93 |
df8a7b8d5929
[svn r320] Begun work on branches out of asm blocks. Unfinished.
ChristianK
parents:
252
diff
changeset
|
94 // stores the labels within the asm block |
df8a7b8d5929
[svn r320] Begun work on branches out of asm blocks. Unfinished.
ChristianK
parents:
252
diff
changeset
|
95 std::vector<Identifier*> internalLabels; |
945
03d7c4aac654
SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
920
diff
changeset
|
96 |
03d7c4aac654
SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
920
diff
changeset
|
97 AsmBlockStatement* asmBlock; |
03d7c4aac654
SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
920
diff
changeset
|
98 const LLType* retty; |
03d7c4aac654
SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
920
diff
changeset
|
99 unsigned retn; |
954
e048e36bc155
Added support for using a temporary to implement emulated ABI return from inline asm, could be easier to use, but I think this will do. It's so extremely target dependent in any case that doing a completely generic approach seems hard.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
946
diff
changeset
|
100 bool retemu; // emulate abi ret with a temporary |
959
7e669954db7d
Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents:
954
diff
changeset
|
101 LLValue* (*retfixup)(IRBuilderHelper b, LLValue* orig); // Modifies retval |
945
03d7c4aac654
SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
920
diff
changeset
|
102 |
959
7e669954db7d
Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents:
954
diff
changeset
|
103 IRAsmBlock(AsmBlockStatement* b) |
971
985104c0f1db
Fix the problems exposed by the callingconv1.d test case.
Frits van Bommel <fvbommel wxs.nl>
parents:
959
diff
changeset
|
104 : asmBlock(b), retty(NULL), retn(0), retemu(false), retfixup(NULL), |
985104c0f1db
Fix the problems exposed by the callingconv1.d test case.
Frits van Bommel <fvbommel wxs.nl>
parents:
959
diff
changeset
|
105 outputcount(0) |
985104c0f1db
Fix the problems exposed by the callingconv1.d test case.
Frits van Bommel <fvbommel wxs.nl>
parents:
959
diff
changeset
|
106 {} |
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
|
107 }; |
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
|
108 |
315
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
109 // llvm::CallInst and llvm::InvokeInst don't share a common base |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
110 // but share common functionality. to avoid duplicating code for |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
111 // adjusting these common properties these structs are made |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
112 struct CallOrInvoke |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
113 { |
632
df196c8dea26
Updated to latest LLVM trunk, function notes have been removed and merged with parameter attributes, which have been renamed to just attributes. Nothing seems to have broke!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
493
diff
changeset
|
114 virtual void setAttributes(const llvm::AttrListPtr& Attrs) = 0; |
315
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
115 virtual void setCallingConv(unsigned CC) = 0; |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
116 virtual llvm::Instruction* get() = 0; |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
117 }; |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
118 |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
119 struct CallOrInvoke_Call : public CallOrInvoke |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
120 { |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
121 llvm::CallInst* inst; |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
122 CallOrInvoke_Call(llvm::CallInst* call) : inst(call) {} |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
123 |
632
df196c8dea26
Updated to latest LLVM trunk, function notes have been removed and merged with parameter attributes, which have been renamed to just attributes. Nothing seems to have broke!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
493
diff
changeset
|
124 virtual void setAttributes(const llvm::AttrListPtr& Attrs) |
df196c8dea26
Updated to latest LLVM trunk, function notes have been removed and merged with parameter attributes, which have been renamed to just attributes. Nothing seems to have broke!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
493
diff
changeset
|
125 { inst->setAttributes(Attrs); } |
315
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
126 virtual void setCallingConv(unsigned CC) |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
127 { inst->setCallingConv(CC); } |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
128 virtual llvm::Instruction* get() |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
129 { return inst; } |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
130 }; |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
131 |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
132 struct CallOrInvoke_Invoke : public CallOrInvoke |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
133 { |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
134 llvm::InvokeInst* inst; |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
135 CallOrInvoke_Invoke(llvm::InvokeInst* invoke) : inst(invoke) {} |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
136 |
632
df196c8dea26
Updated to latest LLVM trunk, function notes have been removed and merged with parameter attributes, which have been renamed to just attributes. Nothing seems to have broke!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
493
diff
changeset
|
137 virtual void setAttributes(const llvm::AttrListPtr& Attrs) |
df196c8dea26
Updated to latest LLVM trunk, function notes have been removed and merged with parameter attributes, which have been renamed to just attributes. Nothing seems to have broke!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
493
diff
changeset
|
138 { inst->setAttributes(Attrs); } |
315
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
139 virtual void setCallingConv(unsigned CC) |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
140 { inst->setCallingConv(CC); } |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
141 virtual llvm::Instruction* get() |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
142 { return inst; } |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
143 }; |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
144 |
1 | 145 // represents the module |
40 | 146 struct IRState |
1 | 147 { |
946
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
945
diff
changeset
|
148 IRState(llvm::Module* m); |
1 | 149 |
150 // module | |
151 Module* dmodule; | |
152 llvm::Module* module; | |
153 | |
161
3a891cfcd249
[svn r177] moved variable for interface info type from being local static to being within IRState
ChristianK
parents:
157
diff
changeset
|
154 // interface info type, used in DtoInterfaceInfoType |
309 | 155 const LLStructType* interfaceInfoType; |
156 const LLStructType* mutexType; | |
323
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
319
diff
changeset
|
157 const LLStructType* moduleRefType; |
161
3a891cfcd249
[svn r177] moved variable for interface info type from being local static to being within IRState
ChristianK
parents:
157
diff
changeset
|
158 |
1 | 159 // functions |
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:
116
diff
changeset
|
160 typedef std::vector<IrFunction*> FunctionVector; |
40 | 161 FunctionVector functions; |
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:
116
diff
changeset
|
162 IrFunction* func(); |
40 | 163 |
1 | 164 llvm::Function* topfunc(); |
165 TypeFunction* topfunctype(); | |
166 llvm::Instruction* topallocapoint(); | |
167 | |
168 // structs | |
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:
116
diff
changeset
|
169 typedef std::vector<IrStruct*> StructVector; |
1 | 170 StructVector structs; |
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:
116
diff
changeset
|
171 IrStruct* topstruct(); |
1 | 172 |
173 // D main function | |
174 bool emitMain; | |
175 llvm::Function* mainFunc; | |
176 | |
177 // basic block scopes | |
178 std::vector<IRScope> scopes; | |
179 IRScope& scope(); | |
108
288fe1029e1f
[svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents:
103
diff
changeset
|
180 llvm::BasicBlock* scopebb(); |
1 | 181 llvm::BasicBlock* scopeend(); |
182 bool scopereturned(); | |
183 | |
315
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
184 // create a call or invoke, depending on the landing pad info |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
185 // the template function is defined further down in this file |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
186 template <typename InputIterator> |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
187 CallOrInvoke* CreateCallOrInvoke(LLValue* Callee, InputIterator ArgBegin, InputIterator ArgEnd, const char* Name=""); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
188 CallOrInvoke* CreateCallOrInvoke(LLValue* Callee, const char* Name=""); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
189 CallOrInvoke* CreateCallOrInvoke(LLValue* Callee, LLValue* Arg1, const char* Name=""); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
190 CallOrInvoke* CreateCallOrInvoke2(LLValue* Callee, LLValue* Arg1, LLValue* Arg2, const char* Name=""); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
191 CallOrInvoke* CreateCallOrInvoke3(LLValue* Callee, LLValue* Arg1, LLValue* Arg2, LLValue* Arg3, const char* Name=""); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
192 CallOrInvoke* CreateCallOrInvoke4(LLValue* Callee, LLValue* Arg1, LLValue* Arg2, LLValue* Arg3, LLValue* Arg4, const char* Name=""); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
193 |
1 | 194 // loop blocks |
145
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
195 typedef std::vector<IRLoopScope> LoopScopeVec; |
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
196 LoopScopeVec loopbbs; |
1 | 197 |
198 // this holds the array being indexed or sliced so $ will work | |
199 // might be a better way but it works. problem is I only get a | |
200 // VarDeclaration for __dollar, but I can't see how to get the | |
201 // array pointer from this :( | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
82
diff
changeset
|
202 std::vector<DValue*> arrays; |
15
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
6
diff
changeset
|
203 |
40 | 204 // builder helper |
205 IRBuilderHelper ir; | |
98
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
94
diff
changeset
|
206 |
946
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
945
diff
changeset
|
207 // debug info helper |
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
945
diff
changeset
|
208 llvm::DIFactory difactory; |
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
945
diff
changeset
|
209 |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
210 typedef std::list<Dsymbol*> DsymbolList; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
211 // dsymbols that need to be resolved |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
212 DsymbolList resolveList; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
213 // dsymbols that need to be declared |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
214 DsymbolList declareList; |
100 | 215 // dsymbols that need constant initializers constructed |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
216 DsymbolList constInitList; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
217 // dsymbols that need definitions |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
218 DsymbolList defineList; |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
113
diff
changeset
|
219 |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
113
diff
changeset
|
220 // static ctors/dtors/unittests |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
113
diff
changeset
|
221 typedef std::vector<FuncDeclaration*> FuncDeclVector; |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
113
diff
changeset
|
222 FuncDeclVector ctors; |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
113
diff
changeset
|
223 FuncDeclVector dtors; |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
113
diff
changeset
|
224 FuncDeclVector unitTests; |
232
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
213
diff
changeset
|
225 |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
213
diff
changeset
|
226 // for inline asm |
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
|
227 IRAsmBlock* asmBlock; |
920
545f54041d91
Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
797
diff
changeset
|
228 std::ostringstream nakedAsm; |
545f54041d91
Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
797
diff
changeset
|
229 |
545f54041d91
Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
797
diff
changeset
|
230 // 'used' array solely for keeping a reference to globals |
545f54041d91
Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
797
diff
changeset
|
231 std::vector<LLConstant*> usedArray; |
250
fc9c1a0eabbd
[svn r267] Fixed debug info for global variables.
lindquist
parents:
233
diff
changeset
|
232 |
252 | 233 // dwarf dbg stuff |
234 LLGlobalVariable* dwarfCUs; | |
235 LLGlobalVariable* dwarfSPs; | |
236 LLGlobalVariable* dwarfGVs; | |
1 | 237 }; |
238 | |
315
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
239 template <typename InputIterator> |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
240 CallOrInvoke* IRState::CreateCallOrInvoke(LLValue* Callee, InputIterator ArgBegin, InputIterator ArgEnd, const char* Name) |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
241 { |
319
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
315
diff
changeset
|
242 llvm::BasicBlock* pad; |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
315
diff
changeset
|
243 if(pad = func()->landingPad.get()) |
315
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
244 { |
447
f7259fa1349c
Fixed problem with invoking intrinsics, which llvm doesn't allow.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
334
diff
changeset
|
245 // intrinsics don't support invoking |
f7259fa1349c
Fixed problem with invoking intrinsics, which llvm doesn't allow.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
334
diff
changeset
|
246 LLFunction* funcval = llvm::dyn_cast<LLFunction>(Callee); |
f7259fa1349c
Fixed problem with invoking intrinsics, which llvm doesn't allow.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
334
diff
changeset
|
247 if (funcval && funcval->isIntrinsic()) |
f7259fa1349c
Fixed problem with invoking intrinsics, which llvm doesn't allow.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
334
diff
changeset
|
248 { |
f7259fa1349c
Fixed problem with invoking intrinsics, which llvm doesn't allow.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
334
diff
changeset
|
249 return new CallOrInvoke_Call(ir->CreateCall(Callee, ArgBegin, ArgEnd, Name)); |
f7259fa1349c
Fixed problem with invoking intrinsics, which llvm doesn't allow.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
334
diff
changeset
|
250 } |
f7259fa1349c
Fixed problem with invoking intrinsics, which llvm doesn't allow.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
334
diff
changeset
|
251 |
315
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
252 llvm::BasicBlock* postinvoke = llvm::BasicBlock::Create("postinvoke", topfunc(), scopeend()); |
319
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
315
diff
changeset
|
253 llvm::InvokeInst* invoke = ir->CreateInvoke(Callee, postinvoke, pad, ArgBegin, ArgEnd, Name); |
315
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
254 scope() = IRScope(postinvoke, scopeend()); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
255 return new CallOrInvoke_Invoke(invoke); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
256 } |
319
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
315
diff
changeset
|
257 else |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
315
diff
changeset
|
258 return new CallOrInvoke_Call(ir->CreateCall(Callee, ArgBegin, ArgEnd, Name)); |
315
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
259 } |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
314
diff
changeset
|
260 |
664
eef8ac26c66c
Some missed LLVMDC -> LDC.
Christian Kamm <kamm incasoftware de>
parents:
632
diff
changeset
|
261 #endif // LDC_GEN_IRSTATE_H |