lc_opts_enum.h 2.36 KB
Newer Older
1
/*
2
3
4
 * This file is part of libFirm.
 * Copyright (C) 2012 IPD Goos, Universit"at Karlsruhe, Germany
 */
5
6
7
8

#ifndef _LC_OPTS_ENUM_T
#define _LC_OPTS_ENUM_T

9
#include "lc_opts.h"
10
11
12
13
14
15
16
17
18
19
20
21

#define _LC_OPT_DECL_ENUM(T, N)                 \
typedef struct {                                \
	const char *name;                             \
	T value;                                      \
} lc_opt_enum_ ## N ## _items_t;                \
                                                \
typedef struct {                                \
	T* value;                                     \
	const lc_opt_enum_ ## N ## _items_t *items;   \
} lc_opt_enum_ ## N ## _var_t;                  \
\
22
bool lc_opt_enum_ ## N ## _cb(const char *name, lc_opt_type_t type, void *data, size_t len, ...); \
23
24
25
26
int lc_opt_enum_ ## N ## _dump(char *buf, size_t n, const char *name, lc_opt_type_t type, void *data, size_t len); \
int lc_opt_enum_ ## N ## _dump_vals(char *buf, size_t n, const char *name, lc_opt_type_t type, void *data, size_t len); \

#define _LC_OPT_ENT_ENUM(N, name, desc, var) \
27
	_LC_OPT_ENT(name, desc, lc_opt_type_enum, lc_opt_enum_ ## N ## _var_t, var, 0, lc_opt_enum_ ## N ## _cb, lc_opt_enum_ ## N ## _dump, lc_opt_enum_ ## N ## _dump_vals)
28
29
30
31
32
33

_LC_OPT_DECL_ENUM(int, int)
_LC_OPT_DECL_ENUM(unsigned, mask)
_LC_OPT_DECL_ENUM(void *, ptr)
_LC_OPT_DECL_ENUM(const void *, const_ptr)

34
35
36
37
#define LC_OPT_ENT_ENUM_INT(name, desc, var)                _LC_OPT_ENT_ENUM(int, name, desc, var)
#define LC_OPT_ENT_ENUM_MASK(name, desc, var)               _LC_OPT_ENT_ENUM(mask, name, desc, var)
#define LC_OPT_ENT_ENUM_PTR(name, desc, var)                _LC_OPT_ENT_ENUM(ptr, name, desc, var)
#define LC_OPT_ENT_ENUM_CONST_PTR(name, desc, var)          _LC_OPT_ENT_ENUM(const_ptr, name, desc, var)
38
39
40
41
42
43
44
45
46
47
48
49
50

typedef struct {
	const char *name;
	int (*value)(void);
} lc_opt_enum_func_ptr_items_t;

typedef struct {
	int (**value)(void);
	const lc_opt_enum_func_ptr_items_t *items;
} lc_opt_enum_func_ptr_var_t;

#define LC_OPT_ENT_ENUM_FUNC_PTR(name, desc, var)       _LC_OPT_ENT_ENUM(func_ptr, name, desc, var)

51
bool lc_opt_enum_func_ptr_cb(const char *name, lc_opt_type_t type, void *data, size_t len, ...);
52
53
54
55
int lc_opt_enum_func_ptr_dump(char *buf, size_t n, const char *name, lc_opt_type_t type, void *data, size_t len);
int lc_opt_enum_func_ptr_dump_vals(char *buf, size_t n, const char *name, lc_opt_type_t type, void *data, size_t len);

#endif