From 101614097f11cd69ee0138b272a925a555a3f075 Mon Sep 17 00:00:00 2001 From: hufeng Date: Fri, 18 Nov 2022 07:29:46 +0000 Subject: [PATCH] Set packageName to merge-abc Signed-off-by: hufeng Change-Id: Ia1ab47a417cc5c15fa79acb7ba8a586bf37f7de4 --- es2panda/aot/options.cpp | 6 +++++- es2panda/compiler/core/compilerContext.cpp | 4 ++-- es2panda/compiler/core/compilerContext.h | 9 ++++++++- es2panda/compiler/core/compilerImpl.cpp | 5 +++-- es2panda/compiler/core/compilerImpl.h | 2 +- es2panda/compiler/core/emitter/emitter.cpp | 11 +++++++++++ es2panda/compiler/core/emitter/emitter.h | 1 + es2panda/es2panda.cpp | 3 ++- es2panda/es2panda.h | 1 + 9 files changed, 34 insertions(+), 8 deletions(-) diff --git a/es2panda/aot/options.cpp b/es2panda/aot/options.cpp index 6b591b2694b..e8d2e3ead68 100644 --- a/es2panda/aot/options.cpp +++ b/es2panda/aot/options.cpp @@ -66,7 +66,7 @@ bool Options::CollectInputFilesFromFileList(const std::string &input) return false; } - constexpr size_t ITEM_COUNT_MERGE = 4; // item list: [filePath; recordName; moduleKind; sourceFile] + constexpr size_t ITEM_COUNT_MERGE = 5; // item list: [filePath; recordName; moduleKind; sourceFile, pkgName] constexpr size_t ITEM_COUNT_NOT_MERGE = 5; // item list: [filePath; recordName; moduleKind; sourceFile; outputfile] while (std::getline(ifs, line)) { const std::string seperator = ";"; @@ -90,6 +90,10 @@ bool Options::CollectInputFilesFromFileList(const std::string &input) es2panda::SourceFile src(fileName, recordName, scriptKind); src.sourcefile = itemList[3]; + if (compilerOptions_.mergeAbc) { + src.pkgName = itemList[4]; + } + sourceFiles_.push_back(src); if (!compilerOptions_.mergeAbc) { outputFiles_.insert({fileName, itemList[4]}); diff --git a/es2panda/compiler/core/compilerContext.cpp b/es2panda/compiler/core/compilerContext.cpp index 96ea7c675c2..5120ab97adb 100644 --- a/es2panda/compiler/core/compilerContext.cpp +++ b/es2panda/compiler/core/compilerContext.cpp @@ -22,10 +22,10 @@ namespace panda::es2panda::compiler { CompilerContext::CompilerContext(binder::Binder *binder, bool isDebug, bool isDebuggerEvaluateExpressionMode, bool isMergeAbc, bool isTypeExtractorEnabled, std::string sourceFile, - util::StringView recordName) + std::string pkgName, util::StringView recordName) : binder_(binder), isDebug_(isDebug), isDebuggerEvaluateExpressionMode_(isDebuggerEvaluateExpressionMode), isMergeAbc_(isMergeAbc), isTypeExtractorEnabled_(isTypeExtractorEnabled), sourceFile_(sourceFile), - emitter_(std::make_unique(this)), recordName_(recordName) + pkgName_(pkgName), emitter_(std::make_unique(this)), recordName_(recordName) { } diff --git a/es2panda/compiler/core/compilerContext.h b/es2panda/compiler/core/compilerContext.h index b43cbcadcde..4332c9a1b20 100644 --- a/es2panda/compiler/core/compilerContext.h +++ b/es2panda/compiler/core/compilerContext.h @@ -43,7 +43,8 @@ class Emitter; class CompilerContext { public: CompilerContext(binder::Binder *binder, bool isDebug, bool isDebuggerEvaluateExpressionMode, - bool isMergeAbc, bool isTypeExtractorEnabled, std::string sourceFile, util::StringView recordName); + bool isMergeAbc, bool isTypeExtractorEnabled, std::string sourceFile, + std::string pkgName, util::StringView recordName); NO_COPY_SEMANTIC(CompilerContext); NO_MOVE_SEMANTIC(CompilerContext); ~CompilerContext() = default; @@ -94,6 +95,11 @@ public: return sourceFile_; } + std::string PkgName() const + { + return pkgName_; + } + void AddHotfixHelper(util::Hotfix *hotfixHelper) { hotfixHelper_ = hotfixHelper; @@ -132,6 +138,7 @@ private: bool isTypeExtractorEnabled_; extractor::TypeRecorder *recorder_ {}; std::string sourceFile_; + std::string pkgName_; std::unique_ptr emitter_; util::Hotfix *hotfixHelper_ {nullptr}; util::StringView recordName_; diff --git a/es2panda/compiler/core/compilerImpl.cpp b/es2panda/compiler/core/compilerImpl.cpp index 3225df90d88..bd7ce35e970 100644 --- a/es2panda/compiler/core/compilerImpl.cpp +++ b/es2panda/compiler/core/compilerImpl.cpp @@ -37,10 +37,11 @@ CompilerImpl::~CompilerImpl() } panda::pandasm::Program *CompilerImpl::Compile(parser::Program *program, const es2panda::CompilerOptions &options, - const std::string &debugInfoSourceFile) + const std::string &debugInfoSourceFile, const std::string &pkgName) { CompilerContext context(program->Binder(), options.isDebug, options.isDebuggerEvaluateExpressionMode, - options.mergeAbc, options.typeExtractor, debugInfoSourceFile, program->RecordName()); + options.mergeAbc, options.typeExtractor, debugInfoSourceFile, pkgName, + program->RecordName()); if (hotfixHelper_ != nullptr) { context.AddHotfixHelper(hotfixHelper_); diff --git a/es2panda/compiler/core/compilerImpl.h b/es2panda/compiler/core/compilerImpl.h index fbf7e6253a4..595e9521cf0 100644 --- a/es2panda/compiler/core/compilerImpl.h +++ b/es2panda/compiler/core/compilerImpl.h @@ -44,7 +44,7 @@ public: NO_MOVE_SEMANTIC(CompilerImpl); panda::pandasm::Program *Compile(parser::Program *program, const es2panda::CompilerOptions &options, - const std::string &debugInfoSourceFile); + const std::string &debugInfoSourceFile, const std::string &pkgName); static void DumpAsm(const panda::pandasm::Program *prog); void AddHotfixHelper(util::Hotfix *hotfixHelper) diff --git a/es2panda/compiler/core/emitter/emitter.cpp b/es2panda/compiler/core/emitter/emitter.cpp index 114d43fdced..9a3dde65413 100644 --- a/es2panda/compiler/core/emitter/emitter.cpp +++ b/es2panda/compiler/core/emitter/emitter.cpp @@ -295,6 +295,7 @@ Emitter::Emitter(const CompilerContext *context) if (context->IsMergeAbc()) { auto recordName = context->Binder()->Program()->FormatedRecordName().Mutf8(); rec_ = new panda::pandasm::Record(recordName.substr(0, recordName.find_last_of('.')), LANG_EXT); + SetPkgNameField(context->PkgName()); SetCommonjsField(context->Binder()->Program()->Kind() == parser::ScriptKind::COMMONJS); } else { rec_ = nullptr; @@ -309,6 +310,16 @@ Emitter::~Emitter() delete prog_; } +void Emitter::SetPkgNameField(std::string pkgName) +{ + auto pkgNameField = panda::pandasm::Field(LANG_EXT); + pkgNameField.name = "pkgName@" + pkgName; + pkgNameField.type = panda::pandasm::Type("u8", 0); + pkgNameField.metadata->SetValue( + panda::pandasm::ScalarValue::Create(static_cast(0))); + rec_->field_list.emplace_back(std::move(pkgNameField)); +} + void Emitter::GenTypeInfoRecord() const { auto typeInfoRecord = panda::pandasm::Record(TypeExtractorEmitter::TYPE_INFO_RECORD, LANG_EXT); diff --git a/es2panda/compiler/core/emitter/emitter.h b/es2panda/compiler/core/emitter/emitter.h index d766694ff7b..3ef8387bbec 100644 --- a/es2panda/compiler/core/emitter/emitter.h +++ b/es2panda/compiler/core/emitter/emitter.h @@ -116,6 +116,7 @@ public: private: void SetCommonjsField(bool isCommonjs); + void SetPkgNameField(std::string pkgName); void GenCommonjsRecord() const; void GenTypeInfoRecord() const; void GenESTypeAnnotationRecord() const; diff --git a/es2panda/es2panda.cpp b/es2panda/es2panda.cpp index 5ab01d0d6bf..49d2bf80ff5 100644 --- a/es2panda/es2panda.cpp +++ b/es2panda/es2panda.cpp @@ -59,6 +59,7 @@ panda::pandasm::Program *Compiler::Compile(const SourceFile &input, const Compil std::string src(input.source); std::string rname(input.recordName); std::string sourcefile(input.sourcefile); + std::string pkgName(input.pkgName); parser::ScriptKind kind(input.scriptKind); bool needDumpSymbolFile = !options.hotfixOptions.dumpSymbolTable.empty(); @@ -95,7 +96,7 @@ panda::pandasm::Program *Compiler::Compile(const SourceFile &input, const Compil std::string debugInfoSourceFile = options.debugInfoSourceFile.empty() ? sourcefile : options.debugInfoSourceFile; - auto *prog = compiler_->Compile(&ast, options, debugInfoSourceFile); + auto *prog = compiler_->Compile(&ast, options, debugInfoSourceFile, pkgName); if (hotfixHelper) { delete hotfixHelper; diff --git a/es2panda/es2panda.h b/es2panda/es2panda.h index 766d15c0938..8ac8084008a 100644 --- a/es2panda/es2panda.h +++ b/es2panda/es2panda.h @@ -56,6 +56,7 @@ struct SourceFile { std::string_view source {}; parser::ScriptKind scriptKind {}; std::string sourcefile {}; + std::string pkgName {}; uint32_t hash {0}; }; -- Gitee