diff options
Diffstat (limited to 'tools/perf/util/parse-options.h')
-rw-r--r-- | tools/perf/util/parse-options.h | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/tools/perf/util/parse-options.h b/tools/perf/util/parse-options.h index b2da725f102a..c7d72dce54b2 100644 --- a/tools/perf/util/parse-options.h +++ b/tools/perf/util/parse-options.h | |||
@@ -1,6 +1,9 @@ | |||
1 | #ifndef __PERF_PARSE_OPTIONS_H | 1 | #ifndef __PERF_PARSE_OPTIONS_H |
2 | #define __PERF_PARSE_OPTIONS_H | 2 | #define __PERF_PARSE_OPTIONS_H |
3 | 3 | ||
4 | #include <linux/kernel.h> | ||
5 | #include <stdbool.h> | ||
6 | |||
4 | enum parse_opt_type { | 7 | enum parse_opt_type { |
5 | /* special types */ | 8 | /* special types */ |
6 | OPTION_END, | 9 | OPTION_END, |
@@ -10,13 +13,15 @@ enum parse_opt_type { | |||
10 | OPTION_BIT, | 13 | OPTION_BIT, |
11 | OPTION_BOOLEAN, | 14 | OPTION_BOOLEAN, |
12 | OPTION_INCR, | 15 | OPTION_INCR, |
13 | OPTION_SET_INT, | 16 | OPTION_SET_UINT, |
14 | OPTION_SET_PTR, | 17 | OPTION_SET_PTR, |
15 | /* options with arguments (usually) */ | 18 | /* options with arguments (usually) */ |
16 | OPTION_STRING, | 19 | OPTION_STRING, |
17 | OPTION_INTEGER, | 20 | OPTION_INTEGER, |
18 | OPTION_LONG, | 21 | OPTION_LONG, |
19 | OPTION_CALLBACK, | 22 | OPTION_CALLBACK, |
23 | OPTION_U64, | ||
24 | OPTION_UINTEGER, | ||
20 | }; | 25 | }; |
21 | 26 | ||
22 | enum parse_opt_flags { | 27 | enum parse_opt_flags { |
@@ -74,7 +79,7 @@ typedef int parse_opt_cb(const struct option *, const char *arg, int unset); | |||
74 | * | 79 | * |
75 | * `defval`:: | 80 | * `defval`:: |
76 | * default value to fill (*->value) with for PARSE_OPT_OPTARG. | 81 | * default value to fill (*->value) with for PARSE_OPT_OPTARG. |
77 | * OPTION_{BIT,SET_INT,SET_PTR} store the {mask,integer,pointer} to put in | 82 | * OPTION_{BIT,SET_UINT,SET_PTR} store the {mask,integer,pointer} to put in |
78 | * the value when met. | 83 | * the value when met. |
79 | * CALLBACKS can use it like they want. | 84 | * CALLBACKS can use it like they want. |
80 | */ | 85 | */ |
@@ -91,17 +96,21 @@ struct option { | |||
91 | intptr_t defval; | 96 | intptr_t defval; |
92 | }; | 97 | }; |
93 | 98 | ||
99 | #define check_vtype(v, type) ( BUILD_BUG_ON_ZERO(!__builtin_types_compatible_p(typeof(v), type)) + v ) | ||
100 | |||
94 | #define OPT_END() { .type = OPTION_END } | 101 | #define OPT_END() { .type = OPTION_END } |
95 | #define OPT_ARGUMENT(l, h) { .type = OPTION_ARGUMENT, .long_name = (l), .help = (h) } | 102 | #define OPT_ARGUMENT(l, h) { .type = OPTION_ARGUMENT, .long_name = (l), .help = (h) } |
96 | #define OPT_GROUP(h) { .type = OPTION_GROUP, .help = (h) } | 103 | #define OPT_GROUP(h) { .type = OPTION_GROUP, .help = (h) } |
97 | #define OPT_BIT(s, l, v, h, b) { .type = OPTION_BIT, .short_name = (s), .long_name = (l), .value = (v), .help = (h), .defval = (b) } | 104 | #define OPT_BIT(s, l, v, h, b) { .type = OPTION_BIT, .short_name = (s), .long_name = (l), .value = check_vtype(v, int *), .help = (h), .defval = (b) } |
98 | #define OPT_BOOLEAN(s, l, v, h) { .type = OPTION_BOOLEAN, .short_name = (s), .long_name = (l), .value = (v), .help = (h) } | 105 | #define OPT_BOOLEAN(s, l, v, h) { .type = OPTION_BOOLEAN, .short_name = (s), .long_name = (l), .value = check_vtype(v, bool *), .help = (h) } |
99 | #define OPT_INCR(s, l, v, h) { .type = OPTION_INCR, .short_name = (s), .long_name = (l), .value = (v), .help = (h) } | 106 | #define OPT_INCR(s, l, v, h) { .type = OPTION_INCR, .short_name = (s), .long_name = (l), .value = check_vtype(v, int *), .help = (h) } |
100 | #define OPT_SET_INT(s, l, v, h, i) { .type = OPTION_SET_INT, .short_name = (s), .long_name = (l), .value = (v), .help = (h), .defval = (i) } | 107 | #define OPT_SET_UINT(s, l, v, h, i) { .type = OPTION_SET_UINT, .short_name = (s), .long_name = (l), .value = check_vtype(v, unsigned int *), .help = (h), .defval = (i) } |
101 | #define OPT_SET_PTR(s, l, v, h, p) { .type = OPTION_SET_PTR, .short_name = (s), .long_name = (l), .value = (v), .help = (h), .defval = (p) } | 108 | #define OPT_SET_PTR(s, l, v, h, p) { .type = OPTION_SET_PTR, .short_name = (s), .long_name = (l), .value = (v), .help = (h), .defval = (p) } |
102 | #define OPT_INTEGER(s, l, v, h) { .type = OPTION_INTEGER, .short_name = (s), .long_name = (l), .value = (v), .help = (h) } | 109 | #define OPT_INTEGER(s, l, v, h) { .type = OPTION_INTEGER, .short_name = (s), .long_name = (l), .value = check_vtype(v, int *), .help = (h) } |
103 | #define OPT_LONG(s, l, v, h) { .type = OPTION_LONG, .short_name = (s), .long_name = (l), .value = (v), .help = (h) } | 110 | #define OPT_UINTEGER(s, l, v, h) { .type = OPTION_UINTEGER, .short_name = (s), .long_name = (l), .value = check_vtype(v, unsigned int *), .help = (h) } |
104 | #define OPT_STRING(s, l, v, a, h) { .type = OPTION_STRING, .short_name = (s), .long_name = (l), .value = (v), (a), .help = (h) } | 111 | #define OPT_LONG(s, l, v, h) { .type = OPTION_LONG, .short_name = (s), .long_name = (l), .value = check_vtype(v, long *), .help = (h) } |
112 | #define OPT_U64(s, l, v, h) { .type = OPTION_U64, .short_name = (s), .long_name = (l), .value = check_vtype(v, u64 *), .help = (h) } | ||
113 | #define OPT_STRING(s, l, v, a, h) { .type = OPTION_STRING, .short_name = (s), .long_name = (l), .value = check_vtype(v, const char **), (a), .help = (h) } | ||
105 | #define OPT_DATE(s, l, v, h) \ | 114 | #define OPT_DATE(s, l, v, h) \ |
106 | { .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), .argh = "time", .help = (h), .callback = parse_opt_approxidate_cb } | 115 | { .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), .argh = "time", .help = (h), .callback = parse_opt_approxidate_cb } |
107 | #define OPT_CALLBACK(s, l, v, a, h, f) \ | 116 | #define OPT_CALLBACK(s, l, v, a, h, f) \ |