11cb0ef41Sopenharmony_ci// Copyright 2011 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci// A simple interpreter for the Irregexp byte code.
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ci#ifndef V8_REGEXP_REGEXP_INTERPRETER_H_
81cb0ef41Sopenharmony_ci#define V8_REGEXP_REGEXP_INTERPRETER_H_
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ci#include "src/regexp/regexp.h"
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_cinamespace v8 {
131cb0ef41Sopenharmony_cinamespace internal {
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ciclass ByteArray;
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ciclass V8_EXPORT_PRIVATE IrregexpInterpreter : public AllStatic {
181cb0ef41Sopenharmony_ci public:
191cb0ef41Sopenharmony_ci  enum Result {
201cb0ef41Sopenharmony_ci    FAILURE = RegExp::kInternalRegExpFailure,
211cb0ef41Sopenharmony_ci    SUCCESS = RegExp::kInternalRegExpSuccess,
221cb0ef41Sopenharmony_ci    EXCEPTION = RegExp::kInternalRegExpException,
231cb0ef41Sopenharmony_ci    RETRY = RegExp::kInternalRegExpRetry,
241cb0ef41Sopenharmony_ci    FALLBACK_TO_EXPERIMENTAL = RegExp::kInternalRegExpFallbackToExperimental,
251cb0ef41Sopenharmony_ci  };
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_ci  // In case a StackOverflow occurs, a StackOverflowException is created and
281cb0ef41Sopenharmony_ci  // EXCEPTION is returned.
291cb0ef41Sopenharmony_ci  static Result MatchForCallFromRuntime(
301cb0ef41Sopenharmony_ci      Isolate* isolate, Handle<JSRegExp> regexp, Handle<String> subject_string,
311cb0ef41Sopenharmony_ci      int* output_registers, int output_register_count, int start_position);
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ci  // In case a StackOverflow occurs, EXCEPTION is returned. The caller is
341cb0ef41Sopenharmony_ci  // responsible for creating the exception.
351cb0ef41Sopenharmony_ci  //
361cb0ef41Sopenharmony_ci  // RETRY is returned if a retry through the runtime is needed (e.g. when
371cb0ef41Sopenharmony_ci  // interrupts have been scheduled or the regexp is marked for tier-up).
381cb0ef41Sopenharmony_ci  //
391cb0ef41Sopenharmony_ci  // Arguments input_start and input_end are unused. They are only passed to
401cb0ef41Sopenharmony_ci  // match the signature of the native irregex code.
411cb0ef41Sopenharmony_ci  //
421cb0ef41Sopenharmony_ci  // Arguments output_registers and output_register_count describe the results
431cb0ef41Sopenharmony_ci  // array, which will contain register values of all captures if SUCCESS is
441cb0ef41Sopenharmony_ci  // returned. For all other return codes, the results array remains unmodified.
451cb0ef41Sopenharmony_ci  static Result MatchForCallFromJs(Address subject, int32_t start_position,
461cb0ef41Sopenharmony_ci                                   Address input_start, Address input_end,
471cb0ef41Sopenharmony_ci                                   int* output_registers,
481cb0ef41Sopenharmony_ci                                   int32_t output_register_count,
491cb0ef41Sopenharmony_ci                                   RegExp::CallOrigin call_origin,
501cb0ef41Sopenharmony_ci                                   Isolate* isolate, Address regexp);
511cb0ef41Sopenharmony_ci
521cb0ef41Sopenharmony_ci  static Result MatchInternal(Isolate* isolate, ByteArray code_array,
531cb0ef41Sopenharmony_ci                              String subject_string, int* output_registers,
541cb0ef41Sopenharmony_ci                              int output_register_count,
551cb0ef41Sopenharmony_ci                              int total_register_count, int start_position,
561cb0ef41Sopenharmony_ci                              RegExp::CallOrigin call_origin,
571cb0ef41Sopenharmony_ci                              uint32_t backtrack_limit);
581cb0ef41Sopenharmony_ci
591cb0ef41Sopenharmony_ci private:
601cb0ef41Sopenharmony_ci  static Result Match(Isolate* isolate, JSRegExp regexp, String subject_string,
611cb0ef41Sopenharmony_ci                      int* output_registers, int output_register_count,
621cb0ef41Sopenharmony_ci                      int start_position, RegExp::CallOrigin call_origin);
631cb0ef41Sopenharmony_ci};
641cb0ef41Sopenharmony_ci
651cb0ef41Sopenharmony_ci}  // namespace internal
661cb0ef41Sopenharmony_ci}  // namespace v8
671cb0ef41Sopenharmony_ci
681cb0ef41Sopenharmony_ci#endif  // V8_REGEXP_REGEXP_INTERPRETER_H_
69