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

Side by Side Diff: src/regexp-macro-assembler-re2k.cc

Issue 10830: * We want to be able to find atoms and character classes without advancing th... (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 10 matching lines...) Expand all
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #include "v8.h" 28 #include "v8.h"
29 #include "ast.h" 29 #include "ast.h"
30 #include "bytecodes-re2k.h" 30 #include "bytecodes-re2k.h"
31 #include "assembler-re2k.h"
32 #include "assembler-re2k-inl.h"
31 #include "regexp-macro-assembler.h" 33 #include "regexp-macro-assembler.h"
32 #include "regexp-macro-assembler-re2k.h" 34 #include "regexp-macro-assembler-re2k.h"
33 35
34 36
37 namespace v8 { namespace internal {
38
39
40 RegExpMacroAssemblerRe2k::~RegExpMacroAssemblerRe2k() {
41 }
42
43
44 RegExpMacroAssemblerRe2k::Re2kImplementation
45 RegExpMacroAssemblerRe2k::Implementation() {
46 return kBytecodeImplementation;
47 }
48
49
50 void RegExpMacroAssemblerRe2k::Bind(Label* l) {
51 assembler_->Bind(l);
52 }
53
54
55 void RegExpMacroAssemblerRe2k::EmitOrLink(Label* l) {
56 assembler_->EmitOrLink(l);
57 }
58
59
60 void RegExpMacroAssemblerRe2k::PopRegister(int register_index) {
61 assembler_->PopRegister(register_index);
62 }
63
64
65 void RegExpMacroAssemblerRe2k::PushRegister(int register_index) {
66 assembler_->PushRegister(register_index);
67 }
68
69
70 void RegExpMacroAssemblerRe2k::WriteCurrentPositionToRegister(
71 int register_index) {
72 assembler_->SetRegisterToCurrentPosition(register_index);
73 }
74
75
76 void RegExpMacroAssemblerRe2k::SetRegister(int register_index, int to) {
77 assembler_->SetRegister(register_index, to);
78 }
79
80
81 void RegExpMacroAssemblerRe2k::AdvanceRegister(int register_index, int by) {
82 assembler_->AdvanceRegister(register_index, by);
83 }
84
85
86 void RegExpMacroAssemblerRe2k::PopCurrentPosition() {
87 assembler_->PopCurrentPosition();
88 }
89
90
91 void RegExpMacroAssemblerRe2k::PushCurrentPosition() {
92 assembler_->PushCurrentPosition();
93 }
94
95
96 void RegExpMacroAssemblerRe2k::Backtrack() {
97 assembler_->PopBacktrack();
98 }
99
100
101 void RegExpMacroAssemblerRe2k::GoTo(Label* l) {
102 assembler_->GoTo(l);
103 }
104
105
106 void RegExpMacroAssemblerRe2k::PushBacktrack(Label* l) {
107 assembler_->PushBacktrack(l);
108 }
109
110
111 void RegExpMacroAssemblerRe2k::Succeed() {
112 assembler_->Succeed();
113 }
114
115
116 void RegExpMacroAssemblerRe2k::Fail() {
117 assembler_->Fail();
118 }
119
120
121 void RegExpMacroAssemblerRe2k::AdvanceCurrentPosition(int by) {
122 assembler_->AdvanceCP(by);
123 }
124
125
126 static void TwoWayCharacterClass(
127 Re2kAssembler* assembler,
128 RegExpCharacterClass* char_class,
129 Label* on_match,
130 Label* on_mismatch) {
131 ZoneList<CharacterRange>* ranges = char_class->ranges();
132 int range_count = ranges->length();
133 if (!char_class->is_negated()) {
134 for (int i = 0; i < range_count; i++) {
135 CharacterRange& range = ranges->at(i);
136 assembler->CheckRange(range.from(), range.to(), on_match);
137 }
138 if (on_mismatch == NULL) {
139 assembler->PopBacktrack();
140 } else {
141 assembler->GoTo(on_mismatch);
142 }
143 } else { // range is negated.
144 if (range_count == 0) {
145 assembler->GoTo(on_match);
146 } else {
147 CharacterRange& previous = ranges->at(0);
148 if (previous.from() > 0) {
149 assembler->CheckRange(0, previous.from() - 1, on_match);
150 }
151 for (int i = 1; i < range_count; i++) {
152 CharacterRange& range = ranges->at(i);
153 if (previous.to() < range.from() - 1) {
154 assembler->CheckRange(previous.to() + 1, range.from() - 1, on_match);
155 }
156 previous = range;
157 }
158 if (previous.to() < 65535) {
159 assembler->CheckRange(previous.to() + 1, 65535, on_match);
160 }
161 }
162 }
163 }
164
165
166 void RegExpMacroAssemblerRe2k::CheckCurrentPosition(
167 int register_index,
168 Label* on_equal) {
169 // TODO(erikcorry): Implement.
170 UNREACHABLE();
171 }
172
173
174 void RegExpMacroAssemblerRe2k::CheckCharacterClass(
175 RegExpCharacterClass* char_class,
176 int cp_offset,
177 Label* on_failure) {
178 assembler_->LoadCurrentChar(cp_offset, on_failure);
179 if (!char_class->is_negated() &&
180 char_class->ranges()->length() == 1 &&
181 on_failure != NULL) {
182 // This is the simple case where the char class has one range and we want to
183 // fall through if it matches.
184 CharacterRange& range = char_class->ranges()->at(0);
185 assembler_->CheckNotRange(range.from(), range.to(), on_failure);
186 } else {
187 Label on_success;
188 TwoWayCharacterClass(assembler_, char_class, &on_success, on_failure);
189 assembler_->Bind(&on_success);
190 }
191 }
192
193
194 void RegExpMacroAssemblerRe2k::CheckBitmap(uc16 start,
195 Label* bitmap,
196 Label* on_zero) {
197 assembler_->LookupMap1(start, bitmap, on_zero);
198 }
199
200
201 void RegExpMacroAssemblerRe2k::DispatchHalfNibbleMap(
202 uc16 start,
203 Label* half_nibble_map,
204 const Vector<Label*>& table) {
205 assembler_->LookupMap2(start, half_nibble_map, table);
206 }
207
208
209 void RegExpMacroAssemblerRe2k::DispatchByteMap(uc16 start,
210 Label* byte_map,
211 const Vector<Label*>& table) {
212 assembler_->LookupMap8(start, byte_map, table);
213 }
214
215
216 void RegExpMacroAssemblerRe2k::DispatchHighByteMap(
217 byte start,
218 Label* byte_map,
219 const Vector<Label*>& table) {
220 assembler_->LookupHighMap8(start, byte_map, table);
221 }
222
223
224 void RegExpMacroAssemblerRe2k::CheckCharacters(
225 Vector<const uc16> str,
226 int cp_offset,
227 Label* on_failure) {
228 for (int i = str.length() - 1; i >= 0; i--) {
229 assembler_->LoadCurrentChar(cp_offset + i, on_failure);
230 assembler_->CheckChar(str[i], on_failure);
231 }
232 }
233
234
235 void RegExpMacroAssemblerRe2k::IfRegisterLT(int register_index,
236 int comparand,
237 Label* if_less_than) {
238 ASSERT(comparand >= 0 && comparand <= 65535);
239 assembler_->CheckRegisterLT(register_index, comparand, if_less_than);
240 }
241
242
243 void RegExpMacroAssemblerRe2k::IfRegisterGE(int register_index,
244 int comparand,
245 Label* if_greater_or_equal) {
246 ASSERT(comparand >= 0 && comparand <= 65535);
247 assembler_->CheckRegisterGE(register_index, comparand, if_greater_or_equal);
248 }
249
250
251 Handle<Object> RegExpMacroAssemblerRe2k::GetCode() {
252 Handle<ByteArray> array = Factory::NewByteArray(assembler_->length());
253 assembler_->Copy(array->GetDataStartAddress());
254 return array;
255 }
256
257 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698