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

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

Issue 9664062: Support allocating and calling closures in the new non-optimizing compiler. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 9 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
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #ifndef VM_INTERMEDIATE_LANGUAGE_H_ 5 #ifndef VM_INTERMEDIATE_LANGUAGE_H_
6 #define VM_INTERMEDIATE_LANGUAGE_H_ 6 #define VM_INTERMEDIATE_LANGUAGE_H_
7 7
8 #include "vm/allocation.h" 8 #include "vm/allocation.h"
9 #include "vm/ast.h" 9 #include "vm/ast.h"
10 #include "vm/growable_array.h" 10 #include "vm/growable_array.h"
11 #include "vm/handles_impl.h" 11 #include "vm/handles_impl.h"
12 #include "vm/object.h" 12 #include "vm/object.h"
13 13
14 namespace dart { 14 namespace dart {
15 15
16 class FlowGraphVisitor; 16 class FlowGraphVisitor;
17 class LocalVariable; 17 class LocalVariable;
18 18
19 // Computations and values. 19 // Computations and values.
20 // 20 //
21 // <Computation> ::= 21 // <Computation> ::=
22 // <Value> 22 // <Value>
23 // | AssertAssignable <Value> <AbstractType> 23 // | AssertAssignable <Value> <AbstractType>
24 // | InstanceCall <AstNode> <String> <Value> ... 24 // | CurrentContext
25 // | ClosureCall <ClosureCallNode> <Value> <Value> ...
26 // | InstanceCall <String> <Value> ...
25 // | StaticCall <StaticCallNode> <Value> ... 27 // | StaticCall <StaticCallNode> <Value> ...
26 // | LoadLocal <LocalVariable> 28 // | LoadLocal <LocalVariable>
27 // | StoreLocal <LocalVariable> <Value> 29 // | StoreLocal <LocalVariable> <Value>
28 // | StrictCompare <Token::kind> <Value> <Value> 30 // | StrictCompare <Token::kind> <Value> <Value>
29 // | NativeCall <NativeBodyNode> 31 // | NativeCall <NativeBodyNode>
30 // | StoreIndexed <Value> <Value> <Value> 32 // | StoreIndexed <Value> <Value> <Value>
31 // | InstanceSetter <String> <Value> <Value> 33 // | InstanceSetter <String> <Value> <Value>
32 // | LoadInstanceField <LoadInstanceFieldNode> <Value> 34 // | LoadInstanceField <LoadInstanceFieldNode> <Value>
33 // | StoreInstanceField <StoreInstanceFieldNode> <Value> <Value> 35 // | StoreInstanceField <StoreInstanceFieldNode> <Value> <Value>
34 // | LoadStaticField <Field> 36 // | LoadStaticField <Field>
35 // | StoreStaticField <Field> <Value> 37 // | StoreStaticField <Field> <Value>
36 // | BooleanNegate <Value> 38 // | BooleanNegate <Value>
37 // | InstanceOf <Value> <Type> 39 // | InstanceOf <Value> <Type>
40 // | CreateArray <ArrayNode> <Value> ...
41 // | CreateClosure <ClosureNode>
38 // | AllocateObject <ConstructorCallNode> 42 // | AllocateObject <ConstructorCallNode>
39 // 43 //
40 // <Value> ::= 44 // <Value> ::=
41 // Temp <int> 45 // Temp <int>
42 // | Constant <Instance> 46 // | Constant <Instance>
43 47
44 // M is a two argument macro. It is applied to each concrete value's 48 // M is a two argument macro. It is applied to each concrete value's
45 // typename and classname. 49 // typename and classname.
46 #define FOR_EACH_VALUE(M) \ 50 #define FOR_EACH_VALUE(M) \
47 M(Temp, TempVal) \ 51 M(Temp, TempVal) \
48 M(Constant, ConstantVal) \ 52 M(Constant, ConstantVal) \
49 53
50 54
51 // M is a two argument macro. It is applied to each concrete instruction's 55 // M is a two argument macro. It is applied to each concrete instruction's
52 // (including the values) typename and classname. 56 // (including the values) typename and classname.
53 #define FOR_EACH_COMPUTATION(M) \ 57 #define FOR_EACH_COMPUTATION(M) \
54 FOR_EACH_VALUE(M) \ 58 FOR_EACH_VALUE(M) \
55 M(AssertAssignable, AssertAssignableComp) \ 59 M(AssertAssignable, AssertAssignableComp) \
60 M(CurrentContext, CurrentContextComp) \
61 M(ClosureCall, ClosureCallComp) \
56 M(InstanceCall, InstanceCallComp) \ 62 M(InstanceCall, InstanceCallComp) \
57 M(StaticCall, StaticCallComp) \ 63 M(StaticCall, StaticCallComp) \
58 M(LoadLocal, LoadLocalComp) \ 64 M(LoadLocal, LoadLocalComp) \
59 M(StoreLocal, StoreLocalComp) \ 65 M(StoreLocal, StoreLocalComp) \
60 M(StrictCompare, StrictCompareComp) \ 66 M(StrictCompare, StrictCompareComp) \
61 M(NativeCall, NativeCallComp) \ 67 M(NativeCall, NativeCallComp) \
62 M(StoreIndexed, StoreIndexedComp) \ 68 M(StoreIndexed, StoreIndexedComp) \
63 M(InstanceSetter, InstanceSetterComp) \ 69 M(InstanceSetter, InstanceSetterComp) \
64 M(LoadInstanceField, LoadInstanceFieldComp) \ 70 M(LoadInstanceField, LoadInstanceFieldComp) \
65 M(StoreInstanceField, StoreInstanceFieldComp) \ 71 M(StoreInstanceField, StoreInstanceFieldComp) \
66 M(LoadStaticField, LoadStaticFieldComp) \ 72 M(LoadStaticField, LoadStaticFieldComp) \
67 M(StoreStaticField, StoreStaticFieldComp) \ 73 M(StoreStaticField, StoreStaticFieldComp) \
68 M(BooleanNegate, BooleanNegateComp) \ 74 M(BooleanNegate, BooleanNegateComp) \
69 M(InstanceOf, InstanceOfComp) \ 75 M(InstanceOf, InstanceOfComp) \
70 M(CreateArray, CreateArrayComp) \ 76 M(CreateArray, CreateArrayComp) \
77 M(CreateClosure, CreateClosureComp) \
71 M(AllocateObject, AllocateObjectComp) \ 78 M(AllocateObject, AllocateObjectComp) \
72 79
73 80
74 #define FORWARD_DECLARATION(ShortName, ClassName) class ClassName; 81 #define FORWARD_DECLARATION(ShortName, ClassName) class ClassName;
75 FOR_EACH_COMPUTATION(FORWARD_DECLARATION) 82 FOR_EACH_COMPUTATION(FORWARD_DECLARATION)
76 #undef FORWARD_DECLARATION 83 #undef FORWARD_DECLARATION
77 84
78 class Computation : public ZoneAllocated { 85 class Computation : public ZoneAllocated {
79 public: 86 public:
80 Computation() { } 87 Computation() { }
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 const AbstractType& type() const { return type_; } 165 const AbstractType& type() const { return type_; }
159 166
160 private: 167 private:
161 Value* value_; 168 Value* value_;
162 const AbstractType& type_; 169 const AbstractType& type_;
163 170
164 DISALLOW_COPY_AND_ASSIGN(AssertAssignableComp); 171 DISALLOW_COPY_AND_ASSIGN(AssertAssignableComp);
165 }; 172 };
166 173
167 174
175 // Denotes the current context, normally held in a register. This is
176 // a computation, not a value, because it's mutable.
177 class CurrentContextComp : public Computation {
178 public:
179 CurrentContextComp() { }
180
181 DECLARE_COMPUTATION(CurrentContext)
182
183 private:
184 DISALLOW_COPY_AND_ASSIGN(CurrentContextComp);
185 };
186
187
188 class ClosureCallComp : public Computation {
189 public:
190 ClosureCallComp(ClosureCallNode* node,
191 Value* context,
192 ZoneGrowableArray<Value*>* arguments)
193 : ast_node_(*node),
194 context_(context),
195 arguments_(arguments) {
196 ASSERT(context->IsTemp());
197 }
198
199 DECLARE_COMPUTATION(ClosureCall)
200
201 const Array& argument_names() const { return ast_node_.arguments()->names(); }
202 intptr_t token_index() const { return ast_node_.token_index(); }
203
204 Value* context() const { return context_; }
205 intptr_t ArgumentCount() const { return arguments_->length(); }
206 Value* ArgumentAt(intptr_t index) const { return (*arguments_)[index]; }
207
208 private:
209 const ClosureCallNode& ast_node_;
210 Value* context_;
211 ZoneGrowableArray<Value*>* arguments_;
212
213 DISALLOW_COPY_AND_ASSIGN(ClosureCallComp);
214 };
215
216
168 class InstanceCallComp : public Computation { 217 class InstanceCallComp : public Computation {
169 public: 218 public:
170 InstanceCallComp(intptr_t node_id, 219 InstanceCallComp(intptr_t node_id,
171 intptr_t token_index, 220 intptr_t token_index,
172 const String& function_name, 221 const String& function_name,
173 ZoneGrowableArray<Value*>* arguments, 222 ZoneGrowableArray<Value*>* arguments,
174 const Array& argument_names, 223 const Array& argument_names,
175 intptr_t checked_argument_count) 224 intptr_t checked_argument_count)
176 : node_id_(node_id), 225 : node_id_(node_id),
177 token_index_(token_index), 226 token_index_(token_index),
178 function_name_(function_name), 227 function_name_(function_name),
179 arguments_(arguments), 228 arguments_(arguments),
180 argument_names_(argument_names), 229 argument_names_(argument_names),
181 checked_argument_count_(checked_argument_count) { 230 checked_argument_count_(checked_argument_count) {
182 ASSERT(function_name.IsZoneHandle()); 231 ASSERT(function_name.IsZoneHandle());
183 ASSERT(!arguments->is_empty()); 232 ASSERT(!arguments->is_empty());
184 ASSERT(argument_names.IsZoneHandle()); 233 ASSERT(argument_names.IsZoneHandle());
185 } 234 }
186 235
187 DECLARE_COMPUTATION(InstanceCall) 236 DECLARE_COMPUTATION(InstanceCall)
188 237
189 intptr_t node_id() const { return node_id_; } 238 intptr_t node_id() const { return node_id_; }
190 intptr_t token_index() const { return token_index_; } 239 intptr_t token_index() const { return token_index_; }
191 const String& function_name() const { return function_name_; } 240 const String& function_name() const { return function_name_; }
192 int ArgumentCount() const { return arguments_->length(); } 241 intptr_t ArgumentCount() const { return arguments_->length(); }
193 Value* ArgumentAt(int index) const { return (*arguments_)[index]; } 242 Value* ArgumentAt(intptr_t index) const { return (*arguments_)[index]; }
194 const Array& argument_names() const { return argument_names_; } 243 const Array& argument_names() const { return argument_names_; }
195 intptr_t checked_argument_count() const { return checked_argument_count_; } 244 intptr_t checked_argument_count() const { return checked_argument_count_; }
196 245
197 private: 246 private:
198 const intptr_t node_id_; 247 const intptr_t node_id_;
199 const intptr_t token_index_; 248 const intptr_t token_index_;
200 const String& function_name_; 249 const String& function_name_;
201 ZoneGrowableArray<Value*>* const arguments_; 250 ZoneGrowableArray<Value*>* const arguments_;
202 const Array& argument_names_; 251 const Array& argument_names_;
203 const intptr_t checked_argument_count_; 252 const intptr_t checked_argument_count_;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 ASSERT(argument_names.IsZoneHandle()); 291 ASSERT(argument_names.IsZoneHandle());
243 } 292 }
244 293
245 DECLARE_COMPUTATION(StaticCall) 294 DECLARE_COMPUTATION(StaticCall)
246 295
247 // Accessors forwarded to the AST node. 296 // Accessors forwarded to the AST node.
248 const Function& function() const { return function_; } 297 const Function& function() const { return function_; }
249 const Array& argument_names() const { return argument_names_; } 298 const Array& argument_names() const { return argument_names_; }
250 intptr_t token_index() const { return token_index_; } 299 intptr_t token_index() const { return token_index_; }
251 300
252 int ArgumentCount() const { return arguments_->length(); } 301 intptr_t ArgumentCount() const { return arguments_->length(); }
253 Value* ArgumentAt(int index) const { return (*arguments_)[index]; } 302 Value* ArgumentAt(intptr_t index) const { return (*arguments_)[index]; }
254 303
255 private: 304 private:
256 const intptr_t token_index_; 305 const intptr_t token_index_;
257 const Function& function_; 306 const Function& function_;
258 const Array& argument_names_; 307 const Array& argument_names_;
259 ZoneGrowableArray<Value*>* arguments_; 308 ZoneGrowableArray<Value*>* arguments_;
260 309
261 DISALLOW_COPY_AND_ASSIGN(StaticCallComp); 310 DISALLOW_COPY_AND_ASSIGN(StaticCallComp);
262 }; 311 };
263 312
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 Value* ElementAt(intptr_t i) const { return (*elements_)[i]; } 610 Value* ElementAt(intptr_t i) const { return (*elements_)[i]; }
562 611
563 private: 612 private:
564 const ArrayNode& ast_node_; 613 const ArrayNode& ast_node_;
565 ZoneGrowableArray<Value*>* const elements_; 614 ZoneGrowableArray<Value*>* const elements_;
566 615
567 DISALLOW_COPY_AND_ASSIGN(CreateArrayComp); 616 DISALLOW_COPY_AND_ASSIGN(CreateArrayComp);
568 }; 617 };
569 618
570 619
620 class CreateClosureComp : public Computation {
621 public:
622 explicit CreateClosureComp(ClosureNode* node) : ast_node_(*node) { }
623
624 DECLARE_COMPUTATION(CreateClosure)
625
626 intptr_t token_index() const { return ast_node_.token_index(); }
627 const Function& function() const { return ast_node_.function(); }
628
629 private:
630 const ClosureNode& ast_node_;
631
632 DISALLOW_COPY_AND_ASSIGN(CreateClosureComp);
633 };
634
635
571 #undef DECLARE_COMPUTATION 636 #undef DECLARE_COMPUTATION
572 637
573 638
574 // Instructions. 639 // Instructions.
575 // 640 //
576 // <Instruction> ::= JoinEntry <Instruction> 641 // <Instruction> ::= JoinEntry <Instruction>
577 // | TargetEntry <Instruction> 642 // | TargetEntry <Instruction>
578 // | PickTemp <int> <int> <Instruction> 643 // | PickTemp <int> <int> <Instruction>
579 // | TuckTemp <int> <int> <Instruction> 644 // | TuckTemp <int> <int> <Instruction>
580 // | Do <Computation> <Instruction> 645 // | Do <Computation> <Instruction>
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
910 #undef DECLARE_VISIT_INSTRUCTION 975 #undef DECLARE_VISIT_INSTRUCTION
911 976
912 private: 977 private:
913 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); 978 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor);
914 }; 979 };
915 980
916 981
917 } // namespace dart 982 } // namespace dart
918 983
919 #endif // VM_INTERMEDIATE_LANGUAGE_H_ 984 #endif // VM_INTERMEDIATE_LANGUAGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698