Mercurial > projects > ldc
annotate gen/irstate.cpp @ 145:8f704cb9969b trunk
[svn r150] fixes #16 and #17, implements GotoCaseStatement
author | ChristianK |
---|---|
date | Sat, 08 Mar 2008 15:22:07 +0100 |
parents | 0e28624814e8 |
children | 86d3bb8ca33e |
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 |
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
38 IRLoopScope::IRLoopScope(Statement* s, TryFinallyStatement* enclosingtry, llvm::BasicBlock* b, llvm::BasicBlock* e) |
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; |
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
44 this->enclosingtry = enclosingtry; |
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 { | |
50 dmodule = 0; | |
51 module = 0; | |
52 emitMain = false; | |
53 mainFunc = 0; | |
40 | 54 ir.state = this; |
55 } | |
56 | |
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
|
57 IrFunction* IRState::func() |
40 | 58 { |
59 assert(!functions.empty() && "Function stack is empty!"); | |
60 return functions.back(); | |
1 | 61 } |
62 | |
63 llvm::Function* IRState::topfunc() | |
64 { | |
40 | 65 assert(!functions.empty() && "Function stack is empty!"); |
100 | 66 return functions.back()->func; |
1 | 67 } |
68 | |
69 TypeFunction* IRState::topfunctype() | |
70 { | |
40 | 71 assert(!functions.empty() && "Function stack is empty!"); |
100 | 72 return functions.back()->type; |
1 | 73 } |
74 | |
75 llvm::Instruction* IRState::topallocapoint() | |
76 { | |
40 | 77 assert(!functions.empty() && "AllocaPoint stack is empty!"); |
100 | 78 return functions.back()->allocapoint; |
1 | 79 } |
80 | |
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
|
81 IrStruct* IRState::topstruct() |
1 | 82 { |
83 assert(!structs.empty() && "Struct vector is empty!"); | |
84 return structs.back(); | |
85 } | |
86 | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
87 IRExp* IRState::topexp() |
1 | 88 { |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
89 return exps.empty() ? NULL : &exps.back(); |
1 | 90 } |
91 | |
92 IRScope& IRState::scope() | |
93 { | |
94 assert(!scopes.empty()); | |
95 return scopes.back(); | |
96 } | |
97 | |
98 llvm::BasicBlock* IRState::scopebb() | |
99 { | |
100 IRScope& s = scope(); | |
101 assert(s.begin); | |
102 return s.begin; | |
103 } | |
104 llvm::BasicBlock* IRState::scopeend() | |
105 { | |
106 IRScope& s = scope(); | |
107 assert(s.end); | |
108 return s.end; | |
109 } | |
110 bool IRState::scopereturned() | |
111 { | |
14
0e86428ee567
[svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
6
diff
changeset
|
112 //return scope().returned; |
0e86428ee567
[svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
6
diff
changeset
|
113 return !scopebb()->empty() && scopebb()->back().isTerminator(); |
1 | 114 } |
115 | |
116 ////////////////////////////////////////////////////////////////////////////////////////// | |
117 | |
40 | 118 LLVMBuilder* IRBuilderHelper::operator->() |
119 { | |
120 LLVMBuilder& b = state->scope().builder; | |
121 assert(b.GetInsertBlock() != NULL); | |
122 return &b; | |
123 } | |
124 | |
125 ////////////////////////////////////////////////////////////////////////////////////////// | |
126 | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
127 IRExp::IRExp() |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
128 { |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
129 e1 = e2 = NULL; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
130 v = NULL; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
131 } |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
132 |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
82
diff
changeset
|
133 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
|
134 { |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
135 e1 = l; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
136 e2 = r; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
137 v = val; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
138 } |