Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: runtime/vm/regexp_assembler_ir.cc

Issue 2481873005: clang-format runtime/vm (Closed)
Patch Set: Merge Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/regexp_assembler_ir.h ('k') | runtime/vm/regexp_ast.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/regexp_assembler_ir.h" 5 #include "vm/regexp_assembler_ir.h"
6 6
7 #include "vm/bit_vector.h" 7 #include "vm/bit_vector.h"
8 #include "vm/compiler.h" 8 #include "vm/compiler.h"
9 #include "vm/dart_entry.h" 9 #include "vm/dart_entry.h"
10 #include "vm/flow_graph_builder.h" 10 #include "vm/flow_graph_builder.h"
11 #include "vm/il_printer.h" 11 #include "vm/il_printer.h"
12 #include "vm/object_store.h" 12 #include "vm/object_store.h"
13 #include "vm/regexp.h" 13 #include "vm/regexp.h"
14 #include "vm/resolver.h" 14 #include "vm/resolver.h"
15 #include "vm/runtime_entry.h" 15 #include "vm/runtime_entry.h"
16 #include "vm/stack_frame.h" 16 #include "vm/stack_frame.h"
17 #include "vm/unibrow-inl.h" 17 #include "vm/unibrow-inl.h"
18 #include "vm/unicode.h" 18 #include "vm/unicode.h"
19 19
20 #define Z zone() 20 #define Z zone()
21 21
22 // Debugging output macros. TAG() is called at the head of each interesting 22 // Debugging output macros. TAG() is called at the head of each interesting
23 // function and prints its name during execution if irregexp tracing is enabled. 23 // function and prints its name during execution if irregexp tracing is enabled.
24 #define TAG() if (FLAG_trace_irregexp) { TAG_(); } 24 #define TAG() \
25 #define TAG_() \ 25 if (FLAG_trace_irregexp) { \
26 Print(PushArgument( \ 26 TAG_(); \
27 Bind(new(Z) ConstantInstr(String::ZoneHandle(Z, String::Concat( \ 27 }
28 String::Handle(String::New("TAG: ")), \ 28 #define TAG_() \
29 String::Handle(String::New(__FUNCTION__)), Heap::kOld)))))); 29 Print(PushArgument(Bind(new (Z) ConstantInstr(String::ZoneHandle( \
30 Z, String::Concat(String::Handle(String::New("TAG: ")), \
31 String::Handle(String::New(__FUNCTION__)), \
32 Heap::kOld))))));
30 33
31 #define PRINT(arg) if (FLAG_trace_irregexp) { Print(arg); } 34 #define PRINT(arg) \
35 if (FLAG_trace_irregexp) { \
36 Print(arg); \
37 }
32 38
33 namespace dart { 39 namespace dart {
34 40
35 DEFINE_FLAG(bool, trace_irregexp, false, "Trace irregexps"); 41 DEFINE_FLAG(bool, trace_irregexp, false, "Trace irregexps");
36 42
37 43
38 static const intptr_t kInvalidTryIndex = CatchClauseNode::kInvalidTryIndex; 44 static const intptr_t kInvalidTryIndex = CatchClauseNode::kInvalidTryIndex;
39 static const intptr_t kMinStackSize = 512; 45 static const intptr_t kMinStackSize = 512;
40 46
41 47
42 void PrintUtf16(uint16_t c) { 48 void PrintUtf16(uint16_t c) {
43 const char* format = (0x20 <= c && c <= 0x7F) ? 49 const char* format =
44 "%c" : (c <= 0xff) ? "\\x%02x" : "\\u%04x"; 50 (0x20 <= c && c <= 0x7F) ? "%c" : (c <= 0xff) ? "\\x%02x" : "\\u%04x";
45 OS::Print(format, c); 51 OS::Print(format, c);
46 } 52 }
47 53
48 54
49 /* 55 /*
50 * This assembler uses the following main local variables: 56 * This assembler uses the following main local variables:
51 * - stack_: A pointer to a growable list which we use as an all-purpose stack 57 * - stack_: A pointer to a growable list which we use as an all-purpose stack
52 * storing backtracking offsets, positions & stored register values. 58 * storing backtracking offsets, positions & stored register values.
53 * - current_character_: Stores the currently loaded characters (possibly more 59 * - current_character_: Stores the currently loaded characters (possibly more
54 * than one). 60 * than one).
(...skipping 30 matching lines...) Expand all
85 string_param_(NULL), 91 string_param_(NULL),
86 string_param_length_(NULL), 92 string_param_length_(NULL),
87 start_index_param_(NULL), 93 start_index_param_(NULL),
88 registers_count_(0), 94 registers_count_(0),
89 saved_registers_count_((capture_count + 1) * 2), 95 saved_registers_count_((capture_count + 1) * 2),
90 stack_array_cell_(Array::ZoneHandle(zone, Array::New(1, Heap::kOld))), 96 stack_array_cell_(Array::ZoneHandle(zone, Array::New(1, Heap::kOld))),
91 // The registers array is allocated at a fixed size after assembly. 97 // The registers array is allocated at a fixed size after assembly.
92 registers_array_(TypedData::ZoneHandle(zone, TypedData::null())) { 98 registers_array_(TypedData::ZoneHandle(zone, TypedData::null())) {
93 switch (specialization_cid) { 99 switch (specialization_cid) {
94 case kOneByteStringCid: 100 case kOneByteStringCid:
95 case kExternalOneByteStringCid: mode_ = ASCII; break; 101 case kExternalOneByteStringCid:
102 mode_ = ASCII;
103 break;
96 case kTwoByteStringCid: 104 case kTwoByteStringCid:
97 case kExternalTwoByteStringCid: mode_ = UC16; break; 105 case kExternalTwoByteStringCid:
98 default: UNREACHABLE(); 106 mode_ = UC16;
107 break;
108 default:
109 UNREACHABLE();
99 } 110 }
100 111
101 InitializeLocals(); 112 InitializeLocals();
102 113
103 // Allocate an initial stack backing of the minimum stack size. The stack 114 // Allocate an initial stack backing of the minimum stack size. The stack
104 // backing is indirectly referred to so we can reuse it on subsequent matches 115 // backing is indirectly referred to so we can reuse it on subsequent matches
105 // even in the case where the backing has been enlarged and thus reallocated. 116 // even in the case where the backing has been enlarged and thus reallocated.
106 stack_array_cell_.SetAt(0, TypedData::Handle(zone, 117 stack_array_cell_.SetAt(
107 TypedData::New(kTypedDataInt32ArrayCid, kMinStackSize / 4, Heap::kOld))); 118 0,
119 TypedData::Handle(zone, TypedData::New(kTypedDataInt32ArrayCid,
120 kMinStackSize / 4, Heap::kOld)));
108 121
109 // Create and generate all preset blocks. 122 // Create and generate all preset blocks.
110 entry_block_ = 123 entry_block_ = new (zone) GraphEntryInstr(
111 new(zone) GraphEntryInstr( 124 *parsed_function_,
112 *parsed_function_, 125 new (zone) TargetEntryInstr(block_id_.Alloc(), kInvalidTryIndex),
113 new(zone) TargetEntryInstr(block_id_.Alloc(), kInvalidTryIndex), 126 Compiler::kNoOSRDeoptId);
114 Compiler::kNoOSRDeoptId); 127 start_block_ = new (zone) JoinEntryInstr(block_id_.Alloc(), kInvalidTryIndex);
115 start_block_ =
116 new(zone) JoinEntryInstr(block_id_.Alloc(), kInvalidTryIndex);
117 success_block_ = 128 success_block_ =
118 new(zone) JoinEntryInstr(block_id_.Alloc(), kInvalidTryIndex); 129 new (zone) JoinEntryInstr(block_id_.Alloc(), kInvalidTryIndex);
119 backtrack_block_ = 130 backtrack_block_ =
120 new(zone) JoinEntryInstr(block_id_.Alloc(), kInvalidTryIndex); 131 new (zone) JoinEntryInstr(block_id_.Alloc(), kInvalidTryIndex);
121 exit_block_ = 132 exit_block_ = new (zone) JoinEntryInstr(block_id_.Alloc(), kInvalidTryIndex);
122 new(zone) JoinEntryInstr(block_id_.Alloc(), kInvalidTryIndex);
123 133
124 GenerateEntryBlock(); 134 GenerateEntryBlock();
125 GenerateSuccessBlock(); 135 GenerateSuccessBlock();
126 GenerateExitBlock(); 136 GenerateExitBlock();
127 137
128 blocks_.Add(entry_block_); 138 blocks_.Add(entry_block_);
129 blocks_.Add(entry_block_->normal_entry()); 139 blocks_.Add(entry_block_->normal_entry());
130 blocks_.Add(start_block_); 140 blocks_.Add(start_block_);
131 blocks_.Add(success_block_); 141 blocks_.Add(success_block_);
132 blocks_.Add(backtrack_block_); 142 blocks_.Add(backtrack_block_);
133 blocks_.Add(exit_block_); 143 blocks_.Add(exit_block_);
134 144
135 // Begin emission at the start_block_. 145 // Begin emission at the start_block_.
136 set_current_instruction(start_block_); 146 set_current_instruction(start_block_);
137 } 147 }
138 148
139 149
140 IRRegExpMacroAssembler::~IRRegExpMacroAssembler() { } 150 IRRegExpMacroAssembler::~IRRegExpMacroAssembler() {}
141 151
142 152
143 void IRRegExpMacroAssembler::InitializeLocals() { 153 void IRRegExpMacroAssembler::InitializeLocals() {
144 // All generated functions are expected to have a current-context variable. 154 // All generated functions are expected to have a current-context variable.
145 // This variable is unused in irregexp functions. 155 // This variable is unused in irregexp functions.
146 parsed_function_->current_context_var()->set_index(GetNextLocalIndex()); 156 parsed_function_->current_context_var()->set_index(GetNextLocalIndex());
147 157
148 // Create local variables and parameters. 158 // Create local variables and parameters.
149 stack_ = Local(Symbols::stack()); 159 stack_ = Local(Symbols::stack());
150 stack_pointer_ = Local(Symbols::stack_pointer()); 160 stack_pointer_ = Local(Symbols::stack_pointer());
(...skipping 17 matching lines...) Expand all
168 } 178 }
169 179
170 180
171 void IRRegExpMacroAssembler::GenerateEntryBlock() { 181 void IRRegExpMacroAssembler::GenerateEntryBlock() {
172 set_current_instruction(entry_block_->normal_entry()); 182 set_current_instruction(entry_block_->normal_entry());
173 TAG(); 183 TAG();
174 184
175 // Store string.length. 185 // Store string.length.
176 PushArgumentInstr* string_push = PushLocal(string_param_); 186 PushArgumentInstr* string_push = PushLocal(string_param_);
177 187
178 StoreLocal( 188 StoreLocal(string_param_length_,
179 string_param_length_, 189 Bind(InstanceCall(InstanceCallDescriptor(String::ZoneHandle(
180 Bind(InstanceCall( 190 Field::GetterSymbol(Symbols::Length()))),
181 InstanceCallDescriptor( 191 string_push)));
182 String::ZoneHandle(Field::GetterSymbol(Symbols::Length()))),
183 string_push)));
184 192
185 // Store (start_index - string.length) as the current position (since it's a 193 // Store (start_index - string.length) as the current position (since it's a
186 // negative offset from the end of the string). 194 // negative offset from the end of the string).
187 PushArgumentInstr* start_index_push = PushLocal(start_index_param_); 195 PushArgumentInstr* start_index_push = PushLocal(start_index_param_);
188 PushArgumentInstr* length_push = PushLocal(string_param_length_); 196 PushArgumentInstr* length_push = PushLocal(string_param_length_);
189 197
190 StoreLocal(current_position_, Bind(Sub(start_index_push, length_push))); 198 StoreLocal(current_position_, Bind(Sub(start_index_push, length_push)));
191 199
192 // Generate a local list variable to represent "registers" and 200 // Generate a local list variable to represent "registers" and
193 // initialize capture registers (others remain garbage). 201 // initialize capture registers (others remain garbage).
194 StoreLocal(registers_, Bind(new(Z) ConstantInstr(registers_array_))); 202 StoreLocal(registers_, Bind(new (Z) ConstantInstr(registers_array_)));
195 ClearRegisters(0, saved_registers_count_ - 1); 203 ClearRegisters(0, saved_registers_count_ - 1);
196 204
197 // Generate a local list variable to represent the backtracking stack. 205 // Generate a local list variable to represent the backtracking stack.
198 PushArgumentInstr* stack_cell_push = 206 PushArgumentInstr* stack_cell_push =
199 PushArgument(Bind(new(Z) ConstantInstr(stack_array_cell_))); 207 PushArgument(Bind(new (Z) ConstantInstr(stack_array_cell_)));
200 StoreLocal(stack_, Bind(InstanceCall( 208 StoreLocal(stack_,
201 InstanceCallDescriptor::FromToken(Token::kINDEX), 209 Bind(InstanceCall(InstanceCallDescriptor::FromToken(Token::kINDEX),
202 stack_cell_push, 210 stack_cell_push,
203 PushArgument(Bind(Uint64Constant(0)))))); 211 PushArgument(Bind(Uint64Constant(0))))));
204 StoreLocal(stack_pointer_, Bind(Int64Constant(-1))); 212 StoreLocal(stack_pointer_, Bind(Int64Constant(-1)));
205 213
206 // Jump to the start block. 214 // Jump to the start block.
207 current_instruction_->Goto(start_block_); 215 current_instruction_->Goto(start_block_);
208 } 216 }
209 217
210 218
211 void IRRegExpMacroAssembler::GenerateBacktrackBlock() { 219 void IRRegExpMacroAssembler::GenerateBacktrackBlock() {
212 set_current_instruction(backtrack_block_); 220 set_current_instruction(backtrack_block_);
213 TAG(); 221 TAG();
214 CheckPreemption(); 222 CheckPreemption();
215 223
216 const intptr_t entries_count = entry_block_->indirect_entries().length(); 224 const intptr_t entries_count = entry_block_->indirect_entries().length();
217 225
218 TypedData& offsets = TypedData::ZoneHandle(Z, 226 TypedData& offsets = TypedData::ZoneHandle(
219 TypedData::New(kTypedDataInt32ArrayCid, entries_count, Heap::kOld)); 227 Z, TypedData::New(kTypedDataInt32ArrayCid, entries_count, Heap::kOld));
220 228
221 PushArgumentInstr* block_offsets_push = 229 PushArgumentInstr* block_offsets_push =
222 PushArgument(Bind(new(Z) ConstantInstr(offsets))); 230 PushArgument(Bind(new (Z) ConstantInstr(offsets)));
223 PushArgumentInstr* block_id_push = PushArgument(Bind(PopStack())); 231 PushArgumentInstr* block_id_push = PushArgument(Bind(PopStack()));
224 232
225 Value* offset_value = 233 Value* offset_value =
226 Bind(InstanceCall(InstanceCallDescriptor::FromToken(Token::kINDEX), 234 Bind(InstanceCall(InstanceCallDescriptor::FromToken(Token::kINDEX),
227 block_offsets_push, 235 block_offsets_push, block_id_push));
228 block_id_push));
229 236
230 backtrack_goto_ = new(Z) IndirectGotoInstr(&offsets, offset_value); 237 backtrack_goto_ = new (Z) IndirectGotoInstr(&offsets, offset_value);
231 CloseBlockWith(backtrack_goto_); 238 CloseBlockWith(backtrack_goto_);
232 239
233 // Add an edge from the "indirect" goto to each of the targets. 240 // Add an edge from the "indirect" goto to each of the targets.
234 for (intptr_t j = 0; j < entries_count; j++) { 241 for (intptr_t j = 0; j < entries_count; j++) {
235 backtrack_goto_->AddSuccessor( 242 backtrack_goto_->AddSuccessor(
236 TargetWithJoinGoto(entry_block_->indirect_entries().At(j))); 243 TargetWithJoinGoto(entry_block_->indirect_entries().At(j)));
237 } 244 }
238 } 245 }
239 246
240 247
241 void IRRegExpMacroAssembler::GenerateSuccessBlock() { 248 void IRRegExpMacroAssembler::GenerateSuccessBlock() {
242 set_current_instruction(success_block_); 249 set_current_instruction(success_block_);
243 TAG(); 250 TAG();
244 251
245 Value* type = Bind(new(Z) ConstantInstr( 252 Value* type = Bind(new (Z) ConstantInstr(
246 TypeArguments::ZoneHandle(Z, TypeArguments::null()))); 253 TypeArguments::ZoneHandle(Z, TypeArguments::null())));
247 Value* length = Bind(Uint64Constant(saved_registers_count_)); 254 Value* length = Bind(Uint64Constant(saved_registers_count_));
248 Value* array = Bind(new(Z) CreateArrayInstr( 255 Value* array =
249 TokenPosition::kNoSource, type, length)); 256 Bind(new (Z) CreateArrayInstr(TokenPosition::kNoSource, type, length));
250 StoreLocal(result_, array); 257 StoreLocal(result_, array);
251 258
252 // Store captured offsets in the `matches` parameter. 259 // Store captured offsets in the `matches` parameter.
253 for (intptr_t i = 0; i < saved_registers_count_; i++) { 260 for (intptr_t i = 0; i < saved_registers_count_; i++) {
254 PushArgumentInstr* matches_push = PushLocal(result_); 261 PushArgumentInstr* matches_push = PushLocal(result_);
255 PushArgumentInstr* index_push = PushArgument(Bind(Uint64Constant(i))); 262 PushArgumentInstr* index_push = PushArgument(Bind(Uint64Constant(i)));
256 263
257 // Convert negative offsets from the end of the string to string indices. 264 // Convert negative offsets from the end of the string to string indices.
258 // TODO(zerny): use positive offsets from the get-go. 265 // TODO(zerny): use positive offsets from the get-go.
259 PushArgumentInstr* offset_push = PushArgument(LoadRegister(i)); 266 PushArgumentInstr* offset_push = PushArgument(LoadRegister(i));
260 PushArgumentInstr* len_push = PushLocal(string_param_length_); 267 PushArgumentInstr* len_push = PushLocal(string_param_length_);
261 PushArgumentInstr* value_push = 268 PushArgumentInstr* value_push =
262 PushArgument(Bind(Add(offset_push, len_push))); 269 PushArgument(Bind(Add(offset_push, len_push)));
263 270
264 Do(InstanceCall(InstanceCallDescriptor::FromToken(Token::kASSIGN_INDEX), 271 Do(InstanceCall(InstanceCallDescriptor::FromToken(Token::kASSIGN_INDEX),
265 matches_push, 272 matches_push, index_push, value_push));
266 index_push,
267 value_push));
268 } 273 }
269 274
270 // Print the result if tracing. 275 // Print the result if tracing.
271 PRINT(PushLocal(result_)); 276 PRINT(PushLocal(result_));
272 277
273 // Return true on success. 278 // Return true on success.
274 AppendInstruction(new(Z) ReturnInstr( 279 AppendInstruction(
275 TokenPosition::kNoSource, Bind(LoadLocal(result_)))); 280 new (Z) ReturnInstr(TokenPosition::kNoSource, Bind(LoadLocal(result_))));
276 } 281 }
277 282
278 283
279 void IRRegExpMacroAssembler::GenerateExitBlock() { 284 void IRRegExpMacroAssembler::GenerateExitBlock() {
280 set_current_instruction(exit_block_); 285 set_current_instruction(exit_block_);
281 TAG(); 286 TAG();
282 287
283 // Return false on failure. 288 // Return false on failure.
284 AppendInstruction(new(Z) ReturnInstr( 289 AppendInstruction(
285 TokenPosition::kNoSource, Bind(LoadLocal(result_)))); 290 new (Z) ReturnInstr(TokenPosition::kNoSource, Bind(LoadLocal(result_))));
286 } 291 }
287 292
288 293
289 void IRRegExpMacroAssembler::FinalizeRegistersArray() { 294 void IRRegExpMacroAssembler::FinalizeRegistersArray() {
290 ASSERT(registers_count_ >= saved_registers_count_); 295 ASSERT(registers_count_ >= saved_registers_count_);
291 registers_array_ = 296 registers_array_ =
292 TypedData::New(kTypedDataInt32ArrayCid, registers_count_, Heap::kOld); 297 TypedData::New(kTypedDataInt32ArrayCid, registers_count_, Heap::kOld);
293 } 298 }
294 299
295 300
296 #if defined(TARGET_ARCH_ARM64) || \ 301 #if defined(TARGET_ARCH_ARM64) || defined(TARGET_ARCH_ARM) || \
297 defined(TARGET_ARCH_ARM) || \
298 defined(TARGET_ARCH_MIPS) 302 defined(TARGET_ARCH_MIPS)
299 // Disabling unaligned accesses forces the regexp engine to load characters one 303 // Disabling unaligned accesses forces the regexp engine to load characters one
300 // by one instead of up to 4 at once, along with the associated performance hit. 304 // by one instead of up to 4 at once, along with the associated performance hit.
301 // TODO(zerny): Be less conservative about disabling unaligned accesses. 305 // TODO(zerny): Be less conservative about disabling unaligned accesses.
302 // For instance, ARMv6 supports unaligned accesses. Once it is enabled here, 306 // For instance, ARMv6 supports unaligned accesses. Once it is enabled here,
303 // update LoadCodeUnitsInstr methods for the appropriate architectures. 307 // update LoadCodeUnitsInstr methods for the appropriate architectures.
304 static const bool kEnableUnalignedAccesses = false; 308 static const bool kEnableUnalignedAccesses = false;
305 #else 309 #else
306 static const bool kEnableUnalignedAccesses = true; 310 static const bool kEnableUnalignedAccesses = true;
307 #endif 311 #endif
308 bool IRRegExpMacroAssembler::CanReadUnaligned() { 312 bool IRRegExpMacroAssembler::CanReadUnaligned() {
309 return kEnableUnalignedAccesses && !slow_safe(); 313 return kEnableUnalignedAccesses && !slow_safe();
310 } 314 }
311 315
312 316
313 RawArray* IRRegExpMacroAssembler::Execute( 317 RawArray* IRRegExpMacroAssembler::Execute(const RegExp& regexp,
314 const RegExp& regexp, 318 const String& input,
315 const String& input, 319 const Smi& start_offset,
316 const Smi& start_offset, 320 Zone* zone) {
317 Zone* zone) {
318 const intptr_t cid = input.GetClassId(); 321 const intptr_t cid = input.GetClassId();
319 const Function& fun = Function::Handle(regexp.function(cid)); 322 const Function& fun = Function::Handle(regexp.function(cid));
320 ASSERT(!fun.IsNull()); 323 ASSERT(!fun.IsNull());
321 // Create the argument list. 324 // Create the argument list.
322 const Array& args = 325 const Array& args =
323 Array::Handle(Array::New(RegExpMacroAssembler::kParamCount)); 326 Array::Handle(Array::New(RegExpMacroAssembler::kParamCount));
324 args.SetAt(RegExpMacroAssembler::kParamRegExpIndex, regexp); 327 args.SetAt(RegExpMacroAssembler::kParamRegExpIndex, regexp);
325 args.SetAt(RegExpMacroAssembler::kParamStringIndex, input); 328 args.SetAt(RegExpMacroAssembler::kParamStringIndex, input);
326 args.SetAt(RegExpMacroAssembler::kParamStartOffsetIndex, start_offset); 329 args.SetAt(RegExpMacroAssembler::kParamStartOffsetIndex, start_offset);
327 330
(...skipping 27 matching lines...) Expand all
355 const Smi& length = Smi::Handle(length_raw); 358 const Smi& length = Smi::Handle(length_raw);
356 359
357 // TODO(zerny): Optimize as single instance. V8 has this as an 360 // TODO(zerny): Optimize as single instance. V8 has this as an
358 // isolate member. 361 // isolate member.
359 unibrow::Mapping<unibrow::Ecma262Canonicalize> canonicalize; 362 unibrow::Mapping<unibrow::Ecma262Canonicalize> canonicalize;
360 363
361 for (intptr_t i = 0; i < length.Value(); i++) { 364 for (intptr_t i = 0; i < length.Value(); i++) {
362 int32_t c1 = str.CharAt(lhs_index.Value() + i); 365 int32_t c1 = str.CharAt(lhs_index.Value() + i);
363 int32_t c2 = str.CharAt(rhs_index.Value() + i); 366 int32_t c2 = str.CharAt(rhs_index.Value() + i);
364 if (c1 != c2) { 367 if (c1 != c2) {
365 int32_t s1[1] = { c1 }; 368 int32_t s1[1] = {c1};
366 canonicalize.get(c1, '\0', s1); 369 canonicalize.get(c1, '\0', s1);
367 if (s1[0] != c2) { 370 if (s1[0] != c2) {
368 int32_t s2[1] = { c2 }; 371 int32_t s2[1] = {c2};
369 canonicalize.get(c2, '\0', s2); 372 canonicalize.get(c2, '\0', s2);
370 if (s1[0] != s2[0]) { 373 if (s1[0] != s2[0]) {
371 return Bool::False().raw(); 374 return Bool::False().raw();
372 } 375 }
373 } 376 }
374 } 377 }
375 } 378 }
376 return Bool::True().raw(); 379 return Bool::True().raw();
377 } 380 }
378 381
379 382
380 DEFINE_RAW_LEAF_RUNTIME_ENTRY( 383 DEFINE_RAW_LEAF_RUNTIME_ENTRY(
381 CaseInsensitiveCompareUC16, 4, false /* is_float */, 384 CaseInsensitiveCompareUC16,
385 4,
386 false /* is_float */,
382 reinterpret_cast<RuntimeFunction>(&CaseInsensitiveCompareUC16)); 387 reinterpret_cast<RuntimeFunction>(&CaseInsensitiveCompareUC16));
383 388
384 389
385 LocalVariable* IRRegExpMacroAssembler::Parameter(const String& name, 390 LocalVariable* IRRegExpMacroAssembler::Parameter(const String& name,
386 intptr_t index) const { 391 intptr_t index) const {
387 LocalVariable* local = new(Z) LocalVariable( 392 LocalVariable* local =
388 TokenPosition::kNoSource, 393 new (Z) LocalVariable(TokenPosition::kNoSource, TokenPosition::kNoSource,
389 TokenPosition::kNoSource, 394 name, Object::dynamic_type());
390 name,
391 Object::dynamic_type());
392 395
393 intptr_t param_frame_index = kParamEndSlotFromFp + kParamCount - index; 396 intptr_t param_frame_index = kParamEndSlotFromFp + kParamCount - index;
394 local->set_index(param_frame_index); 397 local->set_index(param_frame_index);
395 398
396 return local; 399 return local;
397 } 400 }
398 401
399 402
400 LocalVariable* IRRegExpMacroAssembler::Local(const String& name) { 403 LocalVariable* IRRegExpMacroAssembler::Local(const String& name) {
401 LocalVariable* local = new(Z) LocalVariable( 404 LocalVariable* local =
402 TokenPosition::kNoSource, 405 new (Z) LocalVariable(TokenPosition::kNoSource, TokenPosition::kNoSource,
403 TokenPosition::kNoSource, 406 name, Object::dynamic_type());
404 name,
405 Object::dynamic_type());
406 local->set_index(GetNextLocalIndex()); 407 local->set_index(GetNextLocalIndex());
407 408
408 return local; 409 return local;
409 } 410 }
410 411
411 412
412 ConstantInstr* IRRegExpMacroAssembler::Int64Constant(int64_t value) const { 413 ConstantInstr* IRRegExpMacroAssembler::Int64Constant(int64_t value) const {
413 return new(Z) ConstantInstr( 414 return new (Z)
414 Integer::ZoneHandle(Z, Integer::New(value, Heap::kOld))); 415 ConstantInstr(Integer::ZoneHandle(Z, Integer::New(value, Heap::kOld)));
415 } 416 }
416 417
417 418
418 ConstantInstr* IRRegExpMacroAssembler::Uint64Constant(uint64_t value) const { 419 ConstantInstr* IRRegExpMacroAssembler::Uint64Constant(uint64_t value) const {
419 return new(Z) ConstantInstr( 420 return new (Z) ConstantInstr(
420 Integer::ZoneHandle(Z, Integer::NewFromUint64(value, Heap::kOld))); 421 Integer::ZoneHandle(Z, Integer::NewFromUint64(value, Heap::kOld)));
421 } 422 }
422 423
423 424
424 ConstantInstr* IRRegExpMacroAssembler::BoolConstant(bool value) const { 425 ConstantInstr* IRRegExpMacroAssembler::BoolConstant(bool value) const {
425 return new(Z) ConstantInstr(value ? Bool::True() : Bool::False()); 426 return new (Z) ConstantInstr(value ? Bool::True() : Bool::False());
426 } 427 }
427 428
428 429
429 ConstantInstr* IRRegExpMacroAssembler::StringConstant(const char* value) const { 430 ConstantInstr* IRRegExpMacroAssembler::StringConstant(const char* value) const {
430 return new(Z) ConstantInstr( 431 return new (Z)
431 String::ZoneHandle(Z, String::New(value, Heap::kOld))); 432 ConstantInstr(String::ZoneHandle(Z, String::New(value, Heap::kOld)));
432 } 433 }
433 434
434 435
435 ConstantInstr* IRRegExpMacroAssembler::WordCharacterMapConstant() const { 436 ConstantInstr* IRRegExpMacroAssembler::WordCharacterMapConstant() const {
436 const Library& lib = Library::Handle(Z, Library::CoreLibrary()); 437 const Library& lib = Library::Handle(Z, Library::CoreLibrary());
437 const Class& regexp_class = Class::Handle(Z, 438 const Class& regexp_class =
438 lib.LookupClassAllowPrivate(Symbols::_RegExp())); 439 Class::Handle(Z, lib.LookupClassAllowPrivate(Symbols::_RegExp()));
439 const Field& word_character_field = Field::ZoneHandle(Z, 440 const Field& word_character_field = Field::ZoneHandle(
441 Z,
440 regexp_class.LookupStaticFieldAllowPrivate(Symbols::_wordCharacterMap())); 442 regexp_class.LookupStaticFieldAllowPrivate(Symbols::_wordCharacterMap()));
441 ASSERT(!word_character_field.IsNull()); 443 ASSERT(!word_character_field.IsNull());
442 444
443 if (word_character_field.IsUninitialized()) { 445 if (word_character_field.IsUninitialized()) {
444 ASSERT(!Compiler::IsBackgroundCompilation()); 446 ASSERT(!Compiler::IsBackgroundCompilation());
445 word_character_field.EvaluateInitializer(); 447 word_character_field.EvaluateInitializer();
446 } 448 }
447 ASSERT(!word_character_field.IsUninitialized()); 449 ASSERT(!word_character_field.IsUninitialized());
448 450
449 return new(Z) ConstantInstr( 451 return new (Z) ConstantInstr(
450 Instance::ZoneHandle(Z, word_character_field.StaticValue())); 452 Instance::ZoneHandle(Z, word_character_field.StaticValue()));
451 } 453 }
452 454
453 455
454 ComparisonInstr* IRRegExpMacroAssembler::Comparison( 456 ComparisonInstr* IRRegExpMacroAssembler::Comparison(ComparisonKind kind,
455 ComparisonKind kind, PushArgumentInstr* lhs, PushArgumentInstr* rhs) { 457 PushArgumentInstr* lhs,
458 PushArgumentInstr* rhs) {
456 Token::Kind strict_comparison = Token::kEQ_STRICT; 459 Token::Kind strict_comparison = Token::kEQ_STRICT;
457 Token::Kind intermediate_operator = Token::kILLEGAL; 460 Token::Kind intermediate_operator = Token::kILLEGAL;
458 switch (kind) { 461 switch (kind) {
459 case kEQ: 462 case kEQ:
460 intermediate_operator = Token::kEQ; 463 intermediate_operator = Token::kEQ;
461 break; 464 break;
462 case kNE: 465 case kNE:
463 intermediate_operator = Token::kEQ; 466 intermediate_operator = Token::kEQ;
464 strict_comparison = Token::kNE_STRICT; 467 strict_comparison = Token::kNE_STRICT;
465 break; 468 break;
466 case kLT: 469 case kLT:
467 intermediate_operator = Token::kLT; 470 intermediate_operator = Token::kLT;
468 break; 471 break;
469 case kGT: 472 case kGT:
470 intermediate_operator = Token::kGT; 473 intermediate_operator = Token::kGT;
471 break; 474 break;
472 case kLTE: 475 case kLTE:
473 intermediate_operator = Token::kLTE; 476 intermediate_operator = Token::kLTE;
474 break; 477 break;
475 case kGTE: 478 case kGTE:
476 intermediate_operator = Token::kGTE; 479 intermediate_operator = Token::kGTE;
477 break; 480 break;
478 default: 481 default:
479 UNREACHABLE(); 482 UNREACHABLE();
480 } 483 }
481 484
482 ASSERT(intermediate_operator != Token::kILLEGAL); 485 ASSERT(intermediate_operator != Token::kILLEGAL);
483 486
484 Value* lhs_value = 487 Value* lhs_value = Bind(InstanceCall(
485 Bind(InstanceCall( 488 InstanceCallDescriptor::FromToken(intermediate_operator), lhs, rhs));
486 InstanceCallDescriptor::FromToken(intermediate_operator),
487 lhs,
488 rhs));
489 Value* rhs_value = Bind(BoolConstant(true)); 489 Value* rhs_value = Bind(BoolConstant(true));
490 490
491 return new(Z) StrictCompareInstr( 491 return new (Z) StrictCompareInstr(TokenPosition::kNoSource, strict_comparison,
492 TokenPosition::kNoSource, strict_comparison, lhs_value, rhs_value, true); 492 lhs_value, rhs_value, true);
493 } 493 }
494 494
495 ComparisonInstr* IRRegExpMacroAssembler::Comparison( 495 ComparisonInstr* IRRegExpMacroAssembler::Comparison(ComparisonKind kind,
496 ComparisonKind kind, Definition* lhs, Definition* rhs) { 496 Definition* lhs,
497 Definition* rhs) {
497 PushArgumentInstr* lhs_push = PushArgument(Bind(lhs)); 498 PushArgumentInstr* lhs_push = PushArgument(Bind(lhs));
498 PushArgumentInstr* rhs_push = PushArgument(Bind(rhs)); 499 PushArgumentInstr* rhs_push = PushArgument(Bind(rhs));
499 return Comparison(kind, lhs_push, rhs_push); 500 return Comparison(kind, lhs_push, rhs_push);
500 } 501 }
501 502
502 503
503 StaticCallInstr* IRRegExpMacroAssembler::StaticCall( 504 StaticCallInstr* IRRegExpMacroAssembler::StaticCall(
504 const Function& function) const { 505 const Function& function) const {
505 ZoneGrowableArray<PushArgumentInstr*>* arguments = 506 ZoneGrowableArray<PushArgumentInstr*>* arguments =
506 new(Z) ZoneGrowableArray<PushArgumentInstr*>(0); 507 new (Z) ZoneGrowableArray<PushArgumentInstr*>(0);
507 return StaticCall(function, arguments); 508 return StaticCall(function, arguments);
508 } 509 }
509 510
510 511
511 StaticCallInstr* IRRegExpMacroAssembler::StaticCall( 512 StaticCallInstr* IRRegExpMacroAssembler::StaticCall(
512 const Function& function, 513 const Function& function,
513 PushArgumentInstr* arg1) const { 514 PushArgumentInstr* arg1) const {
514 ZoneGrowableArray<PushArgumentInstr*>* arguments = 515 ZoneGrowableArray<PushArgumentInstr*>* arguments =
515 new(Z) ZoneGrowableArray<PushArgumentInstr*>(1); 516 new (Z) ZoneGrowableArray<PushArgumentInstr*>(1);
516 arguments->Add(arg1); 517 arguments->Add(arg1);
517 518
518 return StaticCall(function, arguments); 519 return StaticCall(function, arguments);
519 } 520 }
520 521
521 522
522 StaticCallInstr* IRRegExpMacroAssembler::StaticCall( 523 StaticCallInstr* IRRegExpMacroAssembler::StaticCall(
523 const Function& function, 524 const Function& function,
524 PushArgumentInstr* arg1, 525 PushArgumentInstr* arg1,
525 PushArgumentInstr* arg2) const { 526 PushArgumentInstr* arg2) const {
526 ZoneGrowableArray<PushArgumentInstr*>* arguments = 527 ZoneGrowableArray<PushArgumentInstr*>* arguments =
527 new(Z) ZoneGrowableArray<PushArgumentInstr*>(2); 528 new (Z) ZoneGrowableArray<PushArgumentInstr*>(2);
528 arguments->Add(arg1); 529 arguments->Add(arg1);
529 arguments->Add(arg2); 530 arguments->Add(arg2);
530 531
531 return StaticCall(function, arguments); 532 return StaticCall(function, arguments);
532 } 533 }
533 534
534 535
535 StaticCallInstr* IRRegExpMacroAssembler::StaticCall( 536 StaticCallInstr* IRRegExpMacroAssembler::StaticCall(
536 const Function& function, 537 const Function& function,
537 ZoneGrowableArray<PushArgumentInstr*>* arguments) const { 538 ZoneGrowableArray<PushArgumentInstr*>* arguments) const {
538 return new(Z) StaticCallInstr(TokenPosition::kNoSource, 539 return new (Z)
539 function, 540 StaticCallInstr(TokenPosition::kNoSource, function, Object::null_array(),
540 Object::null_array(), 541 arguments, ic_data_array_);
541 arguments,
542 ic_data_array_);
543 } 542 }
544 543
545 544
546 InstanceCallInstr* IRRegExpMacroAssembler::InstanceCall( 545 InstanceCallInstr* IRRegExpMacroAssembler::InstanceCall(
547 const InstanceCallDescriptor& desc, 546 const InstanceCallDescriptor& desc,
548 PushArgumentInstr* arg1) const { 547 PushArgumentInstr* arg1) const {
549 ZoneGrowableArray<PushArgumentInstr*>* arguments = 548 ZoneGrowableArray<PushArgumentInstr*>* arguments =
550 new(Z) ZoneGrowableArray<PushArgumentInstr*>(1); 549 new (Z) ZoneGrowableArray<PushArgumentInstr*>(1);
551 arguments->Add(arg1); 550 arguments->Add(arg1);
552 551
553 return InstanceCall(desc, arguments); 552 return InstanceCall(desc, arguments);
554 } 553 }
555 554
556 555
557 InstanceCallInstr* IRRegExpMacroAssembler::InstanceCall( 556 InstanceCallInstr* IRRegExpMacroAssembler::InstanceCall(
558 const InstanceCallDescriptor& desc, 557 const InstanceCallDescriptor& desc,
559 PushArgumentInstr* arg1, 558 PushArgumentInstr* arg1,
560 PushArgumentInstr* arg2) const { 559 PushArgumentInstr* arg2) const {
561 ZoneGrowableArray<PushArgumentInstr*>* arguments = 560 ZoneGrowableArray<PushArgumentInstr*>* arguments =
562 new(Z) ZoneGrowableArray<PushArgumentInstr*>(2); 561 new (Z) ZoneGrowableArray<PushArgumentInstr*>(2);
563 arguments->Add(arg1); 562 arguments->Add(arg1);
564 arguments->Add(arg2); 563 arguments->Add(arg2);
565 564
566 return InstanceCall(desc, arguments); 565 return InstanceCall(desc, arguments);
567 } 566 }
568 567
569 568
570 InstanceCallInstr* IRRegExpMacroAssembler::InstanceCall( 569 InstanceCallInstr* IRRegExpMacroAssembler::InstanceCall(
571 const InstanceCallDescriptor& desc, 570 const InstanceCallDescriptor& desc,
572 PushArgumentInstr* arg1, 571 PushArgumentInstr* arg1,
573 PushArgumentInstr* arg2, 572 PushArgumentInstr* arg2,
574 PushArgumentInstr* arg3) const { 573 PushArgumentInstr* arg3) const {
575 ZoneGrowableArray<PushArgumentInstr*>* arguments = 574 ZoneGrowableArray<PushArgumentInstr*>* arguments =
576 new(Z) ZoneGrowableArray<PushArgumentInstr*>(3); 575 new (Z) ZoneGrowableArray<PushArgumentInstr*>(3);
577 arguments->Add(arg1); 576 arguments->Add(arg1);
578 arguments->Add(arg2); 577 arguments->Add(arg2);
579 arguments->Add(arg3); 578 arguments->Add(arg3);
580 579
581 return InstanceCall(desc, arguments); 580 return InstanceCall(desc, arguments);
582 } 581 }
583 582
584 583
585 InstanceCallInstr* IRRegExpMacroAssembler::InstanceCall( 584 InstanceCallInstr* IRRegExpMacroAssembler::InstanceCall(
586 const InstanceCallDescriptor& desc, 585 const InstanceCallDescriptor& desc,
587 ZoneGrowableArray<PushArgumentInstr*> *arguments) const { 586 ZoneGrowableArray<PushArgumentInstr*>* arguments) const {
588 return 587 return new (Z) InstanceCallInstr(
589 new(Z) InstanceCallInstr(TokenPosition::kNoSource, 588 TokenPosition::kNoSource, desc.name, desc.token_kind, arguments,
590 desc.name, 589 Object::null_array(), desc.checked_argument_count, ic_data_array_);
591 desc.token_kind,
592 arguments,
593 Object::null_array(),
594 desc.checked_argument_count,
595 ic_data_array_);
596 } 590 }
597 591
598 592
599 LoadLocalInstr* IRRegExpMacroAssembler::LoadLocal(LocalVariable* local) const { 593 LoadLocalInstr* IRRegExpMacroAssembler::LoadLocal(LocalVariable* local) const {
600 return new(Z) LoadLocalInstr(*local, TokenPosition::kNoSource); 594 return new (Z) LoadLocalInstr(*local, TokenPosition::kNoSource);
601 } 595 }
602 596
603 597
604 void IRRegExpMacroAssembler::StoreLocal(LocalVariable* local, 598 void IRRegExpMacroAssembler::StoreLocal(LocalVariable* local, Value* value) {
605 Value* value) { 599 Do(new (Z) StoreLocalInstr(*local, value, TokenPosition::kNoSource));
606 Do(new(Z) StoreLocalInstr(*local, value, TokenPosition::kNoSource));
607 } 600 }
608 601
609 602
610 void IRRegExpMacroAssembler::set_current_instruction(Instruction* instruction) { 603 void IRRegExpMacroAssembler::set_current_instruction(Instruction* instruction) {
611 current_instruction_ = instruction; 604 current_instruction_ = instruction;
612 } 605 }
613 606
614 607
615 Value* IRRegExpMacroAssembler::Bind(Definition* definition) { 608 Value* IRRegExpMacroAssembler::Bind(Definition* definition) {
616 AppendInstruction(definition); 609 AppendInstruction(definition);
617 definition->set_temp_index(temp_id_.Alloc()); 610 definition->set_temp_index(temp_id_.Alloc());
618 611
619 return new(Z) Value(definition); 612 return new (Z) Value(definition);
620 } 613 }
621 614
622 615
623 void IRRegExpMacroAssembler::Do(Definition* definition) { 616 void IRRegExpMacroAssembler::Do(Definition* definition) {
624 AppendInstruction(definition); 617 AppendInstruction(definition);
625 } 618 }
626 619
627 620
628 Value* IRRegExpMacroAssembler::BindLoadLocal(const LocalVariable& local) { 621 Value* IRRegExpMacroAssembler::BindLoadLocal(const LocalVariable& local) {
629 if (local.IsConst()) { 622 if (local.IsConst()) {
630 return Bind(new(Z) ConstantInstr(*local.ConstValue())); 623 return Bind(new (Z) ConstantInstr(*local.ConstValue()));
631 } 624 }
632 ASSERT(!local.is_captured()); 625 ASSERT(!local.is_captured());
633 return Bind(new(Z) LoadLocalInstr(local, TokenPosition::kNoSource)); 626 return Bind(new (Z) LoadLocalInstr(local, TokenPosition::kNoSource));
634 } 627 }
635 628
636 629
637 // In some cases, the V8 irregexp engine generates unreachable code by emitting 630 // In some cases, the V8 irregexp engine generates unreachable code by emitting
638 // a jmp not followed by a bind. We cannot do the same, since it is impossible 631 // a jmp not followed by a bind. We cannot do the same, since it is impossible
639 // to append to a block following a jmp. In such cases, assume that we are doing 632 // to append to a block following a jmp. In such cases, assume that we are doing
640 // the correct thing, but output a warning when tracing. 633 // the correct thing, but output a warning when tracing.
641 #define HANDLE_DEAD_CODE_EMISSION() \ 634 #define HANDLE_DEAD_CODE_EMISSION() \
642 if (current_instruction_ == NULL) { \ 635 if (current_instruction_ == NULL) { \
643 if (FLAG_trace_irregexp) { \ 636 if (FLAG_trace_irregexp) { \
644 OS::Print("WARNING: Attempting to append to a closed assembler. " \ 637 OS::Print( \
645 "This could be either a bug or generation of dead code " \ 638 "WARNING: Attempting to append to a closed assembler. " \
646 "inherited from V8.\n"); \ 639 "This could be either a bug or generation of dead code " \
647 } \ 640 "inherited from V8.\n"); \
648 BlockLabel dummy; \ 641 } \
649 BindBlock(&dummy); \ 642 BlockLabel dummy; \
643 BindBlock(&dummy); \
650 } 644 }
651 645
652 void IRRegExpMacroAssembler::AppendInstruction(Instruction* instruction) { 646 void IRRegExpMacroAssembler::AppendInstruction(Instruction* instruction) {
653 HANDLE_DEAD_CODE_EMISSION(); 647 HANDLE_DEAD_CODE_EMISSION();
654 648
655 ASSERT(current_instruction_ != NULL); 649 ASSERT(current_instruction_ != NULL);
656 ASSERT(current_instruction_->next() == NULL); 650 ASSERT(current_instruction_->next() == NULL);
657 651
658 temp_id_.Dealloc(instruction->InputCount()); 652 temp_id_.Dealloc(instruction->InputCount());
659 arg_id_.Dealloc(instruction->ArgumentCount()); 653 arg_id_.Dealloc(instruction->ArgumentCount());
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 688
695 ASSERT(current_instruction_ != NULL); 689 ASSERT(current_instruction_ != NULL);
696 ASSERT(current_instruction_->next() == NULL); 690 ASSERT(current_instruction_->next() == NULL);
697 current_instruction_->Goto(to); 691 current_instruction_->Goto(to);
698 set_current_instruction(NULL); 692 set_current_instruction(NULL);
699 } 693 }
700 694
701 695
702 PushArgumentInstr* IRRegExpMacroAssembler::PushArgument(Value* value) { 696 PushArgumentInstr* IRRegExpMacroAssembler::PushArgument(Value* value) {
703 arg_id_.Alloc(); 697 arg_id_.Alloc();
704 PushArgumentInstr* push = new(Z) PushArgumentInstr(value); 698 PushArgumentInstr* push = new (Z) PushArgumentInstr(value);
705 // Do *not* use Do() for push argument instructions. 699 // Do *not* use Do() for push argument instructions.
706 AppendInstruction(push); 700 AppendInstruction(push);
707 return push; 701 return push;
708 } 702 }
709 703
710 704
711 PushArgumentInstr* IRRegExpMacroAssembler::PushLocal(LocalVariable* local) { 705 PushArgumentInstr* IRRegExpMacroAssembler::PushLocal(LocalVariable* local) {
712 return PushArgument(Bind(LoadLocal(local))); 706 return PushArgument(Bind(LoadLocal(local)));
713 } 707 }
714 708
715 709
716 void IRRegExpMacroAssembler::Print(const char* str) { 710 void IRRegExpMacroAssembler::Print(const char* str) {
717 Print(PushArgument( 711 Print(PushArgument(Bind(new (Z) ConstantInstr(
718 Bind(new(Z) ConstantInstr( 712 String::ZoneHandle(Z, String::New(str, Heap::kOld))))));
719 String::ZoneHandle(Z, String::New(str, Heap::kOld))))));
720 } 713 }
721 714
722 715
723 void IRRegExpMacroAssembler::Print(PushArgumentInstr* argument) { 716 void IRRegExpMacroAssembler::Print(PushArgumentInstr* argument) {
724 const Library& lib = Library::Handle(Library::CoreLibrary()); 717 const Library& lib = Library::Handle(Library::CoreLibrary());
725 const Function& print_fn = Function::ZoneHandle( 718 const Function& print_fn =
726 Z, lib.LookupFunctionAllowPrivate(Symbols::print())); 719 Function::ZoneHandle(Z, lib.LookupFunctionAllowPrivate(Symbols::print()));
727 Do(StaticCall(print_fn, argument)); 720 Do(StaticCall(print_fn, argument));
728 } 721 }
729 722
730 723
731 void IRRegExpMacroAssembler::PrintBlocks() { 724 void IRRegExpMacroAssembler::PrintBlocks() {
732 for (intptr_t i = 0; i < blocks_.length(); i++) { 725 for (intptr_t i = 0; i < blocks_.length(); i++) {
733 FlowGraphPrinter::PrintBlock(blocks_[i], false); 726 FlowGraphPrinter::PrintBlock(blocks_[i], false);
734 } 727 }
735 } 728 }
736 729
737 730
738 intptr_t IRRegExpMacroAssembler::stack_limit_slack() { 731 intptr_t IRRegExpMacroAssembler::stack_limit_slack() {
739 return 32; 732 return 32;
740 } 733 }
741 734
742 735
743 void IRRegExpMacroAssembler::AdvanceCurrentPosition(intptr_t by) { 736 void IRRegExpMacroAssembler::AdvanceCurrentPosition(intptr_t by) {
744 TAG(); 737 TAG();
745 if (by != 0) { 738 if (by != 0) {
746 PushArgumentInstr* cur_pos_push = PushLocal(current_position_); 739 PushArgumentInstr* cur_pos_push = PushLocal(current_position_);
747 PushArgumentInstr* by_push = PushArgument(Bind(Int64Constant(by))); 740 PushArgumentInstr* by_push = PushArgument(Bind(Int64Constant(by)));
748 741
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 intptr_t IRRegExpMacroAssembler::GetNextLocalIndex() { 790 intptr_t IRRegExpMacroAssembler::GetNextLocalIndex() {
798 intptr_t id = local_id_.Alloc(); 791 intptr_t id = local_id_.Alloc();
799 return kFirstLocalSlotFromFp - id; 792 return kFirstLocalSlotFromFp - id;
800 } 793 }
801 794
802 795
803 Value* IRRegExpMacroAssembler::LoadRegister(intptr_t index) { 796 Value* IRRegExpMacroAssembler::LoadRegister(intptr_t index) {
804 PushArgumentInstr* registers_push = PushLocal(registers_); 797 PushArgumentInstr* registers_push = PushLocal(registers_);
805 PushArgumentInstr* index_push = PushRegisterIndex(index); 798 PushArgumentInstr* index_push = PushRegisterIndex(index);
806 return Bind(InstanceCall(InstanceCallDescriptor::FromToken(Token::kINDEX), 799 return Bind(InstanceCall(InstanceCallDescriptor::FromToken(Token::kINDEX),
807 registers_push, 800 registers_push, index_push));
808 index_push));
809 } 801 }
810 802
811 void IRRegExpMacroAssembler::StoreRegister(intptr_t index, intptr_t value) { 803 void IRRegExpMacroAssembler::StoreRegister(intptr_t index, intptr_t value) {
812 PushArgumentInstr* registers_push = PushLocal(registers_); 804 PushArgumentInstr* registers_push = PushLocal(registers_);
813 PushArgumentInstr* index_push = PushRegisterIndex(index); 805 PushArgumentInstr* index_push = PushRegisterIndex(index);
814 PushArgumentInstr* value_push = PushArgument(Bind(Uint64Constant(value))); 806 PushArgumentInstr* value_push = PushArgument(Bind(Uint64Constant(value)));
815 StoreRegister(registers_push, index_push, value_push); 807 StoreRegister(registers_push, index_push, value_push);
816 } 808 }
817 809
818 810
819 void IRRegExpMacroAssembler::StoreRegister(PushArgumentInstr* registers, 811 void IRRegExpMacroAssembler::StoreRegister(PushArgumentInstr* registers,
820 PushArgumentInstr* index, 812 PushArgumentInstr* index,
821 PushArgumentInstr* value) { 813 PushArgumentInstr* value) {
822 TAG(); 814 TAG();
823 Do(InstanceCall(InstanceCallDescriptor::FromToken(Token::kASSIGN_INDEX), 815 Do(InstanceCall(InstanceCallDescriptor::FromToken(Token::kASSIGN_INDEX),
824 registers, 816 registers, index, value));
825 index,
826 value));
827 } 817 }
828 818
829 PushArgumentInstr* IRRegExpMacroAssembler::PushRegisterIndex(intptr_t index) { 819 PushArgumentInstr* IRRegExpMacroAssembler::PushRegisterIndex(intptr_t index) {
830 if (registers_count_ <= index) { 820 if (registers_count_ <= index) {
831 registers_count_ = index + 1; 821 registers_count_ = index + 1;
832 } 822 }
833 return PushArgument(Bind(Uint64Constant(index))); 823 return PushArgument(Bind(Uint64Constant(index)));
834 } 824 }
835 825
836 826
837 void IRRegExpMacroAssembler::CheckCharacter(uint32_t c, BlockLabel* on_equal) { 827 void IRRegExpMacroAssembler::CheckCharacter(uint32_t c, BlockLabel* on_equal) {
838 TAG(); 828 TAG();
839 Definition* cur_char_def = LoadLocal(current_character_); 829 Definition* cur_char_def = LoadLocal(current_character_);
840 Definition* char_def = Uint64Constant(c); 830 Definition* char_def = Uint64Constant(c);
841 831
842 BranchOrBacktrack(Comparison(kEQ, cur_char_def, char_def), on_equal); 832 BranchOrBacktrack(Comparison(kEQ, cur_char_def, char_def), on_equal);
843 } 833 }
844 834
845 835
846 void IRRegExpMacroAssembler::CheckCharacterGT(uint16_t limit, 836 void IRRegExpMacroAssembler::CheckCharacterGT(uint16_t limit,
847 BlockLabel* on_greater) { 837 BlockLabel* on_greater) {
848 TAG(); 838 TAG();
849 BranchOrBacktrack(Comparison(kGT, 839 BranchOrBacktrack(
850 LoadLocal(current_character_), 840 Comparison(kGT, LoadLocal(current_character_), Uint64Constant(limit)),
851 Uint64Constant(limit)), 841 on_greater);
852 on_greater);
853 } 842 }
854 843
855 844
856 void IRRegExpMacroAssembler::CheckAtStart(BlockLabel* on_at_start) { 845 void IRRegExpMacroAssembler::CheckAtStart(BlockLabel* on_at_start) {
857 TAG(); 846 TAG();
858 847
859 BlockLabel not_at_start; 848 BlockLabel not_at_start;
860 849
861 // Did we start the match at the start of the string at all? 850 // Did we start the match at the start of the string at all?
862 BranchOrBacktrack(Comparison(kNE, 851 BranchOrBacktrack(
863 LoadLocal(start_index_param_), 852 Comparison(kNE, LoadLocal(start_index_param_), Uint64Constant(0)),
864 Uint64Constant(0)), 853 &not_at_start);
865 &not_at_start);
866 854
867 // If we did, are we still at the start of the input, i.e. is 855 // If we did, are we still at the start of the input, i.e. is
868 // (offset == string_length * -1)? 856 // (offset == string_length * -1)?
869 Definition* neg_len_def = 857 Definition* neg_len_def =
870 InstanceCall(InstanceCallDescriptor::FromToken(Token::kNEGATE), 858 InstanceCall(InstanceCallDescriptor::FromToken(Token::kNEGATE),
871 PushLocal(string_param_length_)); 859 PushLocal(string_param_length_));
872 Definition* offset_def = LoadLocal(current_position_); 860 Definition* offset_def = LoadLocal(current_position_);
873 BranchOrBacktrack(Comparison(kEQ, neg_len_def, offset_def), 861 BranchOrBacktrack(Comparison(kEQ, neg_len_def, offset_def), on_at_start);
874 on_at_start);
875 862
876 BindBlock(&not_at_start); 863 BindBlock(&not_at_start);
877 } 864 }
878 865
879 866
880 void IRRegExpMacroAssembler::CheckNotAtStart(BlockLabel* on_not_at_start) { 867 void IRRegExpMacroAssembler::CheckNotAtStart(BlockLabel* on_not_at_start) {
881 TAG(); 868 TAG();
882 869
883 // Did we start the match at the start of the string at all? 870 // Did we start the match at the start of the string at all?
884 BranchOrBacktrack(Comparison(kNE, 871 BranchOrBacktrack(
885 LoadLocal(start_index_param_), 872 Comparison(kNE, LoadLocal(start_index_param_), Uint64Constant(0)),
886 Uint64Constant(0)), 873 on_not_at_start);
887 on_not_at_start);
888 874
889 // If we did, are we still at the start of the input, i.e. is 875 // If we did, are we still at the start of the input, i.e. is
890 // (offset == string_length * -1)? 876 // (offset == string_length * -1)?
891 Definition* neg_len_def = 877 Definition* neg_len_def =
892 InstanceCall(InstanceCallDescriptor::FromToken(Token::kNEGATE), 878 InstanceCall(InstanceCallDescriptor::FromToken(Token::kNEGATE),
893 PushLocal(string_param_length_)); 879 PushLocal(string_param_length_));
894 Definition* offset_def = LoadLocal(current_position_); 880 Definition* offset_def = LoadLocal(current_position_);
895 BranchOrBacktrack(Comparison(kNE, neg_len_def, offset_def), 881 BranchOrBacktrack(Comparison(kNE, neg_len_def, offset_def), on_not_at_start);
896 on_not_at_start);
897 } 882 }
898 883
899 884
900 void IRRegExpMacroAssembler::CheckCharacterLT(uint16_t limit, 885 void IRRegExpMacroAssembler::CheckCharacterLT(uint16_t limit,
901 BlockLabel* on_less) { 886 BlockLabel* on_less) {
902 TAG(); 887 TAG();
903 BranchOrBacktrack(Comparison(kLT, 888 BranchOrBacktrack(
904 LoadLocal(current_character_), 889 Comparison(kLT, LoadLocal(current_character_), Uint64Constant(limit)),
905 Uint64Constant(limit)), 890 on_less);
906 on_less);
907 } 891 }
908 892
909 893
910 void IRRegExpMacroAssembler::CheckGreedyLoop(BlockLabel* on_equal) { 894 void IRRegExpMacroAssembler::CheckGreedyLoop(BlockLabel* on_equal) {
911 TAG(); 895 TAG();
912 896
913 BlockLabel fallthrough; 897 BlockLabel fallthrough;
914 898
915 Definition* head = PeekStack(); 899 Definition* head = PeekStack();
916 Definition* cur_pos_def = LoadLocal(current_position_); 900 Definition* cur_pos_def = LoadLocal(current_position_);
917 BranchOrBacktrack(Comparison(kNE, head, cur_pos_def), 901 BranchOrBacktrack(Comparison(kNE, head, cur_pos_def), &fallthrough);
918 &fallthrough);
919 902
920 // Pop, throwing away the value. 903 // Pop, throwing away the value.
921 Do(PopStack()); 904 Do(PopStack());
922 905
923 BranchOrBacktrack(NULL, on_equal); 906 BranchOrBacktrack(NULL, on_equal);
924 907
925 BindBlock(&fallthrough); 908 BindBlock(&fallthrough);
926 } 909 }
927 910
928 911
929 void IRRegExpMacroAssembler::CheckNotBackReferenceIgnoreCase( 912 void IRRegExpMacroAssembler::CheckNotBackReferenceIgnoreCase(
930 intptr_t start_reg, 913 intptr_t start_reg,
931 BlockLabel* on_no_match) { 914 BlockLabel* on_no_match) {
932 TAG(); 915 TAG();
933 ASSERT(start_reg + 1 <= registers_count_); 916 ASSERT(start_reg + 1 <= registers_count_);
934 917
935 BlockLabel fallthrough; 918 BlockLabel fallthrough;
936 919
937 PushArgumentInstr* end_push = PushArgument(LoadRegister(start_reg + 1)); 920 PushArgumentInstr* end_push = PushArgument(LoadRegister(start_reg + 1));
938 PushArgumentInstr* start_push = PushArgument(LoadRegister(start_reg)); 921 PushArgumentInstr* start_push = PushArgument(LoadRegister(start_reg));
939 StoreLocal(capture_length_, Bind(Sub(end_push, start_push))); 922 StoreLocal(capture_length_, Bind(Sub(end_push, start_push)));
940 923
941 // The length of a capture should not be negative. This can only happen 924 // The length of a capture should not be negative. This can only happen
942 // if the end of the capture is unrecorded, or at a point earlier than 925 // if the end of the capture is unrecorded, or at a point earlier than
943 // the start of the capture. 926 // the start of the capture.
944 // BranchOrBacktrack(less, on_no_match); 927 // BranchOrBacktrack(less, on_no_match);
945 928
946 BranchOrBacktrack(Comparison(kLT, 929 BranchOrBacktrack(
947 LoadLocal(capture_length_), 930 Comparison(kLT, LoadLocal(capture_length_), Uint64Constant(0)),
948 Uint64Constant(0)), 931 on_no_match);
949 on_no_match);
950 932
951 // If length is zero, either the capture is empty or it is completely 933 // If length is zero, either the capture is empty or it is completely
952 // uncaptured. In either case succeed immediately. 934 // uncaptured. In either case succeed immediately.
953 BranchOrBacktrack(Comparison(kEQ, 935 BranchOrBacktrack(
954 LoadLocal(capture_length_), 936 Comparison(kEQ, LoadLocal(capture_length_), Uint64Constant(0)),
955 Uint64Constant(0)), 937 &fallthrough);
956 &fallthrough);
957 938
958 939
959 // Check that there are sufficient characters left in the input. 940 // Check that there are sufficient characters left in the input.
960 PushArgumentInstr* pos_push = PushLocal(current_position_); 941 PushArgumentInstr* pos_push = PushLocal(current_position_);
961 PushArgumentInstr* len_push = PushLocal(capture_length_); 942 PushArgumentInstr* len_push = PushLocal(capture_length_);
962 BranchOrBacktrack( 943 BranchOrBacktrack(
963 Comparison(kGT, 944 Comparison(kGT,
964 InstanceCall(InstanceCallDescriptor::FromToken(Token::kADD), 945 InstanceCall(InstanceCallDescriptor::FromToken(Token::kADD),
965 pos_push, 946 pos_push, len_push),
966 len_push), 947 Uint64Constant(0)),
967 Uint64Constant(0)), 948 on_no_match);
968 on_no_match);
969 949
970 pos_push = PushLocal(current_position_); 950 pos_push = PushLocal(current_position_);
971 len_push = PushLocal(string_param_length_); 951 len_push = PushLocal(string_param_length_);
972 StoreLocal(match_start_index_, Bind(Add(pos_push, len_push))); 952 StoreLocal(match_start_index_, Bind(Add(pos_push, len_push)));
973 953
974 pos_push = PushArgument(LoadRegister(start_reg)); 954 pos_push = PushArgument(LoadRegister(start_reg));
975 len_push = PushLocal(string_param_length_); 955 len_push = PushLocal(string_param_length_);
976 StoreLocal(capture_start_index_, Bind(Add(pos_push, len_push))); 956 StoreLocal(capture_start_index_, Bind(Add(pos_push, len_push)));
977 957
978 pos_push = PushLocal(match_start_index_); 958 pos_push = PushLocal(match_start_index_);
979 len_push = PushLocal(capture_length_); 959 len_push = PushLocal(capture_length_);
980 StoreLocal(match_end_index_, Bind(Add(pos_push, len_push))); 960 StoreLocal(match_end_index_, Bind(Add(pos_push, len_push)));
981 961
982 BlockLabel success; 962 BlockLabel success;
983 if (mode_ == ASCII) { 963 if (mode_ == ASCII) {
984 BlockLabel loop_increment; 964 BlockLabel loop_increment;
985 BlockLabel loop; 965 BlockLabel loop;
986 BindBlock(&loop); 966 BindBlock(&loop);
987 967
988 StoreLocal(char_in_capture_, CharacterAt(capture_start_index_)); 968 StoreLocal(char_in_capture_, CharacterAt(capture_start_index_));
989 StoreLocal(char_in_match_, CharacterAt(match_start_index_)); 969 StoreLocal(char_in_match_, CharacterAt(match_start_index_));
990 970
991 BranchOrBacktrack(Comparison(kEQ, 971 BranchOrBacktrack(
992 LoadLocal(char_in_capture_), 972 Comparison(kEQ, LoadLocal(char_in_capture_), LoadLocal(char_in_match_)),
993 LoadLocal(char_in_match_)), 973 &loop_increment);
994 &loop_increment);
995 974
996 // Mismatch, try case-insensitive match (converting letters to lower-case). 975 // Mismatch, try case-insensitive match (converting letters to lower-case).
997 PushArgumentInstr* match_char_push = PushLocal(char_in_match_); 976 PushArgumentInstr* match_char_push = PushLocal(char_in_match_);
998 PushArgumentInstr* mask_push = PushArgument(Bind(Uint64Constant(0x20))); 977 PushArgumentInstr* mask_push = PushArgument(Bind(Uint64Constant(0x20)));
999 StoreLocal(char_in_match_, 978 StoreLocal(
1000 Bind(InstanceCall( 979 char_in_match_,
1001 InstanceCallDescriptor::FromToken(Token::kBIT_OR), 980 Bind(InstanceCall(InstanceCallDescriptor::FromToken(Token::kBIT_OR),
1002 match_char_push, 981 match_char_push, mask_push)));
1003 mask_push)));
1004 982
1005 BlockLabel convert_capture; 983 BlockLabel convert_capture;
1006 BlockLabel on_not_in_range; 984 BlockLabel on_not_in_range;
1007 BranchOrBacktrack(Comparison(kLT, 985 BranchOrBacktrack(
1008 LoadLocal(char_in_match_), 986 Comparison(kLT, LoadLocal(char_in_match_), Uint64Constant('a')),
1009 Uint64Constant('a')), 987 &on_not_in_range);
1010 &on_not_in_range); 988 BranchOrBacktrack(
1011 BranchOrBacktrack(Comparison(kGT, 989 Comparison(kGT, LoadLocal(char_in_match_), Uint64Constant('z')),
1012 LoadLocal(char_in_match_), 990 &on_not_in_range);
1013 Uint64Constant('z')),
1014 &on_not_in_range);
1015 GoTo(&convert_capture); 991 GoTo(&convert_capture);
1016 BindBlock(&on_not_in_range); 992 BindBlock(&on_not_in_range);
1017 993
1018 // Latin-1: Check for values in range [224,254] but not 247. 994 // Latin-1: Check for values in range [224,254] but not 247.
1019 BranchOrBacktrack(Comparison(kLT, 995 BranchOrBacktrack(
1020 LoadLocal(char_in_match_), 996 Comparison(kLT, LoadLocal(char_in_match_), Uint64Constant(224)),
1021 Uint64Constant(224)), 997 on_no_match);
1022 on_no_match); 998 BranchOrBacktrack(
1023 BranchOrBacktrack(Comparison(kGT, 999 Comparison(kGT, LoadLocal(char_in_match_), Uint64Constant(254)),
1024 LoadLocal(char_in_match_), 1000 on_no_match);
1025 Uint64Constant(254)),
1026 on_no_match);
1027 1001
1028 BranchOrBacktrack(Comparison(kEQ, 1002 BranchOrBacktrack(
1029 LoadLocal(char_in_match_), 1003 Comparison(kEQ, LoadLocal(char_in_match_), Uint64Constant(247)),
1030 Uint64Constant(247)), 1004 on_no_match);
1031 on_no_match);
1032 1005
1033 // Also convert capture character. 1006 // Also convert capture character.
1034 BindBlock(&convert_capture); 1007 BindBlock(&convert_capture);
1035 1008
1036 PushArgumentInstr* capture_char_push = PushLocal(char_in_capture_); 1009 PushArgumentInstr* capture_char_push = PushLocal(char_in_capture_);
1037 mask_push = PushArgument(Bind(Uint64Constant(0x20))); 1010 mask_push = PushArgument(Bind(Uint64Constant(0x20)));
1038 StoreLocal(char_in_capture_, 1011 StoreLocal(
1039 Bind(InstanceCall( 1012 char_in_capture_,
1040 InstanceCallDescriptor::FromToken(Token::kBIT_OR), 1013 Bind(InstanceCall(InstanceCallDescriptor::FromToken(Token::kBIT_OR),
1041 capture_char_push, 1014 capture_char_push, mask_push)));
1042 mask_push)));
1043 1015
1044 BranchOrBacktrack(Comparison(kNE, 1016 BranchOrBacktrack(
1045 LoadLocal(char_in_match_), 1017 Comparison(kNE, LoadLocal(char_in_match_), LoadLocal(char_in_capture_)),
1046 LoadLocal(char_in_capture_)), 1018 on_no_match);
1047 on_no_match);
1048 1019
1049 BindBlock(&loop_increment); 1020 BindBlock(&loop_increment);
1050 1021
1051 // Increment indexes into capture and match strings. 1022 // Increment indexes into capture and match strings.
1052 PushArgumentInstr* index_push = PushLocal(capture_start_index_); 1023 PushArgumentInstr* index_push = PushLocal(capture_start_index_);
1053 PushArgumentInstr* inc_push = PushArgument(Bind(Uint64Constant(1))); 1024 PushArgumentInstr* inc_push = PushArgument(Bind(Uint64Constant(1)));
1054 StoreLocal(capture_start_index_, Bind(Add(index_push, inc_push))); 1025 StoreLocal(capture_start_index_, Bind(Add(index_push, inc_push)));
1055 1026
1056 index_push = PushLocal(match_start_index_); 1027 index_push = PushLocal(match_start_index_);
1057 inc_push = PushArgument(Bind(Uint64Constant(1))); 1028 inc_push = PushArgument(Bind(Uint64Constant(1)));
1058 StoreLocal(match_start_index_, Bind(Add(index_push, inc_push))); 1029 StoreLocal(match_start_index_, Bind(Add(index_push, inc_push)));
1059 1030
1060 // Compare to end of match, and loop if not done. 1031 // Compare to end of match, and loop if not done.
1061 BranchOrBacktrack(Comparison(kLT, 1032 BranchOrBacktrack(Comparison(kLT, LoadLocal(match_start_index_),
1062 LoadLocal(match_start_index_),
1063 LoadLocal(match_end_index_)), 1033 LoadLocal(match_end_index_)),
1064 &loop); 1034 &loop);
1065 } else { 1035 } else {
1066 ASSERT(mode_ == UC16); 1036 ASSERT(mode_ == UC16);
1067 1037
1068 Value* string_value = Bind(LoadLocal(string_param_)); 1038 Value* string_value = Bind(LoadLocal(string_param_));
1069 Value* lhs_index_value = Bind(LoadLocal(match_start_index_)); 1039 Value* lhs_index_value = Bind(LoadLocal(match_start_index_));
1070 Value* rhs_index_value = Bind(LoadLocal(capture_start_index_)); 1040 Value* rhs_index_value = Bind(LoadLocal(capture_start_index_));
1071 Value* length_value = Bind(LoadLocal(capture_length_)); 1041 Value* length_value = Bind(LoadLocal(capture_length_));
1072 1042
1073 Definition* is_match_def = 1043 Definition* is_match_def = new (Z) CaseInsensitiveCompareUC16Instr(
1074 new(Z) CaseInsensitiveCompareUC16Instr( 1044 string_value, lhs_index_value, rhs_index_value, length_value,
1075 string_value, 1045 specialization_cid_);
1076 lhs_index_value,
1077 rhs_index_value,
1078 length_value,
1079 specialization_cid_);
1080 1046
1081 BranchOrBacktrack(Comparison(kNE, is_match_def, BoolConstant(true)), 1047 BranchOrBacktrack(Comparison(kNE, is_match_def, BoolConstant(true)),
1082 on_no_match); 1048 on_no_match);
1083 } 1049 }
1084 1050
1085 BindBlock(&success); 1051 BindBlock(&success);
1086 1052
1087 // Move current character position to position after match. 1053 // Move current character position to position after match.
1088 PushArgumentInstr* match_end_push = PushLocal(match_end_index_); 1054 PushArgumentInstr* match_end_push = PushLocal(match_end_index_);
1089 len_push = PushLocal(string_param_length_); 1055 len_push = PushLocal(string_param_length_);
1090 StoreLocal(current_position_, Bind(Sub(match_end_push, len_push))); 1056 StoreLocal(current_position_, Bind(Sub(match_end_push, len_push)));
1091 1057
1092 BindBlock(&fallthrough); 1058 BindBlock(&fallthrough);
1093 } 1059 }
1094 1060
1095 1061
1096 void IRRegExpMacroAssembler::CheckNotBackReference( 1062 void IRRegExpMacroAssembler::CheckNotBackReference(intptr_t start_reg,
1097 intptr_t start_reg, 1063 BlockLabel* on_no_match) {
1098 BlockLabel* on_no_match) {
1099 TAG(); 1064 TAG();
1100 ASSERT(start_reg + 1 <= registers_count_); 1065 ASSERT(start_reg + 1 <= registers_count_);
1101 1066
1102 BlockLabel fallthrough; 1067 BlockLabel fallthrough;
1103 BlockLabel success; 1068 BlockLabel success;
1104 1069
1105 // Find length of back-referenced capture. 1070 // Find length of back-referenced capture.
1106 PushArgumentInstr* end_push = PushArgument(LoadRegister(start_reg + 1)); 1071 PushArgumentInstr* end_push = PushArgument(LoadRegister(start_reg + 1));
1107 PushArgumentInstr* start_push = PushArgument(LoadRegister(start_reg)); 1072 PushArgumentInstr* start_push = PushArgument(LoadRegister(start_reg));
1108 StoreLocal(capture_length_, Bind(Sub(end_push, start_push))); 1073 StoreLocal(capture_length_, Bind(Sub(end_push, start_push)));
1109 1074
1110 // Fail on partial or illegal capture (start of capture after end of capture). 1075 // Fail on partial or illegal capture (start of capture after end of capture).
1111 BranchOrBacktrack(Comparison(kLT, 1076 BranchOrBacktrack(
1112 LoadLocal(capture_length_), 1077 Comparison(kLT, LoadLocal(capture_length_), Uint64Constant(0)),
1113 Uint64Constant(0)), 1078 on_no_match);
1114 on_no_match);
1115 1079
1116 // Succeed on empty capture (including no capture) 1080 // Succeed on empty capture (including no capture)
1117 BranchOrBacktrack(Comparison(kEQ, 1081 BranchOrBacktrack(
1118 LoadLocal(capture_length_), 1082 Comparison(kEQ, LoadLocal(capture_length_), Uint64Constant(0)),
1119 Uint64Constant(0)), 1083 &fallthrough);
1120 &fallthrough);
1121 1084
1122 // Check that there are sufficient characters left in the input. 1085 // Check that there are sufficient characters left in the input.
1123 PushArgumentInstr* pos_push = PushLocal(current_position_); 1086 PushArgumentInstr* pos_push = PushLocal(current_position_);
1124 PushArgumentInstr* len_push = PushLocal(capture_length_); 1087 PushArgumentInstr* len_push = PushLocal(capture_length_);
1125 BranchOrBacktrack( 1088 BranchOrBacktrack(
1126 Comparison(kGT, 1089 Comparison(kGT,
1127 InstanceCall(InstanceCallDescriptor::FromToken(Token::kADD), 1090 InstanceCall(InstanceCallDescriptor::FromToken(Token::kADD),
1128 pos_push, 1091 pos_push, len_push),
1129 len_push), 1092 Uint64Constant(0)),
1130 Uint64Constant(0)), 1093 on_no_match);
1131 on_no_match);
1132 1094
1133 // Compute pointers to match string and capture string. 1095 // Compute pointers to match string and capture string.
1134 pos_push = PushLocal(current_position_); 1096 pos_push = PushLocal(current_position_);
1135 len_push = PushLocal(string_param_length_); 1097 len_push = PushLocal(string_param_length_);
1136 StoreLocal(match_start_index_, Bind(Add(pos_push, len_push))); 1098 StoreLocal(match_start_index_, Bind(Add(pos_push, len_push)));
1137 1099
1138 pos_push = PushArgument(LoadRegister(start_reg)); 1100 pos_push = PushArgument(LoadRegister(start_reg));
1139 len_push = PushLocal(string_param_length_); 1101 len_push = PushLocal(string_param_length_);
1140 StoreLocal(capture_start_index_, Bind(Add(pos_push, len_push))); 1102 StoreLocal(capture_start_index_, Bind(Add(pos_push, len_push)));
1141 1103
1142 pos_push = PushLocal(match_start_index_); 1104 pos_push = PushLocal(match_start_index_);
1143 len_push = PushLocal(capture_length_); 1105 len_push = PushLocal(capture_length_);
1144 StoreLocal(match_end_index_, Bind(Add(pos_push, len_push))); 1106 StoreLocal(match_end_index_, Bind(Add(pos_push, len_push)));
1145 1107
1146 BlockLabel loop; 1108 BlockLabel loop;
1147 BindBlock(&loop); 1109 BindBlock(&loop);
1148 1110
1149 StoreLocal(char_in_capture_, CharacterAt(capture_start_index_)); 1111 StoreLocal(char_in_capture_, CharacterAt(capture_start_index_));
1150 StoreLocal(char_in_match_, CharacterAt(match_start_index_)); 1112 StoreLocal(char_in_match_, CharacterAt(match_start_index_));
1151 1113
1152 BranchOrBacktrack(Comparison(kNE, 1114 BranchOrBacktrack(
1153 LoadLocal(char_in_capture_), 1115 Comparison(kNE, LoadLocal(char_in_capture_), LoadLocal(char_in_match_)),
1154 LoadLocal(char_in_match_)), 1116 on_no_match);
1155 on_no_match);
1156 1117
1157 // Increment indexes into capture and match strings. 1118 // Increment indexes into capture and match strings.
1158 PushArgumentInstr* index_push = PushLocal(capture_start_index_); 1119 PushArgumentInstr* index_push = PushLocal(capture_start_index_);
1159 PushArgumentInstr* inc_push = PushArgument(Bind(Uint64Constant(1))); 1120 PushArgumentInstr* inc_push = PushArgument(Bind(Uint64Constant(1)));
1160 StoreLocal(capture_start_index_, Bind(Add(index_push, inc_push))); 1121 StoreLocal(capture_start_index_, Bind(Add(index_push, inc_push)));
1161 1122
1162 index_push = PushLocal(match_start_index_); 1123 index_push = PushLocal(match_start_index_);
1163 inc_push = PushArgument(Bind(Uint64Constant(1))); 1124 inc_push = PushArgument(Bind(Uint64Constant(1)));
1164 StoreLocal(match_start_index_, Bind(Add(index_push, inc_push))); 1125 StoreLocal(match_start_index_, Bind(Add(index_push, inc_push)));
1165 1126
1166 // Check if we have reached end of match area. 1127 // Check if we have reached end of match area.
1167 BranchOrBacktrack(Comparison(kLT, 1128 BranchOrBacktrack(Comparison(kLT, LoadLocal(match_start_index_),
1168 LoadLocal(match_start_index_),
1169 LoadLocal(match_end_index_)), 1129 LoadLocal(match_end_index_)),
1170 &loop); 1130 &loop);
1171 1131
1172 BindBlock(&success); 1132 BindBlock(&success);
1173 1133
1174 // Move current character position to position after match. 1134 // Move current character position to position after match.
1175 PushArgumentInstr* match_end_push = PushLocal(match_end_index_); 1135 PushArgumentInstr* match_end_push = PushLocal(match_end_index_);
1176 len_push = PushLocal(string_param_length_); 1136 len_push = PushLocal(string_param_length_);
1177 StoreLocal(current_position_, Bind(Sub(match_end_push, len_push))); 1137 StoreLocal(current_position_, Bind(Sub(match_end_push, len_push)));
1178 1138
1179 BindBlock(&fallthrough); 1139 BindBlock(&fallthrough);
1180 } 1140 }
1181 1141
1182 1142
1183 void IRRegExpMacroAssembler::CheckNotCharacter(uint32_t c, 1143 void IRRegExpMacroAssembler::CheckNotCharacter(uint32_t c,
1184 BlockLabel* on_not_equal) { 1144 BlockLabel* on_not_equal) {
1185 TAG(); 1145 TAG();
1186 BranchOrBacktrack(Comparison(kNE, 1146 BranchOrBacktrack(
1187 LoadLocal(current_character_), 1147 Comparison(kNE, LoadLocal(current_character_), Uint64Constant(c)),
1188 Uint64Constant(c)), 1148 on_not_equal);
1189 on_not_equal);
1190 } 1149 }
1191 1150
1192 1151
1193 void IRRegExpMacroAssembler::CheckCharacterAfterAnd(uint32_t c, 1152 void IRRegExpMacroAssembler::CheckCharacterAfterAnd(uint32_t c,
1194 uint32_t mask, 1153 uint32_t mask,
1195 BlockLabel* on_equal) { 1154 BlockLabel* on_equal) {
1196 TAG(); 1155 TAG();
1197 1156
1198 Definition* actual_def = LoadLocal(current_character_); 1157 Definition* actual_def = LoadLocal(current_character_);
1199 Definition* expected_def = Uint64Constant(c); 1158 Definition* expected_def = Uint64Constant(c);
1200 1159
1201 PushArgumentInstr* actual_push = PushArgument(Bind(actual_def)); 1160 PushArgumentInstr* actual_push = PushArgument(Bind(actual_def));
1202 PushArgumentInstr* mask_push = PushArgument(Bind(Uint64Constant(mask))); 1161 PushArgumentInstr* mask_push = PushArgument(Bind(Uint64Constant(mask)));
1203 actual_def = InstanceCall(InstanceCallDescriptor::FromToken(Token::kBIT_AND), 1162 actual_def = InstanceCall(InstanceCallDescriptor::FromToken(Token::kBIT_AND),
1204 actual_push, 1163 actual_push, mask_push);
1205 mask_push);
1206 1164
1207 BranchOrBacktrack(Comparison(kEQ, actual_def, expected_def), on_equal); 1165 BranchOrBacktrack(Comparison(kEQ, actual_def, expected_def), on_equal);
1208 } 1166 }
1209 1167
1210 1168
1211 void IRRegExpMacroAssembler::CheckNotCharacterAfterAnd( 1169 void IRRegExpMacroAssembler::CheckNotCharacterAfterAnd(
1212 uint32_t c, 1170 uint32_t c,
1213 uint32_t mask, 1171 uint32_t mask,
1214 BlockLabel* on_not_equal) { 1172 BlockLabel* on_not_equal) {
1215 TAG(); 1173 TAG();
1216 1174
1217 Definition* actual_def = LoadLocal(current_character_); 1175 Definition* actual_def = LoadLocal(current_character_);
1218 Definition* expected_def = Uint64Constant(c); 1176 Definition* expected_def = Uint64Constant(c);
1219 1177
1220 PushArgumentInstr* actual_push = PushArgument(Bind(actual_def)); 1178 PushArgumentInstr* actual_push = PushArgument(Bind(actual_def));
1221 PushArgumentInstr* mask_push = PushArgument(Bind(Uint64Constant(mask))); 1179 PushArgumentInstr* mask_push = PushArgument(Bind(Uint64Constant(mask)));
1222 actual_def = InstanceCall(InstanceCallDescriptor::FromToken(Token::kBIT_AND), 1180 actual_def = InstanceCall(InstanceCallDescriptor::FromToken(Token::kBIT_AND),
1223 actual_push, 1181 actual_push, mask_push);
1224 mask_push);
1225 1182
1226 BranchOrBacktrack(Comparison(kNE, actual_def, expected_def), on_not_equal); 1183 BranchOrBacktrack(Comparison(kNE, actual_def, expected_def), on_not_equal);
1227 } 1184 }
1228 1185
1229 1186
1230 void IRRegExpMacroAssembler::CheckNotCharacterAfterMinusAnd( 1187 void IRRegExpMacroAssembler::CheckNotCharacterAfterMinusAnd(
1231 uint16_t c, 1188 uint16_t c,
1232 uint16_t minus, 1189 uint16_t minus,
1233 uint16_t mask, 1190 uint16_t mask,
1234 BlockLabel* on_not_equal) { 1191 BlockLabel* on_not_equal) {
1235 TAG(); 1192 TAG();
1236 ASSERT(minus < Utf16::kMaxCodeUnit); // NOLINT 1193 ASSERT(minus < Utf16::kMaxCodeUnit); // NOLINT
1237 1194
1238 Definition* actual_def = LoadLocal(current_character_); 1195 Definition* actual_def = LoadLocal(current_character_);
1239 Definition* expected_def = Uint64Constant(c); 1196 Definition* expected_def = Uint64Constant(c);
1240 1197
1241 PushArgumentInstr* actual_push = PushArgument(Bind(actual_def)); 1198 PushArgumentInstr* actual_push = PushArgument(Bind(actual_def));
1242 PushArgumentInstr* minus_push = PushArgument(Bind(Uint64Constant(minus))); 1199 PushArgumentInstr* minus_push = PushArgument(Bind(Uint64Constant(minus)));
1243 1200
1244 actual_push = PushArgument(Bind(Sub(actual_push, minus_push))); 1201 actual_push = PushArgument(Bind(Sub(actual_push, minus_push)));
1245 PushArgumentInstr* mask_push = PushArgument(Bind(Uint64Constant(mask))); 1202 PushArgumentInstr* mask_push = PushArgument(Bind(Uint64Constant(mask)));
1246 actual_def = InstanceCall(InstanceCallDescriptor::FromToken(Token::kBIT_AND), 1203 actual_def = InstanceCall(InstanceCallDescriptor::FromToken(Token::kBIT_AND),
1247 actual_push, 1204 actual_push, mask_push);
1248 mask_push);
1249 1205
1250 BranchOrBacktrack(Comparison(kNE, actual_def, expected_def), on_not_equal); 1206 BranchOrBacktrack(Comparison(kNE, actual_def, expected_def), on_not_equal);
1251 } 1207 }
1252 1208
1253 1209
1254 void IRRegExpMacroAssembler::CheckCharacterInRange( 1210 void IRRegExpMacroAssembler::CheckCharacterInRange(uint16_t from,
1255 uint16_t from, 1211 uint16_t to,
1256 uint16_t to, 1212 BlockLabel* on_in_range) {
1257 BlockLabel* on_in_range) {
1258 TAG(); 1213 TAG();
1259 ASSERT(from <= to); 1214 ASSERT(from <= to);
1260 1215
1261 // TODO(zerny): All range comparisons could be done cheaper with unsigned 1216 // TODO(zerny): All range comparisons could be done cheaper with unsigned
1262 // compares. This pattern repeats in various places. 1217 // compares. This pattern repeats in various places.
1263 1218
1264 BlockLabel on_not_in_range; 1219 BlockLabel on_not_in_range;
1265 BranchOrBacktrack(Comparison(kLT, 1220 BranchOrBacktrack(
1266 LoadLocal(current_character_), 1221 Comparison(kLT, LoadLocal(current_character_), Uint64Constant(from)),
1267 Uint64Constant(from)), 1222 &on_not_in_range);
1268 &on_not_in_range); 1223 BranchOrBacktrack(
1269 BranchOrBacktrack(Comparison(kGT, 1224 Comparison(kGT, LoadLocal(current_character_), Uint64Constant(to)),
1270 LoadLocal(current_character_), 1225 &on_not_in_range);
1271 Uint64Constant(to)),
1272 &on_not_in_range);
1273 BranchOrBacktrack(NULL, on_in_range); 1226 BranchOrBacktrack(NULL, on_in_range);
1274 1227
1275 BindBlock(&on_not_in_range); 1228 BindBlock(&on_not_in_range);
1276 } 1229 }
1277 1230
1278 1231
1279 void IRRegExpMacroAssembler::CheckCharacterNotInRange( 1232 void IRRegExpMacroAssembler::CheckCharacterNotInRange(
1280 uint16_t from, 1233 uint16_t from,
1281 uint16_t to, 1234 uint16_t to,
1282 BlockLabel* on_not_in_range) { 1235 BlockLabel* on_not_in_range) {
1283 TAG(); 1236 TAG();
1284 ASSERT(from <= to); 1237 ASSERT(from <= to);
1285 1238
1286 BranchOrBacktrack(Comparison(kLT, 1239 BranchOrBacktrack(
1287 LoadLocal(current_character_), 1240 Comparison(kLT, LoadLocal(current_character_), Uint64Constant(from)),
1288 Uint64Constant(from)), 1241 on_not_in_range);
1289 on_not_in_range);
1290 1242
1291 BranchOrBacktrack(Comparison(kGT, 1243 BranchOrBacktrack(
1292 LoadLocal(current_character_), 1244 Comparison(kGT, LoadLocal(current_character_), Uint64Constant(to)),
1293 Uint64Constant(to)), 1245 on_not_in_range);
1294 on_not_in_range);
1295 } 1246 }
1296 1247
1297 1248
1298 void IRRegExpMacroAssembler::CheckBitInTable( 1249 void IRRegExpMacroAssembler::CheckBitInTable(const TypedData& table,
1299 const TypedData& table, 1250 BlockLabel* on_bit_set) {
1300 BlockLabel* on_bit_set) {
1301 TAG(); 1251 TAG();
1302 1252
1303 PushArgumentInstr* table_push = 1253 PushArgumentInstr* table_push =
1304 PushArgument(Bind(new(Z) ConstantInstr(table))); 1254 PushArgument(Bind(new (Z) ConstantInstr(table)));
1305 PushArgumentInstr* index_push = PushLocal(current_character_); 1255 PushArgumentInstr* index_push = PushLocal(current_character_);
1306 1256
1307 if (mode_ != ASCII || kTableMask != Symbols::kMaxOneCharCodeSymbol) { 1257 if (mode_ != ASCII || kTableMask != Symbols::kMaxOneCharCodeSymbol) {
1308 PushArgumentInstr* mask_push = 1258 PushArgumentInstr* mask_push =
1309 PushArgument(Bind(Uint64Constant(kTableSize - 1))); 1259 PushArgument(Bind(Uint64Constant(kTableSize - 1)));
1310 index_push = PushArgument( 1260 index_push = PushArgument(
1311 Bind(InstanceCall(InstanceCallDescriptor::FromToken(Token::kBIT_AND), 1261 Bind(InstanceCall(InstanceCallDescriptor::FromToken(Token::kBIT_AND),
1312 index_push, 1262 index_push, mask_push)));
1313 mask_push)));
1314 } 1263 }
1315 1264
1316 Definition* byte_def = 1265 Definition* byte_def = InstanceCall(
1317 InstanceCall(InstanceCallDescriptor::FromToken(Token::kINDEX), 1266 InstanceCallDescriptor::FromToken(Token::kINDEX), table_push, index_push);
1318 table_push,
1319 index_push);
1320 Definition* zero_def = Int64Constant(0); 1267 Definition* zero_def = Int64Constant(0);
1321 1268
1322 BranchOrBacktrack(Comparison(kNE, byte_def, zero_def), on_bit_set); 1269 BranchOrBacktrack(Comparison(kNE, byte_def, zero_def), on_bit_set);
1323 } 1270 }
1324 1271
1325 1272
1326 bool IRRegExpMacroAssembler::CheckSpecialCharacterClass( 1273 bool IRRegExpMacroAssembler::CheckSpecialCharacterClass(
1327 uint16_t type, 1274 uint16_t type,
1328 BlockLabel* on_no_match) { 1275 BlockLabel* on_no_match) {
1329 TAG(); 1276 TAG();
1330 1277
1331 // Range checks (c in min..max) are generally implemented by an unsigned 1278 // Range checks (c in min..max) are generally implemented by an unsigned
1332 // (c - min) <= (max - min) check 1279 // (c - min) <= (max - min) check
1333 switch (type) { 1280 switch (type) {
1334 case 's': 1281 case 's':
1335 // Match space-characters 1282 // Match space-characters
1336 if (mode_ == ASCII) { 1283 if (mode_ == ASCII) {
1337 // One byte space characters are '\t'..'\r', ' ' and \u00a0. 1284 // One byte space characters are '\t'..'\r', ' ' and \u00a0.
1285 BlockLabel success;
1286 // Space (' ').
1287 BranchOrBacktrack(
1288 Comparison(kEQ, LoadLocal(current_character_), Uint64Constant(' ')),
1289 &success);
1290 // Check range 0x09..0x0d.
1291 CheckCharacterInRange('\t', '\r', &success);
1292 // \u00a0 (NBSP).
1293 BranchOrBacktrack(Comparison(kNE, LoadLocal(current_character_),
1294 Uint64Constant(0x00a0)),
1295 on_no_match);
1296 BindBlock(&success);
1297 return true;
1298 }
1299 return false;
1300 case 'S':
1301 // The emitted code for generic character classes is good enough.
1302 return false;
1303 case 'd':
1304 // Match ASCII digits ('0'..'9')
1305 CheckCharacterNotInRange('0', '9', on_no_match);
1306 return true;
1307 case 'D':
1308 // Match non ASCII-digits
1309 CheckCharacterInRange('0', '9', on_no_match);
1310 return true;
1311 case '.': {
1312 // Match non-newlines (not 0x0a('\n'), 0x0d('\r'), 0x2028 and 0x2029)
1313 BranchOrBacktrack(
1314 Comparison(kEQ, LoadLocal(current_character_), Uint64Constant('\n')),
1315 on_no_match);
1316 BranchOrBacktrack(
1317 Comparison(kEQ, LoadLocal(current_character_), Uint64Constant('\r')),
1318 on_no_match);
1319 if (mode_ == UC16) {
1320 BranchOrBacktrack(Comparison(kEQ, LoadLocal(current_character_),
1321 Uint64Constant(0x2028)),
1322 on_no_match);
1323 BranchOrBacktrack(Comparison(kEQ, LoadLocal(current_character_),
1324 Uint64Constant(0x2029)),
1325 on_no_match);
1326 }
1327 return true;
1328 }
1329 case 'w': {
1330 if (mode_ != ASCII) {
1331 // Table is 128 entries, so all ASCII characters can be tested.
1332 BranchOrBacktrack(
1333 Comparison(kGT, LoadLocal(current_character_), Uint64Constant('z')),
1334 on_no_match);
1335 }
1336
1337 PushArgumentInstr* table_push =
1338 PushArgument(Bind(WordCharacterMapConstant()));
1339 PushArgumentInstr* index_push = PushLocal(current_character_);
1340
1341 Definition* byte_def =
1342 InstanceCall(InstanceCallDescriptor::FromToken(Token::kINDEX),
1343 table_push, index_push);
1344 Definition* zero_def = Int64Constant(0);
1345
1346 BranchOrBacktrack(Comparison(kEQ, byte_def, zero_def), on_no_match);
1347
1348 return true;
1349 }
1350 case 'W': {
1351 BlockLabel done;
1352 if (mode_ != ASCII) {
1353 // Table is 128 entries, so all ASCII characters can be tested.
1354 BranchOrBacktrack(
1355 Comparison(kGT, LoadLocal(current_character_), Uint64Constant('z')),
1356 &done);
1357 }
1358
1359 // TODO(zerny): Refactor to use CheckBitInTable if possible.
1360
1361 PushArgumentInstr* table_push =
1362 PushArgument(Bind(WordCharacterMapConstant()));
1363 PushArgumentInstr* index_push = PushLocal(current_character_);
1364
1365 Definition* byte_def =
1366 InstanceCall(InstanceCallDescriptor::FromToken(Token::kINDEX),
1367 table_push, index_push);
1368 Definition* zero_def = Int64Constant(0);
1369
1370 BranchOrBacktrack(Comparison(kNE, byte_def, zero_def), on_no_match);
1371
1372 if (mode_ != ASCII) {
1373 BindBlock(&done);
1374 }
1375 return true;
1376 }
1377 // Non-standard classes (with no syntactic shorthand) used internally.
1378 case '*':
1379 // Match any character.
1380 return true;
1381 case 'n': {
1382 // Match newlines (0x0a('\n'), 0x0d('\r'), 0x2028 or 0x2029).
1383 // The opposite of '.'.
1338 BlockLabel success; 1384 BlockLabel success;
1339 // Space (' '). 1385 BranchOrBacktrack(
1340 BranchOrBacktrack(Comparison(kEQ, 1386 Comparison(kEQ, LoadLocal(current_character_), Uint64Constant('\n')),
1341 LoadLocal(current_character_), 1387 &success);
1342 Uint64Constant(' ')), 1388 BranchOrBacktrack(
1343 &success); 1389 Comparison(kEQ, LoadLocal(current_character_), Uint64Constant('\r')),
1344 // Check range 0x09..0x0d. 1390 &success);
1345 CheckCharacterInRange('\t', '\r', &success); 1391 if (mode_ == UC16) {
1346 // \u00a0 (NBSP). 1392 BranchOrBacktrack(Comparison(kEQ, LoadLocal(current_character_),
1347 BranchOrBacktrack(Comparison(kNE, 1393 Uint64Constant(0x2028)),
1348 LoadLocal(current_character_), 1394 &success);
1349 Uint64Constant(0x00a0)), 1395 BranchOrBacktrack(Comparison(kEQ, LoadLocal(current_character_),
1350 on_no_match); 1396 Uint64Constant(0x2029)),
1397 &success);
1398 }
1399 BranchOrBacktrack(NULL, on_no_match);
1351 BindBlock(&success); 1400 BindBlock(&success);
1352 return true; 1401 return true;
1353 } 1402 }
1354 return false; 1403 // No custom implementation (yet): s(uint16_t), S(uint16_t).
1355 case 'S': 1404 default:
1356 // The emitted code for generic character classes is good enough. 1405 return false;
1357 return false;
1358 case 'd':
1359 // Match ASCII digits ('0'..'9')
1360 CheckCharacterNotInRange('0', '9', on_no_match);
1361 return true;
1362 case 'D':
1363 // Match non ASCII-digits
1364 CheckCharacterInRange('0', '9', on_no_match);
1365 return true;
1366 case '.': {
1367 // Match non-newlines (not 0x0a('\n'), 0x0d('\r'), 0x2028 and 0x2029)
1368 BranchOrBacktrack(Comparison(kEQ,
1369 LoadLocal(current_character_),
1370 Uint64Constant('\n')),
1371 on_no_match);
1372 BranchOrBacktrack(Comparison(kEQ,
1373 LoadLocal(current_character_),
1374 Uint64Constant('\r')),
1375 on_no_match);
1376 if (mode_ == UC16) {
1377 BranchOrBacktrack(Comparison(kEQ,
1378 LoadLocal(current_character_),
1379 Uint64Constant(0x2028)),
1380 on_no_match);
1381 BranchOrBacktrack(Comparison(kEQ,
1382 LoadLocal(current_character_),
1383 Uint64Constant(0x2029)),
1384 on_no_match);
1385 }
1386 return true;
1387 }
1388 case 'w': {
1389 if (mode_ != ASCII) {
1390 // Table is 128 entries, so all ASCII characters can be tested.
1391 BranchOrBacktrack(Comparison(kGT,
1392 LoadLocal(current_character_),
1393 Uint64Constant('z')),
1394 on_no_match);
1395 }
1396
1397 PushArgumentInstr* table_push =
1398 PushArgument(Bind(WordCharacterMapConstant()));
1399 PushArgumentInstr* index_push = PushLocal(current_character_);
1400
1401 Definition* byte_def =
1402 InstanceCall(InstanceCallDescriptor::FromToken(Token::kINDEX),
1403 table_push,
1404 index_push);
1405 Definition* zero_def = Int64Constant(0);
1406
1407 BranchOrBacktrack(Comparison(kEQ, byte_def, zero_def), on_no_match);
1408
1409 return true;
1410 }
1411 case 'W': {
1412 BlockLabel done;
1413 if (mode_ != ASCII) {
1414 // Table is 128 entries, so all ASCII characters can be tested.
1415 BranchOrBacktrack(Comparison(kGT,
1416 LoadLocal(current_character_),
1417 Uint64Constant('z')),
1418 &done);
1419 }
1420
1421 // TODO(zerny): Refactor to use CheckBitInTable if possible.
1422
1423 PushArgumentInstr* table_push =
1424 PushArgument(Bind(WordCharacterMapConstant()));
1425 PushArgumentInstr* index_push = PushLocal(current_character_);
1426
1427 Definition* byte_def =
1428 InstanceCall(InstanceCallDescriptor::FromToken(Token::kINDEX),
1429 table_push,
1430 index_push);
1431 Definition* zero_def = Int64Constant(0);
1432
1433 BranchOrBacktrack(Comparison(kNE, byte_def, zero_def), on_no_match);
1434
1435 if (mode_ != ASCII) {
1436 BindBlock(&done);
1437 }
1438 return true;
1439 }
1440 // Non-standard classes (with no syntactic shorthand) used internally.
1441 case '*':
1442 // Match any character.
1443 return true;
1444 case 'n': {
1445 // Match newlines (0x0a('\n'), 0x0d('\r'), 0x2028 or 0x2029).
1446 // The opposite of '.'.
1447 BlockLabel success;
1448 BranchOrBacktrack(Comparison(kEQ,
1449 LoadLocal(current_character_),
1450 Uint64Constant('\n')),
1451 &success);
1452 BranchOrBacktrack(Comparison(kEQ,
1453 LoadLocal(current_character_),
1454 Uint64Constant('\r')),
1455 &success);
1456 if (mode_ == UC16) {
1457 BranchOrBacktrack(Comparison(kEQ,
1458 LoadLocal(current_character_),
1459 Uint64Constant(0x2028)),
1460 &success);
1461 BranchOrBacktrack(Comparison(kEQ,
1462 LoadLocal(current_character_),
1463 Uint64Constant(0x2029)),
1464 &success);
1465 }
1466 BranchOrBacktrack(NULL, on_no_match);
1467 BindBlock(&success);
1468 return true;
1469 }
1470 // No custom implementation (yet): s(uint16_t), S(uint16_t).
1471 default:
1472 return false;
1473 } 1406 }
1474 } 1407 }
1475 1408
1476 1409
1477 void IRRegExpMacroAssembler::Fail() { 1410 void IRRegExpMacroAssembler::Fail() {
1478 TAG(); 1411 TAG();
1479 ASSERT(FAILURE == 0); // Return value for failure is zero. 1412 ASSERT(FAILURE == 0); // Return value for failure is zero.
1480 if (!global()) { 1413 if (!global()) {
1481 UNREACHABLE(); // Dart regexps are always global. 1414 UNREACHABLE(); // Dart regexps are always global.
1482 } 1415 }
(...skipping 14 matching lines...) Expand all
1497 void IRRegExpMacroAssembler::IfRegisterLT(intptr_t reg, 1430 void IRRegExpMacroAssembler::IfRegisterLT(intptr_t reg,
1498 intptr_t comparand, 1431 intptr_t comparand,
1499 BlockLabel* if_lt) { 1432 BlockLabel* if_lt) {
1500 TAG(); 1433 TAG();
1501 PushArgumentInstr* reg_push = PushArgument(LoadRegister(reg)); 1434 PushArgumentInstr* reg_push = PushArgument(LoadRegister(reg));
1502 PushArgumentInstr* pos = PushArgument(Bind(Int64Constant(comparand))); 1435 PushArgumentInstr* pos = PushArgument(Bind(Int64Constant(comparand)));
1503 BranchOrBacktrack(Comparison(kLT, reg_push, pos), if_lt); 1436 BranchOrBacktrack(Comparison(kLT, reg_push, pos), if_lt);
1504 } 1437 }
1505 1438
1506 1439
1507 void IRRegExpMacroAssembler::IfRegisterEqPos(intptr_t reg, 1440 void IRRegExpMacroAssembler::IfRegisterEqPos(intptr_t reg, BlockLabel* if_eq) {
1508 BlockLabel* if_eq) {
1509 TAG(); 1441 TAG();
1510 PushArgumentInstr* reg_push = PushArgument(LoadRegister(reg)); 1442 PushArgumentInstr* reg_push = PushArgument(LoadRegister(reg));
1511 PushArgumentInstr* pos = PushArgument(Bind(LoadLocal(current_position_))); 1443 PushArgumentInstr* pos = PushArgument(Bind(LoadLocal(current_position_)));
1512 BranchOrBacktrack(Comparison(kEQ, reg_push, pos), if_eq); 1444 BranchOrBacktrack(Comparison(kEQ, reg_push, pos), if_eq);
1513 } 1445 }
1514 1446
1515 1447
1516 RegExpMacroAssembler::IrregexpImplementation 1448 RegExpMacroAssembler::IrregexpImplementation
1517 IRRegExpMacroAssembler::Implementation() { 1449 IRRegExpMacroAssembler::Implementation() {
1518 return kIRImplementation; 1450 return kIRImplementation;
1519 } 1451 }
1520 1452
1521 1453
1522 void IRRegExpMacroAssembler::LoadCurrentCharacter(intptr_t cp_offset, 1454 void IRRegExpMacroAssembler::LoadCurrentCharacter(intptr_t cp_offset,
1523 BlockLabel* on_end_of_input, 1455 BlockLabel* on_end_of_input,
1524 bool check_bounds, 1456 bool check_bounds,
1525 intptr_t characters) { 1457 intptr_t characters) {
1526 TAG(); 1458 TAG();
1527 ASSERT(cp_offset >= -1); // ^ and \b can look behind one character. 1459 ASSERT(cp_offset >= -1); // ^ and \b can look behind one character.
1528 ASSERT(cp_offset < (1<<30)); // Be sane! (And ensure negation works) 1460 ASSERT(cp_offset < (1 << 30)); // Be sane! (And ensure negation works)
1529 if (check_bounds) { 1461 if (check_bounds) {
1530 CheckPosition(cp_offset + characters - 1, on_end_of_input); 1462 CheckPosition(cp_offset + characters - 1, on_end_of_input);
1531 } 1463 }
1532 LoadCurrentCharacterUnchecked(cp_offset, characters); 1464 LoadCurrentCharacterUnchecked(cp_offset, characters);
1533 } 1465 }
1534 1466
1535 1467
1536 void IRRegExpMacroAssembler::PopCurrentPosition() { 1468 void IRRegExpMacroAssembler::PopCurrentPosition() {
1537 TAG(); 1469 TAG();
1538 StoreLocal(current_position_, Bind(PopStack())); 1470 StoreLocal(current_position_, Bind(PopStack()));
1539 } 1471 }
1540 1472
1541 1473
1542 void IRRegExpMacroAssembler::PopRegister(intptr_t reg) { 1474 void IRRegExpMacroAssembler::PopRegister(intptr_t reg) {
1543 TAG(); 1475 TAG();
1544 ASSERT(reg < registers_count_); 1476 ASSERT(reg < registers_count_);
1545 PushArgumentInstr* registers_push = PushLocal(registers_); 1477 PushArgumentInstr* registers_push = PushLocal(registers_);
1546 PushArgumentInstr* index_push = PushRegisterIndex(reg); 1478 PushArgumentInstr* index_push = PushRegisterIndex(reg);
1547 PushArgumentInstr* pop_push = PushArgument(Bind(PopStack())); 1479 PushArgumentInstr* pop_push = PushArgument(Bind(PopStack()));
1548 StoreRegister(registers_push, index_push, pop_push); 1480 StoreRegister(registers_push, index_push, pop_push);
1549 } 1481 }
1550 1482
1551 1483
1552 void IRRegExpMacroAssembler::PushStack(Definition *definition) { 1484 void IRRegExpMacroAssembler::PushStack(Definition* definition) {
1553 PushArgumentInstr* stack_push = PushLocal(stack_); 1485 PushArgumentInstr* stack_push = PushLocal(stack_);
1554 PushArgumentInstr* stack_pointer_push = PushLocal(stack_pointer_); 1486 PushArgumentInstr* stack_pointer_push = PushLocal(stack_pointer_);
1555 StoreLocal(stack_pointer_, 1487 StoreLocal(stack_pointer_, Bind(Add(stack_pointer_push,
1556 Bind(Add(stack_pointer_push, 1488 PushArgument(Bind(Uint64Constant(1))))));
1557 PushArgument(Bind(Uint64Constant(1))))));
1558 stack_pointer_push = PushLocal(stack_pointer_); 1489 stack_pointer_push = PushLocal(stack_pointer_);
1559 // TODO(zerny): bind value and push could break stack discipline. 1490 // TODO(zerny): bind value and push could break stack discipline.
1560 PushArgumentInstr* value_push = PushArgument(Bind(definition)); 1491 PushArgumentInstr* value_push = PushArgument(Bind(definition));
1561 Do(InstanceCall(InstanceCallDescriptor::FromToken(Token::kASSIGN_INDEX), 1492 Do(InstanceCall(InstanceCallDescriptor::FromToken(Token::kASSIGN_INDEX),
1562 stack_push, 1493 stack_push, stack_pointer_push, value_push));
1563 stack_pointer_push,
1564 value_push));
1565 } 1494 }
1566 1495
1567 1496
1568 Definition* IRRegExpMacroAssembler::PopStack() { 1497 Definition* IRRegExpMacroAssembler::PopStack() {
1569 PushArgumentInstr* stack_push = PushLocal(stack_); 1498 PushArgumentInstr* stack_push = PushLocal(stack_);
1570 PushArgumentInstr* stack_pointer_push1 = PushLocal(stack_pointer_); 1499 PushArgumentInstr* stack_pointer_push1 = PushLocal(stack_pointer_);
1571 PushArgumentInstr* stack_pointer_push2 = PushLocal(stack_pointer_); 1500 PushArgumentInstr* stack_pointer_push2 = PushLocal(stack_pointer_);
1572 StoreLocal(stack_pointer_, 1501 StoreLocal(stack_pointer_, Bind(Sub(stack_pointer_push2,
1573 Bind(Sub(stack_pointer_push2, 1502 PushArgument(Bind(Uint64Constant(1))))));
1574 PushArgument(Bind(Uint64Constant(1))))));
1575 return InstanceCall(InstanceCallDescriptor::FromToken(Token::kINDEX), 1503 return InstanceCall(InstanceCallDescriptor::FromToken(Token::kINDEX),
1576 stack_push, 1504 stack_push, stack_pointer_push1);
1577 stack_pointer_push1);
1578 } 1505 }
1579 1506
1580 1507
1581 Definition* IRRegExpMacroAssembler::PeekStack() { 1508 Definition* IRRegExpMacroAssembler::PeekStack() {
1582 PushArgumentInstr* stack_push = PushLocal(stack_); 1509 PushArgumentInstr* stack_push = PushLocal(stack_);
1583 PushArgumentInstr* stack_pointer_push = PushLocal(stack_pointer_); 1510 PushArgumentInstr* stack_pointer_push = PushLocal(stack_pointer_);
1584 return InstanceCall(InstanceCallDescriptor::FromToken(Token::kINDEX), 1511 return InstanceCall(InstanceCallDescriptor::FromToken(Token::kINDEX),
1585 stack_push, 1512 stack_push, stack_pointer_push);
1586 stack_pointer_push);
1587 } 1513 }
1588 1514
1589 1515
1590 // Pushes the location corresponding to label to the backtracking stack. 1516 // Pushes the location corresponding to label to the backtracking stack.
1591 void IRRegExpMacroAssembler::PushBacktrack(BlockLabel* label) { 1517 void IRRegExpMacroAssembler::PushBacktrack(BlockLabel* label) {
1592 TAG(); 1518 TAG();
1593 1519
1594 // Ensure that targets of indirect jumps are never accessed through a 1520 // Ensure that targets of indirect jumps are never accessed through a
1595 // normal control flow instructions by creating a new block for each backtrack 1521 // normal control flow instructions by creating a new block for each backtrack
1596 // target. 1522 // target.
(...skipping 12 matching lines...) Expand all
1609 TAG(); 1535 TAG();
1610 PushStack(LoadLocal(current_position_)); 1536 PushStack(LoadLocal(current_position_));
1611 } 1537 }
1612 1538
1613 1539
1614 void IRRegExpMacroAssembler::PushRegister(intptr_t reg) { 1540 void IRRegExpMacroAssembler::PushRegister(intptr_t reg) {
1615 TAG(); 1541 TAG();
1616 // TODO(zerny): Refactor PushStack so it can be reused here. 1542 // TODO(zerny): Refactor PushStack so it can be reused here.
1617 PushArgumentInstr* stack_push = PushLocal(stack_); 1543 PushArgumentInstr* stack_push = PushLocal(stack_);
1618 PushArgumentInstr* stack_pointer_push = PushLocal(stack_pointer_); 1544 PushArgumentInstr* stack_pointer_push = PushLocal(stack_pointer_);
1619 StoreLocal(stack_pointer_, 1545 StoreLocal(stack_pointer_, Bind(Add(stack_pointer_push,
1620 Bind(Add(stack_pointer_push, 1546 PushArgument(Bind(Uint64Constant(1))))));
1621 PushArgument(Bind(Uint64Constant(1))))));
1622 stack_pointer_push = PushLocal(stack_pointer_); 1547 stack_pointer_push = PushLocal(stack_pointer_);
1623 // TODO(zerny): bind value and push could break stack discipline. 1548 // TODO(zerny): bind value and push could break stack discipline.
1624 PushArgumentInstr* value_push = PushArgument(LoadRegister(reg)); 1549 PushArgumentInstr* value_push = PushArgument(LoadRegister(reg));
1625 Do(InstanceCall(InstanceCallDescriptor::FromToken(Token::kASSIGN_INDEX), 1550 Do(InstanceCall(InstanceCallDescriptor::FromToken(Token::kASSIGN_INDEX),
1626 stack_push, 1551 stack_push, stack_pointer_push, value_push));
1627 stack_pointer_push,
1628 value_push));
1629 CheckStackLimit(); 1552 CheckStackLimit();
1630 } 1553 }
1631 1554
1632 1555
1633 // Checks that (stack.capacity - stack_limit_slack) > stack_pointer. 1556 // Checks that (stack.capacity - stack_limit_slack) > stack_pointer.
1634 // This ensures that up to stack_limit_slack stack pushes can be 1557 // This ensures that up to stack_limit_slack stack pushes can be
1635 // done without exhausting the stack space. If the check fails the 1558 // done without exhausting the stack space. If the check fails the
1636 // stack will be grown. 1559 // stack will be grown.
1637 void IRRegExpMacroAssembler::CheckStackLimit() { 1560 void IRRegExpMacroAssembler::CheckStackLimit() {
1638 TAG(); 1561 TAG();
1639 PushArgumentInstr* stack_push = PushLocal(stack_); 1562 PushArgumentInstr* stack_push = PushLocal(stack_);
1640 PushArgumentInstr* length_push = PushArgument(Bind(InstanceCall( 1563 PushArgumentInstr* length_push = PushArgument(
1641 InstanceCallDescriptor( 1564 Bind(InstanceCall(InstanceCallDescriptor(String::ZoneHandle(
1642 String::ZoneHandle(Field::GetterSymbol(Symbols::Length()))), 1565 Field::GetterSymbol(Symbols::Length()))),
1643 stack_push))); 1566 stack_push)));
1644 PushArgumentInstr* capacity_push = PushArgument(Bind(Sub( 1567 PushArgumentInstr* capacity_push = PushArgument(Bind(Sub(
1645 length_push, 1568 length_push, PushArgument(Bind(Uint64Constant(stack_limit_slack()))))));
1646 PushArgument(Bind(Uint64Constant(stack_limit_slack()))))));
1647 PushArgumentInstr* stack_pointer_push = PushLocal(stack_pointer_); 1569 PushArgumentInstr* stack_pointer_push = PushLocal(stack_pointer_);
1648 BranchInstr* branch = new(Z) BranchInstr( 1570 BranchInstr* branch =
1649 Comparison(kGT, capacity_push, stack_pointer_push)); 1571 new (Z) BranchInstr(Comparison(kGT, capacity_push, stack_pointer_push));
1650 CloseBlockWith(branch); 1572 CloseBlockWith(branch);
1651 1573
1652 BlockLabel grow_stack; 1574 BlockLabel grow_stack;
1653 BlockLabel fallthrough; 1575 BlockLabel fallthrough;
1654 *branch->true_successor_address() = 1576 *branch->true_successor_address() = TargetWithJoinGoto(fallthrough.block());
1655 TargetWithJoinGoto(fallthrough.block()); 1577 *branch->false_successor_address() = TargetWithJoinGoto(grow_stack.block());
1656 *branch->false_successor_address() =
1657 TargetWithJoinGoto(grow_stack.block());
1658 1578
1659 BindBlock(&grow_stack); 1579 BindBlock(&grow_stack);
1660 GrowStack(); 1580 GrowStack();
1661 1581
1662 BindBlock(&fallthrough); 1582 BindBlock(&fallthrough);
1663 } 1583 }
1664 1584
1665 1585
1666 void IRRegExpMacroAssembler::GrowStack() { 1586 void IRRegExpMacroAssembler::GrowStack() {
1667 TAG(); 1587 TAG();
1668 Value* cell = Bind(new(Z) ConstantInstr(stack_array_cell_)); 1588 Value* cell = Bind(new (Z) ConstantInstr(stack_array_cell_));
1669 StoreLocal(stack_, Bind(new(Z) GrowRegExpStackInstr(cell))); 1589 StoreLocal(stack_, Bind(new (Z) GrowRegExpStackInstr(cell)));
1670 } 1590 }
1671 1591
1672 1592
1673 void IRRegExpMacroAssembler::ReadCurrentPositionFromRegister(intptr_t reg) { 1593 void IRRegExpMacroAssembler::ReadCurrentPositionFromRegister(intptr_t reg) {
1674 TAG(); 1594 TAG();
1675 StoreLocal(current_position_, LoadRegister(reg)); 1595 StoreLocal(current_position_, LoadRegister(reg));
1676 } 1596 }
1677 1597
1678 // Resets the tip of the stack to the value stored in reg. 1598 // Resets the tip of the stack to the value stored in reg.
1679 void IRRegExpMacroAssembler::ReadStackPointerFromRegister(intptr_t reg) { 1599 void IRRegExpMacroAssembler::ReadStackPointerFromRegister(intptr_t reg) {
1680 TAG(); 1600 TAG();
1681 ASSERT(reg < registers_count_); 1601 ASSERT(reg < registers_count_);
1682 StoreLocal(stack_pointer_, LoadRegister(reg)); 1602 StoreLocal(stack_pointer_, LoadRegister(reg));
1683 } 1603 }
1684 1604
1685 void IRRegExpMacroAssembler::SetCurrentPositionFromEnd(intptr_t by) { 1605 void IRRegExpMacroAssembler::SetCurrentPositionFromEnd(intptr_t by) {
1686 TAG(); 1606 TAG();
1687 1607
1688 BlockLabel after_position; 1608 BlockLabel after_position;
1689 1609
1690 Definition* cur_pos_def = LoadLocal(current_position_); 1610 Definition* cur_pos_def = LoadLocal(current_position_);
1691 Definition* by_value_def = Int64Constant(-by); 1611 Definition* by_value_def = Int64Constant(-by);
1692 1612
1693 BranchOrBacktrack(Comparison(kGTE, cur_pos_def, by_value_def), 1613 BranchOrBacktrack(Comparison(kGTE, cur_pos_def, by_value_def),
1694 &after_position); 1614 &after_position);
1695 1615
(...skipping 17 matching lines...) Expand all
1713 1633
1714 1634
1715 bool IRRegExpMacroAssembler::Succeed() { 1635 bool IRRegExpMacroAssembler::Succeed() {
1716 TAG(); 1636 TAG();
1717 GoTo(success_block_); 1637 GoTo(success_block_);
1718 return global(); 1638 return global();
1719 } 1639 }
1720 1640
1721 1641
1722 void IRRegExpMacroAssembler::WriteCurrentPositionToRegister( 1642 void IRRegExpMacroAssembler::WriteCurrentPositionToRegister(
1723 intptr_t reg, intptr_t cp_offset) { 1643 intptr_t reg,
1644 intptr_t cp_offset) {
1724 TAG(); 1645 TAG();
1725 1646
1726 PushArgumentInstr* registers_push = PushLocal(registers_); 1647 PushArgumentInstr* registers_push = PushLocal(registers_);
1727 PushArgumentInstr* index_push = PushRegisterIndex(reg); 1648 PushArgumentInstr* index_push = PushRegisterIndex(reg);
1728 PushArgumentInstr* pos_push = PushLocal(current_position_); 1649 PushArgumentInstr* pos_push = PushLocal(current_position_);
1729 PushArgumentInstr* off_push = PushArgument(Bind(Int64Constant(cp_offset))); 1650 PushArgumentInstr* off_push = PushArgument(Bind(Int64Constant(cp_offset)));
1730 PushArgumentInstr* neg_off_push = PushArgument(Bind(Add(pos_push, off_push))); 1651 PushArgumentInstr* neg_off_push = PushArgument(Bind(Add(pos_push, off_push)));
1731 // Push the negative offset; these are converted to positive string positions 1652 // Push the negative offset; these are converted to positive string positions
1732 // within the success block. 1653 // within the success block.
1733 StoreRegister(registers_push, index_push, neg_off_push); 1654 StoreRegister(registers_push, index_push, neg_off_push);
1734 } 1655 }
1735 1656
1736 1657
1737 void IRRegExpMacroAssembler::ClearRegisters( 1658 void IRRegExpMacroAssembler::ClearRegisters(intptr_t reg_from,
1738 intptr_t reg_from, intptr_t reg_to) { 1659 intptr_t reg_to) {
1739 TAG(); 1660 TAG();
1740 1661
1741 ASSERT(reg_from <= reg_to); 1662 ASSERT(reg_from <= reg_to);
1742 1663
1743 // In order to clear registers to a final result value of -1, set them to 1664 // In order to clear registers to a final result value of -1, set them to
1744 // (-1 - string length), the offset of -1 from the end of the string. 1665 // (-1 - string length), the offset of -1 from the end of the string.
1745 1666
1746 for (intptr_t reg = reg_from; reg <= reg_to; reg++) { 1667 for (intptr_t reg = reg_from; reg <= reg_to; reg++) {
1747 PushArgumentInstr* registers_push = PushLocal(registers_); 1668 PushArgumentInstr* registers_push = PushLocal(registers_);
1748 PushArgumentInstr* index_push = PushRegisterIndex(reg); 1669 PushArgumentInstr* index_push = PushRegisterIndex(reg);
1749 PushArgumentInstr* minus_one_push = 1670 PushArgumentInstr* minus_one_push = PushArgument(Bind(Int64Constant(-1)));
1750 PushArgument(Bind(Int64Constant(-1)));
1751 PushArgumentInstr* length_push = PushLocal(string_param_length_); 1671 PushArgumentInstr* length_push = PushLocal(string_param_length_);
1752 PushArgumentInstr* value_push = 1672 PushArgumentInstr* value_push =
1753 PushArgument(Bind(Sub(minus_one_push, length_push))); 1673 PushArgument(Bind(Sub(minus_one_push, length_push)));
1754 StoreRegister(registers_push, index_push, value_push); 1674 StoreRegister(registers_push, index_push, value_push);
1755 } 1675 }
1756 } 1676 }
1757 1677
1758 1678
1759 void IRRegExpMacroAssembler::WriteStackPointerToRegister(intptr_t reg) { 1679 void IRRegExpMacroAssembler::WriteStackPointerToRegister(intptr_t reg) {
1760 TAG(); 1680 TAG();
(...skipping 10 matching lines...) Expand all
1771 1691
1772 void IRRegExpMacroAssembler::CheckPosition(intptr_t cp_offset, 1692 void IRRegExpMacroAssembler::CheckPosition(intptr_t cp_offset,
1773 BlockLabel* on_outside_input) { 1693 BlockLabel* on_outside_input) {
1774 TAG(); 1694 TAG();
1775 Definition* curpos_def = LoadLocal(current_position_); 1695 Definition* curpos_def = LoadLocal(current_position_);
1776 Definition* cp_off_def = Int64Constant(-cp_offset); 1696 Definition* cp_off_def = Int64Constant(-cp_offset);
1777 1697
1778 // If (current_position_ < -cp_offset), we are in bounds. 1698 // If (current_position_ < -cp_offset), we are in bounds.
1779 // Remember, current_position_ is a negative offset from the string end. 1699 // Remember, current_position_ is a negative offset from the string end.
1780 1700
1781 BranchOrBacktrack(Comparison(kGTE, curpos_def, cp_off_def), 1701 BranchOrBacktrack(Comparison(kGTE, curpos_def, cp_off_def), on_outside_input);
1782 on_outside_input);
1783 } 1702 }
1784 1703
1785 1704
1786 void IRRegExpMacroAssembler::BranchOrBacktrack( 1705 void IRRegExpMacroAssembler::BranchOrBacktrack(ComparisonInstr* comparison,
1787 ComparisonInstr* comparison, 1706 BlockLabel* true_successor) {
1788 BlockLabel* true_successor) {
1789 if (comparison == NULL) { // No condition 1707 if (comparison == NULL) { // No condition
1790 if (true_successor == NULL) { 1708 if (true_successor == NULL) {
1791 Backtrack(); 1709 Backtrack();
1792 return; 1710 return;
1793 } 1711 }
1794 GoTo(true_successor); 1712 GoTo(true_successor);
1795 return; 1713 return;
1796 } 1714 }
1797 1715
1798 // If no successor block has been passed in, backtrack. 1716 // If no successor block has been passed in, backtrack.
1799 JoinEntryInstr* true_successor_block = backtrack_block_; 1717 JoinEntryInstr* true_successor_block = backtrack_block_;
1800 if (true_successor != NULL) { 1718 if (true_successor != NULL) {
1801 true_successor->SetLinked(); 1719 true_successor->SetLinked();
1802 true_successor_block = true_successor->block(); 1720 true_successor_block = true_successor->block();
1803 } 1721 }
1804 ASSERT(true_successor_block != NULL); 1722 ASSERT(true_successor_block != NULL);
1805 1723
1806 // If the condition is not true, fall through to a new block. 1724 // If the condition is not true, fall through to a new block.
1807 BlockLabel fallthrough; 1725 BlockLabel fallthrough;
1808 1726
1809 BranchInstr* branch = new(Z) BranchInstr(comparison); 1727 BranchInstr* branch = new (Z) BranchInstr(comparison);
1810 *branch->true_successor_address() = 1728 *branch->true_successor_address() = TargetWithJoinGoto(true_successor_block);
1811 TargetWithJoinGoto(true_successor_block); 1729 *branch->false_successor_address() = TargetWithJoinGoto(fallthrough.block());
1812 *branch->false_successor_address() =
1813 TargetWithJoinGoto(fallthrough.block());
1814 1730
1815 CloseBlockWith(branch); 1731 CloseBlockWith(branch);
1816 BindBlock(&fallthrough); 1732 BindBlock(&fallthrough);
1817 } 1733 }
1818 1734
1819 1735
1820 TargetEntryInstr* IRRegExpMacroAssembler::TargetWithJoinGoto( 1736 TargetEntryInstr* IRRegExpMacroAssembler::TargetWithJoinGoto(
1821 JoinEntryInstr* dst) { 1737 JoinEntryInstr* dst) {
1822 TargetEntryInstr* target = new(Z) TargetEntryInstr( 1738 TargetEntryInstr* target =
1823 block_id_.Alloc(), kInvalidTryIndex); 1739 new (Z) TargetEntryInstr(block_id_.Alloc(), kInvalidTryIndex);
1824 blocks_.Add(target); 1740 blocks_.Add(target);
1825 1741
1826 target->AppendInstruction(new(Z) GotoInstr(dst)); 1742 target->AppendInstruction(new (Z) GotoInstr(dst));
1827 1743
1828 return target; 1744 return target;
1829 } 1745 }
1830 1746
1831 1747
1832 IndirectEntryInstr* IRRegExpMacroAssembler::IndirectWithJoinGoto( 1748 IndirectEntryInstr* IRRegExpMacroAssembler::IndirectWithJoinGoto(
1833 JoinEntryInstr* dst) { 1749 JoinEntryInstr* dst) {
1834 IndirectEntryInstr* target = new(Z) IndirectEntryInstr( 1750 IndirectEntryInstr* target = new (Z) IndirectEntryInstr(
1835 block_id_.Alloc(), indirect_id_.Alloc(), kInvalidTryIndex); 1751 block_id_.Alloc(), indirect_id_.Alloc(), kInvalidTryIndex);
1836 blocks_.Add(target); 1752 blocks_.Add(target);
1837 1753
1838 target->AppendInstruction(new(Z) GotoInstr(dst)); 1754 target->AppendInstruction(new (Z) GotoInstr(dst));
1839 1755
1840 return target; 1756 return target;
1841 } 1757 }
1842 1758
1843 1759
1844 void IRRegExpMacroAssembler::CheckPreemption() { 1760 void IRRegExpMacroAssembler::CheckPreemption() {
1845 TAG(); 1761 TAG();
1846 AppendInstruction(new(Z) CheckStackOverflowInstr( 1762 AppendInstruction(new (Z)
1847 TokenPosition::kNoSource, 0)); 1763 CheckStackOverflowInstr(TokenPosition::kNoSource, 0));
1848 } 1764 }
1849 1765
1850 1766
1851 Definition* IRRegExpMacroAssembler::Add( 1767 Definition* IRRegExpMacroAssembler::Add(PushArgumentInstr* lhs,
1852 PushArgumentInstr* lhs, 1768 PushArgumentInstr* rhs) {
1853 PushArgumentInstr* rhs) {
1854 return InstanceCall(InstanceCallDescriptor::FromToken(Token::kADD), lhs, rhs); 1769 return InstanceCall(InstanceCallDescriptor::FromToken(Token::kADD), lhs, rhs);
1855 } 1770 }
1856 1771
1857 1772
1858 Definition* IRRegExpMacroAssembler::Sub( 1773 Definition* IRRegExpMacroAssembler::Sub(PushArgumentInstr* lhs,
1859 PushArgumentInstr* lhs, 1774 PushArgumentInstr* rhs) {
1860 PushArgumentInstr* rhs) {
1861 return InstanceCall(InstanceCallDescriptor::FromToken(Token::kSUB), lhs, rhs); 1775 return InstanceCall(InstanceCallDescriptor::FromToken(Token::kSUB), lhs, rhs);
1862 } 1776 }
1863 1777
1864 1778
1865 void IRRegExpMacroAssembler::LoadCurrentCharacterUnchecked( 1779 void IRRegExpMacroAssembler::LoadCurrentCharacterUnchecked(
1866 intptr_t cp_offset, intptr_t characters) { 1780 intptr_t cp_offset,
1781 intptr_t characters) {
1867 TAG(); 1782 TAG();
1868 1783
1869 ASSERT(characters == 1 || CanReadUnaligned()); 1784 ASSERT(characters == 1 || CanReadUnaligned());
1870 if (mode_ == ASCII) { 1785 if (mode_ == ASCII) {
1871 ASSERT(characters == 1 || characters == 2 || characters == 4); 1786 ASSERT(characters == 1 || characters == 2 || characters == 4);
1872 } else { 1787 } else {
1873 ASSERT(mode_ == UC16); 1788 ASSERT(mode_ == UC16);
1874 ASSERT(characters == 1 || characters == 2); 1789 ASSERT(characters == 1 || characters == 2);
1875 } 1790 }
1876 1791
1877 // Calculate the addressed string index as: 1792 // Calculate the addressed string index as:
1878 // cp_offset + current_position_ + string_param_length_ 1793 // cp_offset + current_position_ + string_param_length_
1879 // TODO(zerny): Avoid generating 'add' instance-calls here. 1794 // TODO(zerny): Avoid generating 'add' instance-calls here.
1880 PushArgumentInstr* off_arg = 1795 PushArgumentInstr* off_arg = PushArgument(Bind(Int64Constant(cp_offset)));
1881 PushArgument(Bind(Int64Constant(cp_offset))); 1796 PushArgumentInstr* pos_arg = PushArgument(BindLoadLocal(*current_position_));
1882 PushArgumentInstr* pos_arg = 1797 PushArgumentInstr* off_pos_arg = PushArgument(Bind(Add(off_arg, pos_arg)));
1883 PushArgument(BindLoadLocal(*current_position_));
1884 PushArgumentInstr* off_pos_arg =
1885 PushArgument(Bind(Add(off_arg, pos_arg)));
1886 PushArgumentInstr* len_arg = 1798 PushArgumentInstr* len_arg =
1887 PushArgument(BindLoadLocal(*string_param_length_)); 1799 PushArgument(BindLoadLocal(*string_param_length_));
1888 // Index is stored in a temporary local so that we can later load it safely. 1800 // Index is stored in a temporary local so that we can later load it safely.
1889 StoreLocal(index_temp_, Bind(Add(off_pos_arg, len_arg))); 1801 StoreLocal(index_temp_, Bind(Add(off_pos_arg, len_arg)));
1890 1802
1891 // Load and store the code units. 1803 // Load and store the code units.
1892 Value* code_unit_value = LoadCodeUnitsAt(index_temp_, characters); 1804 Value* code_unit_value = LoadCodeUnitsAt(index_temp_, characters);
1893 StoreLocal(current_character_, code_unit_value); 1805 StoreLocal(current_character_, code_unit_value);
1894 PRINT(PushLocal(current_character_)); 1806 PRINT(PushLocal(current_character_));
1895 } 1807 }
(...skipping 18 matching lines...) Expand all
1914 } else if (specialization_cid_ == kExternalTwoByteStringCid) { 1826 } else if (specialization_cid_ == kExternalTwoByteStringCid) {
1915 external_offset = ExternalTwoByteString::external_data_offset(); 1827 external_offset = ExternalTwoByteString::external_data_offset();
1916 data_offset = RawExternalTwoByteString::ExternalData::data_offset(); 1828 data_offset = RawExternalTwoByteString::ExternalData::data_offset();
1917 } else { 1829 } else {
1918 UNREACHABLE(); 1830 UNREACHABLE();
1919 } 1831 }
1920 // This pushes untagged values on the stack which are immediately consumed: 1832 // This pushes untagged values on the stack which are immediately consumed:
1921 // the first value is consumed to obtain the second value which is consumed 1833 // the first value is consumed to obtain the second value which is consumed
1922 // by LoadCodeUnitsAtInstr below. 1834 // by LoadCodeUnitsAtInstr below.
1923 Value* external_val = 1835 Value* external_val =
1924 Bind(new(Z) LoadUntaggedInstr(pattern_val, external_offset)); 1836 Bind(new (Z) LoadUntaggedInstr(pattern_val, external_offset));
1925 pattern_val = 1837 pattern_val = Bind(new (Z) LoadUntaggedInstr(external_val, data_offset));
1926 Bind(new(Z) LoadUntaggedInstr(external_val, data_offset));
1927 } 1838 }
1928 1839
1929 // Here pattern_val might be untagged so this must not trigger a GC. 1840 // Here pattern_val might be untagged so this must not trigger a GC.
1930 Value* index_val = BindLoadLocal(*index); 1841 Value* index_val = BindLoadLocal(*index);
1931 1842
1932 return Bind(new(Z) LoadCodeUnitsInstr( 1843 return Bind(new (Z) LoadCodeUnitsInstr(pattern_val, index_val, characters,
1933 pattern_val, 1844 specialization_cid_,
1934 index_val, 1845 TokenPosition::kNoSource));
1935 characters,
1936 specialization_cid_,
1937 TokenPosition::kNoSource));
1938 } 1846 }
1939 1847
1940 1848
1941 #undef __ 1849 #undef __
1942 1850
1943 } // namespace dart 1851 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/regexp_assembler_ir.h ('k') | runtime/vm/regexp_ast.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698