1/*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#ifndef ECMASCRIPT_COMPILER_STATE_SPLIT_LINEARIZER_H
17#define ECMASCRIPT_COMPILER_STATE_SPLIT_LINEARIZER_H
18
19#include <numeric>
20
21#include "ecmascript/compiler/circuit.h"
22#include "ecmascript/compiler/compilation_env.h"
23#include "ecmascript/compiler/gate_accessor.h"
24#include "ecmascript/compiler/mcr_lowering.h"
25#include "ecmascript/compiler/graph_linearizer.h"
26#include "ecmascript/mem/chunk_containers.h"
27namespace panda::ecmascript::kungfu {
28class StateSplitLinearizer {
29public:
30    StateSplitLinearizer(CompilationEnv* env, Circuit *circuit, RPOVisitor *visitor, CompilationConfig *cmpCfg,
31                         bool enableLog, const std::string& name, Chunk* chunk)
32        : enableLog_(enableLog), methodName_(name), circuit_(circuit),
33        graphLinearizer_(circuit, enableLog, name, chunk, false, true),
34        lcrLowering_(env, circuit, visitor, cmpCfg, chunk) {}
35
36    void Run();
37private:
38    bool IsLogEnabled() const
39    {
40        return enableLog_;
41    }
42
43    const std::string& GetMethodName() const
44    {
45        return methodName_;
46    }
47
48    void LinearizeStateSplit();
49
50    bool enableLog_ {false};
51    std::string methodName_;
52    Circuit* circuit_ {nullptr};
53    GraphLinearizer graphLinearizer_;
54    MCRLowering lcrLowering_;
55    friend class StateDependBuilder;
56};
57};  // namespace panda::ecmascript::kungfu
58
59#endif  // ECMASCRIPT_COMPILER_STATE_SPLIT_LINEARIZER_H
60