1 /** 2 * Copyright (c) 2025 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 ASSEMBLER_EMIT_ITEM_H 17 #define ASSEMBLER_EMIT_ITEM_H 18 19 #include <mutex> 20 21 #include "assembly-emitter.h" 22 #include "libpandabase/utils/workerQueue.h" 23 24 namespace panda::pandasm { 25 class EmitFunctionsQueue : public panda::WorkerQueue { 26 public: EmitFunctionsQueue(size_t threadCount,panda_file::ItemContainer & items,const std::vector<Program * > & progs,AsmEmitter::AsmEntityCollections & entities,bool emit_debug_info)27 explicit EmitFunctionsQueue(size_t threadCount, panda_file::ItemContainer &items, 28 const std::vector<Program *> &progs, 29 AsmEmitter::AsmEntityCollections &entities, bool emit_debug_info) 30 : WorkerQueue(threadCount), 31 items_(items), 32 progs_(progs), 33 entities_(entities), 34 emit_debug_info_(emit_debug_info) {} 35 36 NO_COPY_SEMANTIC(EmitFunctionsQueue); 37 NO_MOVE_SEMANTIC(EmitFunctionsQueue); 38 ~EmitFunctionsQueue() override = default; 39 40 void Schedule() override; 41 private: 42 panda_file::ItemContainer &items_; 43 const std::vector<Program *> &progs_; 44 AsmEmitter::AsmEntityCollections &entities_; 45 bool emit_debug_info_; 46 }; 47 48 class EmitFunctionsJob : public panda::WorkerJob { 49 public: EmitFunctionsJob(panda_file::ItemContainer & items,const Program & program,bool emit_debug_info,AsmEmitter::AsmEntityCollections & entities)50 explicit EmitFunctionsJob(panda_file::ItemContainer &items, const Program &program, bool emit_debug_info, 51 AsmEmitter::AsmEntityCollections &entities) 52 : items_(items), 53 program_(program), 54 emit_debug_info_(emit_debug_info), 55 entities_(entities) {}; 56 NO_COPY_SEMANTIC(EmitFunctionsJob); 57 NO_MOVE_SEMANTIC(EmitFunctionsJob); 58 ~EmitFunctionsJob() override = default; 59 60 bool Run() override; 61 bool EmitFunctions(const AsmEmitter::AsmEntityCollections &entities, bool emit_debug_info); 62 void EmitDebugInfo(const std::vector<uint8_t> *bytes, const panda_file::MethodItem *method, 63 const Function &func, const std::string &name, bool emit_debug_info); 64 private: 65 static std::mutex mutex_; 66 panda_file::ItemContainer &items_; 67 const Program &program_; 68 bool emit_debug_info_; 69 AsmEmitter::AsmEntityCollections &entities_; 70 }; 71 } 72 #endif // ASSEMBLER_EMIT_ITEM_H