1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
#ifndef APIMAGIC_H
#define APIMAGIC_H
#include <stdint.h>
#include <stdio.h>
#include <cparser/ast/entity.h>
#include <cparser/driver/c_driver.h>
#include <cparser/driver/driver_t.h>
#include "apimagic_api.h"
#ifdef __cplusplus
extern "C" {
#endif
/* pre-alpha */
#ifndef AMGC_APP
#ifndef AMGC_PRE_ALPHA
#error libapimagic: pre-alpha: ABI is not final!
#error to use the library, please pass -DAMGC_PRE_ALPHA to the compiler.
#endif
#endif
/* status codes */
#define AMGC_OK 0x00
#define AMGC_USAGE 0x01
#define AMGC_BAD_OPT 0x02
#define AMGC_BAD_OPT_VAL 0x03
#define AMGC_IO_ERROR 0xA0
#define AMGC_MAP_ERROR 0xA1
#define AMGC_INIT_ERROR 0xA2
/* driver flags */
#define AMGC_DRIVER_VERBOSITY_NONE 0x0000
#define AMGC_DRIVER_VERBOSITY_ERRORS 0x0001
#define AMGC_DRIVER_VERBOSITY_STATUS 0x0002
#define AMGC_DRIVER_VERBOSITY_USAGE 0x0004
#define AMGC_DRIVER_CLONE_VECTOR 0x0008
#define AMGC_DRIVER_VERSION 0x0010
#define AMGC_DRIVER_DRY_RUN 0x0020
/* unit action flags */
struct amgc_input {
void * addr;
size_t size;
};
struct amgc_common_ctx {
uint64_t drvflags;
uint64_t actflags;
uint64_t fmtflags;
struct compilation_env_t * ccenv;
enum lang_standard_t std;
};
struct amgc_driver_ctx {
const char ** units;
const char * program;
const char * module;
const struct amgc_common_ctx * cctx;
void * any;
int status;
int nerrors;
};
struct amgc_unit_meta {
int ndefines;
int nenums;
int nenumvals;
int ntypedefs;
int nstructs;
int nunions;
int nfunctions;
int ngenerated;
};
struct amgc_define {
const pp_definition_t * symbol;
const char * definition;
const char * altname;
};
struct amgc_entity {
const union entity_t * entity;
const char * altname;
int enumval;
bool fmbstr;
bool futf16;
bool fset;
bool fexclude;
};
struct amgc_unit_entities {
struct amgc_define * defines;
struct amgc_entity * enums;
struct amgc_entity * enumvals;
struct amgc_entity * typedefs;
struct amgc_entity * structs;
struct amgc_entity * unions;
struct amgc_entity * functions;
struct amgc_entity * generated;
};
struct amgc_unit_ctx {
const char * const * path;
const struct amgc_input * map;
const struct amgc_common_ctx * cctx;
const struct amgc_unit_meta * meta;
const struct amgc_unit_entities*entities;
const struct compilation_unit_t*ccunit;
void * any;
int status;
int nerrors;
};
/* driver api */
amgc_api int amgc_get_driver_ctx (const char ** argv, const char ** envp, uint32_t flags, struct amgc_driver_ctx **);
amgc_api int amgc_create_driver_ctx (const struct amgc_common_ctx *, struct amgc_driver_ctx **);
amgc_api void amgc_free_driver_ctx (struct amgc_driver_ctx *);
amgc_api int amgc_get_unit_ctx (const struct amgc_driver_ctx *, const char * path, struct amgc_unit_ctx **);
amgc_api void amgc_free_unit_ctx (struct amgc_unit_ctx *);
amgc_api int amgc_map_input (int fd, const char * path, int prot, struct amgc_input *);
amgc_api int amgc_unmap_input (struct amgc_input *);
/* driver helper api */
amgc_api int amgc_lang_std_from_string (const char * std);
/* utility api */
/* low-level api */
amgc_api int amgc_init_unit_meta (const struct amgc_unit_ctx *, struct amgc_unit_meta *);
amgc_api int amgc_get_unit_entities (const struct amgc_unit_ctx *, struct amgc_unit_meta *, struct amgc_unit_entities **);
amgc_api void amgc_free_unit_entities (struct amgc_unit_entities *);
#ifdef __cplusplus
}
#endif
#endif
|