ref: 989c106cae3b5870d966b2cc6a83dcad73254ede
parent: 975c7b569ff06c32eafd382884e8d583b5674679
author: Roberto E. Vargas Caballero <[email protected]>
date: Tue Aug 22 13:16:21 EDT 2017
Chage makefile framework At this moment there were several problems with the makefiles, because we only could configure the archs and systems that we want in the final build, and it meant that the final target list was a cartesian product of both. This set included non desired (and absurd) combinations like for example z80-linux. Other problem was the impossibility of having support for the new qbe support for aarch64. This new framework uses a dep rule which generates makefiles (makefiles are different files than Makefiles), and it helps to avoid all the for loops that were needed for generating all the requested architectures. All the needed information is now in the leaf makefiles.
--- a/Makefile
+++ b/Makefile
@@ -4,40 +4,66 @@
include config.mk
-DIRS = lib cc1 cc2 crt driver/$(DRIVER)
+DIRS = inc cc1 cc2 driver lib
-all: scc-driver
- for i in $(ARCHS); \
+all:
+ @set -e ;\
+ trap 'rm -f bin/cc1-* bin/cc2-* bin/scc' 0 2 3; \
+ if ! test -f bin/dep ;\
+ then \
+ echo Run make dep first >&2 ;\
+ exit 1 ;\
+ fi ;\
+ pwd=$$PWD; \
+ for i in $(DIRS); \
do \
- $(MAKE) $$i || exit; \
+ cd $$i; \
+ $(MAKE) $@; \
+ cd $$pwd; \
done
+ cp cc1/cc1-* bin/
+ cp cc2/cc2-* bin/
+ cp driver/$(DRIVER)/scc bin/
-scc-driver:
- cd driver/$(DRIVER)/ && $(MAKE) scc
- ln -f driver/$(DRIVER)/scc bin/scc
-$(ARCHS):
+clean:
+ @set -e ;\
pwd=$$PWD; \
- for i in cc1 cc2; \
+ for i in $(DIRS); \
do \
cd $$i; \
- ARCH=$@ $(MAKE) -e $$i-$@ || exit; \
+ $(MAKE) $@; \
cd $$pwd; \
done
- cd crt; \
- for i in $(SYSS); \
+ rm -f bin/cc1-*
+ rm -f bin/cc2-*
+ rm -f bin/scc
+
+distclean:
+ @set -e ;\
+ pwd=$$PWD; \
+ for i in $(DIRS); \
do \
- ARCH=$@ SYS=$$i $(MAKE) -e || exit; \
- done; \
- cd $$pwd;
- ln -f cc1/cc1-$@ bin/
- ln -f cc2/cc2-$@ bin/
+ cd $$i; \
+ $(MAKE) $@; \
+ cd $$pwd; \
+ done
+ rm -f bin/cc1-*
+ rm -f bin/cc2-*
+ rm -f bin/scc
+ rm -f bin/dep
-libc/src/libc.a:
+dep:
+ @set -e;\
+ pwd=$$PWD; \
+ for i in $(DIRS); \
+ do \
+ cd $$i; \
+ $(MAKE) $@; \
+ cd $$pwd; \
+ done
+ touch bin/dep
-libc: libc/src/libc.a
- cd libc/src && $(MAKE) -e CC=scc
-
tests: all
cd tests && $(MAKE) -e all
@@ -61,19 +87,3 @@
rm -rf $(DESTDIR)/$(PREFIX)/lib/scc/
rm -f $(DESTDIR)/$(PREFIX)/bin/scc
rm -f $(DESTDIR)/$(PREFIX)/bin/scpp
-
-clean-helper:
- for i in $(DIRS); \
- do \
- (cd $$i && $(MAKE) -e clean || exit); \
- done
-
-clean:
- for i in $(ARCHS); \
- do \
- ARCH=$$i $(MAKE) -e clean-helper || exit; \
- done
- rm -f bin/cc* bin/scc
-
-distclean: clean
- rm -f inc/sysincludes.h inc/syslibs.h inc/ldflags.h
--- a/cc1/Makefile
+++ b/cc1/Makefile
@@ -1,35 +1,35 @@
# See LICENSE file for copyright and license details.
.POSIX:
-CSTDINC = -I../inc/$(STD)
+# Makefile is only used as a template for makefile.
+# If you modify Makefile remember to run make dep
include ../config.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 \
- arch/$(ARCH)/arch.o
+MOREFLAGS = -I../inc/$(STD)
+LIBDIR = ../lib/cc
-all: cc1-$(ARCH)
+OBJ = 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
-cpp.o: stallman.msg
-arch/$(ARCH)/arch.o: ../inc/sysincludes.h
-$(OBJS): cc1.h ../inc/cc.h ../inc/$(STD)/cstd.h
+HDR = cc1.h ../inc/cc.h ../inc/$(STD)/cstd.h ../inc/sysincludes.h
-../inc/sysincludes.h:
- cp -f ../inc/sysincludes.def.h ../inc/sysincludes.h
+all:
-../lib/libcc.a:
- cd ../lib && $(MAKE) -e
+cpp.o: stallman.msg
-cc1-$(ARCH): $(OBJS) ../lib/libcc.a
- $(CC) $(SCC_LDFLAGS) $(OBJS) ../lib/libcc.a -o $@
+$(LIBDIR)/libcc.a:
+ cd $(LIBDIR) && $(MAKE)
-cpp: cc1-$(ARCH)
- ln -f $< cpp
+dep:
+ ./gendep.sh $(TARGETS)
-test:
- cd tests && ./chktest.sh *.c
-
clean:
- rm -f $(OBJS)
- rm -f cc1-* cpp
+ rm -f *.o
+ rm -f target/*/*.o
+ rm -f cc1-*
+
+distclean: clean
+ rm -f makefile
+
+include ../lib/cc/libdep.mk
--- a/cc1/arch/amd64-sysv/arch.c
+++ /dev/null
@@ -1,223 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-static char sccsid[] = "@(#) ./cc1/arch/amd64-sysv/arch.c";
-#include <stdio.h>
-
-#include "../../../inc/sysincludes.h"
-#include "../../../inc/cc.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);
-}
--- a/cc1/arch/i386-sysv/arch.c
+++ /dev/null
@@ -1,224 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-static char sccsid[] = "@(#) ./cc1/arch/i386-sysv/arch.c";
-#include <stdio.h>
-
-#include "../../../inc/sysincludes.h"
-#include "../../../inc/cc.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);
-}
--- a/cc1/arch/qbe/arch.c
+++ /dev/null
@@ -1,223 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-static char sccsid[] = "@(#) ./cc1/arch/qbe/arch.c";
-#include <stdio.h>
-
-#include "../../../inc/sysincludes.h"
-#include "../../../inc/cc.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 = 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 | SIGNED,
- .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_DOUBLE,
- .prop = TDEFINED | TARITH,
- .size = 8,
- .align = 8,
- .n.rank = RANK_DOUBLE,
- },
- { /* 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);
-}
--- a/cc1/arch/z80/arch.c
+++ /dev/null
@@ -1,222 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-static char sccsid[] = "@(#) ./cc1/arch/z80/arch.c";
-#include <stdio.h>
-
-#include "../../../inc/sysincludes.h"
-#include "../../../inc/cc.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);
-}
--- a/cc1/cpp.c
+++ b/cc1/cpp.c
@@ -11,7 +11,6 @@
#include "../inc/cc.h"
#include "cc1.h"
-extern char *sysincludes[];
static char *argp, *macroname;
static unsigned arglen;
static unsigned ncmdlines;
@@ -509,10 +508,6 @@
n = dirinclude.n;
for (bp = dirinclude.s; n--; ++bp) {
- if (includefile(*bp, file, filelen))
- goto its_done;
- }
- for (bp = sysincludes; *bp; ++bp) {
if (includefile(*bp, file, filelen))
goto its_done;
}
--- /dev/null
+++ b/cc1/gendep.sh
@@ -1,0 +1,27 @@
+#!/bin/sh
+
+set -e
+
+rm -f makefile
+trap "rm -f $$.mk" 0 2 3
+
+re='\([^-]*\)-\([^-]*\)-\([^-]*\)-\([^-]*\)'
+
+echo $@ |
+tr ' ' '\n' |
+sed "s/$re/\1-\2/" |
+sort -u |
+(cat Makefile
+echo
+while read i
+do
+ cat <<EOF
+all: cc1-$i
+OBJ-$i= \$(OBJ) target/$i/arch.o
+\$(OBJ-$i): \$(HDR)
+cc1-$i: \$(OBJ-$i) \$(LIBDIR)/libcc.a
+ \$(CC) \$(SCC_LDFLAGS) \$(OBJ-$i) -lcc -o \$@
+
+EOF
+ echo
+done) > $$.mk && mv $$.mk makefile
--- /dev/null
+++ b/cc1/target/amd64-sysv/arch.c
@@ -1,0 +1,222 @@
+/* See LICENSE file for copyright and license details. */
+static char sccsid[] = "@(#) ./cc1/arch/amd64-sysv/arch.c";
+#include <stdio.h>
+
+#include "../../../inc/cc.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);
+}
--- /dev/null
+++ b/cc1/target/i386-sysv/arch.c
@@ -1,0 +1,223 @@
+/* See LICENSE file for copyright and license details. */
+static char sccsid[] = "@(#) ./cc1/arch/i386-sysv/arch.c";
+#include <stdio.h>
+
+#include "../../../inc/cc.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);
+}
--- /dev/null
+++ b/cc1/target/z80-scc/arch.c
@@ -1,0 +1,221 @@
+/* See LICENSE file for copyright and license details. */
+static char sccsid[] = "@(#) ./cc1/arch/z80/arch.c";
+#include <stdio.h>
+
+#include "../../../inc/cc.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);
+}
--- a/cc2/Makefile
+++ b/cc2/Makefile
@@ -1,31 +1,37 @@
# See LICENSE file for copyright and license details.
.POSIX:
-CSTDINC = -I../inc/$(STD)
+# Makefile is only used as a template for makefile.
+# If you modify Makefile remember to run make dep
include ../config.mk
-OBJS = main.o parser.o peep.o symbol.o node.o code.o optm.o\
- arch/$(ARCH)/code.o arch/$(ARCH)/cgen.o \
- arch/$(ARCH)/types.o arch/$(ARCH)/optm.o
+MOREFLAGS = -I../inc/$(STD)
+LIBDIR = ../lib/cc
-all: cc2-$(ARCH)
+OBJ = main.o parser.o peep.o symbol.o node.o code.o optm.o
+HDR = cc2.h ../inc/$(STD)/cstd.h ../inc/cc.h
+all:
+
+dep:
+ MKQBE=${MKQBE} ./gendep.sh $(TARGETS)
+
+$(LIBDIR)/libcc.a:
+ cd $(LIBDIR) && $(MAKE)
+
main.o: error.h
-$(OBJS): cc2.h ../inc/$(STD)/cstd.h ../inc/cc.h
-arch/$(ARCH)/code.o: arch/$(ARCH)/arch.h
-arch/$(ARCH)/cgen.o: arch/$(ARCH)/arch.h
error.h: cc2.h
rm -f $@; trap 'rm -f $$$$.h' EXIT INT QUIT ;\
awk -f generror.awk cc2.h > $$$$.h && mv $$$$.h $@
-../lib/libcc.a:
- cd ../lib && $(MAKE) -e
-
-cc2-$(ARCH): $(OBJS) ../lib/libcc.a
- $(CC) $(SCC_LDFLAGS) $(OBJS) ../lib/libcc.a -o $@
-
clean:
- rm -f $(OBJS)
+ rm -f *.o
+ rm -f target/*/*.o
rm -f cc2-* error.h
+
+distclean: clean
+ rm -f makefile
+
+include ../lib/cc/libdep.mk
--- a/cc2/arch/amd64-sysv/arch.h
+++ /dev/null
@@ -1,1 +1,0 @@
-/* See LICENSE file for copyright and license details. */
--- a/cc2/arch/amd64-sysv/cgen.c
+++ /dev/null
@@ -1,16 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-static char sccsid[] = "@(#) ./cc2/arch/amd64-sysv/cgen.c";
-
-#include "arch.h"
-#include "../../../inc/cc.h"
-#include "../../cc2.h"
-
-Node *
-cgen(Node *np)
-{
-}
-
-Node *
-sethi(Node *np)
-{
-}
--- a/cc2/arch/amd64-sysv/code.c
+++ /dev/null
@@ -1,211 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-static char sccsid[] = "@(#) ./cc2/arch/amd64-sysv/code.c";
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <cstd.h>
-#include "arch.h"
-#include "../../../inc/cc.h"
-#include "../../cc2.h"
-
-enum segment {
- CODESEG,
- DATASEG,
- BSSSEG,
- NOSEG
-};
-
-static int curseg = NOSEG;
-
-static void
-segment(int seg)
-{
- static char *txt[] = {
- [CODESEG] = "\t.text\n",
- [DATASEG] = "\t.data\n",
- [BSSSEG] = "\t.bss\n",
- };
-
- if (seg == curseg)
- return;
- fputs(txt[seg], stdout);
- curseg = seg;
-}
-
-static char *
-symname(Symbol *sym)
-{
- static char name[INTIDENTSIZ+1];
-
- if (sym->name) {
- switch (sym->kind) {
- case SEXTRN:
- case SGLOB:
- case SPRIV:
- return sym->name;
- }
- }
-
- sprintf(name, ".L%d", sym->numid);
-
- return name;
-}
-
-static void
-emitconst(Node *np)
-{
- switch (np->type.size) {
- case 1:
- printf("%d", (int) np->u.i & 0xFF);
- break;
- case 2:
- printf("%d", (int) np->u.i & 0xFFFF);
- break;
- case 4:
- printf("%ld", (long) np->u.i & 0xFFFFFFFF);
- break;
- case 8:
- printf("%lld", (long long) np->u.i & 0xFFFFFFFF);
- break;
- default:
- abort();
- }
-}
-
-static void
-emittree(Node *np)
-{
- if (!np)
- return;
-
- switch (np->op) {
- case OSTRING:
- printf("\"%s\"", np->u.s);
- free(np->u.s);
- np->u.s = NULL;
- break;
- case OCONST:
- emitconst(np);
- break;
- case OADDR:
- emittree(np->left);
- break;
- case OMEM:
- fputs(symname(np->u.sym), stdout);
- break;
- default:
- emittree(np->left);
- printf(" %c ", np->op);
- emittree(np->right);
- break;
- }
-}
-static void
-size2asm(Type *tp)
-{
- char *s;
-
- if (tp->flags & STRF) {
- s = "\t.ascii\t";
- } else {
- switch (tp->size) {
- case 1:
- s = "\t.byte\t";
- break;
- case 2:
- s = "\t.short\t";
- break;
- case 4:
- s = "\t.long\t";
- break;
- case 8:
- s = "\t.quad\t";
- break;
- default:
- s = "\t.space\t%lu,";
- break;
- }
- }
- printf(s, tp->size);
-}
-
-
-void
-data(Node *np)
-{
- size2asm(&np->type);
- emittree(np);
- putchar('\n');
-}
-
-static void
-label(Symbol *sym)
-{
- int seg;
- char *name = symname(sym);
- Type *tp = &sym->type;
-
- if (sym->type.flags & FUNF)
- seg = CODESEG;
- else if (sym->type.flags & INITF)
- seg = DATASEG;
- else
- seg = BSSSEG;
- segment(seg);
-
- switch (sym->kind) {
- case SEXTRN:
- printf("\t.extern\t%s\n", name);
- case SLOCAL:
- return;
- case SGLOB:
- printf("\t.global\t%s\n", name);
- if (seg == BSSSEG)
- printf("\t.comm\t%s,%lu\n", name, tp->size);
- break;
- }
- if (sym->type.align != 1)
- printf("\t.align\t%lu\n", sym->type.align );
- printf("%s:\n", name);
-}
-
-void
-defglobal(Symbol *sym)
-{
- label(sym);
- if (sym->kind == SEXTRN || (sym->type.flags & INITF))
- return;
- size2asm(&sym->type);
- puts("0");
-}
-
-void
-defvar(Symbol *sym)
-{
-}
-
-void
-defpar(Symbol *sym)
-{
-}
-
-void
-newfun(void)
-{
-}
-
-void
-writeout(void)
-{
-}
-
-void
-endinit(void)
-{
-}
-
-void
-getbblocks(void)
-{
-}
--- a/cc2/arch/amd64-sysv/optm.c
+++ /dev/null
@@ -1,11 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-static char sccsid[] = "@(#) ./cc2/arch/amd64-sysv/optm.c";
-
-#include "../../../inc/cc.h"
-#include "../../cc2.h"
-
-Node *
-optm_dep(Node *np)
-{
- return np;
-}
--- a/cc2/arch/amd64-sysv/types.c
+++ /dev/null
@@ -1,94 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-static char sccsid[] = "@(#) ./cc2/arch/amd64-sysv/types.c";
-
-#include "../../../inc/cc.h"
-#include "../../cc2.h"
-
-
-Type int8type = {
- .flags = SIGNF | INTF,
- .size = 1,
- .align = 1
-};
-
-Type int16type = {
- .flags = SIGNF | INTF,
- .size = 2,
- .align = 2
-};
-
-Type int32type = {
- .flags = SIGNF | INTF,
- .size = 4,
- .align = 4
-};
-
-Type int64type = {
- .flags = SIGNF | INTF,
- .size = 8,
- .align = 8
-};
-
-Type uint8type = {
- .flags = INTF,
- .size = 1,
- .align = 1
-};
-
-Type uint16type = {
- .flags = INTF,
- .size = 2,
- .align = 2
-};
-
-Type uint32type = {
- .flags = INTF,
- .size = 4,
- .align = 4
-};
-
-Type uint64type = {
- .flags = INTF,
- .size = 8,
- .align = 2
-};
-
-Type ptrtype = {
- .flags = INTF,
- .size = 8,
- .align = 8
-};
-
-Type booltype = {
- .flags = INTF,
- .size = 1,
- .align = 1
-};
-
-Type float32type = {
- .flags = FLOATF,
- .size = 4,
- .align = 4
-};
-
-Type float64type = {
- .flags = FLOATF,
- .size = 8,
- .align = 8
-};
-
-Type float80type = {
- .flags = FLOATF,
- .size = 16,
- .align = 16
-};
-
-Type voidtype = {
- .size = 0,
- .align = 0
-};
-
-Type arg_type = {
- .size = 24,
- .align = 8
-};
--- a/cc2/arch/i386-sysv/arch.h
+++ /dev/null
@@ -1,1 +1,0 @@
-/* See LICENSE file for copyright and license details. */
--- a/cc2/arch/i386-sysv/cgen.c
+++ /dev/null
@@ -1,16 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-static char sccsid[] = "@(#) ./cc2/arch/i386-sysv/cgen.c";
-
-#include "arch.h"
-#include "../../../inc/cc.h"
-#include "../../cc2.h"
-
-Node *
-cgen(Node *np)
-{
-}
-
-Node *
-sethi(Node *np)
-{
-}
--- a/cc2/arch/i386-sysv/code.c
+++ /dev/null
@@ -1,209 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-static char sccsid[] = "@(#) ./cc2/arch/i386-sysv/code.c";
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <cstd.h>
-#include "arch.h"
-#include "../../../inc/cc.h"
-#include "../../cc2.h"
-
-enum segment {
- CODESEG,
- DATASEG,
- BSSSEG,
- NOSEG
-};
-
-static int curseg = NOSEG;
-
-static void
-segment(int seg)
-{
- static char *txt[] = {
- [CODESEG] = "\t.text\n",
- [DATASEG] = "\t.data\n",
- [BSSSEG] = "\t.bss\n",
- };
-
- if (seg == curseg)
- return;
- fputs(txt[seg], stdout);
- curseg = seg;
-}
-
-static char *
-symname(Symbol *sym)
-{
- static char name[INTIDENTSIZ+1];
-
- if (sym->name) {
- switch (sym->kind) {
- case SEXTRN:
- case SGLOB:
- case SPRIV:
- return sym->name;
- }
- }
-
- sprintf(name, ".L%d", sym->numid);
-
- return name;
-}
-
-static void
-emitconst(Node *np)
-{
- switch (np->type.size) {
- case 1:
- printf("%d", (int) np->u.i & 0xFF);
- break;
- case 2:
- printf("%d", (int) np->u.i & 0xFFFF);
- break;
- case 4:
- printf("%ld", (long) np->u.i & 0xFFFFFFFF);
- break;
- case 8:
- printf("%lld", (long long) np->u.i & 0xFFFFFFFF);
- break;
- default:
- abort();
- }
-}
-
-static void
-emittree(Node *np)
-{
- if (!np)
- return;
-
- switch (np->op) {
- case OSTRING:
- printf("\"%s\"", np->u.s);
- free(np->u.s);
- np->u.s = NULL;
- break;
- case OCONST:
- emitconst(np);
- break;
- case OADDR:
- emittree(np->left);
- break;
- case OMEM:
- fputs(symname(np->u.sym), stdout);
- break;
- default:
- emittree(np->left);
- printf(" %c ", np->op);
- emittree(np->right);
- break;
- }
-}
-static void
-size2asm(Type *tp)
-{
- char *s;
-
- if (tp->flags & STRF) {
- s = "\t.ascii\t";
- } else {
- switch (tp->size) {
- case 1:
- s = "\t.byte\t";
- break;
- case 2:
- s = "\t.short\t";
- break;
- case 4:
- s = "\t.long\t";
- break;
- case 8:
- s = "\t.quad\t";
- break;
- default:
- s = "\t.space\t%lu,";
- break;
- }
- }
- printf(s, tp->size);
-}
-
-void
-data(Node *np)
-{
- size2asm(&np->type);
- emittree(np);
- putchar('\n');
-}
-
-static void
-label(Symbol *sym)
-{
- int seg;
- char *name = symname(sym);
- Type *tp = &sym->type;
-
- if (sym->type.flags & FUNF)
- seg = CODESEG;
- else if (sym->type.flags & INITF)
- seg = DATASEG;
- else
- seg = BSSSEG;
- segment(seg);
-
- switch (sym->kind) {
- case SEXTRN:
- printf("\t.extern\t%s\n", name);
- case SLOCAL:
- return;
- case SGLOB:
- printf("\t.global\t%s\n", name);
- if (seg == BSSSEG)
- printf("\t.comm\t%s,%lu\n", name, tp->size);
- break;
- }
- if (sym->type.align != 1)
- printf("\t.align\t%lu\n", sym->type.align );
- printf("%s:\n", name);
-}
-
-void
-defglobal(Symbol *sym)
-{
- label(sym);
- if (sym->kind == SEXTRN || (sym->type.flags & INITF))
- return;
- size2asm(&sym->type);
- puts("0");
-}
-
-void
-defpar(Symbol *sym)
-{
-}
-
-void
-defvar(Symbol *sym)
-{
-}
-
-void
-newfun(void)
-{
-}
-
-void
-writeout(void)
-{
-}
-
-void
-endinit(void)
-{
-}
-
-void
-getbblocks(void)
-{
-}
--- a/cc2/arch/i386-sysv/optm.c
+++ /dev/null
@@ -1,11 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-static char sccsid[] = "@(#) ./cc2/arch/i386-sysv/optm.c";
-
-#include "../../../inc/cc.h"
-#include "../../cc2.h"
-
-Node *
-optm_dep(Node *np)
-{
- return np;
-}
--- a/cc2/arch/i386-sysv/types.c
+++ /dev/null
@@ -1,95 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-static char sccsid[] = "@(#) ./cc2/arch/i386-sysv/types.c";
-
-#include "../../../inc/cc.h"
-#include "../../cc2.h"
-
-
-Type int8type = {
- .flags = SIGNF | INTF,
- .size = 1,
- .align = 1
-};
-
-Type int16type = {
- .flags = SIGNF | INTF,
- .size = 2,
- .align = 2
-};
-
-Type int32type = {
- .flags = SIGNF | INTF,
- .size = 4,
- .align = 4
-};
-
-Type int64type = {
- .flags = SIGNF | INTF,
- .size = 8,
- .align = 4
-};
-
-Type uint8type = {
- .flags = INTF,
- .size = 1,
- .align = 1
-};
-
-Type uint16type = {
- .flags = INTF,
- .size = 2,
- .align = 2
-};
-
-Type uint32type = {
- .flags = INTF,
- .size = 4,
- .align = 2
-};
-
-Type uint64type = {
- .flags = INTF,
- .size = 8,
- .align = 4
-};
-
-Type ptrtype = {
- .flags = INTF,
- .size = 4,
- .align = 4
-};
-
-Type booltype = {
- .flags = INTF,
- .size = 1,
- .align = 1
-};
-
-Type float32type = {
- .flags = FLOATF,
- .size = 4,
- .align = 4
-};
-
-Type float64type = {
- .flags = FLOATF,
- .size = 8,
- .align = 4
-};
-
-Type float80type = {
- .flags = FLOATF,
- .size = 12,
- .align = 4
-};
-
-Type voidtype = {
- .size = 0,
- .align = 0
-};
-
-/* this type is not used in this architecture */
-Type arg_type = {
- .size = 0,
- .align = 0
-};
--- a/cc2/arch/qbe/arch.h
+++ /dev/null
@@ -1,137 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-enum asmop {
- ASNOP = 0,
- ASSTB,
- ASSTH,
- ASSTW,
- ASSTL,
- ASSTM,
- ASSTS,
- ASSTD,
-
- ASLDSB,
- ASLDUB,
- ASLDSH,
- ASLDUH,
- ASLDSW,
- ASLDUW,
- ASLDL,
- ASLDS,
- ASLDD,
-
- ASADDW,
- ASSUBW,
- ASMULW,
- ASMODW,
- ASUMODW,
- ASDIVW,
- ASUDIVW,
- ASSHLW,
- ASSHRW,
- ASUSHRW,
- ASLTW,
- ASULTW,
- ASGTW,
- ASUGTW,
- ASLEW,
- ASULEW,
- ASGEW,
- ASUGEW,
- ASEQW,
- ASNEW,
- ASBANDW,
- ASBORW,
- ASBXORW,
-
- ASADDL,
- ASSUBL,
- ASMULL,
- ASMODL,
- ASUMODL,
- ASDIVL,
- ASUDIVL,
- ASSHLL,
- ASSHRL,
- ASUSHRL,
- ASLTL,
- ASULTL,
- ASGTL,
- ASUGTL,
- ASLEL,
- ASULEL,
- ASGEL,
- ASUGEL,
- ASEQL,
- ASNEL,
- ASBANDL,
- ASBORL,
- ASBXORL,
-
- ASADDS,
- ASSUBS,
- ASMULS,
- ASDIVS,
- ASLTS,
- ASGTS,
- ASLES,
- ASGES,
- ASEQS,
- ASNES,
-
- ASADDD,
- ASSUBD,
- ASMULD,
- ASDIVD,
- ASLTD,
- ASGTD,
- ASLED,
- ASGED,
- ASEQD,
- ASNED,
-
- ASEXTBW,
- ASUEXTBW,
- ASEXTBL,
- ASUEXTBL,
- ASEXTHW,
- ASUEXTHW,
- ASEXTHL,
- ASUEXTHL,
- ASEXTWL,
- ASUEXTWL,
-
- ASSTOL,
- ASSTOW,
- ASDTOL,
- ASDTOW,
-
- ASSWTOD,
- ASSWTOS,
- ASSLTOD,
- ASSLTOS,
-
- ASEXTS,
- ASTRUNCD,
-
- ASJMP,
- ASBRANCH,
- ASRET,
- ASCALL,
- ASCALLE,
- ASCALLEX,
- ASPAR,
- ASPARE,
- ASALLOC,
- ASFORM,
-
- ASCOPYB,
- ASCOPYH,
- ASCOPYW,
- ASCOPYL,
- ASCOPYS,
- ASCOPYD,
-
- ASVSTAR,
- ASVARG,
-};
--- a/cc2/arch/qbe/cgen.c
+++ /dev/null
@@ -1,731 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-static char sccsid[] = "@(#) ./cc2/arch/qbe/cgen.c";
-
-#include <assert.h>
-#include <stdlib.h>
-
-#include <cstd.h>
-#include "arch.h"
-#include "../../../inc/cc.h"
-#include "../../cc2.h"
-
-enum sflags {
- ISTMP = 1,
- ISCONS = 2
-};
-
-static char opasmw[] = {
- [OADD] = ASADDW,
- [OSUB] = ASSUBW,
- [OMUL] = ASMULW,
- [OMOD] = ASMODW,
- [ODIV] = ASDIVW,
- [OSHL] = ASSHLW,
- [OSHR] = ASSHRW,
- [OLT] = ASLTW,
- [OGT] = ASGTW,
- [OLE] = ASLEW,
- [OGE] = ASGEW,
- [OEQ] = ASEQW,
- [ONE] = ASNEW,
- [OBAND] = ASBANDW,
- [OBOR] = ASBORW,
- [OBXOR] = ASBXORW,
-};
-
-static char opasml[] = {
- [OADD] = ASADDL,
- [OSUB] = ASSUBL,
- [OMUL] = ASMULL,
- [OMOD] = ASMODL,
- [ODIV] = ASDIVL,
- [OSHL] = ASSHLL,
- [OSHR] = ASSHRL,
- [OLT] = ASLTL,
- [OGT] = ASGTL,
- [OLE] = ASLEL,
- [OGE] = ASGEL,
- [OEQ] = ASEQL,
- [ONE] = ASNEL,
- [OBAND] = ASBANDL,
- [OBOR] = ASBORL,
- [OBXOR] = ASBXORL,
-};
-
-static char opasms[] = {
- [OADD] = ASADDS,
- [OSUB] = ASSUBS,
- [OMUL] = ASMULS,
- [ODIV] = ASDIVS,
- [OLT] = ASLTS,
- [OGT] = ASGTS,
- [OLE] = ASLES,
- [OGE] = ASGES,
- [OEQ] = ASEQS,
- [ONE] = ASNES,
-};
-static char opasmd[] = {
- [OADD] = ASADDD,
- [OSUB] = ASSUBD,
- [OMUL] = ASMULD,
- [ODIV] = ASDIVD,
- [OLT] = ASLTD,
- [OGT] = ASGTD,
- [OLE] = ASLED,
- [OGE] = ASGED,
- [OEQ] = ASEQD,
- [ONE] = ASNED,
-};
-
-extern Type int32type, uint32type, ptrtype;
-
-static Node *
-tmpnode(Node *np, Type *tp)
-{
- char flags;
- Symbol *sym;
-
- if (!np)
- np = newnode(OTMP);
- sym = getsym(TMPSYM);
- sym->type = np->type = *tp;
- flags = tp->flags & ~(PARF|INITF);
- sym->type.flags = np->type.flags = flags;
- sym->kind = STMP;
- np->left = np->right = NULL;
- np->u.sym = sym;
- np->op = OTMP;
- np->flags |= ISTMP;
- return np;
-}
-
-static Node *
-load(Type *tp, Node *np, Node *new)
-{
- int op;
- int flags = tp->flags;
-
- if (flags & (AGGRF|FUNF)) {
- *new = *np;
- return new;
- }
- switch (tp->size) {
- case 1:
- op = ASLDSB;
- break;
- case 2:
- op = ASLDSH;
- break;
- case 4:
- op = (flags & FLOATF) ? ASLDS : ASLDSW;
- break;
- case 8:
- op = (flags & FLOATF) ? ASLDD : ASLDL;
- break;
- default:
- abort();
- }
- /*
- * unsigned version of operations are always +1 the
- * signed version
- */
- if ((flags & (INTF|SIGNF)) == INTF && tp->size < 8)
- ++op;
-
- code(op, tmpnode(new, tp), np, NULL);
-
- return new;
-}
-
-static Node *rhs(Node *np, Node *new);
-
-static Node *
-cast(Type *td, Node *ns, Node *nd)
-{
- Type *ts;
- Node aux1, aux2;
- int op, d_isint, s_isint;
-
- ts = &ns->type;
- d_isint = (td->flags & INTF) != 0;
- s_isint = (ts->flags & INTF) != 0;
-
- if (d_isint && s_isint) {
- if (td->size <= ts->size) {
- *nd = *ns;
- return nd;
- }
- assert(td->size == 4 || td->size == 8);
- switch (ts->size) {
- case 1:
- op = (td->size == 4) ? ASEXTBW : ASEXTBL;
- break;
- case 2:
- op = (td->size == 4) ? ASEXTHW : ASEXTHL;
- break;
- case 4:
- op = ASEXTWL;
- break;
- default:
- abort();
- }
- /*
- * unsigned version of operations are always +1 the
- * signed version
- */
- op += (ts->flags & SIGNF) == 0;
- } else if (d_isint) {
- /* conversion from float to int */
- switch (ts->size) {
- case 4:
- op = (td->size == 8) ? ASSTOL : ASSTOW;
- break;
- case 8:
- op = (td->size == 8) ? ASDTOL : ASDTOW;
- break;
- default:
- abort();
- }
- /* TODO: Add signess */
- } else if (s_isint) {
- /* conversion from int to float */
- switch (ts->size) {
- case 1:
- case 2:
- ts = (ts->flags&SIGNF) ? &int32type : &uint32type;
- ns = cast(ts, ns, tmpnode(&aux2, ts));
- case 4:
- op = (td->size == 8) ? ASSWTOD : ASSWTOS;
- break;
- case 8:
- op = (td->size == 8) ? ASSLTOD : ASSLTOS;
- break;
- default:
- abort();
- }
- /* TODO: Add signess */
- } else {
- /* conversion from float to float */
- op = (td->size == 4) ? ASEXTS : ASTRUNCD;
- }
-
- code(op, tmpnode(nd, td), ns, NULL);
- return nd;
-}
-
-static Node *rhs(Node *np, Node *new);
-
-static Node *
-call(Node *np, Node *fun, Node *ret)
-{
- int n, op;
- Type *tp;
- Node aux, **q, *p, *pars[NR_FUNPARAM];
-
- for (n = 0, p = np->right; p; p = p->right)
- pars[n++] = rhs(p->left, newnode(OTMP));
-
- tp = &np->type;
- code(ASCALL, tmpnode(ret, tp), fun, NULL);
-
- for (q = pars; q < &pars[n]; ++q) {
- op = (q == &pars[n-1]) ? ASPARE : ASPAR;
- tmpnode(&aux, &(*q)->type);
- code(op, NULL, *q, &aux);
- }
- code((np->op == OCALL) ? ASCALLE : ASCALLEX, NULL, NULL, NULL);
-
- return ret;
-}
-
-static Node *
-assign(Type *tp, Node *to, Node *from)
-{
- int op;
-
- switch (tp->size) {
- case 1:
- op = ASSTB;
- break;
- case 2:
- op = ASSTH;
- break;
- case 4:
- op = (tp->flags & FLOATF) ? ASSTS : ASSTW;
- break;
- case 8:
- op = (tp->flags & FLOATF) ? ASSTD : ASSTL;
- break;
- default:
- op = ASSTM;
- break;
- }
- code(op, to, from, NULL);
- return from;
-}
-
-static Node *
-copy(Type *tp, Node *to, Node *from)
-{
- int op;
-
- switch (tp->size) {
- case 1:
- op = ASCOPYB;
- break;
- case 2:
- op = ASCOPYH;
- break;
- case 4:
- op = (tp->flags & FLOATF) ? ASCOPYS : ASCOPYW;
- break;
- case 8:
- op = (tp->flags & FLOATF) ? ASCOPYD : ASCOPYL;
- break;
- default:
- /* TODO: Need to handle the general case */
- abort();
- }
- code(op, to, from, NULL);
- return from;
-}
-
-/* TODO: Do field() transformation in sethi */
-
-static Node *
-field(Node *np, Node *ret, int islhs)
-{
- Node base, node, off, add, *addr;
- TUINT offset = np->right->u.sym->u.off;
-
- addr = rhs(np->left, &base);
-
- if (offset != 0) {
- node.op = OADD;
- node.type = ptrtype;
- node.left = addr;
- node.right = constnode(&off, offset, &ptrtype);
- addr = rhs(&node, &add);
- }
-
- if (islhs)
- *ret = *addr;
- else
- load(&np->type, addr, ret);
-
- return ret;
-}
-
-static Node *
-lhs(Node *np, Node *new)
-{
- switch (np->op) {
- case OMEM:
- case OAUTO:
- *new = *np;
- return new;
- case OPTR:
- return rhs(np->left, new);
- case OFIELD:
- return field(np, new, 1);
- default:
- abort();
- }
-}
-
-static void
-bool(Node *np, Symbol *true, Symbol *false)
-{
- Node *l = np->left, *r = np->right;
- Node ret, ifyes, ifno;
- Symbol *label;
-
- switch (np->op) {
- case ONEG:
- bool(l, false, true);
- break;
- case OAND:
- label = newlabel();
- bool(l, label, false);
- setlabel(label);
- bool(r, true, false);
- break;
- case OOR:
- label = newlabel();
- bool(l, true, label);
- setlabel(label);
- bool(r, true, false);
- break;
- default:
- label2node(&ifyes, true);
- label2node(&ifno, false);
- code(ASBRANCH, rhs(np, &ret), &ifyes, &ifno);
- break;
- }
-}
-
-static Node *
-ternary(Node *np, Node *ret)
-{
- Node ifyes, ifno, phi, *colon, aux1, aux2, aux3;
-
- tmpnode(ret, &np->type);
- label2node(&ifyes, NULL);
- label2node(&ifno, NULL);
- label2node(&phi, NULL);
-
- colon = np->right;
- code(ASBRANCH, rhs(np->left, &aux1), &ifyes, &ifno);
-
- setlabel(ifyes.u.sym);
- copy(&ret->type, ret, rhs(colon->left, &aux2));
- code(ASJMP, NULL, &phi, NULL);
-
- setlabel(ifno.u.sym);
- copy(&ret->type, ret, rhs(colon->right, &aux3));
- setlabel(phi.u.sym);
-
- return ret;
-}
-
-static Node *
-function(void)
-{
- Node aux;
- Symbol *p;
-
- /* allocate stack space for parameters */
- for (p = locals; p && (p->type.flags & PARF) != 0; p = p->next)
- code(ASALLOC, label2node(&aux, p), NULL, NULL);
-
- /* allocate stack space for local variables) */
- for ( ; p && p->id != TMPSYM; p = p->next) {
- if (p->kind != SAUTO)
- continue;
- code(ASALLOC, label2node(&aux, p), NULL, NULL);
- }
- /* store formal parameters in parameters */
- for (p = locals; p; p = p->next) {
- if ((p->type.flags & PARF) == 0)
- break;
- code(ASFORM, label2node(&aux, p), NULL, NULL);
- }
- return NULL;
-}
-
-static void
-swtch_if(Node *idx)
-{
- Node aux1, aux2, *np;
- Symbol *deflabel = NULL;
-
- for (;;) {
- np = delstmt();
- setlabel(np->label);
-
- switch (np->op) {
- case OESWITCH:
- if (!deflabel)
- deflabel = np->u.sym;
- aux1.op = OJMP;
- aux1.label = NULL;
- aux1.u.sym = deflabel;
- cgen(&aux1);
- return;
- case OCASE:
- aux1 = *np;
- aux1.op = OBRANCH;
- aux1.label = NULL;
- aux1.left = &aux2;
-
- aux2.op = OEQ;
- aux2.type = idx->type;
- aux2.left = np->left;
- aux2.right = idx;
-
- cgen(&aux1);
- break;
- case ODEFAULT:
- deflabel = np->u.sym;
- break;
- default:
- abort();
- }
- }
-}
-
-static Node *
-rhs(Node *np, Node *ret)
-{
- Node aux1, aux2, *phi, *l = np->left, *r = np->right;
- Type *tp;
- int off, op;
- char *tbl;
- Symbol *true, *false;
-
- tp = &np->type;
-
- switch (np->op) {
- case OBFUN:
- return function();
- case ONOP:
- case OBLOOP:
- case OELOOP:
- case OEFUN:
- return NULL;
- case OTMP:
- case OCONST:
- *ret = *np;
- return np;
- case OMEM:
- case OAUTO:
- return load(tp, np, ret);
- case ONEG:
- case OAND:
- case OOR:
- true = newlabel();
- false = newlabel();
- phi = label2node(&aux1, NULL);
- tmpnode(ret, &int32type);
-
- bool(np, true, false);
-
- setlabel(true);
- code(ASCOPYW, ret, constnode(&aux2, 1, &int32type), NULL);
- code(ASJMP, NULL, phi, NULL);
-
- setlabel(false);
- code(ASCOPYW, ret, constnode(&aux2, 0, &int32type), NULL);
-
- setlabel(phi->u.sym);
- return ret;
- case OMOD:
- case OSHR:
- assert(tp->flags & INTF);
- case ODIV:
- case OLT:
- case OGT:
- case OLE:
- case OGE:
- /*
- * unsigned version of operations are always +1 the
- * signed version
- */
- off = (tp->flags & SIGNF) == 0;
- goto binary;
- case OSHL:
- case OBAND:
- case OBOR:
- case OBXOR:
- assert(tp->flags & INTF);
- case OADD:
- case OSUB:
- case OMUL:
- case OEQ:
- case ONE:
- off = 0;
- binary:
- if (l->complex >= r->complex) {
- rhs(l, &aux1);
- rhs(r, &aux2);
- } else {
- rhs(r, &aux2);
- rhs(l, &aux1);
- }
- switch (tp->size) {
- case 4:
- tbl = (tp->flags & FLOATF) ? opasms : opasmw;
- break;
- case 8:
- tbl = (tp->flags & FLOATF) ? opasmd : opasml;
- break;
- default:
- abort();
- }
- op = tbl[np->op] + off;
- tmpnode(ret, tp);
- code(op, ret, &aux1, &aux2);
- return ret;
- case OCALL:
- case OCALLE:
- if (l->op == OPTR)
- l = rhs(l, &aux1);
- return call(np, l, ret);
- case OCAST:
- return cast(tp, rhs(l, &aux1), ret);
- case OASSIG:
- /* TODO: Do this transformations in sethi */
- switch (np->u.subop) {
- case OINC:
- op = OADD;
- goto post_oper;
- case ODEC:
- op = OSUB;
- post_oper:
- aux1.op = op;
- aux1.left = rhs(l, ret);
- aux1.right = r;
- aux1.type = np->type;
- rhs(&aux1, &aux2);
- lhs(l, &aux1);
- assign(tp, &aux1, &aux2);
- break;
- default:
- aux2.type = np->type;
- aux2.op = np->u.subop;
- aux2.right = np->right;
- aux2.left = np->left;
- r = rhs(&aux2, &aux1);
- Node aux3;
- if (l->op == OCAST) {
- aux3.type = l->left->type;
- aux3.op = OCAST;
- aux3.left = r;
- aux3.right = NULL;
- r = &aux3;
- l = l->left;
- }
- case 0:
- /* TODO: see what is the most difficult */
- lhs(l, &aux2);
- rhs(r, ret);
- return assign(tp, &aux2, ret);
- }
- return ret;
- case OASK:
- return ternary(np, ret);
- case OCOMMA:
- rhs(l, &aux1);
- return rhs(r, ret);
- case OPTR:
- return load(tp, rhs(l, &aux1), ret);
- case OADDR:
- lhs(l, ret);
- ret->type = *tp;
- return ret;
- case OFIELD:
- return field(np, ret, 0);
- case OBUILTIN:
- switch (np->u.subop) {
- case BVA_START:
- l = rhs(l, &aux1);
- code(ASVSTAR, NULL, l, NULL);
- return NULL;
- case BVA_END:
- return NULL;
- case BVA_ARG:
- l = rhs(l, &aux1);
- code(ASVARG, tmpnode(ret, tp), l, NULL);
- return ret;
- case BVA_COPY:
- /* TODO */
- default:
- abort();
- }
- default:
- abort();
- }
- abort();
-}
-
-Node *
-cgen(Node *np)
-{
- Node aux, *p, *next;
-
- setlabel(np->label);
- switch (np->op) {
- case OJMP:
- label2node(&aux, np->u.sym);
- code(ASJMP, NULL, &aux, NULL);
- break;
- case OBRANCH:
- next = np->next;
- if (!next->label)
- next->label = newlabel();
- bool(np->left, np->u.sym, next->label);
- break;
- case ORET:
- p = (np->left) ? rhs(np->left, &aux) : NULL;
- code(ASRET, NULL, p, NULL);
- break;
- case OBSWITCH:
- p = rhs(np->left, &aux);
- swtch_if(p);
- break;
- default:
- rhs(np, &aux);
- break;
- }
- return NULL;
-}
-
-/*
- * This is strongly influenced by
- * http://plan9.bell-labs.com/sys/doc/compiler.ps (/sys/doc/compiler.ps)
- * calculate addresability as follows
- * AUTO => 11 value+fp
- * REG => 11 reg
- * STATIC => 11 (value)
- * CONST => 11 $value
- * These values of addressability are not used in the code generation.
- * They are only used to calculate the Sethi-Ullman numbers. Since
- * QBE is AMD64 targered we could do a better job there, and try to
- * detect some of the complex addressing modes of these processors.
- */
-Node *
-sethi(Node *np)
-{
- Node *lp, *rp;
-
- if (!np)
- return np;
-
- np->complex = 0;
- np->address = 0;
- lp = np->left;
- rp = np->right;
-
- switch (np->op) {
- case OAUTO:
- case OREG:
- case OMEM:
- case OCONST:
- np->address = 11;
- break;
- case OCPL:
- assert(np->type.flags & INTF);
- np->op = OBXOR;
- rp = constnode(NULL, ~(TUINT) 0, &np->type);
- goto binary;
- case OSNEG:
- np->op = OSUB;
- rp = lp;
- lp = constnode(NULL, 0, &np->type);
- if ((np->type.flags & INTF) == 0)
- lp->u.f = 0.0;
- default:
- binary:
- lp = sethi(lp);
- rp = sethi(rp);
- break;
- }
- np->left = lp;
- np->right = rp;
-
- if (np->address > 10)
- return np;
- if (lp)
- np->complex = lp->complex;
- if (rp) {
- int d = np->complex - rp->complex;
-
- if (d == 0)
- ++np->complex;
- else if (d < 0)
- np->complex = rp->complex;
- }
- if (np->complex == 0)
- ++np->complex;
- return np;
-}
--- a/cc2/arch/qbe/code.c
+++ /dev/null
@@ -1,569 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-static char sccsid[] = "@(#) ./cc2/arch/qbe/code.c";
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <cstd.h>
-#include "arch.h"
-#include "../../../inc/cc.h"
-#include "../../cc2.h"
-
-#define ADDR_LEN (INTIDENTSIZ+64)
-
-static void binary(void), unary(void), store(void), jmp(void), ret(void),
- branch(void), call(void), ecall(void), param(void),
- alloc(void), form2local(void), ldir(void), vastart(void),
- vaarg(void);
-
-static struct opdata {
- void (*fun)(void);
- char *txt;
- char letter;
-} optbl [] = {
- [ASLDSB] = {.fun = unary, .txt = "loadsb", .letter = 'w'},
- [ASLDUB] = {.fun = unary, .txt = "loadub", .letter = 'w'},
- [ASLDSH] = {.fun = unary, .txt = "loadsh", .letter = 'w'},
- [ASLDUH] = {.fun = unary, .txt = "loaduh", .letter = 'w'},
- [ASLDSW] = {.fun = unary, .txt = "loadsw", .letter = 'w'},
- [ASLDUW] = {.fun = unary, .txt = "loaduw", .letter = 'w'},
- [ASLDL] = {.fun = unary, .txt = "loadl", .letter = 'l'},
- [ASLDS] = {.fun = unary, .txt = "loads", .letter = 's'},
- [ASLDD] = {.fun = unary, .txt = "loadd", .letter = 'd'},
-
- [ASCOPYB] = {.fun = unary, .txt = "copy", .letter = 'b'},
- [ASCOPYH] = {.fun = unary, .txt = "copy", .letter = 'h'},
- [ASCOPYW] = {.fun = unary, .txt = "copy", .letter = 'w'},
- [ASCOPYL] = {.fun = unary, .txt = "copy", .letter = 'l'},
- [ASCOPYS] = {.fun = unary, .txt = "copy", .letter = 's'},
- [ASCOPYD] = {.fun = unary, .txt = "copy", .letter = 'd'},
-
- [ASSTB] = {.fun = store, .txt = "store", .letter = 'b'},
- [ASSTH] = {.fun = store, .txt = "store", .letter = 'h'},
- [ASSTW] = {.fun = store, .txt = "store", .letter = 'w'},
- [ASSTL] = {.fun = store, .txt = "store", .letter = 'l'},
- [ASSTM] = {.fun = ldir},
- [ASSTS] = {.fun = store, .txt = "store", .letter = 's'},
- [ASSTD] = {.fun = store, .txt = "store", .letter = 'd'},
-
- [ASADDW] = {.fun = binary, .txt = "add", .letter = 'w'},
- [ASSUBW] = {.fun = binary, .txt = "sub", .letter = 'w'},
- [ASMULW] = {.fun = binary, .txt = "mul", .letter = 'w'},
- [ASMODW] = {.fun = binary, .txt = "rem", .letter = 'w'},
- [ASUMODW] = {.fun = binary, .txt = "urem", .letter = 'w'},
- [ASDIVW] = {.fun = binary, .txt = "div", .letter = 'w'},
- [ASUDIVW] = {.fun = binary, .txt = "udiv", .letter = 'w'},
- [ASSHLW] = {.fun = binary, .txt = "shl", .letter = 'w'},
- [ASSHRW] = {.fun = binary, .txt = "sar", .letter = 'w'},
- [ASUSHRW] = {.fun = binary, .txt = "shr", .letter = 'w'},
- [ASLTW] = {.fun = binary, .txt = "csltw", .letter = 'w'},
- [ASULTW] = {.fun = binary, .txt = "cultw", .letter = 'w'},
- [ASGTW] = {.fun = binary, .txt = "csgtw", .letter = 'w'},
- [ASUGTW] = {.fun = binary, .txt = "cugtw", .letter = 'w'},
- [ASLEW] = {.fun = binary, .txt = "cslew", .letter = 'w'},
- [ASULEW] = {.fun = binary, .txt = "culew", .letter = 'w'},
- [ASGEW] = {.fun = binary, .txt = "csgew", .letter = 'w'},
- [ASUGEW] = {.fun = binary, .txt = "cugew", .letter = 'w'},
- [ASEQW] = {.fun = binary, .txt = "ceqw", .letter = 'w'},
- [ASNEW] = {.fun = binary, .txt = "cnew", .letter = 'w'},
- [ASBANDW] = {.fun = binary, .txt = "and", .letter = 'w'},
- [ASBORW] = {.fun = binary, .txt = "or", .letter = 'w'},
- [ASBXORW] = {.fun = binary, .txt = "xor", .letter = 'w'},
-
- [ASADDL] = {.fun = binary, .txt = "add", .letter = 'l'},
- [ASSUBL] = {.fun = binary, .txt = "sub", .letter = 'l'},
- [ASMULL] = {.fun = binary, .txt = "mul", .letter = 'l'},
- [ASMODL] = {.fun = binary, .txt = "rem", .letter = 'l'},
- [ASUMODL] = {.fun = binary, .txt = "urem", .letter = 'l'},
- [ASDIVL] = {.fun = binary, .txt = "div", .letter = 'l'},
- [ASUDIVL] = {.fun = binary, .txt = "udiv", .letter = 'l'},
- [ASSHLL] = {.fun = binary, .txt = "shl", .letter = 'l'},
- [ASSHRL] = {.fun = binary, .txt = "sar", .letter = 'l'},
- [ASUSHRL] = {.fun = binary, .txt = "shr", .letter = 'l'},
- [ASLTL] = {.fun = binary, .txt = "csltl", .letter = 'w'},
- [ASULTL] = {.fun = binary, .txt = "cultl", .letter = 'w'},
- [ASGTL] = {.fun = binary, .txt = "csgtl", .letter = 'w'},
- [ASUGTL] = {.fun = binary, .txt = "cugtl", .letter = 'w'},
- [ASLEL] = {.fun = binary, .txt = "cslel", .letter = 'w'},
- [ASULEL] = {.fun = binary, .txt = "culel", .letter = 'w'},
- [ASGEL] = {.fun = binary, .txt = "csgel", .letter = 'w'},
- [ASUGEL] = {.fun = binary, .txt = "cugel", .letter = 'w'},
- [ASEQL] = {.fun = binary, .txt = "ceql", .letter = 'w'},
- [ASNEL] = {.fun = binary, .txt = "cnel", .letter = 'w'},
- [ASBANDL] = {.fun = binary, .txt = "and", .letter = 'l'},
- [ASBORL] = {.fun = binary, .txt = "or", .letter = 'l'},
- [ASBXORL] = {.fun = binary, .txt = "xor", .letter = 'l'},
-
- [ASADDS] = {.fun = binary, .txt = "add", .letter = 's'},
- [ASSUBS] = {.fun = binary, .txt = "sub", .letter = 's'},
- [ASMULS] = {.fun = binary, .txt = "mul", .letter = 's'},
- [ASDIVS] = {.fun = binary, .txt = "div", .letter = 's'},
- [ASLTS] = {.fun = binary, .txt = "clts", .letter = 'w'},
- [ASGTS] = {.fun = binary, .txt = "cgts", .letter = 'w'},
- [ASLES] = {.fun = binary, .txt = "cles", .letter = 'w'},
- [ASGES] = {.fun = binary, .txt = "cges", .letter = 'w'},
- [ASEQS] = {.fun = binary, .txt = "ceqs", .letter = 'w'},
- [ASNES] = {.fun = binary, .txt = "cnes", .letter = 'w'},
-
- [ASADDD] = {.fun = binary, .txt = "add", .letter = 'd'},
- [ASSUBD] = {.fun = binary, .txt = "sub", .letter = 'd'},
- [ASMULD] = {.fun = binary, .txt = "mul", .letter = 'd'},
- [ASDIVD] = {.fun = binary, .txt = "div", .letter = 'd'},
- [ASLTD] = {.fun = binary, .txt = "cltd", .letter = 'w'},
- [ASGTD] = {.fun = binary, .txt = "cgtd", .letter = 'w'},
- [ASLED] = {.fun = binary, .txt = "cled", .letter = 'w'},
- [ASGED] = {.fun = binary, .txt = "cged", .letter = 'w'},
- [ASEQD] = {.fun = binary, .txt = "ceqd", .letter = 'w'},
- [ASNED] = {.fun = binary, .txt = "cned", .letter = 'w'},
-
- [ASEXTBW] = {.fun = unary, .txt = "extsb", .letter = 'w'},
- [ASUEXTBW]= {.fun = unary, .txt = "extub", .letter = 'w'},
- [ASEXTBL] = {.fun = unary, .txt = "extsb", .letter = 'l'},
- [ASUEXTBL]= {.fun = unary, .txt = "extub", .letter = 'l'},
- [ASEXTHW] = {.fun = unary, .txt = "extsh", .letter = 'w'},
- [ASUEXTHW]= {.fun = unary, .txt = "extuh", .letter = 'w'},
- [ASEXTWL] = {.fun = unary, .txt = "extsw", .letter = 'l'},
- [ASUEXTWL]= {.fun = unary, .txt = "extuw", .letter = 'l'},
-
- [ASSTOL] = {.fun = unary, .txt = "stosi", .letter = 'l'},
- [ASSTOW] = {.fun = unary, .txt = "stosi", .letter = 'w'},
- [ASDTOL] = {.fun = unary, .txt = "dtosi", .letter = 'l'},
- [ASDTOW] = {.fun = unary, .txt = "dtosi", .letter = 'w'},
-
- [ASSWTOD] = {.fun = unary, .txt = "swtof", .letter = 'd'},
- [ASSWTOS] = {.fun = unary, .txt = "swtof", .letter = 's'},
- [ASSLTOD] = {.fun = unary, .txt = "sltof", .letter = 'd'},
- [ASSLTOS] = {.fun = unary, .txt = "sltof", .letter = 's'},
-
- [ASEXTS] = {.fun = unary, .txt = "exts", .letter = 'd'},
- [ASTRUNCD] = {.fun = unary, .txt = "truncd", .letter = 's'},
-
- [ASBRANCH] = {.fun = branch},
- [ASJMP] = {.fun = jmp},
- [ASRET] = {.fun = ret},
- [ASCALL] = {.fun = call},
- [ASCALLE] = {.fun = ecall, .txt = ")"},
- [ASCALLEX] = {.fun = ecall, .txt = ", ...)"},
- [ASPAR] = {.fun = param, .txt = "%s %s, "},
- [ASPARE] = {.fun = param, .txt = "%s %s"},
- [ASALLOC] = {.fun = alloc},
- [ASFORM] = {.fun = form2local},
-
- [ASVSTAR] = {.fun = vastart},
- [ASVARG] = {.fun = vaarg},
-};
-
-static char buff[ADDR_LEN];
-/*
- * : is for user-defined Aggregate Types
- * $ is for globals (represented by a pointer)
- * % is for function-scope temporaries
- * @ is for block labels
- */
-static char
-sigil(Symbol *sym)
-{
- switch (sym->kind) {
- case SEXTRN:
- case SGLOB:
- case SPRIV:
- case SLOCAL:
- return '$';
- case SAUTO:
- case STMP:
- return '%';
- case SLABEL:
- return '@';
- default:
- abort();
- }
-}
-
-static char *
-symname(Symbol *sym)
-{
- char c = sigil(sym);
-
- if (sym->name) {
- switch (sym->kind) {
- case SEXTRN:
- case SGLOB:
- sprintf(buff, "%c%s", c, sym->name);
- return buff;
- case SLOCAL:
- case SPRIV:
- case SAUTO:
- sprintf(buff, "%c%s.%u", c, sym->name, sym->id);
- return buff;
- default:
- abort();
- }
- }
- sprintf(buff, "%c.%u", c, sym->numid);
-
- return buff;
-}
-
-static void
-emitconst(Node *np)
-{
- switch (np->type.size) {
- case 1:
- printf("%d", (int) np->u.i & 0xFF);
- break;
- case 2:
- printf("%d", (int) np->u.i & 0xFFFF);
- break;
- case 4:
- printf("%ld", (long) np->u.i & 0xFFFFFFFF);
- break;
- case 8:
- printf("%lld", (long long) np->u.i);
- break;
- default:
- abort();
- }
-}
-
-static void
-emittree(Node *np)
-{
- if (!np)
- return;
-
- switch (np->op) {
- case OSTRING:
- printf("\"%s\"", np->u.s);
- free(np->u.s);
- np->u.s = NULL;
- break;
- case OCONST:
- emitconst(np);
- break;
- case OADDR:
- emittree(np->left);
- break;
- case OMEM:
- fputs(symname(np->u.sym), stdout);
- break;
- default:
- emittree(np->left);
- printf(" %c ", np->op);
- emittree(np->right);
- break;
- }
-}
-
-static char *
-size2asm(Type *tp)
-{
- if (tp->flags & STRF) {
- return "b";
- } else if (tp->flags & INTF) {
- switch (tp->size) {
- case 1:
- return "b";
- case 2:
- return "h";
- case 4:
- return "w";
- case 8:
- return "l";
- }
- } else if (tp->flags & FLOATF) {
- if (tp->size == 4)
- return "s";
- else if (tp->size == 8)
- return "d";
- }
- abort();
-}
-
-void
-defglobal(Symbol *sym)
-{
- if (sym->kind == SEXTRN)
- return;
- if (sym->kind == SGLOB)
- fputs("export ", stdout);
- printf("data %s = {\n", symname(sym));
- if (sym->type.flags & INITF)
- return;
- printf("\tz\t%lu\n}\n", sym->type.size);
-}
-
-void
-defpar(Symbol *sym)
-{
- sym->type.flags |= PARF;
-}
-
-void
-defvar(Symbol *sym)
-{
- if (sym->kind == SREG)
- sym->kind = SAUTO;
-}
-
-void
-data(Node *np)
-{
- printf("\t%s\t", size2asm(&np->type));
- emittree(np);
- putchar(',');
- putchar('\n');
-}
-
-static char *
-size2stack(Type *tp)
-{
- if (tp->flags & INTF) {
- switch (tp->size) {
- case 1:
- case 2:
- case 4:
- return "w";
- case 8:
- return "l";
- }
- } else if (tp->flags & FLOATF) {
- if (tp->size == 4)
- return "s";
- else if (tp->size == 8)
- return "d";
- } else if (tp->size == 0) {
- return "w";
- }
- abort();
-}
-
-void
-writeout(void)
-{
- Symbol *p;
- Type *tp;
- char *sep, *name;
- int haslabel = 0;
-
- if (!curfun)
- return;
- if (curfun->kind == SGLOB)
- fputs("export ", stdout);
- printf("function %s %s(", size2stack(&curfun->rtype), symname(curfun));
-
- /* declare formal parameters */
- for (sep = "", p = locals; p; p = p->next, sep = ",") {
- if ((p->type.flags & PARF) == 0)
- break;
- printf("%s%s %s.val", sep, size2stack(&p->type), symname(p));
- }
- printf("%s)\n{\n", (curfun->type.flags&ELLIPS) ? ", ..." : "");
-
- /* emit assembler instructions */
- for (pc = prog; pc; pc = pc->next) {
- if (pc->label) {
- haslabel = 1;
- printf("%s\n", symname(pc->label));
- }
- if (!pc->op)
- continue;
- if (pc->flags&BBENTRY && !haslabel)
- printf("%s\n", symname(newlabel()));
- (*optbl[pc->op].fun)();
- if (!pc->label)
- haslabel = 0;
- }
-
- puts("}");
-}
-
-static char *
-addr2txt(Addr *a)
-{
- switch (a->kind) {
- case SCONST:
- sprintf(buff, "%llu", (unsigned long long) a->u.i);
- return buff;
- case SAUTO:
- case SLABEL:
- case STMP:
- case SGLOB:
- case SEXTRN:
- case SPRIV:
- case SLOCAL:
- return symname(a->u.sym);
- default:
- abort();
- }
-}
-
-static void
-binary(void)
-{
- struct opdata *p = &optbl[pc->op];
- char to[ADDR_LEN], from1[ADDR_LEN], from2[ADDR_LEN];
-
- strcpy(to, addr2txt(&pc->to));
- strcpy(from1, addr2txt(&pc->from1));
- strcpy(from2, addr2txt(&pc->from2));
- printf("\t%s =%c\t%s\t%s,%s\n", to, p->letter, p->txt, from1, from2);
-}
-
-static void
-ldir(void)
-{
- struct opdata *p = &optbl[pc->op];
- char to[ADDR_LEN], from[ADDR_LEN];
- /* TODO: what type do we use for the size? */
-
- /* TODO: it is pending */
-}
-
-static void
-store(void)
-{
- struct opdata *p = &optbl[pc->op];
- char to[ADDR_LEN], from[ADDR_LEN];
-
- strcpy(to, addr2txt(&pc->to));
- strcpy(from, addr2txt(&pc->from1));
- printf("\t\t%s%c\t%s,%s\n", p->txt, p->letter, from, to);
-}
-
-static void
-unary(void)
-{
- struct opdata *p = &optbl[pc->op];
- char to[ADDR_LEN], from[ADDR_LEN];
-
- strcpy(to, addr2txt(&pc->to));
- strcpy(from, addr2txt(&pc->from1));
- printf("\t%s =%c\t%s\t%s\n", to, p->letter, p->txt, from);
-}
-
-static void
-call(void)
-{
- struct opdata *p = &optbl[pc->op];
- char to[ADDR_LEN], from[ADDR_LEN];
- Symbol *sym = pc->to.u.sym;
-
- strcpy(to, addr2txt(&pc->to));
- strcpy(from, addr2txt(&pc->from1));
- printf("\t%s =%s\tcall\t%s(",
- to, size2stack(&sym->type), from);
-}
-
-static void
-param(void)
-{
- Symbol *sym = pc->from2.u.sym;
-
- printf(optbl[pc->op].txt,
- size2stack(&sym->type), addr2txt(&pc->from1));
-}
-
-static void
-ecall(void)
-{
- struct opdata *p = &optbl[pc->op];
-
- puts(p->txt);
-}
-
-static void
-ret(void)
-{
- if (pc->from1.kind == SNONE)
- puts("\t\tret");
- else
- printf("\t\tret\t%s\n", addr2txt(&pc->from1));
-}
-
-static void
-jmp(void)
-{
- printf("\t\tjmp\t%s\n", addr2txt(&pc->from1));
-}
-
-static void
-branch(void)
-{
- char to[ADDR_LEN], from1[ADDR_LEN], from2[ADDR_LEN];
-
- strcpy(to, addr2txt(&pc->to));
- strcpy(from1, addr2txt(&pc->from1));
- strcpy(from2, addr2txt(&pc->from2));
- printf("\t\tjnz\t%s,%s,%s\n", to, from1, from2);
-}
-
-static void
-vastart(void)
-{
- printf("\t\tvastart %s\n", addr2txt(&pc->from1));
-}
-
-static void
-vaarg(void)
-{
- Symbol *sym = pc->to.u.sym;
- Type *tp = &sym->type;
- char to[ADDR_LEN], from[ADDR_LEN];
-
- strcpy(to, addr2txt(&pc->to));
- strcpy(from, addr2txt(&pc->from1));
- printf("\t\t%s =%s vaarg %s\n", to, size2asm(tp), from);
-}
-
-static void
-alloc(void)
-{
- Symbol *sym = pc->to.u.sym;
- Type *tp = &sym->type;
- extern Type ptrtype;
-
- printf("\t%s =%s\talloc%lu\t%lu\n",
- symname(sym), size2asm(&ptrtype), tp->align+3 & ~3, tp->size);
-}
-
-static void
-form2local(void)
-{
- Symbol *sym = pc->to.u.sym;
- Type *tp = &sym->type;
- char *name = symname(sym);
-
- printf("\t\tstore%s\t%s.val,%s\n", size2asm(tp), name, name);
-}
-
-void
-endinit(void)
-{
- puts("}");
-}
-
-void
-getbblocks(void)
-{
- Inst *i;
-
- if (!prog)
- return;
-
- prog->flags |= BBENTRY;
- for (pc = prog; pc; pc = pc->next) {
- switch (pc->op) {
- case ASBRANCH:
- i = pc->from2.u.sym->u.inst;
- i->flags |= BBENTRY;
- case ASJMP:
- i = pc->from1.u.sym->u.inst;
- i->flags |= BBENTRY;
- case ASRET:
- if (pc->next)
- pc->next->flags |= BBENTRY;
- break;
- }
- }
-}
--- a/cc2/arch/qbe/optm.c
+++ /dev/null
@@ -1,58 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-static char sccsid[] = "@(#) ./cc2/arch/qbe/optm.c";
-
-#include <stddef.h>
-
-#include "../../../inc/cc.h"
-#include "../../cc2.h"
-
-Node *
-optm_dep(Node *np)
-{
- int op = np->op;
- Node *p, *dst, *next = np->next;
- Symbol *sym, *osym;
-
- switch (op) {
- case OEFUN:
- /*
- * In QBE we need at the end of a basic block
- * a jump, so we have to ensure that the last
- * statement of the function is a ret, a jmp
- * or a branch. In the same way, QBE does
- * not accept labels at the end of a function
- * (ONOP is used for labels) so we have to add
- * a ret there, and in the case of branches
- * we need a label for the next statement
- */
- op = (np->prev) ? np->prev->op : 0;
- if (!op || op == ONOP || op == OBRANCH || (op != ORET && op != OJMP))
- addstmt(newnode(ORET), KEEPCUR);
- break;
- case OBRANCH:
- if (!next->label) {
- sym = getsym(TMPSYM);
- sym->kind = SLABEL;
- next->label = sym;
- }
- case OJMP:
- for (;;) {
- dst = np->u.sym->u.stmt;
- if (dst->op != OJMP)
- break;
- np->u.sym = dst->u.sym;
- }
- for (p = np->next; p; p = p->next) {
- if (p == dst)
- return NULL;
- if (p->op == ONOP ||
- p->op == OBLOOP ||
- p->op == OELOOP) {
- continue;
- }
- break;
- }
- break;
- }
- return np;
-}
--- a/cc2/arch/qbe/types.c
+++ /dev/null
@@ -1,94 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-static char sccsid[] = "@(#) ./cc2/arch/qbe/types.c";
-
-#include "../../../inc/cc.h"
-#include "../../cc2.h"
-
-
-Type int8type = {
- .flags = SIGNF | INTF,
- .size = 1,
- .align = 1
-};
-
-Type int16type = {
- .flags = SIGNF | INTF,
- .size = 2,
- .align = 2
-};
-
-Type int32type = {
- .flags = SIGNF | INTF,
- .size = 4,
- .align = 4
-};
-
-Type int64type = {
- .flags = SIGNF | INTF,
- .size = 8,
- .align = 8
-};
-
-Type uint8type = {
- .flags = INTF,
- .size = 1,
- .align = 1
-};
-
-Type uint16type = {
- .flags = INTF,
- .size = 2,
- .align = 2
-};
-
-Type uint32type = {
- .flags = INTF,
- .size = 4,
- .align = 4
-};
-
-Type uint64type = {
- .flags = INTF,
- .size = 8,
- .align = 2
-};
-
-Type ptrtype = {
- .flags = INTF,
- .size = 8,
- .align = 8
-};
-
-Type booltype = {
- .flags = INTF,
- .size = 1,
- .align = 1
-};
-
-Type float32type = {
- .flags = FLOATF,
- .size = 4,
- .align = 4
-};
-
-Type float64type = {
- .flags = FLOATF,
- .size = 8,
- .align = 8
-};
-
-Type float80type = {
- .flags = FLOATF,
- .size = 16,
- .align = 16
-};
-
-Type voidtype = {
- .size = 0,
- .align = 0
-};
-
-Type arg_type = {
- .size = 24,
- .align = 8
-};
--- a/cc2/arch/z80/arch.h
+++ /dev/null
@@ -1,1 +1,0 @@
-/* See LICENSE file for copyright and license details. */
--- a/cc2/arch/z80/cgen.c
+++ /dev/null
@@ -1,68 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-static char sccsid[] = "@(#) ./cc2/arch/z80/cgen.c";
-
-#include "arch.h"
-#include "../../../inc/cc.h"
-#include "../../cc2.h"
-
-Node *
-cgen(Node *np)
-{
-}
-
-/*
- * This is strongly influenced by
- * http://plan9.bell-labs.com/sys/doc/compiler.ps (/sys/doc/compiler.ps)
- * calculate addresability as follows
- * AUTO => 11 value+fp
- * REG => 13 reg
- * STATIC => 12 (value)
- * CONST => 20 $value
- */
-Node *
-sethi(Node *np)
-{
- Node *lp, *rp;
-
- if (!np)
- return np;
-
- np->complex = 0;
- np->address = 0;
- lp = np->left;
- rp = np->right;
- switch (np->op) {
- case OAUTO:
- np->address = 11;
- break;
- case OREG:
- np->address = 13;
- break;
- case OMEM:
- np->address = 12;
- break;
- case OCONST:
- np->address = 20;
- break;
- default:
- sethi(lp);
- sethi(rp);
- break;
- }
-
- if (np->address > 10)
- return np;
- if (lp)
- np->complex = lp->complex;
- if (rp) {
- int d = np->complex - rp->complex;
-
- if (d == 0)
- ++np->complex;
- else if (d < 0)
- np->complex = rp->complex;
- }
- if (np->complex == 0)
- ++np->complex;
- return np;
-}
--- a/cc2/arch/z80/code.c
+++ /dev/null
@@ -1,229 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-static char sccsid[] = "@(#) ./cc2/arch/z80/code.c";
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <cstd.h>
-#include "arch.h"
-#include "../../../inc/cc.h"
-#include "../../cc2.h"
-
-enum segment {
- CODESEG,
- DATASEG,
- BSSSEG,
- NOSEG
-};
-
-static int curseg = NOSEG;
-static unsigned long offpar, offvar;
-
-static void
-segment(int seg)
-{
- static char *txt[] = {
- [CODESEG] = "\tCSEG\n",
- [DATASEG] = "\tDSEG\n",
- [BSSSEG] = "\tASEG\n",
- };
-
- if (seg == curseg)
- return;
- fputs(txt[seg], stdout);
- curseg = seg;
-}
-
-static char *
-symname(Symbol *sym)
-{
- static char name[INTIDENTSIZ+1];
-
- if (sym->name) {
- switch (sym->kind) {
- case SGLOB:
- case SEXTRN:
- snprintf(name, sizeof(name), "_%s", sym->name);
- return name;
- case SPRIV:
- return sym->name;
- }
- }
-
- sprintf(name, ".%d", sym->numid);
-
- return name;
-}
-
-static void
-label(Symbol *sym)
-{
- int seg;
- char *name = symname(sym);
-
- if (sym->type.flags & FUNF)
- seg = CODESEG;
- else if (sym->type.flags & INITF)
- seg = DATASEG;
- else
- seg = BSSSEG;
- segment(seg);
-
- switch (sym->kind) {
- case SEXTRN:
- printf("\tEXTRN\t%s\n", name);
- return;
- case SGLOB:
- printf("\tPUBLIC\t%s\n", name);
- break;
- }
-
- printf("%s:\n", name);
-}
-
-static void
-emitconst(Node *np)
-{
- switch (np->type.size) {
- case 1:
- printf("%d", (int) np->u.i & 0xFF);
- break;
- case 2:
- printf("%d", (int) np->u.i & 0xFFFF);
- break;
- case 4:
- printf("%ld", (long) np->u.i & 0xFFFFFFFF);
- break;
- default:
- abort();
- }
-}
-
-static void
-emittree(Node *np)
-{
- if (!np)
- return;
-
- switch (np->op) {
- case OSTRING:
- printf("\"%s\"", np->u.s);
- free(np->u.s);
- np->u.s = NULL;
- break;
- case OCONST:
- emitconst(np);
- break;
- case OADDR:
- emittree(np->left);
- break;
- case OMEM:
- fputs(symname(np->u.sym), stdout);
- break;
- default:
- emittree(np->left);
- printf(" %c ", np->op);
- emittree(np->right);
- break;
- }
-}
-
-static void
-size2asm(Type *tp)
-{
- char *s;
-
- /*
- * In z80 we can ignore the alignment
- */
- if (tp->flags & STRF) {
- s = "\tDB\t";
- } else {
- switch (tp->size) {
- case 1:
- s = "\tDB\t";
- break;
- case 2:
- s = "\tDW\t";
- break;
- case 4:
- s = "\tDD\t";
- break;
- default:
- s = "\tDS\t%lu,";
- break;
- }
- }
- printf(s, tp->size);
-}
-
-void
-newfun()
-{
- offpar = offvar = 0;
-}
-
-void
-defpar(Symbol *sym)
-{
- unsigned long align, size;
-
- if (sym->kind != SREG && sym->kind != SAUTO)
- return;
- align = sym->type.align;
- size = sym->type.size;
-
- offpar -= align-1 & ~align;
- sym->u.off = offpar;
- offpar -= size;
- sym->kind = SAUTO;
-}
-
-void
-defvar(Symbol *sym)
-{
- unsigned long align, size;
-
- if (sym->kind != SREG && sym->kind != SAUTO)
- return;
- align = sym->type.align;
- size = sym->type.size;
-
- offvar += align-1 & ~align;
- sym->u.off = offvar;
- offvar += size;
- sym->kind = SAUTO;
-}
-
-void
-defglobal(Symbol *sym)
-{
- label(sym);
- if (sym->kind == SEXTRN || (sym->type.flags & INITF))
- return;
- size2asm(&sym->type);
- puts("0");
-}
-
-void
-data(Node *np)
-{
- size2asm(&np->type);
- emittree(np);
- putchar('\n');
-}
-
-void
-writeout(void)
-{
-}
-
-void
-endinit(void)
-{
-}
-
-void
-getbblocks(void)
-{
-}
--- a/cc2/arch/z80/optm.c
+++ /dev/null
@@ -1,11 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-static char sccsid[] = "@(#) ./cc2/arch/z80/optm.c";
-
-#include "../../../inc/cc.h"
-#include "../../cc2.h"
-
-Node *
-optm_dep(Node *np)
-{
- return np;
-}
--- a/cc2/arch/z80/types.c
+++ /dev/null
@@ -1,95 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-static char sccsid[] = "@(#) ./cc2/arch/z80/types.c";
-
-#include "../../../inc/cc.h"
-#include "../../cc2.h"
-
-
-Type int8type = {
- .flags = SIGNF | INTF,
- .size = 1,
- .align = 1
-};
-
-Type int16type = {
- .flags = SIGNF | INTF,
- .size = 2,
- .align = 1
-};
-
-Type int32type = {
- .flags = SIGNF | INTF,
- .size = 4,
- .align = 1
-};
-
-Type int64type = {
- .flags = SIGNF | INTF,
- .size = 8,
- .align = 1
-};
-
-Type uint8type = {
- .flags = INTF,
- .size = 1,
- .align = 1
-};
-
-Type uint16type = {
- .flags = INTF,
- .size = 2,
- .align = 1
-};
-
-Type uint32type = {
- .flags = INTF,
- .size = 4,
- .align = 1
-};
-
-Type uint64type = {
- .flags = INTF,
- .size = 8,
- .align = 1
-};
-
-Type ptrtype = {
- .flags = INTF,
- .size = 2,
- .align = 1
-};
-
-Type booltype = {
- .flags = INTF,
- .size = 1,
- .align = 1
-};
-
-Type float32type = {
- .flags = FLOATF,
- .size = 4,
- .align = 1
-};
-
-Type float64type = {
- .flags = FLOATF,
- .size = 4,
- .align = 1
-};
-
-Type float80type = {
- .flags = FLOATF,
- .size = 4,
- .align = 1
-};
-
-Type voidtype = {
- .size = 0,
- .align = 0
-};
-
-/* this types is not going to be used in this arch */
-Type arg_type = {
- .size = 0,
- .align = 0
-};
--- /dev/null
+++ b/cc2/gendep.sh
@@ -1,0 +1,39 @@
+#!/bin/sh
+
+gentarget()
+{
+
+ cat <<EOF
+include target/$1/target.mk
+\$(OBJ-$1): \$(HDR)
+all: cc2-$1
+cc2-$1: \$(OBJ-$1) \$(LIBDIR)/libcc.a
+ \$(CC) \$(SCC_LDFLAGS) \$(OBJ-$1) -lcc -o \$@
+
+EOF
+}
+
+set -e
+
+rm -f makefile
+trap "rm -f $$.mk" 0 2 3
+
+re='\([^-]*\)-\([^-]*\)-\([^-]*\)-\([^-]*\)'
+
+echo $@ |
+tr ' ' '\n' |
+sed "s/$re/\1-\2/" |
+sort -u |
+(cat Makefile
+while read i
+do
+ if test ${MKQBE-0} -eq 1
+ then
+ case $i in
+ amd64-sysv)
+ gentarget qbe_$i
+ ;;
+ esac
+ fi
+ gentarget $i
+done) > $$.mk && mv $$.mk makefile
--- /dev/null
+++ b/cc2/target/amd64-sysv/arch.h
@@ -1,0 +1,1 @@
+/* See LICENSE file for copyright and license details. */
--- /dev/null
+++ b/cc2/target/amd64-sysv/cgen.c
@@ -1,0 +1,16 @@
+/* See LICENSE file for copyright and license details. */
+static char sccsid[] = "@(#) ./cc2/arch/amd64-sysv/cgen.c";
+
+#include "arch.h"
+#include "../../../inc/cc.h"
+#include "../../cc2.h"
+
+Node *
+cgen(Node *np)
+{
+}
+
+Node *
+sethi(Node *np)
+{
+}
--- /dev/null
+++ b/cc2/target/amd64-sysv/code.c
@@ -1,0 +1,211 @@
+/* See LICENSE file for copyright and license details. */
+static char sccsid[] = "@(#) ./cc2/arch/amd64-sysv/code.c";
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <cstd.h>
+#include "arch.h"
+#include "../../../inc/cc.h"
+#include "../../cc2.h"
+
+enum segment {
+ CODESEG,
+ DATASEG,
+ BSSSEG,
+ NOSEG
+};
+
+static int curseg = NOSEG;
+
+static void
+segment(int seg)
+{
+ static char *txt[] = {
+ [CODESEG] = "\t.text\n",
+ [DATASEG] = "\t.data\n",
+ [BSSSEG] = "\t.bss\n",
+ };
+
+ if (seg == curseg)
+ return;
+ fputs(txt[seg], stdout);
+ curseg = seg;
+}
+
+static char *
+symname(Symbol *sym)
+{
+ static char name[INTIDENTSIZ+1];
+
+ if (sym->name) {
+ switch (sym->kind) {
+ case SEXTRN:
+ case SGLOB:
+ case SPRIV:
+ return sym->name;
+ }
+ }
+
+ sprintf(name, ".L%d", sym->numid);
+
+ return name;
+}
+
+static void
+emitconst(Node *np)
+{
+ switch (np->type.size) {
+ case 1:
+ printf("%d", (int) np->u.i & 0xFF);
+ break;
+ case 2:
+ printf("%d", (int) np->u.i & 0xFFFF);
+ break;
+ case 4:
+ printf("%ld", (long) np->u.i & 0xFFFFFFFF);
+ break;
+ case 8:
+ printf("%lld", (long long) np->u.i & 0xFFFFFFFF);
+ break;
+ default:
+ abort();
+ }
+}
+
+static void
+emittree(Node *np)
+{
+ if (!np)
+ return;
+
+ switch (np->op) {
+ case OSTRING:
+ printf("\"%s\"", np->u.s);
+ free(np->u.s);
+ np->u.s = NULL;
+ break;
+ case OCONST:
+ emitconst(np);
+ break;
+ case OADDR:
+ emittree(np->left);
+ break;
+ case OMEM:
+ fputs(symname(np->u.sym), stdout);
+ break;
+ default:
+ emittree(np->left);
+ printf(" %c ", np->op);
+ emittree(np->right);
+ break;
+ }
+}
+static void
+size2asm(Type *tp)
+{
+ char *s;
+
+ if (tp->flags & STRF) {
+ s = "\t.ascii\t";
+ } else {
+ switch (tp->size) {
+ case 1:
+ s = "\t.byte\t";
+ break;
+ case 2:
+ s = "\t.short\t";
+ break;
+ case 4:
+ s = "\t.long\t";
+ break;
+ case 8:
+ s = "\t.quad\t";
+ break;
+ default:
+ s = "\t.space\t%lu,";
+ break;
+ }
+ }
+ printf(s, tp->size);
+}
+
+
+void
+data(Node *np)
+{
+ size2asm(&np->type);
+ emittree(np);
+ putchar('\n');
+}
+
+static void
+label(Symbol *sym)
+{
+ int seg;
+ char *name = symname(sym);
+ Type *tp = &sym->type;
+
+ if (sym->type.flags & FUNF)
+ seg = CODESEG;
+ else if (sym->type.flags & INITF)
+ seg = DATASEG;
+ else
+ seg = BSSSEG;
+ segment(seg);
+
+ switch (sym->kind) {
+ case SEXTRN:
+ printf("\t.extern\t%s\n", name);
+ case SLOCAL:
+ return;
+ case SGLOB:
+ printf("\t.global\t%s\n", name);
+ if (seg == BSSSEG)
+ printf("\t.comm\t%s,%lu\n", name, tp->size);
+ break;
+ }
+ if (sym->type.align != 1)
+ printf("\t.align\t%lu\n", sym->type.align );
+ printf("%s:\n", name);
+}
+
+void
+defglobal(Symbol *sym)
+{
+ label(sym);
+ if (sym->kind == SEXTRN || (sym->type.flags & INITF))
+ return;
+ size2asm(&sym->type);
+ puts("0");
+}
+
+void
+defvar(Symbol *sym)
+{
+}
+
+void
+defpar(Symbol *sym)
+{
+}
+
+void
+newfun(void)
+{
+}
+
+void
+writeout(void)
+{
+}
+
+void
+endinit(void)
+{
+}
+
+void
+getbblocks(void)
+{
+}
--- /dev/null
+++ b/cc2/target/amd64-sysv/optm.c
@@ -1,0 +1,11 @@
+/* See LICENSE file for copyright and license details. */
+static char sccsid[] = "@(#) ./cc2/arch/amd64-sysv/optm.c";
+
+#include "../../../inc/cc.h"
+#include "../../cc2.h"
+
+Node *
+optm_dep(Node *np)
+{
+ return np;
+}
--- /dev/null
+++ b/cc2/target/amd64-sysv/target.mk
@@ -1,0 +1,6 @@
+
+OBJ-amd64-sysv = $(OBJ) \
+ target/amd64-sysv/cgen.o \
+ target/amd64-sysv/optm.o \
+ target/amd64-sysv/code.o \
+ target/amd64-sysv/types.o
--- /dev/null
+++ b/cc2/target/amd64-sysv/types.c
@@ -1,0 +1,94 @@
+/* See LICENSE file for copyright and license details. */
+static char sccsid[] = "@(#) ./cc2/arch/amd64-sysv/types.c";
+
+#include "../../../inc/cc.h"
+#include "../../cc2.h"
+
+
+Type int8type = {
+ .flags = SIGNF | INTF,
+ .size = 1,
+ .align = 1
+};
+
+Type int16type = {
+ .flags = SIGNF | INTF,
+ .size = 2,
+ .align = 2
+};
+
+Type int32type = {
+ .flags = SIGNF | INTF,
+ .size = 4,
+ .align = 4
+};
+
+Type int64type = {
+ .flags = SIGNF | INTF,
+ .size = 8,
+ .align = 8
+};
+
+Type uint8type = {
+ .flags = INTF,
+ .size = 1,
+ .align = 1
+};
+
+Type uint16type = {
+ .flags = INTF,
+ .size = 2,
+ .align = 2
+};
+
+Type uint32type = {
+ .flags = INTF,
+ .size = 4,
+ .align = 4
+};
+
+Type uint64type = {
+ .flags = INTF,
+ .size = 8,
+ .align = 2
+};
+
+Type ptrtype = {
+ .flags = INTF,
+ .size = 8,
+ .align = 8
+};
+
+Type booltype = {
+ .flags = INTF,
+ .size = 1,
+ .align = 1
+};
+
+Type float32type = {
+ .flags = FLOATF,
+ .size = 4,
+ .align = 4
+};
+
+Type float64type = {
+ .flags = FLOATF,
+ .size = 8,
+ .align = 8
+};
+
+Type float80type = {
+ .flags = FLOATF,
+ .size = 16,
+ .align = 16
+};
+
+Type voidtype = {
+ .size = 0,
+ .align = 0
+};
+
+Type arg_type = {
+ .size = 24,
+ .align = 8
+};
--- /dev/null
+++ b/cc2/target/i386-sysv/arch.h
@@ -1,0 +1,1 @@
+/* See LICENSE file for copyright and license details. */
--- /dev/null
+++ b/cc2/target/i386-sysv/cgen.c
@@ -1,0 +1,16 @@
+/* See LICENSE file for copyright and license details. */
+static char sccsid[] = "@(#) ./cc2/arch/i386-sysv/cgen.c";
+
+#include "arch.h"
+#include "../../../inc/cc.h"
+#include "../../cc2.h"
+
+Node *
+cgen(Node *np)
+{
+}
+
+Node *
+sethi(Node *np)
+{
+}
--- /dev/null
+++ b/cc2/target/i386-sysv/code.c
@@ -1,0 +1,209 @@
+/* See LICENSE file for copyright and license details. */
+static char sccsid[] = "@(#) ./cc2/arch/i386-sysv/code.c";
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <cstd.h>
+#include "arch.h"
+#include "../../../inc/cc.h"
+#include "../../cc2.h"
+
+enum segment {
+ CODESEG,
+ DATASEG,
+ BSSSEG,
+ NOSEG
+};
+
+static int curseg = NOSEG;
+
+static void
+segment(int seg)
+{
+ static char *txt[] = {
+ [CODESEG] = "\t.text\n",
+ [DATASEG] = "\t.data\n",
+ [BSSSEG] = "\t.bss\n",
+ };
+
+ if (seg == curseg)
+ return;
+ fputs(txt[seg], stdout);
+ curseg = seg;
+}
+
+static char *
+symname(Symbol *sym)
+{
+ static char name[INTIDENTSIZ+1];
+
+ if (sym->name) {
+ switch (sym->kind) {
+ case SEXTRN:
+ case SGLOB:
+ case SPRIV:
+ return sym->name;
+ }
+ }
+
+ sprintf(name, ".L%d", sym->numid);
+
+ return name;
+}
+
+static void
+emitconst(Node *np)
+{
+ switch (np->type.size) {
+ case 1:
+ printf("%d", (int) np->u.i & 0xFF);
+ break;
+ case 2:
+ printf("%d", (int) np->u.i & 0xFFFF);
+ break;
+ case 4:
+ printf("%ld", (long) np->u.i & 0xFFFFFFFF);
+ break;
+ case 8:
+ printf("%lld", (long long) np->u.i & 0xFFFFFFFF);
+ break;
+ default:
+ abort();
+ }
+}
+
+static void
+emittree(Node *np)
+{
+ if (!np)
+ return;
+
+ switch (np->op) {
+ case OSTRING:
+ printf("\"%s\"", np->u.s);
+ free(np->u.s);
+ np->u.s = NULL;
+ break;
+ case OCONST:
+ emitconst(np);
+ break;
+ case OADDR:
+ emittree(np->left);
+ break;
+ case OMEM:
+ fputs(symname(np->u.sym), stdout);
+ break;
+ default:
+ emittree(np->left);
+ printf(" %c ", np->op);
+ emittree(np->right);
+ break;
+ }
+}
+static void
+size2asm(Type *tp)
+{
+ char *s;
+
+ if (tp->flags & STRF) {
+ s = "\t.ascii\t";
+ } else {
+ switch (tp->size) {
+ case 1:
+ s = "\t.byte\t";
+ break;
+ case 2:
+ s = "\t.short\t";
+ break;
+ case 4:
+ s = "\t.long\t";
+ break;
+ case 8:
+ s = "\t.quad\t";
+ break;
+ default:
+ s = "\t.space\t%lu,";
+ break;
+ }
+ }
+ printf(s, tp->size);
+}
+
+void
+data(Node *np)
+{
+ size2asm(&np->type);
+ emittree(np);
+ putchar('\n');
+}
+
+static void
+label(Symbol *sym)
+{
+ int seg;
+ char *name = symname(sym);
+ Type *tp = &sym->type;
+
+ if (sym->type.flags & FUNF)
+ seg = CODESEG;
+ else if (sym->type.flags & INITF)
+ seg = DATASEG;
+ else
+ seg = BSSSEG;
+ segment(seg);
+
+ switch (sym->kind) {
+ case SEXTRN:
+ printf("\t.extern\t%s\n", name);
+ case SLOCAL:
+ return;
+ case SGLOB:
+ printf("\t.global\t%s\n", name);
+ if (seg == BSSSEG)
+ printf("\t.comm\t%s,%lu\n", name, tp->size);
+ break;
+ }
+ if (sym->type.align != 1)
+ printf("\t.align\t%lu\n", sym->type.align );
+ printf("%s:\n", name);
+}
+
+void
+defglobal(Symbol *sym)
+{
+ label(sym);
+ if (sym->kind == SEXTRN || (sym->type.flags & INITF))
+ return;
+ size2asm(&sym->type);
+ puts("0");
+}
+
+void
+defpar(Symbol *sym)
+{
+}
+
+void
+defvar(Symbol *sym)
+{
+}
+
+void
+newfun(void)
+{
+}
+
+void
+writeout(void)
+{
+}
+
+void
+endinit(void)
+{
+}
+
+void
+getbblocks(void)
+{
+}
--- /dev/null
+++ b/cc2/target/i386-sysv/optm.c
@@ -1,0 +1,11 @@
+/* See LICENSE file for copyright and license details. */
+static char sccsid[] = "@(#) ./cc2/arch/i386-sysv/optm.c";
+
+#include "../../../inc/cc.h"
+#include "../../cc2.h"
+
+Node *
+optm_dep(Node *np)
+{
+ return np;
+}
--- /dev/null
+++ b/cc2/target/i386-sysv/target.mk
@@ -1,0 +1,6 @@
+
+OBJ-i386-sysv = $(OBJ) \
+ target/i386-sysv/cgen.o \
+ target/i386-sysv/optm.o \
+ target/i386-sysv/code.o \
+ target/i386-sysv/types.o
--- /dev/null
+++ b/cc2/target/i386-sysv/types.c
@@ -1,0 +1,95 @@
+/* See LICENSE file for copyright and license details. */
+static char sccsid[] = "@(#) ./cc2/arch/i386-sysv/types.c";
+
+#include "../../../inc/cc.h"
+#include "../../cc2.h"
+
+
+Type int8type = {
+ .flags = SIGNF | INTF,
+ .size = 1,
+ .align = 1
+};
+
+Type int16type = {
+ .flags = SIGNF | INTF,
+ .size = 2,
+ .align = 2
+};
+
+Type int32type = {
+ .flags = SIGNF | INTF,
+ .size = 4,
+ .align = 4
+};
+
+Type int64type = {
+ .flags = SIGNF | INTF,
+ .size = 8,
+ .align = 4
+};
+
+Type uint8type = {
+ .flags = INTF,
+ .size = 1,
+ .align = 1
+};
+
+Type uint16type = {
+ .flags = INTF,
+ .size = 2,
+ .align = 2
+};
+
+Type uint32type = {
+ .flags = INTF,
+ .size = 4,
+ .align = 2
+};
+
+Type uint64type = {
+ .flags = INTF,
+ .size = 8,
+ .align = 4
+};
+
+Type ptrtype = {
+ .flags = INTF,
+ .size = 4,
+ .align = 4
+};
+
+Type booltype = {
+ .flags = INTF,
+ .size = 1,
+ .align = 1
+};
+
+Type float32type = {
+ .flags = FLOATF,
+ .size = 4,
+ .align = 4
+};
+
+Type float64type = {
+ .flags = FLOATF,
+ .size = 8,
+ .align = 4
+};
+
+Type float80type = {
+ .flags = FLOATF,
+ .size = 12,
+ .align = 4
+};
+
+Type voidtype = {
+ .size = 0,
+ .align = 0
+};
+
+/* this type is not used in this architecture */
+Type arg_type = {
+ .size = 0,
+ .align = 0
+};
--- /dev/null
+++ b/cc2/target/qbe_amd64-sysv/arch.h
@@ -1,0 +1,137 @@
+/* See LICENSE file for copyright and license details. */
+
+enum asmop {
+ ASNOP = 0,
+ ASSTB,
+ ASSTH,
+ ASSTW,
+ ASSTL,
+ ASSTM,
+ ASSTS,
+ ASSTD,
+
+ ASLDSB,
+ ASLDUB,
+ ASLDSH,
+ ASLDUH,
+ ASLDSW,
+ ASLDUW,
+ ASLDL,
+ ASLDS,
+ ASLDD,
+
+ ASADDW,
+ ASSUBW,
+ ASMULW,
+ ASMODW,
+ ASUMODW,
+ ASDIVW,
+ ASUDIVW,
+ ASSHLW,
+ ASSHRW,
+ ASUSHRW,
+ ASLTW,
+ ASULTW,
+ ASGTW,
+ ASUGTW,
+ ASLEW,
+ ASULEW,
+ ASGEW,
+ ASUGEW,
+ ASEQW,
+ ASNEW,
+ ASBANDW,
+ ASBORW,
+ ASBXORW,
+
+ ASADDL,
+ ASSUBL,
+ ASMULL,
+ ASMODL,
+ ASUMODL,
+ ASDIVL,
+ ASUDIVL,
+ ASSHLL,
+ ASSHRL,
+ ASUSHRL,
+ ASLTL,
+ ASULTL,
+ ASGTL,
+ ASUGTL,
+ ASLEL,
+ ASULEL,
+ ASGEL,
+ ASUGEL,
+ ASEQL,
+ ASNEL,
+ ASBANDL,
+ ASBORL,
+ ASBXORL,
+
+ ASADDS,
+ ASSUBS,
+ ASMULS,
+ ASDIVS,
+ ASLTS,
+ ASGTS,
+ ASLES,
+ ASGES,
+ ASEQS,
+ ASNES,
+
+ ASADDD,
+ ASSUBD,
+ ASMULD,
+ ASDIVD,
+ ASLTD,
+ ASGTD,
+ ASLED,
+ ASGED,
+ ASEQD,
+ ASNED,
+
+ ASEXTBW,
+ ASUEXTBW,
+ ASEXTBL,
+ ASUEXTBL,
+ ASEXTHW,
+ ASUEXTHW,
+ ASEXTHL,
+ ASUEXTHL,
+ ASEXTWL,
+ ASUEXTWL,
+
+ ASSTOL,
+ ASSTOW,
+ ASDTOL,
+ ASDTOW,
+
+ ASSWTOD,
+ ASSWTOS,
+ ASSLTOD,
+ ASSLTOS,
+
+ ASEXTS,
+ ASTRUNCD,
+
+ ASJMP,
+ ASBRANCH,
+ ASRET,
+ ASCALL,
+ ASCALLE,
+ ASCALLEX,
+ ASPAR,
+ ASPARE,
+ ASALLOC,
+ ASFORM,
+
+ ASCOPYB,
+ ASCOPYH,
+ ASCOPYW,
+ ASCOPYL,
+ ASCOPYS,
+ ASCOPYD,
+
+ ASVSTAR,
+ ASVARG,
+};
--- /dev/null
+++ b/cc2/target/qbe_amd64-sysv/cgen.c
@@ -1,0 +1,731 @@
+/* See LICENSE file for copyright and license details. */
+static char sccsid[] = "@(#) ./cc2/arch/qbe/cgen.c";
+
+#include <assert.h>
+#include <stdlib.h>
+
+#include <cstd.h>
+#include "arch.h"
+#include "../../../inc/cc.h"
+#include "../../cc2.h"
+
+enum sflags {
+ ISTMP = 1,
+ ISCONS = 2
+};
+
+static char opasmw[] = {
+ [OADD] = ASADDW,
+ [OSUB] = ASSUBW,
+ [OMUL] = ASMULW,
+ [OMOD] = ASMODW,
+ [ODIV] = ASDIVW,
+ [OSHL] = ASSHLW,
+ [OSHR] = ASSHRW,
+ [OLT] = ASLTW,
+ [OGT] = ASGTW,
+ [OLE] = ASLEW,
+ [OGE] = ASGEW,
+ [OEQ] = ASEQW,
+ [ONE] = ASNEW,
+ [OBAND] = ASBANDW,
+ [OBOR] = ASBORW,
+ [OBXOR] = ASBXORW,
+};
+
+static char opasml[] = {
+ [OADD] = ASADDL,
+ [OSUB] = ASSUBL,
+ [OMUL] = ASMULL,
+ [OMOD] = ASMODL,
+ [ODIV] = ASDIVL,
+ [OSHL] = ASSHLL,
+ [OSHR] = ASSHRL,
+ [OLT] = ASLTL,
+ [OGT] = ASGTL,
+ [OLE] = ASLEL,
+ [OGE] = ASGEL,
+ [OEQ] = ASEQL,
+ [ONE] = ASNEL,
+ [OBAND] = ASBANDL,
+ [OBOR] = ASBORL,
+ [OBXOR] = ASBXORL,
+};
+
+static char opasms[] = {
+ [OADD] = ASADDS,
+ [OSUB] = ASSUBS,
+ [OMUL] = ASMULS,
+ [ODIV] = ASDIVS,
+ [OLT] = ASLTS,
+ [OGT] = ASGTS,
+ [OLE] = ASLES,
+ [OGE] = ASGES,
+ [OEQ] = ASEQS,
+ [ONE] = ASNES,
+};
+static char opasmd[] = {
+ [OADD] = ASADDD,
+ [OSUB] = ASSUBD,
+ [OMUL] = ASMULD,
+ [ODIV] = ASDIVD,
+ [OLT] = ASLTD,
+ [OGT] = ASGTD,
+ [OLE] = ASLED,
+ [OGE] = ASGED,
+ [OEQ] = ASEQD,
+ [ONE] = ASNED,
+};
+
+extern Type int32type, uint32type, ptrtype;
+
+static Node *
+tmpnode(Node *np, Type *tp)
+{
+ char flags;
+ Symbol *sym;
+
+ if (!np)
+ np = newnode(OTMP);
+ sym = getsym(TMPSYM);
+ sym->type = np->type = *tp;
+ flags = tp->flags & ~(PARF|INITF);
+ sym->type.flags = np->type.flags = flags;
+ sym->kind = STMP;
+ np->left = np->right = NULL;
+ np->u.sym = sym;
+ np->op = OTMP;
+ np->flags |= ISTMP;
+ return np;
+}
+
+static Node *
+load(Type *tp, Node *np, Node *new)
+{
+ int op;
+ int flags = tp->flags;
+
+ if (flags & (AGGRF|FUNF)) {
+ *new = *np;
+ return new;
+ }
+ switch (tp->size) {
+ case 1:
+ op = ASLDSB;
+ break;
+ case 2:
+ op = ASLDSH;
+ break;
+ case 4:
+ op = (flags & FLOATF) ? ASLDS : ASLDSW;
+ break;
+ case 8:
+ op = (flags & FLOATF) ? ASLDD : ASLDL;
+ break;
+ default:
+ abort();
+ }
+ /*
+ * unsigned version of operations are always +1 the
+ * signed version
+ */
+ if ((flags & (INTF|SIGNF)) == INTF && tp->size < 8)
+ ++op;
+
+ code(op, tmpnode(new, tp), np, NULL);
+
+ return new;
+}
+
+static Node *rhs(Node *np, Node *new);
+
+static Node *
+cast(Type *td, Node *ns, Node *nd)
+{
+ Type *ts;
+ Node aux1, aux2;
+ int op, d_isint, s_isint;
+
+ ts = &ns->type;
+ d_isint = (td->flags & INTF) != 0;
+ s_isint = (ts->flags & INTF) != 0;
+
+ if (d_isint && s_isint) {
+ if (td->size <= ts->size) {
+ *nd = *ns;
+ return nd;
+ }
+ assert(td->size == 4 || td->size == 8);
+ switch (ts->size) {
+ case 1:
+ op = (td->size == 4) ? ASEXTBW : ASEXTBL;
+ break;
+ case 2:
+ op = (td->size == 4) ? ASEXTHW : ASEXTHL;
+ break;
+ case 4:
+ op = ASEXTWL;
+ break;
+ default:
+ abort();
+ }
+ /*
+ * unsigned version of operations are always +1 the
+ * signed version
+ */
+ op += (ts->flags & SIGNF) == 0;
+ } else if (d_isint) {
+ /* conversion from float to int */
+ switch (ts->size) {
+ case 4:
+ op = (td->size == 8) ? ASSTOL : ASSTOW;
+ break;
+ case 8:
+ op = (td->size == 8) ? ASDTOL : ASDTOW;
+ break;
+ default:
+ abort();
+ }
+ /* TODO: Add signess */
+ } else if (s_isint) {
+ /* conversion from int to float */
+ switch (ts->size) {
+ case 1:
+ case 2:
+ ts = (ts->flags&SIGNF) ? &int32type : &uint32type;
+ ns = cast(ts, ns, tmpnode(&aux2, ts));
+ case 4:
+ op = (td->size == 8) ? ASSWTOD : ASSWTOS;
+ break;
+ case 8:
+ op = (td->size == 8) ? ASSLTOD : ASSLTOS;
+ break;
+ default:
+ abort();
+ }
+ /* TODO: Add signess */
+ } else {
+ /* conversion from float to float */
+ op = (td->size == 4) ? ASEXTS : ASTRUNCD;
+ }
+
+ code(op, tmpnode(nd, td), ns, NULL);
+ return nd;
+}
+
+static Node *rhs(Node *np, Node *new);
+
+static Node *
+call(Node *np, Node *fun, Node *ret)
+{
+ int n, op;
+ Type *tp;
+ Node aux, **q, *p, *pars[NR_FUNPARAM];
+
+ for (n = 0, p = np->right; p; p = p->right)
+ pars[n++] = rhs(p->left, newnode(OTMP));
+
+ tp = &np->type;
+ code(ASCALL, tmpnode(ret, tp), fun, NULL);
+
+ for (q = pars; q < &pars[n]; ++q) {
+ op = (q == &pars[n-1]) ? ASPARE : ASPAR;
+ tmpnode(&aux, &(*q)->type);
+ code(op, NULL, *q, &aux);
+ }
+ code((np->op == OCALL) ? ASCALLE : ASCALLEX, NULL, NULL, NULL);
+
+ return ret;
+}
+
+static Node *
+assign(Type *tp, Node *to, Node *from)
+{
+ int op;
+
+ switch (tp->size) {
+ case 1:
+ op = ASSTB;
+ break;
+ case 2:
+ op = ASSTH;
+ break;
+ case 4:
+ op = (tp->flags & FLOATF) ? ASSTS : ASSTW;
+ break;
+ case 8:
+ op = (tp->flags & FLOATF) ? ASSTD : ASSTL;
+ break;
+ default:
+ op = ASSTM;
+ break;
+ }
+ code(op, to, from, NULL);
+ return from;
+}
+
+static Node *
+copy(Type *tp, Node *to, Node *from)
+{
+ int op;
+
+ switch (tp->size) {
+ case 1:
+ op = ASCOPYB;
+ break;
+ case 2:
+ op = ASCOPYH;
+ break;
+ case 4:
+ op = (tp->flags & FLOATF) ? ASCOPYS : ASCOPYW;
+ break;
+ case 8:
+ op = (tp->flags & FLOATF) ? ASCOPYD : ASCOPYL;
+ break;
+ default:
+ /* TODO: Need to handle the general case */
+ abort();
+ }
+ code(op, to, from, NULL);
+ return from;
+}
+
+/* TODO: Do field() transformation in sethi */
+
+static Node *
+field(Node *np, Node *ret, int islhs)
+{
+ Node base, node, off, add, *addr;
+ TUINT offset = np->right->u.sym->u.off;
+
+ addr = rhs(np->left, &base);
+
+ if (offset != 0) {
+ node.op = OADD;
+ node.type = ptrtype;
+ node.left = addr;
+ node.right = constnode(&off, offset, &ptrtype);
+ addr = rhs(&node, &add);
+ }
+
+ if (islhs)
+ *ret = *addr;
+ else
+ load(&np->type, addr, ret);
+
+ return ret;
+}
+
+static Node *
+lhs(Node *np, Node *new)
+{
+ switch (np->op) {
+ case OMEM:
+ case OAUTO:
+ *new = *np;
+ return new;
+ case OPTR:
+ return rhs(np->left, new);
+ case OFIELD:
+ return field(np, new, 1);
+ default:
+ abort();
+ }
+}
+
+static void
+bool(Node *np, Symbol *true, Symbol *false)
+{
+ Node *l = np->left, *r = np->right;
+ Node ret, ifyes, ifno;
+ Symbol *label;
+
+ switch (np->op) {
+ case ONEG:
+ bool(l, false, true);
+ break;
+ case OAND:
+ label = newlabel();
+ bool(l, label, false);
+ setlabel(label);
+ bool(r, true, false);
+ break;
+ case OOR:
+ label = newlabel();
+ bool(l, true, label);
+ setlabel(label);
+ bool(r, true, false);
+ break;
+ default:
+ label2node(&ifyes, true);
+ label2node(&ifno, false);
+ code(ASBRANCH, rhs(np, &ret), &ifyes, &ifno);
+ break;
+ }
+}
+
+static Node *
+ternary(Node *np, Node *ret)
+{
+ Node ifyes, ifno, phi, *colon, aux1, aux2, aux3;
+
+ tmpnode(ret, &np->type);
+ label2node(&ifyes, NULL);
+ label2node(&ifno, NULL);
+ label2node(&phi, NULL);
+
+ colon = np->right;
+ code(ASBRANCH, rhs(np->left, &aux1), &ifyes, &ifno);
+
+ setlabel(ifyes.u.sym);
+ copy(&ret->type, ret, rhs(colon->left, &aux2));
+ code(ASJMP, NULL, &phi, NULL);
+
+ setlabel(ifno.u.sym);
+ copy(&ret->type, ret, rhs(colon->right, &aux3));
+ setlabel(phi.u.sym);
+
+ return ret;
+}
+
+static Node *
+function(void)
+{
+ Node aux;
+ Symbol *p;
+
+ /* allocate stack space for parameters */
+ for (p = locals; p && (p->type.flags & PARF) != 0; p = p->next)
+ code(ASALLOC, label2node(&aux, p), NULL, NULL);
+
+ /* allocate stack space for local variables) */
+ for ( ; p && p->id != TMPSYM; p = p->next) {
+ if (p->kind != SAUTO)
+ continue;
+ code(ASALLOC, label2node(&aux, p), NULL, NULL);
+ }
+ /* store formal parameters in parameters */
+ for (p = locals; p; p = p->next) {
+ if ((p->type.flags & PARF) == 0)
+ break;
+ code(ASFORM, label2node(&aux, p), NULL, NULL);
+ }
+ return NULL;
+}
+
+static void
+swtch_if(Node *idx)
+{
+ Node aux1, aux2, *np;
+ Symbol *deflabel = NULL;
+
+ for (;;) {
+ np = delstmt();
+ setlabel(np->label);
+
+ switch (np->op) {
+ case OESWITCH:
+ if (!deflabel)
+ deflabel = np->u.sym;
+ aux1.op = OJMP;
+ aux1.label = NULL;
+ aux1.u.sym = deflabel;
+ cgen(&aux1);
+ return;
+ case OCASE:
+ aux1 = *np;
+ aux1.op = OBRANCH;
+ aux1.label = NULL;
+ aux1.left = &aux2;
+
+ aux2.op = OEQ;
+ aux2.type = idx->type;
+ aux2.left = np->left;
+ aux2.right = idx;
+
+ cgen(&aux1);
+ break;
+ case ODEFAULT:
+ deflabel = np->u.sym;
+ break;
+ default:
+ abort();
+ }
+ }
+}
+
+static Node *
+rhs(Node *np, Node *ret)
+{
+ Node aux1, aux2, *phi, *l = np->left, *r = np->right;
+ Type *tp;
+ int off, op;
+ char *tbl;
+ Symbol *true, *false;
+
+ tp = &np->type;
+
+ switch (np->op) {
+ case OBFUN:
+ return function();
+ case ONOP:
+ case OBLOOP:
+ case OELOOP:
+ case OEFUN:
+ return NULL;
+ case OTMP:
+ case OCONST:
+ *ret = *np;
+ return np;
+ case OMEM:
+ case OAUTO:
+ return load(tp, np, ret);
+ case ONEG:
+ case OAND:
+ case OOR:
+ true = newlabel();
+ false = newlabel();
+ phi = label2node(&aux1, NULL);
+ tmpnode(ret, &int32type);
+
+ bool(np, true, false);
+
+ setlabel(true);
+ code(ASCOPYW, ret, constnode(&aux2, 1, &int32type), NULL);
+ code(ASJMP, NULL, phi, NULL);
+
+ setlabel(false);
+ code(ASCOPYW, ret, constnode(&aux2, 0, &int32type), NULL);
+
+ setlabel(phi->u.sym);
+ return ret;
+ case OMOD:
+ case OSHR:
+ assert(tp->flags & INTF);
+ case ODIV:
+ case OLT:
+ case OGT:
+ case OLE:
+ case OGE:
+ /*
+ * unsigned version of operations are always +1 the
+ * signed version
+ */
+ off = (tp->flags & SIGNF) == 0;
+ goto binary;
+ case OSHL:
+ case OBAND:
+ case OBOR:
+ case OBXOR:
+ assert(tp->flags & INTF);
+ case OADD:
+ case OSUB:
+ case OMUL:
+ case OEQ:
+ case ONE:
+ off = 0;
+ binary:
+ if (l->complex >= r->complex) {
+ rhs(l, &aux1);
+ rhs(r, &aux2);
+ } else {
+ rhs(r, &aux2);
+ rhs(l, &aux1);
+ }
+ switch (tp->size) {
+ case 4:
+ tbl = (tp->flags & FLOATF) ? opasms : opasmw;
+ break;
+ case 8:
+ tbl = (tp->flags & FLOATF) ? opasmd : opasml;
+ break;
+ default:
+ abort();
+ }
+ op = tbl[np->op] + off;
+ tmpnode(ret, tp);
+ code(op, ret, &aux1, &aux2);
+ return ret;
+ case OCALL:
+ case OCALLE:
+ if (l->op == OPTR)
+ l = rhs(l, &aux1);
+ return call(np, l, ret);
+ case OCAST:
+ return cast(tp, rhs(l, &aux1), ret);
+ case OASSIG:
+ /* TODO: Do this transformations in sethi */
+ switch (np->u.subop) {
+ case OINC:
+ op = OADD;
+ goto post_oper;
+ case ODEC:
+ op = OSUB;
+ post_oper:
+ aux1.op = op;
+ aux1.left = rhs(l, ret);
+ aux1.right = r;
+ aux1.type = np->type;
+ rhs(&aux1, &aux2);
+ lhs(l, &aux1);
+ assign(tp, &aux1, &aux2);
+ break;
+ default:
+ aux2.type = np->type;
+ aux2.op = np->u.subop;
+ aux2.right = np->right;
+ aux2.left = np->left;
+ r = rhs(&aux2, &aux1);
+ Node aux3;
+ if (l->op == OCAST) {
+ aux3.type = l->left->type;
+ aux3.op = OCAST;
+ aux3.left = r;
+ aux3.right = NULL;
+ r = &aux3;
+ l = l->left;
+ }
+ case 0:
+ /* TODO: see what is the most difficult */
+ lhs(l, &aux2);
+ rhs(r, ret);
+ return assign(tp, &aux2, ret);
+ }
+ return ret;
+ case OASK:
+ return ternary(np, ret);
+ case OCOMMA:
+ rhs(l, &aux1);
+ return rhs(r, ret);
+ case OPTR:
+ return load(tp, rhs(l, &aux1), ret);
+ case OADDR:
+ lhs(l, ret);
+ ret->type = *tp;
+ return ret;
+ case OFIELD:
+ return field(np, ret, 0);
+ case OBUILTIN:
+ switch (np->u.subop) {
+ case BVA_START:
+ l = rhs(l, &aux1);
+ code(ASVSTAR, NULL, l, NULL);
+ return NULL;
+ case BVA_END:
+ return NULL;
+ case BVA_ARG:
+ l = rhs(l, &aux1);
+ code(ASVARG, tmpnode(ret, tp), l, NULL);
+ return ret;
+ case BVA_COPY:
+ /* TODO */
+ default:
+ abort();
+ }
+ default:
+ abort();
+ }
+ abort();
+}
+
+Node *
+cgen(Node *np)
+{
+ Node aux, *p, *next;
+
+ setlabel(np->label);
+ switch (np->op) {
+ case OJMP:
+ label2node(&aux, np->u.sym);
+ code(ASJMP, NULL, &aux, NULL);
+ break;
+ case OBRANCH:
+ next = np->next;
+ if (!next->label)
+ next->label = newlabel();
+ bool(np->left, np->u.sym, next->label);
+ break;
+ case ORET:
+ p = (np->left) ? rhs(np->left, &aux) : NULL;
+ code(ASRET, NULL, p, NULL);
+ break;
+ case OBSWITCH:
+ p = rhs(np->left, &aux);
+ swtch_if(p);
+ break;
+ default:
+ rhs(np, &aux);
+ break;
+ }
+ return NULL;
+}
+
+/*
+ * This is strongly influenced by
+ * http://plan9.bell-labs.com/sys/doc/compiler.ps (/sys/doc/compiler.ps)
+ * calculate addresability as follows
+ * AUTO => 11 value+fp
+ * REG => 11 reg
+ * STATIC => 11 (value)
+ * CONST => 11 $value
+ * These values of addressability are not used in the code generation.
+ * They are only used to calculate the Sethi-Ullman numbers. Since
+ * QBE is AMD64 targered we could do a better job there, and try to
+ * detect some of the complex addressing modes of these processors.
+ */
+Node *
+sethi(Node *np)
+{
+ Node *lp, *rp;
+
+ if (!np)
+ return np;
+
+ np->complex = 0;
+ np->address = 0;
+ lp = np->left;
+ rp = np->right;
+
+ switch (np->op) {
+ case OAUTO:
+ case OREG:
+ case OMEM:
+ case OCONST:
+ np->address = 11;
+ break;
+ case OCPL:
+ assert(np->type.flags & INTF);
+ np->op = OBXOR;
+ rp = constnode(NULL, ~(TUINT) 0, &np->type);
+ goto binary;
+ case OSNEG:
+ np->op = OSUB;
+ rp = lp;
+ lp = constnode(NULL, 0, &np->type);
+ if ((np->type.flags & INTF) == 0)
+ lp->u.f = 0.0;
+ default:
+ binary:
+ lp = sethi(lp);
+ rp = sethi(rp);
+ break;
+ }
+ np->left = lp;
+ np->right = rp;
+
+ if (np->address > 10)
+ return np;
+ if (lp)
+ np->complex = lp->complex;
+ if (rp) {
+ int d = np->complex - rp->complex;
+
+ if (d == 0)
+ ++np->complex;
+ else if (d < 0)
+ np->complex = rp->complex;
+ }
+ if (np->complex == 0)
+ ++np->complex;
+ return np;
+}
--- /dev/null
+++ b/cc2/target/qbe_amd64-sysv/code.c
@@ -1,0 +1,569 @@
+/* See LICENSE file for copyright and license details. */
+static char sccsid[] = "@(#) ./cc2/arch/qbe/code.c";
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <cstd.h>
+#include "arch.h"
+#include "../../../inc/cc.h"
+#include "../../cc2.h"
+
+#define ADDR_LEN (INTIDENTSIZ+64)
+
+static void binary(void), unary(void), store(void), jmp(void), ret(void),
+ branch(void), call(void), ecall(void), param(void),
+ alloc(void), form2local(void), ldir(void), vastart(void),
+ vaarg(void);
+
+static struct opdata {
+ void (*fun)(void);
+ char *txt;
+ char letter;
+} optbl [] = {
+ [ASLDSB] = {.fun = unary, .txt = "loadsb", .letter = 'w'},
+ [ASLDUB] = {.fun = unary, .txt = "loadub", .letter = 'w'},
+ [ASLDSH] = {.fun = unary, .txt = "loadsh", .letter = 'w'},
+ [ASLDUH] = {.fun = unary, .txt = "loaduh", .letter = 'w'},
+ [ASLDSW] = {.fun = unary, .txt = "loadsw", .letter = 'w'},
+ [ASLDUW] = {.fun = unary, .txt = "loaduw", .letter = 'w'},
+ [ASLDL] = {.fun = unary, .txt = "loadl", .letter = 'l'},
+ [ASLDS] = {.fun = unary, .txt = "loads", .letter = 's'},
+ [ASLDD] = {.fun = unary, .txt = "loadd", .letter = 'd'},
+
+ [ASCOPYB] = {.fun = unary, .txt = "copy", .letter = 'b'},
+ [ASCOPYH] = {.fun = unary, .txt = "copy", .letter = 'h'},
+ [ASCOPYW] = {.fun = unary, .txt = "copy", .letter = 'w'},
+ [ASCOPYL] = {.fun = unary, .txt = "copy", .letter = 'l'},
+ [ASCOPYS] = {.fun = unary, .txt = "copy", .letter = 's'},
+ [ASCOPYD] = {.fun = unary, .txt = "copy", .letter = 'd'},
+
+ [ASSTB] = {.fun = store, .txt = "store", .letter = 'b'},
+ [ASSTH] = {.fun = store, .txt = "store", .letter = 'h'},
+ [ASSTW] = {.fun = store, .txt = "store", .letter = 'w'},
+ [ASSTL] = {.fun = store, .txt = "store", .letter = 'l'},
+ [ASSTM] = {.fun = ldir},
+ [ASSTS] = {.fun = store, .txt = "store", .letter = 's'},
+ [ASSTD] = {.fun = store, .txt = "store", .letter = 'd'},
+
+ [ASADDW] = {.fun = binary, .txt = "add", .letter = 'w'},
+ [ASSUBW] = {.fun = binary, .txt = "sub", .letter = 'w'},
+ [ASMULW] = {.fun = binary, .txt = "mul", .letter = 'w'},
+ [ASMODW] = {.fun = binary, .txt = "rem", .letter = 'w'},
+ [ASUMODW] = {.fun = binary, .txt = "urem", .letter = 'w'},
+ [ASDIVW] = {.fun = binary, .txt = "div", .letter = 'w'},
+ [ASUDIVW] = {.fun = binary, .txt = "udiv", .letter = 'w'},
+ [ASSHLW] = {.fun = binary, .txt = "shl", .letter = 'w'},
+ [ASSHRW] = {.fun = binary, .txt = "sar", .letter = 'w'},
+ [ASUSHRW] = {.fun = binary, .txt = "shr", .letter = 'w'},
+ [ASLTW] = {.fun = binary, .txt = "csltw", .letter = 'w'},
+ [ASULTW] = {.fun = binary, .txt = "cultw", .letter = 'w'},
+ [ASGTW] = {.fun = binary, .txt = "csgtw", .letter = 'w'},
+ [ASUGTW] = {.fun = binary, .txt = "cugtw", .letter = 'w'},
+ [ASLEW] = {.fun = binary, .txt = "cslew", .letter = 'w'},
+ [ASULEW] = {.fun = binary, .txt = "culew", .letter = 'w'},
+ [ASGEW] = {.fun = binary, .txt = "csgew", .letter = 'w'},
+ [ASUGEW] = {.fun = binary, .txt = "cugew", .letter = 'w'},
+ [ASEQW] = {.fun = binary, .txt = "ceqw", .letter = 'w'},
+ [ASNEW] = {.fun = binary, .txt = "cnew", .letter = 'w'},
+ [ASBANDW] = {.fun = binary, .txt = "and", .letter = 'w'},
+ [ASBORW] = {.fun = binary, .txt = "or", .letter = 'w'},
+ [ASBXORW] = {.fun = binary, .txt = "xor", .letter = 'w'},
+
+ [ASADDL] = {.fun = binary, .txt = "add", .letter = 'l'},
+ [ASSUBL] = {.fun = binary, .txt = "sub", .letter = 'l'},
+ [ASMULL] = {.fun = binary, .txt = "mul", .letter = 'l'},
+ [ASMODL] = {.fun = binary, .txt = "rem", .letter = 'l'},
+ [ASUMODL] = {.fun = binary, .txt = "urem", .letter = 'l'},
+ [ASDIVL] = {.fun = binary, .txt = "div", .letter = 'l'},
+ [ASUDIVL] = {.fun = binary, .txt = "udiv", .letter = 'l'},
+ [ASSHLL] = {.fun = binary, .txt = "shl", .letter = 'l'},
+ [ASSHRL] = {.fun = binary, .txt = "sar", .letter = 'l'},
+ [ASUSHRL] = {.fun = binary, .txt = "shr", .letter = 'l'},
+ [ASLTL] = {.fun = binary, .txt = "csltl", .letter = 'w'},
+ [ASULTL] = {.fun = binary, .txt = "cultl", .letter = 'w'},
+ [ASGTL] = {.fun = binary, .txt = "csgtl", .letter = 'w'},
+ [ASUGTL] = {.fun = binary, .txt = "cugtl", .letter = 'w'},
+ [ASLEL] = {.fun = binary, .txt = "cslel", .letter = 'w'},
+ [ASULEL] = {.fun = binary, .txt = "culel", .letter = 'w'},
+ [ASGEL] = {.fun = binary, .txt = "csgel", .letter = 'w'},
+ [ASUGEL] = {.fun = binary, .txt = "cugel", .letter = 'w'},
+ [ASEQL] = {.fun = binary, .txt = "ceql", .letter = 'w'},
+ [ASNEL] = {.fun = binary, .txt = "cnel", .letter = 'w'},
+ [ASBANDL] = {.fun = binary, .txt = "and", .letter = 'l'},
+ [ASBORL] = {.fun = binary, .txt = "or", .letter = 'l'},
+ [ASBXORL] = {.fun = binary, .txt = "xor", .letter = 'l'},
+
+ [ASADDS] = {.fun = binary, .txt = "add", .letter = 's'},
+ [ASSUBS] = {.fun = binary, .txt = "sub", .letter = 's'},
+ [ASMULS] = {.fun = binary, .txt = "mul", .letter = 's'},
+ [ASDIVS] = {.fun = binary, .txt = "div", .letter = 's'},
+ [ASLTS] = {.fun = binary, .txt = "clts", .letter = 'w'},
+ [ASGTS] = {.fun = binary, .txt = "cgts", .letter = 'w'},
+ [ASLES] = {.fun = binary, .txt = "cles", .letter = 'w'},
+ [ASGES] = {.fun = binary, .txt = "cges", .letter = 'w'},
+ [ASEQS] = {.fun = binary, .txt = "ceqs", .letter = 'w'},
+ [ASNES] = {.fun = binary, .txt = "cnes", .letter = 'w'},
+
+ [ASADDD] = {.fun = binary, .txt = "add", .letter = 'd'},
+ [ASSUBD] = {.fun = binary, .txt = "sub", .letter = 'd'},
+ [ASMULD] = {.fun = binary, .txt = "mul", .letter = 'd'},
+ [ASDIVD] = {.fun = binary, .txt = "div", .letter = 'd'},
+ [ASLTD] = {.fun = binary, .txt = "cltd", .letter = 'w'},
+ [ASGTD] = {.fun = binary, .txt = "cgtd", .letter = 'w'},
+ [ASLED] = {.fun = binary, .txt = "cled", .letter = 'w'},
+ [ASGED] = {.fun = binary, .txt = "cged", .letter = 'w'},
+ [ASEQD] = {.fun = binary, .txt = "ceqd", .letter = 'w'},
+ [ASNED] = {.fun = binary, .txt = "cned", .letter = 'w'},
+
+ [ASEXTBW] = {.fun = unary, .txt = "extsb", .letter = 'w'},
+ [ASUEXTBW]= {.fun = unary, .txt = "extub", .letter = 'w'},
+ [ASEXTBL] = {.fun = unary, .txt = "extsb", .letter = 'l'},
+ [ASUEXTBL]= {.fun = unary, .txt = "extub", .letter = 'l'},
+ [ASEXTHW] = {.fun = unary, .txt = "extsh", .letter = 'w'},
+ [ASUEXTHW]= {.fun = unary, .txt = "extuh", .letter = 'w'},
+ [ASEXTWL] = {.fun = unary, .txt = "extsw", .letter = 'l'},
+ [ASUEXTWL]= {.fun = unary, .txt = "extuw", .letter = 'l'},
+
+ [ASSTOL] = {.fun = unary, .txt = "stosi", .letter = 'l'},
+ [ASSTOW] = {.fun = unary, .txt = "stosi", .letter = 'w'},
+ [ASDTOL] = {.fun = unary, .txt = "dtosi", .letter = 'l'},
+ [ASDTOW] = {.fun = unary, .txt = "dtosi", .letter = 'w'},
+
+ [ASSWTOD] = {.fun = unary, .txt = "swtof", .letter = 'd'},
+ [ASSWTOS] = {.fun = unary, .txt = "swtof", .letter = 's'},
+ [ASSLTOD] = {.fun = unary, .txt = "sltof", .letter = 'd'},
+ [ASSLTOS] = {.fun = unary, .txt = "sltof", .letter = 's'},
+
+ [ASEXTS] = {.fun = unary, .txt = "exts", .letter = 'd'},
+ [ASTRUNCD] = {.fun = unary, .txt = "truncd", .letter = 's'},
+
+ [ASBRANCH] = {.fun = branch},
+ [ASJMP] = {.fun = jmp},
+ [ASRET] = {.fun = ret},
+ [ASCALL] = {.fun = call},
+ [ASCALLE] = {.fun = ecall, .txt = ")"},
+ [ASCALLEX] = {.fun = ecall, .txt = ", ...)"},
+ [ASPAR] = {.fun = param, .txt = "%s %s, "},
+ [ASPARE] = {.fun = param, .txt = "%s %s"},
+ [ASALLOC] = {.fun = alloc},
+ [ASFORM] = {.fun = form2local},
+
+ [ASVSTAR] = {.fun = vastart},
+ [ASVARG] = {.fun = vaarg},
+};
+
+static char buff[ADDR_LEN];
+/*
+ * : is for user-defined Aggregate Types
+ * $ is for globals (represented by a pointer)
+ * % is for function-scope temporaries
+ * @ is for block labels
+ */
+static char
+sigil(Symbol *sym)
+{
+ switch (sym->kind) {
+ case SEXTRN:
+ case SGLOB:
+ case SPRIV:
+ case SLOCAL:
+ return '$';
+ case SAUTO:
+ case STMP:
+ return '%';
+ case SLABEL:
+ return '@';
+ default:
+ abort();
+ }
+}
+
+static char *
+symname(Symbol *sym)
+{
+ char c = sigil(sym);
+
+ if (sym->name) {
+ switch (sym->kind) {
+ case SEXTRN:
+ case SGLOB:
+ sprintf(buff, "%c%s", c, sym->name);
+ return buff;
+ case SLOCAL:
+ case SPRIV:
+ case SAUTO:
+ sprintf(buff, "%c%s.%u", c, sym->name, sym->id);
+ return buff;
+ default:
+ abort();
+ }
+ }
+ sprintf(buff, "%c.%u", c, sym->numid);
+
+ return buff;
+}
+
+static void
+emitconst(Node *np)
+{
+ switch (np->type.size) {
+ case 1:
+ printf("%d", (int) np->u.i & 0xFF);
+ break;
+ case 2:
+ printf("%d", (int) np->u.i & 0xFFFF);
+ break;
+ case 4:
+ printf("%ld", (long) np->u.i & 0xFFFFFFFF);
+ break;
+ case 8:
+ printf("%lld", (long long) np->u.i);
+ break;
+ default:
+ abort();
+ }
+}
+
+static void
+emittree(Node *np)
+{
+ if (!np)
+ return;
+
+ switch (np->op) {
+ case OSTRING:
+ printf("\"%s\"", np->u.s);
+ free(np->u.s);
+ np->u.s = NULL;
+ break;
+ case OCONST:
+ emitconst(np);
+ break;
+ case OADDR:
+ emittree(np->left);
+ break;
+ case OMEM:
+ fputs(symname(np->u.sym), stdout);
+ break;
+ default:
+ emittree(np->left);
+ printf(" %c ", np->op);
+ emittree(np->right);
+ break;
+ }
+}
+
+static char *
+size2asm(Type *tp)
+{
+ if (tp->flags & STRF) {
+ return "b";
+ } else if (tp->flags & INTF) {
+ switch (tp->size) {
+ case 1:
+ return "b";
+ case 2:
+ return "h";
+ case 4:
+ return "w";
+ case 8:
+ return "l";
+ }
+ } else if (tp->flags & FLOATF) {
+ if (tp->size == 4)
+ return "s";
+ else if (tp->size == 8)
+ return "d";
+ }
+ abort();
+}
+
+void
+defglobal(Symbol *sym)
+{
+ if (sym->kind == SEXTRN)
+ return;
+ if (sym->kind == SGLOB)
+ fputs("export ", stdout);
+ printf("data %s = {\n", symname(sym));
+ if (sym->type.flags & INITF)
+ return;
+ printf("\tz\t%lu\n}\n", sym->type.size);
+}
+
+void
+defpar(Symbol *sym)
+{
+ sym->type.flags |= PARF;
+}
+
+void
+defvar(Symbol *sym)
+{
+ if (sym->kind == SREG)
+ sym->kind = SAUTO;
+}
+
+void
+data(Node *np)
+{
+ printf("\t%s\t", size2asm(&np->type));
+ emittree(np);
+ putchar(',');
+ putchar('\n');
+}
+
+static char *
+size2stack(Type *tp)
+{
+ if (tp->flags & INTF) {
+ switch (tp->size) {
+ case 1:
+ case 2:
+ case 4:
+ return "w";
+ case 8:
+ return "l";
+ }
+ } else if (tp->flags & FLOATF) {
+ if (tp->size == 4)
+ return "s";
+ else if (tp->size == 8)
+ return "d";
+ } else if (tp->size == 0) {
+ return "w";
+ }
+ abort();
+}
+
+void
+writeout(void)
+{
+ Symbol *p;
+ Type *tp;
+ char *sep, *name;
+ int haslabel = 0;
+
+ if (!curfun)
+ return;
+ if (curfun->kind == SGLOB)
+ fputs("export ", stdout);
+ printf("function %s %s(", size2stack(&curfun->rtype), symname(curfun));
+
+ /* declare formal parameters */
+ for (sep = "", p = locals; p; p = p->next, sep = ",") {
+ if ((p->type.flags & PARF) == 0)
+ break;
+ printf("%s%s %s.val", sep, size2stack(&p->type), symname(p));
+ }
+ printf("%s)\n{\n", (curfun->type.flags&ELLIPS) ? ", ..." : "");
+
+ /* emit assembler instructions */
+ for (pc = prog; pc; pc = pc->next) {
+ if (pc->label) {
+ haslabel = 1;
+ printf("%s\n", symname(pc->label));
+ }
+ if (!pc->op)
+ continue;
+ if (pc->flags&BBENTRY && !haslabel)
+ printf("%s\n", symname(newlabel()));
+ (*optbl[pc->op].fun)();
+ if (!pc->label)
+ haslabel = 0;
+ }
+
+ puts("}");
+}
+
+static char *
+addr2txt(Addr *a)
+{
+ switch (a->kind) {
+ case SCONST:
+ sprintf(buff, "%llu", (unsigned long long) a->u.i);
+ return buff;
+ case SAUTO:
+ case SLABEL:
+ case STMP:
+ case SGLOB:
+ case SEXTRN:
+ case SPRIV:
+ case SLOCAL:
+ return symname(a->u.sym);
+ default:
+ abort();
+ }
+}
+
+static void
+binary(void)
+{
+ struct opdata *p = &optbl[pc->op];
+ char to[ADDR_LEN], from1[ADDR_LEN], from2[ADDR_LEN];
+
+ strcpy(to, addr2txt(&pc->to));
+ strcpy(from1, addr2txt(&pc->from1));
+ strcpy(from2, addr2txt(&pc->from2));
+ printf("\t%s =%c\t%s\t%s,%s\n", to, p->letter, p->txt, from1, from2);
+}
+
+static void
+ldir(void)
+{
+ struct opdata *p = &optbl[pc->op];
+ char to[ADDR_LEN], from[ADDR_LEN];
+ /* TODO: what type do we use for the size? */
+
+ /* TODO: it is pending */
+}
+
+static void
+store(void)
+{
+ struct opdata *p = &optbl[pc->op];
+ char to[ADDR_LEN], from[ADDR_LEN];
+
+ strcpy(to, addr2txt(&pc->to));
+ strcpy(from, addr2txt(&pc->from1));
+ printf("\t\t%s%c\t%s,%s\n", p->txt, p->letter, from, to);
+}
+
+static void
+unary(void)
+{
+ struct opdata *p = &optbl[pc->op];
+ char to[ADDR_LEN], from[ADDR_LEN];
+
+ strcpy(to, addr2txt(&pc->to));
+ strcpy(from, addr2txt(&pc->from1));
+ printf("\t%s =%c\t%s\t%s\n", to, p->letter, p->txt, from);
+}
+
+static void
+call(void)
+{
+ struct opdata *p = &optbl[pc->op];
+ char to[ADDR_LEN], from[ADDR_LEN];
+ Symbol *sym = pc->to.u.sym;
+
+ strcpy(to, addr2txt(&pc->to));
+ strcpy(from, addr2txt(&pc->from1));
+ printf("\t%s =%s\tcall\t%s(",
+ to, size2stack(&sym->type), from);
+}
+
+static void
+param(void)
+{
+ Symbol *sym = pc->from2.u.sym;
+
+ printf(optbl[pc->op].txt,
+ size2stack(&sym->type), addr2txt(&pc->from1));
+}
+
+static void
+ecall(void)
+{
+ struct opdata *p = &optbl[pc->op];
+
+ puts(p->txt);
+}
+
+static void
+ret(void)
+{
+ if (pc->from1.kind == SNONE)
+ puts("\t\tret");
+ else
+ printf("\t\tret\t%s\n", addr2txt(&pc->from1));
+}
+
+static void
+jmp(void)
+{
+ printf("\t\tjmp\t%s\n", addr2txt(&pc->from1));
+}
+
+static void
+branch(void)
+{
+ char to[ADDR_LEN], from1[ADDR_LEN], from2[ADDR_LEN];
+
+ strcpy(to, addr2txt(&pc->to));
+ strcpy(from1, addr2txt(&pc->from1));
+ strcpy(from2, addr2txt(&pc->from2));
+ printf("\t\tjnz\t%s,%s,%s\n", to, from1, from2);
+}
+
+static void
+vastart(void)
+{
+ printf("\t\tvastart %s\n", addr2txt(&pc->from1));
+}
+
+static void
+vaarg(void)
+{
+ Symbol *sym = pc->to.u.sym;
+ Type *tp = &sym->type;
+ char to[ADDR_LEN], from[ADDR_LEN];
+
+ strcpy(to, addr2txt(&pc->to));
+ strcpy(from, addr2txt(&pc->from1));
+ printf("\t\t%s =%s vaarg %s\n", to, size2asm(tp), from);
+}
+
+static void
+alloc(void)
+{
+ Symbol *sym = pc->to.u.sym;
+ Type *tp = &sym->type;
+ extern Type ptrtype;
+
+ printf("\t%s =%s\talloc%lu\t%lu\n",
+ symname(sym), size2asm(&ptrtype), tp->align+3 & ~3, tp->size);
+}
+
+static void
+form2local(void)
+{
+ Symbol *sym = pc->to.u.sym;
+ Type *tp = &sym->type;
+ char *name = symname(sym);
+
+ printf("\t\tstore%s\t%s.val,%s\n", size2asm(tp), name, name);
+}
+
+void
+endinit(void)
+{
+ puts("}");
+}
+
+void
+getbblocks(void)
+{
+ Inst *i;
+
+ if (!prog)
+ return;
+
+ prog->flags |= BBENTRY;
+ for (pc = prog; pc; pc = pc->next) {
+ switch (pc->op) {
+ case ASBRANCH:
+ i = pc->from2.u.sym->u.inst;
+ i->flags |= BBENTRY;
+ case ASJMP:
+ i = pc->from1.u.sym->u.inst;
+ i->flags |= BBENTRY;
+ case ASRET:
+ if (pc->next)
+ pc->next->flags |= BBENTRY;
+ break;
+ }
+ }
+}
--- /dev/null
+++ b/cc2/target/qbe_amd64-sysv/optm.c
@@ -1,0 +1,58 @@
+/* See LICENSE file for copyright and license details. */
+static char sccsid[] = "@(#) ./cc2/arch/qbe/optm.c";
+
+#include <stddef.h>
+
+#include "../../../inc/cc.h"
+#include "../../cc2.h"
+
+Node *
+optm_dep(Node *np)
+{
+ int op = np->op;
+ Node *p, *dst, *next = np->next;
+ Symbol *sym, *osym;
+
+ switch (op) {
+ case OEFUN:
+ /*
+ * In QBE we need at the end of a basic block
+ * a jump, so we have to ensure that the last
+ * statement of the function is a ret, a jmp
+ * or a branch. In the same way, QBE does
+ * not accept labels at the end of a function
+ * (ONOP is used for labels) so we have to add
+ * a ret there, and in the case of branches
+ * we need a label for the next statement
+ */
+ op = (np->prev) ? np->prev->op : 0;
+ if (!op || op == ONOP || op == OBRANCH || (op != ORET && op != OJMP))
+ addstmt(newnode(ORET), KEEPCUR);
+ break;
+ case OBRANCH:
+ if (!next->label) {
+ sym = getsym(TMPSYM);
+ sym->kind = SLABEL;
+ next->label = sym;
+ }
+ case OJMP:
+ for (;;) {
+ dst = np->u.sym->u.stmt;
+ if (dst->op != OJMP)
+ break;
+ np->u.sym = dst->u.sym;
+ }
+ for (p = np->next; p; p = p->next) {
+ if (p == dst)
+ return NULL;
+ if (p->op == ONOP ||
+ p->op == OBLOOP ||
+ p->op == OELOOP) {
+ continue;
+ }
+ break;
+ }
+ break;
+ }
+ return np;
+}
--- /dev/null
+++ b/cc2/target/qbe_amd64-sysv/target.mk
@@ -1,0 +1,6 @@
+
+OBJ-qbe_amd64-sysv = $(OBJ) \
+ target/qbe_amd64-sysv/cgen.o \
+ target/qbe_amd64-sysv/optm.o \
+ target/qbe_amd64-sysv/code.o \
+ target/qbe_amd64-sysv/types.o
--- /dev/null
+++ b/cc2/target/qbe_amd64-sysv/types.c
@@ -1,0 +1,94 @@
+/* See LICENSE file for copyright and license details. */
+static char sccsid[] = "@(#) ./cc2/arch/qbe/types.c";
+
+#include "../../../inc/cc.h"
+#include "../../cc2.h"
+
+
+Type int8type = {
+ .flags = SIGNF | INTF,
+ .size = 1,
+ .align = 1
+};
+
+Type int16type = {
+ .flags = SIGNF | INTF,
+ .size = 2,
+ .align = 2
+};
+
+Type int32type = {
+ .flags = SIGNF | INTF,
+ .size = 4,
+ .align = 4
+};
+
+Type int64type = {
+ .flags = SIGNF | INTF,
+ .size = 8,
+ .align = 8
+};
+
+Type uint8type = {
+ .flags = INTF,
+ .size = 1,
+ .align = 1
+};
+
+Type uint16type = {
+ .flags = INTF,
+ .size = 2,
+ .align = 2
+};
+
+Type uint32type = {
+ .flags = INTF,
+ .size = 4,
+ .align = 4
+};
+
+Type uint64type = {
+ .flags = INTF,
+ .size = 8,
+ .align = 2
+};
+
+Type ptrtype = {
+ .flags = INTF,
+ .size = 8,
+ .align = 8
+};
+
+Type booltype = {
+ .flags = INTF,
+ .size = 1,
+ .align = 1
+};
+
+Type float32type = {
+ .flags = FLOATF,
+ .size = 4,
+ .align = 4
+};
+
+Type float64type = {
+ .flags = FLOATF,
+ .size = 8,
+ .align = 8
+};
+
+Type float80type = {
+ .flags = FLOATF,
+ .size = 16,
+ .align = 16
+};
+
+Type voidtype = {
+ .size = 0,
+ .align = 0
+};
+
+Type arg_type = {
+ .size = 24,
+ .align = 8
+};
--- /dev/null
+++ b/cc2/target/z80-scc/arch.h
@@ -1,0 +1,1 @@
+/* See LICENSE file for copyright and license details. */
--- /dev/null
+++ b/cc2/target/z80-scc/cgen.c
@@ -1,0 +1,68 @@
+/* See LICENSE file for copyright and license details. */
+static char sccsid[] = "@(#) ./cc2/arch/z80/cgen.c";
+
+#include "arch.h"
+#include "../../../inc/cc.h"
+#include "../../cc2.h"
+
+Node *
+cgen(Node *np)
+{
+}
+
+/*
+ * This is strongly influenced by
+ * http://plan9.bell-labs.com/sys/doc/compiler.ps (/sys/doc/compiler.ps)
+ * calculate addresability as follows
+ * AUTO => 11 value+fp
+ * REG => 13 reg
+ * STATIC => 12 (value)
+ * CONST => 20 $value
+ */
+Node *
+sethi(Node *np)
+{
+ Node *lp, *rp;
+
+ if (!np)
+ return np;
+
+ np->complex = 0;
+ np->address = 0;
+ lp = np->left;
+ rp = np->right;
+ switch (np->op) {
+ case OAUTO:
+ np->address = 11;
+ break;
+ case OREG:
+ np->address = 13;
+ break;
+ case OMEM:
+ np->address = 12;
+ break;
+ case OCONST:
+ np->address = 20;
+ break;
+ default:
+ sethi(lp);
+ sethi(rp);
+ break;
+ }
+
+ if (np->address > 10)
+ return np;
+ if (lp)
+ np->complex = lp->complex;
+ if (rp) {
+ int d = np->complex - rp->complex;
+
+ if (d == 0)
+ ++np->complex;
+ else if (d < 0)
+ np->complex = rp->complex;
+ }
+ if (np->complex == 0)
+ ++np->complex;
+ return np;
+}
--- /dev/null
+++ b/cc2/target/z80-scc/code.c
@@ -1,0 +1,229 @@
+/* See LICENSE file for copyright and license details. */
+static char sccsid[] = "@(#) ./cc2/arch/z80/code.c";
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <cstd.h>
+#include "arch.h"
+#include "../../../inc/cc.h"
+#include "../../cc2.h"
+
+enum segment {
+ CODESEG,
+ DATASEG,
+ BSSSEG,
+ NOSEG
+};
+
+static int curseg = NOSEG;
+static unsigned long offpar, offvar;
+
+static void
+segment(int seg)
+{
+ static char *txt[] = {
+ [CODESEG] = "\tCSEG\n",
+ [DATASEG] = "\tDSEG\n",
+ [BSSSEG] = "\tASEG\n",
+ };
+
+ if (seg == curseg)
+ return;
+ fputs(txt[seg], stdout);
+ curseg = seg;
+}
+
+static char *
+symname(Symbol *sym)
+{
+ static char name[INTIDENTSIZ+1];
+
+ if (sym->name) {
+ switch (sym->kind) {
+ case SGLOB:
+ case SEXTRN:
+ snprintf(name, sizeof(name), "_%s", sym->name);
+ return name;
+ case SPRIV:
+ return sym->name;
+ }
+ }
+
+ sprintf(name, ".%d", sym->numid);
+
+ return name;
+}
+
+static void
+label(Symbol *sym)
+{
+ int seg;
+ char *name = symname(sym);
+
+ if (sym->type.flags & FUNF)
+ seg = CODESEG;
+ else if (sym->type.flags & INITF)
+ seg = DATASEG;
+ else
+ seg = BSSSEG;
+ segment(seg);
+
+ switch (sym->kind) {
+ case SEXTRN:
+ printf("\tEXTRN\t%s\n", name);
+ return;
+ case SGLOB:
+ printf("\tPUBLIC\t%s\n", name);
+ break;
+ }
+
+ printf("%s:\n", name);
+}
+
+static void
+emitconst(Node *np)
+{
+ switch (np->type.size) {
+ case 1:
+ printf("%d", (int) np->u.i & 0xFF);
+ break;
+ case 2:
+ printf("%d", (int) np->u.i & 0xFFFF);
+ break;
+ case 4:
+ printf("%ld", (long) np->u.i & 0xFFFFFFFF);
+ break;
+ default:
+ abort();
+ }
+}
+
+static void
+emittree(Node *np)
+{
+ if (!np)
+ return;
+
+ switch (np->op) {
+ case OSTRING:
+ printf("\"%s\"", np->u.s);
+ free(np->u.s);
+ np->u.s = NULL;
+ break;
+ case OCONST:
+ emitconst(np);
+ break;
+ case OADDR:
+ emittree(np->left);
+ break;
+ case OMEM:
+ fputs(symname(np->u.sym), stdout);
+ break;
+ default:
+ emittree(np->left);
+ printf(" %c ", np->op);
+ emittree(np->right);
+ break;
+ }
+}
+
+static void
+size2asm(Type *tp)
+{
+ char *s;
+
+ /*
+ * In z80 we can ignore the alignment
+ */
+ if (tp->flags & STRF) {
+ s = "\tDB\t";
+ } else {
+ switch (tp->size) {
+ case 1:
+ s = "\tDB\t";
+ break;
+ case 2:
+ s = "\tDW\t";
+ break;
+ case 4:
+ s = "\tDD\t";
+ break;
+ default:
+ s = "\tDS\t%lu,";
+ break;
+ }
+ }
+ printf(s, tp->size);
+}
+
+void
+newfun()
+{
+ offpar = offvar = 0;
+}
+
+void
+defpar(Symbol *sym)
+{
+ unsigned long align, size;
+
+ if (sym->kind != SREG && sym->kind != SAUTO)
+ return;
+ align = sym->type.align;
+ size = sym->type.size;
+
+ offpar -= align-1 & ~align;
+ sym->u.off = offpar;
+ offpar -= size;
+ sym->kind = SAUTO;
+}
+
+void
+defvar(Symbol *sym)
+{
+ unsigned long align, size;
+
+ if (sym->kind != SREG && sym->kind != SAUTO)
+ return;
+ align = sym->type.align;
+ size = sym->type.size;
+
+ offvar += align-1 & ~align;
+ sym->u.off = offvar;
+ offvar += size;
+ sym->kind = SAUTO;
+}
+
+void
+defglobal(Symbol *sym)
+{
+ label(sym);
+ if (sym->kind == SEXTRN || (sym->type.flags & INITF))
+ return;
+ size2asm(&sym->type);
+ puts("0");
+}
+
+void
+data(Node *np)
+{
+ size2asm(&np->type);
+ emittree(np);
+ putchar('\n');
+}
+
+void
+writeout(void)
+{
+}
+
+void
+endinit(void)
+{
+}
+
+void
+getbblocks(void)
+{
+}
--- /dev/null
+++ b/cc2/target/z80-scc/optm.c
@@ -1,0 +1,11 @@
+/* See LICENSE file for copyright and license details. */
+static char sccsid[] = "@(#) ./cc2/arch/z80/optm.c";
+
+#include "../../../inc/cc.h"
+#include "../../cc2.h"
+
+Node *
+optm_dep(Node *np)
+{
+ return np;
+}
--- /dev/null
+++ b/cc2/target/z80-scc/target.mk
@@ -1,0 +1,7 @@
+
+OBJ-z80-scc = $(OBJ) \
+ target/z80-scc/cgen.o \
+ target/z80-scc/optm.o \
+ target/z80-scc/code.o \
+ target/z80-scc/types.o
+
--- /dev/null
+++ b/cc2/target/z80-scc/types.c
@@ -1,0 +1,95 @@
+/* See LICENSE file for copyright and license details. */
+static char sccsid[] = "@(#) ./cc2/arch/z80/types.c";
+
+#include "../../../inc/cc.h"
+#include "../../cc2.h"
+
+
+Type int8type = {
+ .flags = SIGNF | INTF,
+ .size = 1,
+ .align = 1
+};
+
+Type int16type = {
+ .flags = SIGNF | INTF,
+ .size = 2,
+ .align = 1
+};
+
+Type int32type = {
+ .flags = SIGNF | INTF,
+ .size = 4,
+ .align = 1
+};
+
+Type int64type = {
+ .flags = SIGNF | INTF,
+ .size = 8,
+ .align = 1
+};
+
+Type uint8type = {
+ .flags = INTF,
+ .size = 1,
+ .align = 1
+};
+
+Type uint16type = {
+ .flags = INTF,
+ .size = 2,
+ .align = 1
+};
+
+Type uint32type = {
+ .flags = INTF,
+ .size = 4,
+ .align = 1
+};
+
+Type uint64type = {
+ .flags = INTF,
+ .size = 8,
+ .align = 1
+};
+
+Type ptrtype = {
+ .flags = INTF,
+ .size = 2,
+ .align = 1
+};
+
+Type booltype = {
+ .flags = INTF,
+ .size = 1,
+ .align = 1
+};
+
+Type float32type = {
+ .flags = FLOATF,
+ .size = 4,
+ .align = 1
+};
+
+Type float64type = {
+ .flags = FLOATF,
+ .size = 4,
+ .align = 1
+};
+
+Type float80type = {
+ .flags = FLOATF,
+ .size = 4,
+ .align = 1
+};
+
+Type voidtype = {
+ .size = 0,
+ .align = 0
+};
+
+/* this types is not going to be used in this arch */
+Type arg_type = {
+ .size = 0,
+ .align = 0
+};
--- a/config.mk
+++ b/config.mk
@@ -2,11 +2,21 @@
VERSION = 0.1
## Customize below to fit your system
-ARCHS = z80 i386-sysv amd64-sysv qbe
-SYSS = linux openbsd
-# default architecure used in nested makefiles
-ARCH = qbe
-SYS = linux
+# TARGET is defined by backend-arch-abi-sys
+
+TARGETS = z80-scc-dos-com \
+ amd64-sysv-linux-elf \
+ i386-sysv-linux-elf \
+ amd64-sysv-openbsd-elf
+
+# USEQBE selects QBE by default in the targets that support it
+USEQBE = 1
+
+#MKQBE enable build of
+MKQBE = 1
+
+TARGET = amd64-sys-linux-elf
+
DRIVER = posix
# Can be c89 or c99
@@ -23,14 +33,11 @@
AS = as
# for Plan9 add -D_SUSV2_SOURCE
-SCC_CFLAGS = -DARCH=\"$(ARCH)\" \
- -DSYS=\"$(SYS)\" \
- $(CSTDINC) \
- -DPREFIX=\"$(PREFIX)\" \
+SCC_CFLAGS = $(MOREFLAGS) \
-g \
$(CFLAGS)
-SCC_LDFLAGS = $(LDFLAGS)
+SCC_LDFLAGS = -L$(LIBDIR)/ $(LDFLAGS)
.s.o:
$(AS) $< -o $@
@@ -40,3 +47,4 @@
.c:
$(CC) $(SCC_CFLAGS) $(SCC_LDFLAGS) -o $@ $<
+
--- a/crt/Makefile
+++ /dev/null
@@ -1,11 +1,0 @@
-.POSIX:
-
-include ../config.mk
-
-all: crt-$(ARCH)-$(SYS).o
-
-crt-$(ARCH)-$(SYS).o: $(ARCH)-$(SYS)/crt.o
- ln -f $(ARCH)-$(SYS)/crt.o $@
-
-clean:
- rm -f */crt.o crt-*.o
--- a/crt/amd64-sysv-linux/crt.s
+++ /dev/null
@@ -1,8 +1,0 @@
- .file "crt.s"
-
- .text
- .global _start
-_start:
- call main
- movl %eax, %edi
- call exit
--- a/crt/amd64-sysv-openbsd/crt.s
+++ /dev/null
@@ -1,23 +1,0 @@
- .file "crt.s"
-
- .section ".note.openbsd.ident", "a"
- .p2align 2
- .long 8
- .long 4
- .long 1
- .ascii "OpenBSD\0"
- .long 0
- .p2align 2
-
- .text
- .align 8
- .global _start
-_start:
- call main
- movl %eax, %edi
- call exit
-
- .data
- .global __guard_local
-__guard_local:
- .long 0
--- a/crt/i386-sysv-linux/crt.s
+++ /dev/null
@@ -1,1 +1,0 @@
-/* TODO */
--- a/crt/i386-sysv-openbsd/crt.s
+++ /dev/null
@@ -1,1 +1,0 @@
-/* TODO */
--- a/crt/qbe-linux/crt.s
+++ /dev/null
@@ -1,8 +1,0 @@
- .file "crt.s"
-
- .text
- .global _start
-_start:
- call main
- movl %eax, %edi
- call exit
--- a/crt/qbe-openbsd/crt.s
+++ /dev/null
@@ -1,23 +1,0 @@
- .file "crt.s"
-
- .section ".note.openbsd.ident", "a"
- .p2align 2
- .long 8
- .long 4
- .long 1
- .ascii "OpenBSD\0"
- .long 0
- .p2align 2
-
- .text
- .align 8
- .global _start
-_start:
- call main
- movl %eax, %edi
- call exit
-
- .data
- .global __guard_local
-__guard_local:
- .long 0
--- a/crt/z80-linux/crt.s
+++ /dev/null
@@ -1,1 +1,0 @@
-/* TODO */
--- a/crt/z80-openbsd/crt.s
+++ /dev/null
@@ -1,1 +1,0 @@
-/* TODO */
--- /dev/null
+++ b/driver/Makefile
@@ -1,0 +1,7 @@
+# See LICENSE file for copyright and license details.
+.POSIX:
+
+include ../config.mk
+
+all dep clean distclean:
+ cd $(DRIVER) && $(MAKE) $@
--- a/driver/posix/Makefile
+++ b/driver/posix/Makefile
@@ -3,24 +3,33 @@
include ../../config.mk
-OBJS = scc.o
+LIBDIR = ../../lib/cc
+OBJ = scc.o
+HDR = config.h \
+ ../../inc/cc.h \
+ ../../inc/arg.h \
+ ../../inc/syslibs.h \
+ ../../inc/ldflags.h
+
all: scc
-$(OBJS): ../../inc/cc.h ../../inc/arg.h ../../inc/syslibs.h ../../inc/ldflags.h
+dep:
+ PREFIX=$(PREFIX) USEQBE=$(USEQBE) ./gendep.sh $(TARGET)
-scc: $(OBJS) ../../lib/libcc.a
- $(CC) $(SCC_LDFLAGS) $(OBJS) ../../lib/libcc.a -o $@
+$(OBJ): $(HDR)
-../../inc/syslibs.h: ../../inc/syslibs.def.h
- cp -f ../../inc/syslibs.def.h ../../inc/syslibs.h
+scc: $(OBJ) $(LIBDIR)/libcc.a
+ $(CC) $(SCC_LDFLAGS) $(OBJ) -lcc -o $@
-../../inc/ldflags.h: ../../inc/ldflags.def.h
- cp -f ../../inc/ldflags.def.h ../../inc/ldflags.h
+$(LIBDIR)/libcc.a:
+ cd $(LIBDIR) && $(MAKE)
-../../lib/libcc.a:
- cd ../../lib && $(MAKE) -e
-
clean:
- rm -f $(OBJS)
+ rm -f $(OBJ)
rm -f scc
+
+distclean: clean
+ rm -f config.h
+
+include ../../lib/cc/libdep.mk
--- /dev/null
+++ b/driver/posix/gendep.sh
@@ -1,0 +1,18 @@
+#!/bin/sh
+
+set -e
+
+rm -f config.h
+trap "rm -f $$.h" 0 2 3
+
+PREFIX=${PREFIX-$HOME}
+USEQBE=${USEQBE:-1}
+
+echo $@ |
+(IFS=- read arch abi sys format r
+echo \#define PREFIX \"$PREFIX\"
+echo \#define USEQBE $USEQBE
+echo \#define ARCH \"$arch\"
+echo \#define SYS \"$sys\"
+echo \#define ABI \"$abi\"
+echo \#define FORMAT \"$format\") > $$.h && mv $$.h config.h
--- a/driver/posix/scc.c
+++ b/driver/posix/scc.c
@@ -14,6 +14,7 @@
#include <stdlib.h>
#include <string.h>
+#include "config.h"
#include "../../inc/arg.h"
#include "../../inc/cc.h"
#include "../../inc/syslibs.h"
@@ -53,11 +54,12 @@
};
char *argv0;
-static char *arch, *sys, *execpath, *objfile, *outfile;
+static char *arch, *sys, *abi, *format;
+static char *execpath, *objfile, *outfile;
static char *tmpdir;
static size_t tmpdirln;
static struct items objtmp, objout;
-static int Mflag, Eflag, Sflag, cflag, dflag, kflag, sflag;
+static int Mflag, Eflag, Sflag, cflag, dflag, kflag, sflag, Qflag = USEQBE;
static int devnullfd;
extern int failure;
@@ -99,7 +101,7 @@
inittool(int tool)
{
struct tool *t = &tools[tool];
- char *crt;
+ char *crt, *fmt;
int n;
if (t->init)
@@ -108,7 +110,8 @@
switch (tool) {
case CC1: /* FALLTHROUGH */
case CC2:
- n = snprintf(t->bin, sizeof(t->bin), "%s-%s", t->cmd, arch);
+ fmt = (Qflag && tool == CC2) ? "%s-qbe_%s-%s" : "%s-%s-%s";
+ n = snprintf(t->bin, sizeof(t->bin), fmt, t->cmd, arch, abi);
if (n < 0 || n >= sizeof(t->bin))
die("scc: target tool name too long");
@@ -359,10 +362,10 @@
nexttool = CC2;
break;
case CC2:
- if (!arch || strcmp(arch, "qbe"))
- nexttool = (Sflag || kflag) ? TEEAS : AS;
- else
+ if (Qflag)
nexttool = kflag ? TEEQBE : QBE;
+ else
+ nexttool = (Sflag || kflag) ? TEEAS : AS;
break;
case TEEQBE:
nexttool = QBE;
@@ -445,6 +448,10 @@
arch = ARCH;
if (!(sys = getenv("SYS")))
sys = SYS;
+ if (!(abi = getenv("ABI")))
+ abi = ABI;
+ if (!(format = getenv("FORMAT")))
+ format = FORMAT;
if (!(execpath = getenv("SCCEXECPATH")))
execpath = PREFIX "/libexec/scc";
@@ -512,6 +519,12 @@
EARGF(usage());
case 'w':
addarg(CC1, "-w");
+ break;
+ case 'q':
+ Qflag = 0;
+ break;
+ case 'Q':
+ Qflag = 1;
break;
case '-':
fprintf(stderr,
--- /dev/null
+++ b/inc/Makefile
@@ -1,0 +1,32 @@
+# See LICENSE file for copyright and license details.
+.POSIX:
+
+include ../config.mk
+
+HDR = ldflags.h sysincludes.h syslibs.h
+
+all:
+
+dep: $(HDR)
+
+ldflags.h:
+ rm -f $@ ; \
+ trap "rm -f $$$$.h" 0 2 3; \
+ cat < ldflags.def.h > $$$$.h; \
+ mv $$$$.h $@
+
+sysincludes.h:
+ rm -f $@ ; \
+ trap "rm -f $$$$.h" 0 2 3; \
+ sed 's,PREFIX,"$(PREFIX)",g' < sysincludes.def.h > $$$$.h && \
+ mv $$$$.h $@
+
+syslibs.h:
+ rm -f $@ ; \
+ trap "rm -f $$$$.h" 0 2 3; \
+ sed 's,PREFIX,"$(PREFIX)",g' < syslibs.def.h > $$$$.h && \
+ mv $$$$.h $@
+
+clean:
+distclean:
+ rm -f $(HDR)
--- a/inc/cc.h
+++ b/inc/cc.h
@@ -11,10 +11,6 @@
#define DBGON()
#endif
-#ifndef PREFIX
-#define PREFIX "/usr/local/"
-#endif
-
#define TINT long long
#define TUINT unsigned long long
#define TFLOAT double
--- a/inc/sysincludes.def.h
+++ b/inc/sysincludes.def.h
@@ -1,6 +1,6 @@
char *sysincludes[] = {
PREFIX "/include/scc/" ,
- PREFIX "/include/scc/bits/" ARCH "/",
+ PREFIX "/include/scc/bits/" TARGET "/",
/* configure below your standard sys include paths */
PREFIX "/include/",
PREFIX "/local/include/",
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -1,15 +1,15 @@
# See LICENSE file for copyright and license details.
.POSIX:
+
include ../config.mk
-OBJS = debug.o die.o newitem.o xcalloc.o xmalloc.o xrealloc.o xstrdup.o
+DIRS = cc
-all: libcc.a
-
-
-libcc.a: $(OBJS)
- ar $(ARFLAGS) $@ $?
- ranlib $@
-
-clean:
- rm -f *.o *.a
+all dep clean distclean:
+ @pwd=$$PWD; \
+ for i in $(DIRS); \
+ do \
+ cd $$i; \
+ $(MAKE) $@; \
+ cd $$pwd; \
+ done
--- /dev/null
+++ b/lib/c/Makefile
@@ -1,0 +1,7 @@
+# See LICENSE file for copyright and license details.
+.POSIX:
+
+include ../../config.mk
+
+all dep clean distclean:
+ cd src && CC=scc $(MAKE) -e $@
--- /dev/null
+++ b/lib/c/amd64-sysv-linux/Makefile
@@ -1,0 +1,6 @@
+# See LICENSE file for copyright and license details.
+.POSIX:
+
+include ../../../config.mk
+include ../common.mk
+
--- /dev/null
+++ b/lib/c/common.mk
@@ -1,0 +1,19 @@
+# See LICENSE file for copyright and license details.
+
+SRC=$(OBJ:.o=.c)
+
+all: libc.a
+
+libc.a: $(OBJ)
+ $(AR) $(ARFLAGS) $@ $?
+ ranlib $@
+
+dep:
+ ../gendep.sh
+
+clean:
+ rm -f $(OBJ)
+
+distclean: clean
+ rm -f $(SRC)
+ rm -f makefile
--- /dev/null
+++ b/lib/c/gendep.sh
@@ -1,0 +1,17 @@
+#!/bin/sh
+
+sed 's/\.o/.c/' ../obj.lst |
+while read src
+do
+ echo '#include "../src/'$src'"' > $src
+done
+
+(cat Makefile
+echo
+printf "OBJ ="
+while read i
+do
+ printf " %s" $i
+done < ../obj.lst
+echo) > makefile
+
--- /dev/null
+++ b/lib/c/include/assert.h
@@ -1,0 +1,13 @@
+/* See LICENSE file for copyright and license details. */
+#ifndef _ASSERT_H
+#define _ASSERT_H
+
+void __assert(char *exp, char *file, long line);
+
+#ifndef NDEBUG
+# define assert(exp) ((exp) ? (void) 0 : __assert(#exp, __FILE__, __LINE__))
+#else
+# define assert(exp) ((void)0)
+#endif
+
+#endif
--- /dev/null
+++ b/lib/c/include/bits/amd64-sysv/arch/limits.h
@@ -1,0 +1,17 @@
+#define SCHAR_MAX 0x7F
+#define SCHAR_MIN (-SCHAR_MIN-1)
+#define CHAR_MAX 0x7F
+#define CHAR_MIN (-CHAR_MAX-1)
+#define UCHAR_MAX 0xFF
+#define SHRT_MAX 0x7FFF
+#define SHRT_MIN (-SHRT_MAX-1)
+#define USHRT_MAX 0xFFFF
+#define INT_MAX 0x7FFFFFFF
+#define INT_MIN (-INT_MAX-1)
+#define UINT_MAX 0xFFFFFFFF
+#define LONG_MAX 0x7FFFFFFFFFFFFFFF
+#define LONG_MIN (-LONG_MAX-1)
+#define ULONG_MAX 0xFFFFFFFFFFFFFFFF
+#define LLONG_MAX 0x7FFFFFFFFFFFFFFF
+#define LLONG_MIN (-LLONG_MAX-1)
+#define ULLONG_MAX 0xFFFFFFFFFFFFFFFF
--- /dev/null
+++ b/lib/c/include/bits/amd64-sysv/arch/signal.h
@@ -1,0 +1,29 @@
+/* See LICENSE file for copyright and license details. */
+
+typedef int sig_atomic_t;
+
+#define SIG_ERR -1
+#define SIG_DFL 0
+#define SIG_IGN 1
+
+#define SIGHUP 1
+#define SIGINT 2
+#define SIGQUIT 3
+#define SIGILL 4
+#define SIGABRT 6
+#define SIGFPE 8
+#define SIGKILL 9
+#define SIGUSR1 10
+#define SIGSEGV 11
+#define SIGUSR2 12
+#define SIGPIPE 13
+#define SIGALRM 14
+#define SIGTERM 15
+#define SIGCHLD 17
+#define SIGCONT 18
+#define SIGSTOP 19
+#define SIGSSTP 20
+#define SIGTTIN 21
+#define SIGTTOU 22
+
+#define __NR_SIGNALS 23
--- /dev/null
+++ b/lib/c/include/bits/amd64-sysv/arch/stddef.h
@@ -1,0 +1,16 @@
+/* See LICENSE file for copyright and license details. */
+
+#ifndef _SIZET
+typedef unsigned long size_t;
+#define _SIZET
+#endif
+
+#ifndef _WCHAR_T
+typedef int wchar_t;
+#define _WCHAR_T
+#endif
+
+#ifndef _PTRDIFF_T
+typedef long ptrdiff_t;
+#define _PTRDIFF_T
+#endif
--- /dev/null
+++ b/lib/c/include/bits/amd64-sysv/arch/stdint.h
@@ -1,0 +1,117 @@
+/* See LICENSE file for copyright and license details. */
+
+#define INT8_MAX 0x7F
+#define INT8_MIN (-INT8_MAX-1)
+#define UINT8_MAX 0xFF
+
+#define INT16_MAX 0x7FFF
+#define INT16_MIN (-INT16_MAX-1)
+#define UINT16_MAX 0xFFFF
+
+#define INT32_MAX 0x7FFFFFFF
+#define INT32_MIN (-INT32_MAX-1)
+#define UINT32_MAX 0xFFFFFFFF
+
+#define INT64_MAX 0x7FFFFFFFFFFFFFFF
+#define INT64_MIN (-INT64_MAX-1)
+#define UINT64_MAX 0xFFFFFFFFFFFFFFFF
+
+#define INT_LEAST8_MIN INT8_MIN
+#define INT_LEAST8_MAX INT8_MAX
+#define UINT_LEAST8_MAX UINT8_MAX
+
+#define INT_LEAST16_MIN INT16_MIN
+#define INT_LEAST16_MAX INT16_MAX
+#define UINT_LEAST16_MAX UINT16_MAX
+
+#define INT_LEAST32_MIN INT32_MIN
+#define INT_LEAST32_MAX INT32_MAX
+#define UINT_LEAST32_MAX UINT32_MAX
+
+#define INT_LEAST64_MIN INT64_MIN
+#define INT_LEAST64_MAX INT64_MAX
+#define UINT_LEAST64_MAX UINT64_MAX
+
+#define INT_FAST8_MIN INT32_MIN
+#define INT_FAST8_MAX INT32_MAX
+#define UINT_FAST8_MAX UINT32_MAX
+
+#define INT_FAST16_MIN INT32_MIN
+#define INT_FAST16_MAX INT32_MAX
+#define UINT_FAST16_MAX UINT32_MAX
+
+#define INT_FAST32_MIN INT32_MIN
+#define INT_FAST32_MAX INT32_MAX
+#define UINT_FAST32_MAX UINT32_MAX
+
+#define INT_FAST64_MIN INT64_MIN
+#define INT_FAST64_MAX INT64_MAX
+#define UINT_FAST64_MAX UINT64_MAX
+
+#define INTPTR_MIN INT64_MIN
+#define INTPTR_MAX INT64_MAX
+#define UINTPTR_MAX UINT64_MAX
+
+#define INTMAX_MIN INT64_MIN
+#define INTMAX_MAX INT64_MAX
+#define UINTMAX_MAX UINT64_MAX
+
+#define PTRDIFF_MIN INT64_MIN
+#define PTRDIFF_MAX INT64_MAX
+
+#define SIG_ATOMIC_MIN INT32_MIN
+#define SIG_ATOMIC_MAX INT32_MAX
+
+#define SIZE_MAX UINT64_MAX
+
+#define WCHAR_MIN INT32_MIN
+#define WCHAR_MAX INT32_MAX
+
+#define INT8_C(x) x
+#define INT16_C(x) x
+#define INT32_C(x) x
+#define INT64_C(x) x ## L
+
+#define UINT8_C(x) x
+#define UINT16_C(x) x
+#define UINT32_C(x) x ## U
+#define UINT64_C(x) x ## UL
+
+#define INTMAX_C(x) x ## L
+#define UINTMAX_C(x) x ## UL
+
+typedef signed char int8_t;
+typedef short int16_t;
+typedef int int32_t;
+typedef long int64_t;
+
+typedef unsigned char uint8_t;
+typedef unsigned short uint16_t;
+typedef unsigned uint32_t;
+typedef unsigned long uint64_t;
+
+typedef signed char int8_least_t;
+typedef short int16_least_t;
+typedef int int32_least_t;
+typedef long int64_least_t;
+
+typedef unsigned char uint8_least_t;
+typedef unsigned short uint16_least_t;
+typedef unsigned uint32_least_t;
+typedef unsigned long uint64_least_t;
+
+typedef int int8_fast_t;
+typedef int int16_fast_t;
+typedef int int32_fast_t;
+typedef long int64_fast_t;
+
+typedef unsigned uint8_fast_t;
+typedef unsigned uint16_fast_t;
+typedef unsigned uint32_fast_t;
+typedef unsigned long uint64_fast_t;
+
+typedef long intptr_t;
+typedef unsigned long uintptr_t;
+
+typedef long intmax_t;
+typedef unsigned long uintmax_t;
--- /dev/null
+++ b/lib/c/include/bits/amd64-sysv/arch/stdio.h
@@ -1,0 +1,15 @@
+/* See LICENSE file for copyright and license details. */
+
+#ifndef _SIZET
+typedef unsigned long size_t;
+#define _SIZET
+#endif
+
+#define BUFSIZ 512
+#define FILENAME_MAX 256
+#define FOPEN_MAX 16
+
+#define TMP_MAX 25
+#define L_tmpnam 256
+
+typedef int fpos_t;
--- /dev/null
+++ b/lib/c/include/bits/amd64-sysv/arch/stdlib.h
@@ -1,0 +1,16 @@
+/* See LICENSE file for copyright and license details. */
+
+#ifndef _SIZET
+typedef unsigned long size_t;
+#define _SIZET
+#endif
+
+#define EXIT_FAILURE 1
+#define EXIT_SUCCESS 0
+
+#ifndef _WCHAR_T
+typedef int wchar_t;
+#define _WCHAR_T
+#endif
+
+#define _ALIGNTYPE long double
--- /dev/null
+++ b/lib/c/include/bits/amd64-sysv/arch/string.h
@@ -1,0 +1,5 @@
+/* See LICENSE file for copyright and license details. */
+
+#ifndef _SIZET
+typedef unsigned long size_t;
+#endif
--- /dev/null
+++ b/lib/c/include/bits/amd64-sysv/arch/time.h
@@ -1,0 +1,8 @@
+/* See LICENSE file for copyright and license details. */
+
+#ifndef _SIZET
+typedef unsigned long size_t;
+#define _SIZET
+#endif
+
+typedef long int time_t;
--- /dev/null
+++ b/lib/c/include/bits/i386-sysv/arch/limits.h
@@ -1,0 +1,17 @@
+#define SCHAR_MAX 0x7F
+#define SCHAR_MIN (-SCHAR_MIN-1)
+#define CHAR_MAX 0x7F
+#define CHAR_MIN (-CHAR_MAX-1)
+#define UCHAR_MAX 0xFF
+#define SHRT_MAX 0x7FFF
+#define SHRT_MIN (-SHRT_MAX-1)
+#define USHRT_MAX 0xFFFF
+#define INT_MAX 0x7FFFFFFF
+#define INT_MIN (-INT_MAX-1)
+#define UINT_MAX 0xFFFFFFFF
+#define LONG_MAX 0x7FFFFFFF
+#define LONG_MIN (-LONG_MAX-1)
+#define ULONG_MAX 0xFFFFFFFF
+#define LLONG_MAX 0x7FFFFFFFFFFFFFFF
+#define LLONG_MIN (-LLONG_MAX-1)
+#define ULLONG_MAX 0xFFFFFFFFFFFFFFFF
--- /dev/null
+++ b/lib/c/include/bits/i386-sysv/arch/signal.h
@@ -1,0 +1,29 @@
+/* See LICENSE file for copyright and license details. */
+
+typedef int sig_atomic_t;
+
+#define SIG_ERR -1
+#define SIG_DFL 0
+#define SIG_IGN 1
+
+#define SIGHUP 1
+#define SIGINT 2
+#define SIGQUIT 3
+#define SIGILL 4
+#define SIGABRT 6
+#define SIGFPE 8
+#define SIGKILL 9
+#define SIGUSR1 10
+#define SIGSEGV 11
+#define SIGUSR2 12
+#define SIGPIPE 13
+#define SIGALRM 14
+#define SIGTERM 15
+#define SIGCHLD 17
+#define SIGCONT 18
+#define SIGSTOP 19
+#define SIGSSTP 20
+#define SIGTTIN 21
+#define SIGTTOU 22
+
+#define __NR_SIGNALS 23
--- /dev/null
+++ b/lib/c/include/bits/i386-sysv/arch/stddef.h
@@ -1,0 +1,16 @@
+/* See LICENSE file for copyright and license details. */
+
+#ifndef _SIZET
+typedef unsigned long size_t;
+#define _SIZET
+#endif
+
+#ifndef _WCHAR_T
+typedef int wchar_t;
+#define _WCHAR_T
+#endif
+
+#ifndef _PTRDIFF_T
+typedef long ptrdiff_t;
+#define _PTRDIFF_T
+#endif
--- /dev/null
+++ b/lib/c/include/bits/i386-sysv/arch/stdint.h
@@ -1,0 +1,117 @@
+/* See LICENSE file for copyright and license details. */
+
+#define INT8_MAX 0x7F
+#define INT8_MIN (-INT8_MAX-1)
+#define UINT8_MAX 0xFF
+
+#define INT16_MAX 0x7FFF
+#define INT16_MIN (-INT16_MAX-1)
+#define UINT16_MAX 0xFFFF
+
+#define INT32_MAX 0x7FFFFFFF
+#define INT32_MIN (-INT32_MAX-1)
+#define UINT32_MAX 0xFFFFFFFF
+
+#define INT64_MAX 0x7FFFFFFFFFFFFFFF
+#define INT64_MIN (-INT64_MAX-1)
+#define UINT64_MAX 0xFFFFFFFFFFFFFFFF
+
+#define INT_LEAST8_MIN INT8_MIN
+#define INT_LEAST8_MAX INT8_MAX
+#define UINT_LEAST8_MAX UINT8_MAX
+
+#define INT_LEAST16_MIN INT16_MIN
+#define INT_LEAST16_MAX INT16_MAX
+#define UINT_LEAST16_MAX UINT16_MAX
+
+#define INT_LEAST32_MIN INT32_MIN
+#define INT_LEAST32_MAX INT32_MAX
+#define UINT_LEAST32_MAX UINT32_MAX
+
+#define INT_LEAST64_MIN INT64_MIN
+#define INT_LEAST64_MAX INT64_MAX
+#define UINT_LEAST64_MAX UINT64_MAX
+
+#define INT_FAST8_MIN INT32_MIN
+#define INT_FAST8_MAX INT32_MAX
+#define UINT_FAST8_MAX UINT32_MAX
+
+#define INT_FAST16_MIN INT32_MIN
+#define INT_FAST16_MAX INT32_MAX
+#define UINT_FAST16_MAX UINT32_MAX
+
+#define INT_FAST32_MIN INT32_MIN
+#define INT_FAST32_MAX INT32_MAX
+#define UINT_FAST32_MAX UINT32_MAX
+
+#define INT_FAST64_MIN INT64_MIN
+#define INT_FAST64_MAX INT64_MAX
+#define UINT_FAST64_MAX UINT64_MAX
+
+#define INTPTR_MIN INT32_MIN
+#define INTPTR_MAX INT32_MAX
+#define UINTPTR_MAX UINT32_MAX
+
+#define INTMAX_MIN INT64_MIN
+#define INTMAX_MAX INT64_MAX
+#define UINTMAX_MAX UINT64_MAX
+
+#define PTRDIFF_MIN INT32_MIN
+#define PTRDIFF_MAX INT32_MAX
+
+#define SIG_ATOMIC_MIN INT32_MIN
+#define SIG_ATOMIC_MAX INT32_MAX
+
+#define SIZE_MAX UINT32_MAX
+
+#define WCHAR_MIN INT32_MIN
+#define WCHAR_MAX INT32_MAX
+
+#define INT8_C(x) x
+#define INT16_C(x) x
+#define INT32_C(x) x
+#define INT64_C(x) x ## LL
+
+#define UINT8_C(x) x
+#define UINT16_C(x) x
+#define UINT32_C(x) x ## U
+#define UINT64_C(x) x ## ULL
+
+#define INTMAX_C(x) x ## LL
+#define UINTMAX_C(x) x ## ULL
+
+typedef signed char int8_t;
+typedef short int16_t;
+typedef int int32_t;
+typedef long long int64_t;
+
+typedef unsigned char uint8_t;
+typedef unsigned short uint16_t;
+typedef unsigned uint32_t;
+typedef unsigned long long uint64_t;
+
+typedef signed char int8_least_t;
+typedef short int16_least_t;
+typedef int int32_least_t;
+typedef long long int64_least_t;
+
+typedef unsigned char uint8_least_t;
+typedef unsigned short uint16_least_t;
+typedef unsigned uint32_least_t;
+typedef unsigned long long uint64_least_t;
+
+typedef int int8_fast_t;
+typedef int int16_fast_t;
+typedef int int32_fast_t;
+typedef long long int64_fast_t;
+
+typedef unsigned uint8_fast_t;
+typedef unsigned uint16_fast_t;
+typedef unsigned uint32_fast_t;
+typedef unsigned long long uint64_fast_t;
+
+typedef int intptr_t;
+typedef unsigned uintptr_t;
+
+typedef long long intmax_t;
+typedef unsigned long long uintmax_t;
--- /dev/null
+++ b/lib/c/include/bits/i386-sysv/arch/stdio.h
@@ -1,0 +1,15 @@
+/* See LICENSE file for copyright and license details. */
+
+#ifndef _SIZET
+typedef unsigned long size_t;
+#define _SIZET
+#endif
+
+#define BUFSIZ 512
+#define FILENAME_MAX 256
+#define FOPEN_MAX 16
+
+#define TMP_MAX 25
+#define L_tmpnam 256
+
+typedef long fpos_t;
--- /dev/null
+++ b/lib/c/include/bits/i386-sysv/arch/stdlib.h
@@ -1,0 +1,16 @@
+/* See LICENSE file for copyright and license details. */
+
+#ifndef _SIZET
+typedef unsigned long size_t;
+#define _SIZET
+#endif
+
+#define EXIT_FAILURE 1
+#define EXIT_SUCCESS 0
+
+#ifndef _WCHAR_T
+typedef int wchar_t;
+#define _WCHAR_T
+#endif
+
+#define _ALIGNTYPE long double
--- /dev/null
+++ b/lib/c/include/bits/i386-sysv/arch/string.h
@@ -1,0 +1,5 @@
+/* See LICENSE file for copyright and license details. */
+
+#ifndef _SIZET
+typedef unsigned long size_t;
+#endif
--- /dev/null
+++ b/lib/c/include/bits/i386-sysv/arch/time.h
@@ -1,0 +1,8 @@
+/* See LICENSE file for copyright and license details. */
+
+#ifndef _SIZET
+typedef unsigned long size_t;
+#define _SIZET
+#endif
+
+typedef long int time_t;
--- /dev/null
+++ b/lib/c/include/bits/z80-dos/arch/limits.h
@@ -1,0 +1,17 @@
+#define SCHAR_MAX 0x7F
+#define SCHAR_MIN (-SCHAR_MIN-1)
+#define CHAR_MAX 0xFF
+#define CHAR_MIN 0
+#define UCHAR_MAX 0xFF
+#define SHRT_MAX 0x7FFF
+#define SHRT_MIN (-SHRT_MAX-1)
+#define USHRT_MAX 0xFFFF
+#define INT_MAX 0x7FFF
+#define INT_MIN (-INT_MAX-1)
+#define UINT_MAX 0xFFFF
+#define LONG_MAX 0x7FFFFFFF
+#define LONG_MIN (-LONG_MAX-1)
+#define ULONG_MAX 0xFFFFFFFF
+#define LLONG_MAX 0x7FFFFFFFFFFFFFFF
+#define LLONG_MIN (-LLONG_MAX-1)
+#define ULLONG_MAX 0xFFFFFFFFFFFFFFFF
--- /dev/null
+++ b/lib/c/include/bits/z80-dos/arch/signal.h
@@ -1,0 +1,33 @@
+/* See LICENSE file for copyright and license details. */
+
+typedef char sig_atomic_t;
+
+#define SIG_ERR -1
+#define SIG_DFL 0
+#define SIG_IGN 1
+
+#define SIG_ERR -1
+#define SIG_DFL 0
+#define SIG_IGN 1
+
+#define SIGHUP 1
+#define SIGINT 2
+#define SIGQUIT 3
+#define SIGILL 4
+#define SIGABRT 6
+#define SIGFPE 8
+#define SIGKILL 9
+#define SIGUSR1 10
+#define SIGSEGV 11
+#define SIGUSR2 12
+#define SIGPIPE 13
+#define SIGALRM 14
+#define SIGTERM 15
+#define SIGCHLD 17
+#define SIGCONT 18
+#define SIGSTOP 19
+#define SIGSSTP 20
+#define SIGTTIN 21
+#define SIGTTOU 22
+
+#define __NR_SIGNALS 23
--- /dev/null
+++ b/lib/c/include/bits/z80-dos/arch/stddef.h
@@ -1,0 +1,16 @@
+/* See LICENSE file for copyright and license details. */
+
+#ifndef _SIZET
+typedef unsigned size_t;
+#define _SIZET
+#endif
+
+#ifndef _WCHAR_T
+typedef short wchar_t;
+#define _WCHAR_T
+#endif
+
+#ifndef _PTRDIFF_T
+typedef short ptrdiff_t;
+#define _PTRDIFF_T
+#endif
--- /dev/null
+++ b/lib/c/include/bits/z80-dos/arch/stdint.h
@@ -1,0 +1,117 @@
+/* See LICENSE file for copyright and license details. */
+
+#define INT8_MAX 0x7F
+#define INT8_MIN (-INT8_MAX-1)
+#define UINT8_MAX 0xFF
+
+#define INT16_MAX 0x7FFF
+#define INT16_MIN (-INT16_MAX-1)
+#define UINT16_MAX 0xFFFF
+
+#define INT32_MAX 0x7FFFFFFF
+#define INT32_MIN (-INT32_MAX-1)
+#define UINT32_MAX 0xFFFFFFFF
+
+#define INT64_MAX 0x7FFFFFFFFFFFFFFF
+#define INT64_MIN (-INT64_MAX-1)
+#define UINT64_MAX 0xFFFFFFFFFFFFFFFF
+
+#define INT_LEAST8_MIN INT8_MIN
+#define INT_LEAST8_MAX INT8_MAX
+#define UINT_LEAST8_MAX UINT8_MAX
+
+#define INT_LEAST16_MIN INT16_MIN
+#define INT_LEAST16_MAX INT16_MAX
+#define UINT_LEAST16_MAX UINT16_MAX
+
+#define INT_LEAST32_MIN INT32_MIN
+#define INT_LEAST32_MAX INT32_MAX
+#define UINT_LEAST32_MAX UINT32_MAX
+
+#define INT_LEAST64_MIN INT64_MIN
+#define INT_LEAST64_MAX INT64_MAX
+#define UINT_LEAST64_MAX UINT64_MAX
+
+#define INT_FAST8_MIN INT16_MIN
+#define INT_FAST8_MAX INT16_MAX
+#define UINT_FAST8_MAX UINT16_MAX
+
+#define INT_FAST16_MIN INT16_MIN
+#define INT_FAST16_MAX INT16_MAX
+#define UINT_FAST16_MAX UINT16_MAX
+
+#define INT_FAST32_MIN INT32_MIN
+#define INT_FAST32_MAX INT32_MAX
+#define UINT_FAST32_MAX UINT32_MAX
+
+#define INT_FAST64_MIN INT64_MIN
+#define INT_FAST64_MAX INT64_MAX
+#define UINT_FAST64_MAX UINT64_MAX
+
+#define INTPTR_MIN INT16_MIN
+#define INTPTR_MAX INT16_MAX
+#define UINTPTR_MAX UINT16_MAX
+
+#define INTMAX_MIN INT64_MIN
+#define INTMAX_MAX INT64_MAX
+#define UINTMAX_MAX UINT64_MAX
+
+#define PTRDIFF_MIN INT16_MIN
+#define PTRDIFF_MAX INT16_MAX
+
+#define SIG_ATOMIC_MIN INT16_MIN
+#define SIG_ATOMIC_MAX INT16_MAX
+
+#define SIZE_MAX UINT64_MAX
+
+#define WCHAR_MIN INT16_MIN
+#define WCHAR_MAX INT16_MAX
+
+#define INT8_C(x) x
+#define INT16_C(x) x
+#define INT32_C(x) x ## L
+#define INT64_C(x) x ## LL
+
+#define UINT8_C(x) x
+#define UINT16_C(x) x ## U
+#define UINT32_C(x) x ## UL
+#define UINT64_C(x) x ## ULL
+
+#define INTMAX_C(x) x ## LL
+#define UINTMAX_C(x) x ## ULL
+
+typedef signed char int8_t;
+typedef int int16_t;
+typedef long int32_t;
+typedef long long int64_t;
+
+typedef unsigned char uint8_t;
+typedef unsigned uint16_t;
+typedef unsigned long uint32_t;
+typedef unsigned long long uint64_t;
+
+typedef signed char int8_least_t;
+typedef int int16_least_t;
+typedef long int32_least_t;
+typedef long long int64_least_t;
+
+typedef unsigned char uint8_least_t;
+typedef unsigned uint16_least_t;
+typedef unsigned long uint32_least_t;
+typedef unsigned long long uint64_least_t;
+
+typedef signed char int8_fast_t;
+typedef int int16_fast_t;
+typedef long int32_fast_t;
+typedef long long int64_fast_t;
+
+typedef unsigned char uint8_fast_t;
+typedef unsigned uint16_fast_t;
+typedef unsigned long uint32_fast_t;
+typedef unsigned long long uint64_fast_t;
+
+typedef int intptr_t;
+typedef unsigned uintptr_t;
+
+typedef long long intmax_t;
+typedef unsigned long long uintmax_t;
--- /dev/null
+++ b/lib/c/include/bits/z80-dos/arch/stdio.h
@@ -1,0 +1,15 @@
+/* See LICENSE file for copyright and license details. */
+
+#ifndef _SIZET
+typedef unsigned size_t;
+#define _SIZET
+#endif
+
+#define BUFSIZ 512
+#define FILENAME_MAX 256
+#define FOPEN_MAX 16
+
+#define TMP_MAX 25
+#define L_tmpnam 256
+
+typedef long fpos_t;
--- /dev/null
+++ b/lib/c/include/bits/z80-dos/arch/stdlib.h
@@ -1,0 +1,16 @@
+/* See LICENSE file for copyright and license details. */
+
+#ifndef _SIZET
+typedef unsigned size_t;
+#define _SIZET
+#endif
+
+#define EXIT_FAILURE 1
+#define EXIT_SUCCESS 0
+
+#ifndef _WCHAR_T
+typedef short wchar_t;
+#define _WCHAR_T
+#endif
+
+#define _ALIGNTYPE int
--- /dev/null
+++ b/lib/c/include/bits/z80-dos/arch/string.h
@@ -1,0 +1,5 @@
+/* See LICENSE file for copyright and license details. */
+
+#ifndef _SIZET
+typedef unsigned size_t;
+#endif
--- /dev/null
+++ b/lib/c/include/bits/z80-dos/arch/time.h
@@ -1,0 +1,8 @@
+/* See LICENSE file for copyright and license details. */
+
+#ifndef _SIZET
+typedef unsigned size_t;
+#define _SIZET
+#endif
+
+typedef long time_t;
--- /dev/null
+++ b/lib/c/include/ctype.h
@@ -1,0 +1,49 @@
+/* See LICENSE file for copyright and license details. */
+#ifndef _CTYPE_H
+#define _CTYPE_H
+
+extern int isalnum(int c);
+extern int isalpha(int c);
+extern int islower(int c);
+extern int isupper(int c);
+extern int isdigit(int c);
+extern int isxdigit(int c);
+extern int iscntrl(int c);
+extern int isgraph(int c);
+extern int isspace(int c);
+extern int isblank(int c);
+extern int isprint(int c);
+extern int ispunct(int c);
+extern int tolower(int c);
+extern int toupper(int c);
+
+#ifdef __USE_MACROS
+
+#define _U 0x01 /* upper */
+#define _L 0x02 /* lower */
+#define _D 0x04 /* digit */
+#define _C 0x08 /* cntrl */
+#define _P 0x10 /* punct */
+#define _S 0x20 /* white space (space/lf/tab) */
+#define _X 0x40 /* hex char */
+#define _SP 0x80 /* hard space (0x20) */
+
+extern unsigned char __ctype[];
+
+#define isalnum(c) (__ctype[(unsigned char) c] & (_U|_L|_D))
+#define isalpha(c) (__ctype[(unsigned char) c] & (_U|_L))
+#define iscntrl(c) (__ctype[(unsigned char) c] & (_C))
+#define isdigit(c) (__ctype[(unsigned char) c] & (_D))
+#define isgraph(c) (__ctype[(unsigned char) c] & (_P|_U|_L|_D))
+#define islower(c) (__ctype[(unsigned char) c] & (_L))
+#define isprint(c) (__ctype[(unsigned char) c] & (_P|_U|_L|_D|_SP))
+#define ispunct(c) (__ctype[(unsigned char) c] & (_P))
+#define isspace(c) (__ctype[(unsigned char) c] & (_S))
+#define isupper(c) (__ctype[(unsigned char) c] & (_U))
+#define isxdigit(c) (__ctype[(unsigned char) c] & (_D|_X))
+
+#define isascii(c) (((unsigned) c)<=0x7f)
+
+#endif
+
+#endif
--- /dev/null
+++ b/lib/c/include/errno.h
@@ -1,0 +1,12 @@
+/* See LICENSE file for copyright and license details. */
+#ifndef _ERRNO_H
+#define _ERRNO_H
+
+#define EDOM 1
+#define EILSEQ 2
+#define ERANGE 3
+#define ENOMEN 4
+
+extern int errno;
+
+#endif
--- /dev/null
+++ b/lib/c/include/limits.h
@@ -1,0 +1,9 @@
+#ifndef _LIMITS_H
+#define _LIMITS_H
+
+#include <arch/limits.h>
+
+#define CHAR_BIT 8
+#define MB_LEN_MAX 1
+
+#endif
--- /dev/null
+++ b/lib/c/include/locale.h
@@ -1,0 +1,45 @@
+#ifndef _LOCALE_H
+#define _LOCALE_H
+
+#ifndef NULL
+#define NULL ((void *) 0)
+#endif
+
+#define LC_ALL 0
+#define LC_COLLATE 1
+#define LC_CTYPE 2
+#define LC_MONETARY 3
+#define LC_NUMERIC 4
+#define LC_TIME 5
+
+struct lconv {
+ char *decimal_point;
+ char *thousands_sep;
+ char *grouping;
+ char *mon_decimal_point;
+ char *mon_thousands_sep;
+ char *mon_grouping;
+ char *positive_sign;
+ char *negative_sign;
+ char *currency_symbol;
+ char *int_curr_symbol;
+ char frac_digits;
+ char p_cs_precedes;
+ char n_cs_precedes;
+ char p_sep_by_space;
+ char n_sep_by_space;
+ char p_sign_posn;
+ char n_sign_posn;
+ char int_frac_digits;
+ char int_p_cs_precedes;
+ char int_n_cs_precedes;
+ char int_p_sep_by_space;
+ char int_n_sep_by_space;
+ char int_p_sign_posn;
+ char int_n_sign_posn;
+};
+
+extern char *setlocale(int category, const char *locale);
+extern struct lconv *localeconv(void);
+
+#endif
--- /dev/null
+++ b/lib/c/include/signal.h
@@ -1,0 +1,10 @@
+/* See LICENSE file for copyright and license details. */
+#ifndef _SIGNAL_H
+#define _SIGNAL_H
+
+#include <arch/signal.h>
+
+void ( *signal(int signum, void (*handler)(int)) ) (int);
+int raise(int sig);
+
+#endif
--- /dev/null
+++ b/lib/c/include/stdarg.h
@@ -1,0 +1,11 @@
+/* See LICENSE file for copyright and license details. */
+#ifndef _STDARG_H
+#define _STDARG_H
+
+#define va_list __builtin_va_list
+#define va_start(ap, last) __builtin_va_start(ap, last)
+#define va_end(ap) __builtin_va_end(ap)
+#define va_copy(to, from) __builtin_va_copy(to, from)
+#define va_arg(to, type) __builtin_va_arg(to, type)
+
+#endif
--- /dev/null
+++ b/lib/c/include/stdbool.h
@@ -1,0 +1,10 @@
+/* See LICENSE file for copyright and license details. */
+#ifndef _STDBOOL_H
+#define _STDBOOL_H
+
+#define bool _Bool
+#define true ((bool) 1)
+#define false ((bool) 0)
+#define __bool_true_false_are_defined 1
+
+#endif
--- /dev/null
+++ b/lib/c/include/stddef.h
@@ -1,0 +1,13 @@
+/* See LICENSE file for copyright and license details. */
+#ifndef _STDDEF_H
+#define _STDDEF_H
+
+#include <arch/stddef.h>
+
+#ifndef NULL
+#define NULL ((void *) 0)
+#endif
+
+#define offsetof(st, m) ((size_t)&(((st *)0)->m))
+
+#endif
--- /dev/null
+++ b/lib/c/include/stdint.h
@@ -1,0 +1,7 @@
+/* See LICENSE file for copyright and license details. */
+#ifndef _STDINT_H_
+#define _STDINT_H_
+
+#include <arch/stdint.h>
+
+#endif
--- /dev/null
+++ b/lib/c/include/stdio.h
@@ -1,0 +1,102 @@
+/* See LICENSE file for copyright and license details. */
+#ifndef _STDIO_H
+#define _STDIO_H
+
+#include <arch/stdio.h>
+
+#ifndef NULL
+#define NULL ((void *) 0)
+#endif
+
+#define EOF -1
+#define _IOFBF 0
+#define _IOLBF 1
+#define _IONBF 2
+#define SEEK_CUR 0
+#define SEEK_END 1
+#define SEEK_SET 2
+
+typedef struct {
+ int fd; /* file descriptor */
+ char flags; /* bits for must free buffer on close, line-buffered */
+ char state; /* last operation was read, write, position, error, eof */
+ char *buf; /* pointer to i/o buffer */
+ char *rp; /* read pointer (or write end-of-buffer) */
+ char *wp; /* write pointer (or read end-of-buffer) */
+ char *lp; /* actual write pointer used when line-buffering */
+ size_t len; /* actual length of buffer */
+ char unbuf[1]; /* tiny buffer for unbuffered io */
+} FILE;
+
+extern FILE _IO_stream[FOPEN_MAX];
+
+#define stderr (&_IO_stream[2])
+#define stdin (&_IO_stream[0])
+#define stdout (&_IO_stream[1])
+
+extern int remove(const char *filename);
+extern int rename(const char *old, const char *new);
+extern FILE *tmpfile(void);
+extern char *tmpnam(char *s);
+extern int fclose(FILE *fp);
+extern int fflush(FILE *fp);
+extern FILE *fopen(const char * restrict fname, const char * restrict mode);
+extern FILE *freopen(const char * restrict fname, const char * restrict mode,
+ FILE * restrict fp);
+extern void setbuf(FILE * restrict fp, char * restrict buf);
+extern int setvbuf(FILE * restrict fp,
+ char * restrict buf, int mode, size_t size);
+extern int fprintf(FILE * restrict fp, const char * restrict fmt, ...);
+extern int fscanf(FILE * restrict fp, const char * restrict fmt, ...);
+extern int printf(const char * restrict fmt, ...);
+extern int scanf(const char * restrict fmt, ...);
+extern int snprintf(char * restrict s,
+ size_t n, const char * restrict fmt, ...);
+extern int sprintf(char * restrict s, const char * restrict fmt, ...);
+extern int sscanf(const char * restrict s, const char * restrict fmt, ...);
+
+#ifdef _STDARG_H
+extern int vfprintf(FILE * restrict fp,
+ const char * restrict fmt, va_list arg);
+extern int vfscanf(FILE * restrict fp,
+ const char * restrict fmt, va_list arg);
+extern int vprintf(const char * restrict fmt, va_list arg);
+extern int vscanf(const char * restrict fmt, va_list arg);
+extern int vsnprintf(char * restrict s, size_t n, const char * restrict fmt,
+ va_list arg);
+extern int vsprintf(char * restrict s,
+ const char * restrict fmt, va_list arg);
+extern int vsscanf(const char * restrict s,
+ const char * restrict fmt, va_list arg);
+#endif
+
+extern int fgetc(FILE *fp);
+extern char *fgets(char * restrict s, int n, FILE * restrict fp);
+extern int fputc(int c, FILE *fp);
+extern int fputs(const char * restrict s, FILE * restrict fp);
+extern int getc(FILE *fp);
+extern int getchar(void);
+extern char *gets(char *s);
+extern int putc(int c, FILE *fp);
+extern int putchar(int c);
+extern int puts(const char *s);
+extern int ungetc(int c, FILE *fp);
+extern size_t fread(void * restrict ptr, size_t size, size_t nmemb,
+ FILE * restrict fp);
+extern size_t fwrite(const void * restrict ptr, size_t size, size_t nmemb,
+ FILE * restrict fp);
+extern int fgetpos(FILE * restrict fp, fpos_t * restrict pos);
+extern int fseek(FILE *fp, long int offset, int whence);
+extern int fsetpos(FILE *fp, const fpos_t *pos);
+extern long int ftell(FILE *fp);
+extern void rewind(FILE *fp);
+extern void clearerr(FILE *fp);
+extern int feof(FILE *fp);
+extern int ferror(FILE *fp);
+extern void perror(const char *s);
+
+#ifdef __USE_MACROS
+#define printf(...) fprintf(stdout, __VA_ARGS__)
+#endif
+
+#endif
--- /dev/null
+++ b/lib/c/include/stdlib.h
@@ -1,0 +1,70 @@
+/* See LICENSE file for copyright and license details. */
+#ifndef _STDLIB_H
+#define _STDLIB_H
+
+#include <arch/stdlib.h>
+
+#ifndef NULL
+#define NULL ((void *) 0)
+#endif
+
+#define _ATEXIT_MAX 32
+
+#define MB_CUR_MAX 1
+#define RAND_MAX 32767
+
+typedef struct {
+ int quot, rem;
+} div_t;
+
+typedef struct {
+ long quot, rem;
+} ldiv_t;
+
+typedef struct {
+ long long quot, rem;
+} lldiv_t;
+
+extern double atof(const char *nptr);
+extern int atoi(const char *nptr);
+extern long int atol(const char *nptr);
+extern long long int atoll(const char *nptr);
+extern double strtod(const char * restrict nptr, char ** restrict endptr);
+extern float strtof(const char * restrict nptr, char ** restrict endptr);
+extern long double strtold(const char * restrict nptr, char ** restrict endptr);
+extern long int strtol(const char * restrict nptr, char ** restrict endptr, int base);
+extern long long int strtoll(const char * restrict nptr, char ** restrict endptr,
+ int base);
+extern unsigned long int strtoul(const char * restrict nptr, char ** restrict endptr,
+ int base);
+extern unsigned long long int strtoull(const char * restrict nptr,
+ char ** restrict endptr, int base);
+extern int rand(void);
+extern void srand(unsigned int seed);
+extern void *calloc(size_t nmemb, size_t size);
+extern void free(void *ptr);
+extern void *malloc(size_t size);
+extern void *realloc(void *ptr, size_t size);
+extern void abort(void);
+extern int atexit(void (*func)(void));
+extern void exit(int status);
+extern void _Exit(int status);
+extern char *getenv(const char *name);
+extern int system(const char *string);
+extern void *bsearch(const void *key, const void *base, size_t nmemb, size_t size,
+ int (*compar)(const void *, const void *));
+extern void qsort(void *base, size_t nmemb, size_t size,
+ int (*compar)(const void *, const void *));
+extern int abs(int j);
+extern long int labs(long int j);
+extern long long int llabs(long long int j);
+extern div_t div(int numer, int denom);
+extern ldiv_t ldiv(long int numer, long int denom);
+extern lldiv_t lldiv(long long int numer, long long int denom);
+extern int mblen(const char *s, size_t n);
+extern int mbtowc(wchar_t * restrict pwc, const char * restrict s, size_t n);
+extern int wctomb(char *s, wchar_t wchar);
+extern size_t mbstowcs(wchar_t * restrict pwcs, const char * restrict s, size_t n);
+extern size_t wcstombs(char * restrict s, const wchar_t * restrict pwcs, size_t n);
+
+#endif
--- /dev/null
+++ b/lib/c/include/string.h
@@ -1,0 +1,34 @@
+/* See LICENSE file for copyright and license details. */
+#ifndef _STRING_H
+#define _STRING_H
+
+#include <arch/string.h>
+
+#ifndef NULL
+#define NULL ((void *) 0)
+#endif
+
+extern void *memcpy(void * restrict s1, const void * restrict s2, size_t n);
+extern void *memmove(void *s1, const void *s2, size_t n);
+extern char *strcpy(char * restrict s1, const char * restrict s2);
+extern char *strncpy(char * restrict s1, const char * restrict s2, size_t n);
+extern char *strcat(char * restrict s1, const char * restrict s2);
+extern char *strncat(char * restrict s1, const char * restrict s2, size_t n);
+extern int memcmp(const void *s1, const void *s2, size_t n);
+extern int strcmp(const char *s1, const char *s2);
+extern int strcoll(const char *s1, const char *s2);
+extern int strncmp(const char *s1, const char *s2, size_t n);
+extern size_t strxfrm(char * restrict s1, const char * restrict s2, size_t n);
+extern void *memchr(const void *s, int c, size_t n);
+extern char *strchr(const char *s, int c);
+extern size_t strcspn(const char *s1, const char *s2);
+extern char *strpbrk(const char *s1, const char *s2);
+extern char *strrchr(const char *s, int c);
+extern size_t strspn(const char *s1, const char *s2);
+extern char *strstr(const char *s1, const char *s2);
+extern char *strtok(char * restrict s1, const char * restrict s2);
+extern void *memset(void *s, int c, size_t n);
+extern char *strerror(int errnum);
+extern size_t strlen(const char *s);
+
+#endif
--- /dev/null
+++ b/lib/c/include/time.h
@@ -1,0 +1,38 @@
+#ifndef _TIME_H
+#define _TIME_H
+
+#include <arch/time.h>
+
+#ifndef NULL
+#define NULL ((void *) 0)
+#endif
+
+#define CLOCKS_PER_SEC 1000000
+
+typedef long int clock_t;
+
+struct tm {
+ int tm_sec;
+ int tm_min;
+ int tm_hour;
+ int tm_mday;
+ int tm_mon;
+ int tm_year;
+ int tm_wday;
+ int tm_yday;
+ int tm_isdst;
+};
+
+extern clock_t clock(void);
+extern double difftime(time_t time1, time_t time0);
+extern time_t mktime(struct tm *timeptr);
+extern time_t time(time_t *timer);
+extern char *asctime(const struct tm *timeptr);
+extern char *ctime(const time_t *timer);
+extern struct tm *gmtime(const time_t *timer);
+extern struct tm *localtime(const time_t *timer);
+extern size_t strftime(char * restrict s, size_t maxsize,
+ const char * restrict format,
+ const struct tm * restrict timeptr);
+
+#endif
--- /dev/null
+++ b/lib/c/obj.lst
@@ -1,0 +1,49 @@
+assert.o
+strcpy.o
+strcmp.o
+strlen.o
+strchr.o
+strrchr.o
+strcat.o
+strncmp.o
+strncpy.o
+strncat.o
+strcoll.o
+strxfrm.o
+strstr.o
+strspn.o
+strcspn.o
+strpbrk.o
+strtok.o
+memset.o
+memcpy.o
+memmove.o
+memcmp.o
+memchr.o
+isalnum.o
+isalpha.o
+isascii.o
+isblank.o
+iscntrl.o
+isdigit.o
+isgraph.o
+islower.o
+isprint.o
+ispunct.o
+isspace.o
+isupper.o
+isxdigit.o
+toupper.o
+tolower.o
+ctype.o
+setlocale.o
+localeconv.o
+atoi.o
+atexit.o
+exit.o
+printf.o
+fprintf.o
+vfprintf.o
+realloc.o
+calloc.o
+malloc.o
--- /dev/null
+++ b/lib/c/src/Makefile
@@ -1,0 +1,24 @@
+# See LICENSE file for copyright and license details.
+.POSIX:
+
+include ../../../config.mk
+
+OBJ = assert.o strcpy.o strcmp.o strlen.o strchr.o \
+ strrchr.o strcat.o strncmp.o strncpy.o strncat.o strcoll.o \
+ strxfrm.o strstr.o strspn.o strcspn.o strpbrk.o strtok.o \
+ memset.o memcpy.o memmove.o memcmp.o memchr.o \
+ isalnum.o isalpha.o isascii.o isblank.o iscntrl.o isdigit.o \
+ isgraph.o islower.o isprint.o ispunct.o isspace.o isupper.o \
+ isxdigit.o toupper.o tolower.o ctype.o setlocale.o \
+ localeconv.o atoi.o atexit.o exit.o \
+ printf.o fprintf.o vfprintf.o \
+ realloc.o calloc.o malloc.o
+
+all: $(ARCH)-libc.a
+
+clean distclean:
+ rm -f *.o *-libc.a
+
+$(ARCH)-libc.a: $(OBJ)
+ $(AR) $(ARFLAGS) $@ $?
+ ranlib $@
--- /dev/null
+++ b/lib/c/src/assert.c
@@ -1,0 +1,11 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <assert.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+void __assert(char *exp, char *file, long line)
+{
+ fprintf(stderr, "%s:%ld: assertion failed '%s'\n", file, line, exp);
+ abort();
+}
--- /dev/null
+++ b/lib/c/src/atexit.c
@@ -1,0 +1,19 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <stdlib.h>
+#include <errno.h>
+#undef atexit
+
+extern void (*_exitf[_ATEXIT_MAX])(void);
+extern unsigned _exitn;
+
+int
+atexit(void (*fun)(void))
+{
+ if (_exitn == _ATEXIT_MAX) {
+ errno = ENOMEN;
+ return -1;
+ }
+ _exitf[_exitn++] = fun;
+ return 0;
+}
--- /dev/null
+++ b/lib/c/src/atoi.c
@@ -1,0 +1,28 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <ctype.h>
+#include <stdlib.h>
+#undef atoi
+
+int
+atoi(const char *s)
+{
+ int n, sign = -1;
+
+ while(isspace(*s))
+ ++s;
+
+ switch(*s) {
+ case '-':
+ sign = 1;
+ case '+':
+ ++s;
+ }
+
+ /* Compute n as a negative number to avoid overflow on INT_MIN */
+ for (n = 0; isdigit(*s); ++s)
+ n = 10*n - (*s - '0');
+
+ return sign * n;
+}
+
--- /dev/null
+++ b/lib/c/src/calloc.c
@@ -1,0 +1,19 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <stdlib.h>
+#include <string.h>
+
+void *
+calloc(size_t nmemb, size_t size)
+{
+ size_t nbytes;
+ void *mem;
+
+ if (!nmemb || !size || nmemb > (size_t)-1/size)
+ return NULL;
+
+ nbytes = nmemb * size;
+ if ((mem = malloc(nbytes)) == NULL)
+ return NULL;
+ return memset(mem, 0, nbytes);
+}
--- /dev/null
+++ b/lib/c/src/ctype.c
@@ -1,0 +1,24 @@
+/* See LICENSE file for copyright and license details. */
+
+#define __USE_MACROS
+#include <ctype.h>
+#undef ctype
+
+unsigned char __ctype[255] = {
+ _C,_C,_C,_C,_C,_C,_C,_C, /* 0-7 */
+ _C,_C|_S,_C|_S,_C|_S,_C|_S,_C|_S,_C,_C, /* 8-15 */
+ _C,_C,_C,_C,_C,_C,_C,_C, /* 16-23 */
+ _C,_C,_C,_C,_C,_C,_C,_C, /* 24-31 */
+ _S|_SP,_P,_P,_P,_P,_P,_P,_P, /* 32-39 */
+ _P,_P,_P,_P,_P,_P,_P,_P, /* 40-47 */
+ _D,_D,_D,_D,_D,_D,_D,_D, /* 48-55 */
+ _D,_D,_P,_P,_P,_P,_P,_P, /* 56-63 */
+ _P,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U, /* 64-71 */
+ _U,_U,_U,_U,_U,_U,_U,_U, /* 72-79 */
+ _U,_U,_U,_U,_U,_U,_U,_U, /* 80-87 */
+ _U,_U,_U,_P,_P,_P,_P,_P, /* 88-95 */
+ _P,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L, /* 96-103 */
+ _L,_L,_L,_L,_L,_L,_L,_L, /* 104-111 */
+ _L,_L,_L,_L,_L,_L,_L,_L, /* 112-119 */
+ _L,_L,_L,_P,_P,_P,_P,_C, /* 120-127 */
+};
--- /dev/null
+++ b/lib/c/src/exit.c
@@ -1,0 +1,15 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <stdlib.h>
+#undef exit
+
+void (*_exitf[_ATEXIT_MAX])(void);
+unsigned _exitn;
+
+void
+exit(int status)
+{
+ while (_exitn > 0)
+ (*_exitf[--_exitn])();
+ _Exit(status);
+}
--- /dev/null
+++ b/lib/c/src/fprintf.c
@@ -1,0 +1,17 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <stdarg.h>
+#include <stdio.h>
+#undef fprintf
+
+int
+fprintf(FILE * restrict fp, const char * restrict fmt, ...)
+{
+ va_list va;
+ int cnt;
+
+ va_start(va, fmt);
+ cnt = vfprintf(fp, fmt, va);
+ va_end(va);
+ return cnt;
+}
--- /dev/null
+++ b/lib/c/src/isalnum.c
@@ -1,0 +1,11 @@
+/* See LICENSE file for copyright and license details. */
+
+#define __USE_MACROS
+#include <ctype.h>
+#undef isalnum
+
+int
+isalnum(int c)
+{
+ return __ctype[(unsigned char) c] & (_U|_L|_D);
+}
--- /dev/null
+++ b/lib/c/src/isalpha.c
@@ -1,0 +1,11 @@
+/* See LICENSE file for copyright and license details. */
+
+#define __USE_MACROS
+#include <ctype.h>
+#undef isalpha
+
+int
+isalpha(int c)
+{
+ return __ctype[(unsigned char) c] & (_U|_L);
+}
--- /dev/null
+++ b/lib/c/src/isascii.c
@@ -1,0 +1,11 @@
+/* See LICENSE file for copyright and license details. */
+
+#define __USE_MACROS
+#include <ctype.h>
+#undef isascii
+
+int
+isascii(int c)
+{
+ return c <= 0x7f;
+}
--- /dev/null
+++ b/lib/c/src/isblank.c
@@ -1,0 +1,7 @@
+/* See LICENSE file for copyright and license details. */
+
+int
+isblank(int c)
+{
+ return (c == ' ') || (c == '\t');
+}
--- /dev/null
+++ b/lib/c/src/iscntrl.c
@@ -1,0 +1,11 @@
+/* See LICENSE file for copyright and license details. */
+
+#define __USE_MACROS
+#include <ctype.h>
+#undef iscntrl
+
+int
+iscntrl(int c)
+{
+ return __ctype[(unsigned char) c] & (_C);
+}
--- /dev/null
+++ b/lib/c/src/isdigit.c
@@ -1,0 +1,11 @@
+/* See LICENSE file for copyright and license details. */
+
+#define __USE_MACROS
+#include <ctype.h>
+#undef isdigit
+
+int
+isdigit(int c)
+{
+ return __ctype[(unsigned char) c] & (_D);
+}
--- /dev/null
+++ b/lib/c/src/isgraph.c
@@ -1,0 +1,11 @@
+/* See LICENSE file for copyright and license details. */
+
+#define __USE_MACROS
+#include <ctype.h>
+#undef isgraph
+
+int
+isgraph(int c)
+{
+ return __ctype[(unsigned char) c] & (_P|_U|_L|_D);
+}
--- /dev/null
+++ b/lib/c/src/islower.c
@@ -1,0 +1,11 @@
+/* See LICENSE file for copyright and license details. */
+
+#define __USE_MACROS
+#include <ctype.h>
+#undef islower
+
+int
+islower(int c)
+{
+ return __ctype[(unsigned char) c] & _L;
+}
--- /dev/null
+++ b/lib/c/src/isprint.c
@@ -1,0 +1,11 @@
+/* See LICENSE file for copyright and license details. */
+
+#define __USE_MACROS
+#include <ctype.h>
+#undef isprint
+
+int
+isprint(int c)
+{
+ return __ctype[(unsigned char) c] & (_P|_U|_L|_D|_SP);
+}
--- /dev/null
+++ b/lib/c/src/ispunct.c
@@ -1,0 +1,11 @@
+/* See LICENSE file for copyright and license details. */
+
+#define __USE_MACROS
+#include <ctype.h>
+#undef ispunct
+
+int
+ispunct(int c)
+{
+ return __ctype[(unsigned char) c] & (_P);
+}
--- /dev/null
+++ b/lib/c/src/isspace.c
@@ -1,0 +1,11 @@
+/* See LICENSE file for copyright and license details. */
+
+#define __USE_MACROS
+#include <ctype.h>
+#undef isspace
+
+int
+isspace(int c)
+{
+ return __ctype[(unsigned char) c] & _S;
+}
--- /dev/null
+++ b/lib/c/src/isupper.c
@@ -1,0 +1,11 @@
+/* See LICENSE file for copyright and license details. */
+
+#define __USE_MACROS
+#include <ctype.h>
+#undef isupper
+
+int
+isupper(int c)
+{
+ return __ctype[(unsigned char) c] & _U;
+}
--- /dev/null
+++ b/lib/c/src/isxdigit.c
@@ -1,0 +1,11 @@
+/* See LICENSE file for copyright and license details. */
+
+#define __USE_MACROS
+#include <ctype.h>
+#undef isxdigit
+
+int
+isxdigit(int c)
+{
+ return __ctype[(unsigned char) c] & (_D|_X);
+}
--- /dev/null
+++ b/lib/c/src/localeconv.c
@@ -1,0 +1,14 @@
+#include <locale.h>
+#include <limits.h>
+#undef localeconv
+
+struct lconv *
+localeconv(void)
+{
+ static struct lconv lc = { ".", "", "", "", "", "", "", "", "", "",
+ CHAR_MAX, CHAR_MAX, CHAR_MAX, CHAR_MAX,
+ CHAR_MAX, CHAR_MAX, CHAR_MAX, CHAR_MAX,
+ CHAR_MAX, CHAR_MAX, CHAR_MAX, CHAR_MAX,
+ CHAR_MAX, CHAR_MAX };
+ return &lc;
+}
--- /dev/null
+++ b/lib/c/src/malloc.c
@@ -1,0 +1,154 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "malloc.h"
+#include "syscall.h"
+
+#define MAXADDR ((char *)-1)
+#define ERRADDR ((char *)-1)
+
+extern char end[];
+static Header base = { .h.next = &base };
+static Header *freep = &base;
+static char *heap = end;
+
+/*
+ * Run over the free list looking for the nearest previous
+ * block. There are two possible results: end of the list
+ * or an intermediary block.
+ */
+void *
+_prevchunk(Header *hp)
+{
+ Header *p;
+
+ for (p = freep; ;p = p->h.next) {
+ /* hp between p and p->h.next? */
+ if (p < hp && hp < p->h.next)
+ break;
+ /* p before hp and hp at the end of list? */
+ if (p->h.next <= p && (hp < p->h.next || hp > p))
+ break;
+ }
+ return p;
+}
+
+/*
+ * Get the previous block and try to merge
+ * with next and previous blocks
+ */
+void
+free(void *mem)
+{
+ Header *hp, *prev;
+
+ if (!mem)
+ return;
+
+ hp = (Header *) mem - 1;
+ prev = _prevchunk(hp);
+
+ /* join to next */
+ if (hp + hp->h.size == prev->h.next) {
+ hp->h.size += prev->h.next->h.size;
+ hp->h.next = prev->h.next->h.next;
+ } else {
+ hp->h.next = prev->h.next;
+ }
+
+ /* join to previous */
+ if (prev + prev->h.size == hp) {
+ prev->h.size += hp->h.size;
+ prev->h.next = hp->h.next;
+ } else {
+ prev->h.next = hp;
+ }
+
+ freep = prev;
+}
+
+static void *
+sbrk(uintptr_t inc)
+{
+ char *new, *old = heap;
+
+ if (old >= MAXADDR - inc)
+ return ERRADDR;
+
+ new = old + inc;
+ if (_brk(new) < 0)
+ return ERRADDR;
+ heap = new;
+
+ return old;
+}
+
+static Header *
+morecore(size_t nunits)
+{
+ char *rawmem;
+ Header *hp;
+
+ if (nunits < NALLOC)
+ nunits = NALLOC;
+
+ rawmem = sbrk(nunits * sizeof(Header));
+ if (rawmem == ERRADDR)
+ return NULL;
+
+ hp = (Header*)rawmem;
+ hp->h.size = nunits;
+
+ /* integrate new memory into the list */
+ free(hp + 1);
+
+ return freep;
+}
+
+/*
+ * Run over the list of free blocks trying to find a block
+ * big enough for nbytes. If the block fit perfectly with
+ * the required size then we only have to unlink
+ * the block. Otherwise we have to split the block and
+ * return the right part. If we run over the full list
+ * without a fit then we have to require more memory
+ *
+ * ______________________________________
+ * ___________./______________________________________\_____
+ * ...| in | | | in | |.....| in | | | |....
+ * ...| use | | | use | |.....| use | | | |....
+ * ___|______|___|.____|_____|._|_____|______|._|.___|.|____
+ * \__/ \_________/ \_____________/ \/ \__/
+ */
+void *
+malloc(size_t nbytes)
+{
+ Header *cur, *prev;
+ size_t nunits;
+
+ /* 1 unit for header plus enough units to fit nbytes */
+ nunits = (nbytes+sizeof(Header)-1) / sizeof(Header) + 1;
+
+ for (prev = freep; ; prev = cur) {
+ cur = prev->h.next;
+ if (cur->h.size >= nunits) {
+ if (cur->h.size == nunits) {
+ prev->h.next = cur->h.next;
+ } else {
+ cur->h.size -= nunits;
+ cur += cur->h.size;
+ cur->h.size = nunits;
+ }
+ freep = prev;
+ return cur + 1;
+ }
+
+ if (cur == freep) {
+ if ((cur = morecore(nunits)) == NULL)
+ return NULL;
+ }
+ }
+}
--- /dev/null
+++ b/lib/c/src/malloc.h
@@ -1,0 +1,18 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <stdlib.h>
+
+/* minimum amount of required units */
+#define NALLOC 10000
+
+typedef union header Header;
+union header {
+ struct hdr {
+ Header *next;
+ size_t size;
+ } h;
+ /* most restrictive type fixes the union size for alignment */
+ _ALIGNTYPE most;
+};
+
+extern void *_prevchunk(Header *hp);
--- /dev/null
+++ b/lib/c/src/memchr.c
@@ -1,0 +1,14 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <string.h>
+#undef memchr
+
+void *
+memchr(const void *s, int c, size_t n)
+{
+ unsigned char *bp = (char *) s;
+
+ while (n > 0 && *bp++ != c)
+ --n;
+ return (n == 0) ? NULL : bp-1;
+}
--- /dev/null
+++ b/lib/c/src/memcmp.c
@@ -1,0 +1,14 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <string.h>
+#undef memcmp
+
+int
+memcmp(const void *s1, const void *s2, size_t n)
+{
+ char *s = (char *) s1, *t = (char *) s2;
+
+ while (n > 0 && *s == *t)
+ --n, ++s, ++t;
+ return n ? (*s - *t) : 0;
+}
--- /dev/null
+++ b/lib/c/src/memcpy.c
@@ -1,0 +1,15 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <string.h>
+#undef memcpy
+
+void *
+memcpy(void * restrict dst, const void * restrict src, size_t n)
+{
+ char *s1 = dst;
+ const char *s2 = src;
+
+ while (n-- > 0)
+ *s1++ = *s2++;
+ return dst;
+}
--- /dev/null
+++ b/lib/c/src/memmove.c
@@ -1,0 +1,20 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <string.h>
+#undef memmove
+
+void *
+memmove(void *dst, const void *src, size_t n)
+{
+ char *d = dst, *s = (char *) src;
+
+ if (d < s) {
+ while (n-- > 0)
+ *d++ = *s++;
+ } else {
+ s += n-1, d += n-1;
+ while (n-- > 0)
+ *d-- = *s--;
+ }
+ return dst;
+}
--- /dev/null
+++ b/lib/c/src/memset.c
@@ -1,0 +1,14 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <string.h>
+#undef memset
+
+void *
+memset(void *s, int c, size_t n)
+{
+ char *m = s;
+
+ while (n-- > 0)
+ *m++ = c;
+ return s;
+}
--- /dev/null
+++ b/lib/c/src/printf.c
@@ -1,0 +1,17 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <stdarg.h>
+#include <stdio.h>
+#undef printf
+
+int
+printf(const char * restrict fmt, ...)
+{
+ int cnt;
+ va_list va;
+
+ va_start(va, fmt);
+ cnt = vfprintf(stdin, fmt, va);
+ va_end(va);
+ return cnt;
+}
--- /dev/null
+++ b/lib/c/src/rand.c
@@ -1,0 +1,19 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <stdlib.h>
+#undef rand
+
+static int next;
+
+void
+srand(unsigned seed)
+{
+ next = seed;
+}
+
+int
+rand(void) /* RAND_MAX assumed to be 32767. */
+{
+ next = next * 1103515245 + 12345;
+ return (unsigned)(next/65536) % 32768;
+}
--- /dev/null
+++ b/lib/c/src/realloc.c
@@ -1,0 +1,69 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "malloc.h"
+
+void *
+realloc(void *ptr, size_t nbytes)
+{
+ Header *oh, *prev, *next, *new;
+ size_t nunits, avail, onbytes, n;
+
+ if (!nbytes)
+ return NULL;
+
+ if (!ptr)
+ return malloc(nbytes);
+
+ nunits = (nbytes + sizeof(Header) - 1) / sizeof(Header) + 1;
+ oh = (Header*)ptr - 1;
+
+ if (oh->h.size == nunits)
+ return ptr;
+
+ new = oh + nunits;
+
+ if (nunits < oh->h.size - 1) {
+ new->h.size = oh->h.size - nunits;
+ oh->h.size = nunits;
+ free(new + 1);
+ return oh;
+ }
+
+ prev = _prevchunk(oh);
+
+ if (oh + oh->h.size == prev->h.next) {
+ /*
+ * if there is free space adjacent
+ * to the current memory
+ */
+ next = prev->h.next;
+ avail = oh->h.size + next->h.size;
+
+ if (avail == nunits) {
+ oh->h.size = nunits;
+ prev->h.next = next->h.next;
+ return oh;
+ }
+
+ if (avail > nunits) {
+ oh->h.size = nunits;
+ prev->h.next = new;
+ new->h.next = next;
+ new->h.size = avail - nunits;
+ return oh;
+ }
+ }
+
+ onbytes = (oh->h.size - 1) * sizeof(Header);
+ if ((new = malloc(nbytes)) == NULL)
+ return NULL;
+
+ n = (onbytes > nbytes) ? nbytes : onbytes;
+ memcpy(new, ptr, n);
+ free(ptr);
+
+ return new;
+}
--- /dev/null
+++ b/lib/c/src/setlocale.c
@@ -1,0 +1,18 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <locale.h>
+#include <stddef.h>
+#undef setlocale
+
+char *
+setlocale(int category, const char *locale)
+{
+ if (category > LC_TIME || category < LC_ALL)
+ return NULL;
+ if (!locale ||
+ locale[0] == '\0' ||
+ locale[0] == 'C' && locale[1] == '\0') {
+ return "C";
+ }
+ return NULL;
+}
--- /dev/null
+++ b/lib/c/src/strcat.c
@@ -1,0 +1,16 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <string.h>
+#undef strcat
+
+char *
+strcat(char * restrict dst, const char * restrict src)
+{
+ char *ret = dst;
+
+ while (*dst)
+ ++dst;
+ while (*dst++ = *src++)
+ /* nothing */;
+ return ret;
+}
--- /dev/null
+++ b/lib/c/src/strchr.c
@@ -1,0 +1,12 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <string.h>
+#undef strchr
+
+char *
+strchr(const char *s, int c)
+{
+ while (*s && *s != c)
+ ++s;
+ return (*s == c) ? (char *)s : NULL;
+}
--- /dev/null
+++ b/lib/c/src/strcmp.c
@@ -1,0 +1,12 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <string.h>
+#undef strcmp
+
+int
+strcmp(const char *s1, const char *s2)
+{
+ while (*s1 && *s2 && *s1 == *s2)
+ ++s1, ++s2;
+ return *(unsigned char *)s1 - *(unsigned char *)s2;
+}
--- /dev/null
+++ b/lib/c/src/strcoll.c
@@ -1,0 +1,12 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <string.h>
+#undef strcoll
+
+int
+strcoll(const char *s1, const char *s2)
+{
+ while (*s1 && *s2 && *s1 == *s2)
+ ++s1, ++s2;
+ return *(unsigned char *) s1 - *(unsigned char *) s2;
+}
--- /dev/null
+++ b/lib/c/src/strcpy.c
@@ -1,0 +1,14 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <string.h>
+#undef strcpy
+
+char *
+strcpy(char * restrict dst, const char * restrict src)
+{
+ char *ret = dst;
+
+ while (*dst++ = *src++)
+ /* nothing */;
+ return ret;
+}
--- /dev/null
+++ b/lib/c/src/strcspn.c
@@ -1,0 +1,20 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <string.h>
+#undef strcspn
+
+size_t
+strcspn(const char *s1, const char *s2)
+{
+ size_t n;
+ int c;
+ const char *p;
+
+ for (n = 0; c = *s1++; ++n) {
+ for (p = s2; *p && *p != c; ++p)
+ /* nothing */;
+ if (*p == c)
+ break;
+ }
+ return n;
+}
--- /dev/null
+++ b/lib/c/src/strlen.c
@@ -1,0 +1,14 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <string.h>
+#undef strlen
+
+size_t
+strlen(const char *s)
+{
+ const char *t;
+
+ for (t = s; *t; ++t)
+ /* nothing */;
+ return t - s;
+}
--- /dev/null
+++ b/lib/c/src/strncat.c
@@ -1,0 +1,17 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <string.h>
+#undef strncat
+
+char *
+strncat(char * restrict dst, const char * restrict src, size_t n)
+{
+ char *ret = dst;
+
+ while (*dst)
+ ++dst;
+ while (n-- > 0 && *src)
+ *dst++ = *src++;
+ *dst = '\0';
+ return ret;
+}
--- /dev/null
+++ b/lib/c/src/strncmp.c
@@ -1,0 +1,12 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <string.h>
+#undef strncmp
+
+int
+strncmp(const char *s1, const char *s2, size_t n)
+{
+ for (; n && *s1 && *s2 && *s1 == *s2; --n, ++s1, ++s2);
+ /* nothing */;
+ return n ? (*(unsigned char *)s1 - *(unsigned char *)s2) : 0;
+}
--- /dev/null
+++ b/lib/c/src/strncpy.c
@@ -1,0 +1,16 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <string.h>
+#undef strncpy
+
+char *
+strncpy(char * restrict dst, const char * restrict src, size_t n)
+{
+ char *ret = dst;
+
+ for (; n > 0 && *src; --n)
+ *dst++ = *src++;
+ while (n-- > 0)
+ *dst++ = '\0';
+ return ret;
+}
--- /dev/null
+++ b/lib/c/src/strpbrk.c
@@ -1,0 +1,19 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <string.h>
+#undef strpbrk
+
+char *
+strpbrk(const char *s1, const char *s2)
+{
+ int c;
+ const char *p;
+
+ for (; c = *s1; ++s1) {
+ for (p = s2; *p && *p != c; ++p)
+ /* nothing */;
+ if (*p == c)
+ return s1;
+ }
+ return NULL;
+}
--- /dev/null
+++ b/lib/c/src/strrchr.c
@@ -1,0 +1,16 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <string.h>
+#undef strrchr
+
+char *
+strrchr(const char *s, int c)
+{
+ const char *t = s;
+
+ while (*t)
+ ++t;
+ while (t > s && *t != c)
+ --t;
+ return (*t == c) ? (char *)t : NULL;
+}
--- /dev/null
+++ b/lib/c/src/strspn.c
@@ -1,0 +1,20 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <string.h>
+#undef strspn
+
+size_t
+strspn(const char *s1, const char *s2)
+{
+ size_t n;
+ int c;
+ const char *p;
+
+ for (n = 0; c = *s1++; ++n) {
+ for (p = s2; *p && *p != c; ++p)
+ /* nothing */;
+ if (*p == '\0')
+ break;
+ }
+ return n;
+}
--- /dev/null
+++ b/lib/c/src/strstr.c
@@ -1,0 +1,28 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <string.h>
+#undef strstr
+
+char *
+strstr(const char *s1, const char *s2)
+{
+ const char *p, *q;
+ int c;
+
+ c = *s2++;
+ if (c == '\0')
+ return (char *) s1;
+
+ while (*s1) {
+ if (*s1 != c) {
+ ++s1;
+ } else {
+ p = s1++;
+ for (q = s2; *q && *s1 == *q; ++s1, ++q)
+ /* nothing */;
+ if (*q == '\0')
+ return (char *) p;
+ }
+ }
+ return NULL;
+}
--- /dev/null
+++ b/lib/c/src/strtok.c
@@ -1,0 +1,27 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <string.h>
+#undef strtok
+
+char *
+strtok(char * restrict s, const char * restrict delim)
+{
+ static char *line;
+
+ if (s)
+ line = s;
+ if (!s && !line)
+ return NULL;
+
+ s = line + strspn(line, delim);
+ if (*s == '\0')
+ return line = NULL;
+
+ line = s + strcspn(s, delim);
+ if (*line != '\0')
+ *line++ = '\0';
+ else
+ line = NULL;
+
+ return s;
+}
--- /dev/null
+++ b/lib/c/src/strxfrm.c
@@ -1,0 +1,14 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <string.h>
+#undef strxfrm
+
+size_t
+strxfrm(char * restrict dst, const char * restrict src, size_t n)
+{
+ size_t len = strlen(src);
+
+ if (len < n)
+ strcpy(dst, src);
+ return len;
+}
--- /dev/null
+++ b/lib/c/src/syscall.h
@@ -1,0 +1,11 @@
+/* See LICENSE file for copyright and license details. */
+
+extern void *_brk(void *addr);
+extern int _open(char *path, int flags, int perm);
+extern int _close(int fd);
+extern int _read(int fd, void *buf, size_t n);
+extern int _write(int fd, void *buf, size_t n);
+extern int _lseek(int fd, long off, int whence);
+extern void _Exit(int status);
+extern int raise(int sig);
+extern void (*signal(int sig, void (*func)(int)))(int);
--- /dev/null
+++ b/lib/c/src/tolower.c
@@ -1,0 +1,11 @@
+/* See LICENSE file for copyright and license details. */
+
+#define __USE_MACROS
+#include <ctype.h>
+#undef tolower
+
+int
+tolower(int c)
+{
+ return (isupper(c)) ? c | 0x20 : c;
+}
--- /dev/null
+++ b/lib/c/src/toupper.c
@@ -1,0 +1,11 @@
+/* See LICENSE file for copyright and license details. */
+
+#define __USE_MACROS
+#include <ctype.h>
+#undef toupper
+
+int
+toupper(int c)
+{
+ return (islower(c)) ? c & ~0x20 : c;
+}
--- /dev/null
+++ b/lib/c/src/vfprintf.c
@@ -1,0 +1,76 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <stdarg.h>
+#include <stdio.h>
+#undef vfprintf
+
+static int
+printn2(FILE * restrict fp, unsigned n, int base)
+{
+ unsigned t;
+ int cnt = 0;
+ static char digits[] = "0123456789ABCDEF";
+
+ if ((t = n / base) != 0)
+ cnt += printn2(fp, t, base);
+ putc(digits[n % base], fp);
+ return cnt + 1;
+}
+
+static int
+printn(FILE * restrict fp, int n, int b, int sign)
+{
+ int cnt = 0;
+
+ if (sign && n < 0) {
+ n = -n;
+ putc('-', fp);
+ ++cnt;
+ }
+ cnt += printn2(fp, n, b);
+ return cnt;
+}
+
+int
+vfprintf(FILE * restrict fp, const char *fmt, va_list va)
+{
+ int c, base, sign, cnt = 0;
+ char *s;
+
+ while ((c = *fmt++) != '\0') {
+ if (c == '%') {
+ sign = 0;
+ switch (*fmt++) {
+ case '%':
+ c = '%';
+ break;
+ case 'c':
+ c = va_arg(va, int);
+ break;
+ case 'o':
+ base = 8;
+ goto numeric;
+ case 'd':
+ sign = 1;
+ base = 10;
+ goto numeric;
+ case 'x':
+ base = 16;
+ numeric:
+ c = va_arg(va, int);
+ cnt += printn(fp, c, base, sign);
+ continue;
+ case 's':
+ s = va_arg(va, char *);
+ while ((c = *s++) != '\0')
+ putc(c, fp);
+ /* passthrou */
+ default:
+ continue;
+ }
+ }
+ putc(c, fp);
+ ++cnt;
+ }
+ return cnt;
+}
--- /dev/null
+++ b/lib/cc/Makefile
@@ -1,0 +1,20 @@
+# See LICENSE file for copyright and license details.
+.POSIX:
+
+include ../../config.mk
+
+LIBDIR = ./
+
+all: libcc.a
+
+libcc.a:
+ ar $(ARFLAGS) $@ $?
+ ranlib $@
+
+dep:
+
+clean:
+ rm -f *.o *.a
+
+distclean: clean
+include libdep.mk
--- /dev/null
+++ b/lib/cc/debug.c
@@ -1,0 +1,21 @@
+/* See LICENSE file for copyright and license details. */
+static char sccsid[] = "@(#) ./lib/debug.c";
+#include <stdarg.h>
+#include <stdio.h>
+
+#include "../../inc/cc.h"
+
+int debug;
+
+void
+dbg(const char *fmt, ...)
+{
+ if (!debug)
+ return;
+ va_list va;
+ va_start(va, fmt);
+ vfprintf(stderr, fmt, va);
+ putc('\n', stderr);
+ va_end(va);
+ return;
+}
--- /dev/null
+++ b/lib/cc/die.c
@@ -1,0 +1,21 @@
+/* See LICENSE file for copyright and license details. */
+static char sccsid[] = "@(#) ./lib/die.c";
+#include <stdarg.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "../../inc/cc.h"
+
+int failure;
+
+void
+die(const char *fmt, ...)
+{
+ failure = 1;
+ va_list va;
+ va_start(va, fmt);
+ vfprintf(stderr, fmt, va);
+ putc('\n', stderr);
+ va_end(va);
+ exit(1);
+}
--- /dev/null
+++ b/lib/cc/libdep.mk
@@ -1,0 +1,10 @@
+
+LIB-OBJ = $(LIBDIR)/debug.o \
+ $(LIBDIR)/die.o \
+ $(LIBDIR)/newitem.o \
+ $(LIBDIR)/xcalloc.o \
+ $(LIBDIR)/xmalloc.o \
+ $(LIBDIR)/xrealloc.o \
+ $(LIBDIR)/xstrdup.o \
+
+$(LIBDIR)/libcc.a: $(LIB-OBJ)
--- /dev/null
+++ b/lib/cc/newitem.c
@@ -1,0 +1,12 @@
+#include "../../inc/cc.h"
+
+void
+newitem(struct items *items, char *item)
+{
+ if ((items->n + 1) < items->n)
+ die("newitem: overflow (%u + 1)", items->n);
+
+ items->s = xrealloc(items->s, (items->n + 1) * sizeof(char **));
+ items->s[items->n++] = item;
+}
+
--- /dev/null
+++ b/lib/cc/xcalloc.c
@@ -1,0 +1,14 @@
+/* See LICENSE file for copyright and license details. */
+static char sccsid[] = "@(#) ./lib/xcalloc.c";
+#include <stdlib.h>
+#include "../../inc/cc.h"
+
+void *
+xcalloc(size_t n, size_t size)
+{
+ void *p = calloc(n, size);
+
+ if (!p)
+ die("out of memory");
+ return p;
+}
--- /dev/null
+++ b/lib/cc/xmalloc.c
@@ -1,0 +1,14 @@
+/* See LICENSE file for copyright and license details. */
+static char sccsid[] = "@(#) ./lib/xmalloc.c";
+#include <stdlib.h>
+#include "../../inc/cc.h"
+
+void *
+xmalloc(size_t size)
+{
+ void *p = malloc(size);
+
+ if (!p)
+ die("out of memory");
+ return p;
+}
--- /dev/null
+++ b/lib/cc/xrealloc.c
@@ -1,0 +1,14 @@
+/* See LICENSE file for copyright and license details. */
+static char sccsid[] = "@(#) ./lib/xrealloc.c";
+#include <stdlib.h>
+#include "../../inc/cc.h"
+
+void *
+xrealloc(void *buff, size_t size)
+{
+ void *p = realloc(buff, size);
+
+ if (!p)
+ die("out of memory");
+ return p;
+}
--- /dev/null
+++ b/lib/cc/xstrdup.c
@@ -1,0 +1,13 @@
+/* See LICENSE file for copyright and license details. */
+static char sccsid[] = "@(#) ./lib/xstrdup.c";
+#include <string.h>
+#include "../../inc/cc.h"
+
+char *
+xstrdup(const char *s)
+{
+ size_t len = strlen(s) + 1;
+ char *p = xmalloc(len);
+
+ return memcpy(p, s, len);
+}
--- /dev/null
+++ b/lib/crt/Makefile
@@ -1,0 +1,11 @@
+.POSIX:
+
+include ../../config.mk
+
+all: crt-$(ARCH)-$(SYS).o
+
+crt-$(ARCH)-$(SYS).o: $(ARCH)-$(SYS)/crt.o
+ ln -f $(ARCH)-$(SYS)/crt.o $@
+
+clean:
+ rm -f */crt.o crt-*.o
--- /dev/null
+++ b/lib/crt/amd64-sysv-linux/crt.s
@@ -1,0 +1,8 @@
+ .file "crt.s"
+
+ .text
+ .global _start
+_start:
+ call main
+ movl %eax, %edi
+ call exit
--- /dev/null
+++ b/lib/crt/amd64-sysv-openbsd/crt.s
@@ -1,0 +1,23 @@
+ .file "crt.s"
+
+ .section ".note.openbsd.ident", "a"
+ .p2align 2
+ .long 8
+ .long 4
+ .long 1
+ .ascii "OpenBSD\0"
+ .long 0
+ .p2align 2
+
+ .text
+ .align 8
+ .global _start
+_start:
+ call main
+ movl %eax, %edi
+ call exit
+
+ .data
+ .global __guard_local
+__guard_local:
+ .long 0
--- /dev/null
+++ b/lib/crt/i386-sysv-linux/crt.s
@@ -1,0 +1,1 @@
+/* TODO */
--- /dev/null
+++ b/lib/crt/i386-sysv-openbsd/crt.s
@@ -1,0 +1,1 @@
+/* TODO */
--- a/lib/debug.c
+++ /dev/null
@@ -1,21 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-static char sccsid[] = "@(#) ./lib/debug.c";
-#include <stdarg.h>
-#include <stdio.h>
-
-#include "../inc/cc.h"
-
-int debug;
-
-void
-dbg(const char *fmt, ...)
-{
- if (!debug)
- return;
- va_list va;
- va_start(va, fmt);
- vfprintf(stderr, fmt, va);
- putc('\n', stderr);
- va_end(va);
- return;
-}
--- a/lib/die.c
+++ /dev/null
@@ -1,21 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-static char sccsid[] = "@(#) ./lib/die.c";
-#include <stdarg.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-#include "../inc/cc.h"
-
-int failure;
-
-void
-die(const char *fmt, ...)
-{
- failure = 1;
- va_list va;
- va_start(va, fmt);
- vfprintf(stderr, fmt, va);
- putc('\n', stderr);
- va_end(va);
- exit(1);
-}
--- a/lib/newitem.c
+++ /dev/null
@@ -1,12 +1,0 @@
-#include "../inc/cc.h"
-
-void
-newitem(struct items *items, char *item)
-{
- if ((items->n + 1) < items->n)
- die("newitem: overflow (%u + 1)", items->n);
-
- items->s = xrealloc(items->s, (items->n + 1) * sizeof(char **));
- items->s[items->n++] = item;
-}
-
--- /dev/null
+++ b/lib/sys/Makefile
@@ -1,0 +1,13 @@
+# See LICENSE file for copyright and license details.
+.POSIX:
+
+include ../../config.mk
+
+all clean distclean:
+ pwd=$$PWD ;\
+ for i in $(SYSS); \
+ do \
+ cd $$i; \
+ $(MAKE) -e SYS=$i $@ ;\
+ cd $$pwd; \
+ done
--- /dev/null
+++ b/lib/sys/abi/amd64-sysv.sh
@@ -1,0 +1,15 @@
+#!/bin/sh
+
+#
+# This job is very easy because app and kernel ABI are identical
+# until the 4th parameter, so we only have to set the syscall
+# number in rax
+
+awk '/^#/ {next}
+ {name=$2 ".s"
+ printf ".global %s\n" \
+ "%s:\n" \
+ "\tmovq\t$%d,%%rax\n" \
+ "\tsyscall\n" \
+ "\tret\n", $2, $2, $1 > name
+ close(name)}' syscall.lst
--- /dev/null
+++ b/lib/sys/amd64-sysv-linux/Makefile
@@ -1,0 +1,5 @@
+# See LICENSE file for copyright and license details.
+.POSIX:
+
+include ../common.mk
+ABI = amd64-sysv
--- /dev/null
+++ b/lib/sys/amd64-sysv-linux/syscall.lst
@@ -1,0 +1,11 @@
+#number name
+0 _read
+1 _write
+2 _open
+3 _close
+3 _lseek
+12 _brk
+13 _rt_sigaction
+38 _getpid
+60 _Exit
+32 _kill
--- /dev/null
+++ b/lib/sys/common.mk
@@ -1,0 +1,13 @@
+# See LICENSE file for copyright and license details.
+.POSIX:
+
+include ../../../config.mk
+
+all clean distclean: system.mk
+ $(MAKE) ABI=$(ABI) -f ../libsys.mk $@
+
+system.mk: syscall.lst
+ rm -f $@; trap "rm -f $$$$.mk" 0 2 3; \
+ awk 'BEGIN{printf "OBJ = "} \
+ ! /^#/ {printf "%s.o ", $$2}' syscall.lst > $$$$.mk && \
+ mv $$$$.mk $@
--- /dev/null
+++ b/lib/sys/i386-sysv-linux/Makefile
@@ -1,0 +1,4 @@
+# See LICENSE file for copyright and license details.
+.POSIX:
+
+include ../Makefile.sys
--- /dev/null
+++ b/lib/sys/libsys.mk
@@ -1,0 +1,24 @@
+# See LICENSE file for copyright and license details.
+.POSIX:
+
+include ../../../config.mk
+include system.mk
+
+ASM = $(OBJ:.o=.s)
+
+all: libsys.a
+
+libsys.a: $(OBJ)
+ $(AR) $(ARFLAGS) $@ $?
+ ranlib $@
+
+$(ASM): syscall.lst
+ ../abi/$(ABI).sh
+
+clean:
+ rm -f $(ASM)
+ rm -f $(OBJ)
+ rm -f libsys.a
+
+distclean: clean
+ rm -f system.mk
--- /dev/null
+++ b/lib/sys/qbe-linux/Makefile
@@ -1,0 +1,5 @@
+# See LICENSE file for copyright and license details.
+.POSIX:
+
+include ../common.mk
+ABI=amd64-sysv
--- /dev/null
+++ b/lib/sys/qbe-linux/syscall.lst
@@ -1,0 +1,11 @@
+#number name
+0 _read
+1 _write
+2 _open
+3 _close
+3 _lseek
+12 _brk
+13 _rt_sigaction
+38 _getpid
+60 _Exit
+32 _kill
--- /dev/null
+++ b/lib/sys/z80-linux/Makefile
@@ -1,0 +1,4 @@
+# See LICENSE file for copyright and license details.
+.POSIX:
+
+include ../Makefile.sys
--- a/lib/xcalloc.c
+++ /dev/null
@@ -1,14 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-static char sccsid[] = "@(#) ./lib/xcalloc.c";
-#include <stdlib.h>
-#include "../inc/cc.h"
-
-void *
-xcalloc(size_t n, size_t size)
-{
- void *p = calloc(n, size);
-
- if (!p)
- die("out of memory");
- return p;
-}
--- a/lib/xmalloc.c
+++ /dev/null
@@ -1,14 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-static char sccsid[] = "@(#) ./lib/xmalloc.c";
-#include <stdlib.h>
-#include "../inc/cc.h"
-
-void *
-xmalloc(size_t size)
-{
- void *p = malloc(size);
-
- if (!p)
- die("out of memory");
- return p;
-}
--- a/lib/xrealloc.c
+++ /dev/null
@@ -1,14 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-static char sccsid[] = "@(#) ./lib/xrealloc.c";
-#include <stdlib.h>
-#include "../inc/cc.h"
-
-void *
-xrealloc(void *buff, size_t size)
-{
- void *p = realloc(buff, size);
-
- if (!p)
- die("out of memory");
- return p;
-}
--- a/lib/xstrdup.c
+++ /dev/null
@@ -1,13 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-static char sccsid[] = "@(#) ./lib/xstrdup.c";
-#include <string.h>
-#include "../inc/cc.h"
-
-char *
-xstrdup(const char *s)
-{
- size_t len = strlen(s) + 1;
- char *p = xmalloc(len);
-
- return memcpy(p, s, len);
-}
--- a/libc/include/assert.h
+++ /dev/null
@@ -1,13 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-#ifndef _ASSERT_H
-#define _ASSERT_H
-
-void __assert(char *exp, char *file, long line);
-
-#ifndef NDEBUG
-# define assert(exp) ((exp) ? (void) 0 : __assert(#exp, __FILE__, __LINE__))
-#else
-# define assert(exp) ((void)0)
-#endif
-
-#endif
--- a/libc/include/bits/amd64-sysv/arch/limits.h
+++ /dev/null
@@ -1,17 +1,0 @@
-#define SCHAR_MAX 0x7F
-#define SCHAR_MIN (-SCHAR_MIN-1)
-#define CHAR_MAX 0x7F
-#define CHAR_MIN (-CHAR_MAX-1)
-#define UCHAR_MAX 0xFF
-#define SHRT_MAX 0x7FFF
-#define SHRT_MIN (-SHRT_MAX-1)
-#define USHRT_MAX 0xFFFF
-#define INT_MAX 0x7FFFFFFF
-#define INT_MIN (-INT_MAX-1)
-#define UINT_MAX 0xFFFFFFFF
-#define LONG_MAX 0x7FFFFFFFFFFFFFFF
-#define LONG_MIN (-LONG_MAX-1)
-#define ULONG_MAX 0xFFFFFFFFFFFFFFFF
-#define LLONG_MAX 0x7FFFFFFFFFFFFFFF
-#define LLONG_MIN (-LLONG_MAX-1)
-#define ULLONG_MAX 0xFFFFFFFFFFFFFFFF
--- a/libc/include/bits/amd64-sysv/arch/signal.h
+++ /dev/null
@@ -1,29 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-typedef int sig_atomic_t;
-
-#define SIG_ERR -1
-#define SIG_DFL 0
-#define SIG_IGN 1
-
-#define SIGHUP 1
-#define SIGINT 2
-#define SIGQUIT 3
-#define SIGILL 4
-#define SIGABRT 6
-#define SIGFPE 8
-#define SIGKILL 9
-#define SIGUSR1 10
-#define SIGSEGV 11
-#define SIGUSR2 12
-#define SIGPIPE 13
-#define SIGALRM 14
-#define SIGTERM 15
-#define SIGCHLD 17
-#define SIGCONT 18
-#define SIGSTOP 19
-#define SIGSSTP 20
-#define SIGTTIN 21
-#define SIGTTOU 22
-
-#define __NR_SIGNALS 23
--- a/libc/include/bits/amd64-sysv/arch/stddef.h
+++ /dev/null
@@ -1,16 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#ifndef _SIZET
-typedef unsigned long size_t;
-#define _SIZET
-#endif
-
-#ifndef _WCHAR_T
-typedef int wchar_t;
-#define _WCHAR_T
-#endif
-
-#ifndef _PTRDIFF_T
-typedef long ptrdiff_t;
-#define _PTRDIFF_T
-#endif
--- a/libc/include/bits/amd64-sysv/arch/stdint.h
+++ /dev/null
@@ -1,117 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#define INT8_MAX 0x7F
-#define INT8_MIN (-INT8_MAX-1)
-#define UINT8_MAX 0xFF
-
-#define INT16_MAX 0x7FFF
-#define INT16_MIN (-INT16_MAX-1)
-#define UINT16_MAX 0xFFFF
-
-#define INT32_MAX 0x7FFFFFFF
-#define INT32_MIN (-INT32_MAX-1)
-#define UINT32_MAX 0xFFFFFFFF
-
-#define INT64_MAX 0x7FFFFFFFFFFFFFFF
-#define INT64_MIN (-INT64_MAX-1)
-#define UINT64_MAX 0xFFFFFFFFFFFFFFFF
-
-#define INT_LEAST8_MIN INT8_MIN
-#define INT_LEAST8_MAX INT8_MAX
-#define UINT_LEAST8_MAX UINT8_MAX
-
-#define INT_LEAST16_MIN INT16_MIN
-#define INT_LEAST16_MAX INT16_MAX
-#define UINT_LEAST16_MAX UINT16_MAX
-
-#define INT_LEAST32_MIN INT32_MIN
-#define INT_LEAST32_MAX INT32_MAX
-#define UINT_LEAST32_MAX UINT32_MAX
-
-#define INT_LEAST64_MIN INT64_MIN
-#define INT_LEAST64_MAX INT64_MAX
-#define UINT_LEAST64_MAX UINT64_MAX
-
-#define INT_FAST8_MIN INT32_MIN
-#define INT_FAST8_MAX INT32_MAX
-#define UINT_FAST8_MAX UINT32_MAX
-
-#define INT_FAST16_MIN INT32_MIN
-#define INT_FAST16_MAX INT32_MAX
-#define UINT_FAST16_MAX UINT32_MAX
-
-#define INT_FAST32_MIN INT32_MIN
-#define INT_FAST32_MAX INT32_MAX
-#define UINT_FAST32_MAX UINT32_MAX
-
-#define INT_FAST64_MIN INT64_MIN
-#define INT_FAST64_MAX INT64_MAX
-#define UINT_FAST64_MAX UINT64_MAX
-
-#define INTPTR_MIN INT64_MIN
-#define INTPTR_MAX INT64_MAX
-#define UINTPTR_MAX UINT64_MAX
-
-#define INTMAX_MIN INT64_MIN
-#define INTMAX_MAX INT64_MAX
-#define UINTMAX_MAX UINT64_MAX
-
-#define PTRDIFF_MIN INT64_MIN
-#define PTRDIFF_MAX INT64_MAX
-
-#define SIG_ATOMIC_MIN INT32_MIN
-#define SIG_ATOMIC_MAX INT32_MAX
-
-#define SIZE_MAX UINT64_MAX
-
-#define WCHAR_MIN INT32_MIN
-#define WCHAR_MAX INT32_MAX
-
-#define INT8_C(x) x
-#define INT16_C(x) x
-#define INT32_C(x) x
-#define INT64_C(x) x ## L
-
-#define UINT8_C(x) x
-#define UINT16_C(x) x
-#define UINT32_C(x) x ## U
-#define UINT64_C(x) x ## UL
-
-#define INTMAX_C(x) x ## L
-#define UINTMAX_C(x) x ## UL
-
-typedef signed char int8_t;
-typedef short int16_t;
-typedef int int32_t;
-typedef long int64_t;
-
-typedef unsigned char uint8_t;
-typedef unsigned short uint16_t;
-typedef unsigned uint32_t;
-typedef unsigned long uint64_t;
-
-typedef signed char int8_least_t;
-typedef short int16_least_t;
-typedef int int32_least_t;
-typedef long int64_least_t;
-
-typedef unsigned char uint8_least_t;
-typedef unsigned short uint16_least_t;
-typedef unsigned uint32_least_t;
-typedef unsigned long uint64_least_t;
-
-typedef int int8_fast_t;
-typedef int int16_fast_t;
-typedef int int32_fast_t;
-typedef long int64_fast_t;
-
-typedef unsigned uint8_fast_t;
-typedef unsigned uint16_fast_t;
-typedef unsigned uint32_fast_t;
-typedef unsigned long uint64_fast_t;
-
-typedef long intptr_t;
-typedef unsigned long uintptr_t;
-
-typedef long intmax_t;
-typedef unsigned long uintmax_t;
--- a/libc/include/bits/amd64-sysv/arch/stdio.h
+++ /dev/null
@@ -1,15 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#ifndef _SIZET
-typedef unsigned long size_t;
-#define _SIZET
-#endif
-
-#define BUFSIZ 512
-#define FILENAME_MAX 256
-#define FOPEN_MAX 16
-
-#define TMP_MAX 25
-#define L_tmpnam 256
-
-typedef int fpos_t;
--- a/libc/include/bits/amd64-sysv/arch/stdlib.h
+++ /dev/null
@@ -1,16 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#ifndef _SIZET
-typedef unsigned long size_t;
-#define _SIZET
-#endif
-
-#define EXIT_FAILURE 1
-#define EXIT_SUCCESS 0
-
-#ifndef _WCHAR_T
-typedef int wchar_t;
-#define _WCHAR_T
-#endif
-
-#define _ALIGNTYPE long double
--- a/libc/include/bits/amd64-sysv/arch/string.h
+++ /dev/null
@@ -1,5 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#ifndef _SIZET
-typedef unsigned long size_t;
-#endif
--- a/libc/include/bits/amd64-sysv/arch/time.h
+++ /dev/null
@@ -1,8 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#ifndef _SIZET
-typedef unsigned long size_t;
-#define _SIZET
-#endif
-
-typedef long int time_t;
--- a/libc/include/bits/i386-sysv/arch/limits.h
+++ /dev/null
@@ -1,17 +1,0 @@
-#define SCHAR_MAX 0x7F
-#define SCHAR_MIN (-SCHAR_MIN-1)
-#define CHAR_MAX 0x7F
-#define CHAR_MIN (-CHAR_MAX-1)
-#define UCHAR_MAX 0xFF
-#define SHRT_MAX 0x7FFF
-#define SHRT_MIN (-SHRT_MAX-1)
-#define USHRT_MAX 0xFFFF
-#define INT_MAX 0x7FFFFFFF
-#define INT_MIN (-INT_MAX-1)
-#define UINT_MAX 0xFFFFFFFF
-#define LONG_MAX 0x7FFFFFFF
-#define LONG_MIN (-LONG_MAX-1)
-#define ULONG_MAX 0xFFFFFFFF
-#define LLONG_MAX 0x7FFFFFFFFFFFFFFF
-#define LLONG_MIN (-LLONG_MAX-1)
-#define ULLONG_MAX 0xFFFFFFFFFFFFFFFF
--- a/libc/include/bits/i386-sysv/arch/signal.h
+++ /dev/null
@@ -1,29 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-typedef int sig_atomic_t;
-
-#define SIG_ERR -1
-#define SIG_DFL 0
-#define SIG_IGN 1
-
-#define SIGHUP 1
-#define SIGINT 2
-#define SIGQUIT 3
-#define SIGILL 4
-#define SIGABRT 6
-#define SIGFPE 8
-#define SIGKILL 9
-#define SIGUSR1 10
-#define SIGSEGV 11
-#define SIGUSR2 12
-#define SIGPIPE 13
-#define SIGALRM 14
-#define SIGTERM 15
-#define SIGCHLD 17
-#define SIGCONT 18
-#define SIGSTOP 19
-#define SIGSSTP 20
-#define SIGTTIN 21
-#define SIGTTOU 22
-
-#define __NR_SIGNALS 23
--- a/libc/include/bits/i386-sysv/arch/stddef.h
+++ /dev/null
@@ -1,16 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#ifndef _SIZET
-typedef unsigned long size_t;
-#define _SIZET
-#endif
-
-#ifndef _WCHAR_T
-typedef int wchar_t;
-#define _WCHAR_T
-#endif
-
-#ifndef _PTRDIFF_T
-typedef long ptrdiff_t;
-#define _PTRDIFF_T
-#endif
--- a/libc/include/bits/i386-sysv/arch/stdint.h
+++ /dev/null
@@ -1,117 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#define INT8_MAX 0x7F
-#define INT8_MIN (-INT8_MAX-1)
-#define UINT8_MAX 0xFF
-
-#define INT16_MAX 0x7FFF
-#define INT16_MIN (-INT16_MAX-1)
-#define UINT16_MAX 0xFFFF
-
-#define INT32_MAX 0x7FFFFFFF
-#define INT32_MIN (-INT32_MAX-1)
-#define UINT32_MAX 0xFFFFFFFF
-
-#define INT64_MAX 0x7FFFFFFFFFFFFFFF
-#define INT64_MIN (-INT64_MAX-1)
-#define UINT64_MAX 0xFFFFFFFFFFFFFFFF
-
-#define INT_LEAST8_MIN INT8_MIN
-#define INT_LEAST8_MAX INT8_MAX
-#define UINT_LEAST8_MAX UINT8_MAX
-
-#define INT_LEAST16_MIN INT16_MIN
-#define INT_LEAST16_MAX INT16_MAX
-#define UINT_LEAST16_MAX UINT16_MAX
-
-#define INT_LEAST32_MIN INT32_MIN
-#define INT_LEAST32_MAX INT32_MAX
-#define UINT_LEAST32_MAX UINT32_MAX
-
-#define INT_LEAST64_MIN INT64_MIN
-#define INT_LEAST64_MAX INT64_MAX
-#define UINT_LEAST64_MAX UINT64_MAX
-
-#define INT_FAST8_MIN INT32_MIN
-#define INT_FAST8_MAX INT32_MAX
-#define UINT_FAST8_MAX UINT32_MAX
-
-#define INT_FAST16_MIN INT32_MIN
-#define INT_FAST16_MAX INT32_MAX
-#define UINT_FAST16_MAX UINT32_MAX
-
-#define INT_FAST32_MIN INT32_MIN
-#define INT_FAST32_MAX INT32_MAX
-#define UINT_FAST32_MAX UINT32_MAX
-
-#define INT_FAST64_MIN INT64_MIN
-#define INT_FAST64_MAX INT64_MAX
-#define UINT_FAST64_MAX UINT64_MAX
-
-#define INTPTR_MIN INT32_MIN
-#define INTPTR_MAX INT32_MAX
-#define UINTPTR_MAX UINT32_MAX
-
-#define INTMAX_MIN INT64_MIN
-#define INTMAX_MAX INT64_MAX
-#define UINTMAX_MAX UINT64_MAX
-
-#define PTRDIFF_MIN INT32_MIN
-#define PTRDIFF_MAX INT32_MAX
-
-#define SIG_ATOMIC_MIN INT32_MIN
-#define SIG_ATOMIC_MAX INT32_MAX
-
-#define SIZE_MAX UINT32_MAX
-
-#define WCHAR_MIN INT32_MIN
-#define WCHAR_MAX INT32_MAX
-
-#define INT8_C(x) x
-#define INT16_C(x) x
-#define INT32_C(x) x
-#define INT64_C(x) x ## LL
-
-#define UINT8_C(x) x
-#define UINT16_C(x) x
-#define UINT32_C(x) x ## U
-#define UINT64_C(x) x ## ULL
-
-#define INTMAX_C(x) x ## LL
-#define UINTMAX_C(x) x ## ULL
-
-typedef signed char int8_t;
-typedef short int16_t;
-typedef int int32_t;
-typedef long long int64_t;
-
-typedef unsigned char uint8_t;
-typedef unsigned short uint16_t;
-typedef unsigned uint32_t;
-typedef unsigned long long uint64_t;
-
-typedef signed char int8_least_t;
-typedef short int16_least_t;
-typedef int int32_least_t;
-typedef long long int64_least_t;
-
-typedef unsigned char uint8_least_t;
-typedef unsigned short uint16_least_t;
-typedef unsigned uint32_least_t;
-typedef unsigned long long uint64_least_t;
-
-typedef int int8_fast_t;
-typedef int int16_fast_t;
-typedef int int32_fast_t;
-typedef long long int64_fast_t;
-
-typedef unsigned uint8_fast_t;
-typedef unsigned uint16_fast_t;
-typedef unsigned uint32_fast_t;
-typedef unsigned long long uint64_fast_t;
-
-typedef int intptr_t;
-typedef unsigned uintptr_t;
-
-typedef long long intmax_t;
-typedef unsigned long long uintmax_t;
--- a/libc/include/bits/i386-sysv/arch/stdio.h
+++ /dev/null
@@ -1,15 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#ifndef _SIZET
-typedef unsigned long size_t;
-#define _SIZET
-#endif
-
-#define BUFSIZ 512
-#define FILENAME_MAX 256
-#define FOPEN_MAX 16
-
-#define TMP_MAX 25
-#define L_tmpnam 256
-
-typedef long fpos_t;
--- a/libc/include/bits/i386-sysv/arch/stdlib.h
+++ /dev/null
@@ -1,16 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#ifndef _SIZET
-typedef unsigned long size_t;
-#define _SIZET
-#endif
-
-#define EXIT_FAILURE 1
-#define EXIT_SUCCESS 0
-
-#ifndef _WCHAR_T
-typedef int wchar_t;
-#define _WCHAR_T
-#endif
-
-#define _ALIGNTYPE long double
--- a/libc/include/bits/i386-sysv/arch/string.h
+++ /dev/null
@@ -1,5 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#ifndef _SIZET
-typedef unsigned long size_t;
-#endif
--- a/libc/include/bits/i386-sysv/arch/time.h
+++ /dev/null
@@ -1,8 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#ifndef _SIZET
-typedef unsigned long size_t;
-#define _SIZET
-#endif
-
-typedef long int time_t;
--- a/libc/include/bits/qbe/arch/limits.h
+++ /dev/null
@@ -1,17 +1,0 @@
-#define SCHAR_MAX 0x7F
-#define SCHAR_MIN (-SCHAR_MIN-1)
-#define CHAR_MAX 0x7F
-#define CHAR_MIN (-CHAR_MAX-1)
-#define UCHAR_MAX 0xFF
-#define SHRT_MAX 0x7FFF
-#define SHRT_MIN (-SHRT_MAX-1)
-#define USHRT_MAX 0xFFFF
-#define INT_MAX 0x7FFFFFFF
-#define INT_MIN (-INT_MAX-1)
-#define UINT_MAX 0xFFFFFFFF
-#define LONG_MAX 0x7FFFFFFFFFFFFFFF
-#define LONG_MIN (-LONG_MAX-1)
-#define ULONG_MAX 0xFFFFFFFFFFFFFFFF
-#define LLONG_MAX 0x7FFFFFFFFFFFFFFF
-#define LLONG_MIN (-LLONG_MAX-1)
-#define ULLONG_MAX 0xFFFFFFFFFFFFFFFF
--- a/libc/include/bits/qbe/arch/signal.h
+++ /dev/null
@@ -1,29 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-typedef int sig_atomic_t;
-
-#define SIG_ERR -1
-#define SIG_DFL 0
-#define SIG_IGN 1
-
-#define SIGHUP 1
-#define SIGINT 2
-#define SIGQUIT 3
-#define SIGILL 4
-#define SIGABRT 6
-#define SIGFPE 8
-#define SIGKILL 9
-#define SIGUSR1 10
-#define SIGSEGV 11
-#define SIGUSR2 12
-#define SIGPIPE 13
-#define SIGALRM 14
-#define SIGTERM 15
-#define SIGCHLD 17
-#define SIGCONT 18
-#define SIGSTOP 19
-#define SIGSSTP 20
-#define SIGTTIN 21
-#define SIGTTOU 22
-
-#define __NR_SIGNALS 23
--- a/libc/include/bits/qbe/arch/stddef.h
+++ /dev/null
@@ -1,16 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#ifndef _SIZET
-typedef unsigned long size_t;
-#define _SIZET
-#endif
-
-#ifndef _WCHAR_T
-typedef int wchar_t;
-#define _WCHAR_T
-#endif
-
-#ifndef _PTRDIFF_T
-typedef long ptrdiff_t;
-#define _PTRDIFF_T
-#endif
--- a/libc/include/bits/qbe/arch/stdint.h
+++ /dev/null
@@ -1,117 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#define INT8_MAX 0x7F
-#define INT8_MIN (-INT8_MAX-1)
-#define UINT8_MAX 0xFF
-
-#define INT16_MAX 0x7FFF
-#define INT16_MIN (-INT16_MAX-1)
-#define UINT16_MAX 0xFFFF
-
-#define INT32_MAX 0x7FFFFFFF
-#define INT32_MIN (-INT32_MAX-1)
-#define UINT32_MAX 0xFFFFFFFF
-
-#define INT64_MAX 0x7FFFFFFFFFFFFFFF
-#define INT64_MIN (-INT64_MAX-1)
-#define UINT64_MAX 0xFFFFFFFFFFFFFFFF
-
-#define INT_LEAST8_MIN INT8_MIN
-#define INT_LEAST8_MAX INT8_MAX
-#define UINT_LEAST8_MAX UINT8_MAX
-
-#define INT_LEAST16_MIN INT16_MIN
-#define INT_LEAST16_MAX INT16_MAX
-#define UINT_LEAST16_MAX UINT16_MAX
-
-#define INT_LEAST32_MIN INT32_MIN
-#define INT_LEAST32_MAX INT32_MAX
-#define UINT_LEAST32_MAX UINT32_MAX
-
-#define INT_LEAST64_MIN INT64_MIN
-#define INT_LEAST64_MAX INT64_MAX
-#define UINT_LEAST64_MAX UINT64_MAX
-
-#define INT_FAST8_MIN INT32_MIN
-#define INT_FAST8_MAX INT32_MAX
-#define UINT_FAST8_MAX UINT32_MAX
-
-#define INT_FAST16_MIN INT32_MIN
-#define INT_FAST16_MAX INT32_MAX
-#define UINT_FAST16_MAX UINT32_MAX
-
-#define INT_FAST32_MIN INT32_MIN
-#define INT_FAST32_MAX INT32_MAX
-#define UINT_FAST32_MAX UINT32_MAX
-
-#define INT_FAST64_MIN INT64_MIN
-#define INT_FAST64_MAX INT64_MAX
-#define UINT_FAST64_MAX UINT64_MAX
-
-#define INTPTR_MIN INT64_MIN
-#define INTPTR_MAX INT64_MAX
-#define UINTPTR_MAX UINT64_MAX
-
-#define INTMAX_MIN INT64_MIN
-#define INTMAX_MAX INT64_MAX
-#define UINTMAX_MAX UINT64_MAX
-
-#define PTRDIFF_MIN INT64_MIN
-#define PTRDIFF_MAX INT64_MAX
-
-#define SIG_ATOMIC_MIN INT32_MIN
-#define SIG_ATOMIC_MAX INT32_MAX
-
-#define SIZE_MAX UINT64_MAX
-
-#define WCHAR_MIN INT32_MIN
-#define WCHAR_MAX INT32_MAX
-
-#define INT8_C(x) x
-#define INT16_C(x) x
-#define INT32_C(x) x
-#define INT64_C(x) x ## L
-
-#define UINT8_C(x) x
-#define UINT16_C(x) x
-#define UINT32_C(x) x ## U
-#define UINT64_C(x) x ## UL
-
-#define INTMAX_C(x) x ## L
-#define UINTMAX_C(x) x ## UL
-
-typedef signed char int8_t;
-typedef short int16_t;
-typedef int int32_t;
-typedef long int64_t;
-
-typedef unsigned char uint8_t;
-typedef unsigned short uint16_t;
-typedef unsigned uint32_t;
-typedef unsigned long uint64_t;
-
-typedef signed char int8_least_t;
-typedef short int16_least_t;
-typedef int int32_least_t;
-typedef long int64_least_t;
-
-typedef unsigned char uint8_least_t;
-typedef unsigned short uint16_least_t;
-typedef unsigned uint32_least_t;
-typedef unsigned long uint64_least_t;
-
-typedef int int8_fast_t;
-typedef int int16_fast_t;
-typedef int int32_fast_t;
-typedef long int64_fast_t;
-
-typedef unsigned uint8_fast_t;
-typedef unsigned uint16_fast_t;
-typedef unsigned uint32_fast_t;
-typedef unsigned long uint64_fast_t;
-
-typedef long intptr_t;
-typedef unsigned long uintptr_t;
-
-typedef long intmax_t;
-typedef unsigned long uintmax_t;
--- a/libc/include/bits/qbe/arch/stdio.h
+++ /dev/null
@@ -1,15 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#ifndef _SIZET
-typedef unsigned long size_t;
-#define _SIZET
-#endif
-
-#define BUFSIZ 512
-#define FILENAME_MAX 256
-#define FOPEN_MAX 16
-
-#define TMP_MAX 25
-#define L_tmpnam 256
-
-typedef int fpos_t;
--- a/libc/include/bits/qbe/arch/stdlib.h
+++ /dev/null
@@ -1,16 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#ifndef _SIZET
-typedef unsigned long size_t;
-#define _SIZET
-#endif
-
-#define EXIT_FAILURE 1
-#define EXIT_SUCCESS 0
-
-#ifndef _WCHAR_T
-typedef int wchar_t;
-#define _WCHAR_T
-#endif
-
-#define _ALIGNTYPE long double
--- a/libc/include/bits/qbe/arch/string.h
+++ /dev/null
@@ -1,5 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#ifndef _SIZET
-typedef unsigned long size_t;
-#endif
--- a/libc/include/bits/qbe/arch/time.h
+++ /dev/null
@@ -1,8 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#ifndef _SIZET
-typedef unsigned long size_t;
-#define _SIZET
-#endif
-
-typedef long int time_t;
--- a/libc/include/bits/z80/arch/limits.h
+++ /dev/null
@@ -1,17 +1,0 @@
-#define SCHAR_MAX 0x7F
-#define SCHAR_MIN (-SCHAR_MIN-1)
-#define CHAR_MAX 0xFF
-#define CHAR_MIN 0
-#define UCHAR_MAX 0xFF
-#define SHRT_MAX 0x7FFF
-#define SHRT_MIN (-SHRT_MAX-1)
-#define USHRT_MAX 0xFFFF
-#define INT_MAX 0x7FFF
-#define INT_MIN (-INT_MAX-1)
-#define UINT_MAX 0xFFFF
-#define LONG_MAX 0x7FFFFFFF
-#define LONG_MIN (-LONG_MAX-1)
-#define ULONG_MAX 0xFFFFFFFF
-#define LLONG_MAX 0x7FFFFFFFFFFFFFFF
-#define LLONG_MIN (-LLONG_MAX-1)
-#define ULLONG_MAX 0xFFFFFFFFFFFFFFFF
--- a/libc/include/bits/z80/arch/signal.h
+++ /dev/null
@@ -1,33 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-typedef char sig_atomic_t;
-
-#define SIG_ERR -1
-#define SIG_DFL 0
-#define SIG_IGN 1
-
-#define SIG_ERR -1
-#define SIG_DFL 0
-#define SIG_IGN 1
-
-#define SIGHUP 1
-#define SIGINT 2
-#define SIGQUIT 3
-#define SIGILL 4
-#define SIGABRT 6
-#define SIGFPE 8
-#define SIGKILL 9
-#define SIGUSR1 10
-#define SIGSEGV 11
-#define SIGUSR2 12
-#define SIGPIPE 13
-#define SIGALRM 14
-#define SIGTERM 15
-#define SIGCHLD 17
-#define SIGCONT 18
-#define SIGSTOP 19
-#define SIGSSTP 20
-#define SIGTTIN 21
-#define SIGTTOU 22
-
-#define __NR_SIGNALS 23
--- a/libc/include/bits/z80/arch/stddef.h
+++ /dev/null
@@ -1,16 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#ifndef _SIZET
-typedef unsigned size_t;
-#define _SIZET
-#endif
-
-#ifndef _WCHAR_T
-typedef short wchar_t;
-#define _WCHAR_T
-#endif
-
-#ifndef _PTRDIFF_T
-typedef short ptrdiff_t;
-#define _PTRDIFF_T
-#endif
--- a/libc/include/bits/z80/arch/stdint.h
+++ /dev/null
@@ -1,117 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#define INT8_MAX 0x7F
-#define INT8_MIN (-INT8_MAX-1)
-#define UINT8_MAX 0xFF
-
-#define INT16_MAX 0x7FFF
-#define INT16_MIN (-INT16_MAX-1)
-#define UINT16_MAX 0xFFFF
-
-#define INT32_MAX 0x7FFFFFFF
-#define INT32_MIN (-INT32_MAX-1)
-#define UINT32_MAX 0xFFFFFFFF
-
-#define INT64_MAX 0x7FFFFFFFFFFFFFFF
-#define INT64_MIN (-INT64_MAX-1)
-#define UINT64_MAX 0xFFFFFFFFFFFFFFFF
-
-#define INT_LEAST8_MIN INT8_MIN
-#define INT_LEAST8_MAX INT8_MAX
-#define UINT_LEAST8_MAX UINT8_MAX
-
-#define INT_LEAST16_MIN INT16_MIN
-#define INT_LEAST16_MAX INT16_MAX
-#define UINT_LEAST16_MAX UINT16_MAX
-
-#define INT_LEAST32_MIN INT32_MIN
-#define INT_LEAST32_MAX INT32_MAX
-#define UINT_LEAST32_MAX UINT32_MAX
-
-#define INT_LEAST64_MIN INT64_MIN
-#define INT_LEAST64_MAX INT64_MAX
-#define UINT_LEAST64_MAX UINT64_MAX
-
-#define INT_FAST8_MIN INT16_MIN
-#define INT_FAST8_MAX INT16_MAX
-#define UINT_FAST8_MAX UINT16_MAX
-
-#define INT_FAST16_MIN INT16_MIN
-#define INT_FAST16_MAX INT16_MAX
-#define UINT_FAST16_MAX UINT16_MAX
-
-#define INT_FAST32_MIN INT32_MIN
-#define INT_FAST32_MAX INT32_MAX
-#define UINT_FAST32_MAX UINT32_MAX
-
-#define INT_FAST64_MIN INT64_MIN
-#define INT_FAST64_MAX INT64_MAX
-#define UINT_FAST64_MAX UINT64_MAX
-
-#define INTPTR_MIN INT16_MIN
-#define INTPTR_MAX INT16_MAX
-#define UINTPTR_MAX UINT16_MAX
-
-#define INTMAX_MIN INT64_MIN
-#define INTMAX_MAX INT64_MAX
-#define UINTMAX_MAX UINT64_MAX
-
-#define PTRDIFF_MIN INT16_MIN
-#define PTRDIFF_MAX INT16_MAX
-
-#define SIG_ATOMIC_MIN INT16_MIN
-#define SIG_ATOMIC_MAX INT16_MAX
-
-#define SIZE_MAX UINT64_MAX
-
-#define WCHAR_MIN INT16_MIN
-#define WCHAR_MAX INT16_MAX
-
-#define INT8_C(x) x
-#define INT16_C(x) x
-#define INT32_C(x) x ## L
-#define INT64_C(x) x ## LL
-
-#define UINT8_C(x) x
-#define UINT16_C(x) x ## U
-#define UINT32_C(x) x ## UL
-#define UINT64_C(x) x ## ULL
-
-#define INTMAX_C(x) x ## LL
-#define UINTMAX_C(x) x ## ULL
-
-typedef signed char int8_t;
-typedef int int16_t;
-typedef long int32_t;
-typedef long long int64_t;
-
-typedef unsigned char uint8_t;
-typedef unsigned uint16_t;
-typedef unsigned long uint32_t;
-typedef unsigned long long uint64_t;
-
-typedef signed char int8_least_t;
-typedef int int16_least_t;
-typedef long int32_least_t;
-typedef long long int64_least_t;
-
-typedef unsigned char uint8_least_t;
-typedef unsigned uint16_least_t;
-typedef unsigned long uint32_least_t;
-typedef unsigned long long uint64_least_t;
-
-typedef signed char int8_fast_t;
-typedef int int16_fast_t;
-typedef long int32_fast_t;
-typedef long long int64_fast_t;
-
-typedef unsigned char uint8_fast_t;
-typedef unsigned uint16_fast_t;
-typedef unsigned long uint32_fast_t;
-typedef unsigned long long uint64_fast_t;
-
-typedef int intptr_t;
-typedef unsigned uintptr_t;
-
-typedef long long intmax_t;
-typedef unsigned long long uintmax_t;
--- a/libc/include/bits/z80/arch/stdio.h
+++ /dev/null
@@ -1,15 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#ifndef _SIZET
-typedef unsigned size_t;
-#define _SIZET
-#endif
-
-#define BUFSIZ 512
-#define FILENAME_MAX 256
-#define FOPEN_MAX 16
-
-#define TMP_MAX 25
-#define L_tmpnam 256
-
-typedef long fpos_t;
--- a/libc/include/bits/z80/arch/stdlib.h
+++ /dev/null
@@ -1,16 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#ifndef _SIZET
-typedef unsigned size_t;
-#define _SIZET
-#endif
-
-#define EXIT_FAILURE 1
-#define EXIT_SUCCESS 0
-
-#ifndef _WCHAR_T
-typedef short wchar_t;
-#define _WCHAR_T
-#endif
-
-#define _ALIGNTYPE int
--- a/libc/include/bits/z80/arch/string.h
+++ /dev/null
@@ -1,5 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#ifndef _SIZET
-typedef unsigned size_t;
-#endif
--- a/libc/include/bits/z80/arch/time.h
+++ /dev/null
@@ -1,8 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#ifndef _SIZET
-typedef unsigned size_t;
-#define _SIZET
-#endif
-
-typedef long time_t;
--- a/libc/include/ctype.h
+++ /dev/null
@@ -1,49 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-#ifndef _CTYPE_H
-#define _CTYPE_H
-
-extern int isalnum(int c);
-extern int isalpha(int c);
-extern int islower(int c);
-extern int isupper(int c);
-extern int isdigit(int c);
-extern int isxdigit(int c);
-extern int iscntrl(int c);
-extern int isgraph(int c);
-extern int isspace(int c);
-extern int isblank(int c);
-extern int isprint(int c);
-extern int ispunct(int c);
-extern int tolower(int c);
-extern int toupper(int c);
-
-#ifdef __USE_MACROS
-
-#define _U 0x01 /* upper */
-#define _L 0x02 /* lower */
-#define _D 0x04 /* digit */
-#define _C 0x08 /* cntrl */
-#define _P 0x10 /* punct */
-#define _S 0x20 /* white space (space/lf/tab) */
-#define _X 0x40 /* hex char */
-#define _SP 0x80 /* hard space (0x20) */
-
-extern unsigned char __ctype[];
-
-#define isalnum(c) (__ctype[(unsigned char) c] & (_U|_L|_D))
-#define isalpha(c) (__ctype[(unsigned char) c] & (_U|_L))
-#define iscntrl(c) (__ctype[(unsigned char) c] & (_C))
-#define isdigit(c) (__ctype[(unsigned char) c] & (_D))
-#define isgraph(c) (__ctype[(unsigned char) c] & (_P|_U|_L|_D))
-#define islower(c) (__ctype[(unsigned char) c] & (_L))
-#define isprint(c) (__ctype[(unsigned char) c] & (_P|_U|_L|_D|_SP))
-#define ispunct(c) (__ctype[(unsigned char) c] & (_P))
-#define isspace(c) (__ctype[(unsigned char) c] & (_S))
-#define isupper(c) (__ctype[(unsigned char) c] & (_U))
-#define isxdigit(c) (__ctype[(unsigned char) c] & (_D|_X))
-
-#define isascii(c) (((unsigned) c)<=0x7f)
-
-#endif
-
-#endif
--- a/libc/include/errno.h
+++ /dev/null
@@ -1,12 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-#ifndef _ERRNO_H
-#define _ERRNO_H
-
-#define EDOM 1
-#define EILSEQ 2
-#define ERANGE 3
-#define ENOMEN 4
-
-extern int errno;
-
-#endif
--- a/libc/include/limits.h
+++ /dev/null
@@ -1,9 +1,0 @@
-#ifndef _LIMITS_H
-#define _LIMITS_H
-
-#include <arch/limits.h>
-
-#define CHAR_BIT 8
-#define MB_LEN_MAX 1
-
-#endif
--- a/libc/include/locale.h
+++ /dev/null
@@ -1,45 +1,0 @@
-#ifndef _LOCALE_H
-#define _LOCALE_H
-
-#ifndef NULL
-#define NULL ((void *) 0)
-#endif
-
-#define LC_ALL 0
-#define LC_COLLATE 1
-#define LC_CTYPE 2
-#define LC_MONETARY 3
-#define LC_NUMERIC 4
-#define LC_TIME 5
-
-struct lconv {
- char *decimal_point;
- char *thousands_sep;
- char *grouping;
- char *mon_decimal_point;
- char *mon_thousands_sep;
- char *mon_grouping;
- char *positive_sign;
- char *negative_sign;
- char *currency_symbol;
- char *int_curr_symbol;
- char frac_digits;
- char p_cs_precedes;
- char n_cs_precedes;
- char p_sep_by_space;
- char n_sep_by_space;
- char p_sign_posn;
- char n_sign_posn;
- char int_frac_digits;
- char int_p_cs_precedes;
- char int_n_cs_precedes;
- char int_p_sep_by_space;
- char int_n_sep_by_space;
- char int_p_sign_posn;
- char int_n_sign_posn;
-};
-
-extern char *setlocale(int category, const char *locale);
-extern struct lconv *localeconv(void);
-
-#endif
--- a/libc/include/signal.h
+++ /dev/null
@@ -1,10 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-#ifndef _SIGNAL_H
-#define _SIGNAL_H
-
-#include <arch/signal.h>
-
-void ( *signal(int signum, void (*handler)(int)) ) (int);
-int raise(int sig);
-
-#endif
--- a/libc/include/stdarg.h
+++ /dev/null
@@ -1,11 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-#ifndef _STDARG_H
-#define _STDARG_H
-
-#define va_list __builtin_va_list
-#define va_start(ap, last) __builtin_va_start(ap, last)
-#define va_end(ap) __builtin_va_end(ap)
-#define va_copy(to, from) __builtin_va_copy(to, from)
-#define va_arg(to, type) __builtin_va_arg(to, type)
-
-#endif
--- a/libc/include/stdbool.h
+++ /dev/null
@@ -1,10 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-#ifndef _STDBOOL_H
-#define _STDBOOL_H
-
-#define bool _Bool
-#define true ((bool) 1)
-#define false ((bool) 0)
-#define __bool_true_false_are_defined 1
-
-#endif
--- a/libc/include/stddef.h
+++ /dev/null
@@ -1,13 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-#ifndef _STDDEF_H
-#define _STDDEF_H
-
-#include <arch/stddef.h>
-
-#ifndef NULL
-#define NULL ((void *) 0)
-#endif
-
-#define offsetof(st, m) ((size_t)&(((st *)0)->m))
-
-#endif
--- a/libc/include/stdint.h
+++ /dev/null
@@ -1,7 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-#ifndef _STDINT_H_
-#define _STDINT_H_
-
-#include <arch/stdint.h>
-
-#endif
--- a/libc/include/stdio.h
+++ /dev/null
@@ -1,102 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-#ifndef _STDIO_H
-#define _STDIO_H
-
-#include <arch/stdio.h>
-
-#ifndef NULL
-#define NULL ((void *) 0)
-#endif
-
-#define EOF -1
-#define _IOFBF 0
-#define _IOLBF 1
-#define _IONBF 2
-#define SEEK_CUR 0
-#define SEEK_END 1
-#define SEEK_SET 2
-
-typedef struct {
- int fd; /* file descriptor */
- char flags; /* bits for must free buffer on close, line-buffered */
- char state; /* last operation was read, write, position, error, eof */
- char *buf; /* pointer to i/o buffer */
- char *rp; /* read pointer (or write end-of-buffer) */
- char *wp; /* write pointer (or read end-of-buffer) */
- char *lp; /* actual write pointer used when line-buffering */
- size_t len; /* actual length of buffer */
- char unbuf[1]; /* tiny buffer for unbuffered io */
-} FILE;
-
-extern FILE _IO_stream[FOPEN_MAX];
-
-#define stderr (&_IO_stream[2])
-#define stdin (&_IO_stream[0])
-#define stdout (&_IO_stream[1])
-
-extern int remove(const char *filename);
-extern int rename(const char *old, const char *new);
-extern FILE *tmpfile(void);
-extern char *tmpnam(char *s);
-extern int fclose(FILE *fp);
-extern int fflush(FILE *fp);
-extern FILE *fopen(const char * restrict fname, const char * restrict mode);
-extern FILE *freopen(const char * restrict fname, const char * restrict mode,
- FILE * restrict fp);
-extern void setbuf(FILE * restrict fp, char * restrict buf);
-extern int setvbuf(FILE * restrict fp,
- char * restrict buf, int mode, size_t size);
-extern int fprintf(FILE * restrict fp, const char * restrict fmt, ...);
-extern int fscanf(FILE * restrict fp, const char * restrict fmt, ...);
-extern int printf(const char * restrict fmt, ...);
-extern int scanf(const char * restrict fmt, ...);
-extern int snprintf(char * restrict s,
- size_t n, const char * restrict fmt, ...);
-extern int sprintf(char * restrict s, const char * restrict fmt, ...);
-extern int sscanf(const char * restrict s, const char * restrict fmt, ...);
-
-#ifdef _STDARG_H
-extern int vfprintf(FILE * restrict fp,
- const char * restrict fmt, va_list arg);
-extern int vfscanf(FILE * restrict fp,
- const char * restrict fmt, va_list arg);
-extern int vprintf(const char * restrict fmt, va_list arg);
-extern int vscanf(const char * restrict fmt, va_list arg);
-extern int vsnprintf(char * restrict s, size_t n, const char * restrict fmt,
- va_list arg);
-extern int vsprintf(char * restrict s,
- const char * restrict fmt, va_list arg);
-extern int vsscanf(const char * restrict s,
- const char * restrict fmt, va_list arg);
-#endif
-
-extern int fgetc(FILE *fp);
-extern char *fgets(char * restrict s, int n, FILE * restrict fp);
-extern int fputc(int c, FILE *fp);
-extern int fputs(const char * restrict s, FILE * restrict fp);
-extern int getc(FILE *fp);
-extern int getchar(void);
-extern char *gets(char *s);
-extern int putc(int c, FILE *fp);
-extern int putchar(int c);
-extern int puts(const char *s);
-extern int ungetc(int c, FILE *fp);
-extern size_t fread(void * restrict ptr, size_t size, size_t nmemb,
- FILE * restrict fp);
-extern size_t fwrite(const void * restrict ptr, size_t size, size_t nmemb,
- FILE * restrict fp);
-extern int fgetpos(FILE * restrict fp, fpos_t * restrict pos);
-extern int fseek(FILE *fp, long int offset, int whence);
-extern int fsetpos(FILE *fp, const fpos_t *pos);
-extern long int ftell(FILE *fp);
-extern void rewind(FILE *fp);
-extern void clearerr(FILE *fp);
-extern int feof(FILE *fp);
-extern int ferror(FILE *fp);
-extern void perror(const char *s);
-
-#ifdef __USE_MACROS
-#define printf(...) fprintf(stdout, __VA_ARGS__)
-#endif
-
-#endif
--- a/libc/include/stdlib.h
+++ /dev/null
@@ -1,70 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-#ifndef _STDLIB_H
-#define _STDLIB_H
-
-#include <arch/stdlib.h>
-
-#ifndef NULL
-#define NULL ((void *) 0)
-#endif
-
-#define _ATEXIT_MAX 32
-
-#define MB_CUR_MAX 1
-#define RAND_MAX 32767
-
-typedef struct {
- int quot, rem;
-} div_t;
-
-typedef struct {
- long quot, rem;
-} ldiv_t;
-
-typedef struct {
- long long quot, rem;
-} lldiv_t;
-
-extern double atof(const char *nptr);
-extern int atoi(const char *nptr);
-extern long int atol(const char *nptr);
-extern long long int atoll(const char *nptr);
-extern double strtod(const char * restrict nptr, char ** restrict endptr);
-extern float strtof(const char * restrict nptr, char ** restrict endptr);
-extern long double strtold(const char * restrict nptr, char ** restrict endptr);
-extern long int strtol(const char * restrict nptr, char ** restrict endptr, int base);
-extern long long int strtoll(const char * restrict nptr, char ** restrict endptr,
- int base);
-extern unsigned long int strtoul(const char * restrict nptr, char ** restrict endptr,
- int base);
-extern unsigned long long int strtoull(const char * restrict nptr,
- char ** restrict endptr, int base);
-extern int rand(void);
-extern void srand(unsigned int seed);
-extern void *calloc(size_t nmemb, size_t size);
-extern void free(void *ptr);
-extern void *malloc(size_t size);
-extern void *realloc(void *ptr, size_t size);
-extern void abort(void);
-extern int atexit(void (*func)(void));
-extern void exit(int status);
-extern void _Exit(int status);
-extern char *getenv(const char *name);
-extern int system(const char *string);
-extern void *bsearch(const void *key, const void *base, size_t nmemb, size_t size,
- int (*compar)(const void *, const void *));
-extern void qsort(void *base, size_t nmemb, size_t size,
- int (*compar)(const void *, const void *));
-extern int abs(int j);
-extern long int labs(long int j);
-extern long long int llabs(long long int j);
-extern div_t div(int numer, int denom);
-extern ldiv_t ldiv(long int numer, long int denom);
-extern lldiv_t lldiv(long long int numer, long long int denom);
-extern int mblen(const char *s, size_t n);
-extern int mbtowc(wchar_t * restrict pwc, const char * restrict s, size_t n);
-extern int wctomb(char *s, wchar_t wchar);
-extern size_t mbstowcs(wchar_t * restrict pwcs, const char * restrict s, size_t n);
-extern size_t wcstombs(char * restrict s, const wchar_t * restrict pwcs, size_t n);
-
-#endif
--- a/libc/include/string.h
+++ /dev/null
@@ -1,34 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-#ifndef _STRING_H
-#define _STRING_H
-
-#include <arch/string.h>
-
-#ifndef NULL
-#define NULL ((void *) 0)
-#endif
-
-extern void *memcpy(void * restrict s1, const void * restrict s2, size_t n);
-extern void *memmove(void *s1, const void *s2, size_t n);
-extern char *strcpy(char * restrict s1, const char * restrict s2);
-extern char *strncpy(char * restrict s1, const char * restrict s2, size_t n);
-extern char *strcat(char * restrict s1, const char * restrict s2);
-extern char *strncat(char * restrict s1, const char * restrict s2, size_t n);
-extern int memcmp(const void *s1, const void *s2, size_t n);
-extern int strcmp(const char *s1, const char *s2);
-extern int strcoll(const char *s1, const char *s2);
-extern int strncmp(const char *s1, const char *s2, size_t n);
-extern size_t strxfrm(char * restrict s1, const char * restrict s2, size_t n);
-extern void *memchr(const void *s, int c, size_t n);
-extern char *strchr(const char *s, int c);
-extern size_t strcspn(const char *s1, const char *s2);
-extern char *strpbrk(const char *s1, const char *s2);
-extern char *strrchr(const char *s, int c);
-extern size_t strspn(const char *s1, const char *s2);
-extern char *strstr(const char *s1, const char *s2);
-extern char *strtok(char * restrict s1, const char * restrict s2);
-extern void *memset(void *s, int c, size_t n);
-extern char *strerror(int errnum);
-extern size_t strlen(const char *s);
-
-#endif
--- a/libc/include/time.h
+++ /dev/null
@@ -1,38 +1,0 @@
-#ifndef _TIME_H
-#define _TIME_H
-
-#include <arch/time.h>
-
-#ifndef NULL
-#define NULL ((void *) 0)
-#endif
-
-#define CLOCKS_PER_SEC 1000000
-
-typedef long int clock_t;
-
-struct tm {
- int tm_sec;
- int tm_min;
- int tm_hour;
- int tm_mday;
- int tm_mon;
- int tm_year;
- int tm_wday;
- int tm_yday;
- int tm_isdst;
-};
-
-extern clock_t clock(void);
-extern double difftime(time_t time1, time_t time0);
-extern time_t mktime(struct tm *timeptr);
-extern time_t time(time_t *timer);
-extern char *asctime(const struct tm *timeptr);
-extern char *ctime(const time_t *timer);
-extern struct tm *gmtime(const time_t *timer);
-extern struct tm *localtime(const time_t *timer);
-extern size_t strftime(char * restrict s, size_t maxsize,
- const char * restrict format,
- const struct tm * restrict timeptr);
-
-#endif
--- a/libc/src/Makefile
+++ /dev/null
@@ -1,44 +1,0 @@
-# See LICENSE file for copyright and license details.
-.POSIX:
-
-include ../../config.mk
-
-SYSDIR = sys/$(ARCH)-$(SYS)
-SYSINC = $(SYSDIR)/system.mk
-
-SYSINCLUDE = /dev/null
-include $(SYSINCLUDE)
-
-LIBCOBJ = assert.o strcpy.o strcmp.o strlen.o strchr.o \
- strrchr.o strcat.o strncmp.o strncpy.o strncat.o strcoll.o \
- strxfrm.o strstr.o strspn.o strcspn.o strpbrk.o strtok.o \
- memset.o memcpy.o memmove.o memcmp.o memchr.o \
- isalnum.o isalpha.o isascii.o isblank.o iscntrl.o isdigit.o \
- isgraph.o islower.o isprint.o ispunct.o isspace.o isupper.o \
- isxdigit.o toupper.o tolower.o ctype.o setlocale.o \
- localeconv.o atoi.o atexit.o exit.o \
- printf.o fprintf.o vfprintf.o \
- realloc.o calloc.o malloc.o
-LIBCSYSOBJ = $(SYSOBJ:%=$(SYSDIR)/%)
-OBJ = $(LIBCOBJ) $(LIBCSYSOBJ)
-
-all: all.bootstrap
-all.start: libc.a
-
-clean: clean.bootstrap
-clean.start:
- rm -f *.o libc.a
- cd $(SYSDIR) && $(MAKE) clean
-
-all.bootstrap clean.bootstrap: $(SYSINC)
- $(MAKE) -e SYSINCLUDE="$(SYSINC)" $(@:%.bootstrap=%.start)
-
-$(SYSINC): $(SYSDIR)/Makefile $(SYSDIR)/syscall.lst
- cd $(SYSDIR) && $(MAKE) -e system.mk
-
-libc.a: $(SYSINC) $(OBJ)
- $(AR) $(ARFLAGS) $@ $(OBJ)
- ranlib $@
-
-$(LIBCSYSOBJ):
- cd $(SYSDIR) && $(MAKE)
--- a/libc/src/assert.c
+++ /dev/null
@@ -1,11 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#include <assert.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-void __assert(char *exp, char *file, long line)
-{
- fprintf(stderr, "%s:%ld: assertion failed '%s'\n", file, line, exp);
- abort();
-}
--- a/libc/src/atexit.c
+++ /dev/null
@@ -1,19 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#include <stdlib.h>
-#include <errno.h>
-#undef atexit
-
-extern void (*_exitf[_ATEXIT_MAX])(void);
-extern unsigned _exitn;
-
-int
-atexit(void (*fun)(void))
-{
- if (_exitn == _ATEXIT_MAX) {
- errno = ENOMEN;
- return -1;
- }
- _exitf[_exitn++] = fun;
- return 0;
-}
--- a/libc/src/atoi.c
+++ /dev/null
@@ -1,28 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#include <ctype.h>
-#include <stdlib.h>
-#undef atoi
-
-int
-atoi(const char *s)
-{
- int n, sign = -1;
-
- while(isspace(*s))
- ++s;
-
- switch(*s) {
- case '-':
- sign = 1;
- case '+':
- ++s;
- }
-
- /* Compute n as a negative number to avoid overflow on INT_MIN */
- for (n = 0; isdigit(*s); ++s)
- n = 10*n - (*s - '0');
-
- return sign * n;
-}
-
--- a/libc/src/calloc.c
+++ /dev/null
@@ -1,19 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#include <stdlib.h>
-#include <string.h>
-
-void *
-calloc(size_t nmemb, size_t size)
-{
- size_t nbytes;
- void *mem;
-
- if (!nmemb || !size || nmemb > (size_t)-1/size)
- return NULL;
-
- nbytes = nmemb * size;
- if ((mem = malloc(nbytes)) == NULL)
- return NULL;
- return memset(mem, 0, nbytes);
-}
--- a/libc/src/ctype.c
+++ /dev/null
@@ -1,24 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#define __USE_MACROS
-#include <ctype.h>
-#undef ctype
-
-unsigned char __ctype[255] = {
- _C,_C,_C,_C,_C,_C,_C,_C, /* 0-7 */
- _C,_C|_S,_C|_S,_C|_S,_C|_S,_C|_S,_C,_C, /* 8-15 */
- _C,_C,_C,_C,_C,_C,_C,_C, /* 16-23 */
- _C,_C,_C,_C,_C,_C,_C,_C, /* 24-31 */
- _S|_SP,_P,_P,_P,_P,_P,_P,_P, /* 32-39 */
- _P,_P,_P,_P,_P,_P,_P,_P, /* 40-47 */
- _D,_D,_D,_D,_D,_D,_D,_D, /* 48-55 */
- _D,_D,_P,_P,_P,_P,_P,_P, /* 56-63 */
- _P,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U, /* 64-71 */
- _U,_U,_U,_U,_U,_U,_U,_U, /* 72-79 */
- _U,_U,_U,_U,_U,_U,_U,_U, /* 80-87 */
- _U,_U,_U,_P,_P,_P,_P,_P, /* 88-95 */
- _P,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L, /* 96-103 */
- _L,_L,_L,_L,_L,_L,_L,_L, /* 104-111 */
- _L,_L,_L,_L,_L,_L,_L,_L, /* 112-119 */
- _L,_L,_L,_P,_P,_P,_P,_C, /* 120-127 */
-};
--- a/libc/src/exit.c
+++ /dev/null
@@ -1,15 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#include <stdlib.h>
-#undef exit
-
-void (*_exitf[_ATEXIT_MAX])(void);
-unsigned _exitn;
-
-void
-exit(int status)
-{
- while (_exitn > 0)
- (*_exitf[--_exitn])();
- _Exit(status);
-}
--- a/libc/src/fprintf.c
+++ /dev/null
@@ -1,17 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#include <stdarg.h>
-#include <stdio.h>
-#undef fprintf
-
-int
-fprintf(FILE * restrict fp, const char * restrict fmt, ...)
-{
- va_list va;
- int cnt;
-
- va_start(va, fmt);
- cnt = vfprintf(fp, fmt, va);
- va_end(va);
- return cnt;
-}
--- a/libc/src/isalnum.c
+++ /dev/null
@@ -1,11 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#define __USE_MACROS
-#include <ctype.h>
-#undef isalnum
-
-int
-isalnum(int c)
-{
- return __ctype[(unsigned char) c] & (_U|_L|_D);
-}
--- a/libc/src/isalpha.c
+++ /dev/null
@@ -1,11 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#define __USE_MACROS
-#include <ctype.h>
-#undef isalpha
-
-int
-isalpha(int c)
-{
- return __ctype[(unsigned char) c] & (_U|_L);
-}
--- a/libc/src/isascii.c
+++ /dev/null
@@ -1,11 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#define __USE_MACROS
-#include <ctype.h>
-#undef isascii
-
-int
-isascii(int c)
-{
- return c <= 0x7f;
-}
--- a/libc/src/isblank.c
+++ /dev/null
@@ -1,7 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-int
-isblank(int c)
-{
- return (c == ' ') || (c == '\t');
-}
--- a/libc/src/iscntrl.c
+++ /dev/null
@@ -1,11 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#define __USE_MACROS
-#include <ctype.h>
-#undef iscntrl
-
-int
-iscntrl(int c)
-{
- return __ctype[(unsigned char) c] & (_C);
-}
--- a/libc/src/isdigit.c
+++ /dev/null
@@ -1,11 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#define __USE_MACROS
-#include <ctype.h>
-#undef isdigit
-
-int
-isdigit(int c)
-{
- return __ctype[(unsigned char) c] & (_D);
-}
--- a/libc/src/isgraph.c
+++ /dev/null
@@ -1,11 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#define __USE_MACROS
-#include <ctype.h>
-#undef isgraph
-
-int
-isgraph(int c)
-{
- return __ctype[(unsigned char) c] & (_P|_U|_L|_D);
-}
--- a/libc/src/islower.c
+++ /dev/null
@@ -1,11 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#define __USE_MACROS
-#include <ctype.h>
-#undef islower
-
-int
-islower(int c)
-{
- return __ctype[(unsigned char) c] & _L;
-}
--- a/libc/src/isprint.c
+++ /dev/null
@@ -1,11 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#define __USE_MACROS
-#include <ctype.h>
-#undef isprint
-
-int
-isprint(int c)
-{
- return __ctype[(unsigned char) c] & (_P|_U|_L|_D|_SP);
-}
--- a/libc/src/ispunct.c
+++ /dev/null
@@ -1,11 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#define __USE_MACROS
-#include <ctype.h>
-#undef ispunct
-
-int
-ispunct(int c)
-{
- return __ctype[(unsigned char) c] & (_P);
-}
--- a/libc/src/isspace.c
+++ /dev/null
@@ -1,11 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#define __USE_MACROS
-#include <ctype.h>
-#undef isspace
-
-int
-isspace(int c)
-{
- return __ctype[(unsigned char) c] & _S;
-}
--- a/libc/src/isupper.c
+++ /dev/null
@@ -1,11 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#define __USE_MACROS
-#include <ctype.h>
-#undef isupper
-
-int
-isupper(int c)
-{
- return __ctype[(unsigned char) c] & _U;
-}
--- a/libc/src/isxdigit.c
+++ /dev/null
@@ -1,11 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#define __USE_MACROS
-#include <ctype.h>
-#undef isxdigit
-
-int
-isxdigit(int c)
-{
- return __ctype[(unsigned char) c] & (_D|_X);
-}
--- a/libc/src/localeconv.c
+++ /dev/null
@@ -1,14 +1,0 @@
-#include <locale.h>
-#include <limits.h>
-#undef localeconv
-
-struct lconv *
-localeconv(void)
-{
- static struct lconv lc = { ".", "", "", "", "", "", "", "", "", "",
- CHAR_MAX, CHAR_MAX, CHAR_MAX, CHAR_MAX,
- CHAR_MAX, CHAR_MAX, CHAR_MAX, CHAR_MAX,
- CHAR_MAX, CHAR_MAX, CHAR_MAX, CHAR_MAX,
- CHAR_MAX, CHAR_MAX };
- return &lc;
-}
--- a/libc/src/malloc.c
+++ /dev/null
@@ -1,154 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "malloc.h"
-#include "syscall.h"
-
-#define MAXADDR ((char *)-1)
-#define ERRADDR ((char *)-1)
-
-extern char end[];
-static Header base = { .h.next = &base };
-static Header *freep = &base;
-static char *heap = end;
-
-/*
- * Run over the free list looking for the nearest previous
- * block. There are two possible results: end of the list
- * or an intermediary block.
- */
-void *
-_prevchunk(Header *hp)
-{
- Header *p;
-
- for (p = freep; ;p = p->h.next) {
- /* hp between p and p->h.next? */
- if (p < hp && hp < p->h.next)
- break;
- /* p before hp and hp at the end of list? */
- if (p->h.next <= p && (hp < p->h.next || hp > p))
- break;
- }
- return p;
-}
-
-/*
- * Get the previous block and try to merge
- * with next and previous blocks
- */
-void
-free(void *mem)
-{
- Header *hp, *prev;
-
- if (!mem)
- return;
-
- hp = (Header *) mem - 1;
- prev = _prevchunk(hp);
-
- /* join to next */
- if (hp + hp->h.size == prev->h.next) {
- hp->h.size += prev->h.next->h.size;
- hp->h.next = prev->h.next->h.next;
- } else {
- hp->h.next = prev->h.next;
- }
-
- /* join to previous */
- if (prev + prev->h.size == hp) {
- prev->h.size += hp->h.size;
- prev->h.next = hp->h.next;
- } else {
- prev->h.next = hp;
- }
-
- freep = prev;
-}
-
-static void *
-sbrk(uintptr_t inc)
-{
- char *new, *old = heap;
-
- if (old >= MAXADDR - inc)
- return ERRADDR;
-
- new = old + inc;
- if (_brk(new) < 0)
- return ERRADDR;
- heap = new;
-
- return old;
-}
-
-static Header *
-morecore(size_t nunits)
-{
- char *rawmem;
- Header *hp;
-
- if (nunits < NALLOC)
- nunits = NALLOC;
-
- rawmem = sbrk(nunits * sizeof(Header));
- if (rawmem == ERRADDR)
- return NULL;
-
- hp = (Header*)rawmem;
- hp->h.size = nunits;
-
- /* integrate new memory into the list */
- free(hp + 1);
-
- return freep;
-}
-
-/*
- * Run over the list of free blocks trying to find a block
- * big enough for nbytes. If the block fit perfectly with
- * the required size then we only have to unlink
- * the block. Otherwise we have to split the block and
- * return the right part. If we run over the full list
- * without a fit then we have to require more memory
- *
- * ______________________________________
- * ___________./______________________________________\_____
- * ...| in | | | in | |.....| in | | | |....
- * ...| use | | | use | |.....| use | | | |....
- * ___|______|___|.____|_____|._|_____|______|._|.___|.|____
- * \__/ \_________/ \_____________/ \/ \__/
- */
-void *
-malloc(size_t nbytes)
-{
- Header *cur, *prev;
- size_t nunits;
-
- /* 1 unit for header plus enough units to fit nbytes */
- nunits = (nbytes+sizeof(Header)-1) / sizeof(Header) + 1;
-
- for (prev = freep; ; prev = cur) {
- cur = prev->h.next;
- if (cur->h.size >= nunits) {
- if (cur->h.size == nunits) {
- prev->h.next = cur->h.next;
- } else {
- cur->h.size -= nunits;
- cur += cur->h.size;
- cur->h.size = nunits;
- }
- freep = prev;
- return cur + 1;
- }
-
- if (cur == freep) {
- if ((cur = morecore(nunits)) == NULL)
- return NULL;
- }
- }
-}
--- a/libc/src/malloc.h
+++ /dev/null
@@ -1,18 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#include <stdlib.h>
-
-/* minimum amount of required units */
-#define NALLOC 10000
-
-typedef union header Header;
-union header {
- struct hdr {
- Header *next;
- size_t size;
- } h;
- /* most restrictive type fixes the union size for alignment */
- _ALIGNTYPE most;
-};
-
-extern void *_prevchunk(Header *hp);
--- a/libc/src/memchr.c
+++ /dev/null
@@ -1,14 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#include <string.h>
-#undef memchr
-
-void *
-memchr(const void *s, int c, size_t n)
-{
- unsigned char *bp = (char *) s;
-
- while (n > 0 && *bp++ != c)
- --n;
- return (n == 0) ? NULL : bp-1;
-}
--- a/libc/src/memcmp.c
+++ /dev/null
@@ -1,14 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#include <string.h>
-#undef memcmp
-
-int
-memcmp(const void *s1, const void *s2, size_t n)
-{
- char *s = (char *) s1, *t = (char *) s2;
-
- while (n > 0 && *s == *t)
- --n, ++s, ++t;
- return n ? (*s - *t) : 0;
-}
--- a/libc/src/memcpy.c
+++ /dev/null
@@ -1,15 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#include <string.h>
-#undef memcpy
-
-void *
-memcpy(void * restrict dst, const void * restrict src, size_t n)
-{
- char *s1 = dst;
- const char *s2 = src;
-
- while (n-- > 0)
- *s1++ = *s2++;
- return dst;
-}
--- a/libc/src/memmove.c
+++ /dev/null
@@ -1,20 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#include <string.h>
-#undef memmove
-
-void *
-memmove(void *dst, const void *src, size_t n)
-{
- char *d = dst, *s = (char *) src;
-
- if (d < s) {
- while (n-- > 0)
- *d++ = *s++;
- } else {
- s += n-1, d += n-1;
- while (n-- > 0)
- *d-- = *s--;
- }
- return dst;
-}
--- a/libc/src/memset.c
+++ /dev/null
@@ -1,14 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#include <string.h>
-#undef memset
-
-void *
-memset(void *s, int c, size_t n)
-{
- char *m = s;
-
- while (n-- > 0)
- *m++ = c;
- return s;
-}
--- a/libc/src/printf.c
+++ /dev/null
@@ -1,17 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#include <stdarg.h>
-#include <stdio.h>
-#undef printf
-
-int
-printf(const char * restrict fmt, ...)
-{
- int cnt;
- va_list va;
-
- va_start(va, fmt);
- cnt = vfprintf(stdin, fmt, va);
- va_end(va);
- return cnt;
-}
--- a/libc/src/rand.c
+++ /dev/null
@@ -1,19 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#include <stdlib.h>
-#undef rand
-
-static int next;
-
-void
-srand(unsigned seed)
-{
- next = seed;
-}
-
-int
-rand(void) /* RAND_MAX assumed to be 32767. */
-{
- next = next * 1103515245 + 12345;
- return (unsigned)(next/65536) % 32768;
-}
--- a/libc/src/realloc.c
+++ /dev/null
@@ -1,69 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "malloc.h"
-
-void *
-realloc(void *ptr, size_t nbytes)
-{
- Header *oh, *prev, *next, *new;
- size_t nunits, avail, onbytes, n;
-
- if (!nbytes)
- return NULL;
-
- if (!ptr)
- return malloc(nbytes);
-
- nunits = (nbytes + sizeof(Header) - 1) / sizeof(Header) + 1;
- oh = (Header*)ptr - 1;
-
- if (oh->h.size == nunits)
- return ptr;
-
- new = oh + nunits;
-
- if (nunits < oh->h.size - 1) {
- new->h.size = oh->h.size - nunits;
- oh->h.size = nunits;
- free(new + 1);
- return oh;
- }
-
- prev = _prevchunk(oh);
-
- if (oh + oh->h.size == prev->h.next) {
- /*
- * if there is free space adjacent
- * to the current memory
- */
- next = prev->h.next;
- avail = oh->h.size + next->h.size;
-
- if (avail == nunits) {
- oh->h.size = nunits;
- prev->h.next = next->h.next;
- return oh;
- }
-
- if (avail > nunits) {
- oh->h.size = nunits;
- prev->h.next = new;
- new->h.next = next;
- new->h.size = avail - nunits;
- return oh;
- }
- }
-
- onbytes = (oh->h.size - 1) * sizeof(Header);
- if ((new = malloc(nbytes)) == NULL)
- return NULL;
-
- n = (onbytes > nbytes) ? nbytes : onbytes;
- memcpy(new, ptr, n);
- free(ptr);
-
- return new;
-}
--- a/libc/src/setlocale.c
+++ /dev/null
@@ -1,18 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#include <locale.h>
-#include <stddef.h>
-#undef setlocale
-
-char *
-setlocale(int category, const char *locale)
-{
- if (category > LC_TIME || category < LC_ALL)
- return NULL;
- if (!locale ||
- locale[0] == '\0' ||
- locale[0] == 'C' && locale[1] == '\0') {
- return "C";
- }
- return NULL;
-}
--- a/libc/src/strcat.c
+++ /dev/null
@@ -1,16 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#include <string.h>
-#undef strcat
-
-char *
-strcat(char * restrict dst, const char * restrict src)
-{
- char *ret = dst;
-
- while (*dst)
- ++dst;
- while (*dst++ = *src++)
- /* nothing */;
- return ret;
-}
--- a/libc/src/strchr.c
+++ /dev/null
@@ -1,12 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#include <string.h>
-#undef strchr
-
-char *
-strchr(const char *s, int c)
-{
- while (*s && *s != c)
- ++s;
- return (*s == c) ? (char *)s : NULL;
-}
--- a/libc/src/strcmp.c
+++ /dev/null
@@ -1,12 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#include <string.h>
-#undef strcmp
-
-int
-strcmp(const char *s1, const char *s2)
-{
- while (*s1 && *s2 && *s1 == *s2)
- ++s1, ++s2;
- return *(unsigned char *)s1 - *(unsigned char *)s2;
-}
--- a/libc/src/strcoll.c
+++ /dev/null
@@ -1,12 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#include <string.h>
-#undef strcoll
-
-int
-strcoll(const char *s1, const char *s2)
-{
- while (*s1 && *s2 && *s1 == *s2)
- ++s1, ++s2;
- return *(unsigned char *) s1 - *(unsigned char *) s2;
-}
--- a/libc/src/strcpy.c
+++ /dev/null
@@ -1,14 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#include <string.h>
-#undef strcpy
-
-char *
-strcpy(char * restrict dst, const char * restrict src)
-{
- char *ret = dst;
-
- while (*dst++ = *src++)
- /* nothing */;
- return ret;
-}
--- a/libc/src/strcspn.c
+++ /dev/null
@@ -1,20 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#include <string.h>
-#undef strcspn
-
-size_t
-strcspn(const char *s1, const char *s2)
-{
- size_t n;
- int c;
- const char *p;
-
- for (n = 0; c = *s1++; ++n) {
- for (p = s2; *p && *p != c; ++p)
- /* nothing */;
- if (*p == c)
- break;
- }
- return n;
-}
--- a/libc/src/strlen.c
+++ /dev/null
@@ -1,14 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#include <string.h>
-#undef strlen
-
-size_t
-strlen(const char *s)
-{
- const char *t;
-
- for (t = s; *t; ++t)
- /* nothing */;
- return t - s;
-}
--- a/libc/src/strncat.c
+++ /dev/null
@@ -1,17 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#include <string.h>
-#undef strncat
-
-char *
-strncat(char * restrict dst, const char * restrict src, size_t n)
-{
- char *ret = dst;
-
- while (*dst)
- ++dst;
- while (n-- > 0 && *src)
- *dst++ = *src++;
- *dst = '\0';
- return ret;
-}
--- a/libc/src/strncmp.c
+++ /dev/null
@@ -1,12 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#include <string.h>
-#undef strncmp
-
-int
-strncmp(const char *s1, const char *s2, size_t n)
-{
- for (; n && *s1 && *s2 && *s1 == *s2; --n, ++s1, ++s2);
- /* nothing */;
- return n ? (*(unsigned char *)s1 - *(unsigned char *)s2) : 0;
-}
--- a/libc/src/strncpy.c
+++ /dev/null
@@ -1,16 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#include <string.h>
-#undef strncpy
-
-char *
-strncpy(char * restrict dst, const char * restrict src, size_t n)
-{
- char *ret = dst;
-
- for (; n > 0 && *src; --n)
- *dst++ = *src++;
- while (n-- > 0)
- *dst++ = '\0';
- return ret;
-}
--- a/libc/src/strpbrk.c
+++ /dev/null
@@ -1,19 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#include <string.h>
-#undef strpbrk
-
-char *
-strpbrk(const char *s1, const char *s2)
-{
- int c;
- const char *p;
-
- for (; c = *s1; ++s1) {
- for (p = s2; *p && *p != c; ++p)
- /* nothing */;
- if (*p == c)
- return s1;
- }
- return NULL;
-}
--- a/libc/src/strrchr.c
+++ /dev/null
@@ -1,16 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#include <string.h>
-#undef strrchr
-
-char *
-strrchr(const char *s, int c)
-{
- const char *t = s;
-
- while (*t)
- ++t;
- while (t > s && *t != c)
- --t;
- return (*t == c) ? (char *)t : NULL;
-}
--- a/libc/src/strspn.c
+++ /dev/null
@@ -1,20 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#include <string.h>
-#undef strspn
-
-size_t
-strspn(const char *s1, const char *s2)
-{
- size_t n;
- int c;
- const char *p;
-
- for (n = 0; c = *s1++; ++n) {
- for (p = s2; *p && *p != c; ++p)
- /* nothing */;
- if (*p == '\0')
- break;
- }
- return n;
-}
--- a/libc/src/strstr.c
+++ /dev/null
@@ -1,28 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#include <string.h>
-#undef strstr
-
-char *
-strstr(const char *s1, const char *s2)
-{
- const char *p, *q;
- int c;
-
- c = *s2++;
- if (c == '\0')
- return (char *) s1;
-
- while (*s1) {
- if (*s1 != c) {
- ++s1;
- } else {
- p = s1++;
- for (q = s2; *q && *s1 == *q; ++s1, ++q)
- /* nothing */;
- if (*q == '\0')
- return (char *) p;
- }
- }
- return NULL;
-}
--- a/libc/src/strtok.c
+++ /dev/null
@@ -1,27 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#include <string.h>
-#undef strtok
-
-char *
-strtok(char * restrict s, const char * restrict delim)
-{
- static char *line;
-
- if (s)
- line = s;
- if (!s && !line)
- return NULL;
-
- s = line + strspn(line, delim);
- if (*s == '\0')
- return line = NULL;
-
- line = s + strcspn(s, delim);
- if (*line != '\0')
- *line++ = '\0';
- else
- line = NULL;
-
- return s;
-}
--- a/libc/src/strxfrm.c
+++ /dev/null
@@ -1,14 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#include <string.h>
-#undef strxfrm
-
-size_t
-strxfrm(char * restrict dst, const char * restrict src, size_t n)
-{
- size_t len = strlen(src);
-
- if (len < n)
- strcpy(dst, src);
- return len;
-}
--- a/libc/src/sys/amd64-sysv-linux/Makefile
+++ /dev/null
@@ -1,37 +1,0 @@
-# See LICENSE file for copyright and license details.
-.POSIX:
-
-include ../../../../config.mk
-
-SYSTEMINC = /dev/null
-include $(SYSTEMINC)
-SYSGENINC = /dev/null
-include $(SYSGENINC)
-
-GENASM = $(GENOBJ:.o=.s)
-OBJ =
-
-all: all.bootstrap
-all.start: $(SYSOBJ)
-
-clean: clean.bootstrap
-clean.start:
- rm -f *.o $(GENASM) system.mk sysgen.mk
-
-all.bootstrap clean.bootstrap: system.mk sysgen.mk
- $(MAKE) -e SYSTEMINC=system.mk SYSGENINC=sysgen.mk \
- $(@:%.bootstrap=%.start)
-
-system.mk: Makefile syscall.lst
- printf '%s ' 'SYSOBJ =' \
- "$$(awk '/^#/{next}{printf "%s.o ", $$2}' syscall.lst)" \
- $(OBJ) \
- > $@
-
-sysgen.mk: syscall.lst
- printf '%s ' 'GENOBJ =' \
- "$$(awk '/^#/{next}{printf "%s.o ", $$2}' syscall.lst)" \
- > $@
-
-$(GENASM): syscall.lst
- awk -f syscall.awk < syscall.lst
--- a/libc/src/sys/amd64-sysv-linux/syscall.awk
+++ /dev/null
@@ -1,12 +1,0 @@
-# This job is very easy because app and kernel ABI are identical
-# until the 4th parameter, so we only have to set the syscall
-# number in rax
-
-/^#/ {next}
- {name=$2 ".s"
- printf ".global %s\n" \
- "%s:\n" \
- "\tmovq\t$%d,%%rax\n" \
- "\tsyscall\n" \
- "\tret\n", $2, $2, $1 > name
- close(name)}
--- a/libc/src/sys/amd64-sysv-linux/syscall.lst
+++ /dev/null
@@ -1,11 +1,0 @@
-#number name
-0 _read
-1 _write
-2 _open
-3 _close
-3 _lseek
-12 _brk
-13 _rt_sigaction
-38 _getpid
-60 _Exit
-32 _kill
--- a/libc/src/sys/i386-sysv-linux/Makefile
+++ /dev/null
@@ -1,37 +1,0 @@
-# See LICENSE file for copyright and license details.
-.POSIX:
-
-include ../../../../config.mk
-
-SYSTEMINC = /dev/null
-include $(SYSTEMINC)
-SYSGENINC = /dev/null
-include $(SYSGENINC)
-
-GENASM = $(GENOBJ:.o=.s)
-OBJ =
-
-all: all.bootstrap
-all.start: $(SYSOBJ)
-
-clean: clean.bootstrap
-clean.start:
- rm -f *.o $(GENASM) system.mk sysgen.mk
-
-all.bootstrap clean.bootstrap: system.mk sysgen.mk
- $(MAKE) -e SYSTEMINC=system.mk SYSGENINC=sysgen.mk \
- $(@:%.bootstrap=%.start)
-
-system.mk: Makefile syscall.lst
- printf '%s ' 'SYSOBJ =' \
- "$$(awk '/^#/{next}{printf "%s.o ", $$2}' syscall.lst)" \
- $(OBJ) \
- > $@
-
-sysgen.mk: syscall.lst
- printf '%s ' 'GENOBJ =' \
- "$$(awk '/^#/{next}{printf "%s.o ", $$2}' syscall.lst)" \
- > $@
-
-$(GENASM): syscall.lst
- awk -f syscall.awk < syscall.lst
--- a/libc/src/sys/qbe-linux/Makefile
+++ /dev/null
@@ -1,37 +1,0 @@
-# See LICENSE file for copyright and license details.
-.POSIX:
-
-include ../../../../config.mk
-
-SYSTEMINC = /dev/null
-include $(SYSTEMINC)
-SYSGENINC = /dev/null
-include $(SYSGENINC)
-
-GENASM = $(GENOBJ:.o=.s)
-OBJ =
-
-all: all.bootstrap
-all.start: $(SYSOBJ)
-
-clean: clean.bootstrap
-clean.start:
- rm -f *.o $(GENASM) system.mk sysgen.mk
-
-all.bootstrap clean.bootstrap: system.mk sysgen.mk
- $(MAKE) -e SYSTEMINC=system.mk SYSGENINC=sysgen.mk \
- $(@:%.bootstrap=%.start)
-
-system.mk: Makefile syscall.lst
- printf '%s ' 'SYSOBJ =' \
- "$$(awk '/^#/{next}{printf "%s.o ", $$2}' syscall.lst)" \
- $(OBJ) \
- > $@
-
-sysgen.mk: syscall.lst
- printf '%s ' 'GENOBJ =' \
- "$$(awk '/^#/{next}{printf "%s.o ", $$2}' syscall.lst)" \
- > $@
-
-$(GENASM): syscall.lst
- awk -f syscall.awk < syscall.lst
--- a/libc/src/sys/qbe-linux/syscall.awk
+++ /dev/null
@@ -1,12 +1,0 @@
-# This job is very easy because app and kernel ABI are identical
-# until the 4th parameter, so we only have to set the syscall
-# number in rax
-
-/^#/ {next}
- {name=$2 ".s"
- printf ".global %s\n" \
- "%s:\n" \
- "\tmovq\t$%d,%%rax\n" \
- "\tsyscall\n" \
- "\tret\n", $2, $2, $1 > name
- close(name)}
--- a/libc/src/sys/qbe-linux/syscall.lst
+++ /dev/null
@@ -1,11 +1,0 @@
-#number name
-0 _read
-1 _write
-2 _open
-3 _close
-3 _lseek
-12 _brk
-13 _rt_sigaction
-38 _getpid
-60 _Exit
-32 _kill
--- a/libc/src/sys/z80-linux/Makefile
+++ /dev/null
@@ -1,37 +1,0 @@
-# See LICENSE file for copyright and license details.
-.POSIX:
-
-include ../../../../config.mk
-
-SYSTEMINC = /dev/null
-include $(SYSTEMINC)
-SYSGENINC = /dev/null
-include $(SYSGENINC)
-
-GENASM = $(GENOBJ:.o=.s)
-OBJ =
-
-all: all.bootstrap
-all.start: $(SYSOBJ)
-
-clean: clean.bootstrap
-clean.start:
- rm -f *.o $(GENASM) system.mk sysgen.mk
-
-all.bootstrap clean.bootstrap: system.mk sysgen.mk
- $(MAKE) -e SYSTEMINC=system.mk SYSGENINC=sysgen.mk \
- $(@:%.bootstrap=%.start)
-
-system.mk: Makefile syscall.lst
- printf '%s ' 'SYSOBJ =' \
- "$$(awk '/^#/{next}{printf "%s.o ", $$2}' syscall.lst)" \
- $(OBJ) \
- > $@
-
-sysgen.mk: syscall.lst
- printf '%s ' 'GENOBJ =' \
- "$$(awk '/^#/{next}{printf "%s.o ", $$2}' syscall.lst)" \
- > $@
-
-$(GENASM): syscall.lst
- awk -f syscall.awk < syscall.lst
--- a/libc/src/syscall.h
+++ /dev/null
@@ -1,11 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-extern void *_brk(void *addr);
-extern int _open(char *path, int flags, int perm);
-extern int _close(int fd);
-extern int _read(int fd, void *buf, size_t n);
-extern int _write(int fd, void *buf, size_t n);
-extern int _lseek(int fd, long off, int whence);
-extern void _Exit(int status);
-extern int raise(int sig);
-extern void (*signal(int sig, void (*func)(int)))(int);
--- a/libc/src/tolower.c
+++ /dev/null
@@ -1,11 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#define __USE_MACROS
-#include <ctype.h>
-#undef tolower
-
-int
-tolower(int c)
-{
- return (isupper(c)) ? c | 0x20 : c;
-}
--- a/libc/src/toupper.c
+++ /dev/null
@@ -1,11 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#define __USE_MACROS
-#include <ctype.h>
-#undef toupper
-
-int
-toupper(int c)
-{
- return (islower(c)) ? c & ~0x20 : c;
-}
--- a/libc/src/vfprintf.c
+++ /dev/null
@@ -1,76 +1,0 @@
-/* See LICENSE file for copyright and license details. */
-
-#include <stdarg.h>
-#include <stdio.h>
-#undef vfprintf
-
-static int
-printn2(FILE * restrict fp, unsigned n, int base)
-{
- unsigned t;
- int cnt = 0;
- static char digits[] = "0123456789ABCDEF";
-
- if ((t = n / base) != 0)
- cnt += printn2(fp, t, base);
- putc(digits[n % base], fp);
- return cnt + 1;
-}
-
-static int
-printn(FILE * restrict fp, int n, int b, int sign)
-{
- int cnt = 0;
-
- if (sign && n < 0) {
- n = -n;
- putc('-', fp);
- ++cnt;
- }
- cnt += printn2(fp, n, b);
- return cnt;
-}
-
-int
-vfprintf(FILE * restrict fp, const char *fmt, va_list va)
-{
- int c, base, sign, cnt = 0;
- char *s;
-
- while ((c = *fmt++) != '\0') {
- if (c == '%') {
- sign = 0;
- switch (*fmt++) {
- case '%':
- c = '%';
- break;
- case 'c':
- c = va_arg(va, int);
- break;
- case 'o':
- base = 8;
- goto numeric;
- case 'd':
- sign = 1;
- base = 10;
- goto numeric;
- case 'x':
- base = 16;
- numeric:
- c = va_arg(va, int);
- cnt += printn(fp, c, base, sign);
- continue;
- case 's':
- s = va_arg(va, char *);
- while ((c = *s++) != '\0')
- putc(c, fp);
- /* passthrou */
- default:
- continue;
- }
- }
- putc(c, fp);
- ++cnt;
- }
- return cnt;
-}
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -1,5 +1,5 @@
.POSIX:
-all clean:
+all clean dep distclean:
cd error && make -e $@
cd execute && make -e $@
--- a/tests/execute/Makefile
+++ b/tests/execute/Makefile
@@ -6,3 +6,6 @@
CFLAGS='' SCCEXECPATH=../../bin PATH=../../bin:$$PATH ./chktest.sh < scc-tests.lst
clean:
rm -f *.as *.o *.ir *.qbe *core test.log
+
+distclean: clean
+dep: