scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

arch.c (1982B)


      1 #include <string.h>
      2 #include <stdio.h>
      3 #include <stdlib.h>
      4 
      5 #include <scc/scc.h>
      6 #include "cc1.h"
      7 
      8 Type *voidtype, *pvoidtype, *booltype,
      9      *uchartype, *chartype, *schartype,
     10      *uinttype, *inttype,
     11      *sizettype, *pdifftype,
     12      *ushorttype, *shorttype,
     13      *longtype, *ulongtype,
     14      *ullongtype, *llongtype,
     15      *floattype, *doubletype, *ldoubletype,
     16      *ellipsistype, *va_list_type, *va_type,
     17      *wchartype;
     18 
     19 Symbol *one, *zero;
     20 char *architecture = "amd64-sysv";
     21 
     22 static Arch *arch;
     23 static Symbol zerodata = {.u.i = 0};
     24 static Symbol onedata = {.u.i = 1};
     25 
     26 static Arch *
     27 getarch(void)
     28 {
     29 	static struct archdef {
     30 		char *arch;
     31 		Arch *(*fun)(void);
     32 	} *bp, defs[] = {
     33 		"amd64-sysv", amd64_sysv,
     34 		"arm64-sysv", arm64_sysv,
     35 		"riscv64-sysv", riscv64_sysv,
     36 		"i386-sysv", i386_sysv,
     37 		"z80-scc", z80_scc,
     38 		NULL, NULL,
     39 	};
     40 
     41 	for (bp = defs; bp->arch; ++bp) {
     42 		if (strcmp(bp->arch, architecture) == 0)
     43 			return (*bp->fun)();
     44 	}
     45 
     46 	return NULL;
     47 }
     48 
     49 int
     50 valid_va_list(Type *tp)
     51 {
     52 	return (*arch->valid_va_list)(tp);
     53 }
     54 
     55 void
     56 iarch(void)
     57 {
     58 	if ((arch = getarch()) == NULL) {
     59 		fprintf(stderr, "cc1: wrong architecture '%s'\n", architecture);
     60 		exit(EXIT_FAILURE);
     61 	}
     62 
     63 	voidtype = &arch->voidtype;
     64 	pvoidtype = &arch->pvoidtype;
     65 	booltype = &arch->booltype;
     66 	uchartype = &arch->uchartype;
     67 	chartype = &arch->chartype;
     68 	schartype = &arch->schartype;
     69 	uinttype = &arch->uinttype;
     70 	inttype = &arch->inttype;
     71 	sizettype = &arch->sizettype;
     72 	pdifftype = &arch->pdifftype;
     73 	ushorttype = &arch->ushorttype;
     74 	shorttype = &arch->shorttype;
     75 	longtype = &arch->longtype;
     76 	ulongtype = &arch->ulongtype;
     77 	ullongtype = &arch->ullongtype;
     78 	llongtype = &arch->llongtype;
     79 	floattype = &arch->floattype;
     80 	doubletype = &arch->doubletype;
     81 	ldoubletype = &arch->ldoubletype;
     82 	ellipsistype = &arch->ellipsistype;
     83 	va_list_type = &arch->va_list_type;
     84 	va_type = &arch->va_type;
     85 	wchartype = &arch->wchartype;
     86 	zero = &zerodata;
     87 	one = &onedata;
     88 
     89 	zero->type = inttype;
     90 	one->type = inttype;
     91 }