Commit 4a9b0a74 authored by Jakob Gruber's avatar Jakob Gruber Committed by Commit Bot

[regexp] Add IrregexpInterpreter::Result type

Similar to NativeRegExpMacroAssembler::Result, the regexp interpreter
will need a RETRY return code in case the subject string
representation changes during an interrupt. This CL adds a new
IrregexpInterpreter::Result type to decouple from RegExpImpl::Result.

Bug: v8:8724
Change-Id: I946fc0cbc4d7d8631312b72f13a45abeb9986905
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1511472Reviewed-by: 's avatarPeter Marshall <petermarshall@chromium.org>
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60154}
parent a49a279f
......@@ -147,14 +147,12 @@ class BacktrackStack {
DISALLOW_COPY_AND_ASSIGN(BacktrackStack);
};
template <typename Char>
static RegExpImpl::IrregexpResult RawMatch(Isolate* isolate,
const byte* code_base,
Vector<const Char> subject,
int* registers,
int current,
uint32_t current_char) {
static IrregexpInterpreter::Result RawMatch(Isolate* isolate,
const byte* code_base,
Vector<const Char> subject,
int* registers, int current,
uint32_t current_char) {
const byte* pc = code_base;
// BacktrackStack ensures that the memory allocated for the backtracking stack
// is returned to the system or cached if there is no stack being cached at
......@@ -175,21 +173,21 @@ static RegExpImpl::IrregexpResult RawMatch(Isolate* isolate,
UNREACHABLE();
BYTECODE(PUSH_CP)
if (--backtrack_stack_space < 0) {
return RegExpImpl::RE_EXCEPTION;
return IrregexpInterpreter::EXCEPTION;
}
*backtrack_sp++ = current;
pc += BC_PUSH_CP_LENGTH;
break;
BYTECODE(PUSH_BT)
if (--backtrack_stack_space < 0) {
return RegExpImpl::RE_EXCEPTION;
return IrregexpInterpreter::EXCEPTION;
}
*backtrack_sp++ = Load32Aligned(pc + 4);
pc += BC_PUSH_BT_LENGTH;
break;
BYTECODE(PUSH_REGISTER)
if (--backtrack_stack_space < 0) {
return RegExpImpl::RE_EXCEPTION;
return IrregexpInterpreter::EXCEPTION;
}
*backtrack_sp++ = registers[insn >> BYTECODE_SHIFT];
pc += BC_PUSH_REGISTER_LENGTH;
......@@ -239,9 +237,9 @@ static RegExpImpl::IrregexpResult RawMatch(Isolate* isolate,
pc += BC_POP_REGISTER_LENGTH;
break;
BYTECODE(FAIL)
return RegExpImpl::RE_FAILURE;
return IrregexpInterpreter::FAILURE;
BYTECODE(SUCCEED)
return RegExpImpl::RE_SUCCESS;
return IrregexpInterpreter::SUCCESS;
BYTECODE(ADVANCE_CP)
current += insn >> BYTECODE_SHIFT;
pc += BC_ADVANCE_CP_LENGTH;
......@@ -584,13 +582,9 @@ static RegExpImpl::IrregexpResult RawMatch(Isolate* isolate,
}
}
RegExpImpl::IrregexpResult IrregexpInterpreter::Match(
Isolate* isolate,
Handle<ByteArray> code_array,
Handle<String> subject,
int* registers,
int start_position) {
IrregexpInterpreter::Result IrregexpInterpreter::Match(
Isolate* isolate, Handle<ByteArray> code_array, Handle<String> subject,
int* registers, int start_position) {
DCHECK(subject->IsFlat());
DisallowHeapAllocation no_gc;
......
......@@ -14,11 +14,14 @@ namespace internal {
class IrregexpInterpreter {
public:
static RegExpImpl::IrregexpResult Match(Isolate* isolate,
Handle<ByteArray> code,
Handle<String> subject,
int* captures,
int start_position);
enum Result { RETRY = -2, EXCEPTION = -1, FAILURE = 0, SUCCESS = 1 };
STATIC_ASSERT(EXCEPTION == static_cast<int>(RegExpImpl::RE_EXCEPTION));
STATIC_ASSERT(FAILURE == static_cast<int>(RegExpImpl::RE_FAILURE));
STATIC_ASSERT(SUCCESS == static_cast<int>(RegExpImpl::RE_SUCCESS));
static Result Match(Isolate* isolate, Handle<ByteArray> code_array,
Handle<String> subject, int* registers,
int start_position);
};
......
......@@ -486,14 +486,14 @@ int RegExpImpl::IrregexpExecRaw(Isolate* isolate, Handle<JSRegExp> regexp,
Handle<ByteArray> byte_codes(IrregexpByteCode(*irregexp, is_one_byte),
isolate);
IrregexpResult result = IrregexpInterpreter::Match(
IrregexpInterpreter::Result result = IrregexpInterpreter::Match(
isolate, byte_codes, subject, raw_output, index);
if (result == RE_SUCCESS) {
if (result == IrregexpInterpreter::SUCCESS) {
// Copy capture results to the start of the registers array.
MemCopy(output, raw_output,
number_of_capture_registers * sizeof(int32_t));
}
if (result == RE_EXCEPTION) {
if (result == IrregexpInterpreter::EXCEPTION) {
DCHECK(!isolate->has_pending_exception());
isolate->StackOverflow();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment