From 2afeff7d9e6a0a735f80bae9e932df376bc42590 Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Tue, 25 Jun 2019 11:34:29 -0700 Subject: Pass target to cc-qbe --- Makefile | 2 ++ cc.h | 10 ++++++++++ configure | 9 ++------- driver.c | 20 +++++++++++++++++++- main.c | 7 ++++++- targ.c | 34 ++++++++++++++++++++++++++++++++++ 6 files changed, 73 insertions(+), 9 deletions(-) create mode 100644 targ.c diff --git a/Makefile b/Makefile index 19d2906..030a012 100644 --- a/Makefile +++ b/Makefile @@ -31,6 +31,7 @@ SRC=\ scope.c\ siphash.c\ stmt.c\ + targ.c\ token.c\ tree.c\ type.c\ @@ -54,6 +55,7 @@ $(objdir)/scan.o : scan.c util.h cc.h $(stagedeps) ; $(CC) $(CFLAGS) $(objdir)/scope.o : scope.c util.h cc.h $(stagedeps) ; $(CC) $(CFLAGS) -c -o $@ scope.c $(objdir)/siphash.o : siphash.c $(stagedeps) ; $(CC) $(CFLAGS) -c -o $@ siphash.c $(objdir)/stmt.o : stmt.c util.h cc.h $(stagedeps) ; $(CC) $(CFLAGS) -c -o $@ stmt.c +$(objdir)/targ.o : targ.c util.h cc.h $(stagedeps) ; $(CC) $(CFLAGS) -c -o $@ targ.c $(objdir)/token.o : token.c util.h cc.h $(stagedeps) ; $(CC) $(CFLAGS) -c -o $@ token.c $(objdir)/tree.o : tree.c util.h $(stagedeps) ; $(CC) $(CFLAGS) -c -o $@ tree.c $(objdir)/type.o : type.c util.h cc.h $(stagedeps) ; $(CC) $(CFLAGS) -c -o $@ type.c diff --git a/cc.h b/cc.h index 1f021fa..8978d89 100644 --- a/cc.h +++ b/cc.h @@ -406,6 +406,16 @@ extern struct type typellong, typeullong; extern struct type typefloat, typedouble, typeldouble; extern struct type typevalist, typevalistptr; +/* targ */ + +struct target { + const char *name; +}; + +extern struct target *targ; + +void targinit(const char *); + /* decl */ struct decl *mkdecl(enum declkind, struct type *, enum typequal, enum linkage); diff --git a/configure b/configure index c30d4c3..39f0c0a 100755 --- a/configure +++ b/configure @@ -41,12 +41,6 @@ if [ "$host" != "$target" ] ; then toolprefix=$target- fi -case "$target" in -x86_64*|amd64*) qbetarget=amd64_sysv ;; -aarch64*) qbetarget=arm64 ;; -*) fail "unsupported architecture '${target%%-*}'" -esac - startfiles=0 endfiles=0 defines= @@ -130,6 +124,7 @@ test "$DEFAULT_DYNAMIC_LINKER" && linkflags=$linkflags' "--dynamic-linker", "'$D printf "creating config.h... " cat >config.h < 1) usage(); if (output && !freopen(output, "w", stdout)) diff --git a/targ.c b/targ.c new file mode 100644 index 0000000..a3fd2f0 --- /dev/null +++ b/targ.c @@ -0,0 +1,34 @@ +#include +#include +#include "util.h" +#include "cc.h" + +struct target *targ; + +static struct target alltargs[] = { + { + .name = "x86_64", + }, + { + .name = "aarch64", + }, +}; + +void +targinit(const char *name) +{ + size_t i; + + if (!name) { + /* TODO: provide a way to set this default */ + targ = &alltargs[0]; + return; + } + for (i = 0; i < LEN(alltargs); ++i) { + if (strcmp(alltargs[i].name, name) == 0) { + targ = &alltargs[i]; + return; + } + } + fatal("unknown target '%s'", name); +} -- cgit v1.2.3