├── .gitignore ├── BUGS ├── LICENSE ├── Makefile ├── README ├── ar ├── Makefile ├── main.c └── posix │ ├── stat.c │ └── stat.h ├── as ├── Makefile ├── as.h ├── expr.c ├── gendep.sh ├── gentbl.awk ├── gentbl.sh ├── ins.c ├── main.c ├── myro.c ├── parser.c ├── symbol.c ├── target │ ├── amd64.mk │ ├── i386.mk │ ├── x80 │ │ ├── ins.c │ │ ├── proc.h │ │ ├── rules.dat │ │ ├── x80.dat │ │ ├── z80-test.s │ │ └── z80.c │ ├── x86 │ │ ├── amd64.c │ │ ├── i386.c │ │ ├── ins.c │ │ ├── nasm.dat │ │ ├── proc.h │ │ ├── rules.dat │ │ └── x86.dat │ └── z80.mk └── test.sh ├── cc1 ├── Makefile ├── TODO ├── builtin.c ├── cc1.h ├── code.c ├── cpp.c ├── decl.c ├── error.c ├── expr.c ├── fold.c ├── gendep.sh ├── init.c ├── ir.md ├── lex.c ├── main.c ├── stmt.c ├── symbol.c ├── target │ ├── amd64-sysv │ │ └── arch.c │ ├── arm64-sysv │ │ └── arch.c │ ├── i386-sysv │ │ └── arch.c │ └── z80-scc │ │ └── arch.c └── types.c ├── cc2 ├── Makefile ├── cc2.h ├── code.c ├── gendep.sh ├── generror.awk ├── main.c ├── node.c ├── optm.c ├── parser.c ├── peep.c ├── symbol.c └── target │ ├── amd64-sysv │ ├── arch.h │ ├── cgen.c │ ├── code.c │ ├── optm.c │ ├── target.mk │ └── types.c │ ├── arm64-sysv │ └── types.c │ ├── i386-sysv │ ├── arch.h │ ├── cgen.c │ ├── code.c │ ├── optm.c │ ├── target.mk │ └── types.c │ ├── qbe │ ├── arch.h │ ├── cgen.c │ ├── code.c │ └── optm.c │ ├── qbe_amd64-sysv │ └── target.mk │ ├── qbe_arm64-sysv │ └── target.mk │ └── z80-scc │ ├── arch.h │ ├── cgen.c │ ├── code.c │ ├── optm.c │ ├── target.mk │ └── types.c ├── config.mk.def ├── doc ├── myro.txt └── scc.1 ├── driver ├── Makefile └── posix │ ├── Makefile │ ├── cpp.sh │ ├── gendep.sh │ └── scc.c ├── inc ├── Makefile ├── ar.h ├── arg.h ├── c89 │ └── cstd.h ├── c99 │ └── cstd.h ├── ldflags.def.h ├── myro.h ├── scc.h ├── sysincludes.def.h └── syslibs.def.h ├── lib ├── Makefile ├── c │ ├── Makefile │ ├── __abs.c │ ├── __getc.c │ ├── __labs.c │ ├── __llabs.c │ ├── __putc.c │ ├── _fpopen.c │ ├── abort.c │ ├── abs.c │ ├── assert.c │ ├── atexit.c │ ├── atoi.c │ ├── atol.c │ ├── atoll.c │ ├── bsearch.c │ ├── calloc.c │ ├── clearerr.c │ ├── ctype.c │ ├── exit.c │ ├── fclose.c │ ├── feof.c │ ├── ferror.c │ ├── fgetc.c │ ├── fgets.c │ ├── fopen.c │ ├── fprintf.c │ ├── fputc.c │ ├── fputs.c │ ├── fread.c │ ├── freopen.c │ ├── fseek.c │ ├── fwrite.c │ ├── getc.c │ ├── getchar.c │ ├── gets.c │ ├── include │ │ ├── assert.h │ │ ├── bits │ │ │ ├── amd64-sysv │ │ │ │ └── arch │ │ │ │ │ ├── limits.h │ │ │ │ │ ├── signal.h │ │ │ │ │ ├── stddef.h │ │ │ │ │ ├── stdint.h │ │ │ │ │ ├── stdio.h │ │ │ │ │ ├── stdlib.h │ │ │ │ │ ├── string.h │ │ │ │ │ └── time.h │ │ │ ├── i386-sysv │ │ │ │ └── arch │ │ │ │ │ ├── limits.h │ │ │ │ │ ├── signal.h │ │ │ │ │ ├── stddef.h │ │ │ │ │ ├── stdint.h │ │ │ │ │ ├── stdio.h │ │ │ │ │ ├── stdlib.h │ │ │ │ │ ├── string.h │ │ │ │ │ └── time.h │ │ │ └── z80-dos │ │ │ │ └── arch │ │ │ │ ├── limits.h │ │ │ │ ├── signal.h │ │ │ │ ├── stddef.h │ │ │ │ ├── stdint.h │ │ │ │ ├── stdio.h │ │ │ │ ├── stdlib.h │ │ │ │ ├── string.h │ │ │ │ └── time.h │ │ ├── ctype.h │ │ ├── errno.h │ │ ├── limits.h │ │ ├── locale.h │ │ ├── signal.h │ │ ├── stdarg.h │ │ ├── stdbool.h │ │ ├── stddef.h │ │ ├── stdint.h │ │ ├── stdio.h │ │ ├── stdlib.h │ │ ├── string.h │ │ └── time.h │ ├── isalnum.c │ ├── isalpha.c │ ├── isascii.c │ ├── isblank.c │ ├── iscntrl.c │ ├── isdigit.c │ ├── isgraph.c │ ├── islower.c │ ├── isprint.c │ ├── ispunct.c │ ├── isspace.c │ ├── isupper.c │ ├── isxdigit.c │ ├── labs.c │ ├── llabs.c │ ├── localeconv.c │ ├── malloc.c │ ├── malloc.h │ ├── memchr.c │ ├── memcmp.c │ ├── memcpy.c │ ├── memmove.c │ ├── memset.c │ ├── perror.c │ ├── printf.c │ ├── putc.c │ ├── putchar.c │ ├── puts.c │ ├── qsort.c │ ├── rand.c │ ├── realloc.c │ ├── rewind.c │ ├── setbuf.c │ ├── setlocale.c │ ├── setvbuf.c │ ├── snprintf.c │ ├── sprintf.c │ ├── stdio.c │ ├── strcat.c │ ├── strchr.c │ ├── strcmp.c │ ├── strcoll.c │ ├── strcpy.c │ ├── strcspn.c │ ├── strerror.c │ ├── strlen.c │ ├── strncat.c │ ├── strncmp.c │ ├── strncpy.c │ ├── strpbrk.c │ ├── strrchr.c │ ├── strspn.c │ ├── strstr.c │ ├── strtok.c │ ├── strxfrm.c │ ├── syscall.h │ ├── target │ │ ├── Makefile │ │ ├── amd64-sysv-linux-elf │ │ │ ├── Makefile │ │ │ └── gendep.sh │ │ ├── amd64-sysv-openbsd-elf │ │ │ ├── Makefile │ │ │ └── gendep.sh │ │ ├── common.mk │ │ ├── i386-sysv-linux-elf │ │ │ ├── Makefile │ │ │ └── gendep.sh │ │ ├── objlst.mk │ │ └── z80-scc-none-none │ │ │ ├── Makefile │ │ │ └── gendep.sh │ ├── tmpnam.c │ ├── tolower.c │ ├── toupper.c │ ├── vfprintf.c │ ├── vsnprintf.c │ └── vsprintf.c ├── crt │ ├── Makefile │ ├── amd64-sysv-linux │ │ └── crt.s │ ├── amd64-sysv-openbsd │ │ └── crt.s │ ├── gendep.sh │ ├── i386-sysv-linux │ │ └── crt.s │ ├── i386-sysv-openbsd │ │ └── crt.s │ └── z80-scc-none │ │ └── crt.s ├── scc │ ├── Makefile │ ├── alloc.c │ ├── casecmp.c │ ├── debug.c │ ├── die.c │ ├── libdep.mk │ ├── lpack.c │ ├── lunpack.c │ ├── newitem.c │ ├── rmyro.c │ ├── wmyro.c │ ├── xcalloc.c │ ├── xmalloc.c │ ├── xrealloc.c │ └── xstrdup.c └── sys │ ├── Makefile │ ├── abi │ └── amd64-sysv.sh │ ├── amd64-sysv-linux │ ├── Makefile │ └── syscall.lst │ ├── common.mk │ ├── i386-sysv-linux │ ├── Makefile │ └── syscall.lst │ ├── libsys.mk │ ├── qbe-linux │ ├── Makefile │ └── syscall.lst │ └── z80-linux │ ├── Makefile │ └── syscall.lst ├── nm ├── Makefile └── main.c ├── objdump ├── Makefile └── main.c ├── system.mk └── tests ├── Makefile ├── error ├── 0001-sanity.c ├── 0002-missinginclude.c ├── 0003-junkinclude.c ├── 0004-macroredef.c ├── 0005-fmacro.c ├── 0006-endif.c ├── 0007-unmatchedcppif.c ├── 0008-unmatchedcppelse.c ├── 0009-unmatchedcppelif.c ├── 0010-extraelif.c ├── 0011-extraelse.c ├── 0012-ifnoexpr.c ├── 0013-macro.c ├── 0014-macro.c ├── 0015-macro.c ├── 0016-arrayinitsize.c ├── 0017-duplicatefunc.c ├── 0018-voidparam.c ├── 0019-kr_names.c ├── 0020-storage.c ├── 0021-namespace.c ├── 0021-void.c ├── 0022-cpp-if.c ├── 0023-include.c ├── 0023-include.h ├── Makefile ├── README ├── chktest.sh ├── scc-tests.lst └── update.sh ├── execute ├── 0001-sanity.c ├── 0002-expr.c ├── 0003-local.c ├── 0004-pointer.c ├── 0005-ifstmt.c ├── 0006-whilestmt.c ├── 0007-forstmt.c ├── 0008-dowhilestmt.c ├── 0009-expr.c ├── 0010-goto.c ├── 0011-assign.c ├── 0012-expr.c ├── 0013-addridx.c ├── 0014-assignidx.c ├── 0015-localarray.c ├── 0016-addrarray.c ├── 0017-struct.c ├── 0018-structptr.c ├── 0019-selfrefstruct.c ├── 0020-ptrptr.c ├── 0021-intfunc.c ├── 0022-typedef.c ├── 0023-global.c ├── 0024-typedefstruct.c ├── 0025-string.c ├── 0026-implicitret.c ├── 0027-charval.c ├── 0028-bor.c ├── 0029-band.c ├── 0030-bxor.c ├── 0031-relop.c ├── 0032-indec.c ├── 0033-ptrindec.c ├── 0034-logandor.c ├── 0035-breakcont.c ├── 0036-notneg.c ├── 0037-assignop.c ├── 0038-ptradd.c ├── 0039-sizeof.c ├── 0040-cast.c ├── 0041-queen.c ├── 0042-prime.c ├── 0043-union.c ├── 0044-struct.c ├── 0045-struct.c ├── 0046-inits.c ├── 0047-anonexport.c ├── 0048-inits.c ├── 0049-inits.c ├── 0050-inits.c ├── 0051-inits.c ├── 0052-switch.c ├── 0053-struct.c ├── 0054-struct.c ├── 0055-enum.c ├── 0056-enum.c ├── 0057-duff.c ├── 0058-bug.c ├── 0059-multistring.c ├── 0060-charlit.c ├── 0061-comments.c ├── 0062-include.c ├── 0063-define.c ├── 0064-sysinclude.c ├── 0065-ifdef.c ├── 0066-cppelse.c ├── 0067-define.c ├── 0068-funclikemacro.c ├── 0069-funclikemacro.c ├── 0070-cppif.c ├── 0071-cppelif.c ├── 0072-cppelif.c ├── 0073-ifndef.c ├── 0074-undef.c ├── 0075-ptraddasn.c ├── 0076-ptrsubasn.c ├── 0077-defined.c ├── 0078-dirifexpr.c ├── 0079-cond.c ├── 0080-arrays.c ├── 0081-calls.c ├── 0082-bug.c ├── 0083-voidret.c ├── 0084-longlong.c ├── 0085-ulonglong.c ├── 0086-variadic.c ├── 0087-variadic.c ├── 0088-macros.c ├── 0089-short.c ├── 0090-fptr.c ├── 0091-fptr.c ├── 0092-fptr.c ├── 0093-arrayinit.c ├── 0094-arrayinit.c ├── 0095-arrayselector.c ├── 0096-inferredarraysize.c ├── 0097-extern.c ├── 0098-tentative.c ├── 0099-tentative.c ├── 0100-redeclaremacro.c ├── 0101-wcharlit.c ├── 0102-bug.c ├── 0103-voidparm.c ├── 0104-qbebug.c ├── 0105-shl.c ├── 0106-ppcast.c ├── 0107-bnot.c ├── 0108-bug.c ├── 0109-struct.c ├── 0110-typedefcast.c ├── 0111-doubledef.c ├── 0112-cond.c ├── 0113-externredecl.c ├── 0114-shortassig.c ├── 0115-null-comparision.c ├── 0116-floatcmp.c ├── 0117-pointarith.c ├── 0118-voidmain.c ├── 0119-macrostr.c ├── 0120-funpar.c ├── 0121-localinit.c ├── 0122-localinit.c ├── 0123-doubleconst.c ├── 0124-enumstruct.c ├── 0125-fundcl.c ├── 0126-macropar.c ├── 0127-doublecte.c ├── 0128-kr_names.c ├── 0129-initi.c ├── 0130-mulpars.c ├── 0131-hello.c ├── 0132-forward.c ├── 0133-ftn-ptr.c ├── 0134-arith.c ├── 0135-unary.c ├── 0136-if.c ├── 0137-int-cast.c ├── 0138-namespace.c ├── 0139-ptr-ary.c ├── 0140-int-fold.c ├── 0141-int-iden.c ├── 0142-char-const.c ├── 0143-int-const.c ├── 0144-long-const.c ├── 0145-llong-const.c ├── 0146-ifdef.c ├── 0147-intern-cpp.c ├── 0148-cpp-string.c ├── 0149-define.c ├── 0150-define.c ├── 0151-vararg.c ├── 0152-cat.c ├── 0153-cpp-string.c ├── 0154-if-defined ├── 0155-struct-compl.c ├── 0156-duff2.c ├── 0157-list.c ├── 0158-ternary.c ├── 0159-typedef.c ├── 0160-cpp-if.c ├── 0161-struct.c ├── 0162-array.c ├── 0163-array.c ├── 0164-struct.c ├── 0165-struct.c ├── 0166-desig.c ├── 0167-array.c ├── 0168-array.c ├── 0169-string.c ├── 0170-line.c ├── 0171-macros.c ├── 0172-hexa.c ├── 0173-macro.c ├── 0174-decay.c ├── 0175-defined.c ├── 0176-macro.c ├── 0177-literal.c ├── Makefile ├── README ├── chktest.sh ├── compose.sh ├── include │ ├── 0062-include.h │ └── 0062-include2.h ├── scc-tests.lst └── sysinclude │ ├── 0064-sysinclude.h │ └── 0064-sysinclude2.h └── selfhost.sh /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.a 3 | bin/ 4 | cc1/cc1-* 5 | test.log 6 | cc2/cc2-* 7 | cc2/error.h 8 | as/as-* 9 | driver/posix/scc 10 | makefile 11 | instbl.c 12 | config.mk 13 | inc/ldflags.h 14 | inc/sysincludes.h 15 | inc/syslibs.h 16 | driver/posix/config.h 17 | driver/posix/scpp 18 | rootdir/ 19 | ar/ar-* 20 | nm/nm 21 | objdump/objdump 22 | -------------------------------------------------------------------------------- /BUGS: -------------------------------------------------------------------------------- 1 | # compiling sbase 2 | logger.c:36: error: bad type conversion requested 3 | ls.c abort in cc2-qbe, assign to type with size 0? 4 | tail.c:105: error: 'MIN' undeclared 5 | time.c: segfault in cc2-qbe, ASSHLD not present in optbl 6 | tr.c:196: error: incompatible type for argument 4 in function call 7 | uuencode.c: {standard input}:286: Error: 0x7fffffffffffffff out range of signed 32bit displacement 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | ISC License 2 | 3 | (c) 2012-2017 Roberto E. Vargas Caballero 4 | 5 | (c) 2017 Michael Forney 6 | (c) 2015-2016 Dimitris Papastamos 7 | (c) 2015-2016 Hiltjo Posthuma 8 | (c) 2015-2016 Laslo Hunhold 9 | (c) 2015 Evan Gates 10 | (c) 2015-2017 Quentin Rameau 11 | (c) 2016-2017 Andrew Cahmbers 12 | (c) 2015 Sören Tempel 13 | (c) 2015-2017 Quentin Carbonneaux 14 | (c) 2016 Pekka Jylhä-Ollila 15 | (c) 2016 Alexander Krotov 16 | (c) 2016 Lucas Gabriel Vuotto 17 | (c) 2016 Raymond Nicholson 18 | 19 | Permission to use, copy, modify, and/or distribute this software for any 20 | purpose with or without fee is hereby granted, provided that the above 21 | copyright notice and this permission notice appear in all copies. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 24 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 25 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 26 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 27 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 28 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 29 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 30 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # scc - Suckless C Compiler 2 | 3 | include config.mk.def 4 | 5 | .POSIX: 6 | 7 | DIRS = inc cc1 cc2 driver lib as ar nm objdump 8 | 9 | all: 10 | $(FORALL) 11 | 12 | clean: 13 | $(FORALL) 14 | rm -rf rootdir 15 | 16 | distclean: 17 | touch config.mk # we need config.mk for makes in $DIRS 18 | find . -name makefile | xargs rm -f 19 | $(FORALL) 20 | rm -rf rootdir 21 | rm -f config.mk 22 | 23 | config.mk: 24 | trap "rm -f $$.mk" 0 2 3; \ 25 | (cat config.mk.def ;\ 26 | sed -n '/^# '`uname`'/,/^$$/p' system.mk) > $$.mk && \ 27 | mv $$.mk config.mk 28 | 29 | dep: config.mk 30 | $(FORALL) 31 | 32 | tests: all 33 | +cd tests && $(MAKE) -e all 34 | 35 | install: all 36 | cp -r rootdir/* $(DESTDIR)$(PREFIX)/ 37 | cd $(DESTDIR)$(PREFIX)/libexec/scc/ && chmod 755 cc* && strip cc* 38 | cd $(DESTDIR)$(PREFIX)/bin && chmod 755 scpp scc && strip scc 39 | mkdir -p $(DESTDIR)$(MANPREFIX)/man1 40 | sed "s/VERSION/$(VERSION)/g" < doc/scc.1 > $(DESTDIR)$(MANPREFIX)/man1/scc.1 41 | chmod 644 $(DESTDIR)$(MANPREFIX)/man1/scc.1 42 | 43 | uninstall: 44 | rm -rf $(DESTDIR)$(PREFIX)/libexec/scc/ 45 | rm -rf $(DESTDIR)$(PREFIX)/lib/scc/ 46 | rm -f $(DESTDIR)$(PREFIX)/bin/scc 47 | rm -f $(DESTDIR)$(PREFIX)/bin/scpp 48 | rm -f $(DESTDIR)$(MANPREFIX)/man1/scc.1 49 | -------------------------------------------------------------------------------- /ar/Makefile: -------------------------------------------------------------------------------- 1 | .POSIX: 2 | 3 | LIBDIR = ../lib/scc 4 | include ../config.mk 5 | include $(LIBDIR)/libdep.mk 6 | 7 | OBJ = main.o $(DRIVER)/stat.c 8 | MOREFLAGS = -I$(DRIVER) 9 | 10 | all: ar-$(DRIVER) 11 | mkdir -p ../../rootdir/bin 12 | cp ar-$(DRIVER) ../rootdir/bin/ar 13 | 14 | ar-$(DRIVER): $(OBJ) $(LIBDIR)/libscc.a 15 | $(CC) $(SCC_LDFLAGS) $(OBJ) -lscc -o $@ 16 | 17 | main.o: ../inc/scc.h ../inc/ar.h 18 | 19 | $(DRIVER)/stat.o: $(DRIVER)/stat.h 20 | 21 | $(LIBDIR)/libscc.a: $(LIB-OBJ) 22 | +cd $(LIBDIR) && $(MAKE) 23 | 24 | main.o: $(DRIVER)/stat.h 25 | 26 | dep: 27 | clean: 28 | rm -f ar-* *.o $(DRIVER)/*.o 29 | 30 | distclean: clean 31 | -------------------------------------------------------------------------------- /ar/posix/stat.c: -------------------------------------------------------------------------------- 1 | static char sccsid[] = "@(#) ./ar/stat.c"; 2 | 3 | #include "stat.h" 4 | -------------------------------------------------------------------------------- /ar/posix/stat.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | 6 | #define totime(x) (x) 7 | -------------------------------------------------------------------------------- /as/Makefile: -------------------------------------------------------------------------------- 1 | .POSIX: 2 | 3 | LIBDIR = ../lib/scc 4 | include ../config.mk 5 | include $(LIBDIR)/libdep.mk 6 | 7 | OBJ = main.o symbol.o ins.o parser.o expr.o myro.o 8 | HDR = ../inc/scc.h as.h 9 | MOREFLAGS = -I../inc/$(STD) $(AS_CFLAGS) 10 | 11 | all: 12 | 13 | $(OBJ): $(HDR) 14 | 15 | as: $(OBJ) 16 | $(CC) $(SCC_LDFLAGS) $(OBJ) -lscc -o $@ 17 | 18 | myro.o: ../inc/myro.h 19 | 20 | $(LIBDIR)/libscc.a: $(LIB-OBJ) 21 | +cd $(LIBDIR) && $(MAKE) 22 | 23 | dep: 24 | ./gendep.sh $(TARGETS) 25 | 26 | clean: 27 | rm -f *.o target/*/*.o 28 | rm -f target/*/*tbl.c 29 | rm -f as-* 30 | rm -f *.log 31 | 32 | distclean: clean 33 | rm -f makefile 34 | 35 | -------------------------------------------------------------------------------- /as/gendep.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | rm -f makefile 6 | trap "rm -f $$.mk" 0 2 3 7 | 8 | re='\([^-]*\)-\([^-]*\)-\([^-]*\)-\([^-]*\)' 9 | 10 | echo $@ | 11 | tr ' ' '\n' | 12 | sed "s/$re/\1/" | 13 | sort -u | 14 | (cat Makefile 15 | while read i 16 | do 17 | cat < $$.mk && mv $$.mk makefile 28 | -------------------------------------------------------------------------------- /as/gentbl.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | 4 | set -e 5 | 6 | while test $# -gt 0 7 | do 8 | case $1 in 9 | -c) 10 | cpu=$2 11 | shift 12 | ;; 13 | -f) 14 | family=$2 15 | shift 16 | ;; 17 | *) 18 | echo gen.sh:incorrect parameter:$1 >&2 19 | exit 1 20 | ;; 21 | esac 22 | shift 23 | done 24 | 25 | echo cpu=${cpu:=z80} family=${family:=x80} 26 | 27 | rm -f $$.c target/$family/${cpu}tbl.c 28 | trap "rm -f $$.c" 0 2 3 29 | 30 | awk '!/^$/ {print $1,NR,$2,$3,$4,$5,$6}' target/$family/$family.dat | 31 | sort -k1 -k2n | 32 | awk -v cpu=`echo $cpu | tr a-z A-Z` -v family=$family -f gentbl.awk > $$.c && 33 | mv $$.c target/$family/${cpu}tbl.c 34 | -------------------------------------------------------------------------------- /as/target/amd64.mk: -------------------------------------------------------------------------------- 1 | 2 | amd64_LST = target/x86/amd64tbl.o target/x86/amd64.o target/x86/ins.o 3 | 4 | $(amd64_LST): target/x86/proc.h 5 | 6 | target/x86/amd64tbl.c: gentbl.awk target/x86/x86.dat target/x86/rules.dat 7 | ./gentbl.sh -f x86 -c amd64 8 | 9 | OBJ-amd64 = $(OBJ) $(amd64_LST) 10 | -------------------------------------------------------------------------------- /as/target/i386.mk: -------------------------------------------------------------------------------- 1 | 2 | i386_LST = target/x86/i386tbl.o target/x86/i386.o target/x86/ins.o 3 | 4 | $(i386_LST): target/x86/proc.h 5 | 6 | target/x86/i386tbl.c: gentbl.awk target/x86/x86.dat target/x86/rules.dat 7 | ./gentbl.sh -f x86 -c i386 8 | 9 | OBJ-i386 = $(OBJ) $(i386_LST) 10 | -------------------------------------------------------------------------------- /as/target/x80/proc.h: -------------------------------------------------------------------------------- 1 | 2 | enum args { 3 | AREG_AF = AMAX, 4 | AREG_A, 5 | AREG_F, 6 | 7 | AREG_BC, 8 | AREG_B, 9 | AREG_C, 10 | 11 | AREG_HL, 12 | AREG_H, 13 | AREG_L, 14 | 15 | AREG_DE, 16 | AREG_D, 17 | AREG_E, 18 | 19 | AREG_IX, 20 | AREG_IXL, 21 | AREG_IXH, 22 | 23 | AREG_IY, 24 | AREG_IYL, 25 | AREG_IYH, 26 | 27 | AREG_R, 28 | AREG_I, 29 | AREG_AF_, 30 | AREG_SP, 31 | 32 | AREG_NZ, 33 | AREG_Z, 34 | AREG_NC, 35 | AREG_PO, 36 | AREG_PE, 37 | AREG_P, 38 | AREG_M, 39 | 40 | AREG_RCLASS, /* register class for B, C, D, E, H, L and A */ 41 | AREG_PCLASS, /* register class for B, C, D, E, IXH, IXL and A */ 42 | AREG_QCLASS, /* register class for B, C, D, E, IYH, IYL and A */ 43 | AREG_DDCLASS, /* register class for BC, DE, HL and SP */ 44 | AREG_QQCLASS, /* register class for BC, DE, HL and AF */ 45 | AREG_PPCLASS, /* register class for BC, DE, IX and SP */ 46 | AREG_RRCLASS, /* register class for BC, DE, IY and SP */ 47 | AREG_SSCLASS, /* flag class for C, NC, Z, NZ */ 48 | AREG_CCCLASS, /* flag class for NZ, Z, NC, C, PO, PE, P, M */ 49 | 50 | AINDEX_IX, /* (IX+d) */ 51 | AINDEX_IY, /* (IX+d) */ 52 | 53 | AINDER_HL, /* (HL) */ 54 | AINDER_DE, /* (DE) */ 55 | AINDER_BC, /* (BC) */ 56 | AINDER_SP, /* (SP) */ 57 | AINDER_C, /* (C) */ 58 | AINDER_IX, /* (IX) */ 59 | AINDER_IY, /* (IY) */ 60 | 61 | AIMM3, /* 3 bit immediate */ 62 | AZERO, /* a literal 0 */ 63 | ARST, /* 0h, 08h, 10h, 18h, 20h, 28h, 30h, 38h */ 64 | }; 65 | 66 | enum { 67 | RCLASS = 1 << 0, 68 | PCLASS = 1 << 1, 69 | QCLASS = 1 << 2, 70 | DDCLASS = 1 << 3, 71 | QQCLASS = 1 << 4, 72 | PPCLASS = 1 << 5, 73 | RRCLASS = 1 << 6, 74 | CCCLASS = 1 << 7, 75 | SSCLASS = 1 << 8, 76 | }; 77 | -------------------------------------------------------------------------------- /as/target/x80/rules.dat: -------------------------------------------------------------------------------- 1 | imm8 AIMM8 2 | imm16 AIMM16 3 | imm32 AIMM32 4 | imm64 AIMM64 5 | imm3 AIMM3 6 | rst ARST 7 | \(IY\+n\) AINDEX_IY 8 | \(IX\+n\) AINDEX_IX 9 | ss AREG_SSCLASS 10 | cc AREG_CCCLASS 11 | dd AREG_DDCLASS 12 | qq AREG_QQCLASS 13 | rr AREG_RRCLASS 14 | pp AREG_PPCLASS 15 | p AREG_PCLASS 16 | q AREG_QCLASS 17 | r AREG_RCLASS 18 | R AREG_R 19 | \(DE\) AINDER_DE 20 | \(BC\) AINDER_BC 21 | \(HL\) AINDER_HL 22 | \(SP\) AINDER_SP 23 | \(C\) AINDER_C 24 | \(IX\) AINDER_IX 25 | \(IY\) AINDER_IY 26 | SP AREG_SP 27 | HL AREG_HL 28 | DE AREG_DE 29 | IX AREG_IX 30 | IY AREG_IY 31 | AF' AREG_AF_ 32 | AF AREG_AF 33 | A AREG_A 34 | F AREG_F 35 | \(n\) ADIRECT 36 | I AREG_I 37 | 0 AZERO 38 | sym ASYM 39 | string ASTR 40 | -------------------------------------------------------------------------------- /as/target/x80/z80.c: -------------------------------------------------------------------------------- 1 | static char sccsid[] = "@(#) ./as/target/x80/z80.c"; 2 | 3 | #include 4 | 5 | #include "../../../inc/scc.h" 6 | #include "../../as.h" 7 | #include "../x80/proc.h" 8 | 9 | TUINT maxaddr = 0xFFFFFFFF; 10 | int endian = LITTLE_ENDIAN; 11 | int left2right = 0; 12 | 13 | void 14 | iarch(void) 15 | { 16 | static struct { 17 | char *name; 18 | char type; 19 | } regs[] = { 20 | "AF", AREG_AF, 21 | "A", AREG_A, 22 | "F", AREG_F, 23 | 24 | "BC", AREG_BC, 25 | "B", AREG_B, 26 | "C", AREG_C, 27 | 28 | "HL", AREG_HL, 29 | "H", AREG_H, 30 | "L", AREG_L, 31 | 32 | "DE", AREG_DE, 33 | "D", AREG_D, 34 | "E", AREG_E, 35 | 36 | "IX", AREG_IX, 37 | "IXL", AREG_IXL, 38 | "IXH", AREG_IXH, 39 | 40 | "IY", AREG_IY, 41 | "IYL", AREG_IYL, 42 | "IYH", AREG_IYH, 43 | 44 | "R", AREG_R, 45 | "I", AREG_I, 46 | "AF'", AREG_AF_, 47 | "SP", AREG_SP, 48 | 49 | "NZ", AREG_NZ, 50 | "Z", AREG_Z, 51 | "NC", AREG_NC, 52 | "PO", AREG_PO, 53 | "PE", AREG_PE, 54 | "P", AREG_P, 55 | "M", AREG_M, 56 | 57 | NULL, 58 | }, *bp; 59 | 60 | for (bp = regs; bp->name; ++bp) { 61 | Symbol *sym = lookup(bp->name); 62 | sym->flags = FREG; 63 | sym->value = bp->type; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /as/target/x86/amd64.c: -------------------------------------------------------------------------------- 1 | static char sccsid[] = "@(#) ./as/target/x86/amd64.c"; 2 | 3 | #include "../../../inc/scc.h" 4 | #include "../../as.h" 5 | 6 | TUINT maxaddr = 0xFFFFFFFFFFFFFFFF; 7 | int endian = LITTLE_ENDIAN; 8 | int left2right = 0; 9 | 10 | void 11 | iarch(void) 12 | { 13 | } 14 | -------------------------------------------------------------------------------- /as/target/x86/ins.c: -------------------------------------------------------------------------------- 1 | static char sccsid[] = "@(#) ./as/target/x86/ins.c"; 2 | 3 | #include 4 | 5 | #include "../../../inc/scc.h" 6 | #include "../../as.h" 7 | #include "proc.h" 8 | 9 | int 10 | match(Op *op, Node **args) 11 | { 12 | unsigned char *p; 13 | int a, olda; 14 | 15 | if (!op->args) 16 | return args == NULL; 17 | 18 | for (p = op->args; *p; ++p) { 19 | if (*p != AREP) 20 | a = *p; 21 | else 22 | --p; 23 | 24 | switch (a) { 25 | case AIMM8: 26 | case AIMM16: 27 | case AIMM32: 28 | case AIMM64: 29 | case AREG_AL: 30 | case AREG_AH: 31 | case AREG_AX: 32 | case AREG_EAX: 33 | default: 34 | abort(); 35 | } 36 | } 37 | return 1; 38 | } 39 | 40 | Node * 41 | moperand(void) 42 | { 43 | } 44 | -------------------------------------------------------------------------------- /as/target/x86/rules.dat: -------------------------------------------------------------------------------- 1 | ^imm8 AIMM8 2 | ^imm16 AIMM16 3 | ^imm32 AIMM32 4 | ^imm64 AIMM64 5 | ^\(n\) ADIRECT 6 | ^sym ASYM 7 | ^string ASTR 8 | -------------------------------------------------------------------------------- /as/target/x86/x86.dat: -------------------------------------------------------------------------------- 1 | # Tab 16, tabs 16, :set ts=16 2 | # op args size bytes format cpu 3 | .DB imm8+ 0 none defb BITS16,BITS32,BITS64 4 | .DEFB imm8+ 0 none defb BITS16,BITS32,BITS64 5 | .BYTE imm8+ 0 none defb BITS16,BITS32,BITS64 6 | .DW imm16+ 0 none defw BITS16,BITS32,BITS64 7 | .DEFW imm16+ 0 none defw BITS16,BITS32,BITS64 8 | .SHORT imm16+ 0 none defw BITS16,BITS32,BITS64 9 | .WORD imm16+ 0 none defw BITS16 10 | .WORD imm32+ 0 none defd BITS32,BITS64 11 | .DD imm32+ 0 none defd BITS16,BITS32,BITS64 12 | .DEFD imm32+ 0 none defd BITS16,BITS32,BITS64 13 | .LONG imm32+ 0 none defd BITS16,BITS32 14 | .LONG imm64+ 0 none defq BITS64 15 | .INT imm32+ 0 none defd BITS32,BITS64 16 | .INT imm16+ 0 none defd BITS16 17 | .DQ imm64+ 0 none defq BITS16,BITS32,BITS64 18 | .DEFQ imm64+ 0 none defq BITS16,BITS32,BITS64 19 | .EQU imm16 0 none equ BITS16 20 | .EQU imm32 0 none equ BITS32 21 | .EQU imm64 0 none equ BITS64 22 | NOP none 1 0x90 noargs BITS16,BITS32,BITS64 23 | RET none 1 0xc3 noargs BITS16,BITS32,BITS64 24 | -------------------------------------------------------------------------------- /as/target/z80.mk: -------------------------------------------------------------------------------- 1 | 2 | Z80_LST = target/x80/z80tbl.o target/x80/z80.o target/x80/ins.o 3 | 4 | $(Z80_LST): target/x80/proc.h 5 | 6 | target/x80/z80tbl.c: gentbl.awk target/x80/x80.dat target/x80/rules.dat 7 | LC_ALL=C ./gentbl.sh -f x80 -c z80 8 | 9 | OBJ-z80 = $(OBJ) $(Z80_LST) 10 | -------------------------------------------------------------------------------- /as/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | file=${1?} 5 | exec >test.log 6 | exec 2>&1 7 | 8 | tmp1=`mktemp` 9 | tmp2=`mktemp` 10 | 11 | trap "rm -f a.out $tmp1 $tmp2" 0 2 3 12 | 13 | ./as-$cpu $file 14 | 15 | sed -n '/^\// ! { 16 | s%.*/%% 17 | s%^[ ]*%% 18 | s%[ ]*$%% 19 | /^$/d 20 | s%[ ][ ]*%\ 21 | %g 22 | p 23 | }' $file | 24 | nl -b a > $tmp1 25 | 26 | 27 | ../objdump/objdump | 28 | sed -n '/^data:/,$ { 29 | /^data:/ ! { 30 | s%.*:%% 31 | s%^[ ]*%% 32 | s%[ ]*$%% 33 | /^$/d 34 | s%[ ][ ]*%\ 35 | %g 36 | p 37 | } 38 | }' | 39 | nl -b a > $tmp2 40 | 41 | printf "test.s\n" 42 | cat $tmp1 43 | printf "\nobjdump\n" 44 | cat $tmp2 45 | printf "\ndiff\n" 46 | diff -u $tmp1 $tmp2 47 | -------------------------------------------------------------------------------- /cc1/Makefile: -------------------------------------------------------------------------------- 1 | .POSIX: 2 | 3 | # Makefile is only used as a template for makefile. 4 | # If you modify Makefile remember to run make dep 5 | 6 | LIBDIR = ../lib/scc 7 | include ../config.mk 8 | include $(LIBDIR)/libdep.mk 9 | 10 | MOREFLAGS = -I../inc/$(STD) $(CC1_CFLAGS) 11 | 12 | OBJ = types.o decl.o lex.o error.o symbol.o main.o expr.o \ 13 | code.o stmt.o cpp.o fold.o init.o builtin.o 14 | 15 | HDR = cc1.h ../inc/scc.h ../inc/$(STD)/cstd.h ../inc/sysincludes.h 16 | 17 | all: 18 | mkdir -p ../rootdir/libexec/scc/ 19 | cp cc1-* ../rootdir/libexec/scc/ 20 | 21 | $(LIBDIR)/libscc.a: $(LIB-OBJ) 22 | +cd $(LIBDIR) && $(MAKE) 23 | 24 | dep: 25 | ./gendep.sh $(TARGETS) 26 | 27 | clean: 28 | rm -f *.o 29 | rm -f target/*/*.o 30 | rm -f cc1-* 31 | 32 | distclean: clean 33 | rm -f makefile 34 | -------------------------------------------------------------------------------- /cc1/TODO: -------------------------------------------------------------------------------- 1 | * Implement bitfields 2 | * Rewrite error recovery code, and ensure correct state after recovery 3 | * Parse correctly all integer and float constants 4 | * Add C99 features (almost all the new features of C99 are missed) 5 | * Add correct emit for any kind of constant 6 | * Add warning when some ANSI limit is violated. 7 | * Free memory in emit after some error happened. 8 | * Rewrite initializers to deal with the idea of "current object" 9 | * Add some test about pointer airthmetic. 10 | * Merge all the definitions of the same string 11 | * Do not assign identifierss until symbols are emitted. This change will 12 | avoid identifiers that are not emitted. 13 | * Fix assignation abbreviations. They fail whe lhs type is smaller than 14 | the type in rhs 15 | -------------------------------------------------------------------------------- /cc1/error.c: -------------------------------------------------------------------------------- 1 | static char sccsid[] = "@(#) ./cc1/error.c"; 2 | #include 3 | #include 4 | #include 5 | 6 | #include "../inc/scc.h" 7 | #include "cc1.h" 8 | 9 | #define MAXERRNUM 10 10 | 11 | extern int failure; 12 | static unsigned nerrors; 13 | 14 | static void 15 | warn_error(int flag, char *fmt, va_list va) 16 | { 17 | if (flag == 0) 18 | return; 19 | fprintf(stderr, "%s:%u: %s: ", 20 | filenam, lineno, 21 | (flag < 0) ? "error" : "warning"); 22 | vfprintf(stderr, fmt, va); 23 | putc('\n', stderr); 24 | 25 | if (flag < 0) { 26 | if (!failure) 27 | fclose(stdout); 28 | failure = 1; 29 | if (++nerrors == MAXERRNUM) { 30 | fputs("too many errors\n", stderr); 31 | exit(1); 32 | } 33 | } 34 | } 35 | 36 | void 37 | warn(char *fmt, ...) 38 | { 39 | extern int warnings; 40 | 41 | va_list va; 42 | va_start(va, fmt); 43 | warn_error(warnings, fmt, va); 44 | va_end(va); 45 | } 46 | 47 | void 48 | error(char *fmt, ...) 49 | { 50 | va_list va; 51 | 52 | va_start(va, fmt); 53 | warn_error(-1, fmt, va); 54 | va_end(va); 55 | exit(1); 56 | discard(); 57 | } 58 | 59 | void 60 | errorp(char *fmt, ...) 61 | { 62 | va_list va; 63 | va_start(va, fmt); 64 | warn_error(-1, fmt, va); 65 | va_end(va); 66 | } 67 | 68 | void 69 | cpperror(char *fmt, ...) 70 | { 71 | va_list va; 72 | va_start(va, fmt); 73 | warn_error(-1, fmt, va); 74 | va_end(va); 75 | 76 | /* discard input until the end of the line */ 77 | *input->p = '\0'; 78 | next(); 79 | } 80 | 81 | void 82 | unexpected(void) 83 | { 84 | error("unexpected '%s'", yytext); 85 | } 86 | -------------------------------------------------------------------------------- /cc1/gendep.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | rm -f makefile 6 | trap "rm -f $$.mk" 0 2 3 7 | 8 | re='\([^-]*\)-\([^-]*\)-\([^-]*\)-\([^-]*\)' 9 | 10 | echo $@ | 11 | tr ' ' '\n' | 12 | sed "s/$re/\1-\2/" | 13 | sort -u | 14 | (cat Makefile 15 | echo 16 | while read i 17 | do 18 | cat < $$.mk && mv $$.mk makefile 28 | -------------------------------------------------------------------------------- /cc1/target/arm64-sysv/arch.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/k0gaMSX/scc/e53520a8ec6d7838423fea56e1b028ced9558f59/cc1/target/arm64-sysv/arch.c -------------------------------------------------------------------------------- /cc2/Makefile: -------------------------------------------------------------------------------- 1 | .POSIX: 2 | 3 | # Makefile is only used as a template for makefile. 4 | # If you modify Makefile remember to run make dep 5 | 6 | LIBDIR = ../lib/scc 7 | include ../config.mk 8 | include $(LIBDIR)/libdep.mk 9 | 10 | MOREFLAGS = -I../inc/$(STD) $(CC2_CFLAGS) 11 | 12 | OBJ = main.o parser.o peep.o symbol.o node.o code.o optm.o 13 | HDR = cc2.h ../inc/$(STD)/cstd.h ../inc/scc.h 14 | 15 | all: 16 | mkdir -p ../rootdir/libexec/scc/ 17 | cp cc2-* ../rootdir/libexec/scc/ 18 | 19 | dep: 20 | MKQBE=${MKQBE} ./gendep.sh $(TARGETS) 21 | 22 | $(LIBDIR)/libscc.a: $(LIB-OBJ) 23 | +cd $(LIBDIR) && $(MAKE) 24 | 25 | main.o: error.h 26 | 27 | error.h: cc2.h 28 | rm -f $@; trap 'rm -f $$$$.h' EXIT INT QUIT ;\ 29 | awk -f generror.awk cc2.h > $$$$.h && mv $$$$.h $@ 30 | 31 | clean: 32 | rm -f *.o 33 | rm -f target/*/*.o 34 | rm -f cc2-* error.h 35 | 36 | distclean: clean 37 | rm -f makefile 38 | -------------------------------------------------------------------------------- /cc2/gendep.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | gentarget() 4 | { 5 | 6 | cat < $$.mk && mv $$.mk makefile 40 | -------------------------------------------------------------------------------- /cc2/generror.awk: -------------------------------------------------------------------------------- 1 | /^enum nerrors \{/ {print "char *errlist[] = {"; inhome = 1} 2 | 3 | inhome && /E[A-Z]*, / {sub(/,/, "", $1) 4 | printf("\t[%s] = \"", $1) 5 | for (i = 3; i <= NF-1; ++i) 6 | printf("%s%s", $i, (i == NF-1) ? "\"" : " ") 7 | print ","} 8 | 9 | inhome && /^}/ {print "};" ; inhome = 0} 10 | -------------------------------------------------------------------------------- /cc2/main.c: -------------------------------------------------------------------------------- 1 | static char sccsid[] = "@(#) ./cc2/main.c"; 2 | #include 3 | #include 4 | #include 5 | 6 | #include "../inc/scc.h" 7 | #include "cc2.h" 8 | #include "error.h" 9 | 10 | void 11 | error(unsigned nerror, ...) 12 | { 13 | va_list va; 14 | va_start(va, nerror); 15 | vfprintf(stderr, errlist[nerror], va); 16 | va_end(va); 17 | putc('\n', stderr); 18 | exit(1); 19 | } 20 | 21 | static int 22 | moreinput(void) 23 | { 24 | int c; 25 | 26 | repeat: 27 | if (feof(stdin)) 28 | return 0; 29 | if ((c = getchar()) == '\n' || c == EOF) 30 | goto repeat; 31 | ungetc(c, stdin); 32 | return 1; 33 | } 34 | 35 | int 36 | main(int argc, char *argv[]) 37 | { 38 | if (argc > 2) 39 | die("usage: cc2 [irfile]"); 40 | 41 | if (argv[1] && !freopen(argv[1], "r", stdin)) 42 | die("cc2: cannot open %s", argv[1]); 43 | 44 | while (moreinput()) { 45 | parse(); 46 | apply(optm_ind); 47 | apply(optm_dep); 48 | apply(sethi); 49 | apply(cgen); 50 | getbblocks(); /* TODO: run apply over asm ins too */ 51 | peephole(); 52 | writeout(); 53 | } 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /cc2/optm.c: -------------------------------------------------------------------------------- 1 | #include "../inc/scc.h" 2 | #include "cc2.h" 3 | 4 | Node * 5 | optm_ind(Node *np) 6 | { 7 | return np; 8 | } 9 | 10 | -------------------------------------------------------------------------------- /cc2/peep.c: -------------------------------------------------------------------------------- 1 | static char sccsid[] = "@(#) ./cc2/peep.c"; 2 | #include "../inc/scc.h" 3 | #include "cc2.h" 4 | 5 | void 6 | peephole(void) 7 | { 8 | } 9 | -------------------------------------------------------------------------------- /cc2/symbol.c: -------------------------------------------------------------------------------- 1 | static char sccsid[] = "@(#) ./cc2/symbol.c"; 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "../inc/scc.h" 8 | 9 | #include "cc2.h" 10 | 11 | #define NR_SYMHASH 64 12 | 13 | Symbol *locals; 14 | 15 | static Symbol *symtab[NR_SYMHASH], *curlocal; 16 | static int infunction; 17 | 18 | 19 | void 20 | freesym(Symbol *sym) 21 | { 22 | free(sym->name); 23 | free(sym); 24 | } 25 | 26 | void 27 | pushctx(void) 28 | { 29 | infunction = 1; 30 | } 31 | 32 | void 33 | popctx(void) 34 | { 35 | Symbol *sym, *next; 36 | 37 | infunction = 0; 38 | for (sym = locals; sym; sym = next) { 39 | next = sym->next; 40 | /* 41 | * Symbols are inserted in the hash in the inverted 42 | * order they are found in locals and it is impossible 43 | * to have a global over a local, because a local is 44 | * any symbol defined in the body of a function, 45 | * even if it has extern linkage. 46 | * For this reason when we reach a symbol in the 47 | * locals list we know that it is the head of it 48 | * collision list and we can remove it assigning 49 | * it h_next to the hash table position 50 | */ 51 | if (sym->id != TMPSYM) 52 | symtab[sym->id & NR_SYMHASH-1] = sym->h_next; 53 | freesym(sym); 54 | } 55 | curlocal = locals = NULL; 56 | } 57 | 58 | Symbol * 59 | getsym(unsigned id) 60 | { 61 | Symbol **htab, *sym; 62 | static unsigned short num; 63 | 64 | if (id >= USHRT_MAX) 65 | error(EBADID); 66 | 67 | htab = &symtab[id & NR_SYMHASH-1]; 68 | for (sym = *htab; sym; sym = sym->h_next) { 69 | if (sym->id > 0 && sym->id == id) 70 | break; 71 | } 72 | if (!sym) { 73 | sym = xcalloc(1, sizeof(*sym)); 74 | sym->id = id; 75 | if ((sym->numid = ++num) == 0) 76 | error(EIDOVER); 77 | if (infunction) { 78 | if (!locals) 79 | locals = sym; 80 | if (curlocal) 81 | curlocal->next = sym; 82 | curlocal = sym; 83 | } 84 | if (id != TMPSYM) { 85 | sym->h_next = *htab; 86 | *htab = sym; 87 | } 88 | } 89 | return sym; 90 | } 91 | -------------------------------------------------------------------------------- /cc2/target/amd64-sysv/arch.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/k0gaMSX/scc/e53520a8ec6d7838423fea56e1b028ced9558f59/cc2/target/amd64-sysv/arch.h -------------------------------------------------------------------------------- /cc2/target/amd64-sysv/cgen.c: -------------------------------------------------------------------------------- 1 | static char sccsid[] = "@(#) ./cc2/arch/amd64-sysv/cgen.c"; 2 | 3 | #include "arch.h" 4 | #include "../../../inc/scc.h" 5 | #include "../../cc2.h" 6 | 7 | Node * 8 | cgen(Node *np) 9 | { 10 | } 11 | 12 | Node * 13 | sethi(Node *np) 14 | { 15 | } 16 | -------------------------------------------------------------------------------- /cc2/target/amd64-sysv/optm.c: -------------------------------------------------------------------------------- 1 | static char sccsid[] = "@(#) ./cc2/arch/amd64-sysv/optm.c"; 2 | 3 | #include "../../../inc/scc.h" 4 | #include "../../cc2.h" 5 | 6 | Node * 7 | optm_dep(Node *np) 8 | { 9 | return np; 10 | } 11 | -------------------------------------------------------------------------------- /cc2/target/amd64-sysv/target.mk: -------------------------------------------------------------------------------- 1 | OBJ-amd64-sysv = $(OBJ) \ 2 | target/amd64-sysv/cgen.o \ 3 | target/amd64-sysv/optm.o \ 4 | target/amd64-sysv/code.o \ 5 | target/amd64-sysv/types.o 6 | -------------------------------------------------------------------------------- /cc2/target/amd64-sysv/types.c: -------------------------------------------------------------------------------- 1 | static char sccsid[] = "@(#) ./cc2/arch/amd64-sysv/types.c"; 2 | 3 | #include "../../../inc/scc.h" 4 | #include "../../cc2.h" 5 | 6 | 7 | Type int8type = { 8 | .flags = SIGNF | INTF, 9 | .size = 1, 10 | .align = 1 11 | }; 12 | 13 | Type int16type = { 14 | .flags = SIGNF | INTF, 15 | .size = 2, 16 | .align = 2 17 | }; 18 | 19 | Type int32type = { 20 | .flags = SIGNF | INTF, 21 | .size = 4, 22 | .align = 4 23 | }; 24 | 25 | Type int64type = { 26 | .flags = SIGNF | INTF, 27 | .size = 8, 28 | .align = 8 29 | }; 30 | 31 | Type uint8type = { 32 | .flags = INTF, 33 | .size = 1, 34 | .align = 1 35 | }; 36 | 37 | Type uint16type = { 38 | .flags = INTF, 39 | .size = 2, 40 | .align = 2 41 | }; 42 | 43 | Type uint32type = { 44 | .flags = INTF, 45 | .size = 4, 46 | .align = 4 47 | }; 48 | 49 | Type uint64type = { 50 | .flags = INTF, 51 | .size = 8, 52 | .align = 2 53 | }; 54 | 55 | Type ptrtype = { 56 | .flags = INTF, 57 | .size = 8, 58 | .align = 8 59 | }; 60 | 61 | Type booltype = { 62 | .flags = INTF, 63 | .size = 1, 64 | .align = 1 65 | }; 66 | 67 | Type float32type = { 68 | .flags = FLOATF, 69 | .size = 4, 70 | .align = 4 71 | }; 72 | 73 | Type float64type = { 74 | .flags = FLOATF, 75 | .size = 8, 76 | .align = 8 77 | }; 78 | 79 | Type float80type = { 80 | .flags = FLOATF, 81 | .size = 16, 82 | .align = 16 83 | }; 84 | 85 | Type voidtype = { 86 | .size = 0, 87 | .align = 0 88 | }; 89 | 90 | Type arg_type = { 91 | .size = 24, 92 | .align = 8 93 | }; 94 | -------------------------------------------------------------------------------- /cc2/target/arm64-sysv/types.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/k0gaMSX/scc/e53520a8ec6d7838423fea56e1b028ced9558f59/cc2/target/arm64-sysv/types.c -------------------------------------------------------------------------------- /cc2/target/i386-sysv/arch.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/k0gaMSX/scc/e53520a8ec6d7838423fea56e1b028ced9558f59/cc2/target/i386-sysv/arch.h -------------------------------------------------------------------------------- /cc2/target/i386-sysv/cgen.c: -------------------------------------------------------------------------------- 1 | static char sccsid[] = "@(#) ./cc2/arch/i386-sysv/cgen.c"; 2 | 3 | #include "arch.h" 4 | #include "../../../inc/scc.h" 5 | #include "../../cc2.h" 6 | 7 | Node * 8 | cgen(Node *np) 9 | { 10 | } 11 | 12 | Node * 13 | sethi(Node *np) 14 | { 15 | } 16 | -------------------------------------------------------------------------------- /cc2/target/i386-sysv/optm.c: -------------------------------------------------------------------------------- 1 | static char sccsid[] = "@(#) ./cc2/arch/i386-sysv/optm.c"; 2 | 3 | #include "../../../inc/scc.h" 4 | #include "../../cc2.h" 5 | 6 | Node * 7 | optm_dep(Node *np) 8 | { 9 | return np; 10 | } 11 | -------------------------------------------------------------------------------- /cc2/target/i386-sysv/target.mk: -------------------------------------------------------------------------------- 1 | OBJ-i386-sysv = $(OBJ) \ 2 | target/i386-sysv/cgen.o \ 3 | target/i386-sysv/optm.o \ 4 | target/i386-sysv/code.o \ 5 | target/i386-sysv/types.o 6 | -------------------------------------------------------------------------------- /cc2/target/i386-sysv/types.c: -------------------------------------------------------------------------------- 1 | static char sccsid[] = "@(#) ./cc2/arch/i386-sysv/types.c"; 2 | 3 | #include "../../../inc/scc.h" 4 | #include "../../cc2.h" 5 | 6 | 7 | Type int8type = { 8 | .flags = SIGNF | INTF, 9 | .size = 1, 10 | .align = 1 11 | }; 12 | 13 | Type int16type = { 14 | .flags = SIGNF | INTF, 15 | .size = 2, 16 | .align = 2 17 | }; 18 | 19 | Type int32type = { 20 | .flags = SIGNF | INTF, 21 | .size = 4, 22 | .align = 4 23 | }; 24 | 25 | Type int64type = { 26 | .flags = SIGNF | INTF, 27 | .size = 8, 28 | .align = 4 29 | }; 30 | 31 | Type uint8type = { 32 | .flags = INTF, 33 | .size = 1, 34 | .align = 1 35 | }; 36 | 37 | Type uint16type = { 38 | .flags = INTF, 39 | .size = 2, 40 | .align = 2 41 | }; 42 | 43 | Type uint32type = { 44 | .flags = INTF, 45 | .size = 4, 46 | .align = 2 47 | }; 48 | 49 | Type uint64type = { 50 | .flags = INTF, 51 | .size = 8, 52 | .align = 4 53 | }; 54 | 55 | Type ptrtype = { 56 | .flags = INTF, 57 | .size = 4, 58 | .align = 4 59 | }; 60 | 61 | Type booltype = { 62 | .flags = INTF, 63 | .size = 1, 64 | .align = 1 65 | }; 66 | 67 | Type float32type = { 68 | .flags = FLOATF, 69 | .size = 4, 70 | .align = 4 71 | }; 72 | 73 | Type float64type = { 74 | .flags = FLOATF, 75 | .size = 8, 76 | .align = 4 77 | }; 78 | 79 | Type float80type = { 80 | .flags = FLOATF, 81 | .size = 12, 82 | .align = 4 83 | }; 84 | 85 | Type voidtype = { 86 | .size = 0, 87 | .align = 0 88 | }; 89 | 90 | /* this type is not used in this architecture */ 91 | Type arg_type = { 92 | .size = 0, 93 | .align = 0 94 | }; 95 | -------------------------------------------------------------------------------- /cc2/target/qbe/arch.h: -------------------------------------------------------------------------------- 1 | enum asmop { 2 | ASNOP = 0, 3 | ASSTB, 4 | ASSTH, 5 | ASSTW, 6 | ASSTL, 7 | ASSTM, 8 | ASSTS, 9 | ASSTD, 10 | 11 | ASLDSB, 12 | ASLDUB, 13 | ASLDSH, 14 | ASLDUH, 15 | ASLDSW, 16 | ASLDUW, 17 | ASLDL, 18 | ASLDS, 19 | ASLDD, 20 | 21 | ASADDW, 22 | ASSUBW, 23 | ASMULW, 24 | ASMODW, 25 | ASUMODW, 26 | ASDIVW, 27 | ASUDIVW, 28 | ASSHLW, 29 | ASSHRW, 30 | ASUSHRW, 31 | ASLTW, 32 | ASULTW, 33 | ASGTW, 34 | ASUGTW, 35 | ASLEW, 36 | ASULEW, 37 | ASGEW, 38 | ASUGEW, 39 | ASEQW, 40 | ASNEW, 41 | ASBANDW, 42 | ASBORW, 43 | ASBXORW, 44 | 45 | ASADDL, 46 | ASSUBL, 47 | ASMULL, 48 | ASMODL, 49 | ASUMODL, 50 | ASDIVL, 51 | ASUDIVL, 52 | ASSHLL, 53 | ASSHRL, 54 | ASUSHRL, 55 | ASLTL, 56 | ASULTL, 57 | ASGTL, 58 | ASUGTL, 59 | ASLEL, 60 | ASULEL, 61 | ASGEL, 62 | ASUGEL, 63 | ASEQL, 64 | ASNEL, 65 | ASBANDL, 66 | ASBORL, 67 | ASBXORL, 68 | 69 | ASADDS, 70 | ASSUBS, 71 | ASMULS, 72 | ASDIVS, 73 | ASLTS, 74 | ASGTS, 75 | ASLES, 76 | ASGES, 77 | ASEQS, 78 | ASNES, 79 | 80 | ASADDD, 81 | ASSUBD, 82 | ASMULD, 83 | ASDIVD, 84 | ASLTD, 85 | ASGTD, 86 | ASLED, 87 | ASGED, 88 | ASEQD, 89 | ASNED, 90 | 91 | ASEXTBW, 92 | ASUEXTBW, 93 | ASEXTBL, 94 | ASUEXTBL, 95 | ASEXTHW, 96 | ASUEXTHW, 97 | ASEXTHL, 98 | ASUEXTHL, 99 | ASEXTWL, 100 | ASUEXTWL, 101 | 102 | ASSTOL, 103 | ASSTOW, 104 | ASDTOL, 105 | ASDTOW, 106 | 107 | ASSWTOD, 108 | ASSWTOS, 109 | ASSLTOD, 110 | ASSLTOS, 111 | 112 | ASEXTS, 113 | ASTRUNCD, 114 | 115 | ASJMP, 116 | ASBRANCH, 117 | ASRET, 118 | ASCALL, 119 | ASCALLE, 120 | ASCALLEX, 121 | ASPAR, 122 | ASPARE, 123 | ASALLOC, 124 | ASFORM, 125 | 126 | ASCOPYB, 127 | ASCOPYH, 128 | ASCOPYW, 129 | ASCOPYL, 130 | ASCOPYS, 131 | ASCOPYD, 132 | 133 | ASVSTAR, 134 | ASVARG, 135 | }; 136 | -------------------------------------------------------------------------------- /cc2/target/qbe/optm.c: -------------------------------------------------------------------------------- 1 | static char sccsid[] = "@(#) ./cc2/arch/qbe/optm.c"; 2 | 3 | #include 4 | 5 | #include "../../../inc/scc.h" 6 | #include "../../cc2.h" 7 | 8 | Node * 9 | optm_dep(Node *np) 10 | { 11 | int op = np->op; 12 | Node *p, *dst, *next = np->next; 13 | Symbol *sym, *osym; 14 | 15 | switch (op) { 16 | case OEFUN: 17 | /* 18 | * In QBE we need at the end of a basic block 19 | * a jump, so we have to ensure that the last 20 | * statement of the function is a ret, a jmp 21 | * or a branch. In the same way, QBE does 22 | * not accept labels at the end of a function 23 | * (ONOP is used for labels) so we have to add 24 | * a ret there, and in the case of branches 25 | * we need a label for the next statement 26 | */ 27 | op = (np->prev) ? np->prev->op : 0; 28 | if (!op || op == ONOP || op == OBRANCH || (op != ORET && op != OJMP)) 29 | addstmt(node(ORET), KEEPCUR); 30 | break; 31 | case OBRANCH: 32 | if (!next->label) { 33 | sym = getsym(TMPSYM); 34 | sym->kind = SLABEL; 35 | next->label = sym; 36 | } 37 | case OJMP: 38 | for (;;) { 39 | dst = np->u.sym->u.stmt; 40 | if (dst->op != OJMP) 41 | break; 42 | np->u.sym = dst->u.sym; 43 | } 44 | for (p = np->next; p; p = p->next) { 45 | if (p == dst) 46 | return NULL; 47 | if (p->op == ONOP || 48 | p->op == OBLOOP || 49 | p->op == OELOOP) { 50 | continue; 51 | } 52 | break; 53 | } 54 | break; 55 | } 56 | return np; 57 | } 58 | -------------------------------------------------------------------------------- /cc2/target/qbe_amd64-sysv/target.mk: -------------------------------------------------------------------------------- 1 | OBJ-qbe_amd64-sysv = $(OBJ) \ 2 | target/qbe/cgen.o \ 3 | target/qbe/optm.o \ 4 | target/qbe/code.o \ 5 | target/amd64-sysv/types.o 6 | -------------------------------------------------------------------------------- /cc2/target/qbe_arm64-sysv/target.mk: -------------------------------------------------------------------------------- 1 | OBJ-qbe_amd64-sysv = $(OBJ) \ 2 | target/qbe/cgen.o \ 3 | target/qbe/optm.o \ 4 | target/qbe/code.o \ 5 | target/arm64-sysv/types.o 6 | -------------------------------------------------------------------------------- /cc2/target/z80-scc/arch.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/k0gaMSX/scc/e53520a8ec6d7838423fea56e1b028ced9558f59/cc2/target/z80-scc/arch.h -------------------------------------------------------------------------------- /cc2/target/z80-scc/cgen.c: -------------------------------------------------------------------------------- 1 | static char sccsid[] = "@(#) ./cc2/arch/z80/cgen.c"; 2 | 3 | #include "arch.h" 4 | #include "../../../inc/scc.h" 5 | #include "../../cc2.h" 6 | 7 | Node * 8 | cgen(Node *np) 9 | { 10 | } 11 | 12 | /* 13 | * This is strongly influenced by 14 | * http://plan9.bell-labs.com/sys/doc/compiler.ps (/sys/doc/compiler.ps) 15 | * calculate addresability as follows 16 | * AUTO => 11 value+fp 17 | * REG => 13 reg 18 | * STATIC => 12 (value) 19 | * CONST => 20 $value 20 | */ 21 | Node * 22 | sethi(Node *np) 23 | { 24 | Node *lp, *rp; 25 | 26 | if (!np) 27 | return np; 28 | 29 | np->complex = 0; 30 | np->address = 0; 31 | lp = np->left; 32 | rp = np->right; 33 | switch (np->op) { 34 | case OAUTO: 35 | np->address = 11; 36 | break; 37 | case OREG: 38 | np->address = 13; 39 | break; 40 | case OMEM: 41 | np->address = 12; 42 | break; 43 | case OCONST: 44 | np->address = 20; 45 | break; 46 | default: 47 | sethi(lp); 48 | sethi(rp); 49 | break; 50 | } 51 | 52 | if (np->address > 10) 53 | return np; 54 | if (lp) 55 | np->complex = lp->complex; 56 | if (rp) { 57 | int d = np->complex - rp->complex; 58 | 59 | if (d == 0) 60 | ++np->complex; 61 | else if (d < 0) 62 | np->complex = rp->complex; 63 | } 64 | if (np->complex == 0) 65 | ++np->complex; 66 | return np; 67 | } 68 | -------------------------------------------------------------------------------- /cc2/target/z80-scc/optm.c: -------------------------------------------------------------------------------- 1 | static char sccsid[] = "@(#) ./cc2/arch/z80/optm.c"; 2 | 3 | #include "../../../inc/scc.h" 4 | #include "../../cc2.h" 5 | 6 | Node * 7 | optm_dep(Node *np) 8 | { 9 | return np; 10 | } 11 | -------------------------------------------------------------------------------- /cc2/target/z80-scc/target.mk: -------------------------------------------------------------------------------- 1 | OBJ-z80-scc = $(OBJ) \ 2 | target/z80-scc/cgen.o \ 3 | target/z80-scc/optm.o \ 4 | target/z80-scc/code.o \ 5 | target/z80-scc/types.o 6 | 7 | -------------------------------------------------------------------------------- /cc2/target/z80-scc/types.c: -------------------------------------------------------------------------------- 1 | static char sccsid[] = "@(#) ./cc2/arch/z80/types.c"; 2 | 3 | #include "../../../inc/scc.h" 4 | #include "../../cc2.h" 5 | 6 | 7 | Type int8type = { 8 | .flags = SIGNF | INTF, 9 | .size = 1, 10 | .align = 1 11 | }; 12 | 13 | Type int16type = { 14 | .flags = SIGNF | INTF, 15 | .size = 2, 16 | .align = 1 17 | }; 18 | 19 | Type int32type = { 20 | .flags = SIGNF | INTF, 21 | .size = 4, 22 | .align = 1 23 | }; 24 | 25 | Type int64type = { 26 | .flags = SIGNF | INTF, 27 | .size = 8, 28 | .align = 1 29 | }; 30 | 31 | Type uint8type = { 32 | .flags = INTF, 33 | .size = 1, 34 | .align = 1 35 | }; 36 | 37 | Type uint16type = { 38 | .flags = INTF, 39 | .size = 2, 40 | .align = 1 41 | }; 42 | 43 | Type uint32type = { 44 | .flags = INTF, 45 | .size = 4, 46 | .align = 1 47 | }; 48 | 49 | Type uint64type = { 50 | .flags = INTF, 51 | .size = 8, 52 | .align = 1 53 | }; 54 | 55 | Type ptrtype = { 56 | .flags = INTF, 57 | .size = 2, 58 | .align = 1 59 | }; 60 | 61 | Type booltype = { 62 | .flags = INTF, 63 | .size = 1, 64 | .align = 1 65 | }; 66 | 67 | Type float32type = { 68 | .flags = FLOATF, 69 | .size = 4, 70 | .align = 1 71 | }; 72 | 73 | Type float64type = { 74 | .flags = FLOATF, 75 | .size = 4, 76 | .align = 1 77 | }; 78 | 79 | Type float80type = { 80 | .flags = FLOATF, 81 | .size = 4, 82 | .align = 1 83 | }; 84 | 85 | Type voidtype = { 86 | .size = 0, 87 | .align = 0 88 | }; 89 | 90 | /* this types is not going to be used in this arch */ 91 | Type arg_type = { 92 | .size = 0, 93 | .align = 0 94 | }; 95 | -------------------------------------------------------------------------------- /config.mk.def: -------------------------------------------------------------------------------- 1 | # scc version 2 | VERSION = 0.1 3 | 4 | ## Customize below to fit your system 5 | # TARGETS is defined by a list of backend-arch-abi-sys. First 6 | # element of the list becomes the default target 7 | 8 | TARGETS = amd64-sysv-linux-elf \ 9 | z80-scc-none-none \ 10 | i386-sysv-linux-elf \ 11 | amd64-sysv-openbsd-elf 12 | 13 | # USEQBE selects QBE by default in the targets that support it 14 | USEQBE = 1 15 | 16 | #MKQBE enable build of qbe backends 17 | MKQBE = 1 18 | 19 | DRIVER = posix 20 | 21 | # Can be c89 or c99 22 | STD = c99 23 | 24 | # paths 25 | PREFIX = $(HOME) 26 | MANPREFIX = $(PREFIX)/share/man 27 | 28 | # scc expects to be built by a C99 compiler 29 | # if your system is not at least POSIX 2004 compatible, adjust CC 30 | # CC = c99 31 | # AR = ar 32 | AS = as 33 | 34 | SCC_CFLAGS = $(MOREFLAGS) \ 35 | $(SYSCFLAGS) \ 36 | -g \ 37 | $(CFLAGS) 38 | 39 | SCC_LDFLAGS = -L$(LIBDIR)/ -g $(LDFLAGS) 40 | 41 | .s.o: 42 | $(AS) $< -o $@ 43 | 44 | .c.o: 45 | $(CC) $(SCC_CFLAGS) -o $@ -c $< 46 | 47 | .c: 48 | $(CC) $(SCC_CFLAGS) $(SCC_LDFLAGS) -o $@ $< 49 | 50 | # helper macro to run over all the directories 51 | FORALL = +@set -e ;\ 52 | pwd=$$PWD; \ 53 | for i in $(DIRS); \ 54 | do \ 55 | cd $$i; \ 56 | $(MAKE) $@; \ 57 | cd $$pwd; \ 58 | done 59 | 60 | # system specific flags 61 | -------------------------------------------------------------------------------- /driver/Makefile: -------------------------------------------------------------------------------- 1 | .POSIX: 2 | 3 | # fallback case if DRIVER isn't defined 4 | DRIVER = posix 5 | 6 | include ../config.mk 7 | 8 | all dep clean distclean: 9 | +cd $(DRIVER) && $(MAKE) $@ 10 | -------------------------------------------------------------------------------- /driver/posix/Makefile: -------------------------------------------------------------------------------- 1 | .POSIX: 2 | 3 | LIBDIR = ../../lib/scc 4 | include ../../config.mk 5 | include $(LIBDIR)/libdep.mk 6 | 7 | OBJ = scc.o 8 | HDR = config.h \ 9 | ../../inc/scc.h \ 10 | ../../inc/arg.h \ 11 | ../../inc/syslibs.h \ 12 | ../../inc/ldflags.h 13 | 14 | all: scc cpp 15 | mkdir -p ../../rootdir/bin 16 | cp scc cpp ../../rootdir/bin/ 17 | 18 | dep: 19 | PREFIX=$(PREFIX) USEQBE=$(USEQBE) ./gendep.sh $(TARGETS) 20 | 21 | $(OBJ): $(HDR) 22 | 23 | scc: $(OBJ) $(LIBDIR)/libscc.a 24 | $(CC) $(SCC_LDFLAGS) $(OBJ) -lscc -o $@ 25 | 26 | cpp: cpp.sh config.h 27 | set -x ;\ 28 | trap "rm -f $$$$.sh" 0 2 3;\ 29 | rm -f $@ ;\ 30 | sed "s%@PREFIX@%$(PREFIX)%" < cpp.sh > $$$$.sh && \ 31 | chmod +x $$$$.sh && \ 32 | mv $$$$.sh $@ 33 | 34 | $(LIBDIR)/libscc.a: 35 | +cd $(LIBDIR) && $(MAKE) 36 | 37 | clean: 38 | rm -f $(OBJ) 39 | rm -f scc 40 | rm -f scpp 41 | 42 | distclean: clean 43 | rm -f config.h 44 | 45 | -------------------------------------------------------------------------------- /driver/posix/cpp.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | SCCPREFIX=${SCCPREFIX:-@PREFIX@} 4 | ${SCCPREFIX}/bin/scc -E $@ 5 | -------------------------------------------------------------------------------- /driver/posix/gendep.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | rm -f config.h 6 | trap "rm -f $$.h" 0 2 3 7 | 8 | PREFIX=${PREFIX-$HOME} 9 | USEQBE=${USEQBE:-1} 10 | 11 | echo $@ | 12 | (IFS='- ' read arch abi sys format r 13 | echo \#define PREFIX \"$PREFIX\" 14 | echo \#define USEQBE $USEQBE 15 | echo \#define ARCH \"$arch\" 16 | echo \#define SYS \"$sys\" 17 | echo \#define ABI \"$abi\" 18 | echo \#define FORMAT \"$format\") > $$.h && mv $$.h config.h 19 | -------------------------------------------------------------------------------- /inc/Makefile: -------------------------------------------------------------------------------- 1 | .POSIX: 2 | 3 | include ../config.mk 4 | 5 | HDR = ldflags.h sysincludes.h syslibs.h 6 | 7 | all: 8 | 9 | dep: $(HDR) 10 | 11 | ldflags.h: 12 | rm -f $@ ; \ 13 | trap "rm -f $$$$.h" 0 2 3; \ 14 | cat < ldflags.def.h > $$$$.h; \ 15 | mv $$$$.h $@ 16 | 17 | sysincludes.h: 18 | rm -f $@ ; \ 19 | trap "rm -f $$$$.h" 0 2 3; \ 20 | sed 's,PREFIX,"$(PREFIX)",g' < sysincludes.def.h > $$$$.h && \ 21 | mv $$$$.h $@ 22 | 23 | syslibs.h: 24 | rm -f $@ ; \ 25 | trap "rm -f $$$$.h" 0 2 3; \ 26 | sed 's,PREFIX,"$(PREFIX)",g' < syslibs.def.h > $$$$.h && \ 27 | mv $$$$.h $@ 28 | 29 | clean: 30 | distclean: 31 | rm -f $(HDR) 32 | -------------------------------------------------------------------------------- /inc/ar.h: -------------------------------------------------------------------------------- 1 | 2 | #define ARMAG "!\n" /* ar "magic number" */ 3 | #define SARMAG 8 /* strlen(ARMAG); */ 4 | #define ARFMAG "`\n" 5 | 6 | struct ar_hdr { 7 | char ar_name[16]; /* name */ 8 | char ar_date[12]; /* modification time */ 9 | char ar_uid[6]; /* user id */ 10 | char ar_gid[6]; /* group id */ 11 | char ar_mode[8]; /* octal file permissions */ 12 | char ar_size[10]; /* size in bytes */ 13 | char ar_fmag[2]; /* consistency check */ 14 | }; 15 | -------------------------------------------------------------------------------- /inc/arg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copy me if you can. 3 | * by 20h 4 | */ 5 | 6 | #ifndef ARG_H__ 7 | #define ARG_H__ 8 | 9 | extern char *argv0; 10 | 11 | /* use main(int argc, char *argv[]) */ 12 | #define ARGBEGIN \ 13 | for (argv0 = *argv, argv++, argc--;\ 14 | argv[0];\ 15 | argc--, argv++) {\ 16 | if (argv[0][0] == '-') {\ 17 | char argc_;\ 18 | char **argv_;\ 19 | int brk_;\ 20 | if (argv[0][1] == '-' && argv[0][2] == '\0') {\ 21 | argv++;\ 22 | argc--;\ 23 | break;\ 24 | }\ 25 | for (brk_ = 0, argv[0]++, argv_ = argv;\ 26 | argv[0][0] && !brk_;\ 27 | argv[0]++) {\ 28 | if (argv_ != argv)\ 29 | break;\ 30 | argc_ = argv[0][0];\ 31 | switch (argc_) 32 | 33 | #define ARGOPERAND \ 34 | }\ 35 | } else if (argv[0][0] != '\0') {\ 36 | { 37 | 38 | #define ARGEND \ 39 | }\ 40 | } else {\ 41 | break;\ 42 | }\ 43 | } 44 | 45 | #define ARGC() argc_ 46 | 47 | #define ARGOP() argv[0] 48 | 49 | #define ARGNUMF() (brk_ = 1, estrtonum(argv[0], 0, INT_MAX)) 50 | 51 | #define EARGF(x) \ 52 | ((argv[0][1] == '\0' && argv[1] == NULL) ?\ 53 | ((x), abort(), (char *)0) :\ 54 | (brk_ = 1, (argv[0][1] != '\0') ?\ 55 | (&argv[0][1]) :\ 56 | (argc--, argv++, argv[0]))) 57 | 58 | #define ARGF() \ 59 | ((argv[0][1] == '\0' && argv[1] == NULL)?\ 60 | (char *)0 :\ 61 | (brk_ = 1, (argv[0][1] != '\0')?\ 62 | (&argv[0][1]) :\ 63 | (argc--, argv++, argv[0]))) 64 | 65 | #define LNGARG() &argv[0][0] 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /inc/ldflags.def.h: -------------------------------------------------------------------------------- 1 | char *ldflags[] = { 2 | "-static", 3 | /* on OpenBSD, disable pie */ 4 | /* "-nopie", */ 5 | NULL 6 | }; 7 | -------------------------------------------------------------------------------- /inc/myro.h: -------------------------------------------------------------------------------- 1 | 2 | #define MYROHDR_SIZ 48 3 | #define MYROSECT_SIZ 24 4 | #define MYROSYM_SIZ 26 5 | #define MYROREL_SIZ 16 6 | 7 | #define MYROMAGIC_SIZ 4 8 | #define MYROMAGIC "uobj" 9 | 10 | #define MYROMAXSEC 254 11 | 12 | struct myrohdr { 13 | char magic[4]; 14 | unsigned long format; 15 | unsigned long long entry; 16 | unsigned long long strsize; 17 | unsigned long long secsize; 18 | unsigned long long symsize; 19 | unsigned long long relsize; 20 | }; 21 | 22 | struct myrosect { 23 | unsigned long name; 24 | unsigned short flags; 25 | unsigned char fill; 26 | unsigned char aligment; 27 | unsigned long long offset; 28 | unsigned long long len; 29 | }; 30 | 31 | struct myrosym { 32 | unsigned long name; 33 | unsigned long type; 34 | unsigned char section; 35 | unsigned char flags; 36 | unsigned long long offset; 37 | unsigned long long len; 38 | }; 39 | 40 | struct myrorel { 41 | unsigned long id; 42 | unsigned char flags; 43 | unsigned char size; 44 | unsigned char nbits; 45 | unsigned char shift; 46 | unsigned long long offset; 47 | }; 48 | 49 | enum myrosecflg { 50 | MYROSEC_READ = 1 << 0, 51 | MYROSEC_WRITE = 1 << 1, 52 | MYROSEC_EXEC = 1 << 2, 53 | MYROSEC_LOAD = 1 << 3, 54 | MYROSEC_FILE = 1 << 4, 55 | MYROSEC_ABS = 1 << 5, 56 | }; 57 | 58 | enum myrosymflg { 59 | MYROSYM_COMMON = 1 << 0, 60 | MYROSYM_EXTERN = 1 << 1, 61 | MYROSYM_GLOBAL = 1 << 2, 62 | MYROSYM_UNDEF = 1 << 3, 63 | MYROSYM_ABS = 1 << 4, 64 | }; 65 | 66 | enum myrosectnames { 67 | MYRO_TEXT = 0, 68 | MYRO_DATA = 1, 69 | MYRO_BSS = 2, 70 | MYRO_ABS = 3, 71 | }; 72 | 73 | extern int wrmyrohdr(FILE *fp, struct myrohdr *hdr); 74 | extern int wrmyrosec(FILE *fp, struct myrosect *sect); 75 | extern int wrmyrosym(FILE *fp, struct myrosym *sym); 76 | extern int wrmyrorel(FILE *fp, struct myrorel *rel); 77 | extern int rdmyrohdr(FILE *fp, struct myrohdr *hdr); 78 | extern int rdmyrosec(FILE *fp, struct myrosect *sect); 79 | extern int rdmyrosym(FILE *fp, struct myrosym *sym); 80 | extern int rdmyrorel(FILE *fp, struct myrorel *rel); 81 | -------------------------------------------------------------------------------- /inc/scc.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | extern int debug; 4 | 5 | #ifndef NDEBUG 6 | #define DBG(...) dbg(__VA_ARGS__) 7 | #define DBGON() (debug = 1) 8 | #else 9 | #define DBG(...) 10 | #define DBGON() 11 | #endif 12 | 13 | #define TINT long long 14 | #define TUINT unsigned long long 15 | #define TUINT_MAX ULLONG_MAX 16 | #define TINT_MAX LLONG_MAX 17 | #define TFLOAT double 18 | 19 | struct items { 20 | char **s; 21 | unsigned n; 22 | }; 23 | 24 | typedef struct alloc Alloc; 25 | 26 | extern void die(const char *fmt, ...); 27 | extern void dbg(const char *fmt, ...); 28 | extern void newitem(struct items *items, char *item); 29 | extern void *xmalloc(size_t size); 30 | extern void *xcalloc(size_t nmemb, size_t size); 31 | extern char *xstrdup(const char *s); 32 | extern void *xrealloc(void *buff, register size_t size); 33 | extern Alloc *alloc(size_t size, size_t nmemb); 34 | extern void dealloc(Alloc *allocp); 35 | extern void *new(Alloc *allocp); 36 | extern void delete(Alloc *allocp, void *p); 37 | extern int casecmp(const char *s1, const char *s2); 38 | extern int lpack(unsigned char *dst, char *fmt, ...); 39 | extern int lunpack(unsigned char *src, char *fmt, ...); 40 | -------------------------------------------------------------------------------- /inc/sysincludes.def.h: -------------------------------------------------------------------------------- 1 | char *sysincludes[] = { 2 | PREFIX "/include/scc/" , 3 | PREFIX "/include/scc/bits/" TARGET "/", 4 | /* configure below your standard sys include paths */ 5 | PREFIX "/include/", 6 | PREFIX "/local/include/", 7 | NULL 8 | }; 9 | -------------------------------------------------------------------------------- /inc/syslibs.def.h: -------------------------------------------------------------------------------- 1 | char *syslibs[] = { 2 | PREFIX "/lib/scc/" , 3 | /* configure below your standard sys include paths */ 4 | PREFIX "/lib/", 5 | PREFIX "/local/lib/", 6 | NULL 7 | }; 8 | -------------------------------------------------------------------------------- /lib/Makefile: -------------------------------------------------------------------------------- 1 | .POSIX: 2 | 3 | include ../config.mk 4 | 5 | DIRS = scc 6 | 7 | all dep clean distclean: 8 | $(FORALL) 9 | -------------------------------------------------------------------------------- /lib/c/Makefile: -------------------------------------------------------------------------------- 1 | .POSIX: 2 | 3 | all dep clean distclean: 4 | +cd target && $(MAKE) $@ 5 | -------------------------------------------------------------------------------- /lib/c/__abs.c: -------------------------------------------------------------------------------- 1 | 2 | #define __USE_MACROS 3 | #include 4 | 5 | int __abs; 6 | -------------------------------------------------------------------------------- /lib/c/__getc.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include "syscall.h" 5 | #undef getc 6 | 7 | int 8 | __getc(FILE *fp) 9 | { 10 | int cnt; 11 | 12 | if (fp->flags & (_IOEOF | _IOERR)) 13 | return EOF; 14 | 15 | if ((fp->flags & (_IOREAD | _IORW)) == 0) { 16 | fp->flags |= _IOERR; 17 | errno = EBADF; 18 | return EOF; 19 | } 20 | 21 | if (fp->flags & _IOSTRG) { 22 | fp->flags |= _IOEOF; 23 | return EOF; 24 | } 25 | 26 | if ((cnt = _read(fp->fd, fp->buf, fp->len)) <= 0) { 27 | fp->flags |= (cnt == 0) ? _IOEOF : _IOERR; 28 | return EOF; 29 | } 30 | 31 | fp->flags |= _IOREAD; 32 | fp->rp = fp->buf; 33 | fp->wp = fp->buf + cnt; 34 | 35 | return *fp->rp++; 36 | } 37 | -------------------------------------------------------------------------------- /lib/c/__labs.c: -------------------------------------------------------------------------------- 1 | 2 | #define __USE_MACROS 3 | #include 4 | 5 | long __labs; 6 | -------------------------------------------------------------------------------- /lib/c/__llabs.c: -------------------------------------------------------------------------------- 1 | 2 | #define __USE_MACROS 3 | #include 4 | 5 | long long __llabs; 6 | -------------------------------------------------------------------------------- /lib/c/__putc.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include "syscall.h" 6 | 7 | int 8 | _fflush(FILE *fp) 9 | { 10 | int lnbuf = fp->flags & _IOLBF; 11 | size_t cnt; 12 | 13 | cnt = ((lnbuf) ? fp->lp : fp->wp) - fp->buf; 14 | 15 | if (_write(fp->fd, fp->buf, cnt) != cnt) { 16 | fp->flags |= _IOERR; 17 | return EOF; 18 | } 19 | fp->rp = fp->wp = fp->buf; 20 | 21 | return 0; 22 | } 23 | 24 | int 25 | fflush(FILE *fp) 26 | { 27 | int err = 0; 28 | 29 | if (fp) 30 | return _flsbuf(fp); 31 | 32 | for (fp = __iob; fp < &__iob[FOPEN_MAX]; ++fp) { 33 | if ((fp->flags & _IOWRITE) == 0 && _flush(fp)) 34 | err = EOF; 35 | } 36 | return err; 37 | } 38 | 39 | static void 40 | cleanup(void) 41 | { 42 | fflush(NULL); 43 | } 44 | 45 | int 46 | __putc(int ch, FILE *fp) 47 | { 48 | static int first = 1; 49 | 50 | if (fp->flags & _IOERR) 51 | return EOF; 52 | 53 | if (fp->flags & _IOREAD) { 54 | fp->flags |= _IOERR; 55 | errno = EBADF; 56 | return EOF; 57 | } 58 | 59 | if (fp->flags & _IOSTRG) { 60 | fp->flags |= _IOERR; 61 | return EOF; 62 | } 63 | 64 | if (first) { 65 | if (atexit(cleanup)) { 66 | fp->flags |= _IOERR; 67 | errno = ENOMEM; 68 | return EOF; 69 | } 70 | first = 0; 71 | } 72 | 73 | if (fp->flags & _IOLBF) { 74 | if (fp->lp == fp->rp && _flush(fp)) 75 | return EOF; 76 | *fp->lp++ = ch; 77 | if (ch == '\n' && flsbuf(fp)) 78 | return EOF; 79 | } else { 80 | if (fp->wp == fp->rp && _flsbuf(fp)) 81 | return EOF; 82 | *fp->wp++ = ch; 83 | } 84 | 85 | done: 86 | fp->flags |= _IOWRITE; 87 | return ch & 0xFF; 88 | } 89 | -------------------------------------------------------------------------------- /lib/c/_fpopen.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include "syscall.h" 6 | #undef fopen 7 | 8 | FILE * 9 | _fpopen(const char * restrict fname, 10 | const char * restrict mode, 11 | FILE * restrict fp) 12 | { 13 | int i, flags, fd, rw, bin; 14 | 15 | flags = rw = bin = 0; 16 | 17 | if (mode[0] == '\0) 18 | goto einval; 19 | if (mode[i = 1] == '+') 20 | i++, rw = 1; 21 | if (mode[i] == 'b') 22 | i++, bin = 1; 23 | if (mode[i] != '\0') 24 | goto einval; 25 | 26 | switch (mode[0]) { 27 | case 'a': 28 | flags |= O_APPEND | O_CREAT; 29 | goto wrflags; 30 | case 'w': 31 | flags |= O_TRUNC | O_CREAT; 32 | wrflags: 33 | flags |= (rw) ? O_RDWR : O_WRONLY; 34 | break; 35 | case 'r': 36 | flags = (rw) ? O_RDWR : O_RDONLY; 37 | break; 38 | default: 39 | einval: 40 | errno = EINVAL; 41 | return NULL; 42 | } 43 | 44 | if ((fd = _open(name, flags)) < 0) 45 | return NULL; 46 | 47 | if (fp->buf == NULL) { 48 | if ((fp->buf = malloc(BUFSIZ)) == NULL) { 49 | close(fd); 50 | errno = ENOMEM; 51 | return NULL; 52 | } 53 | fp->flags |= _IOALLOC; 54 | } 55 | fp->fd = fd; 56 | 57 | if (!bin) 58 | fp->flags |= _IOTEXT; 59 | 60 | if (flags & O_RDWR) 61 | fp->flags |= _IORW; 62 | else if (flags & O_RDONLY) 63 | fp->flags |= _IOREAD; 64 | else 65 | fp->flags |= _IOWRITE; 66 | 67 | fp->lp = fp->rp = fp->wp = NULL; 68 | 69 | return fp; 70 | } 71 | -------------------------------------------------------------------------------- /lib/c/abort.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #undef abort 6 | 7 | void 8 | abort(void) 9 | { 10 | raise(SIGABRT); 11 | _Exit(127); 12 | } 13 | -------------------------------------------------------------------------------- /lib/c/abs.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #undef abs 4 | 5 | int 6 | abs(int n) 7 | { 8 | return (n < 0) ? -n : n; 9 | } 10 | -------------------------------------------------------------------------------- /lib/c/assert.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void __assert(char *exp, char *file, long line) 6 | { 7 | fprintf(stderr, "%s:%ld: assertion failed '%s'\n", file, line, exp); 8 | abort(); 9 | } 10 | -------------------------------------------------------------------------------- /lib/c/atexit.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #undef atexit 4 | 5 | extern void (*_exitf[_ATEXIT_MAX])(void); 6 | extern unsigned _exitn; 7 | 8 | int 9 | atexit(void (*fun)(void)) 10 | { 11 | if (_exitn == _ATEXIT_MAX) { 12 | errno = ENOMEM; 13 | return -1; 14 | } 15 | _exitf[_exitn++] = fun; 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /lib/c/atoi.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #undef atoi 4 | 5 | int 6 | atoi(const char *s) 7 | { 8 | int n, sign = -1; 9 | 10 | while (isspace(*s)) 11 | ++s; 12 | 13 | switch (*s) { 14 | case '-': 15 | sign = 1; 16 | case '+': 17 | ++s; 18 | } 19 | 20 | /* Compute n as a negative number to avoid overflow on INT_MIN */ 21 | for (n = 0; isdigit(*s); ++s) 22 | n = 10*n - (*s - '0'); 23 | 24 | return sign * n; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /lib/c/atol.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #undef atol 4 | 5 | long 6 | atol(const char *s) 7 | { 8 | int sign = -1; 9 | long n; 10 | 11 | while (isspace(*s)) 12 | ++s; 13 | 14 | switch (*s) { 15 | case '-': 16 | sign = 1; 17 | case '+': 18 | ++s; 19 | } 20 | 21 | /* Compute n as a negative number to avoid overflow on LONG_MIN */ 22 | for (n = 0; isdigit(*s); ++s) 23 | n = 10*n - (*s - '0'); 24 | 25 | return sign * n; 26 | } 27 | 28 | -------------------------------------------------------------------------------- /lib/c/atoll.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #undef atoll 4 | 5 | long long 6 | atoll(const char *s) 7 | { 8 | int sign = -1; 9 | long long n; 10 | 11 | while (isspace(*s)) 12 | ++s; 13 | 14 | switch (*s) { 15 | case '-': 16 | sign = 1; 17 | case '+': 18 | ++s; 19 | } 20 | 21 | /* Compute n as a negative number to avoid overflow on LLONG_MIN */ 22 | for (n = 0; isdigit(*s); ++s) 23 | n = 10*n - (*s - '0'); 24 | 25 | return sign * n; 26 | } 27 | 28 | -------------------------------------------------------------------------------- /lib/c/bsearch.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | void * 5 | bsearch(const void *key, const void *ary, size_t n, size_t size, 6 | int (*cmp)(const void *, const void *)) 7 | { 8 | int t; 9 | size_t mid, low, high; 10 | const char *cur, *base = ary; 11 | 12 | low = 0; 13 | high = n - 1; 14 | while (low <= high) { 15 | mid = low + (high - low) / 2; 16 | cur = base + mid*size; 17 | 18 | if ((t == (*cmp)(key, cur)) == 0) 19 | return (void *) cur; 20 | else if (t > 0) 21 | low = mid + 1; 22 | else 23 | high = mid - 1; 24 | } 25 | 26 | return NULL; 27 | } 28 | -------------------------------------------------------------------------------- /lib/c/calloc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void * 5 | calloc(size_t nmemb, size_t size) 6 | { 7 | size_t nbytes; 8 | void *mem; 9 | 10 | if (!nmemb || !size || nmemb > (size_t)-1/size) 11 | return NULL; 12 | 13 | nbytes = nmemb * size; 14 | if ((mem = malloc(nbytes)) == NULL) 15 | return NULL; 16 | return memset(mem, 0, nbytes); 17 | } 18 | -------------------------------------------------------------------------------- /lib/c/clearerr.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #undef clearerr 4 | 5 | void 6 | clearerr(FILE *fp) 7 | { 8 | fp->flags &= ~(_IOERR | _IOEOF); 9 | } 10 | -------------------------------------------------------------------------------- /lib/c/ctype.c: -------------------------------------------------------------------------------- 1 | #define __USE_MACROS 2 | #include 3 | #undef ctype 4 | 5 | int __ctmp; 6 | 7 | /* __ctype is shifted by one to match EOF */ 8 | unsigned char __ctype[257] = { 9 | 0, /* EOF */ 10 | _C,_C,_C,_C,_C,_C,_C,_C, /* 0-7 */ 11 | _C,_C|_S,_C|_S,_C|_S,_C|_S,_C|_S,_C,_C, /* 8-15 */ 12 | _C,_C,_C,_C,_C,_C,_C,_C, /* 16-23 */ 13 | _C,_C,_C,_C,_C,_C,_C,_C, /* 24-31 */ 14 | _S|_SP,_P,_P,_P,_P,_P,_P,_P, /* 32-39 */ 15 | _P,_P,_P,_P,_P,_P,_P,_P, /* 40-47 */ 16 | _D,_D,_D,_D,_D,_D,_D,_D, /* 48-55 */ 17 | _D,_D,_P,_P,_P,_P,_P,_P, /* 56-63 */ 18 | _P,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U, /* 64-71 */ 19 | _U,_U,_U,_U,_U,_U,_U,_U, /* 72-79 */ 20 | _U,_U,_U,_U,_U,_U,_U,_U, /* 80-87 */ 21 | _U,_U,_U,_P,_P,_P,_P,_P, /* 88-95 */ 22 | _P,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L, /* 96-103 */ 23 | _L,_L,_L,_L,_L,_L,_L,_L, /* 104-111 */ 24 | _L,_L,_L,_L,_L,_L,_L,_L, /* 112-119 */ 25 | _L,_L,_L,_P,_P,_P,_P,_C, /* 120-127 */ 26 | }; 27 | -------------------------------------------------------------------------------- /lib/c/exit.c: -------------------------------------------------------------------------------- 1 | #include 2 | #undef exit 3 | 4 | void (*_exitf[_ATEXIT_MAX])(void); 5 | unsigned _exitn; 6 | 7 | void 8 | exit(int status) 9 | { 10 | while (_exitn > 0) 11 | (*_exitf[--_exitn])(); 12 | _Exit(status); 13 | } 14 | -------------------------------------------------------------------------------- /lib/c/fclose.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #undef fclose 4 | 5 | int 6 | fclose(FILE *fp) 7 | { 8 | int r = EOF; 9 | 10 | if ((fp->flags & _IOSTRG) == 0 && 11 | fp->flags & (_IOWRITE | _IOREAD | _IOWR)) { 12 | r = 0; 13 | if (fflush(fp) == EOF) 14 | r = EOF; 15 | if (close(fp->fd) < 0) 16 | r = EOF; 17 | } 18 | 19 | if (fp->flags & _IOALLOC) { 20 | free(fp->buf); 21 | fp->buf = NULL; 22 | } 23 | 24 | fp->flags &= ~(_IOWRITE | _IOREAD | _IOWR | 25 | _IOERR | _IOEOF | 26 | _IOALLOC | 27 | _IOTXT | 28 | _IOSTRG); 29 | 30 | return r; 31 | } 32 | -------------------------------------------------------------------------------- /lib/c/feof.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #undef feof 4 | 5 | int 6 | feof(FILE *fp) 7 | { 8 | return fp->flags & _IOEOF; 9 | } 10 | -------------------------------------------------------------------------------- /lib/c/ferror.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #undef ferror 4 | 5 | int 6 | ferror(FILE *fp) 7 | { 8 | return fp->flags & _IOERR; 9 | } 10 | -------------------------------------------------------------------------------- /lib/c/fgetc.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #undef fgetc 4 | 5 | int 6 | fgetc(FILE *fp) 7 | { 8 | return getc(fp); 9 | } 10 | -------------------------------------------------------------------------------- /lib/c/fgets.c: -------------------------------------------------------------------------------- 1 | #include 2 | #undef fgets 3 | 4 | char * 5 | fgets(char *s, int n, FILE *fp) 6 | { 7 | int ch; 8 | char *t = s; 9 | 10 | while (--n > 0 && (ch = getc(fp)) != EOF) { 11 | if ((*t++ = ch) == '\n') 12 | break; 13 | } 14 | if (ch == EOF && s == t) 15 | return NULL; 16 | *t = '\0'; 17 | 18 | return s; 19 | } 20 | -------------------------------------------------------------------------------- /lib/c/fopen.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #undef fopen 5 | 6 | FILE * 7 | fopen(const char * restrict name, const char * restrict mode) 8 | { 9 | FILE *fp; 10 | 11 | for (fp = __iob; fp < &__iob[FILE_MAX]; ++fp) { 12 | if (fp->flags & (_IOREAD | _IOWRITE | _IORW) == 0) 13 | break; 14 | } 15 | if (fp == &__iob[FILE_MAX]) { 16 | errno = ENOMEM; 17 | return NULL; 18 | } 19 | return _fpopen(name, mode, fp); 20 | } 21 | -------------------------------------------------------------------------------- /lib/c/fprintf.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #undef fprintf 4 | 5 | int 6 | fprintf(FILE * restrict fp, const char * restrict fmt, ...) 7 | { 8 | va_list va; 9 | int cnt; 10 | 11 | va_start(va, fmt); 12 | cnt = vfprintf(fp, fmt, va); 13 | va_end(va); 14 | return cnt; 15 | } 16 | -------------------------------------------------------------------------------- /lib/c/fputc.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #undef fputc 4 | 5 | int 6 | fputc(int c, FILE *fp) 7 | { 8 | return putc(c, fp); 9 | } 10 | -------------------------------------------------------------------------------- /lib/c/fputs.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | int 5 | fputs(const char * restrict bp, FILE * restrict fp) 6 | { 7 | int r, ch; 8 | 9 | while (ch = *bp++) 10 | r = putc(ch, fp); 11 | return r; 12 | } 13 | -------------------------------------------------------------------------------- /lib/c/fread.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #undef fread 4 | 5 | size_t 6 | fread(void * restrict ptr, size_t size, size_t nmemb, 7 | FILE * restrict fp) 8 | { 9 | unsigned char *bp = ptr; 10 | size_t n, i; 11 | 12 | if (size == 0) 13 | return 0; 14 | 15 | for (n = 0; n < nmemb; n++) { 16 | i = size; 17 | do { 18 | if ((*bp++ = getc(fp)) == EOF) 19 | return n; 20 | } while (--i); 21 | } 22 | 23 | return n; 24 | } 25 | -------------------------------------------------------------------------------- /lib/c/freopen.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #undef freopen 4 | 5 | FILE * 6 | freopen(const char * restrict name, const char * restrict mode, 7 | FILE * restrict fp) 8 | { 9 | if (fclose(fp) == EOF) 10 | return NULL; 11 | return _fpopen(name, mode, fp); 12 | } 13 | -------------------------------------------------------------------------------- /lib/c/fseek.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "syscall.h" 4 | #undef fseek 5 | 6 | int 7 | fseek(FILE *fp, long off, int whence) 8 | { 9 | if (fp->flags & _IOERR) 10 | return EOF; 11 | 12 | if ((fp->flags & _IOWRITE) && fflush(fp)) 13 | return -1; 14 | else if (whence == SEEK_CUR && (fp->flags & _IOREAD)) 15 | off -= fp->wp - fp->rd; 16 | 17 | if (_seek(fp->fd, off, type) < 0) { 18 | fp->flags |= _IOERR; 19 | return EOF; 20 | } 21 | 22 | if (fp->flags & _IORW) 23 | fp->flags &= ~(_IOREAD | _IOWRITE); 24 | fp->flags &= ~_IOEOF; 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /lib/c/fwrite.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #undef fwrite 4 | 5 | size_t 6 | fwrite(const void * restrict ptr, size_t size, size_t nmemb, 7 | FILE * restrict fp) 8 | { 9 | const unsigned char *bp = ptr; 10 | size_t n, i; 11 | 12 | if (size == 0) 13 | return 0; 14 | 15 | for (n = 0; n < nmemb; n++) { 16 | i = size; 17 | do 18 | putc(*bp++, fp); 19 | while (--i); 20 | if (ferror(fp)) 21 | break; 22 | } 23 | 24 | return n; 25 | } 26 | -------------------------------------------------------------------------------- /lib/c/getc.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #undef getc 4 | 5 | int 6 | getc(FILE *fp) 7 | { 8 | return (fp->rp >= fp->wp) ? __getc(fp) : *fp->rp++; 9 | } 10 | -------------------------------------------------------------------------------- /lib/c/getchar.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #undef getchar 4 | 5 | int 6 | getchar(void) 7 | { 8 | return getc(stdin); 9 | } 10 | -------------------------------------------------------------------------------- /lib/c/gets.c: -------------------------------------------------------------------------------- 1 | #include 2 | #undef gets 3 | 4 | char * 5 | gets(char *s) 6 | { 7 | int ch; 8 | char *t = s; 9 | 10 | while ((ch = getc(stdin)) != EOF && ch != '\n') 11 | *t++ = ch; 12 | if (ch == EOF && s == t) 13 | return NULL; 14 | *t = '\0'; 15 | 16 | return s; 17 | } 18 | -------------------------------------------------------------------------------- /lib/c/include/assert.h: -------------------------------------------------------------------------------- 1 | 2 | void __assert(char *exp, char *file, long line); 3 | 4 | #undef assert 5 | #ifndef NDEBUG 6 | # define assert(exp) ((exp) ? (void) 0 : __assert(#exp, __FILE__, __LINE__)) 7 | #else 8 | # define assert(exp) ((void)0) 9 | #endif 10 | 11 | -------------------------------------------------------------------------------- /lib/c/include/bits/amd64-sysv/arch/limits.h: -------------------------------------------------------------------------------- 1 | #define SCHAR_MAX 0x7F 2 | #define SCHAR_MIN (-SCHAR_MIN-1) 3 | #define CHAR_MAX 0x7F 4 | #define CHAR_MIN (-CHAR_MAX-1) 5 | #define UCHAR_MAX 0xFF 6 | #define SHRT_MAX 0x7FFF 7 | #define SHRT_MIN (-SHRT_MAX-1) 8 | #define USHRT_MAX 0xFFFF 9 | #define INT_MAX 0x7FFFFFFF 10 | #define INT_MIN (-INT_MAX-1) 11 | #define UINT_MAX 0xFFFFFFFF 12 | #define LONG_MAX 0x7FFFFFFFFFFFFFFF 13 | #define LONG_MIN (-LONG_MAX-1) 14 | #define ULONG_MAX 0xFFFFFFFFFFFFFFFF 15 | #define LLONG_MAX 0x7FFFFFFFFFFFFFFF 16 | #define LLONG_MIN (-LLONG_MAX-1) 17 | #define ULLONG_MAX 0xFFFFFFFFFFFFFFFF 18 | -------------------------------------------------------------------------------- /lib/c/include/bits/amd64-sysv/arch/signal.h: -------------------------------------------------------------------------------- 1 | typedef int sig_atomic_t; 2 | 3 | #define SIG_ERR -1 4 | #define SIG_DFL 0 5 | #define SIG_IGN 1 6 | 7 | #define SIGHUP 1 8 | #define SIGINT 2 9 | #define SIGQUIT 3 10 | #define SIGILL 4 11 | #define SIGABRT 6 12 | #define SIGFPE 8 13 | #define SIGKILL 9 14 | #define SIGUSR1 10 15 | #define SIGSEGV 11 16 | #define SIGUSR2 12 17 | #define SIGPIPE 13 18 | #define SIGALRM 14 19 | #define SIGTERM 15 20 | #define SIGCHLD 17 21 | #define SIGCONT 18 22 | #define SIGSTOP 19 23 | #define SIGSSTP 20 24 | #define SIGTTIN 21 25 | #define SIGTTOU 22 26 | 27 | #define __NR_SIGNALS 23 28 | -------------------------------------------------------------------------------- /lib/c/include/bits/amd64-sysv/arch/stddef.h: -------------------------------------------------------------------------------- 1 | #ifndef _SIZET 2 | typedef unsigned long size_t; 3 | #define _SIZET 4 | #endif 5 | 6 | #ifndef _WCHAR_T 7 | typedef int wchar_t; 8 | #define _WCHAR_T 9 | #endif 10 | 11 | #ifndef _PTRDIFF_T 12 | typedef long ptrdiff_t; 13 | #define _PTRDIFF_T 14 | #endif 15 | -------------------------------------------------------------------------------- /lib/c/include/bits/amd64-sysv/arch/stdio.h: -------------------------------------------------------------------------------- 1 | #ifndef _SIZET 2 | typedef unsigned long size_t; 3 | #define _SIZET 4 | #endif 5 | 6 | #define BUFSIZ 512 7 | #define FILENAME_MAX 256 8 | #define FOPEN_MAX 16 9 | 10 | #define TMP_MAX 25 11 | #define L_tmpnam 256 12 | 13 | typedef int fpos_t; 14 | -------------------------------------------------------------------------------- /lib/c/include/bits/amd64-sysv/arch/stdlib.h: -------------------------------------------------------------------------------- 1 | #ifndef _SIZET 2 | typedef unsigned long size_t; 3 | #define _SIZET 4 | #endif 5 | 6 | #define EXIT_FAILURE 1 7 | #define EXIT_SUCCESS 0 8 | 9 | #ifndef _WCHAR_T 10 | typedef int wchar_t; 11 | #define _WCHAR_T 12 | #endif 13 | 14 | #define _ALIGNTYPE long double 15 | -------------------------------------------------------------------------------- /lib/c/include/bits/amd64-sysv/arch/string.h: -------------------------------------------------------------------------------- 1 | #ifndef _SIZET 2 | typedef unsigned long size_t; 3 | #endif 4 | -------------------------------------------------------------------------------- /lib/c/include/bits/amd64-sysv/arch/time.h: -------------------------------------------------------------------------------- 1 | #ifndef _SIZET 2 | typedef unsigned long size_t; 3 | #define _SIZET 4 | #endif 5 | 6 | typedef long int time_t; 7 | -------------------------------------------------------------------------------- /lib/c/include/bits/i386-sysv/arch/limits.h: -------------------------------------------------------------------------------- 1 | #define SCHAR_MAX 0x7F 2 | #define SCHAR_MIN (-SCHAR_MIN-1) 3 | #define CHAR_MAX 0x7F 4 | #define CHAR_MIN (-CHAR_MAX-1) 5 | #define UCHAR_MAX 0xFF 6 | #define SHRT_MAX 0x7FFF 7 | #define SHRT_MIN (-SHRT_MAX-1) 8 | #define USHRT_MAX 0xFFFF 9 | #define INT_MAX 0x7FFFFFFF 10 | #define INT_MIN (-INT_MAX-1) 11 | #define UINT_MAX 0xFFFFFFFF 12 | #define LONG_MAX 0x7FFFFFFF 13 | #define LONG_MIN (-LONG_MAX-1) 14 | #define ULONG_MAX 0xFFFFFFFF 15 | #define LLONG_MAX 0x7FFFFFFFFFFFFFFF 16 | #define LLONG_MIN (-LLONG_MAX-1) 17 | #define ULLONG_MAX 0xFFFFFFFFFFFFFFFF 18 | -------------------------------------------------------------------------------- /lib/c/include/bits/i386-sysv/arch/signal.h: -------------------------------------------------------------------------------- 1 | typedef int sig_atomic_t; 2 | 3 | #define SIG_ERR -1 4 | #define SIG_DFL 0 5 | #define SIG_IGN 1 6 | 7 | #define SIGHUP 1 8 | #define SIGINT 2 9 | #define SIGQUIT 3 10 | #define SIGILL 4 11 | #define SIGABRT 6 12 | #define SIGFPE 8 13 | #define SIGKILL 9 14 | #define SIGUSR1 10 15 | #define SIGSEGV 11 16 | #define SIGUSR2 12 17 | #define SIGPIPE 13 18 | #define SIGALRM 14 19 | #define SIGTERM 15 20 | #define SIGCHLD 17 21 | #define SIGCONT 18 22 | #define SIGSTOP 19 23 | #define SIGSSTP 20 24 | #define SIGTTIN 21 25 | #define SIGTTOU 22 26 | 27 | #define __NR_SIGNALS 23 28 | -------------------------------------------------------------------------------- /lib/c/include/bits/i386-sysv/arch/stddef.h: -------------------------------------------------------------------------------- 1 | #ifndef _SIZET 2 | typedef unsigned long size_t; 3 | #define _SIZET 4 | #endif 5 | 6 | #ifndef _WCHAR_T 7 | typedef int wchar_t; 8 | #define _WCHAR_T 9 | #endif 10 | 11 | #ifndef _PTRDIFF_T 12 | typedef long ptrdiff_t; 13 | #define _PTRDIFF_T 14 | #endif 15 | -------------------------------------------------------------------------------- /lib/c/include/bits/i386-sysv/arch/stdio.h: -------------------------------------------------------------------------------- 1 | #ifndef _SIZET 2 | typedef unsigned long size_t; 3 | #define _SIZET 4 | #endif 5 | 6 | #define BUFSIZ 512 7 | #define FILENAME_MAX 256 8 | #define FOPEN_MAX 16 9 | 10 | #define TMP_MAX 25 11 | #define L_tmpnam 256 12 | 13 | typedef long fpos_t; 14 | -------------------------------------------------------------------------------- /lib/c/include/bits/i386-sysv/arch/stdlib.h: -------------------------------------------------------------------------------- 1 | #ifndef _SIZET 2 | typedef unsigned long size_t; 3 | #define _SIZET 4 | #endif 5 | 6 | #define EXIT_FAILURE 1 7 | #define EXIT_SUCCESS 0 8 | 9 | #ifndef _WCHAR_T 10 | typedef int wchar_t; 11 | #define _WCHAR_T 12 | #endif 13 | 14 | #define _ALIGNTYPE long double 15 | -------------------------------------------------------------------------------- /lib/c/include/bits/i386-sysv/arch/string.h: -------------------------------------------------------------------------------- 1 | #ifndef _SIZET 2 | typedef unsigned long size_t; 3 | #endif 4 | -------------------------------------------------------------------------------- /lib/c/include/bits/i386-sysv/arch/time.h: -------------------------------------------------------------------------------- 1 | #ifndef _SIZET 2 | typedef unsigned long size_t; 3 | #define _SIZET 4 | #endif 5 | 6 | typedef long int time_t; 7 | -------------------------------------------------------------------------------- /lib/c/include/bits/z80-dos/arch/limits.h: -------------------------------------------------------------------------------- 1 | #define SCHAR_MAX 0x7F 2 | #define SCHAR_MIN (-SCHAR_MIN-1) 3 | #define CHAR_MAX 0xFF 4 | #define CHAR_MIN 0 5 | #define UCHAR_MAX 0xFF 6 | #define SHRT_MAX 0x7FFF 7 | #define SHRT_MIN (-SHRT_MAX-1) 8 | #define USHRT_MAX 0xFFFF 9 | #define INT_MAX 0x7FFF 10 | #define INT_MIN (-INT_MAX-1) 11 | #define UINT_MAX 0xFFFF 12 | #define LONG_MAX 0x7FFFFFFF 13 | #define LONG_MIN (-LONG_MAX-1) 14 | #define ULONG_MAX 0xFFFFFFFF 15 | #define LLONG_MAX 0x7FFFFFFFFFFFFFFF 16 | #define LLONG_MIN (-LLONG_MAX-1) 17 | #define ULLONG_MAX 0xFFFFFFFFFFFFFFFF 18 | -------------------------------------------------------------------------------- /lib/c/include/bits/z80-dos/arch/signal.h: -------------------------------------------------------------------------------- 1 | typedef char sig_atomic_t; 2 | 3 | #define SIG_ERR -1 4 | #define SIG_DFL 0 5 | #define SIG_IGN 1 6 | 7 | #define SIG_ERR -1 8 | #define SIG_DFL 0 9 | #define SIG_IGN 1 10 | 11 | #define SIGHUP 1 12 | #define SIGINT 2 13 | #define SIGQUIT 3 14 | #define SIGILL 4 15 | #define SIGABRT 6 16 | #define SIGFPE 8 17 | #define SIGKILL 9 18 | #define SIGUSR1 10 19 | #define SIGSEGV 11 20 | #define SIGUSR2 12 21 | #define SIGPIPE 13 22 | #define SIGALRM 14 23 | #define SIGTERM 15 24 | #define SIGCHLD 17 25 | #define SIGCONT 18 26 | #define SIGSTOP 19 27 | #define SIGSSTP 20 28 | #define SIGTTIN 21 29 | #define SIGTTOU 22 30 | 31 | #define __NR_SIGNALS 23 32 | -------------------------------------------------------------------------------- /lib/c/include/bits/z80-dos/arch/stddef.h: -------------------------------------------------------------------------------- 1 | #ifndef _SIZET 2 | typedef unsigned size_t; 3 | #define _SIZET 4 | #endif 5 | 6 | #ifndef _WCHAR_T 7 | typedef short wchar_t; 8 | #define _WCHAR_T 9 | #endif 10 | 11 | #ifndef _PTRDIFF_T 12 | typedef short ptrdiff_t; 13 | #define _PTRDIFF_T 14 | #endif 15 | -------------------------------------------------------------------------------- /lib/c/include/bits/z80-dos/arch/stdio.h: -------------------------------------------------------------------------------- 1 | #ifndef _SIZET 2 | typedef unsigned size_t; 3 | #define _SIZET 4 | #endif 5 | 6 | #define BUFSIZ 512 7 | #define FILENAME_MAX 256 8 | #define FOPEN_MAX 16 9 | 10 | #define TMP_MAX 25 11 | #define L_tmpnam 256 12 | 13 | typedef long fpos_t; 14 | -------------------------------------------------------------------------------- /lib/c/include/bits/z80-dos/arch/stdlib.h: -------------------------------------------------------------------------------- 1 | #ifndef _SIZET 2 | typedef unsigned size_t; 3 | #define _SIZET 4 | #endif 5 | 6 | #define EXIT_FAILURE 1 7 | #define EXIT_SUCCESS 0 8 | 9 | #ifndef _WCHAR_T 10 | typedef short wchar_t; 11 | #define _WCHAR_T 12 | #endif 13 | 14 | #define _ALIGNTYPE int 15 | -------------------------------------------------------------------------------- /lib/c/include/bits/z80-dos/arch/string.h: -------------------------------------------------------------------------------- 1 | #ifndef _SIZET 2 | typedef unsigned size_t; 3 | #endif 4 | -------------------------------------------------------------------------------- /lib/c/include/bits/z80-dos/arch/time.h: -------------------------------------------------------------------------------- 1 | #ifndef _SIZET 2 | typedef unsigned size_t; 3 | #define _SIZET 4 | #endif 5 | 6 | typedef long time_t; 7 | -------------------------------------------------------------------------------- /lib/c/include/ctype.h: -------------------------------------------------------------------------------- 1 | #ifndef _CTYPE_H 2 | #define _CTYPE_H 3 | 4 | extern int isalnum(int c); 5 | extern int isalpha(int c); 6 | extern int islower(int c); 7 | extern int isupper(int c); 8 | extern int isdigit(int c); 9 | extern int isxdigit(int c); 10 | extern int iscntrl(int c); 11 | extern int isgraph(int c); 12 | extern int isspace(int c); 13 | extern int isblank(int c); 14 | extern int isprint(int c); 15 | extern int ispunct(int c); 16 | extern int tolower(int c); 17 | extern int toupper(int c); 18 | 19 | #ifdef __USE_MACROS 20 | 21 | #define _U 0x01 /* upper */ 22 | #define _L 0x02 /* lower */ 23 | #define _D 0x04 /* digit */ 24 | #define _C 0x08 /* cntrl */ 25 | #define _P 0x10 /* punct */ 26 | #define _S 0x20 /* white space (space/lf/tab) */ 27 | #define _X 0x40 /* hex char */ 28 | #define _SP 0x80 /* hard space (0x20) */ 29 | 30 | extern unsigned char __ctype[]; 31 | extern int __ctmp; 32 | 33 | #define isalnum(c) ((__ctype+1)[c] & (_U|_L|_D)) 34 | #define isalpha(c) ((__ctype+1)[c] & (_U|_L)) 35 | #define iscntrl(c) ((__ctype+1)[c] & (_C)) 36 | #define isdigit(c) ((__ctype+1)[c] & (_D)) 37 | #define isgraph(c) ((__ctype+1)[c] & (_P|_U|_L|_D)) 38 | #define islower(c) ((__ctype+1)[c] & (_L)) 39 | #define isprint(c) ((__ctype+1)[c] & (_P|_U|_L|_D|_SP)) 40 | #define ispunct(c) ((__ctype+1)[c] & (_P)) 41 | #define isspace(c) ((__ctype+1)[c] & (_S)) 42 | #define isupper(c) ((__ctype+1)[c] & (_U)) 43 | #define isxdigit(c) ((__ctype+1)[c] & (_D|_X)) 44 | 45 | #define tolower(c) ((__ctmp=c, isupper(__ctmp) ? __ctmp | 0x20 : __ctmp)) 46 | #define toupper(c) ((__ctmp=c, islower(__ctmp) ? __ctmp & ~0x20 : __ctmp)) 47 | 48 | #define isascii(c) ((unsigned)(c)<=0x7f) 49 | 50 | #endif 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /lib/c/include/errno.h: -------------------------------------------------------------------------------- 1 | #ifndef _ERRNO_H 2 | #define _ERRNO_H 3 | 4 | #define EDOM 1 5 | #define EILSEQ 2 6 | #define ERANGE 3 7 | #define ENOMEM 4 8 | #define EBADF 5 9 | 10 | extern int errno; 11 | extern char *_sys_errlist[]; 12 | extern int _sys_nerr; 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /lib/c/include/limits.h: -------------------------------------------------------------------------------- 1 | #ifndef _LIMITS_H 2 | #define _LIMITS_H 3 | 4 | #include 5 | 6 | #define CHAR_BIT 8 7 | #define MB_LEN_MAX 1 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /lib/c/include/locale.h: -------------------------------------------------------------------------------- 1 | #ifndef _LOCALE_H 2 | #define _LOCALE_H 3 | 4 | #ifndef NULL 5 | #define NULL ((void *) 0) 6 | #endif 7 | 8 | #define LC_ALL 0 9 | #define LC_COLLATE 1 10 | #define LC_CTYPE 2 11 | #define LC_MONETARY 3 12 | #define LC_NUMERIC 4 13 | #define LC_TIME 5 14 | 15 | struct lconv { 16 | char *decimal_point; 17 | char *thousands_sep; 18 | char *grouping; 19 | char *mon_decimal_point; 20 | char *mon_thousands_sep; 21 | char *mon_grouping; 22 | char *positive_sign; 23 | char *negative_sign; 24 | char *currency_symbol; 25 | char *int_curr_symbol; 26 | char frac_digits; 27 | char p_cs_precedes; 28 | char n_cs_precedes; 29 | char p_sep_by_space; 30 | char n_sep_by_space; 31 | char p_sign_posn; 32 | char n_sign_posn; 33 | char int_frac_digits; 34 | char int_p_cs_precedes; 35 | char int_n_cs_precedes; 36 | char int_p_sep_by_space; 37 | char int_n_sep_by_space; 38 | char int_p_sign_posn; 39 | char int_n_sign_posn; 40 | }; 41 | 42 | extern char *setlocale(int category, const char *locale); 43 | extern struct lconv *localeconv(void); 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /lib/c/include/signal.h: -------------------------------------------------------------------------------- 1 | #ifndef _SIGNAL_H 2 | #define _SIGNAL_H 3 | 4 | #include 5 | 6 | void ( *signal(int signum, void (*handler)(int)) ) (int); 7 | int raise(int sig); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /lib/c/include/stdarg.h: -------------------------------------------------------------------------------- 1 | #ifndef _STDARG_H 2 | #define _STDARG_H 3 | 4 | #define va_list __builtin_va_list 5 | #define va_start(ap, last) __builtin_va_start(ap, last) 6 | #define va_end(ap) __builtin_va_end(ap) 7 | #define va_copy(to, from) __builtin_va_copy(to, from) 8 | #define va_arg(to, type) __builtin_va_arg(to, type) 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /lib/c/include/stdbool.h: -------------------------------------------------------------------------------- 1 | #ifndef _STDBOOL_H 2 | #define _STDBOOL_H 3 | 4 | #define bool _Bool 5 | #define true ((bool) 1) 6 | #define false ((bool) 0) 7 | #define __bool_true_false_are_defined 1 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /lib/c/include/stddef.h: -------------------------------------------------------------------------------- 1 | #ifndef _STDDEF_H 2 | #define _STDDEF_H 3 | 4 | #include 5 | 6 | #ifndef NULL 7 | #define NULL ((void *) 0) 8 | #endif 9 | 10 | #define offsetof(st, m) ((size_t)&(((st *)0)->m)) 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /lib/c/include/stdint.h: -------------------------------------------------------------------------------- 1 | #ifndef _STDINT_H_ 2 | #define _STDINT_H_ 3 | 4 | #include 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /lib/c/include/string.h: -------------------------------------------------------------------------------- 1 | #ifndef _STRING_H 2 | #define _STRING_H 3 | 4 | #include 5 | 6 | #ifndef NULL 7 | #define NULL ((void *) 0) 8 | #endif 9 | 10 | extern void *memcpy(void * restrict s1, const void * restrict s2, size_t n); 11 | extern void *memmove(void *s1, const void *s2, size_t n); 12 | extern char *strcpy(char * restrict s1, const char * restrict s2); 13 | extern char *strncpy(char * restrict s1, const char * restrict s2, size_t n); 14 | extern char *strcat(char * restrict s1, const char * restrict s2); 15 | extern char *strncat(char * restrict s1, const char * restrict s2, size_t n); 16 | extern int memcmp(const void *s1, const void *s2, size_t n); 17 | extern int strcmp(const char *s1, const char *s2); 18 | extern int strcoll(const char *s1, const char *s2); 19 | extern int strncmp(const char *s1, const char *s2, size_t n); 20 | extern size_t strxfrm(char * restrict s1, const char * restrict s2, size_t n); 21 | extern void *memchr(const void *s, int c, size_t n); 22 | extern char *strchr(const char *s, int c); 23 | extern size_t strcspn(const char *s1, const char *s2); 24 | extern char *strpbrk(const char *s1, const char *s2); 25 | extern char *strrchr(const char *s, int c); 26 | extern size_t strspn(const char *s1, const char *s2); 27 | extern char *strstr(const char *s1, const char *s2); 28 | extern char *strtok(char * restrict s1, const char * restrict s2); 29 | extern void *memset(void *s, int c, size_t n); 30 | extern char *strerror(int errnum); 31 | extern size_t strlen(const char *s); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /lib/c/include/time.h: -------------------------------------------------------------------------------- 1 | #ifndef _TIME_H 2 | #define _TIME_H 3 | 4 | #include 5 | 6 | #ifndef NULL 7 | #define NULL ((void *) 0) 8 | #endif 9 | 10 | #define CLOCKS_PER_SEC 1000000 11 | 12 | typedef long int clock_t; 13 | 14 | struct tm { 15 | int tm_sec; 16 | int tm_min; 17 | int tm_hour; 18 | int tm_mday; 19 | int tm_mon; 20 | int tm_year; 21 | int tm_wday; 22 | int tm_yday; 23 | int tm_isdst; 24 | }; 25 | 26 | extern clock_t clock(void); 27 | extern double difftime(time_t time1, time_t time0); 28 | extern time_t mktime(struct tm *timeptr); 29 | extern time_t time(time_t *timer); 30 | extern char *asctime(const struct tm *timeptr); 31 | extern char *ctime(const time_t *timer); 32 | extern struct tm *gmtime(const time_t *timer); 33 | extern struct tm *localtime(const time_t *timer); 34 | extern size_t strftime(char * restrict s, size_t maxsize, 35 | const char * restrict format, 36 | const struct tm * restrict timeptr); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /lib/c/isalnum.c: -------------------------------------------------------------------------------- 1 | #define __USE_MACROS 2 | #include 3 | #undef isalnum 4 | 5 | int 6 | isalnum(int c) 7 | { 8 | return (__ctype+1)[c] & (_U|_L|_D); 9 | } 10 | -------------------------------------------------------------------------------- /lib/c/isalpha.c: -------------------------------------------------------------------------------- 1 | #define __USE_MACROS 2 | #include 3 | #undef isalpha 4 | 5 | int 6 | isalpha(int c) 7 | { 8 | return (__ctype+1)[c] & (_U|_L); 9 | } 10 | -------------------------------------------------------------------------------- /lib/c/isascii.c: -------------------------------------------------------------------------------- 1 | #define __USE_MACROS 2 | #include 3 | #undef isascii 4 | 5 | int 6 | isascii(int c) 7 | { 8 | return c <= 0x7f; 9 | } 10 | -------------------------------------------------------------------------------- /lib/c/isblank.c: -------------------------------------------------------------------------------- 1 | int 2 | isblank(int c) 3 | { 4 | return (c == ' ') || (c == '\t'); 5 | } 6 | -------------------------------------------------------------------------------- /lib/c/iscntrl.c: -------------------------------------------------------------------------------- 1 | #define __USE_MACROS 2 | #include 3 | #undef iscntrl 4 | 5 | int 6 | iscntrl(int c) 7 | { 8 | return (__ctype+1)[c] & (_C); 9 | } 10 | -------------------------------------------------------------------------------- /lib/c/isdigit.c: -------------------------------------------------------------------------------- 1 | #define __USE_MACROS 2 | #include 3 | #undef isdigit 4 | 5 | int 6 | isdigit(int c) 7 | { 8 | return (__ctype+1)[c] & (_D); 9 | } 10 | -------------------------------------------------------------------------------- /lib/c/isgraph.c: -------------------------------------------------------------------------------- 1 | #define __USE_MACROS 2 | #include 3 | #undef isgraph 4 | 5 | int 6 | isgraph(int c) 7 | { 8 | return (__ctype+1)[c] & (_P|_U|_L|_D); 9 | } 10 | -------------------------------------------------------------------------------- /lib/c/islower.c: -------------------------------------------------------------------------------- 1 | #define __USE_MACROS 2 | #include 3 | #undef islower 4 | 5 | int 6 | islower(int c) 7 | { 8 | return (__ctype+1)[c] & _L; 9 | } 10 | -------------------------------------------------------------------------------- /lib/c/isprint.c: -------------------------------------------------------------------------------- 1 | #define __USE_MACROS 2 | #include 3 | #undef isprint 4 | 5 | int 6 | isprint(int c) 7 | { 8 | return (__ctype+1)[c] & (_P|_U|_L|_D|_SP); 9 | } 10 | -------------------------------------------------------------------------------- /lib/c/ispunct.c: -------------------------------------------------------------------------------- 1 | #define __USE_MACROS 2 | #include 3 | #undef ispunct 4 | 5 | int 6 | ispunct(int c) 7 | { 8 | return (__ctype+1)[c] & (_P); 9 | } 10 | -------------------------------------------------------------------------------- /lib/c/isspace.c: -------------------------------------------------------------------------------- 1 | #define __USE_MACROS 2 | #include 3 | #undef isspace 4 | 5 | int 6 | isspace(int c) 7 | { 8 | return (__ctype+1)[c] & _S; 9 | } 10 | -------------------------------------------------------------------------------- /lib/c/isupper.c: -------------------------------------------------------------------------------- 1 | #define __USE_MACROS 2 | #include 3 | #undef isupper 4 | 5 | int 6 | isupper(int c) 7 | { 8 | return (__ctype+1)[c] & _U; 9 | } 10 | -------------------------------------------------------------------------------- /lib/c/isxdigit.c: -------------------------------------------------------------------------------- 1 | #define __USE_MACROS 2 | #include 3 | #undef isxdigit 4 | 5 | int 6 | isxdigit(int c) 7 | { 8 | return (__ctype+1)[c] & (_D|_X); 9 | } 10 | -------------------------------------------------------------------------------- /lib/c/labs.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #undef labs 4 | 5 | long 6 | labs(long n) 7 | { 8 | return (n < 0) ? -n : n; 9 | } 10 | -------------------------------------------------------------------------------- /lib/c/llabs.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #undef llabs 4 | 5 | long long 6 | llabs(long long n) 7 | { 8 | return (n < 0) ? -n : n; 9 | } 10 | -------------------------------------------------------------------------------- /lib/c/localeconv.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #undef localeconv 4 | 5 | struct lconv * 6 | localeconv(void) 7 | { 8 | static struct lconv lc = { ".", "", "", "", "", "", "", "", "", "", 9 | CHAR_MAX, CHAR_MAX, CHAR_MAX, CHAR_MAX, 10 | CHAR_MAX, CHAR_MAX, CHAR_MAX, CHAR_MAX, 11 | CHAR_MAX, CHAR_MAX, CHAR_MAX, CHAR_MAX, 12 | CHAR_MAX, CHAR_MAX }; 13 | return &lc; 14 | } 15 | -------------------------------------------------------------------------------- /lib/c/malloc.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* minimum amount of required units */ 4 | #define NALLOC 10000 5 | 6 | typedef union header Header; 7 | union header { 8 | struct hdr { 9 | Header *next; 10 | size_t size; 11 | } h; 12 | /* most restrictive type fixes the union size for alignment */ 13 | _ALIGNTYPE most; 14 | }; 15 | 16 | extern void *_prevchunk(Header *hp); 17 | -------------------------------------------------------------------------------- /lib/c/memchr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #undef memchr 3 | 4 | void * 5 | memchr(const void *s, int c, size_t n) 6 | { 7 | unsigned char *bp = (char *) s; 8 | 9 | while (n > 0 && *bp++ != c) 10 | --n; 11 | return (n == 0) ? NULL : bp-1; 12 | } 13 | -------------------------------------------------------------------------------- /lib/c/memcmp.c: -------------------------------------------------------------------------------- 1 | #include 2 | #undef memcmp 3 | 4 | int 5 | memcmp(const void *s1, const void *s2, size_t n) 6 | { 7 | char *s = (char *) s1, *t = (char *) s2; 8 | 9 | while (n > 0 && *s == *t) 10 | --n, ++s, ++t; 11 | return n ? (*s - *t) : 0; 12 | } 13 | -------------------------------------------------------------------------------- /lib/c/memcpy.c: -------------------------------------------------------------------------------- 1 | #include 2 | #undef memcpy 3 | 4 | void * 5 | memcpy(void * restrict dst, const void * restrict src, size_t n) 6 | { 7 | char *s1 = dst; 8 | const char *s2 = src; 9 | 10 | while (n-- > 0) 11 | *s1++ = *s2++; 12 | return dst; 13 | } 14 | -------------------------------------------------------------------------------- /lib/c/memmove.c: -------------------------------------------------------------------------------- 1 | #include 2 | #undef memmove 3 | 4 | void * 5 | memmove(void *dst, const void *src, size_t n) 6 | { 7 | char *d = dst, *s = (char *) src; 8 | 9 | if (d < s) { 10 | while (n-- > 0) 11 | *d++ = *s++; 12 | } else { 13 | s += n-1, d += n-1; 14 | while (n-- > 0) 15 | *d-- = *s--; 16 | } 17 | return dst; 18 | } 19 | -------------------------------------------------------------------------------- /lib/c/memset.c: -------------------------------------------------------------------------------- 1 | #include 2 | #undef memset 3 | 4 | void * 5 | memset(void *s, int c, size_t n) 6 | { 7 | char *m = s; 8 | 9 | while (n-- > 0) 10 | *m++ = c; 11 | return s; 12 | } 13 | -------------------------------------------------------------------------------- /lib/c/perror.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #undef perror 6 | 7 | void 8 | perror(const char *msg) 9 | { 10 | if (msg && *msg) { 11 | fputs(msg, stderr); 12 | putc(':', stderr); 13 | putc(' ', stderr); 14 | } 15 | fputs(strerror(errno), stderr); 16 | putc('\n', stderr); 17 | } 18 | -------------------------------------------------------------------------------- /lib/c/printf.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #undef printf 4 | 5 | int 6 | printf(const char * restrict fmt, ...) 7 | { 8 | int cnt; 9 | va_list va; 10 | 11 | va_start(va, fmt); 12 | cnt = vfprintf(stdout, fmt, va); 13 | va_end(va); 14 | return cnt; 15 | } 16 | -------------------------------------------------------------------------------- /lib/c/putc.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #undef putc 4 | 5 | int 6 | putc(int ch, FILE *fp) 7 | { 8 | return (fp->wp >= fp->rp) ? __putc(c,fp) : *fp->wp++ = c; 9 | } 10 | -------------------------------------------------------------------------------- /lib/c/putchar.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #undef putchar 4 | 5 | int 6 | putchar(int ch) 7 | { 8 | return putc(ch, stdin); 9 | } 10 | -------------------------------------------------------------------------------- /lib/c/puts.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | int 5 | puts(const char *str) 6 | { 7 | int ch; 8 | 9 | while (ch = *str) 10 | putchar(ch); 11 | return putchar('\n'); 12 | } 13 | -------------------------------------------------------------------------------- /lib/c/qsort.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #undef qsort 5 | 6 | /* 7 | * This implementation of qsort is based in the paper 8 | * "Engineering a Sort Function", by Jon L.Bentley and M. Douglas McIlroy. 9 | * A lot of different optimizations were removed to make the code simpler. 10 | */ 11 | 12 | struct qsort { 13 | size_t es; 14 | int (*cmp)(const void *, const void *); 15 | }; 16 | 17 | static void 18 | swap(char *i, char *j, size_t n) 19 | { 20 | do { 21 | char c = *i; 22 | *i++ = *j; 23 | *j++ = c; 24 | } while (--n > 0); 25 | } 26 | 27 | static void 28 | xqsort(char *a, size_t n, struct qsort *qs) 29 | { 30 | size_t j, es = qs->es; 31 | char *pi, *pj, *pn; 32 | 33 | if (n <= 1) 34 | return; 35 | 36 | pi = a; 37 | pn = pj = a + n*es; 38 | 39 | swap(a, a + n/2 * es, es); 40 | for (;;) { 41 | do { 42 | pi += es; 43 | } while (pi < pn && qs->cmp(pi, a) < 0); 44 | 45 | do { 46 | pj -= es; 47 | } while (pj > a && qs->cmp(pj, a) > 0); 48 | 49 | if (pj < pi) 50 | break; 51 | swap(pi, pj, es); 52 | } 53 | swap(a, pj, es); 54 | 55 | j = (pj - a) / es; 56 | xqsort(a, j, qs); 57 | xqsort(a + (j+1)*es, n-j-1, qs); 58 | } 59 | 60 | void 61 | qsort(void *base, size_t nmemb, size_t size, 62 | int (*f)(const void *, const void *)) 63 | { 64 | struct qsort qs; 65 | 66 | qs.cmp = f; 67 | qs.es = size; 68 | xqsort(base, nmemb, &qs); 69 | } 70 | -------------------------------------------------------------------------------- /lib/c/rand.c: -------------------------------------------------------------------------------- 1 | #include 2 | #undef rand 3 | #undef srand 4 | 5 | static int next; 6 | 7 | void 8 | srand(unsigned seed) 9 | { 10 | next = seed; 11 | } 12 | 13 | int 14 | rand(void) /* RAND_MAX assumed to be 32767. */ 15 | { 16 | next = next * 1103515245 + 12345; 17 | return (unsigned)(next/65536) % 32768; 18 | } 19 | -------------------------------------------------------------------------------- /lib/c/realloc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "malloc.h" 5 | 6 | void * 7 | realloc(void *ptr, size_t nbytes) 8 | { 9 | Header *oh, *prev, *next, *new; 10 | size_t nunits, avail, onbytes, n; 11 | 12 | if (!nbytes) 13 | return NULL; 14 | 15 | if (!ptr) 16 | return malloc(nbytes); 17 | 18 | nunits = (nbytes + sizeof(Header) - 1) / sizeof(Header) + 1; 19 | oh = (Header*)ptr - 1; 20 | 21 | if (oh->h.size == nunits) 22 | return ptr; 23 | 24 | new = oh + nunits; 25 | 26 | if (nunits < oh->h.size - 1) { 27 | new->h.size = oh->h.size - nunits; 28 | oh->h.size = nunits; 29 | free(new + 1); 30 | return oh; 31 | } 32 | 33 | prev = _prevchunk(oh); 34 | 35 | if (oh + oh->h.size == prev->h.next) { 36 | /* 37 | * if there is free space adjacent 38 | * to the current memory 39 | */ 40 | next = prev->h.next; 41 | avail = oh->h.size + next->h.size; 42 | 43 | if (avail == nunits) { 44 | oh->h.size = nunits; 45 | prev->h.next = next->h.next; 46 | return oh; 47 | } 48 | 49 | if (avail > nunits) { 50 | oh->h.size = nunits; 51 | prev->h.next = new; 52 | new->h.next = next; 53 | new->h.size = avail - nunits; 54 | return oh; 55 | } 56 | } 57 | 58 | onbytes = (oh->h.size - 1) * sizeof(Header); 59 | if ((new = malloc(nbytes)) == NULL) 60 | return NULL; 61 | 62 | n = (onbytes > nbytes) ? nbytes : onbytes; 63 | memcpy(new, ptr, n); 64 | free(ptr); 65 | 66 | return new; 67 | } 68 | -------------------------------------------------------------------------------- /lib/c/rewind.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #undef rewind 4 | 5 | void 6 | rewind(FILE *fp) 7 | { 8 | fp->flags &= ~_IOERR; 9 | fseek(fp, 0, SEEK_SET); 10 | clearerr(fp); 11 | } 12 | -------------------------------------------------------------------------------- /lib/c/setbuf.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #undef setbuf 4 | 5 | void 6 | setbuf(FILE * restrict fp, char * restrict buf) 7 | { 8 | setvbuf(fp, buf, (buf) ? _IOFBF : _IONBF, BUFSIZ); 9 | } 10 | -------------------------------------------------------------------------------- /lib/c/setlocale.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #undef setlocale 4 | 5 | char * 6 | setlocale(int category, const char *locale) 7 | { 8 | if (category > LC_TIME || category < LC_ALL) 9 | return NULL; 10 | if (!locale || 11 | locale[0] == '\0' || 12 | locale[0] == 'C' && locale[1] == '\0') { 13 | return "C"; 14 | } 15 | return NULL; 16 | } 17 | -------------------------------------------------------------------------------- /lib/c/setvbuf.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #undef setvbuf 5 | 6 | int 7 | setvbuf(FILE * restrict fp, char * restrict buf, int mode, size_t size) 8 | { 9 | int flags, r; 10 | 11 | if (fflush(fp) == EOF) 12 | return EOF; 13 | 14 | switch (mode) { 15 | case _IONBF: 16 | size = sizeof(fp->unbuf); 17 | buf = fp->unbuf; 18 | break; 19 | case _IOLBF: 20 | case _IOFBF: 21 | if (size == 0) { 22 | if ((buf = malloc(BUFSIZ)) == NULL) { 23 | errno = ENOMEM; 24 | return EOF; 25 | } 26 | size = BUFSIZ; 27 | } 28 | break; 29 | default: 30 | errno = EIVAL; 31 | return EOF; 32 | } 33 | 34 | flags = fp->flags; 35 | if (flags & _IOALLOC) 36 | free(fp->buf); 37 | flag &= ~(_IONBF | _IOLBF | _IOFBF | _IOALLOC | _IOALLOC); 38 | flags |= mode; 39 | fp->flags = flags; 40 | fp->buf = buf; 41 | fp->size = size; 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /lib/c/snprintf.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #undef snprintf 5 | 6 | int 7 | snprintf(char * restrict s, size_t siz, const char * restrict fmt, ...) 8 | { 9 | int r; 10 | va_list va; 11 | 12 | va_list va_arg; 13 | va_start(va, fmt); 14 | r = vsnprintf(s, siz, fmt, va); 15 | va_end(va); 16 | 17 | return r; 18 | } 19 | -------------------------------------------------------------------------------- /lib/c/sprintf.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #undef sprintf 5 | 6 | int 7 | sprintf(char * restrict s, const char * restrict fmt, ...) 8 | { 9 | int r; 10 | 11 | va_list va; 12 | va_start(va, fmt); 13 | r = vsprintf(s, fmt, va); 14 | va_end(va); 15 | 16 | return r; 17 | } 18 | -------------------------------------------------------------------------------- /lib/c/stdio.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | static unsigned char inbuf[BUFSIZ]; 5 | static unsigned char outbuf[BUFSIZ]; 6 | 7 | FILE __iob[FOPEN_MAX] = { 8 | { 9 | .fd = 0, 10 | .buf = inbuf, 11 | .len = BUFSIZ, 12 | .flags = _IOREAD 13 | }, 14 | { 15 | .fd = 1, 16 | .buf = outbuf, 17 | .len = BUFSIZ, 18 | .flags = _IOWRITE | _IOLBF 19 | }, 20 | { 21 | .fd = 2, 22 | .buf = stderr->unbuf, 23 | .len = sizeof(stderr->unbuf), 24 | .flags = _IOWRITE 25 | }, 26 | }; 27 | -------------------------------------------------------------------------------- /lib/c/strcat.c: -------------------------------------------------------------------------------- 1 | #include 2 | #undef strcat 3 | 4 | char * 5 | strcat(char * restrict dst, const char * restrict src) 6 | { 7 | char *ret = dst; 8 | 9 | while (*dst) 10 | ++dst; 11 | while (*dst++ = *src++) 12 | ; 13 | return ret; 14 | } 15 | -------------------------------------------------------------------------------- /lib/c/strchr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #undef strchr 3 | 4 | char * 5 | strchr(const char *s, int c) 6 | { 7 | while (*s && *s != c) 8 | ++s; 9 | return (*s == c) ? (char *)s : NULL; 10 | } 11 | -------------------------------------------------------------------------------- /lib/c/strcmp.c: -------------------------------------------------------------------------------- 1 | #include 2 | #undef strcmp 3 | 4 | int 5 | strcmp(const char *s1, const char *s2) 6 | { 7 | while (*s1 && *s2 && *s1 == *s2) 8 | ++s1, ++s2; 9 | return *(unsigned char *)s1 - *(unsigned char *)s2; 10 | } 11 | -------------------------------------------------------------------------------- /lib/c/strcoll.c: -------------------------------------------------------------------------------- 1 | #include 2 | #undef strcoll 3 | 4 | int 5 | strcoll(const char *s1, const char *s2) 6 | { 7 | while (*s1 && *s2 && *s1 == *s2) 8 | ++s1, ++s2; 9 | return *(unsigned char *) s1 - *(unsigned char *) s2; 10 | } 11 | -------------------------------------------------------------------------------- /lib/c/strcpy.c: -------------------------------------------------------------------------------- 1 | #include 2 | #undef strcpy 3 | 4 | char * 5 | strcpy(char * restrict dst, const char * restrict src) 6 | { 7 | char *ret = dst; 8 | 9 | while (*dst++ = *src++) 10 | ; 11 | return ret; 12 | } 13 | -------------------------------------------------------------------------------- /lib/c/strcspn.c: -------------------------------------------------------------------------------- 1 | #include 2 | #undef strcspn 3 | 4 | size_t 5 | strcspn(const char *s1, const char *s2) 6 | { 7 | size_t n; 8 | int c; 9 | const char *p; 10 | 11 | for (n = 0; c = *s1++; ++n) { 12 | for (p = s2; *p && *p != c; ++p) 13 | ; 14 | if (*p == c) 15 | break; 16 | } 17 | return n; 18 | } 19 | -------------------------------------------------------------------------------- /lib/c/strerror.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #undef strerror 5 | 6 | char * 7 | strerror(int errnum) 8 | { 9 | if (errnum < _sys_nerr) 10 | return _sys_errlist[errnum]; 11 | else 12 | return "Unknown error"; 13 | } 14 | -------------------------------------------------------------------------------- /lib/c/strlen.c: -------------------------------------------------------------------------------- 1 | #include 2 | #undef strlen 3 | 4 | size_t 5 | strlen(const char *s) 6 | { 7 | const char *t; 8 | 9 | for (t = s; *t; ++t) 10 | ; 11 | return t - s; 12 | } 13 | -------------------------------------------------------------------------------- /lib/c/strncat.c: -------------------------------------------------------------------------------- 1 | #include 2 | #undef strncat 3 | 4 | char * 5 | strncat(char * restrict dst, const char * restrict src, size_t n) 6 | { 7 | char *ret = dst; 8 | 9 | while (*dst) 10 | ++dst; 11 | while (n-- > 0 && *src) 12 | *dst++ = *src++; 13 | *dst = '\0'; 14 | return ret; 15 | } 16 | -------------------------------------------------------------------------------- /lib/c/strncmp.c: -------------------------------------------------------------------------------- 1 | #include 2 | #undef strncmp 3 | 4 | int 5 | strncmp(const char *s1, const char *s2, size_t n) 6 | { 7 | int c; 8 | 9 | if (n == 0) 10 | return 0; 11 | while ((c = *s1) != '\0' && c == *s2) { 12 | if (--n == 0) 13 | return 0; 14 | ++s1, ++s2; 15 | } 16 | return (*(unsigned char *) s1 - *(unsigned char *) s2); 17 | } 18 | -------------------------------------------------------------------------------- /lib/c/strncpy.c: -------------------------------------------------------------------------------- 1 | #include 2 | #undef strncpy 3 | 4 | char * 5 | strncpy(char * restrict dst, const char * restrict src, size_t n) 6 | { 7 | char *ret = dst; 8 | 9 | for (; n > 0 && *src; --n) 10 | *dst++ = *src++; 11 | while (n-- > 0) 12 | *dst++ = '\0'; 13 | return ret; 14 | } 15 | -------------------------------------------------------------------------------- /lib/c/strpbrk.c: -------------------------------------------------------------------------------- 1 | #include 2 | #undef strpbrk 3 | 4 | char * 5 | strpbrk(const char *s1, const char *s2) 6 | { 7 | int c; 8 | const char *p; 9 | 10 | for (; c = *s1; ++s1) { 11 | for (p = s2; *p && *p != c; ++p) 12 | ; 13 | if (*p == c) 14 | return s1; 15 | } 16 | return NULL; 17 | } 18 | -------------------------------------------------------------------------------- /lib/c/strrchr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #undef strrchr 3 | 4 | char * 5 | strrchr(const char *s, int c) 6 | { 7 | const char *t = s; 8 | 9 | while (*t) 10 | ++t; 11 | while (t > s && *t != c) 12 | --t; 13 | return (*t == c) ? (char *)t : NULL; 14 | } 15 | -------------------------------------------------------------------------------- /lib/c/strspn.c: -------------------------------------------------------------------------------- 1 | #include 2 | #undef strspn 3 | 4 | size_t 5 | strspn(const char *s1, const char *s2) 6 | { 7 | size_t n; 8 | int c; 9 | const char *p; 10 | 11 | for (n = 0; c = *s1++; ++n) { 12 | for (p = s2; *p && *p != c; ++p) 13 | ; 14 | if (*p == '\0') 15 | break; 16 | } 17 | return n; 18 | } 19 | -------------------------------------------------------------------------------- /lib/c/strstr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #undef strstr 3 | 4 | char * 5 | strstr(const char *s1, const char *s2) 6 | { 7 | const char *p, *q; 8 | int c0, c; 9 | 10 | c0 = *s2; 11 | if (c0 == '\0') 12 | return (char *) s1; 13 | --s1; 14 | while ((s1 = strchr(s1 + 1, c0)) != NULL) { 15 | p = s1; 16 | q = s2; 17 | for (;;) { 18 | if ((c = *++p) == '\0') 19 | return (char *) s1; 20 | if (c != *++q) 21 | break; 22 | } 23 | } 24 | 25 | return NULL; 26 | } 27 | -------------------------------------------------------------------------------- /lib/c/strtok.c: -------------------------------------------------------------------------------- 1 | #include 2 | #undef strtok 3 | 4 | char * 5 | strtok(char * restrict s, const char * restrict delim) 6 | { 7 | static char *line; 8 | 9 | if (s) 10 | line = s; 11 | if (!s && !line) 12 | return NULL; 13 | 14 | s = line + strspn(line, delim); 15 | if (*s == '\0') 16 | return line = NULL; 17 | 18 | line = s + strcspn(s, delim); 19 | if (*line != '\0') 20 | *line++ = '\0'; 21 | else 22 | line = NULL; 23 | 24 | return s; 25 | } 26 | -------------------------------------------------------------------------------- /lib/c/strxfrm.c: -------------------------------------------------------------------------------- 1 | #include 2 | #undef strxfrm 3 | 4 | size_t 5 | strxfrm(char * restrict dst, const char * restrict src, size_t n) 6 | { 7 | size_t len = strlen(src); 8 | 9 | if (len < n) 10 | strcpy(dst, src); 11 | return len; 12 | } 13 | -------------------------------------------------------------------------------- /lib/c/syscall.h: -------------------------------------------------------------------------------- 1 | extern void *_brk(void *addr); 2 | extern int _open(char *path, int flags, int perm); 3 | extern int _close(int fd); 4 | extern int _read(int fd, void *buf, size_t n); 5 | extern int _write(int fd, void *buf, size_t n); 6 | extern int _lseek(int fd, long off, int whence); 7 | extern void _Exit(int status); 8 | extern void _access(char *path, int mode); 9 | 10 | extern int raise(int sig); 11 | extern void (*signal(int sig, void (*func)(int)))(int); 12 | extern getenv(const char *var); 13 | extern int rename(const char *from, const char *to); 14 | extern int remove(const char *path); 15 | -------------------------------------------------------------------------------- /lib/c/target/Makefile: -------------------------------------------------------------------------------- 1 | 2 | include ../../../config.mk 3 | 4 | DIRS = $(TARGETS) 5 | 6 | all dep clean distclean: 7 | $(FORALL) 8 | -------------------------------------------------------------------------------- /lib/c/target/amd64-sysv-linux-elf/Makefile: -------------------------------------------------------------------------------- 1 | .POSIX: 2 | 3 | include ../../../../config.mk 4 | include ../objlst.mk 5 | include ../common.mk 6 | 7 | SCC_CFLAGS = -I../../include -I../../include/bits/amd64-sysv/ 8 | -------------------------------------------------------------------------------- /lib/c/target/amd64-sysv-linux-elf/gendep.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | rm -f makefile 6 | trap "rm -f $$.mk" 0 2 3 7 | 8 | (cat Makefile 9 | for i 10 | do 11 | cat < $$.mk && mv $$.mk makefile 17 | -------------------------------------------------------------------------------- /lib/c/target/amd64-sysv-openbsd-elf/Makefile: -------------------------------------------------------------------------------- 1 | .POSIX: 2 | 3 | include ../../../../config.mk 4 | include ../objlst.mk 5 | include ../common.mk 6 | -------------------------------------------------------------------------------- /lib/c/target/amd64-sysv-openbsd-elf/gendep.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | rm -f makefile 6 | trap "rm -f $$.mk" 0 2 3 7 | 8 | (cat Makefile 9 | for i 10 | do 11 | cat < $$.mk && mv $$.mk makefile 17 | -------------------------------------------------------------------------------- /lib/c/target/common.mk: -------------------------------------------------------------------------------- 1 | 2 | all: libc.a 3 | 4 | libc.a: $(OBJ) 5 | $(AR) $(ARFLAGS) $@ $? 6 | ranlib $@ 7 | 8 | dep: 9 | gendep.sh $(OBJ) 10 | 11 | clean: 12 | rm -f *.o 13 | 14 | distclean: clean 15 | rm -f makefile 16 | -------------------------------------------------------------------------------- /lib/c/target/i386-sysv-linux-elf/Makefile: -------------------------------------------------------------------------------- 1 | .POSIX: 2 | 3 | include ../../../../config.mk 4 | include ../objlst.mk 5 | include ../common.mk 6 | -------------------------------------------------------------------------------- /lib/c/target/i386-sysv-linux-elf/gendep.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | rm -f makefile 6 | trap "rm -f $$.mk" 0 2 3 7 | 8 | (cat Makefile 9 | for i 10 | do 11 | cat < $$.mk && mv $$.mk makefile 17 | -------------------------------------------------------------------------------- /lib/c/target/objlst.mk: -------------------------------------------------------------------------------- 1 | 2 | OBJ = bsearch.o qsort.o \ 3 | abs.o __abs.o labs.o __labs.o llabs.o __llabs.o \ 4 | perror.o strerror.o \ 5 | tmpnam.o \ 6 | sprintf.o snprintf.o vsprintf.o vsnprintf.o \ 7 | printf.o fprintf.o vfprintf.o \ 8 | fgets.o gets.of fgetc.o fputc.o getchar.o putchar.o \ 9 | fputs.o puts.o fread.o fwrite.o \ 10 | getc.o putc.o __putc.o __getc.o \ 11 | rewind.o fseek.o ferror.o feof.o clearerr.o \ 12 | setbuf.o setvbuf.o \ 13 | fclose.o fopen.c freopen.c _fpopen.o stdio.o \ 14 | realloc.o calloc.o malloc.o \ 15 | assert.o strcpy.o strcmp.o strlen.o strchr.o \ 16 | strrchr.o strcat.o strncmp.o strncpy.o strncat.o strcoll.o \ 17 | strxfrm.o strstr.o strspn.o strcspn.o strpbrk.o strtok.o \ 18 | memset.o memcpy.o memmove.o memcmp.o memchr.o \ 19 | isalnum.o isalpha.o isascii.o isblank.o iscntrl.o isdigit.o \ 20 | isgraph.o islower.o isprint.o ispunct.o isspace.o isupper.o \ 21 | isxdigit.o toupper.o tolower.o ctype.o setlocale.o \ 22 | localeconv.o atoi.o atol.o atoll.o atexit.o abort.o exit.o 23 | -------------------------------------------------------------------------------- /lib/c/target/z80-scc-none-none/Makefile: -------------------------------------------------------------------------------- 1 | .POSIX: 2 | 3 | include ../../../../config.mk 4 | include ../objlst.mk 5 | include ../common.mk 6 | -------------------------------------------------------------------------------- /lib/c/target/z80-scc-none-none/gendep.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | rm -f makefile 6 | trap "rm -f $$.mk" 0 2 3 7 | 8 | (cat Makefile 9 | for i 10 | do 11 | cat < $$.mk && mv $$.mk makefile 17 | -------------------------------------------------------------------------------- /lib/c/tmpnam.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include "syscall.h" 5 | #undef tmpnam 6 | 7 | char * 8 | tmpnam(char *s) 9 | { 10 | static char *tmpl, buf[L_tmpnam]; 11 | char *p; 12 | 13 | if (*buf == '\0') { 14 | for (tmpl = buf, p = _TMPNAME; *tmpl++ = *p++; ) 15 | ; 16 | for (p = tmpl; p < &buf[L_tmpnam-1]; ++p) 17 | *p = '0'; 18 | *p = '\0'; 19 | } 20 | for (;;) { 21 | for (p = tmpl; *p && *p != '9'; ++p) 22 | ; 23 | if (*p == '\0') 24 | return NULL; 25 | ++*p; 26 | if (_access(buf, 0) != 0) 27 | break; 28 | } 29 | if (s) 30 | strcpy(s, buf); 31 | return buf; 32 | } 33 | -------------------------------------------------------------------------------- /lib/c/tolower.c: -------------------------------------------------------------------------------- 1 | #define __USE_MACROS 2 | #include 3 | #undef tolower 4 | 5 | int 6 | tolower(int c) 7 | { 8 | return (isupper(c)) ? c | 0x20 : c; 9 | } 10 | -------------------------------------------------------------------------------- /lib/c/toupper.c: -------------------------------------------------------------------------------- 1 | #define __USE_MACROS 2 | #include 3 | #undef toupper 4 | 5 | int 6 | toupper(int c) 7 | { 8 | return (islower(c)) ? c & ~0x20 : c; 9 | } 10 | -------------------------------------------------------------------------------- /lib/c/vsnprintf.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #undef vsnprintf 5 | 6 | int 7 | vsnprintf(char * restrict s, size_t siz, const char * restrict fmt, va_list ap) 8 | { 9 | FILE f; 10 | int r; 11 | 12 | f.flag = _IOWRT | _IOSTRG; 13 | f.size = siz; 14 | f.buf = s; 15 | f.wp = s; 16 | f.rp = s + siz; 17 | 18 | r = vfprintf(&f, fmt, va); 19 | if (s) { 20 | if (f.wp == f.rp) 21 | --f.wp; 22 | *f.wp = '\0'; 23 | } 24 | 25 | return r; 26 | } 27 | -------------------------------------------------------------------------------- /lib/c/vsprintf.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #undef vsprintf 6 | 7 | 8 | int 9 | vsprintf(char * restrict s, const char * restrict fmt, va_list va) 10 | { 11 | return vsnprintf(s, SIZE_MAX, fmt, va); 12 | } 13 | -------------------------------------------------------------------------------- /lib/crt/Makefile: -------------------------------------------------------------------------------- 1 | .POSIX: 2 | 3 | include ../../config.mk 4 | 5 | all: 6 | 7 | dep: 8 | ./gendep.sh $(TARGETS) 9 | 10 | clean: 11 | rm -f */crt.o 12 | 13 | distclean: clean 14 | rm -f makefile 15 | -------------------------------------------------------------------------------- /lib/crt/amd64-sysv-linux/crt.s: -------------------------------------------------------------------------------- 1 | .file "crt.s" 2 | 3 | .text 4 | .global _start 5 | _start: 6 | call main 7 | movl %eax, %edi 8 | call exit 9 | -------------------------------------------------------------------------------- /lib/crt/amd64-sysv-openbsd/crt.s: -------------------------------------------------------------------------------- 1 | .file "crt.s" 2 | 3 | .section ".note.openbsd.ident", "a" 4 | .p2align 2 5 | .long 8 6 | .long 4 7 | .long 1 8 | .ascii "OpenBSD\0" 9 | .long 0 10 | .p2align 2 11 | 12 | .text 13 | .align 8 14 | .global _start 15 | _start: 16 | call main 17 | movl %eax, %edi 18 | call exit 19 | 20 | .data 21 | .global __guard_local 22 | __guard_local: 23 | .long 0 24 | -------------------------------------------------------------------------------- /lib/crt/gendep.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | rm -f makefile $$.tmp 6 | trap "rm -f $$.mk $$.tmp" 0 2 3 7 | 8 | re='\([^-]*\)-\([^-]*\)-\([^-]*\)-\([^-]*\)' 9 | 10 | echo $@ | 11 | tr ' ' '\n' | 12 | sed "s/$re/\1-\2-\3/" | 13 | sort -u | 14 | (cat Makefile 15 | echo 16 | while read i 17 | do 18 | cat <> $$.tmp 19 | mkdir -p ../../rootdir/lib/scc/crt/$i 20 | cp $i/crt.o ../../rootdir/lib/scc/crt/$i/ 21 | EOF 22 | echo all: $i/crt.o 23 | done 24 | echo all: 25 | cat $$.tmp) > $$.mk && mv $$.mk makefile 26 | -------------------------------------------------------------------------------- /lib/crt/i386-sysv-linux/crt.s: -------------------------------------------------------------------------------- 1 | /* TODO */ 2 | -------------------------------------------------------------------------------- /lib/crt/i386-sysv-openbsd/crt.s: -------------------------------------------------------------------------------- 1 | /* TODO */ 2 | -------------------------------------------------------------------------------- /lib/crt/z80-scc-none/crt.s: -------------------------------------------------------------------------------- 1 | .file "crt.s" 2 | 3 | .text 4 | .global _start 5 | _start: 6 | call main 7 | # ex %de,%hl 8 | call exit 9 | -------------------------------------------------------------------------------- /lib/scc/Makefile: -------------------------------------------------------------------------------- 1 | .POSIX: 2 | 3 | LIBDIR = ./ 4 | include ../../config.mk 5 | include libdep.mk 6 | 7 | all: libscc.a 8 | 9 | $(LIB-OBJ): ../../inc/scc.h 10 | $(LIBDIR)/wmyro.o: ../../inc/myro.h 11 | $(LIBDIR)/rmyro.o: ../../inc/myro.h 12 | 13 | libscc.a: $(LIB-OBJ) 14 | ar $(ARFLAGS) $@ $? 15 | ranlib $@ 16 | 17 | dep: 18 | 19 | clean: 20 | rm -f *.o *.a 21 | 22 | distclean: clean 23 | -------------------------------------------------------------------------------- /lib/scc/casecmp.c: -------------------------------------------------------------------------------- 1 | static char sccsid[] = "@(#) ./lib/scc/casecmp.c"; 2 | #include 3 | #include "../../inc/scc.h" 4 | 5 | int 6 | casecmp(const char *s1, const char *s2) 7 | { 8 | while (*s1 && toupper(*s1) == toupper(*s2)) 9 | ++s1, ++s2; 10 | return *s1 - *s2; 11 | } 12 | -------------------------------------------------------------------------------- /lib/scc/debug.c: -------------------------------------------------------------------------------- 1 | static char sccsid[] = "@(#) ./lib/scc/debug.c"; 2 | #include 3 | #include 4 | 5 | #include "../../inc/scc.h" 6 | 7 | int debug; 8 | 9 | void 10 | dbg(const char *fmt, ...) 11 | { 12 | if (!debug) 13 | return; 14 | va_list va; 15 | va_start(va, fmt); 16 | vfprintf(stderr, fmt, va); 17 | putc('\n', stderr); 18 | va_end(va); 19 | return; 20 | } 21 | -------------------------------------------------------------------------------- /lib/scc/die.c: -------------------------------------------------------------------------------- 1 | static char sccsid[] = "@(#) ./lib/scc/die.c"; 2 | #include 3 | #include 4 | #include 5 | 6 | #include "../../inc/scc.h" 7 | 8 | int failure; 9 | 10 | void 11 | die(const char *fmt, ...) 12 | { 13 | failure = 1; 14 | va_list va; 15 | va_start(va, fmt); 16 | vfprintf(stderr, fmt, va); 17 | putc('\n', stderr); 18 | va_end(va); 19 | exit(1); 20 | } 21 | -------------------------------------------------------------------------------- /lib/scc/libdep.mk: -------------------------------------------------------------------------------- 1 | LIB-OBJ = $(LIBDIR)/debug.o \ 2 | $(LIBDIR)/die.o \ 3 | $(LIBDIR)/newitem.o \ 4 | $(LIBDIR)/xcalloc.o \ 5 | $(LIBDIR)/xmalloc.o \ 6 | $(LIBDIR)/xrealloc.o \ 7 | $(LIBDIR)/xstrdup.o \ 8 | $(LIBDIR)/alloc.o \ 9 | $(LIBDIR)/casecmp.o \ 10 | $(LIBDIR)/lunpack.o \ 11 | $(LIBDIR)/lpack.o \ 12 | $(LIBDIR)/wmyro.o \ 13 | $(LIBDIR)/rmyro.o \ 14 | -------------------------------------------------------------------------------- /lib/scc/lpack.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "../../inc/scc.h" 4 | 5 | int 6 | lpack(unsigned char *dst, char *fmt, ...) 7 | { 8 | unsigned char *bp; 9 | unsigned s; 10 | unsigned long l; 11 | unsigned long long q; 12 | va_list va; 13 | 14 | bp = dst; 15 | va_start(va, fmt); 16 | while (*fmt) { 17 | switch (*fmt++) { 18 | case 'c': 19 | *bp++ = va_arg(va, unsigned); 20 | break; 21 | case 's': 22 | s = va_arg(va, unsigned); 23 | *bp++ = s >> 8; 24 | *bp++ = s; 25 | break; 26 | case 'l': 27 | l = va_arg(va, unsigned long); 28 | *bp++ = l >> 24; 29 | *bp++ = l >> 16; 30 | *bp++ = l >> 8; 31 | *bp++ = l; 32 | break; 33 | case 'q': 34 | q = va_arg(va, unsigned long long); 35 | *bp++ = q >> 56; 36 | *bp++ = q >> 48; 37 | *bp++ = q >> 40; 38 | *bp++ = q >> 32; 39 | *bp++ = q >> 24; 40 | *bp++ = q >> 16; 41 | *bp++ = q >> 8; 42 | *bp++ = q; 43 | break; 44 | default: 45 | va_end(va); 46 | return -1; 47 | } 48 | } 49 | va_end(va); 50 | 51 | return bp - dst; 52 | } 53 | -------------------------------------------------------------------------------- /lib/scc/lunpack.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "../../inc/scc.h" 4 | 5 | int 6 | lunpack(unsigned char *src, char *fmt, ...) 7 | { 8 | unsigned char *bp, *cp; 9 | unsigned short *sp; 10 | unsigned s; 11 | unsigned long *lp, l; 12 | unsigned long long *qp, q; 13 | va_list va; 14 | 15 | bp = src; 16 | va_start(va, fmt); 17 | while (*fmt) { 18 | switch (*fmt++) { 19 | case 'c': 20 | cp = va_arg(va, unsigned char *); 21 | *cp = *bp++; 22 | break; 23 | case 's': 24 | sp = va_arg(va, unsigned short *); 25 | s = (unsigned) *bp++ << 8; 26 | s |= (unsigned) *bp++; 27 | *sp = s; 28 | break; 29 | case 'l': 30 | lp = va_arg(va, unsigned long *); 31 | l = (unsigned long) *bp++ << 24; 32 | l |= (unsigned long) *bp++ << 16; 33 | l |= (unsigned long) *bp++ << 8; 34 | l |= (unsigned long) *bp++; 35 | *lp = l; 36 | break; 37 | case 'q': 38 | qp = va_arg(va, unsigned long long *); 39 | q = (unsigned long long) *bp++ << 56; 40 | q |= (unsigned long long) *bp++ << 48; 41 | q |= (unsigned long long) *bp++ << 40; 42 | q |= (unsigned long long) *bp++ << 32; 43 | q |= (unsigned long long) *bp++ << 24; 44 | q |= (unsigned long long) *bp++ << 16; 45 | q |= (unsigned long long) *bp++ << 8; 46 | q |= (unsigned long long) *bp++; 47 | *qp = q; 48 | break; 49 | default: 50 | va_end(va); 51 | return -1; 52 | } 53 | } 54 | va_end(va); 55 | 56 | return bp - src; 57 | } 58 | -------------------------------------------------------------------------------- /lib/scc/newitem.c: -------------------------------------------------------------------------------- 1 | #include "../../inc/scc.h" 2 | 3 | void 4 | newitem(struct items *items, char *item) 5 | { 6 | if ((items->n + 1) < items->n) 7 | die("newitem: overflow (%u + 1)", items->n); 8 | 9 | items->s = xrealloc(items->s, (items->n + 1) * sizeof(char **)); 10 | items->s[items->n++] = item; 11 | } 12 | 13 | -------------------------------------------------------------------------------- /lib/scc/xcalloc.c: -------------------------------------------------------------------------------- 1 | static char sccsid[] = "@(#) ./lib/scc/xcalloc.c"; 2 | #include 3 | #include "../../inc/scc.h" 4 | 5 | void * 6 | xcalloc(size_t n, size_t size) 7 | { 8 | void *p = calloc(n, size); 9 | 10 | if (!p) 11 | die("out of memory"); 12 | return p; 13 | } 14 | -------------------------------------------------------------------------------- /lib/scc/xmalloc.c: -------------------------------------------------------------------------------- 1 | static char sccsid[] = "@(#) ./lib/scc/xmalloc.c"; 2 | #include 3 | #include "../../inc/scc.h" 4 | 5 | void * 6 | xmalloc(size_t size) 7 | { 8 | void *p = malloc(size); 9 | 10 | if (!p) 11 | die("out of memory"); 12 | return p; 13 | } 14 | -------------------------------------------------------------------------------- /lib/scc/xrealloc.c: -------------------------------------------------------------------------------- 1 | static char sccsid[] = "@(#) ./lib/scc/xrealloc.c"; 2 | #include 3 | #include "../../inc/scc.h" 4 | 5 | void * 6 | xrealloc(void *buff, size_t size) 7 | { 8 | void *p = realloc(buff, size); 9 | 10 | if (!p) 11 | die("out of memory"); 12 | return p; 13 | } 14 | -------------------------------------------------------------------------------- /lib/scc/xstrdup.c: -------------------------------------------------------------------------------- 1 | static char sccsid[] = "@(#) ./lib/scc/xstrdup.c"; 2 | #include 3 | #include "../../inc/scc.h" 4 | 5 | char * 6 | xstrdup(const char *s) 7 | { 8 | size_t len = strlen(s) + 1; 9 | char *p = xmalloc(len); 10 | 11 | return memcpy(p, s, len); 12 | } 13 | -------------------------------------------------------------------------------- /lib/sys/Makefile: -------------------------------------------------------------------------------- 1 | .POSIX: 2 | 3 | include ../../config.mk 4 | 5 | all clean distclean: 6 | +@pwd=$$PWD ;\ 7 | for i in $(SYSS); \ 8 | do \ 9 | cd $$i; \ 10 | $(MAKE) -e SYS=$i $@ ;\ 11 | cd $$pwd; \ 12 | done 13 | -------------------------------------------------------------------------------- /lib/sys/abi/amd64-sysv.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # This job is very easy because app and kernel ABI are identical 5 | # until the 4th parameter, so we only have to set the syscall 6 | # number in rax 7 | 8 | awk '/^#/ {next} 9 | {name=$2 ".s" 10 | printf ".global %s\n" \ 11 | "%s:\n" \ 12 | "\tmovq\t$%d,%%rax\n" \ 13 | "\tsyscall\n" \ 14 | "\tret\n", $2, $2, $1 > name 15 | close(name)}' syscall.lst 16 | -------------------------------------------------------------------------------- /lib/sys/amd64-sysv-linux/Makefile: -------------------------------------------------------------------------------- 1 | .POSIX: 2 | 3 | include ../common.mk 4 | ABI = amd64-sysv 5 | -------------------------------------------------------------------------------- /lib/sys/amd64-sysv-linux/syscall.lst: -------------------------------------------------------------------------------- 1 | #number name 2 | 0 _read 3 | 1 _write 4 | 2 _open 5 | 3 _close 6 | 3 _lseek 7 | 12 _brk 8 | 13 _rt_sigaction 9 | 38 _getpid 10 | 60 _Exit 11 | 32 _kill 12 | -------------------------------------------------------------------------------- /lib/sys/common.mk: -------------------------------------------------------------------------------- 1 | .POSIX: 2 | 3 | include ../../../config.mk 4 | 5 | all clean distclean: system.mk 6 | +$(MAKE) ABI=$(ABI) -f ../libsys.mk $@ 7 | 8 | system.mk: syscall.lst 9 | rm -f $@; trap "rm -f $$$$.mk" 0 2 3; \ 10 | awk 'BEGIN{printf "OBJ = "} \ 11 | ! /^#/ {printf "%s.o ", $$2}' syscall.lst > $$$$.mk && \ 12 | mv $$$$.mk $@ 13 | -------------------------------------------------------------------------------- /lib/sys/i386-sysv-linux/Makefile: -------------------------------------------------------------------------------- 1 | .POSIX: 2 | 3 | include ../Makefile.sys 4 | -------------------------------------------------------------------------------- /lib/sys/i386-sysv-linux/syscall.lst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/k0gaMSX/scc/e53520a8ec6d7838423fea56e1b028ced9558f59/lib/sys/i386-sysv-linux/syscall.lst -------------------------------------------------------------------------------- /lib/sys/libsys.mk: -------------------------------------------------------------------------------- 1 | .POSIX: 2 | 3 | include ../../../config.mk 4 | include system.mk 5 | 6 | ASM = $(OBJ:.o=.s) 7 | 8 | all: libsys.a 9 | 10 | libsys.a: $(OBJ) 11 | $(AR) $(ARFLAGS) $@ $? 12 | ranlib $@ 13 | 14 | $(ASM): syscall.lst 15 | ../abi/$(ABI).sh 16 | 17 | clean: 18 | rm -f $(ASM) 19 | rm -f $(OBJ) 20 | rm -f libsys.a 21 | 22 | distclean: clean 23 | rm -f system.mk 24 | -------------------------------------------------------------------------------- /lib/sys/qbe-linux/Makefile: -------------------------------------------------------------------------------- 1 | .POSIX: 2 | 3 | include ../common.mk 4 | ABI=amd64-sysv 5 | -------------------------------------------------------------------------------- /lib/sys/qbe-linux/syscall.lst: -------------------------------------------------------------------------------- 1 | #number name 2 | 0 _read 3 | 1 _write 4 | 2 _open 5 | 3 _close 6 | 3 _lseek 7 | 12 _brk 8 | 13 _rt_sigaction 9 | 38 _getpid 10 | 60 _Exit 11 | 32 _kill 12 | -------------------------------------------------------------------------------- /lib/sys/z80-linux/Makefile: -------------------------------------------------------------------------------- 1 | .POSIX: 2 | 3 | include ../Makefile.sys 4 | -------------------------------------------------------------------------------- /lib/sys/z80-linux/syscall.lst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/k0gaMSX/scc/e53520a8ec6d7838423fea56e1b028ced9558f59/lib/sys/z80-linux/syscall.lst -------------------------------------------------------------------------------- /nm/Makefile: -------------------------------------------------------------------------------- 1 | .POSIX: 2 | 3 | LIBDIR = ../lib/scc 4 | include ../config.mk 5 | include $(LIBDIR)/libdep.mk 6 | 7 | OBJ = main.o 8 | 9 | all: nm 10 | 11 | nm: $(OBJ) $(LIBDIR)/libscc.a 12 | $(CC) $(SCC_LDFLAGS) $(OBJ) -lscc -o $@ 13 | 14 | main.o: ../inc/scc.h ../inc/ar.h ../inc/myro.h 15 | 16 | $(LIBDIR)/libscc.a: $(LIB-OBJ) 17 | +cd $(LIBDIR) && $(MAKE) 18 | 19 | dep: 20 | clean: 21 | rm -f nm *.o 22 | 23 | distclean: clean 24 | -------------------------------------------------------------------------------- /objdump/Makefile: -------------------------------------------------------------------------------- 1 | .POSIX: 2 | 3 | LIBDIR = ../lib/scc 4 | include ../config.mk 5 | include $(LIBDIR)/libdep.mk 6 | 7 | OBJ = main.o 8 | 9 | all: objdump 10 | 11 | objdump: $(OBJ) $(LIBDIR)/libscc.a 12 | $(CC) $(SCC_LDFLAGS) $(OBJ) -lscc -o $@ 13 | 14 | main.o: ../inc/scc.h ../inc/myro.h ../inc/arg.h 15 | 16 | $(LIBDIR)/libscc.a: $(LIB-OBJ) 17 | +cd $(LIBDIR) && $(MAKE) 18 | 19 | dep: 20 | clean: 21 | rm -f objdump *.o 22 | 23 | distclean: clean 24 | -------------------------------------------------------------------------------- /system.mk: -------------------------------------------------------------------------------- 1 | # Plan9 2 | SYSCFLAGS = -D_SUSV2_SOURCE 3 | 4 | # NetBSD 5 | CC1_CFLAGS = -D_ISOC99_SOURCE -D_ANSI_SOURCE 6 | CC2_CFLAGS = -D_ISOC99_SOURCE -D_ANSI_SOURCE 7 | AS_CFLAGS = -D_ISOC99_SOURCE -D_ANSI_SOURCE 8 | 9 | # OpenBSD 10 | CC1_CFLAGS = -D_ISOC99_SOURCE -D_ANSI_SOURCE 11 | CC2_CFLAGS = -D_ISOC99_SOURCE -D_ANSI_SOURCE 12 | AS_CFLAGS = -D_ISOC99_SOURCE -D_ANSI_SOURCE 13 | 14 | # FreeBSD 15 | CC1_CFLAGS = -D_ISOC99_SOURCE -D_ANSI_SOURCE 16 | CC2_CFLAGS = -D_ISOC99_SOURCE -D_ANSI_SOURCE 17 | AS_CFLAGS = -D_ISOC99_SOURCE -D_ANSI_SOURCE 18 | 19 | -------------------------------------------------------------------------------- /tests/Makefile: -------------------------------------------------------------------------------- 1 | .POSIX: 2 | 3 | all clean dep distclean: 4 | cd error && make -e $@ 5 | cd execute && make -e $@ 6 | -------------------------------------------------------------------------------- /tests/error/0001-sanity.c: -------------------------------------------------------------------------------- 1 | /* 2 | PATTERN: 3 | 0001-sanity.c:9: error: 'FOO' undeclared 4 | . 5 | */ 6 | 7 | int main() 8 | { 9 | return FOO; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /tests/error/0002-missinginclude.c: -------------------------------------------------------------------------------- 1 | /* 2 | PATTERN: 3 | 0002-missinginclude.c:7: error: included file 'MISSING.h' not found 4 | . 5 | */ 6 | 7 | #include "MISSING.h" 8 | -------------------------------------------------------------------------------- /tests/error/0003-junkinclude.c: -------------------------------------------------------------------------------- 1 | /* 2 | PATTERN: 3 | 0003-junkinclude.c:7: error: trailing characters after preprocessor directive 4 | . 5 | */ 6 | 7 | #include "0003-junkinclude.c" bar 8 | -------------------------------------------------------------------------------- /tests/error/0004-macroredef.c: -------------------------------------------------------------------------------- 1 | /* 2 | PATTERN: 3 | 0004-macroredef.c:8: warning: 'X' redefined 4 | . 5 | */ 6 | 7 | #define X 1 8 | #define X 2 9 | 10 | -------------------------------------------------------------------------------- /tests/error/0005-fmacro.c: -------------------------------------------------------------------------------- 1 | /* 2 | PATTERN: 3 | 0005-fmacro.c:7: error: macro arguments must be identifiers 4 | . 5 | */ 6 | 7 | #define X( 8 | 9 | -------------------------------------------------------------------------------- /tests/error/0006-endif.c: -------------------------------------------------------------------------------- 1 | /* 2 | PATTERN: 3 | 0006-endif.c:7: error: #endif without #if 4 | . 5 | */ 6 | 7 | #endif 8 | 9 | -------------------------------------------------------------------------------- /tests/error/0007-unmatchedcppif.c: -------------------------------------------------------------------------------- 1 | /* 2 | PATTERN: 3 | 4 | . 5 | */ 6 | 7 | #ifdef FOO 8 | 9 | 10 | -------------------------------------------------------------------------------- /tests/error/0008-unmatchedcppelse.c: -------------------------------------------------------------------------------- 1 | /* 2 | PATTERN: 3 | 0008-unmatchedcppelse.c:7: error: #else without #ifdef/ifndef 4 | . 5 | */ 6 | 7 | #else 8 | 9 | 10 | -------------------------------------------------------------------------------- /tests/error/0009-unmatchedcppelif.c: -------------------------------------------------------------------------------- 1 | /* 2 | PATTERN: 3 | 4 | . 5 | */ 6 | 7 | #elif 1 8 | 9 | -------------------------------------------------------------------------------- /tests/error/0010-extraelif.c: -------------------------------------------------------------------------------- 1 | /* 2 | PATTERN: 3 | 4 | . 5 | */ 6 | 7 | #if 1 8 | 9 | #else 10 | 11 | #elif 0 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /tests/error/0011-extraelse.c: -------------------------------------------------------------------------------- 1 | /* 2 | PATTERN: 3 | 4 | . 5 | */ 6 | 7 | #if 1 8 | 9 | #else 10 | 11 | #else 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /tests/error/0012-ifnoexpr.c: -------------------------------------------------------------------------------- 1 | /* 2 | PATTERN: 3 | 0012-ifnoexpr.c:7: error: unexpected ' 4 | ' 5 | . 6 | */ 7 | 8 | #if 9 | #endif 10 | 11 | -------------------------------------------------------------------------------- /tests/error/0013-macro.c: -------------------------------------------------------------------------------- 1 | /* 2 | PATTERN: 3 | 0013-macro.c:9: error: macro "X" received 0 arguments, but it takes 1 4 | . 5 | */ 6 | 7 | #define X(A, ...) 0 8 | 9 | X() 10 | 11 | -------------------------------------------------------------------------------- /tests/error/0014-macro.c: -------------------------------------------------------------------------------- 1 | /* 2 | PATTERN: 3 | 0014-macro.c:9: error: macro "X" received 1 arguments, but it takes 0 4 | . 5 | */ 6 | 7 | #define X() 0 8 | 9 | X(A) 10 | 11 | -------------------------------------------------------------------------------- /tests/error/0015-macro.c: -------------------------------------------------------------------------------- 1 | /* 2 | PATTERN: 3 | 4 | . 5 | */ 6 | 7 | #define X(A, A) 0 8 | 9 | -------------------------------------------------------------------------------- /tests/error/0016-arrayinitsize.c: -------------------------------------------------------------------------------- 1 | /* 2 | PATTERN: 3 | 4 | . 5 | */ 6 | 7 | int x[2] = {1, 2, 3}; 8 | -------------------------------------------------------------------------------- /tests/error/0017-duplicatefunc.c: -------------------------------------------------------------------------------- 1 | /* 2 | PATTERN: 3 | 0017-duplicatefunc.c:15: error: redefinition of 'main' 4 | . 5 | */ 6 | 7 | int 8 | main() 9 | { 10 | return 0; 11 | } 12 | 13 | int 14 | main() 15 | { 16 | return 0; 17 | } 18 | 19 | -------------------------------------------------------------------------------- /tests/error/0018-voidparam.c: -------------------------------------------------------------------------------- 1 | /* 2 | PATTERN: 3 | 0018-voidparam.c:27: error: a named argument is requiered before '...' 4 | . 5 | */ 6 | 7 | 8 | int 9 | a(void, int i) 10 | { 11 | return 0; 12 | } 13 | 14 | int 15 | b(int i, void) 16 | { 17 | return 0; 18 | } 19 | 20 | int 21 | c(void, void) 22 | { 23 | return 0; 24 | } 25 | 26 | int 27 | d(void, ...) 28 | { 29 | return 0; 30 | } 31 | 32 | int 33 | main() 34 | { 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /tests/error/0019-kr_names.c: -------------------------------------------------------------------------------- 1 | /* 2 | PATTERN: 3 | 0019-kr_names.c:9: warning: parameter names (without types) in function declaration 4 | 0019-kr_names.c:13: warning: type of 'a' defaults to int 5 | 0019-kr_names.c:13: warning: type of 'c' defaults to int 6 | . 7 | */ 8 | 9 | int f(a,b); 10 | 11 | int 12 | f(a,b,c) char b; 13 | { 14 | return a - c + b; 15 | } 16 | 17 | int 18 | main(void) 19 | { 20 | return f(1,0,1); 21 | } 22 | -------------------------------------------------------------------------------- /tests/error/0020-storage.c: -------------------------------------------------------------------------------- 1 | int a; 2 | static char b; 3 | extern int c; 4 | typedef unsigned e; 5 | 6 | int 7 | func1(void) 8 | { 9 | auto h; 10 | static char i; 11 | register long j; 12 | extern int k; 13 | static unsigned long a; 14 | return 0; 15 | } 16 | 17 | void 18 | func2(register int par) 19 | { 20 | int par; 21 | } 22 | 23 | static void 24 | func3(register int par) 25 | { 26 | } 27 | 28 | register short d; 29 | 30 | register void 31 | func4(static int par) 32 | { 33 | static register f; 34 | } 35 | 36 | short d; 37 | char d; 38 | -------------------------------------------------------------------------------- /tests/error/0021-namespace.c: -------------------------------------------------------------------------------- 1 | typedef struct s s; 2 | 3 | struct s { 4 | struct s1 { 5 | int s; 6 | struct s2 { 7 | int s; 8 | } s1; 9 | } s; 10 | } s2; 11 | 12 | #define s s 13 | 14 | int 15 | main(void) 16 | { 17 | #undef s 18 | goto s; 19 | struct s s; 20 | { 21 | int s; 22 | return s; 23 | } 24 | return s.s.s + s.s.s1.s; 25 | s: 26 | { 27 | s: return 0; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /tests/error/0021-void.c: -------------------------------------------------------------------------------- 1 | int 2 | main(void) 3 | { 4 | void f(void); 5 | 6 | return (int) f(); 7 | } 8 | -------------------------------------------------------------------------------- /tests/error/0022-cpp-if.c: -------------------------------------------------------------------------------- 1 | #if 3 != (1,2,3) 2 | #error 3 != (1,2,3) 3 | #endif 4 | 5 | int 6 | main() 7 | { 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/error/0023-include.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Test a comment that goes beyond of the end of an 3 | * included file 4 | */ 5 | 6 | #include "0023-include.h" 7 | -------------------------------------------------------------------------------- /tests/error/0023-include.h: -------------------------------------------------------------------------------- 1 | #ifndef TEST_H_ 2 | #define TEST_H_ 3 | 4 | /* 5 | This is an unterminated comment. 6 | 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /tests/error/Makefile: -------------------------------------------------------------------------------- 1 | .POSIX: 2 | 3 | all: tests 4 | 5 | tests: 6 | CFLAGS='' SCCEXECPATH=../../bin PATH=../../bin:$$PATH ./chktest.sh < scc-tests.lst 7 | 8 | clean: 9 | rm -f *.as *.o *.ir *.qbe *core test.log 10 | 11 | -------------------------------------------------------------------------------- /tests/error/README: -------------------------------------------------------------------------------- 1 | These tests are taken from https://github.com/andrewchambers/qc. 2 | All the credits for this test suite are for Andrew Chambers. 3 | -------------------------------------------------------------------------------- /tests/error/chktest.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | err=/tmp/$$.err 4 | chk=/tmp/$$.chk 5 | 6 | trap "tabs -8;rm -f a.out *.o $chk $err" 0 1 2 3 15 7 | tabs 40 8 | ulimit -c 0 9 | rm -f test.log 10 | 11 | while read i state 12 | do 13 | echo $i >> test.log 14 | printf "%s\t%s" $i $state 15 | 16 | scc $CFLAGS -w -c $i 2> $err 17 | echo "/^PATTERN/+;/^\./-w $chk" | ed -s $i 18 | diff -c $chk $err >> test.log && echo [OK] || echo [FAILED] 19 | rm -f *.o 20 | done 21 | -------------------------------------------------------------------------------- /tests/error/scc-tests.lst: -------------------------------------------------------------------------------- 1 | 0001-sanity.c 2 | 0002-missinginclude.c 3 | 0003-junkinclude.c 4 | 0004-macroredef.c 5 | 0005-fmacro.c 6 | 0006-endif.c 7 | 0007-unmatchedcppif.c [TODO] 8 | 0008-unmatchedcppelse.c 9 | 0009-unmatchedcppelif.c [TODO] 10 | 0010-extraelif.c [TODO] 11 | 0011-extraelse.c [TODO] 12 | 0012-ifnoexpr.c [TODO] 13 | 0013-macro.c 14 | 0014-macro.c 15 | 0015-macro.c [TODO] 16 | 0016-arrayinitsize.c [TODO] 17 | 0017-duplicatefunc.c 18 | 0018-voidparam.c [TODO] 19 | 0019-kr_names.c 20 | 0020-storage.c [TODO] 21 | 0021-void.c [TODO] 22 | 0022-cpp-if.c [TODO] 23 | 0023-include.c [TODO] 24 | -------------------------------------------------------------------------------- /tests/error/update.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | for i 4 | do 5 | (echo '/^PATTERN/+;/^\./-c' 6 | scc $CFLAGS -w -c $i 2>&1 7 | printf ".\nw\n" 8 | echo w) | 9 | ed -s $i 10 | done 11 | -------------------------------------------------------------------------------- /tests/execute/0001-sanity.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /tests/execute/0002-expr.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | return 3-3; 5 | } 6 | -------------------------------------------------------------------------------- /tests/execute/0003-local.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int x; 5 | 6 | x = 4; 7 | return x - 4; 8 | } 9 | -------------------------------------------------------------------------------- /tests/execute/0004-pointer.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int x; 5 | int *p; 6 | 7 | x = 4; 8 | p = &x; 9 | *p = 0; 10 | 11 | return *p; 12 | } 13 | -------------------------------------------------------------------------------- /tests/execute/0005-ifstmt.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int x; 5 | int *p; 6 | int **pp; 7 | 8 | x = 0; 9 | p = &x; 10 | pp = &p; 11 | 12 | if(*p) 13 | return 1; 14 | if(**pp) 15 | return 1; 16 | else 17 | **pp = 1; 18 | 19 | if(x) 20 | return 0; 21 | else 22 | return 1; 23 | } 24 | -------------------------------------------------------------------------------- /tests/execute/0006-whilestmt.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int x; 5 | 6 | x = 50; 7 | while (x) 8 | x = x - 1; 9 | return x; 10 | } 11 | -------------------------------------------------------------------------------- /tests/execute/0007-forstmt.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int x; 5 | 6 | x = 1; 7 | for(x = 10; x; x = x - 1) 8 | ; 9 | if(x) 10 | return 1; 11 | x = 10; 12 | for (;x;) 13 | x = x - 1; 14 | return x; 15 | } 16 | -------------------------------------------------------------------------------- /tests/execute/0008-dowhilestmt.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int x; 5 | 6 | x = 50; 7 | do 8 | x = x - 1; 9 | while(x); 10 | return x; 11 | } 12 | -------------------------------------------------------------------------------- /tests/execute/0009-expr.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int x; 5 | 6 | x = 1; 7 | x = x * 10; 8 | x = x / 2; 9 | x = x % 3; 10 | return x - 2; 11 | } 12 | -------------------------------------------------------------------------------- /tests/execute/0010-goto.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | start: 5 | goto next; 6 | return 1; 7 | success: 8 | return 0; 9 | next: 10 | foo: 11 | goto success; 12 | return 1; 13 | } 14 | -------------------------------------------------------------------------------- /tests/execute/0011-assign.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int x; 5 | int y; 6 | x = y = 0; 7 | return x; 8 | } 9 | -------------------------------------------------------------------------------- /tests/execute/0012-expr.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | return (2 + 2) * 2 - 8; 5 | } 6 | -------------------------------------------------------------------------------- /tests/execute/0013-addridx.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int x; 5 | int *p; 6 | 7 | x = 0; 8 | p = &x; 9 | return p[0]; 10 | } 11 | -------------------------------------------------------------------------------- /tests/execute/0014-assignidx.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int x; 5 | int *p; 6 | 7 | x = 1; 8 | p = &x; 9 | p[0] = 0; 10 | return x; 11 | } 12 | -------------------------------------------------------------------------------- /tests/execute/0015-localarray.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int arr[2]; 5 | 6 | arr[0] = 1; 7 | arr[1] = 2; 8 | 9 | return arr[0] + arr[1] - 3; 10 | } 11 | -------------------------------------------------------------------------------- /tests/execute/0016-addrarray.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int arr[2]; 5 | int *p; 6 | 7 | p = &arr[1]; 8 | *p = 0; 9 | return arr[1]; 10 | } 11 | -------------------------------------------------------------------------------- /tests/execute/0017-struct.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | struct { int x; int y; } s; 5 | 6 | s.x = 3; 7 | s.y = 5; 8 | return s.y - s.x - 2; 9 | } 10 | -------------------------------------------------------------------------------- /tests/execute/0018-structptr.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | 5 | struct S { int x; int y; } s; 6 | struct S *p; 7 | 8 | p = &s; 9 | s.x = 1; 10 | p->y = 2; 11 | return p->y + p->x - 3; 12 | } 13 | 14 | -------------------------------------------------------------------------------- /tests/execute/0019-selfrefstruct.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | struct S { struct S *p; int x; } s; 5 | 6 | s.x = 0; 7 | s.p = &s; 8 | return s.p->p->p->p->p->x; 9 | } 10 | 11 | -------------------------------------------------------------------------------- /tests/execute/0020-ptrptr.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int x, *p, **pp; 5 | 6 | x = 0; 7 | p = &x; 8 | pp = &p; 9 | return **pp; 10 | } 11 | -------------------------------------------------------------------------------- /tests/execute/0021-intfunc.c: -------------------------------------------------------------------------------- 1 | int 2 | foo(int a, int b) 3 | { 4 | return 2 + a - b; 5 | } 6 | 7 | int 8 | main() 9 | { 10 | return foo(1, 3); 11 | } 12 | 13 | -------------------------------------------------------------------------------- /tests/execute/0022-typedef.c: -------------------------------------------------------------------------------- 1 | typedef int x; 2 | 3 | int 4 | main() 5 | { 6 | x v; 7 | v = 0; 8 | return v; 9 | } 10 | 11 | -------------------------------------------------------------------------------- /tests/execute/0023-global.c: -------------------------------------------------------------------------------- 1 | int x; 2 | 3 | int 4 | main() 5 | { 6 | x = 0; 7 | return x; 8 | } 9 | 10 | -------------------------------------------------------------------------------- /tests/execute/0024-typedefstruct.c: -------------------------------------------------------------------------------- 1 | typedef struct { int x; int y; } s; 2 | 3 | s v; 4 | 5 | int 6 | main() 7 | { 8 | v.x = 1; 9 | v.y = 2; 10 | return 3 - v.x - v.y; 11 | } 12 | 13 | -------------------------------------------------------------------------------- /tests/execute/0025-string.c: -------------------------------------------------------------------------------- 1 | int strlen(char *); 2 | 3 | int 4 | main() 5 | { 6 | char *p; 7 | 8 | p = "hello"; 9 | return strlen(p) - 5; 10 | } 11 | -------------------------------------------------------------------------------- /tests/execute/0026-implicitret.c: -------------------------------------------------------------------------------- 1 | main() 2 | { 3 | return 0; 4 | } 5 | 6 | -------------------------------------------------------------------------------- /tests/execute/0027-charval.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | char *p; 5 | 6 | p = "hello"; 7 | return p[0] - 104; 8 | } 9 | -------------------------------------------------------------------------------- /tests/execute/0028-bor.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int x; 5 | 6 | x = 1; 7 | x = x | 4; 8 | return x - 5; 9 | } 10 | 11 | -------------------------------------------------------------------------------- /tests/execute/0029-band.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int x; 5 | 6 | x = 1; 7 | x = x & 3; 8 | return x - 1; 9 | } 10 | 11 | -------------------------------------------------------------------------------- /tests/execute/0030-bxor.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int x; 5 | 6 | x = 1; 7 | x = x ^ 3; 8 | return x - 2; 9 | } 10 | 11 | -------------------------------------------------------------------------------- /tests/execute/0031-relop.c: -------------------------------------------------------------------------------- 1 | int 2 | f() 3 | { 4 | return 100; 5 | } 6 | 7 | int 8 | main() 9 | { 10 | if (f() > 1000) 11 | return 1; 12 | if (f() >= 1000) 13 | return 1; 14 | if (1000 < f()) 15 | return 1; 16 | if (1000 <= f()) 17 | return 1; 18 | if (1000 == f()) 19 | return 1; 20 | if (100 != f()) 21 | return 1; 22 | return 0; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /tests/execute/0032-indec.c: -------------------------------------------------------------------------------- 1 | int 2 | zero() 3 | { 4 | return 0; 5 | } 6 | 7 | int 8 | one() 9 | { 10 | return 1; 11 | } 12 | 13 | int 14 | main() 15 | { 16 | int x; 17 | int y; 18 | 19 | x = zero(); 20 | y = ++x; 21 | if (x != 1) 22 | return 1; 23 | if (y != 1) 24 | return 1; 25 | 26 | x = one(); 27 | y = --x; 28 | if (x != 0) 29 | return 1; 30 | if (y != 0) 31 | return 1; 32 | 33 | x = zero(); 34 | y = x++; 35 | if (x != 1) 36 | return 1; 37 | if (y != 0) 38 | return 1; 39 | 40 | x = one(); 41 | y = x--; 42 | if (x != 0) 43 | return 1; 44 | if (y != 1) 45 | return 1; 46 | 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /tests/execute/0033-ptrindec.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int arr[2]; 5 | int *p; 6 | 7 | arr[0] = 2; 8 | arr[1] = 3; 9 | p = &arr[0]; 10 | if(*(p++) != 2) 11 | return 1; 12 | if(*(p++) != 3) 13 | return 2; 14 | 15 | p = &arr[1]; 16 | if(*(p--) != 3) 17 | return 1; 18 | if(*(p--) != 2) 19 | return 2; 20 | 21 | p = &arr[0]; 22 | if(*(++p) != 3) 23 | return 1; 24 | 25 | p = &arr[1]; 26 | if(*(--p) != 2) 27 | return 1; 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /tests/execute/0034-logandor.c: -------------------------------------------------------------------------------- 1 | int g; 2 | 3 | int 4 | effect() 5 | { 6 | g = 1; 7 | return 1; 8 | } 9 | 10 | int 11 | main() 12 | { 13 | int x; 14 | 15 | g = 0; 16 | x = 0; 17 | if(x && effect()) 18 | return 1; 19 | if(g) 20 | return 2; 21 | x = 1; 22 | if(x && effect()) { 23 | if(g != 1) 24 | return 3; 25 | } else { 26 | return 4; 27 | } 28 | g = 0; 29 | x = 1; 30 | if(x || effect()) { 31 | if(g) 32 | return 5; 33 | } else { 34 | return 6; 35 | } 36 | x = 0; 37 | if(x || effect()) { 38 | if(g != 1) 39 | return 7; 40 | } else { 41 | return 8; 42 | } 43 | return 0; 44 | } 45 | 46 | -------------------------------------------------------------------------------- /tests/execute/0035-breakcont.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int x; 5 | 6 | x = 0; 7 | while(1) 8 | break; 9 | while(1) { 10 | if (x == 5) { 11 | break; 12 | } 13 | x = x + 1; 14 | continue; 15 | } 16 | for (;;) { 17 | if (x == 10) { 18 | break; 19 | } 20 | x = x + 1; 21 | continue; 22 | } 23 | do { 24 | if (x == 15) { 25 | break; 26 | } 27 | x = x + 1; 28 | continue; 29 | } while(1); 30 | return x - 15; 31 | } 32 | 33 | -------------------------------------------------------------------------------- /tests/execute/0036-notneg.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int x; 5 | 6 | x = 4; 7 | if(!x != 0) 8 | return 1; 9 | if(!!x != 1) 10 | return 1; 11 | if(-x != 0 - 4) 12 | return 1; 13 | return 0; 14 | } 15 | 16 | -------------------------------------------------------------------------------- /tests/execute/0037-assignop.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int x; 5 | 6 | x = 0; 7 | x += 2; 8 | x += 2; 9 | if (x != 4) 10 | return 1; 11 | x -= 1; 12 | if (x != 3) 13 | return 2; 14 | x *= 2; 15 | if (x != 6) 16 | return 3; 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /tests/execute/0038-ptradd.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int x[2]; 5 | int *p; 6 | 7 | x[1] = 7; 8 | p = &x[0]; 9 | p = p + 1; 10 | 11 | if(*p != 7) 12 | return 1; 13 | if(&x[1] - &x[0] != 1) 14 | return 1; 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /tests/execute/0039-sizeof.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int x, *p; 5 | 6 | if (sizeof(0) < 2) 7 | return 1; 8 | if (sizeof 0 < 2) 9 | return 1; 10 | if (sizeof(char) < 1) 11 | return 1; 12 | if (sizeof(int) - 2 < 0) 13 | return 1; 14 | if (sizeof(&x) != sizeof p) 15 | return 1; 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /tests/execute/0040-cast.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | void *p; 5 | int x; 6 | 7 | x = 2; 8 | p = &x; 9 | 10 | if(*((int*)p) != 2) 11 | return 1; 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /tests/execute/0041-queen.c: -------------------------------------------------------------------------------- 1 | int *calloc(int, int); 2 | 3 | int N; 4 | int *t; 5 | 6 | int 7 | chk(int x, int y) 8 | { 9 | int i; 10 | int r; 11 | 12 | for (r=i=0; i<8; i++) { 13 | r = r + t[x + 8*i]; 14 | r = r + t[i + 8*y]; 15 | if (x+i < 8 & y+i < 8) 16 | r = r + t[x+i + 8*(y+i)]; 17 | if (x+i < 8 & y-i >= 0) 18 | r = r + t[x+i + 8*(y-i)]; 19 | if (x-i >= 0 & y+i < 8) 20 | r = r + t[x-i + 8*(y+i)]; 21 | if (x-i >= 0 & y-i >= 0) 22 | r = r + t[x-i + 8*(y-i)]; 23 | } 24 | return r; 25 | } 26 | 27 | int 28 | go(int n, int x, int y) 29 | { 30 | if (n == 8) { 31 | N++; 32 | return 0; 33 | } 34 | for (; y<8; y++) { 35 | for (; x<8; x++) 36 | if (chk(x, y) == 0) { 37 | t[x + 8*y]++; 38 | go(n+1, x, y); 39 | t[x + 8*y]--; 40 | } 41 | x = 0; 42 | } 43 | return 0; 44 | } 45 | 46 | int 47 | main() 48 | { 49 | t = calloc(64, sizeof(int)); 50 | go(0, 0, 0); 51 | if(N != 92) 52 | return 1; 53 | return 0; 54 | } 55 | 56 | -------------------------------------------------------------------------------- /tests/execute/0042-prime.c: -------------------------------------------------------------------------------- 1 | int 2 | main() { 3 | int n; 4 | int t; 5 | int c; 6 | int p; 7 | 8 | c = 0; 9 | n = 2; 10 | while (n < 5000) { 11 | t = 2; 12 | p = 1; 13 | while (t*t <= n) { 14 | if (n % t == 0) 15 | p = 0; 16 | t++; 17 | } 18 | n++; 19 | if (p) 20 | c++; 21 | } 22 | if (c != 669) 23 | return 1; 24 | return 0; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /tests/execute/0043-union.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | union { int a; int b; } u; 5 | u.a = 1; 6 | u.b = 3; 7 | 8 | if (u.a != 3 || u.b != 3) 9 | return 1; 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/execute/0044-struct.c: -------------------------------------------------------------------------------- 1 | struct s { 2 | int x; 3 | struct { 4 | int y; 5 | int z; 6 | } nest; 7 | }; 8 | 9 | int 10 | main() { 11 | struct s v; 12 | v.x = 1; 13 | v.nest.y = 2; 14 | v.nest.z = 3; 15 | if (v.x + v.nest.y + v.nest.z != 6) 16 | return 1; 17 | return 0; 18 | } 19 | 20 | -------------------------------------------------------------------------------- /tests/execute/0045-struct.c: -------------------------------------------------------------------------------- 1 | struct T; 2 | 3 | struct T { 4 | int x; 5 | }; 6 | 7 | int 8 | main() 9 | { 10 | struct T v; 11 | { struct T { int z; }; } 12 | v.x = 2; 13 | if(v.x != 2) 14 | return 1; 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /tests/execute/0046-inits.c: -------------------------------------------------------------------------------- 1 | int x = 5; 2 | long y = 6; 3 | int *p = &x; 4 | 5 | int 6 | main() 7 | { 8 | if (x != 5) 9 | return 1; 10 | if (y != 6) 11 | return 2; 12 | if (*p != 5) 13 | return 3; 14 | return 0; 15 | } 16 | 17 | -------------------------------------------------------------------------------- /tests/execute/0047-anonexport.c: -------------------------------------------------------------------------------- 1 | typedef struct { 2 | int a; 3 | union { 4 | int b1; 5 | int b2; 6 | }; 7 | struct { union { struct { int c; }; struct {}; }; }; 8 | struct {}; 9 | struct { 10 | int d; 11 | }; 12 | } s; 13 | 14 | int 15 | main() 16 | { 17 | s v; 18 | 19 | v.a = 1; 20 | v.b1 = 2; 21 | v.c = 3; 22 | v.d = 4; 23 | 24 | if (v.a != 1) 25 | return 1; 26 | if (v.b1 != 2 && v.b2 != 2) 27 | return 2; 28 | if (v.c != 3) 29 | return 3; 30 | if (v.d != 4) 31 | return 4; 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /tests/execute/0048-inits.c: -------------------------------------------------------------------------------- 1 | struct { int a; int b; int c; } s = {1, 2, 3}; 2 | 3 | int 4 | main() 5 | { 6 | if (s.a != 1) 7 | return 1; 8 | if (s.b != 2) 9 | return 2; 10 | if (s.c != 3) 11 | return 3; 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /tests/execute/0049-inits.c: -------------------------------------------------------------------------------- 1 | struct S {int a; int b;}; 2 | struct S s = { .b = 2, .a = 1}; 3 | 4 | int 5 | main() 6 | { 7 | if(s.a != 1) 8 | return 1; 9 | if(s.b != 2) 10 | return 2; 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /tests/execute/0050-inits.c: -------------------------------------------------------------------------------- 1 | int x = 10; 2 | 3 | struct S {int a; int *p;}; 4 | struct S s = { .p = &x, .a = 1}; 5 | 6 | int 7 | main() 8 | { 9 | if(s.a != 1) 10 | return 1; 11 | if(*s.p != 10) 12 | return 2; 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /tests/execute/0051-inits.c: -------------------------------------------------------------------------------- 1 | struct S1 { 2 | int a; 3 | int b; 4 | }; 5 | 6 | struct S2 { 7 | int a; 8 | int b; 9 | union { 10 | int c; 11 | int d; 12 | }; 13 | struct S1 s; 14 | }; 15 | 16 | struct S2 v = {1, 2, 3, {4, 5}}; 17 | 18 | int 19 | main() 20 | { 21 | if(v.a != 1) 22 | return 1; 23 | if(v.b != 2) 24 | return 2; 25 | if(v.c != 3 || v.d != 3) 26 | return 3; 27 | if(v.s.a != 4) 28 | return 4; 29 | if(v.s.b != 5) 30 | return 5; 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /tests/execute/0052-switch.c: -------------------------------------------------------------------------------- 1 | int x = 0; 2 | 3 | int 4 | main() 5 | { 6 | switch(x) 7 | case 0: 8 | ; 9 | switch(x) 10 | case 0: 11 | switch(x) { 12 | case 0: 13 | goto next; 14 | default: 15 | return 1; 16 | } 17 | return 1; 18 | next: 19 | switch(x) 20 | case 1: 21 | return 1; 22 | switch(x) { 23 | { 24 | x = 1 + 1; 25 | foo: 26 | case 1: 27 | return 1; 28 | } 29 | } 30 | switch(x) { 31 | case 0: 32 | return x; 33 | case 1: 34 | return 1; 35 | default: 36 | return 1; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tests/execute/0053-struct.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | struct T { int x; }; 5 | { 6 | struct T s; 7 | s.x = 0; 8 | return s.x; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tests/execute/0054-struct.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | struct T { int x; } s1; 5 | s1.x = 1; 6 | { 7 | struct T { int y; } s2; 8 | s2.y = 1; 9 | if (s1.x - s2.y != 0) 10 | return 1; 11 | } 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /tests/execute/0055-enum.c: -------------------------------------------------------------------------------- 1 | enum E { 2 | x, 3 | y, 4 | z, 5 | }; 6 | 7 | int 8 | main() 9 | { 10 | enum E e; 11 | 12 | if(x != 0) 13 | return 1; 14 | if(y != 1) 15 | return 2; 16 | if(z != 2) 17 | return 3; 18 | 19 | e = x; 20 | return e; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /tests/execute/0056-enum.c: -------------------------------------------------------------------------------- 1 | enum E { 2 | x, 3 | y = 2, 4 | z, 5 | }; 6 | 7 | int 8 | main() 9 | { 10 | enum E e; 11 | 12 | if(x != 0) 13 | return 1; 14 | if(y != 2) 15 | return 2; 16 | if(z != 3) 17 | return 3; 18 | 19 | e = x; 20 | return e; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /tests/execute/0057-duff.c: -------------------------------------------------------------------------------- 1 | int main() 2 | { 3 | int count, n; 4 | char *from, *to; 5 | char a[39], b[39]; 6 | 7 | for(n = 0; n < 39; n++) { 8 | a[n] = n; 9 | b[n] = 0; 10 | } 11 | from = a; 12 | to = b; 13 | count = 39; 14 | n = (count + 7) / 8; 15 | switch (count % 8) { 16 | case 0: do { *to++ = *from++; 17 | case 7: *to++ = *from++; 18 | case 6: *to++ = *from++; 19 | case 5: *to++ = *from++; 20 | case 4: *to++ = *from++; 21 | case 3: *to++ = *from++; 22 | case 2: *to++ = *from++; 23 | case 1: *to++ = *from++; 24 | } while (--n > 0); 25 | } 26 | for(n = 0; n < 39; n++) 27 | if(a[n] != b[n]) 28 | return 1; 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /tests/execute/0058-bug.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | char a[16], b[16]; 5 | 6 | if(sizeof(a) != sizeof(b)) 7 | return 1; 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/execute/0059-multistring.c: -------------------------------------------------------------------------------- 1 | int main() 2 | { 3 | char * s; 4 | 5 | s = "abc" "def"; 6 | if(s[0] != 'a') return 1; 7 | if(s[1] != 'b') return 2; 8 | if(s[2] != 'c') return 3; 9 | if(s[3] != 'd') return 4; 10 | if(s[4] != 'e') return 5; 11 | if(s[5] != 'f') return 6; 12 | if(s[6] != 0) return 7; 13 | 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /tests/execute/0060-charlit.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | if ('a' != 97) 5 | return 1; 6 | 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /tests/execute/0061-comments.c: -------------------------------------------------------------------------------- 1 | // line comment 2 | 3 | int 4 | main() 5 | { 6 | /* 7 | multiline 8 | comment 9 | */ 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/execute/0062-include.c: -------------------------------------------------------------------------------- 1 | #include \ 2 | "include/0062-include.h" 3 | return x; 4 | } 5 | -------------------------------------------------------------------------------- /tests/execute/0063-define.c: -------------------------------------------------------------------------------- 1 | #define FOO 0 2 | 3 | int main() 4 | { 5 | return FOO; 6 | } 7 | 8 | -------------------------------------------------------------------------------- /tests/execute/0064-sysinclude.c: -------------------------------------------------------------------------------- 1 | #include <0064-sysinclude.h> 2 | 3 | int 4 | main() 5 | { 6 | return x - y; 7 | } 8 | -------------------------------------------------------------------------------- /tests/execute/0065-ifdef.c: -------------------------------------------------------------------------------- 1 | #ifdef FOO 2 | XXX 3 | #ifdef BAR 4 | XXX 5 | #endif 6 | XXX 7 | #endif 8 | 9 | #define FOO 1 10 | 11 | #ifdef FOO 12 | 13 | #ifdef FOO 14 | int x = 0; 15 | #endif 16 | 17 | int 18 | main() 19 | { 20 | return x; 21 | } 22 | #endif 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /tests/execute/0066-cppelse.c: -------------------------------------------------------------------------------- 1 | #define BAR 0 2 | #ifdef BAR 3 | #ifdef FOO 4 | XXX 5 | #ifdef FOO 6 | XXX 7 | #endif 8 | #else 9 | #define FOO 10 | #ifdef FOO 11 | int x = BAR; 12 | #endif 13 | #endif 14 | #endif 15 | 16 | int 17 | main() 18 | { 19 | return BAR; 20 | } 21 | -------------------------------------------------------------------------------- /tests/execute/0067-define.c: -------------------------------------------------------------------------------- 1 | #define X 6 / 2 2 | 3 | int 4 | main() 5 | { 6 | return X - 3; 7 | } 8 | -------------------------------------------------------------------------------- /tests/execute/0068-funclikemacro.c: -------------------------------------------------------------------------------- 1 | #define ADD(X, Y) (X + Y) 2 | 3 | 4 | int 5 | main() 6 | { 7 | return ADD(1, 2) - 3; 8 | } 9 | -------------------------------------------------------------------------------- /tests/execute/0069-funclikemacro.c: -------------------------------------------------------------------------------- 1 | #define A 3 2 | #define FOO(X,Y,Z) X + Y + Z 3 | #define SEMI ; 4 | 5 | int 6 | main() 7 | { 8 | if(FOO(1, 2, A) != 6) 9 | return 1 SEMI 10 | return FOO(0,0,0); 11 | } 12 | -------------------------------------------------------------------------------- /tests/execute/0070-cppif.c: -------------------------------------------------------------------------------- 1 | #if 1 2 | int x = 0; 3 | #endif 4 | 5 | #if 0 6 | int x = 1; 7 | #if 1 8 | X 9 | #endif 10 | #ifndef AAA 11 | X 12 | #endif 13 | #endif 14 | 15 | int main() 16 | { 17 | return x; 18 | } 19 | -------------------------------------------------------------------------------- /tests/execute/0071-cppelif.c: -------------------------------------------------------------------------------- 1 | #if 0 2 | X 3 | #elif 1 4 | int x = 0; 5 | #else 6 | X 7 | #endif 8 | 9 | int 10 | main() 11 | { 12 | return x; 13 | } 14 | -------------------------------------------------------------------------------- /tests/execute/0072-cppelif.c: -------------------------------------------------------------------------------- 1 | #if 0 2 | X 3 | #elif 0 4 | X 5 | #elif 1 6 | int x = 0; 7 | #endif 8 | 9 | int 10 | main() 11 | { 12 | return x; 13 | } 14 | -------------------------------------------------------------------------------- /tests/execute/0073-ifndef.c: -------------------------------------------------------------------------------- 1 | #ifndef DEF 2 | int x = 0; 3 | #endif 4 | 5 | #define DEF 6 | 7 | #ifndef DEF 8 | X 9 | #endif 10 | 11 | int 12 | main() 13 | { 14 | return x; 15 | } 16 | -------------------------------------------------------------------------------- /tests/execute/0074-undef.c: -------------------------------------------------------------------------------- 1 | #define X 1 2 | #undef X 3 | 4 | #ifdef X 5 | FAIL 6 | #endif 7 | 8 | int 9 | main() 10 | { 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /tests/execute/0075-ptraddasn.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int arr[2]; 5 | int *p; 6 | 7 | p = &arr[0]; 8 | p += 1; 9 | *p = 123; 10 | 11 | if(arr[1] != 123) 12 | return 1; 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /tests/execute/0076-ptrsubasn.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int arr[2]; 5 | int *p; 6 | 7 | p = &arr[1]; 8 | p -= 1; 9 | *p = 123; 10 | 11 | if(arr[0] != 123) 12 | return 1; 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /tests/execute/0077-defined.c: -------------------------------------------------------------------------------- 1 | #if defined X 2 | X 3 | #endif 4 | 5 | #if defined(X) 6 | X 7 | #endif 8 | 9 | #if X 10 | X 11 | #endif 12 | 13 | #define X 0 14 | 15 | #if X 16 | X 17 | #endif 18 | 19 | #if defined(X) 20 | int x = 0; 21 | #endif 22 | 23 | #undef X 24 | #define X 1 25 | 26 | #if X 27 | int 28 | main() 29 | { 30 | return 0; 31 | } 32 | #endif 33 | -------------------------------------------------------------------------------- /tests/execute/0079-cond.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | if(0 ? 1 : 0) 5 | return 1; 6 | if(1 ? 0 : 1) 7 | return 2; 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/execute/0080-arrays.c: -------------------------------------------------------------------------------- 1 | int 2 | foo(int x[100]) 3 | { 4 | int y[100]; 5 | int *p; 6 | 7 | y[0] = 2000; 8 | 9 | if(x[0] != 1000) 10 | { 11 | return 1; 12 | } 13 | 14 | p = x; 15 | 16 | if(p[0] != 1000) 17 | { 18 | return 2; 19 | } 20 | 21 | p = y; 22 | 23 | if(p[0] != 2000) 24 | { 25 | return 3; 26 | } 27 | 28 | if(sizeof(x) != sizeof(void*)) 29 | { 30 | return 4; 31 | } 32 | 33 | if(sizeof(y) <= sizeof(x)) 34 | { 35 | return 5; 36 | } 37 | 38 | return 0; 39 | } 40 | 41 | int 42 | main() 43 | { 44 | int x[100]; 45 | x[0] = 1000; 46 | 47 | return foo(x); 48 | } 49 | -------------------------------------------------------------------------------- /tests/execute/0081-calls.c: -------------------------------------------------------------------------------- 1 | int 2 | f1(char *p) 3 | { 4 | return *p+1; 5 | } 6 | 7 | int 8 | main() 9 | { 10 | char s = 1; 11 | int v[1000]; 12 | int f1(char *); 13 | 14 | if (f1(&s) != 2) 15 | return 1; 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /tests/execute/0082-bug.c: -------------------------------------------------------------------------------- 1 | #define x(y) ((y) + 1) 2 | 3 | int 4 | main() 5 | { 6 | int x; 7 | int y; 8 | 9 | y = 0; 10 | x = x(y); 11 | 12 | if(x != 1) 13 | return 1; 14 | 15 | return 0; 16 | } 17 | 18 | -------------------------------------------------------------------------------- /tests/execute/0083-voidret.c: -------------------------------------------------------------------------------- 1 | void 2 | voidfn() 3 | { 4 | return; 5 | } 6 | 7 | int 8 | main() 9 | { 10 | voidfn(); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /tests/execute/0084-longlong.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | long long x; 5 | 6 | x = 0; 7 | x = x + 1; 8 | if (x != 1) 9 | return 1; 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/execute/0085-ulonglong.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | unsigned long long x; 5 | 6 | x = 0; 7 | x = x + 1; 8 | if (x != 1) 9 | return 1; 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/execute/0086-variadic.c: -------------------------------------------------------------------------------- 1 | #define CALL(FUN, ...) FUN(__VA_ARGS__) 2 | 3 | int 4 | none() 5 | { 6 | return 0; 7 | } 8 | 9 | int 10 | one(int a) 11 | { 12 | if (a != 1) 13 | return 1; 14 | 15 | return 0; 16 | } 17 | 18 | int 19 | two(int a, int b) 20 | { 21 | if (a != 1) 22 | return 1; 23 | if (b != 2) 24 | return 1; 25 | 26 | return 0; 27 | } 28 | 29 | int 30 | three(int a, int b, int c) 31 | { 32 | if (a != 1) 33 | return 1; 34 | if (b != 2) 35 | return 1; 36 | if (c != 3) 37 | return 1; 38 | 39 | return 0; 40 | } 41 | 42 | int 43 | main() 44 | { 45 | if (CALL(none)) 46 | return 1; 47 | if (CALL(one, 1)) 48 | return 2; 49 | if (CALL(two, 1, 2)) 50 | return 3; 51 | if (CALL(three, 1, 2, 3)) 52 | return 4; 53 | 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /tests/execute/0087-variadic.c: -------------------------------------------------------------------------------- 1 | #define ARGS(...) __VA_ARGS__ 2 | 3 | int 4 | none() 5 | { 6 | return 0; 7 | } 8 | 9 | int 10 | one(int a) 11 | { 12 | if (a != 1) 13 | return 1; 14 | 15 | return 0; 16 | } 17 | 18 | int 19 | two(int a, int b) 20 | { 21 | if (a != 1) 22 | return 1; 23 | if (b != 2) 24 | return 1; 25 | 26 | return 0; 27 | } 28 | 29 | int 30 | three(int a, int b, int c) 31 | { 32 | if (a != 1) 33 | return 1; 34 | if (b != 2) 35 | return 1; 36 | if (c != 3) 37 | return 1; 38 | 39 | return 0; 40 | } 41 | 42 | int 43 | main() 44 | { 45 | if (none(ARGS())) 46 | return 1; 47 | if (one(ARGS(1))) 48 | return 2; 49 | if (two(ARGS(1, 2))) 50 | return 3; 51 | if (three(ARGS(1, 2, 3))) 52 | return 4; 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /tests/execute/0088-macros.c: -------------------------------------------------------------------------------- 1 | #define ZERO_0() 0 2 | #define ZERO_1(A) 0 3 | #define ZERO_2(A, B) 0 4 | #define ZERO_VAR(...) 0 5 | #define ZERO_1_VAR(A, ...) 0 6 | 7 | int 8 | main() 9 | { 10 | if (ZERO_0()) 11 | return 1; 12 | if (ZERO_1(1)) 13 | return 1; 14 | if (ZERO_2(1, 2)) 15 | return 1; 16 | if (ZERO_VAR()) 17 | return 1; 18 | if (ZERO_VAR(1)) 19 | return 1; 20 | if (ZERO_VAR(1, 2)) 21 | return 1; 22 | if (ZERO_1_VAR(1)) 23 | return 1; 24 | if (ZERO_1_VAR(1, 2)) 25 | return 1; 26 | if (ZERO_1_VAR(1, 2, 3)) 27 | return 1; 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /tests/execute/0089-short.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | short x; 5 | 6 | x = 0; 7 | x = x + 1; 8 | if (x != 1) 9 | return 1; 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/execute/0090-fptr.c: -------------------------------------------------------------------------------- 1 | struct S 2 | { 3 | int (*fptr)(); 4 | }; 5 | 6 | int 7 | foo() 8 | { 9 | return 0; 10 | } 11 | 12 | int 13 | main() 14 | { 15 | struct S v; 16 | 17 | v.fptr = foo; 18 | return v.fptr(); 19 | } 20 | 21 | -------------------------------------------------------------------------------- /tests/execute/0091-fptr.c: -------------------------------------------------------------------------------- 1 | int (*fptr)() = 0; 2 | 3 | 4 | int 5 | main() 6 | { 7 | if (fptr) 8 | return 1; 9 | return 0; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /tests/execute/0092-fptr.c: -------------------------------------------------------------------------------- 1 | int 2 | zero() 3 | { 4 | return 0; 5 | } 6 | 7 | struct S 8 | { 9 | int (*zerofunc)(); 10 | } s = { &zero }; 11 | 12 | struct S * 13 | anon() 14 | { 15 | return &s; 16 | } 17 | 18 | typedef struct S * (*fty)(); 19 | 20 | fty 21 | go() 22 | { 23 | return &anon; 24 | } 25 | 26 | int 27 | main() 28 | { 29 | return go()()->zerofunc(); 30 | } 31 | -------------------------------------------------------------------------------- /tests/execute/0093-arrayinit.c: -------------------------------------------------------------------------------- 1 | int a[3] = {0, 1, 2}; 2 | 3 | int 4 | main() 5 | { 6 | if (a[0] != 0) 7 | return 1; 8 | if (a[1] != 1) 9 | return 2; 10 | if (a[2] != 2) 11 | return 3; 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /tests/execute/0094-arrayinit.c: -------------------------------------------------------------------------------- 1 | typedef struct { 2 | int v; 3 | int sub[2]; 4 | } S; 5 | 6 | S a[1] = {{1, {2, 3}}}; 7 | 8 | int 9 | main() 10 | { 11 | if (a[0].v != 1) 12 | return 1; 13 | if (a[0].sub[0] != 2) 14 | return 2; 15 | if (a[0].sub[1] != 3) 16 | return 3; 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /tests/execute/0095-arrayselector.c: -------------------------------------------------------------------------------- 1 | int a[] = {5, [2] = 2, 3}; 2 | 3 | int 4 | main() 5 | { 6 | if (sizeof(a) != 4*sizeof(int)) 7 | return 1; 8 | 9 | if (a[0] != 5) 10 | return 2; 11 | if (a[1] != 0) 12 | return 3; 13 | if (a[2] != 2) 14 | return 4; 15 | if (a[3] != 3) 16 | return 5; 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /tests/execute/0096-inferredarraysize.c: -------------------------------------------------------------------------------- 1 | int a[] = {1, 2, 3, 4}; 2 | 3 | int 4 | main() 5 | { 6 | if (sizeof(a) != 4*sizeof(int)) 7 | return 1; 8 | 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/execute/0097-extern.c: -------------------------------------------------------------------------------- 1 | extern int x; 2 | 3 | int main() 4 | { 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/execute/0098-tentative.c: -------------------------------------------------------------------------------- 1 | int x; 2 | int x = 3; 3 | int x; 4 | 5 | int main(); 6 | 7 | void * 8 | foo() 9 | { 10 | return &main; 11 | } 12 | 13 | int 14 | main() 15 | { 16 | if (x != 3) 17 | return 0; 18 | 19 | x = 0; 20 | return x; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /tests/execute/0099-tentative.c: -------------------------------------------------------------------------------- 1 | int x, x = 3, x; 2 | 3 | int 4 | main() 5 | { 6 | if (x != 3) 7 | return 0; 8 | 9 | x = 0; 10 | return x; 11 | } 12 | 13 | -------------------------------------------------------------------------------- /tests/execute/0100-redeclaremacro.c: -------------------------------------------------------------------------------- 1 | #define NULL ((void*)0) 2 | #define NULL ((void*)0) 3 | 4 | #define FOO(X, Y) (X + Y + Z) 5 | #define FOO(X, Y) (X + Y + Z) 6 | 7 | #define BAR(X, Y, ...) (X + Y + Z) 8 | #define BAR(X, Y, ...) (X + Y + Z) 9 | 10 | int 11 | main() 12 | { 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /tests/execute/0101-wcharlit.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | return L'\0'; 5 | } 6 | -------------------------------------------------------------------------------- /tests/execute/0102-bug.c: -------------------------------------------------------------------------------- 1 | // This wouldn't compile 2 | 3 | typedef struct { } Vec; 4 | 5 | static void 6 | vecresize(Vec *v, int cap) 7 | { 8 | return; 9 | } 10 | 11 | int main() 12 | { 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /tests/execute/0103-voidparm.c: -------------------------------------------------------------------------------- 1 | int 2 | foo(void) 3 | { 4 | return 0; 5 | } 6 | 7 | int 8 | main() 9 | { 10 | return foo(); 11 | } 12 | -------------------------------------------------------------------------------- /tests/execute/0104-qbebug.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int c; 5 | c = 0; 6 | do 7 | ; 8 | while (0); 9 | return c; 10 | } 11 | -------------------------------------------------------------------------------- /tests/execute/0105-shl.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int x; 5 | 6 | x = 1; 7 | if ((x << 1) != 2) 8 | return 1; 9 | 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/execute/0106-ppcast.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int x; 5 | void *foo; 6 | void **bar; 7 | 8 | x = 0; 9 | 10 | foo = (void*)&x; 11 | bar = &foo; 12 | 13 | return **(int**)bar; 14 | } 15 | -------------------------------------------------------------------------------- /tests/execute/0107-bnot.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int 4 | main() 5 | { 6 | int32_t x; 7 | int64_t l; 8 | 9 | x = 0; 10 | l = 0; 11 | 12 | x = ~x; 13 | if (x != 0xffffffff) 14 | return 1; 15 | 16 | l = ~l; 17 | if (x != 0xffffffffffffffff) 18 | return 2; 19 | 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /tests/execute/0108-bug.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int i; 5 | 6 | for(i = 0; i < 10; i++) 7 | if (!i) 8 | continue; 9 | 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/execute/0109-struct.c: -------------------------------------------------------------------------------- 1 | struct S1 { int x; }; 2 | struct S2 { struct S1 s1; }; 3 | 4 | int 5 | main() 6 | { 7 | struct S2 s2; 8 | s2.s1.x = 1; 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/execute/0110-typedefcast.c: -------------------------------------------------------------------------------- 1 | typedef int myint; 2 | myint x = (myint)1; 3 | 4 | int 5 | main(void) 6 | { 7 | return x-1; 8 | } 9 | -------------------------------------------------------------------------------- /tests/execute/0111-doubledef.c: -------------------------------------------------------------------------------- 1 | int foo(void); 2 | int foo(void); 3 | #define FOO 0 4 | 5 | int 6 | main() 7 | { 8 | return FOO; 9 | } 10 | -------------------------------------------------------------------------------- /tests/execute/0112-cond.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int x = 0; 5 | int y = 1; 6 | if(x ? 1 : 0) 7 | return 1; 8 | if(y ? 0 : 1) 9 | return 2; 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/execute/0113-externredecl.c: -------------------------------------------------------------------------------- 1 | extern int x; 2 | int x; 3 | 4 | int 5 | main() 6 | { 7 | return x; 8 | } 9 | -------------------------------------------------------------------------------- /tests/execute/0114-shortassig.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | short s = 1; 5 | long l = 1; 6 | 7 | s -= l; 8 | return s; 9 | } 10 | -------------------------------------------------------------------------------- /tests/execute/0115-null-comparision.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | return "abc" == (void *)0; 5 | } 6 | -------------------------------------------------------------------------------- /tests/execute/0116-floatcmp.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int a = 0; 5 | float f = a + 1; 6 | 7 | return f == a; 8 | } 9 | -------------------------------------------------------------------------------- /tests/execute/0117-pointarith.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int i, *p = &i; 5 | 6 | return p - (void*) 0 == 0; 7 | } 8 | -------------------------------------------------------------------------------- /tests/execute/0118-voidmain.c: -------------------------------------------------------------------------------- 1 | int main(void); 2 | 3 | int 4 | main() 5 | { 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /tests/execute/0119-macrostr.c: -------------------------------------------------------------------------------- 1 | #define B "b" 2 | 3 | char s[] = "a" B "c"; 4 | 5 | int 6 | main() 7 | { 8 | if (s[0] != 'a') 9 | return 1; 10 | if (s[1] != 'b') 11 | return 2; 12 | if (s[2] != 'c') 13 | return 3; 14 | if (s[3] != '\0') 15 | return 4; 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /tests/execute/0120-funpar.c: -------------------------------------------------------------------------------- 1 | int 2 | f(int f) 3 | { 4 | return f; 5 | } 6 | 7 | int 8 | main() 9 | { 10 | return f(0); 11 | } 12 | -------------------------------------------------------------------------------- /tests/execute/0121-localinit.c: -------------------------------------------------------------------------------- 1 | main() 2 | { 3 | int x[] = { 1, 0 }; 4 | return x[1]; 5 | } 6 | -------------------------------------------------------------------------------- /tests/execute/0122-localinit.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | struct { int x; } s = { 0 }; 5 | return s.x; 6 | } 7 | -------------------------------------------------------------------------------- /tests/execute/0123-doubleconst.c: -------------------------------------------------------------------------------- 1 | double x = 100; 2 | 3 | int 4 | main() 5 | { 6 | return x < 1; 7 | } 8 | -------------------------------------------------------------------------------- /tests/execute/0124-enumstruct.c: -------------------------------------------------------------------------------- 1 | struct { 2 | enum { X } x; 3 | } s; 4 | 5 | 6 | int 7 | main() 8 | { 9 | return X; 10 | } 11 | -------------------------------------------------------------------------------- /tests/execute/0125-fundcl.c: -------------------------------------------------------------------------------- 1 | int f(int a), g(int a), a; 2 | 3 | 4 | int 5 | main() 6 | { 7 | return f(1) - g(1); 8 | } 9 | 10 | int 11 | f(int a) 12 | { 13 | return a; 14 | } 15 | 16 | int 17 | g(int a) 18 | { 19 | return a; 20 | } 21 | -------------------------------------------------------------------------------- /tests/execute/0126-macropar.c: -------------------------------------------------------------------------------- 1 | #define F(a, b) a 2 | int 3 | main() 4 | { 5 | return F(, 1) 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/execute/0127-doublecte.c: -------------------------------------------------------------------------------- 1 | double x = 100.0; 2 | 3 | int 4 | main() 5 | { 6 | return x < 1; 7 | } 8 | -------------------------------------------------------------------------------- /tests/execute/0128-kr_names.c: -------------------------------------------------------------------------------- 1 | int f(a,b); 2 | 3 | int 4 | f(a,b,c) char b; 5 | { 6 | return a - c + b; 7 | } 8 | 9 | int 10 | main(void) 11 | { 12 | return f(1,0,1); 13 | } 14 | -------------------------------------------------------------------------------- /tests/execute/0129-initi.c: -------------------------------------------------------------------------------- 1 | struct range { 2 | long quant; 3 | } *a; 4 | long b; 5 | 6 | int 7 | main() 8 | { 9 | struct range r = a[0]; 10 | b = r.quant; 11 | } 12 | -------------------------------------------------------------------------------- /tests/execute/0130-mulpars.c: -------------------------------------------------------------------------------- 1 | int 2 | f2(int c, int b) 3 | { 4 | return c - b; 5 | } 6 | 7 | int (* 8 | f1(int a, int b))(int c, int b) 9 | { 10 | if (a != b) 11 | return f2; 12 | return 0; 13 | } 14 | 15 | int 16 | main() 17 | { 18 | int (* (*p)(int a, int b))(int c, int d) = f1; 19 | 20 | 21 | return (*(*p)(0, 2))(2, 2); 22 | } 23 | -------------------------------------------------------------------------------- /tests/execute/0131-hello.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int 4 | main(void) 5 | { 6 | printf("hello world\n"); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /tests/execute/0132-forward.c: -------------------------------------------------------------------------------- 1 | struct S *x; 2 | struct S { 3 | int i; 4 | struct S *next; 5 | }; 6 | 7 | int 8 | main(void) 9 | { 10 | struct S y, *p; 11 | unsigned n; 12 | 13 | y.i = 0; 14 | y.next = 0; 15 | x = &y; 16 | *x = y; 17 | 18 | for (n = 0, p = &y; p; ++n, p = p->next) 19 | ; 20 | return n; 21 | } 22 | -------------------------------------------------------------------------------- /tests/execute/0133-ftn-ptr.c: -------------------------------------------------------------------------------- 1 | int 2 | foo(void) 3 | { 4 | return 42; 5 | } 6 | 7 | int 8 | bar(void) 9 | { 10 | return 24; 11 | } 12 | 13 | int 14 | main(void) 15 | { 16 | return (1 ? foo : bar)(); 17 | } 18 | -------------------------------------------------------------------------------- /tests/execute/0134-arith.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int x; 5 | 6 | x = 0; 7 | if ((x = x + 2) != 2) // 2 8 | return 1; 9 | if ((x = x - 1) != 1) // 1 10 | return 1; 11 | if ((x = x * 6) != 6) // 6 12 | return 1; 13 | if ((x = x / 2) != 3) // 3 14 | return 1; 15 | if ((x = x % 2) != 1) // 1 16 | return 1; 17 | if ((x = x << 2) != 4) // 4 18 | return 1; 19 | if ((x = x >> 1) != 2) // 2 20 | return 1; 21 | if ((x = x | 255) != 255) // 255 22 | return 1; 23 | if ((x = x & 3) != 3) // 3 24 | return 1; 25 | if ((x = x ^ 1) != 2) // 2 26 | return 1; 27 | if ((x = x + (x > 1)) != 2) // 2 28 | return 1; 29 | if ((x = x + (x < 3)) != 2) // 2 30 | return 1; 31 | if ((x = x + (x > 1)) != 3) // 3 32 | return 1; 33 | if ((x = x + (x < 4)) != 4) // 4 34 | return 1; 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /tests/execute/0135-unary.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int x; 5 | 6 | x = 3; 7 | x = !x; // 0 8 | x = !x; // 1 9 | x = ~x; // -1 10 | x = -x; // 2 11 | if(x != 2) 12 | return 1; 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /tests/execute/0136-if.c: -------------------------------------------------------------------------------- 1 | int c; 2 | 3 | int 4 | main() 5 | { 6 | if(0) { 7 | return 1; 8 | } else if(0) { 9 | /* empty */ 10 | } else { 11 | if(1) { 12 | if(c) 13 | return 1; 14 | else 15 | return 0; 16 | } else { 17 | return 1; 18 | } 19 | } 20 | return 1; 21 | } 22 | -------------------------------------------------------------------------------- /tests/execute/0138-namespace.c: -------------------------------------------------------------------------------- 1 | typedef struct s s; 2 | 3 | struct s { 4 | struct s1 { 5 | int s; 6 | struct s2 { 7 | int s; 8 | } s1; 9 | } s; 10 | } s2; 11 | 12 | #define s s 13 | 14 | int 15 | main(void) 16 | { 17 | #undef s 18 | goto s; 19 | struct s s; 20 | { 21 | int s; 22 | return s; 23 | } 24 | return s.s.s + s.s.s1.s; 25 | s: 26 | { 27 | return 0; 28 | } 29 | return 1; 30 | } 31 | -------------------------------------------------------------------------------- /tests/execute/0139-ptr-ary.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | char arr[2][4], (*p)[4], *q; 5 | int v[4]; 6 | 7 | p = arr; 8 | q = &arr[1][3]; 9 | arr[1][3] = 2; 10 | v[0] = 2; 11 | 12 | if (arr[1][3] != 2) 13 | return 1; 14 | if (p[1][3] != 2) 15 | return 1; 16 | if (*q != 2) 17 | return 1; 18 | if (*v != 2) 19 | return 1; 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /tests/execute/0140-int-fold.c: -------------------------------------------------------------------------------- 1 | int 2 | main(void) 3 | { 4 | int i; 5 | 6 | i = 1 + 2; 7 | i = 2 - 1; 8 | i = 3 * 6; 9 | i = 10 / 5; 10 | i = 10 % 5; 11 | i = i % 0; 12 | i = i % 0; 13 | i = 1 << 3; 14 | i = 8 >> 2; 15 | i = 12 & 4; 16 | i = 8 | 4; 17 | i = 12 ^ 4; 18 | i = -(3); 19 | i = ~12; 20 | i = 1 < 3; 21 | i = 2 > 3; 22 | i = 2 >= 3; 23 | i = 2 <= 3; 24 | i = 1 == 0; 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /tests/execute/0141-int-iden.c: -------------------------------------------------------------------------------- 1 | int 2 | main(void) 3 | { 4 | int i; 5 | 6 | i = i || 0; 7 | i = i || 4; 8 | i = 4 || i; 9 | i = 0 || i; 10 | i = i && 0; 11 | i = i && 4; 12 | i = 4 && i; 13 | i = 0 && i; 14 | i = i << 0; 15 | i = 0 << i; 16 | i = i >> 0; 17 | i = 0 >> i; 18 | i = i + 0; 19 | i = 0 + i; 20 | i = i - 0; 21 | i = 0 - i; 22 | i = i | 0; 23 | i = 0 | i; 24 | i = i ^ 0; 25 | i = 0 ^ i; 26 | i = i * 0; 27 | i = 0 * i; 28 | i = i * 1; 29 | i = 1 * i; 30 | i = i / 1; 31 | i = 1 / i; 32 | i = i & ~0; 33 | i = ~0 & i; 34 | i = i % 1; 35 | i = i / 0; 36 | i = i % 0; 37 | } 38 | -------------------------------------------------------------------------------- /tests/execute/0142-char-const.c: -------------------------------------------------------------------------------- 1 | int 2 | main(void) 3 | { 4 | unsigned char uc; 5 | signed char sc; 6 | 7 | uc = -1; 8 | if ((uc & 0xFF) != 0xFF) 9 | return 1; 10 | 11 | uc = '\x23'; 12 | if (uc != 36) 13 | return 1; 14 | 15 | uc = 1u; 16 | if (uc != (1025 & 0xFF) 17 | return 1; 18 | 19 | uc = 'A'; 20 | if (uc != 0x41) 21 | return 1; 22 | 23 | sc = -1; 24 | if ((sc & 0xFF) != 0xFF) 25 | return 1; 26 | 27 | sc = '\x23'; 28 | if (sc != 36) 29 | return 1; 30 | 31 | sc = 1u; 32 | if (uc != (1025 & 0xFF) 33 | return 1; 34 | 35 | sc = 'A'; 36 | if (uc != 0x41) 37 | return 1; 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /tests/execute/0143-int-const.c: -------------------------------------------------------------------------------- 1 | main(void) 2 | { 3 | int i; 4 | unsigned u; 5 | 6 | i = 1; 7 | i = -1; 8 | i = -1l; 9 | i = -1u; 10 | i = -1ll; 11 | i = 32766 + 1 & 3; 12 | i = (int) 32768 < 0; 13 | i = -1u < 0; 14 | 15 | u = 1; 16 | u = -1; 17 | u = -1l; 18 | u = -1u; 19 | u = -1ll; 20 | u = (unsigned) 32768 < 0; 21 | u = 32766 + 1 & 3; 22 | u = -1u < 0; 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /tests/execute/0144-long-const.c: -------------------------------------------------------------------------------- 1 | int 2 | main(void) 3 | { 4 | long i; 5 | unsigned long u; 6 | 7 | i = 1; 8 | i = -1; 9 | i = -1l; 10 | i = -1u; 11 | i = -1ll; 12 | i = (1ll << 32) - 1 & 3; 13 | i = (long) ((1ll << 32) - 1) < 0; 14 | i = -1u < 0; 15 | 16 | u = 1; 17 | u = -1; 18 | u = -1l; 19 | u = -1u; 20 | u = -1ll; 21 | u = (1ll << 32) - 1 & 3; 22 | u = (long) ((1ll << 32) - 1) < 0; 23 | u = -1u < 0; 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /tests/execute/0145-llong-const.c: -------------------------------------------------------------------------------- 1 | int 2 | main(void) 3 | { 4 | long long i; 5 | unsigned long long u; 6 | 7 | i = 1; 8 | i = -1; 9 | i = -1l; 10 | i = -1u; 11 | i = -1ll; 12 | i = -1ll & 3; 13 | i = -1ll < 0; 14 | 15 | u = 1; 16 | u = -1; 17 | u = -1l; 18 | u = -1u; 19 | u = -1ll; 20 | u = -1llu & 3; 21 | u = -1llu < 0; 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /tests/execute/0146-ifdef.c: -------------------------------------------------------------------------------- 1 | #define FOO 2 | 3 | #ifdef FOO 4 | int a; 5 | int b; 6 | #undef FOO 7 | #ifndef FOO 8 | int c; 9 | int d; 10 | #else 11 | int e; 12 | int f; 13 | #endif 14 | int e; 15 | int f; 16 | #ifdef FOO 17 | int c_; 18 | int d_; 19 | #else 20 | int e_; 21 | int f_; 22 | #endif 23 | int e_; 24 | int f_; 25 | int 26 | main() 27 | { 28 | return 0; 29 | } 30 | #else 31 | int j; 32 | int k; 33 | #ifdef FOO 34 | int j; 35 | int k; 36 | #else 37 | int n; 38 | int o; 39 | #endif 40 | int n; 41 | int o; 42 | #ifndef FOO 43 | int r; 44 | int s; 45 | #else 46 | int t; 47 | int u; 48 | #endif 49 | int t; 50 | int u; 51 | #error bad branch 52 | #endif 53 | -------------------------------------------------------------------------------- /tests/execute/0147-intern-cpp.c: -------------------------------------------------------------------------------- 1 | #define x(y) (y) 2 | 3 | int 4 | main(void) 5 | { 6 | int y; 7 | char *p; 8 | 9 | p = __FILE__; 10 | y = __LINE__; 11 | p = __DATE__; 12 | y = __STDC__; 13 | p = __TIME__; 14 | y = __STDC_HOSTED__; 15 | y = __SCC__; 16 | y = x(1); 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /tests/execute/0148-cpp-string.c: -------------------------------------------------------------------------------- 1 | #define x(y) #y 2 | 3 | int 4 | main(void) 5 | { 6 | char *p; 7 | p = x(hello) " is better than bye"; 8 | 9 | return (*p == 'h') ? 0 : 1; 10 | } 11 | -------------------------------------------------------------------------------- /tests/execute/0149-define.c: -------------------------------------------------------------------------------- 1 | #define M(x) x 2 | #define A(a,b) a(b) 3 | 4 | int 5 | main(void) 6 | { 7 | char *a = A(M,"hi"); 8 | 9 | return (a[1] == 'i') ? 0 : 1; 10 | } 11 | -------------------------------------------------------------------------------- /tests/execute/0150-define.c: -------------------------------------------------------------------------------- 1 | /* 2 | * f(2) will expand to 2*g, which will expand to 2*f, and in this 3 | * moment f will not be expanded because the macro definition is 4 | * a function alike macro, and in this case there is no arguments. 5 | */ 6 | #define f(a) a*g 7 | #define g f 8 | 9 | int 10 | main(void) 11 | { 12 | int f = 0; 13 | 14 | return f(2); 15 | } 16 | -------------------------------------------------------------------------------- /tests/execute/0151-vararg.c: -------------------------------------------------------------------------------- 1 | struct foo { 2 | int i, j, k; 3 | char *p; 4 | float v; 5 | }; 6 | 7 | int 8 | f1(struct foo f, struct foo *p, int n, ...) 9 | { 10 | if (f.i != p->i) 11 | return 0; 12 | return p->j + n; 13 | } 14 | 15 | int 16 | main(void) 17 | { 18 | struct foo f; 19 | 20 | f.i = f.j = 1; 21 | f1(f, &f, 2); 22 | f1(f, &f, 2, 1, f, &f); 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /tests/execute/0152-cat.c: -------------------------------------------------------------------------------- 1 | #define CAT(x,y) x ## y 2 | #define XCAT(x,y) CAT(x,y) 3 | #define FOO foo 4 | #define BAR bar 5 | 6 | int 7 | main(void) 8 | { 9 | int foo, bar, foobar; 10 | 11 | CAT(foo,bar) = foo + bar; 12 | XCAT(FOO,BAR) = foo + bar; 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /tests/execute/0153-cpp-string.c: -------------------------------------------------------------------------------- 1 | #define M1(x) "This is a string $ or # or ## " ## #x 2 | #define STR "This is a string $ or # or ## and it is ok!" 3 | 4 | int 5 | main(void) 6 | { 7 | char *s, *t = M1(and it is ok!); 8 | 9 | for (s = STR; *s && *s == *t; ++s) 10 | ++t; 11 | 12 | return *s; 13 | } 14 | -------------------------------------------------------------------------------- /tests/execute/0154-if-defined: -------------------------------------------------------------------------------- 1 | #if defined(FOO) 2 | int a; 3 | #elif !defined(FOO) && defined(BAR) 4 | int b; 5 | #elif !defined(FOO) && !defined(BAR) 6 | int c; 7 | #else 8 | int d; 9 | #endif 10 | 11 | int 12 | main(void) 13 | { 14 | return c; 15 | } 16 | -------------------------------------------------------------------------------- /tests/execute/0155-struct-compl.c: -------------------------------------------------------------------------------- 1 | extern struct X x; 2 | int foo(); 3 | 4 | int main() 5 | { 6 | extern struct X x; 7 | return &x != 0; 8 | } 9 | 10 | struct X {int v;}; 11 | 12 | int foo() 13 | { 14 | x.v = 0; 15 | return x.v; 16 | } 17 | -------------------------------------------------------------------------------- /tests/execute/0156-duff2.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Disgusting, no? But it compiles and runs just fine. I feel a 3 | * combination of pride and revulsion at this discovery. If no one's 4 | * thought of it before, I think I'll name it after myself. It amazes 5 | * me that after 10 years of writing C there are still little corners 6 | * that I haven't explored fully. 7 | * - Tom Duff 8 | */ 9 | send(to, from, count) 10 | register short *to, *from; 11 | register count; 12 | { 13 | register n=(count+7)/8; 14 | switch(count%8){ 15 | case 0: do{*to = *from++; 16 | case 7: *to = *from++; 17 | case 6: *to = *from++; 18 | case 5: *to = *from++; 19 | case 4: *to = *from++; 20 | case 3: *to = *from++; 21 | case 2: *to = *from++; 22 | case 1: *to = *from++; 23 | }while(--n>0); 24 | } 25 | } 26 | 27 | int 28 | main() 29 | { 30 | short a, b[40]; 31 | 32 | send(&a, b, 40); 33 | 34 | return (a == b[39]) ? 0 : 1; 35 | } 36 | -------------------------------------------------------------------------------- /tests/execute/0157-list.c: -------------------------------------------------------------------------------- 1 | typedef struct List List; 2 | struct List { 3 | int len; 4 | struct List *head; 5 | List *back; 6 | }; 7 | 8 | int 9 | main(void) 10 | { 11 | List List; 12 | 13 | return List.len; 14 | } 15 | -------------------------------------------------------------------------------- /tests/execute/0158-ternary.c: -------------------------------------------------------------------------------- 1 | int 2 | main(void) 3 | { 4 | int i, *q; 5 | void *p; 6 | 7 | i = i ? 0 : 0l; 8 | p = i ? (void *) 0 : 0; 9 | p = i ? 0 : (void *) 0; 10 | p = i ? 0 : (const void *) 0; 11 | q = i ? 0 : p; 12 | q = i ? p : 0; 13 | q = i ? q : 0; 14 | q = i ? 0 : q; 15 | 16 | return (int) q; 17 | } 18 | -------------------------------------------------------------------------------- /tests/execute/0159-typedef.c: -------------------------------------------------------------------------------- 1 | /* Taken from plan9 kernel */ 2 | 3 | typedef struct Clock0link Clock0link; 4 | typedef struct Clock0link { 5 | int (*clock)(void); 6 | Clock0link* link; 7 | } Clock0link; 8 | 9 | 10 | int 11 | f(void) 12 | { 13 | return 0; 14 | } 15 | 16 | Clock0link cl0 = { 17 | .clock = f; 18 | }; 19 | 20 | int 21 | main(void) 22 | { 23 | return (*cl0.clock)(); 24 | } 25 | -------------------------------------------------------------------------------- /tests/execute/0160-cpp-if.c: -------------------------------------------------------------------------------- 1 | #if 0 != (0 && (0/0)) 2 | #error 0 != (0 && (0/0)) 3 | #endif 4 | 5 | #if 1 != (-1 || (0/0)) 6 | #error 1 != (-1 || (0/0)) 7 | #endif 8 | 9 | #if 3 != (-1 ? 3 : (0/0)) 10 | #error 3 != (-1 ? 3 : (0/0)) 11 | #endif 12 | 13 | int 14 | main() 15 | { 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /tests/execute/0161-struct.c: -------------------------------------------------------------------------------- 1 | struct S { int a; int b; }; 2 | struct S s = (struct S){1, 2}; 3 | 4 | int 5 | main() 6 | { 7 | if(s.a != 1) 8 | return 1; 9 | if(s.b != 2) 10 | return 2; 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /tests/execute/0162-array.c: -------------------------------------------------------------------------------- 1 | int arr[3] = {[2] = 2, [0] = 0, [1] = 1}; 2 | 3 | int 4 | main() 5 | { 6 | if(arr[0] != 0) 7 | return 1; 8 | if(arr[1] != 1) 9 | return 2; 10 | if(arr[2] != 2) 11 | return 3; 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /tests/execute/0163-array.c: -------------------------------------------------------------------------------- 1 | struct S {int a; int b;}; 2 | struct S arr[2] = {[1] = {3, 4}, [0] = {1, 2}}; 3 | 4 | int 5 | main() 6 | { 7 | if(arr[0].a != 1) 8 | return 1; 9 | if(arr[0].b != 2) 10 | return 2; 11 | if(arr[1].a != 3) 12 | return 3; 13 | if(arr[1].b != 4) 14 | return 4; 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /tests/execute/0164-struct.c: -------------------------------------------------------------------------------- 1 | struct S { int a; int b; }; 2 | struct S *s = &(struct S) { 1, 2 }; 3 | 4 | int 5 | main() 6 | { 7 | if(s->a != 1) 8 | return 1; 9 | if(s->b != 2) 10 | return 2; 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /tests/execute/0165-struct.c: -------------------------------------------------------------------------------- 1 | struct S1 { 2 | int a; 3 | int b; 4 | }; 5 | struct S2 { 6 | struct S1 s1; 7 | struct S1 *ps1; 8 | int arr[2]; 9 | }; 10 | struct S1 gs1 = (struct S1) {.a = 1, 2}; 11 | struct S2 *s = &(struct S2) { 12 | {.b = 2, .a = 1}, 13 | &gs1, 14 | {[0] = 1, 1+1} 15 | }; 16 | 17 | int 18 | main() 19 | { 20 | if(s->s1.a != 1) 21 | return 1; 22 | if(s->s1.b != 2) 23 | return 2; 24 | if(s->ps1->a != 1) 25 | return 3; 26 | if(s->ps1->b != 2) 27 | return 4; 28 | if(s->arr[0] != 1) 29 | return 5; 30 | if(s->arr[1] != 2) 31 | return 6; 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /tests/execute/0166-desig.c: -------------------------------------------------------------------------------- 1 | struct S { 2 | int a, b, c; 3 | char d[3]; 4 | int e; 5 | } s = { 6 | .a = 1, 7 | .b = 2, 8 | .d = {[0] = 3, [2] = 5}, 9 | .d = {[0] = 4, [1] = 6} 10 | }; 11 | 12 | char m[] = {}; 13 | 14 | int 15 | main(void) 16 | { 17 | return sizeof(m) == s.d[2]; 18 | } 19 | -------------------------------------------------------------------------------- /tests/execute/0167-array.c: -------------------------------------------------------------------------------- 1 | int arr1[][3] = { 2 | { 2, 7, 5, }, 3 | { 5, 1, 2, }, 4 | }; 5 | 6 | int arr2[2][3] = { 7 | 2, 7, 5, 8 | 5, 1, 2 9 | }; 10 | 11 | int 12 | main(void) 13 | { 14 | return !(arr1[1][2] == arr2[1][3]); 15 | } 16 | -------------------------------------------------------------------------------- /tests/execute/0168-array.c: -------------------------------------------------------------------------------- 1 | int arr[][3][5] = { 2 | { 3 | { 0, 0, 3, 5 }, 4 | { 1, [3] = 6, 7 }, 5 | }, 6 | { 7 | { 1, 2 }, 8 | { [4] = 7, }, 9 | }, 10 | }; 11 | 12 | int 13 | main(void) 14 | { 15 | return !(arr[0][1][4] == arr[1][1][4]); 16 | } 17 | -------------------------------------------------------------------------------- /tests/execute/0169-string.c: -------------------------------------------------------------------------------- 1 | char s0[] = "foo"; 2 | char s1[7] = "foo"; 3 | char s2[2] = "foo"; 4 | char s3[] = {"foo"}; 5 | char *p = "foo"; 6 | 7 | int 8 | cmp(char *s1, char *s2) 9 | { 10 | while (*s1 && *s1++ != *s2++) 11 | ; 12 | return *s1; 13 | } 14 | 15 | int 16 | main() 17 | { 18 | if (sizeof(s0) != 4 || cmp(s0, "foo")) 19 | return 1; 20 | if (cmp(s1, "foo")) 21 | return 1; 22 | if (s2[0] != 'f' || s2[1] != 'o') 23 | return 1; 24 | if (sizeof(s3) != 4 || cmp(s3, "foo")) 25 | return 1; 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /tests/execute/0170-line.c: -------------------------------------------------------------------------------- 1 | #undef line 2 | #define line 1000 3 | 4 | #line line 5 | #if 1000 != __LINE__ 6 | #error " # line line" not work as expected 7 | #endif 8 | 9 | int 10 | main() 11 | { 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /tests/execute/0171-macros.c: -------------------------------------------------------------------------------- 1 | #define X (2) 2 | #define L (0) 3 | #define H (1) 4 | #define Q(x) x 5 | 6 | int 7 | main(void) 8 | { 9 | return X == L + H + Q(1); 10 | } 11 | -------------------------------------------------------------------------------- /tests/execute/0172-hexa.c: -------------------------------------------------------------------------------- 1 | int 2 | main(void) 3 | { 4 | return 0xa == 0xA && 5 | 0xb == 0xB && 6 | 0xc == 0xC && 7 | 0xd == 0xD && 8 | 0xe == 0xE && 9 | 0xf == 0xF; 10 | } 11 | -------------------------------------------------------------------------------- /tests/execute/0173-macro.c: -------------------------------------------------------------------------------- 1 | #define x f 2 | #define y() f 3 | 4 | typedef struct { int f; } S; 5 | 6 | int 7 | main() 8 | { 9 | S s; 10 | 11 | s.x = 0; 12 | return s.y(); 13 | } 14 | -------------------------------------------------------------------------------- /tests/execute/0174-decay.c: -------------------------------------------------------------------------------- 1 | int 2 | main(int argc, char *argv[]) 3 | { 4 | int v[1]; 5 | int (*p)[]; 6 | int (*f1)(int ,char *[]); 7 | int (*f2)(int ,char *[]); 8 | 9 | v[0] = 0; 10 | p = &v; 11 | f1 = &main; 12 | f2 = main; 13 | if (argc == 0) 14 | return 1; 15 | if ((****main)(0, 0)) 16 | return 2; 17 | if ((****f1)(0, 0)) 18 | return 3; 19 | if ((****f2)(0, 0)) 20 | return 4; 21 | if (!(*p)[0]) 22 | return 0; 23 | return 1; 24 | } 25 | -------------------------------------------------------------------------------- /tests/execute/0175-defined.c: -------------------------------------------------------------------------------- 1 | #if defined X 2 | X 3 | #endif 4 | 5 | #if defined(X) 6 | X 7 | #endif 8 | 9 | #if X 10 | X 11 | #endif 12 | 13 | #define X 0 14 | 15 | #if X 16 | X 17 | #endif 18 | 19 | #if defined(X) 20 | int x = 0; 21 | #endif 22 | 23 | #undef X 24 | #define X 1 25 | 26 | #if X 27 | int 28 | main() 29 | { 30 | return 0; 31 | } 32 | #endif 33 | -------------------------------------------------------------------------------- /tests/execute/0176-macro.c: -------------------------------------------------------------------------------- 1 | #ifdef __STDC__ 2 | #define __(proto) proto 3 | #else 4 | #define __(proto) () 5 | #endif 6 | 7 | extern int func __((int, int)); 8 | 9 | int 10 | main() 11 | { 12 | int (*fun)(int,int) = func; 13 | 14 | return (*func)(1, 2); 15 | } 16 | 17 | int 18 | func(int a, int b) 19 | { 20 | return a - b - 1; 21 | } 22 | -------------------------------------------------------------------------------- /tests/execute/0177-literal.c: -------------------------------------------------------------------------------- 1 | void boo(int *p) 2 | { 3 | return (*p[1] == 2) ? 0 : 1; 4 | } 5 | 6 | int main() 7 | { 8 | return boo((int[]) {0, 2}); 9 | } 10 | -------------------------------------------------------------------------------- /tests/execute/Makefile: -------------------------------------------------------------------------------- 1 | .POSIX: 2 | 3 | all: tests 4 | 5 | tests: 6 | CFLAGS='' SCCPREFIX=../../rootdir/ PATH=../../rootdir/bin:$$PATH ./chktest.sh scc-tests.lst 7 | 8 | clean: 9 | rm -f *.as *.o *.ir *.qbe *core test.log 10 | 11 | distclean: clean 12 | dep: 13 | -------------------------------------------------------------------------------- /tests/execute/README: -------------------------------------------------------------------------------- 1 | These tests are taken from https://github.com/andrewchambers/qc. 2 | All the credits for this test suite are for Andrew Chambers. 3 | -------------------------------------------------------------------------------- /tests/execute/chktest.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | file=${1?' empty input file'} 4 | ttyflags=`stty -g` 5 | trap "stty $ttyflags;tabs -8;rm -f a.out; exit 1" 0 1 2 3 15 6 | stty tabs 7 | tabs 40 8 | ulimit -c 0 9 | rm -f test.log 10 | 11 | cat $file | 12 | while read i state 13 | do 14 | echo $i >>test.log 15 | printf "%s\t" $i 16 | printf "%s" $state 17 | rm -f a.out 18 | (scc -Isysinclude $CFLAGS "$i" && ./a.out) 2>test.log && 19 | echo "[OK]" || echo "[FAILED]" 20 | done 21 | -------------------------------------------------------------------------------- /tests/execute/compose.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | rm -f tmp_test.c 4 | rm -f tests.h 5 | rm -f tmp_*.c 6 | 7 | (echo '#include "tests.h"' 8 | echo 'int main()' 9 | echo '{' 10 | 11 | for i in *-*.c 12 | do 13 | n=`echo $i | sed 's/\(.*\)-.*\.c/\1/'` 14 | sed s/main/main_$n/ < $i > tmp_$n.c 15 | echo "int main_$n();" >> tests.h 16 | echo "main_$n();" 17 | 18 | done 19 | 20 | echo 'return 0;' 21 | echo '}' 22 | ) > tmp_test.c 23 | 24 | -------------------------------------------------------------------------------- /tests/execute/include/0062-include.h: -------------------------------------------------------------------------------- 1 | #include "0062-include2.h" 2 | 3 | int 4 | main() 5 | { 6 | -------------------------------------------------------------------------------- /tests/execute/include/0062-include2.h: -------------------------------------------------------------------------------- 1 | int x; 2 | 3 | -------------------------------------------------------------------------------- /tests/execute/sysinclude/0064-sysinclude.h: -------------------------------------------------------------------------------- 1 | #include "0064-sysinclude2.h" 2 | 3 | int x = 2; 4 | 5 | -------------------------------------------------------------------------------- /tests/execute/sysinclude/0064-sysinclude2.h: -------------------------------------------------------------------------------- 1 | int y = 2; 2 | -------------------------------------------------------------------------------- /tests/selfhost.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | # A script to self host whatever object files that we can as a regression test. 4 | # One day it can be replaced with: 5 | # make install && make clean && make CC=scc install 6 | 7 | set -e 8 | set -u 9 | 10 | unset SCCEXECPATH 11 | 12 | selfhostedobj=\ 13 | "lib/xstrdup.o 14 | lib/xmalloc.o 15 | lib/xcalloc.o 16 | lib/xrealloc.o" 17 | #lib/newitem.o 18 | #lib/debug.o 19 | #lib/die.o 20 | #driver/posix/scc.o 21 | #cc1/error.o 22 | #cc1/stmt.o 23 | #cc1/init.o 24 | #cc1/arch/qbe/arch.o 25 | #cc1/fold.o 26 | #cc1/types.o 27 | #cc1/builtin.o 28 | #cc1/cpp.o 29 | #cc1/symbol.o 30 | #cc1/lex.o 31 | #cc1/decl.o 32 | #cc1/main.o 33 | #cc1/code.o 34 | #cc1/expr.o 35 | #cc2/arch/qbe/cgen.o 36 | #cc2/arch/qbe/types.o 37 | #cc2/arch/qbe/optm.o 38 | #cc2/arch/qbe/code.o 39 | #cc2/peep.o 40 | #cc2/parser.o 41 | #cc2/node.o 42 | #cc2/symbol.o 43 | #cc2/optm.o 44 | #cc2/main.o 45 | #cc2/code.o" 46 | 47 | if ! test -d ./cc1 48 | then 49 | echo "run this script from the root of the scc repository." 50 | exit 1 51 | fi 52 | 53 | boostrapdir="$(pwd)/_bootstrap" 54 | rm -rf "$boostrapdir" 55 | mkdir "$boostrapdir" 56 | 57 | make clean 58 | make PREFIX="$boostrapdir" install 59 | export PATH="$boostrapdir/bin:$PATH" 60 | 61 | rm lib/libcc.a bin/scc bin/cc* 62 | rm $selfhostedobj 63 | 64 | make CC=scc tests 65 | --------------------------------------------------------------------------------