1 /* 2 * Copyright (c) 2023 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_TYPE_INFERENCE_GLOBAL_TYPE_INFER_H 17 #define ECMASCRIPT_COMPILER_TYPE_INFERENCE_GLOBAL_TYPE_INFER_H 18 19 #include "ecmascript/compiler/type_inference/method_type_infer.h" 20 21 namespace panda::ecmascript::kungfu { 22 class GlobalTypeInfer { 23 public: 24 GlobalTypeInfer(PassContext *ctx, const uint32_t methodOffset, const CString &recordName, 25 PGOProfilerDecoder *decoder, bool enableOptTrackField, bool enableLog); 26 ~GlobalTypeInfer(); 27 28 void ProcessTypeInference(BytecodeCircuitBuilder *builder, Circuit *circuit); 29 30 private: 31 static constexpr size_t MAX_GLOBAL_INFER_ALLOWED = 2; 32 GetTypeInfer(const uint32_t methodOffset)33 inline MethodTypeInfer *GetTypeInfer(const uint32_t methodOffset) const 34 { 35 auto it = typeInfers_.find(methodOffset); 36 if (it != typeInfers_.end()) { 37 return it->second; 38 } 39 return nullptr; 40 } 41 IsLegalMethod(const uint32_t methodOffset)42 inline bool IsLegalMethod(const uint32_t methodOffset) const 43 { 44 return (methodOffset != 0); 45 } 46 47 void NewTypeInfer(const uint32_t methodOffset); 48 void CollectNamespaceMethod(const uint32_t methodOffset); 49 void CollectNamespaceMethods(const uint32_t methodOffset); 50 void RunTypeCheck(); 51 52 PassContext *ctx_ {nullptr}; 53 const JSPandaFile *jsPandaFile_ {nullptr}; 54 BCInfo &bcInfo_; 55 uint32_t methodOffset_ {0}; 56 const CString &recordName_; 57 PGOProfilerDecoder *decoder_ {nullptr}; 58 bool enableOptTrackField_ {false}; 59 bool enableLog_ {false}; 60 bool enableGlobalTypeInfer_ {false}; 61 std::set<uint32_t> namespaceTypes_ {}; 62 std::vector<BytecodeCircuitBuilder *> builders_ {}; 63 std::vector<Circuit *> circuits_ {}; 64 std::map<uint32_t, MethodTypeInfer *> typeInfers_ {}; 65 }; 66 } // namespace panda::ecmascript::kungfu 67 #endif // ECMASCRIPT_COMPILER_TYPE_INFERENCE_GLOBAL_TYPE_INFER_H 68