diff options
| author | 2026-03-21 17:55:01 +0100 | |
|---|---|---|
| committer | 2026-03-21 17:55:01 +0100 | |
| commit | 0e75fc383becccd113416677b7e26e0caf21e28b (patch) | |
| tree | 356cf6c271ea8e0b2ca0211ac0c9efe776cc2118 /src/a_main.c | |
| parent | 8b846d0245744f4eefc32f3c98b6359a3d21e659 (diff) | |
Rework handling of predefined macros.
And add some GCC predefs like __SIZE_TYPE__, __LONG_SIZE__, etc
Diffstat (limited to 'src/a_main.c')
| -rw-r--r-- | src/a_main.c | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/src/a_main.c b/src/a_main.c index 8004dd3..309fe23 100644 --- a/src/a_main.c +++ b/src/a_main.c @@ -121,7 +121,29 @@ static Task task = { .inf = VINIT(infilebuf, countof(infilebuf)) }; static void prihelp(void); -void cpppredef(bool undef, const char *cmd); +void cpp0define(const char *name, const char *body); +void cpp0undef(const char *name); + +static void +predef(bool undef, const char *cmd) +{ + char buf[1024]; + const char *sep = strchr(cmd, '='), + *body = sep ? sep+1 : "1"; + const char *name; + if (sep) { + uint n = sep - cmd; + assert(n < sizeof buf - 1); + memcpy(buf, cmd, n); + buf[n] = 0; + name = buf; + } else { + name = cmd; + } + if (undef) cpp0undef(name); + else cpp0define(name, body); +} + static void optparse(char **args) @@ -251,7 +273,7 @@ optparse(char **args) } else if (*arg == 'D' || *arg == 'U') { const char *def = arg[1] ? arg+1 : *++args; if (!def) fatal(NULL, "macro name missing after `-%c`", *arg); - cpppredef(*arg == 'U', def); + predef(*arg == 'U', def); } else if (*arg == 'O') { /* TODO optimization level */ } else if (*arg == 'I' || !strcmp(arg, "-include-directory")) { @@ -754,7 +776,7 @@ main(int argc, char **argv) } for (const char *const *p = host_predefs; *p; ++p) - cpppredef(0, *p); + predef(0, *p); return driver(); } |