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_TS_HCLASS_GENERATOR_H 17 #define ECMASCRIPT_COMPILER_TS_HCLASS_GENERATOR_H 18 19 #include "ecmascript/pgo_profiler/pgo_profiler_layout.h" 20 #include "ecmascript/ts_types/ts_manager.h" 21 22 namespace panda::ecmascript::kungfu { 23 class TSHClassGenerator { 24 public: TSHClassGenerator(TSManager * tsManager)25 explicit TSHClassGenerator(TSManager *tsManager): tsManager_(tsManager) {}; 26 ~TSHClassGenerator() = default; 27 28 void GenerateTSHClasses() const; 29 void UpdateTSHClassFromPGO(const kungfu::GateType &type, const PGOHClassLayoutDesc &desc, 30 bool enableOptTrackField) const; 31 32 private: 33 void RecursiveGenerate(const JSHandle<TSClassType> &classType) const; 34 35 JSHandle<JSHClass> Generate(const JSHandle<TSClassType> &classType) const; 36 37 enum class Kind : uint8_t { 38 INSTANCE = 0, 39 PROTOTYPE, 40 CONSTRUCTOR, 41 }; 42 43 JSHandle<JSHClass> CreateHClass(const JSThread *thread, const JSHandle<TSClassType> &classType, Kind kind) const; 44 45 JSHandle<JSHClass> CreateIHClass(const JSThread *thread, const JSHandle<TSClassType> &classType) const; 46 47 JSHandle<JSHClass> CreatePHClass(const JSThread *thread, const JSHandle<TSClassType> &classType) const; 48 49 JSHandle<JSHClass> CreateCHClass(const JSThread *thread, const JSHandle<TSClassType> &classType) const; 50 GetCollectedGT()51 inline const std::set<GlobalTSTypeRef>& GetCollectedGT() const 52 { 53 return tsManager_->GetCollectedGT(); 54 } 55 56 TSManager *tsManager_ {nullptr}; 57 }; 58 } // namespace panda::ecmascript::kungfu 59 #endif // ECMASCRIPT_COMPILER_TS_HCLASS_GENERATOR_H 60