summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--all.h1
-rw-r--r--amd64/targ.c1
-rw-r--r--arm64/targ.c1
-rw-r--r--main.c42
-rw-r--r--rv64/targ.c1
5 files changed, 25 insertions, 21 deletions
diff --git a/all.h b/all.h
index b775748..3cfb60a 100644
--- 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
index e227574..d341339 100644
--- 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
index 99c4347..33b14f4 100644
--- 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
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>");
diff --git a/rv64/targ.c b/rv64/targ.c
index ead8fe2..d42d0a1 100644
--- 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,