scc

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

commit 77f0a2c2cff21b19223f8fae93b8344d7e57972a
parent 07765e654c10f17169bd66e0e5ca3e6205a449b7
Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date:   Wed,  6 May 2026 10:25:55 +0200

Merge remote-tracking branch 'origin/master'

Diffstat:
Msrc/cmd/scc-cc/cc2/code.c | 9---------
Msrc/cmd/scc-cc/cc2/qbe/code.c | 6+++---
Msrc/libc/arch/posix/Makefile | 1+
Asrc/libc/arch/posix/putenv.c | 40++++++++++++++++++++++++++++++++++++++++
Msrc/libc/gcc-scc.sh | 7+++++--
Msrc/libc/objs/amd64-linux.mk | 1+
Msrc/libc/objs/amd64-netbsd.mk | 1+
Msrc/libc/objs/amd64-openbsd.mk | 1+
Mtests/libc/execute/Makefile | 6+++++-
Mtests/libc/execute/runtests.sh | 2+-
10 files changed, 58 insertions(+), 16 deletions(-)

diff --git a/src/cmd/scc-cc/cc2/code.c b/src/cmd/scc-cc/cc2/code.c @@ -82,9 +82,6 @@ pprint(char *s) case '\t': t = "\\t"; goto print_str; - case '\a': - t = "\\a"; - goto print_str; case '\f': t = "\\f"; goto print_str; @@ -94,12 +91,6 @@ pprint(char *s) case '"': t = "\\\""; goto print_str; - case '\'': - t = "\\'"; - goto print_str; - case '\?': - t = "\\\?"; - goto print_str; case '\\': putchar('\\'); default: diff --git a/src/cmd/scc-cc/cc2/qbe/code.c b/src/cmd/scc-cc/cc2/qbe/code.c @@ -231,9 +231,9 @@ emitconst(Node *np) case 4: printf("%ld", (long) np->u.i & 0xFFFFFFFF); break; - case 8: - printf("%lld", (long long) np->u.i); - break; + case 8: + printf("%lld", (long long) np->u.i); + break; default: abort(); } diff --git a/src/libc/arch/posix/Makefile b/src/libc/arch/posix/Makefile @@ -10,6 +10,7 @@ OBJS=\ _tzone.$O\ clock.$O\ getenv.$O\ + putenv.$O\ raise.$O\ signal.$O\ system.$O\ diff --git a/src/libc/arch/posix/putenv.c b/src/libc/arch/posix/putenv.c @@ -0,0 +1,40 @@ +#include <errno.h> +#include <stdlib.h> +#include <string.h> + +extern char **_environ; + +int +putenv(char *name) +{ + char **p, *s; + size_t siz, len, cnt; + static char **lastenv; + + if ((s = strchr(name, '=')) == NULL) { + errno = EINVAL; + return -1; + } + len = s - name; + + for (p = _environ; *p; ++p) { + if (!strncmp(name, *p, len) && (*p)[len] == '=') { + *p = name; + return 0; + } + } + + cnt = p - _environ; + siz = (cnt + 2) * sizeof(char **); + + if ((p = realloc(lastenv, siz)) == NULL) + return -1; + if (!lastenv) + memcpy(p, _environ, cnt * sizeof(char **)); + lastenv = _environ = p; + + p[cnt] = name; + p[cnt+1] = NULL; + + return 0; +} diff --git a/src/libc/gcc-scc.sh b/src/libc/gcc-scc.sh @@ -2,12 +2,15 @@ set -e -while getopts gr:a:s:o:c o +while getopts gr:O:a:s:o:c o do case $o in g) g=-g ;; + O) + opti=-O1 + ;; r) root=$OPTARG ;; @@ -52,7 +55,7 @@ OpenBSD) esac includes="-nostdinc -I$inc -I$arch_inc -I$sys_inc -I$sys_arch_inc" -cflags="-std=c99 -w -fno-pie -fno-stack-protector -ffreestanding -static" +cflags="$opti -std=c99 -w -fno-pie -fno-stack-protector -ffreestanding -static" ldflags="-z nodefaultlib -static -L$lib" if test ${onlycc:-0} -eq 1 diff --git a/src/libc/objs/amd64-linux.mk b/src/libc/objs/amd64-linux.mk @@ -41,6 +41,7 @@ OBJS =\ arch/posix/_tzone.$O\ arch/posix/clock.$O\ arch/posix/getenv.$O\ + arch/posix/putenv.$O\ arch/posix/raise.$O\ arch/posix/signal.$O\ arch/posix/system.$O\ diff --git a/src/libc/objs/amd64-netbsd.mk b/src/libc/objs/amd64-netbsd.mk @@ -33,6 +33,7 @@ OBJS =\ arch/posix/_open.$O\ arch/posix/_tzone.$O\ arch/posix/clock.$O\ + arch/posix/putenv.$O\ arch/posix/getenv.$O\ arch/posix/raise.$O\ arch/posix/signal.$O\ diff --git a/src/libc/objs/amd64-openbsd.mk b/src/libc/objs/amd64-openbsd.mk @@ -37,6 +37,7 @@ OBJS =\ arch/posix/_open.$O\ arch/posix/_tzone.$O\ arch/posix/clock.$O\ + arch/posix/putenv.$O\ arch/posix/getenv.$O\ arch/posix/raise.$O\ arch/posix/signal.$O\ diff --git a/tests/libc/execute/Makefile b/tests/libc/execute/Makefile @@ -4,13 +4,17 @@ PROJECTDIR = ../../.. include $(PROJECTDIR)/scripts/rules.mk PROJ_CFLAGS = $(CFLAGS) +PROJ_LDFLAGS = $(LDFLAGS) CC=$(SCC) # Uncomment following line to use gcc to test the libc # CC = $(BINDIR)/gcc-scc all: - CC=$(CC) ./runtests.sh libc-tests.lst + @CC='$(CC)' \ + CFLAGS='$(PROJ_CFLAGS)' \ + LDFLAGS='$(PROJ_CFLAGS)' \ + ./runtests.sh libc-tests.lst tests: @$(MAKE) |\ diff --git a/tests/libc/execute/runtests.sh b/tests/libc/execute/runtests.sh @@ -15,7 +15,7 @@ do rm -f *.o $i $tmp1 $tmp2 (echo $i - $CC $CFLAGS -o $i $i.c + $CC $CFLAGS $LDFLAGS -o $i $i.c echo '/^output:$/+;/^end:$/-'w $tmp1 | ed -s $i.c $EXEC ./$i >$tmp2 2>&1 &