From 6325d693e5869ee2d854fb0c164848accabe970f Mon Sep 17 00:00:00 2001 From: zhangrengao Date: Sun, 21 Aug 2022 12:27:59 +0800 Subject: [PATCH] Add debug file path of es2abc&ts2abc Issue: I5N4FQ Signed-off-by: zhangrengao Change-Id: Iaf8d5e7f9e8181e876f73b427e36e41f2547acde --- es2panda/aot/options.cpp | 4 ++++ es2panda/compiler/core/compilerContext.cpp | 4 ++-- es2panda/compiler/core/compilerContext.h | 8 +++++++- es2panda/compiler/core/compilerImpl.cpp | 2 +- es2panda/compiler/core/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, 37 insertions(+), 7 deletions(-) diff --git a/es2panda/aot/options.cpp b/es2panda/aot/options.cpp index 9be3f001c5..fdcc6fae4a 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 6a97c410fd..1d95ed75d3 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 517163ae62..cdc7cd5c51 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 c4ff569b2a..14459ec691 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 6e617cb41f..d6a121d7e9 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 7d58fa71c4..c28425a72b 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 eefd2e4b24..74a2a6527c 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 f68866c0ca..7b8f01d53d 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 4e108670db..a5078a0ea3 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 982b92334a..29e0fbe4fb 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)) { -- Gitee