| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/regexp.h" | 5 #include "vm/regexp.h" |
| 6 | 6 |
| 7 #include "vm/dart_entry.h" | 7 #include "vm/dart_entry.h" |
| 8 #include "vm/regexp_assembler.h" | 8 #include "vm/regexp_assembler.h" |
| 9 #include "vm/regexp_assembler_bytecode.h" | 9 #include "vm/regexp_assembler_bytecode.h" |
| 10 #include "vm/regexp_assembler_ir.h" | 10 #include "vm/regexp_assembler_ir.h" |
| (...skipping 3011 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3022 const TypedData& boolean_skip_table = TypedData::ZoneHandle( | 3022 const TypedData& boolean_skip_table = TypedData::ZoneHandle( |
| 3023 compiler_->zone(), | 3023 compiler_->zone(), |
| 3024 TypedData::New(kTypedDataUint8ArrayCid, kSize, Heap::kOld)); | 3024 TypedData::New(kTypedDataUint8ArrayCid, kSize, Heap::kOld)); |
| 3025 intptr_t skip_distance = | 3025 intptr_t skip_distance = |
| 3026 GetSkipTable(min_lookahead, max_lookahead, boolean_skip_table); | 3026 GetSkipTable(min_lookahead, max_lookahead, boolean_skip_table); |
| 3027 ASSERT(skip_distance != 0); | 3027 ASSERT(skip_distance != 0); |
| 3028 | 3028 |
| 3029 BlockLabel cont, again; | 3029 BlockLabel cont, again; |
| 3030 | 3030 |
| 3031 masm->BindBlock(&again); | 3031 masm->BindBlock(&again); |
| 3032 masm->CheckPreemption(/*is_backtrack=*/false); |
| 3032 masm->LoadCurrentCharacter(max_lookahead, &cont, true); | 3033 masm->LoadCurrentCharacter(max_lookahead, &cont, true); |
| 3033 masm->CheckBitInTable(boolean_skip_table, &cont); | 3034 masm->CheckBitInTable(boolean_skip_table, &cont); |
| 3034 masm->AdvanceCurrentPosition(skip_distance); | 3035 masm->AdvanceCurrentPosition(skip_distance); |
| 3035 masm->GoTo(&again); | 3036 masm->GoTo(&again); |
| 3036 masm->BindBlock(&cont); | 3037 masm->BindBlock(&cont); |
| 3037 | 3038 |
| 3038 return; | 3039 return; |
| 3039 } | 3040 } |
| 3040 | 3041 |
| 3041 | 3042 |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3228 // information for each iteration of the loop, which could take up a lot of | 3229 // information for each iteration of the loop, which could take up a lot of |
| 3229 // space. | 3230 // space. |
| 3230 ASSERT(trace->stop_node() == NULL); | 3231 ASSERT(trace->stop_node() == NULL); |
| 3231 macro_assembler->PushCurrentPosition(); | 3232 macro_assembler->PushCurrentPosition(); |
| 3232 BlockLabel greedy_match_failed; | 3233 BlockLabel greedy_match_failed; |
| 3233 Trace greedy_match_trace; | 3234 Trace greedy_match_trace; |
| 3234 if (not_at_start()) greedy_match_trace.set_at_start(false); | 3235 if (not_at_start()) greedy_match_trace.set_at_start(false); |
| 3235 greedy_match_trace.set_backtrack(&greedy_match_failed); | 3236 greedy_match_trace.set_backtrack(&greedy_match_failed); |
| 3236 BlockLabel loop_label; | 3237 BlockLabel loop_label; |
| 3237 macro_assembler->BindBlock(&loop_label); | 3238 macro_assembler->BindBlock(&loop_label); |
| 3239 macro_assembler->CheckPreemption(/*is_backtrack=*/false); |
| 3238 greedy_match_trace.set_stop_node(this); | 3240 greedy_match_trace.set_stop_node(this); |
| 3239 greedy_match_trace.set_loop_label(&loop_label); | 3241 greedy_match_trace.set_loop_label(&loop_label); |
| 3240 (*alternatives_)[0].node()->Emit(compiler, &greedy_match_trace); | 3242 (*alternatives_)[0].node()->Emit(compiler, &greedy_match_trace); |
| 3241 macro_assembler->BindBlock(&greedy_match_failed); | 3243 macro_assembler->BindBlock(&greedy_match_failed); |
| 3242 | 3244 |
| 3243 BlockLabel second_choice; // For use in greedy matches. | 3245 BlockLabel second_choice; // For use in greedy matches. |
| 3244 macro_assembler->BindBlock(&second_choice); | 3246 macro_assembler->BindBlock(&second_choice); |
| 3245 | 3247 |
| 3246 Trace* new_trace = greedy_loop_state->counter_backtrack_trace(); | 3248 Trace* new_trace = greedy_loop_state->counter_backtrack_trace(); |
| 3247 | 3249 |
| (...skipping 1563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4811 } | 4813 } |
| 4812 on_success()->FillInBMInfo(offset, budget - 1, bm, | 4814 on_success()->FillInBMInfo(offset, budget - 1, bm, |
| 4813 true); // Not at start after a text node. | 4815 true); // Not at start after a text node. |
| 4814 if (initial_offset == 0) set_bm_info(not_at_start, bm); | 4816 if (initial_offset == 0) set_bm_info(not_at_start, bm); |
| 4815 } | 4817 } |
| 4816 | 4818 |
| 4817 | 4819 |
| 4818 RegExpEngine::CompilationResult RegExpEngine::CompileIR( | 4820 RegExpEngine::CompilationResult RegExpEngine::CompileIR( |
| 4819 RegExpCompileData* data, | 4821 RegExpCompileData* data, |
| 4820 const ParsedFunction* parsed_function, | 4822 const ParsedFunction* parsed_function, |
| 4821 const ZoneGrowableArray<const ICData*>& ic_data_array) { | 4823 const ZoneGrowableArray<const ICData*>& ic_data_array, |
| 4824 intptr_t osr_id) { |
| 4822 ASSERT(!FLAG_interpret_irregexp); | 4825 ASSERT(!FLAG_interpret_irregexp); |
| 4823 Zone* zone = Thread::Current()->zone(); | 4826 Zone* zone = Thread::Current()->zone(); |
| 4824 | 4827 |
| 4825 const Function& function = parsed_function->function(); | 4828 const Function& function = parsed_function->function(); |
| 4826 const intptr_t specialization_cid = function.string_specialization_cid(); | 4829 const intptr_t specialization_cid = function.string_specialization_cid(); |
| 4827 const intptr_t is_sticky = function.is_sticky_specialization(); | 4830 const intptr_t is_sticky = function.is_sticky_specialization(); |
| 4828 const bool is_one_byte = (specialization_cid == kOneByteStringCid || | 4831 const bool is_one_byte = (specialization_cid == kOneByteStringCid || |
| 4829 specialization_cid == kExternalOneByteStringCid); | 4832 specialization_cid == kExternalOneByteStringCid); |
| 4830 RegExp& regexp = RegExp::Handle(zone, function.regexp()); | 4833 RegExp& regexp = RegExp::Handle(zone, function.regexp()); |
| 4831 const String& pattern = String::Handle(zone, regexp.pattern()); | 4834 const String& pattern = String::Handle(zone, regexp.pattern()); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4887 data->node = node; | 4890 data->node = node; |
| 4888 Analysis analysis(ignore_case, is_one_byte); | 4891 Analysis analysis(ignore_case, is_one_byte); |
| 4889 analysis.EnsureAnalyzed(node); | 4892 analysis.EnsureAnalyzed(node); |
| 4890 if (analysis.has_failed()) { | 4893 if (analysis.has_failed()) { |
| 4891 const char* error_message = analysis.error_message(); | 4894 const char* error_message = analysis.error_message(); |
| 4892 return CompilationResult(error_message); | 4895 return CompilationResult(error_message); |
| 4893 } | 4896 } |
| 4894 | 4897 |
| 4895 // Native regexp implementation. | 4898 // Native regexp implementation. |
| 4896 | 4899 |
| 4897 IRRegExpMacroAssembler* macro_assembler = | 4900 IRRegExpMacroAssembler* macro_assembler = new (zone) |
| 4898 new (zone) IRRegExpMacroAssembler(specialization_cid, data->capture_count, | 4901 IRRegExpMacroAssembler(specialization_cid, data->capture_count, |
| 4899 parsed_function, ic_data_array, zone); | 4902 parsed_function, ic_data_array, osr_id, zone); |
| 4900 | 4903 |
| 4901 // Inserted here, instead of in Assembler, because it depends on information | 4904 // Inserted here, instead of in Assembler, because it depends on information |
| 4902 // in the AST that isn't replicated in the Node structure. | 4905 // in the AST that isn't replicated in the Node structure. |
| 4903 static const intptr_t kMaxBacksearchLimit = 1024; | 4906 static const intptr_t kMaxBacksearchLimit = 1024; |
| 4904 if (is_end_anchored && !is_start_anchored && !is_sticky && | 4907 if (is_end_anchored && !is_start_anchored && !is_sticky && |
| 4905 max_length < kMaxBacksearchLimit) { | 4908 max_length < kMaxBacksearchLimit) { |
| 4906 macro_assembler->SetCurrentPositionFromEnd(max_length); | 4909 macro_assembler->SetCurrentPositionFromEnd(max_length); |
| 4907 } | 4910 } |
| 4908 | 4911 |
| 4909 if (is_global) { | 4912 if (is_global) { |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5108 CreateSpecializedFunction(thread, zone, regexp, cid, /*sticky=*/true, | 5111 CreateSpecializedFunction(thread, zone, regexp, cid, /*sticky=*/true, |
| 5109 owner); | 5112 owner); |
| 5110 } | 5113 } |
| 5111 } | 5114 } |
| 5112 | 5115 |
| 5113 return regexp.raw(); | 5116 return regexp.raw(); |
| 5114 } | 5117 } |
| 5115 | 5118 |
| 5116 | 5119 |
| 5117 } // namespace dart | 5120 } // namespace dart |
| OLD | NEW |