|
|
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
|
|
|
8fcd20 |
#define AMGC_ERROR 0x02
|
|
|
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 |
|
|
|
1480f4 |
#define AMGC_DRIVER_ANNOTATE_ALWAYS 0x10000000
|
|
|
1480f4 |
#define AMGC_DRIVER_ANNOTATE_NEVER 0x20000000
|
|
|
1480f4 |
#define AMGC_DRIVER_ANNOTATE_FULL 0x40000000
|
|
|
1480f4 |
|
|
|
615ccc |
/* error flags */
|
|
|
615ccc |
#define AMGC_ERROR_TOP_LEVEL 0x0001
|
|
|
615ccc |
#define AMGC_ERROR_NESTED 0x0002
|
|
|
615ccc |
#define AMGC_ERROR_CHILD 0x0004
|
|
|
615ccc |
#define AMGC_ERROR_CUSTOM 0x0008
|
|
|
615ccc |
|
|
|
615ccc |
enum amgc_custom_error {
|
|
|
615ccc |
AMGC_ERR_FLOW_ERROR,
|
|
|
615ccc |
AMGC_ERR_FLEE_ERROR,
|
|
|
615ccc |
AMGC_ERR_NULL_CONTEXT,
|
|
|
615ccc |
AMGC_ERR_NULL_SOURCE,
|
|
|
615ccc |
AMGC_ERR_INVALID_CONTEXT,
|
|
|
615ccc |
AMGC_ERR_INVALID_SOURCE,
|
|
|
615ccc |
AMGC_ERR_SOURCE_SIZE_ZERO,
|
|
|
615ccc |
AMGC_ERR_CAP,
|
|
|
615ccc |
};
|
|
|
615ccc |
|
|
|
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 |
|
|
|
f83623 |
struct amgc_source_version {
|
|
|
f83623 |
int major;
|
|
|
f83623 |
int minor;
|
|
|
f83623 |
int revision;
|
|
|
f83623 |
const char * commit;
|
|
|
f83623 |
};
|
|
|
f83623 |
|
|
|
abf923 |
struct amgc_fd_ctx {
|
|
|
abf923 |
int fdin;
|
|
|
abf923 |
int fdout;
|
|
|
abf923 |
int fderr;
|
|
|
abf923 |
int fdlog;
|
|
|
abf923 |
int fdcwd;
|
|
|
abf923 |
int fddst;
|
|
|
abf923 |
};
|
|
|
abf923 |
|
|
|
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 |
|
|
|
615ccc |
struct amgc_error_info {
|
|
|
615ccc |
const struct amgc_driver_ctx * edctx;
|
|
|
615ccc |
const struct amgc_unit_ctx * euctx;
|
|
|
615ccc |
const char * eunit;
|
|
|
615ccc |
int esyscode;
|
|
|
615ccc |
int elibcode;
|
|
|
615ccc |
const char * efunction;
|
|
|
615ccc |
int eline;
|
|
|
615ccc |
unsigned eflags;
|
|
|
615ccc |
void * eany;
|
|
|
615ccc |
};
|
|
|
615ccc |
|
|
|
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;
|
|
|
615ccc |
struct amgc_error_info ** errv;
|
|
|
383aa6 |
void * any;
|
|
|
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_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 |
};
|
|
|
383aa6 |
|
|
|
2f6d92 |
struct amgc_layout {
|
|
|
2f6d92 |
const char * header;
|
|
|
2f6d92 |
const char * footer;
|
|
|
2f6d92 |
int symwidth;
|
|
|
2f6d92 |
int tabwidth;
|
|
|
2f6d92 |
};
|
|
|
2f6d92 |
|
|
|
383aa6 |
/* driver api */
|
|
|
0dfdcb |
amgc_api int amgc_get_driver_ctx (char **, char **, uint32_t,
|
|
|
abf923 |
const struct amgc_fd_ctx *,
|
|
|
0dfdcb |
struct amgc_driver_ctx **);
|
|
|
0dfdcb |
|
|
|
0dfdcb |
amgc_api void amgc_free_driver_ctx (struct amgc_driver_ctx *);
|
|
|
383aa6 |
|
|
|
0dfdcb |
amgc_api int amgc_get_unit_ctx (const struct amgc_driver_ctx *,
|
|
|
0dfdcb |
const char *,
|
|
|
0dfdcb |
struct amgc_unit_ctx **);
|
|
|
383aa6 |
|
|
|
0dfdcb |
amgc_api void amgc_free_unit_ctx (struct amgc_unit_ctx *);
|
|
|
383aa6 |
|
|
|
abf923 |
amgc_api int amgc_get_driver_fdctx (const struct amgc_driver_ctx *, struct amgc_fd_ctx *);
|
|
|
abf923 |
amgc_api int amgc_set_driver_fdctx (struct amgc_driver_ctx *, const struct amgc_fd_ctx *);
|
|
|
abf923 |
|
|
|
fd0662 |
/* driver helper api */
|
|
|
0dfdcb |
amgc_api int amgc_lang_std_from_string (const char *);
|
|
|
fd0662 |
|
|
|
383aa6 |
/* utility api */
|
|
|
c44aca |
amgc_api int amgc_main (char **, char **, const struct amgc_fd_ctx *);
|
|
|
b8225b |
|
|
|
b8225b |
amgc_api int amgc_list_unit_defines (const struct amgc_driver_ctx *,
|
|
|
b8225b |
const struct amgc_unit_ctx *,
|
|
|
b8225b |
const struct amgc_layout *);
|
|
|
b8225b |
|
|
|
b8225b |
amgc_api int amgc_list_unit_enums (const struct amgc_driver_ctx *,
|
|
|
b8225b |
const struct amgc_unit_ctx *,
|
|
|
b8225b |
const struct amgc_layout *);
|
|
|
b8225b |
|
|
|
b8225b |
amgc_api int amgc_list_unit_typedefs (const struct amgc_driver_ctx *,
|
|
|
b8225b |
const struct amgc_unit_ctx *,
|
|
|
b8225b |
const struct amgc_layout *);
|
|
|
b8225b |
|
|
|
b8225b |
amgc_api int amgc_list_unit_structs (const struct amgc_driver_ctx *,
|
|
|
b8225b |
const struct amgc_unit_ctx *,
|
|
|
b8225b |
const struct amgc_layout *);
|
|
|
b8225b |
|
|
|
b8225b |
amgc_api int amgc_list_unit_unions (const struct amgc_driver_ctx *,
|
|
|
b8225b |
const struct amgc_unit_ctx *,
|
|
|
b8225b |
const struct amgc_layout *);
|
|
|
b8225b |
|
|
|
b8225b |
amgc_api int amgc_list_unit_functions (const struct amgc_driver_ctx *,
|
|
|
b8225b |
const struct amgc_unit_ctx *,
|
|
|
b8225b |
const struct amgc_layout *);
|
|
|
b8225b |
|
|
|
b8225b |
amgc_api int amgc_output_unit_defines (const struct amgc_driver_ctx *,
|
|
|
b8225b |
const struct amgc_unit_ctx *,
|
|
|
b8225b |
const struct amgc_layout *);
|
|
|
b8225b |
|
|
|
b8225b |
amgc_api int amgc_output_unit_enums (const struct amgc_driver_ctx *,
|
|
|
b8225b |
const struct amgc_unit_ctx *,
|
|
|
b8225b |
const struct amgc_layout *);
|
|
|
b8225b |
|
|
|
b8225b |
amgc_api int amgc_output_unit_typedefs (const struct amgc_driver_ctx *,
|
|
|
b8225b |
const struct amgc_unit_ctx *,
|
|
|
b8225b |
const struct amgc_layout *);
|
|
|
b8225b |
|
|
|
b8225b |
amgc_api int amgc_output_unit_structs (const struct amgc_driver_ctx *,
|
|
|
b8225b |
const struct amgc_unit_ctx *,
|
|
|
b8225b |
const struct amgc_layout *);
|
|
|
b8225b |
|
|
|
b8225b |
amgc_api int amgc_output_unit_unions (const struct amgc_driver_ctx *,
|
|
|
b8225b |
const struct amgc_unit_ctx *,
|
|
|
b8225b |
const struct amgc_layout *);
|
|
|
b8225b |
|
|
|
b8225b |
amgc_api int amgc_output_unit_functions(const struct amgc_driver_ctx *,
|
|
|
b8225b |
const struct amgc_unit_ctx *,
|
|
|
b8225b |
const struct amgc_layout *);
|
|
|
c46a30 |
|
|
|
c46a30 |
/* utility helper api */
|
|
|
b8225b |
amgc_api int amgc_perform_unit_action (const struct amgc_driver_ctx *,
|
|
|
b8225b |
const struct amgc_unit_ctx *,
|
|
|
0dfdcb |
const struct amgc_action *,
|
|
|
b8225b |
const struct amgc_layout *);
|
|
|
0dfdcb |
|
|
|
b8225b |
amgc_api int amgc_output_unit_entities (const struct amgc_driver_ctx *,
|
|
|
b8225b |
const struct amgc_unit_ctx *,
|
|
|
b8225b |
int, int, const struct amgc_layout *);
|
|
|
0dfdcb |
|
|
|
b8225b |
amgc_api int amgc_get_entity_index (const struct amgc_entity *, const char *);
|
|
|
0dfdcb |
amgc_api int amgc_get_define_index (const struct amgc_unit_ctx *, const char *);
|
|
|
0dfdcb |
amgc_api int amgc_get_enum_index (const struct amgc_unit_ctx *, const char *);
|
|
|
0dfdcb |
amgc_api int amgc_get_typedef_index (const struct amgc_unit_ctx *, const char *);
|
|
|
0dfdcb |
amgc_api int amgc_get_struct_index (const struct amgc_unit_ctx *, const char *);
|
|
|
0dfdcb |
amgc_api int amgc_get_union_index (const struct amgc_unit_ctx *, const char *);
|
|
|
0dfdcb |
amgc_api int amgc_get_function_index (const struct amgc_unit_ctx *, const char *);
|
|
|
0dfdcb |
|
|
|
b8225b |
amgc_api int amgc_output_pad_symbol (const struct amgc_driver_ctx *,
|
|
|
b8225b |
const char *, const struct amgc_layout *);
|
|
|
b8225b |
|
|
|
b8225b |
amgc_api int amgc_output_unit_enum (const struct amgc_driver_ctx *,
|
|
|
b8225b |
const struct amgc_unit_ctx *,
|
|
|
b8225b |
const union entity_t *,
|
|
|
b8225b |
const struct amgc_layout *);
|
|
|
b8225b |
|
|
|
b8225b |
amgc_api int amgc_output_custom_enum (const struct amgc_driver_ctx *,
|
|
|
b8225b |
const struct amgc_entity *,
|
|
|
b8225b |
const struct amgc_entity *,
|
|
|
b8225b |
const struct amgc_layout *);
|
|
|
b8225b |
|
|
|
b8225b |
amgc_api int amgc_output_typedef (const struct amgc_driver_ctx *,
|
|
|
b8225b |
const struct amgc_unit_ctx *,
|
|
|
b8225b |
const struct amgc_entity *,
|
|
|
b8225b |
const struct amgc_layout *);
|
|
|
b8225b |
|
|
|
b8225b |
amgc_api int amgc_output_compound (const struct amgc_driver_ctx *,
|
|
|
b8225b |
const struct amgc_unit_ctx *,
|
|
|
b8225b |
const struct amgc_entity *,
|
|
|
b8225b |
const struct amgc_layout *);
|
|
|
b8225b |
|
|
|
b8225b |
amgc_api int amgc_output_struct (const struct amgc_driver_ctx *,
|
|
|
b8225b |
const struct amgc_unit_ctx *,
|
|
|
b8225b |
const struct amgc_entity *,
|
|
|
b8225b |
const struct amgc_layout *);
|
|
|
b8225b |
|
|
|
b8225b |
amgc_api int amgc_output_union (const struct amgc_driver_ctx *,
|
|
|
b8225b |
const struct amgc_unit_ctx *,
|
|
|
b8225b |
const struct amgc_entity *,
|
|
|
b8225b |
const struct amgc_layout *);
|
|
|
0dfdcb |
|
|
|
0dfdcb |
/* error trace api */
|
|
|
0dfdcb |
amgc_api int amgc_output_error_record (const struct amgc_driver_ctx *, const struct amgc_error_info *);
|
|
|
0dfdcb |
amgc_api int amgc_output_error_vector (const struct amgc_driver_ctx *);
|
|
|
0dfdcb |
|
|
|
9c2028 |
/* low-level api */
|
|
|
0dfdcb |
amgc_api int amgc_init_unit_meta (const struct amgc_unit_ctx *, struct amgc_unit_meta *);
|
|
|
f06b53 |
|
|
|
0dfdcb |
amgc_api int amgc_get_unit_entities (const struct amgc_unit_ctx *, struct amgc_unit_meta *, struct amgc_unit_entities **);
|
|
|
0dfdcb |
amgc_api void amgc_free_unit_entities (struct amgc_unit_entities *);
|
|
|
9c2028 |
|
|
|
0dfdcb |
amgc_api int amgc_get_enum_members (const struct amgc_unit_ctx *, const union entity_t *, struct amgc_entity **);
|
|
|
0dfdcb |
amgc_api void amgc_free_enum_members (struct amgc_entity *);
|
|
|
0dfdcb |
|
|
|
0dfdcb |
/* package info */
|
|
|
0dfdcb |
amgc_api const struct amgc_source_version * amgc_source_version(void);
|
|
|
c4a105 |
|
|
|
383aa6 |
#ifdef __cplusplus
|
|
|
383aa6 |
}
|
|
|
383aa6 |
#endif
|
|
|
383aa6 |
|
|
|
383aa6 |
#endif
|