OLD | NEW |
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008-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 |
11 // with the distribution. | 11 // with the distribution. |
(...skipping 20 matching lines...) Expand all Loading... |
32 #include "regexp-macro-assembler-irregexp.h" | 32 #include "regexp-macro-assembler-irregexp.h" |
33 #include "regexp-macro-assembler-irregexp-inl.h" | 33 #include "regexp-macro-assembler-irregexp-inl.h" |
34 | 34 |
35 | 35 |
36 namespace v8 { namespace internal { | 36 namespace v8 { namespace internal { |
37 | 37 |
38 | 38 |
39 RegExpMacroAssemblerIrregexp::RegExpMacroAssemblerIrregexp(Vector<byte> buffer) | 39 RegExpMacroAssemblerIrregexp::RegExpMacroAssemblerIrregexp(Vector<byte> buffer) |
40 : buffer_(buffer), | 40 : buffer_(buffer), |
41 pc_(0), | 41 pc_(0), |
42 own_buffer_(false) { | 42 own_buffer_(false), |
| 43 advance_current_end_(kInvalidPC) { |
43 } | 44 } |
44 | 45 |
45 | 46 |
46 RegExpMacroAssemblerIrregexp::~RegExpMacroAssemblerIrregexp() { | 47 RegExpMacroAssemblerIrregexp::~RegExpMacroAssemblerIrregexp() { |
47 if (backtrack_.is_linked()) backtrack_.Unuse(); | 48 if (backtrack_.is_linked()) backtrack_.Unuse(); |
48 } | 49 } |
49 | 50 |
50 | 51 |
51 RegExpMacroAssemblerIrregexp::IrregexpImplementation | 52 RegExpMacroAssemblerIrregexp::IrregexpImplementation |
52 RegExpMacroAssemblerIrregexp::Implementation() { | 53 RegExpMacroAssemblerIrregexp::Implementation() { |
53 return kBytecodeImplementation; | 54 return kBytecodeImplementation; |
54 } | 55 } |
55 | 56 |
56 | 57 |
57 void RegExpMacroAssemblerIrregexp::Bind(Label* l) { | 58 void RegExpMacroAssemblerIrregexp::Bind(Label* l) { |
| 59 advance_current_end_ = kInvalidPC; |
58 ASSERT(!l->is_bound()); | 60 ASSERT(!l->is_bound()); |
59 if (l->is_linked()) { | 61 if (l->is_linked()) { |
60 int pos = l->pos(); | 62 int pos = l->pos(); |
61 while (pos != 0) { | 63 while (pos != 0) { |
62 int fixup = pos; | 64 int fixup = pos; |
63 pos = *reinterpret_cast<int32_t*>(buffer_.start() + fixup); | 65 pos = *reinterpret_cast<int32_t*>(buffer_.start() + fixup); |
64 *reinterpret_cast<uint32_t*>(buffer_.start() + fixup) = pc_; | 66 *reinterpret_cast<uint32_t*>(buffer_.start() + fixup) = pc_; |
65 } | 67 } |
66 } | 68 } |
67 l->bind_to(pc_); | 69 l->bind_to(pc_); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 Emit(BC_PUSH_CP, 0); | 167 Emit(BC_PUSH_CP, 0); |
166 } | 168 } |
167 | 169 |
168 | 170 |
169 void RegExpMacroAssemblerIrregexp::Backtrack() { | 171 void RegExpMacroAssemblerIrregexp::Backtrack() { |
170 Emit(BC_POP_BT, 0); | 172 Emit(BC_POP_BT, 0); |
171 } | 173 } |
172 | 174 |
173 | 175 |
174 void RegExpMacroAssemblerIrregexp::GoTo(Label* l) { | 176 void RegExpMacroAssemblerIrregexp::GoTo(Label* l) { |
175 Emit(BC_GOTO, 0); | 177 if (advance_current_end_ == pc_) { |
176 EmitOrLink(l); | 178 // Combine advance current and goto. |
| 179 pc_ = advance_current_start_; |
| 180 Emit(BC_ADVANCE_CP_AND_GOTO, advance_current_offset_); |
| 181 EmitOrLink(l); |
| 182 advance_current_end_ = kInvalidPC; |
| 183 } else { |
| 184 // Regular goto. |
| 185 Emit(BC_GOTO, 0); |
| 186 EmitOrLink(l); |
| 187 } |
177 } | 188 } |
178 | 189 |
179 | 190 |
180 void RegExpMacroAssemblerIrregexp::PushBacktrack(Label* l) { | 191 void RegExpMacroAssemblerIrregexp::PushBacktrack(Label* l) { |
181 Emit(BC_PUSH_BT, 0); | 192 Emit(BC_PUSH_BT, 0); |
182 EmitOrLink(l); | 193 EmitOrLink(l); |
183 } | 194 } |
184 | 195 |
185 | 196 |
186 void RegExpMacroAssemblerIrregexp::Succeed() { | 197 void RegExpMacroAssemblerIrregexp::Succeed() { |
187 Emit(BC_SUCCEED, 0); | 198 Emit(BC_SUCCEED, 0); |
188 } | 199 } |
189 | 200 |
190 | 201 |
191 void RegExpMacroAssemblerIrregexp::Fail() { | 202 void RegExpMacroAssemblerIrregexp::Fail() { |
192 Emit(BC_FAIL, 0); | 203 Emit(BC_FAIL, 0); |
193 } | 204 } |
194 | 205 |
195 | 206 |
196 void RegExpMacroAssemblerIrregexp::AdvanceCurrentPosition(int by) { | 207 void RegExpMacroAssemblerIrregexp::AdvanceCurrentPosition(int by) { |
197 ASSERT(by >= kMinCPOffset); | 208 ASSERT(by >= kMinCPOffset); |
198 ASSERT(by <= kMaxCPOffset); | 209 ASSERT(by <= kMaxCPOffset); |
| 210 advance_current_start_ = pc_; |
| 211 advance_current_offset_ = by; |
199 Emit(BC_ADVANCE_CP, by); | 212 Emit(BC_ADVANCE_CP, by); |
| 213 advance_current_end_ = pc_; |
200 } | 214 } |
201 | 215 |
202 | 216 |
203 void RegExpMacroAssemblerIrregexp::CheckGreedyLoop( | 217 void RegExpMacroAssemblerIrregexp::CheckGreedyLoop( |
204 Label* on_tos_equals_current_position) { | 218 Label* on_tos_equals_current_position) { |
205 Emit(BC_CHECK_GREEDY, 0); | 219 Emit(BC_CHECK_GREEDY, 0); |
206 EmitOrLink(on_tos_equals_current_position); | 220 EmitOrLink(on_tos_equals_current_position); |
207 } | 221 } |
208 | 222 |
209 | 223 |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 buffer_ = Vector<byte>::New(old_buffer.length() * 2); | 482 buffer_ = Vector<byte>::New(old_buffer.length() * 2); |
469 own_buffer_ = true; | 483 own_buffer_ = true; |
470 memcpy(buffer_.start(), old_buffer.start(), old_buffer.length()); | 484 memcpy(buffer_.start(), old_buffer.start(), old_buffer.length()); |
471 if (old_buffer_was_our_own) { | 485 if (old_buffer_was_our_own) { |
472 old_buffer.Dispose(); | 486 old_buffer.Dispose(); |
473 } | 487 } |
474 } | 488 } |
475 | 489 |
476 | 490 |
477 } } // namespace v8::internal | 491 } } // namespace v8::internal |
OLD | NEW |