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

Side by Side Diff: src/interpreter-re2k.cc

Issue 11228: * No failures on our own tests.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/regexp2000/
Patch Set: Created 12 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2008 the V8 project authors. All rights reserved. 1 // Copyright 2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 21 matching lines...) Expand all
32 #include "utils.h" 32 #include "utils.h"
33 #include "ast.h" 33 #include "ast.h"
34 #include "bytecodes-re2k.h" 34 #include "bytecodes-re2k.h"
35 #include "interpreter-re2k.h" 35 #include "interpreter-re2k.h"
36 36
37 37
38 namespace v8 { namespace internal { 38 namespace v8 { namespace internal {
39 39
40 40
41 #ifdef DEBUG 41 #ifdef DEBUG
42 # define BYTECODE(name) break; \ 42 # define BYTECODE(name) break; \
Christian Plesner Hansen 2008/11/18 14:07:41 I would prefer if the breaks were written explicit
43 case BC_##name: \ 43 case BC_##name: \
44 if (FLAG_trace_regexp_bytecodes) { \ 44 if (FLAG_trace_regexp_bytecodes) { \
Christian Plesner Hansen 2008/11/18 14:07:41 Couldn't this be factored into a function rather t
45 PrintF("pc = %d, current = %d, bc = " \ 45 PrintF("pc = %02x, sp = %d, current = %d, bc = " \
46 #name "\n", pc - code_base, current); \ 46 #name, \
47 pc - code_base, \
48 backtrack_sp - backtrack_stack, \
49 current); \
50 for (int _i = 1; _i < BC_##name##_LENGTH; _i++) { \
51 printf(", %02x", pc[_i]); \
52 } \
53 printf("\n"); \
47 } 54 }
48 #else 55 #else
49 # define BYTECODE(name) break; \ 56 # define BYTECODE(name) break; \
50 case BC_##name: 57 case BC_##name:
51 #endif 58 #endif
52 59
53 60
54 61
55 static bool RawMatch(const byte* code_base, 62 static bool RawMatch(const byte* code_base,
56 Vector<const uc16> subject, 63 Vector<const uc16> subject,
57 int* registers, 64 int* registers,
58 int current) { 65 int current) {
59 const byte* pc = code_base; 66 const byte* pc = code_base;
60 int backtrack_stack[1000]; 67 int backtrack_stack[10000];
61 int backtrack_stack_space = 1000; 68 int backtrack_stack_space = 10000;
62 int* backtrack_sp = backtrack_stack; 69 int* backtrack_sp = backtrack_stack;
63 int current_char = -1; 70 int current_char = -1;
64 #ifdef DEBUG 71 #ifdef DEBUG
65 if (FLAG_trace_regexp_bytecodes) { 72 if (FLAG_trace_regexp_bytecodes) {
66 PrintF("\n\nStart bytecode interpreter\n\n"); 73 PrintF("\n\nStart bytecode interpreter\n\n");
67 } 74 }
68 #endif 75 #endif
69 while (true) { 76 while (true) {
70 switch (*pc) { 77 switch (*pc) {
71 BYTECODE(BREAK) 78 BYTECODE(BREAK)
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 } 146 }
140 } 147 }
141 BYTECODE(CHECK_NOT_CHAR) { 148 BYTECODE(CHECK_NOT_CHAR) {
142 int c = Load16(pc + 1); 149 int c = Load16(pc + 1);
143 if (c == current_char) { 150 if (c == current_char) {
144 pc = code_base + Load32(pc + 3); 151 pc = code_base + Load32(pc + 3);
145 } else { 152 } else {
146 pc += 7; 153 pc += 7;
147 } 154 }
148 } 155 }
149 BYTECODE(CHECK_RANGE) { 156 BYTECODE(CHECK_LT) {
150 int start = Load16(pc + 1); 157 int limit = Load16(pc + 1);
151 int end = Load16(pc + 3); 158 if (current_char < limit) {
152 if (current_char < start || current_char > end) { 159 pc = code_base + Load32(pc + 3);
153 pc = code_base + Load32(pc + 5);
154 } else { 160 } else {
155 pc += 9; 161 pc += 7;
156 } 162 }
157 } 163 }
158 BYTECODE(CHECK_NOT_RANGE) { 164 BYTECODE(CHECK_GT) {
159 int start = Load16(pc + 1); 165 int limit = Load16(pc + 1);
160 int end = Load16(pc + 3); 166 if (current_char > limit) {
161 if (current_char >= start && current_char <= end) { 167 pc = code_base + Load32(pc + 3);
162 pc = code_base + Load32(pc + 5);
163 } else { 168 } else {
164 pc += 9; 169 pc += 7;
Christian Plesner Hansen 2008/11/18 14:07:41 I would suggest using constants for opcode length
165 } 170 }
166 } 171 }
167 BYTECODE(CHECK_REGISTER_LT) 172 BYTECODE(CHECK_REGISTER_LT)
168 if (registers[pc[1]] < Load16(pc + 2)) { 173 if (registers[pc[1]] < Load16(pc + 2)) {
169 pc = code_base + Load32(pc + 4); 174 pc = code_base + Load32(pc + 4);
170 } else { 175 } else {
171 pc += 8; 176 pc += 8;
172 } 177 }
173 BYTECODE(CHECK_REGISTER_GE) 178 BYTECODE(CHECK_REGISTER_GE)
174 if (registers[pc[1]] >= Load16(pc + 2)) { 179 if (registers[pc[1]] >= Load16(pc + 2)) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 break; // Last one doesn't have break in macro. 237 break; // Last one doesn't have break in macro.
233 default: 238 default:
234 UNREACHABLE(); 239 UNREACHABLE();
235 break; 240 break;
236 } 241 }
237 } 242 }
238 } 243 }
239 244
240 245
241 bool Re2kInterpreter::Match(Handle<ByteArray> code_array, 246 bool Re2kInterpreter::Match(Handle<ByteArray> code_array,
242 Handle<String> subject, 247 Handle<String> subject16,
243 int* registers, 248 int* registers,
244 int start_position) { 249 int start_position) {
250 ASSERT(StringShape(*subject16).IsTwoByteRepresentation());
251 ASSERT(subject16->IsFlat(StringShape(*subject16)));
252
253
254 AssertNoAllocation a;
245 const byte* code_base = code_array->GetDataStartAddress(); 255 const byte* code_base = code_array->GetDataStartAddress();
246 ASSERT(subject->IsFlat(StringShape(*subject)));
247 Handle<String> flat_two_byte = RegExpImpl::CachedStringToTwoByte(subject);
248 ASSERT(StringShape(*flat_two_byte).IsTwoByteRepresentation());
249 return RawMatch(code_base, 256 return RawMatch(code_base,
250 flat_two_byte->ToUC16Vector(), 257 Vector<const uc16>(subject16->GetTwoByteData(),
258 subject16->length()),
251 registers, 259 registers,
252 start_position); 260 start_position);
253 } 261 }
254 262
255 } } // namespace v8::internal 263 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698