From c52128386eb1043fbfe06fc0afcad9d07521bde1 Mon Sep 17 00:00:00 2001 From: Alex Antonov Date: Thu, 25 Nov 2021 17:32:57 +0300 Subject: [PATCH] [mapleall][driver] Restore PrintCommand Restore removed in previous commit PrintCommand. Now PrintCommand uses Action, because information about input files is contained inside Action. --- .../maple_driver/include/mpl_options.h | 8 ++- .../maple_driver/src/compiler_factory.cpp | 2 +- .../maple_driver/src/maple_comb_compiler.cpp | 1 + src/mapleall/maple_driver/src/mpl_options.cpp | 59 +++++++++++++++++-- 4 files changed, 63 insertions(+), 7 deletions(-) diff --git a/src/mapleall/maple_driver/include/mpl_options.h b/src/mapleall/maple_driver/include/mpl_options.h index 526e727746..d724e7518e 100644 --- a/src/mapleall/maple_driver/include/mpl_options.h +++ b/src/mapleall/maple_driver/include/mpl_options.h @@ -394,9 +394,13 @@ class MplOptions { ErrorCode AppendCombOptions(MIRSrcLang srcLang); ErrorCode AppendMplcgOptions(MIRSrcLang srcLang); - void PrintCommand(); + std::string GetInputFileNameForPrint(const Action * const action) const; + void PrintCommand(const Action * const action); void connectOptStr(std::string &optionStr, const std::string &exeName, bool &firstComb, std::string &runStr); - void PrintDetailCommand(); + void PrintDetailCommand(const Action * const action, bool isBeforeParse); + inline void PrintDetailCommand(bool isBeforeParse) { + PrintDetailCommand(nullptr, isBeforeParse); + } private: bool Init(const std::string &inputFile); ErrorCode HandleGeneralOptions(); diff --git a/src/mapleall/maple_driver/src/compiler_factory.cpp b/src/mapleall/maple_driver/src/compiler_factory.cpp index ce965b3eec..fecbce0c69 100644 --- a/src/mapleall/maple_driver/src/compiler_factory.cpp +++ b/src/mapleall/maple_driver/src/compiler_factory.cpp @@ -137,7 +137,7 @@ ErrorCode CompilerFactory::Compile(MplOptions &mplOptions) { } } if (mplOptions.HasSetDebugFlag()) { - mplOptions.PrintDetailCommand(); + mplOptions.PrintDetailCommand(false); } // Compiler finished compileFinished = true; diff --git a/src/mapleall/maple_driver/src/maple_comb_compiler.cpp b/src/mapleall/maple_driver/src/maple_comb_compiler.cpp index 0c0a64afd9..5794a1f537 100644 --- a/src/mapleall/maple_driver/src/maple_comb_compiler.cpp +++ b/src/mapleall/maple_driver/src/maple_comb_compiler.cpp @@ -171,6 +171,7 @@ ErrorCode MapleCombCompiler::Compile(MplOptions &options, const Action &action, theModule = std::make_unique(fileName); fileParsed = false; } + options.PrintCommand(&action); LogInfo::MapleLogger() << "Starting maplecomb\n"; theModule->InitPartO2List(options.GetPartO2List()); DriverRunner runner(theModule.get(), options.GetSelectedExes(), action.GetInputFileType(), fileName, diff --git a/src/mapleall/maple_driver/src/mpl_options.cpp b/src/mapleall/maple_driver/src/mpl_options.cpp index 8606d77e25..efa8efba48 100644 --- a/src/mapleall/maple_driver/src/mpl_options.cpp +++ b/src/mapleall/maple_driver/src/mpl_options.cpp @@ -852,6 +852,50 @@ void MplOptions::UpdateRunningExe(const std::string &args) { } } +std::string MplOptions::GetInputFileNameForPrint(const Action * const action) const { + if (!runningExes.empty()) { + if (runningExes[0] == kBinNameMe || runningExes[0] == kBinNameMpl2mpl + || runningExes[0] == kBinNameMplcg) { + return inputFiles; + } + } + + if (action == nullptr) { + return GetInputFiles(); + } + + if (action->GetInputFileType() == InputFileType::kFileTypeVtableImplMpl) { + return action->GetFullOutputName() + ".VtableImpl.mpl"; + } + if (action->GetInputFileType() == InputFileType::kFileTypeBpl) { + return action->GetFullOutputName() + ".bpl"; + } + return action->GetFullOutputName() + ".mpl"; +} + +void MplOptions::PrintCommand(const Action * const action) { + if (hasPrinted) { + return; + } + std::ostringstream optionStr; + if (runMode == RunMode::kAutoRun) { + if (optimizationLevel == kO0) { + optionStr << " -O0"; + } else if (optimizationLevel == kO2) { + optionStr << " -O2"; + } + + auto inputs = (action == nullptr) ? GetInputFiles() : GetInputFileNameForPrint(action); + + LogInfo::MapleLogger() << "Starting:" << exeFolder << "maple " << optionStr.str() << " " + << printExtraOptStr.str() << printCommandStr << " " << inputs << '\n'; + } + if (runMode == RunMode::kCustomRun) { + PrintDetailCommand(action, true); + } + hasPrinted = true; +} + void MplOptions::connectOptStr(std::string &optionStr, const std::string &exeName, bool &firstComb, std::string &runStr) { std::string connectSym = ""; @@ -870,7 +914,8 @@ void MplOptions::connectOptStr(std::string &optionStr, const std::string &exeNam } } } -void MplOptions::PrintDetailCommand() { + +void MplOptions::PrintDetailCommand(const Action * const action, bool isBeforeParse) { if (exeOptions.find(kBinNameMe) == exeOptions.end() && exeOptions.find(kBinNameMpl2mpl) == exeOptions.end() && exeOptions.find(kBinNameMplcg) == exeOptions.end()) { return; @@ -884,8 +929,14 @@ void MplOptions::PrintDetailCommand() { connectOptStr(optionStr, kBinNameMplcg, firstComb, runStr); optionStr += "\""; - LogInfo::MapleLogger() << "Finished:" << exeFolder << "maple " - << runStr << " " << optionStr << " " - << printCommandStr << " " << GetInputFiles() << '\n'; + auto inputs = (action == nullptr) ? GetInputFiles() : GetInputFileNameForPrint(action); + + if (isBeforeParse) { + LogInfo::MapleLogger() << "Starting:" << exeFolder << "maple " << runStr << " " << optionStr << " " + << printExtraOptStr.str() << printCommandStr << " " << inputs << '\n'; + } else { + LogInfo::MapleLogger() << "Finished:" << exeFolder << "maple " << runStr << " " << optionStr << " " + << printCommandStr << " " << inputs << '\n'; + } } } // namespace maple -- Gitee