1 /* 2 * Copyright (c) 2021-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_IR_MODULERECORD_EMITTER_H 17 #define ES2PANDA_COMPILER_IR_MODULERECORD_EMITTER_H 18 19 #include <assembly-literals.h> 20 #include <parser/module/sourceTextModuleRecord.h> 21 22 #include <vector> 23 24 namespace panda::es2panda::compiler { 25 class ModuleRecordEmitter { 26 public: ModuleRecordEmitter(parser::SourceTextModuleRecord * moduleRecord,int32_t bufferIdx)27 explicit ModuleRecordEmitter(parser::SourceTextModuleRecord *moduleRecord, int32_t bufferIdx) 28 : moduleRecord_(moduleRecord), bufferIdx_(bufferIdx) {} 29 ~ModuleRecordEmitter() = default; 30 NO_COPY_SEMANTIC(ModuleRecordEmitter); 31 NO_MOVE_SEMANTIC(ModuleRecordEmitter); 32 Index()33 int32_t Index() const 34 { 35 return bufferIdx_; 36 } 37 Buffer()38 auto &Buffer() 39 { 40 return buffer_; 41 } 42 43 void Generate(); 44 45 private: 46 void GenModuleRequests(); 47 void GenRegularImportEntries(); 48 void GenNamespaceImportEntries(); 49 void GenLocalExportEntries(); 50 void GenIndirectExportEntries(); 51 void GenStarExportEntries(); 52 53 parser::SourceTextModuleRecord *moduleRecord_; 54 int32_t bufferIdx_ {}; 55 std::vector<panda::pandasm::LiteralArray::Literal> buffer_; 56 }; 57 } // namespace panda::es2panda::compiler 58 59 #endif 60