scc

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

commit edabe2f4ab58eccbeaef50e9e62b09287ec6daf8
parent 0589cb355a5c40f61662f4c4925c46577b23db4a
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sun, 28 Jun 2020 19:34:25 +0200

cc1: Unify all the cc1 programs

The difference between the different archotectures is very small
and it is not needed individual programs for every architecture.

Diffstat:
Msrc/cmd/cc/cc1/Makefile | 49+++++++++++++++++++++++--------------------------
Asrc/cmd/cc/cc1/amd64-sysv.c | 206+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/cmd/cc/cc1/arch.c | 83+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/cmd/cc/cc1/arm64-sysv.c | 206+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/cmd/cc/cc1/cc1.h | 38++++++++++++++++++++++++++++++++++++++
Msrc/cmd/cc/cc1/deps.mk | 18++++++++++--------
Asrc/cmd/cc/cc1/i386-sysv.c | 211+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/cmd/cc/cc1/main.c | 3+++
Dsrc/cmd/cc/cc1/target/amd64-sysv/arch.c | 218-------------------------------------------------------------------------------
Dsrc/cmd/cc/cc1/target/amd64-sysv/arch.mk | 4----
Dsrc/cmd/cc/cc1/target/arm64-sysv/arch.c | 218-------------------------------------------------------------------------------
Dsrc/cmd/cc/cc1/target/arm64-sysv/arch.mk | 4----
Dsrc/cmd/cc/cc1/target/i386-sysv/arch.c | 219-------------------------------------------------------------------------------
Dsrc/cmd/cc/cc1/target/i386-sysv/arch.mk | 4----
Dsrc/cmd/cc/cc1/target/z80-scc/arch.c | 217-------------------------------------------------------------------------------
Dsrc/cmd/cc/cc1/target/z80-scc/arch.mk | 4----
Asrc/cmd/cc/cc1/z80-scc.c | 212+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
17 files changed, 992 insertions(+), 922 deletions(-)

