| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 // A control destination in case the expression has a control-flow | 266 // A control destination in case the expression has a control-flow |
| 267 // effect. | 267 // effect. |
| 268 ControlDestination* destination_; | 268 ControlDestination* destination_; |
| 269 | 269 |
| 270 // The previous state of the owning code generator, restored when | 270 // The previous state of the owning code generator, restored when |
| 271 // this state is destroyed. | 271 // this state is destroyed. |
| 272 CodeGenState* previous_; | 272 CodeGenState* previous_; |
| 273 }; | 273 }; |
| 274 | 274 |
| 275 | 275 |
| 276 // ------------------------------------------------------------------------- |
| 277 // Arguments allocation mode |
| 278 |
| 279 enum ArgumentsAllocationMode { |
| 280 NO_ARGUMENTS_ALLOCATION, |
| 281 EAGER_ARGUMENTS_ALLOCATION, |
| 282 LAZY_ARGUMENTS_ALLOCATION |
| 283 }; |
| 276 | 284 |
| 277 | 285 |
| 278 // ------------------------------------------------------------------------- | 286 // ------------------------------------------------------------------------- |
| 279 // CodeGenerator | 287 // CodeGenerator |
| 280 | 288 |
| 281 class CodeGenerator: public AstVisitor { | 289 class CodeGenerator: public AstVisitor { |
| 282 public: | 290 public: |
| 283 // Takes a function literal, generates code for it. This function should only | 291 // Takes a function literal, generates code for it. This function should only |
| 284 // be called by compiler.cc. | 292 // be called by compiler.cc. |
| 285 static Handle<Code> MakeCode(FunctionLiteral* fun, | 293 static Handle<Code> MakeCode(FunctionLiteral* fun, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 bool in_spilled_code() const { return in_spilled_code_; } | 333 bool in_spilled_code() const { return in_spilled_code_; } |
| 326 void set_in_spilled_code(bool flag) { in_spilled_code_ = flag; } | 334 void set_in_spilled_code(bool flag) { in_spilled_code_ = flag; } |
| 327 | 335 |
| 328 private: | 336 private: |
| 329 // Construction/Destruction | 337 // Construction/Destruction |
| 330 CodeGenerator(int buffer_size, Handle<Script> script, bool is_eval); | 338 CodeGenerator(int buffer_size, Handle<Script> script, bool is_eval); |
| 331 virtual ~CodeGenerator() { delete masm_; } | 339 virtual ~CodeGenerator() { delete masm_; } |
| 332 | 340 |
| 333 // Accessors | 341 // Accessors |
| 334 Scope* scope() const { return scope_; } | 342 Scope* scope() const { return scope_; } |
| 343 bool is_eval() { return is_eval_; } |
| 335 | 344 |
| 336 // Generating deferred code. | 345 // Generating deferred code. |
| 337 void ProcessDeferred(); | 346 void ProcessDeferred(); |
| 338 | 347 |
| 339 bool is_eval() { return is_eval_; } | |
| 340 | |
| 341 // State | 348 // State |
| 342 TypeofState typeof_state() const { return state_->typeof_state(); } | 349 TypeofState typeof_state() const { return state_->typeof_state(); } |
| 343 ControlDestination* destination() const { return state_->destination(); } | 350 ControlDestination* destination() const { return state_->destination(); } |
| 344 | 351 |
| 345 // Track loop nesting level. | 352 // Track loop nesting level. |
| 346 int loop_nesting() const { return loop_nesting_; } | 353 int loop_nesting() const { return loop_nesting_; } |
| 347 void IncrementLoopNesting() { loop_nesting_++; } | 354 void IncrementLoopNesting() { loop_nesting_++; } |
| 348 void DecrementLoopNesting() { loop_nesting_--; } | 355 void DecrementLoopNesting() { loop_nesting_--; } |
| 349 | 356 |
| 350 // Node visitors. | 357 // Node visitors. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 366 void VisitStatementsAndSpill(ZoneList<Statement*>* statements); | 373 void VisitStatementsAndSpill(ZoneList<Statement*>* statements); |
| 367 | 374 |
| 368 // Main code generation function | 375 // Main code generation function |
| 369 void GenCode(FunctionLiteral* fun); | 376 void GenCode(FunctionLiteral* fun); |
| 370 | 377 |
| 371 // Generate the return sequence code. Should be called no more than | 378 // Generate the return sequence code. Should be called no more than |
| 372 // once per compiled function, immediately after binding the return | 379 // once per compiled function, immediately after binding the return |
| 373 // target (which can not be done more than once). | 380 // target (which can not be done more than once). |
| 374 void GenerateReturnSequence(Result* return_value); | 381 void GenerateReturnSequence(Result* return_value); |
| 375 | 382 |
| 383 // Returns the arguments allocation mode. |
| 384 ArgumentsAllocationMode ArgumentsMode() const; |
| 385 |
| 386 // Store the arguments object and allocate it if necessary. |
| 387 Result StoreArgumentsObject(bool initial); |
| 388 |
| 376 // The following are used by class Reference. | 389 // The following are used by class Reference. |
| 377 void LoadReference(Reference* ref); | 390 void LoadReference(Reference* ref); |
| 378 void UnloadReference(Reference* ref); | 391 void UnloadReference(Reference* ref); |
| 379 | 392 |
| 380 Operand ContextOperand(Register context, int index) const { | 393 Operand ContextOperand(Register context, int index) const { |
| 381 return Operand(context, Context::SlotOffset(index)); | 394 return Operand(context, Context::SlotOffset(index)); |
| 382 } | 395 } |
| 383 | 396 |
| 384 Operand SlotOperand(Slot* slot, Register tmp); | 397 Operand SlotOperand(Slot* slot, Register tmp); |
| 385 | 398 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 401 void LoadGlobalReceiver(); | 414 void LoadGlobalReceiver(); |
| 402 | 415 |
| 403 // Generate code to push the value of an expression on top of the frame | 416 // Generate code to push the value of an expression on top of the frame |
| 404 // and then spill the frame fully to memory. This function is used | 417 // and then spill the frame fully to memory. This function is used |
| 405 // temporarily while the code generator is being transformed. | 418 // temporarily while the code generator is being transformed. |
| 406 void LoadAndSpill(Expression* expression, | 419 void LoadAndSpill(Expression* expression, |
| 407 TypeofState typeof_state = NOT_INSIDE_TYPEOF); | 420 TypeofState typeof_state = NOT_INSIDE_TYPEOF); |
| 408 | 421 |
| 409 // Read a value from a slot and leave it on top of the expression stack. | 422 // Read a value from a slot and leave it on top of the expression stack. |
| 410 void LoadFromSlot(Slot* slot, TypeofState typeof_state); | 423 void LoadFromSlot(Slot* slot, TypeofState typeof_state); |
| 424 void LoadFromSlotCheckForArguments(Slot* slot, TypeofState typeof_state); |
| 411 Result LoadFromGlobalSlotCheckExtensions(Slot* slot, | 425 Result LoadFromGlobalSlotCheckExtensions(Slot* slot, |
| 412 TypeofState typeof_state, | 426 TypeofState typeof_state, |
| 413 JumpTarget* slow); | 427 JumpTarget* slow); |
| 414 | 428 |
| 415 // Store the value on top of the expression stack into a slot, leaving the | 429 // Store the value on top of the expression stack into a slot, leaving the |
| 416 // value in place. | 430 // value in place. |
| 417 void StoreToSlot(Slot* slot, InitState init_state); | 431 void StoreToSlot(Slot* slot, InitState init_state); |
| 418 | 432 |
| 419 // Special code for typeof expressions: Unfortunately, we must | 433 // Special code for typeof expressions: Unfortunately, we must |
| 420 // be careful when loading the expression in 'typeof' | 434 // be careful when loading the expression in 'typeof' |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 // from the JavaScript source are loaded in two parts if they are larger | 477 // from the JavaScript source are loaded in two parts if they are larger |
| 464 // than 16 bits. | 478 // than 16 bits. |
| 465 static const int kMaxSmiInlinedBits = 16; | 479 static const int kMaxSmiInlinedBits = 16; |
| 466 bool IsUnsafeSmi(Handle<Object> value); | 480 bool IsUnsafeSmi(Handle<Object> value); |
| 467 // Load an integer constant x into a register target using | 481 // Load an integer constant x into a register target using |
| 468 // at most 16 bits of user-controlled data per assembly operation. | 482 // at most 16 bits of user-controlled data per assembly operation. |
| 469 void LoadUnsafeSmi(Register target, Handle<Object> value); | 483 void LoadUnsafeSmi(Register target, Handle<Object> value); |
| 470 | 484 |
| 471 void CallWithArguments(ZoneList<Expression*>* arguments, int position); | 485 void CallWithArguments(ZoneList<Expression*>* arguments, int position); |
| 472 | 486 |
| 487 // Use an optimized version of Function.prototype.apply that avoid |
| 488 // allocating the arguments object and just copies the arguments |
| 489 // from the stack. |
| 490 void CallApplyLazy(Property* apply, |
| 491 Expression* receiver, |
| 492 VariableProxy* arguments, |
| 493 int position); |
| 494 |
| 473 void CheckStack(); | 495 void CheckStack(); |
| 474 | 496 |
| 475 struct InlineRuntimeLUT { | 497 struct InlineRuntimeLUT { |
| 476 void (CodeGenerator::*method)(ZoneList<Expression*>*); | 498 void (CodeGenerator::*method)(ZoneList<Expression*>*); |
| 477 const char* name; | 499 const char* name; |
| 478 }; | 500 }; |
| 479 | 501 |
| 480 static InlineRuntimeLUT* FindInlineRuntimeLUT(Handle<String> name); | 502 static InlineRuntimeLUT* FindInlineRuntimeLUT(Handle<String> name); |
| 481 bool CheckForInlineRuntimeCall(CallRuntime* node); | 503 bool CheckForInlineRuntimeCall(CallRuntime* node); |
| 482 static bool PatchInlineRuntimeEntry(Handle<String> name, | 504 static bool PatchInlineRuntimeEntry(Handle<String> name, |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 | 601 |
| 580 friend class CodeGeneratorPatcher; // Used in test-log-ia32.cc | 602 friend class CodeGeneratorPatcher; // Used in test-log-ia32.cc |
| 581 | 603 |
| 582 DISALLOW_COPY_AND_ASSIGN(CodeGenerator); | 604 DISALLOW_COPY_AND_ASSIGN(CodeGenerator); |
| 583 }; | 605 }; |
| 584 | 606 |
| 585 | 607 |
| 586 } } // namespace v8::internal | 608 } } // namespace v8::internal |
| 587 | 609 |
| 588 #endif // V8_IA32_CODEGEN_IA32_H_ | 610 #endif // V8_IA32_CODEGEN_IA32_H_ |
| OLD | NEW |