From 4545928179837c75ab1357b77e5723a4fdb60b98 Mon Sep 17 00:00:00 2001 From: lemon Date: Wed, 17 Dec 2025 20:32:10 +0100 Subject: nicer defaults and facilities for cross-compilation --- targ.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 5 deletions(-) (limited to 'targ.c') diff --git a/targ.c b/targ.c index 9821e39..c715ed7 100644 --- a/targ.c +++ b/targ.c @@ -3,32 +3,78 @@ extern const struct mctarg t_x86_64_sysv; static const struct targ { - const char *name; + struct { enum mcarch arch; uint oss, abis; }; struct { uchar longsize, vlongsize, ptrsize, valistsize; }; struct { uchar longalign, vlongalign, doublealign, ptralign; }; bool charsigned; uchar sizetype, ptrdifftype, wchartype; const struct mctarg *mctarg; - enum mcisa isa; } targs[] = { - { "x86_64-sysv", {8, 8, 8, 24}, {8, 8, 8, 8}, 1, TYULONG, TYLONG, TYINT, &t_x86_64_sysv, ISx86_64 }, - { "i686-sysv", {4, 8, 4, 8}, {4, 4, 4, 4}, 1, TYUINT, TYINT, TYINT } + { {ISx86_64, -1, 1<arch = ISx86_64; + } else return 0; + + if (matchstr(&str, "unknown-") || matchstr(&str, "pc-")) {} + + if (matchstr(&str, "linux-")) { + trg->os = OSlinux; + } else if (matchstr(&str, "linux$")) { + trg->os = OSlinux; + trg->abi = ABIgnu; + } else return 0; + + if (matchstr(&str, "gnu")) { + trg->abi = ABIgnu; + } else if (matchstr(&str, "musl")) { + trg->abi = ABImusl; + } else return 0; + + return 1; +} + +#include "hostconfig.h" + void targ_init(const char *starg) { const struct targ *t = &targs[0]; uchar *sizes = targ_primsizes, *align = targ_primalign; + if (!starg) { + target.arch = HOST_ARCH; + target.os = HOST_OS; + target.abi = HOST_ABI; + } else if (!parsetriple(&target, starg)) { + fatal(NULL, "unrecognized target: %s", starg); + } + sizes[TYBOOL] = sizes[TYCHAR] = sizes[TYSCHAR] = sizes[TYUCHAR] = 1; sizes[TYSHORT] = sizes[TYUSHORT] = 2; sizes[TYUINT] = sizes[TYINT] = 4; @@ -52,4 +98,5 @@ targ_init(const char *starg) targ_bigendian = 0; targ_64bit = t->ptrsize == 8; mctarg = t->mctarg; + targ_arch = ISx86_64; } -- cgit v1.2.3