diff --git a/es2panda/aot/options.cpp b/es2panda/aot/options.cpp index 0f430e302e17d235869cd32f6938f44d4baa09b8..0988d69d6b8522531585882bb724df9c2f9818b5 100644 --- a/es2panda/aot/options.cpp +++ b/es2panda/aot/options.cpp @@ -69,6 +69,8 @@ bool Options::Parse(int argc, const char **argv) "evaluate expression in debugger mode"); panda::PandArg base64Input("base64Input", "", "base64 input of js content"); panda::PandArg base64Output("base64Output", false, "output panda file content as base64 to std out"); + panda::PandArg sourceFile("source-file", "", + "specify the file path info recorded in generated abc"); // tail arguments panda::PandArg inputFile("input", "", "input file"); @@ -92,6 +94,7 @@ bool Options::Parse(int argc, const char **argv) argparser_->Add(&inputExtension); argparser_->Add(&outputFile); + argparser_->Add(&sourceFile); argparser_->PushBackTail(&inputFile); argparser_->EnableTail(); @@ -206,6 +209,7 @@ bool Options::Parse(int argc, const char **argv) compilerOptions_.parseOnly = opParseOnly.GetValue(); compilerOptions_.dumpLiteralBuffer = opDumpLiteralBuffer.GetValue(); compilerOptions_.isDebuggerEvaluateExpressionMode = debuggerEvaluateExpression.GetValue(); + compilerOptions_.sourceFile = sourceFile.GetValue(); return true; } diff --git a/es2panda/compiler/core/compilerContext.cpp b/es2panda/compiler/core/compilerContext.cpp index d2542834109edad28c64491e009959d2f0a7bbda..bc82ddcba53576fbc8bfaf6c068f97f1e800ec98 100644 --- a/es2panda/compiler/core/compilerContext.cpp +++ b/es2panda/compiler/core/compilerContext.cpp @@ -19,9 +19,10 @@ namespace panda::es2panda::compiler { -CompilerContext::CompilerContext(binder::Binder *binder, bool isDebug, bool isDebuggerEvaluateExpressionMode) +CompilerContext::CompilerContext(binder::Binder *binder, bool isDebug, bool isDebuggerEvaluateExpressionMode, + std::string sourceFile) : binder_(binder), emitter_(std::make_unique(this)), isDebug_(isDebug), - isDebuggerEvaluateExpressionMode_(isDebuggerEvaluateExpressionMode) + isDebuggerEvaluateExpressionMode_(isDebuggerEvaluateExpressionMode), sourceFile_(sourceFile) { } diff --git a/es2panda/compiler/core/compilerContext.h b/es2panda/compiler/core/compilerContext.h index f05848f27a7b12cdb7fa9d4c5d0616154829cd43..4b94b607279093155951290456fbf1c3365c79f6 100644 --- a/es2panda/compiler/core/compilerContext.h +++ b/es2panda/compiler/core/compilerContext.h @@ -33,7 +33,8 @@ class Emitter; class CompilerContext { public: - CompilerContext(binder::Binder *binder, bool isDebug, bool isDebuggerEvaluateExpressionMode); + CompilerContext(binder::Binder *binder, bool isDebug, bool isDebuggerEvaluateExpressionMode, + std::string sourceFile); NO_COPY_SEMANTIC(CompilerContext); NO_MOVE_SEMANTIC(CompilerContext); ~CompilerContext() = default; @@ -74,6 +75,11 @@ public: return isDebuggerEvaluateExpressionMode_; } + std::string SourceFile() const + { + return sourceFile_; + } + private: binder::Binder *binder_; std::unique_ptr emitter_; @@ -81,6 +87,7 @@ private: std::mutex m_; bool isDebug_; bool isDebuggerEvaluateExpressionMode_; + std::string sourceFile_; }; } // namespace panda::es2panda::compiler diff --git a/es2panda/compiler/core/compilerImpl.cpp b/es2panda/compiler/core/compilerImpl.cpp index 4501d4005f4d9dc9842755042e9aa3bc6508b9b6..c367834290d74178481e28f3688b058be0325510 100644 --- a/es2panda/compiler/core/compilerImpl.cpp +++ b/es2panda/compiler/core/compilerImpl.cpp @@ -36,7 +36,8 @@ CompilerImpl::~CompilerImpl() panda::pandasm::Program *CompilerImpl::Compile(parser::Program *program, const es2panda::CompilerOptions &options) { - CompilerContext context(program->Binder(), options.isDebug, options.isDebuggerEvaluateExpressionMode); + CompilerContext context(program->Binder(), options.isDebug, options.isDebuggerEvaluateExpressionMode, + options.sourceFile); if (program->Extension() == ScriptExtension::TS) { ArenaAllocator localAllocator(SpaceType::SPACE_TYPE_COMPILER, nullptr, true); diff --git a/es2panda/compiler/core/emitter/emitter.cpp b/es2panda/compiler/core/emitter/emitter.cpp index 4852e6a3f146a41fa79d63bf1da8b0245e276679..166fe985de71a0170df9ad371b304128f4de2f7f 100644 --- a/es2panda/compiler/core/emitter/emitter.cpp +++ b/es2panda/compiler/core/emitter/emitter.cpp @@ -290,7 +290,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 78a49b5f538daf0fc19c29c52ec6fb9f850b12ba..d160975af573e79d0baf0a00f893f2b84650ede1 100644 --- a/es2panda/compiler/core/pandagen.cpp +++ b/es2panda/compiler/core/pandagen.cpp @@ -62,6 +62,11 @@ bool PandaGen::isDebuggerEvaluateExpressionMode() const return context_->isDebuggerEvaluateExpressionMode(); } +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 fc421d63f6f95d03f98957988ad3751030422533..35ed697fd52f272ab122cacf15819b55e2dbcb87 100644 --- a/es2panda/compiler/core/pandagen.h +++ b/es2panda/compiler/core/pandagen.h @@ -188,6 +188,7 @@ public: bool IsDebug() const; bool isDebuggerEvaluateExpressionMode() 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 602f77642cfd22ed9af92d51480c010896565365..c7b20297fa140224ab97b01d7baf4d7566e324bb 100644 --- a/es2panda/es2panda.h +++ b/es2panda/es2panda.h @@ -59,6 +59,7 @@ struct CompilerOptions { bool parseOnly {false}; bool dumpLiteralBuffer {false}; bool isDebuggerEvaluateExpressionMode {false}; + std::string sourceFile {}; }; enum class ErrorType { diff --git a/ts2panda/src/cmdOptions.ts b/ts2panda/src/cmdOptions.ts index cfe721a32cf5840b1b866acc8d19436a70de8586..87064a12c145fa7a26c3d635c5b3693d099cec1f 100644 --- a/ts2panda/src/cmdOptions.ts +++ b/ts2panda/src/cmdOptions.ts @@ -48,7 +48,8 @@ const ts2pandaOptions = [ { name: 'output-type', type: Boolean, defaultValue: false, description: "set output type."}, { name: 'display-typeinfo', type: Boolean, defaultValue: false, description: "Display typeinfo of pairs of instruction orders and types when enable-typeinfo is true" }, { name: 'function-sourcecode', type: Boolean, defaultValue: false, description: "Record functions' sourceCode to support the feature of [function].toString()" }, - { name: 'expression-watch-toolchain', type: String, defaultValue: "es2panda", description: "Specify the tool chain used to transform the expression" } + { name: 'expression-watch-toolchain', type: String, defaultValue: "es2panda", description: "Specify the tool chain used to transform the expression" }, + { name: 'source-file', type: String, defaultValue: "", description: "specify the file path info recorded in generated abc" }, ] @@ -302,6 +303,10 @@ export class CmdOptions { return this.options["function-sourcecode"]; } + 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 3df1f37ba5ef3b468467115e98b2db9a4d791126..c2eadc911047166c3ec1b5d3116c9b6aaf99e91e 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() && ts.isSourceFile(node)) { pandaGen.setSourceCode(node.text);