Commit b89b43e6 authored by nagayama15's avatar nagayama15

`RangeOptParser` の名前空間を変更

parent 91146f8a
...@@ -9,46 +9,12 @@ ...@@ -9,46 +9,12 @@
namespace namespace
{ {
template <typename Integer> const llvm::cl::opt<nykk::pass::RangeOptValue<std::size_t>, false, nykk::pass::RangeOptParser<std::size_t, 2, 10>> partition_opt
struct RangeOptValue
{
Integer value;
};
/**
* @brief Command line option analyzer.
*
* @tparam Integer Integer type.
* @tparam Min Minimum value to accept.
* @tparam Max Maximum value to accept.
*/
template <typename Integer, Integer Min, Integer Max>
class RangeOptParser
: public llvm::cl::parser<RangeOptValue<Integer>>
{
static_assert(std::is_integral_v<Integer>);
public:
using llvm::cl::parser<RangeOptValue<Integer>>::parser;
// Returns `true` on error.
bool parse(llvm::cl::Option& o, llvm::StringRef arg_name, llvm::StringRef arg, RangeOptValue<Integer>& value)
{
if (arg.getAsInteger(0, value.value) || value.value < Min || Max < value.value)
{
return o.error("invalid argument '" + arg_name + "=" + arg + "'");
}
return false;
}
};
const llvm::cl::opt<RangeOptValue<std::size_t>, false, RangeOptParser<std::size_t, 2, 10>> partition_opt
{ {
"partition", "partition",
llvm::cl::desc("Block partition number (2 ~ 10 default 7)"), llvm::cl::desc("Block partition number (2 ~ 10 default 7)"),
llvm::cl::value_desc("size"), llvm::cl::value_desc("size"),
llvm::cl::init(RangeOptValue<std::size_t> {7}), llvm::cl::init(nykk::pass::RangeOptValue<std::size_t> {7}),
}; };
/** /**
......
...@@ -5,6 +5,40 @@ ...@@ -5,6 +5,40 @@
namespace nykk::pass namespace nykk::pass
{ {
template <typename Integer>
struct RangeOptValue
{
Integer value;
};
/**
* @brief Command line option analyzer.
*
* @tparam Integer Integer type.
* @tparam Min Minimum value to accept.
* @tparam Max Maximum value to accept.
*/
template <typename Integer, Integer Min, Integer Max>
class RangeOptParser
: public llvm::cl::parser<RangeOptValue<Integer>>
{
static_assert(std::is_integral_v<Integer>);
public:
using llvm::cl::parser<RangeOptValue<Integer>>::parser;
// Returns `true` on error.
bool parse(llvm::cl::Option& o, llvm::StringRef arg_name, llvm::StringRef arg, RangeOptValue<Integer>& value)
{
if (arg.getAsInteger(0, value.value) || value.value < Min || Max < value.value)
{
return o.error("invalid argument '" + arg_name + "=" + arg + "'");
}
return false;
}
};
inline const llvm::cl::opt<std::string> watermark_opt inline const llvm::cl::opt<std::string> watermark_opt
{ {
"watermark", "watermark",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment