From a060b89bc4520fce7275d8215ad4030d4773cf22 Mon Sep 17 00:00:00 2001 From: antyshevtg Date: Wed, 28 Jul 2021 17:49:20 +0300 Subject: [PATCH 01/16] Unfinished version of cpp2mpl --- .../defs/default/O0_options_cpp2mpl.def | 1 + .../maple_driver/defs/default_options.def | 4 ++ src/mapleall/maple_driver/include/compiler.h | 1 + .../maple_driver/include/cpp2mpl_option.h | 61 +++++++++++++++++++ .../include/driver_option_common.h | 1 + .../maple_driver/include/mpl_options.h | 1 + .../maple_driver/src/compiler_factory.cpp | 4 ++ .../maple_driver/src/cpp2mpl_compiler.cpp | 0 .../maple_driver/src/driver_option_common.cpp | 11 +++- src/mapleall/maple_driver/src/mpl_options.cpp | 24 +++++++- .../maple_driver/src/option_parser.cpp | 15 +++++ 11 files changed, 120 insertions(+), 3 deletions(-) create mode 100644 src/mapleall/maple_driver/defs/default/O0_options_cpp2mpl.def create mode 100644 src/mapleall/maple_driver/include/cpp2mpl_option.h create mode 100644 src/mapleall/maple_driver/src/cpp2mpl_compiler.cpp diff --git a/src/mapleall/maple_driver/defs/default/O0_options_cpp2mpl.def b/src/mapleall/maple_driver/defs/default/O0_options_cpp2mpl.def new file mode 100644 index 0000000000..7533ffd890 --- /dev/null +++ b/src/mapleall/maple_driver/defs/default/O0_options_cpp2mpl.def @@ -0,0 +1 @@ +{"--in-ast, "", false} \ No newline at end of file diff --git a/src/mapleall/maple_driver/defs/default_options.def b/src/mapleall/maple_driver/defs/default_options.def index da1f2d9b99..3abbf64663 100644 --- a/src/mapleall/maple_driver/defs/default_options.def +++ b/src/mapleall/maple_driver/defs/default_options.def @@ -108,5 +108,9 @@ static MplOption kMeDefaultOptionsO2ForC[] = { static MplOption kMplcgDefaultOptionsO2ForC[] = { #include "default/O2_options_mplcg_c.def" }; +// O0 cpp2mpl options +static MplOption kCpp2mplDefaultOptionsO0[] = { +#include "default/00_options_cpp2mpl.def" +}; } // namespace maple #endif // MAPLE_DRIVER_INCLUDE_DEFAULT_OPTIONS_H diff --git a/src/mapleall/maple_driver/include/compiler.h b/src/mapleall/maple_driver/include/compiler.h index 54ce62a65f..1876f5f646 100644 --- a/src/mapleall/maple_driver/include/compiler.h +++ b/src/mapleall/maple_driver/include/compiler.h @@ -32,6 +32,7 @@ namespace maple { const std::string kBinNameNone = ""; const std::string kBinNameJbc2mpl = "jbc2mpl"; +const std::string kBinNameCpp2mpl = "mplfe"; const std::string kBinNameDex2mpl = "dex2mpl"; const std::string kBinNameMplipa = "mplipa"; const std::string kBinNameMe = "me"; diff --git a/src/mapleall/maple_driver/include/cpp2mpl_option.h b/src/mapleall/maple_driver/include/cpp2mpl_option.h new file mode 100644 index 0000000000..978d236d05 --- /dev/null +++ b/src/mapleall/maple_driver/include/cpp2mpl_option.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) [2019-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * 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 v2 for more details. + */ +#ifndef MAPLE_CPP2MPL_OPTION_H +#define MAPLE_CPP2MPL_OPTION_H +#include "option_descriptor.h" + +namespace maple { + + enum CppOptionIndex { + kCpp2mplHelp, + kInAst, + kInCpp, + }; + + + const mapleOption::Descriptor cppUsage[] = { + { kUnknown, 0, "", "", mapleOption::kBuildTypeAll, mapleOption::kArgCheckPolicyUnknown, + "========================================\n" + " Usage: cpp2mpl [ options ]\n" + " options:\n", + "cpp2mpl", + {} }, + + { kInAst, 0, "", "inast", mapleOption::kBuildTypeAll, mapleOption::kArgCheckPolicyRequired, + " -inast file1.ast,file2.ast\n" + " : input ast files", + "cpp2mpl", + {} }, + + { kInCpp, 0, "", "incpp", mapleOption::kBuildTypeAll, mapleOption::kArgCheckPolicyRequired, + " -incpp file1.cpp,file2.cpp\n" + " : input cpp files", + "cpp2mpl", + {} }, + + { kDex2mplHelp, 0, "h", "help", mapleOption::kBuildTypeExperimental, mapleOption::kArgCheckPolicyNone, + " -h, --help : print usage and exit.\n", + "cpp2mpl", + {} }, + + { kUnknown, 0, "", "", mapleOption::kBuildTypeAll, mapleOption::kArgCheckPolicyNone, + "", + "jbc2mpl", + {} } + }; +} // namespace maple + + +#endif //MAPLE_CPP2MPL_OPTION_H diff --git a/src/mapleall/maple_driver/include/driver_option_common.h b/src/mapleall/maple_driver/include/driver_option_common.h index 55a8223e0c..92eadc2bba 100644 --- a/src/mapleall/maple_driver/include/driver_option_common.h +++ b/src/mapleall/maple_driver/include/driver_option_common.h @@ -28,6 +28,7 @@ enum DriverOptionIndex { kOptimization2, kWithIpa, kJbc2mplOpt, + kCpp2mplOpt, kDex2mplOpt, kMplipaOpt, kVerify, diff --git a/src/mapleall/maple_driver/include/mpl_options.h b/src/mapleall/maple_driver/include/mpl_options.h index c02fa68842..06f157270e 100644 --- a/src/mapleall/maple_driver/include/mpl_options.h +++ b/src/mapleall/maple_driver/include/mpl_options.h @@ -32,6 +32,7 @@ namespace maple { enum InputFileType { kFileTypeNone, kFileTypeClass, + kFileTypeAst, kFileTypeJar, kFileTypeDex, kFileTypeMpl, diff --git a/src/mapleall/maple_driver/src/compiler_factory.cpp b/src/mapleall/maple_driver/src/compiler_factory.cpp index 5ca6e926a2..efc969abea 100644 --- a/src/mapleall/maple_driver/src/compiler_factory.cpp +++ b/src/mapleall/maple_driver/src/compiler_factory.cpp @@ -34,6 +34,7 @@ CompilerFactory::CompilerFactory() { // Supported compilers ADD_COMPILER("jbc2mpl", Jbc2MplCompiler) ADD_COMPILER("dex2mpl", Dex2MplCompiler) + ADD_COMPILER("cpp2mpl", Cpp2MplCompiler) ADD_COMPILER("mplipa", IpaCompiler) ADD_COMPILER("me", MapleCombCompiler) ADD_COMPILER("mpl2mpl", MapleCombCompiler) @@ -84,6 +85,9 @@ ErrorCode CompilerFactory::DeleteTmpFiles(const MplOptions &mplOptions, const st } ErrorCode CompilerFactory::Compile(MplOptions &mplOptions) { + // Code_exp: GetInstance triggered constructor, which added compilers and CompilerSelectorImpl + // Code_exp: constructor also filled supported compilers + // Code_exp: using SupportedCompilers = std::unordered_map; if (compileFinished) { LogInfo::MapleLogger() << "Failed! Compilation has been completed in previous time and multi-instance compilation is not supported\n"; diff --git a/src/mapleall/maple_driver/src/cpp2mpl_compiler.cpp b/src/mapleall/maple_driver/src/cpp2mpl_compiler.cpp new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/mapleall/maple_driver/src/driver_option_common.cpp b/src/mapleall/maple_driver/src/driver_option_common.cpp index dda7b4487c..2cd7ff5119 100644 --- a/src/mapleall/maple_driver/src/driver_option_common.cpp +++ b/src/mapleall/maple_driver/src/driver_option_common.cpp @@ -138,6 +138,15 @@ const mapleOption::Descriptor usages[] = { " --jbc2mpl-opt \tSet options for jbc2mpl\n", "all", {} }, + { kCpp2mplOpt, + 0, + "", + "cpp2mpl-opt", + kBuildTypeProduct, + kArgCheckPolicyNone, + " --cpp2mpl-opt \tSet options for cpp2mpl\n", + "all", + {} }, { kDex2mplOpt, 0, "", @@ -289,7 +298,7 @@ const mapleOption::Descriptor usages[] = { kArgCheckPolicyBool, " -verbose \t: print informations\n", "all", - { "jbc2mpl", "me", "mpl2mpl", "mplcg" } }, + { "jbc2mpl", "me", "mpl2mpl", "mplcg", "cpp2mpl" } }, { kAllDebug, 0, "", diff --git a/src/mapleall/maple_driver/src/mpl_options.cpp b/src/mapleall/maple_driver/src/mpl_options.cpp index f16918ebb2..014c3720a2 100644 --- a/src/mapleall/maple_driver/src/mpl_options.cpp +++ b/src/mapleall/maple_driver/src/mpl_options.cpp @@ -31,6 +31,7 @@ #endif #include "ipa_option.h" #include "jbc2mpl_option.h" +#include "cpp2mpl_option.h" #include "me_option.h" #include "option.h" #include "cg_option.h" @@ -42,12 +43,16 @@ using namespace maplebe; const std::string kMapleDriverVersion = "MapleDriver " + std::to_string(Version::kMajorMplVersion) + "." + std::to_string(Version::kMinorCompilerVersion) + " 20190929"; -const std::vector kMapleCompilers = { "jbc2mpl", +const std::vector kMapleCompilers = { "jbc2mpl", "cpp2mpl", "dex2mpl", "mplipa", - "me", "mpl2mpl", "mplcg" }; + "me", "mpl2mpl", "mplcg" }; // Code_exp: added cpp2mpl int MplOptions::Parse(int argc, char **argv) { + // Code_exp: MplOptions contains std::unique_ptr optionParser, which we initialize optionParser.reset(new OptionParser()); + // Code_exp: DOC contains common usages and options(GetInstance triggers usageVec fill), we also fill + // Code_exp: vector rawUsages, multimap usages(with short and long opt. names), + // Code_exp: and add no- for boolean options like no-opt optionParser->RegisteUsages(DriverOptionCommon::GetInstance()); #ifdef INTERGRATE_DRIVER optionParser->RegisteUsages(Dex2mplOptions::GetInstance()); @@ -56,10 +61,13 @@ int MplOptions::Parse(int argc, char **argv) { #endif optionParser->RegisteUsages(IpaOption::GetInstance()); optionParser->RegisteUsages(jbcUsage); + optionParser->RegisteUsages(cppUsage); optionParser->RegisteUsages(Options::GetInstance()); optionParser->RegisteUsages(MeOption::GetInstance()); optionParser->RegisteUsages(CGOptions::GetInstance()); + // Code_exp: Finding folder pf maple bin in argv (./ if in cur) exeFolder = FileUtils::GetFileFolder(*argv); + // Code_exp: Parsing fills Options vector of mpl_options with keys, args and descriptors int ret = optionParser->Parse(argc, argv); if (ret != kErrorNoError) { return ret; @@ -128,6 +136,12 @@ ErrorCode MplOptions::HandleGeneralOptions() { return ret; } break; + case kCpp2mplOpt: + ret = UpdatePhaseOption(opt.Args(), kBinNameCpp2mpl); + if (ret != kErrorNoError) { + return ret; + } + break; case kJbc2mplOpt: ret = UpdatePhaseOption(opt.Args(), kBinNameJbc2mpl); if (ret != kErrorNoError) { @@ -255,6 +269,9 @@ ErrorCode MplOptions::DecideRunningPhases() { bool isNeedMapleComb = true; bool isNeedMplcg = true; switch (inputFileType) { + case InputFileType::kFileTypeAst: + UpdateRunningExe(kBinNameDex2mpl); + break; case InputFileType::kFileTypeJar: // fall-through case InputFileType::kFileTypeClass: @@ -359,6 +376,9 @@ bool MplOptions::Init(const std::string &inputFile) { else if (extensionName == "dex") { inputFileType = InputFileType::kFileTypeDex; } + else if (extensionName == "ast") { + inputFileType = InputFileType::kFileTypeAst; + } else if (extensionName == "jar") { inputFileType = InputFileType::kFileTypeJar; } else if (extensionName == "mpl" || extensionName == "bpl") { diff --git a/src/mapleall/maple_driver/src/option_parser.cpp b/src/mapleall/maple_driver/src/option_parser.cpp index 1b7b1c77ed..5060edec56 100644 --- a/src/mapleall/maple_driver/src/option_parser.cpp +++ b/src/mapleall/maple_driver/src/option_parser.cpp @@ -91,6 +91,7 @@ void OptionParser::RegisteUsages(const MapleDriverOptionBase &base) { InsertOption(usage.longOption, usage); } // Insert usage for extra options + // Code_exp: Inserting options with extras like jbc2mpl and dex2mpl InsertExtraUsage(usage); // Add --no-opt for boolean option if (usage.checkPolicy == kArgCheckPolicyBool) { @@ -165,8 +166,11 @@ bool OptionParser::HandleKeyValue(const std::string &key, const std::string &val nonOptionsArgs.push_back(value); return true; } + // Code_exp: in map of keys and descriptors count current key size_t count = usages.count(key); + // Code_exp: find element with this key auto item = usages.find(key); + // Code_exp: get option with correct exeName while (count > 0 && item->second.exeName != exeName) { ++item; --count; @@ -175,6 +179,7 @@ bool OptionParser::HandleKeyValue(const std::string &key, const std::string &val LogInfo::MapleLogger(kLlErr) << ("Unknown Option: " + key) << '\n'; return false; } + // Code_exp: now check required args switch (item->second.checkPolicy) { case kArgCheckPolicyUnknown: LogInfo::MapleLogger(kLlErr) << ("Unknown option " + key) << '\n'; @@ -266,9 +271,12 @@ bool OptionParser::CheckOpt(const std::string option, std::string &lastKey, } } size_t pos = option.find('='); + // Code_exp: options args can be specified either by = i.e. --run=jbc2mpl or with a space bar: + // Code_exp: --infile file1,file2 that's why we need to take that into account if (pos != std::string::npos) { ASSERT(pos > 0, "option should not begin with symbol '='"); isLastMatch = false; + // Code_exp: here we get option name, its string after = and whether it's empty or not std::string key = option.substr(0, pos); std::string value = option.substr(pos + 1); isValueEmpty = value.empty(); @@ -276,6 +284,7 @@ bool OptionParser::CheckOpt(const std::string option, std::string &lastKey, } else { auto item = usages.find(option); if (item != usages.end()) { + // Code_exp: if there is no = in string, but key is found in map check arg policy and act accordingly if (item->second.checkPolicy == kArgCheckPolicyRequired || item->second.checkPolicy == kArgCheckPolicyNumeric) { lastKey = option; isLastMatch = true; @@ -293,13 +302,17 @@ bool OptionParser::CheckOpt(const std::string option, std::string &lastKey, ErrorCode OptionParser::HandleInputArgs(const std::vector &inputArgs, const std::string &exeName, std::vector &inputOption, bool isAllOption) { + // Code_exp: previous option flag bool isLastMatchOpt = false; + // Code_exp: previous key std::string lastKey = ""; bool ret = true; for (size_t i = 0; i < inputArgs.size(); ++i) { + // Code_exp: if arg is empty - skip it if (inputArgs[i] == "") { continue; } + // Code_exp: check for - or -- bool isMatchLongOpt = false; bool isMatchShortOpt = false; MatchedIndex index = kMatchNone; @@ -309,6 +322,7 @@ ErrorCode OptionParser::HandleInputArgs(const std::vector &inputArg index = kMatchLongOpt; } } + // Code_exp: here we remove - or -- marker if (index == kMatchShortOpt) { isMatchShortOpt = true; } else if (index == kMatchLongOpt) { @@ -345,6 +359,7 @@ ErrorCode OptionParser::Parse(int argc, char **argv, const std::string exeName) --argc; ++argv; // skip program name argv[0] if present } + // Code_exp: if there are no args print how to use and return error if (argc == 0 || *argv == nullptr) { PrintUsage(exeName); LogInfo::MapleLogger(kLlErr) << "No input files!" << '\n'; -- Gitee From 51dc62c2d12960036c1f2d2d676564300bb38512 Mon Sep 17 00:00:00 2001 From: JustAnotherArchetype Date: Wed, 28 Jul 2021 18:08:32 +0300 Subject: [PATCH 02/16] Unfinished version of cpp2mpl --- src/mapleall/maple_driver/BUILD.gn | 1 + .../defs/default/O0_options_cpp2mpl.def | 1 + .../defs/default/O0_options_mplcg.def | 2 +- .../defs/default/O2_options_mplcg.def | 1 + .../maple_driver/defs/default_options.def | 4 ++ src/mapleall/maple_driver/defs/phases.def | 1 - src/mapleall/maple_driver/include/compiler.h | 16 ++++++ .../maple_driver/include/cpp2mpl_option.h | 40 +++++++++++++++ .../include/driver_option_common.h | 1 + .../maple_driver/include/mpl_options.h | 1 + .../maple_driver/src/compiler_factory.cpp | 4 ++ .../maple_driver/src/cpp2mpl_compiler.cpp | 49 +++++++++++++++++++ .../maple_driver/src/driver_option_common.cpp | 11 ++++- src/mapleall/maple_driver/src/mpl_options.cpp | 27 ++++++++-- .../maple_driver/src/option_parser.cpp | 19 +++++++ 15 files changed, 172 insertions(+), 6 deletions(-) create mode 100644 src/mapleall/maple_driver/defs/default/O0_options_cpp2mpl.def create mode 100644 src/mapleall/maple_driver/include/cpp2mpl_option.h create mode 100644 src/mapleall/maple_driver/src/cpp2mpl_compiler.cpp diff --git a/src/mapleall/maple_driver/BUILD.gn b/src/mapleall/maple_driver/BUILD.gn index 2210108f70..390dc19884 100644 --- a/src/mapleall/maple_driver/BUILD.gn +++ b/src/mapleall/maple_driver/BUILD.gn @@ -46,6 +46,7 @@ executable("maple") { "src/driver_runner.cpp", "src/file_utils.cpp", "src/jbc2mpl_compiler.cpp", +# "src/cpp2mpl_compiler.cpp", "src/maple.cpp", "src/maple_comb_compiler.cpp", "src/mpl_options.cpp", diff --git a/src/mapleall/maple_driver/defs/default/O0_options_cpp2mpl.def b/src/mapleall/maple_driver/defs/default/O0_options_cpp2mpl.def new file mode 100644 index 0000000000..44ce7937ad --- /dev/null +++ b/src/mapleall/maple_driver/defs/default/O0_options_cpp2mpl.def @@ -0,0 +1 @@ +{"--in-ast", "", false} \ No newline at end of file diff --git a/src/mapleall/maple_driver/defs/default/O0_options_mplcg.def b/src/mapleall/maple_driver/defs/default/O0_options_mplcg.def index c92727c765..59228b4539 100644 --- a/src/mapleall/maple_driver/defs/default/O0_options_mplcg.def +++ b/src/mapleall/maple_driver/defs/default/O0_options_mplcg.def @@ -15,7 +15,7 @@ // option name, option value, append maple root path? { "--quiet", "", false }, { "--no-pie", "", false }, -{ "--fpic", "", false }, +{ "--no-fpic", "", false }, { "--verbose-asm", "", false }, { "--maplelinker", "", false }, { "--duplicate_asm_list", "out/target/product/maple_arm64/lib/codetricks/asm/duplicateFunc.s", true }, diff --git a/src/mapleall/maple_driver/defs/default/O2_options_mplcg.def b/src/mapleall/maple_driver/defs/default/O2_options_mplcg.def index fc489f6b0e..cf81c5bfc2 100644 --- a/src/mapleall/maple_driver/defs/default/O2_options_mplcg.def +++ b/src/mapleall/maple_driver/defs/default/O2_options_mplcg.def @@ -21,3 +21,4 @@ { "--maplelinker", "", false }, { "--gen-c-macro-def", "", false }, { "--duplicate_asm_list", "out/target/product/maple_arm64/lib/codetricks/asm/duplicateFunc.s", true }, + diff --git a/src/mapleall/maple_driver/defs/default_options.def b/src/mapleall/maple_driver/defs/default_options.def index da1f2d9b99..e5296287f1 100644 --- a/src/mapleall/maple_driver/defs/default_options.def +++ b/src/mapleall/maple_driver/defs/default_options.def @@ -108,5 +108,9 @@ static MplOption kMeDefaultOptionsO2ForC[] = { static MplOption kMplcgDefaultOptionsO2ForC[] = { #include "default/O2_options_mplcg_c.def" }; +// Code_exp: standard options for cpp2mpl +static MplOption kCpp2MplDefaultOptionsForAst[] = { +#include "default/O0_options_cpp2mpl.def" +}; } // namespace maple #endif // MAPLE_DRIVER_INCLUDE_DEFAULT_OPTIONS_H diff --git a/src/mapleall/maple_driver/defs/phases.def b/src/mapleall/maple_driver/defs/phases.def index b495f817c8..32ce5fadb4 100644 --- a/src/mapleall/maple_driver/defs/phases.def +++ b/src/mapleall/maple_driver/defs/phases.def @@ -37,7 +37,6 @@ ADD_PHASE("ivcanon", CLANG && MeOption::optLevel >= 3) ADD_PHASE("hprop", CLANG && MeOption::optLevel >= 3) ADD_PHASE("hdse", CLANG && MeOption::optLevel >= 3) ADD_PHASE("lfopreemit", CLANG && MeOption::optLevel >= 3) -ADD_PHASE("deptest", CLANG && MeOption::optLevel >= 3) ADD_PHASE("mecfgbuild", MeOption::optLevel >= 2 || JAVALANG) ADD_PHASE("cfgOpt", CLANG && MeOption::optLevel >= 2) ADD_PHASE("bypatheh", JAVALANG && MeOption::optLevel >= 2) diff --git a/src/mapleall/maple_driver/include/compiler.h b/src/mapleall/maple_driver/include/compiler.h index 54ce62a65f..65db76170e 100644 --- a/src/mapleall/maple_driver/include/compiler.h +++ b/src/mapleall/maple_driver/include/compiler.h @@ -32,6 +32,7 @@ namespace maple { const std::string kBinNameNone = ""; const std::string kBinNameJbc2mpl = "jbc2mpl"; +const std::string kBinNameCpp2mpl = "mplfe"; const std::string kBinNameDex2mpl = "dex2mpl"; const std::string kBinNameMplipa = "mplipa"; const std::string kBinNameMe = "me"; @@ -113,6 +114,21 @@ class Jbc2MplCompiler : public Compiler { std::unordered_set GetFinalOutputs(const MplOptions &mplOptions) const override; }; +/*class Cpp2MplCompiler : public Compiler { + public: + explicit Cpp2MplCompiler(const std::string &name) : Compiler(name) {} + + ~Cpp2MplCompiler() = default; + + //ErrorCode Compile(MplOptions &options, std::unique_ptr &theModule); + + private: + const std::string &GetBinName() const override; + DefaultOption GetDefaultOptions(const MplOptions &options) const override; + void GetTmpFilesToDelete(const MplOptions &mplOptions, std::vector &tempFiles) const override; + std::unordered_set GetFinalOutputs(const MplOptions &mplOptions) const override; +};*/ + class Dex2MplCompiler : public Compiler { public: explicit Dex2MplCompiler(const std::string &name) : Compiler(name) {} diff --git a/src/mapleall/maple_driver/include/cpp2mpl_option.h b/src/mapleall/maple_driver/include/cpp2mpl_option.h new file mode 100644 index 0000000000..16be78a51a --- /dev/null +++ b/src/mapleall/maple_driver/include/cpp2mpl_option.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * 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 v2 for more details. + */ +#ifndef MAPLE_CPP2MPL_OPTION_H +#define MAPLE_CPP2MPL_OPTION_H +#include "option_descriptor.h" + +namespace maple { +enum CppOptionIndex { + kInAst +}; + +const mapleOption::Descriptor cppUsage[] = { +{ kUnknown, 0, "", "", mapleOption::kBuildTypeAll, mapleOption::kArgCheckPolicyUnknown, + "========================================\n" + " Usage: cpp2mpl [ options ]\n" + " options:\n", + "cpp2mpl", + {} }, + +{ kInAst, 0, "", "in-ast", mapleOption::kBuildTypeAll, mapleOption::kArgCheckPolicyRequired, + "-in-ast file1.ast,file2.ast\n" + " : input ast files", + "cpp2mpl", + {} } +}; +} // namespace maple + +#endif //MAPLE_CPP2MPL_OPTION_H diff --git a/src/mapleall/maple_driver/include/driver_option_common.h b/src/mapleall/maple_driver/include/driver_option_common.h index 55a8223e0c..f086ce5f3c 100644 --- a/src/mapleall/maple_driver/include/driver_option_common.h +++ b/src/mapleall/maple_driver/include/driver_option_common.h @@ -28,6 +28,7 @@ enum DriverOptionIndex { kOptimization2, kWithIpa, kJbc2mplOpt, + kCpp2mplOpt, // Code_exp: will be used in mpl_options.cpp function HandleGeneralOptions kDex2mplOpt, kMplipaOpt, kVerify, diff --git a/src/mapleall/maple_driver/include/mpl_options.h b/src/mapleall/maple_driver/include/mpl_options.h index c02fa68842..ef3aaeb87b 100644 --- a/src/mapleall/maple_driver/include/mpl_options.h +++ b/src/mapleall/maple_driver/include/mpl_options.h @@ -33,6 +33,7 @@ enum InputFileType { kFileTypeNone, kFileTypeClass, kFileTypeJar, + kFileTypeAst, // Code_exp: ast file type kFileTypeDex, kFileTypeMpl, kFileTypeVtableImplMpl, diff --git a/src/mapleall/maple_driver/src/compiler_factory.cpp b/src/mapleall/maple_driver/src/compiler_factory.cpp index 5ca6e926a2..06531d0152 100644 --- a/src/mapleall/maple_driver/src/compiler_factory.cpp +++ b/src/mapleall/maple_driver/src/compiler_factory.cpp @@ -41,6 +41,7 @@ CompilerFactory::CompilerFactory() { ADD_COMPILER("mplcg", MplcgCompiler) ADD_COMPILER("as", AsCompiler) ADD_COMPILER("ld", LdCompiler) +// ADD_COMPILER("cpp2mpl", Cpp2MplCompiler) compilerSelector = new CompilerSelectorImpl(); } @@ -84,6 +85,8 @@ ErrorCode CompilerFactory::DeleteTmpFiles(const MplOptions &mplOptions, const st } ErrorCode CompilerFactory::Compile(MplOptions &mplOptions) { + // Code_exp: GetInstance triggered constructor, which triggered adding of compilers and new CompilerSelectorImpl + // Code_exp: Constructor also filled supported compilers if (compileFinished) { LogInfo::MapleLogger() << "Failed! Compilation has been completed in previous time and multi-instance compilation is not supported\n"; @@ -94,6 +97,7 @@ ErrorCode CompilerFactory::Compile(MplOptions &mplOptions) { LogInfo::MapleLogger() << "Failed! Compiler is null." << "\n"; return kErrorCompileFail; } + // Code_exp: Selecting compiler chain user wants into compilers vector ErrorCode ret = compilerSelector->Select(supportedCompilers, mplOptions, compilers); if (ret != kErrorNoError) { return ret; diff --git a/src/mapleall/maple_driver/src/cpp2mpl_compiler.cpp b/src/mapleall/maple_driver/src/cpp2mpl_compiler.cpp new file mode 100644 index 0000000000..dcea2aa773 --- /dev/null +++ b/src/mapleall/maple_driver/src/cpp2mpl_compiler.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * 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 v2 for more details. + */ +#include +#include "compiler.h" +#include "default_options.def" + +namespace maple { + const std::string &Cpp2MplCompiler::GetBinName() const { + return kBinNameCpp2mpl; + } + + DefaultOption Cpp2MplCompiler::GetDefaultOptions(const MplOptions &options) const { + DefaultOption defaultOptions = { nullptr, 0 }; + defaultOptions.mplOptions = kCpp2MplDefaultOptionsForAst; + defaultOptions.length = sizeof(kCpp2MplDefaultOptionsForAst) / sizeof(MplOption); + + for (uint32_t i = 0; i < defaultOptions.length; ++i) { + defaultOptions.mplOptions[i].SetValue( + FileUtils::AppendMapleRootIfNeeded(defaultOptions.mplOptions[i].GetNeedRootPath(), + defaultOptions.mplOptions[i].GetValue(), + options.GetExeFolder())); + } + return defaultOptions; + } + + void Cpp2MplCompiler::GetTmpFilesToDelete(const MplOptions &mplOptions, std::vector &tempFiles) const { + tempFiles.push_back(mplOptions.GetOutputFolder() + mplOptions.GetOutputName() + ".mpl"); + tempFiles.push_back(mplOptions.GetOutputFolder() + mplOptions.GetOutputName() + ".mplt"); + } + + std::unordered_set Cpp2MplCompiler::GetFinalOutputs(const MplOptions &mplOptions) const { + std::unordered_set finalOutputs; + (void)finalOutputs.insert(mplOptions.GetOutputFolder() + mplOptions.GetOutputName() + ".mpl"); + (void)finalOutputs.insert(mplOptions.GetOutputFolder() + mplOptions.GetOutputName() + ".mplt"); + return finalOutputs; + } +} // namespace maple \ No newline at end of file diff --git a/src/mapleall/maple_driver/src/driver_option_common.cpp b/src/mapleall/maple_driver/src/driver_option_common.cpp index dda7b4487c..c62f26ea7b 100644 --- a/src/mapleall/maple_driver/src/driver_option_common.cpp +++ b/src/mapleall/maple_driver/src/driver_option_common.cpp @@ -138,6 +138,15 @@ const mapleOption::Descriptor usages[] = { " --jbc2mpl-opt \tSet options for jbc2mpl\n", "all", {} }, + { kCpp2mplOpt, + 0, + "", + "cpp2mpl-opt", + kBuildTypeProduct, + kArgCheckPolicyNone, + " --cpp2mpl-opt \tSet options for cpp2mpl\n", + "all", + {} }, { kDex2mplOpt, 0, "", @@ -289,7 +298,7 @@ const mapleOption::Descriptor usages[] = { kArgCheckPolicyBool, " -verbose \t: print informations\n", "all", - { "jbc2mpl", "me", "mpl2mpl", "mplcg" } }, + { "jbc2mpl", "cpp2mpl", "me", "mpl2mpl", "mplcg" } }, { kAllDebug, 0, "", diff --git a/src/mapleall/maple_driver/src/mpl_options.cpp b/src/mapleall/maple_driver/src/mpl_options.cpp index f16918ebb2..1917d5d7ab 100644 --- a/src/mapleall/maple_driver/src/mpl_options.cpp +++ b/src/mapleall/maple_driver/src/mpl_options.cpp @@ -31,6 +31,7 @@ #endif #include "ipa_option.h" #include "jbc2mpl_option.h" +#include "cpp2mpl_option.h" #include "me_option.h" #include "option.h" #include "cg_option.h" @@ -42,12 +43,16 @@ using namespace maplebe; const std::string kMapleDriverVersion = "MapleDriver " + std::to_string(Version::kMajorMplVersion) + "." + std::to_string(Version::kMinorCompilerVersion) + " 20190929"; -const std::vector kMapleCompilers = { "jbc2mpl", +const std::vector kMapleCompilers = { "jbc2mpl", "cpp2mpl", "dex2mpl", "mplipa", - "me", "mpl2mpl", "mplcg" }; + "me", "mpl2mpl", "mplcg"}; // Code_exp: added cpp2mpl int MplOptions::Parse(int argc, char **argv) { + // Code_exp: MplOptions contains std::unique_ptr optionParser which we initialize optionParser.reset(new OptionParser()); + // Code_exp: DOC contains common usages and options(GetInstance triggers usageVec fill), we also fill + // Code_exp: vector rawUsages, multimap usages(with short and long opt. names), + // Code_exp: and add no- for boolean options like no-opt optionParser->RegisteUsages(DriverOptionCommon::GetInstance()); #ifdef INTERGRATE_DRIVER optionParser->RegisteUsages(Dex2mplOptions::GetInstance()); @@ -56,10 +61,13 @@ int MplOptions::Parse(int argc, char **argv) { #endif optionParser->RegisteUsages(IpaOption::GetInstance()); optionParser->RegisteUsages(jbcUsage); + optionParser->RegisteUsages(cppUsage); // Code_exp: need to create enum for cpp and array of Descriptors optionParser->RegisteUsages(Options::GetInstance()); optionParser->RegisteUsages(MeOption::GetInstance()); optionParser->RegisteUsages(CGOptions::GetInstance()); + // Code_exp: Finding folder of maple bin in argv (./ if in cur) exeFolder = FileUtils::GetFileFolder(*argv); + // Code_exp: Parsing fills Options vector of mpl_options with keys, args and descriptors int ret = optionParser->Parse(argc, argv); if (ret != kErrorNoError) { return ret; @@ -134,6 +142,12 @@ ErrorCode MplOptions::HandleGeneralOptions() { return ret; } break; + case kCpp2mplOpt: + ret = UpdatePhaseOption(opt.Args(), kBinNameCpp2mpl); + if (ret != kErrorNoError) { + return ret; + } + break; case kMplipaOpt: ret = UpdatePhaseOption(opt.Args(), kBinNameMplipa); if (ret != kErrorNoError) { @@ -255,6 +269,9 @@ ErrorCode MplOptions::DecideRunningPhases() { bool isNeedMapleComb = true; bool isNeedMplcg = true; switch (inputFileType) { + case InputFileType::kFileTypeAst: + UpdateRunningExe(kBinNameCpp2mpl); + break; case InputFileType::kFileTypeJar: // fall-through case InputFileType::kFileTypeClass: @@ -361,7 +378,11 @@ bool MplOptions::Init(const std::string &inputFile) { } else if (extensionName == "jar") { inputFileType = InputFileType::kFileTypeJar; - } else if (extensionName == "mpl" || extensionName == "bpl") { + } + else if (extensionName == "ast") { + inputFileType = InputFileType::kFileTypeAst; + } + else if (extensionName == "mpl" || extensionName == "bpl") { if (firstInputFile.find("VtableImpl") == std::string::npos) { if (firstInputFile.find(".me.mpl") != std::string::npos) { inputFileType = InputFileType::kFileTypeMeMpl; diff --git a/src/mapleall/maple_driver/src/option_parser.cpp b/src/mapleall/maple_driver/src/option_parser.cpp index 1b7b1c77ed..dc277def1d 100644 --- a/src/mapleall/maple_driver/src/option_parser.cpp +++ b/src/mapleall/maple_driver/src/option_parser.cpp @@ -91,6 +91,7 @@ void OptionParser::RegisteUsages(const MapleDriverOptionBase &base) { InsertOption(usage.longOption, usage); } // Insert usage for extra options + // Code_exp: inserting options with extras like jbc2mpl and dex2mpl InsertExtraUsage(usage); // Add --no-opt for boolean option if (usage.checkPolicy == kArgCheckPolicyBool) { @@ -165,8 +166,11 @@ bool OptionParser::HandleKeyValue(const std::string &key, const std::string &val nonOptionsArgs.push_back(value); return true; } + // Code_exp: in map of keys and descriptors count current key size_t count = usages.count(key); + // Code_exp: find element with this key auto item = usages.find(key); + // Code_exp: get option with correct exeName while (count > 0 && item->second.exeName != exeName) { ++item; --count; @@ -175,6 +179,7 @@ bool OptionParser::HandleKeyValue(const std::string &key, const std::string &val LogInfo::MapleLogger(kLlErr) << ("Unknown Option: " + key) << '\n'; return false; } + // Code_exp: now check required args switch (item->second.checkPolicy) { case kArgCheckPolicyUnknown: LogInfo::MapleLogger(kLlErr) << ("Unknown option " + key) << '\n'; @@ -183,6 +188,7 @@ bool OptionParser::HandleKeyValue(const std::string &key, const std::string &val case kArgCheckPolicyOptional: break; case kArgCheckPolicyRequired: + // Code_exp: if (value.empty() && !isValueEmpty) { LogInfo::MapleLogger(kLlErr) << ("Option " + key + " requires an argument.") << '\n'; return false; @@ -266,9 +272,12 @@ bool OptionParser::CheckOpt(const std::string option, std::string &lastKey, } } size_t pos = option.find('='); + // Code_exp: options args can be specified either by = i.e. --run=jbc2mpl or with a space bar: + // Code_exp: --infile file1,file2 that's why we need to take that into account if (pos != std::string::npos) { ASSERT(pos > 0, "option should not begin with symbol '='"); isLastMatch = false; + // Code_exp: here we get option name, its arg after = and whether it's empty or not std::string key = option.substr(0, pos); std::string value = option.substr(pos + 1); isValueEmpty = value.empty(); @@ -276,6 +285,7 @@ bool OptionParser::CheckOpt(const std::string option, std::string &lastKey, } else { auto item = usages.find(option); if (item != usages.end()) { + // Code_exp if there is no = in string, but key is found in map check arg policy and act accordingly if (item->second.checkPolicy == kArgCheckPolicyRequired || item->second.checkPolicy == kArgCheckPolicyNumeric) { lastKey = option; isLastMatch = true; @@ -293,13 +303,17 @@ bool OptionParser::CheckOpt(const std::string option, std::string &lastKey, ErrorCode OptionParser::HandleInputArgs(const std::vector &inputArgs, const std::string &exeName, std::vector &inputOption, bool isAllOption) { + // Code_exp: previous option flag bool isLastMatchOpt = false; + // Code_exp: previous key std::string lastKey = ""; bool ret = true; for (size_t i = 0; i < inputArgs.size(); ++i) { + // Code_exp: if arg is empty - skip it if (inputArgs[i] == "") { continue; } + // Code_exp: check for - or -- bool isMatchLongOpt = false; bool isMatchShortOpt = false; MatchedIndex index = kMatchNone; @@ -314,9 +328,13 @@ ErrorCode OptionParser::HandleInputArgs(const std::vector &inputArg } else if (index == kMatchLongOpt) { isMatchLongOpt = true; } + //Code_exp: here we remove option marker(- or --) std::string arg = inputArgs[i].substr(index); bool isOptMatched = (isMatchLongOpt || isMatchShortOpt); + // Code_exp: if option marker is matched and previous match is not option if (!isLastMatchOpt && isOptMatched) { + // Code_exp: arg - one option from argv, inputOption - vec of options where we will put them + // Code_exp: exeName = "all" ret = CheckOpt(arg, lastKey, isLastMatchOpt, inputOption, exeName); } else if (isLastMatchOpt && !isOptMatched) { isLastMatchOpt = false; @@ -345,6 +363,7 @@ ErrorCode OptionParser::Parse(int argc, char **argv, const std::string exeName) --argc; ++argv; // skip program name argv[0] if present } + // Code_exp: if there are no more args print how to use and return initialization error if (argc == 0 || *argv == nullptr) { PrintUsage(exeName); LogInfo::MapleLogger(kLlErr) << "No input files!" << '\n'; -- Gitee From ba6c528dc10c5777bdc8aae1bba0faf6769c3b99 Mon Sep 17 00:00:00 2001 From: antyshevtg Date: Wed, 28 Jul 2021 18:18:29 +0300 Subject: [PATCH 03/16] Unfinished version of cpp2mpl 2 --- src/mapleall/maple_driver/include/cpp2mpl_option.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mapleall/maple_driver/include/cpp2mpl_option.h b/src/mapleall/maple_driver/include/cpp2mpl_option.h index 978d236d05..64dd75eac6 100644 --- a/src/mapleall/maple_driver/include/cpp2mpl_option.h +++ b/src/mapleall/maple_driver/include/cpp2mpl_option.h @@ -52,7 +52,7 @@ namespace maple { { kUnknown, 0, "", "", mapleOption::kBuildTypeAll, mapleOption::kArgCheckPolicyNone, "", - "jbc2mpl", + "cpp2mpl", {} } }; } // namespace maple -- Gitee From 33003206d0d9e9fa6949c7135be69c3bf7707cc5 Mon Sep 17 00:00:00 2001 From: antyshevtg Date: Wed, 28 Jul 2021 18:31:27 +0300 Subject: [PATCH 04/16] Fixed map overflow bug --- .../maple_driver/include/cpp2mpl_option.h | 41 +++++++++++++------ 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/src/mapleall/maple_driver/include/cpp2mpl_option.h b/src/mapleall/maple_driver/include/cpp2mpl_option.h index e89cfb466e..1bd0a8dd5e 100644 --- a/src/mapleall/maple_driver/include/cpp2mpl_option.h +++ b/src/mapleall/maple_driver/include/cpp2mpl_option.h @@ -22,19 +22,34 @@ enum CppOptionIndex { }; const mapleOption::Descriptor cppUsage[] = { -{ kUnknown, 0, "", "", mapleOption::kBuildTypeAll, mapleOption::kArgCheckPolicyUnknown, - "========================================\n" - " Usage: cpp2mpl [ options ]\n" - " options:\n", - "cpp2mpl", - {} }, - -{ kInAst, 0, "", "in-ast", mapleOption::kBuildTypeAll, mapleOption::kArgCheckPolicyRequired, - "-in-ast file1.ast,file2.ast\n" - " : input ast files", - "cpp2mpl", - {} } -}; + { kUnknown, 0, "", "", mapleOption::kBuildTypeAll, mapleOption::kArgCheckPolicyUnknown, + "========================================\n" + " Usage: cpp2mpl [ options ]\n" + " options:\n", + "cpp2mpl", + {} }, + + { kInAst, 0, "", "inast", mapleOption::kBuildTypeAll, mapleOption::kArgCheckPolicyRequired, + " -inast file1.ast,file2.ast\n" + " : input ast files", + "cpp2mpl", + {} }, + + { kInCpp, 0, "", "incpp", mapleOption::kBuildTypeAll, mapleOption::kArgCheckPolicyRequired, + " -incpp file1.cpp,file2.cpp\n" + " : input cpp files", + "cpp2mpl", + {} }, + + { kDex2mplHelp, 0, "h", "help", mapleOption::kBuildTypeExperimental, mapleOption::kArgCheckPolicyNone, + " -h, --help : print usage and exit.\n", + "cpp2mpl", + {} }, + + { kUnknown, 0, "", "", mapleOption::kBuildTypeAll, mapleOption::kArgCheckPolicyNone, + "", + "cpp2mpl", + {} }; } // namespace maple #endif //MAPLE_CPP2MPL_OPTION_H -- Gitee From ff2a6fe17b5f19f25058084d9375a06fb155ed21 Mon Sep 17 00:00:00 2001 From: antyshevtg Date: Thu, 29 Jul 2021 11:56:54 +0300 Subject: [PATCH 05/16] Fixed consequences of merge conflicts --- src/mapleall/maple_driver/include/compiler.h | 4 ++-- src/mapleall/maple_driver/include/cpp2mpl_option.h | 9 ++++++--- src/mapleall/maple_driver/include/mpl_options.h | 1 - src/mapleall/maple_driver/src/compiler_factory.cpp | 2 +- src/mapleall/maple_driver/src/mpl_options.cpp | 8 +------- 5 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/mapleall/maple_driver/include/compiler.h b/src/mapleall/maple_driver/include/compiler.h index 65db76170e..1b9159fd5d 100644 --- a/src/mapleall/maple_driver/include/compiler.h +++ b/src/mapleall/maple_driver/include/compiler.h @@ -114,7 +114,7 @@ class Jbc2MplCompiler : public Compiler { std::unordered_set GetFinalOutputs(const MplOptions &mplOptions) const override; }; -/*class Cpp2MplCompiler : public Compiler { +class Cpp2MplCompiler : public Compiler { public: explicit Cpp2MplCompiler(const std::string &name) : Compiler(name) {} @@ -127,7 +127,7 @@ class Jbc2MplCompiler : public Compiler { DefaultOption GetDefaultOptions(const MplOptions &options) const override; void GetTmpFilesToDelete(const MplOptions &mplOptions, std::vector &tempFiles) const override; std::unordered_set GetFinalOutputs(const MplOptions &mplOptions) const override; -};*/ +}; class Dex2MplCompiler : public Compiler { public: diff --git a/src/mapleall/maple_driver/include/cpp2mpl_option.h b/src/mapleall/maple_driver/include/cpp2mpl_option.h index 1bd0a8dd5e..01a9811245 100644 --- a/src/mapleall/maple_driver/include/cpp2mpl_option.h +++ b/src/mapleall/maple_driver/include/cpp2mpl_option.h @@ -18,7 +18,9 @@ namespace maple { enum CppOptionIndex { - kInAst + kInAst, + kInCpp, + kCpp2mplHelp, }; const mapleOption::Descriptor cppUsage[] = { @@ -41,7 +43,7 @@ const mapleOption::Descriptor cppUsage[] = { "cpp2mpl", {} }, - { kDex2mplHelp, 0, "h", "help", mapleOption::kBuildTypeExperimental, mapleOption::kArgCheckPolicyNone, + { kCpp2mplHelp, 0, "h", "help", mapleOption::kBuildTypeExperimental, mapleOption::kArgCheckPolicyNone, " -h, --help : print usage and exit.\n", "cpp2mpl", {} }, @@ -49,7 +51,8 @@ const mapleOption::Descriptor cppUsage[] = { { kUnknown, 0, "", "", mapleOption::kBuildTypeAll, mapleOption::kArgCheckPolicyNone, "", "cpp2mpl", - {} }; + {} } +}; } // namespace maple #endif //MAPLE_CPP2MPL_OPTION_H diff --git a/src/mapleall/maple_driver/include/mpl_options.h b/src/mapleall/maple_driver/include/mpl_options.h index b44aa98952..ef3aaeb87b 100644 --- a/src/mapleall/maple_driver/include/mpl_options.h +++ b/src/mapleall/maple_driver/include/mpl_options.h @@ -32,7 +32,6 @@ namespace maple { enum InputFileType { kFileTypeNone, kFileTypeClass, - kFileTypeAst, kFileTypeJar, kFileTypeAst, // Code_exp: ast file type kFileTypeDex, diff --git a/src/mapleall/maple_driver/src/compiler_factory.cpp b/src/mapleall/maple_driver/src/compiler_factory.cpp index 6c5278a4f2..f51c2789ce 100644 --- a/src/mapleall/maple_driver/src/compiler_factory.cpp +++ b/src/mapleall/maple_driver/src/compiler_factory.cpp @@ -42,7 +42,7 @@ CompilerFactory::CompilerFactory() { ADD_COMPILER("mplcg", MplcgCompiler) ADD_COMPILER("as", AsCompiler) ADD_COMPILER("ld", LdCompiler) -// ADD_COMPILER("cpp2mpl", Cpp2MplCompiler) + ADD_COMPILER("cpp2mpl", Cpp2MplCompiler) compilerSelector = new CompilerSelectorImpl(); } diff --git a/src/mapleall/maple_driver/src/mpl_options.cpp b/src/mapleall/maple_driver/src/mpl_options.cpp index 20a93db503..7ba1931cdc 100644 --- a/src/mapleall/maple_driver/src/mpl_options.cpp +++ b/src/mapleall/maple_driver/src/mpl_options.cpp @@ -148,12 +148,6 @@ ErrorCode MplOptions::HandleGeneralOptions() { return ret; } break; - case kCpp2mplOpt: - ret = UpdatePhaseOption(opt.Args(), kBinNameCpp2mpl); - if (ret != kErrorNoError) { - return ret; - } - break; case kMplipaOpt: ret = UpdatePhaseOption(opt.Args(), kBinNameMplipa); if (ret != kErrorNoError) { @@ -635,4 +629,4 @@ void MplOptions::PrintDetailCommand(bool isBeforeParse) { << printCommandStr << " " << GetInputFileNameForPrint() << '\n'; } } -} // namespace maple +} // namespace maple -- Gitee From cf815c77aada355094bdbd4e37bc5ae02d280791 Mon Sep 17 00:00:00 2001 From: antyshevtg Date: Thu, 29 Jul 2021 16:37:27 +0300 Subject: [PATCH 06/16] Binary maple support of ast to mpl via cpp2mpl option (alpha version) --- src/mapleall/maple_driver/include/compiler_factory.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mapleall/maple_driver/include/compiler_factory.h b/src/mapleall/maple_driver/include/compiler_factory.h index 4a6046d22b..d30f680e98 100644 --- a/src/mapleall/maple_driver/include/compiler_factory.h +++ b/src/mapleall/maple_driver/include/compiler_factory.h @@ -38,6 +38,7 @@ class CompilerFactory { void Insert(const std::string &name, Compiler *value); ErrorCode DeleteTmpFiles(const MplOptions &mplOptions, const std::vector &tempFiles, const std::unordered_set &finalOutputs) const; + // Code_exp: it is from compiler_selector.h: using SupportedCompilers = std::unordered_map; SupportedCompilers supportedCompilers; CompilerSelector *compilerSelector; std::unique_ptr theModule; -- Gitee From 85d799f8b5404808eb86cffe4e0b5e911d10bdc6 Mon Sep 17 00:00:00 2001 From: antyshevtg Date: Fri, 30 Jul 2021 11:00:17 +0300 Subject: [PATCH 07/16] Fixed codestyle --- .../maple_driver/defs/default_options.def | 2 +- src/mapleall/maple_driver/include/compiler.h | 2 - .../maple_driver/include/compiler_factory.h | 1 - .../maple_driver/include/cpp2mpl_option.h | 56 +++++++++---------- .../include/driver_option_common.h | 2 +- .../maple_driver/include/mpl_options.h | 2 +- .../maple_driver/src/compiler_factory.cpp | 4 -- .../maple_driver/src/cpp2mpl_compiler.cpp | 48 ++++++++-------- src/mapleall/maple_driver/src/mpl_options.cpp | 13 +---- .../maple_driver/src/option_parser.cpp | 20 ------- 10 files changed, 57 insertions(+), 93 deletions(-) diff --git a/src/mapleall/maple_driver/defs/default_options.def b/src/mapleall/maple_driver/defs/default_options.def index e5296287f1..6e551e9162 100644 --- a/src/mapleall/maple_driver/defs/default_options.def +++ b/src/mapleall/maple_driver/defs/default_options.def @@ -108,7 +108,7 @@ static MplOption kMeDefaultOptionsO2ForC[] = { static MplOption kMplcgDefaultOptionsO2ForC[] = { #include "default/O2_options_mplcg_c.def" }; -// Code_exp: standard options for cpp2mpl +// 00 cpp2mpl options static MplOption kCpp2MplDefaultOptionsForAst[] = { #include "default/O0_options_cpp2mpl.def" }; diff --git a/src/mapleall/maple_driver/include/compiler.h b/src/mapleall/maple_driver/include/compiler.h index 1b9159fd5d..a3491ed83b 100644 --- a/src/mapleall/maple_driver/include/compiler.h +++ b/src/mapleall/maple_driver/include/compiler.h @@ -120,8 +120,6 @@ class Cpp2MplCompiler : public Compiler { ~Cpp2MplCompiler() = default; - //ErrorCode Compile(MplOptions &options, std::unique_ptr &theModule); - private: const std::string &GetBinName() const override; DefaultOption GetDefaultOptions(const MplOptions &options) const override; diff --git a/src/mapleall/maple_driver/include/compiler_factory.h b/src/mapleall/maple_driver/include/compiler_factory.h index d30f680e98..4a6046d22b 100644 --- a/src/mapleall/maple_driver/include/compiler_factory.h +++ b/src/mapleall/maple_driver/include/compiler_factory.h @@ -38,7 +38,6 @@ class CompilerFactory { void Insert(const std::string &name, Compiler *value); ErrorCode DeleteTmpFiles(const MplOptions &mplOptions, const std::vector &tempFiles, const std::unordered_set &finalOutputs) const; - // Code_exp: it is from compiler_selector.h: using SupportedCompilers = std::unordered_map; SupportedCompilers supportedCompilers; CompilerSelector *compilerSelector; std::unique_ptr theModule; diff --git a/src/mapleall/maple_driver/include/cpp2mpl_option.h b/src/mapleall/maple_driver/include/cpp2mpl_option.h index 01a9811245..01433ddcb0 100644 --- a/src/mapleall/maple_driver/include/cpp2mpl_option.h +++ b/src/mapleall/maple_driver/include/cpp2mpl_option.h @@ -24,34 +24,34 @@ enum CppOptionIndex { }; const mapleOption::Descriptor cppUsage[] = { - { kUnknown, 0, "", "", mapleOption::kBuildTypeAll, mapleOption::kArgCheckPolicyUnknown, - "========================================\n" - " Usage: cpp2mpl [ options ]\n" - " options:\n", - "cpp2mpl", - {} }, - - { kInAst, 0, "", "inast", mapleOption::kBuildTypeAll, mapleOption::kArgCheckPolicyRequired, - " -inast file1.ast,file2.ast\n" - " : input ast files", - "cpp2mpl", - {} }, - - { kInCpp, 0, "", "incpp", mapleOption::kBuildTypeAll, mapleOption::kArgCheckPolicyRequired, - " -incpp file1.cpp,file2.cpp\n" - " : input cpp files", - "cpp2mpl", - {} }, - - { kCpp2mplHelp, 0, "h", "help", mapleOption::kBuildTypeExperimental, mapleOption::kArgCheckPolicyNone, - " -h, --help : print usage and exit.\n", - "cpp2mpl", - {} }, - - { kUnknown, 0, "", "", mapleOption::kBuildTypeAll, mapleOption::kArgCheckPolicyNone, - "", - "cpp2mpl", - {} } + { kUnknown, 0, "", "", mapleOption::kBuildTypeAll, mapleOption::kArgCheckPolicyUnknown, + "========================================\n" + " Usage: cpp2mpl [ options ]\n" + " options:\n", + "cpp2mpl", + {} }, + + { kInAst, 0, "", "inast", mapleOption::kBuildTypeAll, mapleOption::kArgCheckPolicyRequired, + " -in-ast file1.ast,file2.ast\n" + " : input ast files", + "cpp2mpl", + {} }, + + { kInCpp, 0, "", "incpp", mapleOption::kBuildTypeAll, mapleOption::kArgCheckPolicyRequired, + " -in-cpp file1.cpp,file2.cpp\n" + " : input cpp files", + "cpp2mpl", + {} }, + + { kCpp2mplHelp, 0, "h", "help", mapleOption::kBuildTypeExperimental, mapleOption::kArgCheckPolicyNone, + " -h, --help : print usage and exit.\n", + "cpp2mpl", + {} }, + + { kUnknown, 0, "", "", mapleOption::kBuildTypeAll, mapleOption::kArgCheckPolicyNone, + "", + "cpp2mpl", + {} } }; } // namespace maple diff --git a/src/mapleall/maple_driver/include/driver_option_common.h b/src/mapleall/maple_driver/include/driver_option_common.h index f086ce5f3c..92eadc2bba 100644 --- a/src/mapleall/maple_driver/include/driver_option_common.h +++ b/src/mapleall/maple_driver/include/driver_option_common.h @@ -28,7 +28,7 @@ enum DriverOptionIndex { kOptimization2, kWithIpa, kJbc2mplOpt, - kCpp2mplOpt, // Code_exp: will be used in mpl_options.cpp function HandleGeneralOptions + kCpp2mplOpt, kDex2mplOpt, kMplipaOpt, kVerify, diff --git a/src/mapleall/maple_driver/include/mpl_options.h b/src/mapleall/maple_driver/include/mpl_options.h index ef3aaeb87b..0f37d87b17 100644 --- a/src/mapleall/maple_driver/include/mpl_options.h +++ b/src/mapleall/maple_driver/include/mpl_options.h @@ -33,7 +33,7 @@ enum InputFileType { kFileTypeNone, kFileTypeClass, kFileTypeJar, - kFileTypeAst, // Code_exp: ast file type + kFileTypeAst, kFileTypeDex, kFileTypeMpl, kFileTypeVtableImplMpl, diff --git a/src/mapleall/maple_driver/src/compiler_factory.cpp b/src/mapleall/maple_driver/src/compiler_factory.cpp index f51c2789ce..03a420e35c 100644 --- a/src/mapleall/maple_driver/src/compiler_factory.cpp +++ b/src/mapleall/maple_driver/src/compiler_factory.cpp @@ -42,7 +42,6 @@ CompilerFactory::CompilerFactory() { ADD_COMPILER("mplcg", MplcgCompiler) ADD_COMPILER("as", AsCompiler) ADD_COMPILER("ld", LdCompiler) - ADD_COMPILER("cpp2mpl", Cpp2MplCompiler) compilerSelector = new CompilerSelectorImpl(); } @@ -86,8 +85,6 @@ ErrorCode CompilerFactory::DeleteTmpFiles(const MplOptions &mplOptions, const st } ErrorCode CompilerFactory::Compile(MplOptions &mplOptions) { - // Code_exp: GetInstance triggered constructor, which triggered adding of compilers and new CompilerSelectorImpl - // Code_exp: Constructor also filled supported compilers if (compileFinished) { LogInfo::MapleLogger() << "Failed! Compilation has been completed in previous time and multi-instance compilation is not supported\n"; @@ -98,7 +95,6 @@ ErrorCode CompilerFactory::Compile(MplOptions &mplOptions) { LogInfo::MapleLogger() << "Failed! Compiler is null." << "\n"; return kErrorCompileFail; } - // Code_exp: Selecting compiler chain user wants into compilers vector ErrorCode ret = compilerSelector->Select(supportedCompilers, mplOptions, compilers); if (ret != kErrorNoError) { return ret; diff --git a/src/mapleall/maple_driver/src/cpp2mpl_compiler.cpp b/src/mapleall/maple_driver/src/cpp2mpl_compiler.cpp index dcea2aa773..710d42fa23 100644 --- a/src/mapleall/maple_driver/src/cpp2mpl_compiler.cpp +++ b/src/mapleall/maple_driver/src/cpp2mpl_compiler.cpp @@ -17,33 +17,33 @@ #include "default_options.def" namespace maple { - const std::string &Cpp2MplCompiler::GetBinName() const { - return kBinNameCpp2mpl; - } +const std::string &Cpp2MplCompiler::GetBinName() const { + return kBinNameCpp2mpl; +} - DefaultOption Cpp2MplCompiler::GetDefaultOptions(const MplOptions &options) const { - DefaultOption defaultOptions = { nullptr, 0 }; - defaultOptions.mplOptions = kCpp2MplDefaultOptionsForAst; - defaultOptions.length = sizeof(kCpp2MplDefaultOptionsForAst) / sizeof(MplOption); +DefaultOption Cpp2MplCompiler::GetDefaultOptions(const MplOptions &options) const { + DefaultOption defaultOptions = { nullptr, 0 }; + defaultOptions.mplOptions = kCpp2MplDefaultOptionsForAst; + defaultOptions.length = sizeof(kCpp2MplDefaultOptionsForAst) / sizeof(MplOption); - for (uint32_t i = 0; i < defaultOptions.length; ++i) { - defaultOptions.mplOptions[i].SetValue( - FileUtils::AppendMapleRootIfNeeded(defaultOptions.mplOptions[i].GetNeedRootPath(), - defaultOptions.mplOptions[i].GetValue(), - options.GetExeFolder())); - } - return defaultOptions; + for (uint32_t i = 0; i < defaultOptions.length; ++i) { + defaultOptions.mplOptions[i].SetValue( + FileUtils::AppendMapleRootIfNeeded(defaultOptions.mplOptions[i].GetNeedRootPath(), + defaultOptions.mplOptions[i].GetValue(), + options.GetExeFolder())); } + return defaultOptions; +} - void Cpp2MplCompiler::GetTmpFilesToDelete(const MplOptions &mplOptions, std::vector &tempFiles) const { - tempFiles.push_back(mplOptions.GetOutputFolder() + mplOptions.GetOutputName() + ".mpl"); - tempFiles.push_back(mplOptions.GetOutputFolder() + mplOptions.GetOutputName() + ".mplt"); - } +void Cpp2MplCompiler::GetTmpFilesToDelete(const MplOptions &mplOptions, std::vector &tempFiles) const { + tempFiles.push_back(mplOptions.GetOutputFolder() + mplOptions.GetOutputName() + ".mpl"); + tempFiles.push_back(mplOptions.GetOutputFolder() + mplOptions.GetOutputName() + ".mplt"); +} - std::unordered_set Cpp2MplCompiler::GetFinalOutputs(const MplOptions &mplOptions) const { - std::unordered_set finalOutputs; - (void)finalOutputs.insert(mplOptions.GetOutputFolder() + mplOptions.GetOutputName() + ".mpl"); - (void)finalOutputs.insert(mplOptions.GetOutputFolder() + mplOptions.GetOutputName() + ".mplt"); - return finalOutputs; - } +std::unordered_set Cpp2MplCompiler::GetFinalOutputs(const MplOptions &mplOptions) const { + std::unordered_set finalOutputs; + (void)finalOutputs.insert(mplOptions.GetOutputFolder() + mplOptions.GetOutputName() + ".mpl"); + (void)finalOutputs.insert(mplOptions.GetOutputFolder() + mplOptions.GetOutputName() + ".mplt"); + return finalOutputs; +} } // namespace maple \ No newline at end of file diff --git a/src/mapleall/maple_driver/src/mpl_options.cpp b/src/mapleall/maple_driver/src/mpl_options.cpp index 7ba1931cdc..f3c9a68348 100644 --- a/src/mapleall/maple_driver/src/mpl_options.cpp +++ b/src/mapleall/maple_driver/src/mpl_options.cpp @@ -45,14 +45,10 @@ const std::string kMapleDriverVersion = "MapleDriver " + std::to_string(Version: const std::vector kMapleCompilers = { "jbc2mpl", "cpp2mpl", "dex2mpl", "mplipa", - "me", "mpl2mpl", "mplcg"}; // Code_exp: added cpp2mpl + "me", "mpl2mpl", "mplcg"}; int MplOptions::Parse(int argc, char **argv) { - // Code_exp: MplOptions contains std::unique_ptr optionParser which we initialize optionParser.reset(new OptionParser()); - // Code_exp: DOC contains common usages and options(GetInstance triggers usageVec fill), we also fill - // Code_exp: vector rawUsages, multimap usages(with short and long opt. names), - // Code_exp: and add no- for boolean options like no-opt optionParser->RegisteUsages(DriverOptionCommon::GetInstance()); #ifdef INTERGRATE_DRIVER optionParser->RegisteUsages(Dex2mplOptions::GetInstance()); @@ -61,13 +57,11 @@ int MplOptions::Parse(int argc, char **argv) { #endif optionParser->RegisteUsages(IpaOption::GetInstance()); optionParser->RegisteUsages(jbcUsage); - optionParser->RegisteUsages(cppUsage); // Code_exp: need to create enum for cpp and array of Descriptors + optionParser->RegisteUsages(cppUsage); optionParser->RegisteUsages(Options::GetInstance()); optionParser->RegisteUsages(MeOption::GetInstance()); optionParser->RegisteUsages(CGOptions::GetInstance()); - // Code_exp: Finding folder of maple bin in argv (./ if in cur) exeFolder = FileUtils::GetFileFolder(*argv); - // Code_exp: Parsing fills Options vector of mpl_options with keys, args and descriptors int ret = optionParser->Parse(argc, argv); if (ret != kErrorNoError) { return ret; @@ -382,9 +376,6 @@ bool MplOptions::Init(const std::string &inputFile) { else if (extensionName == "jar") { inputFileType = InputFileType::kFileTypeJar; } - else if (extensionName == "ast") { - inputFileType = InputFileType::kFileTypeAst; - } else if (extensionName == "mpl" || extensionName == "bpl") { if (firstInputFile.find("VtableImpl") == std::string::npos) { if (firstInputFile.find(".me.mpl") != std::string::npos) { diff --git a/src/mapleall/maple_driver/src/option_parser.cpp b/src/mapleall/maple_driver/src/option_parser.cpp index 702bd3ad99..1b7b1c77ed 100644 --- a/src/mapleall/maple_driver/src/option_parser.cpp +++ b/src/mapleall/maple_driver/src/option_parser.cpp @@ -91,7 +91,6 @@ void OptionParser::RegisteUsages(const MapleDriverOptionBase &base) { InsertOption(usage.longOption, usage); } // Insert usage for extra options - // Code_exp: inserting options with extras like jbc2mpl and dex2mpl InsertExtraUsage(usage); // Add --no-opt for boolean option if (usage.checkPolicy == kArgCheckPolicyBool) { @@ -166,11 +165,8 @@ bool OptionParser::HandleKeyValue(const std::string &key, const std::string &val nonOptionsArgs.push_back(value); return true; } - // Code_exp: in map of keys and descriptors count current key size_t count = usages.count(key); - // Code_exp: find element with this key auto item = usages.find(key); - // Code_exp: get option with correct exeName while (count > 0 && item->second.exeName != exeName) { ++item; --count; @@ -179,7 +175,6 @@ bool OptionParser::HandleKeyValue(const std::string &key, const std::string &val LogInfo::MapleLogger(kLlErr) << ("Unknown Option: " + key) << '\n'; return false; } - // Code_exp: now check required args switch (item->second.checkPolicy) { case kArgCheckPolicyUnknown: LogInfo::MapleLogger(kLlErr) << ("Unknown option " + key) << '\n'; @@ -188,7 +183,6 @@ bool OptionParser::HandleKeyValue(const std::string &key, const std::string &val case kArgCheckPolicyOptional: break; case kArgCheckPolicyRequired: - // Code_exp: if (value.empty() && !isValueEmpty) { LogInfo::MapleLogger(kLlErr) << ("Option " + key + " requires an argument.") << '\n'; return false; @@ -272,12 +266,9 @@ bool OptionParser::CheckOpt(const std::string option, std::string &lastKey, } } size_t pos = option.find('='); - // Code_exp: options args can be specified either by = i.e. --run=jbc2mpl or with a space bar: - // Code_exp: --infile file1,file2 that's why we need to take that into account if (pos != std::string::npos) { ASSERT(pos > 0, "option should not begin with symbol '='"); isLastMatch = false; - // Code_exp: here we get option name, its arg after = and whether it's empty or not std::string key = option.substr(0, pos); std::string value = option.substr(pos + 1); isValueEmpty = value.empty(); @@ -285,7 +276,6 @@ bool OptionParser::CheckOpt(const std::string option, std::string &lastKey, } else { auto item = usages.find(option); if (item != usages.end()) { - // Code_exp if there is no = in string, but key is found in map check arg policy and act accordingly if (item->second.checkPolicy == kArgCheckPolicyRequired || item->second.checkPolicy == kArgCheckPolicyNumeric) { lastKey = option; isLastMatch = true; @@ -303,17 +293,13 @@ bool OptionParser::CheckOpt(const std::string option, std::string &lastKey, ErrorCode OptionParser::HandleInputArgs(const std::vector &inputArgs, const std::string &exeName, std::vector &inputOption, bool isAllOption) { - // Code_exp: previous option flag bool isLastMatchOpt = false; - // Code_exp: previous key std::string lastKey = ""; bool ret = true; for (size_t i = 0; i < inputArgs.size(); ++i) { - // Code_exp: if arg is empty - skip it if (inputArgs[i] == "") { continue; } - // Code_exp: check for - or -- bool isMatchLongOpt = false; bool isMatchShortOpt = false; MatchedIndex index = kMatchNone; @@ -323,19 +309,14 @@ ErrorCode OptionParser::HandleInputArgs(const std::vector &inputArg index = kMatchLongOpt; } } - // Code_exp: here we remove - or -- marker if (index == kMatchShortOpt) { isMatchShortOpt = true; } else if (index == kMatchLongOpt) { isMatchLongOpt = true; } - //Code_exp: here we remove option marker(- or --) std::string arg = inputArgs[i].substr(index); bool isOptMatched = (isMatchLongOpt || isMatchShortOpt); - // Code_exp: if option marker is matched and previous match is not option if (!isLastMatchOpt && isOptMatched) { - // Code_exp: arg - one option from argv, inputOption - vec of options where we will put them - // Code_exp: exeName = "all" ret = CheckOpt(arg, lastKey, isLastMatchOpt, inputOption, exeName); } else if (isLastMatchOpt && !isOptMatched) { isLastMatchOpt = false; @@ -364,7 +345,6 @@ ErrorCode OptionParser::Parse(int argc, char **argv, const std::string exeName) --argc; ++argv; // skip program name argv[0] if present } - // Code_exp: if there are no more args print how to use and return initialization error if (argc == 0 || *argv == nullptr) { PrintUsage(exeName); LogInfo::MapleLogger(kLlErr) << "No input files!" << '\n'; -- Gitee From 96e02c3ca2c705786051b50ee531f4877014c464 Mon Sep 17 00:00:00 2001 From: antyshevtg Date: Tue, 3 Aug 2021 17:23:03 +0300 Subject: [PATCH 08/16] As usage options template --- src/mapleall/maple_driver/include/as_option.h | 52 +++++++++++++++++++ .../include/driver_option_common.h | 1 + .../maple_driver/src/driver_option_common.cpp | 8 +++ src/mapleall/maple_driver/src/mpl_options.cpp | 10 +++- 4 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 src/mapleall/maple_driver/include/as_option.h diff --git a/src/mapleall/maple_driver/include/as_option.h b/src/mapleall/maple_driver/include/as_option.h new file mode 100644 index 0000000000..63862beb31 --- /dev/null +++ b/src/mapleall/maple_driver/include/as_option.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * 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 v2 for more details. + */ +#ifndef MAPLE_AS_OPTION_H +#define MAPLE_AS_OPTION_H +#include "option_descriptor.h" + +namespace maple { +enum CppOptionIndex { + kInS, + kAsHelp, +}; + +const mapleOption::Descriptor asUsage[] = { + { kUnknown, 0, "", "", mapleOption::kBuildTypeAll, mapleOption::kArgCheckPolicyUnknown, + "========================================\n" + " Usage: as [ options ]\n" + " options:\n", + "as", + {} }, + + { kInS, 0, "", "in-s", mapleOption::kBuildTypeAll, mapleOption::kArgCheckPolicyRequired, + " --in-s file1.s,file2.s\n" + " : input asm files", + "as", + {} }, + + + { kAsHelp, 0, "h", "help", mapleOption::kBuildTypeExperimental, mapleOption::kArgCheckPolicyNone, + " -h, --help : print usage and exit.\n", + "as", + {} }, + + { kUnknown, 0, "", "", mapleOption::kBuildTypeAll, mapleOption::kArgCheckPolicyNone, + "", + "as", + {} } +}; +} // namespace maple + +#endif // \ No newline at end of file diff --git a/src/mapleall/maple_driver/include/driver_option_common.h b/src/mapleall/maple_driver/include/driver_option_common.h index 92eadc2bba..4a4e0761d3 100644 --- a/src/mapleall/maple_driver/include/driver_option_common.h +++ b/src/mapleall/maple_driver/include/driver_option_common.h @@ -29,6 +29,7 @@ enum DriverOptionIndex { kWithIpa, kJbc2mplOpt, kCpp2mplOpt, + kAsOpt, kDex2mplOpt, kMplipaOpt, kVerify, diff --git a/src/mapleall/maple_driver/src/driver_option_common.cpp b/src/mapleall/maple_driver/src/driver_option_common.cpp index c62f26ea7b..04a85733ed 100644 --- a/src/mapleall/maple_driver/src/driver_option_common.cpp +++ b/src/mapleall/maple_driver/src/driver_option_common.cpp @@ -147,6 +147,14 @@ const mapleOption::Descriptor usages[] = { " --cpp2mpl-opt \tSet options for cpp2mpl\n", "all", {} }, + { kAsOpt, + 0, + "", + "as-opt", + kBuildTypeProduct, + kArgCheckPolicyNone, + "--as-opt \tSet options for as\n", + {} }, { kDex2mplOpt, 0, "", diff --git a/src/mapleall/maple_driver/src/mpl_options.cpp b/src/mapleall/maple_driver/src/mpl_options.cpp index f3c9a68348..414d2300ee 100644 --- a/src/mapleall/maple_driver/src/mpl_options.cpp +++ b/src/mapleall/maple_driver/src/mpl_options.cpp @@ -31,6 +31,7 @@ #endif #include "ipa_option.h" #include "jbc2mpl_option.h" +#include "as_option.h" #include "cpp2mpl_option.h" #include "me_option.h" #include "option.h" @@ -44,7 +45,7 @@ const std::string kMapleDriverVersion = "MapleDriver " + std::to_string(Version: std::to_string(Version::kMinorCompilerVersion) + " 20190929"; const std::vector kMapleCompilers = { "jbc2mpl", "cpp2mpl", - "dex2mpl", "mplipa", + "dex2mpl", "mplipa", "as", "me", "mpl2mpl", "mplcg"}; int MplOptions::Parse(int argc, char **argv) { @@ -58,6 +59,7 @@ int MplOptions::Parse(int argc, char **argv) { optionParser->RegisteUsages(IpaOption::GetInstance()); optionParser->RegisteUsages(jbcUsage); optionParser->RegisteUsages(cppUsage); + optionParser->RegisteUsages(asUsage); optionParser->RegisteUsages(Options::GetInstance()); optionParser->RegisteUsages(MeOption::GetInstance()); optionParser->RegisteUsages(CGOptions::GetInstance()); @@ -130,6 +132,12 @@ ErrorCode MplOptions::HandleGeneralOptions() { return ret; } break; + case kAsOpt: + ret = UpdatePhaseOption(opt.Args(), kBinNameAs); + if (ret != kErrorNoError) { + return ret; + } + break; case kCpp2mplOpt: ret = UpdatePhaseOption(opt.Args(), kBinNameCpp2mpl); if (ret != kErrorNoError) { -- Gitee From 4bf97e7c70fc7d87d8e549acf766a553f9ce4390 Mon Sep 17 00:00:00 2001 From: antyshevtg Date: Thu, 5 Aug 2021 17:55:03 +0300 Subject: [PATCH 09/16] [mapleall] Minor bug fixes for cpp2mpl and as --- src/mapleall/maple_driver/include/as_option.h | 5 ++--- src/mapleall/maple_driver/include/compiler.h | 1 + src/mapleall/maple_driver/src/as_compiler.cpp | 4 ++-- src/mapleall/maple_driver/src/cpp2mpl_compiler.cpp | 5 +++++ src/mapleall/maple_driver/src/mpl_options.cpp | 3 ++- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/mapleall/maple_driver/include/as_option.h b/src/mapleall/maple_driver/include/as_option.h index 63862beb31..3a32617987 100644 --- a/src/mapleall/maple_driver/include/as_option.h +++ b/src/mapleall/maple_driver/include/as_option.h @@ -17,7 +17,7 @@ #include "option_descriptor.h" namespace maple { -enum CppOptionIndex { +enum AsOptionIndex { kInS, kAsHelp, }; @@ -48,5 +48,4 @@ const mapleOption::Descriptor asUsage[] = { {} } }; } // namespace maple - -#endif // \ No newline at end of file +#endif // MAPLE_AS_OPTION_H \ No newline at end of file diff --git a/src/mapleall/maple_driver/include/compiler.h b/src/mapleall/maple_driver/include/compiler.h index a3491ed83b..7e925a07a3 100644 --- a/src/mapleall/maple_driver/include/compiler.h +++ b/src/mapleall/maple_driver/include/compiler.h @@ -121,6 +121,7 @@ class Cpp2MplCompiler : public Compiler { ~Cpp2MplCompiler() = default; private: + std::string GetBinPath(const MplOptions &options) const override; const std::string &GetBinName() const override; DefaultOption GetDefaultOptions(const MplOptions &options) const override; void GetTmpFilesToDelete(const MplOptions &mplOptions, std::vector &tempFiles) const override; diff --git a/src/mapleall/maple_driver/src/as_compiler.cpp b/src/mapleall/maple_driver/src/as_compiler.cpp index 664d327f35..13056b74cc 100644 --- a/src/mapleall/maple_driver/src/as_compiler.cpp +++ b/src/mapleall/maple_driver/src/as_compiler.cpp @@ -20,12 +20,12 @@ std::string AsCompiler::GetBinPath(const MplOptions&) const { #ifdef ANDROID return "prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin/"; #else - return std::string(kMapleRoot) + "/third-party/ndk/toolchain/bin/"; + return "/usr/bin/"; #endif } const std::string &AsCompiler::GetBinName() const { - return kBinNameGcc; + return kBinNameAs; } DefaultOption AsCompiler::GetDefaultOptions(const MplOptions&) const { diff --git a/src/mapleall/maple_driver/src/cpp2mpl_compiler.cpp b/src/mapleall/maple_driver/src/cpp2mpl_compiler.cpp index 710d42fa23..23eebcbbdb 100644 --- a/src/mapleall/maple_driver/src/cpp2mpl_compiler.cpp +++ b/src/mapleall/maple_driver/src/cpp2mpl_compiler.cpp @@ -14,9 +14,14 @@ */ #include #include "compiler.h" +#include "file_utils.h" #include "default_options.def" namespace maple { +std::string Cpp2MplCompiler::GetBinPath(const MplOptions&) const{ + return std::string(std::getenv(kMapleRoot)) + "/output/aarch64-clang-debug/bin/"; +} + const std::string &Cpp2MplCompiler::GetBinName() const { return kBinNameCpp2mpl; } diff --git a/src/mapleall/maple_driver/src/mpl_options.cpp b/src/mapleall/maple_driver/src/mpl_options.cpp index 414d2300ee..870557f4ab 100644 --- a/src/mapleall/maple_driver/src/mpl_options.cpp +++ b/src/mapleall/maple_driver/src/mpl_options.cpp @@ -59,7 +59,8 @@ int MplOptions::Parse(int argc, char **argv) { optionParser->RegisteUsages(IpaOption::GetInstance()); optionParser->RegisteUsages(jbcUsage); optionParser->RegisteUsages(cppUsage); - optionParser->RegisteUsages(asUsage); + // Not sure if this is even required + // optionParser->RegisteUsages(asUsage); optionParser->RegisteUsages(Options::GetInstance()); optionParser->RegisteUsages(MeOption::GetInstance()); optionParser->RegisteUsages(CGOptions::GetInstance()); -- Gitee From 8620abc1f236951c8e4507f65cb47073c6d161a2 Mon Sep 17 00:00:00 2001 From: Tikhon Antyshev Date: Wed, 11 Aug 2021 11:38:41 +0300 Subject: [PATCH 10/16] Clang and bug fixes --- src/mapleall/maple_driver/BUILD.gn | 1 + .../defs/default/O0_options_clang.def | 1 + .../maple_driver/defs/default_options.def | 6 +- src/mapleall/maple_driver/include/compiler.h | 28 ++++++++-- .../maple_driver/include/mpl_options.h | 2 + src/mapleall/maple_driver/src/as_compiler.cpp | 4 +- .../maple_driver/src/clang_compiler.cpp | 55 +++++++++++++++++++ .../maple_driver/src/compiler_factory.cpp | 1 + .../maple_driver/src/cpp2mpl_compiler.cpp | 16 ++++++ src/mapleall/maple_driver/src/mpl_options.cpp | 12 +++- 10 files changed, 116 insertions(+), 10 deletions(-) create mode 100644 src/mapleall/maple_driver/defs/default/O0_options_clang.def create mode 100644 src/mapleall/maple_driver/src/clang_compiler.cpp diff --git a/src/mapleall/maple_driver/BUILD.gn b/src/mapleall/maple_driver/BUILD.gn index e139dc7e2f..41451906c5 100644 --- a/src/mapleall/maple_driver/BUILD.gn +++ b/src/mapleall/maple_driver/BUILD.gn @@ -50,6 +50,7 @@ executable("maple") { "src/ipa_compiler.cpp", "src/jbc2mpl_compiler.cpp", "src/cpp2mpl_compiler.cpp", + "src/clang_compiler.cpp", "src/ld_compiler.cpp", "src/maple.cpp", "src/maple_comb_compiler.cpp", diff --git a/src/mapleall/maple_driver/defs/default/O0_options_clang.def b/src/mapleall/maple_driver/defs/default/O0_options_clang.def new file mode 100644 index 0000000000..f7dabc091c --- /dev/null +++ b/src/mapleall/maple_driver/defs/default/O0_options_clang.def @@ -0,0 +1 @@ +{"-emit-ast", "", false} \ No newline at end of file diff --git a/src/mapleall/maple_driver/defs/default_options.def b/src/mapleall/maple_driver/defs/default_options.def index 6e551e9162..7c5fac1085 100644 --- a/src/mapleall/maple_driver/defs/default_options.def +++ b/src/mapleall/maple_driver/defs/default_options.def @@ -108,9 +108,13 @@ static MplOption kMeDefaultOptionsO2ForC[] = { static MplOption kMplcgDefaultOptionsO2ForC[] = { #include "default/O2_options_mplcg_c.def" }; -// 00 cpp2mpl options +// O0 cpp2mpl options static MplOption kCpp2MplDefaultOptionsForAst[] = { #include "default/O0_options_cpp2mpl.def" }; +// O0 clang options +static MplOption kClangDefaultOptions[] = { +#include "default/O0_options_clang.def" +}; } // namespace maple #endif // MAPLE_DRIVER_INCLUDE_DEFAULT_OPTIONS_H diff --git a/src/mapleall/maple_driver/include/compiler.h b/src/mapleall/maple_driver/include/compiler.h index 7e925a07a3..044fd70ee8 100644 --- a/src/mapleall/maple_driver/include/compiler.h +++ b/src/mapleall/maple_driver/include/compiler.h @@ -33,6 +33,7 @@ namespace maple { const std::string kBinNameNone = ""; const std::string kBinNameJbc2mpl = "jbc2mpl"; const std::string kBinNameCpp2mpl = "mplfe"; +const std::string kBinNameClang = "clang"; const std::string kBinNameDex2mpl = "dex2mpl"; const std::string kBinNameMplipa = "mplipa"; const std::string kBinNameMe = "me"; @@ -114,18 +115,33 @@ class Jbc2MplCompiler : public Compiler { std::unordered_set GetFinalOutputs(const MplOptions &mplOptions) const override; }; +class ClangCompiler : public Compiler { + public: + explicit ClangCompiler(const std::string &name) : Compiler(name) {} + + ~ClangCompiler() = default; + + private: + const std::string &GetBinName() const override; + std::string GetBinPath(const MplOptions &options) const override; + DefaultOption GetDefaultOptions(const MplOptions &options) const override; + void GetTmpFilesToDelete(const MplOptions &mplOptions, std::vector &tempFiles) const override; + std::unordered_set GetFinalOutputs(const MplOptions &mplOptions) const override ; +}; + class Cpp2MplCompiler : public Compiler { public: explicit Cpp2MplCompiler(const std::string &name) : Compiler(name) {} ~Cpp2MplCompiler() = default; - private: - std::string GetBinPath(const MplOptions &options) const override; - const std::string &GetBinName() const override; - DefaultOption GetDefaultOptions(const MplOptions &options) const override; - void GetTmpFilesToDelete(const MplOptions &mplOptions, std::vector &tempFiles) const override; - std::unordered_set GetFinalOutputs(const MplOptions &mplOptions) const override; +private: + std::string GetBinPath(const MplOptions &options) const override; + const std::string &GetBinName() const override; + std::string GetInputFileName(const MplOptions &options) const override; + DefaultOption GetDefaultOptions(const MplOptions &options) const override; + void GetTmpFilesToDelete(const MplOptions &mplOptions, std::vector &tempFiles) const override; + std::unordered_set GetFinalOutputs(const MplOptions &mplOptions) const override; }; class Dex2MplCompiler : public Compiler { diff --git a/src/mapleall/maple_driver/include/mpl_options.h b/src/mapleall/maple_driver/include/mpl_options.h index 0f37d87b17..6fed0f4899 100644 --- a/src/mapleall/maple_driver/include/mpl_options.h +++ b/src/mapleall/maple_driver/include/mpl_options.h @@ -34,6 +34,8 @@ enum InputFileType { kFileTypeClass, kFileTypeJar, kFileTypeAst, + kFileTypeCpp, + kFileTypeC, kFileTypeDex, kFileTypeMpl, kFileTypeVtableImplMpl, diff --git a/src/mapleall/maple_driver/src/as_compiler.cpp b/src/mapleall/maple_driver/src/as_compiler.cpp index 13056b74cc..f7f6f34fb5 100644 --- a/src/mapleall/maple_driver/src/as_compiler.cpp +++ b/src/mapleall/maple_driver/src/as_compiler.cpp @@ -20,12 +20,12 @@ std::string AsCompiler::GetBinPath(const MplOptions&) const { #ifdef ANDROID return "prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin/"; #else - return "/usr/bin/"; + return std::string(std::getenv(kMapleRoot)) + "/tools/gcc-linaro-7.5.0/bin/"; #endif } const std::string &AsCompiler::GetBinName() const { - return kBinNameAs; + return kBinNameGcc; } DefaultOption AsCompiler::GetDefaultOptions(const MplOptions&) const { diff --git a/src/mapleall/maple_driver/src/clang_compiler.cpp b/src/mapleall/maple_driver/src/clang_compiler.cpp new file mode 100644 index 0000000000..b73c3c40e9 --- /dev/null +++ b/src/mapleall/maple_driver/src/clang_compiler.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (c) [2019-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * 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 v2 for more details. + */ +#include +#include "compiler.h" +#include "file_utils.h" +#include "default_options.def" + +namespace maple { + + +std::string ClangCompiler::GetBinPath(const MplOptions&) const{ + return std::string(std::getenv(kMapleRoot)) + "/tools/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/"; +} + +const std::string &ClangCompiler::GetBinName() const { + return kBinNameClang; +} + +DefaultOption ClangCompiler::GetDefaultOptions(const MplOptions &options) const { + DefaultOption defaultOptions = { nullptr, 0 }; + defaultOptions.mplOptions = kClangDefaultOptions; + defaultOptions.length = sizeof(kClangDefaultOptions) / sizeof(MplOption); + + for (uint32_t i = 0; i < defaultOptions.length; ++i) { + defaultOptions.mplOptions[i].SetValue( + FileUtils::AppendMapleRootIfNeeded(defaultOptions.mplOptions[i].GetNeedRootPath(), + defaultOptions.mplOptions[i].GetValue(), + options.GetExeFolder())); + } + return defaultOptions; +} + +void ClangCompiler::GetTmpFilesToDelete(const MplOptions &mplOptions, std::vector &tempFiles) const { + tempFiles.push_back(mplOptions.GetOutputFolder() + mplOptions.GetOutputName() + ".ast"); +} + +std::unordered_set ClangCompiler::GetFinalOutputs(const MplOptions &mplOptions) const { + std::unordered_set finalOutputs; + (void)finalOutputs.insert(mplOptions.GetOutputFolder() + mplOptions.GetOutputName() + ".ast"); + return finalOutputs; +} + +} \ No newline at end of file diff --git a/src/mapleall/maple_driver/src/compiler_factory.cpp b/src/mapleall/maple_driver/src/compiler_factory.cpp index 03a420e35c..e399c2ec20 100644 --- a/src/mapleall/maple_driver/src/compiler_factory.cpp +++ b/src/mapleall/maple_driver/src/compiler_factory.cpp @@ -35,6 +35,7 @@ CompilerFactory::CompilerFactory() { ADD_COMPILER("jbc2mpl", Jbc2MplCompiler) ADD_COMPILER("dex2mpl", Dex2MplCompiler) ADD_COMPILER("cpp2mpl", Cpp2MplCompiler) + ADD_COMPILER("clang", ClangCompiler) ADD_COMPILER("mplipa", IpaCompiler) ADD_COMPILER("me", MapleCombCompiler) ADD_COMPILER("mpl2mpl", MapleCombCompiler) diff --git a/src/mapleall/maple_driver/src/cpp2mpl_compiler.cpp b/src/mapleall/maple_driver/src/cpp2mpl_compiler.cpp index 23eebcbbdb..8ebae8b5f4 100644 --- a/src/mapleall/maple_driver/src/cpp2mpl_compiler.cpp +++ b/src/mapleall/maple_driver/src/cpp2mpl_compiler.cpp @@ -15,6 +15,7 @@ #include #include "compiler.h" #include "file_utils.h" +#include "mpl_logging.h" #include "default_options.def" namespace maple { @@ -26,6 +27,21 @@ const std::string &Cpp2MplCompiler::GetBinName() const { return kBinNameCpp2mpl; } +std::string Cpp2MplCompiler::GetInputFileName(const MplOptions &options) const { + if (!options.GetRunningExes().empty()) { + if (options.GetRunningExes()[0] == kBinNameCpp2mpl) { + return options.GetInputFiles(); + } + } + // Get base file name + auto idx = options.GetOutputName().find(".ast"); + std::string outputName = options.GetOutputName(); + if (idx != std::string::npos) { + outputName = options.GetOutputName().substr(0, idx); + } + return options.GetOutputFolder() + outputName + ".ast"; +} + DefaultOption Cpp2MplCompiler::GetDefaultOptions(const MplOptions &options) const { DefaultOption defaultOptions = { nullptr, 0 }; defaultOptions.mplOptions = kCpp2MplDefaultOptionsForAst; diff --git a/src/mapleall/maple_driver/src/mpl_options.cpp b/src/mapleall/maple_driver/src/mpl_options.cpp index 870557f4ab..fcda46e22a 100644 --- a/src/mapleall/maple_driver/src/mpl_options.cpp +++ b/src/mapleall/maple_driver/src/mpl_options.cpp @@ -46,7 +46,7 @@ const std::string kMapleDriverVersion = "MapleDriver " + std::to_string(Version: const std::vector kMapleCompilers = { "jbc2mpl", "cpp2mpl", "dex2mpl", "mplipa", "as", - "me", "mpl2mpl", "mplcg"}; + "me", "mpl2mpl", "mplcg", "clang"}; int MplOptions::Parse(int argc, char **argv) { optionParser.reset(new OptionParser()); @@ -272,6 +272,10 @@ ErrorCode MplOptions::DecideRunningPhases() { bool isNeedMapleComb = true; bool isNeedMplcg = true; switch (inputFileType) { + case InputFileType::kFileTypeC: + case InputFileType::kFileTypeCpp: + UpdateRunningExe(kBinNameClang); + break; case InputFileType::kFileTypeAst: UpdateRunningExe(kBinNameCpp2mpl); break; @@ -379,6 +383,12 @@ bool MplOptions::Init(const std::string &inputFile) { else if (extensionName == "dex") { inputFileType = InputFileType::kFileTypeDex; } + else if (extensionName == "c") { + inputFileType = InputFileType::kFileTypeC; + } + else if (extensionName == "cpp") { + inputFileType = InputFileType::kFileTypeCpp; + } else if (extensionName == "ast") { inputFileType = InputFileType::kFileTypeAst; } -- Gitee From 4c2c422c6d6352de01b395a4885a5f3bc5161005 Mon Sep 17 00:00:00 2001 From: Tikhon Antyshev Date: Wed, 11 Aug 2021 12:23:29 +0300 Subject: [PATCH 11/16] Required Patch --- src/mapleall/maple_driver/defs/default/O0_options_mplcg.def | 2 +- src/mapleall/maple_driver/defs/default/O2_options_mplcg.def | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/mapleall/maple_driver/defs/default/O0_options_mplcg.def b/src/mapleall/maple_driver/defs/default/O0_options_mplcg.def index 59228b4539..c92727c765 100644 --- a/src/mapleall/maple_driver/defs/default/O0_options_mplcg.def +++ b/src/mapleall/maple_driver/defs/default/O0_options_mplcg.def @@ -15,7 +15,7 @@ // option name, option value, append maple root path? { "--quiet", "", false }, { "--no-pie", "", false }, -{ "--no-fpic", "", false }, +{ "--fpic", "", false }, { "--verbose-asm", "", false }, { "--maplelinker", "", false }, { "--duplicate_asm_list", "out/target/product/maple_arm64/lib/codetricks/asm/duplicateFunc.s", true }, diff --git a/src/mapleall/maple_driver/defs/default/O2_options_mplcg.def b/src/mapleall/maple_driver/defs/default/O2_options_mplcg.def index cf81c5bfc2..fc489f6b0e 100644 --- a/src/mapleall/maple_driver/defs/default/O2_options_mplcg.def +++ b/src/mapleall/maple_driver/defs/default/O2_options_mplcg.def @@ -21,4 +21,3 @@ { "--maplelinker", "", false }, { "--gen-c-macro-def", "", false }, { "--duplicate_asm_list", "out/target/product/maple_arm64/lib/codetricks/asm/duplicateFunc.s", true }, - -- Gitee From c7fcd2b1bd2bb12e7bea233b31850b270a802d61 Mon Sep 17 00:00:00 2001 From: Tikhon Antyshev Date: Wed, 11 Aug 2021 12:28:04 +0300 Subject: [PATCH 12/16] Rebase --- src/mapleall/maple_driver/BUILD.gn | 2 - .../defs/default/O0_options_clang.def | 1 - .../defs/default/O0_options_cpp2mpl.def | 2 - .../maple_driver/defs/default_options.def | 8 --- src/mapleall/maple_driver/include/as_option.h | 51 -------------- src/mapleall/maple_driver/include/compiler.h | 31 -------- .../maple_driver/include/cpp2mpl_option.h | 59 ---------------- .../include/driver_option_common.h | 2 - .../maple_driver/include/mpl_options.h | 3 - src/mapleall/maple_driver/src/as_compiler.cpp | 2 +- .../maple_driver/src/clang_compiler.cpp | 55 --------------- .../maple_driver/src/compiler_factory.cpp | 2 - .../maple_driver/src/cpp2mpl_compiler.cpp | 70 ------------------- .../maple_driver/src/driver_option_common.cpp | 19 +---- src/mapleall/maple_driver/src/mpl_options.cpp | 44 ++---------- 15 files changed, 7 insertions(+), 344 deletions(-) delete mode 100644 src/mapleall/maple_driver/defs/default/O0_options_clang.def delete mode 100644 src/mapleall/maple_driver/defs/default/O0_options_cpp2mpl.def delete mode 100644 src/mapleall/maple_driver/include/as_option.h delete mode 100644 src/mapleall/maple_driver/include/cpp2mpl_option.h delete mode 100644 src/mapleall/maple_driver/src/clang_compiler.cpp delete mode 100644 src/mapleall/maple_driver/src/cpp2mpl_compiler.cpp diff --git a/src/mapleall/maple_driver/BUILD.gn b/src/mapleall/maple_driver/BUILD.gn index 41451906c5..162a90a1ee 100644 --- a/src/mapleall/maple_driver/BUILD.gn +++ b/src/mapleall/maple_driver/BUILD.gn @@ -49,8 +49,6 @@ executable("maple") { "src/file_utils.cpp", "src/ipa_compiler.cpp", "src/jbc2mpl_compiler.cpp", - "src/cpp2mpl_compiler.cpp", - "src/clang_compiler.cpp", "src/ld_compiler.cpp", "src/maple.cpp", "src/maple_comb_compiler.cpp", diff --git a/src/mapleall/maple_driver/defs/default/O0_options_clang.def b/src/mapleall/maple_driver/defs/default/O0_options_clang.def deleted file mode 100644 index f7dabc091c..0000000000 --- a/src/mapleall/maple_driver/defs/default/O0_options_clang.def +++ /dev/null @@ -1 +0,0 @@ -{"-emit-ast", "", false} \ No newline at end of file diff --git a/src/mapleall/maple_driver/defs/default/O0_options_cpp2mpl.def b/src/mapleall/maple_driver/defs/default/O0_options_cpp2mpl.def deleted file mode 100644 index 8e7a8d13e1..0000000000 --- a/src/mapleall/maple_driver/defs/default/O0_options_cpp2mpl.def +++ /dev/null @@ -1,2 +0,0 @@ -{"--in-ast", "", false} - diff --git a/src/mapleall/maple_driver/defs/default_options.def b/src/mapleall/maple_driver/defs/default_options.def index 7c5fac1085..da1f2d9b99 100644 --- a/src/mapleall/maple_driver/defs/default_options.def +++ b/src/mapleall/maple_driver/defs/default_options.def @@ -108,13 +108,5 @@ static MplOption kMeDefaultOptionsO2ForC[] = { static MplOption kMplcgDefaultOptionsO2ForC[] = { #include "default/O2_options_mplcg_c.def" }; -// O0 cpp2mpl options -static MplOption kCpp2MplDefaultOptionsForAst[] = { -#include "default/O0_options_cpp2mpl.def" -}; -// O0 clang options -static MplOption kClangDefaultOptions[] = { -#include "default/O0_options_clang.def" -}; } // namespace maple #endif // MAPLE_DRIVER_INCLUDE_DEFAULT_OPTIONS_H diff --git a/src/mapleall/maple_driver/include/as_option.h b/src/mapleall/maple_driver/include/as_option.h deleted file mode 100644 index 3a32617987..0000000000 --- a/src/mapleall/maple_driver/include/as_option.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under Mulan PSL v2. - * You can use this software according to the terms and conditions of the Mulan PSL v2. - * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * 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 v2 for more details. - */ -#ifndef MAPLE_AS_OPTION_H -#define MAPLE_AS_OPTION_H -#include "option_descriptor.h" - -namespace maple { -enum AsOptionIndex { - kInS, - kAsHelp, -}; - -const mapleOption::Descriptor asUsage[] = { - { kUnknown, 0, "", "", mapleOption::kBuildTypeAll, mapleOption::kArgCheckPolicyUnknown, - "========================================\n" - " Usage: as [ options ]\n" - " options:\n", - "as", - {} }, - - { kInS, 0, "", "in-s", mapleOption::kBuildTypeAll, mapleOption::kArgCheckPolicyRequired, - " --in-s file1.s,file2.s\n" - " : input asm files", - "as", - {} }, - - - { kAsHelp, 0, "h", "help", mapleOption::kBuildTypeExperimental, mapleOption::kArgCheckPolicyNone, - " -h, --help : print usage and exit.\n", - "as", - {} }, - - { kUnknown, 0, "", "", mapleOption::kBuildTypeAll, mapleOption::kArgCheckPolicyNone, - "", - "as", - {} } -}; -} // namespace maple -#endif // MAPLE_AS_OPTION_H \ No newline at end of file diff --git a/src/mapleall/maple_driver/include/compiler.h b/src/mapleall/maple_driver/include/compiler.h index 044fd70ee8..54ce62a65f 100644 --- a/src/mapleall/maple_driver/include/compiler.h +++ b/src/mapleall/maple_driver/include/compiler.h @@ -32,8 +32,6 @@ namespace maple { const std::string kBinNameNone = ""; const std::string kBinNameJbc2mpl = "jbc2mpl"; -const std::string kBinNameCpp2mpl = "mplfe"; -const std::string kBinNameClang = "clang"; const std::string kBinNameDex2mpl = "dex2mpl"; const std::string kBinNameMplipa = "mplipa"; const std::string kBinNameMe = "me"; @@ -115,35 +113,6 @@ class Jbc2MplCompiler : public Compiler { std::unordered_set GetFinalOutputs(const MplOptions &mplOptions) const override; }; -class ClangCompiler : public Compiler { - public: - explicit ClangCompiler(const std::string &name) : Compiler(name) {} - - ~ClangCompiler() = default; - - private: - const std::string &GetBinName() const override; - std::string GetBinPath(const MplOptions &options) const override; - DefaultOption GetDefaultOptions(const MplOptions &options) const override; - void GetTmpFilesToDelete(const MplOptions &mplOptions, std::vector &tempFiles) const override; - std::unordered_set GetFinalOutputs(const MplOptions &mplOptions) const override ; -}; - -class Cpp2MplCompiler : public Compiler { - public: - explicit Cpp2MplCompiler(const std::string &name) : Compiler(name) {} - - ~Cpp2MplCompiler() = default; - -private: - std::string GetBinPath(const MplOptions &options) const override; - const std::string &GetBinName() const override; - std::string GetInputFileName(const MplOptions &options) const override; - DefaultOption GetDefaultOptions(const MplOptions &options) const override; - void GetTmpFilesToDelete(const MplOptions &mplOptions, std::vector &tempFiles) const override; - std::unordered_set GetFinalOutputs(const MplOptions &mplOptions) const override; -}; - class Dex2MplCompiler : public Compiler { public: explicit Dex2MplCompiler(const std::string &name) : Compiler(name) {} diff --git a/src/mapleall/maple_driver/include/cpp2mpl_option.h b/src/mapleall/maple_driver/include/cpp2mpl_option.h deleted file mode 100644 index 01433ddcb0..0000000000 --- a/src/mapleall/maple_driver/include/cpp2mpl_option.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under Mulan PSL v2. - * You can use this software according to the terms and conditions of the Mulan PSL v2. - * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * 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 v2 for more details. - */ -#ifndef MAPLE_CPP2MPL_OPTION_H -#define MAPLE_CPP2MPL_OPTION_H -#include "option_descriptor.h" - -namespace maple { -enum CppOptionIndex { - kInAst, - kInCpp, - kCpp2mplHelp, -}; - -const mapleOption::Descriptor cppUsage[] = { - { kUnknown, 0, "", "", mapleOption::kBuildTypeAll, mapleOption::kArgCheckPolicyUnknown, - "========================================\n" - " Usage: cpp2mpl [ options ]\n" - " options:\n", - "cpp2mpl", - {} }, - - { kInAst, 0, "", "inast", mapleOption::kBuildTypeAll, mapleOption::kArgCheckPolicyRequired, - " -in-ast file1.ast,file2.ast\n" - " : input ast files", - "cpp2mpl", - {} }, - - { kInCpp, 0, "", "incpp", mapleOption::kBuildTypeAll, mapleOption::kArgCheckPolicyRequired, - " -in-cpp file1.cpp,file2.cpp\n" - " : input cpp files", - "cpp2mpl", - {} }, - - { kCpp2mplHelp, 0, "h", "help", mapleOption::kBuildTypeExperimental, mapleOption::kArgCheckPolicyNone, - " -h, --help : print usage and exit.\n", - "cpp2mpl", - {} }, - - { kUnknown, 0, "", "", mapleOption::kBuildTypeAll, mapleOption::kArgCheckPolicyNone, - "", - "cpp2mpl", - {} } -}; -} // namespace maple - -#endif //MAPLE_CPP2MPL_OPTION_H - diff --git a/src/mapleall/maple_driver/include/driver_option_common.h b/src/mapleall/maple_driver/include/driver_option_common.h index 4a4e0761d3..55a8223e0c 100644 --- a/src/mapleall/maple_driver/include/driver_option_common.h +++ b/src/mapleall/maple_driver/include/driver_option_common.h @@ -28,8 +28,6 @@ enum DriverOptionIndex { kOptimization2, kWithIpa, kJbc2mplOpt, - kCpp2mplOpt, - kAsOpt, kDex2mplOpt, kMplipaOpt, kVerify, diff --git a/src/mapleall/maple_driver/include/mpl_options.h b/src/mapleall/maple_driver/include/mpl_options.h index 6fed0f4899..c02fa68842 100644 --- a/src/mapleall/maple_driver/include/mpl_options.h +++ b/src/mapleall/maple_driver/include/mpl_options.h @@ -33,9 +33,6 @@ enum InputFileType { kFileTypeNone, kFileTypeClass, kFileTypeJar, - kFileTypeAst, - kFileTypeCpp, - kFileTypeC, kFileTypeDex, kFileTypeMpl, kFileTypeVtableImplMpl, diff --git a/src/mapleall/maple_driver/src/as_compiler.cpp b/src/mapleall/maple_driver/src/as_compiler.cpp index f7f6f34fb5..664d327f35 100644 --- a/src/mapleall/maple_driver/src/as_compiler.cpp +++ b/src/mapleall/maple_driver/src/as_compiler.cpp @@ -20,7 +20,7 @@ std::string AsCompiler::GetBinPath(const MplOptions&) const { #ifdef ANDROID return "prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin/"; #else - return std::string(std::getenv(kMapleRoot)) + "/tools/gcc-linaro-7.5.0/bin/"; + return std::string(kMapleRoot) + "/third-party/ndk/toolchain/bin/"; #endif } diff --git a/src/mapleall/maple_driver/src/clang_compiler.cpp b/src/mapleall/maple_driver/src/clang_compiler.cpp deleted file mode 100644 index b73c3c40e9..0000000000 --- a/src/mapleall/maple_driver/src/clang_compiler.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) [2019-2021] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under Mulan PSL v2. - * You can use this software according to the terms and conditions of the Mulan PSL v2. - * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * 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 v2 for more details. - */ -#include -#include "compiler.h" -#include "file_utils.h" -#include "default_options.def" - -namespace maple { - - -std::string ClangCompiler::GetBinPath(const MplOptions&) const{ - return std::string(std::getenv(kMapleRoot)) + "/tools/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/"; -} - -const std::string &ClangCompiler::GetBinName() const { - return kBinNameClang; -} - -DefaultOption ClangCompiler::GetDefaultOptions(const MplOptions &options) const { - DefaultOption defaultOptions = { nullptr, 0 }; - defaultOptions.mplOptions = kClangDefaultOptions; - defaultOptions.length = sizeof(kClangDefaultOptions) / sizeof(MplOption); - - for (uint32_t i = 0; i < defaultOptions.length; ++i) { - defaultOptions.mplOptions[i].SetValue( - FileUtils::AppendMapleRootIfNeeded(defaultOptions.mplOptions[i].GetNeedRootPath(), - defaultOptions.mplOptions[i].GetValue(), - options.GetExeFolder())); - } - return defaultOptions; -} - -void ClangCompiler::GetTmpFilesToDelete(const MplOptions &mplOptions, std::vector &tempFiles) const { - tempFiles.push_back(mplOptions.GetOutputFolder() + mplOptions.GetOutputName() + ".ast"); -} - -std::unordered_set ClangCompiler::GetFinalOutputs(const MplOptions &mplOptions) const { - std::unordered_set finalOutputs; - (void)finalOutputs.insert(mplOptions.GetOutputFolder() + mplOptions.GetOutputName() + ".ast"); - return finalOutputs; -} - -} \ No newline at end of file diff --git a/src/mapleall/maple_driver/src/compiler_factory.cpp b/src/mapleall/maple_driver/src/compiler_factory.cpp index e399c2ec20..5ca6e926a2 100644 --- a/src/mapleall/maple_driver/src/compiler_factory.cpp +++ b/src/mapleall/maple_driver/src/compiler_factory.cpp @@ -34,8 +34,6 @@ CompilerFactory::CompilerFactory() { // Supported compilers ADD_COMPILER("jbc2mpl", Jbc2MplCompiler) ADD_COMPILER("dex2mpl", Dex2MplCompiler) - ADD_COMPILER("cpp2mpl", Cpp2MplCompiler) - ADD_COMPILER("clang", ClangCompiler) ADD_COMPILER("mplipa", IpaCompiler) ADD_COMPILER("me", MapleCombCompiler) ADD_COMPILER("mpl2mpl", MapleCombCompiler) diff --git a/src/mapleall/maple_driver/src/cpp2mpl_compiler.cpp b/src/mapleall/maple_driver/src/cpp2mpl_compiler.cpp deleted file mode 100644 index 8ebae8b5f4..0000000000 --- a/src/mapleall/maple_driver/src/cpp2mpl_compiler.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under Mulan PSL v2. - * You can use this software according to the terms and conditions of the Mulan PSL v2. - * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * 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 v2 for more details. - */ -#include -#include "compiler.h" -#include "file_utils.h" -#include "mpl_logging.h" -#include "default_options.def" - -namespace maple { -std::string Cpp2MplCompiler::GetBinPath(const MplOptions&) const{ - return std::string(std::getenv(kMapleRoot)) + "/output/aarch64-clang-debug/bin/"; -} - -const std::string &Cpp2MplCompiler::GetBinName() const { - return kBinNameCpp2mpl; -} - -std::string Cpp2MplCompiler::GetInputFileName(const MplOptions &options) const { - if (!options.GetRunningExes().empty()) { - if (options.GetRunningExes()[0] == kBinNameCpp2mpl) { - return options.GetInputFiles(); - } - } - // Get base file name - auto idx = options.GetOutputName().find(".ast"); - std::string outputName = options.GetOutputName(); - if (idx != std::string::npos) { - outputName = options.GetOutputName().substr(0, idx); - } - return options.GetOutputFolder() + outputName + ".ast"; -} - -DefaultOption Cpp2MplCompiler::GetDefaultOptions(const MplOptions &options) const { - DefaultOption defaultOptions = { nullptr, 0 }; - defaultOptions.mplOptions = kCpp2MplDefaultOptionsForAst; - defaultOptions.length = sizeof(kCpp2MplDefaultOptionsForAst) / sizeof(MplOption); - - for (uint32_t i = 0; i < defaultOptions.length; ++i) { - defaultOptions.mplOptions[i].SetValue( - FileUtils::AppendMapleRootIfNeeded(defaultOptions.mplOptions[i].GetNeedRootPath(), - defaultOptions.mplOptions[i].GetValue(), - options.GetExeFolder())); - } - return defaultOptions; -} - -void Cpp2MplCompiler::GetTmpFilesToDelete(const MplOptions &mplOptions, std::vector &tempFiles) const { - tempFiles.push_back(mplOptions.GetOutputFolder() + mplOptions.GetOutputName() + ".mpl"); - tempFiles.push_back(mplOptions.GetOutputFolder() + mplOptions.GetOutputName() + ".mplt"); -} - -std::unordered_set Cpp2MplCompiler::GetFinalOutputs(const MplOptions &mplOptions) const { - std::unordered_set finalOutputs; - (void)finalOutputs.insert(mplOptions.GetOutputFolder() + mplOptions.GetOutputName() + ".mpl"); - (void)finalOutputs.insert(mplOptions.GetOutputFolder() + mplOptions.GetOutputName() + ".mplt"); - return finalOutputs; -} -} // namespace maple \ No newline at end of file diff --git a/src/mapleall/maple_driver/src/driver_option_common.cpp b/src/mapleall/maple_driver/src/driver_option_common.cpp index 04a85733ed..dda7b4487c 100644 --- a/src/mapleall/maple_driver/src/driver_option_common.cpp +++ b/src/mapleall/maple_driver/src/driver_option_common.cpp @@ -138,23 +138,6 @@ const mapleOption::Descriptor usages[] = { " --jbc2mpl-opt \tSet options for jbc2mpl\n", "all", {} }, - { kCpp2mplOpt, - 0, - "", - "cpp2mpl-opt", - kBuildTypeProduct, - kArgCheckPolicyNone, - " --cpp2mpl-opt \tSet options for cpp2mpl\n", - "all", - {} }, - { kAsOpt, - 0, - "", - "as-opt", - kBuildTypeProduct, - kArgCheckPolicyNone, - "--as-opt \tSet options for as\n", - {} }, { kDex2mplOpt, 0, "", @@ -306,7 +289,7 @@ const mapleOption::Descriptor usages[] = { kArgCheckPolicyBool, " -verbose \t: print informations\n", "all", - { "jbc2mpl", "cpp2mpl", "me", "mpl2mpl", "mplcg" } }, + { "jbc2mpl", "me", "mpl2mpl", "mplcg" } }, { kAllDebug, 0, "", diff --git a/src/mapleall/maple_driver/src/mpl_options.cpp b/src/mapleall/maple_driver/src/mpl_options.cpp index fcda46e22a..f16918ebb2 100644 --- a/src/mapleall/maple_driver/src/mpl_options.cpp +++ b/src/mapleall/maple_driver/src/mpl_options.cpp @@ -31,8 +31,6 @@ #endif #include "ipa_option.h" #include "jbc2mpl_option.h" -#include "as_option.h" -#include "cpp2mpl_option.h" #include "me_option.h" #include "option.h" #include "cg_option.h" @@ -44,9 +42,9 @@ using namespace maplebe; const std::string kMapleDriverVersion = "MapleDriver " + std::to_string(Version::kMajorMplVersion) + "." + std::to_string(Version::kMinorCompilerVersion) + " 20190929"; -const std::vector kMapleCompilers = { "jbc2mpl", "cpp2mpl", - "dex2mpl", "mplipa", "as", - "me", "mpl2mpl", "mplcg", "clang"}; +const std::vector kMapleCompilers = { "jbc2mpl", + "dex2mpl", "mplipa", + "me", "mpl2mpl", "mplcg" }; int MplOptions::Parse(int argc, char **argv) { optionParser.reset(new OptionParser()); @@ -58,9 +56,6 @@ int MplOptions::Parse(int argc, char **argv) { #endif optionParser->RegisteUsages(IpaOption::GetInstance()); optionParser->RegisteUsages(jbcUsage); - optionParser->RegisteUsages(cppUsage); - // Not sure if this is even required - // optionParser->RegisteUsages(asUsage); optionParser->RegisteUsages(Options::GetInstance()); optionParser->RegisteUsages(MeOption::GetInstance()); optionParser->RegisteUsages(CGOptions::GetInstance()); @@ -133,18 +128,6 @@ ErrorCode MplOptions::HandleGeneralOptions() { return ret; } break; - case kAsOpt: - ret = UpdatePhaseOption(opt.Args(), kBinNameAs); - if (ret != kErrorNoError) { - return ret; - } - break; - case kCpp2mplOpt: - ret = UpdatePhaseOption(opt.Args(), kBinNameCpp2mpl); - if (ret != kErrorNoError) { - return ret; - } - break; case kJbc2mplOpt: ret = UpdatePhaseOption(opt.Args(), kBinNameJbc2mpl); if (ret != kErrorNoError) { @@ -272,13 +255,6 @@ ErrorCode MplOptions::DecideRunningPhases() { bool isNeedMapleComb = true; bool isNeedMplcg = true; switch (inputFileType) { - case InputFileType::kFileTypeC: - case InputFileType::kFileTypeCpp: - UpdateRunningExe(kBinNameClang); - break; - case InputFileType::kFileTypeAst: - UpdateRunningExe(kBinNameCpp2mpl); - break; case InputFileType::kFileTypeJar: // fall-through case InputFileType::kFileTypeClass: @@ -383,19 +359,9 @@ bool MplOptions::Init(const std::string &inputFile) { else if (extensionName == "dex") { inputFileType = InputFileType::kFileTypeDex; } - else if (extensionName == "c") { - inputFileType = InputFileType::kFileTypeC; - } - else if (extensionName == "cpp") { - inputFileType = InputFileType::kFileTypeCpp; - } - else if (extensionName == "ast") { - inputFileType = InputFileType::kFileTypeAst; - } else if (extensionName == "jar") { inputFileType = InputFileType::kFileTypeJar; - } - else if (extensionName == "mpl" || extensionName == "bpl") { + } else if (extensionName == "mpl" || extensionName == "bpl") { if (firstInputFile.find("VtableImpl") == std::string::npos) { if (firstInputFile.find(".me.mpl") != std::string::npos) { inputFileType = InputFileType::kFileTypeMeMpl; @@ -639,4 +605,4 @@ void MplOptions::PrintDetailCommand(bool isBeforeParse) { << printCommandStr << " " << GetInputFileNameForPrint() << '\n'; } } -} // namespace maple +} // namespace maple -- Gitee From 59193894b3756aed38e1dec874b4acca0a90ddba Mon Sep 17 00:00:00 2001 From: Tikhon Antyshev Date: Wed, 11 Aug 2021 12:30:20 +0300 Subject: [PATCH 13/16] Patch --- src/mapleall/maple_driver/BUILD.gn | 2 + .../defs/default/O0_options_clang.def | 1 + .../defs/default/O0_options_cpp2mpl.def | 2 + .../maple_driver/defs/default_options.def | 8 +++ src/mapleall/maple_driver/include/as_option.h | 51 ++++++++++++++ src/mapleall/maple_driver/include/compiler.h | 31 ++++++++ .../maple_driver/include/cpp2mpl_option.h | 59 ++++++++++++++++ .../include/driver_option_common.h | 2 + .../maple_driver/include/mpl_options.h | 3 + src/mapleall/maple_driver/src/as_compiler.cpp | 2 +- .../maple_driver/src/clang_compiler.cpp | 55 +++++++++++++++ .../maple_driver/src/compiler_factory.cpp | 2 + .../maple_driver/src/cpp2mpl_compiler.cpp | 70 +++++++++++++++++++ .../maple_driver/src/driver_option_common.cpp | 19 ++++- src/mapleall/maple_driver/src/mpl_options.cpp | 44 ++++++++++-- 15 files changed, 344 insertions(+), 7 deletions(-) create mode 100644 src/mapleall/maple_driver/defs/default/O0_options_clang.def create mode 100644 src/mapleall/maple_driver/defs/default/O0_options_cpp2mpl.def create mode 100644 src/mapleall/maple_driver/include/as_option.h create mode 100644 src/mapleall/maple_driver/include/cpp2mpl_option.h create mode 100644 src/mapleall/maple_driver/src/clang_compiler.cpp create mode 100644 src/mapleall/maple_driver/src/cpp2mpl_compiler.cpp diff --git a/src/mapleall/maple_driver/BUILD.gn b/src/mapleall/maple_driver/BUILD.gn index 162a90a1ee..41451906c5 100644 --- a/src/mapleall/maple_driver/BUILD.gn +++ b/src/mapleall/maple_driver/BUILD.gn @@ -49,6 +49,8 @@ executable("maple") { "src/file_utils.cpp", "src/ipa_compiler.cpp", "src/jbc2mpl_compiler.cpp", + "src/cpp2mpl_compiler.cpp", + "src/clang_compiler.cpp", "src/ld_compiler.cpp", "src/maple.cpp", "src/maple_comb_compiler.cpp", diff --git a/src/mapleall/maple_driver/defs/default/O0_options_clang.def b/src/mapleall/maple_driver/defs/default/O0_options_clang.def new file mode 100644 index 0000000000..f7dabc091c --- /dev/null +++ b/src/mapleall/maple_driver/defs/default/O0_options_clang.def @@ -0,0 +1 @@ +{"-emit-ast", "", false} \ No newline at end of file diff --git a/src/mapleall/maple_driver/defs/default/O0_options_cpp2mpl.def b/src/mapleall/maple_driver/defs/default/O0_options_cpp2mpl.def new file mode 100644 index 0000000000..8e7a8d13e1 --- /dev/null +++ b/src/mapleall/maple_driver/defs/default/O0_options_cpp2mpl.def @@ -0,0 +1,2 @@ +{"--in-ast", "", false} + diff --git a/src/mapleall/maple_driver/defs/default_options.def b/src/mapleall/maple_driver/defs/default_options.def index da1f2d9b99..7c5fac1085 100644 --- a/src/mapleall/maple_driver/defs/default_options.def +++ b/src/mapleall/maple_driver/defs/default_options.def @@ -108,5 +108,13 @@ static MplOption kMeDefaultOptionsO2ForC[] = { static MplOption kMplcgDefaultOptionsO2ForC[] = { #include "default/O2_options_mplcg_c.def" }; +// O0 cpp2mpl options +static MplOption kCpp2MplDefaultOptionsForAst[] = { +#include "default/O0_options_cpp2mpl.def" +}; +// O0 clang options +static MplOption kClangDefaultOptions[] = { +#include "default/O0_options_clang.def" +}; } // namespace maple #endif // MAPLE_DRIVER_INCLUDE_DEFAULT_OPTIONS_H diff --git a/src/mapleall/maple_driver/include/as_option.h b/src/mapleall/maple_driver/include/as_option.h new file mode 100644 index 0000000000..3a32617987 --- /dev/null +++ b/src/mapleall/maple_driver/include/as_option.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * 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 v2 for more details. + */ +#ifndef MAPLE_AS_OPTION_H +#define MAPLE_AS_OPTION_H +#include "option_descriptor.h" + +namespace maple { +enum AsOptionIndex { + kInS, + kAsHelp, +}; + +const mapleOption::Descriptor asUsage[] = { + { kUnknown, 0, "", "", mapleOption::kBuildTypeAll, mapleOption::kArgCheckPolicyUnknown, + "========================================\n" + " Usage: as [ options ]\n" + " options:\n", + "as", + {} }, + + { kInS, 0, "", "in-s", mapleOption::kBuildTypeAll, mapleOption::kArgCheckPolicyRequired, + " --in-s file1.s,file2.s\n" + " : input asm files", + "as", + {} }, + + + { kAsHelp, 0, "h", "help", mapleOption::kBuildTypeExperimental, mapleOption::kArgCheckPolicyNone, + " -h, --help : print usage and exit.\n", + "as", + {} }, + + { kUnknown, 0, "", "", mapleOption::kBuildTypeAll, mapleOption::kArgCheckPolicyNone, + "", + "as", + {} } +}; +} // namespace maple +#endif // MAPLE_AS_OPTION_H \ No newline at end of file diff --git a/src/mapleall/maple_driver/include/compiler.h b/src/mapleall/maple_driver/include/compiler.h index 54ce62a65f..044fd70ee8 100644 --- a/src/mapleall/maple_driver/include/compiler.h +++ b/src/mapleall/maple_driver/include/compiler.h @@ -32,6 +32,8 @@ namespace maple { const std::string kBinNameNone = ""; const std::string kBinNameJbc2mpl = "jbc2mpl"; +const std::string kBinNameCpp2mpl = "mplfe"; +const std::string kBinNameClang = "clang"; const std::string kBinNameDex2mpl = "dex2mpl"; const std::string kBinNameMplipa = "mplipa"; const std::string kBinNameMe = "me"; @@ -113,6 +115,35 @@ class Jbc2MplCompiler : public Compiler { std::unordered_set GetFinalOutputs(const MplOptions &mplOptions) const override; }; +class ClangCompiler : public Compiler { + public: + explicit ClangCompiler(const std::string &name) : Compiler(name) {} + + ~ClangCompiler() = default; + + private: + const std::string &GetBinName() const override; + std::string GetBinPath(const MplOptions &options) const override; + DefaultOption GetDefaultOptions(const MplOptions &options) const override; + void GetTmpFilesToDelete(const MplOptions &mplOptions, std::vector &tempFiles) const override; + std::unordered_set GetFinalOutputs(const MplOptions &mplOptions) const override ; +}; + +class Cpp2MplCompiler : public Compiler { + public: + explicit Cpp2MplCompiler(const std::string &name) : Compiler(name) {} + + ~Cpp2MplCompiler() = default; + +private: + std::string GetBinPath(const MplOptions &options) const override; + const std::string &GetBinName() const override; + std::string GetInputFileName(const MplOptions &options) const override; + DefaultOption GetDefaultOptions(const MplOptions &options) const override; + void GetTmpFilesToDelete(const MplOptions &mplOptions, std::vector &tempFiles) const override; + std::unordered_set GetFinalOutputs(const MplOptions &mplOptions) const override; +}; + class Dex2MplCompiler : public Compiler { public: explicit Dex2MplCompiler(const std::string &name) : Compiler(name) {} diff --git a/src/mapleall/maple_driver/include/cpp2mpl_option.h b/src/mapleall/maple_driver/include/cpp2mpl_option.h new file mode 100644 index 0000000000..01433ddcb0 --- /dev/null +++ b/src/mapleall/maple_driver/include/cpp2mpl_option.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * 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 v2 for more details. + */ +#ifndef MAPLE_CPP2MPL_OPTION_H +#define MAPLE_CPP2MPL_OPTION_H +#include "option_descriptor.h" + +namespace maple { +enum CppOptionIndex { + kInAst, + kInCpp, + kCpp2mplHelp, +}; + +const mapleOption::Descriptor cppUsage[] = { + { kUnknown, 0, "", "", mapleOption::kBuildTypeAll, mapleOption::kArgCheckPolicyUnknown, + "========================================\n" + " Usage: cpp2mpl [ options ]\n" + " options:\n", + "cpp2mpl", + {} }, + + { kInAst, 0, "", "inast", mapleOption::kBuildTypeAll, mapleOption::kArgCheckPolicyRequired, + " -in-ast file1.ast,file2.ast\n" + " : input ast files", + "cpp2mpl", + {} }, + + { kInCpp, 0, "", "incpp", mapleOption::kBuildTypeAll, mapleOption::kArgCheckPolicyRequired, + " -in-cpp file1.cpp,file2.cpp\n" + " : input cpp files", + "cpp2mpl", + {} }, + + { kCpp2mplHelp, 0, "h", "help", mapleOption::kBuildTypeExperimental, mapleOption::kArgCheckPolicyNone, + " -h, --help : print usage and exit.\n", + "cpp2mpl", + {} }, + + { kUnknown, 0, "", "", mapleOption::kBuildTypeAll, mapleOption::kArgCheckPolicyNone, + "", + "cpp2mpl", + {} } +}; +} // namespace maple + +#endif //MAPLE_CPP2MPL_OPTION_H + diff --git a/src/mapleall/maple_driver/include/driver_option_common.h b/src/mapleall/maple_driver/include/driver_option_common.h index 55a8223e0c..4a4e0761d3 100644 --- a/src/mapleall/maple_driver/include/driver_option_common.h +++ b/src/mapleall/maple_driver/include/driver_option_common.h @@ -28,6 +28,8 @@ enum DriverOptionIndex { kOptimization2, kWithIpa, kJbc2mplOpt, + kCpp2mplOpt, + kAsOpt, kDex2mplOpt, kMplipaOpt, kVerify, diff --git a/src/mapleall/maple_driver/include/mpl_options.h b/src/mapleall/maple_driver/include/mpl_options.h index c02fa68842..6fed0f4899 100644 --- a/src/mapleall/maple_driver/include/mpl_options.h +++ b/src/mapleall/maple_driver/include/mpl_options.h @@ -33,6 +33,9 @@ enum InputFileType { kFileTypeNone, kFileTypeClass, kFileTypeJar, + kFileTypeAst, + kFileTypeCpp, + kFileTypeC, kFileTypeDex, kFileTypeMpl, kFileTypeVtableImplMpl, diff --git a/src/mapleall/maple_driver/src/as_compiler.cpp b/src/mapleall/maple_driver/src/as_compiler.cpp index 664d327f35..f7f6f34fb5 100644 --- a/src/mapleall/maple_driver/src/as_compiler.cpp +++ b/src/mapleall/maple_driver/src/as_compiler.cpp @@ -20,7 +20,7 @@ std::string AsCompiler::GetBinPath(const MplOptions&) const { #ifdef ANDROID return "prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin/"; #else - return std::string(kMapleRoot) + "/third-party/ndk/toolchain/bin/"; + return std::string(std::getenv(kMapleRoot)) + "/tools/gcc-linaro-7.5.0/bin/"; #endif } diff --git a/src/mapleall/maple_driver/src/clang_compiler.cpp b/src/mapleall/maple_driver/src/clang_compiler.cpp new file mode 100644 index 0000000000..b73c3c40e9 --- /dev/null +++ b/src/mapleall/maple_driver/src/clang_compiler.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (c) [2019-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * 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 v2 for more details. + */ +#include +#include "compiler.h" +#include "file_utils.h" +#include "default_options.def" + +namespace maple { + + +std::string ClangCompiler::GetBinPath(const MplOptions&) const{ + return std::string(std::getenv(kMapleRoot)) + "/tools/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/"; +} + +const std::string &ClangCompiler::GetBinName() const { + return kBinNameClang; +} + +DefaultOption ClangCompiler::GetDefaultOptions(const MplOptions &options) const { + DefaultOption defaultOptions = { nullptr, 0 }; + defaultOptions.mplOptions = kClangDefaultOptions; + defaultOptions.length = sizeof(kClangDefaultOptions) / sizeof(MplOption); + + for (uint32_t i = 0; i < defaultOptions.length; ++i) { + defaultOptions.mplOptions[i].SetValue( + FileUtils::AppendMapleRootIfNeeded(defaultOptions.mplOptions[i].GetNeedRootPath(), + defaultOptions.mplOptions[i].GetValue(), + options.GetExeFolder())); + } + return defaultOptions; +} + +void ClangCompiler::GetTmpFilesToDelete(const MplOptions &mplOptions, std::vector &tempFiles) const { + tempFiles.push_back(mplOptions.GetOutputFolder() + mplOptions.GetOutputName() + ".ast"); +} + +std::unordered_set ClangCompiler::GetFinalOutputs(const MplOptions &mplOptions) const { + std::unordered_set finalOutputs; + (void)finalOutputs.insert(mplOptions.GetOutputFolder() + mplOptions.GetOutputName() + ".ast"); + return finalOutputs; +} + +} \ No newline at end of file diff --git a/src/mapleall/maple_driver/src/compiler_factory.cpp b/src/mapleall/maple_driver/src/compiler_factory.cpp index 5ca6e926a2..e399c2ec20 100644 --- a/src/mapleall/maple_driver/src/compiler_factory.cpp +++ b/src/mapleall/maple_driver/src/compiler_factory.cpp @@ -34,6 +34,8 @@ CompilerFactory::CompilerFactory() { // Supported compilers ADD_COMPILER("jbc2mpl", Jbc2MplCompiler) ADD_COMPILER("dex2mpl", Dex2MplCompiler) + ADD_COMPILER("cpp2mpl", Cpp2MplCompiler) + ADD_COMPILER("clang", ClangCompiler) ADD_COMPILER("mplipa", IpaCompiler) ADD_COMPILER("me", MapleCombCompiler) ADD_COMPILER("mpl2mpl", MapleCombCompiler) diff --git a/src/mapleall/maple_driver/src/cpp2mpl_compiler.cpp b/src/mapleall/maple_driver/src/cpp2mpl_compiler.cpp new file mode 100644 index 0000000000..8ebae8b5f4 --- /dev/null +++ b/src/mapleall/maple_driver/src/cpp2mpl_compiler.cpp @@ -0,0 +1,70 @@ +/* + * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * 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 v2 for more details. + */ +#include +#include "compiler.h" +#include "file_utils.h" +#include "mpl_logging.h" +#include "default_options.def" + +namespace maple { +std::string Cpp2MplCompiler::GetBinPath(const MplOptions&) const{ + return std::string(std::getenv(kMapleRoot)) + "/output/aarch64-clang-debug/bin/"; +} + +const std::string &Cpp2MplCompiler::GetBinName() const { + return kBinNameCpp2mpl; +} + +std::string Cpp2MplCompiler::GetInputFileName(const MplOptions &options) const { + if (!options.GetRunningExes().empty()) { + if (options.GetRunningExes()[0] == kBinNameCpp2mpl) { + return options.GetInputFiles(); + } + } + // Get base file name + auto idx = options.GetOutputName().find(".ast"); + std::string outputName = options.GetOutputName(); + if (idx != std::string::npos) { + outputName = options.GetOutputName().substr(0, idx); + } + return options.GetOutputFolder() + outputName + ".ast"; +} + +DefaultOption Cpp2MplCompiler::GetDefaultOptions(const MplOptions &options) const { + DefaultOption defaultOptions = { nullptr, 0 }; + defaultOptions.mplOptions = kCpp2MplDefaultOptionsForAst; + defaultOptions.length = sizeof(kCpp2MplDefaultOptionsForAst) / sizeof(MplOption); + + for (uint32_t i = 0; i < defaultOptions.length; ++i) { + defaultOptions.mplOptions[i].SetValue( + FileUtils::AppendMapleRootIfNeeded(defaultOptions.mplOptions[i].GetNeedRootPath(), + defaultOptions.mplOptions[i].GetValue(), + options.GetExeFolder())); + } + return defaultOptions; +} + +void Cpp2MplCompiler::GetTmpFilesToDelete(const MplOptions &mplOptions, std::vector &tempFiles) const { + tempFiles.push_back(mplOptions.GetOutputFolder() + mplOptions.GetOutputName() + ".mpl"); + tempFiles.push_back(mplOptions.GetOutputFolder() + mplOptions.GetOutputName() + ".mplt"); +} + +std::unordered_set Cpp2MplCompiler::GetFinalOutputs(const MplOptions &mplOptions) const { + std::unordered_set finalOutputs; + (void)finalOutputs.insert(mplOptions.GetOutputFolder() + mplOptions.GetOutputName() + ".mpl"); + (void)finalOutputs.insert(mplOptions.GetOutputFolder() + mplOptions.GetOutputName() + ".mplt"); + return finalOutputs; +} +} // namespace maple \ No newline at end of file diff --git a/src/mapleall/maple_driver/src/driver_option_common.cpp b/src/mapleall/maple_driver/src/driver_option_common.cpp index dda7b4487c..04a85733ed 100644 --- a/src/mapleall/maple_driver/src/driver_option_common.cpp +++ b/src/mapleall/maple_driver/src/driver_option_common.cpp @@ -138,6 +138,23 @@ const mapleOption::Descriptor usages[] = { " --jbc2mpl-opt \tSet options for jbc2mpl\n", "all", {} }, + { kCpp2mplOpt, + 0, + "", + "cpp2mpl-opt", + kBuildTypeProduct, + kArgCheckPolicyNone, + " --cpp2mpl-opt \tSet options for cpp2mpl\n", + "all", + {} }, + { kAsOpt, + 0, + "", + "as-opt", + kBuildTypeProduct, + kArgCheckPolicyNone, + "--as-opt \tSet options for as\n", + {} }, { kDex2mplOpt, 0, "", @@ -289,7 +306,7 @@ const mapleOption::Descriptor usages[] = { kArgCheckPolicyBool, " -verbose \t: print informations\n", "all", - { "jbc2mpl", "me", "mpl2mpl", "mplcg" } }, + { "jbc2mpl", "cpp2mpl", "me", "mpl2mpl", "mplcg" } }, { kAllDebug, 0, "", diff --git a/src/mapleall/maple_driver/src/mpl_options.cpp b/src/mapleall/maple_driver/src/mpl_options.cpp index f16918ebb2..fcda46e22a 100644 --- a/src/mapleall/maple_driver/src/mpl_options.cpp +++ b/src/mapleall/maple_driver/src/mpl_options.cpp @@ -31,6 +31,8 @@ #endif #include "ipa_option.h" #include "jbc2mpl_option.h" +#include "as_option.h" +#include "cpp2mpl_option.h" #include "me_option.h" #include "option.h" #include "cg_option.h" @@ -42,9 +44,9 @@ using namespace maplebe; const std::string kMapleDriverVersion = "MapleDriver " + std::to_string(Version::kMajorMplVersion) + "." + std::to_string(Version::kMinorCompilerVersion) + " 20190929"; -const std::vector kMapleCompilers = { "jbc2mpl", - "dex2mpl", "mplipa", - "me", "mpl2mpl", "mplcg" }; +const std::vector kMapleCompilers = { "jbc2mpl", "cpp2mpl", + "dex2mpl", "mplipa", "as", + "me", "mpl2mpl", "mplcg", "clang"}; int MplOptions::Parse(int argc, char **argv) { optionParser.reset(new OptionParser()); @@ -56,6 +58,9 @@ int MplOptions::Parse(int argc, char **argv) { #endif optionParser->RegisteUsages(IpaOption::GetInstance()); optionParser->RegisteUsages(jbcUsage); + optionParser->RegisteUsages(cppUsage); + // Not sure if this is even required + // optionParser->RegisteUsages(asUsage); optionParser->RegisteUsages(Options::GetInstance()); optionParser->RegisteUsages(MeOption::GetInstance()); optionParser->RegisteUsages(CGOptions::GetInstance()); @@ -128,6 +133,18 @@ ErrorCode MplOptions::HandleGeneralOptions() { return ret; } break; + case kAsOpt: + ret = UpdatePhaseOption(opt.Args(), kBinNameAs); + if (ret != kErrorNoError) { + return ret; + } + break; + case kCpp2mplOpt: + ret = UpdatePhaseOption(opt.Args(), kBinNameCpp2mpl); + if (ret != kErrorNoError) { + return ret; + } + break; case kJbc2mplOpt: ret = UpdatePhaseOption(opt.Args(), kBinNameJbc2mpl); if (ret != kErrorNoError) { @@ -255,6 +272,13 @@ ErrorCode MplOptions::DecideRunningPhases() { bool isNeedMapleComb = true; bool isNeedMplcg = true; switch (inputFileType) { + case InputFileType::kFileTypeC: + case InputFileType::kFileTypeCpp: + UpdateRunningExe(kBinNameClang); + break; + case InputFileType::kFileTypeAst: + UpdateRunningExe(kBinNameCpp2mpl); + break; case InputFileType::kFileTypeJar: // fall-through case InputFileType::kFileTypeClass: @@ -359,9 +383,19 @@ bool MplOptions::Init(const std::string &inputFile) { else if (extensionName == "dex") { inputFileType = InputFileType::kFileTypeDex; } + else if (extensionName == "c") { + inputFileType = InputFileType::kFileTypeC; + } + else if (extensionName == "cpp") { + inputFileType = InputFileType::kFileTypeCpp; + } + else if (extensionName == "ast") { + inputFileType = InputFileType::kFileTypeAst; + } else if (extensionName == "jar") { inputFileType = InputFileType::kFileTypeJar; - } else if (extensionName == "mpl" || extensionName == "bpl") { + } + else if (extensionName == "mpl" || extensionName == "bpl") { if (firstInputFile.find("VtableImpl") == std::string::npos) { if (firstInputFile.find(".me.mpl") != std::string::npos) { inputFileType = InputFileType::kFileTypeMeMpl; @@ -605,4 +639,4 @@ void MplOptions::PrintDetailCommand(bool isBeforeParse) { << printCommandStr << " " << GetInputFileNameForPrint() << '\n'; } } -} // namespace maple +} // namespace maple -- Gitee From 26f67012d02ccafb41f2d08a234ba75c6a144655 Mon Sep 17 00:00:00 2001 From: antyshevtg Date: Thu, 12 Aug 2021 17:02:31 +0300 Subject: [PATCH 14/16] Clang bug fix --- src/mapleall/maple_driver/defs/default/O0_options_clang.def | 3 ++- src/mapleall/maple_driver/src/clang_compiler.cpp | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/mapleall/maple_driver/defs/default/O0_options_clang.def b/src/mapleall/maple_driver/defs/default/O0_options_clang.def index f7dabc091c..a8edd35c27 100644 --- a/src/mapleall/maple_driver/defs/default/O0_options_clang.def +++ b/src/mapleall/maple_driver/defs/default/O0_options_clang.def @@ -1 +1,2 @@ -{"-emit-ast", "", false} \ No newline at end of file +{"-emit-ast", "", false}, +{"-o", "", false}, \ No newline at end of file diff --git a/src/mapleall/maple_driver/src/clang_compiler.cpp b/src/mapleall/maple_driver/src/clang_compiler.cpp index b73c3c40e9..2789ddaf81 100644 --- a/src/mapleall/maple_driver/src/clang_compiler.cpp +++ b/src/mapleall/maple_driver/src/clang_compiler.cpp @@ -15,6 +15,7 @@ #include #include "compiler.h" #include "file_utils.h" +#include "mpl_timer.h" #include "default_options.def" namespace maple { @@ -31,6 +32,7 @@ const std::string &ClangCompiler::GetBinName() const { DefaultOption ClangCompiler::GetDefaultOptions(const MplOptions &options) const { DefaultOption defaultOptions = { nullptr, 0 }; defaultOptions.mplOptions = kClangDefaultOptions; + defaultOptions.mplOptions[1].SetValue( options.GetOutputFolder() + options.GetOutputName() + ".ast"); defaultOptions.length = sizeof(kClangDefaultOptions) / sizeof(MplOption); for (uint32_t i = 0; i < defaultOptions.length; ++i) { -- Gitee From 8b6713f6970b2907222c9086a34d767e623b0167 Mon Sep 17 00:00:00 2001 From: Tikhon Antyshev Date: Fri, 13 Aug 2021 10:34:06 +0300 Subject: [PATCH 15/16] delete gitignore --- .gitignore | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 .gitignore diff --git a/.gitignore b/.gitignore deleted file mode 100644 index f71bf2703f..0000000000 --- a/.gitignore +++ /dev/null @@ -1,28 +0,0 @@ -android/* -third_party/d8* -third_party/icu* -third_party/libdex* -third_party/aosp_10.0.0_r35* -third_party/aosp_modified* -third_party/ctorture* -third_party/llvm_modified* -tools/bin* -tools/android* -tools/aosp* -tools/clang* -tools/gcc* -tools/gn* -tools/icu* -tools/libz* -tools/zlib* -tools/ninja* -tools/qemu* -tools/r8* -tools/release* -tools/sysroot-glibc* -build/logs* -libjava-core -output -compile_commands.json -testsuite/tools* -*__pycache__* -- Gitee From 73662bd21412e2ba0ac5cc58d609adae698504a5 Mon Sep 17 00:00:00 2001 From: Tikhon Antyshev Date: Tue, 17 Aug 2021 10:25:30 +0300 Subject: [PATCH 16/16] [mapleall] c2mpl driver patch fix --- src/mapleall/maple_driver/include/as_option.h | 7 ------- src/mapleall/maple_driver/include/compiler.h | 3 ++- .../maple_driver/include/cpp2mpl_option.h | 19 ++++++------------- src/mapleall/maple_driver/src/as_compiler.cpp | 4 ++-- .../maple_driver/src/compiler_factory.cpp | 2 +- .../maple_driver/src/driver_option_common.cpp | 6 +++--- src/mapleall/maple_driver/src/mpl_options.cpp | 5 +++-- 7 files changed, 17 insertions(+), 29 deletions(-) diff --git a/src/mapleall/maple_driver/include/as_option.h b/src/mapleall/maple_driver/include/as_option.h index 3a32617987..cb75e589e6 100644 --- a/src/mapleall/maple_driver/include/as_option.h +++ b/src/mapleall/maple_driver/include/as_option.h @@ -18,7 +18,6 @@ namespace maple { enum AsOptionIndex { - kInS, kAsHelp, }; @@ -30,12 +29,6 @@ const mapleOption::Descriptor asUsage[] = { "as", {} }, - { kInS, 0, "", "in-s", mapleOption::kBuildTypeAll, mapleOption::kArgCheckPolicyRequired, - " --in-s file1.s,file2.s\n" - " : input asm files", - "as", - {} }, - { kAsHelp, 0, "h", "help", mapleOption::kBuildTypeExperimental, mapleOption::kArgCheckPolicyNone, " -h, --help : print usage and exit.\n", diff --git a/src/mapleall/maple_driver/include/compiler.h b/src/mapleall/maple_driver/include/compiler.h index 044fd70ee8..4f3e4339e2 100644 --- a/src/mapleall/maple_driver/include/compiler.h +++ b/src/mapleall/maple_driver/include/compiler.h @@ -40,13 +40,14 @@ const std::string kBinNameMe = "me"; const std::string kBinNameMpl2mpl = "mpl2mpl"; const std::string kBinNameMplcg = "mplcg"; const std::string kBinNameMapleComb = "maplecomb"; -const std::string kBinNameAs = "as"; const std::string kBinNameLd = "ld"; const std::string kMachine = "aarch64-"; const std::string kVendor = "unknown-"; const std::string kOperatingSystem = "linux-gnu-"; const std::string kGccFlag = "gcc"; const std::string kGppFlag = "g++"; +const std::string kAsFlag = "as"; +const std::string kBinNameAs = kMachine + kOperatingSystem + kAsFlag; const std::string kBinNameGcc = kMachine + kOperatingSystem + kGccFlag; const std::string kBinNameGpp = kMachine + kOperatingSystem + kGppFlag; diff --git a/src/mapleall/maple_driver/include/cpp2mpl_option.h b/src/mapleall/maple_driver/include/cpp2mpl_option.h index 01433ddcb0..386fe5f44d 100644 --- a/src/mapleall/maple_driver/include/cpp2mpl_option.h +++ b/src/mapleall/maple_driver/include/cpp2mpl_option.h @@ -19,38 +19,31 @@ namespace maple { enum CppOptionIndex { kInAst, - kInCpp, kCpp2mplHelp, }; const mapleOption::Descriptor cppUsage[] = { { kUnknown, 0, "", "", mapleOption::kBuildTypeAll, mapleOption::kArgCheckPolicyUnknown, "========================================\n" - " Usage: cpp2mpl [ options ]\n" + " Usage: c2mpl [ options ]\n" " options:\n", - "cpp2mpl", + "c2mpl", {} }, { kInAst, 0, "", "inast", mapleOption::kBuildTypeAll, mapleOption::kArgCheckPolicyRequired, - " -in-ast file1.ast,file2.ast\n" + " -inast file1.ast,file2.ast\n" " : input ast files", - "cpp2mpl", - {} }, - - { kInCpp, 0, "", "incpp", mapleOption::kBuildTypeAll, mapleOption::kArgCheckPolicyRequired, - " -in-cpp file1.cpp,file2.cpp\n" - " : input cpp files", - "cpp2mpl", + "c2mpl", {} }, { kCpp2mplHelp, 0, "h", "help", mapleOption::kBuildTypeExperimental, mapleOption::kArgCheckPolicyNone, " -h, --help : print usage and exit.\n", - "cpp2mpl", + "c2mpl", {} }, { kUnknown, 0, "", "", mapleOption::kBuildTypeAll, mapleOption::kArgCheckPolicyNone, "", - "cpp2mpl", + "c2mpl", {} } }; } // namespace maple diff --git a/src/mapleall/maple_driver/src/as_compiler.cpp b/src/mapleall/maple_driver/src/as_compiler.cpp index f7f6f34fb5..7f6e6b4f6a 100644 --- a/src/mapleall/maple_driver/src/as_compiler.cpp +++ b/src/mapleall/maple_driver/src/as_compiler.cpp @@ -25,7 +25,7 @@ std::string AsCompiler::GetBinPath(const MplOptions&) const { } const std::string &AsCompiler::GetBinName() const { - return kBinNameGcc; + return kBinNameAs; } DefaultOption AsCompiler::GetDefaultOptions(const MplOptions&) const { @@ -34,7 +34,7 @@ DefaultOption AsCompiler::GetDefaultOptions(const MplOptions&) const { } std::string AsCompiler::GetInputFileName(const MplOptions &options) const { - return options.GetOutputFolder() + options.GetOutputName() + ".VtableImpl.s"; + return options.GetOutputFolder() + options.GetOutputName() + ".s"; } void AsCompiler::GetTmpFilesToDelete(const MplOptions &mplOptions, std::vector &tempFiles) const { diff --git a/src/mapleall/maple_driver/src/compiler_factory.cpp b/src/mapleall/maple_driver/src/compiler_factory.cpp index e399c2ec20..ae50de6a8e 100644 --- a/src/mapleall/maple_driver/src/compiler_factory.cpp +++ b/src/mapleall/maple_driver/src/compiler_factory.cpp @@ -34,7 +34,7 @@ CompilerFactory::CompilerFactory() { // Supported compilers ADD_COMPILER("jbc2mpl", Jbc2MplCompiler) ADD_COMPILER("dex2mpl", Dex2MplCompiler) - ADD_COMPILER("cpp2mpl", Cpp2MplCompiler) + ADD_COMPILER("c2mpl", Cpp2MplCompiler) ADD_COMPILER("clang", ClangCompiler) ADD_COMPILER("mplipa", IpaCompiler) ADD_COMPILER("me", MapleCombCompiler) diff --git a/src/mapleall/maple_driver/src/driver_option_common.cpp b/src/mapleall/maple_driver/src/driver_option_common.cpp index 04a85733ed..5ca3f15c8b 100644 --- a/src/mapleall/maple_driver/src/driver_option_common.cpp +++ b/src/mapleall/maple_driver/src/driver_option_common.cpp @@ -141,10 +141,10 @@ const mapleOption::Descriptor usages[] = { { kCpp2mplOpt, 0, "", - "cpp2mpl-opt", + "c2mpl-opt", kBuildTypeProduct, kArgCheckPolicyNone, - " --cpp2mpl-opt \tSet options for cpp2mpl\n", + " --c2mpl-opt \tSet options for cpp2mpl\n", "all", {} }, { kAsOpt, @@ -306,7 +306,7 @@ const mapleOption::Descriptor usages[] = { kArgCheckPolicyBool, " -verbose \t: print informations\n", "all", - { "jbc2mpl", "cpp2mpl", "me", "mpl2mpl", "mplcg" } }, + { "jbc2mpl", "c2mpl", "me", "mpl2mpl", "mplcg" } }, { kAllDebug, 0, "", diff --git a/src/mapleall/maple_driver/src/mpl_options.cpp b/src/mapleall/maple_driver/src/mpl_options.cpp index fcda46e22a..f97d9f34b0 100644 --- a/src/mapleall/maple_driver/src/mpl_options.cpp +++ b/src/mapleall/maple_driver/src/mpl_options.cpp @@ -44,7 +44,7 @@ using namespace maplebe; const std::string kMapleDriverVersion = "MapleDriver " + std::to_string(Version::kMajorMplVersion) + "." + std::to_string(Version::kMinorCompilerVersion) + " 20190929"; -const std::vector kMapleCompilers = { "jbc2mpl", "cpp2mpl", +const std::vector kMapleCompilers = { "jbc2mpl", "c2mpl", "dex2mpl", "mplipa", "as", "me", "mpl2mpl", "mplcg", "clang"}; @@ -275,9 +275,10 @@ ErrorCode MplOptions::DecideRunningPhases() { case InputFileType::kFileTypeC: case InputFileType::kFileTypeCpp: UpdateRunningExe(kBinNameClang); + UpdateRunningExe("c2mpl"); break; case InputFileType::kFileTypeAst: - UpdateRunningExe(kBinNameCpp2mpl); + UpdateRunningExe("c2mpl"); break; case InputFileType::kFileTypeJar: // fall-through -- Gitee