diff --git a/src/bin/jbc2mpl b/src/bin/jbc2mpl index 84ea5241d5765e70afd9181db3473d5b74afedd8..9aab27b5e4782839dfe5ca2f58b8f2e11518aa24 100755 Binary files a/src/bin/jbc2mpl and b/src/bin/jbc2mpl differ diff --git a/src/bin/maple b/src/bin/maple index e03b0269da540e6d572e9e23c171b77f6829727e..a483a79c0bb8c35e55aafceeab73a4caaa819e1d 100755 Binary files a/src/bin/maple and b/src/bin/maple differ diff --git a/src/bin/mplcg b/src/bin/mplcg index 944794d30c14c2f68c9b38bc22928726a77b2563..eb23624789923fd2c6d1cbcf6493f63018f17885 100755 Binary files a/src/bin/mplcg and b/src/bin/mplcg differ diff --git a/src/deplibs/libmaple_driverutil.a b/src/deplibs/libmaple_driverutil.a index 1a92467cd373d11837d86aaefe8845d3655692a5..63349fa0f13814f279dc7685821101ef1aac7211 100644 Binary files a/src/deplibs/libmaple_driverutil.a and b/src/deplibs/libmaple_driverutil.a differ diff --git a/src/deplibs/libmplutil.a b/src/deplibs/libmplutil.a index 2bde69a30febfa1781cdffed942fc7fa84bcb4a8..3e790dba23889a214cb1ad93dac4e64dfc2e843e 100644 Binary files a/src/deplibs/libmplutil.a and b/src/deplibs/libmplutil.a differ diff --git a/src/maple_driver/include/default_options.h b/src/maple_driver/defs/default_options.def similarity index 100% rename from src/maple_driver/include/default_options.h rename to src/maple_driver/defs/default_options.def diff --git a/src/maple_driver/include/compiler.h b/src/maple_driver/include/compiler.h index 3e98a31229009ae18c731222e9c428507fe5078f..e5907770b33e673ae7e2edf1a4198e105e6fd63c 100644 --- a/src/maple_driver/include/compiler.h +++ b/src/maple_driver/include/compiler.h @@ -34,10 +34,10 @@ class Compiler { public: explicit Compiler(const std::string &name) : name(name) {} - virtual ~Compiler() {} + virtual ~Compiler() = default; virtual ErrorCode Compile(const MplOptions &options, MIRModulePtr &theModule); - inline const std::string &GetName() const { + const std::string &GetName() const { return name; } @@ -45,9 +45,7 @@ class Compiler { return std::vector(); } - virtual void GetTmpFilesToDelete(const MplOptions &mplOptions, std::vector &tempFiles) const { - return; - } + virtual void GetTmpFilesToDelete(const MplOptions &mplOptions, std::vector &tempFiles) const {} virtual const std::unordered_set GetFinalOutputs(const MplOptions &mplOptions) const { return std::unordered_set(); @@ -62,11 +60,11 @@ class Compiler { } virtual const std::string GetInputFileName(const MplOptions &options) const { - std::string strOption = ""; + std::ostringstream ss; for (auto const &inputFile : options.splitsInputFiles) { - strOption += " " + inputFile; + ss << " " << inputFile; } - return strOption; + return ss.str(); } virtual const DefaultOption GetDefaultOptions(const MplOptions &options) { @@ -74,7 +72,7 @@ class Compiler { } virtual void AppendExtraOptions(std::map &finalOptions, - std::map> extraOptions) const; + const std::map> &extraOptions) const; virtual const std::string AppendSpecialOption(const MplOptions &options, const std::string &optionStr) const { return optionStr; } @@ -89,7 +87,7 @@ class Compiler { void AppendDefaultOptions(std::map &finalOptions, const std::map &defaultOptions) const; void AppendUserOptions(std::map &finalOptions, - const std::vector userOption) const; + const std::vector &userOption) const; const std::map MakeDefaultOptions(const MplOptions &options); const int Exe(const MplOptions &mplOptions, const std::string &options) const; const std::string name; diff --git a/src/maple_driver/include/compiler_factory.h b/src/maple_driver/include/compiler_factory.h index 1a6a082206959bd3593b2a1d47ce8761bb12756f..ad3466cd0c35ae5e12cc6193cfe90988f9704b1d 100644 --- a/src/maple_driver/include/compiler_factory.h +++ b/src/maple_driver/include/compiler_factory.h @@ -14,12 +14,10 @@ */ #ifndef MAPLE_DRIVER_INCLUDE_COMPILER_FACTORY_H #define MAPLE_DRIVER_INCLUDE_COMPILER_FACTORY_H -#include #include #include "compiler.h" #include "compiler_selector.h" #include "error_code.h" -#include "supported_compilers.h" #include "mir_module.h" #include "mir_parser.h" diff --git a/src/maple_driver/include/compiler_selector.h b/src/maple_driver/include/compiler_selector.h index 0fd6b80a690f5ca7683389e04d3ba45100ec6ac6..05457ae96e6378c12b5a5c7f5f1053059bcdad70 100644 --- a/src/maple_driver/include/compiler_selector.h +++ b/src/maple_driver/include/compiler_selector.h @@ -18,9 +18,9 @@ #include #include "compiler.h" #include "error_code.h" -#include "supported_compilers.h" namespace maple { +using SupportedCompilers = std::unordered_map; class CompilerSelector { public: CompilerSelector() {} @@ -43,7 +43,7 @@ class CompilerSelectorImpl : public CompilerSelector { std::vector &selected) const; private: - Compiler *FindCompiler(const SupportedCompilers &compilers, const std::string name) const; + Compiler *FindCompiler(const SupportedCompilers &compilers, const std::string &name) const; const ErrorCode InsertCompilerIfNeeded(std::vector &selected, const SupportedCompilers &compilers, const std::string name) const; }; diff --git a/src/maple_driver/include/driver_runner.h b/src/maple_driver/include/driver_runner.h index 729c2c4768b4dc754a87217e5dac7a9072692f73..cc5681b71fd0486ace1504e05796ecebc13015ba 100644 --- a/src/maple_driver/include/driver_runner.h +++ b/src/maple_driver/include/driver_runner.h @@ -19,6 +19,7 @@ #include #include "me_option.h" #include "interleaved_manager.h" +#include "error_code.h" extern const char *kNoFile; @@ -54,9 +55,9 @@ class DriverRunner final { ~DriverRunner() {} - int Run(); + ErrorCode Run(); void ReleaseOptions(); - bool ParseInput(std::string outputFile, std::string oriBasename) const; + ErrorCode ParseInput(std::string outputFile, std::string oriBasename) const; bool VerifyModule(MIRModulePtr &mModule) const; void ProcessMpl2mplAndMePhases(std::string outputFile, std::string vtableImplFile) const; diff --git a/src/maple_driver/include/file_utils.h b/src/maple_driver/include/file_utils.h index c4924195f0e13d7d96d4cab4b15c4038eab15622..ecd0f7679f52763351c3f00e1ad7b615a1676e28 100644 --- a/src/maple_driver/include/file_utils.h +++ b/src/maple_driver/include/file_utils.h @@ -17,12 +17,12 @@ #include namespace FileSeperator { -const static char kFileSeperatorLinuxStyleChar = '/'; -const static char kFileSeperatorWindowsStyleChar = '\\'; -const static char kFileSeperatorChar = kFileSeperatorLinuxStyleChar; -const static std::string kFileSeperatorLinuxStyleStr = std::string(1, kFileSeperatorLinuxStyleChar); -const static std::string kFileSeperatorWindowsStyleStr = std::string(1, kFileSeperatorWindowsStyleChar); -const static std::string kFileSeperatorStr = kFileSeperatorLinuxStyleStr; +const char kFileSeperatorLinuxStyleChar = '/'; +const char kFileSeperatorWindowsStyleChar = '\\'; +const char kFileSeperatorChar = kFileSeperatorLinuxStyleChar; +const std::string kFileSeperatorLinuxStyleStr = std::string(1, kFileSeperatorLinuxStyleChar); +const std::string kFileSeperatorWindowsStyleStr = std::string(1, kFileSeperatorWindowsStyleChar); +const std::string kFileSeperatorStr = kFileSeperatorLinuxStyleStr; } // namespace FileSeperator namespace maple { diff --git a/src/maple_driver/include/mpl_options.h b/src/maple_driver/include/mpl_options.h index 72e87d8e40204b47dc80fe53e98ef51d4ddd5bce..ef1719089dc981c7e5d2671be37724fe9c5d8f98 100644 --- a/src/maple_driver/include/mpl_options.h +++ b/src/maple_driver/include/mpl_options.h @@ -55,7 +55,7 @@ class MplOption { void init(const std::string &key, const std::string &value, const std::string &connectSymbol, bool isAppend, const std::string &appendSplit, bool needRootPath = false) { - CHECK_FATAL(!key.empty(), "key is empty"); + CHECK_FATAL(!key.empty(), "MplOption got an empty key."); this->key = key; this->value = value; @@ -68,32 +68,20 @@ class MplOption { struct DefaultOption { MplOption *mplOptions; - unsigned int length; -}; - -class UserOption : public std::map> { - public: - void Insert(const std::string &exeName, const mapleOption::Option &option) { - auto it = find(exeName); - if (it == end()) { - insert(make_pair(exeName, std::vector())); - it = find(exeName); - } - it->second.push_back(option); - } + uint32_t length; }; class MplOptions { public: mapleOption::OptionParser *optionParser; - // may used future - UserOption options; + std::map> options; std::map> exeOptions; std::string inputFiles; std::string inputFolder; std::string outputFolder; std::string outputName; std::string exeFolder; + std::string optLevelStr; InputFileType inputFileType; OptimizationLevel optimizationLevel; bool setDefaultLevel; @@ -111,13 +99,14 @@ class MplOptions { bool verify; MplOptions() : optionParser(nullptr), - options(UserOption()), + options({}), exeOptions({}), inputFiles(""), inputFolder(""), outputFolder(""), outputName("maple"), exeFolder(""), + optLevelStr(""), inputFileType(InputFileType::kNone), optimizationLevel(OptimizationLevel::kO2), setDefaultLevel(false), @@ -145,6 +134,11 @@ class MplOptions { private: bool Init(const std::string &inputFile); + ErrorCode HandleGeneralOptions(); + ErrorCode DecideRunType(); + ErrorCode DecideRunningPhases(); + ErrorCode CheckInputFileValidity(); + ErrorCode CheckOptLevel(const std::string &inputOpt, const std::string &filterOpt); ErrorCode CheckFileExits(); void AddOption(const mapleOption::Option &option); void UpdateOptLevel(OptimizationLevel level); diff --git a/src/maple_driver/include/supported_compilers.h b/src/maple_driver/include/supported_compilers.h deleted file mode 100644 index c8f85a7583fef2773ae88fb7f709e0e5db487816..0000000000000000000000000000000000000000 --- a/src/maple_driver/include/supported_compilers.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under the Mulan PSL v1. - * You can use this software according to the terms and conditions of the Mulan PSL v1. - * You may obtain a copy of Mulan PSL v1 at: - * - * http://license.coscl.org.cn/MulanPSL - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. - * See the Mulan PSL v1 for more details. - */ -#ifndef MAPLE_DRIVER_INCLUDE_SUPPORTED_COMPILERS_H -#define MAPLE_DRIVER_INCLUDE_SUPPORTED_COMPILERS_H -#include -#include "compiler.h" - -namespace maple { -using SupportedCompilers = std::unordered_map; -} -#endif // MAPLE_DRIVER_INCLUDE_SUPPORTED_COMPILERS_H diff --git a/src/maple_driver/src/compiler.cpp b/src/maple_driver/src/compiler.cpp index 5999575b970592d8026c3a6b8b7f640ee34b4195..a7082b81ca7114a59b5d3841a7f44206bbd66040 100644 --- a/src/maple_driver/src/compiler.cpp +++ b/src/maple_driver/src/compiler.cpp @@ -18,71 +18,69 @@ #include "safe_exe.h" #include "mpl_timer.h" -using namespace mapleOption; namespace maple { +using namespace mapleOption; const int Compiler::Exe(const MplOptions &mplOptions, const std::string &options) const { - const std::string binPath = FileUtils::ConvertPathIfNeeded(this->GetBinPath(mplOptions) + this->GetBinName()); + std::ostringstream ostrStream; + ostrStream << GetBinPath(mplOptions) << GetBinName(); + std::string binPath = FileUtils::ConvertPathIfNeeded(ostrStream.str()); return SafeExe::Exe(binPath, options); } const std::string Compiler::GetBinPath(const MplOptions &mplOptions) const { - std::string binPath; #ifdef MAPLE_PRODUCT_EXECUTABLE // build flag -DMAPLE_PRODUCT_EXECUTABLE - binPath = std::string(MAPLE_PRODUCT_EXECUTABLE); + std::string binPath = std::string(MAPLE_PRODUCT_EXECUTABLE); if (binPath.empty()) { binPath = mplOptions.exeFolder; } else { binPath = binPath + FileSeperator::kFileSeperatorChar; } #else - binPath = mplOptions.exeFolder; + std::string binPath = mplOptions.exeFolder; #endif return binPath; } ErrorCode Compiler::Compile(const MplOptions &options, MIRModulePtr &theModule) { MPLTimer timer = MPLTimer(); - LogInfo::MapleLogger() << "Starting " << this->GetName() << std::endl; + LogInfo::MapleLogger() << "Starting " << GetName() << std::endl; timer.Start(); - std::string strOption = this->MakeOption(options); + std::string strOption = MakeOption(options); if (strOption.empty()) { return ErrorCode::kErrorInvalidParameter; } - if (this->Exe(options, strOption) != 0) { + if (Exe(options, strOption) != 0) { return ErrorCode::kErrorCompileFail; } timer.Stop(); - LogInfo::MapleLogger() << (this->GetName() + " consumed ") << timer.Elapsed() << "s" << std::endl; + LogInfo::MapleLogger() << (GetName() + " consumed ") << timer.Elapsed() << "s" << std::endl; return ErrorCode::kErrorNoError; } const std::string Compiler::MakeOption(const MplOptions &options) { std::map finalOptions; - auto defaultOptions = this->MakeDefaultOptions(options); - this->AppendDefaultOptions(finalOptions, defaultOptions); - for (auto binName : this->GetBinNames()) { + auto defaultOptions = MakeDefaultOptions(options); + AppendDefaultOptions(finalOptions, defaultOptions); + for (auto binName : GetBinNames()) { auto userOption = options.options.find(binName); if (userOption != options.options.end()) { - this->AppendUserOptions(finalOptions, userOption->second); + AppendUserOptions(finalOptions, userOption->second); } } - this->AppendExtraOptions(finalOptions, options.extras); - std::string strOption = ""; + AppendExtraOptions(finalOptions, options.extras); + std::ostringstream strOption; for (auto finalOption : finalOptions) { - strOption += " " + finalOption.first + finalOption.second.connectSymbol + finalOption.second.value; + strOption << " " << finalOption.first << finalOption.second.connectSymbol << finalOption.second.value; if (options.debugFlag) { LogInfo::MapleLogger() << Compiler::GetName() << " options: " << finalOption.first << " " << finalOption.second.value << std::endl; } } - strOption = this->AppendOptimization(options, strOption); - strOption = this->AppendSpecialOption(options, strOption); - strOption += " " + this->GetInputFileName(options); + strOption << " " << this->GetInputFileName(options); if (options.debugFlag) { - LogInfo::MapleLogger() << Compiler::GetName() << " input files: " << this->GetInputFileName(options) << std::endl; + LogInfo::MapleLogger() << Compiler::GetName() << " input files: " << GetInputFileName(options) << std::endl; } - strOption = FileUtils::ConvertPathIfNeeded(strOption); - return strOption; + return FileUtils::ConvertPathIfNeeded(strOption.str()); } void Compiler::AppendDefaultOptions(std::map &finalOptions, @@ -93,8 +91,8 @@ void Compiler::AppendDefaultOptions(std::map &finalOptio } void Compiler::AppendUserOptions(std::map &finalOptions, - const std::vector