From 44bb1a2aac13105f190a4d686114bf16c12e9d61 Mon Sep 17 00:00:00 2001 From: jiangkaiwen678217 Date: Sat, 10 Aug 2024 16:19:09 +0800 Subject: [PATCH 1/3] Update option code Issue:IAJ5J7 Signed-off-by: jiangkaiwen678217 --- arkfuzzilli/frontend/options.cpp | 275 ++++++++++++++++++++++++------- arkfuzzilli/frontend/options.h | 14 +- 2 files changed, 229 insertions(+), 60 deletions(-) diff --git a/arkfuzzilli/frontend/options.cpp b/arkfuzzilli/frontend/options.cpp index a375609..4e4f900 100644 --- a/arkfuzzilli/frontend/options.cpp +++ b/arkfuzzilli/frontend/options.cpp @@ -26,6 +26,8 @@ #include #endif +#include "bytecode_optimizer/bytecodeopt_options.h" +#include "compiler_options.h" #include "os/file.h" #include "mergeProgram.h" @@ -34,8 +36,12 @@ namespace panda::es2panda::aot { constexpr char PROCESS_AS_LIST_MARK = '@'; +// item list: [filePath; recordName; moduleKind; sourceFile; pkgName; isSharedModule] +constexpr size_t ITEM_COUNT_MERGE = 6; +// item list: [filePath; recordName; moduleKind; sourceFile; outputfile; isSharedModule] +constexpr size_t ITEM_COUNT_NOT_MERGE = 6; const std::string LIST_ITEM_SEPERATOR = ";"; -const std::set VALID_EXTENSIONS = { "js", "ts", "as" }; +const std::set VALID_EXTENSIONS = { "js", "ts", "as", "abc" }; template T RemoveExtension(T const &filename) @@ -52,6 +58,8 @@ static es2panda::ScriptExtension GetScriptExtensionFromStr(const std::string &ex return es2panda::ScriptExtension::TS; } else if (extension == "as") { return es2panda::ScriptExtension::AS; + } else if (extension == "abc") { + return es2panda::ScriptExtension::ABC; } else { return es2panda::ScriptExtension::JS; } @@ -90,6 +98,68 @@ static std::vector GetStringItems(std::string &input, const std::st return items; } +void Options::CollectInputAbcFile(const std::string &fileName, const std::string &inputExtension) +{ + es2panda::SourceFile src(fileName, "", parser::ScriptKind::SCRIPT, GetScriptExtension(fileName, + inputExtension)); + src.isSourceMode = false; + sourceFiles_.push_back(src); +} + +void Options::CollectInputSourceFile(const std::vector &itemList, const std::string &inputExtension) +{ + std::string fileName = itemList[0]; + std::string recordName = compilerOptions_.mergeAbc ? itemList[1] : ""; + constexpr uint32_t SCRIPT_KIND_IDX = 2; + constexpr uint32_t SOURCE_FIEL_IDX = 3; + constexpr uint32_t PKG_NAME_IDX = 4; + constexpr uint32_t Is_SHARED_MODULE_IDX = 5; + parser::ScriptKind scriptKind; + if (itemList[SCRIPT_KIND_IDX] == "script") { + scriptKind = parser::ScriptKind::SCRIPT; + } else if (itemList[SCRIPT_KIND_IDX] == "commonjs") { + scriptKind = parser::ScriptKind::COMMONJS; + } else { + scriptKind = parser::ScriptKind::MODULE; + } + + es2panda::SourceFile src(fileName, recordName, scriptKind, GetScriptExtension(fileName, inputExtension)); + src.sourcefile = itemList[SOURCE_FIEL_IDX]; + if (compilerOptions_.mergeAbc) { + src.pkgName = itemList[PKG_NAME_IDX]; + } + + if (itemList.size() == ITEM_COUNT_MERGE) { + src.isSharedModule = itemList[Is_SHARED_MODULE_IDX] == "true"; + } + + sourceFiles_.push_back(src); + if (!compilerOptions_.mergeAbc) { + outputFiles_.insert({fileName, itemList[PKG_NAME_IDX]}); + } +} + +bool Options::CheckFilesValidity(const std::string &input, const std::vector &itemList, + const std::string &line) +{ + // For compatibility, only throw error when item list's size is bigger than given size. + if ((compilerOptions_.mergeAbc && itemList.size() > ITEM_COUNT_MERGE) || + (!compilerOptions_.mergeAbc && itemList.size() > ITEM_COUNT_NOT_MERGE) || itemList.empty()) { + std::cerr << "Failed to parse line " << line << " of the input file: '" + << input << "'." << std::endl + << "Expected " << (compilerOptions_.mergeAbc ? ITEM_COUNT_MERGE : ITEM_COUNT_NOT_MERGE) + << " items per line, but found " << itemList.size() << " items." << std::endl + << "Please check the file format and content for correctness." << std::endl; + return false; + } + return true; +} + +bool Options::IsAbcFile(const std::string &fileName, const std::string &inputExtension) +{ + return (GetScriptExtension(fileName, inputExtension) == es2panda::ScriptExtension::ABC); +} + // Options bool Options::CollectInputFilesFromFileList(const std::string &input, const std::string &inputExtension) { @@ -97,40 +167,21 @@ bool Options::CollectInputFilesFromFileList(const std::string &input, const std: std::string line; ifs.open(panda::os::file::File::GetExtendedFilePath(input)); if (!ifs.is_open()) { - std::cerr << "Failed to open source list: " << input << std::endl; + std::cerr << "Failed to open source list file '" << input << "' during input file collection." << std::endl + << "Please check if the file exists or the path is correct, " + << "and you have the necessary permissions to access it." << std::endl; return false; } - 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)) { std::vector itemList = GetStringItems(line, LIST_ITEM_SEPERATOR); - if ((compilerOptions_.mergeAbc && itemList.size() != ITEM_COUNT_MERGE) || - (!compilerOptions_.mergeAbc && itemList.size() != ITEM_COUNT_NOT_MERGE)) { - std::cerr << "Failed to parse input file" << std::endl; + if (!CheckFilesValidity(input, itemList, line)) { return false; } - - std::string fileName = itemList[0]; - std::string recordName = compilerOptions_.mergeAbc ? itemList[1] : ""; - parser::ScriptKind scriptKind; - if (itemList[2] == "script") { - scriptKind = parser::ScriptKind::SCRIPT; - } else if (itemList[2] == "commonjs") { - scriptKind = parser::ScriptKind::COMMONJS; + if (IsAbcFile(itemList[0], inputExtension)) { + CollectInputAbcFile(itemList[0], inputExtension); } else { - scriptKind = parser::ScriptKind::MODULE; - } - - es2panda::SourceFile src(fileName, recordName, scriptKind, GetScriptExtension(fileName, inputExtension)); - src.sourcefile = itemList[3]; - if (compilerOptions_.mergeAbc) { - src.pkgName = itemList[4]; - } - - sourceFiles_.push_back(src); - if (!compilerOptions_.mergeAbc) { - outputFiles_.insert({fileName, itemList[4]}); + CollectInputSourceFile(itemList, inputExtension); } } return true; @@ -163,7 +214,9 @@ void Options::ParseCacheFileOption(const std::string &cacheInput) std::string line; ifs.open(panda::os::file::File::GetExtendedFilePath(cacheInput.substr(1))); if (!ifs.is_open()) { - std::cerr << "Failed to open cache file list: " << cacheInput << std::endl; + std::cerr << "Failed to open cache file list from the provided path: '" << cacheInput << "'." << std::endl + << "Please check if the file exists or the path is correct, " + << "and you have the necessary permissions to read the file." << std::endl; return; } @@ -190,7 +243,7 @@ bool Options::Parse(int argc, const char **argv) // parser panda::PandArg inputExtension("extension", "js", - "Parse the input as the given extension (options: js | ts | as)"); + "Parse the input as the given extension (options: js | ts | as | abc)"); panda::PandArg opModule("module", false, "Parse the input as module"); panda::PandArg opCommonjs("commonjs", false, "Parse the input as commonjs"); panda::PandArg opParseOnly("parse-only", false, "Parse the input only"); @@ -199,14 +252,23 @@ bool Options::Parse(int argc, const char **argv) panda::PandArg opDumpTransformedAst("dump-transformed-ast", false, "Dump the parsed AST after transform"); panda::PandArg opCheckTransformedAstStructure("check-transformed-ast-structure", false, "Check the AST structure after transform"); - panda::PandArg opRecordSource("record-source", false, "Record all functions' source codes to support the "\ - "using of [function].toString()"); - - // type extractor - panda::PandArg opTypeExtractor("type-extractor", false, "Enable type extractor for typescript"); - panda::PandArg opTypeDtsBuiltin("type-dts-builtin", false, "Enable builtin type extractor for .d.ts file"); + panda::PandArg opRecordDebugSource("record-debug-source", false, "Record source code to support "\ + "multi-platform debugger & detailed backtrace in debug mode"); // compiler + panda::PandArg opEnableAbcInput("enable-abc-input", false, "Allow abc file as input"); + panda::PandArg opDumpAsmProgram("dump-asm-program", false, "Dump program"); + std::string descOfDumpNormalizedProg = + "Dump program in normalized form to ensure the output of source code compilation is consistent with that of " + "abc file compilation.\n" + " The normalized form differs mainly as follows:\n" + " 1. all instructions will be labled consecutively and all the labels will be dumped\n" + " 2. the content of a literal array, rather than its id, will be dumped when the literal array appears in " + "an opcode or is nested in another literal array\n" + " 3. labels stored in catch blocks will be unified\n" + " 4. strings won't be dumped\n" + " 5. invalid opcodes won't be dumped, local variables' start and end offset will skip invalid opcodes"; + panda::PandArg opDumpNormalizedAsmProgram("dump-normalized-asm-program", false, descOfDumpNormalizedProg); panda::PandArg opDumpAssembly("dump-assembly", false, "Dump pandasm"); panda::PandArg opDebugInfo("debug-info", false, "Compile with debug info"); panda::PandArg opDumpDebugInfo("dump-debug-info", false, "Dump debug info"); @@ -214,7 +276,11 @@ bool Options::Parse(int argc, const char **argv) "Compiler optimization level (options: 0 | 1 | 2). In debug and base64Input mode, optimizer is disabled"); panda::PandArg opFunctionThreadCount("function-threads", 0, "Number of worker threads to compile function"); panda::PandArg opFileThreadCount("file-threads", 0, "Number of worker threads to compile file"); + panda::PandArg opAbcClassThreadCount("abc-class-threads", 4, + "Number of worker threads to compile classes of abc file"); panda::PandArg opSizeStat("dump-size-stat", false, "Dump size statistics"); + panda::PandArg opSizePctStat("dump-file-item-size", false, "Dump the size of each kind of file item "\ + "of the abc file"); panda::PandArg opDumpLiteralBuffer("dump-literal-buffer", false, "Dump literal buffer"); panda::PandArg outputFile("output", "", "Compiler binary output (.abc)"); panda::PandArg recordName("record-name", "", "Specify the record name"); @@ -229,6 +295,13 @@ bool Options::Parse(int argc, const char **argv) panda::PandArg opCacheFile("cache-file", "", "cache file for incremental compile"); panda::PandArg opNpmModuleEntryList("npm-module-entry-list", "", "entry list file for module compile"); panda::PandArg opMergeAbc("merge-abc", false, "Compile as merge abc"); + panda::PandArg opuseDefineSemantic("use-define-semantic", false, "Compile ts class fields "\ + "in accordance with ECMAScript2022"); + + // optimizer + panda::PandArg opBranchElimination("branch-elimination", false, "Enable branch elimination optimization"); + panda::PandArg opOptTryCatchFunc("opt-try-catch-func", true, "Enable optimizations for functions with "\ + "try-catch blocks"); // patchfix && hotreload panda::PandArg opDumpSymbolTable("dump-symbol-table", "", "dump symbol table to file"); @@ -236,13 +309,34 @@ bool Options::Parse(int argc, const char **argv) panda::PandArg opGeneratePatch("generate-patch", false, "generate patch abc, default as hotfix mode unless "\ "the cold-fix argument is set"); panda::PandArg opHotReload("hot-reload", false, "compile as hot-reload mode"); + panda::PandArg opColdReload("cold-reload", false, "compile as cold-reload mode"); panda::PandArg opColdFix("cold-fix", false, "generate patch abc as cold-fix mode"); // version - panda::PandArg bcVersion("bc-version", false, "Print ark bytecode version"); + panda::PandArg bcVersion("bc-version", false, "Print ark bytecode version. If both bc-version and"\ + "bc-min-version are enabled, only bc-version will take effects"); panda::PandArg bcMinVersion("bc-min-version", false, "Print ark bytecode minimum supported version"); - panda::PandArg targetApiVersion("target-api-version", 11, "Specify the targeting api version for es2abc to "\ - "generated the corresponding version of bytecode"); + panda::PandArg targetApiVersion("target-api-version", util::Helpers::DEFAULT_TARGET_API_VERSION, + "Specify the targeting api version for es2abc to generated the corresponding version of bytecode"); + panda::PandArg targetBcVersion("target-bc-version", false, "Print the corresponding ark bytecode version"\ + "for target api version. If both target-bc-version and bc-version are enabled, only target-bc-version"\ + "will take effects"); + panda::PandArg targetApiSubVersion("target-api-sub-version", + std::string {util::Helpers::DEFAULT_SUB_API_VERSION}, + "Specify the targeting api sub version for es2abc to generated the corresponding version of bytecode"); + + // compile entries and pkg context info + panda::PandArg compileContextInfoPath("compile-context-info", "", "The path to compile context"\ + "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"); // tail arguments panda::PandArg inputFile("input", "", "input file"); @@ -253,11 +347,12 @@ bool Options::Parse(int argc, const char **argv) argparser_->Add(&opDumpAst); argparser_->Add(&opDumpTransformedAst); argparser_->Add(&opCheckTransformedAstStructure); - argparser_->Add(&opRecordSource); + argparser_->Add(&opRecordDebugSource); argparser_->Add(&opParseOnly); argparser_->Add(&opEnableTypeCheck); - argparser_->Add(&opTypeExtractor); - argparser_->Add(&opTypeDtsBuiltin); + argparser_->Add(&opEnableAbcInput); + argparser_->Add(&opDumpAsmProgram); + argparser_->Add(&opDumpNormalizedAsmProgram); argparser_->Add(&opDumpAssembly); argparser_->Add(&opDebugInfo); argparser_->Add(&opDumpDebugInfo); @@ -268,7 +363,9 @@ bool Options::Parse(int argc, const char **argv) argparser_->Add(&opOptLevel); argparser_->Add(&opFunctionThreadCount); argparser_->Add(&opFileThreadCount); + argparser_->Add(&opAbcClassThreadCount); argparser_->Add(&opSizeStat); + argparser_->Add(&opSizePctStat); argparser_->Add(&opDumpLiteralBuffer); argparser_->Add(&inputExtension); @@ -279,16 +376,29 @@ bool Options::Parse(int argc, const char **argv) argparser_->Add(&opCacheFile); argparser_->Add(&opNpmModuleEntryList); argparser_->Add(&opMergeAbc); + argparser_->Add(&opuseDefineSemantic); + argparser_->Add(&opBranchElimination); + argparser_->Add(&opOptTryCatchFunc); argparser_->Add(&opDumpSymbolTable); argparser_->Add(&opInputSymbolTable); argparser_->Add(&opGeneratePatch); argparser_->Add(&opHotReload); + argparser_->Add(&opColdReload); argparser_->Add(&opColdFix); argparser_->Add(&bcVersion); argparser_->Add(&bcMinVersion); argparser_->Add(&targetApiVersion); + argparser_->Add(&targetBcVersion); + argparser_->Add(&targetApiSubVersion); + + argparser_->Add(&compileContextInfoPath); + argparser_->Add(&opDumpDepsInfo); + argparser_->Add(&opRemoveRedundantFile); + argparser_->Add(&opDumpString); + + argparser_->Add(&transformLib); argparser_->PushBackTail(&inputFile); argparser_->EnableTail(); @@ -296,13 +406,20 @@ bool Options::Parse(int argc, const char **argv) bool parseStatus = argparser_->Parse(argc, argv); + compilerOptions_.targetApiVersion = targetApiVersion.GetValue(); + compilerOptions_.targetApiSubVersion = targetApiSubVersion.GetValue(); + if (parseStatus && targetBcVersion.GetValue()) { + compilerOptions_.targetBcVersion = targetBcVersion.GetValue(); + return true; + } + if (parseStatus && (bcVersion.GetValue() || bcMinVersion.GetValue())) { compilerOptions_.bcVersion = bcVersion.GetValue(); compilerOptions_.bcMinVersion = bcMinVersion.GetValue(); return true; } - if (!parseStatus || opHelp.GetValue()) { + if (!parseStatus || opHelp.GetValue() || (inputFile.GetValue().empty() && base64Input.GetValue().empty())) { std::stringstream ss; ss << argparser_->GetErrorString() << std::endl; @@ -344,20 +461,10 @@ bool Options::Parse(int argc, const char **argv) scriptKind_ = es2panda::parser::ScriptKind::SCRIPT; } - auto parseTypeExtractor = [&opTypeExtractor, &opTypeDtsBuiltin, this]() { - compilerOptions_.typeExtractor = opTypeExtractor.GetValue(); - if (compilerOptions_.typeExtractor) { - compilerOptions_.typeDtsBuiltin = opTypeDtsBuiltin.GetValue(); - DCOUT << "[LOG]TypeExtractor is enabled, type-dts-builtin: " << - compilerOptions_.typeDtsBuiltin << std::endl; - } - }; - parseTypeExtractor(); // Type Extractor is only enabled for TypeScript - std::string extension = inputExtension.GetValue(); if (!extension.empty()) { if (VALID_EXTENSIONS.find(extension) == VALID_EXTENSIONS.end()) { - errorMsg_ = "Invalid extension (available options: js, ts, as)"; + errorMsg_ = "Invalid extension (available options: js, ts, as, abc)"; return false; } } @@ -387,9 +494,9 @@ bool Options::Parse(int argc, const char **argv) compilerOptions_.mergeAbc = opMergeAbc.GetValue(); } - es2panda::SourceFile src("", recordName_, es2panda::parser::ScriptKind::SCRIPT, - GetScriptExtensionFromStr(extension)); - sourceFiles_.push_back(src); + if (opuseDefineSemantic.GetValue()) { + compilerOptions_.useDefineSemantic = opuseDefineSemantic.GetValue(); + } // if (!inputIsEmpty) { // // common mode @@ -429,6 +536,7 @@ bool Options::Parse(int argc, const char **argv) optLevel_ = opOptLevel.GetValue(); functionThreadCount_ = opFunctionThreadCount.GetValue(); fileThreadCount_ = opFileThreadCount.GetValue(); + abcClassThreadCount_ = opAbcClassThreadCount.GetValue(); npmModuleEntryList_ = opNpmModuleEntryList.GetValue(); if (!opCacheFile.GetValue().empty()) { @@ -443,7 +551,14 @@ bool Options::Parse(int argc, const char **argv) options_ |= OptionFlags::SIZE_STAT; } - compilerOptions_.recordSource = opRecordSource.GetValue(); + if (opSizePctStat.GetValue()) { + options_ |= OptionFlags::SIZE_PCT_STAT; + } + + compilerOptions_.recordDebugSource = opRecordDebugSource.GetValue(); + compilerOptions_.enableAbcInput = opEnableAbcInput.GetValue(); + compilerOptions_.dumpAsmProgram = opDumpAsmProgram.GetValue(); + compilerOptions_.dumpNormalizedAsmProgram = opDumpNormalizedAsmProgram.GetValue(); compilerOptions_.dumpAsm = opDumpAssembly.GetValue(); compilerOptions_.dumpAst = opDumpAst.GetValue(); compilerOptions_.dumpTransformedAst = opDumpTransformedAst.GetValue(); @@ -457,19 +572,26 @@ bool Options::Parse(int argc, const char **argv) compilerOptions_.functionThreadCount = functionThreadCount_; compilerOptions_.fileThreadCount = fileThreadCount_; + compilerOptions_.abcClassThreadCount = abcClassThreadCount_; compilerOptions_.output = compilerOutput_; compilerOptions_.debugInfoSourceFile = sourceFile.GetValue(); compilerOptions_.optLevel = (compilerOptions_.isDebug || !base64Input.GetValue().empty() || base64Output.GetValue()) ? 0 : opOptLevel.GetValue(); compilerOptions_.sourceFiles = sourceFiles_; compilerOptions_.mergeAbc = opMergeAbc.GetValue(); - compilerOptions_.targetApiVersion = targetApiVersion.GetValue(); + compilerOptions_.compileContextInfoPath = 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(); bool generatePatch = opGeneratePatch.GetValue(); bool hotReload = opHotReload.GetValue(); + bool coldReload = opColdReload.GetValue(); bool coldFix = opColdFix.GetValue(); if (generatePatch && hotReload) { errorMsg_ = "--generate-patch and --hot-reload can not be used simultaneously"; @@ -481,8 +603,43 @@ bool Options::Parse(int argc, const char **argv) } compilerOptions_.patchFixOptions.generatePatch = generatePatch; compilerOptions_.patchFixOptions.hotReload = hotReload; + compilerOptions_.patchFixOptions.coldReload = coldReload; compilerOptions_.patchFixOptions.coldFix = coldFix; - + + bool transformLibIsEmpty = transformLib.GetValue().empty(); + if (!transformLibIsEmpty) { + auto libName = transformLib.GetValue(); + // check file exist or not + auto transformLibAbs = panda::os::file::File::GetAbsolutePath(libName); + if (!transformLibAbs) { + std::cerr << "Failed to find file '" << libName << "' during transformLib file resolution" << std::endl + << "Please check if the file name is correct, the file exists at the specified path, " + << "and your project has the necessary permissions to access it." << std::endl; + return false; + } + compilerOptions_.transformLib = transformLibAbs.Value(); + } + + compilerOptions_.branchElimination = opBranchElimination.GetValue(); + compilerOptions_.requireGlobalOptimization = compilerOptions_.optLevel > 0 && + compilerOptions_.branchElimination && + compilerOptions_.mergeAbc; + panda::compiler::options.SetCompilerBranchElimination(compilerOptions_.branchElimination); + panda::bytecodeopt::options.SetSkipMethodsWithEh(!opOptTryCatchFunc.GetValue()); + return true; } + +std::string Options::ExtractContentFromBase64Input(const std::string &inputBase64String) +{ + std::string inputContent = util::Base64Decode(inputBase64String); + if (inputContent == "") { + return ""; + } + bool validBase64Input = util::Base64Encode(inputContent) == inputBase64String; + if (!validBase64Input) { + return ""; + } + return inputContent; +} } // namespace panda::es2panda::aot diff --git a/arkfuzzilli/frontend/options.h b/arkfuzzilli/frontend/options.h index 00a2b7c..33fad0b 100644 --- a/arkfuzzilli/frontend/options.h +++ b/arkfuzzilli/frontend/options.h @@ -31,10 +31,11 @@ class PandaArg; } // namespace panda namespace panda::es2panda::aot { -enum class OptionFlags { +enum class OptionFlags : uint8_t { DEFAULT = 0, PARSE_ONLY = 1 << 1, SIZE_STAT = 1 << 2, + SIZE_PCT_STAT = 1 << 3, }; inline std::underlying_type_t operator&(OptionFlags a, OptionFlags b) @@ -110,6 +111,11 @@ public: return (options_ & OptionFlags::SIZE_STAT) != 0; } + bool SizePctStat() const + { + return (options_ & OptionFlags::SIZE_PCT_STAT) != 0; + } + std::string ExtractContentFromBase64Input(const std::string &inputBase64String); const std::string &compilerProtoOutput() const @@ -133,6 +139,11 @@ public: private: es2panda::CompilerOptions compilerOptions_ {}; + void CollectInputAbcFile(const std::string &fileName, const std::string &inputExtension); + void CollectInputSourceFile(const std::vector &itemList, const std::string &inputExtension); + bool CheckFilesValidity(const std::string &input, const std::vector &itemList, + const std::string &line); + bool IsAbcFile(const std::string &fileName, const std::string &inputExtension); es2panda::parser::ScriptKind scriptKind_ {es2panda::parser::ScriptKind::SCRIPT}; OptionFlags options_ {OptionFlags::DEFAULT}; panda::PandArgParser *argparser_; @@ -146,6 +157,7 @@ private: int optLevel_ {0}; int functionThreadCount_ {0}; int fileThreadCount_ {0}; + int abcClassThreadCount_ {0}; std::string npmModuleEntryList_; std::vector sourceFiles_; std::unordered_map outputFiles_; -- Gitee From dcf69fad1cc387b6c2e5a2d8200c3916c9529a17 Mon Sep 17 00:00:00 2001 From: jiangkaiwen Date: Wed, 21 Aug 2024 08:16:19 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=E5=9B=9E=E9=80=80=20'Pull=20Request=20!11?= =?UTF-8?q?=20:=20Update=20options=20code'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- arkfuzzilli/frontend/options.cpp | 275 +++++++------------------------ arkfuzzilli/frontend/options.h | 14 +- 2 files changed, 60 insertions(+), 229 deletions(-) diff --git a/arkfuzzilli/frontend/options.cpp b/arkfuzzilli/frontend/options.cpp index 4e4f900..a375609 100644 --- a/arkfuzzilli/frontend/options.cpp +++ b/arkfuzzilli/frontend/options.cpp @@ -26,8 +26,6 @@ #include #endif -#include "bytecode_optimizer/bytecodeopt_options.h" -#include "compiler_options.h" #include "os/file.h" #include "mergeProgram.h" @@ -36,12 +34,8 @@ namespace panda::es2panda::aot { constexpr char PROCESS_AS_LIST_MARK = '@'; -// item list: [filePath; recordName; moduleKind; sourceFile; pkgName; isSharedModule] -constexpr size_t ITEM_COUNT_MERGE = 6; -// item list: [filePath; recordName; moduleKind; sourceFile; outputfile; isSharedModule] -constexpr size_t ITEM_COUNT_NOT_MERGE = 6; const std::string LIST_ITEM_SEPERATOR = ";"; -const std::set VALID_EXTENSIONS = { "js", "ts", "as", "abc" }; +const std::set VALID_EXTENSIONS = { "js", "ts", "as" }; template T RemoveExtension(T const &filename) @@ -58,8 +52,6 @@ static es2panda::ScriptExtension GetScriptExtensionFromStr(const std::string &ex return es2panda::ScriptExtension::TS; } else if (extension == "as") { return es2panda::ScriptExtension::AS; - } else if (extension == "abc") { - return es2panda::ScriptExtension::ABC; } else { return es2panda::ScriptExtension::JS; } @@ -98,68 +90,6 @@ static std::vector GetStringItems(std::string &input, const std::st return items; } -void Options::CollectInputAbcFile(const std::string &fileName, const std::string &inputExtension) -{ - es2panda::SourceFile src(fileName, "", parser::ScriptKind::SCRIPT, GetScriptExtension(fileName, - inputExtension)); - src.isSourceMode = false; - sourceFiles_.push_back(src); -} - -void Options::CollectInputSourceFile(const std::vector &itemList, const std::string &inputExtension) -{ - std::string fileName = itemList[0]; - std::string recordName = compilerOptions_.mergeAbc ? itemList[1] : ""; - constexpr uint32_t SCRIPT_KIND_IDX = 2; - constexpr uint32_t SOURCE_FIEL_IDX = 3; - constexpr uint32_t PKG_NAME_IDX = 4; - constexpr uint32_t Is_SHARED_MODULE_IDX = 5; - parser::ScriptKind scriptKind; - if (itemList[SCRIPT_KIND_IDX] == "script") { - scriptKind = parser::ScriptKind::SCRIPT; - } else if (itemList[SCRIPT_KIND_IDX] == "commonjs") { - scriptKind = parser::ScriptKind::COMMONJS; - } else { - scriptKind = parser::ScriptKind::MODULE; - } - - es2panda::SourceFile src(fileName, recordName, scriptKind, GetScriptExtension(fileName, inputExtension)); - src.sourcefile = itemList[SOURCE_FIEL_IDX]; - if (compilerOptions_.mergeAbc) { - src.pkgName = itemList[PKG_NAME_IDX]; - } - - if (itemList.size() == ITEM_COUNT_MERGE) { - src.isSharedModule = itemList[Is_SHARED_MODULE_IDX] == "true"; - } - - sourceFiles_.push_back(src); - if (!compilerOptions_.mergeAbc) { - outputFiles_.insert({fileName, itemList[PKG_NAME_IDX]}); - } -} - -bool Options::CheckFilesValidity(const std::string &input, const std::vector &itemList, - const std::string &line) -{ - // For compatibility, only throw error when item list's size is bigger than given size. - if ((compilerOptions_.mergeAbc && itemList.size() > ITEM_COUNT_MERGE) || - (!compilerOptions_.mergeAbc && itemList.size() > ITEM_COUNT_NOT_MERGE) || itemList.empty()) { - std::cerr << "Failed to parse line " << line << " of the input file: '" - << input << "'." << std::endl - << "Expected " << (compilerOptions_.mergeAbc ? ITEM_COUNT_MERGE : ITEM_COUNT_NOT_MERGE) - << " items per line, but found " << itemList.size() << " items." << std::endl - << "Please check the file format and content for correctness." << std::endl; - return false; - } - return true; -} - -bool Options::IsAbcFile(const std::string &fileName, const std::string &inputExtension) -{ - return (GetScriptExtension(fileName, inputExtension) == es2panda::ScriptExtension::ABC); -} - // Options bool Options::CollectInputFilesFromFileList(const std::string &input, const std::string &inputExtension) { @@ -167,21 +97,40 @@ bool Options::CollectInputFilesFromFileList(const std::string &input, const std: std::string line; ifs.open(panda::os::file::File::GetExtendedFilePath(input)); if (!ifs.is_open()) { - std::cerr << "Failed to open source list file '" << input << "' during input file collection." << std::endl - << "Please check if the file exists or the path is correct, " - << "and you have the necessary permissions to access it." << std::endl; + std::cerr << "Failed to open source list: " << input << std::endl; return false; } + 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)) { std::vector itemList = GetStringItems(line, LIST_ITEM_SEPERATOR); - if (!CheckFilesValidity(input, itemList, line)) { + if ((compilerOptions_.mergeAbc && itemList.size() != ITEM_COUNT_MERGE) || + (!compilerOptions_.mergeAbc && itemList.size() != ITEM_COUNT_NOT_MERGE)) { + std::cerr << "Failed to parse input file" << std::endl; return false; } - if (IsAbcFile(itemList[0], inputExtension)) { - CollectInputAbcFile(itemList[0], inputExtension); + + std::string fileName = itemList[0]; + std::string recordName = compilerOptions_.mergeAbc ? itemList[1] : ""; + parser::ScriptKind scriptKind; + if (itemList[2] == "script") { + scriptKind = parser::ScriptKind::SCRIPT; + } else if (itemList[2] == "commonjs") { + scriptKind = parser::ScriptKind::COMMONJS; } else { - CollectInputSourceFile(itemList, inputExtension); + scriptKind = parser::ScriptKind::MODULE; + } + + es2panda::SourceFile src(fileName, recordName, scriptKind, GetScriptExtension(fileName, inputExtension)); + src.sourcefile = itemList[3]; + if (compilerOptions_.mergeAbc) { + src.pkgName = itemList[4]; + } + + sourceFiles_.push_back(src); + if (!compilerOptions_.mergeAbc) { + outputFiles_.insert({fileName, itemList[4]}); } } return true; @@ -214,9 +163,7 @@ void Options::ParseCacheFileOption(const std::string &cacheInput) std::string line; ifs.open(panda::os::file::File::GetExtendedFilePath(cacheInput.substr(1))); if (!ifs.is_open()) { - std::cerr << "Failed to open cache file list from the provided path: '" << cacheInput << "'." << std::endl - << "Please check if the file exists or the path is correct, " - << "and you have the necessary permissions to read the file." << std::endl; + std::cerr << "Failed to open cache file list: " << cacheInput << std::endl; return; } @@ -243,7 +190,7 @@ bool Options::Parse(int argc, const char **argv) // parser panda::PandArg inputExtension("extension", "js", - "Parse the input as the given extension (options: js | ts | as | abc)"); + "Parse the input as the given extension (options: js | ts | as)"); panda::PandArg opModule("module", false, "Parse the input as module"); panda::PandArg opCommonjs("commonjs", false, "Parse the input as commonjs"); panda::PandArg opParseOnly("parse-only", false, "Parse the input only"); @@ -252,23 +199,14 @@ bool Options::Parse(int argc, const char **argv) panda::PandArg opDumpTransformedAst("dump-transformed-ast", false, "Dump the parsed AST after transform"); panda::PandArg opCheckTransformedAstStructure("check-transformed-ast-structure", false, "Check the AST structure after transform"); - panda::PandArg opRecordDebugSource("record-debug-source", false, "Record source code to support "\ - "multi-platform debugger & detailed backtrace in debug mode"); + panda::PandArg opRecordSource("record-source", false, "Record all functions' source codes to support the "\ + "using of [function].toString()"); + + // type extractor + panda::PandArg opTypeExtractor("type-extractor", false, "Enable type extractor for typescript"); + panda::PandArg opTypeDtsBuiltin("type-dts-builtin", false, "Enable builtin type extractor for .d.ts file"); // compiler - panda::PandArg opEnableAbcInput("enable-abc-input", false, "Allow abc file as input"); - panda::PandArg opDumpAsmProgram("dump-asm-program", false, "Dump program"); - std::string descOfDumpNormalizedProg = - "Dump program in normalized form to ensure the output of source code compilation is consistent with that of " - "abc file compilation.\n" - " The normalized form differs mainly as follows:\n" - " 1. all instructions will be labled consecutively and all the labels will be dumped\n" - " 2. the content of a literal array, rather than its id, will be dumped when the literal array appears in " - "an opcode or is nested in another literal array\n" - " 3. labels stored in catch blocks will be unified\n" - " 4. strings won't be dumped\n" - " 5. invalid opcodes won't be dumped, local variables' start and end offset will skip invalid opcodes"; - panda::PandArg opDumpNormalizedAsmProgram("dump-normalized-asm-program", false, descOfDumpNormalizedProg); panda::PandArg opDumpAssembly("dump-assembly", false, "Dump pandasm"); panda::PandArg opDebugInfo("debug-info", false, "Compile with debug info"); panda::PandArg opDumpDebugInfo("dump-debug-info", false, "Dump debug info"); @@ -276,11 +214,7 @@ bool Options::Parse(int argc, const char **argv) "Compiler optimization level (options: 0 | 1 | 2). In debug and base64Input mode, optimizer is disabled"); panda::PandArg opFunctionThreadCount("function-threads", 0, "Number of worker threads to compile function"); panda::PandArg opFileThreadCount("file-threads", 0, "Number of worker threads to compile file"); - panda::PandArg opAbcClassThreadCount("abc-class-threads", 4, - "Number of worker threads to compile classes of abc file"); panda::PandArg opSizeStat("dump-size-stat", false, "Dump size statistics"); - panda::PandArg opSizePctStat("dump-file-item-size", false, "Dump the size of each kind of file item "\ - "of the abc file"); panda::PandArg opDumpLiteralBuffer("dump-literal-buffer", false, "Dump literal buffer"); panda::PandArg outputFile("output", "", "Compiler binary output (.abc)"); panda::PandArg recordName("record-name", "", "Specify the record name"); @@ -295,13 +229,6 @@ bool Options::Parse(int argc, const char **argv) panda::PandArg opCacheFile("cache-file", "", "cache file for incremental compile"); panda::PandArg opNpmModuleEntryList("npm-module-entry-list", "", "entry list file for module compile"); panda::PandArg opMergeAbc("merge-abc", false, "Compile as merge abc"); - panda::PandArg opuseDefineSemantic("use-define-semantic", false, "Compile ts class fields "\ - "in accordance with ECMAScript2022"); - - // optimizer - panda::PandArg opBranchElimination("branch-elimination", false, "Enable branch elimination optimization"); - panda::PandArg opOptTryCatchFunc("opt-try-catch-func", true, "Enable optimizations for functions with "\ - "try-catch blocks"); // patchfix && hotreload panda::PandArg opDumpSymbolTable("dump-symbol-table", "", "dump symbol table to file"); @@ -309,34 +236,13 @@ bool Options::Parse(int argc, const char **argv) panda::PandArg opGeneratePatch("generate-patch", false, "generate patch abc, default as hotfix mode unless "\ "the cold-fix argument is set"); panda::PandArg opHotReload("hot-reload", false, "compile as hot-reload mode"); - panda::PandArg opColdReload("cold-reload", false, "compile as cold-reload mode"); panda::PandArg opColdFix("cold-fix", false, "generate patch abc as cold-fix mode"); // version - panda::PandArg bcVersion("bc-version", false, "Print ark bytecode version. If both bc-version and"\ - "bc-min-version are enabled, only bc-version will take effects"); + panda::PandArg bcVersion("bc-version", false, "Print ark bytecode version"); panda::PandArg bcMinVersion("bc-min-version", false, "Print ark bytecode minimum supported version"); - panda::PandArg targetApiVersion("target-api-version", util::Helpers::DEFAULT_TARGET_API_VERSION, - "Specify the targeting api version for es2abc to generated the corresponding version of bytecode"); - panda::PandArg targetBcVersion("target-bc-version", false, "Print the corresponding ark bytecode version"\ - "for target api version. If both target-bc-version and bc-version are enabled, only target-bc-version"\ - "will take effects"); - panda::PandArg targetApiSubVersion("target-api-sub-version", - std::string {util::Helpers::DEFAULT_SUB_API_VERSION}, - "Specify the targeting api sub version for es2abc to generated the corresponding version of bytecode"); - - // compile entries and pkg context info - panda::PandArg compileContextInfoPath("compile-context-info", "", "The path to compile context"\ - "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"); + panda::PandArg targetApiVersion("target-api-version", 11, "Specify the targeting api version for es2abc to "\ + "generated the corresponding version of bytecode"); // tail arguments panda::PandArg inputFile("input", "", "input file"); @@ -347,12 +253,11 @@ bool Options::Parse(int argc, const char **argv) argparser_->Add(&opDumpAst); argparser_->Add(&opDumpTransformedAst); argparser_->Add(&opCheckTransformedAstStructure); - argparser_->Add(&opRecordDebugSource); + argparser_->Add(&opRecordSource); argparser_->Add(&opParseOnly); argparser_->Add(&opEnableTypeCheck); - argparser_->Add(&opEnableAbcInput); - argparser_->Add(&opDumpAsmProgram); - argparser_->Add(&opDumpNormalizedAsmProgram); + argparser_->Add(&opTypeExtractor); + argparser_->Add(&opTypeDtsBuiltin); argparser_->Add(&opDumpAssembly); argparser_->Add(&opDebugInfo); argparser_->Add(&opDumpDebugInfo); @@ -363,9 +268,7 @@ bool Options::Parse(int argc, const char **argv) argparser_->Add(&opOptLevel); argparser_->Add(&opFunctionThreadCount); argparser_->Add(&opFileThreadCount); - argparser_->Add(&opAbcClassThreadCount); argparser_->Add(&opSizeStat); - argparser_->Add(&opSizePctStat); argparser_->Add(&opDumpLiteralBuffer); argparser_->Add(&inputExtension); @@ -376,29 +279,16 @@ bool Options::Parse(int argc, const char **argv) argparser_->Add(&opCacheFile); argparser_->Add(&opNpmModuleEntryList); argparser_->Add(&opMergeAbc); - argparser_->Add(&opuseDefineSemantic); - argparser_->Add(&opBranchElimination); - argparser_->Add(&opOptTryCatchFunc); argparser_->Add(&opDumpSymbolTable); argparser_->Add(&opInputSymbolTable); argparser_->Add(&opGeneratePatch); argparser_->Add(&opHotReload); - argparser_->Add(&opColdReload); argparser_->Add(&opColdFix); argparser_->Add(&bcVersion); argparser_->Add(&bcMinVersion); argparser_->Add(&targetApiVersion); - argparser_->Add(&targetBcVersion); - argparser_->Add(&targetApiSubVersion); - - argparser_->Add(&compileContextInfoPath); - argparser_->Add(&opDumpDepsInfo); - argparser_->Add(&opRemoveRedundantFile); - argparser_->Add(&opDumpString); - - argparser_->Add(&transformLib); argparser_->PushBackTail(&inputFile); argparser_->EnableTail(); @@ -406,20 +296,13 @@ bool Options::Parse(int argc, const char **argv) bool parseStatus = argparser_->Parse(argc, argv); - compilerOptions_.targetApiVersion = targetApiVersion.GetValue(); - compilerOptions_.targetApiSubVersion = targetApiSubVersion.GetValue(); - if (parseStatus && targetBcVersion.GetValue()) { - compilerOptions_.targetBcVersion = targetBcVersion.GetValue(); - return true; - } - if (parseStatus && (bcVersion.GetValue() || bcMinVersion.GetValue())) { compilerOptions_.bcVersion = bcVersion.GetValue(); compilerOptions_.bcMinVersion = bcMinVersion.GetValue(); return true; } - if (!parseStatus || opHelp.GetValue() || (inputFile.GetValue().empty() && base64Input.GetValue().empty())) { + if (!parseStatus || opHelp.GetValue()) { std::stringstream ss; ss << argparser_->GetErrorString() << std::endl; @@ -461,10 +344,20 @@ bool Options::Parse(int argc, const char **argv) scriptKind_ = es2panda::parser::ScriptKind::SCRIPT; } + auto parseTypeExtractor = [&opTypeExtractor, &opTypeDtsBuiltin, this]() { + compilerOptions_.typeExtractor = opTypeExtractor.GetValue(); + if (compilerOptions_.typeExtractor) { + compilerOptions_.typeDtsBuiltin = opTypeDtsBuiltin.GetValue(); + DCOUT << "[LOG]TypeExtractor is enabled, type-dts-builtin: " << + compilerOptions_.typeDtsBuiltin << std::endl; + } + }; + parseTypeExtractor(); // Type Extractor is only enabled for TypeScript + std::string extension = inputExtension.GetValue(); if (!extension.empty()) { if (VALID_EXTENSIONS.find(extension) == VALID_EXTENSIONS.end()) { - errorMsg_ = "Invalid extension (available options: js, ts, as, abc)"; + errorMsg_ = "Invalid extension (available options: js, ts, as)"; return false; } } @@ -494,9 +387,9 @@ bool Options::Parse(int argc, const char **argv) compilerOptions_.mergeAbc = opMergeAbc.GetValue(); } - if (opuseDefineSemantic.GetValue()) { - compilerOptions_.useDefineSemantic = opuseDefineSemantic.GetValue(); - } + es2panda::SourceFile src("", recordName_, es2panda::parser::ScriptKind::SCRIPT, + GetScriptExtensionFromStr(extension)); + sourceFiles_.push_back(src); // if (!inputIsEmpty) { // // common mode @@ -536,7 +429,6 @@ bool Options::Parse(int argc, const char **argv) optLevel_ = opOptLevel.GetValue(); functionThreadCount_ = opFunctionThreadCount.GetValue(); fileThreadCount_ = opFileThreadCount.GetValue(); - abcClassThreadCount_ = opAbcClassThreadCount.GetValue(); npmModuleEntryList_ = opNpmModuleEntryList.GetValue(); if (!opCacheFile.GetValue().empty()) { @@ -551,14 +443,7 @@ bool Options::Parse(int argc, const char **argv) options_ |= OptionFlags::SIZE_STAT; } - if (opSizePctStat.GetValue()) { - options_ |= OptionFlags::SIZE_PCT_STAT; - } - - compilerOptions_.recordDebugSource = opRecordDebugSource.GetValue(); - compilerOptions_.enableAbcInput = opEnableAbcInput.GetValue(); - compilerOptions_.dumpAsmProgram = opDumpAsmProgram.GetValue(); - compilerOptions_.dumpNormalizedAsmProgram = opDumpNormalizedAsmProgram.GetValue(); + compilerOptions_.recordSource = opRecordSource.GetValue(); compilerOptions_.dumpAsm = opDumpAssembly.GetValue(); compilerOptions_.dumpAst = opDumpAst.GetValue(); compilerOptions_.dumpTransformedAst = opDumpTransformedAst.GetValue(); @@ -572,26 +457,19 @@ bool Options::Parse(int argc, const char **argv) compilerOptions_.functionThreadCount = functionThreadCount_; compilerOptions_.fileThreadCount = fileThreadCount_; - compilerOptions_.abcClassThreadCount = abcClassThreadCount_; compilerOptions_.output = compilerOutput_; compilerOptions_.debugInfoSourceFile = sourceFile.GetValue(); compilerOptions_.optLevel = (compilerOptions_.isDebug || !base64Input.GetValue().empty() || base64Output.GetValue()) ? 0 : opOptLevel.GetValue(); compilerOptions_.sourceFiles = sourceFiles_; compilerOptions_.mergeAbc = opMergeAbc.GetValue(); - compilerOptions_.compileContextInfoPath = compileContextInfoPath.GetValue(); - compilerOptions_.dumpDepsInfo = opDumpDepsInfo.GetValue(); - compilerOptions_.updatePkgVersionForAbcInput = compilerOptions_.enableAbcInput - && !compilerOptions_.compileContextInfo.pkgContextInfo.empty(); - compilerOptions_.removeRedundantFile = opRemoveRedundantFile.GetValue(); - compilerOptions_.dumpString = opDumpString.GetValue(); + compilerOptions_.targetApiVersion = targetApiVersion.GetValue(); compilerOptions_.patchFixOptions.dumpSymbolTable = opDumpSymbolTable.GetValue(); compilerOptions_.patchFixOptions.symbolTable = opInputSymbolTable.GetValue(); bool generatePatch = opGeneratePatch.GetValue(); bool hotReload = opHotReload.GetValue(); - bool coldReload = opColdReload.GetValue(); bool coldFix = opColdFix.GetValue(); if (generatePatch && hotReload) { errorMsg_ = "--generate-patch and --hot-reload can not be used simultaneously"; @@ -603,43 +481,8 @@ bool Options::Parse(int argc, const char **argv) } compilerOptions_.patchFixOptions.generatePatch = generatePatch; compilerOptions_.patchFixOptions.hotReload = hotReload; - compilerOptions_.patchFixOptions.coldReload = coldReload; compilerOptions_.patchFixOptions.coldFix = coldFix; - - bool transformLibIsEmpty = transformLib.GetValue().empty(); - if (!transformLibIsEmpty) { - auto libName = transformLib.GetValue(); - // check file exist or not - auto transformLibAbs = panda::os::file::File::GetAbsolutePath(libName); - if (!transformLibAbs) { - std::cerr << "Failed to find file '" << libName << "' during transformLib file resolution" << std::endl - << "Please check if the file name is correct, the file exists at the specified path, " - << "and your project has the necessary permissions to access it." << std::endl; - return false; - } - compilerOptions_.transformLib = transformLibAbs.Value(); - } - - compilerOptions_.branchElimination = opBranchElimination.GetValue(); - compilerOptions_.requireGlobalOptimization = compilerOptions_.optLevel > 0 && - compilerOptions_.branchElimination && - compilerOptions_.mergeAbc; - panda::compiler::options.SetCompilerBranchElimination(compilerOptions_.branchElimination); - panda::bytecodeopt::options.SetSkipMethodsWithEh(!opOptTryCatchFunc.GetValue()); - + return true; } - -std::string Options::ExtractContentFromBase64Input(const std::string &inputBase64String) -{ - std::string inputContent = util::Base64Decode(inputBase64String); - if (inputContent == "") { - return ""; - } - bool validBase64Input = util::Base64Encode(inputContent) == inputBase64String; - if (!validBase64Input) { - return ""; - } - return inputContent; -} } // namespace panda::es2panda::aot diff --git a/arkfuzzilli/frontend/options.h b/arkfuzzilli/frontend/options.h index 33fad0b..00a2b7c 100644 --- a/arkfuzzilli/frontend/options.h +++ b/arkfuzzilli/frontend/options.h @@ -31,11 +31,10 @@ class PandaArg; } // namespace panda namespace panda::es2panda::aot { -enum class OptionFlags : uint8_t { +enum class OptionFlags { DEFAULT = 0, PARSE_ONLY = 1 << 1, SIZE_STAT = 1 << 2, - SIZE_PCT_STAT = 1 << 3, }; inline std::underlying_type_t operator&(OptionFlags a, OptionFlags b) @@ -111,11 +110,6 @@ public: return (options_ & OptionFlags::SIZE_STAT) != 0; } - bool SizePctStat() const - { - return (options_ & OptionFlags::SIZE_PCT_STAT) != 0; - } - std::string ExtractContentFromBase64Input(const std::string &inputBase64String); const std::string &compilerProtoOutput() const @@ -139,11 +133,6 @@ public: private: es2panda::CompilerOptions compilerOptions_ {}; - void CollectInputAbcFile(const std::string &fileName, const std::string &inputExtension); - void CollectInputSourceFile(const std::vector &itemList, const std::string &inputExtension); - bool CheckFilesValidity(const std::string &input, const std::vector &itemList, - const std::string &line); - bool IsAbcFile(const std::string &fileName, const std::string &inputExtension); es2panda::parser::ScriptKind scriptKind_ {es2panda::parser::ScriptKind::SCRIPT}; OptionFlags options_ {OptionFlags::DEFAULT}; panda::PandArgParser *argparser_; @@ -157,7 +146,6 @@ private: int optLevel_ {0}; int functionThreadCount_ {0}; int fileThreadCount_ {0}; - int abcClassThreadCount_ {0}; std::string npmModuleEntryList_; std::vector sourceFiles_; std::unordered_map outputFiles_; -- Gitee From 204a5cb445a72672f658bf3ab3ec0c92a795eca9 Mon Sep 17 00:00:00 2001 From: zhangyouyou Date: Fri, 13 Sep 2024 15:11:15 +0800 Subject: [PATCH 3/3] update runtime.diff Signed-off-by: zhangyouyou --- patch/ets_runtime.diff | 194 +++++++++++++++++++++++++++++++++-------- 1 file changed, 156 insertions(+), 38 deletions(-) diff --git a/patch/ets_runtime.diff b/patch/ets_runtime.diff index fe4e1b7..f53265d 100644 --- a/patch/ets_runtime.diff +++ b/patch/ets_runtime.diff @@ -1,8 +1,8 @@ diff --git a/BUILD.gn b/BUILD.gn -index 95cb26c32..981af9770 100644 +index 130f36f95..a2267684a 100644 --- a/BUILD.gn +++ b/BUILD.gn -@@ -1021,6 +1021,91 @@ libark_jsruntime_common_set("libark_jsruntime_arm_set") { +@@ -1133,6 +1133,91 @@ libark_jsruntime_common_set("libark_jsruntime_arm_set") { } } @@ -94,20 +94,27 @@ index 95cb26c32..981af9770 100644 libark_jsruntime_intl_common_set("libark_js_intl_set") { } -@@ -1135,7 +1220,7 @@ ohos_source_set("libark_jsruntime_static") { - - deps = [ - ":libark_js_intl_arm_set", -- ":libark_jsruntime_arm_set", -+ ":libark_jsruntime_set_cov" - ] +@@ -1250,13 +1335,13 @@ ohos_source_set("libark_jsruntime_static") { + if (is_ohos && is_standard_system) { + deps = [ + ":libark_js_intl_arm_set", +- ":libark_jsruntime_arm_set", ++ ":libark_jsruntime_set_cov", + ] + } else { + # in this case libark_jsruntime_arm_set and libark_jsruntime_set are identical + deps = [ + ":libark_js_intl_set", +- ":libark_jsruntime_set", ++ ":libark_jsruntime_set_cov", + ] + } external_deps = [] - if (!is_arkui_x) { diff --git a/ecmascript/ecma_context.cpp b/ecmascript/ecma_context.cpp -index b00cfe81a..f89ca208d 100644 +index 63cc7552b..b9e6981ca 100644 --- a/ecmascript/ecma_context.cpp +++ b/ecmascript/ecma_context.cpp -@@ -375,10 +375,10 @@ Expected EcmaContext::InvokeEcmaEntrypointForHotReload( +@@ -427,10 +427,10 @@ Expected EcmaContext::InvokeEcmaEntrypointForHotReload( AddPatchModule(recordName, moduleRecordHandle); // print exception information @@ -123,10 +130,10 @@ index b00cfe81a..f89ca208d 100644 } diff --git a/ecmascript/js_arraybuffer.cpp b/ecmascript/js_arraybuffer.cpp -index 178d0e14a..018bcd374 100644 +index 8e6c55a10..7a7007e58 100644 --- a/ecmascript/js_arraybuffer.cpp +++ b/ecmascript/js_arraybuffer.cpp -@@ -46,7 +46,7 @@ void JSArrayBuffer::CopyDataPointBytes(void *toBuf, void *fromBuf, int32_t fromI +@@ -41,7 +41,7 @@ void JSArrayBuffer::CopyDataPointBytes(void *toBuf, void *fromBuf, int32_t fromI void JSArrayBuffer::Attach(JSThread *thread, uint32_t arrayBufferByteLength, JSTaggedValue arrayBufferData, bool transferWithNativeAreaAllocator) { @@ -135,7 +142,7 @@ index 178d0e14a..018bcd374 100644 // only in transition, should the JSArrayBuffer with NativeAreaAllocator increase mem usage if (transferWithNativeAreaAllocator) { LOG_FULL(DEBUG) << "attaching for transfer"; -@@ -78,4 +78,4 @@ void JSArrayBuffer::Detach(JSThread *thread, bool transferWithNativeAreaAllocato +@@ -76,4 +76,4 @@ void JSArrayBuffer::Detach(JSThread *thread, bool transferWithNativeAreaAllocato SetArrayBufferData(thread, JSTaggedValue::Null()); SetArrayBufferByteLength(0); } @@ -143,7 +150,7 @@ index 178d0e14a..018bcd374 100644 \ No newline at end of file +} // namespace panda::ecmascript diff --git a/ecmascript/js_native_pointer.h b/ecmascript/js_native_pointer.h -index ce0981f6f..136d09ba3 100644 +index 8157917d4..be94c8c99 100644 --- a/ecmascript/js_native_pointer.h +++ b/ecmascript/js_native_pointer.h @@ -28,7 +28,7 @@ class JSNativePointer : public TaggedObject { @@ -156,49 +163,145 @@ index ce0981f6f..136d09ba3 100644 } diff --git a/ecmascript/js_thread.cpp b/ecmascript/js_thread.cpp -index 6c66de8f1..056bb1cf9 100644 +index d2ecab7c9..397dce0c9 100644 --- a/ecmascript/js_thread.cpp +++ b/ecmascript/js_thread.cpp -@@ -561,12 +561,14 @@ bool JSThread::CheckSafepoint() +@@ -794,12 +794,15 @@ bool JSThread::CheckSafepoint() } #endif // ECMASCRIPT_SUPPORT_CPUPROFILER bool gcTriggered = false; +/* #ifndef NDEBUG - if (vm_->GetJSOptions().EnableForceGC()) { +- if (vm_->GetJSOptions().EnableForceGC()) { ++ ++#endif ++*/ ++if (vm_->GetJSOptions().EnableForceGC()) { GetEcmaVM()->CollectGarbage(TriggerGCType::FULL_GC); gcTriggered = true; } - #endif -+*/ +-#endif auto heap = const_cast(GetEcmaVM()->GetHeap()); // Handle exit app senstive scene heap->HandleExitHighSensitiveEvent(); -diff --git a/ecmascript/mem/machine_code.cpp b/ecmascript/mem/machine_code.cpp -index 2b88f7449..a47415fc5 100644 ---- a/ecmascript/mem/machine_code.cpp -+++ b/ecmascript/mem/machine_code.cpp -@@ -18,6 +18,7 @@ - #include "ecmascript/compiler/aot_file/func_entry_des.h" - #include "ecmascript/stackmap/ark_stackmap.h" - #include "ecmascript/js_handle.h" -+#include "ecmascript/js_tagged_value-inl.h" +@@ -1318,7 +1321,7 @@ void JSThread::PostFork() + ASSERT(GetState() == ThreadState::NATIVE); + } + } +-#ifndef NDEBUG ++// #ifndef NDEBUG + bool JSThread::IsInManagedState() const + { + ASSERT(this == JSThread::GetCurrent()); +@@ -1334,5 +1337,5 @@ void JSThread::SetMutatorLockState(MutatorLock::MutatorLockState newState) + { + mutatorLockState_ = newState; + } +-#endif ++// #endif + } // namespace panda::ecmascript +diff --git a/ecmascript/js_thread.h b/ecmascript/js_thread.h +index c45a5f266..21a3d4566 100644 +--- a/ecmascript/js_thread.h ++++ b/ecmascript/js_thread.h +@@ -1356,11 +1356,9 @@ public: + static bool IsMainThread(); + PUBLIC_API void ManagedCodeBegin(); + PUBLIC_API void ManagedCodeEnd(); +-#ifndef NDEBUG + bool IsInManagedState() const; + MutatorLock::MutatorLockState GetMutatorLockState() const; + void SetMutatorLockState(MutatorLock::MutatorLockState newState); +-#endif + void SetWeakFinalizeTaskCallback(const WeakFinalizeTaskCallback &callback) + { + finalizeTaskCallback_ = callback; +@@ -1461,7 +1459,7 @@ public: + + + +-#ifndef NDEBUG ++ + inline void LaunchSuspendAll() + { + launchedSuspendAll_ = true; +@@ -1476,7 +1474,7 @@ public: + { + launchedSuspendAll_ = false; + } +-#endif ++ + + protected: + void SetThreadId() +@@ -1606,10 +1604,10 @@ private: + + uint64_t jobId_ {0}; + +-#ifndef NDEBUG ++ + MutatorLock::MutatorLockState mutatorLockState_ = MutatorLock::MutatorLockState::UNLOCKED; + std::atomic launchedSuspendAll_ {false}; +-#endif ++ + // Collect a map from JsError to MachineCode objects, JsError objects with stack frame generated by jit in the map. + // It will be used to keep MachineCode objects alive (for dump) before JsError object be free. + std::map jitCodeMaps_; +diff --git a/ecmascript/mutator_lock.cpp b/ecmascript/mutator_lock.cpp +index 6e6408cc0..ddf1f2f3a 100644 +--- a/ecmascript/mutator_lock.cpp ++++ b/ecmascript/mutator_lock.cpp +@@ -17,7 +17,7 @@ + #include "ecmascript/js_thread.h" namespace panda::ecmascript { - void MachineCode::SetData(const MachineCodeDesc *desc, JSHandle &method, size_t dataSize) +-#ifndef NDEBUG ++ + void MutatorLock::ReadLock() + { + ASSERT(!HasLock()); +@@ -73,7 +73,6 @@ void MutatorLock::SetState(MutatorLock::MutatorLockState newState) + { + JSThread::GetCurrent()->SetMutatorLockState(newState); + } +-#endif + + void SuspendBarrier::Wait() + { +diff --git a/ecmascript/mutator_lock.h b/ecmascript/mutator_lock.h +index 75b235715..dd9773b02 100644 +--- a/ecmascript/mutator_lock.h ++++ b/ecmascript/mutator_lock.h +@@ -21,7 +21,7 @@ + namespace panda::ecmascript { + + class MutatorLock : public RWLock { +-#ifndef NDEBUG ++ + public: + enum MutatorLockState { UNLOCKED, RDLOCK, WRLOCK }; + void ReadLock(); +@@ -34,7 +34,6 @@ public: + private: + MutatorLockState GetState() const; + void SetState(MutatorLockState newState); +-#endif + }; + + class SuspendBarrier { diff --git a/ecmascript/object_factory.cpp b/ecmascript/object_factory.cpp -index 9852bab3d..c88b243f1 100644 +index f93f64cbe..f3093d349 100644 --- a/ecmascript/object_factory.cpp +++ b/ecmascript/object_factory.cpp -@@ -3148,6 +3148,7 @@ JSHandle ObjectFactory::NewBigInt(uint32_t length) - // static +@@ -3314,6 +3314,7 @@ JSHandle ObjectFactory::NewBigInt(uint32_t length) void ObjectFactory::NewObjectHook() const { -+ /* + CHECK_NO_HEAP_ALLOC; ++/* #ifndef NDEBUG - if (vm_->GetJSOptions().EnableForceGC() && vm_->IsInitialized() && thread_->IsAllContextsInitialized()) { - if (vm_->GetJSOptions().ForceFullGC()) { -@@ -3160,6 +3161,7 @@ void ObjectFactory::NewObjectHook() const + if (vm_->GetJSOptions().EnableForceGC() && vm_->IsInitialized() && thread_->IsAllContextsInitialized() + && !heap_->InSensitiveStatus()) { +@@ -3327,6 +3328,7 @@ void ObjectFactory::NewObjectHook() const } } #endif @@ -206,3 +309,18 @@ index 9852bab3d..c88b243f1 100644 } JSHandle ObjectFactory::NewTaggedQueue(uint32_t length) +diff --git a/ecmascript/runtime_lock.cpp b/ecmascript/runtime_lock.cpp +index dbe4b5e16..949b0598a 100644 +--- a/ecmascript/runtime_lock.cpp ++++ b/ecmascript/runtime_lock.cpp +@@ -23,9 +23,8 @@ RuntimeLockHolder::RuntimeLockHolder(JSThread *thread, Mutex &mtx) + if (mtx_.TryLock()) { + return; + } +-#ifndef NDEBUG ++ + SharedHeap::GetInstance()->CollectGarbage(thread_); +-#endif + ThreadStateTransitionScope ts(thread_); + mtx.Lock(); + } -- Gitee