From dc162c57bbc6846ef6eb8907c5bb8a0681e81fe5 Mon Sep 17 00:00:00 2001 From: Alex Antonov Date: Mon, 13 Dec 2021 11:02:07 +0300 Subject: [PATCH 1/8] [mapleall][driver] Do not dump duplicated --run/option/infile options These options are dumped as part of me/mpl2mpl/mplcg options. So duplicated options were excluded from the dump. --- src/mapleall/maple_driver/src/mpl_options.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/mapleall/maple_driver/src/mpl_options.cpp b/src/mapleall/maple_driver/src/mpl_options.cpp index eb7d789856..7183a88603 100644 --- a/src/mapleall/maple_driver/src/mpl_options.cpp +++ b/src/mapleall/maple_driver/src/mpl_options.cpp @@ -651,12 +651,23 @@ ErrorCode MplOptions::AddOption(const mapleOption::Option &option) { } std::string MplOptions::GetCommonOptionsStr() const { + static DriverOptionIndex exclude[] = { kRun, kOption, kInFile, kMeOpt, kMpl2MplOpt, kMplcgOpt }; + std::string driverOptions; auto it = exeOptions.find("all"); if (it != exeOptions.end()) { for (const mapleOption::Option &opt : it->second) { - auto connectSym = !opt.Args().empty() ? "=" : ""; - driverOptions += " --" + opt.OptionKey() + connectSym + opt.Args(); + if (!(std::find(std::begin(exclude), std::end(exclude), opt.Index()) != std::end(exclude))) { + std::string prefix; + if (opt.GetPrefixType() == mapleOption::shortOptPrefix) { + prefix = "-"; + } else if (opt.GetPrefixType() == mapleOption::longOptPrefix) { + prefix = "--"; + } + + auto connectSym = !opt.Args().empty() ? "=" : ""; + driverOptions += " " + prefix + opt.OptionKey() + connectSym + opt.Args(); + } } } -- Gitee From 3284af2dbf6f76b96f4153db40d5e436d15aa2c5 Mon Sep 17 00:00:00 2001 From: Alex Antonov Date: Mon, 13 Dec 2021 14:56:58 +0300 Subject: [PATCH 2/8] [mapleall][driver] Add error log for unsupported tool If compilation is run with incorrect tool, like this: maple --run=clang:incorrecttool . The log must show what is wrong. This was implemented in this commit. The log for this error will be: Fatal error: incorrecttool tool is not supported Supported Tool: as maplecombwrp ld maplecomb me mpl2mpl mplipa clang hir2mpl mplcg dex2mpl jbc2mpl --- .../maple_driver/src/compiler_selector.cpp | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/mapleall/maple_driver/src/compiler_selector.cpp b/src/mapleall/maple_driver/src/compiler_selector.cpp index 5d5608ada8..87e3fc327e 100644 --- a/src/mapleall/maple_driver/src/compiler_selector.cpp +++ b/src/mapleall/maple_driver/src/compiler_selector.cpp @@ -44,20 +44,36 @@ ErrorCode CompilerSelectorImpl::Select(const SupportedCompilers &supportedCompil const MplOptions &mplOptions, Action &action, std::vector &selectedActions) const { + ErrorCode ret = kErrorNoError; + /* Traverse Action tree recursively and select compilers in * "from leaf(clang) to root(ld)" order */ for (const std::unique_ptr &a : action.GetInputActions()) { - Select(supportedCompilers, mplOptions, *a, selectedActions); + ret = Select(supportedCompilers, mplOptions, *a, selectedActions); + if (ret != kErrorNoError) { + return ret; + } } Compiler *compiler = FindCompiler(supportedCompilers, action.GetTool()); if (compiler == nullptr) { - return kErrorToolNotFound; + if (action.GetTool() != "input") { + LogInfo::MapleLogger(kLlErr) << "Fatal error: " << action.GetTool() + << " tool is not supported" << "\n"; + LogInfo::MapleLogger(kLlErr) << "Supported Tool: "; + + auto print = [](auto supportedComp) { std::cout << " " << supportedComp.first; }; + std::for_each(supportedCompilers.begin(), supportedCompilers.end(), print); + LogInfo::MapleLogger(kLlErr) << "\n"; + + return kErrorToolNotFound; + } + } else { + action.SetCompiler(compiler); + selectedActions.push_back(&action); } - action.SetCompiler(compiler); - selectedActions.push_back(&action); - return kErrorNoError; + return ret; } ErrorCode CompilerSelectorImpl::Select(const SupportedCompilers &supportedCompilers, @@ -67,6 +83,9 @@ ErrorCode CompilerSelectorImpl::Select(const SupportedCompilers &supportedCompil for (const std::unique_ptr &action : mplOptions.GetActions()) { ret = Select(supportedCompilers, mplOptions, *action, selectedActions); + if (ret != kErrorNoError) { + return ret; + } } return selectedActions.empty() ? kErrorToolNotFound : kErrorNoError; -- Gitee From b6df6cd01ad5caa068d85108a1ab3a5655d1a7ec Mon Sep 17 00:00:00 2001 From: Alex Antonov Date: Mon, 13 Dec 2021 18:25:55 +0300 Subject: [PATCH 3/8] [mapleall][driver] Do not show the error if removed file does not exist Some time file can be removed at the previous step. --- src/mapleall/maple_driver/src/compiler_factory.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/mapleall/maple_driver/src/compiler_factory.cpp b/src/mapleall/maple_driver/src/compiler_factory.cpp index 4aad43864a..6167155d71 100644 --- a/src/mapleall/maple_driver/src/compiler_factory.cpp +++ b/src/mapleall/maple_driver/src/compiler_factory.cpp @@ -92,10 +92,7 @@ ErrorCode CompilerFactory::DeleteTmpFiles(const MplOptions &mplOptions, } if (isNeedRemove == true) { - ret = FileUtils::Remove(tmpFile); - if (ret != 0) { - LogInfo::MapleLogger() << tmpFile << " File Not Found in DeleteTmpFiles\n"; - } + FileUtils::Remove(tmpFile); } } } -- Gitee From cbf348cfa09ff2401949555131298f32c6127320 Mon Sep 17 00:00:00 2001 From: Alex Antonov Date: Tue, 14 Dec 2021 13:41:32 +0300 Subject: [PATCH 4/8] [mapleall][driver] Detect first compilation step by Action Some places in the code require a check of first compilation tool. RunningExe was used to detect it. But RunningExe contains incorrect order of tools for mplcg compiler. MplOptions::DecideRunningPhasesByType sets mplcg(kBinNameMapleComb) in RinningExe before me and mpl2mpl. me and mpl2mpl were added in MapleCombCompiler::Compile. It's more correct to use Action Tree to detect first compilation tool. This commit implements this. --- src/mapleall/maple_driver/include/mpl_options.h | 10 ++++++++++ src/mapleall/maple_driver/src/cpp2mpl_compiler.cpp | 8 +++----- src/mapleall/maple_driver/src/maple_comb_compiler.cpp | 8 +++----- .../maple_driver/src/maple_comb_compiler_wrapper.cpp | 8 +++----- src/mapleall/maple_driver/src/mplcg_compiler.cpp | 8 +++----- 5 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/mapleall/maple_driver/include/mpl_options.h b/src/mapleall/maple_driver/include/mpl_options.h index 6324fa8e68..9106d06ea2 100644 --- a/src/mapleall/maple_driver/include/mpl_options.h +++ b/src/mapleall/maple_driver/include/mpl_options.h @@ -217,6 +217,16 @@ public: compilerTool = compiler; } + bool IsItFirstRealAction() const { + /* First action is always "Input". + * But first real action will be a tool from kMapleCompilers. + */ + if (inputActions.size() > 0 && inputActions[0]->tool == "input") { + return true; + } + return false; + } + private: const InputInfo *inputInfo; diff --git a/src/mapleall/maple_driver/src/cpp2mpl_compiler.cpp b/src/mapleall/maple_driver/src/cpp2mpl_compiler.cpp index 58bf4a7ec2..ffb863baa2 100644 --- a/src/mapleall/maple_driver/src/cpp2mpl_compiler.cpp +++ b/src/mapleall/maple_driver/src/cpp2mpl_compiler.cpp @@ -28,11 +28,9 @@ const std::string &Cpp2MplCompiler::GetBinName() const { return kBinNameCpp2mpl; } -std::string Cpp2MplCompiler::GetInputFileName(const MplOptions &options, const Action &action) const { - if (!options.GetRunningExes().empty()) { - if (options.GetRunningExes()[0] == kBinNameCpp2mpl) { - return action.GetInputFile(); - } +std::string Cpp2MplCompiler::GetInputFileName(const MplOptions &, const Action &action) const { + if (action.IsItFirstRealAction()) { + return action.GetInputFile(); } // Get base file name auto idx = action.GetOutputName().find(".ast"); diff --git a/src/mapleall/maple_driver/src/maple_comb_compiler.cpp b/src/mapleall/maple_driver/src/maple_comb_compiler.cpp index e7384c1006..8c8d77a4b9 100644 --- a/src/mapleall/maple_driver/src/maple_comb_compiler.cpp +++ b/src/mapleall/maple_driver/src/maple_comb_compiler.cpp @@ -25,11 +25,9 @@ namespace maple { using namespace mapleOption; -std::string MapleCombCompiler::GetInputFileName(const MplOptions &options, const Action &action) const { - if (!options.GetRunningExes().empty()) { - if (options.GetRunningExes()[0] == kBinNameMe || options.GetRunningExes()[0] == kBinNameMpl2mpl) { - return action.GetInputFile(); - } +std::string MapleCombCompiler::GetInputFileName(const MplOptions &, const Action &action) const { + if (action.IsItFirstRealAction()) { + return action.GetInputFile(); } if (action.GetInputFileType() == InputFileType::kFileTypeVtableImplMpl) { return action.GetFullOutputName() + ".VtableImpl.mpl"; diff --git a/src/mapleall/maple_driver/src/maple_comb_compiler_wrapper.cpp b/src/mapleall/maple_driver/src/maple_comb_compiler_wrapper.cpp index 886d1e8358..0e3463c782 100644 --- a/src/mapleall/maple_driver/src/maple_comb_compiler_wrapper.cpp +++ b/src/mapleall/maple_driver/src/maple_comb_compiler_wrapper.cpp @@ -92,11 +92,9 @@ DefaultOption MapleCombCompilerWrp::GetDefaultOptions(const MplOptions &mplOptio return defaultOptions; } -std::string MapleCombCompilerWrp::GetInputFileName(const MplOptions &options, const Action &action) const { - if (!options.GetRunningExes().empty()) { - if (options.GetRunningExes()[0] == kBinNameMe || options.GetRunningExes()[0] == kBinNameMpl2mpl) { - return action.GetInputFile(); - } +std::string MapleCombCompilerWrp::GetInputFileName(const MplOptions &, const Action &action) const { + if (action.IsItFirstRealAction()) { + return action.GetInputFile(); } InputFileType fileType = action.GetInputFileType(); diff --git a/src/mapleall/maple_driver/src/mplcg_compiler.cpp b/src/mapleall/maple_driver/src/mplcg_compiler.cpp index 712cd7775c..8d1c514d4b 100644 --- a/src/mapleall/maple_driver/src/mplcg_compiler.cpp +++ b/src/mapleall/maple_driver/src/mplcg_compiler.cpp @@ -57,12 +57,10 @@ const std::string &MplcgCompiler::GetBinName() const { return kBinNameMplcg; } -std::string MplcgCompiler::GetInputFile(const MplOptions &options, const Action &action, +std::string MplcgCompiler::GetInputFile(const MplOptions &, const Action &action, const MIRModule *md) const { - if (!options.GetRunningExes().empty()) { - if (options.GetRunningExes()[0] == kBinNameMplcg) { - return action.GetInputFile(); - } + if (action.IsItFirstRealAction()) { + return action.GetInputFile(); } // Get base file name auto idx = action.GetOutputName().find(".VtableImpl"); -- Gitee From ecc63b8415d3a354ddbc0259b6e2a4b462cded56 Mon Sep 17 00:00:00 2001 From: Alex Antonov Date: Mon, 13 Dec 2021 18:08:37 +0300 Subject: [PATCH 5/8] [script] Add bash tab-autocompletion for maple driver maple_autocompletion.sh is used to add bash tab-autocompletion for maple driver. It uses "complete" linux tool to add this. envsetup.sh runs maple_autocompletion.sh during environment configuration. It works like this: "maple -" shows all available options. To show it, "--help option output" is parsed. --- build/envsetup.sh | 5 +++++ tools/maple_autocompletion.sh | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 tools/maple_autocompletion.sh diff --git a/build/envsetup.sh b/build/envsetup.sh index 3b526916d5..70e5e2f321 100644 --- a/build/envsetup.sh +++ b/build/envsetup.sh @@ -108,6 +108,11 @@ export MAPLE_EXECUTE_BIN=${MAPLE_ROOT}/output/${MAPLE_BUILD_TYPE}/bin export TEST_BIN=${CASE_ROOT}/driver/script export PATH=$PATH:${MAPLE_EXECUTE_BIN}:${TEST_BIN} +# Enable Autocompletion for maple driver +if [ -f $MAPLE_ROOT/tools/maple_autocompletion.sh ]; then + source ${MAPLE_ROOT}/tools/maple_autocompletion.sh +fi + if [ ! -f $MAPLE_ROOT/tools/qemu/usr/bin/qemu-aarch64 ] && [ "$OLD_OS" = "0" ]; then echo " " echo "!!! please run \"make setup\" to get proper qemu-aarch64" diff --git a/tools/maple_autocompletion.sh b/tools/maple_autocompletion.sh new file mode 100644 index 0000000000..7775e87192 --- /dev/null +++ b/tools/maple_autocompletion.sh @@ -0,0 +1,27 @@ +_maple_complete() +{ + local cur_word prev_word type_list + + cur_word="${COMP_WORDS[COMP_CWORD]}" + prev_word="${COMP_WORDS[COMP_CWORD-1]}" + + # generate a list of options it supports + type_list=`maple --help` + + # Only perform completion by "--help parsing" if the current word starts with a dash ('-'), + # meaning that the user is trying to complete an option. + # Else, show input files as the options. + # COMPREPLY is the array of possible completions, generated with + # the compgen builtin. + if [[ ${cur_word} == -* ]] ; then + # Parse --help output to show options + COMPREPLY=( $(compgen -W "${type_list}" -- ${cur_word}) $(compgen -f -- ${cur_word}) ) + else + # Input files + COMPREPLY=( $(compgen -f -- ${cur_word}) ) + fi + return 0 +} + +# Register _maple_complete to provide completion for the maple driver +complete -F _maple_complete maple -- Gitee From dde53682507a04a4db23c865e5f94e05df41d409 Mon Sep 17 00:00:00 2001 From: Alex Antonov Date: Mon, 13 Dec 2021 18:50:32 +0300 Subject: [PATCH 6/8] [mapleall][driver] Add --no-maple-phase into help Add --no-maple-phase into help. --- src/mapleall/maple_driver/src/driver_option_common.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mapleall/maple_driver/src/driver_option_common.cpp b/src/mapleall/maple_driver/src/driver_option_common.cpp index faed5f45c6..69a2217338 100644 --- a/src/mapleall/maple_driver/src/driver_option_common.cpp +++ b/src/mapleall/maple_driver/src/driver_option_common.cpp @@ -516,7 +516,7 @@ const mapleOption::Descriptor kUsages[] = { "maple-phase", kBuildTypeAll, kArgCheckPolicyBool, - " --maple-phase \tRun maple phase only\n", + " --maple-phase \tRun maple phase only\n --no-maple-phase\n", "all", {} }, { kMapleOut, -- Gitee From f7250c393597ed85e86a820222c85be38e6c006e Mon Sep 17 00:00:00 2001 From: Alex Antonov Date: Tue, 14 Dec 2021 16:05:46 +0300 Subject: [PATCH 7/8] [mapleall][driver] Add common options dump in mplcg Add common options dump in mplcg. --- src/mapleall/maple_driver/src/mplcg_compiler.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/mapleall/maple_driver/src/mplcg_compiler.cpp b/src/mapleall/maple_driver/src/mplcg_compiler.cpp index 8d1c514d4b..5291917d3e 100644 --- a/src/mapleall/maple_driver/src/mplcg_compiler.cpp +++ b/src/mapleall/maple_driver/src/mplcg_compiler.cpp @@ -100,8 +100,11 @@ void MplcgCompiler::PrintMplcgCommand(const MplOptions &options, const Action &a } } optionStr += "\""; - LogInfo::MapleLogger() << "Starting:" << options.GetExeFolder() << "maple " << runStr << " " << optionStr - << " --infile " << GetInputFile(options, action, &md) << '\n'; + + std::string driverOptions = options.GetCommonOptionsStr(); + + LogInfo::MapleLogger() << "Starting:" << options.GetExeFolder() << "maple " << runStr << " " << optionStr << " " + << driverOptions << " --infile " << GetInputFile(options, action, &md) << '\n'; } ErrorCode MplcgCompiler::MakeCGOptions(const MplOptions &options) { -- Gitee From afaf02d07819daaf1431d7d094594331ed2417ab Mon Sep 17 00:00:00 2001 From: Alex Antonov Date: Wed, 15 Dec 2021 12:29:51 +0300 Subject: [PATCH 8/8] [mapleall][driver] Remove duplicated options in maplecombwrapper maple comb wrapper is used to run mpl2mpl:me:mplcg as one separated step. It uses all input options to run maplecomb wrapper. But --infile and --maple-phase must be excluded, because they are filled inside maple comb wrapper. --- .../src/maple_comb_compiler_wrapper.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/mapleall/maple_driver/src/maple_comb_compiler_wrapper.cpp b/src/mapleall/maple_driver/src/maple_comb_compiler_wrapper.cpp index 0e3463c782..7ddeaf6183 100644 --- a/src/mapleall/maple_driver/src/maple_comb_compiler_wrapper.cpp +++ b/src/mapleall/maple_driver/src/maple_comb_compiler_wrapper.cpp @@ -36,6 +36,9 @@ DefaultOption MapleCombCompilerWrp::GetDefaultOptions(const MplOptions &mplOptio auto options = mplOptions.GetOptions(); std::vector