1// Copyright 2020 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_REGEXP_EXPERIMENTAL_EXPERIMENTAL_COMPILER_H_
6#define V8_REGEXP_EXPERIMENTAL_EXPERIMENTAL_COMPILER_H_
7
8#include "src/regexp/experimental/experimental-bytecode.h"
9#include "src/regexp/regexp-ast.h"
10#include "src/regexp/regexp-flags.h"
11#include "src/zone/zone-list.h"
12
13namespace v8 {
14namespace internal {
15
16class ExperimentalRegExpCompiler final : public AllStatic {
17 public:
18  // Checks whether a given RegExpTree can be compiled into an experimental
19  // bytecode program.  This mostly amounts to the absence of back references,
20  // but see the definition.
21  // TODO(mbid,v8:10765): Currently more things are not handled, e.g. some
22  // quantifiers and unicode.
23  static bool CanBeHandled(RegExpTree* tree, RegExpFlags flags,
24                           int capture_count);
25  // Compile regexp into a bytecode program.  The regexp must be handlable by
26  // the experimental engine; see`CanBeHandled`.  The program is returned as a
27  // ZoneList backed by the same Zone that is used in the RegExpTree argument.
28  static ZoneList<RegExpInstruction> Compile(RegExpTree* tree,
29                                             RegExpFlags flags, Zone* zone);
30};
31
32}  // namespace internal
33}  // namespace v8
34
35#endif  // V8_REGEXP_EXPERIMENTAL_EXPERIMENTAL_COMPILER_H_
36