From ae4f35049fc4a8ec016df418b27d4c17326bc388 Mon Sep 17 00:00:00 2001 From: qiuyu Date: Thu, 1 Sep 2022 14:41:28 +0800 Subject: [PATCH] Bugfix: return in advance when error or parse only Return in advance when error or parse only Issue: #I5P8ZM Signed-off-by: qiuyu Change-Id: Ia0294ba729a79d14210a5e561ca9cada4fe0ef09 --- es2panda/aot/main.cpp | 24 ++++++++++++++---------- es2panda/compiler/core/compileQueue.cpp | 4 ++++ es2panda/es2panda.cpp | 4 ++++ 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/es2panda/aot/main.cpp b/es2panda/aot/main.cpp index 641d85bf87..a6e82613d3 100644 --- a/es2panda/aot/main.cpp +++ b/es2panda/aot/main.cpp @@ -83,11 +83,6 @@ static void DumpPandaFileSizeStatistic(std::map &stat) static bool GenerateProgram(std::vector &progs, std::unique_ptr &options) { - if (progs.size() == 0) { - std::cerr << "Failed to generate program " << std::endl; - return false; - } - int optLevel = options->OptLevel(); bool dumpSize = options->SizeStat(); const std::string output = options->CompilerOutput(); @@ -148,8 +143,8 @@ int Run(int argc, const char **argv) std::vector programs; std::unordered_map programsInfo; + size_t expectedProgsCount = options->CompilerOptions().sourceFiles.size(); panda::ArenaAllocator allocator(panda::SpaceType::SPACE_TYPE_COMPILER, nullptr, true); - std::unordered_map *cachePrograms = nullptr; if (!options->CacheFile().empty()) { @@ -159,13 +154,14 @@ int Run(int argc, const char **argv) Compiler::CompileFiles(options->CompilerOptions(), cachePrograms, programs, programsInfo, &allocator); + if (options->ParseOnly()) { + return 0; + } + if (!options->NpmModuleEntryList().empty()) { es2panda::util::ModuleHelpers::CompileNpmModuleEntryList(options->NpmModuleEntryList(), cachePrograms, programs, programsInfo, &allocator); - } - - if (!GenerateProgram(programs, options)) { - return 1; + expectedProgsCount++; } if (!options->CacheFile().empty()) { @@ -173,6 +169,14 @@ int Run(int argc, const char **argv) options->CacheFile()); } + if (programs.size() != expectedProgsCount) { + return 1; + } + + if (!GenerateProgram(programs, options)) { + return 1; + } + return 0; } } // namespace panda::es2panda::aot diff --git a/es2panda/compiler/core/compileQueue.cpp b/es2panda/compiler/core/compileQueue.cpp index 2e2b5345ba..5e3e4b69b2 100644 --- a/es2panda/compiler/core/compileQueue.cpp +++ b/es2panda/compiler/core/compileQueue.cpp @@ -106,6 +106,10 @@ void CompileFileJob::Run() auto *prog = compiler.CompileFile(*options_, src_); + if (prog == nullptr) { + return; + } + if (options_->optLevel != 0) { util::Helpers::OptimizeProgram(prog, options_); } diff --git a/es2panda/es2panda.cpp b/es2panda/es2panda.cpp index 0dac82455a..0f2204eb13 100644 --- a/es2panda/es2panda.cpp +++ b/es2panda/es2panda.cpp @@ -59,6 +59,10 @@ panda::pandasm::Program *Compiler::Compile(const SourceFile &input, const Compil std::cout << ast.Dump() << std::endl; } + if (options.parseOnly) { + return nullptr; + } + std::string debugInfoSourceFile = options.debugInfoSourceFile.empty() ? fname : options.debugInfoSourceFile; auto *prog = compiler_->Compile(&ast, options, debugInfoSourceFile); -- Gitee