| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 // compiler and needs to setup everything or the compiler is used as | 154 // compiler and needs to setup everything or the compiler is used as |
| 155 // the secondary compiler for split compilation and has to handle | 155 // the secondary compiler for split compilation and has to handle |
| 156 // bailouts. | 156 // bailouts. |
| 157 enum Mode { | 157 enum Mode { |
| 158 PRIMARY, | 158 PRIMARY, |
| 159 SECONDARY | 159 SECONDARY |
| 160 }; | 160 }; |
| 161 | 161 |
| 162 // Takes a function literal, generates code for it. This function should only | 162 // Takes a function literal, generates code for it. This function should only |
| 163 // be called by compiler.cc. | 163 // be called by compiler.cc. |
| 164 static Handle<Code> MakeCode(FunctionLiteral* fun, | 164 static Handle<Code> MakeCode(CompilationInfo* info); |
| 165 Handle<Script> script, | |
| 166 bool is_eval, | |
| 167 CompilationInfo* info); | |
| 168 | 165 |
| 169 // Printing of AST, etc. as requested by flags. | 166 // Printing of AST, etc. as requested by flags. |
| 170 static void MakeCodePrologue(FunctionLiteral* fun); | 167 static void MakeCodePrologue(CompilationInfo* info); |
| 171 | 168 |
| 172 // Allocate and install the code. | 169 // Allocate and install the code. |
| 173 static Handle<Code> MakeCodeEpilogue(FunctionLiteral* fun, | 170 static Handle<Code> MakeCodeEpilogue(MacroAssembler* masm, |
| 174 MacroAssembler* masm, | |
| 175 Code::Flags flags, | 171 Code::Flags flags, |
| 176 Handle<Script> script); | 172 CompilationInfo* info); |
| 177 | 173 |
| 178 #ifdef ENABLE_LOGGING_AND_PROFILING | 174 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 179 static bool ShouldGenerateLog(Expression* type); | 175 static bool ShouldGenerateLog(Expression* type); |
| 180 #endif | 176 #endif |
| 181 | 177 |
| 182 static void SetFunctionInfo(Handle<JSFunction> fun, | 178 static void SetFunctionInfo(Handle<JSFunction> fun, |
| 183 FunctionLiteral* lit, | 179 FunctionLiteral* lit, |
| 184 bool is_toplevel, | 180 bool is_toplevel, |
| 185 Handle<Script> script); | 181 Handle<Script> script); |
| 186 | 182 |
| 187 static void RecordPositions(MacroAssembler* masm, int pos); | 183 static void RecordPositions(MacroAssembler* masm, int pos); |
| 188 | 184 |
| 189 // Accessors | 185 // Accessors |
| 190 MacroAssembler* masm() { return masm_; } | 186 MacroAssembler* masm() { return masm_; } |
| 191 VirtualFrame* frame() const { return frame_; } | 187 VirtualFrame* frame() const { return frame_; } |
| 192 Handle<Script> script() { return script_; } | 188 inline Handle<Script> script(); |
| 193 | 189 |
| 194 bool has_valid_frame() const { return frame_ != NULL; } | 190 bool has_valid_frame() const { return frame_ != NULL; } |
| 195 | 191 |
| 196 // Set the virtual frame to be new_frame, with non-frame register | 192 // Set the virtual frame to be new_frame, with non-frame register |
| 197 // reference counts given by non_frame_registers. The non-frame | 193 // reference counts given by non_frame_registers. The non-frame |
| 198 // register reference counts of the old frame are returned in | 194 // register reference counts of the old frame are returned in |
| 199 // non_frame_registers. | 195 // non_frame_registers. |
| 200 void SetFrame(VirtualFrame* new_frame, RegisterFile* non_frame_registers); | 196 void SetFrame(VirtualFrame* new_frame, RegisterFile* non_frame_registers); |
| 201 | 197 |
| 202 void DeleteFrame(); | 198 void DeleteFrame(); |
| 203 | 199 |
| 204 RegisterAllocator* allocator() const { return allocator_; } | 200 RegisterAllocator* allocator() const { return allocator_; } |
| 205 | 201 |
| 206 CodeGenState* state() { return state_; } | 202 CodeGenState* state() { return state_; } |
| 207 void set_state(CodeGenState* state) { state_ = state; } | 203 void set_state(CodeGenState* state) { state_ = state; } |
| 208 | 204 |
| 209 void AddDeferred(DeferredCode* code) { deferred_.Add(code); } | 205 void AddDeferred(DeferredCode* code) { deferred_.Add(code); } |
| 210 | 206 |
| 211 static const int kUnknownIntValue = -1; | 207 static const int kUnknownIntValue = -1; |
| 212 | 208 |
| 213 private: | 209 private: |
| 214 // Construction/Destruction | 210 // Construction/Destruction |
| 215 CodeGenerator(MacroAssembler* masm, Handle<Script> script, bool is_eval); | 211 CodeGenerator(MacroAssembler* masm); |
| 216 | 212 |
| 217 // Accessors | 213 // Accessors |
| 218 Scope* scope() const { return scope_; } | 214 inline bool is_eval(); |
| 215 Scope* scope(); |
| 219 | 216 |
| 220 // Generating deferred code. | 217 // Generating deferred code. |
| 221 void ProcessDeferred(); | 218 void ProcessDeferred(); |
| 222 | 219 |
| 223 bool is_eval() { return is_eval_; } | |
| 224 | |
| 225 // State | 220 // State |
| 226 bool has_cc() const { return cc_reg_ != al; } | 221 bool has_cc() const { return cc_reg_ != al; } |
| 227 JumpTarget* true_target() const { return state_->true_target(); } | 222 JumpTarget* true_target() const { return state_->true_target(); } |
| 228 JumpTarget* false_target() const { return state_->false_target(); } | 223 JumpTarget* false_target() const { return state_->false_target(); } |
| 229 | 224 |
| 230 // We don't track loop nesting level on ARM yet. | 225 // We don't track loop nesting level on ARM yet. |
| 231 int loop_nesting() const { return 0; } | 226 int loop_nesting() const { return 0; } |
| 232 | 227 |
| 233 // Node visitors. | 228 // Node visitors. |
| 234 void VisitStatements(ZoneList<Statement*>* statements); | 229 void VisitStatements(ZoneList<Statement*>* statements); |
| 235 | 230 |
| 236 #define DEF_VISIT(type) \ | 231 #define DEF_VISIT(type) \ |
| 237 void Visit##type(type* node); | 232 void Visit##type(type* node); |
| 238 AST_NODE_LIST(DEF_VISIT) | 233 AST_NODE_LIST(DEF_VISIT) |
| 239 #undef DEF_VISIT | 234 #undef DEF_VISIT |
| 240 | 235 |
| 241 // Visit a statement and then spill the virtual frame if control flow can | 236 // Visit a statement and then spill the virtual frame if control flow can |
| 242 // reach the end of the statement (ie, it does not exit via break, | 237 // reach the end of the statement (ie, it does not exit via break, |
| 243 // continue, return, or throw). This function is used temporarily while | 238 // continue, return, or throw). This function is used temporarily while |
| 244 // the code generator is being transformed. | 239 // the code generator is being transformed. |
| 245 inline void VisitAndSpill(Statement* statement); | 240 inline void VisitAndSpill(Statement* statement); |
| 246 | 241 |
| 247 // Visit a list of statements and then spill the virtual frame if control | 242 // Visit a list of statements and then spill the virtual frame if control |
| 248 // flow can reach the end of the list. | 243 // flow can reach the end of the list. |
| 249 inline void VisitStatementsAndSpill(ZoneList<Statement*>* statements); | 244 inline void VisitStatementsAndSpill(ZoneList<Statement*>* statements); |
| 250 | 245 |
| 251 // Main code generation function | 246 // Main code generation function |
| 252 void Generate(FunctionLiteral* fun, Mode mode, CompilationInfo* info); | 247 void Generate(CompilationInfo* info, Mode mode); |
| 253 | 248 |
| 254 // The following are used by class Reference. | 249 // The following are used by class Reference. |
| 255 void LoadReference(Reference* ref); | 250 void LoadReference(Reference* ref); |
| 256 void UnloadReference(Reference* ref); | 251 void UnloadReference(Reference* ref); |
| 257 | 252 |
| 258 static MemOperand ContextOperand(Register context, int index) { | 253 static MemOperand ContextOperand(Register context, int index) { |
| 259 return MemOperand(context, Context::SlotOffset(index)); | 254 return MemOperand(context, Context::SlotOffset(index)); |
| 260 } | 255 } |
| 261 | 256 |
| 262 MemOperand SlotOperand(Slot* slot, Register tmp); | 257 MemOperand SlotOperand(Slot* slot, Register tmp); |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 void CodeForReturnPosition(FunctionLiteral* fun); | 413 void CodeForReturnPosition(FunctionLiteral* fun); |
| 419 void CodeForStatementPosition(Statement* node); | 414 void CodeForStatementPosition(Statement* node); |
| 420 void CodeForDoWhileConditionPosition(DoWhileStatement* stmt); | 415 void CodeForDoWhileConditionPosition(DoWhileStatement* stmt); |
| 421 void CodeForSourcePosition(int pos); | 416 void CodeForSourcePosition(int pos); |
| 422 | 417 |
| 423 #ifdef DEBUG | 418 #ifdef DEBUG |
| 424 // True if the registers are valid for entry to a block. | 419 // True if the registers are valid for entry to a block. |
| 425 bool HasValidEntryRegisters(); | 420 bool HasValidEntryRegisters(); |
| 426 #endif | 421 #endif |
| 427 | 422 |
| 428 bool is_eval_; // Tells whether code is generated for eval. | |
| 429 | |
| 430 Handle<Script> script_; | |
| 431 List<DeferredCode*> deferred_; | 423 List<DeferredCode*> deferred_; |
| 432 | 424 |
| 433 // Assembler | 425 // Assembler |
| 434 MacroAssembler* masm_; // to generate code | 426 MacroAssembler* masm_; // to generate code |
| 435 | 427 |
| 428 CompilationInfo* info_; |
| 429 |
| 436 // Code generation state | 430 // Code generation state |
| 437 Scope* scope_; | |
| 438 VirtualFrame* frame_; | 431 VirtualFrame* frame_; |
| 439 RegisterAllocator* allocator_; | 432 RegisterAllocator* allocator_; |
| 440 Condition cc_reg_; | 433 Condition cc_reg_; |
| 441 CodeGenState* state_; | 434 CodeGenState* state_; |
| 442 | 435 |
| 443 // Jump targets | 436 // Jump targets |
| 444 BreakTarget function_return_; | 437 BreakTarget function_return_; |
| 445 | 438 |
| 446 // True if the function return is shadowed (ie, jumping to the target | 439 // True if the function return is shadowed (ie, jumping to the target |
| 447 // function_return_ does not jump to the true function return, but rather | 440 // function_return_ does not jump to the true function return, but rather |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 Major MajorKey() { return StringCompare; } | 549 Major MajorKey() { return StringCompare; } |
| 557 int MinorKey() { return 0; } | 550 int MinorKey() { return 0; } |
| 558 | 551 |
| 559 void Generate(MacroAssembler* masm); | 552 void Generate(MacroAssembler* masm); |
| 560 }; | 553 }; |
| 561 | 554 |
| 562 | 555 |
| 563 } } // namespace v8::internal | 556 } } // namespace v8::internal |
| 564 | 557 |
| 565 #endif // V8_ARM_CODEGEN_ARM_H_ | 558 #endif // V8_ARM_CODEGEN_ARM_H_ |
| OLD | NEW |