diff --git a/ets2panda/compiler/core/codeGen.cpp b/ets2panda/compiler/core/codeGen.cpp index fd01a1c9f22233b98eef8ca278a813014eea0587..ae7026472b827935a2275f90914ace88ea91c1f5 100644 --- a/ets2panda/compiler/core/codeGen.cpp +++ b/ets2panda/compiler/core/codeGen.cpp @@ -52,12 +52,12 @@ const ir::AstNode *CodeGen::RootNode() const noexcept return rootNode_; } -ArenaVector &CodeGen::Insns() noexcept +ArenaList &CodeGen::Insns() noexcept { return insns_; } -const ArenaVector &CodeGen::Insns() const noexcept +const ArenaList &CodeGen::Insns() const noexcept { return insns_; } diff --git a/ets2panda/compiler/core/codeGen.h b/ets2panda/compiler/core/codeGen.h index 8fbeeb010606d820b488a2ddc2cbb144342c4f79..18ea3b653849dd458964267f5629de224f4fb522 100644 --- a/ets2panda/compiler/core/codeGen.h +++ b/ets2panda/compiler/core/codeGen.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 - 2024 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -101,8 +101,8 @@ public: [[nodiscard]] const varbinder::Scope *Scope() const noexcept; [[nodiscard]] const ir::AstNode *RootNode() const noexcept; - [[nodiscard]] ArenaVector &Insns() noexcept; - [[nodiscard]] const ArenaVector &Insns() const noexcept; + [[nodiscard]] ArenaList &Insns() noexcept; + [[nodiscard]] const ArenaList &Insns() const noexcept; [[nodiscard]] VReg AllocReg(); [[nodiscard]] VReg AllocRegWithType(const checker::Type *type); @@ -173,7 +173,7 @@ private: varbinder::FunctionScope *topScope_ {}; varbinder::Scope *scope_ {}; const ir::AstNode *rootNode_ {}; - ArenaVector insns_; + ArenaList insns_; ArenaVector catchList_; TypeMap typeMap_; ProgramElement *programElement_ {}; diff --git a/ets2panda/compiler/core/emitter.cpp b/ets2panda/compiler/core/emitter.cpp index f6027fc99ed63e7e3626e81912872d79f1a09e3d..f299614ef2a894d09723f60f1ffd28e214162b6b 100644 --- a/ets2panda/compiler/core/emitter.cpp +++ b/ets2panda/compiler/core/emitter.cpp @@ -225,13 +225,15 @@ void FunctionEmitter::GenInstructionDebugInfo(const IRNode *ins, pandasm::Ins *p void FunctionEmitter::GenFunctionInstructions(pandasm::Function *func) { - func->ins.reserve(cg_->Insns().size()); + const size_t insCount = cg_->Insns().size(); + + func->ins.resize(insCount); uint32_t totalRegs = cg_->TotalRegsNum(); + size_t index = 0; for (const auto *ins : cg_->Insns()) { - auto &pandaIns = func->ins.emplace_back(); - + auto &pandaIns = func->ins[index++]; ins->Transform(&pandaIns, programElement_, totalRegs); GenInstructionDebugInfo(ins, &pandaIns); } @@ -344,11 +346,20 @@ void FunctionEmitter::GenScopeVariableInfo(pandasm::Function *func, const varbin { const auto &instructions = cg_->Insns(); auto lastIter = instructions.end(); - auto iter = std::find(instructions.begin(), lastIter, scope->ScopeStart()); + + uint32_t count = 0; + auto iter = instructions.begin(); + + for (; iter != lastIter; ++iter, ++count) { + if (*iter == scope->ScopeStart()) { + break; + } + } + if (iter == lastIter || *iter == scope->ScopeEnd()) { return; } - uint32_t count = iter - instructions.begin(); + uint32_t start = count; auto checkNodeIsValid = [](const ir::AstNode *node) { return node != nullptr && node != FIRST_NODE_OF_FUNCTION; };