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)26     explicit BuiltinLowering(Circuit *circuit): circuit_(circuit), builder_(circuit), acc_(circuit) {}
27     ~BuiltinLowering() = default;
28     void LowerTypedCallBuitin(GateRef gate);
29     GateRef LowerCallTargetCheck(Environment *env, GateRef gate);
30     GateRef CheckPara(GateRef gate, GateRef funcCheck);
31     void LowerTypedLocaleCompare(GateRef gate);
32     void LowerTypedArraySort(GateRef gate);
33 
34 private:
35     void LowerTypedFloor(GateRef gate);
36     GateRef TypedLocaleCompare(GateRef glue, GateRef gate, GateRef thisObj, GateRef thatObj);
37     GateRef TypedFloor(GateRef gate);
38     GateRef IntToTaggedIntPtr(GateRef x);
39     GateRef LowerCallRuntime(GateRef glue, GateRef gate, int index, const std::vector<GateRef> &args,
40                              bool useLabel = false);
41     void ReplaceHirWithValue(GateRef hirGate, GateRef value, bool noThrow = false);
42     GateRef LowerCallTargetCheckDefault(GateRef gate, BuiltinsStubCSigns::ID id);
43     GateRef LowerCallTargetCheckWithGlobalEnv(GateRef gate, BuiltinsStubCSigns::ID id);
44     GateRef LowerCallTargetCheckWithDetector(GateRef gate, BuiltinsStubCSigns::ID id);
45     GateRef LowerCallTargetCheckWithObjectType(GateRef gate, BuiltinsStubCSigns::ID id);
46     void LowerTypedStringify(GateRef gate);
47     void LowerBuiltinIterator(GateRef gate, BuiltinsStubCSigns::ID id);
48     void LowerIteratorNext(GateRef gate, BuiltinsStubCSigns::ID id);
49     void LowerIteratorReturn(GateRef gate, BuiltinsStubCSigns::ID id);
50     void LowerNumberConstructor(GateRef gate);
51     void LowerGlobalDecodeURIComponent(GateRef gate);
52 
53     Circuit *circuit_ {nullptr};
54     CircuitBuilder builder_;
55     GateAccessor acc_;
56 };
57 }  // panda::ecmascript::kungfu
58 #endif  // ECMASCRIPT_COMPILER_BUILTIN_LOWERING_H
59