OLD | NEW |
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 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 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 | 263 |
264 // Irregexp implementation. | 264 // Irregexp implementation. |
265 | 265 |
266 // Ensures that the regexp object contains a compiled version of the | 266 // Ensures that the regexp object contains a compiled version of the |
267 // source for either ASCII or non-ASCII strings. | 267 // source for either ASCII or non-ASCII strings. |
268 // If the compiled version doesn't already exist, it is compiled | 268 // If the compiled version doesn't already exist, it is compiled |
269 // from the source pattern. | 269 // from the source pattern. |
270 // If compilation fails, an exception is thrown and this function | 270 // If compilation fails, an exception is thrown and this function |
271 // returns false. | 271 // returns false. |
272 bool RegExpImpl::EnsureCompiledIrregexp(Handle<JSRegExp> re, bool is_ascii) { | 272 bool RegExpImpl::EnsureCompiledIrregexp(Handle<JSRegExp> re, bool is_ascii) { |
| 273 Object* compiled_code = re->DataAt(JSRegExp::code_index(is_ascii)); |
273 #ifdef V8_NATIVE_REGEXP | 274 #ifdef V8_NATIVE_REGEXP |
274 if (re->DataAt(JSRegExp::code_index(is_ascii))->IsCode()) return true; | 275 if (compiled_code->IsCode()) return true; |
275 #else // ! V8_NATIVE_REGEXP (RegExp interpreter code) | 276 #else // ! V8_NATIVE_REGEXP (RegExp interpreter code) |
276 if (re->DataAt(JSRegExp::code_index(is_ascii))->IsByteArray()) return true; | 277 if (compiled_code->IsByteArray()) return true; |
277 #endif | 278 #endif |
278 return CompileIrregexp(re, is_ascii); | 279 return CompileIrregexp(re, is_ascii); |
279 } | 280 } |
280 | 281 |
281 | 282 |
282 bool RegExpImpl::CompileIrregexp(Handle<JSRegExp> re, bool is_ascii) { | 283 bool RegExpImpl::CompileIrregexp(Handle<JSRegExp> re, bool is_ascii) { |
283 // Compile the RegExp. | 284 // Compile the RegExp. |
284 CompilationZoneScope zone_scope(DELETE_ON_EXIT); | 285 CompilationZoneScope zone_scope(DELETE_ON_EXIT); |
285 Object* entry = re->DataAt(JSRegExp::code_index(is_ascii)); | 286 Object* entry = re->DataAt(JSRegExp::code_index(is_ascii)); |
286 if (entry->IsJSObject()) { | 287 if (entry->IsJSObject()) { |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 if (!subject->IsFlat()) { | 408 if (!subject->IsFlat()) { |
408 FlattenString(subject); | 409 FlattenString(subject); |
409 } | 410 } |
410 | 411 |
411 last_match_info->EnsureSize(number_of_capture_registers + kLastMatchOverhead); | 412 last_match_info->EnsureSize(number_of_capture_registers + kLastMatchOverhead); |
412 | 413 |
413 Handle<FixedArray> array; | 414 Handle<FixedArray> array; |
414 | 415 |
415 // Dispatch to the correct RegExp implementation. | 416 // Dispatch to the correct RegExp implementation. |
416 Handle<FixedArray> regexp(FixedArray::cast(jsregexp->data())); | 417 Handle<FixedArray> regexp(FixedArray::cast(jsregexp->data())); |
| 418 |
417 #ifdef V8_NATIVE_REGEXP | 419 #ifdef V8_NATIVE_REGEXP |
418 #if V8_TARGET_ARCH_IA32 | 420 #ifdef V8_TARGET_ARCH_ARM |
| 421 UNIMPLEMENTED(); |
| 422 #else // Native regexp supported. |
419 OffsetsVector captures(number_of_capture_registers); | 423 OffsetsVector captures(number_of_capture_registers); |
420 int* captures_vector = captures.vector(); | 424 int* captures_vector = captures.vector(); |
421 RegExpMacroAssemblerIA32::Result res; | 425 NativeRegExpMacroAssembler::Result res; |
422 do { | 426 do { |
423 bool is_ascii = subject->IsAsciiRepresentation(); | 427 bool is_ascii = subject->IsAsciiRepresentation(); |
424 if (!EnsureCompiledIrregexp(jsregexp, is_ascii)) { | 428 if (!EnsureCompiledIrregexp(jsregexp, is_ascii)) { |
425 return Handle<Object>::null(); | 429 return Handle<Object>::null(); |
426 } | 430 } |
427 Handle<Code> code(RegExpImpl::IrregexpNativeCode(*regexp, is_ascii)); | 431 Handle<Code> code(RegExpImpl::IrregexpNativeCode(*regexp, is_ascii)); |
428 res = RegExpMacroAssemblerIA32::Match(code, | 432 res = NativeRegExpMacroAssembler::Match(code, |
429 subject, | 433 subject, |
430 captures_vector, | 434 captures_vector, |
431 captures.length(), | 435 captures.length(), |
432 previous_index); | 436 previous_index); |
433 // If result is RETRY, the string have changed representation, and we | 437 // If result is RETRY, the string have changed representation, and we |
434 // must restart from scratch. | 438 // must restart from scratch. |
435 } while (res == RegExpMacroAssemblerIA32::RETRY); | 439 } while (res == NativeRegExpMacroAssembler::RETRY); |
436 if (res == RegExpMacroAssemblerIA32::EXCEPTION) { | 440 if (res == NativeRegExpMacroAssembler::EXCEPTION) { |
437 ASSERT(Top::has_pending_exception()); | 441 ASSERT(Top::has_pending_exception()); |
438 return Handle<Object>::null(); | 442 return Handle<Object>::null(); |
439 } | 443 } |
440 ASSERT(res == RegExpMacroAssemblerIA32::SUCCESS | 444 ASSERT(res == NativeRegExpMacroAssembler::SUCCESS |
441 || res == RegExpMacroAssemblerIA32::FAILURE); | 445 || res == NativeRegExpMacroAssembler::FAILURE); |
442 | 446 |
443 if (res != RegExpMacroAssemblerIA32::SUCCESS) return Factory::null_value(); | 447 if (res != NativeRegExpMacroAssembler::SUCCESS) return Factory::null_value(); |
444 | 448 |
445 array = Handle<FixedArray>(FixedArray::cast(last_match_info->elements())); | 449 array = Handle<FixedArray>(FixedArray::cast(last_match_info->elements())); |
446 ASSERT(array->length() >= number_of_capture_registers + kLastMatchOverhead); | 450 ASSERT(array->length() >= number_of_capture_registers + kLastMatchOverhead); |
447 // The captures come in (start, end+1) pairs. | 451 // The captures come in (start, end+1) pairs. |
448 for (int i = 0; i < number_of_capture_registers; i += 2) { | 452 for (int i = 0; i < number_of_capture_registers; i += 2) { |
449 SetCapture(*array, i, captures_vector[i]); | 453 SetCapture(*array, i, captures_vector[i]); |
450 SetCapture(*array, i + 1, captures_vector[i + 1]); | 454 SetCapture(*array, i + 1, captures_vector[i + 1]); |
451 } | 455 } |
452 #else // !V8_TARGET_ARCH_IA32 | 456 #endif // Native regexp supported. |
453 UNREACHABLE(); | 457 |
454 #endif // V8_TARGET_ARCH_IA32 | 458 #else // ! V8_NATIVE_REGEXP |
455 #else // !V8_NATIVE_REGEXP | |
456 bool is_ascii = subject->IsAsciiRepresentation(); | 459 bool is_ascii = subject->IsAsciiRepresentation(); |
457 if (!EnsureCompiledIrregexp(jsregexp, is_ascii)) { | 460 if (!EnsureCompiledIrregexp(jsregexp, is_ascii)) { |
458 return Handle<Object>::null(); | 461 return Handle<Object>::null(); |
459 } | 462 } |
460 // Now that we have done EnsureCompiledIrregexp we can get the number of | 463 // Now that we have done EnsureCompiledIrregexp we can get the number of |
461 // registers. | 464 // registers. |
462 int number_of_registers = | 465 int number_of_registers = |
463 IrregexpNumberOfRegisters(FixedArray::cast(jsregexp->data())); | 466 IrregexpNumberOfRegisters(FixedArray::cast(jsregexp->data())); |
464 OffsetsVector registers(number_of_registers); | 467 OffsetsVector registers(number_of_registers); |
465 int* register_vector = registers.vector(); | 468 int* register_vector = registers.vector(); |
(...skipping 3984 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4450 data->node = node; | 4453 data->node = node; |
4451 Analysis analysis(ignore_case); | 4454 Analysis analysis(ignore_case); |
4452 analysis.EnsureAnalyzed(node); | 4455 analysis.EnsureAnalyzed(node); |
4453 if (analysis.has_failed()) { | 4456 if (analysis.has_failed()) { |
4454 const char* error_message = analysis.error_message(); | 4457 const char* error_message = analysis.error_message(); |
4455 return CompilationResult(error_message); | 4458 return CompilationResult(error_message); |
4456 } | 4459 } |
4457 | 4460 |
4458 NodeInfo info = *node->info(); | 4461 NodeInfo info = *node->info(); |
4459 | 4462 |
| 4463 // Create the correct assembler for the architecture. |
4460 #ifdef V8_NATIVE_REGEXP | 4464 #ifdef V8_NATIVE_REGEXP |
4461 #ifdef V8_TARGET_ARCH_ARM | 4465 // Native regexp implementation. |
4462 // ARM native regexp not implemented yet. | 4466 |
4463 UNREACHABLE(); | 4467 NativeRegExpMacroAssembler::Mode mode = |
| 4468 is_ascii ? NativeRegExpMacroAssembler::ASCII |
| 4469 : NativeRegExpMacroAssembler::UC16; |
| 4470 |
| 4471 #ifdef V8_TARGET_ARCH_IA32 |
| 4472 RegExpMacroAssemblerIA32 macro_assembler(mode, |
| 4473 (data->capture_count + 1) * 2); |
4464 #endif | 4474 #endif |
4465 #ifdef V8_TARGET_ARCH_X64 | 4475 #ifdef V8_TARGET_ARCH_X64 |
4466 // X64 native regexp not implemented yet. | 4476 RegExpMacroAssemblerX64 macro_assembler(mode, |
4467 UNREACHABLE(); | 4477 (data->capture_count + 1) * 2); |
4468 #endif | 4478 #endif |
4469 #ifdef V8_TARGET_ARCH_IA32 | 4479 #ifdef V8_TARGET_ARCH_ARM |
4470 RegExpMacroAssemblerIA32::Mode mode; | 4480 UNIMPLEMENTED(); |
4471 if (is_ascii) { | 4481 #endif |
4472 mode = RegExpMacroAssemblerIA32::ASCII; | 4482 |
4473 } else { | 4483 #else // ! V8_NATIVE_REGEXP |
4474 mode = RegExpMacroAssemblerIA32::UC16; | 4484 // Interpreted regexp implementation. |
4475 } | 4485 EmbeddedVector<byte, 1024> codes; |
4476 RegExpMacroAssemblerIA32 macro_assembler(mode, | 4486 RegExpMacroAssemblerIrregexp macro_assembler(codes); |
4477 (data->capture_count + 1) * 2); | 4487 #endif |
| 4488 |
4478 return compiler.Assemble(¯o_assembler, | 4489 return compiler.Assemble(¯o_assembler, |
4479 node, | 4490 node, |
4480 data->capture_count, | 4491 data->capture_count, |
4481 pattern); | 4492 pattern); |
4482 #endif | |
4483 #else // ! V8_NATIVE_REGEXP | |
4484 // Interpreted regexp. | |
4485 EmbeddedVector<byte, 1024> codes; | |
4486 RegExpMacroAssemblerIrregexp macro_assembler(codes); | |
4487 return compiler.Assemble(¯o_assembler, | |
4488 node, | |
4489 data->capture_count, | |
4490 pattern); | |
4491 #endif // V8_NATIVE_REGEXP | |
4492 } | 4493 } |
4493 | 4494 |
4494 }} // namespace v8::internal | 4495 }} // namespace v8::internal |
OLD | NEW |