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

Side by Side Diff: src/assembler-irregexp.cc

Issue 12427: Merge regexp2000 back into bleeding_edge (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 12 years 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
(Empty)
1 // Copyright 2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
27
28 // A light-weight assembler for the Irregexp byte code.
29
30
31 #include "v8.h"
32 #include "ast.h"
33 #include "bytecodes-irregexp.h"
34 #include "assembler-irregexp.h"
35
36 #include "assembler-irregexp-inl.h"
37
38
39 namespace v8 { namespace internal {
40
41
42 IrregexpAssembler::IrregexpAssembler(Vector<byte> buffer)
43 : buffer_(buffer),
Mads Ager (chromium) 2008/11/25 21:09:41 4 space indent of the initializer list?
Erik Corry 2008/11/26 12:18:36 Fixed.
44 pc_(0),
45 own_buffer_(false) {
46 }
47
48
49 IrregexpAssembler::~IrregexpAssembler() {
50 if (own_buffer_) {
51 buffer_.Dispose();
52 }
53 }
54
55
56 void IrregexpAssembler::PushCurrentPosition(int cp_offset) {
57 ASSERT(cp_offset >= 0);
58 Emit(BC_PUSH_CP);
59 Emit32(cp_offset);
60 }
61
62
63 void IrregexpAssembler::PushBacktrack(Label* l) {
64 Emit(BC_PUSH_BT);
65 EmitOrLink(l);
66 }
67
68
69 void IrregexpAssembler::PushRegister(int index) {
70 ASSERT(index >= 0);
71 Emit(BC_PUSH_REGISTER);
72 Emit(index);
73 }
74
75
76 void IrregexpAssembler::WriteCurrentPositionToRegister(int index,
77 int cp_offset) {
78 ASSERT(cp_offset >= 0);
79 ASSERT(index >= 0);
80 Emit(BC_SET_REGISTER_TO_CP);
81 Emit(index);
82 Emit32(cp_offset);
83 }
84
85
86 void IrregexpAssembler::ReadCurrentPositionFromRegister(int index) {
87 ASSERT(index >= 0);
88 Emit(BC_SET_CP_TO_REGISTER);
89 Emit(index);
90 }
91
92
93 void IrregexpAssembler::WriteStackPointerToRegister(int index) {
94 ASSERT(index >= 0);
95 Emit(BC_SET_REGISTER_TO_SP);
96 Emit(index);
97 }
98
99
100 void IrregexpAssembler::ReadStackPointerFromRegister(int index) {
101 ASSERT(index >= 0);
102 Emit(BC_SET_SP_TO_REGISTER);
103 Emit(index);
104 }
105
106
107 void IrregexpAssembler::SetRegister(int index, int value) {
108 ASSERT(index >= 0);
109 Emit(BC_SET_REGISTER);
110 Emit(index);
111 Emit32(value);
112 }
113
114
115 void IrregexpAssembler::AdvanceRegister(int index, int by) {
116 ASSERT(index >= 0);
117 Emit(BC_ADVANCE_REGISTER);
118 Emit(index);
119 Emit32(by);
120 }
121
122
123 void IrregexpAssembler::PopCurrentPosition() {
124 Emit(BC_POP_CP);
125 }
126
127
128 void IrregexpAssembler::PopBacktrack() {
129 Emit(BC_POP_BT);
130 }
131
132
133 void IrregexpAssembler::PopRegister(int index) {
134 Emit(BC_POP_REGISTER);
135 Emit(index);
136 }
137
138
139 void IrregexpAssembler::Fail() {
140 Emit(BC_FAIL);
141 }
142
143
144 void IrregexpAssembler::Break() {
145 Emit(BC_BREAK);
146 }
147
148
149 void IrregexpAssembler::Succeed() {
150 Emit(BC_SUCCEED);
151 }
152
153
154 void IrregexpAssembler::Bind(Label* l) {
155 ASSERT(!l->is_bound());
156 if (l->is_linked()) {
157 int pos = l->pos();
158 while (pos != 0) {
159 int fixup = pos;
160 pos = Load32(buffer_.start() + fixup);
161 Store32(buffer_.start() + fixup, pc_);
162 }
163 }
164 l->bind_to(pc_);
165 }
166
167
168 void IrregexpAssembler::AdvanceCP(int cp_offset) {
169 Emit(BC_ADVANCE_CP);
170 Emit32(cp_offset);
171 }
172
173
174 void IrregexpAssembler::GoTo(Label* l) {
175 Emit(BC_GOTO);
176 EmitOrLink(l);
177 }
178
179
180 void IrregexpAssembler::LoadCurrentChar(int cp_offset, Label* on_end) {
181 Emit(BC_LOAD_CURRENT_CHAR);
182 Emit32(cp_offset);
183 EmitOrLink(on_end);
184 }
185
186
187 void IrregexpAssembler::CheckCharacter(uc16 c, Label* on_match) {
188 Emit(BC_CHECK_CHAR);
189 Emit16(c);
190 EmitOrLink(on_match);
191 }
192
193
194 void IrregexpAssembler::CheckNotCharacter(uc16 c, Label* on_mismatch) {
195 Emit(BC_CHECK_NOT_CHAR);
196 Emit16(c);
197 EmitOrLink(on_mismatch);
198 }
199
200 void IrregexpAssembler::OrThenCheckNotCharacter(uc16 c,
201 uc16 mask,
202 Label* on_mismatch) {
203 Emit(BC_OR_CHECK_NOT_CHAR);
204 Emit16(c);
205 Emit16(mask);
206 EmitOrLink(on_mismatch);
207 }
208
209
210 void IrregexpAssembler::MinusOrThenCheckNotCharacter(uc16 c,
211 uc16 mask,
212 Label* on_mismatch) {
213 Emit(BC_MINUS_OR_CHECK_NOT_CHAR);
214 Emit16(c);
215 Emit16(mask);
216 EmitOrLink(on_mismatch);
217 }
218
219
220 void IrregexpAssembler::CheckCharacterLT(uc16 limit, Label* on_less) {
221 Emit(BC_CHECK_LT);
222 Emit16(limit);
223 EmitOrLink(on_less);
224 }
225
226
227 void IrregexpAssembler::CheckCharacterGT(uc16 limit, Label* on_greater) {
228 Emit(BC_CHECK_GT);
229 Emit16(limit);
230 EmitOrLink(on_greater);
231 }
232
233
234 void IrregexpAssembler::CheckNotBackReference(int capture_index,
235 Label* on_mismatch) {
Mads Ager (chromium) 2008/11/25 21:09:41 Identation is off here.
Erik Corry 2008/11/26 12:18:36 Fixed.
236 Emit(BC_CHECK_NOT_BACK_REF);
237 Emit(capture_index);
238 EmitOrLink(on_mismatch);
239 }
240
241
242 void IrregexpAssembler::CheckRegister(int byte_code,
243 int reg_index,
244 uint16_t vs,
245 Label* on_true) {
246 Emit(byte_code);
247 Emit(reg_index);
248 Emit16(vs);
249 EmitOrLink(on_true);
250 }
251
252
253 void IrregexpAssembler::CheckRegisterLT(int reg_index,
254 uint16_t vs,
255 Label* on_less_than) {
256 CheckRegister(BC_CHECK_REGISTER_LT, reg_index, vs, on_less_than);
257 }
258
259
260 void IrregexpAssembler::CheckRegisterGE(int reg_index,
261 uint16_t vs,
262 Label* on_greater_than_equal) {
263 CheckRegister(BC_CHECK_REGISTER_GE, reg_index, vs, on_greater_than_equal);
264 }
265
266
267 void IrregexpAssembler::LookupMap1(uc16 start, Label* bit_map, Label* on_zero) {
268 Emit(BC_LOOKUP_MAP1);
269 Emit16(start);
270 EmitOrLink(bit_map);
271 EmitOrLink(on_zero);
272 }
273
274
275 void IrregexpAssembler::LookupMap2(uc16 start,
276 Label* half_nibble_map,
277 const Vector<Label*>& table) {
278 Emit(BC_LOOKUP_MAP2);
279 Emit16(start);
280 EmitOrLink(half_nibble_map);
281 ASSERT(table.length() > 0);
282 ASSERT(table.length() <= 4);
283 for (int i = 0; i < table.length(); i++) {
284 EmitOrLink(table[i]);
285 }
286 }
287
288
289 void IrregexpAssembler::LookupMap8(uc16 start,
290 Label* byte_map,
291 const Vector<Label*>& table) {
292 Emit(BC_LOOKUP_MAP8);
293 Emit16(start);
294 EmitOrLink(byte_map);
295 ASSERT(table.length() > 0);
296 ASSERT(table.length() <= 256);
297 for (int i = 0; i < table.length(); i++) {
298 EmitOrLink(table[i]);
299 }
300 }
301
302
303 void IrregexpAssembler::LookupHighMap8(byte start,
304 Label* byte_map,
305 const Vector<Label*>& table) {
306 Emit(BC_LOOKUP_HI_MAP8);
307 Emit(start);
308 EmitOrLink(byte_map);
309 ASSERT(table.length() > 0);
310 ASSERT(table.length() <= 256);
311 for (int i = 0; i < table.length(); i++) {
312 EmitOrLink(table[i]);
313 }
314 }
315
316
317 int IrregexpAssembler::length() {
318 return pc_;
319 }
320
321
322 void IrregexpAssembler::Copy(Address a) {
323 memcpy(a, buffer_.start(), length());
324 }
325
326
327 void IrregexpAssembler::Expand() {
328 bool old_buffer_was_our_own = own_buffer_;
329 Vector<byte> old_buffer = buffer_;
330 buffer_ = Vector<byte>::New(old_buffer.length() * 2);
331 own_buffer_ = true;
332 memcpy(buffer_.start(), old_buffer.start(), old_buffer.length());
333 if (old_buffer_was_our_own) {
334 old_buffer.Dispose();
335 }
336 }
337
338
339 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698