| 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 2899 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2910 Label next, fall_through, default_case; | 2910 Label next, fall_through, default_case; |
| 2911 ZoneList<CaseClause*>* cases = node->cases(); | 2911 ZoneList<CaseClause*>* cases = node->cases(); |
| 2912 int length = cases->length(); | 2912 int length = cases->length(); |
| 2913 | 2913 |
| 2914 for (int i = 0; i < length; i++) { | 2914 for (int i = 0; i < length; i++) { |
| 2915 CaseClause* clause = cases->at(i); | 2915 CaseClause* clause = cases->at(i); |
| 2916 | 2916 |
| 2917 Comment cmnt(masm_, "[ case clause"); | 2917 Comment cmnt(masm_, "[ case clause"); |
| 2918 | 2918 |
| 2919 if (clause->is_default()) { | 2919 if (clause->is_default()) { |
| 2920 // Continue matching cases. The program will execute the default case's |
| 2921 // statements if it does not match any of the cases. |
| 2922 __ jmp(&next); |
| 2923 |
| 2920 // Bind the default case label, so we can branch to it when we | 2924 // Bind the default case label, so we can branch to it when we |
| 2921 // have compared against all other cases. | 2925 // have compared against all other cases. |
| 2922 ASSERT(default_case.is_unused()); // at most one default clause | 2926 ASSERT(default_case.is_unused()); // at most one default clause |
| 2923 | 2927 __ bind(&default_case); |
| 2924 // If the default case is the first (but not only) case, we have | |
| 2925 // to jump past it for now. Once we're done with the remaining | |
| 2926 // clauses, we'll branch back here. If it isn't the first case, | |
| 2927 // we jump past it by avoiding to chain it into the next chain. | |
| 2928 if (length > 1) { | |
| 2929 if (i == 0) __ jmp(&next); | |
| 2930 __ bind(&default_case); | |
| 2931 } | |
| 2932 | |
| 2933 } else { | 2928 } else { |
| 2934 __ bind(&next); | 2929 __ bind(&next); |
| 2935 next.Unuse(); | 2930 next.Unuse(); |
| 2936 __ mov(eax, TOS); | 2931 __ mov(eax, TOS); |
| 2937 __ push(eax); // duplicate TOS | 2932 __ push(eax); // duplicate TOS |
| 2938 Load(clause->label()); | 2933 Load(clause->label()); |
| 2939 Comparison(equal, true); | 2934 Comparison(equal, true); |
| 2940 Branch(false, &next); | 2935 Branch(false, &next); |
| 2941 // Entering the case statement -> remove the switch value from the stack | |
| 2942 __ pop(eax); | |
| 2943 } | 2936 } |
| 2944 | 2937 |
| 2938 // Entering the case statement for the first time. Remove the switch value |
| 2939 // from the stack. |
| 2940 __ pop(eax); |
| 2941 |
| 2945 // Generate code for the body. | 2942 // Generate code for the body. |
| 2943 // This is also the target for the fall through from the previous case's |
| 2944 // statements which has to skip over the matching code and the popping of |
| 2945 // the switch value. |
| 2946 __ bind(&fall_through); | 2946 __ bind(&fall_through); |
| 2947 fall_through.Unuse(); | 2947 fall_through.Unuse(); |
| 2948 VisitStatements(clause->statements()); | 2948 VisitStatements(clause->statements()); |
| 2949 __ jmp(&fall_through); | 2949 __ jmp(&fall_through); |
| 2950 } | 2950 } |
| 2951 | 2951 |
| 2952 __ bind(&next); | 2952 __ bind(&next); |
| 2953 // Reached the end of the case statements -> remove the switch value | 2953 // Reached the end of the case statements without matching any of the cases. |
| 2954 // from the stack | 2954 if (default_case.is_bound()) { |
| 2955 __ pop(eax); // Pop(no_reg) | 2955 // A default case exists -> execute its statements. |
| 2956 if (default_case.is_bound()) __ jmp(&default_case); | 2956 __ jmp(&default_case); |
| 2957 } else { |
| 2958 // Remove the switch value from the stack. |
| 2959 __ pop(eax); |
| 2960 } |
| 2957 | 2961 |
| 2958 __ bind(&fall_through); | 2962 __ bind(&fall_through); |
| 2959 __ bind(node->break_target()); | 2963 __ bind(node->break_target()); |
| 2960 } | 2964 } |
| 2961 | 2965 |
| 2962 | 2966 |
| 2963 void Ia32CodeGenerator::VisitLoopStatement(LoopStatement* node) { | 2967 void Ia32CodeGenerator::VisitLoopStatement(LoopStatement* node) { |
| 2964 Comment cmnt(masm_, "[ LoopStatement"); | 2968 Comment cmnt(masm_, "[ LoopStatement"); |
| 2965 if (FLAG_debug_info) RecordStatementPosition(node); | 2969 if (FLAG_debug_info) RecordStatementPosition(node); |
| 2966 node->set_break_stack_height(break_stack_height_); | 2970 node->set_break_stack_height(break_stack_height_); |
| (...skipping 2428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5395 bool is_eval) { | 5399 bool is_eval) { |
| 5396 Handle<Code> code = Ia32CodeGenerator::MakeCode(fun, script, is_eval); | 5400 Handle<Code> code = Ia32CodeGenerator::MakeCode(fun, script, is_eval); |
| 5397 if (!code.is_null()) { | 5401 if (!code.is_null()) { |
| 5398 Counters::total_compiled_code_size.Increment(code->instruction_size()); | 5402 Counters::total_compiled_code_size.Increment(code->instruction_size()); |
| 5399 } | 5403 } |
| 5400 return code; | 5404 return code; |
| 5401 } | 5405 } |
| 5402 | 5406 |
| 5403 | 5407 |
| 5404 } } // namespace v8::internal | 5408 } } // namespace v8::internal |
| OLD | NEW |