diff --git a/ecmascript/compiler/file_generators.cpp b/ecmascript/compiler/file_generators.cpp index 601ec98f44a708790f0204bbed2724cfbf84c330..ba2cb0919d147841acecc2af52af074efac6a8b4 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 35b8ec5a2e607bce01a5394d1d44813a0bb00fd8..58cf0c8a2422eff8ddda62232236179d583a2a3c 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_;