Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1334)

Side by Side Diff: runtime/vm/intermediate_language.h

Issue 9414003: Initial implementation of a flow-graph builder for Dart's AST. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Big refactor to incorporate review comments. Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 #ifndef VM_INTERMEDIATE_LANGUAGE_H_
6 #define VM_INTERMEDIATE_LANGUAGE_H_
7
8 #include "vm/allocation.h"
9 #include "vm/growable_array.h"
10
11 namespace dart {
12
13 class AbstractType;
14 class Function;
15 class Instance;
16 class LocalVariable;
17
18 // Computations and values.
19 //
20 // <Computation> ::= <Value>
21 // | AssertAssignable <Value> <AbstractType>
22 // | InstanceCall <cstring> <Value> ...
23 // | StaticCall <Function> <Value> ...
24 // | LoadLocal <LocalVariable>
25 // | StoreLocal <LocalVariable> <Value>
26 //
27 // <Value> ::= Temp <int>
28 // | Constant <Instance>
29
30 class Computation : public ZoneAllocated {
31 public:
32 Computation() { }
33
34 // Prints a computation without indentation or trailing newlines.
35 virtual void Print() const = 0;
srdjan 2012/02/21 14:33:41 I would suggest to move printing to a separate cla
Kevin Millikin (Google) 2012/02/22 13:15:42 I generally dislike visitors because they don't se
srdjan 2012/02/22 14:08:16 No urgency in that change, especially while the pr
36
37 private:
38 DISALLOW_COPY_AND_ASSIGN(Computation);
39 };
40
41
42 class Value : public Computation {
43 public:
44 Value() { }
45
46 private:
47 DISALLOW_COPY_AND_ASSIGN(Value);
48 };
49
50
51 class AssertAssignableComp : public Computation {
52 public:
53 AssertAssignableComp(Value* value, const AbstractType& type)
54 : value_(value), type_(type) { }
55
56 virtual void Print() const;
57
58 private:
59 Value* value_;
60 const AbstractType& type_;
61
62 DISALLOW_COPY_AND_ASSIGN(AssertAssignableComp);
63 };
64
65
66 class InstanceCallComp : public Computation {
67 public:
68 InstanceCallComp(const char* name, ZoneGrowableArray<Value*>* arguments)
69 : name_(name), arguments_(arguments) { }
70
71 virtual void Print() const;
72
73 private:
74 const char* name_;
75 ZoneGrowableArray<Value*>* arguments_;
76
77 DISALLOW_COPY_AND_ASSIGN(InstanceCallComp);
78 };
79
80
81 class StaticCallComp : public Computation {
82 public:
83 StaticCallComp(const Function& function, ZoneGrowableArray<Value*>* arguments)
84 : function_(function), arguments_(arguments) { }
srdjan 2012/02/22 00:41:34 Add ASSERT(function.IsZoneHandle());
Kevin Millikin (Google) 2012/02/22 13:15:42 OK. I guess there are more places we will want su
85
86 virtual void Print() const;
87
88 private:
89 const Function& function_;
90 ZoneGrowableArray<Value*>* arguments_;
91
92 DISALLOW_COPY_AND_ASSIGN(StaticCallComp);
93 };
94
95
96 class LoadLocalComp : public Computation {
97 public:
98 explicit LoadLocalComp(const LocalVariable& local) : local_(local) { }
99
100 virtual void Print() const;
101
102 private:
103 const LocalVariable& local_;
104
105 DISALLOW_COPY_AND_ASSIGN(LoadLocalComp);
106 };
107
108
109 class StoreLocalComp : public Computation {
110 public:
111 StoreLocalComp(const LocalVariable& local, Value* value)
112 : local_(local), value_(value) { }
113
114 virtual void Print() const;
115
116 private:
117 const LocalVariable& local_;
118 Value* value_;
119
120 DISALLOW_COPY_AND_ASSIGN(StoreLocalComp);
121 };
122
123
124 class TempValue : public Value {
125 public:
126 explicit TempValue(intptr_t index) : index_(index) { }
127
128 virtual void Print() const;
129
130 private:
131 uintptr_t index_;
srdjan 2012/02/22 00:41:34 intptr_t
Kevin Millikin (Google) 2012/02/22 13:15:42 Done.
132
133 DISALLOW_COPY_AND_ASSIGN(TempValue);
134 };
135
136
137 class ConstantValue: public Value {
138 public:
139 explicit ConstantValue(const Instance& instance) : instance_(instance) { }
140
141 virtual void Print() const;
142
143 private:
144 const Instance& instance_;
145
146 DISALLOW_COPY_AND_ASSIGN(ConstantValue);
147 };
148
149
150 // Instructions.
151 //
152 // <Instruction> ::= Do <Computation> <Instruction>
153 // | Bind <int> <Computation> <Instruction>
154 // | Return <Value>
155 // | Branch <Value> <Instruction> <Instruction>
156 // | Empty <Instruction>
157
158 class Instruction : public ZoneAllocated {
159 public:
160 Instruction() : mark_(false) { }
161
162 virtual void set_successor(Instruction* instr) = 0;
163
164 // Perform a postorder traversal of the instruction graph reachable from
165 // this instruction. Append the result to the end of the in/out parameter
166 // visited.
167 virtual void Postorder(GrowableArray<Instruction*>* visited) = 0;
168
169 // Print an instruction without indentation, instruction number, or a
170 // trailing newline.
171 virtual void Print(
172 intptr_t instruction_index,
173 const GrowableArray<Instruction*>& instruction_list) const = 0;
174
175 // Mark bit to support non-reentrant recursive traversal (i.e.,
176 // identification of cycles). Before and after a traversal, all the nodes
177 // must have the same mark.
178 bool mark() const { return mark_; }
179 void flip_mark() { mark_ = !mark_; }
180
181 protected:
182 // Helper for print handling of successors of nodes with a single successor.
183 // "goto %d" is printed if the successor is not the next instruction.
184 void PrintGotoSuccessor(
185 Instruction* successor,
186 intptr_t instruction_index,
187 const GrowableArray<Instruction*>& instruction_list) const;
188
189 private:
190 bool mark_;
191 };
192
193
194 class DoInstr : public Instruction {
195 public:
196 explicit DoInstr(Computation* comp) : computation_(comp), successor_(NULL) { }
srdjan 2012/02/22 00:41:34 Must call super constructor Instruction() to initi
Kevin Millikin (Google) 2012/02/22 13:15:42 Done. Is that a style issue (the superclass const
srdjan 2012/02/22 14:08:16 I find that the explicitness clarifies that the su
197
198 virtual void set_successor(Instruction* instr) {
199 ASSERT(successor_ == NULL);
200 successor_ = instr;
201 }
202
203 virtual void Postorder(GrowableArray<Instruction*>* visited);
204
205 virtual void Print(
206 intptr_t instruction_index,
207 const GrowableArray<Instruction*>& instruction_list) const;
208
209 private:
210 Computation* computation_;
211 Instruction* successor_;
212 };
213
214
215 class BindInstr : public Instruction {
216 public:
217 BindInstr(intptr_t temp_index, Computation* computation)
218 : temp_index_(temp_index), computation_(computation), successor_(NULL) { }
219
220 virtual void set_successor(Instruction* instr) {
221 ASSERT(successor_ == NULL);
222 successor_ = instr;
223 }
224
225 virtual void Postorder(GrowableArray<Instruction*>* visited);
226
227 virtual void Print(
228 intptr_t instruction_index,
229 const GrowableArray<Instruction*>& instruction_list) const;
230
231 private:
232 intptr_t temp_index_;
srdjan 2012/02/22 00:41:34 const
Kevin Millikin (Google) 2012/02/22 13:15:42 Done.
233 Computation* computation_;
234 Instruction* successor_;
235 };
236
237
238 class JoinEntryInstr : public Instruction {
239 public:
240 JoinEntryInstr() : successor_(NULL) { }
241
242 virtual void set_successor(Instruction* instr) {
243 ASSERT(successor_ == NULL);
244 successor_ = instr;
245 }
246
247 virtual void Postorder(GrowableArray<Instruction*>* visited);
248
249 virtual void Print(
250 intptr_t instruction_index,
251 const GrowableArray<Instruction*>& instruction_list) const;
252
253 private:
254 Instruction* successor_;
255 };
256
257
258 class TargetEntryInstr : public Instruction {
259 public:
260 TargetEntryInstr() : successor_(NULL) { }
261
262 virtual void set_successor(Instruction* instr) {
263 ASSERT(successor_ == NULL);
264 successor_ = instr;
265 }
266
267 virtual void Postorder(GrowableArray<Instruction*>* visited);
268
269 virtual void Print(
270 intptr_t instruction_index,
271 const GrowableArray<Instruction*>& instruction_list) const;
272
273 private:
274 Instruction* successor_;
275 };
276
277
278 class ReturnInstr : public Instruction {
279 public:
280 explicit ReturnInstr(Value* value) : value_(value) { }
281
282 virtual void set_successor(Instruction* instr) { UNREACHABLE(); }
283
284 virtual void Postorder(GrowableArray<Instruction*>* visited);
285
286 virtual void Print(
287 intptr_t instruction_index,
288 const GrowableArray<Instruction*>& instruction_list) const;
289
290 private:
291 Value* value_;
292 };
293
294
295 class BranchInstr : public Instruction {
296 public:
297 explicit BranchInstr(Value* value)
298 : value_(value), true_successor_(NULL), false_successor_(NULL) { }
299
300 virtual void set_successor(Instruction* instr) { UNREACHABLE(); }
301
302 TargetEntryInstr** true_successor_address() { return &true_successor_; }
303 TargetEntryInstr** false_successor_address() { return &false_successor_; }
304
305 virtual void Postorder(GrowableArray<Instruction*>* visited);
306
307 virtual void Print(
308 intptr_t instruction_index,
309 const GrowableArray<Instruction*>& instruction_list) const;
310
311 private:
312 Value* value_;
313 TargetEntryInstr* true_successor_;
314 TargetEntryInstr* false_successor_;
315 };
316
317
318 } // namespace dart
319
320 #endif // VM_INTERMEDIATE_LANGUAGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698