Files
FEX-Emu--FEX/Source/Common/ArgumentLoader.cpp
T
Ryan Houdek b6c0a9f2a0 Configuration option improvements
This commit does three things that are bounded to each other
1) Moves configs from ConfigValues.inl to Config.json
2) Uses the json to generate a man file with the options inside of it
3) Generates the code required for FEXLoader to automatically parse defined options

Moving the configuration options to a parseable format was required to generate the man pages.
Can't really include an inl file in the man page
Man page gets generated and installed through the regular cmake install process
`man FEX` to get the man page

With this change, FEXLoader's argument parsing now will automatically be generated from the json.
This way whatever is in the json file matches what is in the man page, in the json, AND what is returned in FEXLoader --help.
It will stay in sync now.

FEXConfig is the only application that stays out of sync for now as it requires some more thought to plan out.

A minor improvement that this brings as well is that every boolean option that has a long argument also gains the inversion of that property.
aka, `--gdb` also gains `--no-gdb` The use case for this is minor but boolean arguments should always allow negated variants.
2021-03-28 23:28:41 -07:00

90 lines
2.5 KiB
C++

#include "Common/ArgumentLoader.h"
#include "Common/Config.h"
#include "OptionParser.h"
#include "git_version.h"
namespace FEX::Handler {
std::string CoreHandler(std::string &Value) {
if (Value == "irint")
return "0";
else if (Value == "irjit")
return "1";
#ifdef _M_X86_64
else if (Value == "host")
return "2";
#endif
return "1";
}
std::string SingleStepHandler(std::string &Value) {
// Single stepping also enforces single instruction size blocks
Set(FEXCore::Config::ConfigOption::CONFIG_MAXBLOCKINST, std::to_string(1u));
return Value;
}
std::string SMCCheckHandler(std::string &Value) {
if (Value == "none")
return "0";
else if (Value == "mman")
return "1";
else if (Value == "full")
return "2";
return "0";
}
}
namespace FEX::ArgLoader {
std::vector<std::string> RemainingArgs;
std::vector<std::string> ProgramArguments;
static std::string Version = "FEX-Emu (" GIT_DESCRIBE_STRING ") ";
void FEX::ArgLoader::ArgLoader::Load() {
optparse::OptionParser Parser{};
Parser.version(Version);
optparse::OptionGroup CPUGroup(Parser, "CPU Core options");
optparse::OptionGroup EmulationGroup(Parser, "Emulation options");
optparse::OptionGroup DebugGroup(Parser, "Debug options");
optparse::OptionGroup HacksGroup(Parser, "Hacks options");
optparse::OptionGroup MiscGroup(Parser, "Miscellaneous options");
optparse::OptionGroup LoggingGroup(Parser, "Logging options");
#define BEFORE_PARSE
#include <FEXCore/Config/ConfigOptions.inl>
Parser.add_option_group(CPUGroup);
Parser.add_option_group(EmulationGroup);
Parser.add_option_group(DebugGroup);
Parser.add_option_group(HacksGroup);
Parser.add_option_group(MiscGroup);
Parser.add_option_group(LoggingGroup);
optparse::Values Options = Parser.parse_args(argc, argv);
using int32 = int32_t;
using uint32 = uint32_t;
#define AFTER_PARSE
#include <FEXCore/Config/ConfigOptions.inl>
RemainingArgs = Parser.args();
ProgramArguments = Parser.parsed_args();
}
void LoadWithoutArguments(int _argc, char **_argv) {
// Skip argument 0, which will be the interpreter
for (int i = 1; i < _argc; ++i) {
RemainingArgs.emplace_back(_argv[i]);
}
// Put the interpreter in ProgramArguments
ProgramArguments.emplace_back(_argv[0]);
}
std::vector<std::string> Get() {
return RemainingArgs;
}
std::vector<std::string> GetParsedArgs() {
return ProgramArguments;
}
}