From f1ac2298c874b5253ec2ef7061b01f3aac733c38 Mon Sep 17 00:00:00 2001 From: gavin1012_hw Date: Sat, 25 May 2024 17:09:30 +0800 Subject: [PATCH] Remove redundant data in program Issue: I9IEAK Signed-off-by: gavin1012_hw Change-Id: I88374f37085e0e3a32c67827e7819f9a6cdd82cf --- es2panda/aot/emitFiles.cpp | 4 +- es2panda/aot/main.cpp | 33 +- es2panda/aot/options.cpp | 20 +- es2panda/aot/options.h | 1 + es2panda/compiler/core/compileQueue.cpp | 3 +- es2panda/es2panda.h | 8 +- .../hap-file-exec-expected.pa.txt | 995 ++++++++++++++++++ .../hap-file-exec-expected.pa.txt | 416 +++++++- .../hap-file-exec-expected.pa.txt | 324 +++++- .../hap-file-exec-expected.pa.txt | 725 ++++++++++++- es2panda/test/runner.py | 11 +- es2panda/util/dumper.cpp | 18 +- es2panda/util/dumper.h | 4 +- es2panda/util/helpers.cpp | 88 ++ es2panda/util/helpers.h | 25 +- es2panda/util/programCache.h | 3 +- 16 files changed, 2617 insertions(+), 61 deletions(-) mode change 100755 => 100644 es2panda/test/compiler/bytecodehar/js/projects/bytecodehar-dependency-resolve/hap-file-exec-expected.pa.txt mode change 100755 => 100644 es2panda/test/compiler/bytecodehar/projects/bytecodehar-dependency-resolve/hap-file-exec-expected.pa.txt mode change 100755 => 100644 es2panda/test/compiler/bytecodehar/projects/bytecodehar-test-project/hap-file-exec-expected.pa.txt diff --git a/es2panda/aot/emitFiles.cpp b/es2panda/aot/emitFiles.cpp index 2ecd5bac81..f1f5a35979 100644 --- a/es2panda/aot/emitFiles.cpp +++ b/es2panda/aot/emitFiles.cpp @@ -16,9 +16,11 @@ #include "emitFiles.h" #include -#include #include + +#include #include +#include namespace panda::es2panda::aot { void EmitFileQueue::ScheduleEmitCacheJobs(EmitMergedAbcJob *emitMergedAbcJob) diff --git a/es2panda/aot/main.cpp b/es2panda/aot/main.cpp index 7b35a4b826..a0308d0c99 100644 --- a/es2panda/aot/main.cpp +++ b/es2panda/aot/main.cpp @@ -150,14 +150,20 @@ static void DumpProgramInfos(const std::mapprogram.literalarray_table); + panda::es2panda::util::Dumper::DumpLiterals(progInfo.second->program.literalarray_table, + compilerOptions.enableAbcInput); + } + + if (compilerOptions.dumpString) { + panda::es2panda::util::Dumper::DumpStrings(progInfo.second->program.strings); } } } } -static bool GenerateProgram(const std::map &programsInfo, - const std::unique_ptr &options) +static bool GenerateProgram(std::map &programsInfo, + const std::unique_ptr &options, + util::DepsRelationInfo *depsRelationInfo) { DumpProgramInfos(programsInfo, options); @@ -176,6 +182,12 @@ static bool GenerateProgram(const std::mapNeedRemoveRedundantRecord()) { + util::Helpers::RemoveProgramsRedundantData(programsInfo, depsRelationInfo->resolvedDepsRelation, + depsRelationInfo->generatedRecords); + DumpProgramInfos(programsInfo, options); + } + bool dumpSize = options->SizeStat(); bool dumpSizePct = options->SizePctStat(); std::map stat; @@ -196,8 +208,9 @@ static bool GenerateProgram(const std::map &programsInfo, - const std::unique_ptr &options, size_t expectedProgsCount) +static bool GenerateAbcFiles(std::map &programsInfo, + const std::unique_ptr &options, size_t expectedProgsCount, + util::DepsRelationInfo *depsRelationInfo) { if (programsInfo.size() != expectedProgsCount) { std::cerr << "The size of programs is expected to be " << expectedProgsCount @@ -205,7 +218,7 @@ static bool GenerateAbcFiles(const std::map> resolvedDepsRelation {}; std::unordered_set generatedRecords {}; - if (options->NeedRemoveRedundantRecord() && + if (options->NeedCollectDepsRelation() && !ResolveDepsRelations(programsInfo, options, resolvedDepsRelation, generatedRecords)) { return 1; } - if (!GenerateAbcFiles(programsInfo, options, expectedProgsCount)) { + auto *depsRelationInfo = allocator.New(resolvedDepsRelation, generatedRecords); + + if (!GenerateAbcFiles(programsInfo, options, expectedProgsCount, depsRelationInfo)) { return 1; } diff --git a/es2panda/aot/options.cpp b/es2panda/aot/options.cpp index 675bed0796..7c3b5bda44 100644 --- a/es2panda/aot/options.cpp +++ b/es2panda/aot/options.cpp @@ -270,12 +270,18 @@ void Options::ParseCompileContextInfo(const std::string compileContextInfoPath) compilerOptions_.compileContextInfo.pkgContextInfo = pkgContextMap; } -// Collect dependencies based on the compile entries and remove redundant content from the abc file as input. -bool Options::NeedRemoveRedundantRecord() +// Collect dependencies based on the compile entries. +bool Options::NeedCollectDepsRelation() { return compilerOptions_.enableAbcInput && !compilerOptions_.compileContextInfo.compileEntries.empty(); } +// Remove redundant content from the abc file and remove programs generated from redundant source files. +bool Options::NeedRemoveRedundantRecord() +{ + return compilerOptions_.removeRedundantFile && NeedCollectDepsRelation(); +} + Options::Options() : argparser_(new panda::PandArgParser()) {} Options::~Options() @@ -360,6 +366,10 @@ bool Options::Parse(int argc, const char **argv) "info file"); panda::PandArg opDumpDepsInfo("dump-deps-info", false, "Dump all dependency files and records "\ "including source files and bytecode files"); + panda::PandArg opRemoveRedundantFile("remove-redundant-file", false, "Remove redundant info"\ + " from abc file and remove redundant source file, which is effective when the compile-context-info switch"\ + " is turned on and there is abc input"); + panda::PandArg opDumpString("dump-string", false, "Dump program strings"); // aop transform panda::PandArg transformLib("transform-lib", "", "aop transform lib file path"); @@ -418,6 +428,8 @@ bool Options::Parse(int argc, const char **argv) argparser_->Add(&compileContextInfoPath); argparser_->Add(&opDumpDepsInfo); + argparser_->Add(&opRemoveRedundantFile); + argparser_->Add(&opDumpString); argparser_->Add(&transformLib); @@ -604,6 +616,10 @@ bool Options::Parse(int argc, const char **argv) ParseCompileContextInfo(compileContextInfoPath.GetValue()); } compilerOptions_.dumpDepsInfo = opDumpDepsInfo.GetValue(); + compilerOptions_.updatePkgVersionForAbcInput = compilerOptions_.enableAbcInput + && !compilerOptions_.compileContextInfo.pkgContextInfo.empty(); + compilerOptions_.removeRedundantFile = opRemoveRedundantFile.GetValue(); + compilerOptions_.dumpString = opDumpString.GetValue(); compilerOptions_.patchFixOptions.dumpSymbolTable = opDumpSymbolTable.GetValue(); compilerOptions_.patchFixOptions.symbolTable = opInputSymbolTable.GetValue(); diff --git a/es2panda/aot/options.h b/es2panda/aot/options.h index 26e9166182..c23dbcc882 100644 --- a/es2panda/aot/options.h +++ b/es2panda/aot/options.h @@ -137,6 +137,7 @@ public: bool CollectInputFilesFromFileDirectory(const std::string &input, const std::string &extension); void ParseCacheFileOption(const std::string &cacheInput); void ParseCompileContextInfo(const std::string compileContextInfoPath); + bool NeedCollectDepsRelation(); bool NeedRemoveRedundantRecord(); private: diff --git a/es2panda/compiler/core/compileQueue.cpp b/es2panda/compiler/core/compileQueue.cpp index bffcde89f1..9d5e4c9ffd 100644 --- a/es2panda/compiler/core/compileQueue.cpp +++ b/es2panda/compiler/core/compileQueue.cpp @@ -117,7 +117,7 @@ void CompileFileJob::Run() } // Update version for abc input when needed - if (!src_->isSourceMode && options_->NeedUpdatePkgVersionForAbcInput()) { + if (!src_->isSourceMode && options_->updatePkgVersionForAbcInput) { compiler.UpdatePackageVersion(prog, *options_); } @@ -136,6 +136,7 @@ void CompileFileJob::Run() { std::unique_lock lock(global_m_); auto *cache = allocator_->New(src_->hash, std::move(*prog), src_->isSourceMode); + cache->generatedFromAbc = !src_->isSourceMode; progsInfo_.insert({src_->fileName, cache}); if (requireOptimizationAfterAnalysis) { optimizationPendingProgs_.insert(src_->fileName); diff --git a/es2panda/es2panda.h b/es2panda/es2panda.h index f395944077..47d67fe603 100644 --- a/es2panda/es2panda.h +++ b/es2panda/es2panda.h @@ -114,11 +114,9 @@ struct CompilerOptions { std::string compileContextInfoPath {}; CompileContextInfo compileContextInfo {}; bool dumpDepsInfo {false}; - - bool NeedUpdatePkgVersionForAbcInput() const - { - return enableAbcInput && !compileContextInfo.pkgContextInfo.empty(); - } + bool updatePkgVersionForAbcInput {false}; + bool removeRedundantFile {false}; + bool dumpString {false}; }; enum class ErrorType { diff --git a/es2panda/test/compiler/bytecodehar/js/projects/bytecodehar-dependency-resolve/hap-file-exec-expected.pa.txt b/es2panda/test/compiler/bytecodehar/js/projects/bytecodehar-dependency-resolve/hap-file-exec-expected.pa.txt old mode 100755 new mode 100644 index 2a83d1d081..c0a007597c --- a/es2panda/test/compiler/bytecodehar/js/projects/bytecodehar-dependency-resolve/hap-file-exec-expected.pa.txt +++ b/es2panda/test/compiler/bytecodehar/js/projects/bytecodehar-dependency-resolve/hap-file-exec-expected.pa.txt @@ -57,6 +57,131 @@ record_name: &myapp/test-require& } +======> literal array buffer <====== +------------------------------------ +{ + index: 0 + tag: 2 + val: 1 +}, +{ + index: 1 + tag: 5 + val: @normalized:N&&&@ohos/bytecodehar2/bytecodehar2-file1&2.0.0 +}, +{ + index: 2 + tag: 2 + val: 1 +}, +{ + index: 3 + tag: 5 + val: test1 +}, +{ + index: 4 + tag: 5 + val: test +}, +{ + index: 5 + tag: 9 + val: 0 +}, +{ + index: 6 + tag: 2 + val: 0 +}, +{ + index: 7 + tag: 2 + val: 1 +}, +{ + index: 8 + tag: 5 + val: test +}, +{ + index: 9 + tag: 5 + val: test +}, +{ + index: 10 + tag: 2 + val: 0 +}, +{ + index: 11 + tag: 2 + val: 0 +}, +------------------------------------ +{ + index: 0 + tag: 2 + val: 1 +}, +{ + index: 1 + tag: 5 + val: @normalized:N&&&@ohos/bytecodehar2/bytecodehar2-file2&2.0.0 +}, +{ + index: 2 + tag: 2 + val: 1 +}, +{ + index: 3 + tag: 5 + val: test1 +}, +{ + index: 4 + tag: 5 + val: test +}, +{ + index: 5 + tag: 9 + val: 0 +}, +{ + index: 6 + tag: 2 + val: 0 +}, +{ + index: 7 + tag: 2 + val: 1 +}, +{ + index: 8 + tag: 5 + val: test +}, +{ + index: 9 + tag: 5 + val: test +}, +{ + index: 10 + tag: 2 + val: 0 +}, +{ + index: 11 + tag: 2 + val: 0 +}, +======> strings <====== +"&bytecodehar1/bytecodehar1-file1&2.0.0.#*#test"; "&bytecodehar1/bytecodehar1-file2&2.0.0.#*#test"; "@normalized:N&&&sourcehar/sourcehar-file1&2.0.0"; "@normalized:N&&&sourcehar/sourcehar-file2&2.0.0"; "bytecodehar1.file1.test"; "bytecodehar1.file2.test"; "print"; .language ECMAScript .function any &@ohos/bytecodehar2/bytecodehar2-file1&2.0.0.#*#test(any a0, any a1, any a2) { @@ -96,6 +221,91 @@ record_name: &myapp/test-require& } +======> literal array buffer <====== +------------------------------------ +{ + index: 0 + tag: 2 + val: 0 +}, +{ + index: 1 + tag: 2 + val: 0 +}, +{ + index: 2 + tag: 2 + val: 0 +}, +{ + index: 3 + tag: 2 + val: 1 +}, +{ + index: 4 + tag: 5 + val: test +}, +{ + index: 5 + tag: 5 + val: test +}, +{ + index: 6 + tag: 2 + val: 0 +}, +{ + index: 7 + tag: 2 + val: 0 +}, +------------------------------------ +{ + index: 0 + tag: 2 + val: 0 +}, +{ + index: 1 + tag: 2 + val: 0 +}, +{ + index: 2 + tag: 2 + val: 0 +}, +{ + index: 3 + tag: 2 + val: 1 +}, +{ + index: 4 + tag: 5 + val: test +}, +{ + index: 5 + tag: 5 + val: test +}, +{ + index: 6 + tag: 2 + val: 0 +}, +{ + index: 7 + tag: 2 + val: 0 +}, +======> strings <====== +"&@ohos/bytecodehar2/bytecodehar2-file1&2.0.0.#*#test"; "&@ohos/bytecodehar2/bytecodehar2-file2&2.0.0.#*#test"; "bytecodehar2.file1.test"; "bytecodehar2.file2.test"; "print"; .language ECMAScript .function any commonjs-say.#*#(any a0, any a1, any a2, any a3, any a4, any a5, any a6, any a7) { @@ -150,6 +360,10 @@ label_2: } +======> literal array buffer <====== +------------------------------------ +======> strings <====== +"Reflect"; "apply"; "commonjs-say.#*#"; "commonjs-say.#**#hi"; "exports"; "hello require"; "hi"; .language ECMAScript .function any &myapp/hap-file-exec&.#*#main(any a0, any a1, any a2) { @@ -180,6 +394,81 @@ label_2: } +======> literal array buffer <====== +------------------------------------ +------------------------------------ +{ + index: 0 + tag: 2 + val: 2 +}, +{ + index: 1 + tag: 5 + val: @normalized:N&&&bytecodehar1/bytecodehar1-file1&2.0.0 +}, +{ + index: 2 + tag: 5 + val: @normalized:N&&&myapp/test-require& +}, +{ + index: 3 + tag: 2 + val: 2 +}, +{ + index: 4 + tag: 5 + val: test +}, +{ + index: 5 + tag: 5 + val: test +}, +{ + index: 6 + tag: 9 + val: 0 +}, +{ + index: 7 + tag: 5 + val: testRequire +}, +{ + index: 8 + tag: 5 + val: testRequire +}, +{ + index: 9 + tag: 9 + val: 1 +}, +{ + index: 10 + tag: 2 + val: 0 +}, +{ + index: 11 + tag: 2 + val: 0 +}, +{ + index: 12 + tag: 2 + val: 0 +}, +{ + index: 13 + tag: 2 + val: 0 +}, +======> strings <====== +"&myapp/hap-file-exec&.#*#main"; "test"; "testRequire"; .language ECMAScript .function any &sourcehar/sourcehar-file1&2.0.0.#*#test(any a0, any a1, any a2) { @@ -207,6 +496,71 @@ label_2: } +======> literal array buffer <====== +------------------------------------ +------------------------------------ +{ + index: 0 + tag: 2 + val: 1 +}, +{ + index: 1 + tag: 5 + val: @normalized:N&&&sourcehar/sourcehar-file2&2.0.0 +}, +{ + index: 2 + tag: 2 + val: 1 +}, +{ + index: 3 + tag: 5 + val: test1 +}, +{ + index: 4 + tag: 5 + val: test +}, +{ + index: 5 + tag: 9 + val: 0 +}, +{ + index: 6 + tag: 2 + val: 0 +}, +{ + index: 7 + tag: 2 + val: 1 +}, +{ + index: 8 + tag: 5 + val: test +}, +{ + index: 9 + tag: 5 + val: test +}, +{ + index: 10 + tag: 2 + val: 0 +}, +{ + index: 11 + tag: 2 + val: 0 +}, +======> strings <====== +"&sourcehar/sourcehar-file1&2.0.0.#*#test"; "print"; "sourcehar.file1.test"; .language ECMAScript .function any &sourcehar/sourcehar-file2&2.0.0.#*#test(any a0, any a1, any a2) { @@ -234,6 +588,51 @@ label_2: } +======> literal array buffer <====== +------------------------------------ +------------------------------------ +{ + index: 0 + tag: 2 + val: 0 +}, +{ + index: 1 + tag: 2 + val: 0 +}, +{ + index: 2 + tag: 2 + val: 0 +}, +{ + index: 3 + tag: 2 + val: 1 +}, +{ + index: 4 + tag: 5 + val: test +}, +{ + index: 5 + tag: 5 + val: test +}, +{ + index: 6 + tag: 2 + val: 0 +}, +{ + index: 7 + tag: 2 + val: 0 +}, +======> strings <====== +"&sourcehar/sourcehar-file2&2.0.0.#*#test"; "print"; "sourcehar.file2.test"; .language ECMAScript .function any &myapp/test-require&.#*#testRequire(any a0, any a1, any a2) { @@ -281,3 +680,599 @@ label_2: } +======> literal array buffer <====== +------------------------------------ +------------------------------------ +{ + index: 0 + tag: 2 + val: 0 +}, +{ + index: 1 + tag: 2 + val: 0 +}, +{ + index: 2 + tag: 2 + val: 0 +}, +{ + index: 3 + tag: 2 + val: 0 +}, +{ + index: 4 + tag: 2 + val: 0 +}, +{ + index: 5 + tag: 2 + val: 0 +}, +======> strings <====== +"&myapp/test-require&.#*#testRequire"; "./commonjs-say"; "console"; "exports"; "hi"; "log"; "module"; "require"; "testRequire"; +.language ECMAScript + +.function any &bytecodehar1/bytecodehar1-file1&2.0.0.#*#test(any a0, any a1, any a2) { + tryldglobalbyname 0x0, print + sta v0 + lda.str bytecodehar1.file1.test + sta v1 + lda v0 + callarg1 0x1, v1 + lda.str @normalized:N&&&sourcehar/sourcehar-file1&2.0.0 + dynamicimport + ldundefined + returnundefined +} + +.function any &bytecodehar1/bytecodehar1-file1&2.0.0.func_main_0(any a0, any a1, any a2) { + definefunc 0x0, &bytecodehar1/bytecodehar1-file1&2.0.0.#*#test, 0x0 + stmodulevar 0x0 + ldundefined + returnundefined +} + + +======> literal array buffer <====== +------------------------------------ +{ + index: 0 + tag: 2 + val: 1 +}, +{ + index: 1 + tag: 5 + val: @normalized:N&&&@ohos/bytecodehar2/bytecodehar2-file1&2.0.0 +}, +{ + index: 2 + tag: 2 + val: 1 +}, +{ + index: 3 + tag: 5 + val: test1 +}, +{ + index: 4 + tag: 5 + val: test +}, +{ + index: 5 + tag: 9 + val: 0 +}, +{ + index: 6 + tag: 2 + val: 0 +}, +{ + index: 7 + tag: 2 + val: 1 +}, +{ + index: 8 + tag: 5 + val: test +}, +{ + index: 9 + tag: 5 + val: test +}, +{ + index: 10 + tag: 2 + val: 0 +}, +{ + index: 11 + tag: 2 + val: 0 +}, +======> strings <====== +"&bytecodehar1/bytecodehar1-file1&2.0.0.#*#test"; "@normalized:N&&&sourcehar/sourcehar-file1&2.0.0"; "bytecodehar1.file1.test"; "print"; +.language ECMAScript + +.function any &@ohos/bytecodehar2/bytecodehar2-file1&2.0.0.#*#test(any a0, any a1, any a2) { + tryldglobalbyname 0x0, print + sta v0 + lda.str bytecodehar2.file1.test + sta v1 + lda v0 + callarg1 0x1, v1 + ldundefined + returnundefined +} + +.function any &@ohos/bytecodehar2/bytecodehar2-file1&2.0.0.func_main_0(any a0, any a1, any a2) { + definefunc 0x0, &@ohos/bytecodehar2/bytecodehar2-file1&2.0.0.#*#test, 0x0 + stmodulevar 0x0 + ldundefined + returnundefined +} + + +======> literal array buffer <====== +------------------------------------ +{ + index: 0 + tag: 2 + val: 0 +}, +{ + index: 1 + tag: 2 + val: 0 +}, +{ + index: 2 + tag: 2 + val: 0 +}, +{ + index: 3 + tag: 2 + val: 1 +}, +{ + index: 4 + tag: 5 + val: test +}, +{ + index: 5 + tag: 5 + val: test +}, +{ + index: 6 + tag: 2 + val: 0 +}, +{ + index: 7 + tag: 2 + val: 0 +}, +======> strings <====== +"&@ohos/bytecodehar2/bytecodehar2-file1&2.0.0.#*#test"; "bytecodehar2.file1.test"; "print"; +.language ECMAScript + +.function any commonjs-say.#*#(any a0, any a1, any a2, any a3, any a4, any a5, any a6, any a7) { +label_1: +label_0: + definefunc 0x0, commonjs-say.#**#hi, 0x0 + sta v0 + lda a5 + ldobjbyname 0x1, exports + sta v1 + lda v0 + stobjbyname 0x3, hi, v1 + ldundefined + returnundefined +label_2: +} + +.function any commonjs-say.#**#hi(any a0, any a1, any a2) { +label_1: +label_0: + lda.str hello require + return +label_2: +} + +.function any commonjs-say.func_main_0(any a0, any a1, any a2, any a3, any a4, any a5, any a6, any a7) { +label_1: +label_0: + tryldglobalbyname 0x0, Reflect + sta v0 + ldobjbyname 0x1, apply + sta v1 + definefunc 0x3, commonjs-say.#*#, 0x5 + sta v2 + createemptyarray 0x4 + sta v3 + lda a3 + stownbyindex 0x5, v3, 0x0 + lda a4 + stownbyindex 0x7, v3, 0x1 + lda a5 + stownbyindex 0x9, v3, 0x2 + lda a6 + stownbyindex 0xb, v3, 0x3 + lda a7 + stownbyindex 0xd, v3, 0x4 + lda v1 + callthis3 0xf, v0, v2, a3, v3 + ldundefined + returnundefined +label_2: +} + + +======> literal array buffer <====== +------------------------------------ +======> strings <====== +"Reflect"; "apply"; "commonjs-say.#*#"; "commonjs-say.#**#hi"; "exports"; "hello require"; "hi"; +.language ECMAScript + +.function any &myapp/hap-file-exec&.#*#main(any a0, any a1, any a2) { +label_1: +label_0: + ldexternalmodulevar 0x0 + sta v0 + throw.undefinedifholewithname test + lda v0 + callarg0 0x0 + ldexternalmodulevar 0x1 + sta v0 + throw.undefinedifholewithname testRequire + lda v0 + callarg0 0x2 + ldundefined + returnundefined +label_2: +} + +.function any &myapp/hap-file-exec&.func_main_0(any a0, any a1, any a2) { +label_1: +label_0: + definefunc 0x0, &myapp/hap-file-exec&.#*#main, 0x0 + ldundefined + returnundefined +label_2: +} + + +======> literal array buffer <====== +------------------------------------ +------------------------------------ +{ + index: 0 + tag: 2 + val: 2 +}, +{ + index: 1 + tag: 5 + val: @normalized:N&&&bytecodehar1/bytecodehar1-file1&2.0.0 +}, +{ + index: 2 + tag: 5 + val: @normalized:N&&&myapp/test-require& +}, +{ + index: 3 + tag: 2 + val: 2 +}, +{ + index: 4 + tag: 5 + val: test +}, +{ + index: 5 + tag: 5 + val: test +}, +{ + index: 6 + tag: 9 + val: 0 +}, +{ + index: 7 + tag: 5 + val: testRequire +}, +{ + index: 8 + tag: 5 + val: testRequire +}, +{ + index: 9 + tag: 9 + val: 1 +}, +{ + index: 10 + tag: 2 + val: 0 +}, +{ + index: 11 + tag: 2 + val: 0 +}, +{ + index: 12 + tag: 2 + val: 0 +}, +{ + index: 13 + tag: 2 + val: 0 +}, +======> strings <====== +"&myapp/hap-file-exec&.#*#main"; "test"; "testRequire"; +.language ECMAScript + +.function any &sourcehar/sourcehar-file1&2.0.0.#*#test(any a0, any a1, any a2) { +label_1: +label_0: + tryldglobalbyname 0x0, print + sta v0 + lda.str sourcehar.file1.test + sta v1 + lda v0 + callarg1 0x1, v1 + ldundefined + returnundefined +label_2: +} + +.function any &sourcehar/sourcehar-file1&2.0.0.func_main_0(any a0, any a1, any a2) { +label_1: +label_0: + definefunc 0x0, &sourcehar/sourcehar-file1&2.0.0.#*#test, 0x0 + stmodulevar 0x0 + ldundefined + returnundefined +label_2: +} + + +======> literal array buffer <====== +------------------------------------ +------------------------------------ +{ + index: 0 + tag: 2 + val: 1 +}, +{ + index: 1 + tag: 5 + val: @normalized:N&&&sourcehar/sourcehar-file2&2.0.0 +}, +{ + index: 2 + tag: 2 + val: 1 +}, +{ + index: 3 + tag: 5 + val: test1 +}, +{ + index: 4 + tag: 5 + val: test +}, +{ + index: 5 + tag: 9 + val: 0 +}, +{ + index: 6 + tag: 2 + val: 0 +}, +{ + index: 7 + tag: 2 + val: 1 +}, +{ + index: 8 + tag: 5 + val: test +}, +{ + index: 9 + tag: 5 + val: test +}, +{ + index: 10 + tag: 2 + val: 0 +}, +{ + index: 11 + tag: 2 + val: 0 +}, +======> strings <====== +"&sourcehar/sourcehar-file1&2.0.0.#*#test"; "print"; "sourcehar.file1.test"; +.language ECMAScript + +.function any &sourcehar/sourcehar-file2&2.0.0.#*#test(any a0, any a1, any a2) { +label_1: +label_0: + tryldglobalbyname 0x0, print + sta v0 + lda.str sourcehar.file2.test + sta v1 + lda v0 + callarg1 0x1, v1 + ldundefined + returnundefined +label_2: +} + +.function any &sourcehar/sourcehar-file2&2.0.0.func_main_0(any a0, any a1, any a2) { +label_1: +label_0: + definefunc 0x0, &sourcehar/sourcehar-file2&2.0.0.#*#test, 0x0 + stmodulevar 0x0 + ldundefined + returnundefined +label_2: +} + + +======> literal array buffer <====== +------------------------------------ +------------------------------------ +{ + index: 0 + tag: 2 + val: 0 +}, +{ + index: 1 + tag: 2 + val: 0 +}, +{ + index: 2 + tag: 2 + val: 0 +}, +{ + index: 3 + tag: 2 + val: 1 +}, +{ + index: 4 + tag: 5 + val: test +}, +{ + index: 5 + tag: 5 + val: test +}, +{ + index: 6 + tag: 2 + val: 0 +}, +{ + index: 7 + tag: 2 + val: 0 +}, +======> strings <====== +"&sourcehar/sourcehar-file2&2.0.0.#*#test"; "print"; "sourcehar.file2.test"; +.language ECMAScript + +.function any &myapp/test-require&.#*#testRequire(any a0, any a1, any a2) { +label_1: +label_0: + tryldglobalbyname 0x0, console + sta v0 + ldobjbyname 0x1, log + sta v1 + ldlexvar 0x0, 0x0 + sta v2 + ldobjbyname 0x3, hi + callthis0 0x5, v2 + sta v2 + lda v1 + callthis1 0x7, v0, v2 + ldundefined + returnundefined +label_2: +} + +.function any &myapp/test-require&.func_main_0(any a0, any a1, any a2) { +label_1: +label_0: + newlexenv 0x1 + definefunc 0x0, &myapp/test-require&.#*#testRequire, 0x0 + sta v0 + ldundefined + stlexvar 0x0, 0x0 + tryldglobalbyname 0x1, require + sta v1 + lda.str ./commonjs-say + sta v2 + lda v1 + callarg1 0x2, v2 + stlexvar 0x0, 0x0 + tryldglobalbyname 0x4, module + ldobjbyname 0x5, exports + sta v1 + lda v0 + stobjbyname 0x7, testRequire, v1 + ldundefined + returnundefined +label_2: +} + + +======> literal array buffer <====== +------------------------------------ +------------------------------------ +{ + index: 0 + tag: 2 + val: 0 +}, +{ + index: 1 + tag: 2 + val: 0 +}, +{ + index: 2 + tag: 2 + val: 0 +}, +{ + index: 3 + tag: 2 + val: 0 +}, +{ + index: 4 + tag: 2 + val: 0 +}, +{ + index: 5 + tag: 2 + val: 0 +}, +======> strings <====== +"&myapp/test-require&.#*#testRequire"; "./commonjs-say"; "console"; "exports"; "hi"; "log"; "module"; "require"; "testRequire"; diff --git a/es2panda/test/compiler/bytecodehar/projects/bytecodehar-dependency-resolve/hap-file-exec-expected.pa.txt b/es2panda/test/compiler/bytecodehar/projects/bytecodehar-dependency-resolve/hap-file-exec-expected.pa.txt old mode 100755 new mode 100644 index 53d09542d7..4fee31ae6d --- a/es2panda/test/compiler/bytecodehar/projects/bytecodehar-dependency-resolve/hap-file-exec-expected.pa.txt +++ b/es2panda/test/compiler/bytecodehar/projects/bytecodehar-dependency-resolve/hap-file-exec-expected.pa.txt @@ -55,7 +55,6 @@ record_name: &sourcehar/sourcehar-file2&2.0.0 ======> literal array buffer <====== ------------------------------------ -slot &bytecodehar1/bytecodehar1-file1&2.0.0_880 { index: 0 tag: 2 @@ -117,7 +116,6 @@ slot &bytecodehar1/bytecodehar1-file1&2.0.0_880 val: 0 }, ------------------------------------ -slot &bytecodehar1/bytecodehar1-file2&2.0.0_1510 { index: 0 tag: 2 @@ -178,6 +176,8 @@ slot &bytecodehar1/bytecodehar1-file2&2.0.0_1510 tag: 2 val: 0 }, +======> strings <====== +"&bytecodehar1/bytecodehar1-file1&2.0.0.#*#test"; "&bytecodehar1/bytecodehar1-file2&2.0.0.#*#test"; "@normalized:N&&&sourcehar/sourcehar-file1&2.0.0"; "@normalized:N&&&sourcehar/sourcehar-file2&2.0.0"; "bytecodehar1.file1.test"; "bytecodehar1.file2.test"; "print"; .language ECMAScript .function any &@ohos/bytecodehar2/bytecodehar2-file1&2.0.0.#*#test(any a0, any a1, any a2) { @@ -219,7 +219,6 @@ slot &bytecodehar1/bytecodehar1-file2&2.0.0_1510 ======> literal array buffer <====== ------------------------------------ -slot &@ohos/bytecodehar2/bytecodehar2-file1&2.0.0_841 { index: 0 tag: 2 @@ -261,7 +260,6 @@ slot &@ohos/bytecodehar2/bytecodehar2-file1&2.0.0_841 val: 0 }, ------------------------------------ -slot &@ohos/bytecodehar2/bytecodehar2-file2&2.0.0_1358 { index: 0 tag: 2 @@ -302,6 +300,8 @@ slot &@ohos/bytecodehar2/bytecodehar2-file2&2.0.0_1358 tag: 2 val: 0 }, +======> strings <====== +"&@ohos/bytecodehar2/bytecodehar2-file1&2.0.0.#*#test"; "&@ohos/bytecodehar2/bytecodehar2-file2&2.0.0.#*#test"; "bytecodehar2.file1.test"; "bytecodehar2.file2.test"; "print"; .language ECMAScript .function any &myapp/hap-file-exec&.#*#main(any a0, any a1, any a2) { @@ -329,9 +329,7 @@ label_2: ======> literal array buffer <====== ------------------------------------ -slot &myapp/hap-file-exec&_0 ------------------------------------ -slot &myapp/hap-file-exec&_1 { index: 0 tag: 2 @@ -382,6 +380,8 @@ slot &myapp/hap-file-exec&_1 tag: 2 val: 0 }, +======> strings <====== +"&myapp/hap-file-exec&.#*#main"; "test"; .language ECMAScript .function any &sourcehar/sourcehar-file1&2.0.0.#*#test(any a0, any a1, any a2) { @@ -411,9 +411,7 @@ label_2: ======> literal array buffer <====== ------------------------------------ -slot &sourcehar/sourcehar-file1&2.0.0_0 ------------------------------------ -slot &sourcehar/sourcehar-file1&2.0.0_1 { index: 0 tag: 2 @@ -474,6 +472,8 @@ slot &sourcehar/sourcehar-file1&2.0.0_1 tag: 2 val: 0 }, +======> strings <====== +"&sourcehar/sourcehar-file1&2.0.0.#*#test"; "print"; "sourcehar.file1.test"; .language ECMAScript .function any &sourcehar/sourcehar-file2&2.0.0.#*#test(any a0, any a1, any a2) { @@ -503,9 +503,7 @@ label_2: ======> literal array buffer <====== ------------------------------------ -slot &sourcehar/sourcehar-file2&2.0.0_0 ------------------------------------ -slot &sourcehar/sourcehar-file2&2.0.0_1 { index: 0 tag: 2 @@ -546,3 +544,401 @@ slot &sourcehar/sourcehar-file2&2.0.0_1 tag: 2 val: 0 }, +======> strings <====== +"&sourcehar/sourcehar-file2&2.0.0.#*#test"; "print"; "sourcehar.file2.test"; +.language ECMAScript + +.function any &bytecodehar1/bytecodehar1-file1&2.0.0.#*#test(any a0, any a1, any a2) { + tryldglobalbyname 0x0, print + sta v0 + lda.str bytecodehar1.file1.test + sta v1 + lda v0 + callarg1 0x1, v1 + lda.str @normalized:N&&&sourcehar/sourcehar-file1&2.0.0 + dynamicimport + ldundefined + returnundefined +} + +.function any &bytecodehar1/bytecodehar1-file1&2.0.0.func_main_0(any a0, any a1, any a2) { + definefunc 0x0, &bytecodehar1/bytecodehar1-file1&2.0.0.#*#test, 0x0 + stmodulevar 0x0 + ldundefined + returnundefined +} + + +======> literal array buffer <====== +------------------------------------ +{ + index: 0 + tag: 2 + val: 1 +}, +{ + index: 1 + tag: 5 + val: @normalized:N&&&@ohos/bytecodehar2/bytecodehar2-file1&2.0.0 +}, +{ + index: 2 + tag: 2 + val: 1 +}, +{ + index: 3 + tag: 5 + val: test1 +}, +{ + index: 4 + tag: 5 + val: test +}, +{ + index: 5 + tag: 9 + val: 0 +}, +{ + index: 6 + tag: 2 + val: 0 +}, +{ + index: 7 + tag: 2 + val: 1 +}, +{ + index: 8 + tag: 5 + val: test +}, +{ + index: 9 + tag: 5 + val: test +}, +{ + index: 10 + tag: 2 + val: 0 +}, +{ + index: 11 + tag: 2 + val: 0 +}, +======> strings <====== +"&bytecodehar1/bytecodehar1-file1&2.0.0.#*#test"; "@normalized:N&&&sourcehar/sourcehar-file1&2.0.0"; "bytecodehar1.file1.test"; "print"; +.language ECMAScript + +.function any &@ohos/bytecodehar2/bytecodehar2-file1&2.0.0.#*#test(any a0, any a1, any a2) { + tryldglobalbyname 0x0, print + sta v0 + lda.str bytecodehar2.file1.test + sta v1 + lda v0 + callarg1 0x1, v1 + ldundefined + returnundefined +} + +.function any &@ohos/bytecodehar2/bytecodehar2-file1&2.0.0.func_main_0(any a0, any a1, any a2) { + definefunc 0x0, &@ohos/bytecodehar2/bytecodehar2-file1&2.0.0.#*#test, 0x0 + stmodulevar 0x0 + ldundefined + returnundefined +} + + +======> literal array buffer <====== +------------------------------------ +{ + index: 0 + tag: 2 + val: 0 +}, +{ + index: 1 + tag: 2 + val: 0 +}, +{ + index: 2 + tag: 2 + val: 0 +}, +{ + index: 3 + tag: 2 + val: 1 +}, +{ + index: 4 + tag: 5 + val: test +}, +{ + index: 5 + tag: 5 + val: test +}, +{ + index: 6 + tag: 2 + val: 0 +}, +{ + index: 7 + tag: 2 + val: 0 +}, +======> strings <====== +"&@ohos/bytecodehar2/bytecodehar2-file1&2.0.0.#*#test"; "bytecodehar2.file1.test"; "print"; +.language ECMAScript + +.function any &myapp/hap-file-exec&.#*#main(any a0, any a1, any a2) { +label_1: +label_0: + ldexternalmodulevar 0x0 + sta v0 + throw.undefinedifholewithname test + lda v0 + callarg0 0x0 + ldundefined + returnundefined +label_2: +} + +.function any &myapp/hap-file-exec&.func_main_0(any a0, any a1, any a2) { +label_1: +label_0: + definefunc 0x0, &myapp/hap-file-exec&.#*#main, 0x0 + ldundefined + returnundefined +label_2: +} + + +======> literal array buffer <====== +------------------------------------ +------------------------------------ +{ + index: 0 + tag: 2 + val: 1 +}, +{ + index: 1 + tag: 5 + val: @normalized:N&&&bytecodehar1/bytecodehar1-file1&2.0.0 +}, +{ + index: 2 + tag: 2 + val: 1 +}, +{ + index: 3 + tag: 5 + val: test +}, +{ + index: 4 + tag: 5 + val: test +}, +{ + index: 5 + tag: 9 + val: 0 +}, +{ + index: 6 + tag: 2 + val: 0 +}, +{ + index: 7 + tag: 2 + val: 0 +}, +{ + index: 8 + tag: 2 + val: 0 +}, +{ + index: 9 + tag: 2 + val: 0 +}, +======> strings <====== +"&myapp/hap-file-exec&.#*#main"; "test"; +.language ECMAScript + +.function any &sourcehar/sourcehar-file1&2.0.0.#*#test(any a0, any a1, any a2) { +label_1: +label_0: + tryldglobalbyname 0x0, print + sta v0 + lda.str sourcehar.file1.test + sta v1 + lda v0 + callarg1 0x1, v1 + ldundefined + returnundefined +label_2: +} + +.function any &sourcehar/sourcehar-file1&2.0.0.func_main_0(any a0, any a1, any a2) { +label_1: +label_0: + definefunc 0x0, &sourcehar/sourcehar-file1&2.0.0.#*#test, 0x0 + stmodulevar 0x0 + ldundefined + returnundefined +label_2: +} + + +======> literal array buffer <====== +------------------------------------ +------------------------------------ +{ + index: 0 + tag: 2 + val: 1 +}, +{ + index: 1 + tag: 5 + val: @normalized:N&&&sourcehar/sourcehar-file2&2.0.0 +}, +{ + index: 2 + tag: 2 + val: 1 +}, +{ + index: 3 + tag: 5 + val: test1 +}, +{ + index: 4 + tag: 5 + val: test +}, +{ + index: 5 + tag: 9 + val: 0 +}, +{ + index: 6 + tag: 2 + val: 0 +}, +{ + index: 7 + tag: 2 + val: 1 +}, +{ + index: 8 + tag: 5 + val: test +}, +{ + index: 9 + tag: 5 + val: test +}, +{ + index: 10 + tag: 2 + val: 0 +}, +{ + index: 11 + tag: 2 + val: 0 +}, +======> strings <====== +"&sourcehar/sourcehar-file1&2.0.0.#*#test"; "print"; "sourcehar.file1.test"; +.language ECMAScript + +.function any &sourcehar/sourcehar-file2&2.0.0.#*#test(any a0, any a1, any a2) { +label_1: +label_0: + tryldglobalbyname 0x0, print + sta v0 + lda.str sourcehar.file2.test + sta v1 + lda v0 + callarg1 0x1, v1 + ldundefined + returnundefined +label_2: +} + +.function any &sourcehar/sourcehar-file2&2.0.0.func_main_0(any a0, any a1, any a2) { +label_1: +label_0: + definefunc 0x0, &sourcehar/sourcehar-file2&2.0.0.#*#test, 0x0 + stmodulevar 0x0 + ldundefined + returnundefined +label_2: +} + + +======> literal array buffer <====== +------------------------------------ +------------------------------------ +{ + index: 0 + tag: 2 + val: 0 +}, +{ + index: 1 + tag: 2 + val: 0 +}, +{ + index: 2 + tag: 2 + val: 0 +}, +{ + index: 3 + tag: 2 + val: 1 +}, +{ + index: 4 + tag: 5 + val: test +}, +{ + index: 5 + tag: 5 + val: test +}, +{ + index: 6 + tag: 2 + val: 0 +}, +{ + index: 7 + tag: 2 + val: 0 +}, +======> strings <====== +"&sourcehar/sourcehar-file2&2.0.0.#*#test"; "print"; "sourcehar.file2.test"; diff --git a/es2panda/test/compiler/bytecodehar/projects/bytecodehar-test-project/hap-file-exec-expected.pa.txt b/es2panda/test/compiler/bytecodehar/projects/bytecodehar-test-project/hap-file-exec-expected.pa.txt old mode 100755 new mode 100644 index 21790b4ae8..e830034309 --- a/es2panda/test/compiler/bytecodehar/projects/bytecodehar-test-project/hap-file-exec-expected.pa.txt +++ b/es2panda/test/compiler/bytecodehar/projects/bytecodehar-test-project/hap-file-exec-expected.pa.txt @@ -53,7 +53,6 @@ record_name: &sourcehar/sourcehar-file1&2.0.0 ======> literal array buffer <====== ------------------------------------ -slot &bytecodehar1/bytecodehar1-file1&2.0.0_874 { index: 0 tag: 2 @@ -115,7 +114,6 @@ slot &bytecodehar1/bytecodehar1-file1&2.0.0_874 val: 0 }, ------------------------------------ -slot &bytecodehar1/bytecodehar1-file2&2.0.0_1498 { index: 0 tag: 2 @@ -176,6 +174,8 @@ slot &bytecodehar1/bytecodehar1-file2&2.0.0_1498 tag: 2 val: 0 }, +======> strings <====== +"&bytecodehar1/bytecodehar1-file1&2.0.0.#*#test"; "&bytecodehar1/bytecodehar1-file2&2.0.0.#*#test"; "@normalized:N&&&sourcehar/sourcehar-file1&2.0.0"; "@normalized:N&&&sourcehar/sourcehar-file2&2.0.0"; "bytecodehar1.file1.test"; "bytecodehar1.file2.test"; "print"; .language ECMAScript .function any &@ohos/bytecodehar2/bytecodehar2-file1&2.0.0.#*#test(any a0, any a1, any a2) { @@ -217,7 +217,6 @@ slot &bytecodehar1/bytecodehar1-file2&2.0.0_1498 ======> literal array buffer <====== ------------------------------------ -slot &@ohos/bytecodehar2/bytecodehar2-file1&2.0.0_835 { index: 0 tag: 2 @@ -259,7 +258,6 @@ slot &@ohos/bytecodehar2/bytecodehar2-file1&2.0.0_835 val: 0 }, ------------------------------------ -slot &@ohos/bytecodehar2/bytecodehar2-file2&2.0.0_1346 { index: 0 tag: 2 @@ -300,6 +298,8 @@ slot &@ohos/bytecodehar2/bytecodehar2-file2&2.0.0_1346 tag: 2 val: 0 }, +======> strings <====== +"&@ohos/bytecodehar2/bytecodehar2-file1&2.0.0.#*#test"; "&@ohos/bytecodehar2/bytecodehar2-file2&2.0.0.#*#test"; "bytecodehar2.file1.test"; "bytecodehar2.file2.test"; "print"; .language ECMAScript .function any &myapp/hap-file-exec&.#*#main(any a0, any a1, any a2) { @@ -327,9 +327,7 @@ label_2: ======> literal array buffer <====== ------------------------------------ -slot &myapp/hap-file-exec&_0 ------------------------------------ -slot &myapp/hap-file-exec&_1 { index: 0 tag: 2 @@ -380,6 +378,8 @@ slot &myapp/hap-file-exec&_1 tag: 2 val: 0 }, +======> strings <====== +"&myapp/hap-file-exec&.#*#main"; "test"; .language ECMAScript .function any &sourcehar/sourcehar-file1&2.0.0.#*#test(any a0, any a1, any a2) { @@ -409,9 +409,7 @@ label_2: ======> literal array buffer <====== ------------------------------------ -slot &sourcehar/sourcehar-file1&2.0.0_0 ------------------------------------ -slot &sourcehar/sourcehar-file1&2.0.0_1 { index: 0 tag: 2 @@ -452,6 +450,8 @@ slot &sourcehar/sourcehar-file1&2.0.0_1 tag: 2 val: 0 }, +======> strings <====== +"&sourcehar/sourcehar-file1&2.0.0.#*#test"; "print"; "sourcehar.file1.test"; .language ECMAScript .function any &sourcehar/sourcehar-file2&2.0.0.#*#test(any a0, any a1, any a2) { @@ -481,9 +481,7 @@ label_2: ======> literal array buffer <====== ------------------------------------ -slot &sourcehar/sourcehar-file2&2.0.0_0 ------------------------------------ -slot &sourcehar/sourcehar-file2&2.0.0_1 { index: 0 tag: 2 @@ -524,3 +522,309 @@ slot &sourcehar/sourcehar-file2&2.0.0_1 tag: 2 val: 0 }, +======> strings <====== +"&sourcehar/sourcehar-file2&2.0.0.#*#test"; "print"; "sourcehar.file2.test"; +.language ECMAScript + +.function any &bytecodehar1/bytecodehar1-file1&2.0.0.#*#test(any a0, any a1, any a2) { + tryldglobalbyname 0x0, print + sta v0 + lda.str bytecodehar1.file1.test + sta v1 + lda v0 + callarg1 0x1, v1 + lda.str @normalized:N&&&sourcehar/sourcehar-file1&2.0.0 + dynamicimport + ldundefined + returnundefined +} + +.function any &bytecodehar1/bytecodehar1-file1&2.0.0.func_main_0(any a0, any a1, any a2) { + definefunc 0x0, &bytecodehar1/bytecodehar1-file1&2.0.0.#*#test, 0x0 + stmodulevar 0x0 + ldundefined + returnundefined +} + + +======> literal array buffer <====== +------------------------------------ +{ + index: 0 + tag: 2 + val: 1 +}, +{ + index: 1 + tag: 5 + val: @normalized:N&&&@ohos/bytecodehar2/bytecodehar2-file1&2.0.0 +}, +{ + index: 2 + tag: 2 + val: 1 +}, +{ + index: 3 + tag: 5 + val: test1 +}, +{ + index: 4 + tag: 5 + val: test +}, +{ + index: 5 + tag: 9 + val: 0 +}, +{ + index: 6 + tag: 2 + val: 0 +}, +{ + index: 7 + tag: 2 + val: 1 +}, +{ + index: 8 + tag: 5 + val: test +}, +{ + index: 9 + tag: 5 + val: test +}, +{ + index: 10 + tag: 2 + val: 0 +}, +{ + index: 11 + tag: 2 + val: 0 +}, +======> strings <====== +"&bytecodehar1/bytecodehar1-file1&2.0.0.#*#test"; "@normalized:N&&&sourcehar/sourcehar-file1&2.0.0"; "bytecodehar1.file1.test"; "print"; +.language ECMAScript + +.function any &@ohos/bytecodehar2/bytecodehar2-file1&2.0.0.#*#test(any a0, any a1, any a2) { + tryldglobalbyname 0x0, print + sta v0 + lda.str bytecodehar2.file1.test + sta v1 + lda v0 + callarg1 0x1, v1 + ldundefined + returnundefined +} + +.function any &@ohos/bytecodehar2/bytecodehar2-file1&2.0.0.func_main_0(any a0, any a1, any a2) { + definefunc 0x0, &@ohos/bytecodehar2/bytecodehar2-file1&2.0.0.#*#test, 0x0 + stmodulevar 0x0 + ldundefined + returnundefined +} + + +======> literal array buffer <====== +------------------------------------ +{ + index: 0 + tag: 2 + val: 0 +}, +{ + index: 1 + tag: 2 + val: 0 +}, +{ + index: 2 + tag: 2 + val: 0 +}, +{ + index: 3 + tag: 2 + val: 1 +}, +{ + index: 4 + tag: 5 + val: test +}, +{ + index: 5 + tag: 5 + val: test +}, +{ + index: 6 + tag: 2 + val: 0 +}, +{ + index: 7 + tag: 2 + val: 0 +}, +======> strings <====== +"&@ohos/bytecodehar2/bytecodehar2-file1&2.0.0.#*#test"; "bytecodehar2.file1.test"; "print"; +.language ECMAScript + +.function any &myapp/hap-file-exec&.#*#main(any a0, any a1, any a2) { +label_1: +label_0: + ldexternalmodulevar 0x0 + sta v0 + throw.undefinedifholewithname test + lda v0 + callarg0 0x0 + ldundefined + returnundefined +label_2: +} + +.function any &myapp/hap-file-exec&.func_main_0(any a0, any a1, any a2) { +label_1: +label_0: + definefunc 0x0, &myapp/hap-file-exec&.#*#main, 0x0 + ldundefined + returnundefined +label_2: +} + + +======> literal array buffer <====== +------------------------------------ +------------------------------------ +{ + index: 0 + tag: 2 + val: 1 +}, +{ + index: 1 + tag: 5 + val: @normalized:N&&&bytecodehar1/bytecodehar1-file1&2.0.0 +}, +{ + index: 2 + tag: 2 + val: 1 +}, +{ + index: 3 + tag: 5 + val: test +}, +{ + index: 4 + tag: 5 + val: test +}, +{ + index: 5 + tag: 9 + val: 0 +}, +{ + index: 6 + tag: 2 + val: 0 +}, +{ + index: 7 + tag: 2 + val: 0 +}, +{ + index: 8 + tag: 2 + val: 0 +}, +{ + index: 9 + tag: 2 + val: 0 +}, +======> strings <====== +"&myapp/hap-file-exec&.#*#main"; "test"; +.language ECMAScript + +.function any &sourcehar/sourcehar-file1&2.0.0.#*#test(any a0, any a1, any a2) { +label_1: +label_0: + tryldglobalbyname 0x0, print + sta v0 + lda.str sourcehar.file1.test + sta v1 + lda v0 + callarg1 0x1, v1 + ldundefined + returnundefined +label_2: +} + +.function any &sourcehar/sourcehar-file1&2.0.0.func_main_0(any a0, any a1, any a2) { +label_1: +label_0: + definefunc 0x0, &sourcehar/sourcehar-file1&2.0.0.#*#test, 0x0 + stmodulevar 0x0 + ldundefined + returnundefined +label_2: +} + + +======> literal array buffer <====== +------------------------------------ +------------------------------------ +{ + index: 0 + tag: 2 + val: 0 +}, +{ + index: 1 + tag: 2 + val: 0 +}, +{ + index: 2 + tag: 2 + val: 0 +}, +{ + index: 3 + tag: 2 + val: 1 +}, +{ + index: 4 + tag: 5 + val: test +}, +{ + index: 5 + tag: 5 + val: test +}, +{ + index: 6 + tag: 2 + val: 0 +}, +{ + index: 7 + tag: 2 + val: 0 +}, +======> strings <====== +"&sourcehar/sourcehar-file1&2.0.0.#*#test"; "print"; "sourcehar.file1.test"; diff --git a/es2panda/test/compiler/bytecodehar/projects/bytecodehar-version-update/hap-file-exec-expected.pa.txt b/es2panda/test/compiler/bytecodehar/projects/bytecodehar-version-update/hap-file-exec-expected.pa.txt index e43f83ebca..15f9600b89 100644 --- a/es2panda/test/compiler/bytecodehar/projects/bytecodehar-version-update/hap-file-exec-expected.pa.txt +++ b/es2panda/test/compiler/bytecodehar/projects/bytecodehar-version-update/hap-file-exec-expected.pa.txt @@ -165,7 +165,6 @@ record_name: &@ohos/lib2/importfile4& ======> literal array buffer <====== ------------------------------------ -slot &bytecodehar/bytecodehar-dynamic-import&_1704 { index: 0 tag: 2 @@ -207,7 +206,6 @@ slot &bytecodehar/bytecodehar-dynamic-import&_1704 val: 0 }, ------------------------------------ -slot &bytecodehar/bytecodehar-static-import&_2222 { index: 0 tag: 2 @@ -388,6 +386,8 @@ slot &bytecodehar/bytecodehar-static-import&_2222 tag: 2 val: 0 }, +======> strings <====== +"&bytecodehar/bytecodehar-dynamic-import&.#*#testNonConst"; "&bytecodehar/bytecodehar-dynamic-import&.#*#testNonOhmurl"; "&bytecodehar/bytecodehar-dynamic-import&.#*#testReplacementWithAt"; "&bytecodehar/bytecodehar-dynamic-import&.#*#testReplacementWoAt"; "&bytecodehar/bytecodehar-static-import&.#*#foo"; "@normalized:N&&&@ohos/lib/importfile2&"; "@normalized:N&&&@ohos/lib/importfile2&1.0.0"; "@normalized:N&&&@ohos/lib/importfile2&2.0.0"; "@normalized:N&&&@ohos/lib2/importfile4&"; "@normalized:N&&&lib2/importfile3&"; "@normalized:N&&bundle&lib/importfile1&"; "@normalized:N&&bundle&lib/importfile1&1.0.0"; "@normalized:N&&bundle&lib/importfile1&2.0.0"; "@normalized:N&module&&@ohos/lib/importfile2&"; "@normalized:N&module&&@ohos/lib/importfile2&1.0.0"; "@normalized:N&module&&@ohos/lib/importfile2&2.0.0"; "@normalized:N&module&bundle&lib/importfile1&"; "@normalized:N&module&bundle&lib/importfile1&1.0.0"; "@normalized:N&module&bundle&lib/importfile1&2.0.0"; "a"; "aaa"; "b"; "c"; "d"; "e"; "f"; "g"; "h"; "i"; "j"; "print"; "test"; .language ECMAScript .function any &myapp/hap-file-exec&.func_main_0(any a0, any a1, any a2) { @@ -419,9 +419,7 @@ label_2: ======> literal array buffer <====== ------------------------------------ -slot &myapp/hap-file-exec&_0 ------------------------------------ -slot &myapp/hap-file-exec&_1 { index: 0 tag: 2 @@ -482,6 +480,8 @@ slot &myapp/hap-file-exec&_1 tag: 2 val: 0 }, +======> strings <====== +"print"; "test"; .language ECMAScript .function any bundle&lib/importfile1&2.0.0.func_main_0(any a0, any a1, any a2) { @@ -497,9 +497,7 @@ label_2: ======> literal array buffer <====== ------------------------------------ -slot bundle&lib/importfile1&2.0.0_0 ------------------------------------ -slot bundle&lib/importfile1&2.0.0_1 { index: 0 tag: 2 @@ -540,6 +538,709 @@ slot bundle&lib/importfile1&2.0.0_1 tag: 2 val: 0 }, +======> strings <====== + +.language ECMAScript + +.function any &@ohos/lib/importfile2&2.0.0.func_main_0(any a0, any a1, any a2) { +label_1: +label_0: + ldtrue + stmodulevar 0x0 + ldundefined + returnundefined +label_2: +} + + +======> literal array buffer <====== +------------------------------------ +------------------------------------ +{ + index: 0 + tag: 2 + val: 0 +}, +{ + index: 1 + tag: 2 + val: 0 +}, +{ + index: 2 + tag: 2 + val: 0 +}, +{ + index: 3 + tag: 2 + val: 1 +}, +{ + index: 4 + tag: 5 + val: test2 +}, +{ + index: 5 + tag: 5 + val: test2 +}, +{ + index: 6 + tag: 2 + val: 0 +}, +{ + index: 7 + tag: 2 + val: 0 +}, +======> strings <====== + +.language ECMAScript + +.function any &lib2/importfile3&.func_main_0(any a0, any a1, any a2) { +label_1: +label_0: + ldtrue + stmodulevar 0x0 + ldundefined + returnundefined +label_2: +} + + +======> literal array buffer <====== +------------------------------------ +------------------------------------ +{ + index: 0 + tag: 2 + val: 0 +}, +{ + index: 1 + tag: 2 + val: 0 +}, +{ + index: 2 + tag: 2 + val: 0 +}, +{ + index: 3 + tag: 2 + val: 1 +}, +{ + index: 4 + tag: 5 + val: test3 +}, +{ + index: 5 + tag: 5 + val: test3 +}, +{ + index: 6 + tag: 2 + val: 0 +}, +{ + index: 7 + tag: 2 + val: 0 +}, +======> strings <====== + +.language ECMAScript + +.function any &@ohos/lib2/importfile4&.func_main_0(any a0, any a1, any a2) { +label_1: +label_0: + ldtrue + stmodulevar 0x0 + ldundefined + returnundefined +label_2: +} + + +======> literal array buffer <====== +------------------------------------ +------------------------------------ +{ + index: 0 + tag: 2 + val: 0 +}, +{ + index: 1 + tag: 2 + val: 0 +}, +{ + index: 2 + tag: 2 + val: 0 +}, +{ + index: 3 + tag: 2 + val: 1 +}, +{ + index: 4 + tag: 5 + val: test4 +}, +{ + index: 5 + tag: 5 + val: test4 +}, +{ + index: 6 + tag: 2 + val: 0 +}, +{ + index: 7 + tag: 2 + val: 0 +}, +======> strings <====== + +.language ECMAScript + +.function any &bytecodehar/bytecodehar-dynamic-import&.#*#testNonConst(any a0, any a1, any a2) { + lda.str @normalized:N&&bundle&lib/importfile1&2.0.0 + dynamicimport + lda.str @normalized:N&&bundle&lib/importfile1&2.0.0 + dynamicimport + lda.str @normalized:N&&bundle&lib/importfile1&2.0.0 + dynamicimport + ldundefined + returnundefined +} + +.function any &bytecodehar/bytecodehar-dynamic-import&.#*#testNonOhmurl(any a0, any a1, any a2) { + lda.str aaa + dynamicimport + ldundefined + returnundefined +} + +.function any &bytecodehar/bytecodehar-dynamic-import&.#*#testReplacementWithAt(any a0, any a1, any a2) { + lda.str @normalized:N&module&&@ohos/lib/importfile2&2.0.0 + dynamicimport + lda.str @normalized:N&module&&@ohos/lib/importfile2&2.0.0 + dynamicimport + lda.str @normalized:N&&&@ohos/lib/importfile2&2.0.0 + dynamicimport + lda.str @normalized:N&&&@ohos/lib/importfile2&2.0.0 + dynamicimport + lda.str @normalized:N&&&@ohos/lib2/importfile4& + dynamicimport + ldundefined + returnundefined +} + +.function any &bytecodehar/bytecodehar-dynamic-import&.#*#testReplacementWoAt(any a0, any a1, any a2) { + lda.str @normalized:N&module&bundle&lib/importfile1&2.0.0 + dynamicimport + lda.str @normalized:N&module&bundle&lib/importfile1&2.0.0 + dynamicimport + lda.str @normalized:N&&bundle&lib/importfile1&2.0.0 + dynamicimport + lda.str @normalized:N&&bundle&lib/importfile1&2.0.0 + dynamicimport + lda.str @normalized:N&&&lib2/importfile3& + dynamicimport + ldundefined + returnundefined +} + +.function any &bytecodehar/bytecodehar-dynamic-import&.func_main_0(any a0, any a1, any a2) { + definefunc 0x0, &bytecodehar/bytecodehar-dynamic-import&.#*#testNonConst, 0x0 + definefunc 0x1, &bytecodehar/bytecodehar-dynamic-import&.#*#testNonOhmurl, 0x0 + definefunc 0x2, &bytecodehar/bytecodehar-dynamic-import&.#*#testReplacementWithAt, 0x0 + definefunc 0x3, &bytecodehar/bytecodehar-dynamic-import&.#*#testReplacementWoAt, 0x0 + lda.str test + stmodulevar 0x0 + ldundefined + returnundefined +} + +.function any &bytecodehar/bytecodehar-static-import&.#*#foo(any a0, any a1, any a2) { + tryldglobalbyname 0x0, print + sta v0 + createemptyarray 0x1 + sta v1 + ldlexvar 0x0, 0x0 + sta v2 + throw.undefinedifholewithname a + lda v2 + stownbyindex 0x2, v1, 0x0 + ldlexvar 0x0, 0x1 + sta v2 + throw.undefinedifholewithname b + lda v2 + stownbyindex 0x4, v1, 0x1 + ldlexvar 0x0, 0x2 + sta v2 + throw.undefinedifholewithname c + lda v2 + stownbyindex 0x6, v1, 0x2 + ldlexvar 0x0, 0x3 + sta v2 + throw.undefinedifholewithname d + lda v2 + stownbyindex 0x8, v1, 0x3 + ldlexvar 0x0, 0x4 + sta v2 + throw.undefinedifholewithname e + lda v2 + stownbyindex 0xa, v1, 0x4 + ldlexvar 0x0, 0x5 + sta v2 + throw.undefinedifholewithname f + lda v2 + stownbyindex 0xc, v1, 0x5 + ldlexvar 0x0, 0x6 + sta v2 + throw.undefinedifholewithname g + lda v2 + stownbyindex 0xe, v1, 0x6 + ldlexvar 0x0, 0x7 + sta v2 + throw.undefinedifholewithname h + lda v2 + stownbyindex 0x10, v1, 0x7 + ldlexvar 0x0, 0x8 + sta v2 + throw.undefinedifholewithname i + lda v2 + stownbyindex 0x12, v1, 0x8 + ldlexvar 0x0, 0x9 + sta v2 + throw.undefinedifholewithname j + lda v2 + stownbyindex 0x14, v1, 0x9 + lda v0 + callarg1 0x16, v1 + ldundefined + returnundefined +} + +.function any &bytecodehar/bytecodehar-static-import&.func_main_0(any a0, any a1, any a2) { + newlexenv 0xa + definefunc 0x0, &bytecodehar/bytecodehar-static-import&.#*#foo, 0x0 + getmodulenamespace 0x0 + stlexvar 0x0, 0x0 + getmodulenamespace 0x1 + stlexvar 0x0, 0x1 + getmodulenamespace 0x2 + stlexvar 0x0, 0x2 + getmodulenamespace 0x3 + stlexvar 0x0, 0x3 + getmodulenamespace 0x4 + stlexvar 0x0, 0x4 + getmodulenamespace 0x5 + stlexvar 0x0, 0x5 + getmodulenamespace 0x6 + stlexvar 0x0, 0x6 + getmodulenamespace 0x7 + stlexvar 0x0, 0x7 + getmodulenamespace 0x8 + stlexvar 0x0, 0x8 + getmodulenamespace 0x9 + stlexvar 0x0, 0x9 + ldundefined + returnundefined +} + + +======> literal array buffer <====== +------------------------------------ +{ + index: 0 + tag: 2 + val: 0 +}, +{ + index: 1 + tag: 2 + val: 0 +}, +{ + index: 2 + tag: 2 + val: 0 +}, +{ + index: 3 + tag: 2 + val: 1 +}, +{ + index: 4 + tag: 5 + val: test +}, +{ + index: 5 + tag: 5 + val: test +}, +{ + index: 6 + tag: 2 + val: 0 +}, +{ + index: 7 + tag: 2 + val: 0 +}, +------------------------------------ +{ + index: 0 + tag: 2 + val: 10 +}, +{ + index: 1 + tag: 5 + val: @normalized:N&module&bundle&lib/importfile1&2.0.0 +}, +{ + index: 2 + tag: 5 + val: @normalized:N&module&bundle&lib/importfile1&2.0.0 +}, +{ + index: 3 + tag: 5 + val: @normalized:N&&bundle&lib/importfile1&2.0.0 +}, +{ + index: 4 + tag: 5 + val: @normalized:N&&bundle&lib/importfile1&2.0.0 +}, +{ + index: 5 + tag: 5 + val: @normalized:N&&&lib2/importfile3& +}, +{ + index: 6 + tag: 5 + val: @normalized:N&module&&@ohos/lib/importfile2&2.0.0 +}, +{ + index: 7 + tag: 5 + val: @normalized:N&module&&@ohos/lib/importfile2&2.0.0 +}, +{ + index: 8 + tag: 5 + val: @normalized:N&&&@ohos/lib/importfile2&2.0.0 +}, +{ + index: 9 + tag: 5 + val: @normalized:N&&&@ohos/lib/importfile2&2.0.0 +}, +{ + index: 10 + tag: 5 + val: @normalized:N&&&@ohos/lib2/importfile4& +}, +{ + index: 11 + tag: 2 + val: 0 +}, +{ + index: 12 + tag: 2 + val: 10 +}, +{ + index: 13 + tag: 5 + val: a +}, +{ + index: 14 + tag: 9 + val: 0 +}, +{ + index: 15 + tag: 5 + val: b +}, +{ + index: 16 + tag: 9 + val: 1 +}, +{ + index: 17 + tag: 5 + val: c +}, +{ + index: 18 + tag: 9 + val: 2 +}, +{ + index: 19 + tag: 5 + val: d +}, +{ + index: 20 + tag: 9 + val: 3 +}, +{ + index: 21 + tag: 5 + val: e +}, +{ + index: 22 + tag: 9 + val: 4 +}, +{ + index: 23 + tag: 5 + val: f +}, +{ + index: 24 + tag: 9 + val: 5 +}, +{ + index: 25 + tag: 5 + val: g +}, +{ + index: 26 + tag: 9 + val: 6 +}, +{ + index: 27 + tag: 5 + val: h +}, +{ + index: 28 + tag: 9 + val: 7 +}, +{ + index: 29 + tag: 5 + val: i +}, +{ + index: 30 + tag: 9 + val: 8 +}, +{ + index: 31 + tag: 5 + val: j +}, +{ + index: 32 + tag: 9 + val: 9 +}, +{ + index: 33 + tag: 2 + val: 0 +}, +{ + index: 34 + tag: 2 + val: 0 +}, +{ + index: 35 + tag: 2 + val: 0 +}, +======> strings <====== +"&bytecodehar/bytecodehar-dynamic-import&.#*#testNonConst"; "&bytecodehar/bytecodehar-dynamic-import&.#*#testNonOhmurl"; "&bytecodehar/bytecodehar-dynamic-import&.#*#testReplacementWithAt"; "&bytecodehar/bytecodehar-dynamic-import&.#*#testReplacementWoAt"; "&bytecodehar/bytecodehar-static-import&.#*#foo"; "@normalized:N&&&@ohos/lib/importfile2&2.0.0"; "@normalized:N&&&@ohos/lib2/importfile4&"; "@normalized:N&&&lib2/importfile3&"; "@normalized:N&&bundle&lib/importfile1&2.0.0"; "@normalized:N&module&&@ohos/lib/importfile2&2.0.0"; "@normalized:N&module&bundle&lib/importfile1&2.0.0"; "a"; "aaa"; "b"; "c"; "d"; "e"; "f"; "g"; "h"; "i"; "j"; "print"; "test"; +.language ECMAScript + +.function any &myapp/hap-file-exec&.func_main_0(any a0, any a1, any a2) { +label_1: +label_0: + getmodulenamespace 0x0 + sta v0 + getmodulenamespace 0x1 + sta v1 + tryldglobalbyname 0x0, print + sta v2 + lda v0 + ldobjbyname 0x1, test + sta v0 + lda v2 + callarg1 0x3, v0 + tryldglobalbyname 0x5, print + sta v0 + lda v1 + ldobjbyname 0x6, test + sta v1 + lda v0 + callarg1 0x8, v1 + ldundefined + returnundefined +label_2: +} + + +======> literal array buffer <====== +------------------------------------ +------------------------------------ +{ + index: 0 + tag: 2 + val: 2 +}, +{ + index: 1 + tag: 5 + val: @normalized:N&&&bytecodehar/bytecodehar-dynamic-import& +}, +{ + index: 2 + tag: 5 + val: @normalized:N&&&bytecodehar/bytecodehar-static-import& +}, +{ + index: 3 + tag: 2 + val: 0 +}, +{ + index: 4 + tag: 2 + val: 2 +}, +{ + index: 5 + tag: 5 + val: bytecodeharDynamicImport +}, +{ + index: 6 + tag: 9 + val: 0 +}, +{ + index: 7 + tag: 5 + val: bytecodeharStaticImport +}, +{ + index: 8 + tag: 9 + val: 1 +}, +{ + index: 9 + tag: 2 + val: 0 +}, +{ + index: 10 + tag: 2 + val: 0 +}, +{ + index: 11 + tag: 2 + val: 0 +}, +======> strings <====== +"print"; "test"; +.language ECMAScript + +.function any bundle&lib/importfile1&2.0.0.func_main_0(any a0, any a1, any a2) { +label_1: +label_0: + ldtrue + stmodulevar 0x0 + ldundefined + returnundefined +label_2: +} + + +======> literal array buffer <====== +------------------------------------ +------------------------------------ +{ + index: 0 + tag: 2 + val: 0 +}, +{ + index: 1 + tag: 2 + val: 0 +}, +{ + index: 2 + tag: 2 + val: 0 +}, +{ + index: 3 + tag: 2 + val: 1 +}, +{ + index: 4 + tag: 5 + val: test1 +}, +{ + index: 5 + tag: 5 + val: test1 +}, +{ + index: 6 + tag: 2 + val: 0 +}, +{ + index: 7 + tag: 2 + val: 0 +}, +======> strings <====== + .language ECMAScript .function any &@ohos/lib/importfile2&2.0.0.func_main_0(any a0, any a1, any a2) { @@ -555,9 +1256,7 @@ label_2: ======> literal array buffer <====== ------------------------------------ -slot &@ohos/lib/importfile2&2.0.0_0 ------------------------------------ -slot &@ohos/lib/importfile2&2.0.0_1 { index: 0 tag: 2 @@ -598,6 +1297,8 @@ slot &@ohos/lib/importfile2&2.0.0_1 tag: 2 val: 0 }, +======> strings <====== + .language ECMAScript .function any &lib2/importfile3&.func_main_0(any a0, any a1, any a2) { @@ -613,9 +1314,7 @@ label_2: ======> literal array buffer <====== ------------------------------------ -slot &lib2/importfile3&_0 ------------------------------------ -slot &lib2/importfile3&_1 { index: 0 tag: 2 @@ -656,6 +1355,8 @@ slot &lib2/importfile3&_1 tag: 2 val: 0 }, +======> strings <====== + .language ECMAScript .function any &@ohos/lib2/importfile4&.func_main_0(any a0, any a1, any a2) { @@ -671,9 +1372,7 @@ label_2: ======> literal array buffer <====== ------------------------------------ -slot &@ohos/lib2/importfile4&_0 ------------------------------------ -slot &@ohos/lib2/importfile4&_1 { index: 0 tag: 2 @@ -714,3 +1413,5 @@ slot &@ohos/lib2/importfile4&_1 tag: 2 val: 0 }, +======> strings <====== + diff --git a/es2panda/test/runner.py b/es2panda/test/runner.py index 756e4517a4..b2dd1db1cd 100755 --- a/es2panda/test/runner.py +++ b/es2panda/test/runner.py @@ -981,7 +981,7 @@ class BcVersionTest(Test): 12: "12.0.4.0", 13: "12.0.4.0" } - + def run(self): process = subprocess.Popen(self.cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = process.communicate() @@ -1478,9 +1478,12 @@ def add_directory_for_compiler(runners, args): "--file-threads=8"])) compiler_test_infos.append(CompilerTestInfo("compiler/bytecodehar/projects", "ts", ["--merge-abc", "--dump-assembly", "--enable-abc-input", - "--dump-deps-info", "--dump-literal-buffer"])) + "--dump-deps-info", "--remove-redundant-file", + "--dump-literal-buffer", "--dump-string"])) compiler_test_infos.append(CompilerTestInfo("compiler/bytecodehar/js/projects", "js", - ["--merge-abc", "--dump-assembly", "--enable-abc-input", "--dump-deps-info"])) + ["--merge-abc", "--dump-assembly", "--enable-abc-input", + "--dump-deps-info", "--remove-redundant-file", + "--dump-literal-buffer", "--dump-string"])) if args.enable_arkguard: prepare_for_obfuscation(compiler_test_infos, runner.test_root) @@ -1551,7 +1554,7 @@ def add_cmd_for_aop_transform(runners, args): class AopTransform(Runner): def __init__(self, args): Runner.__init__(self, args, "AopTransform") - + def add_cmd(self, cmd, compare_str, compare_abc_str, remove_file, func=TestAop): self.tests += [func(cmd, compare_str, compare_abc_str, remove_file)] diff --git a/es2panda/util/dumper.cpp b/es2panda/util/dumper.cpp index e709cf861b..483858f740 100644 --- a/es2panda/util/dumper.cpp +++ b/es2panda/util/dumper.cpp @@ -16,12 +16,17 @@ namespace panda::es2panda::util { -void Dumper::DumpLiterals(std::map const &literalTable) +void Dumper::DumpLiterals(std::map const &literalTable, + bool skipLiteralArraySlot) { std::cout << "======> literal array buffer <======" << std::endl; for (auto it : literalTable) { std::cout << "------------------------------------" << std::endl; - std::cout << "slot " << it.first << std::endl; + // Literalarray slot of programs generated from abc input depends on literalarray' offset, which is unstable, + // and will affect the UT. Skip dumping this information as a workaround. + if (!skipLiteralArraySlot) { + std::cout << "slot " << it.first << std::endl; + } int count = 0; for (auto literal : it.second.literals_) { std::cout << "{" << std::endl; @@ -43,5 +48,14 @@ void Dumper::DumpLiterals(std::map co } } +void Dumper::DumpStrings(std::set const &strings) +{ + std::cout << "======> strings <======" << std::endl; + for (auto &string : strings) { + std::cout << "\"" << string << "\"; "; + } + std::cout << std::endl; +} + } // namespace panda::es2panda::util diff --git a/es2panda/util/dumper.h b/es2panda/util/dumper.h index cdfa7c7cb6..0e28128296 100644 --- a/es2panda/util/dumper.h +++ b/es2panda/util/dumper.h @@ -25,7 +25,9 @@ namespace panda::es2panda::util { class Dumper { public: - static void DumpLiterals(std::map const &literalTable); + static void DumpLiterals(std::map const &literalTable, + bool skipLiteralArraySlot = false); + static void DumpStrings(std::set const &strings); }; } // namespace panda::es2panda::util diff --git a/es2panda/util/helpers.cpp b/es2panda/util/helpers.cpp index c1e1154ffb..0d4d209d92 100644 --- a/es2panda/util/helpers.cpp +++ b/es2panda/util/helpers.cpp @@ -946,4 +946,92 @@ bool Helpers::IsSpecialScopeName(const util::StringView &name) return name.Find(Helpers::DOT.data()) != std::string::npos || name.Find(Helpers::BACKSLASH.data()) != std::string::npos; } + +bool Helpers::BelongingToRecords(const std::string &name, const std::unordered_set &retainRecordSet, + const std::string &delimiter) +{ + size_t pos = name.rfind(delimiter); + if (pos == std::string::npos) { + std::cerr << "The input name: " << name << " is illegal, it should contain the delimiter character '" + << delimiter << "'" << std::endl; + return false; + } + + auto recordName = name.substr(0, pos); + return retainRecordSet.find(recordName) != retainRecordSet.end(); +} + +void Helpers::RemoveProgramRedundantData(panda::pandasm::Program &program, + const std::unordered_set &retainRecordSet, + const std::unordered_set &generatedRecords) +{ + // remove redundant record + auto recordIter = program.record_table.begin(); + while (recordIter != program.record_table.end()) { + if (retainRecordSet.find(recordIter->first) == retainRecordSet.end() + && generatedRecords.find(recordIter->first) == generatedRecords.end()) { + recordIter = program.record_table.erase(recordIter); + } else { + recordIter++; + } + } + + std::set updatedStrings {}; + + // remove redundant function + auto functionIter = program.function_table.begin(); + while (functionIter != program.function_table.end()) { + auto funcName = functionIter->first; + if (!BelongingToRecords(funcName, retainRecordSet)) { + functionIter = program.function_table.erase(functionIter); + + auto synonymsIter = program.function_synonyms.find(funcName); + if (synonymsIter != program.function_synonyms.end()) { + program.function_synonyms.erase(synonymsIter); + } + } else { + auto funcStringSet = functionIter->second.CollectStringsFromFunctionInsns(); + updatedStrings.insert(funcStringSet.begin(), funcStringSet.end()); + + functionIter++; + } + } + + // remove redundant string + program.strings = updatedStrings; + + // remove redundant literalarray + auto literalarrayIter = program.literalarray_table.begin(); + while (literalarrayIter != program.literalarray_table.end()) { + // literalArrayKey format: recordName_literalArrayOffset + if (!BelongingToRecords(literalarrayIter->first, retainRecordSet, "_")) { + literalarrayIter = program.literalarray_table.erase(literalarrayIter); + } else { + literalarrayIter++; + } + } +} + +void Helpers::RemoveProgramsRedundantData(std::map &progsInfo, + const std::map> &resolvedDepsRelation, + const std::unordered_set &generatedRecords) +{ + auto progInfoIter = progsInfo.begin(); + while (progInfoIter != progsInfo.end()) { + // 1. remove redundant files which are not dependant in compilation + if (resolvedDepsRelation.find(progInfoIter->first) == resolvedDepsRelation.end()) { + progInfoIter = progsInfo.erase(progInfoIter); + continue; + } + + // 2. remove redundant data from programs which are generated from abc + if (progInfoIter->second->generatedFromAbc) { + auto retainRecordSet = resolvedDepsRelation.find(progInfoIter->first)->second; + RemoveProgramRedundantData(progInfoIter->second->program, retainRecordSet, generatedRecords); + } + + progInfoIter++; + } +} + } // namespace panda::es2panda::util diff --git a/es2panda/util/helpers.h b/es2panda/util/helpers.h index 01f14159cc..61614a1f3f 100644 --- a/es2panda/util/helpers.h +++ b/es2panda/util/helpers.h @@ -16,13 +16,15 @@ #ifndef ES2PANDA_UTIL_HELPERS_H #define ES2PANDA_UTIL_HELPERS_H -#include +#include + #include #include #include -#include -#include +#include +#include +#include namespace panda::es2panda::ir { class Expression; @@ -83,6 +85,15 @@ public: static constexpr std::string_view DYLIB = ".dylib"; }; +struct DepsRelationInfo { + const std::map> resolvedDepsRelation {}; + const std::unordered_set generatedRecords {}; + + DepsRelationInfo(const std::map> resolvedDepsRelation, + const std::unordered_set generatedRecords) + : resolvedDepsRelation(resolvedDepsRelation), generatedRecords(generatedRecords) {}; +}; + using AopTransformFuncDef = int (*)(const char *); class Helpers { @@ -148,6 +159,14 @@ public: static bool IsUseShared(const ir::Statement *statement); static const ir::ClassDefinition *GetContainingSendableClass(const ir::AstNode *node); static bool IsSpecialScopeName(const util::StringView &str); + static bool BelongingToRecords(const std::string &name, const std::unordered_set &retainRecordSet, + const std::string &delimiter = std::string(DOT)); + static void RemoveProgramRedundantData(panda::pandasm::Program &program, + const std::unordered_set &retainRecordSet, + const std::unordered_set &generatedRecords); + static void RemoveProgramsRedundantData(std::map &progsInfo, + const std::map> &resolveDepsRelation, + const std::unordered_set &generatedRecords); static const uint32_t MAX_DOUBLE_DIGIT = 310; static const uint32_t MAX_DOUBLE_PRECISION_DIGIT = 17; diff --git a/es2panda/util/programCache.h b/es2panda/util/programCache.h index 946dd3c4fd..d8da105302 100644 --- a/es2panda/util/programCache.h +++ b/es2panda/util/programCache.h @@ -23,7 +23,8 @@ namespace panda::es2panda::util { struct ProgramCache { uint32_t hashCode; panda::pandasm::Program program; - bool needUpdateCache { false }; + bool needUpdateCache {false}; + bool generatedFromAbc {false}; ProgramCache(uint32_t hashCode, panda::pandasm::Program program) : hashCode(hashCode), program(std::move(program)) { -- Gitee