| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 // | 45 // |
| 46 // The live registers are: | 46 // The live registers are: |
| 47 // o r1: the JS function object being called (ie, ourselves) | 47 // o r1: the JS function object being called (ie, ourselves) |
| 48 // o cp: our context | 48 // o cp: our context |
| 49 // o fp: our caller's frame pointer | 49 // o fp: our caller's frame pointer |
| 50 // o sp: stack pointer | 50 // o sp: stack pointer |
| 51 // o lr: return address | 51 // o lr: return address |
| 52 // | 52 // |
| 53 // The function builds a JS frame. Please see JavaScriptFrameConstants in | 53 // The function builds a JS frame. Please see JavaScriptFrameConstants in |
| 54 // frames-arm.h for its layout. | 54 // frames-arm.h for its layout. |
| 55 void FullCodeGenerator::Generate(FunctionLiteral* fun) { | 55 void FullCodeGenerator::Generate(FunctionLiteral* fun, Mode mode) { |
| 56 function_ = fun; | 56 function_ = fun; |
| 57 SetFunctionPosition(fun); | 57 SetFunctionPosition(fun); |
| 58 int locals_count = fun->scope()->num_stack_slots(); | |
| 59 | 58 |
| 60 __ stm(db_w, sp, r1.bit() | cp.bit() | fp.bit() | lr.bit()); | 59 if (mode == PRIMARY) { |
| 61 if (locals_count > 0) { | 60 int locals_count = fun->scope()->num_stack_slots(); |
| 62 // Load undefined value here, so the value is ready for the loop below. | 61 |
| 62 __ stm(db_w, sp, r1.bit() | cp.bit() | fp.bit() | lr.bit()); |
| 63 if (locals_count > 0) { |
| 64 // Load undefined value here, so the value is ready for the loop |
| 65 // below. |
| 63 __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); | 66 __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 64 } | 67 } |
| 65 // Adjust fp to point to caller's fp. | 68 // Adjust fp to point to caller's fp. |
| 66 __ add(fp, sp, Operand(2 * kPointerSize)); | 69 __ add(fp, sp, Operand(2 * kPointerSize)); |
| 67 | 70 |
| 68 { Comment cmnt(masm_, "[ Allocate locals"); | 71 { Comment cmnt(masm_, "[ Allocate locals"); |
| 69 for (int i = 0; i < locals_count; i++) { | 72 for (int i = 0; i < locals_count; i++) { |
| 70 __ push(ip); | 73 __ push(ip); |
| 74 } |
| 75 } |
| 76 |
| 77 bool function_in_register = true; |
| 78 |
| 79 // Possibly allocate a local context. |
| 80 if (fun->scope()->num_heap_slots() > 0) { |
| 81 Comment cmnt(masm_, "[ Allocate local context"); |
| 82 // Argument to NewContext is the function, which is in r1. |
| 83 __ push(r1); |
| 84 __ CallRuntime(Runtime::kNewContext, 1); |
| 85 function_in_register = false; |
| 86 // Context is returned in both r0 and cp. It replaces the context |
| 87 // passed to us. It's saved in the stack and kept live in cp. |
| 88 __ str(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 89 // Copy any necessary parameters into the context. |
| 90 int num_parameters = fun->scope()->num_parameters(); |
| 91 for (int i = 0; i < num_parameters; i++) { |
| 92 Slot* slot = fun->scope()->parameter(i)->slot(); |
| 93 if (slot != NULL && slot->type() == Slot::CONTEXT) { |
| 94 int parameter_offset = StandardFrameConstants::kCallerSPOffset + |
| 95 (num_parameters - 1 - i) * kPointerSize; |
| 96 // Load parameter from stack. |
| 97 __ ldr(r0, MemOperand(fp, parameter_offset)); |
| 98 // Store it in the context |
| 99 __ str(r0, MemOperand(cp, Context::SlotOffset(slot->index()))); |
| 100 } |
| 101 } |
| 102 } |
| 103 |
| 104 Variable* arguments = fun->scope()->arguments()->AsVariable(); |
| 105 if (arguments != NULL) { |
| 106 // Function uses arguments object. |
| 107 Comment cmnt(masm_, "[ Allocate arguments object"); |
| 108 if (!function_in_register) { |
| 109 // Load this again, if it's used by the local context below. |
| 110 __ ldr(r3, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); |
| 111 } else { |
| 112 __ mov(r3, r1); |
| 113 } |
| 114 // Receiver is just before the parameters on the caller's stack. |
| 115 __ add(r2, fp, Operand(StandardFrameConstants::kCallerSPOffset + |
| 116 fun->num_parameters() * kPointerSize)); |
| 117 __ mov(r1, Operand(Smi::FromInt(fun->num_parameters()))); |
| 118 __ stm(db_w, sp, r3.bit() | r2.bit() | r1.bit()); |
| 119 |
| 120 // Arguments to ArgumentsAccessStub: |
| 121 // function, receiver address, parameter count. |
| 122 // The stub will rewrite receiever and parameter count if the previous |
| 123 // stack frame was an arguments adapter frame. |
| 124 ArgumentsAccessStub stub(ArgumentsAccessStub::NEW_OBJECT); |
| 125 __ CallStub(&stub); |
| 126 // Duplicate the value; move-to-slot operation might clobber registers. |
| 127 __ mov(r3, r0); |
| 128 Move(arguments->slot(), r0, r1, r2); |
| 129 Slot* dot_arguments_slot = |
| 130 fun->scope()->arguments_shadow()->AsVariable()->slot(); |
| 131 Move(dot_arguments_slot, r3, r1, r2); |
| 71 } | 132 } |
| 72 } | 133 } |
| 73 | 134 |
| 74 bool function_in_register = true; | |
| 75 | |
| 76 // Possibly allocate a local context. | |
| 77 if (fun->scope()->num_heap_slots() > 0) { | |
| 78 Comment cmnt(masm_, "[ Allocate local context"); | |
| 79 // Argument to NewContext is the function, which is in r1. | |
| 80 __ push(r1); | |
| 81 __ CallRuntime(Runtime::kNewContext, 1); | |
| 82 function_in_register = false; | |
| 83 // Context is returned in both r0 and cp. It replaces the context | |
| 84 // passed to us. It's saved in the stack and kept live in cp. | |
| 85 __ str(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); | |
| 86 // Copy any necessary parameters into the context. | |
| 87 int num_parameters = fun->scope()->num_parameters(); | |
| 88 for (int i = 0; i < num_parameters; i++) { | |
| 89 Slot* slot = fun->scope()->parameter(i)->slot(); | |
| 90 if (slot != NULL && slot->type() == Slot::CONTEXT) { | |
| 91 int parameter_offset = StandardFrameConstants::kCallerSPOffset + | |
| 92 (num_parameters - 1 - i) * kPointerSize; | |
| 93 // Load parameter from stack. | |
| 94 __ ldr(r0, MemOperand(fp, parameter_offset)); | |
| 95 // Store it in the context | |
| 96 __ str(r0, MemOperand(cp, Context::SlotOffset(slot->index()))); | |
| 97 } | |
| 98 } | |
| 99 } | |
| 100 | |
| 101 Variable* arguments = fun->scope()->arguments()->AsVariable(); | |
| 102 if (arguments != NULL) { | |
| 103 // Function uses arguments object. | |
| 104 Comment cmnt(masm_, "[ Allocate arguments object"); | |
| 105 if (!function_in_register) { | |
| 106 // Load this again, if it's used by the local context below. | |
| 107 __ ldr(r3, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); | |
| 108 } else { | |
| 109 __ mov(r3, r1); | |
| 110 } | |
| 111 // Receiver is just before the parameters on the caller's stack. | |
| 112 __ add(r2, fp, Operand(StandardFrameConstants::kCallerSPOffset + | |
| 113 fun->num_parameters() * kPointerSize)); | |
| 114 __ mov(r1, Operand(Smi::FromInt(fun->num_parameters()))); | |
| 115 __ stm(db_w, sp, r3.bit() | r2.bit() | r1.bit()); | |
| 116 | |
| 117 // Arguments to ArgumentsAccessStub: | |
| 118 // function, receiver address, parameter count. | |
| 119 // The stub will rewrite receiever and parameter count if the previous | |
| 120 // stack frame was an arguments adapter frame. | |
| 121 ArgumentsAccessStub stub(ArgumentsAccessStub::NEW_OBJECT); | |
| 122 __ CallStub(&stub); | |
| 123 // Duplicate the value; move-to-slot operation might clobber registers. | |
| 124 __ mov(r3, r0); | |
| 125 Move(arguments->slot(), r0, r1, r2); | |
| 126 Slot* dot_arguments_slot = | |
| 127 fun->scope()->arguments_shadow()->AsVariable()->slot(); | |
| 128 Move(dot_arguments_slot, r3, r1, r2); | |
| 129 } | |
| 130 | |
| 131 // Check the stack for overflow or break request. | 135 // Check the stack for overflow or break request. |
| 132 // Put the lr setup instruction in the delay slot. The kInstrSize is | 136 // Put the lr setup instruction in the delay slot. The kInstrSize is |
| 133 // added to the implicit 8 byte offset that always applies to operations | 137 // added to the implicit 8 byte offset that always applies to operations |
| 134 // with pc and gives a return address 12 bytes down. | 138 // with pc and gives a return address 12 bytes down. |
| 135 { Comment cmnt(masm_, "[ Stack check"); | 139 { Comment cmnt(masm_, "[ Stack check"); |
| 136 __ LoadRoot(r2, Heap::kStackLimitRootIndex); | 140 __ LoadRoot(r2, Heap::kStackLimitRootIndex); |
| 137 __ add(lr, pc, Operand(Assembler::kInstrSize)); | 141 __ add(lr, pc, Operand(Assembler::kInstrSize)); |
| 138 __ cmp(sp, Operand(r2)); | 142 __ cmp(sp, Operand(r2)); |
| 139 StackCheckStub stub; | 143 StackCheckStub stub; |
| 140 __ mov(pc, | 144 __ mov(pc, |
| 141 Operand(reinterpret_cast<intptr_t>(stub.GetCode().location()), | 145 Operand(reinterpret_cast<intptr_t>(stub.GetCode().location()), |
| 142 RelocInfo::CODE_TARGET), | 146 RelocInfo::CODE_TARGET), |
| 143 LeaveCC, | 147 LeaveCC, |
| 144 lo); | 148 lo); |
| 145 } | 149 } |
| 146 | 150 |
| 147 { Comment cmnt(masm_, "[ Declarations"); | 151 { Comment cmnt(masm_, "[ Declarations"); |
| 148 VisitDeclarations(fun->scope()->declarations()); | 152 VisitDeclarations(fun->scope()->declarations()); |
| 149 } | 153 } |
| 150 | 154 |
| 151 if (FLAG_trace) { | 155 if (FLAG_trace) { |
| 152 __ CallRuntime(Runtime::kTraceEnter, 0); | 156 __ CallRuntime(Runtime::kTraceEnter, 0); |
| 153 } | 157 } |
| 154 | 158 |
| (...skipping 1607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1762 __ pop(result_register()); | 1766 __ pop(result_register()); |
| 1763 ASSERT_EQ(1, kSmiTagSize + kSmiShiftSize); | 1767 ASSERT_EQ(1, kSmiTagSize + kSmiShiftSize); |
| 1764 __ mov(r1, Operand(r1, ASR, 1)); // Un-smi-tag value. | 1768 __ mov(r1, Operand(r1, ASR, 1)); // Un-smi-tag value. |
| 1765 __ add(pc, r1, Operand(masm_->CodeObject())); | 1769 __ add(pc, r1, Operand(masm_->CodeObject())); |
| 1766 } | 1770 } |
| 1767 | 1771 |
| 1768 | 1772 |
| 1769 #undef __ | 1773 #undef __ |
| 1770 | 1774 |
| 1771 } } // namespace v8::internal | 1775 } } // namespace v8::internal |
| OLD | NEW |