OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 Scope* scope, | 315 Scope* scope, |
316 Handle<JSFunction> closure); | 316 Handle<JSFunction> closure); |
317 | 317 |
318 // Simple accessors. | 318 // Simple accessors. |
319 Handle<JSFunction> closure() const { return closure_; } | 319 Handle<JSFunction> closure() const { return closure_; } |
320 const ZoneList<HValue*>* values() const { return &values_; } | 320 const ZoneList<HValue*>* values() const { return &values_; } |
321 const ZoneList<int>* assigned_variables() const { | 321 const ZoneList<int>* assigned_variables() const { |
322 return &assigned_variables_; | 322 return &assigned_variables_; |
323 } | 323 } |
324 int parameter_count() const { return parameter_count_; } | 324 int parameter_count() const { return parameter_count_; } |
| 325 int specials_count() const { return specials_count_; } |
325 int local_count() const { return local_count_; } | 326 int local_count() const { return local_count_; } |
326 HEnvironment* outer() const { return outer_; } | 327 HEnvironment* outer() const { return outer_; } |
327 int pop_count() const { return pop_count_; } | 328 int pop_count() const { return pop_count_; } |
328 int push_count() const { return push_count_; } | 329 int push_count() const { return push_count_; } |
329 | 330 |
330 int ast_id() const { return ast_id_; } | 331 int ast_id() const { return ast_id_; } |
331 void set_ast_id(int id) { ast_id_ = id; } | 332 void set_ast_id(int id) { ast_id_ = id; } |
332 | 333 |
333 int length() const { return values_.length(); } | 334 int length() const { return values_.length(); } |
| 335 bool is_special_index(int i) const { |
| 336 return i >= parameter_count() && i < parameter_count() + specials_count(); |
| 337 } |
334 | 338 |
335 void Bind(Variable* variable, HValue* value) { | 339 void Bind(Variable* variable, HValue* value) { |
336 Bind(IndexFor(variable), value); | 340 Bind(IndexFor(variable), value); |
337 } | 341 } |
338 | 342 |
339 void Bind(int index, HValue* value); | 343 void Bind(int index, HValue* value); |
340 | 344 |
| 345 void BindContext(HValue* value) { |
| 346 Bind(parameter_count(), value); |
| 347 } |
| 348 |
341 HValue* Lookup(Variable* variable) const { | 349 HValue* Lookup(Variable* variable) const { |
342 return Lookup(IndexFor(variable)); | 350 return Lookup(IndexFor(variable)); |
343 } | 351 } |
344 | 352 |
345 HValue* Lookup(int index) const { | 353 HValue* Lookup(int index) const { |
346 HValue* result = values_[index]; | 354 HValue* result = values_[index]; |
347 ASSERT(result != NULL); | 355 ASSERT(result != NULL); |
348 return result; | 356 return result; |
349 } | 357 } |
350 | 358 |
| 359 HValue* LookupContext() const { |
| 360 // Return first special. |
| 361 return Lookup(parameter_count()); |
| 362 } |
| 363 |
351 void Push(HValue* value) { | 364 void Push(HValue* value) { |
352 ASSERT(value != NULL); | 365 ASSERT(value != NULL); |
353 ++push_count_; | 366 ++push_count_; |
354 values_.Add(value); | 367 values_.Add(value); |
355 } | 368 } |
356 | 369 |
357 HValue* Pop() { | 370 HValue* Pop() { |
358 ASSERT(!ExpressionStackIsEmpty()); | 371 ASSERT(!ExpressionStackIsEmpty()); |
359 if (push_count_ > 0) { | 372 if (push_count_ > 0) { |
360 --push_count_; | 373 --push_count_; |
361 } else { | 374 } else { |
362 ++pop_count_; | 375 ++pop_count_; |
363 } | 376 } |
364 return values_.RemoveLast(); | 377 return values_.RemoveLast(); |
365 } | 378 } |
366 | 379 |
367 void Drop(int count); | 380 void Drop(int count); |
368 | 381 |
369 HValue* Top() const { return ExpressionStackAt(0); } | 382 HValue* Top() const { return ExpressionStackAt(0); } |
370 | 383 |
| 384 bool ExpressionStackIsEmpty() const; |
| 385 |
371 HValue* ExpressionStackAt(int index_from_top) const { | 386 HValue* ExpressionStackAt(int index_from_top) const { |
372 int index = length() - index_from_top - 1; | 387 int index = length() - index_from_top - 1; |
373 ASSERT(HasExpressionAt(index)); | 388 ASSERT(HasExpressionAt(index)); |
374 return values_[index]; | 389 return values_[index]; |
375 } | 390 } |
376 | 391 |
377 void SetExpressionStackAt(int index_from_top, HValue* value); | 392 void SetExpressionStackAt(int index_from_top, HValue* value); |
378 | 393 |
379 HEnvironment* Copy() const; | 394 HEnvironment* Copy() const; |
380 HEnvironment* CopyWithoutHistory() const; | 395 HEnvironment* CopyWithoutHistory() const; |
(...skipping 24 matching lines...) Expand all Loading... |
405 | 420 |
406 void PrintTo(StringStream* stream); | 421 void PrintTo(StringStream* stream); |
407 void PrintToStd(); | 422 void PrintToStd(); |
408 | 423 |
409 private: | 424 private: |
410 explicit HEnvironment(const HEnvironment* other); | 425 explicit HEnvironment(const HEnvironment* other); |
411 | 426 |
412 // True if index is included in the expression stack part of the environment. | 427 // True if index is included in the expression stack part of the environment. |
413 bool HasExpressionAt(int index) const; | 428 bool HasExpressionAt(int index) const; |
414 | 429 |
415 bool ExpressionStackIsEmpty() const; | |
416 | |
417 void Initialize(int parameter_count, int local_count, int stack_height); | 430 void Initialize(int parameter_count, int local_count, int stack_height); |
418 void Initialize(const HEnvironment* other); | 431 void Initialize(const HEnvironment* other); |
419 | 432 |
420 // Map a variable to an environment index. Parameter indices are shifted | 433 // Map a variable to an environment index. Parameter indices are shifted |
421 // by 1 (receiver is parameter index -1 but environment index 0). | 434 // by 1 (receiver is parameter index -1 but environment index 0). |
422 // Stack-allocated local indices are shifted by the number of parameters. | 435 // Stack-allocated local indices are shifted by the number of parameters. |
423 int IndexFor(Variable* variable) const { | 436 int IndexFor(Variable* variable) const { |
424 Slot* slot = variable->AsSlot(); | 437 Slot* slot = variable->AsSlot(); |
425 ASSERT(slot != NULL && slot->IsStackAllocated()); | 438 ASSERT(slot != NULL && slot->IsStackAllocated()); |
426 int shift = (slot->type() == Slot::PARAMETER) ? 1 : parameter_count_; | 439 int shift = (slot->type() == Slot::PARAMETER) |
| 440 ? 1 |
| 441 : parameter_count_ + specials_count_; |
427 return slot->index() + shift; | 442 return slot->index() + shift; |
428 } | 443 } |
429 | 444 |
430 Handle<JSFunction> closure_; | 445 Handle<JSFunction> closure_; |
431 // Value array [parameters] [locals] [temporaries]. | 446 // Value array [parameters] [specials] [locals] [temporaries]. |
432 ZoneList<HValue*> values_; | 447 ZoneList<HValue*> values_; |
433 ZoneList<int> assigned_variables_; | 448 ZoneList<int> assigned_variables_; |
434 int parameter_count_; | 449 int parameter_count_; |
| 450 int specials_count_; |
435 int local_count_; | 451 int local_count_; |
436 HEnvironment* outer_; | 452 HEnvironment* outer_; |
437 int pop_count_; | 453 int pop_count_; |
438 int push_count_; | 454 int push_count_; |
439 int ast_id_; | 455 int ast_id_; |
440 }; | 456 }; |
441 | 457 |
442 | 458 |
443 class HGraphBuilder; | 459 class HGraphBuilder; |
444 | 460 |
(...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1158 const char* filename_; | 1174 const char* filename_; |
1159 HeapStringAllocator string_allocator_; | 1175 HeapStringAllocator string_allocator_; |
1160 StringStream trace_; | 1176 StringStream trace_; |
1161 int indent_; | 1177 int indent_; |
1162 }; | 1178 }; |
1163 | 1179 |
1164 | 1180 |
1165 } } // namespace v8::internal | 1181 } } // namespace v8::internal |
1166 | 1182 |
1167 #endif // V8_HYDROGEN_H_ | 1183 #endif // V8_HYDROGEN_H_ |
OLD | NEW |