2009-02-19 10:03:27 +00:00
|
|
|
// Copyright 2008-2009 the V8 project authors. All rights reserved.
|
2008-11-25 11:07:48 +00:00
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following
|
|
|
|
// disclaimer in the documentation and/or other materials provided
|
|
|
|
// with the distribution.
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived
|
|
|
|
// from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
#include "v8.h"
|
|
|
|
#include "ast.h"
|
|
|
|
#include "bytecodes-irregexp.h"
|
|
|
|
#include "regexp-macro-assembler.h"
|
|
|
|
#include "regexp-macro-assembler-irregexp.h"
|
2008-11-28 10:37:06 +00:00
|
|
|
#include "regexp-macro-assembler-irregexp-inl.h"
|
2008-11-25 11:07:48 +00:00
|
|
|
|
|
|
|
|
2009-05-25 10:05:56 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2008-11-25 11:07:48 +00:00
|
|
|
|
2010-04-19 19:30:11 +00:00
|
|
|
#ifdef V8_INTERPRETED_REGEXP
|
2008-11-25 11:07:48 +00:00
|
|
|
|
2012-06-14 17:06:16 +00:00
|
|
|
RegExpMacroAssemblerIrregexp::RegExpMacroAssemblerIrregexp(Vector<byte> buffer,
|
|
|
|
Zone* zone)
|
|
|
|
: RegExpMacroAssembler(zone),
|
|
|
|
buffer_(buffer),
|
2008-11-28 10:37:06 +00:00
|
|
|
pc_(0),
|
2009-02-19 10:03:27 +00:00
|
|
|
own_buffer_(false),
|
|
|
|
advance_current_end_(kInvalidPC) {
|
2008-11-28 10:37:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-25 11:07:48 +00:00
|
|
|
RegExpMacroAssemblerIrregexp::~RegExpMacroAssemblerIrregexp() {
|
2008-12-19 12:02:34 +00:00
|
|
|
if (backtrack_.is_linked()) backtrack_.Unuse();
|
2009-06-15 06:27:33 +00:00
|
|
|
if (own_buffer_) buffer_.Dispose();
|
2008-11-25 11:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RegExpMacroAssemblerIrregexp::IrregexpImplementation
|
|
|
|
RegExpMacroAssemblerIrregexp::Implementation() {
|
|
|
|
return kBytecodeImplementation;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RegExpMacroAssemblerIrregexp::Bind(Label* l) {
|
2009-02-19 10:03:27 +00:00
|
|
|
advance_current_end_ = kInvalidPC;
|
2008-11-28 10:37:06 +00:00
|
|
|
ASSERT(!l->is_bound());
|
|
|
|
if (l->is_linked()) {
|
|
|
|
int pos = l->pos();
|
|
|
|
while (pos != 0) {
|
|
|
|
int fixup = pos;
|
2009-01-21 08:20:40 +00:00
|
|
|
pos = *reinterpret_cast<int32_t*>(buffer_.start() + fixup);
|
|
|
|
*reinterpret_cast<uint32_t*>(buffer_.start() + fixup) = pc_;
|
2008-11-28 10:37:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
l->bind_to(pc_);
|
2008-11-25 11:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RegExpMacroAssemblerIrregexp::EmitOrLink(Label* l) {
|
2008-12-08 09:22:12 +00:00
|
|
|
if (l == NULL) l = &backtrack_;
|
2008-11-28 10:37:06 +00:00
|
|
|
if (l->is_bound()) {
|
|
|
|
Emit32(l->pos());
|
|
|
|
} else {
|
|
|
|
int pos = 0;
|
|
|
|
if (l->is_linked()) {
|
|
|
|
pos = l->pos();
|
|
|
|
}
|
|
|
|
l->link_to(pc_);
|
|
|
|
Emit32(pos);
|
|
|
|
}
|
2008-11-25 11:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RegExpMacroAssemblerIrregexp::PopRegister(int register_index) {
|
2009-01-26 20:09:35 +00:00
|
|
|
ASSERT(register_index >= 0);
|
|
|
|
ASSERT(register_index <= kMaxRegister);
|
2009-01-20 18:50:01 +00:00
|
|
|
Emit(BC_POP_REGISTER, register_index);
|
2008-11-25 11:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-12 13:05:23 +00:00
|
|
|
void RegExpMacroAssemblerIrregexp::PushRegister(
|
|
|
|
int register_index,
|
|
|
|
StackCheckFlag check_stack_limit) {
|
2008-11-28 10:37:06 +00:00
|
|
|
ASSERT(register_index >= 0);
|
2009-01-26 20:09:35 +00:00
|
|
|
ASSERT(register_index <= kMaxRegister);
|
2009-01-20 18:50:01 +00:00
|
|
|
Emit(BC_PUSH_REGISTER, register_index);
|
2008-11-25 11:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RegExpMacroAssemblerIrregexp::WriteCurrentPositionToRegister(
|
2008-12-08 09:22:12 +00:00
|
|
|
int register_index, int cp_offset) {
|
2008-11-28 10:37:06 +00:00
|
|
|
ASSERT(register_index >= 0);
|
2009-01-26 20:09:35 +00:00
|
|
|
ASSERT(register_index <= kMaxRegister);
|
2009-01-20 18:50:01 +00:00
|
|
|
Emit(BC_SET_REGISTER_TO_CP, register_index);
|
2008-12-08 09:22:12 +00:00
|
|
|
Emit32(cp_offset); // Current position offset.
|
2008-11-25 11:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-26 14:38:17 +00:00
|
|
|
void RegExpMacroAssemblerIrregexp::ClearRegisters(int reg_from, int reg_to) {
|
|
|
|
ASSERT(reg_from <= reg_to);
|
|
|
|
for (int reg = reg_from; reg <= reg_to; reg++) {
|
|
|
|
SetRegister(reg, -1);
|
|
|
|
}
|
2009-01-14 11:32:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-25 11:07:48 +00:00
|
|
|
void RegExpMacroAssemblerIrregexp::ReadCurrentPositionFromRegister(
|
|
|
|
int register_index) {
|
2008-11-28 10:37:06 +00:00
|
|
|
ASSERT(register_index >= 0);
|
2009-01-26 20:09:35 +00:00
|
|
|
ASSERT(register_index <= kMaxRegister);
|
2009-01-20 18:50:01 +00:00
|
|
|
Emit(BC_SET_CP_TO_REGISTER, register_index);
|
2008-11-25 11:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RegExpMacroAssemblerIrregexp::WriteStackPointerToRegister(
|
|
|
|
int register_index) {
|
2008-11-28 10:37:06 +00:00
|
|
|
ASSERT(register_index >= 0);
|
2009-01-26 20:09:35 +00:00
|
|
|
ASSERT(register_index <= kMaxRegister);
|
2009-01-20 18:50:01 +00:00
|
|
|
Emit(BC_SET_REGISTER_TO_SP, register_index);
|
2008-11-25 11:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RegExpMacroAssemblerIrregexp::ReadStackPointerFromRegister(
|
|
|
|
int register_index) {
|
2008-11-28 10:37:06 +00:00
|
|
|
ASSERT(register_index >= 0);
|
2009-01-26 20:09:35 +00:00
|
|
|
ASSERT(register_index <= kMaxRegister);
|
2009-01-20 18:50:01 +00:00
|
|
|
Emit(BC_SET_SP_TO_REGISTER, register_index);
|
2008-11-25 11:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-19 14:00:01 +00:00
|
|
|
void RegExpMacroAssemblerIrregexp::SetCurrentPositionFromEnd(int by) {
|
|
|
|
ASSERT(is_uint24(by));
|
|
|
|
Emit(BC_SET_CURRENT_POSITION_FROM_END, by);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-25 11:07:48 +00:00
|
|
|
void RegExpMacroAssemblerIrregexp::SetRegister(int register_index, int to) {
|
2008-11-28 10:37:06 +00:00
|
|
|
ASSERT(register_index >= 0);
|
2009-01-26 20:09:35 +00:00
|
|
|
ASSERT(register_index <= kMaxRegister);
|
2009-01-20 18:50:01 +00:00
|
|
|
Emit(BC_SET_REGISTER, register_index);
|
2008-11-28 10:37:06 +00:00
|
|
|
Emit32(to);
|
2008-11-25 11:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RegExpMacroAssemblerIrregexp::AdvanceRegister(int register_index, int by) {
|
2008-11-28 10:37:06 +00:00
|
|
|
ASSERT(register_index >= 0);
|
2009-01-26 20:09:35 +00:00
|
|
|
ASSERT(register_index <= kMaxRegister);
|
2009-01-20 18:50:01 +00:00
|
|
|
Emit(BC_ADVANCE_REGISTER, register_index);
|
2008-11-28 10:37:06 +00:00
|
|
|
Emit32(by);
|
2008-11-25 11:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RegExpMacroAssemblerIrregexp::PopCurrentPosition() {
|
2009-01-20 18:50:01 +00:00
|
|
|
Emit(BC_POP_CP, 0);
|
2008-11-25 11:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RegExpMacroAssemblerIrregexp::PushCurrentPosition() {
|
2009-01-20 18:50:01 +00:00
|
|
|
Emit(BC_PUSH_CP, 0);
|
2008-11-25 11:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RegExpMacroAssemblerIrregexp::Backtrack() {
|
2009-01-20 18:50:01 +00:00
|
|
|
Emit(BC_POP_BT, 0);
|
2008-11-25 11:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RegExpMacroAssemblerIrregexp::GoTo(Label* l) {
|
2009-02-19 10:03:27 +00:00
|
|
|
if (advance_current_end_ == pc_) {
|
|
|
|
// Combine advance current and goto.
|
|
|
|
pc_ = advance_current_start_;
|
|
|
|
Emit(BC_ADVANCE_CP_AND_GOTO, advance_current_offset_);
|
|
|
|
EmitOrLink(l);
|
|
|
|
advance_current_end_ = kInvalidPC;
|
|
|
|
} else {
|
|
|
|
// Regular goto.
|
|
|
|
Emit(BC_GOTO, 0);
|
|
|
|
EmitOrLink(l);
|
|
|
|
}
|
2008-11-25 11:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RegExpMacroAssemblerIrregexp::PushBacktrack(Label* l) {
|
2009-01-20 18:50:01 +00:00
|
|
|
Emit(BC_PUSH_BT, 0);
|
2008-11-28 10:37:06 +00:00
|
|
|
EmitOrLink(l);
|
2008-11-25 11:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-22 14:05:44 +00:00
|
|
|
bool RegExpMacroAssemblerIrregexp::Succeed() {
|
2009-01-20 18:50:01 +00:00
|
|
|
Emit(BC_SUCCEED, 0);
|
2012-05-22 14:05:44 +00:00
|
|
|
return false; // Restart matching for global regexp not supported.
|
2008-11-25 11:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RegExpMacroAssemblerIrregexp::Fail() {
|
2009-01-20 18:50:01 +00:00
|
|
|
Emit(BC_FAIL, 0);
|
2008-11-25 11:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RegExpMacroAssemblerIrregexp::AdvanceCurrentPosition(int by) {
|
2009-01-26 20:09:35 +00:00
|
|
|
ASSERT(by >= kMinCPOffset);
|
|
|
|
ASSERT(by <= kMaxCPOffset);
|
2009-02-19 10:03:27 +00:00
|
|
|
advance_current_start_ = pc_;
|
|
|
|
advance_current_offset_ = by;
|
2009-01-20 18:50:01 +00:00
|
|
|
Emit(BC_ADVANCE_CP, by);
|
2009-02-19 10:03:27 +00:00
|
|
|
advance_current_end_ = pc_;
|
2008-11-25 11:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-08 09:22:12 +00:00
|
|
|
void RegExpMacroAssemblerIrregexp::CheckGreedyLoop(
|
|
|
|
Label* on_tos_equals_current_position) {
|
2009-01-20 18:50:01 +00:00
|
|
|
Emit(BC_CHECK_GREEDY, 0);
|
2008-12-08 09:22:12 +00:00
|
|
|
EmitOrLink(on_tos_equals_current_position);
|
2008-11-25 11:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RegExpMacroAssemblerIrregexp::LoadCurrentCharacter(int cp_offset,
|
2008-12-19 12:02:34 +00:00
|
|
|
Label* on_failure,
|
|
|
|
bool check_bounds,
|
|
|
|
int characters) {
|
2009-01-26 20:09:35 +00:00
|
|
|
ASSERT(cp_offset >= kMinCPOffset);
|
|
|
|
ASSERT(cp_offset <= kMaxCPOffset);
|
2008-12-19 12:02:34 +00:00
|
|
|
int bytecode;
|
|
|
|
if (check_bounds) {
|
|
|
|
if (characters == 4) {
|
|
|
|
bytecode = BC_LOAD_4_CURRENT_CHARS;
|
|
|
|
} else if (characters == 2) {
|
|
|
|
bytecode = BC_LOAD_2_CURRENT_CHARS;
|
|
|
|
} else {
|
|
|
|
ASSERT(characters == 1);
|
|
|
|
bytecode = BC_LOAD_CURRENT_CHAR;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (characters == 4) {
|
|
|
|
bytecode = BC_LOAD_4_CURRENT_CHARS_UNCHECKED;
|
|
|
|
} else if (characters == 2) {
|
|
|
|
bytecode = BC_LOAD_2_CURRENT_CHARS_UNCHECKED;
|
|
|
|
} else {
|
|
|
|
ASSERT(characters == 1);
|
|
|
|
bytecode = BC_LOAD_CURRENT_CHAR_UNCHECKED;
|
|
|
|
}
|
|
|
|
}
|
2009-01-20 18:50:01 +00:00
|
|
|
Emit(bytecode, cp_offset);
|
2008-12-19 12:02:34 +00:00
|
|
|
if (check_bounds) EmitOrLink(on_failure);
|
2008-12-08 09:22:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-25 11:07:48 +00:00
|
|
|
void RegExpMacroAssemblerIrregexp::CheckCharacterLT(uc16 limit,
|
|
|
|
Label* on_less) {
|
2009-01-20 18:50:01 +00:00
|
|
|
Emit(BC_CHECK_LT, limit);
|
2008-11-28 10:37:06 +00:00
|
|
|
EmitOrLink(on_less);
|
2008-11-25 11:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RegExpMacroAssemblerIrregexp::CheckCharacterGT(uc16 limit,
|
|
|
|
Label* on_greater) {
|
2009-01-20 18:50:01 +00:00
|
|
|
Emit(BC_CHECK_GT, limit);
|
2008-11-28 10:37:06 +00:00
|
|
|
EmitOrLink(on_greater);
|
2008-11-25 11:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-19 12:02:34 +00:00
|
|
|
void RegExpMacroAssemblerIrregexp::CheckCharacter(uint32_t c, Label* on_equal) {
|
2009-01-20 18:50:01 +00:00
|
|
|
if (c > MAX_FIRST_ARG) {
|
|
|
|
Emit(BC_CHECK_4_CHARS, 0);
|
|
|
|
Emit32(c);
|
|
|
|
} else {
|
|
|
|
Emit(BC_CHECK_CHAR, c);
|
|
|
|
}
|
2008-11-28 10:37:06 +00:00
|
|
|
EmitOrLink(on_equal);
|
2008-11-25 11:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-19 18:56:47 +00:00
|
|
|
void RegExpMacroAssemblerIrregexp::CheckAtStart(Label* on_at_start) {
|
2009-01-20 18:50:01 +00:00
|
|
|
Emit(BC_CHECK_AT_START, 0);
|
2009-01-19 18:56:47 +00:00
|
|
|
EmitOrLink(on_at_start);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-28 11:48:22 +00:00
|
|
|
void RegExpMacroAssemblerIrregexp::CheckNotAtStart(Label* on_not_at_start) {
|
2009-01-20 18:50:01 +00:00
|
|
|
Emit(BC_CHECK_NOT_AT_START, 0);
|
2008-11-28 11:48:22 +00:00
|
|
|
EmitOrLink(on_not_at_start);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-19 12:02:34 +00:00
|
|
|
void RegExpMacroAssemblerIrregexp::CheckNotCharacter(uint32_t c,
|
2008-11-25 11:07:48 +00:00
|
|
|
Label* on_not_equal) {
|
2009-01-20 18:50:01 +00:00
|
|
|
if (c > MAX_FIRST_ARG) {
|
|
|
|
Emit(BC_CHECK_NOT_4_CHARS, 0);
|
|
|
|
Emit32(c);
|
|
|
|
} else {
|
|
|
|
Emit(BC_CHECK_NOT_CHAR, c);
|
|
|
|
}
|
2008-11-28 10:37:06 +00:00
|
|
|
EmitOrLink(on_not_equal);
|
2008-11-25 11:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-19 12:02:34 +00:00
|
|
|
void RegExpMacroAssemblerIrregexp::CheckCharacterAfterAnd(
|
|
|
|
uint32_t c,
|
|
|
|
uint32_t mask,
|
|
|
|
Label* on_equal) {
|
2009-01-20 18:50:01 +00:00
|
|
|
if (c > MAX_FIRST_ARG) {
|
|
|
|
Emit(BC_AND_CHECK_4_CHARS, 0);
|
|
|
|
Emit32(c);
|
|
|
|
} else {
|
|
|
|
Emit(BC_AND_CHECK_CHAR, c);
|
|
|
|
}
|
2008-12-19 12:02:34 +00:00
|
|
|
Emit32(mask);
|
|
|
|
EmitOrLink(on_equal);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RegExpMacroAssemblerIrregexp::CheckNotCharacterAfterAnd(
|
|
|
|
uint32_t c,
|
|
|
|
uint32_t mask,
|
2008-11-28 10:37:06 +00:00
|
|
|
Label* on_not_equal) {
|
2009-01-20 18:50:01 +00:00
|
|
|
if (c > MAX_FIRST_ARG) {
|
|
|
|
Emit(BC_AND_CHECK_NOT_4_CHARS, 0);
|
|
|
|
Emit32(c);
|
|
|
|
} else {
|
|
|
|
Emit(BC_AND_CHECK_NOT_CHAR, c);
|
|
|
|
}
|
2008-12-19 12:02:34 +00:00
|
|
|
Emit32(mask);
|
2008-11-28 10:37:06 +00:00
|
|
|
EmitOrLink(on_not_equal);
|
2008-11-25 11:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-19 12:02:34 +00:00
|
|
|
void RegExpMacroAssemblerIrregexp::CheckNotCharacterAfterMinusAnd(
|
2008-11-25 11:07:48 +00:00
|
|
|
uc16 c,
|
2008-12-19 12:02:34 +00:00
|
|
|
uc16 minus,
|
2008-11-25 11:07:48 +00:00
|
|
|
uc16 mask,
|
|
|
|
Label* on_not_equal) {
|
2009-01-20 18:50:01 +00:00
|
|
|
Emit(BC_MINUS_AND_CHECK_NOT_CHAR, c);
|
2008-12-19 12:02:34 +00:00
|
|
|
Emit16(minus);
|
2008-11-28 10:37:06 +00:00
|
|
|
Emit16(mask);
|
|
|
|
EmitOrLink(on_not_equal);
|
2008-11-25 11:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-30 07:43:48 +00:00
|
|
|
void RegExpMacroAssemblerIrregexp::CheckCharacterInRange(
|
|
|
|
uc16 from,
|
|
|
|
uc16 to,
|
|
|
|
Label* on_in_range) {
|
|
|
|
Emit(BC_CHECK_CHAR_IN_RANGE, 0);
|
|
|
|
Emit16(from);
|
|
|
|
Emit16(to);
|
|
|
|
EmitOrLink(on_in_range);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RegExpMacroAssemblerIrregexp::CheckCharacterNotInRange(
|
|
|
|
uc16 from,
|
|
|
|
uc16 to,
|
|
|
|
Label* on_not_in_range) {
|
|
|
|
Emit(BC_CHECK_CHAR_NOT_IN_RANGE, 0);
|
|
|
|
Emit16(from);
|
|
|
|
Emit16(to);
|
|
|
|
EmitOrLink(on_not_in_range);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RegExpMacroAssemblerIrregexp::CheckBitInTable(
|
|
|
|
Handle<ByteArray> table, Label* on_bit_set) {
|
|
|
|
Emit(BC_CHECK_BIT_IN_TABLE, 0);
|
|
|
|
EmitOrLink(on_bit_set);
|
|
|
|
for (int i = 0; i < kTableSize; i += kBitsPerByte) {
|
|
|
|
int byte = 0;
|
|
|
|
for (int j = 0; j < kBitsPerByte; j++) {
|
|
|
|
if (table->get(i + j) != 0) byte |= 1 << j;
|
|
|
|
}
|
|
|
|
Emit8(byte);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-25 11:07:48 +00:00
|
|
|
void RegExpMacroAssemblerIrregexp::CheckNotBackReference(int start_reg,
|
2008-12-08 09:22:12 +00:00
|
|
|
Label* on_not_equal) {
|
2009-01-26 20:09:35 +00:00
|
|
|
ASSERT(start_reg >= 0);
|
|
|
|
ASSERT(start_reg <= kMaxRegister);
|
2009-01-20 18:50:01 +00:00
|
|
|
Emit(BC_CHECK_NOT_BACK_REF, start_reg);
|
2008-11-28 10:37:06 +00:00
|
|
|
EmitOrLink(on_not_equal);
|
2008-11-25 11:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-27 07:27:08 +00:00
|
|
|
void RegExpMacroAssemblerIrregexp::CheckNotBackReferenceIgnoreCase(
|
2008-11-25 11:39:20 +00:00
|
|
|
int start_reg,
|
|
|
|
Label* on_not_equal) {
|
2009-01-26 20:09:35 +00:00
|
|
|
ASSERT(start_reg >= 0);
|
|
|
|
ASSERT(start_reg <= kMaxRegister);
|
2009-01-20 18:50:01 +00:00
|
|
|
Emit(BC_CHECK_NOT_BACK_REF_NO_CASE, start_reg);
|
2008-11-28 10:37:06 +00:00
|
|
|
EmitOrLink(on_not_equal);
|
2008-11-25 11:39:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-25 11:07:48 +00:00
|
|
|
void RegExpMacroAssemblerIrregexp::IfRegisterLT(int register_index,
|
|
|
|
int comparand,
|
2008-11-28 10:37:06 +00:00
|
|
|
Label* on_less_than) {
|
2009-01-26 20:09:35 +00:00
|
|
|
ASSERT(register_index >= 0);
|
|
|
|
ASSERT(register_index <= kMaxRegister);
|
2009-01-20 18:50:01 +00:00
|
|
|
Emit(BC_CHECK_REGISTER_LT, register_index);
|
|
|
|
Emit32(comparand);
|
2008-11-28 10:37:06 +00:00
|
|
|
EmitOrLink(on_less_than);
|
2008-11-25 11:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RegExpMacroAssemblerIrregexp::IfRegisterGE(int register_index,
|
|
|
|
int comparand,
|
2008-11-28 10:37:06 +00:00
|
|
|
Label* on_greater_or_equal) {
|
2009-01-26 20:09:35 +00:00
|
|
|
ASSERT(register_index >= 0);
|
|
|
|
ASSERT(register_index <= kMaxRegister);
|
2009-01-20 18:50:01 +00:00
|
|
|
Emit(BC_CHECK_REGISTER_GE, register_index);
|
|
|
|
Emit32(comparand);
|
2008-11-28 10:37:06 +00:00
|
|
|
EmitOrLink(on_greater_or_equal);
|
2008-11-25 11:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 12:40:47 +00:00
|
|
|
void RegExpMacroAssemblerIrregexp::IfRegisterEqPos(int register_index,
|
|
|
|
Label* on_eq) {
|
2009-01-26 20:09:35 +00:00
|
|
|
ASSERT(register_index >= 0);
|
|
|
|
ASSERT(register_index <= kMaxRegister);
|
2009-01-20 18:50:01 +00:00
|
|
|
Emit(BC_CHECK_REGISTER_EQ_POS, register_index);
|
2009-01-08 12:40:47 +00:00
|
|
|
EmitOrLink(on_eq);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-11 06:39:27 +00:00
|
|
|
Handle<HeapObject> RegExpMacroAssemblerIrregexp::GetCode(
|
|
|
|
Handle<String> source) {
|
2008-12-08 09:22:12 +00:00
|
|
|
Bind(&backtrack_);
|
2009-01-20 18:50:01 +00:00
|
|
|
Emit(BC_POP_BT, 0);
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<ByteArray> array = FACTORY->NewByteArray(length());
|
2008-11-28 10:37:06 +00:00
|
|
|
Copy(array->GetDataStartAddress());
|
2008-11-25 11:07:48 +00:00
|
|
|
return array;
|
|
|
|
}
|
|
|
|
|
2008-11-28 10:37:06 +00:00
|
|
|
|
|
|
|
int RegExpMacroAssemblerIrregexp::length() {
|
|
|
|
return pc_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RegExpMacroAssemblerIrregexp::Copy(Address a) {
|
2013-04-16 12:30:51 +00:00
|
|
|
OS::MemCopy(a, buffer_.start(), length());
|
2008-11-28 10:37:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RegExpMacroAssemblerIrregexp::Expand() {
|
|
|
|
bool old_buffer_was_our_own = own_buffer_;
|
|
|
|
Vector<byte> old_buffer = buffer_;
|
|
|
|
buffer_ = Vector<byte>::New(old_buffer.length() * 2);
|
|
|
|
own_buffer_ = true;
|
2013-04-16 12:30:51 +00:00
|
|
|
OS::MemCopy(buffer_.start(), old_buffer.start(), old_buffer.length());
|
2008-11-28 10:37:06 +00:00
|
|
|
if (old_buffer_was_our_own) {
|
|
|
|
old_buffer.Dispose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-19 19:30:11 +00:00
|
|
|
#endif // V8_INTERPRETED_REGEXP
|
2008-11-28 10:37:06 +00:00
|
|
|
|
2008-11-25 11:07:48 +00:00
|
|
|
} } // namespace v8::internal
|