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