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 #include "v8.h"
29 #include "ast.h"
30 #include "regexp-macro-assembler.h"
31 #include "regexp-macro-assembler-tracer.h"
32
33 namespace v8 {
34 namespace internal {
35
RegExpMacroAssemblerTracer(RegExpMacroAssembler * assembler)36 RegExpMacroAssemblerTracer::RegExpMacroAssemblerTracer(
37 RegExpMacroAssembler* assembler) :
38 assembler_(assembler) {
39 unsigned int type = assembler->Implementation();
40 ASSERT(type < 3);
41 const char* impl_names[3] = {"IA32", "ARM", "Bytecode"};
42 PrintF("RegExpMacroAssembler%s();\n", impl_names[type]);
43 }
44
45
~RegExpMacroAssemblerTracer()46 RegExpMacroAssemblerTracer::~RegExpMacroAssemblerTracer() {
47 }
48
49
Bind(Label * label)50 void RegExpMacroAssemblerTracer::Bind(Label* label) {
51 PrintF("label[%08x]: (Bind)\n", label, label);
52 assembler_->Bind(label);
53 }
54
55
AdvanceCurrentPosition(int by)56 void RegExpMacroAssemblerTracer::AdvanceCurrentPosition(int by) {
57 PrintF(" AdvanceCurrentPosition(by=%d);\n", by);
58 assembler_->AdvanceCurrentPosition(by);
59 }
60
61
CheckGreedyLoop(Label * label)62 void RegExpMacroAssemblerTracer::CheckGreedyLoop(Label* label) {
63 PrintF(" CheckGreedyLoop(label[%08x]);\n\n", label);
64 assembler_->CheckGreedyLoop(label);
65 }
66
67
PopCurrentPosition()68 void RegExpMacroAssemblerTracer::PopCurrentPosition() {
69 PrintF(" PopCurrentPosition();\n");
70 assembler_->PopCurrentPosition();
71 }
72
73
PushCurrentPosition()74 void RegExpMacroAssemblerTracer::PushCurrentPosition() {
75 PrintF(" PushCurrentPosition();\n");
76 assembler_->PushCurrentPosition();
77 }
78
79
Backtrack()80 void RegExpMacroAssemblerTracer::Backtrack() {
81 PrintF(" Backtrack();\n");
82 assembler_->Backtrack();
83 }
84
85
GoTo(Label * label)86 void RegExpMacroAssemblerTracer::GoTo(Label* label) {
87 PrintF(" GoTo(label[%08x]);\n\n", label);
88 assembler_->GoTo(label);
89 }
90
91
PushBacktrack(Label * label)92 void RegExpMacroAssemblerTracer::PushBacktrack(Label* label) {
93 PrintF(" PushBacktrack(label[%08x]);\n",
94 label);
95 assembler_->PushBacktrack(label);
96 }
97
98
Succeed()99 void RegExpMacroAssemblerTracer::Succeed() {
100 PrintF(" Succeed();\n");
101 assembler_->Succeed();
102 }
103
104
Fail()105 void RegExpMacroAssemblerTracer::Fail() {
106 PrintF(" Fail();\n");
107 assembler_->Fail();
108 }
109
110
PopRegister(int register_index)111 void RegExpMacroAssemblerTracer::PopRegister(int register_index) {
112 PrintF(" PopRegister(register=%d);\n", register_index);
113 assembler_->PopRegister(register_index);
114 }
115
116
PushRegister(int register_index,StackCheckFlag check_stack_limit)117 void RegExpMacroAssemblerTracer::PushRegister(
118 int register_index,
119 StackCheckFlag check_stack_limit) {
120 PrintF(" PushRegister(register=%d, %s);\n",
121 register_index,
122 check_stack_limit ? "check stack limit" : "");
123 assembler_->PushRegister(register_index, check_stack_limit);
124 }
125
126
AdvanceRegister(int reg,int by)127 void RegExpMacroAssemblerTracer::AdvanceRegister(int reg, int by) {
128 PrintF(" AdvanceRegister(register=%d, by=%d);\n", reg, by);
129 assembler_->AdvanceRegister(reg, by);
130 }
131
132
SetRegister(int register_index,int to)133 void RegExpMacroAssemblerTracer::SetRegister(int register_index, int to) {
134 PrintF(" SetRegister(register=%d, to=%d);\n", register_index, to);
135 assembler_->SetRegister(register_index, to);
136 }
137
138
WriteCurrentPositionToRegister(int reg,int cp_offset)139 void RegExpMacroAssemblerTracer::WriteCurrentPositionToRegister(int reg,
140 int cp_offset) {
141 PrintF(" WriteCurrentPositionToRegister(register=%d,cp_offset=%d);\n",
142 reg,
143 cp_offset);
144 assembler_->WriteCurrentPositionToRegister(reg, cp_offset);
145 }
146
147
ClearRegisters(int reg_from,int reg_to)148 void RegExpMacroAssemblerTracer::ClearRegisters(int reg_from, int reg_to) {
149 PrintF(" ClearRegister(from=%d, to=%d);\n", reg_from, reg_to);
150 assembler_->ClearRegisters(reg_from, reg_to);
151 }
152
153
ReadCurrentPositionFromRegister(int reg)154 void RegExpMacroAssemblerTracer::ReadCurrentPositionFromRegister(int reg) {
155 PrintF(" ReadCurrentPositionFromRegister(register=%d);\n", reg);
156 assembler_->ReadCurrentPositionFromRegister(reg);
157 }
158
159
WriteStackPointerToRegister(int reg)160 void RegExpMacroAssemblerTracer::WriteStackPointerToRegister(int reg) {
161 PrintF(" WriteStackPointerToRegister(register=%d);\n", reg);
162 assembler_->WriteStackPointerToRegister(reg);
163 }
164
165
ReadStackPointerFromRegister(int reg)166 void RegExpMacroAssemblerTracer::ReadStackPointerFromRegister(int reg) {
167 PrintF(" ReadStackPointerFromRegister(register=%d);\n", reg);
168 assembler_->ReadStackPointerFromRegister(reg);
169 }
170
171
LoadCurrentCharacter(int cp_offset,Label * on_end_of_input,bool check_bounds,int characters)172 void RegExpMacroAssemblerTracer::LoadCurrentCharacter(int cp_offset,
173 Label* on_end_of_input,
174 bool check_bounds,
175 int characters) {
176 const char* check_msg = check_bounds ? "" : " (unchecked)";
177 PrintF(" LoadCurrentCharacter(cp_offset=%d, label[%08x]%s (%d chars));\n",
178 cp_offset,
179 on_end_of_input,
180 check_msg,
181 characters);
182 assembler_->LoadCurrentCharacter(cp_offset,
183 on_end_of_input,
184 check_bounds,
185 characters);
186 }
187
188
CheckCharacterLT(uc16 limit,Label * on_less)189 void RegExpMacroAssemblerTracer::CheckCharacterLT(uc16 limit, Label* on_less) {
190 PrintF(" CheckCharacterLT(c='u%04x', label[%08x]);\n", limit, on_less);
191 assembler_->CheckCharacterLT(limit, on_less);
192 }
193
194
CheckCharacterGT(uc16 limit,Label * on_greater)195 void RegExpMacroAssemblerTracer::CheckCharacterGT(uc16 limit,
196 Label* on_greater) {
197 PrintF(" CheckCharacterGT(c='u%04x', label[%08x]);\n", limit, on_greater);
198 assembler_->CheckCharacterGT(limit, on_greater);
199 }
200
201
CheckCharacter(uint32_t c,Label * on_equal)202 void RegExpMacroAssemblerTracer::CheckCharacter(uint32_t c, Label* on_equal) {
203 PrintF(" CheckCharacter(c='u%04x', label[%08x]);\n", c, on_equal);
204 assembler_->CheckCharacter(c, on_equal);
205 }
206
207
CheckAtStart(Label * on_at_start)208 void RegExpMacroAssemblerTracer::CheckAtStart(Label* on_at_start) {
209 PrintF(" CheckAtStart(label[%08x]);\n", on_at_start);
210 assembler_->CheckAtStart(on_at_start);
211 }
212
213
CheckNotAtStart(Label * on_not_at_start)214 void RegExpMacroAssemblerTracer::CheckNotAtStart(Label* on_not_at_start) {
215 PrintF(" CheckNotAtStart(label[%08x]);\n", on_not_at_start);
216 assembler_->CheckNotAtStart(on_not_at_start);
217 }
218
219
CheckNotCharacter(uint32_t c,Label * on_not_equal)220 void RegExpMacroAssemblerTracer::CheckNotCharacter(uint32_t c,
221 Label* on_not_equal) {
222 PrintF(" CheckNotCharacter(c='u%04x', label[%08x]);\n", c, on_not_equal);
223 assembler_->CheckNotCharacter(c, on_not_equal);
224 }
225
226
CheckCharacterAfterAnd(uint32_t c,uint32_t mask,Label * on_equal)227 void RegExpMacroAssemblerTracer::CheckCharacterAfterAnd(
228 uint32_t c,
229 uint32_t mask,
230 Label* on_equal) {
231 PrintF(" CheckCharacterAfterAnd(c='u%04x', mask=0x%04x, label[%08x]);\n",
232 c,
233 mask,
234 on_equal);
235 assembler_->CheckCharacterAfterAnd(c, mask, on_equal);
236 }
237
238
CheckNotCharacterAfterAnd(uint32_t c,uint32_t mask,Label * on_not_equal)239 void RegExpMacroAssemblerTracer::CheckNotCharacterAfterAnd(
240 uint32_t c,
241 uint32_t mask,
242 Label* on_not_equal) {
243 PrintF(" CheckNotCharacterAfterAnd(c='u%04x', mask=0x%04x, label[%08x]);\n",
244 c,
245 mask,
246 on_not_equal);
247 assembler_->CheckNotCharacterAfterAnd(c, mask, on_not_equal);
248 }
249
250
CheckNotCharacterAfterMinusAnd(uc16 c,uc16 minus,uc16 mask,Label * on_not_equal)251 void RegExpMacroAssemblerTracer::CheckNotCharacterAfterMinusAnd(
252 uc16 c,
253 uc16 minus,
254 uc16 mask,
255 Label* on_not_equal) {
256 PrintF(" CheckNotCharacterAfterMinusAnd(c='u%04x', minus=%04x, mask=0x%04x, "
257 "label[%08x]);\n",
258 c,
259 minus,
260 mask,
261 on_not_equal);
262 assembler_->CheckNotCharacterAfterMinusAnd(c, minus, mask, on_not_equal);
263 }
264
265
CheckNotBackReference(int start_reg,Label * on_no_match)266 void RegExpMacroAssemblerTracer::CheckNotBackReference(int start_reg,
267 Label* on_no_match) {
268 PrintF(" CheckNotBackReference(register=%d, label[%08x]);\n", start_reg,
269 on_no_match);
270 assembler_->CheckNotBackReference(start_reg, on_no_match);
271 }
272
273
CheckNotBackReferenceIgnoreCase(int start_reg,Label * on_no_match)274 void RegExpMacroAssemblerTracer::CheckNotBackReferenceIgnoreCase(
275 int start_reg,
276 Label* on_no_match) {
277 PrintF(" CheckNotBackReferenceIgnoreCase(register=%d, label[%08x]);\n",
278 start_reg, on_no_match);
279 assembler_->CheckNotBackReferenceIgnoreCase(start_reg, on_no_match);
280 }
281
282
CheckNotRegistersEqual(int reg1,int reg2,Label * on_not_equal)283 void RegExpMacroAssemblerTracer::CheckNotRegistersEqual(int reg1,
284 int reg2,
285 Label* on_not_equal) {
286 PrintF(" CheckNotRegistersEqual(reg1=%d, reg2=%d, label[%08x]);\n",
287 reg1,
288 reg2,
289 on_not_equal);
290 assembler_->CheckNotRegistersEqual(reg1, reg2, on_not_equal);
291 }
292
293
CheckCharacters(Vector<const uc16> str,int cp_offset,Label * on_failure,bool check_end_of_string)294 void RegExpMacroAssemblerTracer::CheckCharacters(Vector<const uc16> str,
295 int cp_offset,
296 Label* on_failure,
297 bool check_end_of_string) {
298 PrintF(" %s(str=\"",
299 check_end_of_string ? "CheckCharacters" : "CheckCharactersUnchecked");
300 for (int i = 0; i < str.length(); i++) {
301 PrintF("u%04x", str[i]);
302 }
303 PrintF("\", cp_offset=%d, label[%08x])\n", cp_offset, on_failure);
304 assembler_->CheckCharacters(str, cp_offset, on_failure, check_end_of_string);
305 }
306
307
CheckSpecialCharacterClass(uc16 type,int cp_offset,bool check_offset,Label * on_no_match)308 bool RegExpMacroAssemblerTracer::CheckSpecialCharacterClass(
309 uc16 type,
310 int cp_offset,
311 bool check_offset,
312 Label* on_no_match) {
313 bool supported = assembler_->CheckSpecialCharacterClass(type,
314 cp_offset,
315 check_offset,
316 on_no_match);
317 PrintF(" CheckSpecialCharacterClass(type='%c', offset=%d, "
318 "check_offset=%s, label[%08x]): %s;\n",
319 type,
320 cp_offset,
321 check_offset ? "true" : "false",
322 on_no_match,
323 supported ? "true" : "false");
324 return supported;
325 }
326
327
IfRegisterLT(int register_index,int comparand,Label * if_lt)328 void RegExpMacroAssemblerTracer::IfRegisterLT(int register_index,
329 int comparand, Label* if_lt) {
330 PrintF(" IfRegisterLT(register=%d, number=%d, label[%08x]);\n",
331 register_index, comparand, if_lt);
332 assembler_->IfRegisterLT(register_index, comparand, if_lt);
333 }
334
335
IfRegisterEqPos(int register_index,Label * if_eq)336 void RegExpMacroAssemblerTracer::IfRegisterEqPos(int register_index,
337 Label* if_eq) {
338 PrintF(" IfRegisterEqPos(register=%d, label[%08x]);\n",
339 register_index, if_eq);
340 assembler_->IfRegisterEqPos(register_index, if_eq);
341 }
342
343
IfRegisterGE(int register_index,int comparand,Label * if_ge)344 void RegExpMacroAssemblerTracer::IfRegisterGE(int register_index,
345 int comparand, Label* if_ge) {
346 PrintF(" IfRegisterGE(register=%d, number=%d, label[%08x]);\n",
347 register_index, comparand, if_ge);
348 assembler_->IfRegisterGE(register_index, comparand, if_ge);
349 }
350
351
352 RegExpMacroAssembler::IrregexpImplementation
Implementation()353 RegExpMacroAssemblerTracer::Implementation() {
354 return assembler_->Implementation();
355 }
356
357
GetCode(Handle<String> source)358 Handle<Object> RegExpMacroAssemblerTracer::GetCode(Handle<String> source) {
359 PrintF(" GetCode(%s);\n", *(source->ToCString()));
360 return assembler_->GetCode(source);
361 }
362
363 }} // namespace v8::internal
364