OLD | NEW |
(Empty) | |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are |
| 4 // met: |
| 5 // |
| 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided |
| 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. |
| 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 |
| 28 #include "v8.h" |
| 29 |
| 30 #include "codegen-inl.h" |
| 31 #include "fast-codegen.h" |
| 32 |
| 33 namespace v8 { |
| 34 namespace internal { |
| 35 |
| 36 #define __ ACCESS_MASM(masm()) |
| 37 |
| 38 void FastCodeGenerator::EmitLoadReceiver(Register reg) { |
| 39 // Offset 2 is due to return address and saved frame pointer. |
| 40 int index = 2 + function()->scope()->num_parameters(); |
| 41 __ mov(reg, Operand(ebp, index * kPointerSize)); |
| 42 } |
| 43 |
| 44 |
| 45 void FastCodeGenerator::EmitReceiverMapCheck() { |
| 46 Comment cmnt(masm(), ";; MapCheck(this)"); |
| 47 if (FLAG_print_ir) { |
| 48 PrintF("MapCheck(this)\n"); |
| 49 } |
| 50 |
| 51 EmitLoadReceiver(edx); |
| 52 __ test(edx, Immediate(kSmiTagMask)); |
| 53 __ j(zero, bailout()); |
| 54 |
| 55 ASSERT(has_receiver() && receiver()->IsHeapObject()); |
| 56 Handle<HeapObject> object = Handle<HeapObject>::cast(receiver()); |
| 57 Handle<Map> map(object->map()); |
| 58 __ cmp(FieldOperand(edx, HeapObject::kMapOffset), Immediate(map)); |
| 59 __ j(not_equal, bailout()); |
| 60 } |
| 61 |
| 62 |
| 63 void FastCodeGenerator::EmitGlobalVariableLoad(Handle<String> name) { |
| 64 // Compile global variable accesses as load IC calls. The only live |
| 65 // registers are esi (context) and possibly edx (this). Both are also |
| 66 // saved in the stack and esi is preserved by the call. |
| 67 __ push(CodeGenerator::GlobalObject()); |
| 68 __ mov(ecx, name); |
| 69 Handle<Code> ic(Builtins::builtin(Builtins::LoadIC_Initialize)); |
| 70 __ call(ic, RelocInfo::CODE_TARGET_CONTEXT); |
| 71 if (has_this_properties()) { |
| 72 // Restore this. |
| 73 EmitLoadReceiver(edx); |
| 74 } else { |
| 75 __ nop(); // Not test eax, indicates IC has no inlined code at call site. |
| 76 } |
| 77 } |
| 78 |
| 79 |
| 80 void FastCodeGenerator::EmitThisPropertyStore(Handle<String> name) { |
| 81 LookupResult lookup; |
| 82 receiver()->Lookup(*name, &lookup); |
| 83 |
| 84 ASSERT(lookup.holder() == *receiver()); |
| 85 ASSERT(lookup.type() == FIELD); |
| 86 Handle<Map> map(Handle<HeapObject>::cast(receiver())->map()); |
| 87 int index = lookup.GetFieldIndex() - map->inobject_properties(); |
| 88 int offset = index * kPointerSize; |
| 89 |
| 90 // Negative offsets are inobject properties. |
| 91 if (offset < 0) { |
| 92 offset += map->instance_size(); |
| 93 __ mov(ecx, edx); // Copy receiver for write barrier. |
| 94 } else { |
| 95 offset += FixedArray::kHeaderSize; |
| 96 __ mov(ecx, FieldOperand(edx, JSObject::kPropertiesOffset)); |
| 97 } |
| 98 // Perform the store. |
| 99 __ mov(FieldOperand(ecx, offset), eax); |
| 100 // Preserve value from write barrier in case it's needed. |
| 101 __ mov(ebx, eax); |
| 102 __ RecordWrite(ecx, offset, ebx, edi); |
| 103 } |
| 104 |
| 105 |
| 106 void FastCodeGenerator::Generate(FunctionLiteral* fun, CompilationInfo* info) { |
| 107 ASSERT(function_ == NULL); |
| 108 ASSERT(info_ == NULL); |
| 109 function_ = fun; |
| 110 info_ = info; |
| 111 |
| 112 // Save the caller's frame pointer and set up our own. |
| 113 Comment prologue_cmnt(masm(), ";; Prologue"); |
| 114 __ push(ebp); |
| 115 __ mov(ebp, esp); |
| 116 __ push(esi); // Context. |
| 117 __ push(edi); // Closure. |
| 118 // Note that we keep a live register reference to esi (context) at this |
| 119 // point. |
| 120 |
| 121 // Receiver (this) is allocated to edx if there are this properties. |
| 122 if (has_this_properties()) EmitReceiverMapCheck(); |
| 123 |
| 124 VisitStatements(fun->body()); |
| 125 |
| 126 Comment return_cmnt(masm(), ";; Return(<undefined>)"); |
| 127 __ mov(eax, Factory::undefined_value()); |
| 128 |
| 129 Comment epilogue_cmnt(masm(), ";; Epilogue"); |
| 130 __ mov(esp, ebp); |
| 131 __ pop(ebp); |
| 132 __ ret((fun->scope()->num_parameters() + 1) * kPointerSize); |
| 133 |
| 134 __ bind(&bailout_); |
| 135 } |
| 136 |
| 137 |
| 138 #undef __ |
| 139 |
| 140 |
| 141 } } // namespace v8::internal |
OLD | NEW |