diff --git a/BUILD.gn b/BUILD.gn index 40e691379fdb548eb9a6292775b15262bfa1c51d..03ee5f1e1029561697cb91a6470d5db6bbd4baa8 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -41,7 +41,8 @@ group("ast2mpl") { group("mapleallUT") { deps = [ - "${MAPLEALL_ROOT}/test:mapleallUT", + "${MAPLEALL_ROOT}/test:UTDriver", + "${MAPLEALL_ROOT}/test:UTCL", ] } diff --git a/src/hir2mpl/BUILD.gn b/src/hir2mpl/BUILD.gn index 80b4e5e920ecc003426b7bf3ef3ded50aad58a32..eac5c38b06dde4a350c5b76d8c080d5ddc696aa6 100644 --- a/src/hir2mpl/BUILD.gn +++ b/src/hir2mpl/BUILD.gn @@ -97,6 +97,7 @@ static_library("lib_hir2mpl_common") { "${HIR2MPL_ROOT}/common/src/hir2mpl_compiler_component.cpp", "${HIR2MPL_ROOT}/common/src/hir2mpl_env.cpp", "${HIR2MPL_ROOT}/common/src/hir2mpl_options.cpp", + "${HIR2MPL_ROOT}/common/src/hir2mpl_option.cpp", "${HIR2MPL_ROOT}/common/src/simple_xml.cpp", "${HIR2MPL_ROOT}/common/src/simple_zip.cpp", "${HIR2MPL_ROOT}/common/src/generic_attrs.cpp", diff --git a/src/hir2mpl/common/include/hir2mpl_option.h b/src/hir2mpl/common/include/hir2mpl_option.h new file mode 100644 index 0000000000000000000000000000000000000000..d92e11e9393fae910fe1a2395ec726aca00062d1 --- /dev/null +++ b/src/hir2mpl/common/include/hir2mpl_option.h @@ -0,0 +1,71 @@ +/* + * Copyright (c) [2022] 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 HIR2MPL_COMMON_INCLUDE_HIR2MPL_OPTIONS_H +#define HIR2MPL_COMMON_INCLUDE_HIR2MPL_OPTIONS_H + +#include "driver_options.h" + +#include +#include + +namespace opts::hir2mpl { +extern cl::Option help; +extern cl::Option version; +extern cl::Option mpltSys; +extern cl::Option mpltApk; +extern cl::Option mplt; +extern cl::Option inClass; +extern cl::Option inJar; +extern cl::Option inDex; + extern cl::Option inAst; +extern cl::Option inMast; +extern cl::Option output; +extern cl::Option outputName; +extern cl::Option mpltOnly; +extern cl::Option asciimplt; +extern cl::Option dumpInstComment; +extern cl::Option noMplFile; +extern cl::Option dumpLevel; +extern cl::Option dumpTime; +extern cl::Option dumpComment; +extern cl::Option dumpLOC; +extern cl::Option dumpPhaseTime; +extern cl::Option dumpPhaseTimeDetail; +extern cl::Option rc; +extern cl::Option nobarrier; +extern cl::Option usesignedchar; +extern cl::Option be; +extern cl::Option o2; +extern cl::Option simplifyShortCircuit; +extern cl::Option enableVariableArray; +extern cl::Option funcInliceSize; +extern cl::Option np; +extern cl::Option dumpThreadTime; +extern cl::Option xbootclasspath; +extern cl::Option classloadercontext; +extern cl::Option dep; +extern cl::Option depsamename; +extern cl::Option npeCheckDynamic; +extern cl::Option boundaryCheckDynamic; +extern cl::Option safeRegion; +extern cl::Option dumpFEIRBB; +extern cl::Option dumpFEIRCFGGraph; +extern cl::Option wpaa; +extern cl::Option debug; + +} + +#endif /* HIR2MPL_COMMON_INCLUDE_HIR2MPL_OPTIONS_H */ diff --git a/src/hir2mpl/common/include/hir2mpl_options.h b/src/hir2mpl/common/include/hir2mpl_options.h index bbfe437c9b53e1181ae15cd33d5c5dc33a2c5e48..e561fce1ae967a9ea3dc15cc41758fa131aca695 100644 --- a/src/hir2mpl/common/include/hir2mpl_options.h +++ b/src/hir2mpl/common/include/hir2mpl_options.h @@ -18,12 +18,12 @@ #include #include "factory.h" #include "parser_opt.h" -#include "option_parser.h" +#include "mpl_options.h" #include "types_def.h" -#include "driver_option_common.h" +#include "hir2mpl_option.h" namespace maple { -class HIR2MPLOptions : public maple::MapleDriverOptionBase { +class HIR2MPLOptions { public: static inline HIR2MPLOptions &GetInstance() { static HIR2MPLOptions options; @@ -31,7 +31,7 @@ class HIR2MPLOptions : public maple::MapleDriverOptionBase { } void Init(); static bool InitFactory(); - bool SolveOptions(const std::deque &opts, bool isDebug); + bool SolveOptions(bool isDebug); bool SolveArgs(int argc, char **argv); void DumpUsage() const; void DumpVersion() const; @@ -43,86 +43,86 @@ class HIR2MPLOptions : public maple::MapleDriverOptionBase { void ProcessInputFiles(const std::vector &inputs); private: - using OptionProcessFactory = FunctionFactory; + template + using OptionProcessFactory = FunctionFactory; + using OptionFactory = OptionProcessFactory; HIR2MPLOptions(); ~HIR2MPLOptions() = default; // option process - bool ProcessHelp(const mapleOption::Option &opt); - bool ProcessVersion(const mapleOption::Option &opt); + bool ProcessHelp(const cl::OptionInterface &opt); + bool ProcessVersion(const cl::OptionInterface &opt); // input control options - bool ProcessInClass(const mapleOption::Option &opt); - bool ProcessInJar(const mapleOption::Option &opt); - bool ProcessInDex(const mapleOption::Option &opt); - bool ProcessInAST(const mapleOption::Option &opt); - bool ProcessInMAST(const mapleOption::Option &opt); - bool ProcessInputMplt(const mapleOption::Option &opt); - bool ProcessInputMpltFromSys(const mapleOption::Option &opt); - bool ProcessInputMpltFromApk(const mapleOption::Option &opt); - - // output control options - bool ProcessOutputPath(const mapleOption::Option &opt); - bool ProcessOutputName(const mapleOption::Option &opt); - bool ProcessGenMpltOnly(const mapleOption::Option &opt); - bool ProcessGenAsciiMplt(const mapleOption::Option &opt); - bool ProcessDumpInstComment(const mapleOption::Option &opt); - bool ProcessNoMplFile(const mapleOption::Option &opt); - - // debug info control options - bool ProcessDumpLevel(const mapleOption::Option &opt); - bool ProcessDumpTime(const mapleOption::Option &opt); - bool ProcessDumpComment(const mapleOption::Option &opt); - bool ProcessDumpLOC(const mapleOption::Option &opt); - bool ProcessDumpPhaseTime(const mapleOption::Option &opt); - bool ProcessDumpPhaseTimeDetail(const mapleOption::Option &opt); + bool ProcessInClass(const cl::OptionInterface &mpltSys); + bool ProcessInJar(const cl::OptionInterface &mpltApk); + bool ProcessInDex(const cl::OptionInterface &inDex); + bool ProcessInAST(const cl::OptionInterface &inAst); + bool ProcessInMAST(const cl::OptionInterface &inMast); + bool ProcessInputMplt(const cl::OptionInterface &mplt); + bool ProcessInputMpltFromSys(const cl::OptionInterface &mpltSys); + bool ProcessInputMpltFromApk(const cl::OptionInterface &mpltApk); + + // // output control options + bool ProcessOutputPath(const cl::OptionInterface &output); + bool ProcessOutputName(const cl::OptionInterface &outputName); + bool ProcessGenMpltOnly(const cl::OptionInterface &opt); + bool ProcessGenAsciiMplt(const cl::OptionInterface &opt); + bool ProcessDumpInstComment(const cl::OptionInterface &opt); + bool ProcessNoMplFile(const cl::OptionInterface &opt); + + // // debug info control options + bool ProcessDumpLevel(const cl::OptionInterface &outputName); + bool ProcessDumpTime(const cl::OptionInterface &opt); + bool ProcessDumpComment(const cl::OptionInterface &opt); + bool ProcessDumpLOC(const cl::OptionInterface &opt); + bool ProcessDumpPhaseTime(const cl::OptionInterface &opt); + bool ProcessDumpPhaseTimeDetail(const cl::OptionInterface &opt); // java compiler options - bool ProcessModeForJavaStaticFieldName(const mapleOption::Option &opt); - bool ProcessJBCInfoUsePathName(const mapleOption::Option &opt); - bool ProcessDumpJBCStmt(const mapleOption::Option &opt); - bool ProcessDumpJBCAll(const mapleOption::Option &opt); - bool ProcessDumpJBCErrorOnly(const mapleOption::Option &opt); - bool ProcessDumpJBCFuncName(const mapleOption::Option &opt); - bool ProcessEmitJBCLocalVarInfo(const mapleOption::Option &opt); + bool ProcessModeForJavaStaticFieldName(const cl::OptionInterface &opt); + bool ProcessJBCInfoUsePathName(const cl::OptionInterface &opt); + bool ProcessDumpJBCStmt(const cl::OptionInterface &opt); + bool ProcessDumpJBCAll(const cl::OptionInterface &opt); + bool ProcessDumpJBCErrorOnly(const cl::OptionInterface &opt); + bool ProcessDumpJBCFuncName(const cl::OptionInterface &opt); + bool ProcessEmitJBCLocalVarInfo(const cl::OptionInterface &opt); // bc compiler options - bool ProcessRC(const mapleOption::Option &opt); - bool ProcessNoBarrier(const mapleOption::Option &opt); - bool ProcessO2(const mapleOption::Option &opt); - bool ProcessSimplifyShortCircuit(const mapleOption::Option &opt); - bool ProcessEnableVariableArray(const mapleOption::Option &opt); - bool ProcessFuncInlineSize(const mapleOption::Option &opt); - bool ProcessWPAA(const mapleOption::Option &opt); + bool ProcessRC(const cl::OptionInterface &opt); + bool ProcessNoBarrier(const cl::OptionInterface &opt); + bool ProcessO2(const cl::OptionInterface &opt); + bool ProcessSimplifyShortCircuit(const cl::OptionInterface &opt); + bool ProcessEnableVariableArray(const cl::OptionInterface &opt); + bool ProcessFuncInlineSize(const cl::OptionInterface &funcInliceSize); + bool ProcessWPAA(const cl::OptionInterface &opt); // ast compiler options - bool ProcessUseSignedChar(const mapleOption::Option &opt); - bool ProcessBigEndian(const mapleOption::Option &opt); + bool ProcessUseSignedChar(const cl::OptionInterface &opt); + bool ProcessBigEndian(const cl::OptionInterface &opt); // general stmt/bb/cfg options - bool ProcessDumpFEIRBB(const mapleOption::Option &opt); - bool ProcessDumpFEIRCFGGraph(const mapleOption::Option &opt); + bool ProcessDumpFEIRBB(const cl::OptionInterface &opt); + bool ProcessDumpFEIRCFGGraph(const cl::OptionInterface &opt); - // multi-thread control options - bool ProcessNThreads(const mapleOption::Option &opt); - bool ProcessDumpThreadTime(const mapleOption::Option &opt); - bool ProcessReleaseAfterEmit(const mapleOption::Option &opt); + // // multi-thread control options + bool ProcessNThreads(const cl::OptionInterface &numThreads); + bool ProcessDumpThreadTime(const cl::OptionInterface &opt); // On Demand Type Creation - bool ProcessXbootclasspath(const mapleOption::Option &opt); - bool ProcessClassLoaderContext(const mapleOption::Option &opt); - bool ProcessCompilefile(const mapleOption::Option &opt); - bool ProcessCollectDepTypes(const mapleOption::Option &opt); - bool ProcessDepSameNamePolicy(const mapleOption::Option &opt); + bool ProcessXbootclasspath(const cl::OptionInterface &xbootclasspath); + bool ProcessClassLoaderContext(const cl::OptionInterface &classloadercontext); + bool ProcessCollectDepTypes(const cl::OptionInterface &dep); + bool ProcessDepSameNamePolicy(const cl::OptionInterface &depsamename); // EnhanceC - bool ProcessNpeCheckDynamic(const mapleOption::Option &opt); - bool ProcessBoundaryCheckDynamic(const mapleOption::Option &opt); - bool ProcessSafeRegion(const mapleOption::Option &opt); + bool ProcessNpeCheckDynamic(const cl::OptionInterface &opt); + bool ProcessBoundaryCheckDynamic(const cl::OptionInterface &opt); + bool ProcessSafeRegion(const cl::OptionInterface &opt); // symbol resolve - bool ProcessAOT(const mapleOption::Option &opt); + bool ProcessAOT(const cl::OptionInterface &opt); }; // class HIR2MPLOptions } // namespace maple #endif // HIR2MPL_INCLUDE_COMMON_HIR2MPL_OPTIONS_H diff --git a/src/hir2mpl/common/src/hir2mpl_option.cpp b/src/hir2mpl/common/src/hir2mpl_option.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2a0b082edba44a8d8843979f60b30d7dc0655039 --- /dev/null +++ b/src/hir2mpl/common/src/hir2mpl_option.cpp @@ -0,0 +1,221 @@ +/* + * Copyright (c) [2022] 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 "driver_options.h" + +#include +#include + +namespace opts::hir2mpl { + +cl::Option help({"--help", "-h"}, + " -h, -help : print usage and exit", + {hir2mplCategory}); + +cl::Option version({"--version", "-v"}, + " -v, -version : print version and exit", + {hir2mplCategory}); + +cl::Option mpltSys({"--mplt-sys", "-mplt-sys"}, + " -mplt-sys sys1.mplt,sys2.mplt\n" + " : input sys mplt files", + {hir2mplCategory}); + +cl::Option mpltApk({"--mplt-apk", "-mplt-apk"}, + " -mplt-apk apk1.mplt,apk2.mplt\n" + " : input apk mplt files", + {hir2mplCategory}); + +cl::Option mplt({"--mplt", "-mplt"}, + " -mplt lib1.mplt,lib2.mplt\n" + " : input mplt files", + {hir2mplCategory}); + +cl::Option inClass({"--in-class", "-in-class"}, + " -in-class file1.jar,file2.jar\n" + " : input class files", + {hir2mplCategory}); + +cl::Option inJar({"--in-jar", "-in-jar"}, + " -in-jar file1.jar,file2.jar\n" + " : input jar files", + {hir2mplCategory}); + +cl::Option inDex({"--in-dex", "-in-dex"}, + " -in-dex file1.dex,file2.dex\n" + " : input dex files", + {hir2mplCategory}); + +cl::Option inAst({"--in-ast", "-in-ast"}, + " -in-ast file1.ast,file2.ast\n" + " : input ast files", + {hir2mplCategory}); + +cl::Option inMast({"--in-mast", "-in-mast"}, + " -in-mast file1.mast,file2.mast\n" + " : input mast files", + {hir2mplCategory}); + +cl::Option output({"--output", "-p"}, + " -p, -output : output path", + {hir2mplCategory}); + +cl::Option outputName({"--output-name", "-o"}, + " -o, -output-name : output name", + {hir2mplCategory}); + +cl::Option mpltOnly({"--t", "-t"}, + " -t : generate mplt only", + {hir2mplCategory}); + +cl::Option asciimplt({"--asciimplt", "-asciimplt"}, + " -asciimplt : generate mplt in ascii format", + {hir2mplCategory}); + +cl::Option dumpInstComment({"--dump-inst-comment", "-dump-inst-comment"}, + " -dump-inst-comment : dump instruction comment", + {hir2mplCategory}); + +cl::Option noMplFile({"--no-mpl-file", "-no-mpl-file"}, + " -no-mpl-file : disable dump mpl file", + {hir2mplCategory}); + +cl::Option dumpLevel({"--dump-level", "-d"}, + " -d, -dump-level xx : debug info dump level\n" + " [0] disable\n" + " [1] dump simple info\n" + " [2] dump detail info\n" + " [3] dump debug info", + {hir2mplCategory}); + +cl::Option dumpTime({"--dump-time", "-dump-time"}, + " -dump-time : dump time", + {hir2mplCategory}); + +cl::Option dumpComment({"--dump-comment", "-dump-comment"}, + " -dump-comment : gen comment stmt", + {hir2mplCategory}); + +cl::Option dumpLOC({"--dump-LOC", "-dump-LOC"}, + " -dump-LOC : gen LOC", + {hir2mplCategory}); + +cl::Option dumpPhaseTime({"--dump-phase-time", "-dump-phase-time"}, + " -dump-phase-time : dump total phase time", + {hir2mplCategory}); + +cl::Option dumpPhaseTimeDetail({"-dump-phase-time-detail", "--dump-phase-time-detail"}, + " -dump-phase-time-detail\n" \ + " : dump phase time for each method", + {hir2mplCategory}); + +cl::Option rc({"-rc", "--rc"}, + " -rc : enable rc", + {hir2mplCategory}); + +cl::Option nobarrier({"-nobarrier", "--nobarrier"}, + " -nobarrier : no barrier", + {hir2mplCategory}); + +cl::Option usesignedchar({"-usesignedchar", "--usesignedchar"}, + " -usesignedchar : use signed char", + {hir2mplCategory}); + +cl::Option be({"-be", "--be"}, + " -be : enable big endian", + {hir2mplCategory}); + +cl::Option o2({"-O2", "--O2"}, + " -O2 : enable hir2mpl O2 optimize", + {hir2mplCategory}); + +cl::Option simplifyShortCircuit({"-simplify-short-circuit", "--simplify-short-circuit"}, + " -simplify-short-circuit\n" \ + " : enable simplify short circuit", + {hir2mplCategory}); + +cl::Option enableVariableArray({"-enable-variable-array", "--enable-variable-array"}, + " -enable-variable-array\n" \ + " : enable variable array", + {hir2mplCategory}); + +cl::Option funcInliceSize({"-func-inline-size", "--func-inline-size"}, + " -func-inline-size : set func inline size", + {hir2mplCategory}); + +cl::Option np({"-np", "--np"}, + " -np num : number of threads", + {hir2mplCategory}); + +cl::Option dumpThreadTime({"-dump-thread-time", "--dump-thread-time"}, + " -dump-thread-time : dump thread time in mpl schedular", + {hir2mplCategory}); + +cl::Option xbootclasspath({"-Xbootclasspath", "--Xbootclasspath"}, + " -Xbootclasspath=bootclasspath\n" \ + " : boot class path list", + {hir2mplCategory}); + +cl::Option classloadercontext({"-classloadercontext", "--classloadercontext"}, + " -classloadercontext=pcl\n" \ + " : class loader context \n" \ + " : path class loader", + {hir2mplCategory}); + +cl::Option dep({"-dep", "--dep"}, + " -dep=all or func\n" \ + " : [all] collect all dependent types\n" \ + " : [func] collect dependent types in function", + {hir2mplCategory}); + +cl::Option depsamename({"-depsamename", "--depsamename"}, + " -DepSameNamePolicy=sys or src\n" \ + " : [sys] load type from sys when on-demand load same name type\n" \ + " : [src] load type from src when on-demand load same name type", + {hir2mplCategory}); + +cl::Option npeCheckDynamic({"-npe-check-dynamic", "--npe-check-dynamic"}, + " -npe-check-dynamic : Nonnull pointr dynamic checking", + {hir2mplCategory}); + +cl::Option boundaryCheckDynamic({"-boundary-check-dynamic", "--boundary-check-dynamic"}, + " -boundary-check-dynamic\n" \ + " : Boundary dynamic checking", + {hir2mplCategory}); + +cl::Option safeRegion({"-safe-region", "--safe-region"}, + " -boundary-check-dynamic\n" \ + " -safe-region : Enable safe region", + {hir2mplCategory}); + +cl::Option dumpFEIRBB({"-dump-bb", "--dump-bb"}, + " -dump-bb : dump basic blocks info", + {hir2mplCategory}); + +cl::Option dumpFEIRCFGGraph({"-dump-cfg", "--dump-cfg"}, + " -dump-cfg funcname1,funcname2\n" \ + " : dump cfg graph to dot file", + {hir2mplCategory}); + +cl::Option wpaa({"-wpaa", "--wpaa"}, + " -dump-cfg funcname1,funcname2\n" \ + " -wpaa : enable whole program ailas analysis", + {hir2mplCategory}); + +cl::Option debug({"-debug", "--debug"}, + " -debug : dump enabled options", + {hir2mplCategory}); + +} diff --git a/src/hir2mpl/common/src/hir2mpl_options.cpp b/src/hir2mpl/common/src/hir2mpl_options.cpp index aae8a15cdba3a181c97f36f10d696cf852f92e9d..8d14c9c34a3e5e910d1913c8f9db8914888a2000 100644 --- a/src/hir2mpl/common/src/hir2mpl_options.cpp +++ b/src/hir2mpl/common/src/hir2mpl_options.cpp @@ -12,284 +12,29 @@ * FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. */ +#include "driver_options.h" +#include "file_utils.h" +#include "hir2mpl_option.h" #include "hir2mpl_options.h" -#include -#include #include "fe_options.h" #include "fe_macros.h" -#include "option_parser.h" +#include "mpl_options.h" #include "parser_opt.h" #include "fe_file_type.h" +#include "types_def.h" #include "version.h" +#include +#include +#include +#include +#include +#include + namespace maple { using namespace mapleOption; -enum OptionIndex : uint32 { - kHir2mplHelp = kCommonOptionEnd + 1, - // input control options - kMpltSys, - kMpltApk, - kInClass, - kInJar, - kInDex, - kInAST, - kInMAST, - // output control options - kOutputPath, - kOutputName, - kGenMpltOnly, - kGenAsciiMplt, - kDumpInstComment, - kNoMplFile, - // debug info control options - kDumpLevel, - kDumpTime, - kDumpComment, - kDumpLOC, - kDumpPhaseTime, - kDumpPhaseTimeDetail, - // bc bytecode compile options - kRC, - kNoBarrier, - // java bytecode compile options - kJavaStaticFieldName, - kJBCInfoUsePathName, - kDumpJBCStmt, - kDumpJBCAll, - kDumpJBCErrorOnly, - kDumpJBCFuncName, - kEmitJBCLocalVarInfo, - // ast compiler options - kUseSignedChar, - kFEBigEndian, - // general stmt/bb/cfg debug options - kDumpFEIRBB, - kDumpFEIRCFGGraph, - // multi-thread control options - kNThreads, - kDumpThreadTime, - // type-infer - kTypeInfer, - // On Demand Type Creation - kXBootClassPath, - kClassLoaderContext, - kInputFile, - kCollectDepTypes, - kDepSameNamePolicy, - // EnhanceC - kNpeCheckDynamic, - kBoundaryCheckDynamic, - kSafeRegion, - kO2, - kSimplifyShortCircuit, - kEnableVariableArray, - kFuncInlineSize, - kWPAA, -}; - -const Descriptor kUsage[] = { - { kUnknown, 0, "", "", - kBuildTypeAll, kArgCheckPolicyUnknown, - "\n====== Usage: hir2mpl [options] input1 input2 input3 ======\n" - " options:", "hir2mpl", {} }, - { kHir2mplHelp, 0, "h", "help", - kBuildTypeAll, kArgCheckPolicyNone, - " -h, -help : print usage and exit", "hir2mpl", {} }, - { kVersion, 0, "v", "version", - kBuildTypeAll, kArgCheckPolicyNone, - " -v, -version : print version and exit", "hir2mpl", {} }, - - // input control options - { kUnknown, 0, "", "", - kBuildTypeAll, kArgCheckPolicyUnknown, - "\n====== Input Control Options ======", "hir2mpl", {} }, - { kMpltSys, 0, "", "mplt-sys", - kBuildTypeAll, kArgCheckPolicyRequired, - " -mplt-sys sys1.mplt,sys2.mplt\n" - " : input sys mplt files", "hir2mpl", {} }, - { kMpltApk, 0, "", "mplt-apk", - kBuildTypeAll, kArgCheckPolicyRequired, - " -mplt-apk apk1.mplt,apk2.mplt\n" - " : input apk mplt files", "hir2mpl", {} }, - { kInMplt, 0, "", "mplt", - kBuildTypeAll, kArgCheckPolicyRequired, - " -mplt lib1.mplt,lib2.mplt\n" - " : input mplt files", "hir2mpl", {} }, - { kInClass, 0, "", "in-class", - kBuildTypeAll, kArgCheckPolicyRequired, - " -in-class file1.jar,file2.jar\n" - " : input class files", "hir2mpl", {} }, - { kInJar, 0, "", "in-jar", - kBuildTypeAll, kArgCheckPolicyRequired, - " -in-jar file1.jar,file2.jar\n" - " : input jar files", "hir2mpl", {} }, - { kInDex, 0, "", "in-dex", - kBuildTypeAll, kArgCheckPolicyRequired, - " -in-dex file1.dex,file2.dex\n" - " : input dex files", "hir2mpl", {} }, - { kInAST, 0, "", "in-ast", - kBuildTypeAll, kArgCheckPolicyRequired, - " -in-ast file1.ast,file2.ast\n" - " : input ast files", "hir2mpl", {} }, - { kInMAST, 0, "", "in-mast", - kBuildTypeAll, kArgCheckPolicyRequired, - " -in-mast file1.mast,file2.mast\n" - " : input mast files", "hir2mpl", {} }, - - // output control options - { kUnknown, 0, "", "", - kBuildTypeAll, kArgCheckPolicyUnknown, - "\n====== Output Control Options ======", "hir2mpl", {} }, - { kOutputPath, 0, "p", "output", - kBuildTypeAll, kArgCheckPolicyRequired, - " -p, -output : output path", "hir2mpl", {} }, - { kOutputName, 0, "o", "output-name", - kBuildTypeAll, kArgCheckPolicyRequired, - " -o, -output-name : output name", "hir2mpl", {} }, - { kGenMpltOnly, 0, "t", "", - kBuildTypeAll, kArgCheckPolicyNone, - " -t : generate mplt only", "hir2mpl", {} }, - { kGenAsciiMplt, 0, "", "asciimplt", - kBuildTypeAll, kArgCheckPolicyNone, - " -asciimplt : generate mplt in ascii format", "hir2mpl", {} }, - { kDumpInstComment, 0, "", "dump-inst-comment", - kBuildTypeAll, kArgCheckPolicyNone, - " -dump-inst-comment : dump instruction comment", "hir2mpl", {} }, - { kNoMplFile, 0, "", "no-mpl-file", - kBuildTypeAll, kArgCheckPolicyNone, - " -no-mpl-file : disable dump mpl file", "hir2mpl", {} }, - - // debug info control options - { kUnknown, 0, "", "", - kBuildTypeAll, kArgCheckPolicyUnknown, - "\n====== Debug Info Control Options ======", "hir2mpl", {} }, - { kDumpLevel, 0, "d", "dump-level", - kBuildTypeAll, kArgCheckPolicyNumeric, - " -d, -dump-level xx : debug info dump level\n" - " [0] disable\n" - " [1] dump simple info\n" - " [2] dump detail info\n" - " [3] dump debug info", "hir2mpl", {} }, - { kDumpTime, 0, "", "dump-time", - kBuildTypeAll, kArgCheckPolicyNone, - " -dump-time : dump time", "hir2mpl", {} }, - { kDumpComment, 0, "", "dump-comment", - kBuildTypeAll, kArgCheckPolicyNone, - " -dump-comment : gen comment stmt", "hir2mpl", {} }, - { kDumpLOC, 0, "", "dump-LOC", - kBuildTypeAll, kArgCheckPolicyNone, - " -dump-LOC : gen LOC", "hir2mpl", {} }, - { kDumpPhaseTime, 0, "", "dump-phase-time", - kBuildTypeAll, kArgCheckPolicyNone, - " -dump-phase-time : dump total phase time", "hir2mpl", {} }, - { kDumpPhaseTimeDetail, 0, "", "dump-phase-time-detail", - kBuildTypeAll, kArgCheckPolicyNone, - " -dump-phase-time-detail\n" \ - " : dump phase time for each method", "hir2mpl", {} }, - { kDumpFEIRBB, 0, "", "dump-bb", - kBuildTypeAll, kArgCheckPolicyNone, - " -dump-bb : dump basic blocks info", "hir2mpl", {} }, - { kDumpFEIRCFGGraph, 0, "", "dump-cfg", - kBuildTypeAll, kArgCheckPolicyRequired, - " -dump-cfg funcname1,funcname2\n"\ - " : dump cfg graph to dot file", "hir2mpl", {} }, - - // bc bytecode compile options - { kUnknown, 0, "", "", - kBuildTypeAll, kArgCheckPolicyUnknown, - "\n====== BC Bytecode Compile Options ======", "hir2mpl", {} }, - { kRC, 0, "", "rc", - kBuildTypeAll, kArgCheckPolicyNone, - " -rc : enable rc", "hir2mpl", {} }, - { kNoBarrier, 0, "", "nobarrier", - kBuildTypeAll, kArgCheckPolicyNone, - " -nobarrier : no barrier", "hir2mpl", {} }, - - // ast compiler options - { kUnknown, 0, "", "", - kBuildTypeAll, kArgCheckPolicyUnknown, - "\n====== ast Compile Options ======", "hir2mpl", {} }, - { kUseSignedChar, 0, "", "usesignedchar", - kBuildTypeAll, kArgCheckPolicyNone, - " -usesignedchar : use signed char", "hir2mpl", {} }, - { kFEBigEndian, 0, "", "be", - kBuildTypeAll, kArgCheckPolicyNone, - " -be : enable big endian", "hir2mpl", {} }, - { kO2, 0, "O2", "", - kBuildTypeAll, kArgCheckPolicyNone, - " -O2 : enable hir2mpl O2 optimize", "hir2mpl", {} }, - { kSimplifyShortCircuit, 0, "", "simplify-short-circuit", - kBuildTypeAll, kArgCheckPolicyNone, - " -simplify-short-circuit\n" \ - " : enable simplify short circuit", "hir2mpl", {} }, - { kEnableVariableArray, 0, "", "enable-variable-array", - kBuildTypeAll, kArgCheckPolicyNone, - " -enable-variable-array\n" \ - " : enable variable array", "hir2mpl", {} }, - { kFuncInlineSize, 0, "", "func-inline-size", - kBuildTypeAll, kArgCheckPolicyRequired, - " -func-inline-size : set func inline size", "hir2mpl", {} }, - { kWPAA, 0, "", "wpaa", - kBuildTypeAll, kArgCheckPolicyNone, - " -wpaa : enable whole program ailas analysis", "hir2mpl", {} }, - - // multi-thread control - { kUnknown, 0, "", "", - kBuildTypeAll, kArgCheckPolicyUnknown, - "\n====== Multi-Thread Control Options ======", "hir2mpl", {} }, - { kNThreads, 0, "", "np", - kBuildTypeAll, kArgCheckPolicyRequired, - " -np num : number of threads", "hir2mpl", {} }, - { kDumpThreadTime, 0, "", "dump-thread-time", - kBuildTypeAll, kArgCheckPolicyNone, - " -dump-thread-time : dump thread time in mpl schedular", "hir2mpl", {} }, - - // On Demand Type Creation - { kUnknown, 0, "", "", - kBuildTypeAll, kArgCheckPolicyUnknown, - "\n====== On Demand Type Creation ======", "hir2mpl", {} }, - { kXBootClassPath, 0, "", "Xbootclasspath", - kBuildTypeAll, kArgCheckPolicyRequired, - " -Xbootclasspath=bootclasspath\n"\ - " : boot class path list", "hir2mpl", {} }, - { kClassLoaderContext, 0, "", "classloadercontext", - kBuildTypeAll, kArgCheckPolicyRequired, - " -classloadercontext=pcl\n"\ - " : class loader context \n"\ - " : path class loader", "hir2mpl", {} }, - { kCollectDepTypes, 0, "", "dep", - kBuildTypeAll, kArgCheckPolicyRequired, - " -dep=all or func\n"\ - " : [all] collect all dependent types\n"\ - " : [func] collect dependent types in function", "hir2mpl", {} }, - { kDepSameNamePolicy, 0, "", "depsamename", - kBuildTypeAll, kArgCheckPolicyRequired, - " -DepSameNamePolicy=sys or src\n"\ - " : [sys] load type from sys when on-demand load same name type\n"\ - " : [src] load type from src when on-demand load same name type", "hir2mpl", {} }, - - // security check - { kUnknown, 0, "", "", - kBuildTypeAll, kArgCheckPolicyUnknown, - "\n====== Security Check ======", "hir2mpl", {} }, - { kNpeCheckDynamic, 0, "", "npe-check-dynamic", - kBuildTypeAll, kArgCheckPolicyNone, - " -npe-check-dynamic : Nonnull pointr dynamic checking", "hir2mpl", {} }, - { kBoundaryCheckDynamic, 0, "", "boundary-check-dynamic", - kBuildTypeAll, kArgCheckPolicyNone, - " -boundary-check-dynamic\n" \ - " : Boundary dynamic checking", "hir2mpl", {} }, - { kSafeRegion, 0, "", "safe-region", - kBuildTypeAll, kArgCheckPolicyNone, - " -safe-region : Enable safe region", "hir2mpl", {} }, - { kUnknown, 0, "", "", - kBuildTypeAll, kArgCheckPolicyNone, - "\n", "hir2mpl", {} } -}; - HIR2MPLOptions::HIR2MPLOptions() { - CreateUsages(kUsage); Init(); } @@ -300,315 +45,318 @@ void HIR2MPLOptions::Init() { } bool HIR2MPLOptions::InitFactory() { - RegisterFactoryFunction(kHir2mplHelp, - &HIR2MPLOptions::ProcessHelp); - RegisterFactoryFunction(kVersion, - &HIR2MPLOptions::ProcessVersion); + + RegisterFactoryFunction(&opts::hir2mpl::help, + &HIR2MPLOptions::ProcessHelp); + RegisterFactoryFunction(&opts::hir2mpl::version, + &HIR2MPLOptions::ProcessVersion); // input control options - RegisterFactoryFunction(kMpltSys, - &HIR2MPLOptions::ProcessInputMpltFromSys); - RegisterFactoryFunction(kMpltApk, - &HIR2MPLOptions::ProcessInputMpltFromApk); - RegisterFactoryFunction(kInMplt, - &HIR2MPLOptions::ProcessInputMplt); - RegisterFactoryFunction(kInClass, - &HIR2MPLOptions::ProcessInClass); - RegisterFactoryFunction(kInJar, - &HIR2MPLOptions::ProcessInJar); - RegisterFactoryFunction(kInDex, - &HIR2MPLOptions::ProcessInDex); - RegisterFactoryFunction(kInAST, - &HIR2MPLOptions::ProcessInAST); - RegisterFactoryFunction(kInMAST, - &HIR2MPLOptions::ProcessInMAST); + RegisterFactoryFunction(&opts::hir2mpl::mpltSys, + &HIR2MPLOptions::ProcessInputMpltFromSys); + RegisterFactoryFunction(&opts::hir2mpl::mpltApk, + &HIR2MPLOptions::ProcessInputMpltFromApk); + RegisterFactoryFunction(&opts::hir2mpl::mplt, + &HIR2MPLOptions::ProcessInputMplt); + RegisterFactoryFunction(&opts::hir2mpl::inClass, + &HIR2MPLOptions::ProcessInClass); + RegisterFactoryFunction(&opts::hir2mpl::inJar, + &HIR2MPLOptions::ProcessInJar); + RegisterFactoryFunction(&opts::hir2mpl::inDex, + &HIR2MPLOptions::ProcessInDex); + RegisterFactoryFunction(&opts::hir2mpl::inAst, + &HIR2MPLOptions::ProcessInAST); + RegisterFactoryFunction(&opts::hir2mpl::inMast, + &HIR2MPLOptions::ProcessInMAST); // output control options - RegisterFactoryFunction(kOutputPath, - &HIR2MPLOptions::ProcessOutputPath); - RegisterFactoryFunction(kOutputName, - &HIR2MPLOptions::ProcessOutputName); - RegisterFactoryFunction(kGenMpltOnly, - &HIR2MPLOptions::ProcessGenMpltOnly); - RegisterFactoryFunction(kGenAsciiMplt, - &HIR2MPLOptions::ProcessGenAsciiMplt); - RegisterFactoryFunction(kDumpInstComment, - &HIR2MPLOptions::ProcessDumpInstComment); - RegisterFactoryFunction(kNoMplFile, - &HIR2MPLOptions::ProcessNoMplFile); + RegisterFactoryFunction(&opts::hir2mpl::output, + &HIR2MPLOptions::ProcessOutputPath); + RegisterFactoryFunction(&opts::hir2mpl::outputName, + &HIR2MPLOptions::ProcessOutputName); + RegisterFactoryFunction(&opts::hir2mpl::mpltOnly, + &HIR2MPLOptions::ProcessGenMpltOnly); + RegisterFactoryFunction(&opts::hir2mpl::asciimplt, + &HIR2MPLOptions::ProcessGenAsciiMplt); + RegisterFactoryFunction(&opts::hir2mpl::dumpInstComment, + &HIR2MPLOptions::ProcessDumpInstComment); + RegisterFactoryFunction(&opts::hir2mpl::noMplFile, + &HIR2MPLOptions::ProcessNoMplFile); // debug info control options - RegisterFactoryFunction(kDumpLevel, - &HIR2MPLOptions::ProcessDumpLevel); - RegisterFactoryFunction(kDumpTime, - &HIR2MPLOptions::ProcessDumpTime); - RegisterFactoryFunction(kDumpComment, - &HIR2MPLOptions::ProcessDumpComment); - RegisterFactoryFunction(kDumpLOC, - &HIR2MPLOptions::ProcessDumpLOC); - RegisterFactoryFunction(kDumpPhaseTime, - &HIR2MPLOptions::ProcessDumpPhaseTime); - RegisterFactoryFunction(kDumpPhaseTimeDetail, - &HIR2MPLOptions::ProcessDumpPhaseTimeDetail); - - // java bytecode compile options - RegisterFactoryFunction(kJavaStaticFieldName, - &HIR2MPLOptions::ProcessModeForJavaStaticFieldName); - RegisterFactoryFunction(kJBCInfoUsePathName, - &HIR2MPLOptions::ProcessJBCInfoUsePathName); - RegisterFactoryFunction(kDumpJBCStmt, - &HIR2MPLOptions::ProcessDumpJBCStmt); - RegisterFactoryFunction(kDumpJBCErrorOnly, - &HIR2MPLOptions::ProcessDumpJBCErrorOnly); - RegisterFactoryFunction(kDumpJBCFuncName, - &HIR2MPLOptions::ProcessDumpJBCFuncName); - RegisterFactoryFunction(kEmitJBCLocalVarInfo, - &HIR2MPLOptions::ProcessEmitJBCLocalVarInfo); + RegisterFactoryFunction(&opts::hir2mpl::dumpLevel, + &HIR2MPLOptions::ProcessDumpLevel); + RegisterFactoryFunction(&opts::hir2mpl::dumpTime, + &HIR2MPLOptions::ProcessDumpTime); + RegisterFactoryFunction(&opts::hir2mpl::dumpComment, + &HIR2MPLOptions::ProcessDumpComment); + RegisterFactoryFunction(&opts::hir2mpl::dumpLOC, + &HIR2MPLOptions::ProcessDumpLOC); + RegisterFactoryFunction(&opts::hir2mpl::dumpPhaseTime, + &HIR2MPLOptions::ProcessDumpPhaseTime); + RegisterFactoryFunction(&opts::hir2mpl::dumpPhaseTimeDetail, + &HIR2MPLOptions::ProcessDumpPhaseTimeDetail); // general stmt/bb/cfg debug options - RegisterFactoryFunction(kDumpFEIRBB, - &HIR2MPLOptions::ProcessDumpFEIRBB); - RegisterFactoryFunction(kDumpFEIRCFGGraph, - &HIR2MPLOptions::ProcessDumpFEIRCFGGraph); + RegisterFactoryFunction(&opts::hir2mpl::dumpFEIRBB, + &HIR2MPLOptions::ProcessDumpFEIRBB); + RegisterFactoryFunction(&opts::hir2mpl::dumpFEIRCFGGraph, + &HIR2MPLOptions::ProcessDumpFEIRCFGGraph); // multi-thread control options - RegisterFactoryFunction(kNThreads, - &HIR2MPLOptions::ProcessNThreads); - RegisterFactoryFunction(kDumpThreadTime, - &HIR2MPLOptions::ProcessDumpThreadTime); + RegisterFactoryFunction(&opts::hir2mpl::np, + &HIR2MPLOptions::ProcessNThreads); + RegisterFactoryFunction(&opts::hir2mpl::dumpThreadTime, + &HIR2MPLOptions::ProcessDumpThreadTime); - RegisterFactoryFunction(kRC, - &HIR2MPLOptions::ProcessRC); - RegisterFactoryFunction(kNoBarrier, - &HIR2MPLOptions::ProcessNoBarrier); + RegisterFactoryFunction(&opts::hir2mpl::rc, + &HIR2MPLOptions::ProcessRC); + RegisterFactoryFunction(&opts::hir2mpl::nobarrier, + &HIR2MPLOptions::ProcessNoBarrier); // ast compiler options - RegisterFactoryFunction(kUseSignedChar, - &HIR2MPLOptions::ProcessUseSignedChar); - RegisterFactoryFunction(kFEBigEndian, - &HIR2MPLOptions::ProcessBigEndian); + RegisterFactoryFunction(&opts::hir2mpl::usesignedchar, + &HIR2MPLOptions::ProcessUseSignedChar); + RegisterFactoryFunction(&opts::hir2mpl::be, + &HIR2MPLOptions::ProcessBigEndian); // On Demand Type Creation - RegisterFactoryFunction(kXBootClassPath, - &HIR2MPLOptions::ProcessXbootclasspath); - RegisterFactoryFunction(kClassLoaderContext, - &HIR2MPLOptions::ProcessClassLoaderContext); - RegisterFactoryFunction(kInputFile, - &HIR2MPLOptions::ProcessCompilefile); - RegisterFactoryFunction(kCollectDepTypes, - &HIR2MPLOptions::ProcessCollectDepTypes); - RegisterFactoryFunction(kDepSameNamePolicy, - &HIR2MPLOptions::ProcessDepSameNamePolicy); + RegisterFactoryFunction(&opts::hir2mpl::xbootclasspath, + &HIR2MPLOptions::ProcessXbootclasspath); + RegisterFactoryFunction(&opts::hir2mpl::classloadercontext, + &HIR2MPLOptions::ProcessClassLoaderContext); + RegisterFactoryFunction(&opts::hir2mpl::dep, + &HIR2MPLOptions::ProcessCollectDepTypes); + RegisterFactoryFunction(&opts::hir2mpl::depsamename, + &HIR2MPLOptions::ProcessDepSameNamePolicy); // EnhanceC - RegisterFactoryFunction(kNpeCheckDynamic, - &HIR2MPLOptions::ProcessNpeCheckDynamic); - RegisterFactoryFunction(kBoundaryCheckDynamic, - &HIR2MPLOptions::ProcessBoundaryCheckDynamic); - RegisterFactoryFunction(kSafeRegion, - &HIR2MPLOptions::ProcessSafeRegion); - - RegisterFactoryFunction(kO2, - &HIR2MPLOptions::ProcessO2); - RegisterFactoryFunction(kSimplifyShortCircuit, - &HIR2MPLOptions::ProcessSimplifyShortCircuit); - RegisterFactoryFunction(kEnableVariableArray, - &HIR2MPLOptions::ProcessEnableVariableArray); - RegisterFactoryFunction(kFuncInlineSize, - &HIR2MPLOptions::ProcessFuncInlineSize); - RegisterFactoryFunction(kWPAA, - &HIR2MPLOptions::ProcessWPAA); - return true; -} - -bool HIR2MPLOptions::SolveOptions(const std::deque