• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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_PASS_H
17 #define ECMASCRIPT_COMPILER_PASS_H
18 
19 #include "bytecode_circuit_builder.h"
20 #include "fast_stub.h"
21 #include "llvm_codegen.h"
22 #include "scheduler.h"
23 #include "slowpath_lowering.h"
24 #include "verifier.h"
25 
26 namespace panda::ecmascript::kungfu {
27 class PassData {
28 public:
PassData(Circuit * circuit)29     explicit PassData(Circuit* circuit) : circuit_(circuit) {}
30     ~PassData() = default;
GetScheduleResult()31     const ControlFlowGraph &GetScheduleResult() const
32     {
33         return cfg_;
34     }
35 
SetScheduleResult(const ControlFlowGraph & result)36     void SetScheduleResult(const ControlFlowGraph &result)
37     {
38         cfg_ = result;
39     }
40 
GetCircuit()41     virtual Circuit* GetCircuit() const
42     {
43         return circuit_;
44     }
45 
46 private:
47     Circuit* circuit_;
48     ControlFlowGraph cfg_;
49 };
50 
51 template<typename T1>
52 class PassRunner {
53 public:
PassRunner(T1 * data)54     explicit PassRunner(T1* data) : data_(data) {}
55     ~PassRunner() = default;
56     template<typename T2, typename... Args>
RunPass(Args...args)57     bool RunPass(Args... args)
58     {
59         T2 pass;
60         return pass.Run(data_, std::forward<Args>(args)...);
61     }
62 
63 private:
64     T1* data_;
65 };
66 
67 class SlowPathLoweringPass {
68 public:
Run(PassData * data,BytecodeCircuitBuilder * builder)69     bool Run(PassData* data, BytecodeCircuitBuilder *builder)
70     {
71         SlowPathLowering lowering(builder, data->GetCircuit());
72         lowering.CallRuntimeLowering();
73         return true;
74     }
75 };
76 
77 class VerifierPass {
78 public:
Run(PassData * data)79     bool Run(PassData* data)
80     {
81         Verifier::Run(data->GetCircuit());
82         return true;
83     }
84 };
85 
86 class SchedulingPass {
87 public:
Run(PassData * data)88     bool Run(PassData* data)
89     {
90         data->SetScheduleResult(Scheduler::Run(data->GetCircuit()));
91         return true;
92     }
93 };
94 
95 class LLVMIRGenPass {
96 public:
Run(PassData * data)97     bool Run(PassData* data)
98     {
99         return true;
100     }
101 
102 private:
103     std::unique_ptr<CodeGeneratorImpl> llvmImpl_ {nullptr};
104 };
105 }
106 #endif
107