[V8] Introduce a QML compilation mode
[profile/ivi/qtjsbackend.git] / src / 3rdparty / v8 / src / regexp-macro-assembler-tracer.cc
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
36 RegExpMacroAssemblerTracer::RegExpMacroAssemblerTracer(
37     RegExpMacroAssembler* assembler) :
38   assembler_(assembler) {
39   unsigned int type = assembler->Implementation();
40   ASSERT(type < 5);
41   const char* impl_names[] = {"IA32", "ARM", "MIPS", "X64", "Bytecode"};
42   PrintF("RegExpMacroAssembler%s();\n", impl_names[type]);
43 }
44
45
46 RegExpMacroAssemblerTracer::~RegExpMacroAssemblerTracer() {
47 }
48
49
50 // This is used for printing out debugging information.  It makes an integer
51 // that is closely related to the address of an object.
52 static int LabelToInt(Label* label) {
53   return static_cast<int>(reinterpret_cast<intptr_t>(label));
54 }
55
56
57 void RegExpMacroAssemblerTracer::Bind(Label* label) {
58   PrintF("label[%08x]: (Bind)\n", LabelToInt(label));
59   assembler_->Bind(label);
60 }
61
62
63 void RegExpMacroAssemblerTracer::AdvanceCurrentPosition(int by) {
64   PrintF(" AdvanceCurrentPosition(by=%d);\n", by);
65   assembler_->AdvanceCurrentPosition(by);
66 }
67
68
69 void RegExpMacroAssemblerTracer::CheckGreedyLoop(Label* label) {
70   PrintF(" CheckGreedyLoop(label[%08x]);\n\n", LabelToInt(label));
71   assembler_->CheckGreedyLoop(label);
72 }
73
74
75 void RegExpMacroAssemblerTracer::PopCurrentPosition() {
76   PrintF(" PopCurrentPosition();\n");
77   assembler_->PopCurrentPosition();
78 }
79
80
81 void RegExpMacroAssemblerTracer::PushCurrentPosition() {
82   PrintF(" PushCurrentPosition();\n");
83   assembler_->PushCurrentPosition();
84 }
85
86
87 void RegExpMacroAssemblerTracer::Backtrack() {
88   PrintF(" Backtrack();\n");
89   assembler_->Backtrack();
90 }
91
92
93 void RegExpMacroAssemblerTracer::GoTo(Label* label) {
94   PrintF(" GoTo(label[%08x]);\n\n", LabelToInt(label));
95   assembler_->GoTo(label);
96 }
97
98
99 void RegExpMacroAssemblerTracer::PushBacktrack(Label* label) {
100   PrintF(" PushBacktrack(label[%08x]);\n", LabelToInt(label));
101   assembler_->PushBacktrack(label);
102 }
103
104
105 void RegExpMacroAssemblerTracer::Succeed() {
106   PrintF(" Succeed();\n");
107   assembler_->Succeed();
108 }
109
110
111 void RegExpMacroAssemblerTracer::Fail() {
112   PrintF(" Fail();\n");
113   assembler_->Fail();
114 }
115
116
117 void RegExpMacroAssemblerTracer::PopRegister(int register_index) {
118   PrintF(" PopRegister(register=%d);\n", register_index);
119   assembler_->PopRegister(register_index);
120 }
121
122
123 void RegExpMacroAssemblerTracer::PushRegister(
124     int register_index,
125     StackCheckFlag check_stack_limit) {
126   PrintF(" PushRegister(register=%d, %s);\n",
127          register_index,
128          check_stack_limit ? "check stack limit" : "");
129   assembler_->PushRegister(register_index, check_stack_limit);
130 }
131
132
133 void RegExpMacroAssemblerTracer::AdvanceRegister(int reg, int by) {
134   PrintF(" AdvanceRegister(register=%d, by=%d);\n", reg, by);
135   assembler_->AdvanceRegister(reg, by);
136 }
137
138
139 void RegExpMacroAssemblerTracer::SetCurrentPositionFromEnd(int by) {
140   PrintF(" SetCurrentPositionFromEnd(by=%d);\n", by);
141   assembler_->SetCurrentPositionFromEnd(by);
142 }
143
144
145 void RegExpMacroAssemblerTracer::SetRegister(int register_index, int to) {
146   PrintF(" SetRegister(register=%d, to=%d);\n", register_index, to);
147   assembler_->SetRegister(register_index, to);
148 }
149
150
151 void RegExpMacroAssemblerTracer::WriteCurrentPositionToRegister(int reg,
152                                                                 int cp_offset) {
153   PrintF(" WriteCurrentPositionToRegister(register=%d,cp_offset=%d);\n",
154          reg,
155          cp_offset);
156   assembler_->WriteCurrentPositionToRegister(reg, cp_offset);
157 }
158
159
160 void RegExpMacroAssemblerTracer::ClearRegisters(int reg_from, int reg_to) {
161   PrintF(" ClearRegister(from=%d, to=%d);\n", reg_from, reg_to);
162   assembler_->ClearRegisters(reg_from, reg_to);
163 }
164
165
166 void RegExpMacroAssemblerTracer::ReadCurrentPositionFromRegister(int reg) {
167   PrintF(" ReadCurrentPositionFromRegister(register=%d);\n", reg);
168   assembler_->ReadCurrentPositionFromRegister(reg);
169 }
170
171
172 void RegExpMacroAssemblerTracer::WriteStackPointerToRegister(int reg) {
173   PrintF(" WriteStackPointerToRegister(register=%d);\n", reg);
174   assembler_->WriteStackPointerToRegister(reg);
175 }
176
177
178 void RegExpMacroAssemblerTracer::ReadStackPointerFromRegister(int reg) {
179   PrintF(" ReadStackPointerFromRegister(register=%d);\n", reg);
180   assembler_->ReadStackPointerFromRegister(reg);
181 }
182
183
184 void RegExpMacroAssemblerTracer::LoadCurrentCharacter(int cp_offset,
185                                                       Label* on_end_of_input,
186                                                       bool check_bounds,
187                                                       int characters) {
188   const char* check_msg = check_bounds ? "" : " (unchecked)";
189   PrintF(" LoadCurrentCharacter(cp_offset=%d, label[%08x]%s (%d chars));\n",
190          cp_offset,
191          LabelToInt(on_end_of_input),
192          check_msg,
193          characters);
194   assembler_->LoadCurrentCharacter(cp_offset,
195                                    on_end_of_input,
196                                    check_bounds,
197                                    characters);
198 }
199
200
201 class PrintablePrinter {
202  public:
203   explicit PrintablePrinter(uc16 character) : character_(character) { }
204
205   const char* operator*() {
206     if (character_ >= ' ' && character_ <= '~') {
207       buffer_[0] = '(';
208       buffer_[1] = static_cast<char>(character_);
209       buffer_[2] = ')';
210       buffer_[3] = '\0';
211     } else {
212       buffer_[0] = '\0';
213     }
214     return &buffer_[0];
215   };
216
217  private:
218   uc16 character_;
219   char buffer_[4];
220 };
221
222
223 void RegExpMacroAssemblerTracer::CheckCharacterLT(uc16 limit, Label* on_less) {
224   PrintablePrinter printable(limit);
225   PrintF(" CheckCharacterLT(c=0x%04x%s, label[%08x]);\n",
226          limit,
227          *printable,
228          LabelToInt(on_less));
229   assembler_->CheckCharacterLT(limit, on_less);
230 }
231
232
233 void RegExpMacroAssemblerTracer::CheckCharacterGT(uc16 limit,
234                                                   Label* on_greater) {
235   PrintablePrinter printable(limit);
236   PrintF(" CheckCharacterGT(c=0x%04x%s, label[%08x]);\n",
237          limit,
238          *printable,
239          LabelToInt(on_greater));
240   assembler_->CheckCharacterGT(limit, on_greater);
241 }
242
243
244 void RegExpMacroAssemblerTracer::CheckCharacter(unsigned c, Label* on_equal) {
245   PrintablePrinter printable(c);
246   PrintF(" CheckCharacter(c=0x%04x%s, label[%08x]);\n",
247          c,
248          *printable,
249          LabelToInt(on_equal));
250   assembler_->CheckCharacter(c, on_equal);
251 }
252
253
254 void RegExpMacroAssemblerTracer::CheckAtStart(Label* on_at_start) {
255   PrintF(" CheckAtStart(label[%08x]);\n", LabelToInt(on_at_start));
256   assembler_->CheckAtStart(on_at_start);
257 }
258
259
260 void RegExpMacroAssemblerTracer::CheckNotAtStart(Label* on_not_at_start) {
261   PrintF(" CheckNotAtStart(label[%08x]);\n", LabelToInt(on_not_at_start));
262   assembler_->CheckNotAtStart(on_not_at_start);
263 }
264
265
266 void RegExpMacroAssemblerTracer::CheckNotCharacter(unsigned c,
267                                                    Label* on_not_equal) {
268   PrintablePrinter printable(c);
269   PrintF(" CheckNotCharacter(c=0x%04x%s, label[%08x]);\n",
270          c,
271          *printable,
272          LabelToInt(on_not_equal));
273   assembler_->CheckNotCharacter(c, on_not_equal);
274 }
275
276
277 void RegExpMacroAssemblerTracer::CheckCharacterAfterAnd(
278     unsigned c,
279     unsigned mask,
280     Label* on_equal) {
281   PrintablePrinter printable(c);
282   PrintF(" CheckCharacterAfterAnd(c=0x%04x%s, mask=0x%04x, label[%08x]);\n",
283          c,
284          *printable,
285          mask,
286          LabelToInt(on_equal));
287   assembler_->CheckCharacterAfterAnd(c, mask, on_equal);
288 }
289
290
291 void RegExpMacroAssemblerTracer::CheckNotCharacterAfterAnd(
292     unsigned c,
293     unsigned mask,
294     Label* on_not_equal) {
295   PrintablePrinter printable(c);
296   PrintF(" CheckNotCharacterAfterAnd(c=0x%04x%s, mask=0x%04x, label[%08x]);\n",
297          c,
298          *printable,
299          mask,
300          LabelToInt(on_not_equal));
301   assembler_->CheckNotCharacterAfterAnd(c, mask, on_not_equal);
302 }
303
304
305 void RegExpMacroAssemblerTracer::CheckNotCharacterAfterMinusAnd(
306     uc16 c,
307     uc16 minus,
308     uc16 mask,
309     Label* on_not_equal) {
310   PrintF(" CheckNotCharacterAfterMinusAnd(c=0x%04x, minus=%04x, mask=0x%04x, "
311              "label[%08x]);\n",
312          c,
313          minus,
314          mask,
315          LabelToInt(on_not_equal));
316   assembler_->CheckNotCharacterAfterMinusAnd(c, minus, mask, on_not_equal);
317 }
318
319
320 void RegExpMacroAssemblerTracer::CheckCharacterInRange(
321     uc16 from,
322     uc16 to,
323     Label* on_not_in_range) {
324   PrintablePrinter printable_from(from);
325   PrintablePrinter printable_to(to);
326   PrintF(" CheckCharacterInRange(from=0x%04x%s, to=0x%04x%s, label[%08x]);\n",
327          from,
328          *printable_from,
329          to,
330          *printable_to,
331          LabelToInt(on_not_in_range));
332   assembler_->CheckCharacterInRange(from, to, on_not_in_range);
333 }
334
335
336 void RegExpMacroAssemblerTracer::CheckCharacterNotInRange(
337     uc16 from,
338     uc16 to,
339     Label* on_in_range) {
340   PrintablePrinter printable_from(from);
341   PrintablePrinter printable_to(to);
342   PrintF(
343       " CheckCharacterNotInRange(from=0x%04x%s," " to=%04x%s, label[%08x]);\n",
344       from,
345       *printable_from,
346       to,
347       *printable_to,
348       LabelToInt(on_in_range));
349   assembler_->CheckCharacterNotInRange(from, to, on_in_range);
350 }
351
352
353 void RegExpMacroAssemblerTracer::CheckBitInTable(
354     Handle<ByteArray> table, Label* on_bit_set) {
355   PrintF(" CheckBitInTable(label[%08x] ", LabelToInt(on_bit_set));
356   for (int i = 0; i < kTableSize; i++) {
357     PrintF("%c", table->get(i) != 0 ? 'X' : '.');
358     if (i % 32 == 31 && i != kTableMask) {
359       PrintF("\n                                 ");
360     }
361   }
362   PrintF(");\n");
363   assembler_->CheckBitInTable(table, on_bit_set);
364 }
365
366
367 void RegExpMacroAssemblerTracer::CheckNotBackReference(int start_reg,
368                                                        Label* on_no_match) {
369   PrintF(" CheckNotBackReference(register=%d, label[%08x]);\n", start_reg,
370          LabelToInt(on_no_match));
371   assembler_->CheckNotBackReference(start_reg, on_no_match);
372 }
373
374
375 void RegExpMacroAssemblerTracer::CheckNotBackReferenceIgnoreCase(
376     int start_reg,
377     Label* on_no_match) {
378   PrintF(" CheckNotBackReferenceIgnoreCase(register=%d, label[%08x]);\n",
379          start_reg, LabelToInt(on_no_match));
380   assembler_->CheckNotBackReferenceIgnoreCase(start_reg, on_no_match);
381 }
382
383
384 void RegExpMacroAssemblerTracer::CheckNotRegistersEqual(int reg1,
385                                                         int reg2,
386                                                         Label* on_not_equal) {
387   PrintF(" CheckNotRegistersEqual(reg1=%d, reg2=%d, label[%08x]);\n",
388          reg1,
389          reg2,
390          LabelToInt(on_not_equal));
391   assembler_->CheckNotRegistersEqual(reg1, reg2, on_not_equal);
392 }
393
394
395 void RegExpMacroAssemblerTracer::CheckCharacters(Vector<const uc16> str,
396                                                  int cp_offset,
397                                                  Label* on_failure,
398                                                  bool check_end_of_string) {
399   PrintF(" %s(str=\"",
400          check_end_of_string ? "CheckCharacters" : "CheckCharactersUnchecked");
401   for (int i = 0; i < str.length(); i++) {
402     PrintF("0x%04x", str[i]);
403   }
404   PrintF("\", cp_offset=%d, label[%08x])\n",
405          cp_offset, LabelToInt(on_failure));
406   assembler_->CheckCharacters(str, cp_offset, on_failure, check_end_of_string);
407 }
408
409
410 bool RegExpMacroAssemblerTracer::CheckSpecialCharacterClass(
411     uc16 type,
412     Label* on_no_match) {
413   bool supported = assembler_->CheckSpecialCharacterClass(type,
414                                                           on_no_match);
415   PrintF(" CheckSpecialCharacterClass(type='%c', label[%08x]): %s;\n",
416          type,
417          LabelToInt(on_no_match),
418          supported ? "true" : "false");
419   return supported;
420 }
421
422
423 void RegExpMacroAssemblerTracer::IfRegisterLT(int register_index,
424                                               int comparand, Label* if_lt) {
425   PrintF(" IfRegisterLT(register=%d, number=%d, label[%08x]);\n",
426          register_index, comparand, LabelToInt(if_lt));
427   assembler_->IfRegisterLT(register_index, comparand, if_lt);
428 }
429
430
431 void RegExpMacroAssemblerTracer::IfRegisterEqPos(int register_index,
432                                                  Label* if_eq) {
433   PrintF(" IfRegisterEqPos(register=%d, label[%08x]);\n",
434          register_index, LabelToInt(if_eq));
435   assembler_->IfRegisterEqPos(register_index, if_eq);
436 }
437
438
439 void RegExpMacroAssemblerTracer::IfRegisterGE(int register_index,
440                                               int comparand, Label* if_ge) {
441   PrintF(" IfRegisterGE(register=%d, number=%d, label[%08x]);\n",
442          register_index, comparand, LabelToInt(if_ge));
443   assembler_->IfRegisterGE(register_index, comparand, if_ge);
444 }
445
446
447 RegExpMacroAssembler::IrregexpImplementation
448     RegExpMacroAssemblerTracer::Implementation() {
449   return assembler_->Implementation();
450 }
451
452
453 Handle<HeapObject> RegExpMacroAssemblerTracer::GetCode(Handle<String> source) {
454   PrintF(" GetCode(%s);\n", *(source->ToCString()));
455   return assembler_->GetCode(source);
456 }
457
458 }}  // namespace v8::internal