| OLD | NEW | 
| (Empty) |  | 
 |    1 // Copyright 2009 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 // Generate code for a JS function.  On entry to the function the receiver | 
 |   39 // and arguments have been pushed on the stack left to right.  The actual | 
 |   40 // argument count matches the formal parameter count expected by the | 
 |   41 // function. | 
 |   42 // | 
 |   43 // The live registers are: | 
 |   44 //   o r1: the JS function object being called (ie, ourselves) | 
 |   45 //   o cp: our context | 
 |   46 //   o fp: our caller's frame pointer | 
 |   47 //   o sp: stack pointer | 
 |   48 //   o lr: return address | 
 |   49 // | 
 |   50 // The function builds a JS frame.  Please see JavaScriptFrameConstants in | 
 |   51 // frames-arm.h for its layout. | 
 |   52 void FastCodeGenerator::Generate(FunctionLiteral* fun) { | 
 |   53   function_ = fun; | 
 |   54  | 
 |   55   __ stm(db_w, sp, r1.bit() | cp.bit() | fp.bit() | lr.bit()); | 
 |   56   // Adjust fp to point to caller's fp. | 
 |   57   __ add(fp, sp, Operand(2 * kPointerSize)); | 
 |   58  | 
 |   59   { Comment cmnt(masm_, "[ Allocate locals"); | 
 |   60     int locals_count = fun->scope()->num_stack_slots(); | 
 |   61     if (locals_count > 0) { | 
 |   62       __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); | 
 |   63     } | 
 |   64     if (FLAG_check_stack) { | 
 |   65       __ LoadRoot(r2, Heap::kStackLimitRootIndex); | 
 |   66     } | 
 |   67     for (int i = 0; i < locals_count; i++) { | 
 |   68       __ push(ip); | 
 |   69     } | 
 |   70   } | 
 |   71  | 
 |   72   if (FLAG_check_stack) { | 
 |   73     // Put the lr setup instruction in the delay slot.  The kInstrSize is | 
 |   74     // added to the implicit 8 byte offset that always applies to operations | 
 |   75     // with pc and gives a return address 12 bytes down. | 
 |   76     Comment cmnt(masm_, "[ Stack check"); | 
 |   77     __ add(lr, pc, Operand(Assembler::kInstrSize)); | 
 |   78     __ cmp(sp, Operand(r2)); | 
 |   79     StackCheckStub stub; | 
 |   80     __ mov(pc, | 
 |   81            Operand(reinterpret_cast<intptr_t>(stub.GetCode().location()), | 
 |   82                    RelocInfo::CODE_TARGET), | 
 |   83            LeaveCC, | 
 |   84            lo); | 
 |   85   } | 
 |   86  | 
 |   87   { Comment cmnt(masm_, "[ Body"); | 
 |   88     VisitStatements(fun->body()); | 
 |   89   } | 
 |   90  | 
 |   91   { Comment cmnt(masm_, "[ return <undefined>;"); | 
 |   92     // Emit a 'return undefined' in case control fell off the end of the | 
 |   93     // body. | 
 |   94     __ LoadRoot(r0, Heap::kUndefinedValueRootIndex); | 
 |   95     __ RecordJSReturn(); | 
 |   96     __ mov(sp, fp); | 
 |   97     __ ldm(ia_w, sp, fp.bit() | lr.bit()); | 
 |   98     int num_parameters = function_->scope()->num_parameters(); | 
 |   99     __ add(sp, sp, Operand((num_parameters + 1) * kPointerSize)); | 
 |  100     __ Jump(lr); | 
 |  101   } | 
 |  102 } | 
 |  103  | 
 |  104  | 
 |  105 void FastCodeGenerator::VisitExpressionStatement(ExpressionStatement* stmt) { | 
 |  106   Comment cmnt(masm_, "[ ExpressionStatement"); | 
 |  107   Visit(stmt->expression()); | 
 |  108   __ pop(); | 
 |  109 } | 
 |  110  | 
 |  111  | 
 |  112 void FastCodeGenerator::VisitReturnStatement(ReturnStatement* stmt) { | 
 |  113   Comment cmnt(masm_, "[ ReturnStatement"); | 
 |  114   Visit(stmt->expression()); | 
 |  115   __ pop(r0); | 
 |  116   __ RecordJSReturn(); | 
 |  117   __ mov(sp, fp); | 
 |  118   __ ldm(ia_w, sp, fp.bit() | lr.bit()); | 
 |  119     int num_parameters = function_->scope()->num_parameters(); | 
 |  120   __ add(sp, sp, Operand((num_parameters + 1) * kPointerSize)); | 
 |  121   __ Jump(lr); | 
 |  122 } | 
 |  123  | 
 |  124  | 
 |  125 void FastCodeGenerator::VisitSlot(Slot* expr) { | 
 |  126   Comment cmnt(masm_, "[ Slot"); | 
 |  127   __ ldr(ip, MemOperand(fp, SlotOffset(expr))); | 
 |  128   __ push(ip); | 
 |  129 } | 
 |  130  | 
 |  131  | 
 |  132 void FastCodeGenerator::VisitLiteral(Literal* expr) { | 
 |  133   Comment cmnt(masm_, "[ Literal"); | 
 |  134   __ mov(ip, Operand(expr->handle())); | 
 |  135   __ push(ip); | 
 |  136 } | 
 |  137  | 
 |  138  | 
 |  139 void FastCodeGenerator::VisitAssignment(Assignment* expr) { | 
 |  140   Comment cmnt(masm_, "[ Assignment"); | 
 |  141   ASSERT(expr->op() == Token::ASSIGN || expr->op() == Token::INIT_VAR); | 
 |  142  | 
 |  143   Visit(expr->value()); | 
 |  144  | 
 |  145   Variable* var = expr->target()->AsVariableProxy()->AsVariable(); | 
 |  146   ASSERT(var != NULL && var->slot() != NULL); | 
 |  147   __ ldr(ip, MemOperand(sp)); | 
 |  148   __ str(ip, MemOperand(fp, SlotOffset(var->slot()))); | 
 |  149 } | 
 |  150  | 
 |  151  | 
 |  152 } }  // namespace v8::internal | 
| OLD | NEW |