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 33namespace v8 { 34namespace internal { 35 36RegExpMacroAssemblerTracer::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 46RegExpMacroAssemblerTracer::~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. 52static int LabelToInt(Label* label) { 53 return static_cast<int>(reinterpret_cast<intptr_t>(label)); 54} 55 56 57void RegExpMacroAssemblerTracer::Bind(Label* label) { 58 PrintF("label[%08x]: (Bind)\n", LabelToInt(label)); 59 assembler_->Bind(label); 60} 61 62 63void RegExpMacroAssemblerTracer::AdvanceCurrentPosition(int by) { 64 PrintF(" AdvanceCurrentPosition(by=%d);\n", by); 65 assembler_->AdvanceCurrentPosition(by); 66} 67 68 69void RegExpMacroAssemblerTracer::CheckGreedyLoop(Label* label) { 70 PrintF(" CheckGreedyLoop(label[%08x]);\n\n", LabelToInt(label)); 71 assembler_->CheckGreedyLoop(label); 72} 73 74 75void RegExpMacroAssemblerTracer::PopCurrentPosition() { 76 PrintF(" PopCurrentPosition();\n"); 77 assembler_->PopCurrentPosition(); 78} 79 80 81void RegExpMacroAssemblerTracer::PushCurrentPosition() { 82 PrintF(" PushCurrentPosition();\n"); 83 assembler_->PushCurrentPosition(); 84} 85 86 87void RegExpMacroAssemblerTracer::Backtrack() { 88 PrintF(" Backtrack();\n"); 89 assembler_->Backtrack(); 90} 91 92 93void RegExpMacroAssemblerTracer::GoTo(Label* label) { 94 PrintF(" GoTo(label[%08x]);\n\n", LabelToInt(label)); 95 assembler_->GoTo(label); 96} 97 98 99void RegExpMacroAssemblerTracer::PushBacktrack(Label* label) { 100 PrintF(" PushBacktrack(label[%08x]);\n", LabelToInt(label)); 101 assembler_->PushBacktrack(label); 102} 103 104 105void RegExpMacroAssemblerTracer::Succeed() { 106 PrintF(" Succeed();\n"); 107 assembler_->Succeed(); 108} 109 110 111void RegExpMacroAssemblerTracer::Fail() { 112 PrintF(" Fail();\n"); 113 assembler_->Fail(); 114} 115 116 117void RegExpMacroAssemblerTracer::PopRegister(int register_index) { 118 PrintF(" PopRegister(register=%d);\n", register_index); 119 assembler_->PopRegister(register_index); 120} 121 122 123void 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 133void RegExpMacroAssemblerTracer::AdvanceRegister(int reg, int by) { 134 PrintF(" AdvanceRegister(register=%d, by=%d);\n", reg, by); 135 assembler_->AdvanceRegister(reg, by); 136} 137 138 139void RegExpMacroAssemblerTracer::SetCurrentPositionFromEnd(int by) { 140 PrintF(" SetCurrentPositionFromEnd(by=%d);\n", by); 141 assembler_->SetCurrentPositionFromEnd(by); 142} 143 144 145void 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 151void 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 160void 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 166void RegExpMacroAssemblerTracer::ReadCurrentPositionFromRegister(int reg) { 167 PrintF(" ReadCurrentPositionFromRegister(register=%d);\n", reg); 168 assembler_->ReadCurrentPositionFromRegister(reg); 169} 170 171 172void RegExpMacroAssemblerTracer::WriteStackPointerToRegister(int reg) { 173 PrintF(" WriteStackPointerToRegister(register=%d);\n", reg); 174 assembler_->WriteStackPointerToRegister(reg); 175} 176 177 178void RegExpMacroAssemblerTracer::ReadStackPointerFromRegister(int reg) { 179 PrintF(" ReadStackPointerFromRegister(register=%d);\n", reg); 180 assembler_->ReadStackPointerFromRegister(reg); 181} 182 183 184void 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 201void RegExpMacroAssemblerTracer::CheckCharacterLT(uc16 limit, Label* on_less) { 202 PrintF(" CheckCharacterLT(c='u%04x', label[%08x]);\n", 203 limit, LabelToInt(on_less)); 204 assembler_->CheckCharacterLT(limit, on_less); 205} 206 207 208void RegExpMacroAssemblerTracer::CheckCharacterGT(uc16 limit, 209 Label* on_greater) { 210 PrintF(" CheckCharacterGT(c='u%04x', label[%08x]);\n", 211 limit, LabelToInt(on_greater)); 212 assembler_->CheckCharacterGT(limit, on_greater); 213} 214 215 216void RegExpMacroAssemblerTracer::CheckCharacter(unsigned c, Label* on_equal) { 217 PrintF(" CheckCharacter(c='u%04x', label[%08x]);\n", 218 c, LabelToInt(on_equal)); 219 assembler_->CheckCharacter(c, on_equal); 220} 221 222 223void RegExpMacroAssemblerTracer::CheckAtStart(Label* on_at_start) { 224 PrintF(" CheckAtStart(label[%08x]);\n", LabelToInt(on_at_start)); 225 assembler_->CheckAtStart(on_at_start); 226} 227 228 229void RegExpMacroAssemblerTracer::CheckNotAtStart(Label* on_not_at_start) { 230 PrintF(" CheckNotAtStart(label[%08x]);\n", LabelToInt(on_not_at_start)); 231 assembler_->CheckNotAtStart(on_not_at_start); 232} 233 234 235void RegExpMacroAssemblerTracer::CheckNotCharacter(unsigned c, 236 Label* on_not_equal) { 237 PrintF(" CheckNotCharacter(c='u%04x', label[%08x]);\n", 238 c, LabelToInt(on_not_equal)); 239 assembler_->CheckNotCharacter(c, on_not_equal); 240} 241 242 243void RegExpMacroAssemblerTracer::CheckCharacterAfterAnd( 244 unsigned c, 245 unsigned mask, 246 Label* on_equal) { 247 PrintF(" CheckCharacterAfterAnd(c='u%04x', mask=0x%04x, label[%08x]);\n", 248 c, 249 mask, 250 LabelToInt(on_equal)); 251 assembler_->CheckCharacterAfterAnd(c, mask, on_equal); 252} 253 254 255void RegExpMacroAssemblerTracer::CheckNotCharacterAfterAnd( 256 unsigned c, 257 unsigned mask, 258 Label* on_not_equal) { 259 PrintF(" CheckNotCharacterAfterAnd(c='u%04x', mask=0x%04x, label[%08x]);\n", 260 c, 261 mask, 262 LabelToInt(on_not_equal)); 263 assembler_->CheckNotCharacterAfterAnd(c, mask, on_not_equal); 264} 265 266 267void RegExpMacroAssemblerTracer::CheckNotCharacterAfterMinusAnd( 268 uc16 c, 269 uc16 minus, 270 uc16 mask, 271 Label* on_not_equal) { 272 PrintF(" CheckNotCharacterAfterMinusAnd(c='u%04x', minus=%04x, mask=0x%04x, " 273 "label[%08x]);\n", 274 c, 275 minus, 276 mask, 277 LabelToInt(on_not_equal)); 278 assembler_->CheckNotCharacterAfterMinusAnd(c, minus, mask, on_not_equal); 279} 280 281 282void RegExpMacroAssemblerTracer::CheckNotBackReference(int start_reg, 283 Label* on_no_match) { 284 PrintF(" CheckNotBackReference(register=%d, label[%08x]);\n", start_reg, 285 LabelToInt(on_no_match)); 286 assembler_->CheckNotBackReference(start_reg, on_no_match); 287} 288 289 290void RegExpMacroAssemblerTracer::CheckNotBackReferenceIgnoreCase( 291 int start_reg, 292 Label* on_no_match) { 293 PrintF(" CheckNotBackReferenceIgnoreCase(register=%d, label[%08x]);\n", 294 start_reg, LabelToInt(on_no_match)); 295 assembler_->CheckNotBackReferenceIgnoreCase(start_reg, on_no_match); 296} 297 298 299void RegExpMacroAssemblerTracer::CheckNotRegistersEqual(int reg1, 300 int reg2, 301 Label* on_not_equal) { 302 PrintF(" CheckNotRegistersEqual(reg1=%d, reg2=%d, label[%08x]);\n", 303 reg1, 304 reg2, 305 LabelToInt(on_not_equal)); 306 assembler_->CheckNotRegistersEqual(reg1, reg2, on_not_equal); 307} 308 309 310void RegExpMacroAssemblerTracer::CheckCharacters(Vector<const uc16> str, 311 int cp_offset, 312 Label* on_failure, 313 bool check_end_of_string) { 314 PrintF(" %s(str=\"", 315 check_end_of_string ? "CheckCharacters" : "CheckCharactersUnchecked"); 316 for (int i = 0; i < str.length(); i++) { 317 PrintF("u%04x", str[i]); 318 } 319 PrintF("\", cp_offset=%d, label[%08x])\n", 320 cp_offset, LabelToInt(on_failure)); 321 assembler_->CheckCharacters(str, cp_offset, on_failure, check_end_of_string); 322} 323 324 325bool RegExpMacroAssemblerTracer::CheckSpecialCharacterClass( 326 uc16 type, 327 Label* on_no_match) { 328 bool supported = assembler_->CheckSpecialCharacterClass(type, 329 on_no_match); 330 PrintF(" CheckSpecialCharacterClass(type='%c', label[%08x]): %s;\n", 331 type, 332 LabelToInt(on_no_match), 333 supported ? "true" : "false"); 334 return supported; 335} 336 337 338void RegExpMacroAssemblerTracer::IfRegisterLT(int register_index, 339 int comparand, Label* if_lt) { 340 PrintF(" IfRegisterLT(register=%d, number=%d, label[%08x]);\n", 341 register_index, comparand, LabelToInt(if_lt)); 342 assembler_->IfRegisterLT(register_index, comparand, if_lt); 343} 344 345 346void RegExpMacroAssemblerTracer::IfRegisterEqPos(int register_index, 347 Label* if_eq) { 348 PrintF(" IfRegisterEqPos(register=%d, label[%08x]);\n", 349 register_index, LabelToInt(if_eq)); 350 assembler_->IfRegisterEqPos(register_index, if_eq); 351} 352 353 354void RegExpMacroAssemblerTracer::IfRegisterGE(int register_index, 355 int comparand, Label* if_ge) { 356 PrintF(" IfRegisterGE(register=%d, number=%d, label[%08x]);\n", 357 register_index, comparand, LabelToInt(if_ge)); 358 assembler_->IfRegisterGE(register_index, comparand, if_ge); 359} 360 361 362RegExpMacroAssembler::IrregexpImplementation 363 RegExpMacroAssemblerTracer::Implementation() { 364 return assembler_->Implementation(); 365} 366 367 368Handle<HeapObject> RegExpMacroAssemblerTracer::GetCode(Handle<String> source) { 369 PrintF(" GetCode(%s);\n", *(source->ToCString())); 370 return assembler_->GetCode(source); 371} 372 373}} // namespace v8::internal 374