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 ES2PANDA_COMPILER_CORE_EMITTER_TYPEEXTRACTOR_EMITTER_H 17 #define ES2PANDA_COMPILER_CORE_EMITTER_TYPEEXTRACTOR_EMITTER_H 18 19 #include <macros.h> 20 21 #include <assembly-function.h> 22 #include <assembly-program.h> 23 24 #include <compiler/core/pandagen.h> 25 #include <typescript/extractor/typeRecorder.h> 26 27 namespace panda::es2panda::compiler { 28 29 using AnnotationData = panda::pandasm::AnnotationData; 30 31 class TypeExtractorEmitter { 32 public: 33 explicit TypeExtractorEmitter(const PandaGen *pg, panda::pandasm::Function *func); 34 ~TypeExtractorEmitter() = default; 35 NO_COPY_SEMANTIC(TypeExtractorEmitter); 36 NO_MOVE_SEMANTIC(TypeExtractorEmitter); 37 38 static void GenTypeInfoRecord(panda::pandasm::Program *prog, bool typeFlag, int64_t typeSummaryIndex, 39 const std::string &recordName); 40 static void GenTypeInfoRecordForMergeABC(panda::pandasm::Program *prog, bool typeFlag, int64_t typeSummaryIndex, 41 const std::string &recordName); 42 static void GenTypeLiteralBuffers(panda::pandasm::Program *prog, const extractor::TypeRecorder *recorder); 43 44 static constexpr const char *TYPE_INFO_RECORD = "_ESTypeInfoRecord"; 45 static constexpr const char *TYPE_ANNOTATION = "_ESTypeAnnotation"; 46 static constexpr const char *TYPE_INSTRUCTION = "_TypeOfInstruction"; 47 48 static constexpr const char *TYPE_FLAG = "typeFlag"; 49 static constexpr const char *TYPE_SUMMARY = "typeSummaryOffset"; 50 static constexpr const char *EXPORTED_SYMBOL_TYPES = "exportedSymbolTypes"; 51 static constexpr const char *DECLARED_SYMBOL_TYPES = "declaredSymbolTypes"; 52 53 private: 54 int32_t literalId_ = -1; 55 const PandaGen *pg_; 56 panda::pandasm::Function *func_; 57 58 bool IsFuncMain0(const std::string &funcName, bool isMergeAbc) const; 59 void GenFunctionTypeInfo(panda::pandasm::Program *prog); 60 void GenExportTypeInfo(panda::pandasm::Program *prog); 61 void GenDeclareTypeInfo(panda::pandasm::Program *prog); 62 63 template <bool isExport, typename M> 64 void GenImportOrDeclareTypeInfo(panda::pandasm::Program *prog, const extractor::TypeRecorder *recorder, 65 const M &map, AnnotationData &funcTypeAnnotation); 66 }; 67 68 } // namespace panda::es2panda::compiler 69 70 #endif // ES2PANDA_COMPILER_CORE_EMITTER_TYPEEXTRACTOR_EMITTER_H 71