annotate gen/irstate.cpp @ 161:3a891cfcd249 trunk

[svn r177] moved variable for interface info type from being local static to being within IRState
author ChristianK
date Sun, 04 May 2008 21:25:48 +0200
parents 86d3bb8ca33e
children 3aed08fb64f4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1 /* DMDFE backend stubs
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2 * This file contains the implementations of the backend routines.
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3 * For dmdfe these do nothing but print a message saying the module
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
4 * has been parsed. Substitute your own behaviors for these routimes.
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
5 */
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
6
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
7 #include <cstdarg>
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
8
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
9 #include "gen/llvm.h"
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
10
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
11 #include "mtype.h"
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
12 #include "declaration.h"
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
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
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
15 #include "tollvm.h"
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
16
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
17 IRState* gIR = 0;
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 54
diff changeset
18 const llvm::TargetData* gTargetData = 0;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
19
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
20 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
21 IRScope::IRScope()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
22 {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
23 begin = end = NULL;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
24 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
25
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
26 IRScope::IRScope(llvm::BasicBlock* b, llvm::BasicBlock* e)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
27 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
28 begin = b;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
29 end = e;
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
30 builder.SetInsertPoint(b);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
31 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
32
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
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
148
86d3bb8ca33e [svn r154] renaming enclosingtry to enclosingtryfinally to distinguish it from enclosingtrycatch, which will probably need to be added for exception handling
ChristianK
parents: 145
diff changeset
38 IRLoopScope::IRLoopScope(Statement* s, TryFinallyStatement* enclosingtryfinally, llvm::BasicBlock* b, llvm::BasicBlock* e)
145
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;
148
86d3bb8ca33e [svn r154] renaming enclosingtry to enclosingtryfinally to distinguish it from enclosingtrycatch, which will probably need to be added for exception handling
ChristianK
parents: 145
diff changeset
44 this->enclosingtryfinally = enclosingtryfinally;
145
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
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
48 IRState::IRState()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
49 {
161
3a891cfcd249 [svn r177] moved variable for interface info type from being local static to being within IRState
ChristianK
parents: 148
diff changeset
50 interfaceInfoType = NULL;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
51 dmodule = 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
52 module = 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
53 emitMain = false;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
54 mainFunc = 0;
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
55 ir.state = this;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
56 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
57
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
58 IrFunction* IRState::func()
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
59 {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
60 assert(!functions.empty() && "Function stack is empty!");
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
61 return functions.back();
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
62 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
63
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
64 llvm::Function* IRState::topfunc()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
65 {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
66 assert(!functions.empty() && "Function stack is empty!");
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 94
diff changeset
67 return functions.back()->func;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
68 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
69
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
70 TypeFunction* IRState::topfunctype()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
71 {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
72 assert(!functions.empty() && "Function stack is empty!");
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 94
diff changeset
73 return functions.back()->type;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
74 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
75
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
76 llvm::Instruction* IRState::topallocapoint()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
77 {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
78 assert(!functions.empty() && "AllocaPoint stack is empty!");
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 94
diff changeset
79 return functions.back()->allocapoint;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
80 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
81
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
82 IrStruct* IRState::topstruct()
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
83 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
84 assert(!structs.empty() && "Struct vector is empty!");
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
85 return structs.back();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
86 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
87
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 40
diff changeset
88 IRExp* IRState::topexp()
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
89 {
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 40
diff changeset
90 return exps.empty() ? NULL : &exps.back();
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
91 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
92
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
93 IRScope& IRState::scope()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
94 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
95 assert(!scopes.empty());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
96 return scopes.back();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
97 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
98
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
99 llvm::BasicBlock* IRState::scopebb()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
100 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
101 IRScope& s = scope();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
102 assert(s.begin);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
103 return s.begin;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
104 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
105 llvm::BasicBlock* IRState::scopeend()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
106 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
107 IRScope& s = scope();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
108 assert(s.end);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
109 return s.end;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
110 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
111 bool IRState::scopereturned()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
112 {
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents: 6
diff changeset
113 //return scope().returned;
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents: 6
diff changeset
114 return !scopebb()->empty() && scopebb()->back().isTerminator();
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
115 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
116
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
117 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
118
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
119 LLVMBuilder* IRBuilderHelper::operator->()
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
120 {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
121 LLVMBuilder& b = state->scope().builder;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
122 assert(b.GetInsertBlock() != NULL);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
123 return &b;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
124 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
125
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
126 //////////////////////////////////////////////////////////////////////////////////////////
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
127
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 40
diff changeset
128 IRExp::IRExp()
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 40
diff changeset
129 {
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 40
diff changeset
130 e1 = e2 = NULL;
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 40
diff changeset
131 v = NULL;
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 40
diff changeset
132 }
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 40
diff changeset
133
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
134 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
135 {
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 40
diff changeset
136 e1 = l;
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 40
diff changeset
137 e2 = r;
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 40
diff changeset
138 v = val;
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 40
diff changeset
139 }