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