diff options
author | Quentin Carbonneaux <quentin@c9x.me> | 2022-03-15 22:29:09 +0100 |
---|---|---|
committer | Quentin Carbonneaux <quentin@c9x.me> | 2022-03-15 22:30:34 +0100 |
commit | 2416d291417954a1fd7f4945a100f2c125d4d9a6 (patch) | |
tree | 24fcd3478d1f8c654747684aca3822b053dc022e /main.c | |
parent | da36b211ab9f0d00b0128d9daaf32eba5ab5e56e (diff) | |
download | roux-2416d291417954a1fd7f4945a100f2c125d4d9a6.tar.gz |
new -t? flag to print default target
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/main.c b/main.c index 74d057d..dc76a86 100644 --- 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>"); |