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