• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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/builtins/builtins_call_signature.h"
22 #include "ecmascript/compiler/circuit_builder-inl.h"
23 
24 namespace panda::ecmascript::kungfu {
25 class BuiltinLowering {
26 public:
BuiltinLowering(Circuit * circuit)27     explicit BuiltinLowering(Circuit *circuit): circuit_(circuit), builder_(circuit), acc_(circuit) {}
28     ~BuiltinLowering() = default;
29     void LowerTypedCallBuitin(GateRef gate);
30     GateRef LowerCallTargetCheck(Environment *env, GateRef gate);
31     void LowerTypedSqrt(GateRef gate);
32     GateRef CheckPara(GateRef gate, GateRef funcCheck);
33     void LowerTypedLocaleCompare(GateRef gate);
34     void LowerTypedArraySort(GateRef gate);
35 
36 private:
37     void LowerTypedTrigonometric(GateRef gate, BuiltinsStubCSigns::ID id);
38     GateRef TypedTrigonometric(GateRef gate, BuiltinsStubCSigns::ID id);
39     GateRef IntToTaggedIntPtr(GateRef x);
40     void LowerTypedAbs(GateRef gate);
41     GateRef TypedAbs(GateRef gate);
42     GateRef LowerCallRuntime(GateRef glue, GateRef gate, int index, const std::vector<GateRef> &args,
43                              bool useLabel = false);
44     void ReplaceHirWithValue(GateRef hirGate, GateRef value, bool noThrow = false);
45     GateRef LowerCallTargetCheckDefault(GateRef gate, BuiltinsStubCSigns::ID id);
46     GateRef LowerCallTargetCheckWithGlobalEnv(GateRef gate, BuiltinsStubCSigns::ID id);
47     GateRef LowerCallTargetCheckWithDetector(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 LowerNumberConstructor(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