From 7caacfb4cbee88c88169a9f1c3e41ec556e813fd Mon Sep 17 00:00:00 2001 From: chenqy930 Date: Thu, 15 Sep 2022 16:34:40 +0800 Subject: [PATCH] Make func_main_0 external in patch mode Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/I5R1Y5 Signed-off-by: chenqy930 Change-Id: I49848e1c655afa034469704be06f62e41024adf0 --- es2panda/util/hotfix.cpp | 18 ++++++------------ es2panda/util/hotfix.h | 6 ++++++ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/es2panda/util/hotfix.cpp b/es2panda/util/hotfix.cpp index 1241548e80..1994170652 100644 --- a/es2panda/util/hotfix.cpp +++ b/es2panda/util/hotfix.cpp @@ -32,12 +32,6 @@ const std::string EXTERNAL_ATTRIBUTE = "external"; const uint32_t PATCH_ENV_VREG = 0; // reuse first param vreg const panda::panda_file::SourceLang SRC_LANG = panda::panda_file::SourceLang::ECMASCRIPT; -const std::string FUNC_MAIN = "func_main_0"; -// stores newly added function define ins, runtime will execute -const std::string PATCH_FUNC_MAIN_0 = "patch_main_0"; -// stores modified function and class define ins, runtime will scan but not execute -const std::string PATCH_FUNC_MAIN_1 = "patch_main_1"; - void Hotfix::ProcessFunction(const compiler::PandaGen *pg, panda::pandasm::Function *func, LiteralBuffers &literalBuffers) { @@ -219,7 +213,7 @@ bool Hotfix::IsScopeValidToPatchLexical(binder::VariableScope *scope) } auto funcName = scope->AsFunctionVariableScope()->InternalName(); - if (std::string(funcName) != (recordName_ + FUNC_MAIN)) { + if (std::string(funcName) != funcMain0_) { return false; } return true; @@ -234,7 +228,7 @@ void Hotfix::AllocSlotfromPatchEnv(const std::string &variableName) uint32_t Hotfix::GetSlotIdFromSymbolTable(const std::string &variableName) { - auto functionIter = originFunctionInfo_->find(recordName_ + FUNC_MAIN); + auto functionIter = originFunctionInfo_->find(funcMain0_); if (functionIter != originFunctionInfo_->end()) { auto lexenvIter = functionIter->second.lexenv.find(variableName); if (lexenvIter != functionIter->second.lexenv.end()) { @@ -374,8 +368,8 @@ void Hotfix::Finalize(panda::pandasm::Program **prog) return; } - panda::pandasm::Function patchFuncMain0(recordName_ + PATCH_FUNC_MAIN_0, SRC_LANG); - panda::pandasm::Function patchFuncMain1(recordName_ + PATCH_FUNC_MAIN_1, SRC_LANG); + panda::pandasm::Function patchFuncMain0(patchMain0_, SRC_LANG); + panda::pandasm::Function patchFuncMain1(patchMain1_, SRC_LANG); CreateFunctionPatchMain0AndMain1(patchFuncMain0, patchFuncMain1); (*prog)->function_table.emplace(patchFuncMain0.name, std::move(patchFuncMain0)); @@ -387,7 +381,7 @@ bool Hotfix::CompareLexenv(const std::string &funcName, const compiler::PandaGen { auto &lexicalVarNameAndTypes = pg->TopScope()->GetLexicalVarNameAndTypes(); auto &lexenv = bytecodeInfo.lexenv; - if (funcName != (recordName_ + FUNC_MAIN)) { + if (funcName != funcMain0_) { if (lexenv.size() != lexicalVarNameAndTypes.size()) { std::cerr << "Found lexenv size changed, not supported!" << std::endl; patchError_ = true; @@ -458,7 +452,7 @@ void Hotfix::HandleFunction(const compiler::PandaGen *pg, panda::pandasm::Functi } auto funcHash = std::to_string(hashList.back().second); - if (funcHash == bytecodeInfo.funcHash) { + if (funcHash == bytecodeInfo.funcHash || funcName == funcMain0_) { func->metadata->SetAttribute(EXTERNAL_ATTRIBUTE); } else { patchFuncNames_.insert(funcName); diff --git a/es2panda/util/hotfix.h b/es2panda/util/hotfix.h index 17b8d061a7..53bf7a043e 100644 --- a/es2panda/util/hotfix.h +++ b/es2panda/util/hotfix.h @@ -50,6 +50,9 @@ public: classMemberFunctions_(allocator_.Adapter()) { originFunctionInfo_ = symbolTable_->GetOriginFunctionInfo(); originModuleInfo_ = symbolTable_->GetOriginModuleInfo(); + patchMain0_ = recordName_ + "patch_main_0"; + patchMain1_ = recordName_ + "patch_main_1"; + funcMain0_ = recordName_ + "func_main_0"; } void Finalize(panda::pandasm::Program **prog); @@ -91,6 +94,9 @@ private: bool generateSymbolFile_ {false}; bool generatePatch_ {false}; std::string recordName_; + std::string funcMain0_; + std::string patchMain0_; // stores newly added function define ins, runtime will execute + std::string patchMain1_; // stores modified function and class define ins, runtime will scan but not execute util::SymbolTable* symbolTable_ {nullptr}; ArenaAllocator allocator_; -- Gitee