• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2024 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_BUILTIN_LOWERING_H
17 #define ECMASCRIPT_COMPILER_BUILTIN_LOWERING_H
18 
19 #include <string>
20 #include "ecmascript/compiler/argument_accessor.h"
21 #include "ecmascript/compiler/circuit_builder-inl.h"
22 
23 namespace panda::ecmascript::kungfu {
24 class BuiltinLowering {
25 public:
BuiltinLowering(Circuit * circuit,CompilationConfig * cmpCfg,bool traceBuiltins)26     BuiltinLowering(Circuit *circuit, CompilationConfig *cmpCfg, bool traceBuiltins)
27         : circuit_(circuit), builder_(circuit, cmpCfg), acc_(circuit), traceBuiltins_(traceBuiltins)
28     {}
29     ~BuiltinLowering() = default;
30     void LowerTypedCallBuitin(GateRef gate);
31     GateRef LowerCallTargetCheck(Environment *env, GateRef gate);
32     GateRef CheckPara(GateRef gate, GateRef funcCheck);
33     void LowerTypedLocaleCompare(GateRef gate);
34     void LowerTypedArraySort(GateRef gate);
35 
36 private:
37     void LowerTypedFloor(GateRef gate);
38     GateRef TypedLocaleCompare(GateRef glue, GateRef gate, GateRef thisObj, GateRef thatObj);
39     GateRef TypedFloor(GateRef gate);
40     GateRef IntToTaggedIntPtr(GateRef x);
41     GateRef LowerCallRuntime(GateRef glue, GateRef gate, int index, const std::vector<GateRef> &args,
42                              bool useLabel = false);
43     void ReplaceHirWithValue(GateRef hirGate, GateRef value);
44     GateRef LowerCallTargetCheckDefault(GateRef gate, BuiltinsStubCSigns::ID id);
45     GateRef LowerCallTargetCheckWithGlobalEnv(GateRef gate, BuiltinsStubCSigns::ID id);
46     GateRef LowerCallTargetCheckWithDetector(GateRef gate, BuiltinsStubCSigns::ID id);
47     GateRef LowerCallTargetCheckWithObjectType(GateRef gate, BuiltinsStubCSigns::ID id);
48     void LowerTypedStringify(GateRef gate);
49     void LowerBuiltinIterator(GateRef gate, BuiltinsStubCSigns::ID id);
50     void LowerIteratorNext(GateRef gate, BuiltinsStubCSigns::ID id);
51     void LowerIteratorReturn(GateRef gate, BuiltinsStubCSigns::ID id);
52     void LowerNumberConstructor(GateRef gate);
53     void LowerGlobalDecodeURIComponent(GateRef gate);
54     void LowerCallBuiltinStub(GateRef gate, BuiltinsStubCSigns::ID id);
55     void AddTraceLogs(GateRef gate, BuiltinsStubCSigns::ID id);
56 
57     Circuit *circuit_ {nullptr};
58     CircuitBuilder builder_;
59     GateAccessor acc_;
60     bool traceBuiltins_ {false};
61 };
62 }  // panda::ecmascript::kungfu
63 #endif  // ECMASCRIPT_COMPILER_BUILTIN_LOWERING_H
64