From 4df2f730c107625b17aeea04d1bb4ecc4fdce6d1 Mon Sep 17 00:00:00 2001 From: chenqy930 Date: Sat, 18 Feb 2023 17:59:47 +0800 Subject: [PATCH] fixed 1c0106b from https://gitee.com/chenqy930/arkcompiler_ets_frontend_hotfix_dev/pulls/870 Fix abc inconsistency while generating merged abc by es2abc Issue:I6GC4K Change-Id: Ib68f7f10cfdd22721f843ef074437bb69fdecb66 Signed-off-by: chenqy930 --- es2panda/aot/main.cpp | 60 +++++++++++++------------ merge_abc/protos/assemblyFunction.proto | 1 + merge_abc/src/assemblyFunctionProto.cpp | 2 + 3 files changed, 34 insertions(+), 29 deletions(-) diff --git a/es2panda/aot/main.cpp b/es2panda/aot/main.cpp index ce7cf8be19..1f1ae0f651 100644 --- a/es2panda/aot/main.cpp +++ b/es2panda/aot/main.cpp @@ -80,16 +80,16 @@ static void DumpPandaFileSizeStatistic(std::map &stat) std::cout << "total: " << totalSize << std::endl; } -static bool GenerateMultiProgram(const std::unordered_map &programs, +static bool GenerateMultiProgram(const std::map &programsInfo, const std::unique_ptr &options) { if (options->CompilerOptions().mergeAbc) { std::vector progs; - for (auto &prog: programs) { - progs.push_back(prog.first); + for (const auto &progInfo: programsInfo) { + progs.push_back(progInfo.second->program); } - auto output = programs.begin()->second; + const auto &output = options->CompilerOutput(); if (!panda::pandasm::AsmEmitter::EmitPrograms(panda::os::file::File::GetExtendedFilePath(output), progs, true)) { std::cerr << "Failed to emit merged program, error: " << @@ -97,9 +97,10 @@ static bool GenerateMultiProgram(const std::unordered_mapOutputFiles().at(progInfo.first); + if (!panda::pandasm::AsmEmitter::Emit(panda::os::file::File::GetExtendedFilePath(output), + *(progInfo.second->program), nullptr, nullptr, true)) { std::cout << "Failed to emit single program, error: " << panda::pandasm::AsmEmitter::GetLastError() << std::endl; return false; @@ -109,34 +110,41 @@ static bool GenerateMultiProgram(const std::unordered_map &programs, +static void DumpProgramInfos(const std::map &programsInfo, const std::unique_ptr &options) { - int optLevel = options->OptLevel(); - bool dumpSize = options->SizeStat(); - const es2panda::CompilerOptions compilerOptions = options->CompilerOptions(); + const es2panda::CompilerOptions &compilerOptions = options->CompilerOptions(); if (compilerOptions.dumpAsm || compilerOptions.dumpLiteralBuffer) { - for (auto &prog : programs) { + for (const auto &progInfo : programsInfo) { if (compilerOptions.dumpAsm) { - es2panda::Compiler::DumpAsm(prog.first); + es2panda::Compiler::DumpAsm(progInfo.second->program); } if (compilerOptions.dumpLiteralBuffer) { - panda::es2panda::util::Dumper::DumpLiterals(prog.first->literalarray_table); + panda::es2panda::util::Dumper::DumpLiterals(progInfo.second->program->literalarray_table); } } } +} - if (programs.size() > 1) { - return GenerateMultiProgram(programs, options); +static bool GenerateProgram(const std::map &programsInfo, + const std::unique_ptr &options) +{ + DumpProgramInfos(programsInfo, options); + if (programsInfo.size() > 1) { + return GenerateMultiProgram(programsInfo, options); } else { - auto *prog = programs.begin()->first; + auto *prog = programsInfo.begin()->second->program; + + int optLevel = options->OptLevel(); + bool dumpSize = options->SizeStat(); std::map stat; std::map *statp = optLevel != 0 ? &stat : nullptr; panda::pandasm::AsmEmitter::PandaFileToPandaAsmMaps maps {}; panda::pandasm::AsmEmitter::PandaFileToPandaAsmMaps *mapsp = optLevel != 0 ? &maps : nullptr; - auto output = programs.begin()->second; + const auto &output = options->OutputFiles().empty() ? options->CompilerOutput() : + options->OutputFiles().at(programsInfo.begin()->first); if (output.empty()) { GenerateBase64Output(prog, mapsp); return true; @@ -147,7 +155,8 @@ static bool GenerateProgram(const std::unordered_map &programsInfo, const std::unique_ptr &options, size_t expectedProgsCount) { - std::unordered_map programs; - for (auto &info : programsInfo) { - auto outputFileName = options->OutputFiles().empty() ? options->CompilerOutput() : - options->OutputFiles().at(info.first); - programs.insert({info.second->program, outputFileName}); - } - - if (programs.size() != expectedProgsCount) { + if (programsInfo.size() != expectedProgsCount) { std::cerr << "the size of programs is expected to be " << expectedProgsCount - << ", but is " << programs.size() << std::endl; + << ", but is " << programsInfo.size() << std::endl; return false; } - if (!GenerateProgram(programs, options)) { + if (!GenerateProgram(programsInfo, options)) { std::cerr << "GenerateProgram Failed!" << std::endl; return false; } diff --git a/merge_abc/protos/assemblyFunction.proto b/merge_abc/protos/assemblyFunction.proto index 731877424a..28fcff032e 100644 --- a/merge_abc/protos/assemblyFunction.proto +++ b/merge_abc/protos/assemblyFunction.proto @@ -75,5 +75,6 @@ message Function { SourceLocation bodyLocation = 15; optional FileLocation fileLocation = 16; uint32 function_kind = 17; + uint64 slotsNum = 18; } diff --git a/merge_abc/src/assemblyFunctionProto.cpp b/merge_abc/src/assemblyFunctionProto.cpp index f5f9972365..c0129bc255 100644 --- a/merge_abc/src/assemblyFunctionProto.cpp +++ b/merge_abc/src/assemblyFunctionProto.cpp @@ -106,6 +106,7 @@ void Function::Serialize(const panda::pandasm::Function &function, protoPanda::F FileLocation::Serialize(fileLocation.value(), *protoFileLocation); } protoFunction.set_function_kind(static_cast(function.function_kind)); + protoFunction.set_slotsnum(function.slots_num); } void Function::Deserialize(const protoPanda::Function &protoFunction, panda::pandasm::Function &function, @@ -164,5 +165,6 @@ void Function::Deserialize(const protoPanda::Function &protoFunction, panda::pan FileLocation::Deserialize(protoFunction.filelocation(), function.file_location); } function.SetFunctionKind(static_cast(protoFunction.function_kind())); + function.SetSlotsNum(protoFunction.slotsnum()); } } // panda::proto -- Gitee