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

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

Issue 9570015: Support instance getters and setters, indexed loads and stores. (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/growable_array.h" 10 #include "vm/growable_array.h"
10 #include "vm/handles_impl.h" 11 #include "vm/handles_impl.h"
11 #include "vm/object.h" 12 #include "vm/object.h"
12 13
13 namespace dart { 14 namespace dart {
14 15
15 class FlowGraphVisitor; 16 class FlowGraphVisitor;
16 class LocalVariable; 17 class LocalVariable;
17 18
18 // Computations and values. 19 // Computations and values.
19 // 20 //
20 // <Computation> ::= <Value> 21 // <Computation> ::=
21 // | AssertAssignable <Value> <AbstractType> 22 // <Value>
22 // | InstanceCall <cstring> <Value> ... 23 // | AssertAssignable <Value> <AbstractType>
23 // | StaticCall <Function> <Value> ... 24 // | InstanceCall <AstNode> <String> <Value> ...
24 // | LoadLocal <LocalVariable> 25 // | StaticCall <StaticCallNode> <Value> ...
25 // | StoreLocal <LocalVariable> <Value> 26 // | LoadLocal <LocalVariable>
26 // | StrictCompare <Token::kind> <Value> <Value> 27 // | StoreLocal <LocalVariable> <Value>
28 // | StoreIndexed <Value> <Value> <Value> <Value>
29 // | StrictCompare <Token::kind> <Value> <Value>
27 // 30 //
28 // <Value> ::= Temp <int> 31 // <Value> ::=
29 // | Constant <Instance> 32 // Temp <int>
33 // | Constant <Instance>
30 34
31 // M is a two argument macro. It is applied to each concrete value's 35 // M is a two argument macro. It is applied to each concrete value's
32 // typename and classname. 36 // typename and classname.
33 #define FOR_EACH_VALUE(M) \ 37 #define FOR_EACH_VALUE(M) \
34 M(Temp, TempVal) \ 38 M(Temp, TempVal) \
35 M(Constant, ConstantVal) 39 M(Constant, ConstantVal) \
40
36 41
37 // M is a two argument macro. It is applied to each concrete instruction's 42 // M is a two argument macro. It is applied to each concrete instruction's
38 // (including the values) typename and classname. 43 // (including the values) typename and classname.
39 #define FOR_EACH_COMPUTATION(M) \ 44 #define FOR_EACH_COMPUTATION(M) \
40 FOR_EACH_VALUE(M) \ 45 FOR_EACH_VALUE(M) \
41 M(AssertAssignable, AssertAssignableComp) \ 46 M(AssertAssignable, AssertAssignableComp) \
42 M(InstanceCall, InstanceCallComp) \ 47 M(InstanceCall, InstanceCallComp) \
43 M(StrictCompare, StrictCompareComp) \ 48 M(StrictCompare, StrictCompareComp) \
44 M(StaticCall, StaticCallComp) \ 49 M(StaticCall, StaticCallComp) \
45 M(LoadLocal, LoadLocalComp) \ 50 M(LoadLocal, LoadLocalComp) \
46 M(StoreLocal, StoreLocalComp) 51 M(StoreLocal, StoreLocalComp) \
52 M(StoreIndexed, StoreIndexedComp) \
53 M(InstanceSetter, InstanceSetterComp) \
47 54
48 55
49 #define FORWARD_DECLARATION(ShortName, ClassName) class ClassName; 56 #define FORWARD_DECLARATION(ShortName, ClassName) class ClassName;
50 FOR_EACH_COMPUTATION(FORWARD_DECLARATION) 57 FOR_EACH_COMPUTATION(FORWARD_DECLARATION)
51 #undef FORWARD_DECLARATION 58 #undef FORWARD_DECLARATION
52 59
53 class Computation : public ZoneAllocated { 60 class Computation : public ZoneAllocated {
54 public: 61 public:
55 Computation() { } 62 Computation() { }
56 63
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 private: 142 private:
136 Value* value_; 143 Value* value_;
137 const AbstractType& type_; 144 const AbstractType& type_;
138 145
139 DISALLOW_COPY_AND_ASSIGN(AssertAssignableComp); 146 DISALLOW_COPY_AND_ASSIGN(AssertAssignableComp);
140 }; 147 };
141 148
142 149
143 class InstanceCallComp : public Computation { 150 class InstanceCallComp : public Computation {
144 public: 151 public:
145 InstanceCallComp(const char* name, ZoneGrowableArray<Value*>* arguments) 152 InstanceCallComp(AstNode* node,
146 : name_(name), arguments_(arguments) { 153 const String& function_name,
154 ZoneGrowableArray<Value*>* arguments,
155 const Array& argument_names,
156 intptr_t checked_argument_count)
157 : ast_node_(*node),
158 function_name_(function_name),
159 arguments_(arguments),
160 argument_names_(argument_names),
161 checked_argument_count_(checked_argument_count) {
162 ASSERT(function_name.IsZoneHandle());
147 ASSERT(!arguments->is_empty()); 163 ASSERT(!arguments->is_empty());
164 ASSERT(argument_names.IsZoneHandle());
148 } 165 }
149 166
150 DECLARE_COMPUTATION(InstanceCall) 167 DECLARE_COMPUTATION(InstanceCall)
151 168
152 const char* name() const { return name_; } 169 // Accessors forwarded to the AST node.
170 intptr_t node_id() const { return ast_node_.id(); }
171 intptr_t token_index() const { return ast_node_.token_index(); }
172
173 const String& function_name() const { return function_name_; }
153 int ArgumentCount() const { return arguments_->length(); } 174 int ArgumentCount() const { return arguments_->length(); }
154 Value* ArgumentAt(int index) const { return (*arguments_)[index]; } 175 Value* ArgumentAt(int index) const { return (*arguments_)[index]; }
176 const Array& argument_names() const { return argument_names_; }
177 intptr_t checked_argument_count() const { return checked_argument_count_; }
155 178
156 private: 179 private:
157 const char* name_; 180 const AstNode& ast_node_;
158 ZoneGrowableArray<Value*>* arguments_; 181 const String& function_name_;
182 ZoneGrowableArray<Value*>* const arguments_;
183 const Array& argument_names_;
184 const intptr_t checked_argument_count_;
159 185
160 DISALLOW_COPY_AND_ASSIGN(InstanceCallComp); 186 DISALLOW_COPY_AND_ASSIGN(InstanceCallComp);
161 }; 187 };
162 188
163 189
164 class StrictCompareComp : public Computation { 190 class StrictCompareComp : public Computation {
165 public: 191 public:
166 StrictCompareComp(Token::Kind kind, Value* left, Value* right) 192 StrictCompareComp(Token::Kind kind, Value* left, Value* right)
167 : kind_(kind), left_(left), right_(right) { 193 : kind_(kind), left_(left), right_(right) {
168 ASSERT((kind_ == Token::kEQ_STRICT) || (kind_ == Token::kNE_STRICT)); 194 ASSERT((kind_ == Token::kEQ_STRICT) || (kind_ == Token::kNE_STRICT));
169 } 195 }
170 196
171 DECLARE_COMPUTATION(StrictCompare) 197 DECLARE_COMPUTATION(StrictCompare)
172 198
173 Token::Kind kind() const { return kind_; } 199 Token::Kind kind() const { return kind_; }
174 Value* left() const { return left_; } 200 Value* left() const { return left_; }
175 Value* right() const { return right_; } 201 Value* right() const { return right_; }
176 202
177 private: 203 private:
178 const Token::Kind kind_; 204 const Token::Kind kind_;
179 Value* left_; 205 Value* left_;
180 Value* right_; 206 Value* right_;
181 207
182 DISALLOW_COPY_AND_ASSIGN(StrictCompareComp); 208 DISALLOW_COPY_AND_ASSIGN(StrictCompareComp);
183 }; 209 };
184 210
185 211
186 class StaticCallComp : public Computation { 212 class StaticCallComp : public Computation {
187 public: 213 public:
188 StaticCallComp(const Function& function, ZoneGrowableArray<Value*>* arguments) 214 StaticCallComp(StaticCallNode* node, ZoneGrowableArray<Value*>* arguments)
189 : function_(function), arguments_(arguments) { 215 : ast_node_(*node), arguments_(arguments) { }
190 ASSERT(function.IsZoneHandle());
191 }
192 216
193 DECLARE_COMPUTATION(StaticCall) 217 DECLARE_COMPUTATION(StaticCall)
194 218
195 const Function& function() const { return function_; } 219 // Accessors forwarded to the AST node.
220 const Function& function() const { return ast_node_.function(); }
221 const Array& argument_names() const { return ast_node_.arguments()->names(); }
222 intptr_t token_index() const { return ast_node_.token_index(); }
223
196 int ArgumentCount() const { return arguments_->length(); } 224 int ArgumentCount() const { return arguments_->length(); }
197 Value* ArgumentAt(int index) const { return (*arguments_)[index]; } 225 Value* ArgumentAt(int index) const { return (*arguments_)[index]; }
198 226
199 private: 227 private:
200 const Function& function_; 228 const StaticCallNode& ast_node_;
201 ZoneGrowableArray<Value*>* arguments_; 229 ZoneGrowableArray<Value*>* arguments_;
202 230
203 DISALLOW_COPY_AND_ASSIGN(StaticCallComp); 231 DISALLOW_COPY_AND_ASSIGN(StaticCallComp);
204 }; 232 };
205 233
206 234
207 class LoadLocalComp : public Computation { 235 class LoadLocalComp : public Computation {
208 public: 236 public:
209 explicit LoadLocalComp(const LocalVariable& local) : local_(local) { } 237 explicit LoadLocalComp(const LocalVariable& local) : local_(local) { }
210 238
(...skipping 18 matching lines...) Expand all
229 const LocalVariable& local() const { return local_; } 257 const LocalVariable& local() const { return local_; }
230 Value* value() const { return value_; } 258 Value* value() const { return value_; }
231 259
232 private: 260 private:
233 const LocalVariable& local_; 261 const LocalVariable& local_;
234 Value* value_; 262 Value* value_;
235 263
236 DISALLOW_COPY_AND_ASSIGN(StoreLocalComp); 264 DISALLOW_COPY_AND_ASSIGN(StoreLocalComp);
237 }; 265 };
238 266
267
268 // Not simply an InstanceCall because it has somewhat more complicated
269 // semantics: the value operand is preserved in a placeholder (the first
270 // operand is a preallocated slot that can be used).
271 class StoreIndexedComp : public Computation {
272 public:
273 StoreIndexedComp(StoreIndexedNode* node,
274 Value* placeholder,
275 Value* array,
276 Value* index,
277 Value* value)
278 : ast_node_(*node),
279 placeholder_(placeholder),
280 array_(array),
281 index_(index),
282 value_(value) { }
283
284 DECLARE_COMPUTATION(StoreIndexed)
285
286 // Accessors forwarded to the AST node.
287 intptr_t node_id() const { return ast_node_.id(); }
288 intptr_t token_index() const { return ast_node_.token_index(); }
289
290 Value* placeholder() const { return placeholder_; }
291 Value* array() const { return array_; }
292 Value* index() const { return index_; }
293 Value* value() const { return value_; }
294
295 private:
296 const StoreIndexedNode& ast_node_;
297 Value* placeholder_;
298 Value* array_;
299 Value* index_;
300 Value* value_;
301
302 DISALLOW_COPY_AND_ASSIGN(StoreIndexedComp);
303 };
304
305
306 // Not simply an InstanceCall because it has somewhat more complicated
307 // semantics: the value operand is preserved in a placeholder (the first
308 // operand is a preallocate slot that can be used).
309 class InstanceSetterComp : public Computation {
310 public:
311 InstanceSetterComp(InstanceSetterNode* node,
312 Value* placeholder,
313 Value* receiver,
314 Value* value)
315 : ast_node_(*node),
316 placeholder_(placeholder),
317 receiver_(receiver),
318 value_(value) { }
319
320 DECLARE_COMPUTATION(InstanceSetter)
321
322 // Accessors forwarded to the AST node.
323 intptr_t node_id() const { return ast_node_.id(); }
324 intptr_t token_index() const { return ast_node_.token_index(); }
325 const String& field_name() const { return ast_node_.field_name(); }
326
327 Value* placeholder() const { return placeholder_; }
328 Value* receiver() const { return receiver_; }
329 Value* value() const { return value_; }
330
331 private:
332 const InstanceSetterNode& ast_node_;
333 Value* placeholder_;
334 Value* receiver_;
335 Value* value_;
336
337 DISALLOW_COPY_AND_ASSIGN(InstanceSetterComp);
338 };
339
340
239 #undef DECLARE_COMPUTATION 341 #undef DECLARE_COMPUTATION
240 342
241 343
242 // Instructions. 344 // Instructions.
243 // 345 //
244 // <Instruction> ::= Do <Computation> <Instruction> 346 // <Instruction> ::= Do <Computation> <Instruction>
245 // | Bind <int> <Computation> <Instruction> 347 // | Bind <int> <Computation> <Instruction>
246 // | Return <Value> 348 // | Return <Value>
247 // | Branch <Value> <Instruction> <Instruction> 349 // | Branch <Value> <Instruction> <Instruction>
248 // | Empty <Instruction> 350 // | Empty <Instruction>
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 #undef DECLARE_VISIT_INSTRUCTION 609 #undef DECLARE_VISIT_INSTRUCTION
508 610
509 private: 611 private:
510 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); 612 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor);
511 }; 613 };
512 614
513 615
514 } // namespace dart 616 } // namespace dart
515 617
516 #endif // VM_INTERMEDIATE_LANGUAGE_H_ 618 #endif // VM_INTERMEDIATE_LANGUAGE_H_
OLDNEW
« runtime/vm/flow_graph_compiler_x64.cc ('K') | « runtime/vm/flow_graph_compiler_x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698