| OLD | NEW |
| 1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 return kBytecodeImplementation; | 53 return kBytecodeImplementation; |
| 54 } | 54 } |
| 55 | 55 |
| 56 | 56 |
| 57 void RegExpMacroAssemblerIrregexp::Bind(Label* l) { | 57 void RegExpMacroAssemblerIrregexp::Bind(Label* l) { |
| 58 ASSERT(!l->is_bound()); | 58 ASSERT(!l->is_bound()); |
| 59 if (l->is_linked()) { | 59 if (l->is_linked()) { |
| 60 int pos = l->pos(); | 60 int pos = l->pos(); |
| 61 while (pos != 0) { | 61 while (pos != 0) { |
| 62 int fixup = pos; | 62 int fixup = pos; |
| 63 pos = Load32(buffer_.start() + fixup); | 63 pos = *reinterpret_cast<int32_t*>(buffer_.start() + fixup); |
| 64 Store32(buffer_.start() + fixup, pc_); | 64 *reinterpret_cast<uint32_t*>(buffer_.start() + fixup) = pc_; |
| 65 } | 65 } |
| 66 } | 66 } |
| 67 l->bind_to(pc_); | 67 l->bind_to(pc_); |
| 68 } | 68 } |
| 69 | 69 |
| 70 | 70 |
| 71 void RegExpMacroAssemblerIrregexp::EmitOrLink(Label* l) { | 71 void RegExpMacroAssemblerIrregexp::EmitOrLink(Label* l) { |
| 72 if (l == NULL) l = &backtrack_; | 72 if (l == NULL) l = &backtrack_; |
| 73 if (l->is_bound()) { | 73 if (l->is_bound()) { |
| 74 Emit32(l->pos()); | 74 Emit32(l->pos()); |
| 75 } else { | 75 } else { |
| 76 int pos = 0; | 76 int pos = 0; |
| 77 if (l->is_linked()) { | 77 if (l->is_linked()) { |
| 78 pos = l->pos(); | 78 pos = l->pos(); |
| 79 } | 79 } |
| 80 l->link_to(pc_); | 80 l->link_to(pc_); |
| 81 Emit32(pos); | 81 Emit32(pos); |
| 82 } | 82 } |
| 83 } | 83 } |
| 84 | 84 |
| 85 | 85 |
| 86 void RegExpMacroAssemblerIrregexp::PopRegister(int register_index) { | 86 void RegExpMacroAssemblerIrregexp::PopRegister(int register_index) { |
| 87 Emit(BC_POP_REGISTER); | 87 ASSERT(register_index >= 0); |
| 88 Emit(register_index); | 88 ASSERT(register_index <= kMaxRegister); |
| 89 Emit(BC_POP_REGISTER, register_index); |
| 89 } | 90 } |
| 90 | 91 |
| 91 | 92 |
| 92 void RegExpMacroAssemblerIrregexp::PushRegister( | 93 void RegExpMacroAssemblerIrregexp::PushRegister( |
| 93 int register_index, | 94 int register_index, |
| 94 StackCheckFlag check_stack_limit) { | 95 StackCheckFlag check_stack_limit) { |
| 95 ASSERT(register_index >= 0); | 96 ASSERT(register_index >= 0); |
| 96 Emit(BC_PUSH_REGISTER); | 97 ASSERT(register_index <= kMaxRegister); |
| 97 Emit(register_index); | 98 Emit(BC_PUSH_REGISTER, register_index); |
| 98 } | 99 } |
| 99 | 100 |
| 100 | 101 |
| 101 void RegExpMacroAssemblerIrregexp::WriteCurrentPositionToRegister( | 102 void RegExpMacroAssemblerIrregexp::WriteCurrentPositionToRegister( |
| 102 int register_index, int cp_offset) { | 103 int register_index, int cp_offset) { |
| 103 ASSERT(register_index >= 0); | 104 ASSERT(register_index >= 0); |
| 104 Emit(BC_SET_REGISTER_TO_CP); | 105 ASSERT(register_index <= kMaxRegister); |
| 105 Emit(register_index); | 106 Emit(BC_SET_REGISTER_TO_CP, register_index); |
| 106 Emit32(cp_offset); // Current position offset. | 107 Emit32(cp_offset); // Current position offset. |
| 107 } | 108 } |
| 108 | 109 |
| 109 | 110 |
| 110 void RegExpMacroAssemblerIrregexp::ClearRegister(int reg) { | 111 void RegExpMacroAssemblerIrregexp::ClearRegisters(int reg_from, int reg_to) { |
| 111 SetRegister(reg, -1); | 112 ASSERT(reg_from <= reg_to); |
| 113 for (int reg = reg_from; reg <= reg_to; reg++) { |
| 114 SetRegister(reg, -1); |
| 115 } |
| 112 } | 116 } |
| 113 | 117 |
| 114 | 118 |
| 115 void RegExpMacroAssemblerIrregexp::ReadCurrentPositionFromRegister( | 119 void RegExpMacroAssemblerIrregexp::ReadCurrentPositionFromRegister( |
| 116 int register_index) { | 120 int register_index) { |
| 117 ASSERT(register_index >= 0); | 121 ASSERT(register_index >= 0); |
| 118 Emit(BC_SET_CP_TO_REGISTER); | 122 ASSERT(register_index <= kMaxRegister); |
| 119 Emit(register_index); | 123 Emit(BC_SET_CP_TO_REGISTER, register_index); |
| 120 } | 124 } |
| 121 | 125 |
| 122 | 126 |
| 123 void RegExpMacroAssemblerIrregexp::WriteStackPointerToRegister( | 127 void RegExpMacroAssemblerIrregexp::WriteStackPointerToRegister( |
| 124 int register_index) { | 128 int register_index) { |
| 125 ASSERT(register_index >= 0); | 129 ASSERT(register_index >= 0); |
| 126 Emit(BC_SET_REGISTER_TO_SP); | 130 ASSERT(register_index <= kMaxRegister); |
| 127 Emit(register_index); | 131 Emit(BC_SET_REGISTER_TO_SP, register_index); |
| 128 } | 132 } |
| 129 | 133 |
| 130 | 134 |
| 131 void RegExpMacroAssemblerIrregexp::ReadStackPointerFromRegister( | 135 void RegExpMacroAssemblerIrregexp::ReadStackPointerFromRegister( |
| 132 int register_index) { | 136 int register_index) { |
| 133 ASSERT(register_index >= 0); | 137 ASSERT(register_index >= 0); |
| 134 Emit(BC_SET_SP_TO_REGISTER); | 138 ASSERT(register_index <= kMaxRegister); |
| 135 Emit(register_index); | 139 Emit(BC_SET_SP_TO_REGISTER, register_index); |
| 136 } | 140 } |
| 137 | 141 |
| 138 | 142 |
| 139 void RegExpMacroAssemblerIrregexp::SetRegister(int register_index, int to) { | 143 void RegExpMacroAssemblerIrregexp::SetRegister(int register_index, int to) { |
| 140 ASSERT(register_index >= 0); | 144 ASSERT(register_index >= 0); |
| 141 Emit(BC_SET_REGISTER); | 145 ASSERT(register_index <= kMaxRegister); |
| 142 Emit(register_index); | 146 Emit(BC_SET_REGISTER, register_index); |
| 143 Emit32(to); | 147 Emit32(to); |
| 144 } | 148 } |
| 145 | 149 |
| 146 | 150 |
| 147 void RegExpMacroAssemblerIrregexp::AdvanceRegister(int register_index, int by) { | 151 void RegExpMacroAssemblerIrregexp::AdvanceRegister(int register_index, int by) { |
| 148 ASSERT(register_index >= 0); | 152 ASSERT(register_index >= 0); |
| 149 Emit(BC_ADVANCE_REGISTER); | 153 ASSERT(register_index <= kMaxRegister); |
| 150 Emit(register_index); | 154 Emit(BC_ADVANCE_REGISTER, register_index); |
| 151 Emit32(by); | 155 Emit32(by); |
| 152 } | 156 } |
| 153 | 157 |
| 154 | 158 |
| 155 void RegExpMacroAssemblerIrregexp::PopCurrentPosition() { | 159 void RegExpMacroAssemblerIrregexp::PopCurrentPosition() { |
| 156 Emit(BC_POP_CP); | 160 Emit(BC_POP_CP, 0); |
| 157 } | 161 } |
| 158 | 162 |
| 159 | 163 |
| 160 void RegExpMacroAssemblerIrregexp::PushCurrentPosition() { | 164 void RegExpMacroAssemblerIrregexp::PushCurrentPosition() { |
| 161 Emit(BC_PUSH_CP); | 165 Emit(BC_PUSH_CP, 0); |
| 162 Emit32(0); // Current position offset. | |
| 163 } | 166 } |
| 164 | 167 |
| 165 | 168 |
| 166 void RegExpMacroAssemblerIrregexp::Backtrack() { | 169 void RegExpMacroAssemblerIrregexp::Backtrack() { |
| 167 Emit(BC_POP_BT); | 170 Emit(BC_POP_BT, 0); |
| 168 } | 171 } |
| 169 | 172 |
| 170 | 173 |
| 171 void RegExpMacroAssemblerIrregexp::GoTo(Label* l) { | 174 void RegExpMacroAssemblerIrregexp::GoTo(Label* l) { |
| 172 Emit(BC_GOTO); | 175 Emit(BC_GOTO, 0); |
| 173 EmitOrLink(l); | 176 EmitOrLink(l); |
| 174 } | 177 } |
| 175 | 178 |
| 176 | 179 |
| 177 void RegExpMacroAssemblerIrregexp::PushBacktrack(Label* l) { | 180 void RegExpMacroAssemblerIrregexp::PushBacktrack(Label* l) { |
| 178 Emit(BC_PUSH_BT); | 181 Emit(BC_PUSH_BT, 0); |
| 179 EmitOrLink(l); | 182 EmitOrLink(l); |
| 180 } | 183 } |
| 181 | 184 |
| 182 | 185 |
| 183 void RegExpMacroAssemblerIrregexp::Succeed() { | 186 void RegExpMacroAssemblerIrregexp::Succeed() { |
| 184 Emit(BC_SUCCEED); | 187 Emit(BC_SUCCEED, 0); |
| 185 } | 188 } |
| 186 | 189 |
| 187 | 190 |
| 188 void RegExpMacroAssemblerIrregexp::Fail() { | 191 void RegExpMacroAssemblerIrregexp::Fail() { |
| 189 Emit(BC_FAIL); | 192 Emit(BC_FAIL, 0); |
| 190 } | 193 } |
| 191 | 194 |
| 192 | 195 |
| 193 void RegExpMacroAssemblerIrregexp::AdvanceCurrentPosition(int by) { | 196 void RegExpMacroAssemblerIrregexp::AdvanceCurrentPosition(int by) { |
| 194 Emit(BC_ADVANCE_CP); | 197 ASSERT(by >= kMinCPOffset); |
| 195 Emit32(by); | 198 ASSERT(by <= kMaxCPOffset); |
| 199 Emit(BC_ADVANCE_CP, by); |
| 196 } | 200 } |
| 197 | 201 |
| 198 | 202 |
| 199 void RegExpMacroAssemblerIrregexp::CheckGreedyLoop( | 203 void RegExpMacroAssemblerIrregexp::CheckGreedyLoop( |
| 200 Label* on_tos_equals_current_position) { | 204 Label* on_tos_equals_current_position) { |
| 201 Emit(BC_CHECK_GREEDY); | 205 Emit(BC_CHECK_GREEDY, 0); |
| 202 EmitOrLink(on_tos_equals_current_position); | 206 EmitOrLink(on_tos_equals_current_position); |
| 203 } | 207 } |
| 204 | 208 |
| 205 | 209 |
| 206 void RegExpMacroAssemblerIrregexp::LoadCurrentCharacter(int cp_offset, | 210 void RegExpMacroAssemblerIrregexp::LoadCurrentCharacter(int cp_offset, |
| 207 Label* on_failure, | 211 Label* on_failure, |
| 208 bool check_bounds, | 212 bool check_bounds, |
| 209 int characters) { | 213 int characters) { |
| 214 ASSERT(cp_offset >= kMinCPOffset); |
| 215 ASSERT(cp_offset <= kMaxCPOffset); |
| 210 int bytecode; | 216 int bytecode; |
| 211 if (check_bounds) { | 217 if (check_bounds) { |
| 212 if (characters == 4) { | 218 if (characters == 4) { |
| 213 bytecode = BC_LOAD_4_CURRENT_CHARS; | 219 bytecode = BC_LOAD_4_CURRENT_CHARS; |
| 214 } else if (characters == 2) { | 220 } else if (characters == 2) { |
| 215 bytecode = BC_LOAD_2_CURRENT_CHARS; | 221 bytecode = BC_LOAD_2_CURRENT_CHARS; |
| 216 } else { | 222 } else { |
| 217 ASSERT(characters == 1); | 223 ASSERT(characters == 1); |
| 218 bytecode = BC_LOAD_CURRENT_CHAR; | 224 bytecode = BC_LOAD_CURRENT_CHAR; |
| 219 } | 225 } |
| 220 } else { | 226 } else { |
| 221 if (characters == 4) { | 227 if (characters == 4) { |
| 222 bytecode = BC_LOAD_4_CURRENT_CHARS_UNCHECKED; | 228 bytecode = BC_LOAD_4_CURRENT_CHARS_UNCHECKED; |
| 223 } else if (characters == 2) { | 229 } else if (characters == 2) { |
| 224 bytecode = BC_LOAD_2_CURRENT_CHARS_UNCHECKED; | 230 bytecode = BC_LOAD_2_CURRENT_CHARS_UNCHECKED; |
| 225 } else { | 231 } else { |
| 226 ASSERT(characters == 1); | 232 ASSERT(characters == 1); |
| 227 bytecode = BC_LOAD_CURRENT_CHAR_UNCHECKED; | 233 bytecode = BC_LOAD_CURRENT_CHAR_UNCHECKED; |
| 228 } | 234 } |
| 229 } | 235 } |
| 230 Emit(bytecode); | 236 Emit(bytecode, cp_offset); |
| 231 Emit32(cp_offset); | |
| 232 if (check_bounds) EmitOrLink(on_failure); | 237 if (check_bounds) EmitOrLink(on_failure); |
| 233 } | 238 } |
| 234 | 239 |
| 235 | 240 |
| 236 void RegExpMacroAssemblerIrregexp::CheckCharacterLT(uc16 limit, | 241 void RegExpMacroAssemblerIrregexp::CheckCharacterLT(uc16 limit, |
| 237 Label* on_less) { | 242 Label* on_less) { |
| 238 Emit(BC_CHECK_LT); | 243 Emit(BC_CHECK_LT, limit); |
| 239 Emit16(limit); | |
| 240 EmitOrLink(on_less); | 244 EmitOrLink(on_less); |
| 241 } | 245 } |
| 242 | 246 |
| 243 | 247 |
| 244 void RegExpMacroAssemblerIrregexp::CheckCharacterGT(uc16 limit, | 248 void RegExpMacroAssemblerIrregexp::CheckCharacterGT(uc16 limit, |
| 245 Label* on_greater) { | 249 Label* on_greater) { |
| 246 Emit(BC_CHECK_GT); | 250 Emit(BC_CHECK_GT, limit); |
| 247 Emit16(limit); | |
| 248 EmitOrLink(on_greater); | 251 EmitOrLink(on_greater); |
| 249 } | 252 } |
| 250 | 253 |
| 251 | 254 |
| 252 void RegExpMacroAssemblerIrregexp::CheckCharacter(uint32_t c, Label* on_equal) { | 255 void RegExpMacroAssemblerIrregexp::CheckCharacter(uint32_t c, Label* on_equal) { |
| 253 Emit(BC_CHECK_CHAR); | 256 if (c > MAX_FIRST_ARG) { |
| 254 Emit32(c); | 257 Emit(BC_CHECK_4_CHARS, 0); |
| 258 Emit32(c); |
| 259 } else { |
| 260 Emit(BC_CHECK_CHAR, c); |
| 261 } |
| 255 EmitOrLink(on_equal); | 262 EmitOrLink(on_equal); |
| 256 } | 263 } |
| 257 | 264 |
| 258 | 265 |
| 266 void RegExpMacroAssemblerIrregexp::CheckAtStart(Label* on_at_start) { |
| 267 Emit(BC_CHECK_AT_START, 0); |
| 268 EmitOrLink(on_at_start); |
| 269 } |
| 270 |
| 271 |
| 259 void RegExpMacroAssemblerIrregexp::CheckNotAtStart(Label* on_not_at_start) { | 272 void RegExpMacroAssemblerIrregexp::CheckNotAtStart(Label* on_not_at_start) { |
| 260 Emit(BC_CHECK_NOT_AT_START); | 273 Emit(BC_CHECK_NOT_AT_START, 0); |
| 261 EmitOrLink(on_not_at_start); | 274 EmitOrLink(on_not_at_start); |
| 262 } | 275 } |
| 263 | 276 |
| 264 | 277 |
| 265 void RegExpMacroAssemblerIrregexp::CheckNotCharacter(uint32_t c, | 278 void RegExpMacroAssemblerIrregexp::CheckNotCharacter(uint32_t c, |
| 266 Label* on_not_equal) { | 279 Label* on_not_equal) { |
| 267 Emit(BC_CHECK_NOT_CHAR); | 280 if (c > MAX_FIRST_ARG) { |
| 268 Emit32(c); | 281 Emit(BC_CHECK_NOT_4_CHARS, 0); |
| 282 Emit32(c); |
| 283 } else { |
| 284 Emit(BC_CHECK_NOT_CHAR, c); |
| 285 } |
| 269 EmitOrLink(on_not_equal); | 286 EmitOrLink(on_not_equal); |
| 270 } | 287 } |
| 271 | 288 |
| 272 | 289 |
| 273 void RegExpMacroAssemblerIrregexp::CheckCharacterAfterAnd( | 290 void RegExpMacroAssemblerIrregexp::CheckCharacterAfterAnd( |
| 274 uint32_t c, | 291 uint32_t c, |
| 275 uint32_t mask, | 292 uint32_t mask, |
| 276 Label* on_equal) { | 293 Label* on_equal) { |
| 277 Emit(BC_AND_CHECK_CHAR); | 294 if (c > MAX_FIRST_ARG) { |
| 278 Emit32(c); | 295 Emit(BC_AND_CHECK_4_CHARS, 0); |
| 296 Emit32(c); |
| 297 } else { |
| 298 Emit(BC_AND_CHECK_CHAR, c); |
| 299 } |
| 279 Emit32(mask); | 300 Emit32(mask); |
| 280 EmitOrLink(on_equal); | 301 EmitOrLink(on_equal); |
| 281 } | 302 } |
| 282 | 303 |
| 283 | 304 |
| 284 void RegExpMacroAssemblerIrregexp::CheckNotCharacterAfterAnd( | 305 void RegExpMacroAssemblerIrregexp::CheckNotCharacterAfterAnd( |
| 285 uint32_t c, | 306 uint32_t c, |
| 286 uint32_t mask, | 307 uint32_t mask, |
| 287 Label* on_not_equal) { | 308 Label* on_not_equal) { |
| 288 Emit(BC_AND_CHECK_NOT_CHAR); | 309 if (c > MAX_FIRST_ARG) { |
| 289 Emit32(c); | 310 Emit(BC_AND_CHECK_NOT_4_CHARS, 0); |
| 311 Emit32(c); |
| 312 } else { |
| 313 Emit(BC_AND_CHECK_NOT_CHAR, c); |
| 314 } |
| 290 Emit32(mask); | 315 Emit32(mask); |
| 291 EmitOrLink(on_not_equal); | 316 EmitOrLink(on_not_equal); |
| 292 } | 317 } |
| 293 | 318 |
| 294 | 319 |
| 295 void RegExpMacroAssemblerIrregexp::CheckNotCharacterAfterMinusAnd( | 320 void RegExpMacroAssemblerIrregexp::CheckNotCharacterAfterMinusAnd( |
| 296 uc16 c, | 321 uc16 c, |
| 297 uc16 minus, | 322 uc16 minus, |
| 298 uc16 mask, | 323 uc16 mask, |
| 299 Label* on_not_equal) { | 324 Label* on_not_equal) { |
| 300 Emit(BC_MINUS_AND_CHECK_NOT_CHAR); | 325 Emit(BC_MINUS_AND_CHECK_NOT_CHAR, c); |
| 301 Emit16(c); | |
| 302 Emit16(minus); | 326 Emit16(minus); |
| 303 Emit16(mask); | 327 Emit16(mask); |
| 304 EmitOrLink(on_not_equal); | 328 EmitOrLink(on_not_equal); |
| 305 } | 329 } |
| 306 | 330 |
| 307 | 331 |
| 308 void RegExpMacroAssemblerIrregexp::CheckNotBackReference(int start_reg, | 332 void RegExpMacroAssemblerIrregexp::CheckNotBackReference(int start_reg, |
| 309 Label* on_not_equal) { | 333 Label* on_not_equal) { |
| 310 Emit(BC_CHECK_NOT_BACK_REF); | 334 ASSERT(start_reg >= 0); |
| 311 Emit(start_reg); | 335 ASSERT(start_reg <= kMaxRegister); |
| 336 Emit(BC_CHECK_NOT_BACK_REF, start_reg); |
| 312 EmitOrLink(on_not_equal); | 337 EmitOrLink(on_not_equal); |
| 313 } | 338 } |
| 314 | 339 |
| 315 | 340 |
| 316 void RegExpMacroAssemblerIrregexp::CheckNotBackReferenceIgnoreCase( | 341 void RegExpMacroAssemblerIrregexp::CheckNotBackReferenceIgnoreCase( |
| 317 int start_reg, | 342 int start_reg, |
| 318 Label* on_not_equal) { | 343 Label* on_not_equal) { |
| 319 Emit(BC_CHECK_NOT_BACK_REF_NO_CASE); | 344 ASSERT(start_reg >= 0); |
| 320 Emit(start_reg); | 345 ASSERT(start_reg <= kMaxRegister); |
| 346 Emit(BC_CHECK_NOT_BACK_REF_NO_CASE, start_reg); |
| 321 EmitOrLink(on_not_equal); | 347 EmitOrLink(on_not_equal); |
| 322 } | 348 } |
| 323 | 349 |
| 324 | 350 |
| 325 void RegExpMacroAssemblerIrregexp::CheckNotRegistersEqual(int reg1, | 351 void RegExpMacroAssemblerIrregexp::CheckNotRegistersEqual(int reg1, |
| 326 int reg2, | 352 int reg2, |
| 327 Label* on_not_equal) { | 353 Label* on_not_equal) { |
| 328 Emit(BC_CHECK_NOT_REGS_EQUAL); | 354 ASSERT(reg1 >= 0); |
| 329 Emit(reg1); | 355 ASSERT(reg1 <= kMaxRegister); |
| 330 Emit(reg2); | 356 Emit(BC_CHECK_NOT_REGS_EQUAL, reg1); |
| 357 Emit32(reg2); |
| 331 EmitOrLink(on_not_equal); | 358 EmitOrLink(on_not_equal); |
| 332 } | 359 } |
| 333 | 360 |
| 334 | 361 |
| 335 void RegExpMacroAssemblerIrregexp::CheckBitmap(uc16 start, | 362 void RegExpMacroAssemblerIrregexp::CheckBitmap(uc16 start, |
| 336 Label* bitmap, | 363 Label* bitmap, |
| 337 Label* on_zero) { | 364 Label* on_zero) { |
| 338 UNIMPLEMENTED(); | 365 UNIMPLEMENTED(); |
| 339 } | 366 } |
| 340 | 367 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 361 const Vector<Label*>& table) { | 388 const Vector<Label*>& table) { |
| 362 UNIMPLEMENTED(); | 389 UNIMPLEMENTED(); |
| 363 } | 390 } |
| 364 | 391 |
| 365 | 392 |
| 366 void RegExpMacroAssemblerIrregexp::CheckCharacters( | 393 void RegExpMacroAssemblerIrregexp::CheckCharacters( |
| 367 Vector<const uc16> str, | 394 Vector<const uc16> str, |
| 368 int cp_offset, | 395 int cp_offset, |
| 369 Label* on_failure, | 396 Label* on_failure, |
| 370 bool check_end_of_string) { | 397 bool check_end_of_string) { |
| 398 ASSERT(cp_offset >= kMinCPOffset); |
| 399 ASSERT(cp_offset + str.length() - 1 <= kMaxCPOffset); |
| 371 // It is vital that this loop is backwards due to the unchecked character | 400 // It is vital that this loop is backwards due to the unchecked character |
| 372 // load below. | 401 // load below. |
| 373 for (int i = str.length() - 1; i >= 0; i--) { | 402 for (int i = str.length() - 1; i >= 0; i--) { |
| 374 if (check_end_of_string && i == str.length() - 1) { | 403 if (check_end_of_string && i == str.length() - 1) { |
| 375 Emit(BC_LOAD_CURRENT_CHAR); | 404 Emit(BC_LOAD_CURRENT_CHAR, cp_offset + i); |
| 376 Emit32(cp_offset + i); | |
| 377 EmitOrLink(on_failure); | 405 EmitOrLink(on_failure); |
| 378 } else { | 406 } else { |
| 379 Emit(BC_LOAD_CURRENT_CHAR_UNCHECKED); | 407 Emit(BC_LOAD_CURRENT_CHAR_UNCHECKED, cp_offset + i); |
| 380 Emit32(cp_offset + i); | |
| 381 } | 408 } |
| 382 Emit(BC_CHECK_NOT_CHAR); | 409 Emit(BC_CHECK_NOT_CHAR, str[i]); |
| 383 Emit32(str[i]); | |
| 384 EmitOrLink(on_failure); | 410 EmitOrLink(on_failure); |
| 385 } | 411 } |
| 386 } | 412 } |
| 387 | 413 |
| 388 | 414 |
| 389 void RegExpMacroAssemblerIrregexp::IfRegisterLT(int register_index, | 415 void RegExpMacroAssemblerIrregexp::IfRegisterLT(int register_index, |
| 390 int comparand, | 416 int comparand, |
| 391 Label* on_less_than) { | 417 Label* on_less_than) { |
| 392 ASSERT(comparand >= 0 && comparand <= 65535); | 418 ASSERT(register_index >= 0); |
| 393 Emit(BC_CHECK_REGISTER_LT); | 419 ASSERT(register_index <= kMaxRegister); |
| 394 Emit(register_index); | 420 Emit(BC_CHECK_REGISTER_LT, register_index); |
| 395 Emit16(comparand); | 421 Emit32(comparand); |
| 396 EmitOrLink(on_less_than); | 422 EmitOrLink(on_less_than); |
| 397 } | 423 } |
| 398 | 424 |
| 399 | 425 |
| 400 void RegExpMacroAssemblerIrregexp::IfRegisterGE(int register_index, | 426 void RegExpMacroAssemblerIrregexp::IfRegisterGE(int register_index, |
| 401 int comparand, | 427 int comparand, |
| 402 Label* on_greater_or_equal) { | 428 Label* on_greater_or_equal) { |
| 403 ASSERT(comparand >= 0 && comparand <= 65535); | 429 ASSERT(register_index >= 0); |
| 404 Emit(BC_CHECK_REGISTER_GE); | 430 ASSERT(register_index <= kMaxRegister); |
| 405 Emit(register_index); | 431 Emit(BC_CHECK_REGISTER_GE, register_index); |
| 406 Emit16(comparand); | 432 Emit32(comparand); |
| 407 EmitOrLink(on_greater_or_equal); | 433 EmitOrLink(on_greater_or_equal); |
| 408 } | 434 } |
| 409 | 435 |
| 410 | 436 |
| 411 void RegExpMacroAssemblerIrregexp::IfRegisterEqPos(int register_index, | 437 void RegExpMacroAssemblerIrregexp::IfRegisterEqPos(int register_index, |
| 412 Label* on_eq) { | 438 Label* on_eq) { |
| 413 Emit(BC_CHECK_REGISTER_EQ_POS); | 439 ASSERT(register_index >= 0); |
| 414 Emit(register_index); | 440 ASSERT(register_index <= kMaxRegister); |
| 441 Emit(BC_CHECK_REGISTER_EQ_POS, register_index); |
| 415 EmitOrLink(on_eq); | 442 EmitOrLink(on_eq); |
| 416 } | 443 } |
| 417 | 444 |
| 418 | 445 |
| 419 Handle<Object> RegExpMacroAssemblerIrregexp::GetCode(Handle<String> source) { | 446 Handle<Object> RegExpMacroAssemblerIrregexp::GetCode(Handle<String> source) { |
| 420 Bind(&backtrack_); | 447 Bind(&backtrack_); |
| 421 Emit(BC_POP_BT); | 448 Emit(BC_POP_BT, 0); |
| 422 Handle<ByteArray> array = Factory::NewByteArray(length()); | 449 Handle<ByteArray> array = Factory::NewByteArray(length()); |
| 423 Copy(array->GetDataStartAddress()); | 450 Copy(array->GetDataStartAddress()); |
| 424 return array; | 451 return array; |
| 425 } | 452 } |
| 426 | 453 |
| 427 | 454 |
| 428 int RegExpMacroAssemblerIrregexp::length() { | 455 int RegExpMacroAssemblerIrregexp::length() { |
| 429 return pc_; | 456 return pc_; |
| 430 } | 457 } |
| 431 | 458 |
| 432 | 459 |
| 433 void RegExpMacroAssemblerIrregexp::Copy(Address a) { | 460 void RegExpMacroAssemblerIrregexp::Copy(Address a) { |
| 434 memcpy(a, buffer_.start(), length()); | 461 memcpy(a, buffer_.start(), length()); |
| 435 } | 462 } |
| 436 | 463 |
| 437 | 464 |
| 438 void RegExpMacroAssemblerIrregexp::Expand() { | 465 void RegExpMacroAssemblerIrregexp::Expand() { |
| 439 bool old_buffer_was_our_own = own_buffer_; | 466 bool old_buffer_was_our_own = own_buffer_; |
| 440 Vector<byte> old_buffer = buffer_; | 467 Vector<byte> old_buffer = buffer_; |
| 441 buffer_ = Vector<byte>::New(old_buffer.length() * 2); | 468 buffer_ = Vector<byte>::New(old_buffer.length() * 2); |
| 442 own_buffer_ = true; | 469 own_buffer_ = true; |
| 443 memcpy(buffer_.start(), old_buffer.start(), old_buffer.length()); | 470 memcpy(buffer_.start(), old_buffer.start(), old_buffer.length()); |
| 444 if (old_buffer_was_our_own) { | 471 if (old_buffer_was_our_own) { |
| 445 old_buffer.Dispose(); | 472 old_buffer.Dispose(); |
| 446 } | 473 } |
| 447 } | 474 } |
| 448 | 475 |
| 449 | 476 |
| 450 } } // namespace v8::internal | 477 } } // namespace v8::internal |
| OLD | NEW |