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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 int fixup = pos; | 61 int fixup = pos; |
62 pos = Load32(buffer_.start() + fixup); | 62 pos = Load32(buffer_.start() + fixup); |
63 Store32(buffer_.start() + fixup, pc_); | 63 Store32(buffer_.start() + fixup, pc_); |
64 } | 64 } |
65 } | 65 } |
66 l->bind_to(pc_); | 66 l->bind_to(pc_); |
67 } | 67 } |
68 | 68 |
69 | 69 |
70 void RegExpMacroAssemblerIrregexp::EmitOrLink(Label* l) { | 70 void RegExpMacroAssemblerIrregexp::EmitOrLink(Label* l) { |
| 71 if (l == NULL) l = &backtrack_; |
71 if (l->is_bound()) { | 72 if (l->is_bound()) { |
72 Emit32(l->pos()); | 73 Emit32(l->pos()); |
73 } else { | 74 } else { |
74 int pos = 0; | 75 int pos = 0; |
75 if (l->is_linked()) { | 76 if (l->is_linked()) { |
76 pos = l->pos(); | 77 pos = l->pos(); |
77 } | 78 } |
78 l->link_to(pc_); | 79 l->link_to(pc_); |
79 Emit32(pos); | 80 Emit32(pos); |
80 } | 81 } |
81 } | 82 } |
82 | 83 |
83 | 84 |
84 void RegExpMacroAssemblerIrregexp::PopRegister(int register_index) { | 85 void RegExpMacroAssemblerIrregexp::PopRegister(int register_index) { |
85 Emit(BC_POP_REGISTER); | 86 Emit(BC_POP_REGISTER); |
86 Emit(register_index); | 87 Emit(register_index); |
87 } | 88 } |
88 | 89 |
89 | 90 |
90 void RegExpMacroAssemblerIrregexp::PushRegister(int register_index) { | 91 void RegExpMacroAssemblerIrregexp::PushRegister(int register_index) { |
91 ASSERT(register_index >= 0); | 92 ASSERT(register_index >= 0); |
92 Emit(BC_PUSH_REGISTER); | 93 Emit(BC_PUSH_REGISTER); |
93 Emit(register_index); | 94 Emit(register_index); |
94 } | 95 } |
95 | 96 |
96 | 97 |
97 void RegExpMacroAssemblerIrregexp::WriteCurrentPositionToRegister( | 98 void RegExpMacroAssemblerIrregexp::WriteCurrentPositionToRegister( |
98 int register_index) { | 99 int register_index, int cp_offset) { |
99 ASSERT(register_index >= 0); | 100 ASSERT(register_index >= 0); |
100 Emit(BC_SET_REGISTER_TO_CP); | 101 Emit(BC_SET_REGISTER_TO_CP); |
101 Emit(register_index); | 102 Emit(register_index); |
102 Emit32(0); // Current position offset. | 103 Emit32(cp_offset); // Current position offset. |
103 } | 104 } |
104 | 105 |
105 | 106 |
106 void RegExpMacroAssemblerIrregexp::ReadCurrentPositionFromRegister( | 107 void RegExpMacroAssemblerIrregexp::ReadCurrentPositionFromRegister( |
107 int register_index) { | 108 int register_index) { |
108 ASSERT(register_index >= 0); | 109 ASSERT(register_index >= 0); |
109 Emit(BC_SET_CP_TO_REGISTER); | 110 Emit(BC_SET_CP_TO_REGISTER); |
110 Emit(register_index); | 111 Emit(register_index); |
111 } | 112 } |
112 | 113 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 Emit(BC_FAIL); | 181 Emit(BC_FAIL); |
181 } | 182 } |
182 | 183 |
183 | 184 |
184 void RegExpMacroAssemblerIrregexp::AdvanceCurrentPosition(int by) { | 185 void RegExpMacroAssemblerIrregexp::AdvanceCurrentPosition(int by) { |
185 Emit(BC_ADVANCE_CP); | 186 Emit(BC_ADVANCE_CP); |
186 Emit32(by); | 187 Emit32(by); |
187 } | 188 } |
188 | 189 |
189 | 190 |
190 void RegExpMacroAssemblerIrregexp::CheckCurrentPosition( | 191 void RegExpMacroAssemblerIrregexp::CheckGreedyLoop( |
191 int register_index, | 192 Label* on_tos_equals_current_position) { |
192 Label* on_equal) { | 193 Emit(BC_CHECK_GREEDY); |
193 // TODO(erikcorry): Implement. | 194 EmitOrLink(on_tos_equals_current_position); |
194 UNIMPLEMENTED(); | |
195 } | 195 } |
196 | 196 |
197 | 197 |
198 void RegExpMacroAssemblerIrregexp::LoadCurrentCharacter(int cp_offset, | 198 void RegExpMacroAssemblerIrregexp::LoadCurrentCharacter(int cp_offset, |
199 Label* on_failure) { | 199 Label* on_failure) { |
200 Emit(BC_LOAD_CURRENT_CHAR); | 200 Emit(BC_LOAD_CURRENT_CHAR); |
201 Emit32(cp_offset); | 201 Emit32(cp_offset); |
202 EmitOrLink(on_failure); | 202 EmitOrLink(on_failure); |
203 } | 203 } |
204 | 204 |
205 | 205 |
| 206 void RegExpMacroAssemblerIrregexp::LoadCurrentCharacterUnchecked( |
| 207 int cp_offset) { |
| 208 Emit(BC_LOAD_CURRENT_CHAR_UNCHECKED); |
| 209 Emit32(cp_offset); |
| 210 } |
| 211 |
| 212 |
206 void RegExpMacroAssemblerIrregexp::CheckCharacterLT(uc16 limit, | 213 void RegExpMacroAssemblerIrregexp::CheckCharacterLT(uc16 limit, |
207 Label* on_less) { | 214 Label* on_less) { |
208 Emit(BC_CHECK_LT); | 215 Emit(BC_CHECK_LT); |
209 Emit16(limit); | 216 Emit16(limit); |
210 EmitOrLink(on_less); | 217 EmitOrLink(on_less); |
211 } | 218 } |
212 | 219 |
213 | 220 |
214 void RegExpMacroAssemblerIrregexp::CheckCharacterGT(uc16 limit, | 221 void RegExpMacroAssemblerIrregexp::CheckCharacterGT(uc16 limit, |
215 Label* on_greater) { | 222 Label* on_greater) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 uc16 mask, | 263 uc16 mask, |
257 Label* on_not_equal) { | 264 Label* on_not_equal) { |
258 Emit(BC_MINUS_OR_CHECK_NOT_CHAR); | 265 Emit(BC_MINUS_OR_CHECK_NOT_CHAR); |
259 Emit16(c); | 266 Emit16(c); |
260 Emit16(mask); | 267 Emit16(mask); |
261 EmitOrLink(on_not_equal); | 268 EmitOrLink(on_not_equal); |
262 } | 269 } |
263 | 270 |
264 | 271 |
265 void RegExpMacroAssemblerIrregexp::CheckNotBackReference(int start_reg, | 272 void RegExpMacroAssemblerIrregexp::CheckNotBackReference(int start_reg, |
266 Label* on_not_equal) { | 273 Label* on_not_equal) { |
267 Emit(BC_CHECK_NOT_BACK_REF); | 274 Emit(BC_CHECK_NOT_BACK_REF); |
268 Emit(start_reg); | 275 Emit(start_reg); |
269 EmitOrLink(on_not_equal); | 276 EmitOrLink(on_not_equal); |
270 } | 277 } |
271 | 278 |
272 | 279 |
273 void RegExpMacroAssemblerIrregexp::CheckNotBackReferenceIgnoreCase( | 280 void RegExpMacroAssemblerIrregexp::CheckNotBackReferenceIgnoreCase( |
274 int start_reg, | 281 int start_reg, |
275 Label* on_not_equal) { | 282 Label* on_not_equal) { |
276 Emit(BC_CHECK_NOT_BACK_REF_NO_CASE); | 283 Emit(BC_CHECK_NOT_BACK_REF_NO_CASE); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 byte start, | 323 byte start, |
317 Label* byte_map, | 324 Label* byte_map, |
318 const Vector<Label*>& table) { | 325 const Vector<Label*>& table) { |
319 UNIMPLEMENTED(); | 326 UNIMPLEMENTED(); |
320 } | 327 } |
321 | 328 |
322 | 329 |
323 void RegExpMacroAssemblerIrregexp::CheckCharacters( | 330 void RegExpMacroAssemblerIrregexp::CheckCharacters( |
324 Vector<const uc16> str, | 331 Vector<const uc16> str, |
325 int cp_offset, | 332 int cp_offset, |
326 Label* on_failure) { | 333 Label* on_failure, |
| 334 bool check_end_of_string) { |
| 335 // It is vital that this loop is backwards due to the unchecked character |
| 336 // load below. |
327 for (int i = str.length() - 1; i >= 0; i--) { | 337 for (int i = str.length() - 1; i >= 0; i--) { |
328 Emit(BC_LOAD_CURRENT_CHAR); | 338 if (check_end_of_string && i == str.length() - 1) { |
329 Emit32(cp_offset + i); | 339 Emit(BC_LOAD_CURRENT_CHAR); |
330 EmitOrLink(on_failure); | 340 Emit32(cp_offset + i); |
| 341 EmitOrLink(on_failure); |
| 342 } else { |
| 343 Emit(BC_LOAD_CURRENT_CHAR_UNCHECKED); |
| 344 Emit32(cp_offset + i); |
| 345 } |
331 Emit(BC_CHECK_NOT_CHAR); | 346 Emit(BC_CHECK_NOT_CHAR); |
332 Emit16(str[i]); | 347 Emit16(str[i]); |
333 EmitOrLink(on_failure); | 348 EmitOrLink(on_failure); |
334 } | 349 } |
335 } | 350 } |
336 | 351 |
337 | 352 |
338 void RegExpMacroAssemblerIrregexp::IfRegisterLT(int register_index, | 353 void RegExpMacroAssemblerIrregexp::IfRegisterLT(int register_index, |
339 int comparand, | 354 int comparand, |
340 Label* on_less_than) { | 355 Label* on_less_than) { |
341 ASSERT(comparand >= 0 && comparand <= 65535); | 356 ASSERT(comparand >= 0 && comparand <= 65535); |
342 Emit(BC_CHECK_REGISTER_LT); | 357 Emit(BC_CHECK_REGISTER_LT); |
343 Emit(register_index); | 358 Emit(register_index); |
344 Emit16(comparand); | 359 Emit16(comparand); |
345 EmitOrLink(on_less_than); | 360 EmitOrLink(on_less_than); |
346 } | 361 } |
347 | 362 |
348 | 363 |
349 void RegExpMacroAssemblerIrregexp::IfRegisterGE(int register_index, | 364 void RegExpMacroAssemblerIrregexp::IfRegisterGE(int register_index, |
350 int comparand, | 365 int comparand, |
351 Label* on_greater_or_equal) { | 366 Label* on_greater_or_equal) { |
352 ASSERT(comparand >= 0 && comparand <= 65535); | 367 ASSERT(comparand >= 0 && comparand <= 65535); |
353 Emit(BC_CHECK_REGISTER_GE); | 368 Emit(BC_CHECK_REGISTER_GE); |
354 Emit(register_index); | 369 Emit(register_index); |
355 Emit16(comparand); | 370 Emit16(comparand); |
356 EmitOrLink(on_greater_or_equal); | 371 EmitOrLink(on_greater_or_equal); |
357 } | 372 } |
358 | 373 |
359 | 374 |
360 Handle<Object> RegExpMacroAssemblerIrregexp::GetCode() { | 375 Handle<Object> RegExpMacroAssemblerIrregexp::GetCode(Handle<String> source) { |
| 376 Bind(&backtrack_); |
| 377 Emit(BC_POP_BT); |
361 Handle<ByteArray> array = Factory::NewByteArray(length()); | 378 Handle<ByteArray> array = Factory::NewByteArray(length()); |
362 Copy(array->GetDataStartAddress()); | 379 Copy(array->GetDataStartAddress()); |
363 return array; | 380 return array; |
364 } | 381 } |
365 | 382 |
366 | 383 |
367 int RegExpMacroAssemblerIrregexp::length() { | 384 int RegExpMacroAssemblerIrregexp::length() { |
368 return pc_; | 385 return pc_; |
369 } | 386 } |
370 | 387 |
371 | 388 |
372 void RegExpMacroAssemblerIrregexp::Copy(Address a) { | 389 void RegExpMacroAssemblerIrregexp::Copy(Address a) { |
373 memcpy(a, buffer_.start(), length()); | 390 memcpy(a, buffer_.start(), length()); |
374 } | 391 } |
375 | 392 |
376 | 393 |
377 void RegExpMacroAssemblerIrregexp::Expand() { | 394 void RegExpMacroAssemblerIrregexp::Expand() { |
378 bool old_buffer_was_our_own = own_buffer_; | 395 bool old_buffer_was_our_own = own_buffer_; |
379 Vector<byte> old_buffer = buffer_; | 396 Vector<byte> old_buffer = buffer_; |
380 buffer_ = Vector<byte>::New(old_buffer.length() * 2); | 397 buffer_ = Vector<byte>::New(old_buffer.length() * 2); |
381 own_buffer_ = true; | 398 own_buffer_ = true; |
382 memcpy(buffer_.start(), old_buffer.start(), old_buffer.length()); | 399 memcpy(buffer_.start(), old_buffer.start(), old_buffer.length()); |
383 if (old_buffer_was_our_own) { | 400 if (old_buffer_was_our_own) { |
384 old_buffer.Dispose(); | 401 old_buffer.Dispose(); |
385 } | 402 } |
386 } | 403 } |
387 | 404 |
388 | 405 |
389 } } // namespace v8::internal | 406 } } // namespace v8::internal |
OLD | NEW |