diff --git a/src/mapleall/bin/dex2mpl b/src/mapleall/bin/dex2mpl index 2e4d12eb305fbb1689ce4d65a3eab329fe852b4a..4c9ee78e699dd058f1d40c18e82db4f780042104 100755 Binary files a/src/mapleall/bin/dex2mpl and b/src/mapleall/bin/dex2mpl differ diff --git a/src/mapleall/maple_be/src/cg/aarch64/aarch64_proepilog.cpp b/src/mapleall/maple_be/src/cg/aarch64/aarch64_proepilog.cpp index 8a1939f7fa48a16701e7572411a8522f4ac913e5..fb6d239af766406f7e83337100d03cb8b63b0cb1 100644 --- a/src/mapleall/maple_be/src/cg/aarch64/aarch64_proepilog.cpp +++ b/src/mapleall/maple_be/src/cg/aarch64/aarch64_proepilog.cpp @@ -1294,9 +1294,9 @@ void AArch64GenProEpilog::GeneratePushUnnamedVarargRegs() { for (uint32 i = start_regno + static_cast(V0); i < static_cast(V8); i++) { Operand &stackloc = aarchCGFunc.CreateStkTopOpnd(offset, dataSizeBits); RegOperand ® = - aarchCGFunc.GetOrCreatePhysicalRegisterOperand(static_cast(i), k64BitSize, kRegTyInt); + aarchCGFunc.GetOrCreatePhysicalRegisterOperand(static_cast(i), k64BitSize, kRegTyFloat); Insn &inst = - currCG->BuildInstruction(aarchCGFunc.PickStInsn(dataSizeBits, PTY_i64), reg, stackloc); + currCG->BuildInstruction(aarchCGFunc.PickStInsn(dataSizeBits, PTY_f64), reg, stackloc); cgFunc.GetCurBB()->AppendInsn(inst); offset += (kSizeOfPtr * k2BitSize); } diff --git a/src/mapleall/maple_driver/BUILD.gn b/src/mapleall/maple_driver/BUILD.gn index e9efbfca10adb342c239097b0f410163e9b082a8..47e497e17889e59df843fc6d9429d4ee99e7c14a 100644 --- a/src/mapleall/maple_driver/BUILD.gn +++ b/src/mapleall/maple_driver/BUILD.gn @@ -53,6 +53,7 @@ executable("maple") { "src/clang_compiler.cpp", "src/ld_compiler.cpp", "src/maple.cpp", + "src/maple_comb_compiler_wrapper.cpp", "src/maple_comb_compiler.cpp", "src/mpl_options.cpp", "src/mplcg_compiler.cpp", diff --git a/src/mapleall/maple_driver/defs/default/O0_options_ld.def b/src/mapleall/maple_driver/defs/default/O0_options_ld.def index 6ab606bc6c342a78c158b9438edd165742613035..035cffe53c9502acc9fe8f4fdb7a51e240dc5d8c 100644 --- a/src/mapleall/maple_driver/defs/default/O0_options_ld.def +++ b/src/mapleall/maple_driver/defs/default/O0_options_ld.def @@ -1,2 +1 @@ -{"-o", "", false}, {"-static", "", false} \ 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 9c542e7c1856aab59ff34a7bd09b34741a8a6f70..6dfe17d4cbe782497b3fe06ee777b1829b93fa50 100644 --- a/src/mapleall/maple_driver/include/compiler.h +++ b/src/mapleall/maple_driver/include/compiler.h @@ -40,6 +40,7 @@ const std::string kBinNameMe = "me"; const std::string kBinNameMpl2mpl = "mpl2mpl"; const std::string kBinNameMplcg = "mplcg"; const std::string kBinNameMapleComb = "maplecomb"; +const std::string kBinNameMapleCombWrp = "maplecombwrp"; const std::string kMachine = "aarch64-"; const std::string kVendor = "unknown-"; const std::string kOperatingSystem = "linux-gnu-"; @@ -58,15 +59,17 @@ class Compiler { virtual ~Compiler() = default; - virtual ErrorCode Compile(MplOptions &options, std::unique_ptr &theModule); + virtual ErrorCode Compile(MplOptions &options, const Action &action, + std::unique_ptr &theModule); - virtual void GetTmpFilesToDelete(const MplOptions&, std::vector&) const {} + virtual void GetTmpFilesToDelete(const MplOptions&, const Action &action, + std::vector&) const {} - virtual std::unordered_set GetFinalOutputs(const MplOptions&) const { + virtual std::unordered_set GetFinalOutputs(const MplOptions&, const Action &) const { return std::unordered_set(); } - virtual void PrintCommand(const MplOptions&) const {} + virtual void PrintCommand(const MplOptions&, const Action &action) const {} protected: virtual std::string GetBinPath(const MplOptions &mplOptions) const; @@ -74,21 +77,18 @@ class Compiler { return kBinNameNone; } - virtual std::string GetInputFileName(const MplOptions &options) const { - std::ostringstream stream; - for (const auto &inputFile : options.GetSplitsInputFiles()) { - stream << " " << inputFile; - } - return stream.str(); + virtual std::string GetInputFileName(const MplOptions &, const Action &action) const { + return action.GetInputFile(); } - virtual DefaultOption GetDefaultOptions(const MplOptions&) const { + + virtual DefaultOption GetDefaultOptions(const MplOptions&, const Action &) const { return DefaultOption(); } private: const std::string name; - std::string MakeOption(const MplOptions &options) const; + std::string MakeOption(const MplOptions &options, const Action &action) const; void AppendDefaultOptions(std::map &finalOptions, const std::map &defaultOptions, std::ostringstream &strOption, bool isDebug) const; @@ -97,7 +97,7 @@ class Compiler { void AppendExtraOptions(std::map &finalOptions, const MplOptions &options, std::ostringstream &strOption, bool isDebug) const; - std::map MakeDefaultOptions(const MplOptions &options) const; + std::map MakeDefaultOptions(const MplOptions &options, const Action &action) const; int Exe(const MplOptions &mplOptions, const std::string &options) const; const std::string &GetName() const { return name; @@ -112,9 +112,11 @@ class Jbc2MplCompiler : public Compiler { 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; + DefaultOption GetDefaultOptions(const MplOptions &options, const Action &action) const override; + void GetTmpFilesToDelete(const MplOptions &mplOptions, const Action &action, + std::vector &tempFiles) const override; + std::unordered_set GetFinalOutputs(const MplOptions &mplOptions, + const Action &action) const override; }; class ClangCompiler : public Compiler { @@ -126,9 +128,11 @@ class ClangCompiler : public Compiler { 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 ; + DefaultOption GetDefaultOptions(const MplOptions &options, const Action &action) const override; + void GetTmpFilesToDelete(const MplOptions &mplOptions, const Action &action, + std::vector &tempFiles) const override; + std::unordered_set GetFinalOutputs(const MplOptions &mplOptions, + const Action &action) const override ; }; class Cpp2MplCompiler : public Compiler { @@ -140,10 +144,12 @@ class Cpp2MplCompiler : public Compiler { 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; + std::string GetInputFileName(const MplOptions &options, const Action &action) const override; + DefaultOption GetDefaultOptions(const MplOptions &options, const Action &action) const override; + void GetTmpFilesToDelete(const MplOptions &mplOptions, const Action &action, + std::vector &tempFiles) const override; + std::unordered_set GetFinalOutputs(const MplOptions &mplOptions, + const Action &action) const override; }; class Dex2MplCompiler : public Compiler { @@ -152,16 +158,19 @@ class Dex2MplCompiler : public Compiler { ~Dex2MplCompiler() = default; #ifdef INTERGRATE_DRIVER - ErrorCode Compile(MplOptions &options, std::unique_ptr &theModule) override; + ErrorCode Compile(MplOptions &options, const Action &action, + std::unique_ptr &theModule) override; #endif - void PrintCommand(const MplOptions &options) const override; + void PrintCommand(const MplOptions &options, const Action &action) const override; 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; + DefaultOption GetDefaultOptions(const MplOptions &options, const Action &action) const override; + void GetTmpFilesToDelete(const MplOptions &mplOptions, const Action &action, + std::vector &tempFiles) const override; + std::unordered_set GetFinalOutputs(const MplOptions &mplOptions, + const Action &action) const override; #ifdef INTERGRATE_DRIVER void PostDex2Mpl(std::unique_ptr &theModule) const; bool MakeDex2mplOptions(const MplOptions &options); @@ -176,8 +185,8 @@ class IpaCompiler : public Compiler { private: const std::string &GetBinName() const override; - DefaultOption GetDefaultOptions(const MplOptions &options) const override; - std::string GetInputFileName(const MplOptions &options) const override; + DefaultOption GetDefaultOptions(const MplOptions &options, const Action &action) const override; + std::string GetInputFileName(const MplOptions &options, const Action &action) const override; }; class MapleCombCompiler : public Compiler { @@ -186,13 +195,16 @@ class MapleCombCompiler : public Compiler { ~MapleCombCompiler() = default; - ErrorCode Compile(MplOptions &options, std::unique_ptr &theModule) override; - void PrintCommand(const MplOptions &options) const override; - std::string GetInputFileName(const MplOptions &options) const override; + ErrorCode Compile(MplOptions &options, const Action &action, + std::unique_ptr &theModule) override; + void PrintCommand(const MplOptions &options, const Action &action) const override; + std::string GetInputFileName(const MplOptions &options, const Action &action) const override; private: - std::unordered_set GetFinalOutputs(const MplOptions &mplOptions) const override; - void GetTmpFilesToDelete(const MplOptions &mplOptions, std::vector &tempFiles) const override; + std::unordered_set GetFinalOutputs(const MplOptions &mplOptions, + const Action &action) const override; + void GetTmpFilesToDelete(const MplOptions &mplOptions, const Action &action, + std::vector &tempFiles) const override; ErrorCode MakeMeOptions(const MplOptions &options, DriverRunner &runner); ErrorCode MakeMpl2MplOptions(const MplOptions &options, DriverRunner &runner); std::string DecideOutExe(const MplOptions &options); @@ -203,19 +215,37 @@ class MplcgCompiler : public Compiler { explicit MplcgCompiler(const std::string &name) : Compiler(name) {} ~MplcgCompiler() = default; - ErrorCode Compile(MplOptions &options, std::unique_ptr &theModule) override; - void PrintMplcgCommand(const MplOptions &options, const MIRModule &md) const; - void SetOutputFileName(const MplOptions &options, const MIRModule &md); - std::string GetInputFile(const MplOptions &options, const MIRModule *md) const; + ErrorCode Compile(MplOptions &options, const Action &action, + std::unique_ptr &theModule) override; + void PrintMplcgCommand(const MplOptions &options, const Action &action, const MIRModule &md) const; + void SetOutputFileName(const MplOptions &options, const Action &action, const MIRModule &md); + std::string GetInputFile(const MplOptions &options, const Action &action, const MIRModule *md) const; private: - DefaultOption GetDefaultOptions(const MplOptions &options) const override; - ErrorCode GetMplcgOptions(MplOptions &options, const MIRModule *theModule); + DefaultOption GetDefaultOptions(const MplOptions &options, const Action &action) const override; + ErrorCode GetMplcgOptions(MplOptions &options, const Action &action, const MIRModule *theModule); ErrorCode MakeCGOptions(const MplOptions &options); const std::string &GetBinName() const override; std::string baseName; std::string outputFile; }; +class MapleCombCompilerWrp : public Compiler { + public: + explicit MapleCombCompilerWrp(const std::string &name) : Compiler(name) {} + ~MapleCombCompilerWrp() = default; + + std::string GetInputFileName(const MplOptions &options, const Action &action) const override; + + private: + std::string GetBinPath(const MplOptions &options) const override; + const std::string &GetBinName() const override; + DefaultOption GetDefaultOptions(const MplOptions &options, const Action &action) const override; + void GetTmpFilesToDelete(const MplOptions &mplOptions, const Action &action, + std::vector &tempFiles) const override; + std::unordered_set GetFinalOutputs(const MplOptions &mplOptions, + const Action &action) const override; +}; + // Build .s to .o class AsCompiler : public Compiler { public: @@ -226,10 +256,12 @@ class AsCompiler : public Compiler { private: std::string GetBinPath(const MplOptions &options) const override; const std::string &GetBinName() const override; - DefaultOption GetDefaultOptions(const MplOptions &options) const override; - std::string GetInputFileName(const MplOptions &options) const override; - void GetTmpFilesToDelete(const MplOptions &mplOptions, std::vector &tempFiles) const override; - std::unordered_set GetFinalOutputs(const MplOptions &mplOptions) const override; + DefaultOption GetDefaultOptions(const MplOptions &options, const Action &action) const override; + std::string GetInputFileName(const MplOptions &options, const Action &action) const override; + void GetTmpFilesToDelete(const MplOptions &mplOptions, const Action &action, + std::vector &tempFiles) const override; + std::unordered_set GetFinalOutputs(const MplOptions &mplOptions, + const Action &action) const override; }; // Build .o to .so @@ -242,9 +274,8 @@ class LdCompiler : public Compiler { private: std::string GetBinPath(const MplOptions &options) const override; const std::string &GetBinName() const override; - DefaultOption GetDefaultOptions(const MplOptions &options) const override; - std::string GetInputFileName(const MplOptions &options) const override; - void GetTmpFilesToDelete(const MplOptions &mplOptions, std::vector &tempFiles) const override; + DefaultOption GetDefaultOptions(const MplOptions &options, const Action &action) const override; + std::string GetInputFileName(const MplOptions &options, const Action &action) const override; }; } // namespace maple #endif // MAPLE_DRIVER_INCLUDE_COMPILER_H diff --git a/src/mapleall/maple_driver/include/compiler_factory.h b/src/mapleall/maple_driver/include/compiler_factory.h index 4a6046d22b837144ee1b570bea020d37b83c5479..1b5118ff5d94164fede2fe4c98a248923824f84c 100644 --- a/src/mapleall/maple_driver/include/compiler_factory.h +++ b/src/mapleall/maple_driver/include/compiler_factory.h @@ -36,8 +36,8 @@ class CompilerFactory { bool compileFinished = false; CompilerFactory(); void Insert(const std::string &name, Compiler *value); - ErrorCode DeleteTmpFiles(const MplOptions &mplOptions, const std::vector &tempFiles, - const std::unordered_set &finalOutputs) const; + ErrorCode DeleteTmpFiles(const MplOptions &mplOptions, + const std::vector &tempFiles) const; SupportedCompilers supportedCompilers; CompilerSelector *compilerSelector; std::unique_ptr theModule; diff --git a/src/mapleall/maple_driver/include/compiler_selector.h b/src/mapleall/maple_driver/include/compiler_selector.h index b226f9971d6b8a3a3fc1192163f3d87e58750e1a..9c819e7d27e7a32fe4c1ee523b9ca467df64a00d 100644 --- a/src/mapleall/maple_driver/include/compiler_selector.h +++ b/src/mapleall/maple_driver/include/compiler_selector.h @@ -27,7 +27,8 @@ class CompilerSelector { virtual ~CompilerSelector() = default; - virtual ErrorCode Select(const SupportedCompilers&, const MplOptions&, std::vector&) const { + virtual ErrorCode Select(const SupportedCompilers&, const MplOptions&, + std::vector&) const { return kErrorToolNotFound; } }; @@ -39,12 +40,14 @@ class CompilerSelectorImpl : public CompilerSelector { ~CompilerSelectorImpl() = default; ErrorCode Select(const SupportedCompilers &supportedCompilers, const MplOptions &mplOptions, - std::vector &selected) const override; + std::vector &selectedActions) const override; private: Compiler *FindCompiler(const SupportedCompilers &compilers, const std::string &name) const; ErrorCode InsertCompilerIfNeeded(std::vector &selected, const SupportedCompilers &compilers, const std::string &name) const; + ErrorCode Select(const SupportedCompilers &supportedCompilers, const MplOptions &mplOptions, + Action &action, std::vector &selectedActions) const; }; } // namespace maple #endif // MAPLE_DRIVER_INCLUDE_COMPILER_SELECTOR_H diff --git a/src/mapleall/maple_driver/include/driver_option_common.h b/src/mapleall/maple_driver/include/driver_option_common.h index ee3f6e8a38a7eb80b5a7c8443d91fab6f67df035..5758a0bca78931a7488346e7f8da10e9816472b2 100644 --- a/src/mapleall/maple_driver/include/driver_option_common.h +++ b/src/mapleall/maple_driver/include/driver_option_common.h @@ -20,6 +20,7 @@ namespace maple { enum DriverOptionIndex { kUnknown, kHelp, + kMaplePrintPhases, kVersion, kInFile, kInMplt, diff --git a/src/mapleall/maple_driver/include/mpl_options.h b/src/mapleall/maple_driver/include/mpl_options.h index 547f1547079cb940fc13152413a928434bce753d..6a7a2cd98552aa224ddf69108f166cdd44c0b5c1 100644 --- a/src/mapleall/maple_driver/include/mpl_options.h +++ b/src/mapleall/maple_driver/include/mpl_options.h @@ -58,8 +58,171 @@ enum RunMode { kUnkownRun }; +class Compiler; + +class InputInfo { +public: + InputInfo(const std::string &inputFile) + : inputFile(inputFile) { + + inputFileType = GetInputFileType(inputFile); + + inputName = FileUtils::GetFileName(inputFile, true); + inputFolder = FileUtils::GetFileFolder(inputFile); + outputFolder = inputFolder; + outputName = FileUtils::GetFileName(inputFile, false); + fullOutput = outputFolder + outputName; + } + + static InputFileType GetInputFileType(const std::string &inputFile) { + InputFileType fileType = InputFileType::kFileTypeNone; + std::string extensionName = FileUtils::GetFileExtension(inputFile); + + if (extensionName == "class") { + fileType = InputFileType::kFileTypeClass; + } + else if (extensionName == "dex") { + fileType = InputFileType::kFileTypeDex; + } + else if (extensionName == "c") { + fileType = InputFileType::kFileTypeC; + } + else if (extensionName == "cpp") { + fileType = InputFileType::kFileTypeCpp; + } + else if (extensionName == "ast") { + fileType = InputFileType::kFileTypeAst; + } + else if (extensionName == "jar") { + fileType = InputFileType::kFileTypeJar; + } + else if (extensionName == "mpl" || extensionName == "bpl") { + if (inputFile.find("VtableImpl") == std::string::npos) { + if (inputFile.find(".me.mpl") != std::string::npos) { + fileType = InputFileType::kFileTypeMeMpl; + } else { + fileType = extensionName == "mpl" ? InputFileType::kFileTypeMpl : InputFileType::kFileTypeBpl; + } + } else { + fileType = InputFileType::kFileTypeVtableImplMpl; + } + } else if (extensionName == "s") { + fileType = InputFileType::kFileTypeS; + } + + return fileType; + } + + InputFileType GetInputFileType() const { + return inputFileType; + } + + const std::string &GetInputFile() const { + return inputFile; + } + + const std::string &GetOutputFolder() const { + return outputFolder; + } + + const std::string &GetOutputName() const { + return outputName; + } + + const std::string &GetFullOutputName() const { + return fullOutput; + } + +private: + std::string inputFile = ""; + InputFileType inputFileType = InputFileType::kFileTypeNone; + + std::string inputName = ""; + std::string inputFolder = ""; + std::string outputName = ""; + std::string outputFolder = ""; + std::string fullOutput = ""; +}; + +class Action { +public: + Action(const std::string &tool, std::shared_ptr inputInfo) + : inputInfo(inputInfo), tool(tool) {} + + Action(const std::string &tool, std::shared_ptr inputInfo, + std::shared_ptr in_action) + : inputInfo(inputInfo), tool(tool) { + inputActions.push_back(in_action); + } + + Action(const std::string &tool, const std::vector> &inActions) + : tool(tool) { + + for (auto &inAction : inActions) { + inputActions.push_back(inAction); + linkInputFiles.push_back(inAction->GetInputFile()); + } + + /* FIXME: fix hardcode a.out */ + inputInfo = std::make_shared("./a.out"); + } + + const std::string &GetTool() const { + return tool; + } + + const std::string &GetInputFile() const { + return inputInfo->GetInputFile(); + } + + const std::string &GetOutputFolder() const { + return inputInfo->GetOutputFolder(); + } + + const std::string &GetOutputName() const { + return inputInfo->GetOutputName(); + } + + const std::string &GetFullOutputName() const { + return inputInfo->GetFullOutputName(); + } + + InputFileType GetInputFileType() const { + return inputInfo->GetInputFileType(); + } + + const std::vector &GetLinkFiles() const { + return linkInputFiles; + } + + const std::vector> &GetInputActions() const { + return inputActions; + } + + Compiler *GetCompiler() const { + return compilerTool; + } + + void SetCompiler(Compiler *compiler) { + compilerTool = compiler; + } + +private: + std::shared_ptr inputInfo; + + std::string tool = ""; + std::string exeFolder = ""; + std::vector linkInputFiles; + + Compiler *compilerTool; + + /* This vector contains a links to previous actions in Action tree */ + std::vector> inputActions; +}; + class MplOption { public: + MplOption(){needRootPath = false;} MplOption(const std::string &key, const std::string &value, bool needRootPath = false) : key(key), value(value), @@ -81,6 +244,10 @@ class MplOption { value = val; } + void SetKey(std::string k) { + key = k; + } + bool GetNeedRootPath() const { return needRootPath; } @@ -207,6 +374,14 @@ class MplOptions { return generalRegOnly; } + const std::vector> &GetActions() const { + return rootActions; + } + + const std::vector &GetOptions() const { + return optionParser->GetOptions(); + } + ErrorCode AppendCombOptions(MIRSrcLang srcLang); ErrorCode AppendMplcgOptions(MIRSrcLang srcLang); std::string GetInputFileNameForPrint() const; @@ -218,6 +393,12 @@ class MplOptions { ErrorCode HandleGeneralOptions(); ErrorCode DecideRunType(); ErrorCode DecideRunningPhases(); + ErrorCode DecideRunningPhases(const std::vector &runExes); + std::shared_ptr DecideRunningPhasesByType(const std::string &inputFile, bool isMultipleFiles); + ErrorCode MFCreateActionByExe(const std::string &exe, std::shared_ptr ¤tAction, + std::shared_ptr inputInfo, bool &wasWrpCombCompilerCreated); + ErrorCode SFCreateActionByExe(const std::string &exe, std::shared_ptr ¤tAction, + std::shared_ptr inputInfo, bool &isCombCompiler); ErrorCode CheckInputFileValidity(); ErrorCode CheckFileExits(); ErrorCode AddOption(const mapleOption::Option &option); @@ -225,6 +406,8 @@ class MplOptions { ErrorCode UpdateExtraOptionOpt(const std::string &args); ErrorCode AppendDefaultOptions(const std::string &exeName, MplOption mplOptions[], unsigned int length); void UpdateRunningExe(const std::string &args); + void DumpActionTree(const Action &action, int idents) const; + void DumpActionTree() const; std::unique_ptr optionParser = nullptr; std::map> options = {}; std::map> exeOptions = {}; @@ -258,8 +441,11 @@ class MplOptions { bool genVtableImpl = false; bool hasPrinted = false; bool generalRegOnly = false; + bool isDriverPhasesDumpCmd = false; unsigned int helpLevel = mapleOption::kBuildTypeDefault; std::string partO2List = ""; + + std::vector> rootActions; }; } // namespace maple #endif // MAPLE_DRIVER_INCLUDE_MPL_OPTIONS_H diff --git a/src/mapleall/maple_driver/include/option_descriptor.h b/src/mapleall/maple_driver/include/option_descriptor.h index 02abb695de8e458b002b764cd3f20a2e36e7b07c..ebe7ad27c73fe55c5b614fd06ec72e6da5d6998f 100644 --- a/src/mapleall/maple_driver/include/option_descriptor.h +++ b/src/mapleall/maple_driver/include/option_descriptor.h @@ -36,6 +36,12 @@ enum ArgCheckPolicy { kArgCheckPolicyBool }; +enum OptionPrefixType { + shortOptPrefix, + longOptPrefix, + undefinedOpt, +}; + constexpr size_t kMaxExtraOptions = 10; struct Descriptor { @@ -89,6 +95,12 @@ class Option { Option(const Descriptor &desc, const std::string &optionKey, const std::string &args) : descriptor(desc), optionKey(optionKey), args(args) {} + Option(const Descriptor &desc, const std::string &optionKey, + const std::string &args, OptionPrefixType prefixType, + bool isEqualPrefix) + : descriptor(desc), optionKey(optionKey), args(args), + prefixType(prefixType), isEqualPrefix(isEqualPrefix) {} + ~Option() = default; size_t Index() const { @@ -99,6 +111,14 @@ class Option { return descriptor.type; } + OptionPrefixType GetPrefixType() const { + return prefixType; + } + + bool CheckEqualPrefix() const { + return isEqualPrefix; + } + const std::string &Args() const { return args; } @@ -107,6 +127,10 @@ class Option { return optionKey; } + const Descriptor &GetDescriptor() const { + return descriptor; + } + bool HasExtra() const { return (descriptor.extras.size() > 0); } @@ -132,6 +156,8 @@ class Option { Descriptor descriptor; const std::string optionKey; const std::string args; + OptionPrefixType prefixType = undefinedOpt; + bool isEqualPrefix = false; // whether option contains "=", like -op=-value }; enum EnabledIndex { @@ -139,4 +165,4 @@ enum EnabledIndex { kEnable }; } // namespace mapleOption -#endif // MAPLE_OPTION_DESCRIPTOR_H \ No newline at end of file +#endif // MAPLE_OPTION_DESCRIPTOR_H diff --git a/src/mapleall/maple_driver/include/option_parser.h b/src/mapleall/maple_driver/include/option_parser.h index 42782f63b7d49fda9d4a5c8fb00cbf4565c57d0a..43fd7895661bf6c78d6a2769dfff281cbfe1620c 100644 --- a/src/mapleall/maple_driver/include/option_parser.h +++ b/src/mapleall/maple_driver/include/option_parser.h @@ -56,19 +56,30 @@ class OptionParser { void PrintUsage(const std::string &helpType, const uint32_t helpLevel = kBuildTypeDefault) const; private: + + struct UsageWrp { + UsageWrp(const Descriptor &desc, const OptionPrefixType &type) : + desc(desc), + type(type) {}; + Descriptor desc; + OptionPrefixType type; + }; + bool HandleKeyValue(const std::string &key, const std::string &value, std::vector &inputOption, const std::string &exeName, - bool isAllOption = true); + bool isAllOption = true, bool isEqualPrefix = false); bool CheckOpt(const std::string option, std::string &lastKey, bool &isLastMatch, std::vector &inputOption, const std::string &exeName); - void InsertOption(const std::string &opt, const Descriptor &usage) { + void InsertOption(const std::string &opt, const Descriptor &usage, + OptionPrefixType optPrefix) { if (usage.IsEnabledForCurrentBuild()) { - (void)usages.insert(make_pair(opt, usage)); + (void)usages.insert(make_pair(opt, UsageWrp(usage, optPrefix))); } } + bool CheckSpecialOption(const std::string &option, std::string &key, std::string &value); std::vector rawUsages; - std::multimap usages; + std::multimap usages; std::vector