From bfbfcee4cfe6cbd7553dfff245b384df31cd9c17 Mon Sep 17 00:00:00 2001 From: hewei Date: Sat, 30 Aug 2025 10:48:44 +0800 Subject: [PATCH] enhance aot code comment Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/ICVJFT Change-Id: I84fc5b90de281e8adb04ca73ba846cd1fa89af5a Signed-off-by: hewei --- ecmascript/compiler/file_generators.cpp | 1 + ecmascript/compiler/file_generators.h | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/ecmascript/compiler/file_generators.cpp b/ecmascript/compiler/file_generators.cpp index 601ec98f44..ba2cb0919d 100644 --- a/ecmascript/compiler/file_generators.cpp +++ b/ecmascript/compiler/file_generators.cpp @@ -666,6 +666,7 @@ bool AOTFileGenerator::SaveAOTFile(const std::string &filename, const std::strin return false; } PrintMergedCodeComment(); + CodeCommentToFile(); GenerateMergedStackmapSection(); aotInfo_.GenerateMethodToEntryIndexMap(); if (!aotInfo_.Save(filename, cfg_.GetTriple(), anFileMaxByteSize_, fileNameToChecksumMap)) { diff --git a/ecmascript/compiler/file_generators.h b/ecmascript/compiler/file_generators.h index 35b8ec5a2e..58cf0c8a24 100644 --- a/ecmascript/compiler/file_generators.h +++ b/ecmascript/compiler/file_generators.h @@ -235,6 +235,31 @@ public: std::string GenAotCodeCommentFileName(const std::string &filename); bool PUBLIC_API CreateAOTCodeCommentFile(const std::string &filename); + void CodeCommentToFile() + { + if (useLiteCG_ || codeStream_.str().empty()) { + return; + } + + if (aotCodeCommentFile_.empty()) { + return; + } + + std::ofstream file(aotCodeCommentFile_, std::ios::out | std::ios::app); + if (!file.is_open()) { + LOG_COMPILER(ERROR) << "Failed to open AOT code comment file: " << aotCodeCommentFile_; + return; + } + + file << codeStream_.str(); + file.flush(); + file.close(); + + if (file.fail()) { + LOG_COMPILER(ERROR) << "Failed to write to AOT code comment file: " << aotCodeCommentFile_; + } + } + const std::string &GetAotCodeCommentFile() const { return aotCodeCommentFile_; -- Gitee