diff --git a/es2panda/aot/options.cpp b/es2panda/aot/options.cpp index 9be3f001c5b1f2f8a6c5e7e5cd796649fe38f70d..fdcc6fae4a401cee70842ff89f948ad4840b6b67 100644 --- a/es2panda/aot/options.cpp +++ b/es2panda/aot/options.cpp @@ -62,6 +62,8 @@ bool Options::Parse(int argc, const char **argv) panda::PandArg opThreadCount("thread", 0, "Number of worker theads"); panda::PandArg opSizeStat("dump-size-stat", false, "Dump size statistics"); panda::PandArg outputFile("output", "", "Compiler binary output (.abc)"); + panda::PandArg sourceFile("source-file", "", + "specify the file path info recorded in generated abc"); // tail arguments panda::PandArg inputFile("input", "", "input file"); @@ -80,6 +82,7 @@ bool Options::Parse(int argc, const char **argv) argparser_->Add(&inputExtension); argparser_->Add(&outputFile); + argparser_->Add(&sourceFile); argparser_->PushBackTail(&inputFile); argparser_->EnableTail(); @@ -156,6 +159,7 @@ bool Options::Parse(int argc, const char **argv) compilerOptions_.dumpDebugInfo = opDumpDebugInfo.GetValue(); compilerOptions_.isDebug = opDebugInfo.GetValue(); compilerOptions_.parseOnly = opParseOnly.GetValue(); + compilerOptions_.sourceFile = sourceFile.GetValue(); return true; } diff --git a/es2panda/compiler/core/compilerContext.cpp b/es2panda/compiler/core/compilerContext.cpp index 6a97c410fdd32e9a6b48274c4700ec069553893c..1d95ed75d33f735fc3c21c15eca82b3cf13f53ac 100644 --- a/es2panda/compiler/core/compilerContext.cpp +++ b/es2panda/compiler/core/compilerContext.cpp @@ -19,8 +19,8 @@ namespace panda::es2panda::compiler { -CompilerContext::CompilerContext(binder::Binder *binder, bool isDebug) - : binder_(binder), emitter_(std::make_unique(this)), isDebug_(isDebug) +CompilerContext::CompilerContext(binder::Binder *binder, bool isDebug, std::string sourceFile) + : binder_(binder), emitter_(std::make_unique(this)), isDebug_(isDebug), sourceFile_(sourceFile) { } diff --git a/es2panda/compiler/core/compilerContext.h b/es2panda/compiler/core/compilerContext.h index 517163ae62d861c45600c38321c9780a62103e3a..cdc7cd5c51d4c4b29cf94c124b2cf7f978bec9e9 100644 --- a/es2panda/compiler/core/compilerContext.h +++ b/es2panda/compiler/core/compilerContext.h @@ -33,7 +33,7 @@ class Emitter; class CompilerContext { public: - CompilerContext(binder::Binder *binder, bool isDebug); + CompilerContext(binder::Binder *binder, bool isDebug, std::string sourceFile); NO_COPY_SEMANTIC(CompilerContext); NO_MOVE_SEMANTIC(CompilerContext); ~CompilerContext() = default; @@ -69,12 +69,18 @@ public: return isDebug_; } + std::string SourceFile() const + { + return sourceFile_; + } + private: binder::Binder *binder_; std::unique_ptr emitter_; int32_t literalBufferIdx_ {0}; std::mutex m_; bool isDebug_; + std::string sourceFile_; }; } // namespace panda::es2panda::compiler diff --git a/es2panda/compiler/core/compilerImpl.cpp b/es2panda/compiler/core/compilerImpl.cpp index c4ff569b2a7da04f7405cbb0f76ded8ea043606e..14459ec6915b7db148b1bbcf58c55d9166ea5bee 100644 --- a/es2panda/compiler/core/compilerImpl.cpp +++ b/es2panda/compiler/core/compilerImpl.cpp @@ -36,7 +36,7 @@ CompilerImpl::~CompilerImpl() panda::pandasm::Program *CompilerImpl::Compile(parser::Program *program, const es2panda::CompilerOptions &options) { - CompilerContext context(program->Binder(), options.isDebug); + CompilerContext context(program->Binder(), options.isDebug, options.sourceFile); if (program->Extension() == ScriptExtension::TS) { ArenaAllocator localAllocator(SpaceType::SPACE_TYPE_COMPILER, nullptr, true); diff --git a/es2panda/compiler/core/emitter.cpp b/es2panda/compiler/core/emitter.cpp index 6e617cb41f196d3b1ae3fdc361eed462f28af155..d6a121d7e9567d082f5bce8d1221ea3d817c1d59 100644 --- a/es2panda/compiler/core/emitter.cpp +++ b/es2panda/compiler/core/emitter.cpp @@ -281,7 +281,11 @@ void FunctionEmitter::GenLiteralBuffers() void FunctionEmitter::GenSourceFileDebugInfo() { - func_->source_file = std::string {pg_->Binder()->Program()->SourceFile()}; + if (pg_->SourceFile().size() > 0) { + func_->source_file = pg_->SourceFile(); + } else { + func_->source_file = std::string {pg_->Binder()->Program()->SourceFile()}; + } if (!pg_->IsDebug()) { return; diff --git a/es2panda/compiler/core/pandagen.cpp b/es2panda/compiler/core/pandagen.cpp index 7d58fa71c45b4622695a76884a4c7035854e2eac..c28425a72ba0755d1309e8cfba38b48fbd3c8514 100644 --- a/es2panda/compiler/core/pandagen.cpp +++ b/es2panda/compiler/core/pandagen.cpp @@ -53,6 +53,11 @@ bool PandaGen::IsDebug() const return context_->IsDebug(); } +std::string PandaGen::SourceFile() const +{ + return context_->SourceFile(); +} + uint32_t PandaGen::ParamCount() const { if (rootNode_->IsProgram()) { diff --git a/es2panda/compiler/core/pandagen.h b/es2panda/compiler/core/pandagen.h index eefd2e4b24180c09cf99b988a6a7f24cd2927186..74a2a6527cb58f45940ad23a00cc4ddcade01554 100644 --- a/es2panda/compiler/core/pandagen.h +++ b/es2panda/compiler/core/pandagen.h @@ -180,6 +180,7 @@ public: } bool IsDebug() const; + std::string SourceFile() const uint32_t ParamCount() const; uint32_t FormalParametersCount() const; uint32_t InternalParamCount() const; diff --git a/es2panda/es2panda.h b/es2panda/es2panda.h index f68866c0caa52f0ecbf0a60cb7d8b18f122ddb6b..7b8f01d53d1c93da4e377923fc16f7694254c8f7 100644 --- a/es2panda/es2panda.h +++ b/es2panda/es2panda.h @@ -54,6 +54,7 @@ struct CompilerOptions { bool dumpAsm {false}; bool dumpDebugInfo {false}; bool parseOnly {false}; + std::string sourceFile {}; }; enum class ErrorType { diff --git a/ts2panda/src/cmdOptions.ts b/ts2panda/src/cmdOptions.ts index 4e108670db4789dfb4ba0e5bde0af7bc345a089b..a5078a0ea3c6638c40dd8e6c4e3bc396ed94c927 100644 --- a/ts2panda/src/cmdOptions.ts +++ b/ts2panda/src/cmdOptions.ts @@ -46,7 +46,8 @@ const ts2pandaOptions = [ { name: 'debug-type', alias: 'g', type: Boolean, defaultValue: false, description: "Print type-related log. Default: false" }, { name: 'output-type', type: Boolean, defaultValue: false, description: "set output type."}, { name: 'enable-typeinfo', type: Boolean, defaultValue: false, description: "Enable typeinfo of pairs of instruction orders and types" }, - { name: 'display-typeinfo', type: Boolean, defaultValue: false, description: "Display typeinfo of pairs of instruction orders and types when enable-typeinfo is true" } + { name: 'display-typeinfo', type: Boolean, defaultValue: false, description: "Display typeinfo of pairs of instruction orders and types when enable-typeinfo is true" }, + { name: 'source-file', type: String, defaultValue: "", description: "specify the file path info recorded in generated abc" }, ] @@ -271,6 +272,10 @@ export class CmdOptions { return this.options["debug-type"]; } + static getSourceFile(): string { + return this.options["source-file"]; + } + // @ts-ignore static parseUserCmd(args: string[]): ts.ParsedCommandLine | undefined { this.options = commandLineArgs(ts2pandaOptions, { partial: true }); diff --git a/ts2panda/src/debuginfo.ts b/ts2panda/src/debuginfo.ts index 982b92334ac084034166091af7330d2fb5f7b812..29e0fbe4fb9aacacf6a2011d2e88b887899cb88a 100644 --- a/ts2panda/src/debuginfo.ts +++ b/ts2panda/src/debuginfo.ts @@ -352,7 +352,11 @@ export class DebugInfo { public static setSourceFileDebugInfo(pandaGen: PandaGen, node: ts.SourceFile | ts.FunctionLikeDeclaration) { let sourceFile = jshelpers.getSourceFileOfNode(node); - pandaGen.setSourceFileDebugInfo(sourceFile.fileName); + if (CmdOptions.getSourceFile().length > 0) { + pandaGen.setSourceFileDebugInfo(CmdOptions.getSourceFile()); + } else { + pandaGen.setSourceFileDebugInfo(sourceFile.fileName); + } if (CmdOptions.isDebugMode()) { if (ts.isSourceFile(node)) {