qbe

Internal scc patchset buffer for QBE
Log | Files | Refs | README | LICENSE

commit 2416d291417954a1fd7f4945a100f2c125d4d9a6
parent da36b211ab9f0d00b0128d9daaf32eba5ab5e56e
Author: Quentin Carbonneaux <quentin@c9x.me>
Date:   Tue, 15 Mar 2022 22:29:09 +0100

new -t? flag to print default target

Diffstat:
Mall.h | 1+
Mamd64/targ.c | 1+
Marm64/targ.c | 1+
Mmain.c | 42+++++++++++++++++++++---------------------
Mrv64/targ.c | 1+
5 files changed, 25 insertions(+), 21 deletions(-)

diff --git a/all.h b/all.h @@ -40,6 +40,7 @@ enum { }; struct Target { + char name[8]; int gpr0; /* first general purpose reg */ int ngpr; int fpr0; /* first floating point reg */ diff --git a/amd64/targ.c b/amd64/targ.c @@ -13,6 +13,7 @@ amd64_memargs(int op) } Target T_amd64_sysv = { + .name = "amd64", .gpr0 = RAX, .ngpr = NGPR, .fpr0 = XMM0, diff --git a/arm64/targ.c b/arm64/targ.c @@ -26,6 +26,7 @@ arm64_memargs(int op) } Target T_arm64 = { + .name = "arm64", .gpr0 = R0, .ngpr = NGPR, .fpr0 = V0, diff --git a/main.c b/main.c @@ -5,20 +5,6 @@ Target T; -extern Target T_amd64_sysv; -extern Target T_arm64; -extern Target T_rv64; - -static struct TMap { - char *name; - Target *T; -} tmap[] = { - { "amd64_sysv", &T_amd64_sysv }, - { "arm64", &T_arm64 }, - { "rv64", &T_rv64 }, - { 0, 0 } -}; - char debug['Z'+1] = { ['P'] = 0, /* parsing */ ['M'] = 0, /* memory optimization */ @@ -32,6 +18,16 @@ char debug['Z'+1] = { ['R'] = 0, /* reg. allocation */ }; +extern Target T_amd64_sysv; +extern Target T_arm64; +extern Target T_rv64; + +static Target *tlist[] = { + &T_amd64_sysv, + &T_arm64, + &T_rv64, + 0 +}; static FILE *outf; static int dbg; @@ -106,7 +102,7 @@ func(Fn *fn) int main(int ac, char *av[]) { - struct TMap *tm; + Target **t; FILE *inf, *hf; char *f, *sep; int c, asmmode; @@ -133,13 +129,17 @@ main(int ac, char *av[]) } break; case 't': - for (tm=tmap;; tm++) { - if (!tm->name) { + if (strcmp(optarg, "?") == 0) { + puts(T.name); + exit(0); + } + for (t=tlist;; t++) { + if (!*t) { fprintf(stderr, "unknown target '%s'\n", optarg); exit(1); } - if (strcmp(optarg, tm->name) == 0) { - T = *tm->T; + if (strcmp(optarg, (*t)->name) == 0) { + T = **t; break; } } @@ -162,8 +162,8 @@ main(int ac, char *av[]) fprintf(hf, "\t%-11s output to file\n", "-o file"); fprintf(hf, "\t%-11s generate for a target among:\n", "-t <target>"); fprintf(hf, "\t%-11s ", ""); - for (tm=tmap, sep=""; tm->name; tm++, sep=", ") - fprintf(hf, "%s%s", sep, tm->name); + for (t=tlist, sep=""; *t; t++, sep=", ") + fprintf(hf, "%s%s", sep, (*t)->name); fprintf(hf, "\n"); fprintf(hf, "\t%-11s generate gas (e) or osx (m) asm\n", "-G {e,m}"); fprintf(hf, "\t%-11s dump debug information\n", "-d <flags>"); diff --git a/rv64/targ.c b/rv64/targ.c @@ -33,6 +33,7 @@ rv64_memargs(int op) } Target T_rv64 = { + .name = "rv64", .gpr0 = T0, .ngpr = NGPR, .fpr0 = FT0,