diff --git a/src/hir2mpl/common/src/hir2mpl_options.cpp b/src/hir2mpl/common/src/hir2mpl_options.cpp index 63843ddbdce5647a96d47860ee04ebc579374798..9debcd1921fce6b19e1e1f000c8b169d3647bbfc 100644 --- a/src/hir2mpl/common/src/hir2mpl_options.cpp +++ b/src/hir2mpl/common/src/hir2mpl_options.cpp @@ -302,7 +302,7 @@ const Descriptor kUsage[] = { { kSafeRegion, 0, "", "safe-region", kBuildTypeAll, kArgCheckPolicyNone, " -safe-region : EnhanceC: enable safe region", "hir2mpl", {} }, - { kO2, 0, "", "O2", + { kO2, 0, "O2", "", kBuildTypeAll, kArgCheckPolicyNone, " -O2 : enable hir2mpl O2 optimize", "hir2mpl", {} }, { kSimplifyShortCircuit, 0, "", "simplify-short-circuit", @@ -310,7 +310,7 @@ const Descriptor kUsage[] = { " -simplify-short-circuit : enable simplify short circuit", "hir2mpl", {} }, { kEnableVariableArray, 0, "", "enable-variable-array", kBuildTypeAll, kArgCheckPolicyNone, - " -enable-variable-array : enable variable array", "hir2mpl", {} }, + " --enable-variable-array : enable variable array", "hir2mpl", {} }, { kFuncInlineSize, 0, "", "func-inline-size", kBuildTypeAll, kArgCheckPolicyRequired, " -func-inline-size : set func inline size", "hir2mpl", {} }, diff --git a/src/mapleall/maple_be/src/cg/cg_option.cpp b/src/mapleall/maple_be/src/cg/cg_option.cpp index aebe679fd59246644cccebc115c0c78f9a8b3196..74e6902ee0cbd0cc7cfc3850580cd1629c6ecb4b 100644 --- a/src/mapleall/maple_be/src/cg/cg_option.cpp +++ b/src/mapleall/maple_be/src/cg/cg_option.cpp @@ -215,7 +215,7 @@ const Descriptor kUsage[] = { " --pie \tGenerate position-independent executable\n" " --no-pie\n", "mplcg", - {} }, + {"driver"} }, { kPic, kEnable, "", @@ -225,7 +225,7 @@ const Descriptor kUsage[] = { " --fpic \tGenerate position-independent shared library\n" " --no-fpic\n", "mplcg", - {} }, + {"driver"} }, { kCGVerbose, kEnable, "", @@ -708,8 +708,8 @@ const Descriptor kUsage[] = { {} }, { kCGO0, 0, - "", "O0", + "", kBuildTypeExperimental, kArgCheckPolicyNone, " -O0 \tNo optimization.\n", @@ -717,8 +717,8 @@ const Descriptor kUsage[] = { {} }, { kCGO1, 0, - "", "O1", + "", kBuildTypeExperimental, kArgCheckPolicyOptional, " -O1 \tDo some optimization.\n", @@ -726,8 +726,8 @@ const Descriptor kUsage[] = { {} }, { kCGO2, 0, - "", "O2", + "", kBuildTypeProduct, kArgCheckPolicyOptional, " -O2 \tDo some optimization.\n", @@ -1066,7 +1066,7 @@ const Descriptor kUsage[] = { " --omit-frame-pointer \t do not use frame pointer \n" " --no-omit-frame-pointer\n", "mplcg", - {} }, + {"driver"} }, { kFastMath, kEnable, "", diff --git a/src/mapleall/maple_driver/include/file_utils.h b/src/mapleall/maple_driver/include/file_utils.h index 5e233b725e47f4f376bdd88b549c7e29051917f0..921d3fa489d81d1ebf354c25da3e344a19fada5c 100644 --- a/src/mapleall/maple_driver/include/file_utils.h +++ b/src/mapleall/maple_driver/include/file_utils.h @@ -29,6 +29,7 @@ class FileUtils { static std::string GetFileName(const std::string &filePath, bool isWithExtension); static std::string GetFileExtension(const std::string &filePath); static std::string GetFileFolder(const std::string &filePath); + static std::string GetExecutable(); static int Remove(const std::string &filePath); static std::string AppendMapleRootIfNeeded(bool needRootPath, const std::string &path, const std::string &defaultRoot = "." + kFileSeperatorStr); diff --git a/src/mapleall/maple_driver/include/option_descriptor.h b/src/mapleall/maple_driver/include/option_descriptor.h index f1e83553e8a7c79c674959c3dfe8c7f56e8d5b44..c68ff769a7e4df28e4581a359570eafaed42de66 100644 --- a/src/mapleall/maple_driver/include/option_descriptor.h +++ b/src/mapleall/maple_driver/include/option_descriptor.h @@ -15,6 +15,7 @@ #ifndef MAPLE_OPTION_DESCRIPTOR_H #define MAPLE_OPTION_DESCRIPTOR_H #include +#include #include #include @@ -103,6 +104,8 @@ class Option { ~Option() = default; + std::string GetPrefix() const; + size_t Index() const { return descriptor.index; } diff --git a/src/mapleall/maple_driver/include/option_parser.h b/src/mapleall/maple_driver/include/option_parser.h index 9b6fbd2a0aac50554b7c71cda0efb26771610aea..3b19beae2566fa1b0782b7a248d16db37d81cb0e 100644 --- a/src/mapleall/maple_driver/include/option_parser.h +++ b/src/mapleall/maple_driver/include/option_parser.h @@ -17,12 +17,30 @@ #include #include #include +#include #include #include "error_code.h" #include "option_descriptor.h" #include "driver_option_common.h" namespace mapleOption { + +OptionPrefixType DetectOptPrefix(std::string_view opt); +std::pair ExtractKey(std::string_view opt, + OptionPrefixType prefix); + +/* This structure is used to aggregate option information during option parsing. + * It's a string view from original input command line string. */ +struct Arg { + explicit Arg(std::string_view arg) : rawArg(arg) {} + std::string_view rawArg; /* full option, like "--key=value" */ + std::string_view key; /* Extracted key, like "--key" */ + std::string_view val; /* Extracted value, like "value" */ + OptionPrefixType prefixType = undefinedOpt; + bool isEqualOpt = false; /* indicates whether the parsed option contained "=" symbol. + For options like --key=value, it's true. For options like --key value, it's false */ +}; + class OptionParser { public: OptionParser() = default; @@ -31,9 +49,9 @@ class OptionParser { void RegisteUsages(const maple::MapleDriverOptionBase &base); void RegisteUsages(const Descriptor usage[]); - maple::ErrorCode Parse(int argc, char **argv, const std::string exeName = "all"); + maple::ErrorCode Parse(int argc, char **argv, const std::string exeName = "driver"); - maple::ErrorCode HandleInputArgs(const std::vector &inputArgs, const std::string &exeName, + maple::ErrorCode HandleInputArgs(std::vector &inputArgs, const std::string &exeName, std::deque &inputOption, bool isAllOption = false); const std::deque