From cda39ccade3a8417735d9c0c83b880a2488afdfc Mon Sep 17 00:00:00 2001 From: zhangrengao Date: Fri, 19 Aug 2022 14:21:11 +0800 Subject: [PATCH] fixed 89500fb from https://gitee.com/zhangrengao1/ark_ts2abc/pulls/445 Add debug file path of es2abc&ts2abc Issue: I5N4FQ Signed-off-by: zhangrengao Change-Id: Ifcc4803a3ed6015f8df4addf01ffd9f18b4234cd --- es2panda/aot/options.cpp | 4 ++++ es2panda/compiler/core/compilerContext.cpp | 5 +++-- es2panda/compiler/core/compilerContext.h | 9 ++++++++- es2panda/compiler/core/compilerImpl.cpp | 3 ++- es2panda/compiler/core/emitter/emitter.cpp | 6 +++++- es2panda/compiler/core/pandagen.cpp | 5 +++++ es2panda/compiler/core/pandagen.h | 1 + es2panda/es2panda.h | 1 + ts2panda/src/cmdOptions.ts | 7 ++++++- ts2panda/src/debuginfo.ts | 6 +++++- 10 files changed, 40 insertions(+), 7 deletions(-) diff --git a/es2panda/aot/options.cpp b/es2panda/aot/options.cpp index 0f430e302e..0988d69d6b 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 d254283410..bc82ddcba5 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 f05848f27a..4b94b60727 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 4501d4005f..c367834290 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 4852e6a3f1..166fe985de 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 78a49b5f53..d160975af5 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 fc421d63f6..35ed697fd5 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 602f77642c..c7b20297fa 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 cfe721a32c..87064a12c1 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 3df1f37ba5..c2eadc9110 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); -- Gitee