diff --git a/es2panda/aot/options.cpp b/es2panda/aot/options.cpp index 7d56cfb73cda5854536aa510be4af5dee0ff57da..d3acf5dcf42c8eaec805d00f0564354e4b55e33e 100644 --- a/es2panda/aot/options.cpp +++ b/es2panda/aot/options.cpp @@ -71,7 +71,7 @@ bool Options::CollectInputFilesFromFileList(const std::string &input) return false; } - constexpr size_t ITEM_COUNT = 3; + constexpr size_t ITEM_COUNT = 4; while (std::getline(ifs, line)) { const std::string seperator = ";"; std::vector itemList = GetStringItems(line, seperator); @@ -79,6 +79,7 @@ bool Options::CollectInputFilesFromFileList(const std::string &input) std::cerr << "Failed to parse input file" << std::endl; return false; } + // itemList: [filePath, recordName, moduleKind, sourceFile] std::string fileName = itemList[0]; std::string recordName = FormatRecordName(itemList[1]); parser::ScriptKind scriptKind; @@ -91,6 +92,7 @@ bool Options::CollectInputFilesFromFileList(const std::string &input) } es2panda::SourceFile src(fileName, recordName, scriptKind); + src.sourcefile = itemList[3]; sourceFiles_.push_back(src); } return true; diff --git a/es2panda/compiler/core/emitter/emitter.cpp b/es2panda/compiler/core/emitter/emitter.cpp index 53064fdc1dea20e7c450060e75a09504cadcdc15..7006d4478e9696de8d804453c27c3562d75076dd 100644 --- a/es2panda/compiler/core/emitter/emitter.cpp +++ b/es2panda/compiler/core/emitter/emitter.cpp @@ -274,10 +274,10 @@ void FunctionEmitter::GenLiteralBuffers() void FunctionEmitter::GenSourceFileDebugInfo() { - if (pg_->SourceFile().size() > 0) { - func_->source_file = pg_->SourceFile(); - } else { + if (pg_->SourceFile().empty()) { func_->source_file = std::string {pg_->Binder()->Program()->SourceFile()}; + } else { + func_->source_file = pg_->SourceFile(); } if (!pg_->IsDebug()) { diff --git a/es2panda/es2panda.cpp b/es2panda/es2panda.cpp index fcb7f8208afd65955f971e5d9386169a6c5e952e..a87da3ed75aa318c14ff92be8abe01ea0aa1ab06 100644 --- a/es2panda/es2panda.cpp +++ b/es2panda/es2panda.cpp @@ -53,6 +53,7 @@ panda::pandasm::Program *Compiler::Compile(const SourceFile &input, const Compil std::string fname(input.fileName); std::string src(input.source); std::string rname(input.recordName); + std::string sourcefile(input.sourcefile); parser::ScriptKind kind(input.scriptKind); bool needDumpSymbolFile = !options.hotfixOptions.dumpSymbolTable.empty(); @@ -71,7 +72,8 @@ panda::pandasm::Program *Compiler::Compile(const SourceFile &input, const Compil std::cout << ast.Dump() << std::endl; } - std::string debugInfoSourceFile = options.debugInfoSourceFile.empty() ? fname : options.debugInfoSourceFile; + std::string debugInfoSourceFile = options.debugInfoSourceFile.empty() ? + sourcefile : options.debugInfoSourceFile; auto *prog = compiler_->Compile(&ast, options, debugInfoSourceFile); if (hotfixHelper) { diff --git a/es2panda/es2panda.h b/es2panda/es2panda.h index dc0e9480ee368666994e677414916114dc90fe07..72b7c4394ad1fe07bac09bcd9a648865cf0b79f3 100644 --- a/es2panda/es2panda.h +++ b/es2panda/es2panda.h @@ -54,6 +54,7 @@ struct SourceFile { std::string recordName {}; std::string_view source {}; parser::ScriptKind scriptKind {}; + std::string sourcefile {}; uint32_t hash {0}; };