Blame include/apimagic/apimagic.h

383aa6
#ifndef APIMAGIC_H
383aa6
#define APIMAGIC_H
383aa6
383aa6
#include <stdint.h>
383aa6
#include <stdio.h>
383aa6
7a622c
#include <cparser/ast/entity.h>
fd0662
#include <cparser/driver/c_driver.h>
43c8c9
#include <cparser/driver/driver_t.h>
43c8c9
383aa6
#include "apimagic_api.h"
383aa6
383aa6
#ifdef __cplusplus
383aa6
extern "C" {
383aa6
#endif
383aa6
383aa6
/* pre-alpha */
383aa6
#ifndef AMGC_APP
383aa6
#ifndef AMGC_PRE_ALPHA
383aa6
#error  libapimagic: pre-alpha: ABI is not final!
383aa6
#error  to use the library, please pass -DAMGC_PRE_ALPHA to the compiler.
383aa6
#endif
383aa6
#endif
383aa6
383aa6
/* status codes */
383aa6
#define AMGC_OK				0x00
383aa6
#define AMGC_USAGE			0x01
383aa6
#define AMGC_BAD_OPT			0x02
383aa6
#define AMGC_BAD_OPT_VAL		0x03
383aa6
#define AMGC_IO_ERROR			0xA0
383aa6
#define AMGC_MAP_ERROR			0xA1
1fd161
#define AMGC_INIT_ERROR			0xA2
383aa6
383aa6
/* driver flags */
383aa6
#define AMGC_DRIVER_VERBOSITY_NONE	0x0000
383aa6
#define AMGC_DRIVER_VERBOSITY_ERRORS	0x0001
383aa6
#define AMGC_DRIVER_VERBOSITY_STATUS	0x0002
383aa6
#define AMGC_DRIVER_VERBOSITY_USAGE	0x0004
383aa6
#define AMGC_DRIVER_CLONE_VECTOR	0x0008
383aa6
383aa6
#define AMGC_DRIVER_VERSION		0x0010
383aa6
#define AMGC_DRIVER_DRY_RUN		0x0020
383aa6
d3f07e
enum amgc_action_type {
d3f07e
	AMGC_ACTION_NONE,
d3f07e
	AMGC_ACTION_OUTPUT,
d3f07e
};
d3f07e
d3f07e
enum amgc_output_action {
d3f07e
	AMGC_OUTPUT_DEFINE,
d3f07e
	AMGC_OUTPUT_ENUM,
d3f07e
	AMGC_OUTPUT_TYPEDEF,
d3f07e
	AMGC_OUTPUT_STRUCT,
d3f07e
	AMGC_OUTPUT_UNION,
d3f07e
	AMGC_OUTPUT_FUNCTION,
2e879c
	AMGC_LIST_DEFINE,
2e879c
	AMGC_LIST_ENUM,
2e879c
	AMGC_LIST_TYPEDEF,
2e879c
	AMGC_LIST_STRUCT,
2e879c
	AMGC_LIST_UNION,
2e879c
	AMGC_LIST_FUNCTION,
d3f07e
};
383aa6
383aa6
struct amgc_input {
383aa6
	void *	addr;
383aa6
	size_t	size;
383aa6
};
383aa6
d3f07e
struct amgc_action {
d3f07e
	enum amgc_action_type		type;
d3f07e
	int				action;
6adb90
	const char *			symbol;
d3f07e
	const char *			filter;
55f11a
	int				subset;
d3f07e
};
d3f07e
383aa6
struct amgc_common_ctx {
383aa6
	uint64_t			drvflags;
383aa6
	uint64_t			actflags;
383aa6
	uint64_t			fmtflags;
d3f07e
	const struct amgc_action *	actions;
43c8c9
	struct compilation_env_t *	ccenv;
fd0662
	enum lang_standard_t		std;
383aa6
};
383aa6
383aa6
struct amgc_driver_ctx {
383aa6
	const char **			units;
383aa6
	const char *			program;
383aa6
	const char *			module;
383aa6
	const struct amgc_common_ctx *	cctx;
383aa6
	void *				any;
383aa6
	int				status;
383aa6
	int				nerrors;
383aa6
};
383aa6
9c2028
struct amgc_unit_meta {
9c2028
	int	ndefines;
9c2028
	int	nenums;
9c2028
	int	nenumvals;
9c2028
	int	ntypedefs;
9c2028
	int	nstructs;
9c2028
	int	nunions;
9c2028
	int	nfunctions;
9c2028
	int	ngenerated;
9c2028
};
9c2028
7a622c
struct amgc_define {
7a622c
	const pp_definition_t *		symbol;
7a622c
	const char *			definition;
7a622c
	const char *			altname;
7a622c
};
7a622c
7a622c
struct amgc_entity {
7a622c
	const union entity_t *		entity;
91ea2c
	const union type_t *		reftype;
a77596
	const struct amgc_entity *	parent;
7a622c
	const char * 			altname;
7a622c
	int 				enumval;
3aebba
	int				ptrdepth;
7a622c
	bool 				fmbstr;
7a622c
	bool 				futf16;
7a622c
	bool				fset;
7a622c
	bool				fexclude;
7a622c
};
7a622c
7a622c
struct amgc_unit_entities {
7a622c
	struct amgc_define *		defines;
7a622c
	struct amgc_entity *		enums;
7a622c
	struct amgc_entity *		enumvals;
7a622c
	struct amgc_entity *		typedefs;
7a622c
	struct amgc_entity *		structs;
7a622c
	struct amgc_entity *		unions;
7a622c
	struct amgc_entity *		functions;
7a622c
	struct amgc_entity *		generated;
7a622c
};
7a622c
383aa6
struct amgc_unit_ctx {
383aa6
	const char * const *		path;
383aa6
	const struct amgc_input *	map;
383aa6
	const struct amgc_common_ctx *	cctx;
9c2028
	const struct amgc_unit_meta *	meta;
7a622c
	const struct amgc_unit_entities*entities;
43c8c9
	const struct compilation_unit_t*ccunit;
383aa6
	void *				any;
383aa6
	int				status;
383aa6
	int				nerrors;
383aa6
};
383aa6
2f6d92
struct amgc_layout {
2f6d92
	const char *	header;
2f6d92
	const char *	footer;
2f6d92
	int		symwidth;
2f6d92
	int		tabwidth;
2f6d92
};
2f6d92
383aa6
/* driver api */
383aa6
amgc_api int  amgc_get_driver_ctx	(const char ** argv, const char ** envp, uint32_t flags, struct amgc_driver_ctx **);
383aa6
amgc_api int  amgc_create_driver_ctx	(const struct amgc_common_ctx *, struct amgc_driver_ctx **);
383aa6
amgc_api void amgc_free_driver_ctx	(struct amgc_driver_ctx *);
383aa6
383aa6
amgc_api int  amgc_get_unit_ctx		(const struct amgc_driver_ctx *, const char * path, struct amgc_unit_ctx **);
383aa6
amgc_api void amgc_free_unit_ctx	(struct amgc_unit_ctx *);
383aa6
383aa6
amgc_api int  amgc_map_input		(int fd, const char * path, int prot, struct amgc_input *);
383aa6
amgc_api int  amgc_unmap_input		(struct amgc_input *);
383aa6
fd0662
/* driver helper api */
fd0662
amgc_api int  amgc_lang_std_from_string	(const char * std);
fd0662
383aa6
/* utility api */
c46a30
amgc_api int  amgc_list_unit_defines	(const struct amgc_unit_ctx *, const struct amgc_layout *, FILE *);
c46a30
amgc_api int  amgc_list_unit_enums	(const struct amgc_unit_ctx *, const struct amgc_layout *, FILE *);
c46a30
amgc_api int  amgc_list_unit_typedefs	(const struct amgc_unit_ctx *, const struct amgc_layout *, FILE *);
c46a30
amgc_api int  amgc_list_unit_structs	(const struct amgc_unit_ctx *, const struct amgc_layout *, FILE *);
c46a30
amgc_api int  amgc_list_unit_unions	(const struct amgc_unit_ctx *, const struct amgc_layout *, FILE *);
c46a30
amgc_api int  amgc_list_unit_functions	(const struct amgc_unit_ctx *, const struct amgc_layout *, FILE *);
c46a30
c46a30
amgc_api int  amgc_output_unit_defines	(const struct amgc_unit_ctx *, const struct amgc_layout *, FILE *);
c46a30
amgc_api int  amgc_output_unit_enums	(const struct amgc_unit_ctx *, const struct amgc_layout *, FILE *);
c46a30
amgc_api int  amgc_output_unit_typedefs	(const struct amgc_unit_ctx *, const struct amgc_layout *, FILE *);
c46a30
amgc_api int  amgc_output_unit_structs	(const struct amgc_unit_ctx *, const struct amgc_layout *, FILE *);
c46a30
amgc_api int  amgc_output_unit_unions	(const struct amgc_unit_ctx *, const struct amgc_layout *, FILE *);
c46a30
amgc_api int  amgc_output_unit_functions(const struct amgc_unit_ctx *, const struct amgc_layout *, FILE *);
c46a30
c46a30
/* utility helper api */
bbff09
amgc_api int  amgc_perform_unit_action	(const struct amgc_unit_ctx *, const struct amgc_action *, const struct amgc_layout *, FILE *);
43b7a2
amgc_api int  amgc_output_unit_entities	(const struct amgc_unit_ctx *, int kind, int subset, const struct amgc_layout *, FILE *);
bbff09
c46a30
amgc_api int  amgc_get_entity_index	(const struct amgc_entity[], const char *);
c46a30
amgc_api int  amgc_get_define_index	(const struct amgc_unit_ctx *, const char *);
c46a30
amgc_api int  amgc_get_enum_index	(const struct amgc_unit_ctx *, const char *);
c46a30
amgc_api int  amgc_get_typedef_index	(const struct amgc_unit_ctx *, const char *);
c46a30
amgc_api int  amgc_get_struct_index	(const struct amgc_unit_ctx *, const char *);
c46a30
amgc_api int  amgc_get_union_index	(const struct amgc_unit_ctx *, const char *);
c46a30
amgc_api int  amgc_get_function_index	(const struct amgc_unit_ctx *, const char *);
c46a30
2f6d92
amgc_api int  amgc_output_pad_symbol	(const char *, const struct amgc_layout *, FILE *);
7b509c
amgc_api int  amgc_output_unit_enum	(const struct amgc_unit_ctx *, const union entity_t *, const struct amgc_layout *, FILE *);
7b509c
amgc_api int  amgc_output_custom_enum	(const struct amgc_entity *, const struct amgc_entity[], const struct amgc_layout *, FILE *);
25ada8
amgc_api int  amgc_output_typedef	(const struct amgc_unit_ctx *, const struct amgc_entity *, const struct amgc_layout *, FILE *);
383aa6
9c2028
/* low-level api */
9c2028
amgc_api int  amgc_init_unit_meta	(const struct amgc_unit_ctx *, struct amgc_unit_meta *);
f06b53
7a622c
amgc_api int  amgc_get_unit_entities	(const struct amgc_unit_ctx *, struct amgc_unit_meta *, struct amgc_unit_entities **);
7a622c
amgc_api void amgc_free_unit_entities	(struct amgc_unit_entities *);
9c2028
c4a105
amgc_api int  amgc_get_enum_members	(const struct amgc_unit_ctx *, const union entity_t *, struct amgc_entity **);
c4a105
amgc_api void amgc_free_enum_members	(struct amgc_entity *);
c4a105
383aa6
#ifdef __cplusplus
383aa6
}
383aa6
#endif
383aa6
383aa6
#endif