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 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 intptr_t total_samples_; | 291 intptr_t total_samples_; |
292 }; | 292 }; |
293 | 293 |
294 | 294 |
295 class RegExpCompiler : public ValueObject { | 295 class RegExpCompiler : public ValueObject { |
296 public: | 296 public: |
297 RegExpCompiler(intptr_t capture_count, bool ignore_case, bool is_one_byte); | 297 RegExpCompiler(intptr_t capture_count, bool ignore_case, bool is_one_byte); |
298 | 298 |
299 intptr_t AllocateRegister() { return next_register_++; } | 299 intptr_t AllocateRegister() { return next_register_++; } |
300 | 300 |
| 301 #if !defined(DART_PRECOMPILED_RUNTIME) |
301 RegExpEngine::CompilationResult Assemble(IRRegExpMacroAssembler* assembler, | 302 RegExpEngine::CompilationResult Assemble(IRRegExpMacroAssembler* assembler, |
302 RegExpNode* start, | 303 RegExpNode* start, |
303 intptr_t capture_count, | 304 intptr_t capture_count, |
304 const String& pattern); | 305 const String& pattern); |
| 306 #endif |
305 | 307 |
306 RegExpEngine::CompilationResult Assemble( | 308 RegExpEngine::CompilationResult Assemble( |
307 BytecodeRegExpMacroAssembler* assembler, | 309 BytecodeRegExpMacroAssembler* assembler, |
308 RegExpNode* start, | 310 RegExpNode* start, |
309 intptr_t capture_count, | 311 intptr_t capture_count, |
310 const String& pattern); | 312 const String& pattern); |
311 | 313 |
312 inline void AddWork(RegExpNode* node) { work_list_->Add(node); } | 314 inline void AddWork(RegExpNode* node) { work_list_->Add(node); } |
313 | 315 |
314 static const intptr_t kImplementationOffset = 0; | 316 static const intptr_t kImplementationOffset = 0; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 recursion_depth_(0), | 382 recursion_depth_(0), |
381 ignore_case_(ignore_case), | 383 ignore_case_(ignore_case), |
382 is_one_byte_(is_one_byte), | 384 is_one_byte_(is_one_byte), |
383 reg_exp_too_big_(false), | 385 reg_exp_too_big_(false), |
384 current_expansion_factor_(1), | 386 current_expansion_factor_(1), |
385 zone_(Thread::Current()->zone()) { | 387 zone_(Thread::Current()->zone()) { |
386 accept_ = new (Z) EndNode(EndNode::ACCEPT, Z); | 388 accept_ = new (Z) EndNode(EndNode::ACCEPT, Z); |
387 } | 389 } |
388 | 390 |
389 | 391 |
| 392 #if !defined(DART_PRECOMPILED_RUNTIME) |
390 RegExpEngine::CompilationResult RegExpCompiler::Assemble( | 393 RegExpEngine::CompilationResult RegExpCompiler::Assemble( |
391 IRRegExpMacroAssembler* macro_assembler, | 394 IRRegExpMacroAssembler* macro_assembler, |
392 RegExpNode* start, | 395 RegExpNode* start, |
393 intptr_t capture_count, | 396 intptr_t capture_count, |
394 const String& pattern) { | 397 const String& pattern) { |
395 macro_assembler->set_slow_safe(false /* use_slow_safe_regexp_compiler */); | 398 macro_assembler->set_slow_safe(false /* use_slow_safe_regexp_compiler */); |
396 macro_assembler_ = macro_assembler; | 399 macro_assembler_ = macro_assembler; |
397 | 400 |
398 ZoneGrowableArray<RegExpNode*> work_list(0); | 401 ZoneGrowableArray<RegExpNode*> work_list(0); |
399 work_list_ = &work_list; | 402 work_list_ = &work_list; |
400 BlockLabel fail; | 403 BlockLabel fail; |
401 macro_assembler_->PushBacktrack(&fail); | 404 macro_assembler_->PushBacktrack(&fail); |
402 Trace new_trace; | 405 Trace new_trace; |
403 start->Emit(this, &new_trace); | 406 start->Emit(this, &new_trace); |
404 macro_assembler_->BindBlock(&fail); | 407 macro_assembler_->BindBlock(&fail); |
405 macro_assembler_->Fail(); | 408 macro_assembler_->Fail(); |
406 while (!work_list.is_empty()) { | 409 while (!work_list.is_empty()) { |
407 work_list.RemoveLast()->Emit(this, &new_trace); | 410 work_list.RemoveLast()->Emit(this, &new_trace); |
408 } | 411 } |
409 if (reg_exp_too_big_) return IrregexpRegExpTooBig(); | 412 if (reg_exp_too_big_) return IrregexpRegExpTooBig(); |
410 | 413 |
411 macro_assembler->GenerateBacktrackBlock(); | 414 macro_assembler->GenerateBacktrackBlock(); |
412 macro_assembler->FinalizeRegistersArray(); | 415 macro_assembler->FinalizeRegistersArray(); |
413 | 416 |
414 return RegExpEngine::CompilationResult( | 417 return RegExpEngine::CompilationResult( |
415 macro_assembler->backtrack_goto(), macro_assembler->graph_entry(), | 418 macro_assembler->backtrack_goto(), macro_assembler->graph_entry(), |
416 macro_assembler->num_blocks(), macro_assembler->num_stack_locals(), | 419 macro_assembler->num_blocks(), macro_assembler->num_stack_locals(), |
417 next_register_); | 420 next_register_); |
418 } | 421 } |
| 422 #endif |
419 | 423 |
420 | 424 |
421 RegExpEngine::CompilationResult RegExpCompiler::Assemble( | 425 RegExpEngine::CompilationResult RegExpCompiler::Assemble( |
422 BytecodeRegExpMacroAssembler* macro_assembler, | 426 BytecodeRegExpMacroAssembler* macro_assembler, |
423 RegExpNode* start, | 427 RegExpNode* start, |
424 intptr_t capture_count, | 428 intptr_t capture_count, |
425 const String& pattern) { | 429 const String& pattern) { |
426 macro_assembler->set_slow_safe(false /* use_slow_safe_regexp_compiler */); | 430 macro_assembler->set_slow_safe(false /* use_slow_safe_regexp_compiler */); |
427 macro_assembler_ = macro_assembler; | 431 macro_assembler_ = macro_assembler; |
428 | 432 |
(...skipping 4381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4810 if (offset >= bm->length()) { | 4814 if (offset >= bm->length()) { |
4811 if (initial_offset == 0) set_bm_info(not_at_start, bm); | 4815 if (initial_offset == 0) set_bm_info(not_at_start, bm); |
4812 return; | 4816 return; |
4813 } | 4817 } |
4814 on_success()->FillInBMInfo(offset, budget - 1, bm, | 4818 on_success()->FillInBMInfo(offset, budget - 1, bm, |
4815 true); // Not at start after a text node. | 4819 true); // Not at start after a text node. |
4816 if (initial_offset == 0) set_bm_info(not_at_start, bm); | 4820 if (initial_offset == 0) set_bm_info(not_at_start, bm); |
4817 } | 4821 } |
4818 | 4822 |
4819 | 4823 |
| 4824 #if !defined(DART_PRECOMPILED_RUNTIME) |
4820 RegExpEngine::CompilationResult RegExpEngine::CompileIR( | 4825 RegExpEngine::CompilationResult RegExpEngine::CompileIR( |
4821 RegExpCompileData* data, | 4826 RegExpCompileData* data, |
4822 const ParsedFunction* parsed_function, | 4827 const ParsedFunction* parsed_function, |
4823 const ZoneGrowableArray<const ICData*>& ic_data_array, | 4828 const ZoneGrowableArray<const ICData*>& ic_data_array, |
4824 intptr_t osr_id) { | 4829 intptr_t osr_id) { |
4825 ASSERT(!FLAG_interpret_irregexp); | 4830 ASSERT(!FLAG_interpret_irregexp); |
4826 Zone* zone = Thread::Current()->zone(); | 4831 Zone* zone = Thread::Current()->zone(); |
4827 | 4832 |
4828 const Function& function = parsed_function->function(); | 4833 const Function& function = parsed_function->function(); |
4829 const intptr_t specialization_cid = function.string_specialization_cid(); | 4834 const intptr_t specialization_cid = function.string_specialization_cid(); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4918 | 4923 |
4919 RegExpEngine::CompilationResult result = | 4924 RegExpEngine::CompilationResult result = |
4920 compiler.Assemble(macro_assembler, node, data->capture_count, pattern); | 4925 compiler.Assemble(macro_assembler, node, data->capture_count, pattern); |
4921 | 4926 |
4922 if (FLAG_trace_irregexp) { | 4927 if (FLAG_trace_irregexp) { |
4923 macro_assembler->PrintBlocks(); | 4928 macro_assembler->PrintBlocks(); |
4924 } | 4929 } |
4925 | 4930 |
4926 return result; | 4931 return result; |
4927 } | 4932 } |
| 4933 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
4928 | 4934 |
4929 | 4935 |
4930 RegExpEngine::CompilationResult RegExpEngine::CompileBytecode( | 4936 RegExpEngine::CompilationResult RegExpEngine::CompileBytecode( |
4931 RegExpCompileData* data, | 4937 RegExpCompileData* data, |
4932 const RegExp& regexp, | 4938 const RegExp& regexp, |
4933 bool is_one_byte, | 4939 bool is_one_byte, |
4934 bool is_sticky, | 4940 bool is_sticky, |
4935 Zone* zone) { | 4941 Zone* zone) { |
4936 ASSERT(FLAG_interpret_irregexp); | 4942 ASSERT(FLAG_interpret_irregexp); |
4937 const String& pattern = String::Handle(zone, regexp.pattern()); | 4943 const String& pattern = String::Handle(zone, regexp.pattern()); |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5111 CreateSpecializedFunction(thread, zone, regexp, cid, /*sticky=*/true, | 5117 CreateSpecializedFunction(thread, zone, regexp, cid, /*sticky=*/true, |
5112 owner); | 5118 owner); |
5113 } | 5119 } |
5114 } | 5120 } |
5115 | 5121 |
5116 return regexp.raw(); | 5122 return regexp.raw(); |
5117 } | 5123 } |
5118 | 5124 |
5119 | 5125 |
5120 } // namespace dart | 5126 } // namespace dart |
OLD | NEW |