Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 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 960 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 971 } | 971 } |
| 972 | 972 |
| 973 | 973 |
| 974 void RegExpMacroAssemblerIA32::WriteStackPointerToRegister(int reg) { | 974 void RegExpMacroAssemblerIA32::WriteStackPointerToRegister(int reg) { |
| 975 __ mov(eax, backtrack_stackpointer()); | 975 __ mov(eax, backtrack_stackpointer()); |
| 976 __ sub(eax, Operand(ebp, kStackHighEnd)); | 976 __ sub(eax, Operand(ebp, kStackHighEnd)); |
| 977 __ mov(register_location(reg), eax); | 977 __ mov(register_location(reg), eax); |
| 978 } | 978 } |
| 979 | 979 |
| 980 | 980 |
| 981 | |
| 982 RegExpMacroAssemblerIA32::Result RegExpMacroAssemblerIA32::Match( | |
| 983 Handle<Code> regexp_code, | |
| 984 Handle<String> subject, | |
| 985 int* offsets_vector, | |
| 986 int offsets_vector_length, | |
| 987 int previous_index) { | |
| 988 StringShape shape(*subject); | |
| 989 | |
| 990 // Character offsets into string. | |
| 991 int start_offset = previous_index; | |
| 992 int end_offset = subject->length(shape); | |
| 993 | |
| 994 String* subject_ptr = *subject; | |
|
Erik Corry
2009/03/12 10:13:00
Please add an AssertNoAllocation object here.
Lasse Reichstein
2009/03/13 08:36:51
Rewritten to use handles everywhere.
| |
| 995 if (shape.IsCons()) { | |
| 996 subject_ptr = String::cast(ConsString::cast(subject_ptr)->first()); | |
| 997 } else if (shape.IsSliced()) { | |
| 998 SlicedString* slice = SlicedString::cast(subject_ptr); | |
| 999 start_offset += slice->start(); | |
| 1000 end_offset += slice->start(); | |
| 1001 subject_ptr = String::cast(slice->buffer()); | |
| 1002 } | |
| 1003 | |
| 1004 // String is now either Sequential or External | |
| 1005 StringShape flatshape(subject_ptr); | |
| 1006 bool is_ascii = flatshape.IsAsciiRepresentation(); | |
| 1007 int char_size_shift = is_ascii ? 0 : 1; | |
| 1008 | |
| 1009 RegExpMacroAssemblerIA32::Result res; | |
| 1010 | |
| 1011 if (flatshape.IsExternal()) { | |
| 1012 const byte* address; | |
| 1013 if (is_ascii) { | |
| 1014 ExternalAsciiString* ext = ExternalAsciiString::cast(subject_ptr); | |
| 1015 address = reinterpret_cast<const byte*>(ext->resource()->data()); | |
| 1016 } else { | |
| 1017 ExternalTwoByteString* ext = ExternalTwoByteString::cast(subject_ptr); | |
| 1018 address = reinterpret_cast<const byte*>(ext->resource()->data()); | |
| 1019 } | |
| 1020 res = Execute(*regexp_code, | |
| 1021 const_cast<Address*>(&address), | |
| 1022 start_offset << char_size_shift, | |
| 1023 end_offset << char_size_shift, | |
| 1024 offsets_vector, | |
| 1025 previous_index == 0); | |
| 1026 } else { // Sequential string | |
| 1027 ASSERT(StringShape(subject_ptr).IsSequential()); | |
| 1028 Address char_address = | |
| 1029 is_ascii ? SeqAsciiString::cast(subject_ptr)->GetCharsAddress() | |
| 1030 : SeqTwoByteString::cast(subject_ptr)->GetCharsAddress(); | |
| 1031 int byte_offset = char_address - reinterpret_cast<Address>(subject_ptr); | |
| 1032 Handle<String> flat_subject_handle; | |
| 1033 if (*subject == subject_ptr) { | |
| 1034 flat_subject_handle = subject; | |
| 1035 } else { | |
| 1036 flat_subject_handle = Handle<String>(subject_ptr); | |
| 1037 } | |
| 1038 res = Execute(*regexp_code, | |
| 1039 reinterpret_cast<Address*>(flat_subject_handle.location()), | |
| 1040 byte_offset + (start_offset << char_size_shift), | |
| 1041 byte_offset + (end_offset << char_size_shift), | |
| 1042 offsets_vector, | |
| 1043 previous_index == 0); | |
| 1044 } | |
| 1045 | |
| 1046 if (res == RegExpMacroAssemblerIA32::SUCCESS) { | |
| 1047 // Capture values are relative to start_offset only. | |
| 1048 for (int i = 0; i < offsets_vector_length; i++) { | |
| 1049 if (offsets_vector[i] >= 0) { | |
| 1050 offsets_vector[i] += previous_index; | |
| 1051 } | |
| 1052 } | |
| 1053 } | |
| 1054 | |
| 1055 return res; | |
| 1056 } | |
| 1057 | |
| 1058 | |
| 981 // Private methods: | 1059 // Private methods: |
| 982 | 1060 |
| 983 | 1061 |
| 984 static unibrow::Mapping<unibrow::Ecma262Canonicalize> canonicalize; | 1062 static unibrow::Mapping<unibrow::Ecma262Canonicalize> canonicalize; |
| 985 | 1063 |
| 986 RegExpMacroAssemblerIA32::Result RegExpMacroAssemblerIA32::Execute( | 1064 RegExpMacroAssemblerIA32::Result RegExpMacroAssemblerIA32::Execute( |
| 987 Code* code, | 1065 Code* code, |
| 988 Address* input, | 1066 Address* input, |
| 989 int start_offset, | 1067 int start_offset, |
| 990 int end_offset, | 1068 int end_offset, |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1252 | 1330 |
| 1253 | 1331 |
| 1254 void RegExpMacroAssemblerIA32::LoadConstantBufferAddress(Register reg, | 1332 void RegExpMacroAssemblerIA32::LoadConstantBufferAddress(Register reg, |
| 1255 ArraySlice* buffer) { | 1333 ArraySlice* buffer) { |
| 1256 __ mov(reg, buffer->array()); | 1334 __ mov(reg, buffer->array()); |
| 1257 __ add(Operand(reg), Immediate(buffer->base_offset())); | 1335 __ add(Operand(reg), Immediate(buffer->base_offset())); |
| 1258 } | 1336 } |
| 1259 | 1337 |
| 1260 #undef __ | 1338 #undef __ |
| 1261 }} // namespace v8::internal | 1339 }} // namespace v8::internal |
| OLD | NEW |