diff --git a/es2panda/aot/main.cpp b/es2panda/aot/main.cpp index aa3c20310770810705b2873412f687bd7f7e8e5d..2da57c1bb0edd3ccb5ad60058ec827725194fae1 100644 --- a/es2panda/aot/main.cpp +++ b/es2panda/aot/main.cpp @@ -151,10 +151,9 @@ int Run(int argc, const char **argv) options->CompilerOptions().isDebug, &allocator); } - Compiler::CompileFiles(options->CompilerOptions(), cachePrograms, programsInfo, &allocator); - + int ret = Compiler::CompileFiles(options->CompilerOptions(), cachePrograms, programsInfo, &allocator); if (options->ParseOnly()) { - return 0; + return ret; } if (!options->NpmModuleEntryList().empty()) { diff --git a/es2panda/es2panda.cpp b/es2panda/es2panda.cpp index fcb7f8208afd65955f971e5d9386169a6c5e952e..22e3d95387d5362fd660efaaee872f48e8904840 100644 --- a/es2panda/es2panda.cpp +++ b/es2panda/es2panda.cpp @@ -144,7 +144,7 @@ void Compiler::SelectCompileFile(CompilerOptions &options, options.sourceFiles = inputList; } -void Compiler::CompileFiles(CompilerOptions &options, +int Compiler::CompileFiles(CompilerOptions &options, std::map *cacheProgs, std::map &progsInfo, panda::ArenaAllocator *allocator) @@ -154,17 +154,22 @@ void Compiler::CompileFiles(CompilerOptions &options, symbolTable = new util::SymbolTable(options.hotfixOptions.symbolTable, options.hotfixOptions.dumpSymbolTable); if (!symbolTable->Initialize()) { std::cerr << "Exits due to hot fix initialize failed!" << std::endl; - return; + return 1; } } SelectCompileFile(options, cacheProgs, progsInfo, allocator); + bool failed = false; auto queue = new compiler::CompileFileQueue(options.fileThreadCount, &options, progsInfo, symbolTable, allocator); - queue->Schedule(); - queue->Consume(); - queue->Wait(); + try { + queue->Schedule(); + queue->Consume(); + queue->Wait(); + } catch (const class Error &e) { + failed = true; + } delete queue; queue = nullptr; @@ -173,6 +178,8 @@ void Compiler::CompileFiles(CompilerOptions &options, delete symbolTable; symbolTable = nullptr; } + + return failed ? 1 : 0; } panda::pandasm::Program *Compiler::CompileFile(CompilerOptions &options, SourceFile *src, @@ -203,7 +210,7 @@ panda::pandasm::Program *Compiler::CompileFile(CompilerOptions &options, SourceF std::cerr << err.TypeString() << ": " << err.Message(); std::cerr << " [" << src->fileName << ":" << err.Line() << ":" << err.Col() << "]" << std::endl; - return nullptr; + throw err; } return program; } diff --git a/es2panda/es2panda.h b/es2panda/es2panda.h index dc0e9480ee368666994e677414916114dc90fe07..c6144e2e6f206a8f12ef4ec9645837983010b2d5 100644 --- a/es2panda/es2panda.h +++ b/es2panda/es2panda.h @@ -165,7 +165,7 @@ public: util::SymbolTable *symbolTable = nullptr); panda::pandasm::Program *CompileFile(CompilerOptions &options, SourceFile *src, util::SymbolTable *symbolTable_); - static void CompileFiles(CompilerOptions &options, + static int CompileFiles(CompilerOptions &options, std::map *cacheProgs, std::map &progsInfo, panda::ArenaAllocator *allocator);