| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 bool is_property() const { return type_ == NAMED || type_ == KEYED; } | 75 bool is_property() const { return type_ == NAMED || type_ == KEYED; } |
| 76 | 76 |
| 77 // Return the name. Only valid for named property references. | 77 // Return the name. Only valid for named property references. |
| 78 Handle<String> GetName(); | 78 Handle<String> GetName(); |
| 79 | 79 |
| 80 // Generate code to push the value of the reference on top of the | 80 // Generate code to push the value of the reference on top of the |
| 81 // expression stack. The reference is expected to be already on top of | 81 // expression stack. The reference is expected to be already on top of |
| 82 // the expression stack, and it is left in place with its value above it. | 82 // the expression stack, and it is left in place with its value above it. |
| 83 void GetValue(TypeofState typeof_state); | 83 void GetValue(TypeofState typeof_state); |
| 84 | 84 |
| 85 // Generate code to push the value of a reference on top of the expression |
| 86 // stack and then spill the stack frame. This function is used temporarily wh
ile |
| 87 // the code generator is being transformed. |
| 88 inline void GetValueAndSpill(TypeofState typeof_state); |
| 89 |
| 85 // Generate code to store the value on top of the expression stack in the | 90 // Generate code to store the value on top of the expression stack in the |
| 86 // reference. The reference is expected to be immediately below the value | 91 // reference. The reference is expected to be immediately below the value |
| 87 // on the expression stack. The stored value is left in place (with the | 92 // on the expression stack. The stored value is left in place (with the |
| 88 // reference intact below it) to support chained assignments. | 93 // reference intact below it) to support chained assignments. |
| 89 void SetValue(InitState init_state); | 94 void SetValue(InitState init_state); |
| 90 | 95 |
| 91 private: | 96 private: |
| 92 CodeGenerator* cgen_; | 97 CodeGenerator* cgen_; |
| 93 Expression* expression_; | 98 Expression* expression_; |
| 94 Type type_; | 99 Type type_; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 | 184 |
| 180 void DeleteFrame(); | 185 void DeleteFrame(); |
| 181 | 186 |
| 182 RegisterAllocator* allocator() const { return allocator_; } | 187 RegisterAllocator* allocator() const { return allocator_; } |
| 183 | 188 |
| 184 CodeGenState* state() { return state_; } | 189 CodeGenState* state() { return state_; } |
| 185 void set_state(CodeGenState* state) { state_ = state; } | 190 void set_state(CodeGenState* state) { state_ = state; } |
| 186 | 191 |
| 187 void AddDeferred(DeferredCode* code) { deferred_.Add(code); } | 192 void AddDeferred(DeferredCode* code) { deferred_.Add(code); } |
| 188 | 193 |
| 194 bool in_spilled_code() const { return in_spilled_code_; } |
| 195 void set_in_spilled_code(bool flag) { in_spilled_code_ = flag; } |
| 196 |
| 189 private: | 197 private: |
| 190 // Construction/Destruction | 198 // Construction/Destruction |
| 191 CodeGenerator(int buffer_size, Handle<Script> script, bool is_eval); | 199 CodeGenerator(int buffer_size, Handle<Script> script, bool is_eval); |
| 192 virtual ~CodeGenerator() { delete masm_; } | 200 virtual ~CodeGenerator() { delete masm_; } |
| 193 | 201 |
| 194 // Accessors | 202 // Accessors |
| 195 Scope* scope() const { return scope_; } | 203 Scope* scope() const { return scope_; } |
| 196 | 204 |
| 197 void ProcessDeferred(); | 205 void ProcessDeferred(); |
| 198 | 206 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 211 | 219 |
| 212 | 220 |
| 213 // Node visitors. | 221 // Node visitors. |
| 214 void VisitStatements(ZoneList<Statement*>* statements); | 222 void VisitStatements(ZoneList<Statement*>* statements); |
| 215 | 223 |
| 216 #define DEF_VISIT(type) \ | 224 #define DEF_VISIT(type) \ |
| 217 void Visit##type(type* node); | 225 void Visit##type(type* node); |
| 218 NODE_LIST(DEF_VISIT) | 226 NODE_LIST(DEF_VISIT) |
| 219 #undef DEF_VISIT | 227 #undef DEF_VISIT |
| 220 | 228 |
| 229 // Visit a statement and then spill the virtual frame if control flow can |
| 230 // reach the end of the statement (ie, it does not exit via break, |
| 231 // continue, return, or throw). This function is used temporarily while |
| 232 // the code generator is being transformed. |
| 233 void VisitAndSpill(Statement* statement) { |
| 234 ASSERT(in_spilled_code()); |
| 235 set_in_spilled_code(false); |
| 236 Visit(statement); |
| 237 if (frame_ != NULL) { |
| 238 frame_->SpillAll(); |
| 239 } |
| 240 set_in_spilled_code(true); |
| 241 } |
| 242 |
| 243 // Visit a list of statements and then spill the virtual frame if control |
| 244 // flow can reach the end of the list. |
| 245 void VisitStatementsAndSpill(ZoneList<Statement*>* statements) { |
| 246 ASSERT(in_spilled_code()); |
| 247 set_in_spilled_code(false); |
| 248 VisitStatements(statements); |
| 249 if (frame_ != NULL) { |
| 250 frame_->SpillAll(); |
| 251 } |
| 252 set_in_spilled_code(true); |
| 253 } |
| 254 |
| 221 // Main code generation function | 255 // Main code generation function |
| 222 void GenCode(FunctionLiteral* fun); | 256 void GenCode(FunctionLiteral* fun); |
| 223 | 257 |
| 224 // The following are used by class Reference. | 258 // The following are used by class Reference. |
| 225 void LoadReference(Reference* ref); | 259 void LoadReference(Reference* ref); |
| 226 void UnloadReference(Reference* ref); | 260 void UnloadReference(Reference* ref); |
| 227 | 261 |
| 228 Operand ContextOperand(Register context, int index) const { | 262 Operand ContextOperand(Register context, int index) const { |
| 229 return Operand(context, Context::SlotOffset(index)); | 263 return Operand(context, Context::SlotOffset(index)); |
| 230 } | 264 } |
| 231 | 265 |
| 232 Operand SlotOperand(Slot* slot, Register tmp); | 266 Operand SlotOperand(Slot* slot, Register tmp); |
| 233 | 267 |
| 234 | 268 |
| 235 // Expressions | 269 // Expressions |
| 236 Operand GlobalObject() const { | 270 Operand GlobalObject() const { |
| 237 return ContextOperand(esi, Context::GLOBAL_INDEX); | 271 return ContextOperand(esi, Context::GLOBAL_INDEX); |
| 238 } | 272 } |
| 239 | 273 |
| 240 void LoadCondition(Expression* x, | 274 void LoadCondition(Expression* x, |
| 241 TypeofState typeof_state, | 275 TypeofState typeof_state, |
| 242 JumpTarget* true_target, | 276 JumpTarget* true_target, |
| 243 JumpTarget* false_target, | 277 JumpTarget* false_target, |
| 244 bool force_cc); | 278 bool force_cc); |
| 245 void Load(Expression* x, TypeofState typeof_state = NOT_INSIDE_TYPEOF); | 279 void Load(Expression* x, TypeofState typeof_state = NOT_INSIDE_TYPEOF); |
| 246 void LoadGlobal(); | 280 void LoadGlobal(); |
| 247 void LoadGlobalReceiver(Register scratch); | 281 void LoadGlobalReceiver(Register scratch); |
| 248 | 282 |
| 283 // Generate code to push the value of an expression on top of the frame |
| 284 // and then spill the frame fully to memory. This function is used |
| 285 // temporarily while the code generator is being transformed. |
| 286 void LoadAndSpill(Expression* expression, |
| 287 TypeofState typeof_state = NOT_INSIDE_TYPEOF) { |
| 288 ASSERT(in_spilled_code()); |
| 289 set_in_spilled_code(false); |
| 290 Load(expression, typeof_state); |
| 291 frame_->SpillAll(); |
| 292 set_in_spilled_code(true); |
| 293 } |
| 294 |
| 295 // Call LoadCondition and then spill the virtual frame unless control flow |
| 296 // cannot reach the end of the expression (ie, by emitting only |
| 297 // unconditional jumps to the control targets). |
| 298 void LoadConditionAndSpill(Expression* expression, |
| 299 TypeofState typeof_state, |
| 300 JumpTarget* true_target, |
| 301 JumpTarget* false_target, |
| 302 bool force_cc) { |
| 303 ASSERT(in_spilled_code()); |
| 304 set_in_spilled_code(false); |
| 305 LoadCondition(expression, typeof_state, true_target, false_target, |
| 306 force_cc); |
| 307 if (frame_ != NULL) { |
| 308 frame_->SpillAll(); |
| 309 } |
| 310 set_in_spilled_code(true); |
| 311 } |
| 312 |
| 249 // Read a value from a slot and leave it on top of the expression stack. | 313 // Read a value from a slot and leave it on top of the expression stack. |
| 250 void LoadFromSlot(Slot* slot, TypeofState typeof_state); | 314 void LoadFromSlot(Slot* slot, TypeofState typeof_state); |
| 251 | 315 |
| 252 // Store the value on top of the expression stack into a slot, leaving the | 316 // Store the value on top of the expression stack into a slot, leaving the |
| 253 // value in place. | 317 // value in place. |
| 254 void StoreToSlot(Slot* slot, InitState init_state); | 318 void StoreToSlot(Slot* slot, InitState init_state); |
| 255 | 319 |
| 256 // Special code for typeof expressions: Unfortunately, we must | 320 // Special code for typeof expressions: Unfortunately, we must |
| 257 // be careful when loading the expression in 'typeof' | 321 // be careful when loading the expression in 'typeof' |
| 258 // expressions. We are not allowed to throw reference errors for | 322 // expressions. We are not allowed to throw reference errors for |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 | 466 |
| 403 // Jump targets. | 467 // Jump targets. |
| 404 // The target of the return from the function. | 468 // The target of the return from the function. |
| 405 JumpTarget function_return_; | 469 JumpTarget function_return_; |
| 406 | 470 |
| 407 // True if the function return is shadowed (ie, jumping to the target | 471 // True if the function return is shadowed (ie, jumping to the target |
| 408 // function_return_ does not jump to the true function return, but rather | 472 // function_return_ does not jump to the true function return, but rather |
| 409 // to some unlinking code). | 473 // to some unlinking code). |
| 410 bool function_return_is_shadowed_; | 474 bool function_return_is_shadowed_; |
| 411 | 475 |
| 476 // True when we are in code that expects the virtual frame to be fully |
| 477 // spilled. Some virtual frame function are disabled in DEBUG builds when |
| 478 // called from spilled code, because they do not leave the virtual frame |
| 479 // in a spilled state. |
| 480 bool in_spilled_code_; |
| 481 |
| 412 friend class VirtualFrame; | 482 friend class VirtualFrame; |
| 413 friend class JumpTarget; | 483 friend class JumpTarget; |
| 414 friend class Reference; | 484 friend class Reference; |
| 415 | 485 |
| 416 DISALLOW_COPY_AND_ASSIGN(CodeGenerator); | 486 DISALLOW_COPY_AND_ASSIGN(CodeGenerator); |
| 417 }; | 487 }; |
| 418 | 488 |
| 419 | 489 |
| 490 void Reference::GetValueAndSpill(TypeofState typeof_state) { |
| 491 ASSERT(cgen_->in_spilled_code()); |
| 492 cgen_->set_in_spilled_code(false); |
| 493 GetValue(typeof_state); |
| 494 cgen_->frame()->SpillAll(); |
| 495 cgen_->set_in_spilled_code(true); |
| 496 } |
| 497 |
| 498 |
| 420 } } // namespace v8::internal | 499 } } // namespace v8::internal |
| 421 | 500 |
| 422 #endif // V8_CODEGEN_IA32_H_ | 501 #endif // V8_CODEGEN_IA32_H_ |
| OLD | NEW |