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 25 matching lines...) Expand all Loading... | |
36 #include "runtime.h" | 36 #include "runtime.h" |
37 #include "top.h" | 37 #include "top.h" |
38 #include "compilation-cache.h" | 38 #include "compilation-cache.h" |
39 #include "string-stream.h" | 39 #include "string-stream.h" |
40 #include "parser.h" | 40 #include "parser.h" |
41 #include "regexp-macro-assembler.h" | 41 #include "regexp-macro-assembler.h" |
42 #include "regexp-macro-assembler-tracer.h" | 42 #include "regexp-macro-assembler-tracer.h" |
43 #include "regexp-macro-assembler-irregexp.h" | 43 #include "regexp-macro-assembler-irregexp.h" |
44 #include "regexp-stack.h" | 44 #include "regexp-stack.h" |
45 | 45 |
46 #ifdef V8_NATIVE_REGEXP | 46 #ifndef V8_INTERPRETED_REGEXP |
47 #if V8_TARGET_ARCH_IA32 | 47 #if V8_TARGET_ARCH_IA32 |
48 #include "ia32/regexp-macro-assembler-ia32.h" | 48 #include "ia32/regexp-macro-assembler-ia32.h" |
49 #elif V8_TARGET_ARCH_X64 | 49 #elif V8_TARGET_ARCH_X64 |
50 #include "x64/regexp-macro-assembler-x64.h" | 50 #include "x64/regexp-macro-assembler-x64.h" |
51 #elif V8_TARGET_ARCH_ARM | 51 #elif V8_TARGET_ARCH_ARM |
52 #include "arm/regexp-macro-assembler-arm.h" | 52 #include "arm/regexp-macro-assembler-arm.h" |
53 #else | 53 #else |
54 #error Unsupported target architecture. | 54 #error Unsupported target architecture. |
55 #endif | 55 #endif |
56 #endif | 56 #endif |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
228 // Irregexp implementation. | 228 // Irregexp implementation. |
229 | 229 |
230 // Ensures that the regexp object contains a compiled version of the | 230 // Ensures that the regexp object contains a compiled version of the |
231 // source for either ASCII or non-ASCII strings. | 231 // source for either ASCII or non-ASCII strings. |
232 // If the compiled version doesn't already exist, it is compiled | 232 // If the compiled version doesn't already exist, it is compiled |
233 // from the source pattern. | 233 // from the source pattern. |
234 // If compilation fails, an exception is thrown and this function | 234 // If compilation fails, an exception is thrown and this function |
235 // returns false. | 235 // returns false. |
236 bool RegExpImpl::EnsureCompiledIrregexp(Handle<JSRegExp> re, bool is_ascii) { | 236 bool RegExpImpl::EnsureCompiledIrregexp(Handle<JSRegExp> re, bool is_ascii) { |
237 Object* compiled_code = re->DataAt(JSRegExp::code_index(is_ascii)); | 237 Object* compiled_code = re->DataAt(JSRegExp::code_index(is_ascii)); |
238 #ifdef V8_NATIVE_REGEXP | 238 #ifdef V8_INTERPRETED_REGEXP |
239 if (compiled_code->IsByteArray()) return true; | |
240 #else // V8_INTERPRETED_REGEXP (RegExp native code) | |
239 if (compiled_code->IsCode()) return true; | 241 if (compiled_code->IsCode()) return true; |
240 #else // ! V8_NATIVE_REGEXP (RegExp interpreter code) | |
241 if (compiled_code->IsByteArray()) return true; | |
242 #endif | 242 #endif |
Søren Thygesen Gjesse
2010/04/19 19:59:12
Add comment here or remove from #else
| |
243 return CompileIrregexp(re, is_ascii); | 243 return CompileIrregexp(re, is_ascii); |
244 } | 244 } |
245 | 245 |
246 | 246 |
247 bool RegExpImpl::CompileIrregexp(Handle<JSRegExp> re, bool is_ascii) { | 247 bool RegExpImpl::CompileIrregexp(Handle<JSRegExp> re, bool is_ascii) { |
248 // Compile the RegExp. | 248 // Compile the RegExp. |
249 CompilationZoneScope zone_scope(DELETE_ON_EXIT); | 249 CompilationZoneScope zone_scope(DELETE_ON_EXIT); |
250 Object* entry = re->DataAt(JSRegExp::code_index(is_ascii)); | 250 Object* entry = re->DataAt(JSRegExp::code_index(is_ascii)); |
251 if (entry->IsJSObject()) { | 251 if (entry->IsJSObject()) { |
252 // If it's a JSObject, a previous compilation failed and threw this object. | 252 // If it's a JSObject, a previous compilation failed and threw this object. |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
351 | 351 |
352 int RegExpImpl::IrregexpPrepare(Handle<JSRegExp> regexp, | 352 int RegExpImpl::IrregexpPrepare(Handle<JSRegExp> regexp, |
353 Handle<String> subject) { | 353 Handle<String> subject) { |
354 if (!subject->IsFlat()) { | 354 if (!subject->IsFlat()) { |
355 FlattenString(subject); | 355 FlattenString(subject); |
356 } | 356 } |
357 bool is_ascii = subject->IsAsciiRepresentation(); | 357 bool is_ascii = subject->IsAsciiRepresentation(); |
358 if (!EnsureCompiledIrregexp(regexp, is_ascii)) { | 358 if (!EnsureCompiledIrregexp(regexp, is_ascii)) { |
359 return -1; | 359 return -1; |
360 } | 360 } |
361 #ifdef V8_NATIVE_REGEXP | 361 #ifdef V8_INTERPRETED_REGEXP |
362 // Byte-code regexp needs space allocated for all its registers. | |
363 return IrregexpNumberOfRegisters(FixedArray::cast(regexp->data())); | |
364 #else // V8_INTERPRETED_REGEXP | |
362 // Native regexp only needs room to output captures. Registers are handled | 365 // Native regexp only needs room to output captures. Registers are handled |
363 // internally. | 366 // internally. |
364 return (IrregexpNumberOfCaptures(FixedArray::cast(regexp->data())) + 1) * 2; | 367 return (IrregexpNumberOfCaptures(FixedArray::cast(regexp->data())) + 1) * 2; |
365 #else // !V8_NATIVE_REGEXP | 368 #endif // V8_INTERPRETED_REGEXP |
366 // Byte-code regexp needs space allocated for all its registers. | |
367 return IrregexpNumberOfRegisters(FixedArray::cast(regexp->data())); | |
368 #endif // V8_NATIVE_REGEXP | |
369 } | 369 } |
370 | 370 |
371 | 371 |
372 RegExpImpl::IrregexpResult RegExpImpl::IrregexpExecOnce(Handle<JSRegExp> regexp, | 372 RegExpImpl::IrregexpResult RegExpImpl::IrregexpExecOnce(Handle<JSRegExp> regexp, |
373 Handle<String> subject, | 373 Handle<String> subject, |
374 int index, | 374 int index, |
375 Vector<int> output) { | 375 Vector<int> output) { |
376 Handle<FixedArray> irregexp(FixedArray::cast(regexp->data())); | 376 Handle<FixedArray> irregexp(FixedArray::cast(regexp->data())); |
377 | 377 |
378 ASSERT(index >= 0); | 378 ASSERT(index >= 0); |
379 ASSERT(index <= subject->length()); | 379 ASSERT(index <= subject->length()); |
380 ASSERT(subject->IsFlat()); | 380 ASSERT(subject->IsFlat()); |
381 | 381 |
382 #ifdef V8_NATIVE_REGEXP | 382 #ifndef V8_INTERPRETED_REGEXP |
383 ASSERT(output.length() >= | 383 ASSERT(output.length() >= |
384 (IrregexpNumberOfCaptures(*irregexp) + 1) * 2); | 384 (IrregexpNumberOfCaptures(*irregexp) + 1) * 2); |
385 do { | 385 do { |
386 bool is_ascii = subject->IsAsciiRepresentation(); | 386 bool is_ascii = subject->IsAsciiRepresentation(); |
387 Handle<Code> code(IrregexpNativeCode(*irregexp, is_ascii)); | 387 Handle<Code> code(IrregexpNativeCode(*irregexp, is_ascii)); |
388 NativeRegExpMacroAssembler::Result res = | 388 NativeRegExpMacroAssembler::Result res = |
389 NativeRegExpMacroAssembler::Match(code, | 389 NativeRegExpMacroAssembler::Match(code, |
390 subject, | 390 subject, |
391 output.start(), | 391 output.start(), |
392 output.length(), | 392 output.length(), |
(...skipping 12 matching lines...) Expand all Loading... | |
405 // If result is RETRY, the string has changed representation, and we | 405 // If result is RETRY, the string has changed representation, and we |
406 // must restart from scratch. | 406 // must restart from scratch. |
407 // In this case, it means we must make sure we are prepared to handle | 407 // In this case, it means we must make sure we are prepared to handle |
408 // the, potentially, differen subject (the string can switch between | 408 // the, potentially, differen subject (the string can switch between |
409 // being internal and external, and even between being ASCII and UC16, | 409 // being internal and external, and even between being ASCII and UC16, |
410 // but the characters are always the same). | 410 // but the characters are always the same). |
411 IrregexpPrepare(regexp, subject); | 411 IrregexpPrepare(regexp, subject); |
412 } while (true); | 412 } while (true); |
413 UNREACHABLE(); | 413 UNREACHABLE(); |
414 return RE_EXCEPTION; | 414 return RE_EXCEPTION; |
415 #else // ndef V8_NATIVE_REGEXP | 415 #else // V8_INTERPRETED_REGEXP |
416 | 416 |
417 ASSERT(output.length() >= IrregexpNumberOfRegisters(*irregexp)); | 417 ASSERT(output.length() >= IrregexpNumberOfRegisters(*irregexp)); |
418 bool is_ascii = subject->IsAsciiRepresentation(); | 418 bool is_ascii = subject->IsAsciiRepresentation(); |
419 // We must have done EnsureCompiledIrregexp, so we can get the number of | 419 // We must have done EnsureCompiledIrregexp, so we can get the number of |
420 // registers. | 420 // registers. |
421 int* register_vector = output.start(); | 421 int* register_vector = output.start(); |
422 int number_of_capture_registers = | 422 int number_of_capture_registers = |
423 (IrregexpNumberOfCaptures(*irregexp) + 1) * 2; | 423 (IrregexpNumberOfCaptures(*irregexp) + 1) * 2; |
424 for (int i = number_of_capture_registers - 1; i >= 0; i--) { | 424 for (int i = number_of_capture_registers - 1; i >= 0; i--) { |
425 register_vector[i] = -1; | 425 register_vector[i] = -1; |
426 } | 426 } |
427 Handle<ByteArray> byte_codes(IrregexpByteCode(*irregexp, is_ascii)); | 427 Handle<ByteArray> byte_codes(IrregexpByteCode(*irregexp, is_ascii)); |
428 | 428 |
429 if (IrregexpInterpreter::Match(byte_codes, | 429 if (IrregexpInterpreter::Match(byte_codes, |
430 subject, | 430 subject, |
431 register_vector, | 431 register_vector, |
432 index)) { | 432 index)) { |
433 return RE_SUCCESS; | 433 return RE_SUCCESS; |
434 } | 434 } |
435 return RE_FAILURE; | 435 return RE_FAILURE; |
436 #endif // ndef V8_NATIVE_REGEXP | 436 #endif // V8_INTERPRETED_REGEXP |
437 } | 437 } |
438 | 438 |
439 | 439 |
440 Handle<Object> RegExpImpl::IrregexpExec(Handle<JSRegExp> jsregexp, | 440 Handle<Object> RegExpImpl::IrregexpExec(Handle<JSRegExp> jsregexp, |
441 Handle<String> subject, | 441 Handle<String> subject, |
442 int previous_index, | 442 int previous_index, |
443 Handle<JSArray> last_match_info) { | 443 Handle<JSArray> last_match_info) { |
444 ASSERT_EQ(jsregexp->TypeTag(), JSRegExp::IRREGEXP); | 444 ASSERT_EQ(jsregexp->TypeTag(), JSRegExp::IRREGEXP); |
445 | 445 |
446 // Prepare space for the return values. | 446 // Prepare space for the return values. |
447 #ifndef V8_NATIVE_REGEXP | 447 #ifdef V8_INTERPRETED_REGEXP |
448 #ifdef DEBUG | 448 #ifdef DEBUG |
449 if (FLAG_trace_regexp_bytecodes) { | 449 if (FLAG_trace_regexp_bytecodes) { |
450 String* pattern = jsregexp->Pattern(); | 450 String* pattern = jsregexp->Pattern(); |
451 PrintF("\n\nRegexp match: /%s/\n\n", *(pattern->ToCString())); | 451 PrintF("\n\nRegexp match: /%s/\n\n", *(pattern->ToCString())); |
452 PrintF("\n\nSubject string: '%s'\n\n", *(subject->ToCString())); | 452 PrintF("\n\nSubject string: '%s'\n\n", *(subject->ToCString())); |
453 } | 453 } |
454 #endif | 454 #endif |
455 #endif | 455 #endif |
456 int required_registers = RegExpImpl::IrregexpPrepare(jsregexp, subject); | 456 int required_registers = RegExpImpl::IrregexpPrepare(jsregexp, subject); |
457 if (required_registers < 0) { | 457 if (required_registers < 0) { |
(...skipping 4765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5223 Analysis analysis(ignore_case, is_ascii); | 5223 Analysis analysis(ignore_case, is_ascii); |
5224 analysis.EnsureAnalyzed(node); | 5224 analysis.EnsureAnalyzed(node); |
5225 if (analysis.has_failed()) { | 5225 if (analysis.has_failed()) { |
5226 const char* error_message = analysis.error_message(); | 5226 const char* error_message = analysis.error_message(); |
5227 return CompilationResult(error_message); | 5227 return CompilationResult(error_message); |
5228 } | 5228 } |
5229 | 5229 |
5230 NodeInfo info = *node->info(); | 5230 NodeInfo info = *node->info(); |
5231 | 5231 |
5232 // Create the correct assembler for the architecture. | 5232 // Create the correct assembler for the architecture. |
5233 #ifdef V8_NATIVE_REGEXP | 5233 #ifndef V8_INTERPRETED_REGEXP |
5234 // Native regexp implementation. | 5234 // Native regexp implementation. |
5235 | 5235 |
5236 NativeRegExpMacroAssembler::Mode mode = | 5236 NativeRegExpMacroAssembler::Mode mode = |
5237 is_ascii ? NativeRegExpMacroAssembler::ASCII | 5237 is_ascii ? NativeRegExpMacroAssembler::ASCII |
5238 : NativeRegExpMacroAssembler::UC16; | 5238 : NativeRegExpMacroAssembler::UC16; |
5239 | 5239 |
5240 #if V8_TARGET_ARCH_IA32 | 5240 #if V8_TARGET_ARCH_IA32 |
5241 RegExpMacroAssemblerIA32 macro_assembler(mode, (data->capture_count + 1) * 2); | 5241 RegExpMacroAssemblerIA32 macro_assembler(mode, (data->capture_count + 1) * 2); |
5242 #elif V8_TARGET_ARCH_X64 | 5242 #elif V8_TARGET_ARCH_X64 |
5243 RegExpMacroAssemblerX64 macro_assembler(mode, (data->capture_count + 1) * 2); | 5243 RegExpMacroAssemblerX64 macro_assembler(mode, (data->capture_count + 1) * 2); |
5244 #elif V8_TARGET_ARCH_ARM | 5244 #elif V8_TARGET_ARCH_ARM |
5245 RegExpMacroAssemblerARM macro_assembler(mode, (data->capture_count + 1) * 2); | 5245 RegExpMacroAssemblerARM macro_assembler(mode, (data->capture_count + 1) * 2); |
5246 #endif | 5246 #endif |
5247 | 5247 |
5248 #else // ! V8_NATIVE_REGEXP | 5248 #else // V8_INTERPRETED_REGEXP |
5249 // Interpreted regexp implementation. | 5249 // Interpreted regexp implementation. |
5250 EmbeddedVector<byte, 1024> codes; | 5250 EmbeddedVector<byte, 1024> codes; |
5251 RegExpMacroAssemblerIrregexp macro_assembler(codes); | 5251 RegExpMacroAssemblerIrregexp macro_assembler(codes); |
5252 #endif | 5252 #endif // V8_INTERPRETED_REGEXP |
5253 | 5253 |
5254 return compiler.Assemble(¯o_assembler, | 5254 return compiler.Assemble(¯o_assembler, |
5255 node, | 5255 node, |
5256 data->capture_count, | 5256 data->capture_count, |
5257 pattern); | 5257 pattern); |
5258 } | 5258 } |
5259 | 5259 |
5260 | 5260 |
5261 int OffsetsVector::static_offsets_vector_[ | 5261 int OffsetsVector::static_offsets_vector_[ |
5262 OffsetsVector::kStaticOffsetsVectorSize]; | 5262 OffsetsVector::kStaticOffsetsVectorSize]; |
5263 | 5263 |
5264 }} // namespace v8::internal | 5264 }} // namespace v8::internal |
OLD | NEW |