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 { ...@@ -147,14 +147,12 @@ class BacktrackStack {
DISALLOW_COPY_AND_ASSIGN(BacktrackStack); DISALLOW_COPY_AND_ASSIGN(BacktrackStack);
}; };
template <typename Char> template <typename Char>
static RegExpImpl::IrregexpResult RawMatch(Isolate* isolate, static IrregexpInterpreter::Result RawMatch(Isolate* isolate,
const byte* code_base, const byte* code_base,
Vector<const Char> subject, Vector<const Char> subject,
int* registers, int* registers, int current,
int current, uint32_t current_char) {
uint32_t current_char) {
const byte* pc = code_base; const byte* pc = code_base;
// BacktrackStack ensures that the memory allocated for the backtracking stack // 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 // 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, ...@@ -175,21 +173,21 @@ static RegExpImpl::IrregexpResult RawMatch(Isolate* isolate,
UNREACHABLE(); UNREACHABLE();
BYTECODE(PUSH_CP) BYTECODE(PUSH_CP)
if (--backtrack_stack_space < 0) { if (--backtrack_stack_space < 0) {
return RegExpImpl::RE_EXCEPTION; return IrregexpInterpreter::EXCEPTION;
} }
*backtrack_sp++ = current; *backtrack_sp++ = current;
pc += BC_PUSH_CP_LENGTH; pc += BC_PUSH_CP_LENGTH;
break; break;
BYTECODE(PUSH_BT) BYTECODE(PUSH_BT)
if (--backtrack_stack_space < 0) { if (--backtrack_stack_space < 0) {
return RegExpImpl::RE_EXCEPTION; return IrregexpInterpreter::EXCEPTION;
} }
*backtrack_sp++ = Load32Aligned(pc + 4); *backtrack_sp++ = Load32Aligned(pc + 4);
pc += BC_PUSH_BT_LENGTH; pc += BC_PUSH_BT_LENGTH;
break; break;
BYTECODE(PUSH_REGISTER) BYTECODE(PUSH_REGISTER)
if (--backtrack_stack_space < 0) { if (--backtrack_stack_space < 0) {
return RegExpImpl::RE_EXCEPTION; return IrregexpInterpreter::EXCEPTION;
} }
*backtrack_sp++ = registers[insn >> BYTECODE_SHIFT]; *backtrack_sp++ = registers[insn >> BYTECODE_SHIFT];
pc += BC_PUSH_REGISTER_LENGTH; pc += BC_PUSH_REGISTER_LENGTH;
...@@ -239,9 +237,9 @@ static RegExpImpl::IrregexpResult RawMatch(Isolate* isolate, ...@@ -239,9 +237,9 @@ static RegExpImpl::IrregexpResult RawMatch(Isolate* isolate,
pc += BC_POP_REGISTER_LENGTH; pc += BC_POP_REGISTER_LENGTH;
break; break;
BYTECODE(FAIL) BYTECODE(FAIL)
return RegExpImpl::RE_FAILURE; return IrregexpInterpreter::FAILURE;
BYTECODE(SUCCEED) BYTECODE(SUCCEED)
return RegExpImpl::RE_SUCCESS; return IrregexpInterpreter::SUCCESS;
BYTECODE(ADVANCE_CP) BYTECODE(ADVANCE_CP)
current += insn >> BYTECODE_SHIFT; current += insn >> BYTECODE_SHIFT;
pc += BC_ADVANCE_CP_LENGTH; pc += BC_ADVANCE_CP_LENGTH;
...@@ -584,13 +582,9 @@ static RegExpImpl::IrregexpResult RawMatch(Isolate* isolate, ...@@ -584,13 +582,9 @@ static RegExpImpl::IrregexpResult RawMatch(Isolate* isolate,
} }
} }
IrregexpInterpreter::Result IrregexpInterpreter::Match(
RegExpImpl::IrregexpResult IrregexpInterpreter::Match( Isolate* isolate, Handle<ByteArray> code_array, Handle<String> subject,
Isolate* isolate, int* registers, int start_position) {
Handle<ByteArray> code_array,
Handle<String> subject,
int* registers,
int start_position) {
DCHECK(subject->IsFlat()); DCHECK(subject->IsFlat());
DisallowHeapAllocation no_gc; DisallowHeapAllocation no_gc;
......
...@@ -14,11 +14,14 @@ namespace internal { ...@@ -14,11 +14,14 @@ namespace internal {
class IrregexpInterpreter { class IrregexpInterpreter {
public: public:
static RegExpImpl::IrregexpResult Match(Isolate* isolate, enum Result { RETRY = -2, EXCEPTION = -1, FAILURE = 0, SUCCESS = 1 };
Handle<ByteArray> code, STATIC_ASSERT(EXCEPTION == static_cast<int>(RegExpImpl::RE_EXCEPTION));
Handle<String> subject, STATIC_ASSERT(FAILURE == static_cast<int>(RegExpImpl::RE_FAILURE));
int* captures, STATIC_ASSERT(SUCCESS == static_cast<int>(RegExpImpl::RE_SUCCESS));
int start_position);
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, ...@@ -486,14 +486,14 @@ int RegExpImpl::IrregexpExecRaw(Isolate* isolate, Handle<JSRegExp> regexp,
Handle<ByteArray> byte_codes(IrregexpByteCode(*irregexp, is_one_byte), Handle<ByteArray> byte_codes(IrregexpByteCode(*irregexp, is_one_byte),
isolate); isolate);
IrregexpResult result = IrregexpInterpreter::Match( IrregexpInterpreter::Result result = IrregexpInterpreter::Match(
isolate, byte_codes, subject, raw_output, index); 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. // Copy capture results to the start of the registers array.
MemCopy(output, raw_output, MemCopy(output, raw_output,
number_of_capture_registers * sizeof(int32_t)); number_of_capture_registers * sizeof(int32_t));
} }
if (result == RE_EXCEPTION) { if (result == IrregexpInterpreter::EXCEPTION) {
DCHECK(!isolate->has_pending_exception()); DCHECK(!isolate->has_pending_exception());
isolate->StackOverflow(); 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