diff --git a/src/cmd/cc/cc1/Makefile b/src/cmd/cc/cc1/Makefile @@ -3,36 +3,33 @@ PROJECTDIR = ../../../.. include $(PROJECTDIR)/scripts/rules.mk -OBJS = types.o \ - decl.o \ - lex.o \ - error.o \ - symbol.o \ - main.o \ - expr.o \ - code.o \ - stmt.o \ - cpp.o \ - fold.o \ - init.o \ - builtin.o \ - -TARGET = $(LIBEXEC)/cc1-amd64-sysv \ - $(LIBEXEC)/cc1-arm64-sysv \ - $(LIBEXEC)/cc1-i386-sysv \ - $(LIBEXEC)/cc1-z80-scc \ +OBJS =\ + types.o \ + decl.o \ + lex.o \ + error.o \ + symbol.o \ + main.o \ + expr.o \ + code.o \ + stmt.o \ + cpp.o \ + fold.o \ + init.o \ + builtin.o \ + arch.o\ + amd64-sysv.o\ + arm64-sysv.o \ + i386-sysv.o \ + z80-scc.o\ + +TARGET = $(LIBEXEC)/cc1 all: $(TARGET) -$(TARGET): $(LIBDIR)/libscc.a +$(TARGET): $(LIBDIR)/libscc.a $(OBJS) + $(CC) $(SCC_LDFLAGS) $(OBJS) -lscc -o $@ dep: inc-dep -clean: - rm -f target/*/*.o - -include target/amd64-sysv/arch.mk -include target/arm64-sysv/arch.mk -include target/i386-sysv/arch.mk -include target/z80-scc/arch.mk include deps.mk diff --git a/src/cmd/cc/cc1/amd64-sysv.c b/src/cmd/cc/cc1/amd64-sysv.c @@ -0,0 +1,206 @@ +#include <scc/scc.h> +#include "cc1.h" + +#define RANK_BOOL 0 +#define RANK_SCHAR 1 +#define RANK_UCHAR 1 +#define RANK_CHAR 1 +#define RANK_SHORT 2 +#define RANK_USHORT 2 +#define RANK_INT 3 +#define RANK_UINT 3 +#define RANK_LONG 4 +#define RANK_ULONG 4 +#define RANK_LLONG 5 +#define RANK_ULLONG 5 +#define RANK_FLOAT 6 +#define RANK_DOUBLE 7 +#define RANK_LDOUBLE 8 + +static int +local_valid_va_list(Type *tp) +{ + return tp->op == PTR && eqtype(tp->type, va_type, 1); +} + +Arch * +amd64_sysv(void) +{ + static Arch arch = { + .voidtype = { + .op = VOID, + .letter = L_VOID, + }, + .pvoidtype = { + .op = PTR, + .letter = L_POINTER, + .prop = TDEFINED, + .size = 8, + .align = 8, + }, + .booltype = { + .op = INT, + .letter = L_BOOL, + .prop = TDEFINED | TINTEGER | TARITH, + .size = 1, + .align = 1, + .n.rank = RANK_BOOL, + }, + .schartype = { + .op = INT, + .letter = L_INT8, + .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, + .size = 1, + .align = 1, + .n.rank = RANK_SCHAR, + + }, + .uchartype = { + .op = INT, + .letter = L_UINT8, + .prop = TDEFINED | TINTEGER | TARITH, + .size = 1, + .align = 1, + .n.rank = RANK_UCHAR, + }, + .chartype = { + .op = INT, + .letter = L_INT8, + .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, + .size = 1, + .align = 1, + .n.rank = RANK_CHAR, + }, + .ushortype = { + .op = INT, + .letter = L_UINT16, + .prop = TDEFINED | TINTEGER | TARITH, + .size = 2, + .align = 2, + .n.rank = RANK_USHORT, + + }, + .shortype = { + .op = INT, + .letter = L_INT16, + .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, + .size = 2, + .align = 2, + .n.rank = RANK_SHORT, + }, + .uinttype = (Type) { + .op = INT, + .letter = L_UINT32, + .prop = TDEFINED | TINTEGER | TARITH, + .size = 4, + .align = 4, + .n.rank = RANK_UINT, + }, + .inttype = (Type) { + .op = INT, + .letter = L_INT32, + .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, + .size = 4, + .align = 4, + .n.rank = RANK_INT, + }, + .longtype = { + .op = INT, + .letter = L_INT64, + .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, + .size = 8, + .align = 8, + .n.rank = RANK_LONG, + }, + .ulongtype = { + .op = INT, + .letter = L_UINT64, + .prop = TDEFINED | TINTEGER | TARITH, + .size = 8, + .align = 8, + .n.rank = RANK_ULONG, + }, + .ullongtype = { + .op = INT, + .letter = L_UINT64, + .prop = TDEFINED | TINTEGER | TARITH, + .size = 8, + .align = 8, + .n.rank = RANK_ULLONG, + }, + .llongtype = { + .op = INT, + .letter = L_INT64, + .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, + .size = 8, + .align = 8, + .n.rank = RANK_LLONG, + }, + .floattype = { + .op = FLOAT, + .letter = L_FLOAT, + .prop = TDEFINED | TARITH, + .size = 4, + .align = 4, + .n.rank = RANK_FLOAT, + }, + .doubletype = { + .op = FLOAT, + .letter = L_DOUBLE, + .prop = TDEFINED | TARITH, + .size = 8, + .align = 8, + .n.rank = RANK_DOUBLE, + }, + .ldoubletype = { + .op = FLOAT, + .letter = L_LDOUBLE, + .prop = TDEFINED | TARITH, + .size = 16, + .align = 16, + .n.rank = RANK_LDOUBLE, + }, + .sizettype = { + .op = INT, + .letter = L_UINT64, + .prop = TDEFINED | TINTEGER | TARITH, + .size = 8, + .align = 8, + .n.rank = RANK_UINT, + }, + .pdifftype = { + .op = INT, + .letter = L_INT64, + .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, + .size = 8, + .align = 8, + .n.rank = RANK_LONG, + }, + .ellipsistype = { + .op = ELLIPSIS, + .letter = L_ELLIPSIS, + .prop = TDEFINED, + }, + .va_type = { + .op = STRUCT, + .letter = L_VA_ARG, + .prop = TDEFINED, + .size = 24, + .align = 8, + }, + .zero = { + .u.i = 0, + }, + .one = { + .u.i = 1, + }, + }; + + arch.va_list_type = *mktype(va_type, ARY, 1, NULL); + arch.pvoidtype.type = &arch.chartype; + arch.valid_va_list = local_valid_va_list; + arch.zero.type = inttype; + arch.one.type = inttype; + + return &arch; +} diff --git a/src/cmd/cc/cc1/arch.c b/src/cmd/cc/cc1/arch.c @@ -0,0 +1,83 @@ +#include <string.h> +#include <stdio.h> +#include <stdlib.h> + +#include <scc/scc.h> +#include "cc1.h" + +Type *voidtype, *pvoidtype, *booltype, + *uchartype, *chartype, *schartype, + *uinttype, *inttype, + *sizettype, *pdifftype, + *ushortype, *shortype, + *longtype, *ulongtype, + *ullongtype, *llongtype, + *floattype, *doubletype, *ldoubletype, + *ellipsistype, *va_list_type, *va_type; + +Symbol *one, *zero; +char *architecture = "amd64-sysv"; + +static Arch *arch; + +static Arch * +getarch(void) +{ + static struct archdef { + char *arch; + Arch *(*fun)(void); + } *bp, defs[] = { + "amd64-sysv", amd64_sysv, + "arm64-sysv", arm64_sysv, + "i386-sysv", i386_sysv, + "z80-scc", z80_scc, + NULL, NULL, + }; + + for (bp = defs; bp->arch; ++bp) { + if (strcmp(bp->arch, architecture) == 0) + return (*bp->fun)(); + } + + return NULL; +} + +int +valid_va_list(Type *tp) +{ + return (*arch->valid_va_list)(tp); +} + +void +iarch(void) +{ + if ((arch = getarch()) == NULL) { + fprintf(stderr, "cc1: wrong architecture '%s'\n", architecture); + exit(EXIT_FAILURE); + } + + voidtype = &arch->voidtype; + pvoidtype = &arch->pvoidtype; + booltype = &arch->booltype; + uchartype = &arch->uchartype; + chartype = &arch->chartype; + schartype = &arch->schartype; + uinttype = &arch->uinttype; + inttype = &arch->inttype; + sizettype = &arch->sizettype; + pdifftype = &arch->pdifftype; + ushortype = &arch->ushortype; + shortype = &arch->shortype; + longtype = &arch->longtype; + ulongtype = &arch->ulongtype; + ullongtype = &arch->ullongtype; + llongtype = &arch->llongtype; + floattype = &arch->floattype; + doubletype = &arch->doubletype; + ldoubletype = &arch->ldoubletype; + ellipsistype = &arch->ellipsistype; + va_list_type = &arch->va_list_type; + va_type = &arch->va_type; + zero = &arch->zero; + one = &arch->one; +} diff --git a/src/cmd/cc/cc1/arm64-sysv.c b/src/cmd/cc/cc1/arm64-sysv.c @@ -0,0 +1,206 @@ +#include <scc/scc.h> +#include "cc1.h" + +#define RANK_BOOL 0 +#define RANK_SCHAR 1 +#define RANK_UCHAR 1 +#define RANK_CHAR 1 +#define RANK_SHORT 2 +#define RANK_USHORT 2 +#define RANK_INT 3 +#define RANK_UINT 3 +#define RANK_LONG 4 +#define RANK_ULONG 4 +#define RANK_LLONG 5 +#define RANK_ULLONG 5 +#define RANK_FLOAT 6 +#define RANK_DOUBLE 7 +#define RANK_LDOUBLE 8 + +static int +local_valid_va_list(Type *tp) +{ + return tp->op == PTR && eqtype(tp->type, va_type, 1); +} + +Arch * +arm64_sysv(void) +{ + static Arch arch = { + .voidtype = { + .op = VOID, + .letter = L_VOID, + }, + .pvoidtype = { + .op = PTR, + .letter = L_POINTER, + .prop = TDEFINED, + .size = 8, + .align = 8, + }, + .booltype = { + .op = INT, + .letter = L_BOOL, + .prop = TDEFINED | TINTEGER | TARITH, + .size = 1, + .align = 1, + .n.rank = RANK_BOOL, + }, + .schartype = { + .op = INT, + .letter = L_INT8, + .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, + .size = 1, + .align = 1, + .n.rank = RANK_SCHAR, + + }, + .uchartype = { + .op = INT, + .letter = L_UINT8, + .prop = TDEFINED | TINTEGER | TARITH, + .size = 1, + .align = 1, + .n.rank = RANK_UCHAR, + }, + .chartype = { + .op = INT, + .letter = L_INT8, + .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, + .size = 1, + .align = 1, + .n.rank = RANK_CHAR, + }, + .ushortype = { + .op = INT, + .letter = L_UINT16, + .prop = TDEFINED | TINTEGER | TARITH, + .size = 2, + .align = 2, + .n.rank = RANK_USHORT, + + }, + .shortype = { + .op = INT, + .letter = L_INT16, + .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, + .size = 2, + .align = 2, + .n.rank = RANK_SHORT, + }, + .uinttype = (Type) { + .op = INT, + .letter = L_UINT32, + .prop = TDEFINED | TINTEGER | TARITH, + .size = 4, + .align = 4, + .n.rank = RANK_UINT, + }, + .inttype = (Type) { + .op = INT, + .letter = L_INT32, + .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, + .size = 4, + .align = 4, + .n.rank = RANK_INT, + }, + .longtype = { + .op = INT, + .letter = L_INT64, + .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, + .size = 8, + .align = 8, + .n.rank = RANK_LONG, + }, + .ulongtype = { + .op = INT, + .letter = L_UINT64, + .prop = TDEFINED | TINTEGER | TARITH, + .size = 8, + .align = 8, + .n.rank = RANK_ULONG, + }, + .ullongtype = { + .op = INT, + .letter = L_UINT64, + .prop = TDEFINED | TINTEGER | TARITH, + .size = 8, + .align = 8, + .n.rank = RANK_ULLONG, + }, + .llongtype = { + .op = INT, + .letter = L_INT64, + .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, + .size = 8, + .align = 8, + .n.rank = RANK_LLONG, + }, + .floattype = { + .op = FLOAT, + .letter = L_FLOAT, + .prop = TDEFINED | TARITH, + .size = 4, + .align = 4, + .n.rank = RANK_FLOAT, + }, + .doubletype = { + .op = FLOAT, + .letter = L_DOUBLE, + .prop = TDEFINED | TARITH, + .size = 8, + .align = 8, + .n.rank = RANK_DOUBLE, + }, + .ldoubletype = { + .op = FLOAT, + .letter = L_LDOUBLE, + .prop = TDEFINED | TARITH, + .size = 16, + .align = 16, + .n.rank = RANK_LDOUBLE, + }, + .sizettype = { + .op = INT, + .letter = L_UINT64, + .prop = TDEFINED | TINTEGER | TARITH, + .size = 8, + .align = 8, + .n.rank = RANK_UINT, + }, + .pdifftype = { + .op = INT, + .letter = L_INT64, + .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, + .size = 8, + .align = 8, + .n.rank = RANK_LONG, + }, + .ellipsistype = { + .op = ELLIPSIS, + .letter = L_ELLIPSIS, + .prop = TDEFINED, + }, + .va_type = { + .op = STRUCT, + .letter = L_VA_ARG, + .prop = TDEFINED, + .size = 24, + .align = 8, + }, + .zero = { + .u.i = 0, + }, + .one = { + .u.i = 1, + }, + }; + + arch.va_list_type = *mktype(va_type, ARY, 1, NULL); + arch.pvoidtype.type = &arch.chartype; + arch.valid_va_list = local_valid_va_list; + arch.zero.type = inttype; + arch.one.type = inttype; + + return &arch; +} diff --git a/src/cmd/cc/cc1/cc1.h b/src/cmd/cc/cc1/cc1.h @@ -276,6 +276,7 @@ typedef struct symbol Symbol; typedef struct swtch Switch; typedef struct node Node; typedef struct input Input; +typedef struct arch Arch; struct limits { union { @@ -356,6 +357,36 @@ struct swtch { char hasdef; }; +struct arch { + Symbol zero; + Symbol one; + + Type voidtype; + Type pvoidtype; + Type booltype; + Type schartype; + Type uchartype; + Type chartype; + Type ushortype; + Type shortype; + Type uinttype; + Type inttype; + Type longtype; + Type ulongtype; + Type ullongtype; + Type llongtype; + Type floattype; + Type doubletype; + Type ldoubletype; + Type sizettype; + Type pdifftype; + Type ellipsistype; + Type va_type; + Type va_list_type; + + int (*valid_va_list)(Type *tp); +}; + struct yystype { Symbol *sym; unsigned char token; @@ -467,6 +498,12 @@ extern void ibuilts(void); extern void iarch(void); extern int valid_va_list(Type *tp); +/* architectures */ +extern Arch *amd64_sysv(void); +extern Arch *z80_scc(void); +extern Arch *arm64_sysv(void); +extern Arch *i386_sysv(void); + /* * Definition of global variables */ @@ -484,6 +521,7 @@ extern Symbol *curfun, *zero, *one; extern char *infile; extern unsigned lineno; extern char filenam[]; +extern char *architecture; extern Type *voidtype, *pvoidtype, *booltype, *uchartype, *chartype, *schartype, diff --git a/src/cmd/cc/cc1/deps.mk b/src/cmd/cc/cc1/deps.mk @@ -1,4 +1,10 @@ #deps +./amd64-sysv.o: $(INCDIR)/scc/scc/scc.h +./amd64-sysv.o: ./cc1.h +./arch.o: $(INCDIR)/scc/scc/scc.h +./arch.o: ./cc1.h +./arm64-sysv.o: $(INCDIR)/scc/scc/scc.h +./arm64-sysv.o: ./cc1.h ./builtin.o: $(INCDIR)/scc/scc/scc.h ./builtin.o: ./cc1.h ./code.o: $(INCDIR)/scc/scc/scc.h @@ -16,6 +22,8 @@ ./expr.o: ./cc1.h ./fold.o: $(INCDIR)/scc/scc/scc.h ./fold.o: ./cc1.h +./i386-sysv.o: $(INCDIR)/scc/scc/scc.h +./i386-sysv.o: ./cc1.h ./init.o: $(INCDIR)/scc/scc/cstd.h ./init.o: $(INCDIR)/scc/scc/scc.h ./init.o: ./cc1.h @@ -31,14 +39,8 @@ ./symbol.o: $(INCDIR)/scc/scc/cstd.h ./symbol.o: $(INCDIR)/scc/scc/scc.h ./symbol.o: ./cc1.h -./target/amd64-sysv/arch.o: $(INCDIR)/scc/scc/scc.h -./target/amd64-sysv/arch.o: ./target/amd64-sysv/../../cc1.h -./target/arm64-sysv/arch.o: $(INCDIR)/scc/scc/scc.h -./target/arm64-sysv/arch.o: ./target/arm64-sysv/../../cc1.h -./target/i386-sysv/arch.o: $(INCDIR)/scc/scc/scc.h -./target/i386-sysv/arch.o: ./target/i386-sysv/../../cc1.h -./target/z80-scc/arch.o: $(INCDIR)/scc/scc/scc.h -./target/z80-scc/arch.o: ./target/z80-scc/../../cc1.h ./types.o: $(INCDIR)/scc/scc/cstd.h ./types.o: $(INCDIR)/scc/scc/scc.h ./types.o: ./cc1.h +./z80-scc.o: $(INCDIR)/scc/scc/scc.h +./z80-scc.o: ./cc1.h diff --git a/src/cmd/cc/cc1/i386-sysv.c b/src/cmd/cc/cc1/i386-sysv.c @@ -0,0 +1,211 @@ +#include <scc/scc.h> +#include "cc1.h" + +#define RANK_BOOL 0 +#define RANK_SCHAR 1 +#define RANK_UCHAR 1 +#define RANK_CHAR 1 +#define RANK_SHORT 2 +#define RANK_USHORT 2 +#define RANK_INT 3 +#define RANK_UINT 3 +#define RANK_LONG 4 +#define RANK_ULONG 4 +#define RANK_LLONG 5 +#define RANK_ULLONG 5 +#define RANK_FLOAT 6 +#define RANK_DOUBLE 7 +#define RANK_LDOUBLE 8 + +static int +local_valid_va_list(Type *tp) +{ + return eqtype(tp, va_list_type, 1); +} + +Arch * +i386_sysv(void) +{ + static Arch arch = { + .voidtype = { + .op = VOID, + .letter = L_VOID, + }, + .pvoidtype = { + .op = PTR, + .letter = L_POINTER, + .prop = TDEFINED, + .size = 8, + .align = 8, + }, + .booltype = { + .op = INT, + .letter = L_BOOL, + .prop = TDEFINED | TINTEGER | TARITH, + .size = 1, + .align = 1, + .n.rank = RANK_BOOL, + }, + .schartype = { + .op = INT, + .letter = L_INT8, + .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, + .size = 1, + .align = 1, + .n.rank = RANK_SCHAR, + + }, + .uchartype = { + .op = INT, + .letter = L_UINT8, + .prop = TDEFINED | TINTEGER | TARITH, + .size = 1, + .align = 1, + .n.rank = RANK_UCHAR, + }, + .chartype = { + .op = INT, + .letter = L_INT8, + .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, + .size = 1, + .align = 1, + .n.rank = RANK_CHAR, + }, + .ushortype = { + .op = INT, + .letter = L_UINT16, + .prop = TDEFINED | TINTEGER | TARITH, + .size = 2, + .align = 2, + .n.rank = RANK_USHORT, + + }, + .shortype = { + .op = INT, + .letter = L_INT16, + .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, + .size = 2, + .align = 2, + .n.rank = RANK_SHORT, + }, + .uinttype = (Type) { + .op = INT, + .letter = L_UINT32, + .prop = TDEFINED | TINTEGER | TARITH, + .size = 4, + .align = 4, + .n.rank = RANK_UINT, + }, + .inttype = (Type) { + .op = INT, + .letter = L_INT32, + .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, + .size = 4, + .align = 4, + .n.rank = RANK_INT, + }, + .longtype = { + .op = INT, + .letter = L_INT32, + .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, + .size = 4, + .align = 4, + .n.rank = RANK_LONG, + }, + .ulongtype = { + .op = INT, + .letter = L_UINT64, + .prop = TDEFINED | TINTEGER | TARITH, + .size = 8, + .align = 4, + .n.rank = RANK_ULLONG, + }, + .ullongtype = { + .op = INT, + .letter = L_UINT64, + .prop = TDEFINED | TINTEGER | TARITH, + .size = 8, + .align = 8, + .n.rank = RANK_ULLONG, + }, + .llongtype = { + .op = INT, + .letter = L_INT64, + .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, + .size = 8, + .align = 8, + .n.rank = RANK_LLONG, + }, + .floattype = { + .op = FLOAT, + .letter = L_FLOAT, + .prop = TDEFINED | TARITH, + .size = 4, + .align = 4, + .n.rank = RANK_FLOAT, + }, + .doubletype = { + .op = FLOAT, + .letter = L_DOUBLE, + .prop = TDEFINED | TARITH, + .size = 8, + .align = 4, + .n.rank = RANK_DOUBLE, + }, + .ldoubletype = { + .op = FLOAT, + .letter = L_LDOUBLE, + .prop = TDEFINED | TARITH, + .size = 12, + .align = 4, + .n.rank = RANK_LDOUBLE, + }, + .sizettype = { + .op = INT, + .letter = L_UINT32, + .prop = TDEFINED | TINTEGER | TARITH, + .size = 4, + .align = 4, + .n.rank = RANK_UINT, + }, + .pdifftype = { + .op = INT, + .letter = L_INT32, + .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, + .size = 4, + .align = 4, + .n.rank = RANK_INT, + }, + .ellipsistype = { + .op = ELLIPSIS, + .letter = L_ELLIPSIS, + .prop = TDEFINED, + }, + .zero = { + .u.i = 0, + }, + .one = { + .u.i = 1, + }, + .va_type = { + .op = PTR, + .letter = L_POINTER, + .prop = TDEFINED, + .size = 4, + .align = 4, + }, + .va_list_type = { + .op = PTR, + .letter = L_POINTER, + .prop = TDEFINED, + .size = 4, + .align = 4, + }, + }; + + arch.valid_va_list = local_valid_va_list; + arch.pvoidtype.type = &arch.chartype; + arch.va_list_type.type = &arch.longtype; + + return &arch; +} diff --git a/src/cmd/cc/cc1/main.c b/src/cmd/cc/cc1/main.c @@ -51,6 +51,9 @@ main(int argc, char *argv[]) ibuilts(); ARGBEGIN { + case 'a': + architecture = EARGF(usage()); + break; case 'D': defmacro(EARGF(usage())); break; diff --git a/src/cmd/cc/cc1/target/amd64-sysv/arch.c b/src/cmd/cc/cc1/target/amd64-sysv/arch.c @@ -1,218 +0,0 @@ -#include <scc/scc.h> -#include "../../cc1.h" - -#define RANK_BOOL 0 -#define RANK_SCHAR 1 -#define RANK_UCHAR 1 -#define RANK_CHAR 1 -#define RANK_SHORT 2 -#define RANK_USHORT 2 -#define RANK_INT 3 -#define RANK_UINT 3 -#define RANK_LONG 4 -#define RANK_ULONG 4 -#define RANK_LLONG 5 -#define RANK_ULLONG 5 -#define RANK_FLOAT 6 -#define RANK_DOUBLE 7 -#define RANK_LDOUBLE 8 - -/* - * Initializaion of type pointers were done with - * a C99 initilizator '... = &(Type) {...', but - * c compiler in Plan9 gives error with this - * syntax, so I have switched it to this ugly form - * I hope I will change it again in the future - */ - -static Type types[] = { - { /* 0 = voidtype */ - .op = VOID, - .letter = L_VOID, - }, - { /* 1 = pvoidtype */ - .op = PTR, - .letter = L_POINTER, - .prop = TDEFINED, - .type = &types[5], /* chartype */ - .size = 8, - .align = 8, - }, - { /* 2 = booltype */ - .op = INT, - .letter = L_BOOL, - .prop = TDEFINED | TINTEGER | TARITH, - .size = 1, - .align = 1, - .n.rank = RANK_BOOL, - }, - { /* 3 = schartype */ - .op = INT, - .letter = L_INT8, - .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, - .size = 1, - .align = 1, - .n.rank = RANK_SCHAR, - }, - { /* 4 = uchartype */ - .op = INT, - .letter = L_UINT8, - .prop = TDEFINED | TINTEGER | TARITH, - .size = 1, - .align = 1, - .n.rank = RANK_UCHAR, - }, - { /* 5 = chartype */ - .op = INT, - .letter = L_INT8, - .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, - .size = 1, - .align = 1, - .n.rank = RANK_CHAR, - }, - { /* 6 = ushortype */ - .op = INT, - .letter = L_UINT16, - .prop = TDEFINED | TINTEGER | TARITH, - .size = 2, - .align = 2, - .n.rank = RANK_USHORT, - }, - { /* 7 = shortype */ - .op = INT, - .letter = L_INT16, - .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, - .size = 2, - .align = 2, - .n.rank = RANK_SHORT, - }, - { /* 8 = uinttype */ - .op = INT, - .letter = L_UINT32, - .prop = TDEFINED | TINTEGER | TARITH, - .size = 4, - .align = 4, - .n.rank = RANK_UINT, - }, - { /* 9 = inttype */ - .op = INT, - .letter = L_INT32, - .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, - .size = 4, - .align = 4, - .n.rank = RANK_INT, - }, - { /* 10 = longtype */ - .op = INT, - .letter = L_INT64, - .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, - .size = 8, - .align = 8, - .n.rank = RANK_LONG, - }, - { /* 11 = ulongtype */ - .op = INT, - .letter = L_UINT64, - .prop = TDEFINED | TINTEGER | TARITH, - .size = 8, - .align = 8, - .n.rank = RANK_ULONG, - }, - { /* 12 = ullongtype */ - .op = INT, - .letter = L_UINT64, - .prop = TDEFINED | TINTEGER | TARITH, - .size = 8, - .align = 8, - .n.rank = RANK_ULLONG, - }, - { /* 13 = llongtype */ - .op = INT, - .letter = L_INT64, - .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, - .size = 8, - .align = 8, - .n.rank = RANK_LLONG, - }, - { /* 14 = floattype */ - .op = FLOAT, - .letter = L_FLOAT, - .prop = TDEFINED | TARITH, - .size = 4, - .align = 4, - .n.rank = RANK_FLOAT, - }, - { /* 15 = doubletype */ - .op = FLOAT, - .letter = L_DOUBLE, - .prop = TDEFINED | TARITH, - .size = 8, - .align = 8, - .n.rank = RANK_DOUBLE, - }, - { /* 16 = ldoubletype */ - .op = FLOAT, - .letter = L_LDOUBLE, - .prop = TDEFINED | TARITH, - .size = 16, - .align = 16, - .n.rank = RANK_LDOUBLE, - }, - { /* 17 = sizettype */ - .op = INT, - .letter = L_UINT64, - .prop = TDEFINED | TINTEGER | TARITH, - .size = 8, - .align = 8, - .n.rank = RANK_UINT, - }, - { /* 18 = ellipsis */ - .op = ELLIPSIS, - .letter = L_ELLIPSIS, - .prop = TDEFINED, - }, - { /* 19 = pdifftype */ - .op = INT, - .letter = L_INT64, - .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, - .size = 8, - .align = 8, - .n.rank = RANK_LONG, - }, - { /* 20 = va_type */ - .op = STRUCT, - .letter = L_VA_ARG, - .prop = TDEFINED, - .size = 24, - .align = 8, - }, -}; - -Type *voidtype = &types[0], *pvoidtype = &types[1], - *booltype = &types[2], *schartype = &types[3], - *uchartype = &types[4], *chartype = &types[5], - *ushortype = &types[6], *shortype = &types[7], - *uinttype = &types[8], *inttype = &types[9], - *longtype = &types[10], *ulongtype = &types[11], - *ullongtype = &types[12], *llongtype = &types[13], - *floattype = &types[14], *doubletype = &types[15], - *ldoubletype = &types[16], - *sizettype = &types[17], *pdifftype = &types[19], - *ellipsistype = &types[18], *va_type = &types[20], - *va_list_type; - -static Symbol dummy0 = {.u.i = 0, .type = &types[9]}, - dummy1 = {.u.i = 1, .type = &types[9]}; -Symbol *zero = &dummy0, *one = &dummy1; - -void -iarch(void) -{ - va_list_type = mktype(va_type, ARY, 1, NULL); -} - -int -valid_va_list(Type *tp) -{ - return tp->op == PTR && eqtype(tp->type, va_type, 1); -} diff --git a/src/cmd/cc/cc1/target/amd64-sysv/arch.mk b/src/cmd/cc/cc1/target/amd64-sysv/arch.mk @@ -1,4 +0,0 @@ -OBJ-amd64-sysv= $(OBJS) target/amd64-sysv/arch.o - -$(LIBEXEC)/cc1-amd64-sysv: $(OBJ-amd64-sysv) - $(CC) $(SCC_LDFLAGS) $(OBJ-amd64-sysv) -lscc -o $@ diff --git a/src/cmd/cc/cc1/target/arm64-sysv/arch.c b/src/cmd/cc/cc1/target/arm64-sysv/arch.c @@ -1,218 +0,0 @@ -#include <scc/scc.h> -#include "../../cc1.h" - -#define RANK_BOOL 0 -#define RANK_SCHAR 1 -#define RANK_UCHAR 1 -#define RANK_CHAR 1 -#define RANK_SHORT 2 -#define RANK_USHORT 2 -#define RANK_INT 3 -#define RANK_UINT 3 -#define RANK_LONG 4 -#define RANK_ULONG 4 -#define RANK_LLONG 5 -#define RANK_ULLONG 5 -#define RANK_FLOAT 6 -#define RANK_DOUBLE 7 -#define RANK_LDOUBLE 8 - -/* - * Initializaion of type pointers were done with - * a C99 initilizator '... = &(Type) {...', but - * c compiler in Plan9 gives error with this - * syntax, so I have switched it to this ugly form - * I hope I will change it again in the future - */ - -static Type types[] = { - { /* 0 = voidtype */ - .op = VOID, - .letter = L_VOID, - }, - { /* 1 = pvoidtype */ - .op = PTR, - .letter = L_POINTER, - .prop = TDEFINED, - .type = &types[5], /* chartype */ - .size = 8, - .align = 8, - }, - { /* 2 = booltype */ - .op = INT, - .letter = L_BOOL, - .prop = TDEFINED | TINTEGER | TARITH, - .size = 1, - .align = 1, - .n.rank = RANK_BOOL, - }, - { /* 3 = schartype */ - .op = INT, - .letter = L_INT8, - .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, - .size = 1, - .align = 1, - .n.rank = RANK_SCHAR, - }, - { /* 4 = uchartype */ - .op = INT, - .letter = L_UINT8, - .prop = TDEFINED | TINTEGER | TARITH, - .size = 1, - .align = 1, - .n.rank = RANK_UCHAR, - }, - { /* 5 = chartype */ - .op = INT, - .letter = L_INT8, - .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, - .size = 1, - .align = 1, - .n.rank = RANK_CHAR, - }, - { /* 6 = ushortype */ - .op = INT, - .letter = L_UINT16, - .prop = TDEFINED | TINTEGER | TARITH, - .size = 2, - .align = 2, - .n.rank = RANK_USHORT, - }, - { /* 7 = shortype */ - .op = INT, - .letter = L_INT16, - .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, - .size = 2, - .align = 2, - .n.rank = RANK_SHORT, - }, - { /* 8 = uinttype */ - .op = INT, - .letter = L_UINT32, - .prop = TDEFINED | TINTEGER | TARITH, - .size = 4, - .align = 4, - .n.rank = RANK_UINT, - }, - { /* 9 = inttype */ - .op = INT, - .letter = L_INT32, - .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, - .size = 4, - .align = 4, - .n.rank = RANK_INT, - }, - { /* 10 = longtype */ - .op = INT, - .letter = L_INT64, - .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, - .size = 8, - .align = 8, - .n.rank = RANK_LONG, - }, - { /* 11 = ulongtype */ - .op = INT, - .letter = L_UINT64, - .prop = TDEFINED | TINTEGER | TARITH, - .size = 8, - .align = 8, - .n.rank = RANK_ULONG, - }, - { /* 12 = ullongtype */ - .op = INT, - .letter = L_UINT64, - .prop = TDEFINED | TINTEGER | TARITH, - .size = 8, - .align = 8, - .n.rank = RANK_ULLONG, - }, - { /* 13 = llongtype */ - .op = INT, - .letter = L_INT64, - .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, - .size = 8, - .align = 8, - .n.rank = RANK_LLONG, - }, - { /* 14 = floattype */ - .op = FLOAT, - .letter = L_FLOAT, - .prop = TDEFINED | TARITH, - .size = 4, - .align = 4, - .n.rank = RANK_FLOAT, - }, - { /* 15 = doubletype */ - .op = FLOAT, - .letter = L_DOUBLE, - .prop = TDEFINED | TARITH, - .size = 8, - .align = 8, - .n.rank = RANK_DOUBLE, - }, - { /* 16 = ldoubletype */ - .op = FLOAT, - .letter = L_LDOUBLE, - .prop = TDEFINED | TARITH, - .size = 16, - .align = 16, - .n.rank = RANK_LDOUBLE, - }, - { /* 17 = sizettype */ - .op = INT, - .letter = L_UINT64, - .prop = TDEFINED | TINTEGER | TARITH, - .size = 8, - .align = 8, - .n.rank = RANK_UINT, - }, - { /* 18 = ellipsis */ - .op = ELLIPSIS, - .letter = L_ELLIPSIS, - .prop = TDEFINED, - }, - { /* 19 = pdifftype */ - .op = INT, - .letter = L_INT64, - .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, - .size = 8, - .align = 8, - .n.rank = RANK_LONG, - }, - { /* 20 = va_type */ - .op = STRUCT, - .letter = L_VA_ARG, - .prop = TDEFINED, - .size = 24, - .align = 8, - }, -}; - -Type *voidtype = &types[0], *pvoidtype = &types[1], - *booltype = &types[2], *schartype = &types[3], - *uchartype = &types[4], *chartype = &types[5], - *ushortype = &types[6], *shortype = &types[7], - *uinttype = &types[8], *inttype = &types[9], - *longtype = &types[10], *ulongtype = &types[11], - *ullongtype = &types[12], *llongtype = &types[13], - *floattype = &types[14], *doubletype = &types[15], - *ldoubletype = &types[16], - *sizettype = &types[17], *pdifftype = &types[19], - *ellipsistype = &types[18], *va_type = &types[20], - *va_list_type; - -static Symbol dummy0 = {.u.i = 0, .type = &types[9]}, - dummy1 = {.u.i = 1, .type = &types[9]}; -Symbol *zero = &dummy0, *one = &dummy1; - -void -iarch(void) -{ - va_list_type = mktype(va_type, ARY, 1, NULL); -} - -int -valid_va_list(Type *tp) -{ - return tp->op == PTR && eqtype(tp->type, va_type, 1); -} diff --git a/src/cmd/cc/cc1/target/arm64-sysv/arch.mk b/src/cmd/cc/cc1/target/arm64-sysv/arch.mk @@ -1,4 +0,0 @@ -OBJ-arm64-sysv= $(OBJS) target/arm64-sysv/arch.o - -$(LIBEXEC)/cc1-arm64-sysv: $(OBJ-arm64-sysv) - $(CC) $(SCC_LDFLAGS) $(OBJ-arm64-sysv) -lscc -o $@ diff --git a/src/cmd/cc/cc1/target/i386-sysv/arch.c b/src/cmd/cc/cc1/target/i386-sysv/arch.c @@ -1,219 +0,0 @@ -#include <scc/scc.h> -#include "../../cc1.h" - -#define RANK_BOOL 0 -#define RANK_SCHAR 1 -#define RANK_UCHAR 1 -#define RANK_CHAR 1 -#define RANK_SHORT 2 -#define RANK_USHORT 2 -#define RANK_INT 3 -#define RANK_UINT 3 -#define RANK_LONG 4 -#define RANK_ULONG 4 -#define RANK_LLONG 5 -#define RANK_ULLONG 5 -#define RANK_FLOAT 6 -#define RANK_DOUBLE 7 -#define RANK_LDOUBLE 8 - -/* - * Initializaion of type pointers were done with - * a C99 initilizator '... = &(Type) {...', but - * c compiler in Plan9 gives error with this - * syntax, so I have switched it to this ugly form - * I hope I will change it again in the future - */ - -static Type types[] = { - { /* 0 = voidtype */ - .op = VOID, - .letter = L_VOID, - }, - { /* 1 = pvoidtype */ - .op = PTR, - .letter = L_POINTER, - .prop = TDEFINED, - .type = &types[5], /* chartype */ - .size = 4, - .align = 4, - }, - { /* 2 = booltype */ - .op = INT, - .letter = L_BOOL, - .prop = TDEFINED | TINTEGER | TARITH, - .size = 1, - .align = 1, - .n.rank = RANK_BOOL, - }, - { /* 3 = schartype */ - .op = INT, - .letter = L_INT8, - .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, - .size = 1, - .align = 1, - .n.rank = RANK_SCHAR, - }, - { /* 4 = uchartype */ - .op = INT, - .letter = L_UINT8, - .prop = TDEFINED | TINTEGER | TARITH, - .size = 1, - .align = 1, - .n.rank = RANK_UCHAR, - }, - { /* 5 = chartype */ - .op = INT, - .letter = L_INT8, - .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, - .size = 1, - .align = 1, - .n.rank = RANK_CHAR, - }, - { /* 6 = ushortype */ - .op = INT, - .letter = L_UINT16, - .prop = TDEFINED | TINTEGER | TARITH, - .size = 2, - .align = 2, - .n.rank = RANK_USHORT, - }, - { /* 7 = shortype */ - .op = INT, - .letter = L_INT16, - .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, - .size = 2, - .align = 2, - .n.rank = RANK_SHORT, - }, - { /* 8 = uinttype */ - .op = INT, - .letter = L_UINT32, - .prop = TDEFINED | TINTEGER | TARITH, - .size = 4, - .align = 4, - .n.rank = RANK_UINT, - }, - { /* 9 = inttype */ - .op = INT, - .letter = L_INT32, - .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, - .size = 4, - .align = 4, - .n.rank = RANK_INT, - }, - { /* 10 = longtype */ - .op = INT, - .letter = L_INT32, - .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, - .size = 4, - .align = 4, - .n.rank = RANK_LONG, - }, - { /* 11 = ulongtype */ - .op = INT, - .letter = L_UINT32, - .prop = TDEFINED | TINTEGER | TARITH, - .size = 4, - .align = 4, - .n.rank = RANK_ULONG, - }, - { /* 12 = ullongtype */ - .op = INT, - .letter = L_UINT64, - .prop = TDEFINED | TINTEGER | TARITH, - .size = 8, - .align = 4, - .n.rank = RANK_ULLONG, - }, - { /* 13 = llongtype */ - .op = INT, - .letter = L_INT64, - .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, - .size = 8, - .align = 4, - .n.rank = RANK_LLONG, - }, - { /* 14 = floattype */ - .op = FLOAT, - .letter = L_FLOAT, - .prop = TDEFINED | TARITH, - .size = 4, - .align = 4, - .n.rank = RANK_FLOAT, - }, - { /* 15 = doubletype */ - .op = FLOAT, - .letter = L_DOUBLE, - .prop = TDEFINED | TARITH, - .size = 8, - .align = 4, - .n.rank = RANK_DOUBLE, - }, - { /* 16 = ldoubletype */ - .op = FLOAT, - .letter = L_LDOUBLE, - .prop = TDEFINED | TARITH, - .size = 12, - .align = 4, - .n.rank = RANK_LDOUBLE, - }, - { /* 17 = sizettype */ - .op = INT, - .letter = L_UINT32, - .prop = TDEFINED | TINTEGER | TARITH, - .size = 4, - .align = 4, - .n.rank = RANK_UINT, - }, - { /* 18 = ellipsis */ - .op = ELLIPSIS, - .letter = L_ELLIPSIS, - .prop = TDEFINED, - }, - { /* 19 = pdifftype */ - .op = INT, - .letter = L_INT32, - .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, - .size = 4, - .align = 4, - .n.rank = RANK_INT, - }, - { /* 20 = va_list_type */ - .op = PTR, - .letter = L_POINTER, - .prop = TDEFINED, - .size = 4, - .align = 4, - }, -}; - - -Type *voidtype = &types[0], *pvoidtype = &types[1], - *booltype = &types[2], *schartype = &types[3], - *uchartype = &types[4], *chartype = &types[5], - *ushortype = &types[6], *shortype = &types[7], - *uinttype = &types[8], *inttype = &types[9], - *longtype = &types[10], *ulongtype = &types[11], - *ullongtype = &types[12], *llongtype = &types[13], - *floattype = &types[14], *doubletype = &types[15], - *ldoubletype = &types[16], - *sizettype = &types[17], *pdifftype = &types[19], - *ellipsistype = &types[18], *va_list_type = &types[20]; - - - -static Symbol dummy0 = {.u.i = 0, .type = &types[9]}, - dummy1 = {.u.i = 1, .type = &types[9]}; -Symbol *zero = &dummy0, *one = &dummy1; - -void -iarch(void) -{ -} - -int -valid_va_list(Type *tp) -{ - return eqtype(tp, va_list_type, 1); -} diff --git a/src/cmd/cc/cc1/target/i386-sysv/arch.mk b/src/cmd/cc/cc1/target/i386-sysv/arch.mk @@ -1,4 +0,0 @@ -OBJ-i386-sysv= $(OBJS) target/i386-sysv/arch.o - -$(LIBEXEC)/cc1-i386-sysv: $(OBJ-i386-sysv) - $(CC) $(SCC_LDFLAGS) $(OBJ-i386-sysv) -lscc -o $@ diff --git a/src/cmd/cc/cc1/target/z80-scc/arch.c b/src/cmd/cc/cc1/target/z80-scc/arch.c @@ -1,217 +0,0 @@ -#include <scc/scc.h> -#include "../../cc1.h" - -#define RANK_BOOL 0 -#define RANK_SCHAR 1 -#define RANK_UCHAR 1 -#define RANK_CHAR 1 -#define RANK_SHORT 2 -#define RANK_USHORT 2 -#define RANK_INT 3 -#define RANK_UINT 3 -#define RANK_LONG 4 -#define RANK_ULONG 4 -#define RANK_LLONG 5 -#define RANK_ULLONG 5 -#define RANK_FLOAT 6 -#define RANK_DOUBLE 7 -#define RANK_LDOUBLE 8 - -/* - * Initializaion of type pointers were done with - * a C99 initilizator '... = &(Type) {...', but - * c compiler in Plan9 gives error with this - * syntax, so I have switched it to this ugly form - * I hope I will change it again in the future - */ - -static Type types[] = { - { /* 0 = voidtype */ - .op = VOID, - .letter = L_VOID, - }, - { /* 1 = pvoidtype */ - .op = PTR, - .letter = L_POINTER, - .prop = TDEFINED, - .type = &types[5], /* char type */ - .size = 2, - .align = 2, - }, - { /* 2 = booltype */ - .op = INT, - .letter = L_BOOL, - .prop = TDEFINED | TINTEGER | TARITH, - .size = 1, - .align = 1, - .n.rank = RANK_BOOL, - }, - { /* 3 = schartype */ - .op = INT, - .letter = L_INT8, - .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, - .size = 1, - .align = 1, - .n.rank = RANK_SCHAR, - }, - { /* 4 = uchartype */ - .op = INT, - .letter = L_UINT8, - .prop = TDEFINED | TINTEGER | TARITH, - .size = 1, - .align = 1, - .n.rank = RANK_UCHAR, - }, - { /* 5 = chartype */ - .op = INT, - .letter = L_UINT8, - .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, - .size = 1, - .align = 1, - .n.rank = RANK_CHAR, - }, - { /* 6 = ushortype */ - .op = INT, - .letter = L_UINT16, - .prop = TDEFINED | TINTEGER | TARITH, - .size = 2, - .align = 1, - .n.rank = RANK_USHORT, - }, - { /* 7 = shortype */ - .op = INT, - .letter = L_INT16, - .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, - .size = 2, - .align = 1, - .n.rank = RANK_SHORT, - }, - { /* 8 = uinttype */ - .op = INT, - .letter = L_UINT16, - .prop = TDEFINED | TINTEGER | TARITH, - .size = 2, - .align = 1, - .n.rank = RANK_UINT, - }, - { /* 9 = inttype */ - .op = INT, - .letter = L_INT16, - .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, - .size = 2, - .align = 1, - .n.rank = RANK_INT, - }, - { /* 10 = longtype */ - .op = INT, - .letter = L_INT32, - .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, - .size = 4, - .align = 1, - .n.rank = RANK_LONG, - }, - { /* 11 = ulongtype */ - .op = INT, - .letter = L_UINT32, - .prop = TDEFINED | TINTEGER | TARITH, - .size = 4, - .align = 1, - .n.rank = RANK_ULONG, - }, - { /* 12 = ullongtype */ - .op = INT, - .letter = L_UINT64, - .prop = TDEFINED | TINTEGER | TARITH, - .size = 8, - .align = 1, - .n.rank = RANK_ULLONG, - }, - { /* 13 = llongtype */ - .op = INT, - .letter = L_INT64, - .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, - .size = 8, - .align = 1, - .n.rank = RANK_LLONG, - }, - { /* 14 = floattype */ - .op = FLOAT, - .letter = L_FLOAT, - .prop = TDEFINED | TARITH, - .size = 4, - .align = 1, - .n.rank = RANK_FLOAT, - }, - { /* 15 = doubletype */ - .op = FLOAT, - .letter = L_DOUBLE, - .prop = TDEFINED | TARITH, - .size = 8, - .align = 1, - .n.rank = RANK_DOUBLE, - }, - { /* 16 = ldoubletype */ - .op = FLOAT, - .letter = L_LDOUBLE, - .prop = TDEFINED | TARITH, - .size = 16, - .align = 1, - .n.rank = RANK_LDOUBLE, - }, - { /* 17 = sizettype */ - .op = INT, - .letter = L_UINT16, - .prop = TDEFINED | TINTEGER | TARITH, - .size = 2, - .align = 1, - .n.rank = RANK_UINT, - }, - { /* 18 = ellipsis */ - .op = ELLIPSIS, - .letter = L_ELLIPSIS, - .prop = TDEFINED, - }, - { /* 7 = pdifftype */ - .op = INT, - .letter = L_INT16, - .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, - .size = 2, - .align = 1, - .n.rank = RANK_SHORT, - }, - { /* 20 = va_list_type */ - .op = PTR, - .letter = L_POINTER, - .prop = TDEFINED, - .size = 2, - .align = 1, - } -}; - -Type *voidtype = &types[0], *pvoidtype = &types[1], - *booltype = &types[2], *schartype = &types[3], - *uchartype = &types[4], *chartype = &types[5], - *ushortype = &types[6], *shortype = &types[7], - *uinttype = &types[8], *inttype = &types[9], - *longtype = &types[10], *ulongtype = &types[11], - *ullongtype = &types[12], *llongtype = &types[13], - *floattype = &types[14], *doubletype = &types[15], - *ldoubletype = &types[16], - *sizettype = &types[17], *pdifftype = &types[19], - *ellipsistype = &types[18], *va_list_type = &types[20]; - - -static Symbol dummy0 = {.u.i = 0, .type = &types[9]}, - dummy1 = {.u.i = 1, .type = &types[9]}; -Symbol *zero = &dummy0, *one = &dummy1; - -void -iarch(void) -{ -} - -int -valid_va_list(Type *tp) -{ - return eqtype(tp, va_list_type, 1); -} diff --git a/src/cmd/cc/cc1/target/z80-scc/arch.mk b/src/cmd/cc/cc1/target/z80-scc/arch.mk @@ -1,4 +0,0 @@ -OBJ-z80-scc= $(OBJS) target/z80-scc/arch.o - -$(LIBEXEC)/cc1-z80-scc: $(OBJ-z80-scc) - $(CC) $(SCC_LDFLAGS) $(OBJ-z80-scc) -lscc -o $@ diff --git a/src/cmd/cc/cc1/z80-scc.c b/src/cmd/cc/cc1/z80-scc.c @@ -0,0 +1,212 @@ +#include <scc/scc.h> +#include "cc1.h" + +#define RANK_BOOL 0 +#define RANK_SCHAR 1 +#define RANK_UCHAR 1 +#define RANK_CHAR 1 +#define RANK_SHORT 2 +#define RANK_USHORT 2 +#define RANK_INT 3 +#define RANK_UINT 3 +#define RANK_LONG 4 +#define RANK_ULONG 4 +#define RANK_LLONG 5 +#define RANK_ULLONG 5 +#define RANK_FLOAT 6 +#define RANK_DOUBLE 7 +#define RANK_LDOUBLE 8 + +static int +local_valid_va_list(Type *tp) +{ + return eqtype(tp, va_list_type, 1); +} + +Arch * +z80_scc(void) +{ + static Arch arch = { + .voidtype = { + .op = VOID, + .letter = L_VOID, + }, + .pvoidtype = { + .op = PTR, + .letter = L_POINTER, + .prop = TDEFINED, + .size = 8, + .align = 8, + }, + .booltype = { + .op = INT, + .letter = L_BOOL, + .prop = TDEFINED | TINTEGER | TARITH, + .size = 1, + .align = 1, + .n.rank = RANK_BOOL, + }, + .schartype = { + .op = INT, + .letter = L_INT8, + .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, + .size = 1, + .align = 1, + .n.rank = RANK_SCHAR, + + }, + .uchartype = { + .op = INT, + .letter = L_UINT8, + .prop = TDEFINED | TINTEGER | TARITH, + .size = 1, + .align = 1, + .n.rank = RANK_UCHAR, + }, + .chartype = { + .op = INT, + .letter = L_INT8, + .prop = TDEFINED | TINTEGER | TARITH, + .size = 1, + .align = 1, + .n.rank = RANK_CHAR, + }, + .ushortype = { + .op = INT, + .letter = L_UINT16, + .prop = TDEFINED | TINTEGER | TARITH, + .size = 2, + .align = 2, + .n.rank = RANK_USHORT, + + }, + .shortype = { + .op = INT, + .letter = L_INT16, + .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, + .size = 2, + .align = 2, + .n.rank = RANK_SHORT, + }, + .uinttype = (Type) { + .op = INT, + .letter = L_UINT16, + .prop = TDEFINED | TINTEGER | TARITH, + .size = 2, + .align = 1, + .n.rank = RANK_UINT, + }, + .inttype = (Type) { + .op = INT, + .letter = L_INT16, + .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, + .size = 2, + .align = 1, + .n.rank = RANK_INT, + }, + .longtype = { + .op = INT, + .letter = L_INT32, + .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, + .size = 4, + .align = 1, + .n.rank = RANK_LONG, + }, + .ulongtype = { + .op = INT, + .letter = L_UINT32, + .prop = TDEFINED | TINTEGER | TARITH, + .size = 4, + .align = 1, + .n.rank = RANK_ULONG, + }, + .ullongtype = { + .op = INT, + .letter = L_UINT64, + .prop = TDEFINED | TINTEGER | TARITH, + .size = 8, + .align = 8, + .n.rank = RANK_ULLONG, + }, + .llongtype = { + .op = INT, + .letter = L_INT64, + .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, + .size = 8, + .align = 8, + .n.rank = RANK_LLONG, + }, + .floattype = { + .op = FLOAT, + .letter = L_FLOAT, + .prop = TDEFINED | TARITH, + .size = 4, + .align = 1, + .n.rank = RANK_FLOAT, + }, + .doubletype = { + .op = FLOAT, + .letter = L_DOUBLE, + .prop = TDEFINED | TARITH, + .size = 8, + .align = 1, + .n.rank = RANK_DOUBLE, + }, + .ldoubletype = { + .op = FLOAT, + .letter = L_LDOUBLE, + .prop = TDEFINED | TARITH, + .size = 16, + .align = 1, + .n.rank = RANK_LDOUBLE, + }, + .sizettype = { + .op = INT, + .letter = L_UINT16, + .prop = TDEFINED | TINTEGER | TARITH, + .size = 2, + .align = 1, + .n.rank = RANK_UINT, + }, + .pdifftype = { + .op = INT, + .letter = L_INT16, + .prop = TDEFINED | TINTEGER | TARITH | TSIGNED, + .size = 2, + .align = 1, + .n.rank = RANK_SHORT, + }, + .ellipsistype = { + .op = ELLIPSIS, + .letter = L_ELLIPSIS, + .prop = TDEFINED, + }, + .zero = { + .u.i = 0, + }, + .one = { + .u.i = 1, + }, + .va_type = { + .op = PTR, + .letter = L_POINTER, + .prop = TDEFINED, + .size = 2, + .align = 1, + }, + .va_list_type = { + .op = PTR, + .letter = L_POINTER, + .prop = TDEFINED, + .size = 2, + .align = 1, + }, + }; + arch.valid_va_list = local_valid_va_list; + arch.pvoidtype.type = &arch.chartype; + arch.va_type.type = &arch.inttype; + arch.zero.type = inttype; + arch.one.type = inttype; + + return &arch; +}