scc

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

arch.c (1781B)


      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      *ushortype, *shortype,
     13      *longtype, *ulongtype,
     14      *ullongtype, *llongtype,
     15      *floattype, *doubletype, *ldoubletype,
     16      *ellipsistype, *va_list_type, *va_type;
     17 
     18 Symbol *one, *zero;
     19 char *architecture = "amd64-sysv";
     20 
     21 static Arch *arch;
     22 
     23 static Arch *
     24 getarch(void)
     25 {
     26 	static struct archdef {
     27 		char *arch;
     28 		Arch *(*fun)(void);
     29 	} *bp, defs[] = {
     30 		"amd64-sysv", amd64_sysv,
     31 		"arm64-sysv", arm64_sysv,
     32 		"i386-sysv", i386_sysv,
     33 		"z80-scc", z80_scc,
     34 		NULL, NULL,
     35 	};
     36 
     37 	for (bp = defs; bp->arch; ++bp) {
     38 		if (strcmp(bp->arch, architecture) == 0)
     39 			return (*bp->fun)();
     40 	}
     41 
     42 	return NULL;
     43 }
     44 
     45 int
     46 valid_va_list(Type *tp)
     47 {
     48 	return (*arch->valid_va_list)(tp);
     49 }
     50 
     51 void
     52 iarch(void)
     53 {
     54 	if ((arch = getarch()) == NULL) {
     55 		fprintf(stderr, "cc1: wrong architecture '%s'\n", architecture);
     56 		exit(EXIT_FAILURE);
     57 	}
     58 
     59 	voidtype = &arch->voidtype;
     60 	pvoidtype = &arch->pvoidtype;
     61 	booltype = &arch->booltype;
     62 	uchartype = &arch->uchartype;
     63 	chartype = &arch->chartype;
     64 	schartype = &arch->schartype;
     65 	uinttype = &arch->uinttype;
     66 	inttype = &arch->inttype;
     67 	sizettype = &arch->sizettype;
     68 	pdifftype = &arch->pdifftype;
     69 	ushortype = &arch->ushortype;
     70 	shortype = &arch->shortype;
     71 	longtype = &arch->longtype;
     72 	ulongtype = &arch->ulongtype;
     73 	ullongtype = &arch->ullongtype;
     74 	llongtype = &arch->llongtype;
     75 	floattype = &arch->floattype;
     76 	doubletype = &arch->doubletype;
     77 	ldoubletype = &arch->ldoubletype;
     78 	ellipsistype = &arch->ellipsistype;
     79 	va_list_type = &arch->va_list_type;
     80 	va_type = &arch->va_type;
     81 	zero = &arch->zero;
     82 	one = &arch->one;
     83 }