[WRAPPERHELPER] Added the `--gst` option (#2072)

This commit is contained in:
rajdakin 2024-11-25 16:13:04 +01:00 committed by GitHub
parent 84608fc581
commit a71856801b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 20 additions and 4 deletions

View File

@ -1176,7 +1176,8 @@ void type_print(type_t *typ) {
void struct_print(const struct_t *st) {
printf("<" DISP_ADDR_FMT "n_uses=%zu> ", DISP_ADDR_ARG(st) st->nrefs);
if (st->is_simple) {
printf("<simple> ");
printf("<simple> %s %s <don't care>", st->is_struct ? "struct" : "union", st->tag ? string_content(st->tag) : "<no tag>");
return;
}
if (st->is_defined) {
printf(

View File

@ -13,8 +13,8 @@
static void help(char *arg0) {
printf("Usage: %s --help\n"
" %s {-I/path/to/include}* [--prepare|--preproc|--proc] [--arch <arch>|-32|-64|--32|--64] <filename_in>\n"
" %s {-I/path/to/include}* [[--emu <arch>] [--target <arch>]|-32|-64|--32|--64] <filename_in> <filename_reqs> <filename_out>\n"
" %s {-I/path/to/include}* [--gst] [--prepare|--preproc|--proc] [--arch <arch>|-32|-64|--32|--64] <filename_in>\n"
" %s {-I/path/to/include}* [--gst] [[--emu <arch>] [--target <arch>]|-32|-64|--32|--64] <filename_in> <filename_reqs> <filename_out>\n"
"\n"
" --prepare Dump all preprocessor tokens (prepare phase)\n"
" --preproc Dump all processor tokens (preprocessor phase)\n"
@ -33,7 +33,9 @@ static void help(char *arg0) {
" -32 --32 Use the x86 architecture as arch/emulated, aarch64 as target\n"
" -64 --64 Use the x86_64 architecture as arch/emulated, aarch64 as target\n"
"\n"
" <arch> is one of 'x86', 'x86_64', 'aarch64'\n",
" <arch> is one of 'x86', 'x86_64', 'aarch64'\n"
"\n"
" --gst Mark all structures with a tag starting with '_G' and ending with 'Class' as simple\n",
arg0, arg0, arg0);
}
@ -50,6 +52,8 @@ enum bits_state {
BITS_64,
};
int is_gst = 0;
int main(int argc, char **argv) {
setbuf(stdout, NULL);
if (!setlocale(LC_NUMERIC, "C")) {
@ -75,6 +79,8 @@ int main(int argc, char **argv) {
ms = MAIN_PREPROC;
} else if (!strcmp(argv[i], "--proc")) {
ms = MAIN_PROC;
} else if (!strcmp(argv[i], "--gst")) {
is_gst = 1;
} else if (!strcmp(argv[i], "-pthread")) {
// Ignore
} else if (!strcmp(argv[i], "-I") && (i + 1 < argc)) {

View File

@ -1431,6 +1431,8 @@ static int eval_expression(loginfo_t *li, machine_t *target, expr_t *e, khash_t(
}
}
extern int is_gst; // If 1, mark structures _G*Class as simple
// declaration-specifier with storage != NULL
// specifier-qualifier-list + static_assert-declaration with storage == NULL
static int parse_declaration_specifier(machine_t *target, khash_t(struct_map) *struct_map, khash_t(type_map) *type_map, khash_t(type_map) *enum_map,
@ -2047,6 +2049,13 @@ parse_cur_token_decl:
typ->val.st->nmembers = vector_size(st_members, members);
typ->val.st->members = vector_steal(st_members, members);
typ->val.st->is_defined = 1;
if (is_gst
&& typ->val.st->tag
&& (string_len(typ->val.st->tag) >= 7)
&& !strncmp(string_content(typ->val.st->tag), "_G", 2)
&& !strcmp(string_content(typ->val.st->tag) + string_len(typ->val.st->tag) - 5, "Class")) {
typ->val.st->is_simple = 1;
}
*tok = proc_next_token(prep);
goto parse_cur_token_decl;
} else {