scc

A fork of https://git.simple-cc.org/scc/ for Qute

git clone https://git.8pit.net/scc.git

 1#include <string.h>
 2#include <stdio.h>
 3#include <stdlib.h>
 4
 5#include <scc/scc.h>
 6#include "cc1.h"
 7
 8Type *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
19Symbol *one, *zero;
20char *architecture = "amd64-sysv";
21
22static Arch *arch;
23static Symbol zerodata = {.u.i = 0};
24static Symbol onedata = {.u.i = 1};
25
26static Arch *
27getarch(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
49int
50valid_va_list(Type *tp)
51{
52	return (*arch->valid_va_list)(tp);
53}
54
55void
56iarch(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}