OLD | NEW |
---|---|
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 25 matching lines...) Expand all Loading... | |
36 class ExitNode; | 36 class ExitNode; |
37 class Location; | 37 class Location; |
38 | 38 |
39 // Translate a source AST into a control-flow graph (CFG). The CFG contains | 39 // Translate a source AST into a control-flow graph (CFG). The CFG contains |
40 // single-entry, single-exit blocks of straight-line instructions and | 40 // single-entry, single-exit blocks of straight-line instructions and |
41 // administrative nodes. | 41 // administrative nodes. |
42 // | 42 // |
43 // Instructions are described by the following grammar. | 43 // Instructions are described by the following grammar. |
44 // | 44 // |
45 // <Instruction> ::= | 45 // <Instruction> ::= |
46 // MoveInstr <Location> <Value> | 46 // Move <Location> <Value> |
47 // | BinaryOpInstr <Location> Token::Value <Value> <Value> | 47 // | PropRef <Location> <Value> <Value> |
48 // | ReturnInstr Nowhere <Value> | 48 // | BinaryOp <Location> Token::Value <Value> <Value> |
49 // | PositionInstr <Int> | 49 // | Return Nowhere <Value> |
50 // | Position <Int> | |
50 // | 51 // |
51 // Values are trivial expressions: | 52 // Values are trivial expressions: |
52 // | 53 // |
53 // <Value> ::= Constant | <Location> | 54 // <Value> ::= Constant | <Location> |
54 // | 55 // |
55 // Locations are storable values ('lvalues'). They can be slots, | 56 // Locations are storable values ('lvalues'). They can be slots, |
56 // compiler-generated temporaries, or the special location 'Nowhere' | 57 // compiler-generated temporaries, or the special location 'Nowhere' |
57 // indicating that no value is needed. | 58 // indicating that no value is needed. |
58 // | 59 // |
59 // <Location> ::= | 60 // <Location> ::= |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
124 class SlotLocation; | 125 class SlotLocation; |
125 | 126 |
126 // Values represent trivial source expressions: ones with no side effects | 127 // Values represent trivial source expressions: ones with no side effects |
127 // and that do not require code to be generated. | 128 // and that do not require code to be generated. |
128 class Value : public ZoneObject { | 129 class Value : public ZoneObject { |
129 public: | 130 public: |
130 virtual ~Value() {} | 131 virtual ~Value() {} |
131 | 132 |
132 // Predicates: | 133 // Predicates: |
133 | 134 |
135 virtual bool is_temporary() { return false; } | |
136 virtual bool is_slot() { return false; } | |
137 virtual bool is_constant() { return false; } | |
138 | |
134 // True if the value is a temporary allocated to the stack in | 139 // True if the value is a temporary allocated to the stack in |
135 // fast-compilation mode. | 140 // fast-compilation mode. |
136 virtual bool is_on_stack() { return false; } | 141 virtual bool is_on_stack() { return false; } |
137 | 142 |
138 // True if the value is a compiler-generated temporary location. | |
139 virtual bool is_temporary() { return false; } | |
140 | |
141 // True if the value is a slot location. | |
142 virtual bool is_slot() { return false; } | |
143 | |
144 // Support for fast-compilation mode: | 143 // Support for fast-compilation mode: |
145 | 144 |
146 // Move the value into a register. | 145 // Move the value into a register. |
147 virtual void Get(MacroAssembler* masm, Register reg) = 0; | 146 virtual void Get(MacroAssembler* masm, Register reg) = 0; |
148 | 147 |
149 // Push the value on the stack. | 148 // Push the value on the stack. |
150 virtual void Push(MacroAssembler* masm) = 0; | 149 virtual void Push(MacroAssembler* masm) = 0; |
151 | 150 |
152 // Move the value into a slot location. | 151 // Move the value into a slot location. |
153 virtual void MoveToSlot(MacroAssembler* masm, SlotLocation* loc) = 0; | 152 virtual void MoveToSlot(MacroAssembler* masm, SlotLocation* loc) = 0; |
154 | 153 |
155 #ifdef DEBUG | 154 #ifdef DEBUG |
156 virtual void Print() = 0; | 155 virtual void Print() = 0; |
157 #endif | 156 #endif |
158 }; | 157 }; |
159 | 158 |
160 | 159 |
161 // A compile-time constant that appeared as a literal in the source AST. | 160 // A compile-time constant that appeared as a literal in the source AST. |
162 class Constant : public Value { | 161 class Constant : public Value { |
163 public: | 162 public: |
164 explicit Constant(Handle<Object> handle) : handle_(handle) {} | 163 explicit Constant(Handle<Object> handle) : handle_(handle) {} |
165 | 164 |
166 virtual ~Constant() {} | 165 // Cast accessor. |
166 static Constant* cast(Value* value) { | |
167 ASSERT(value->is_constant()); | |
168 return reinterpret_cast<Constant*>(value); | |
169 } | |
170 | |
171 // Accessors. | |
172 Handle<Object> handle() { return handle_; } | |
173 | |
174 // Predicates. | |
175 bool is_constant() { return true; } | |
167 | 176 |
168 // Support for fast-compilation mode. | 177 // Support for fast-compilation mode. |
169 void Get(MacroAssembler* masm, Register reg); | 178 void Get(MacroAssembler* masm, Register reg); |
170 void Push(MacroAssembler* masm); | 179 void Push(MacroAssembler* masm); |
171 void MoveToSlot(MacroAssembler* masm, SlotLocation* loc); | 180 void MoveToSlot(MacroAssembler* masm, SlotLocation* loc); |
172 | 181 |
173 #ifdef DEBUG | 182 #ifdef DEBUG |
174 void Print(); | 183 void Print(); |
175 #endif | 184 #endif |
176 | 185 |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
403 | 412 |
404 #ifdef DEBUG | 413 #ifdef DEBUG |
405 void Print(); | 414 void Print(); |
406 #endif | 415 #endif |
407 | 416 |
408 private: | 417 private: |
409 Value* value_; | 418 Value* value_; |
410 }; | 419 }; |
411 | 420 |
412 | 421 |
422 // Load a property from a receiver, leaving the result in a location. | |
William Hesse
2009/08/07 12:50:26
I like PropertyLoad better. A PropertyRef to me m
Kevin Millikin (Chromium)
2009/08/07 13:25:33
Going with PropLoad.
| |
423 class PropRefInstr : public Instruction { | |
424 public: | |
425 PropRefInstr(Location* loc, Value* object, Value* key) | |
426 : Instruction(loc), object_(object), key_(key) { | |
427 } | |
428 | |
429 // Accessors. | |
430 Value* object() { return object_; } | |
431 Value* key() { return key_; } | |
432 | |
433 // Support for fast-compilation mode. | |
434 void Compile(MacroAssembler* masm); | |
435 void FastAllocate(TempLocation* temp); | |
436 | |
437 #ifdef DEBUG | |
438 void Print(); | |
439 #endif | |
440 | |
441 private: | |
442 Value* object_; | |
443 Value* key_; | |
444 }; | |
445 | |
446 | |
413 // Perform a (non-short-circuited) binary operation on a pair of values, | 447 // Perform a (non-short-circuited) binary operation on a pair of values, |
414 // leaving the result in a location. | 448 // leaving the result in a location. |
415 class BinaryOpInstr : public Instruction { | 449 class BinaryOpInstr : public Instruction { |
416 public: | 450 public: |
417 BinaryOpInstr(Location* loc, Token::Value op, Value* value0, Value* value1) | 451 BinaryOpInstr(Location* loc, Token::Value op, Value* left, Value* right) |
418 : Instruction(loc), op_(op), value0_(value0), value1_(value1) { | 452 : Instruction(loc), op_(op), left_(left), right_(right) { |
419 } | 453 } |
420 | 454 |
421 // Accessors. | 455 // Accessors. |
422 Token::Value op() { return op_; } | 456 Token::Value op() { return op_; } |
423 Value* value0() { return value0_; } | 457 Value* left() { return left_; } |
424 Value* value1() { return value1_; } | 458 Value* right() { return right_; } |
425 | 459 |
426 // Support for fast-compilation mode. | 460 // Support for fast-compilation mode. |
427 void Compile(MacroAssembler* masm); | 461 void Compile(MacroAssembler* masm); |
428 void FastAllocate(TempLocation* temp); | 462 void FastAllocate(TempLocation* temp); |
429 | 463 |
430 #ifdef DEBUG | 464 #ifdef DEBUG |
431 void Print(); | 465 void Print(); |
432 #endif | 466 #endif |
433 | 467 |
434 private: | 468 private: |
435 Token::Value op_; | 469 Token::Value op_; |
436 Value* value0_; | 470 Value* left_; |
437 Value* value1_; | 471 Value* right_; |
438 }; | 472 }; |
439 | 473 |
440 | 474 |
441 // Return a value. Has the side effect of moving its value into the return | 475 // Return a value. Has the side effect of moving its value into the return |
442 // value register. Can only occur as the last instruction in an instruction | 476 // value register. Can only occur as the last instruction in an instruction |
443 // block, and implies that the block is closed (cannot have instructions | 477 // block, and implies that the block is closed (cannot have instructions |
444 // appended or graph fragments concatenated to the end) and that the block's | 478 // appended or graph fragments concatenated to the end) and that the block's |
445 // successor is the global exit node for the current function. | 479 // successor is the global exit node for the current function. |
446 class ReturnInstr : public Instruction { | 480 class ReturnInstr : public Instruction { |
447 public: | 481 public: |
448 explicit ReturnInstr(Value* value) : value_(value) {} | 482 explicit ReturnInstr(Value* value) : value_(value) {} |
449 | 483 |
450 virtual ~ReturnInstr() {} | 484 virtual ~ReturnInstr() {} |
451 | 485 |
486 // Accessors. | |
487 Value* value() { return value_; } | |
488 | |
452 // Support for fast-compilation mode. | 489 // Support for fast-compilation mode. |
453 void Compile(MacroAssembler* masm); | 490 void Compile(MacroAssembler* masm); |
454 void FastAllocate(TempLocation* temp); | 491 void FastAllocate(TempLocation* temp); |
455 | 492 |
456 #ifdef DEBUG | 493 #ifdef DEBUG |
457 void Print(); | 494 void Print(); |
458 #endif | 495 #endif |
459 | 496 |
460 private: | 497 private: |
461 Value* value_; | 498 Value* value_; |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
773 | 810 |
774 private: | 811 private: |
775 // State for the visitor. Input/output parameter: | 812 // State for the visitor. Input/output parameter: |
776 Cfg* graph_; | 813 Cfg* graph_; |
777 }; | 814 }; |
778 | 815 |
779 | 816 |
780 } } // namespace v8::internal | 817 } } // namespace v8::internal |
781 | 818 |
782 #endif // V8_CFG_H_ | 819 #endif // V8_CFG_H_ |
OLD | NEW |