Mercurial > projects > ldc
annotate gen/irstate.cpp @ 1451:297d1e2f6441
Add `syscall` to the x86-64 asm parser, and both `syscall` and `sysret` to the
x86 one. Fixes #316.
author | Frits van Bommel <fvbommel wxs.nl> |
---|---|
date | Mon, 01 Jun 2009 23:42:42 +0200 |
parents | f99a3b393c03 |
children | ad7f2f1862d6 |
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() | |
25 { | |
40 | 26 begin = end = NULL; |
1 | 27 } |
28 | |
29 IRScope::IRScope(llvm::BasicBlock* b, llvm::BasicBlock* e) | |
30 { | |
31 begin = b; | |
32 end = e; | |
40 | 33 builder.SetInsertPoint(b); |
1 | 34 } |
35 | |
36 ////////////////////////////////////////////////////////////////////////////////////////// | |
1141
f99a3b393c03
Reorganize EnclosingHandlers to require less changes to the frontend and allow us to
Christian Kamm <kamm incasoftware de>
parents:
1013
diff
changeset
|
37 IRTargetScope::IRTargetScope() |
145
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
38 { |
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 |
1141
f99a3b393c03
Reorganize EnclosingHandlers to require less changes to the frontend and allow us to
Christian Kamm <kamm incasoftware de>
parents:
1013
diff
changeset
|
41 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
|
42 { |
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
43 this->s = s; |
309 | 44 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
|
45 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
|
46 this->continueTarget = continueTarget; |
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 ////////////////////////////////////////////////////////////////////////////////////////// |
946
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
493
diff
changeset
|
50 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
|
51 : module(m), difactory(*m) |
1 | 52 { |
161
3a891cfcd249
[svn r177] moved variable for interface info type from being local static to being within IRState
ChristianK
parents:
148
diff
changeset
|
53 interfaceInfoType = NULL; |
309 | 54 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
|
55 moduleRefType = NULL; |
309 | 56 |
1 | 57 dmodule = 0; |
58 emitMain = false; | |
59 mainFunc = 0; | |
40 | 60 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
|
61 asmBlock = NULL; |
252 | 62 |
63 dwarfCUs = NULL; | |
64 dwarfSPs = NULL; | |
65 dwarfGVs = NULL; | |
40 | 66 } |
67 | |
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
|
68 IrFunction* IRState::func() |
40 | 69 { |
70 assert(!functions.empty() && "Function stack is empty!"); | |
71 return functions.back(); | |
1 | 72 } |
73 | |
74 llvm::Function* IRState::topfunc() | |
75 { | |
40 | 76 assert(!functions.empty() && "Function stack is empty!"); |
100 | 77 return functions.back()->func; |
1 | 78 } |
79 | |
80 TypeFunction* IRState::topfunctype() | |
81 { | |
40 | 82 assert(!functions.empty() && "Function stack is empty!"); |
100 | 83 return functions.back()->type; |
1 | 84 } |
85 | |
86 llvm::Instruction* IRState::topallocapoint() | |
87 { | |
40 | 88 assert(!functions.empty() && "AllocaPoint stack is empty!"); |
100 | 89 return functions.back()->allocapoint; |
1 | 90 } |
91 | |
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
|
92 IrStruct* IRState::topstruct() |
1 | 93 { |
94 assert(!structs.empty() && "Struct vector is empty!"); | |
95 return structs.back(); | |
96 } | |
97 | |
98 IRScope& IRState::scope() | |
99 { | |
100 assert(!scopes.empty()); | |
101 return scopes.back(); | |
102 } | |
103 | |
104 llvm::BasicBlock* IRState::scopebb() | |
105 { | |
106 IRScope& s = scope(); | |
107 assert(s.begin); | |
108 return s.begin; | |
109 } | |
110 llvm::BasicBlock* IRState::scopeend() | |
111 { | |
112 IRScope& s = scope(); | |
113 assert(s.end); | |
114 return s.end; | |
115 } | |
116 bool IRState::scopereturned() | |
117 { | |
14
0e86428ee567
[svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
6
diff
changeset
|
118 //return scope().returned; |
0e86428ee567
[svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
6
diff
changeset
|
119 return !scopebb()->empty() && scopebb()->back().isTerminator(); |
1 | 120 } |
121 | |
1013
8c73ff5f69e0
Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents:
988
diff
changeset
|
122 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
|
123 { |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
124 LLSmallVector<LLValue*, 1> args; |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
125 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
|
126 } |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
127 |
1013
8c73ff5f69e0
Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents:
988
diff
changeset
|
128 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
|
129 { |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
130 LLSmallVector<LLValue*, 1> args; |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
131 args.push_back(Arg1); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
132 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
|
133 } |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
134 |
1013
8c73ff5f69e0
Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents:
988
diff
changeset
|
135 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
|
136 { |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
137 LLSmallVector<LLValue*, 2> args; |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
138 args.push_back(Arg1); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
139 args.push_back(Arg2); |
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::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
|
144 { |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
145 LLSmallVector<LLValue*, 3> 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 args.push_back(Arg3); |
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::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
|
153 { |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
154 LLSmallVector<LLValue*, 4> 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 args.push_back(Arg4); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
159 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
|
160 } |
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 |
1 | 163 ////////////////////////////////////////////////////////////////////////////////////////// |
164 | |
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
|
165 IRBuilder<>* IRBuilderHelper::operator->() |
40 | 166 { |
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
|
167 IRBuilder<>& b = state->scope().builder; |
40 | 168 assert(b.GetInsertBlock() != NULL); |
169 return &b; | |
170 } |