├── LICENSE ├── Makefile ├── README ├── bin ├── README └── cpp.sh ├── cc1 ├── Makefile ├── TODO ├── arch │ ├── amd64-sysv │ │ ├── arch.c │ │ └── arch.h │ ├── i386-sysv │ │ ├── arch.c │ │ └── arch.h │ ├── i386 │ │ └── arch.h │ ├── qbe │ │ ├── arch.c │ │ └── arch.h │ └── z80 │ │ ├── arch.c │ │ └── arch.h ├── builtin.c ├── cc1.h ├── code.c ├── cpp.c ├── decl.c ├── error.c ├── expr.c ├── fold.c ├── init.c ├── ir.md ├── lex.c ├── main.c ├── stallman.msg ├── stmt.c ├── symbol.c ├── tests │ ├── chktest.sh │ ├── stdio.h │ ├── test001.c │ ├── test002.c │ ├── test003.c │ ├── test004.c │ ├── test005.c │ ├── test006.c │ ├── test007.c │ ├── test008.c │ ├── test009.c │ ├── test010.c │ ├── test011.c │ ├── test012.c │ ├── test013.c │ ├── test014.c │ ├── test015.c │ ├── test016.c │ ├── test017.c │ ├── test018.c │ ├── test019.c │ ├── test020.c │ ├── test021.c │ ├── test022.c │ ├── test023.c │ ├── test024.c │ ├── test025.c │ ├── test026.c │ ├── test027.c │ ├── test028.c │ ├── test029.c │ ├── test030.c │ ├── test031.c │ ├── test032.c │ ├── test033.c │ ├── test034.c │ ├── test035.c │ ├── test036.c │ ├── test037.c │ ├── test038.c │ ├── test039.c │ ├── test040.c │ ├── test041.c │ ├── test042.c │ ├── test043.c │ ├── test044.c │ ├── test045.c │ ├── test046.c │ ├── test047.c │ ├── test048.c │ ├── test049.c │ ├── test050.c │ ├── test051.c │ ├── test052.c │ ├── test053.c │ ├── test054.c │ ├── test055.c │ ├── test056.c │ ├── test057.c │ ├── test058.c │ ├── test059.c │ ├── test060.c │ ├── test061.c │ ├── test062.c │ ├── test063.c │ ├── test063.h │ ├── test064.c │ ├── test065.c │ ├── test066.c │ └── update.sh └── types.c ├── cc2.old ├── Makefile ├── cast.patch ├── cc2.h ├── cgen.c ├── code.c ├── generror ├── main.c ├── optm.c ├── parser.c └── peep.c ├── cc2 ├── Makefile ├── arch │ ├── amd64-sysv │ │ ├── arch.h │ │ ├── cgen.c │ │ ├── code.c │ │ ├── optm.c │ │ └── types.c │ ├── i386-sysv │ │ ├── arch.h │ │ ├── cgen.c │ │ ├── code.c │ │ ├── optm.c │ │ └── types.c │ ├── qbe │ │ ├── arch.h │ │ ├── cgen.c │ │ ├── code.c │ │ ├── optm.c │ │ └── types.c │ └── z80 │ │ ├── arch.h │ │ ├── cgen.c │ │ ├── code.c │ │ ├── optm.c │ │ └── types.c ├── cc2.h ├── cgen.c ├── code.c ├── generror ├── generror.awk ├── main.c ├── node.c ├── optm.c ├── parser.c ├── peep.c └── symbol.c ├── config.mk ├── crt └── amd64-linux │ └── crt.s ├── driver └── posix │ ├── Makefile │ └── scc.c ├── inc ├── arg.h ├── c89 │ └── cstd.h ├── c99 │ └── cstd.h ├── cc.h ├── sizes.h ├── sizes_c89.h ├── sizes_c99.h └── sysincludes.def.h ├── lib ├── Makefile ├── debug.c ├── die.c ├── newitem.c ├── xcalloc.c ├── xmalloc.c ├── xrealloc.c └── xstrdup.c ├── libc ├── include │ ├── amd64-sysv │ │ ├── assert.h │ │ ├── ctype.h │ │ ├── errno.h │ │ ├── signal.h │ │ ├── stdio.h │ │ ├── stdlib.h │ │ └── string.h │ ├── 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 │ │ ├── qbe │ │ │ └── arch │ │ │ │ ├── limits.h │ │ │ │ ├── signal.h │ │ │ │ ├── stddef.h │ │ │ │ ├── stdint.h │ │ │ │ ├── stdio.h │ │ │ │ ├── stdlib.h │ │ │ │ ├── string.h │ │ │ │ └── time.h │ │ └── z80 │ │ │ └── arch │ │ │ ├── limits.h │ │ │ ├── signal.h │ │ │ ├── stddef.h │ │ │ ├── stdint.h │ │ │ ├── stdio.h │ │ │ ├── stdlib.h │ │ │ ├── string.h │ │ │ └── time.h │ ├── ctype.h │ ├── errno.h │ ├── i386-sysv │ │ ├── assert.h │ │ ├── ctype.h │ │ ├── errno.h │ │ ├── signal.h │ │ ├── stdio.h │ │ ├── stdlib.h │ │ └── string.h │ ├── limits.h │ ├── locale.h │ ├── qbe │ │ ├── assert.h │ │ ├── ctype.h │ │ ├── errno.h │ │ ├── signal.h │ │ ├── stdio.h │ │ ├── stdlib.h │ │ └── string.h │ ├── signal.h │ ├── stdarg.h │ ├── stdbool.h │ ├── stddef.h │ ├── stdint.h │ ├── stdio.h │ ├── stdlib.h │ ├── string.h │ ├── time.h │ └── z80 │ │ ├── assert.h │ │ ├── ctype.h │ │ ├── errno.h │ │ ├── signal.h │ │ ├── stdio.h │ │ ├── stdlib.h │ │ └── string.h └── src │ ├── Makefile │ ├── assert.c │ ├── atexit.c │ ├── atoi.c │ ├── calloc.c │ ├── ctype.c │ ├── exit.c │ ├── fprintf.c │ ├── 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 │ ├── localeconv.c │ ├── malloc.c │ ├── malloc.h │ ├── memchr.c │ ├── memcmp.c │ ├── memcpy.c │ ├── memmove.c │ ├── memset.c │ ├── printf.c │ ├── rand.c │ ├── realloc.c │ ├── setlocale.c │ ├── strcat.c │ ├── strchr.c │ ├── strcmp.c │ ├── strcoll.c │ ├── strcpy.c │ ├── strcspn.c │ ├── strlen.c │ ├── strncat.c │ ├── strncmp.c │ ├── strncpy.c │ ├── strpbrk.c │ ├── strrchr.c │ ├── strspn.c │ ├── strstr.c │ ├── strtok.c │ ├── strxfrm.c │ ├── sys │ ├── amd64-sysv-linux │ │ ├── Makefile │ │ ├── syscall.awk │ │ └── syscall.lst │ ├── i386-sysv-linux │ │ ├── Makefile │ │ └── syscall.lst │ ├── qbe-linux │ │ ├── Makefile │ │ ├── syscall.awk │ │ └── syscall.lst │ └── z80-linux │ │ ├── Makefile │ │ └── syscall.lst │ ├── syscall.h │ ├── tolower.c │ ├── toupper.c │ └── vfprintf.c ├── scc └── tests ├── 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 ├── 0062-include.h ├── 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 ├── Makefile ├── README ├── chktest.sh ├── 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 ├── 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 ├── Makefile ├── README ├── chktest.sh ├── compose.sh ├── include │ ├── 0062-include.h │ └── 0062-include2.h ├── scc-tests.lst └── sysinclude │ ├── 0064-sysinclude.h │ └── 0064-sysinclude2.h ├── include └── 0064-sysinclude.h └── selfhost.sh /bin/README: -------------------------------------------------------------------------------- 1 | This is place holder for control version systems 2 | -------------------------------------------------------------------------------- /bin/cpp.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | scc -E $@ 3 | -------------------------------------------------------------------------------- /cc1/Makefile: -------------------------------------------------------------------------------- 1 | # See LICENSE file for copyright and license details. 2 | .POSIX: 3 | 4 | CSTDINC = -I../inc/$(STD) 5 | 6 | include ../config.mk 7 | 8 | OBJS = types.o decl.o lex.o error.o symbol.o main.o expr.o \ 9 | code.o stmt.o cpp.o fold.o init.o builtin.o \ 10 | arch/$(ARCH)/arch.o 11 | 12 | all: cc1-$(ARCH) 13 | 14 | cpp.o: stallman.msg 15 | arch/$(ARCH)/arch.o: ../inc/sysincludes.h 16 | $(OBJS): cc1.h ../inc/cc.h ../inc/$(STD)/cstd.h 17 | 18 | ../inc/sysincludes.h: 19 | cp -f ../inc/sysincludes.def.h ../inc/sysincludes.h 20 | 21 | ../lib/libcc.a: 22 | cd ../lib && $(MAKE) -e 23 | 24 | cc1-$(ARCH): $(OBJS) ../lib/libcc.a 25 | $(CC) $(SCC_LDFLAGS) $(OBJS) ../lib/libcc.a -o $@ 26 | 27 | cpp: cc1-$(ARCH) 28 | ln -f $< cpp 29 | 30 | test: 31 | cd tests && ./chktest.sh *.c 32 | 33 | clean: 34 | rm -f $(OBJS) 35 | rm -f cc1-* cpp 36 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /cc1/arch/amd64-sysv/arch.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | #define RANK_BOOL 0 3 | #define RANK_SCHAR 1 4 | #define RANK_UCHAR 1 5 | #define RANK_CHAR 1 6 | #define RANK_SHORT 2 7 | #define RANK_USHORT 2 8 | #define RANK_INT 3 9 | #define RANK_UINT 3 10 | #define RANK_LONG 4 11 | #define RANK_ULONG 4 12 | #define RANK_LLONG 5 13 | #define RANK_ULLONG 5 14 | #define RANK_FLOAT 6 15 | #define RANK_DOUBLE 7 16 | #define RANK_LDOUBLE 8 17 | 18 | #define TINT long long 19 | #define TUINT unsigned long long 20 | #define TFLOAT double 21 | 22 | #define L_ENUM L_INT32 23 | -------------------------------------------------------------------------------- /cc1/arch/i386-sysv/arch.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | #define RANK_BOOL 0 3 | #define RANK_SCHAR 1 4 | #define RANK_UCHAR 1 5 | #define RANK_CHAR 1 6 | #define RANK_SHORT 2 7 | #define RANK_USHORT 2 8 | #define RANK_INT 3 9 | #define RANK_UINT 3 10 | #define RANK_LONG 4 11 | #define RANK_ULONG 4 12 | #define RANK_LLONG 5 13 | #define RANK_ULLONG 5 14 | #define RANK_FLOAT 6 15 | #define RANK_DOUBLE 7 16 | #define RANK_LDOUBLE 8 17 | 18 | #define TINT long long 19 | #define TUINT unsigned long long 20 | #define TFLOAT double 21 | 22 | #define L_ENUM L_INT32 23 | -------------------------------------------------------------------------------- /cc1/arch/i386/arch.h: -------------------------------------------------------------------------------- 1 | 2 | #define TINT long long 3 | #define TUINT unsigned long long 4 | #define TFLOAT double 5 | 6 | #define L_SCHAR L_INT8 7 | #define L_UCHAR L_UINT8 8 | #define L_CHAR L_INT8 9 | #define L_SHORT L_INT16 10 | #define L_USHORT L_UINT16 11 | #define L_INT L_INT32 12 | #define L_UINT L_UINT32 13 | #define L_LONG L_INT32 14 | #define L_ULONG L_UINT32 15 | #define L_LLONG L_INT64 16 | #define L_ULLONG L_UINT64 17 | #define L_BOOL 'B' 18 | #define L_FLOAT 'J' 19 | #define L_DOUBLE 'D' 20 | #define L_LDOUBLE 'H' 21 | #define L_ENUM L_INT 22 | -------------------------------------------------------------------------------- /cc1/arch/qbe/arch.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | #define RANK_BOOL 0 3 | #define RANK_SCHAR 1 4 | #define RANK_UCHAR 1 5 | #define RANK_CHAR 1 6 | #define RANK_SHORT 2 7 | #define RANK_USHORT 2 8 | #define RANK_INT 3 9 | #define RANK_UINT 3 10 | #define RANK_LONG 4 11 | #define RANK_ULONG 4 12 | #define RANK_LLONG 5 13 | #define RANK_ULLONG 5 14 | #define RANK_FLOAT 6 15 | #define RANK_DOUBLE 7 16 | #define RANK_LDOUBLE 8 17 | 18 | #define TINT long long 19 | #define TUINT unsigned long long 20 | #define TFLOAT double 21 | 22 | #define L_ENUM L_INT32 23 | -------------------------------------------------------------------------------- /cc1/arch/z80/arch.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | #define RANK_BOOL 0 3 | #define RANK_SCHAR 1 4 | #define RANK_UCHAR 1 5 | #define RANK_CHAR 1 6 | #define RANK_SHORT 2 7 | #define RANK_USHORT 2 8 | #define RANK_INT 3 9 | #define RANK_UINT 3 10 | #define RANK_LONG 4 11 | #define RANK_ULONG 4 12 | #define RANK_LLONG 5 13 | #define RANK_ULLONG 5 14 | #define RANK_FLOAT 6 15 | #define RANK_DOUBLE 7 16 | #define RANK_LDOUBLE 8 17 | 18 | #define TINT long long 19 | #define TUINT unsigned long long 20 | #define TFLOAT double 21 | 22 | #define L_ENUM L_INT16 23 | -------------------------------------------------------------------------------- /cc1/tests/chktest.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # See LICENSE file for copyright and license details. 3 | 4 | out=/tmp/$$.out 5 | err=/tmp/$$.err 6 | chk=/tmp/$$.chk 7 | tst=/tmp/$$.tst 8 | 9 | trap "rm -f $out $chk $err $tst" EXIT INT QUIT HUP 10 | rm -f test.log 11 | 12 | for i 13 | do 14 | rm -f $chk 15 | awk '/^name:/ {printf "Running %s ", $2} 16 | /^error:$/ {copyon=1; next} 17 | /^TODO/ {printf "[DISABLED]"} 18 | /^output:$/ {next} 19 | /^\*\// {copyon=0; next} 20 | copyon==1 {print > "'$chk'"}' $i 21 | 22 | ../cc1-z80 -I. -w $i > $out 2>$err 23 | echo $i >> test.log 24 | cat $err $out > $tst 25 | diff -c $chk $tst >> test.log && echo [OK] || echo [FAILED] 26 | done 27 | -------------------------------------------------------------------------------- /cc1/tests/stdio.h: -------------------------------------------------------------------------------- 1 | #ifndef _STDIO_H 2 | #define _STDIO_H 3 | 4 | int printf(const char *fmt, ...); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /cc1/tests/test001.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST001 5 | description: Basic hello world test 6 | error: 7 | output: 8 | X4 I F "printf 9 | G6 I F "main 10 | { 11 | \ 12 | V8 K #ND 13 | Y9 V8 " ( 14 | #"hello world 15 | #K0A 16 | #K00 17 | ) 18 | X4 Y9 'P pP cI 19 | h #I0 20 | } 21 | */ 22 | 23 | #include 24 | 25 | int 26 | main(void) 27 | { 28 | printf("hello world\n"); 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /cc1/tests/test002.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST002 5 | description: Test forward references before definition of types 6 | error: 7 | output: 8 | G4 P "x 9 | S2 "S #N8 #N2 10 | M5 I "i #N0 11 | M6 P "next #N2 12 | G8 I F "main 13 | { 14 | \ 15 | A9 S2 "y 16 | A10 P "p 17 | A11 N "n 18 | A9 M5 .I #I0 :I 19 | G4 @S2 A9 :S2 20 | A11 #N0 :N A10 A9 'P :P ,P 21 | j L14 22 | e 23 | L12 24 | A11 #N1 :+N A10 A10 @S2 M6 .P :P ,P 25 | L14 26 | y L12 A10 #P0 !I 27 | b 28 | L13 29 | } 30 | */ 31 | 32 | struct S *x; 33 | struct S { 34 | int i; 35 | struct S *next; 36 | }; 37 | 38 | int 39 | main(void) 40 | { 41 | struct S y, *p; 42 | unsigned n; 43 | 44 | y.i = 0; 45 | *x = y; 46 | 47 | for (n = 0, p = &y; p; ++n, p = p->next) 48 | /* nothing */; 49 | } 50 | -------------------------------------------------------------------------------- /cc1/tests/test003.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST003 5 | description: Select function to call inside ternary operator 6 | error: 7 | output: 8 | G2 I F "foo 9 | { 10 | \ 11 | h #I2A 12 | } 13 | G3 I F "bar 14 | { 15 | \ 16 | h #I18 17 | } 18 | G4 I F "main 19 | { 20 | \ 21 | h G2 cI 22 | } 23 | */ 24 | 25 | int 26 | foo(void) 27 | { 28 | return 42; 29 | } 30 | 31 | int 32 | bar(void) 33 | { 34 | return 24; 35 | } 36 | 37 | int 38 | main(void) 39 | { 40 | return (1 ? foo : bar)(); 41 | } 42 | -------------------------------------------------------------------------------- /cc1/tests/test004.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST004 5 | description: Test integer operations 6 | error: 7 | output: 8 | G2 I F "main 9 | { 10 | \ 11 | A3 I "x 12 | A3 #I0 :I 13 | A3 A3 #I2 +I :I 14 | A3 A3 #I1 -I :I 15 | A3 A3 #I6 *I :I 16 | A3 A3 #I2 /I :I 17 | A3 A3 #I2 %I :I 18 | A3 A3 #I2 lI :I 19 | A3 A3 #I1 rI :I 20 | A3 A3 #IFF |I :I 21 | A3 A3 #I3 &I :I 22 | A3 A3 #I1 ^I :I 23 | A3 A3 A3 #I1 >I +I :I 24 | A3 A3 A3 #I3 I +I :I 26 | A3 A3 A3 #I4 > 1; // 2 47 | x = x | 255; // 255 48 | x = x & 3; // 3 49 | x = x ^ 1; // 2 50 | x = x + (x > 1); // 2 51 | x = x + (x < 3); // 2 52 | x = x + (x > 1); // 3 53 | x = x + (x < 4); // 4 54 | if(x != 4) 55 | return 1; 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /cc1/tests/test005.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST005 5 | description: Test unary integer operations 6 | error: 7 | output: 8 | G2 I F "main 9 | { 10 | \ 11 | A3 I "x 12 | A3 #I3 :I 13 | A3 A3 #I0 =I :I 14 | A3 A3 #I0 =I :I 15 | A3 A3 ~I :I 16 | A3 A3 _I :I 17 | y L4 A3 #I2 =I 18 | h #I1 19 | L4 20 | h #I0 21 | } 22 | */ 23 | 24 | 25 | int 26 | main() 27 | { 28 | int x; 29 | 30 | x = 3; 31 | x = !x; // 0 32 | x = !x; // 1 33 | x = ~x; // -1 34 | x = -x; // 2 35 | if(x != 2) 36 | return 1; 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /cc1/tests/test006.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST006 5 | description: Basic test for if 6 | error: 7 | test006.c:5: warning: conditional expression is constant 8 | test006.c:7: warning: conditional expression is constant 9 | test006.c:10: warning: conditional expression is constant 10 | output: 11 | G1 K "c 12 | G3 I F "main 13 | { 14 | \ 15 | y L4 #I1 16 | h #I1 17 | j L5 18 | L4 19 | y L6 #I1 20 | j L7 21 | L6 22 | y L8 #I0 23 | y L9 G1 gI #I0 =I 24 | h #I1 25 | j L10 26 | L9 27 | h #I0 28 | L10 29 | j L11 30 | L8 31 | h #I1 32 | L11 33 | L7 34 | L5 35 | h #I1 36 | } 37 | */ 38 | 39 | char c; 40 | 41 | #line 1 42 | 43 | int 44 | main() 45 | { 46 | if(0) { 47 | return 1; 48 | } else if(0) { 49 | /* empty */ 50 | } else { 51 | if(1) { 52 | if(c) 53 | return 1; 54 | else 55 | return 0; 56 | } else { 57 | return 1; 58 | } 59 | } 60 | return 1; 61 | } 62 | -------------------------------------------------------------------------------- /cc1/tests/test007.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST007 5 | description: basic while test 6 | error: 7 | output: 8 | G2 I F "main 9 | { 10 | \ 11 | A3 I "x 12 | A3 #IA :I 13 | j L6 14 | e 15 | L4 16 | A3 A3 #I1 -I :I 17 | L6 18 | y L4 A3 #I0 !I 19 | b 20 | L5 21 | h A3 22 | } 23 | */ 24 | 25 | int 26 | main() 27 | { 28 | int x; 29 | 30 | x = 10; 31 | while (x) 32 | x = x - 1; 33 | return x; 34 | } 35 | -------------------------------------------------------------------------------- /cc1/tests/test008.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST008 5 | description: Basic do while loop 6 | error: 7 | output: 8 | G2 I F "main 9 | { 10 | \ 11 | A3 I "x 12 | A3 #I0 :I 13 | e 14 | L4 15 | A3 A3 #I1 +I :I 16 | y L4 A3 #IA y = 1; 48 | v.p->z = 2; 49 | if (nested.y != 1) 50 | return 1; 51 | if (nested.z != 2) 52 | return 2; 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /cc1/tests/test018.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST018 5 | description: Basic test for arrays 6 | error: 7 | output: 8 | G2 I F "main 9 | { 10 | \ 11 | V3 K #N4 12 | V4 V3 #N2 13 | A5 V4 "arr 14 | A7 P "p 15 | A9 P "q 16 | V10 I #N4 17 | A11 V10 "v 18 | A7 A5 'P :P 19 | A9 A5 'P #P4 +P #P3 +P :P 20 | A5 'P #P4 +P #P3 +P @K #K2 :K 21 | A11 #I2 :I 22 | y L13 A5 'P #P4 +P #P3 +P @K gI #I2 =I 23 | h #I1 24 | L13 25 | y L14 A7 #P4 +P #P3 +P @K gI #I2 =I 26 | h #I1 27 | L14 28 | y L15 A9 @K gI #I2 =I 29 | h #I1 30 | L15 31 | y L16 A11 #I2 =I 32 | h #I1 33 | L16 34 | h #I0 35 | } 36 | */ 37 | 38 | #line 1 39 | 40 | int 41 | main() 42 | { 43 | char arr[2][4], (*p)[4], *q; 44 | int v[4]; 45 | 46 | p = arr; 47 | q = &arr[1][3]; 48 | arr[1][3] = 2; 49 | v[0] = 2; 50 | 51 | if (arr[1][3] != 2) 52 | return 1; 53 | if (p[1][3] != 2) 54 | return 1; 55 | if (*q != 2) 56 | return 1; 57 | if (*v != 2) 58 | return 1; 59 | 60 | return 0; 61 | } 62 | -------------------------------------------------------------------------------- /cc1/tests/test019.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST019 5 | description: Basic test of constant folding in integer arithmetic operations 6 | error: 7 | test019.c:12: warning: division by 0 8 | test019.c:13: warning: division by 0 9 | output: 10 | G2 I F "main 11 | { 12 | \ 13 | A3 I "i 14 | A3 #I3 :I 15 | A3 #I1 :I 16 | A3 #I12 :I 17 | A3 #I2 :I 18 | A3 #I0 :I 19 | A3 A3 #I0 %I :I 20 | A3 A3 #I0 %I :I 21 | A3 #I8 :I 22 | A3 #I2 :I 23 | A3 #I4 :I 24 | A3 #IC :I 25 | A3 #I8 :I 26 | A3 #IFFFD :I 27 | A3 #IFFF3 :I 28 | A3 #I1 :I 29 | A3 #I0 :I 30 | A3 #I0 :I 31 | A3 #I1 :I 32 | A3 #I0 :I 33 | } 34 | */ 35 | 36 | #line 1 37 | 38 | int 39 | main(void) 40 | { 41 | int i; 42 | 43 | i = 1 + 2; 44 | i = 2 - 1; 45 | i = 3 * 6; 46 | i = 10 / 5; 47 | i = 10 % 5; 48 | i = i % 0; 49 | i = i % 0; 50 | i = 1 << 3; 51 | i = 8 >> 2; 52 | i = 12 & 4; 53 | i = 8 | 4; 54 | i = 12 ^ 4; 55 | i = -(3); 56 | i = ~12; 57 | i = 1 < 3; 58 | i = 2 > 3; 59 | i = 2 >= 3; 60 | i = 2 <= 3; 61 | i = 1 == 0; 62 | } 63 | -------------------------------------------------------------------------------- /cc1/tests/test021.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST021 5 | description: Basic test for char constants 6 | comments: This test is done for z80 implementation 7 | error: 8 | output: 9 | G2 I F "main 10 | { 11 | \ 12 | A3 K "uc 13 | A4 C "sc 14 | A3 #KFF :K 15 | A3 #K23 :K 16 | A3 #K1 :K 17 | A3 #K1 :K 18 | A3 #K41 :K 19 | A4 #CFF :C 20 | A4 #C23 :C 21 | A4 #C1 :C 22 | A4 #C1 :C 23 | A4 #C41 :C 24 | } 25 | */ 26 | 27 | int 28 | main(void) 29 | { 30 | unsigned char uc; 31 | signed char sc; 32 | 33 | uc = -1; 34 | uc = '\x23'; 35 | uc = 1u; 36 | uc = 1025; 37 | uc = 'A'; 38 | 39 | sc = -1; 40 | sc = '\x23'; 41 | sc = 1u; 42 | sc = 1025; 43 | sc = 'A'; 44 | } 45 | -------------------------------------------------------------------------------- /cc1/tests/test022.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST022 5 | description: Basic test for int constants 6 | comments: This test is done for z80 data types 7 | error: 8 | output: 9 | G2 I F "main 10 | { 11 | \ 12 | A3 I "i 13 | A4 N "u 14 | A3 #I1 :I 15 | A3 #IFFFF :I 16 | A3 #IFFFF :I 17 | A3 #IFFFF :I 18 | A3 #IFFFF :I 19 | A3 #I3 :I 20 | A3 #I1 :I 21 | A3 #I0 :I 22 | A4 #N1 :N 23 | A4 #NFFFF :N 24 | A4 #NFFFF :N 25 | A4 #NFFFF :N 26 | A4 #NFFFF :N 27 | A4 #N0 :N 28 | A4 #N3 :N 29 | A4 #N0 :N 30 | h #I0 31 | } 32 | */ 33 | 34 | int 35 | main(void) 36 | { 37 | int i; 38 | unsigned u; 39 | 40 | i = 1; 41 | i = -1; 42 | i = -1l; 43 | i = -1u; 44 | i = -1ll; 45 | i = 32766 + 1 & 3; 46 | i = (int) 32768 < 0; 47 | i = -1u < 0; 48 | 49 | u = 1; 50 | u = -1; 51 | u = -1l; 52 | u = -1u; 53 | u = -1ll; 54 | u = (unsigned) 32768 < 0; 55 | u = 32766 + 1 & 3; 56 | u = -1u < 0; 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /cc1/tests/test023.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST023 5 | description: Basic test for long constants 6 | comments: This test is done for z80 data types 7 | error: 8 | output: 9 | G2 I F "main 10 | { 11 | \ 12 | A3 W "i 13 | A4 Z "u 14 | A3 #W1 :W 15 | A3 #WFFFFFFFF :W 16 | A3 #WFFFFFFFF :W 17 | A3 #WFFFF :W 18 | A3 #WFFFFFFFF :W 19 | A3 #W3 :W 20 | A3 #W1 :W 21 | A3 #W0 :W 22 | A4 #Z1 :Z 23 | A4 #ZFFFFFFFF :Z 24 | A4 #ZFFFFFFFF :Z 25 | A4 #ZFFFF :Z 26 | A4 #ZFFFFFFFF :Z 27 | A4 #Z3 :Z 28 | A4 #Z1 :Z 29 | A4 #Z0 :Z 30 | h #I0 31 | } 32 | */ 33 | 34 | int 35 | main(void) 36 | { 37 | long i; 38 | unsigned long u; 39 | 40 | i = 1; 41 | i = -1; 42 | i = -1l; 43 | i = -1u; 44 | i = -1ll; 45 | i = (1ll << 32) - 1 & 3; 46 | i = (long) ((1ll << 32) - 1) < 0; 47 | i = -1u < 0; 48 | 49 | u = 1; 50 | u = -1; 51 | u = -1l; 52 | u = -1u; 53 | u = -1ll; 54 | u = (1ll << 32) - 1 & 3; 55 | u = (long) ((1ll << 32) - 1) < 0; 56 | u = -1u < 0; 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /cc1/tests/test024.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST024 5 | description: Basic test for long long constants 6 | comments: This test is done for z80 data types 7 | error: 8 | output: 9 | G2 I F "main 10 | { 11 | \ 12 | A3 Q "i 13 | A4 O "u 14 | A3 #Q1 :Q 15 | A3 #QFFFFFFFFFFFFFFFF :Q 16 | A3 #QFFFFFFFFFFFFFFFF :Q 17 | A3 #QFFFF :Q 18 | A3 #QFFFFFFFFFFFFFFFF :Q 19 | A3 #Q3 :Q 20 | A3 #Q1 :Q 21 | A4 #O1 :O 22 | A4 #OFFFFFFFFFFFFFFFF :O 23 | A4 #OFFFFFFFFFFFFFFFF :O 24 | A4 #OFFFF :O 25 | A4 #OFFFFFFFFFFFFFFFF :O 26 | A4 #O3 :O 27 | A4 #O0 :O 28 | h #I0 29 | } 30 | */ 31 | 32 | int 33 | main(void) 34 | { 35 | long long i; 36 | unsigned long long u; 37 | 38 | i = 1; 39 | i = -1; 40 | i = -1l; 41 | i = -1u; 42 | i = -1ll; 43 | i = -1ll & 3; 44 | i = -1ll < 0; 45 | 46 | u = 1; 47 | u = -1; 48 | u = -1l; 49 | u = -1u; 50 | u = -1ll; 51 | u = -1llu & 3; 52 | u = -1llu < 0; 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /cc1/tests/test025.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST025 5 | descritpion: Test of ifdef and ifndef 6 | error: 7 | output: 8 | G1 I "a 9 | G2 I "b 10 | G3 I "c 11 | G4 I "d 12 | G5 I "_1 13 | G6 I "_2 14 | G7 I "e_ 15 | G8 I "f_ 16 | G9 I "h 17 | G10 I "i 18 | */ 19 | 20 | #define FOO 21 | 22 | #ifdef FOO 23 | int a; 24 | int b; 25 | #undef FOO 26 | #ifndef FOO 27 | int c; 28 | int d; 29 | #else 30 | int e; 31 | int f; 32 | #endif 33 | int _1; 34 | int _2; 35 | #ifdef FOO 36 | int c_; 37 | int d_; 38 | #else 39 | int e_; 40 | int f_; 41 | #endif 42 | int h; 43 | int i; 44 | #else 45 | int j; 46 | int k; 47 | #ifdef FOO 48 | int l; 49 | int m; 50 | #else 51 | int n; 52 | int o; 53 | #endif 54 | int p; 55 | int q; 56 | #ifndef FOO 57 | int r; 58 | int s; 59 | #else 60 | int t; 61 | int u; 62 | #endif 63 | int v; 64 | int w; 65 | #endif 66 | 67 | -------------------------------------------------------------------------------- /cc1/tests/test026.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST026 5 | descritpion: Test of predefined cpp macros 6 | error: 7 | output: 8 | G3 I F "main 9 | { 10 | \ 11 | A4 I "y 12 | A6 P "p 13 | V7 K #NA 14 | Y8 V7 " ( 15 | #"test026.c 16 | #K00 17 | ) 18 | A6 Y8 'P :P 19 | A4 #I24 :I 20 | A4 #I1 :I 21 | A4 #I1 :I 22 | A4 #I1 :I 23 | A4 #I1 :I 24 | } 25 | */ 26 | 27 | #define x(y) (y) 28 | 29 | int 30 | main(void) 31 | { 32 | int y; 33 | char *p; 34 | 35 | p = __FILE__; 36 | y = __LINE__; 37 | /* p = __DATE__; __DATE__ generates different value each time */ 38 | y = __STDC__; 39 | /* p = __TIME__; __TIME__ generates different value each time */ 40 | y = __STDC_HOSTED__; 41 | y = __SCC__; 42 | y = x(1); 43 | } 44 | -------------------------------------------------------------------------------- /cc1/tests/test027.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST027 5 | description: Test of cpp stringizer 6 | error: 7 | output: 8 | G3 I F "main 9 | { 10 | \ 11 | A5 P "p 12 | V6 K #N19 13 | Y7 V6 " ( 14 | #"hello is better than bye 15 | #K00 16 | ) 17 | A5 Y7 'P :P 18 | h A5 @K gI 19 | } 20 | */ 21 | 22 | #define x(y) #y 23 | 24 | int 25 | main(void) 26 | { 27 | char *p; 28 | p = x(hello) " is better than bye"; 29 | 30 | return *p; 31 | } 32 | -------------------------------------------------------------------------------- /cc1/tests/test028.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST028 5 | description: Test of reinterpretation in define 6 | error: 7 | output: 8 | G6 P F "foo 9 | { 10 | \ 11 | V7 K #N3 12 | Y10 V7 " ( 13 | #"hi 14 | #K00 15 | ) 16 | h Y10 'P 17 | } 18 | */ 19 | 20 | 21 | #define M(x) x 22 | #define A(a,b) a(b) 23 | 24 | char * 25 | foo(void) 26 | { 27 | return A(M,"hi"); 28 | } 29 | -------------------------------------------------------------------------------- /cc1/tests/test029.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST029 5 | description: Test of nested expansion and refusing macro without arguments 6 | comments: f(2) will expand to 2*g, which will expand to 2*f, and in this 7 | moment f will not be expanded because the macro definition is 8 | a function alike macro, and in this case there is no arguments. 9 | error: 10 | test029.c:32: warning: expression without side effects 11 | test029.c:37: error: redefinition of 'f1' 12 | test029.c:38: error: 'f' undeclared 13 | test029.c:38: warning: expression without side effects 14 | output: 15 | G3 I F "f1 16 | { 17 | \ 18 | A4 I "f 19 | A4 #I2 *I 20 | } 21 | */ 22 | 23 | 24 | #define f(a) a*g 25 | #define g f 26 | 27 | int 28 | f1(void) 29 | { 30 | int f; 31 | 32 | f(2); 33 | } 34 | 35 | int 36 | f1(void) 37 | { 38 | f(2); 39 | } 40 | -------------------------------------------------------------------------------- /cc1/tests/test030.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST030 5 | description: Basic test for vararg functions 6 | error: 7 | output: 8 | S2 "foo #N18 #N2 9 | M3 I "i #N0 10 | M4 I "j #N2 11 | M5 I "k #N4 12 | M7 P "p #N6 13 | M8 J "v #N8 14 | G14 I F "f1 15 | { 16 | A9 S2 "f 17 | A11 P "p 18 | A12 I "n 19 | \ 20 | y L15 A9 M3 .I A11 @S2 M3 .I =I 21 | h #I0 22 | L15 23 | h A11 @S2 M4 .I A12 +I 24 | } 25 | G17 I F "main 26 | { 27 | \ 28 | A18 S2 "f 29 | A18 M3 .I A18 M4 .I #I1 :I :I 30 | G14 A18 pS2 A18 'P pP #I2 pI cI 31 | G14 A18 pS2 A18 'P pP #I2 pI #I1 pI A18 pS2 A18 'P pP cI 32 | h #I0 33 | } 34 | */ 35 | 36 | struct foo { 37 | int i, j, k; 38 | char *p; 39 | float v; 40 | }; 41 | 42 | int 43 | f1(struct foo f, struct foo *p, int n, ...) 44 | { 45 | if (f.i != p->i) 46 | return 0; 47 | return p->j + n; 48 | } 49 | 50 | int 51 | main(void) 52 | { 53 | struct foo f; 54 | 55 | f.i = f.j = 1; 56 | f1(f, &f, 2); 57 | f1(f, &f, 2, 1, f, &f); 58 | 59 | return 0; 60 | } 61 | -------------------------------------------------------------------------------- /cc1/tests/test031.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST031 5 | description: Test concatenation in preprocessor 6 | error: 7 | TODO 8 | output: 9 | 10 | */ 11 | 12 | #define CAT(x,y) x ## y 13 | #define XCAT(x,y) CAT(x,y) 14 | #define FOO foo 15 | #define BAR bar 16 | 17 | int 18 | main(void) 19 | { 20 | int foo, bar, foobar; 21 | 22 | CAT(foo,bar) = foo + bar; 23 | XCAT(FOO,BAR) = foo + bar; 24 | return 0; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /cc1/tests/test032.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST032 5 | description: test special characters @ and $ in macro definitions 6 | error: 7 | output: 8 | G3 I F "main 9 | { 10 | \ 11 | V6 K #N2C 12 | Y7 V6 " ( 13 | #"This is a string $ or # or ##and it is ok ! 14 | #K00 15 | ) 16 | A5 P "p 17 | A5 Y7 'P :P 18 | h A5 #P0 !I 19 | } 20 | */ 21 | 22 | #define M1(x) "This is a string $ or # or ##" ## #x 23 | 24 | int 25 | main(void) 26 | { 27 | char *p = M1(and it is ok!); 28 | 29 | return p != 0; 30 | } 31 | 32 | -------------------------------------------------------------------------------- /cc1/tests/test033.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST033 5 | description: test for #if defined() 6 | error: 7 | output: 8 | G1 I "c 9 | */ 10 | 11 | #if defined(FOO) 12 | int a; 13 | #elif !defined(FOO) && defined(BAR) 14 | int b; 15 | #elif !defined(FOO) && !defined(BAR) 16 | int c; 17 | #else 18 | int d; 19 | #endif 20 | 21 | -------------------------------------------------------------------------------- /cc1/tests/test034.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST034 5 | description: Basic test for incomplete structures 6 | error: 7 | test034.c:48: error: declared variable 'bar' of incomplete type 8 | test034.c:48: error: redeclaration of 'bar' 9 | output: 10 | X3 S2 "x 11 | X5 I F "foo 12 | G6 I F "main 13 | { 14 | \ 15 | X7 S2 "x 16 | h X7 'P #P0 !I 17 | } 18 | S2 "X #N2 #N1 19 | M9 I "v #N0 20 | G5 I F "foo 21 | { 22 | \ 23 | X3 M9 .I #I0 :I 24 | h X3 M9 .I 25 | } 26 | X13 S11 "bar2 27 | */ 28 | 29 | extern struct X x; 30 | int foo(); 31 | 32 | int main() 33 | { 34 | extern struct X x; 35 | return &x != 0; 36 | } 37 | 38 | struct X {int v;}; 39 | 40 | int foo() 41 | { 42 | x.v = 0; 43 | return x.v; 44 | } 45 | 46 | typedef struct bar bar; 47 | extern bar bar2; 48 | bar bar; 49 | -------------------------------------------------------------------------------- /cc1/tests/test035.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST035 5 | description: Basic test for enumerations 6 | error: 7 | output: 8 | G7 I F "main 9 | { 10 | \ 11 | A8 I "e 12 | A8 #I3 :I 13 | y L9 A8 #I1 =I 14 | h #I0 15 | L9 16 | y L10 A8 #I0 =I 17 | h #I1 18 | L10 19 | y L11 A8 #I2 =I 20 | h #I2 21 | L11 22 | y L12 A8 #I3 =I 23 | h #I3 24 | L12 25 | h #I0 26 | } 27 | */ 28 | 29 | enum E { 30 | x, 31 | y = 2, 32 | z, 33 | }; 34 | 35 | 36 | int 37 | main() 38 | { 39 | enum E e = 3; 40 | 41 | if (e !=1) 42 | return 0; 43 | if (e != x) 44 | return 1; 45 | if (e != y) 46 | return 2; 47 | if (e != z) 48 | return 3; 49 | 50 | return x; 51 | } 52 | -------------------------------------------------------------------------------- /cc1/tests/test037.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST037 5 | description: Basic sizeof test 6 | comments: This test is based in z80 sizes 7 | error: 8 | test037.c:30: warning: conditional expression is constant 9 | test037.c:32: warning: conditional expression is constant 10 | test037.c:34: warning: conditional expression is constant 11 | output: 12 | G2 I F "main 13 | { 14 | \ 15 | y L3 #I1 16 | h #I1 17 | L3 18 | y L4 #I1 19 | h #I2 20 | L4 21 | y L5 #I1 22 | h #I3 23 | L5 24 | h #I0 25 | } 26 | */ 27 | 28 | int main() 29 | { 30 | if(sizeof(0) != 2) 31 | return 1; 32 | if(sizeof(char) != 1) 33 | return 2; 34 | if(sizeof(int) != 2) 35 | return 3; 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /cc1/tests/test038.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST038 5 | description: Basic test for tentative definitions 6 | error: 7 | test038.c:45: error: redeclaration of 'x' 8 | output: 9 | G1 I "x 10 | G1 I "x ( 11 | #I0 12 | ) 13 | X3 I F "main 14 | G5 P F "foo 15 | { 16 | \ 17 | h X3 'P 18 | } 19 | G3 I F "main 20 | { 21 | \ 22 | G1 #I0 :I 23 | h G1 24 | } 25 | */ 26 | 27 | int x; 28 | int x = 0; 29 | int x; 30 | 31 | int main(); 32 | 33 | void * 34 | foo() 35 | { 36 | return &main; 37 | } 38 | 39 | int 40 | main() 41 | { 42 | x = 0; 43 | return x; 44 | } 45 | int x = 1; 46 | -------------------------------------------------------------------------------- /cc1/tests/test039.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST039 5 | description: Test of integer constants 6 | comments: This test is done for z80 sizes 7 | error: 8 | output: 9 | G2 I F "main 10 | { 11 | \ 12 | A3 I "i 13 | A4 N "u 14 | A5 W "l 15 | A6 Z "ul 16 | A7 Q "ll 17 | A8 O "ull 18 | A3 #I1 :I 19 | A3 #I1 :I 20 | A4 #N1 :N 21 | A4 #N1 :N 22 | A5 #W1 :W 23 | A5 #W0 :W 24 | A4 #N0 :N 25 | A6 #Z1 :Z 26 | A5 #W1 :W 27 | A7 #Q0 :Q 28 | A6 #Z0 :Z 29 | A8 #O1 :O 30 | A8 #O1 :O 31 | h #I0 32 | } 33 | */ 34 | 35 | int 36 | main(void) 37 | { 38 | int i; 39 | unsigned u; 40 | long l; 41 | unsigned long ul; 42 | long long ll; 43 | unsigned long long ull; 44 | 45 | i = 1; 46 | i = 1u; 47 | u = 1u; 48 | u = 1; 49 | l = 1l; 50 | l = 0xFFFF + 1; 51 | u = 0xFFFF + 1; 52 | ul = 1ul; 53 | l = 1ul; 54 | ll = 0xFFFFFFFF + 1; 55 | ul = 0xFFFFFFFF + 1; 56 | ull = 1lul; 57 | ull = 1; 58 | return 0; 59 | } 60 | -------------------------------------------------------------------------------- /cc1/tests/test040.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST040 5 | description: Test for bug parsing typenames in struct definition 6 | error: 7 | output: 8 | S2 "List #NC #N2 9 | M4 I "len #N0 10 | M6 P "head #N2 11 | M7 P "back #N4 12 | G9 I F "main 13 | { 14 | \ 15 | A10 S2 "List 16 | h A10 M4 .I 17 | } 18 | */ 19 | 20 | typedef struct List List; 21 | struct List { 22 | int len; 23 | struct List *head; 24 | List *back; 25 | }; 26 | 27 | int 28 | main(void) 29 | { 30 | List List; 31 | 32 | return List.len; 33 | } 34 | 35 | -------------------------------------------------------------------------------- /cc1/tests/test041.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST041 5 | description: Test for bug parsing ternary operators 6 | error: 7 | test041.c:51: error: type mismatch in conditional expression 8 | test041.c:51: error: incompatible types when assigning 9 | test041.c:52: error: used struct/union type value where scalar is required 10 | test041.c:52: warning: expression without side effects 11 | test041.c:53: warning: 'i' defined but not used 12 | test041.c:53: warning: 'foo' defined but not used 13 | test041.c:53: warning: 's' defined but not used 14 | output: 15 | G2 I F "main 16 | { 17 | \ 18 | A3 I "i 19 | A5 P "q 20 | A7 P "s 21 | A8 P "p 22 | S10 "foo #N2 #N1 23 | M11 I "i #N0 24 | A12 S10 "foo 25 | A3 A3 #I0 !I #W0 #W0 ?W gI :I 26 | A8 A3 #I0 !I #P0 #P0 ?P :P 27 | A8 A3 #I0 !I #P0 #P0 ?P :P 28 | A8 A3 #I0 !I #P0 #P0 ?P :P 29 | A5 A3 #I0 !I #P0 A8 ?P :P 30 | A5 A3 #I0 !I A8 #P0 ?P :P 31 | A5 A3 #I0 !I A5 #P0 ?P :P 32 | A5 A3 #I0 !I #P0 A5 ?P :P 33 | */ 34 | 35 | int 36 | main(void) 37 | { 38 | int i, *q; 39 | char *s; 40 | void *p; 41 | struct foo {int i;} foo; 42 | 43 | i = i ? 0 : 0l; 44 | p = i ? (void *) 0 : 0; 45 | p = i ? 0 : (void *) 0; 46 | p = i ? 0 : (const void *) 0; 47 | q = i ? 0 : p; 48 | q = i ? p : 0; 49 | q = i ? q : 0; 50 | q = i ? 0 : q; 51 | p = i ? 2 : p; 52 | foo ? 1 : 2; 53 | } 54 | 55 | -------------------------------------------------------------------------------- /cc1/tests/test042.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST042 5 | description: Test for bug parsing ternary operators 6 | error: 7 | test042.c:20: error: bad type conversion requested 8 | output: 9 | G2 I F "main 10 | { 11 | \ 12 | X4 0 F "f 13 | */ 14 | 15 | int 16 | main(void) 17 | { 18 | void f(void); 19 | 20 | return (int) f(); 21 | } 22 | -------------------------------------------------------------------------------- /cc1/tests/test043.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST043 5 | description: Test for double typedef (taken from plan9 kernel) 6 | error: 7 | output: 8 | S2 "Clock0link #N8 #N2 9 | M6 P "clock #N0 10 | M8 P "link #N2 11 | G9 S2 "cl0 12 | G11 I F "main 13 | { 14 | \ 15 | G9 M6 .P @F c0 16 | h #I0 17 | } 18 | */ 19 | 20 | typedef struct Clock0link Clock0link; 21 | typedef struct Clock0link { 22 | void (*clock)(void); 23 | Clock0link* link; 24 | } Clock0link; 25 | 26 | 27 | 28 | Clock0link cl0; 29 | 30 | int 31 | main(void) 32 | { 33 | (*cl0.clock)(); 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /cc1/tests/test044.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST044 5 | description: Test of corner cases in #if 6 | error: 7 | test044.c:17: warning: division by 0 8 | test044.c:21: warning: division by 0 9 | test044.c:25: warning: division by 0 10 | test044.c:31: error: parameter of #if is not an integer constant expression 11 | test044.c:32: error: #error 3 != (1,2,3) 12 | output: 13 | */ 14 | 15 | /* These should be accepted */ 16 | 17 | #if 0 != (0 && (0/0)) 18 | #error 0 != (0 && (0/0)) 19 | #endif 20 | 21 | #if 1 != (-1 || (0/0)) 22 | #error 1 != (-1 || (0/0)) 23 | #endif 24 | 25 | #if 3 != (-1 ? 3 : (0/0)) 26 | #error 3 != (-1 ? 3 : (0/0)) 27 | #endif 28 | 29 | /* This is invalid code (it is a constraint violation) */ 30 | 31 | #if 3 != (1,2,3) 32 | #error 3 != (1,2,3) 33 | #endif 34 | 35 | -------------------------------------------------------------------------------- /cc1/tests/test045.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST045 5 | description: Basic test of initializers 6 | error: 7 | output: 8 | G1 I "x ( 9 | #I5 10 | ) 11 | G3 I F "main 12 | { 13 | \ 14 | y L4 G1 #I5 =I 15 | h #I1 16 | L4 17 | h #I0 18 | } 19 | */ 20 | 21 | 22 | 23 | int x = 5; 24 | 25 | int 26 | main() 27 | { 28 | if(x != 5) 29 | return 1; 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /cc1/tests/test046.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST046 5 | description: Basic test for initializators 6 | error: 7 | output: 8 | V1 I #N3 9 | G2 V1 "x ( 10 | #I1 11 | #I2 12 | #I3 13 | ) 14 | G4 I F "main 15 | { 16 | \ 17 | y L5 G2 #I1 =I 18 | h #I1 19 | L5 20 | y L7 G2 'P #P2 +P @I #I2 =I 21 | h #I2 22 | L7 23 | y L8 G2 'P #P4 +P @I #I3 =I 24 | h #I3 25 | L8 26 | h #I0 27 | } 28 | */ 29 | 30 | int x[3] = {1, 2, 3}; 31 | 32 | int 33 | main() 34 | { 35 | if(x[0] != 1) 36 | return 1; 37 | if(x[1] != 2) 38 | return 2; 39 | if(x[2] != 3) 40 | return 3; 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /cc1/tests/test047.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST047 5 | description: Basic test for initializer 6 | error: 7 | output: 8 | S2 "S #N6 #N1 9 | M3 I "a #N0 10 | M4 I "b #N2 11 | M5 I "c #N4 12 | G6 S2 "x ( 13 | #I1 14 | #I2 15 | #I3 16 | ) 17 | G8 I F "main 18 | { 19 | \ 20 | y L9 G6 M3 .I #I1 =I 21 | h #I1 22 | L9 23 | y L10 G6 M4 .I #I2 =I 24 | h #I2 25 | L10 26 | y L11 G6 M5 .I #I3 =I 27 | h #I3 28 | L11 29 | h #I0 30 | } 31 | */ 32 | 33 | 34 | 35 | struct S { 36 | int a; 37 | int b; 38 | int c; 39 | }; 40 | 41 | struct S x = {1, 2, 3}; 42 | 43 | int 44 | main() 45 | { 46 | if(x.a != 1) 47 | return 1; 48 | if(x.b != 2) 49 | return 2; 50 | if(x.c != 3) 51 | return 3; 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /cc1/tests/test048.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST048 5 | description: Basic test for initializer 6 | error: 7 | output: 8 | S2 "S #N4 #N1 9 | M3 I "a #N0 10 | M4 I "b #N2 11 | V5 S2 #N1 12 | G6 V5 "x ( 13 | #I1 14 | #I2 15 | ) 16 | G8 I F "main 17 | { 18 | \ 19 | y L9 G6 M3 .I #I1 =I 20 | h #I1 21 | L9 22 | y L11 G6 M4 .I #I2 =I 23 | h #I2 24 | L11 25 | h #I0 26 | } 27 | */ 28 | 29 | struct S { 30 | int a; 31 | int b; 32 | }; 33 | 34 | struct S x[1] = {{1, 2}}; 35 | 36 | int 37 | main() 38 | { 39 | if(x[0].a != 1) 40 | return 1; 41 | if(x[0].b != 2) 42 | return 2; 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /cc1/tests/test049.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST049 5 | description: Basic test for initializer 6 | error: 7 | output: 8 | G1 I "x ( 9 | #I5 10 | ) 11 | G3 P "p ( 12 | G1 'P 13 | ) 14 | G5 I F "main 15 | { 16 | \ 17 | y L6 G3 @I #I5 =I 18 | h #I1 19 | L6 20 | h #I0 21 | } 22 | */ 23 | 24 | int x = 5; 25 | int *p = &x; 26 | 27 | int 28 | main() 29 | { 30 | if(*p != 5) 31 | return 1; 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /cc1/tests/test050.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST050 5 | description: Basic test for initializer 6 | error: 7 | TODO: 8 | output: 9 | */ 10 | 11 | struct S { int a; int b; }; 12 | struct S s = (struct S){1, 2}; 13 | 14 | int 15 | main() 16 | { 17 | if(s.a != 1) 18 | return 1; 19 | if(s.b != 2) 20 | return 2; 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /cc1/tests/test051.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST051 5 | description: Basic test for initializer 6 | error: 7 | output: 8 | V1 I #N3 9 | G2 V1 "arr ( 10 | #I0 11 | #I1 12 | #I2 13 | ) 14 | G4 I F "main 15 | { 16 | \ 17 | y L5 G2 #I0 =I 18 | h #I1 19 | L5 20 | y L7 G2 'P #P2 +P @I #I1 =I 21 | h #I2 22 | L7 23 | y L8 G2 'P #P4 +P @I #I2 =I 24 | h #I3 25 | L8 26 | h #I0 27 | } 28 | */ 29 | 30 | int arr[3] = {[2] = 2, [0] = 0, [1] = 1}; 31 | 32 | int 33 | main() 34 | { 35 | if(arr[0] != 0) 36 | return 1; 37 | if(arr[1] != 1) 38 | return 2; 39 | if(arr[2] != 2) 40 | return 3; 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /cc1/tests/test052.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST052 5 | description: Basic test for initializer 6 | error: 7 | output: 8 | S2 "S #N4 #N1 9 | M3 I "a #N0 10 | M4 I "b #N2 11 | V5 S2 #N2 12 | G6 V5 "arr ( 13 | #I1 14 | #I2 15 | #I3 16 | #I4 17 | ) 18 | G8 I F "main 19 | { 20 | \ 21 | y L9 G6 M3 .I #I1 =I 22 | h #I1 23 | L9 24 | y L11 G6 M4 .I #I2 =I 25 | h #I2 26 | L11 27 | y L12 G6 'P #P4 +P @S2 M3 .I #I3 =I 28 | h #I3 29 | L12 30 | y L13 G6 'P #P4 +P @S2 M4 .I #I4 =I 31 | h #I4 32 | L13 33 | h #I0 34 | } 35 | */ 36 | 37 | struct S {int a; int b;}; 38 | struct S arr[2] = {[1] = {3, 4}, [0] = {1, 2}}; 39 | 40 | int 41 | main() 42 | { 43 | if(arr[0].a != 1) 44 | return 1; 45 | if(arr[0].b != 2) 46 | return 2; 47 | if(arr[1].a != 3) 48 | return 3; 49 | if(arr[1].b != 4) 50 | return 4; 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /cc1/tests/test053.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST053 5 | description: Basic test for initializer 6 | error: 7 | output: 8 | S2 "S #N4 #N1 9 | M3 I "a #N0 10 | M4 I "b #N2 11 | G5 S2 "s ( 12 | #I1 13 | #I2 14 | ) 15 | G7 I F "main 16 | { 17 | \ 18 | y L8 G5 M3 .I #I1 =I 19 | h #I1 20 | L8 21 | y L9 G5 M4 .I #I2 =I 22 | h #I2 23 | L9 24 | h #I0 25 | } 26 | */ 27 | 28 | struct S {int a; int b;}; 29 | struct S s = { .b = 2, .a = 1}; 30 | 31 | int 32 | main() 33 | { 34 | if(s.a != 1) 35 | return 1; 36 | if(s.b != 2) 37 | return 2; 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /cc1/tests/test054.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST054 5 | description: Basic test for initializer 6 | error: 7 | TODO 8 | output: 9 | 10 | */ 11 | 12 | struct S { int a; int b; }; 13 | struct S *s = &(struct S) { 1, 2 }; 14 | 15 | int 16 | main() 17 | { 18 | if(s->a != 1) 19 | return 1; 20 | if(s->b != 2) 21 | return 2; 22 | return 0; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /cc1/tests/test055.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST055 5 | description: Basic test for initializer 6 | error: 7 | TODO 8 | output: 9 | 10 | */ 11 | 12 | struct S1 { 13 | int a; 14 | int b; 15 | }; 16 | struct S2 { 17 | struct S1 s1; 18 | struct S1 *ps1; 19 | int arr[2]; 20 | }; 21 | struct S1 gs1 = (struct S1) {.a = 1, 2}; 22 | struct S2 *s = &(struct S2) { 23 | {.b = 2, .a = 1}, 24 | &gs1, 25 | {[0] = 1, 1+1} 26 | }; 27 | 28 | int 29 | main() 30 | { 31 | if(s->s1.a != 1) 32 | return 1; 33 | if(s->s1.b != 2) 34 | return 2; 35 | if(s->ps1->a != 1) 36 | return 3; 37 | if(s->ps1->b != 2) 38 | return 4; 39 | if(s->arr[0] != 1) 40 | return 5; 41 | if(s->arr[1] != 2) 42 | return 6; 43 | return 0; 44 | } 45 | 46 | -------------------------------------------------------------------------------- /cc1/tests/test056.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST056 5 | desciption: Test of overlaying designators 6 | error: 7 | output: 8 | V6 K #N3 9 | S2 "S #NB #N1 10 | M3 I "a #N0 11 | M4 I "b #N2 12 | M5 I "c #N4 13 | M7 V6 "d #N6 14 | M8 I "e #N9 15 | G9 S2 "s ( 16 | #I1 17 | #I2 18 | #I0 19 | #K4 20 | #K6 21 | #K0 22 | #I0 23 | ) 24 | G11 V10 "m ( 25 | ) 26 | G13 I F "main 27 | { 28 | \ 29 | h G9 M7 .V6 'P #P2 +P @K gI gN #N0 =I 30 | } 31 | */ 32 | 33 | struct S { 34 | int a, b, c; 35 | char d[3]; 36 | int e; 37 | } s = { 38 | .a = 1, 39 | .b = 2, 40 | .d = {[0] = 3, [2] = 5}, 41 | .d = {[0] = 4, [1] = 6} 42 | }; 43 | 44 | char m[] = {}; 45 | 46 | int 47 | main(void) 48 | { 49 | return sizeof(m) == s.d[2]; 50 | } 51 | -------------------------------------------------------------------------------- /cc1/tests/test057.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST057 5 | description: test of initialization of incomplete arrays 6 | error: 7 | output: 8 | V1 I #N3 9 | G3 V2 "arr1 ( 10 | #I2 11 | #I7 12 | #I5 13 | #I5 14 | #I1 15 | #I2 16 | ) 17 | G4 V2 "arr2 ( 18 | #I2 19 | #I7 20 | #I5 21 | #I5 22 | #I1 23 | #I2 24 | ) 25 | G6 I F "main 26 | { 27 | \ 28 | h G3 'P #P6 +P #P4 +P @I G4 'P #P6 +P #P6 +P @I !I 29 | } 30 | */ 31 | 32 | int arr1[][3] = { 33 | { 2, 7, 5, }, 34 | { 5, 1, 2, }, 35 | }; 36 | 37 | int arr2[2][3] = { 38 | 2, 7, 5, 39 | 5, 1, 2 40 | }; 41 | 42 | int 43 | main(void) 44 | { 45 | return !(arr1[1][2] == arr2[1][3]); 46 | } 47 | -------------------------------------------------------------------------------- /cc1/tests/test058.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST058 5 | description: Test of initialization mixing designators and sequence 6 | error: 7 | output: 8 | V1 I #N5 9 | V2 V1 #N3 10 | G4 V3 "arr ( 11 | #I0 12 | #I0 13 | #I3 14 | #I5 15 | #I0 16 | #I1 17 | #I0 18 | #I0 19 | #I6 20 | #I7 21 | #I0 22 | #I0 23 | #I0 24 | #I0 25 | #I0 26 | #I1 27 | #I2 28 | #I0 29 | #I0 30 | #I0 31 | #I0 32 | #I0 33 | #I0 34 | #I0 35 | #I7 36 | #I0 37 | #I0 38 | #I0 39 | #I0 40 | #I0 41 | ) 42 | G6 I F "main 43 | { 44 | \ 45 | h G4 'P #PA +P #P8 +P @I G4 'P #P1E +P #PA +P #P8 +P @I !I 46 | } 47 | */ 48 | 49 | int arr[][3][5] = { 50 | { 51 | { 0, 0, 3, 5 }, 52 | { 1, [3] = 6, 7 }, 53 | }, 54 | { 55 | { 1, 2 }, 56 | { [4] = 7, }, 57 | }, 58 | }; 59 | 60 | 61 | int 62 | main(void) 63 | { 64 | return !(arr[0][1][4] == arr[1][1][4]); 65 | } 66 | -------------------------------------------------------------------------------- /cc1/tests/test059.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST059 5 | description: Test of initalizers for strings 6 | error: 7 | TODO 8 | output: 9 | 10 | */ 11 | 12 | char s0[] = "foo"; 13 | char s1[7] = "foo"; 14 | char s2[2] = "foo"; 15 | char s3[] = {"foo"}; 16 | char *p = "foo"; 17 | int m[] = "foo"; 18 | -------------------------------------------------------------------------------- /cc1/tests/test060.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST060 5 | description: Test for correctness of #line 6 | error: 7 | output: 8 | G2 I F "main 9 | { 10 | \ 11 | h #I0 12 | } 13 | */ 14 | 15 | #undef line 16 | #define line 1000 17 | 18 | #line line 19 | #if 1000 != __LINE__ 20 | #error " # line line" not work as expected 21 | #endif 22 | 23 | int 24 | main() 25 | { 26 | return 0; 27 | } 28 | 29 | -------------------------------------------------------------------------------- /cc1/tests/test061.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST061 5 | description: Test for macros without arguments but with parenthesis 6 | error: 7 | output: 8 | G3 I F "main 9 | { 10 | \ 11 | h #I1 12 | } 13 | */ 14 | 15 | #define X (2) 16 | #define L (0) 17 | #define H (1) 18 | #define Q(x) x 19 | 20 | int 21 | main(void) 22 | { 23 | return X == L + H + Q(1); 24 | } 25 | -------------------------------------------------------------------------------- /cc1/tests/test062.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST062 5 | description: Test for hexadecimal numbers in upper and lower case 6 | error: 7 | output: 8 | G2 I F "main 9 | { 10 | \ 11 | h #I1 12 | } 13 | */ 14 | 15 | int 16 | main(void) 17 | { 18 | return 0xa == 0xA && 19 | 0xb == 0xB && 20 | 0xc == 0xC && 21 | 0xd == 0xD && 22 | 0xe == 0xE && 23 | 0xf == 0xF; 24 | } 25 | -------------------------------------------------------------------------------- /cc1/tests/test063.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST063 5 | description: Test a comment that goes beyond of the end of an included file 6 | error: 7 | test063.h:9: error: unterminated comment 8 | test063.c:12: error: #endif expected 9 | output: 10 | */ 11 | 12 | #include "test063.h" 13 | -------------------------------------------------------------------------------- /cc1/tests/test063.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef TEST_H_ 3 | #define TEST_H_ 4 | 5 | /* 6 | This is an unterminated comment. 7 | 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /cc1/tests/test064.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST064 5 | description: Test function alike macro without parenthesis 6 | error: 7 | output: 8 | S1 " #N2 #N1 9 | M2 I "f #N0 10 | G5 I F "main 11 | { 12 | \ 13 | A6 S1 "s 14 | A6 M2 .I #I0 :I 15 | h A6 M2 .I 16 | } 17 | */ 18 | 19 | #define x f 20 | #define y() f 21 | 22 | typedef struct { int f; } S; 23 | 24 | int 25 | main() 26 | { 27 | S s; 28 | 29 | s.x = 0; 30 | return s.y(); 31 | } 32 | 33 | -------------------------------------------------------------------------------- /cc1/tests/test065.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST065 5 | description: Test decay mixed with * operators 6 | error: 7 | test065.c:65: error: increment of pointer to an incomplete type 8 | test065.c:65: error: invalid use of undefined type 9 | test065.c:66: warning: 'argv' defined but not used 10 | output: 11 | G7 I F "main 12 | { 13 | A1 I "argc 14 | A5 P "argv 15 | \ 16 | V8 I #N1 17 | A9 V8 "v 18 | A12 P "p 19 | A14 P "f1 20 | A15 P "f2 21 | A9 #I0 :I 22 | A12 A9 'P :P 23 | A14 G7 'P :P 24 | A15 G7 'P :P 25 | y L18 A1 #I0 !I 26 | h #I1 27 | L18 28 | y L19 G7 #I0 pI #P0 pP cI #I0 =I 29 | h #I2 30 | L19 31 | y L20 A14 @F #I0 pI #P0 pP cI #I0 =I 32 | h #I3 33 | L20 34 | y L21 A15 @F #I0 pI #P0 pP cI #I0 =I 35 | h #I4 36 | L21 37 | y L22 A12 @I #I0 !I 38 | h #I0 39 | L22 40 | */ 41 | 42 | int 43 | main(int argc, char *argv[]) 44 | { 45 | int v[1]; 46 | int (*p)[]; 47 | int (*f1)(int ,char *[]); 48 | int (*f2)(int ,char *[]); 49 | 50 | v[0] = 0; 51 | p = &v; 52 | f1 = &main; 53 | f2 = main; 54 | if (argc == 0) 55 | return 1; 56 | if ((****main)(0, 0)) 57 | return 2; 58 | if ((****f1)(0, 0)) 59 | return 3; 60 | if ((****f2)(0, 0)) 61 | return 4; 62 | if (!(*p)[0]) 63 | return 0; 64 | 65 | return (*++p)[0] || p[1][0]; 66 | } 67 | -------------------------------------------------------------------------------- /cc1/tests/test066.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* 4 | name: TEST066 5 | description: Test cpp defined operator 6 | error: 7 | test066.c:53: error: operator 'defined' requires an identifier 8 | test066.c:53: error: expected ')' before '' 9 | output: 10 | G1 I "x ( 11 | #I0 12 | ) 13 | G3 I F "main 14 | { 15 | \ 16 | h #I0 17 | */ 18 | 19 | 20 | #if defined X 21 | X 22 | #endif 23 | 24 | #if defined(X) 25 | X 26 | #endif 27 | 28 | #if X 29 | X 30 | #endif 31 | 32 | #define X 0 33 | 34 | #if X 35 | X 36 | #endif 37 | 38 | #if defined(X) 39 | int x = 0; 40 | #endif 41 | 42 | #undef X 43 | #define X 1 44 | 45 | #if X 46 | int 47 | main() 48 | { 49 | return 0; 50 | } 51 | #endif 52 | 53 | #if defined (1) 54 | #error 1 is defined 55 | #endif 56 | -------------------------------------------------------------------------------- /cc1/tests/update.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # See LICENSE file for copyright and license details. 3 | 4 | out=/tmp/$$.out 5 | err=/tmp/$$.err 6 | 7 | trap "rm -f $out $err" EXIT INT QUIT HUP 8 | 9 | case $# in 10 | 0) 11 | echo "usage: update.sh test ..." >&2 12 | exit 1 13 | ;; 14 | *) 15 | for i 16 | do 17 | ../cc1-z80 -I./ -w $i >$out 2>$err 18 | (echo '/^error/+;/^output/-c' 19 | cat $err 20 | printf ".\n" 21 | echo '/^output/+;/^\*\//-c' 22 | cat $out 23 | printf ".\nw\n") | ed -s $i 24 | done 25 | ;; 26 | esac 27 | -------------------------------------------------------------------------------- /cc2.old/Makefile: -------------------------------------------------------------------------------- 1 | .POSIX: 2 | 3 | include ../config.mk 4 | 5 | OBJS = main.o parser.o cgen.o code.o optm.o peep.o 6 | 7 | all: cc2 8 | 9 | 10 | $(OBJS): ../inc/cc.h ../inc/sizes.h cc2.h 11 | main.o: error.h 12 | 13 | error.h: cc2.h 14 | rm -f $@; trap 'rm -f $$$$.h' EXIT INT QUIT 15 | awk -f generror cc2.h > $$$$.h && mv $$$$.h $@ 16 | 17 | cc2: $(OBJS) ../lib/libcc.a 18 | $(CC) $(LDFLAGS) $(OBJS) ../lib/libcc.a -o $@ 19 | 20 | clean: 21 | rm -f $(OBJS) 22 | rm -f cc2 error.h 23 | 24 | -------------------------------------------------------------------------------- /cc2.old/generror: -------------------------------------------------------------------------------- 1 | 2 | BEGIN { 3 | print "char *errlist[] = {" 4 | } 5 | /^enum nerrors \{/ { 6 | inhome = 1 7 | } 8 | inhome && /E[A-Z]*, / { 9 | sub(/,/, "", $1) 10 | printf("\t[%s] = \"", $1) 11 | for (i = 3; i < NF-1; ++i) 12 | printf("%s ", $i) 13 | printf("%s\",\n", $(NF-1)); 14 | } 15 | inhome && /^}/ { 16 | print "};" 17 | inhome = 0 18 | } 19 | 20 | -------------------------------------------------------------------------------- /cc2.old/main.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "../inc/cc.h" 8 | 9 | #include "cc2.h" 10 | #include "error.h" 11 | 12 | char odebug; 13 | 14 | void 15 | error(unsigned nerror, ...) 16 | { 17 | va_list va; 18 | va_start(va, nerror); 19 | if (nerror >= ENUMERR) 20 | fprintf(stderr, "incorrect error number '%d'", nerror); 21 | else 22 | vfprintf(stderr, errlist[nerror], va); 23 | va_end(va); 24 | putc('\n', stderr); 25 | exit(1); 26 | } 27 | 28 | bool 29 | moreinput(void) 30 | { 31 | int c; 32 | 33 | repeat: 34 | if (feof(stdin)) 35 | return 0; 36 | if ((c = getchar()) == '\n' || c == EOF) 37 | goto repeat; 38 | ungetc(c, stdin); 39 | return 1; 40 | } 41 | 42 | int 43 | main(void) 44 | { 45 | fputs("cc2 is not updated with the output of cc1", stderr); 46 | exit(1); 47 | while (moreinput()) { 48 | parse(); 49 | optimize(); 50 | addable(); 51 | generate(); 52 | peephole(); 53 | writeout(); 54 | } 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /cc2.old/optm.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | #include "../inc/cc.h" 6 | #include "cc2.h" 7 | 8 | 9 | #include 10 | 11 | static Node * 12 | optcasts(Node *np, Type *tp) 13 | { 14 | if (!np) 15 | return NULL; 16 | 17 | repeat: 18 | switch (np->op) { 19 | case OCAST: 20 | /* TODO: be careful with the sign */ 21 | if (np->type.flags&INTF && np->type.size >= tp->size) { 22 | np = np->left; 23 | goto repeat; 24 | } 25 | break; 26 | case OASSIG: 27 | tp = &np->type; 28 | break; 29 | default: 30 | if (np->type.size > tp->size) 31 | np->type = *tp; 32 | break; 33 | } 34 | 35 | np->left = optcasts(np->left, tp); 36 | np->right = optcasts(np->right, tp); 37 | return np; 38 | } 39 | 40 | static Node * 41 | opt(Node *np) 42 | { 43 | np = optcasts(np, &np->type); 44 | return np; 45 | } 46 | 47 | void 48 | optimize(void) 49 | { 50 | apply(opt); 51 | } 52 | -------------------------------------------------------------------------------- /cc2.old/peep.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | #include "../inc/cc.h" 6 | #include "cc2.h" 7 | 8 | void 9 | peephole(void) 10 | { 11 | Addr to, from; 12 | TINT i; 13 | uint8_t op; 14 | 15 | for (pc = prog; pc; pc = pc->next) { 16 | to = pc->to; 17 | from = pc->from; 18 | 19 | switch (pc->op) { 20 | case SUB: 21 | case ADD: 22 | if (from.kind == CONST) { 23 | if ((i = from.u.i) == 0 || i < 4) { 24 | delcode(); 25 | op = (pc->op == ADD) ? INC : DEC; 26 | 27 | while (i--) 28 | inscode(op, &to, NULL); 29 | } 30 | /* TODO: More optimizations (ex: -1) */ 31 | } 32 | break; 33 | case JP: 34 | if (to.u.sym->u.pc == pc->next) 35 | delcode(); 36 | break; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /cc2/Makefile: -------------------------------------------------------------------------------- 1 | # See LICENSE file for copyright and license details. 2 | .POSIX: 3 | 4 | CSTDINC = -I../inc/$(STD) 5 | 6 | include ../config.mk 7 | 8 | OBJS = main.o parser.o peep.o symbol.o node.o code.o optm.o\ 9 | arch/$(ARCH)/code.o arch/$(ARCH)/cgen.o \ 10 | arch/$(ARCH)/types.o arch/$(ARCH)/optm.o 11 | 12 | all: cc2-$(ARCH) 13 | 14 | main.o: error.h 15 | $(OBJS): cc2.h ../inc/$(STD)/cstd.h ../inc/cc.h 16 | arch/$(ARCH)/code.o: arch/$(ARCH)/arch.h 17 | arch/$(ARCH)/cgen.o: arch/$(ARCH)/arch.h 18 | 19 | error.h: cc2.h 20 | rm -f $@; trap 'rm -f $$$$.h' EXIT INT QUIT ;\ 21 | awk -f generror.awk cc2.h > $$$$.h && mv $$$$.h $@ 22 | 23 | ../lib/libcc.a: 24 | cd ../lib && $(MAKE) -e 25 | 26 | cc2-$(ARCH): $(OBJS) ../lib/libcc.a 27 | $(CC) $(SCC_LDFLAGS) $(OBJS) ../lib/libcc.a -o $@ 28 | 29 | clean: 30 | rm -f $(OBJS) 31 | rm -f cc2-* error.h 32 | -------------------------------------------------------------------------------- /cc2/arch/amd64-sysv/arch.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | -------------------------------------------------------------------------------- /cc2/arch/amd64-sysv/cgen.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | static char sccsid[] = "@(#) ./cc2/arch/amd64-sysv/cgen.c"; 3 | 4 | #include "arch.h" 5 | #include "../../../inc/cc.h" 6 | #include "../../cc2.h" 7 | 8 | Node * 9 | cgen(Node *np) 10 | { 11 | } 12 | 13 | Node * 14 | sethi(Node *np) 15 | { 16 | } 17 | -------------------------------------------------------------------------------- /cc2/arch/amd64-sysv/optm.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | static char sccsid[] = "@(#) ./cc2/arch/amd64-sysv/optm.c"; 3 | 4 | #include "../../../inc/cc.h" 5 | #include "../../cc2.h" 6 | 7 | Node * 8 | optm_dep(Node *np) 9 | { 10 | return np; 11 | } 12 | -------------------------------------------------------------------------------- /cc2/arch/i386-sysv/arch.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | -------------------------------------------------------------------------------- /cc2/arch/i386-sysv/cgen.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | static char sccsid[] = "@(#) ./cc2/arch/i386-sysv/cgen.c"; 3 | 4 | #include "arch.h" 5 | #include "../../../inc/cc.h" 6 | #include "../../cc2.h" 7 | 8 | Node * 9 | cgen(Node *np) 10 | { 11 | } 12 | 13 | Node * 14 | sethi(Node *np) 15 | { 16 | } 17 | -------------------------------------------------------------------------------- /cc2/arch/i386-sysv/optm.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | static char sccsid[] = "@(#) ./cc2/arch/i386-sysv/optm.c"; 3 | 4 | #include "../../../inc/cc.h" 5 | #include "../../cc2.h" 6 | 7 | Node * 8 | optm_dep(Node *np) 9 | { 10 | return np; 11 | } 12 | -------------------------------------------------------------------------------- /cc2/arch/z80/arch.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | -------------------------------------------------------------------------------- /cc2/arch/z80/optm.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | static char sccsid[] = "@(#) ./cc2/arch/z80/optm.c"; 3 | 4 | #include "../../../inc/cc.h" 5 | #include "../../cc2.h" 6 | 7 | Node * 8 | optm_dep(Node *np) 9 | { 10 | return np; 11 | } 12 | -------------------------------------------------------------------------------- /cc2/generror: -------------------------------------------------------------------------------- 1 | 2 | BEGIN { 3 | print "char *errlist[] = {" 4 | } 5 | /^enum nerrors \{/ {inhome = 1} 6 | inhome && /E[A-Z]*, / {sub(/,/, "", $1) 7 | printf("\t[%s] = \"", $1) 8 | for (i = 3; i < NF-1; ++i) 9 | printf("%s ", $i) 10 | printf("%s\",\n", $(NF-1));} 11 | inhome && /^}/ {print "};" ; inhome = 0} 12 | 13 | -------------------------------------------------------------------------------- /cc2/generror.awk: -------------------------------------------------------------------------------- 1 | # See LICENSE file for copyright and license details. 2 | BEGIN { 3 | print "char *errlist[] = {" 4 | } 5 | /^enum nerrors \{/ {inhome = 1} 6 | inhome && /E[A-Z]*, / {sub(/,/, "", $1) 7 | printf("\t[%s] = \"", $1) 8 | for (i = 3; i < NF-1; ++i) 9 | printf("%s ", $i) 10 | printf("%s\",\n", $(NF-1));} 11 | inhome && /^}/ {print "};" ; inhome = 0} 12 | 13 | -------------------------------------------------------------------------------- /cc2/main.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | static char sccsid[] = "@(#) ./cc2/main.c"; 3 | #include 4 | #include 5 | #include 6 | 7 | #include "../inc/cc.h" 8 | #include "cc2.h" 9 | #include "error.h" 10 | 11 | void 12 | error(unsigned nerror, ...) 13 | { 14 | va_list va; 15 | va_start(va, nerror); 16 | vfprintf(stderr, errlist[nerror], va); 17 | va_end(va); 18 | putc('\n', stderr); 19 | exit(1); 20 | } 21 | 22 | static int 23 | moreinput(void) 24 | { 25 | int c; 26 | 27 | repeat: 28 | if (feof(stdin)) 29 | return 0; 30 | if ((c = getchar()) == '\n' || c == EOF) 31 | goto repeat; 32 | ungetc(c, stdin); 33 | return 1; 34 | } 35 | 36 | int 37 | main(int argc, char *argv[]) 38 | { 39 | if (argc > 2) 40 | die("usage: cc2 [irfile]"); 41 | 42 | if (argv[1] && !freopen(argv[1], "r", stdin)) 43 | die("cc2: cannot open %s", argv[1]); 44 | 45 | while (moreinput()) { 46 | parse(); 47 | apply(optm_ind); 48 | apply(optm_dep); 49 | apply(sethi); 50 | apply(cgen); 51 | getbblocks(); /* TODO: run apply over asm ins too */ 52 | peephole(); 53 | writeout(); 54 | } 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /cc2/optm.c: -------------------------------------------------------------------------------- 1 | 2 | #include "../inc/cc.h" 3 | #include "cc2.h" 4 | 5 | Node * 6 | optm_ind(Node *np) 7 | { 8 | return np; 9 | } 10 | 11 | -------------------------------------------------------------------------------- /cc2/peep.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | static char sccsid[] = "@(#) ./cc2/peep.c"; 3 | #include "../inc/cc.h" 4 | #include "cc2.h" 5 | 6 | void 7 | peephole(void) 8 | { 9 | } 10 | -------------------------------------------------------------------------------- /config.mk: -------------------------------------------------------------------------------- 1 | # scc version 2 | VERSION = 0.1 3 | 4 | ## Customize below to fit your system 5 | ARCHS = z80 i386-sysv amd64-sysv qbe 6 | # default architecure used in nested makefiles 7 | ARCH = qbe 8 | SYS = linux 9 | DRIVER = posix 10 | 11 | # Can be c89 or c99 12 | STD = c99 13 | 14 | # paths 15 | PREFIX = $(HOME) 16 | MANPREFIX = $(PREFIX)/share/man 17 | 18 | # scc expects to be built by a C99 compiler 19 | # if your system is not at least POSIX 2004 compatible, adjust CC 20 | # CC = c99 21 | # AR = ar 22 | AS = as 23 | 24 | # for Plan9 add -D_SUSV2_SOURCE 25 | SCC_CFLAGS = -DARCH=\"$(ARCH)\" \ 26 | $(CSTDINC) \ 27 | -DPREFIX=\"$(PREFIX)\" \ 28 | -g \ 29 | $(CFLAGS) 30 | 31 | SCC_LDFLAGS = $(LDFLAGS) 32 | 33 | .s.o: 34 | $(AS) $< -o $@ 35 | 36 | .c.o: 37 | $(CC) $(SCC_CFLAGS) -o $@ -c $< 38 | 39 | .c: 40 | $(CC) $(SCC_CFLAGS) $(SCC_LDFLAGS) -o $@ $< 41 | -------------------------------------------------------------------------------- /crt/amd64-linux/crt.s: -------------------------------------------------------------------------------- 1 | .file "crt.as" 2 | .text 3 | .global _start 4 | 5 | _start: 6 | call main 7 | movl %eax, %edi 8 | call exit 9 | -------------------------------------------------------------------------------- /driver/posix/Makefile: -------------------------------------------------------------------------------- 1 | # See LICENSE file for copyright and license details. 2 | .POSIX: 3 | 4 | include ../../config.mk 5 | 6 | OBJS = scc.o 7 | 8 | all: scc 9 | 10 | $(OBJS): ../../inc/cc.h ../../inc/arg.h 11 | 12 | ../../lib/libcc.a: 13 | cd ../../lib && $(MAKE) -e 14 | 15 | scc: $(OBJS) ../../lib/libcc.a 16 | $(CC) $(SCC_LDFLAGS) $(OBJS) ../../lib/libcc.a -o $@ 17 | 18 | clean: 19 | rm -f $(OBJS) 20 | rm -f scc 21 | -------------------------------------------------------------------------------- /inc/cc.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | #include 3 | 4 | extern int debug; 5 | 6 | #ifndef NDEBUG 7 | #define DBG(...) dbg(__VA_ARGS__) 8 | #define DBGON() (debug = 1) 9 | #else 10 | #define DBG(...) 11 | #define DBGON() 12 | #endif 13 | 14 | #ifndef PREFIX 15 | #define PREFIX "/usr/local/" 16 | #endif 17 | 18 | #define TINT long long 19 | #define TUINT unsigned long long 20 | #define TFLOAT double 21 | 22 | struct items { 23 | char **s; 24 | unsigned n; 25 | }; 26 | 27 | extern void die(const char *fmt, ...); 28 | extern void dbg(const char *fmt, ...); 29 | extern void newitem(struct items *items, char *item); 30 | extern void *xmalloc(size_t size); 31 | extern void *xcalloc(size_t nmemb, size_t size); 32 | extern char *xstrdup(const char *s); 33 | extern void *xrealloc(void *buff, register size_t size); 34 | -------------------------------------------------------------------------------- /inc/sysincludes.def.h: -------------------------------------------------------------------------------- 1 | char *sysincludes[] = { 2 | PREFIX "/include/scc/" , 3 | PREFIX "/include/scc/bits/" ARCH "/", 4 | /* configure below your standard sys include paths */ 5 | PREFIX "/include/", 6 | PREFIX "/local/include/", 7 | NULL 8 | }; 9 | -------------------------------------------------------------------------------- /lib/Makefile: -------------------------------------------------------------------------------- 1 | # See LICENSE file for copyright and license details. 2 | .POSIX: 3 | include ../config.mk 4 | 5 | OBJS = debug.o die.o newitem.o xcalloc.o xmalloc.o xrealloc.o xstrdup.o 6 | 7 | all: libcc.a 8 | 9 | 10 | libcc.a: $(OBJS) 11 | ar $(ARFLAGS) $@ $? 12 | ranlib $@ 13 | 14 | clean: 15 | rm -f *.o *.a 16 | -------------------------------------------------------------------------------- /lib/debug.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | static char sccsid[] = "@(#) ./lib/debug.c"; 3 | #include 4 | #include 5 | 6 | #include "../inc/cc.h" 7 | 8 | int debug; 9 | 10 | void 11 | dbg(const char *fmt, ...) 12 | { 13 | if (!debug) 14 | return; 15 | va_list va; 16 | va_start(va, fmt); 17 | vfprintf(stderr, fmt, va); 18 | putc('\n', stderr); 19 | va_end(va); 20 | return; 21 | } 22 | -------------------------------------------------------------------------------- /lib/die.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | static char sccsid[] = "@(#) ./lib/die.c"; 3 | #include 4 | #include 5 | #include 6 | 7 | #include "../inc/cc.h" 8 | 9 | int failure; 10 | 11 | void 12 | die(const char *fmt, ...) 13 | { 14 | failure = 1; 15 | va_list va; 16 | va_start(va, fmt); 17 | vfprintf(stderr, fmt, va); 18 | putc('\n', stderr); 19 | va_end(va); 20 | exit(1); 21 | } 22 | -------------------------------------------------------------------------------- /lib/newitem.c: -------------------------------------------------------------------------------- 1 | #include "../inc/cc.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/xcalloc.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | static char sccsid[] = "@(#) ./lib/xcalloc.c"; 3 | #include 4 | #include "../inc/cc.h" 5 | 6 | void * 7 | xcalloc(size_t n, size_t size) 8 | { 9 | void *p = calloc(n, size); 10 | 11 | if (!p) 12 | die("out of memory"); 13 | return p; 14 | } 15 | -------------------------------------------------------------------------------- /lib/xmalloc.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | static char sccsid[] = "@(#) ./lib/xmalloc.c"; 3 | #include 4 | #include "../inc/cc.h" 5 | 6 | void * 7 | xmalloc(size_t size) 8 | { 9 | void *p = malloc(size); 10 | 11 | if (!p) 12 | die("out of memory"); 13 | return p; 14 | } 15 | -------------------------------------------------------------------------------- /lib/xrealloc.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | static char sccsid[] = "@(#) ./lib/xrealloc.c"; 3 | #include 4 | #include "../inc/cc.h" 5 | 6 | void * 7 | xrealloc(void *buff, size_t size) 8 | { 9 | void *p = realloc(buff, size); 10 | 11 | if (!p) 12 | die("out of memory"); 13 | return p; 14 | } 15 | -------------------------------------------------------------------------------- /lib/xstrdup.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | static char sccsid[] = "@(#) ./lib/xstrdup.c"; 3 | #include 4 | #include "../inc/cc.h" 5 | 6 | char * 7 | xstrdup(const char *s) 8 | { 9 | size_t len = strlen(s) + 1; 10 | char *p = xmalloc(len); 11 | 12 | return memcpy(p, s, len); 13 | } 14 | -------------------------------------------------------------------------------- /libc/include/amd64-sysv/assert.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | #ifndef _ASSERT_H 3 | #define _ASSERT_H 4 | 5 | #ifndef NDEBUG 6 | #define assert(exp) __assert(exp, #exp, __FILE__, __LINE__) 7 | #endif 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /libc/include/amd64-sysv/ctype.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | #ifndef _CTYPE_H 3 | #define _CTYPE_H 4 | 5 | int isalnum(int c); 6 | int isalpha(int c); 7 | int islower(int c); 8 | int isupper(int c); 9 | int isdigit(int c); 10 | int isxdigit(int c); 11 | int iscntrl(int c); 12 | int isgraph(int c); 13 | int isspace(int c); 14 | int isblank(int c); 15 | int isprint(int c); 16 | int ispunct(int c); 17 | int tolower(int c); 18 | int toupper(int c); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /libc/include/amd64-sysv/errno.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | #ifndef _ERRNO_H 3 | #define _ERRNO_H 4 | 5 | extern int errno; 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /libc/include/amd64-sysv/signal.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | #ifndef _SIGNAL_H 3 | #define _SIGNAL_H 4 | 5 | void ( *signal(int signum, void (*handler)(int)) ) (int); 6 | int raise(int sig); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /libc/include/assert.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | #ifndef _ASSERT_H 3 | #define _ASSERT_H 4 | 5 | void __assert(char *exp, char *file, long line); 6 | 7 | #ifndef NDEBUG 8 | # define assert(exp) ((exp) ? (void) 0 : __assert(#exp, __FILE__, __LINE__)) 9 | #else 10 | # define assert(exp) ((void)0) 11 | #endif 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /libc/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 | -------------------------------------------------------------------------------- /libc/include/bits/amd64-sysv/arch/signal.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | typedef int sig_atomic_t; 4 | 5 | #define SIG_ERR -1 6 | #define SIG_DFL 0 7 | #define SIG_IGN 1 8 | 9 | #define SIGHUP 1 10 | #define SIGINT 2 11 | #define SIGQUIT 3 12 | #define SIGILL 4 13 | #define SIGABRT 6 14 | #define SIGFPE 8 15 | #define SIGKILL 9 16 | #define SIGUSR1 10 17 | #define SIGSEGV 11 18 | #define SIGUSR2 12 19 | #define SIGPIPE 13 20 | #define SIGALRM 14 21 | #define SIGTERM 15 22 | #define SIGCHLD 17 23 | #define SIGCONT 18 24 | #define SIGSTOP 19 25 | #define SIGSSTP 20 26 | #define SIGTTIN 21 27 | #define SIGTTOU 22 28 | 29 | #define __NR_SIGNALS 23 30 | -------------------------------------------------------------------------------- /libc/include/bits/amd64-sysv/arch/stddef.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #ifndef _SIZET 4 | typedef unsigned long size_t; 5 | #define _SIZET 6 | #endif 7 | 8 | #ifndef _WCHAR_T 9 | typedef int wchar_t; 10 | #define _WCHAR_T 11 | #endif 12 | 13 | #ifndef _PTRDIFF_T 14 | typedef long ptrdiff_t; 15 | #define _PTRDIFF_T 16 | #endif 17 | -------------------------------------------------------------------------------- /libc/include/bits/amd64-sysv/arch/stdio.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #ifndef _SIZET 4 | typedef unsigned long size_t; 5 | #define _SIZET 6 | #endif 7 | 8 | #define BUFSIZ 512 9 | #define FILENAME_MAX 256 10 | #define FOPEN_MAX 16 11 | 12 | #define TMP_MAX 25 13 | #define L_tmpnam 256 14 | 15 | typedef int fpos_t; 16 | -------------------------------------------------------------------------------- /libc/include/bits/amd64-sysv/arch/stdlib.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #ifndef _SIZET 4 | typedef unsigned long size_t; 5 | #define _SIZET 6 | #endif 7 | 8 | #define EXIT_FAILURE 1 9 | #define EXIT_SUCCESS 0 10 | 11 | #ifndef _WCHAR_T 12 | typedef int wchar_t; 13 | #define _WCHAR_T 14 | #endif 15 | 16 | #define _ALIGNTYPE long double 17 | -------------------------------------------------------------------------------- /libc/include/bits/amd64-sysv/arch/string.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #ifndef _SIZET 4 | typedef unsigned long size_t; 5 | #endif 6 | -------------------------------------------------------------------------------- /libc/include/bits/amd64-sysv/arch/time.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #ifndef _SIZET 4 | typedef unsigned long size_t; 5 | #define _SIZET 6 | #endif 7 | 8 | typedef long int time_t; 9 | -------------------------------------------------------------------------------- /libc/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 | -------------------------------------------------------------------------------- /libc/include/bits/i386-sysv/arch/signal.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | typedef int sig_atomic_t; 4 | 5 | #define SIG_ERR -1 6 | #define SIG_DFL 0 7 | #define SIG_IGN 1 8 | 9 | #define SIGHUP 1 10 | #define SIGINT 2 11 | #define SIGQUIT 3 12 | #define SIGILL 4 13 | #define SIGABRT 6 14 | #define SIGFPE 8 15 | #define SIGKILL 9 16 | #define SIGUSR1 10 17 | #define SIGSEGV 11 18 | #define SIGUSR2 12 19 | #define SIGPIPE 13 20 | #define SIGALRM 14 21 | #define SIGTERM 15 22 | #define SIGCHLD 17 23 | #define SIGCONT 18 24 | #define SIGSTOP 19 25 | #define SIGSSTP 20 26 | #define SIGTTIN 21 27 | #define SIGTTOU 22 28 | 29 | #define __NR_SIGNALS 23 30 | -------------------------------------------------------------------------------- /libc/include/bits/i386-sysv/arch/stddef.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #ifndef _SIZET 4 | typedef unsigned long size_t; 5 | #define _SIZET 6 | #endif 7 | 8 | #ifndef _WCHAR_T 9 | typedef int wchar_t; 10 | #define _WCHAR_T 11 | #endif 12 | 13 | #ifndef _PTRDIFF_T 14 | typedef long ptrdiff_t; 15 | #define _PTRDIFF_T 16 | #endif 17 | -------------------------------------------------------------------------------- /libc/include/bits/i386-sysv/arch/stdio.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #ifndef _SIZET 4 | typedef unsigned long size_t; 5 | #define _SIZET 6 | #endif 7 | 8 | #define BUFSIZ 512 9 | #define FILENAME_MAX 256 10 | #define FOPEN_MAX 16 11 | 12 | #define TMP_MAX 25 13 | #define L_tmpnam 256 14 | 15 | typedef long fpos_t; 16 | -------------------------------------------------------------------------------- /libc/include/bits/i386-sysv/arch/stdlib.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #ifndef _SIZET 4 | typedef unsigned long size_t; 5 | #define _SIZET 6 | #endif 7 | 8 | #define EXIT_FAILURE 1 9 | #define EXIT_SUCCESS 0 10 | 11 | #ifndef _WCHAR_T 12 | typedef int wchar_t; 13 | #define _WCHAR_T 14 | #endif 15 | 16 | #define _ALIGNTYPE long double 17 | -------------------------------------------------------------------------------- /libc/include/bits/i386-sysv/arch/string.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #ifndef _SIZET 4 | typedef unsigned long size_t; 5 | #endif 6 | -------------------------------------------------------------------------------- /libc/include/bits/i386-sysv/arch/time.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #ifndef _SIZET 4 | typedef unsigned long size_t; 5 | #define _SIZET 6 | #endif 7 | 8 | typedef long int time_t; 9 | -------------------------------------------------------------------------------- /libc/include/bits/qbe/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 | -------------------------------------------------------------------------------- /libc/include/bits/qbe/arch/signal.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | typedef int sig_atomic_t; 4 | 5 | #define SIG_ERR -1 6 | #define SIG_DFL 0 7 | #define SIG_IGN 1 8 | 9 | #define SIGHUP 1 10 | #define SIGINT 2 11 | #define SIGQUIT 3 12 | #define SIGILL 4 13 | #define SIGABRT 6 14 | #define SIGFPE 8 15 | #define SIGKILL 9 16 | #define SIGUSR1 10 17 | #define SIGSEGV 11 18 | #define SIGUSR2 12 19 | #define SIGPIPE 13 20 | #define SIGALRM 14 21 | #define SIGTERM 15 22 | #define SIGCHLD 17 23 | #define SIGCONT 18 24 | #define SIGSTOP 19 25 | #define SIGSSTP 20 26 | #define SIGTTIN 21 27 | #define SIGTTOU 22 28 | 29 | #define __NR_SIGNALS 23 30 | -------------------------------------------------------------------------------- /libc/include/bits/qbe/arch/stddef.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #ifndef _SIZET 4 | typedef unsigned long size_t; 5 | #define _SIZET 6 | #endif 7 | 8 | #ifndef _WCHAR_T 9 | typedef int wchar_t; 10 | #define _WCHAR_T 11 | #endif 12 | 13 | #ifndef _PTRDIFF_T 14 | typedef long ptrdiff_t; 15 | #define _PTRDIFF_T 16 | #endif 17 | -------------------------------------------------------------------------------- /libc/include/bits/qbe/arch/stdio.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #ifndef _SIZET 4 | typedef unsigned long size_t; 5 | #define _SIZET 6 | #endif 7 | 8 | #define BUFSIZ 512 9 | #define FILENAME_MAX 256 10 | #define FOPEN_MAX 16 11 | 12 | #define TMP_MAX 25 13 | #define L_tmpnam 256 14 | 15 | typedef int fpos_t; 16 | -------------------------------------------------------------------------------- /libc/include/bits/qbe/arch/stdlib.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #ifndef _SIZET 4 | typedef unsigned long size_t; 5 | #define _SIZET 6 | #endif 7 | 8 | #define EXIT_FAILURE 1 9 | #define EXIT_SUCCESS 0 10 | 11 | #ifndef _WCHAR_T 12 | typedef int wchar_t; 13 | #define _WCHAR_T 14 | #endif 15 | 16 | #define _ALIGNTYPE long double 17 | -------------------------------------------------------------------------------- /libc/include/bits/qbe/arch/string.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #ifndef _SIZET 4 | typedef unsigned long size_t; 5 | #endif 6 | -------------------------------------------------------------------------------- /libc/include/bits/qbe/arch/time.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #ifndef _SIZET 4 | typedef unsigned long size_t; 5 | #define _SIZET 6 | #endif 7 | 8 | typedef long int time_t; 9 | -------------------------------------------------------------------------------- /libc/include/bits/z80/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 | -------------------------------------------------------------------------------- /libc/include/bits/z80/arch/signal.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | typedef char sig_atomic_t; 4 | 5 | #define SIG_ERR -1 6 | #define SIG_DFL 0 7 | #define SIG_IGN 1 8 | 9 | #define SIG_ERR -1 10 | #define SIG_DFL 0 11 | #define SIG_IGN 1 12 | 13 | #define SIGHUP 1 14 | #define SIGINT 2 15 | #define SIGQUIT 3 16 | #define SIGILL 4 17 | #define SIGABRT 6 18 | #define SIGFPE 8 19 | #define SIGKILL 9 20 | #define SIGUSR1 10 21 | #define SIGSEGV 11 22 | #define SIGUSR2 12 23 | #define SIGPIPE 13 24 | #define SIGALRM 14 25 | #define SIGTERM 15 26 | #define SIGCHLD 17 27 | #define SIGCONT 18 28 | #define SIGSTOP 19 29 | #define SIGSSTP 20 30 | #define SIGTTIN 21 31 | #define SIGTTOU 22 32 | 33 | #define __NR_SIGNALS 23 34 | -------------------------------------------------------------------------------- /libc/include/bits/z80/arch/stddef.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #ifndef _SIZET 4 | typedef unsigned size_t; 5 | #define _SIZET 6 | #endif 7 | 8 | #ifndef _WCHAR_T 9 | typedef short wchar_t; 10 | #define _WCHAR_T 11 | #endif 12 | 13 | #ifndef _PTRDIFF_T 14 | typedef short ptrdiff_t; 15 | #define _PTRDIFF_T 16 | #endif 17 | -------------------------------------------------------------------------------- /libc/include/bits/z80/arch/stdio.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #ifndef _SIZET 4 | typedef unsigned size_t; 5 | #define _SIZET 6 | #endif 7 | 8 | #define BUFSIZ 512 9 | #define FILENAME_MAX 256 10 | #define FOPEN_MAX 16 11 | 12 | #define TMP_MAX 25 13 | #define L_tmpnam 256 14 | 15 | typedef long fpos_t; 16 | -------------------------------------------------------------------------------- /libc/include/bits/z80/arch/stdlib.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #ifndef _SIZET 4 | typedef unsigned size_t; 5 | #define _SIZET 6 | #endif 7 | 8 | #define EXIT_FAILURE 1 9 | #define EXIT_SUCCESS 0 10 | 11 | #ifndef _WCHAR_T 12 | typedef short wchar_t; 13 | #define _WCHAR_T 14 | #endif 15 | 16 | #define _ALIGNTYPE int 17 | -------------------------------------------------------------------------------- /libc/include/bits/z80/arch/string.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #ifndef _SIZET 4 | typedef unsigned size_t; 5 | #endif 6 | -------------------------------------------------------------------------------- /libc/include/bits/z80/arch/time.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #ifndef _SIZET 4 | typedef unsigned size_t; 5 | #define _SIZET 6 | #endif 7 | 8 | typedef long time_t; 9 | -------------------------------------------------------------------------------- /libc/include/errno.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | #ifndef _ERRNO_H 3 | #define _ERRNO_H 4 | 5 | #define EDOM 1 6 | #define EILSEQ 2 7 | #define ERANGE 3 8 | #define ENOMEN 4 9 | 10 | extern int errno; 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /libc/include/i386-sysv/assert.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | #ifndef _ASSERT_H 3 | #define _ASSERT_H 4 | 5 | #ifndef NDEBUG 6 | #define assert(exp) __assert(exp, #exp, __FILE__, __LINE__) 7 | #endif 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /libc/include/i386-sysv/ctype.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | #ifndef _CTYPE_H 3 | #define _CTYPE_H 4 | 5 | int isalnum(int c); 6 | int isalpha(int c); 7 | int islower(int c); 8 | int isupper(int c); 9 | int isdigit(int c); 10 | int isxdigit(int c); 11 | int iscntrl(int c); 12 | int isgraph(int c); 13 | int isspace(int c); 14 | int isblank(int c); 15 | int isprint(int c); 16 | int ispunct(int c); 17 | int tolower(int c); 18 | int toupper(int c); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /libc/include/i386-sysv/errno.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | #ifndef _ERRNO_H 3 | #define _ERRNO_H 4 | 5 | extern int errno; 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /libc/include/i386-sysv/signal.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | #ifndef _SIGNAL_H 3 | #define _SIGNAL_H 4 | 5 | void ( *signal(int signum, void (*handler)(int)) ) (int); 6 | int raise(int sig); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /libc/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 | -------------------------------------------------------------------------------- /libc/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 | -------------------------------------------------------------------------------- /libc/include/qbe/assert.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | #ifndef _ASSERT_H 3 | #define _ASSERT_H 4 | 5 | #ifndef NDEBUG 6 | #define assert(exp) __assert(exp, #exp, __FILE__, __LINE__) 7 | #endif 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /libc/include/qbe/ctype.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | #ifndef _CTYPE_H 3 | #define _CTYPE_H 4 | 5 | int isalnum(int c); 6 | int isalpha(int c); 7 | int islower(int c); 8 | int isupper(int c); 9 | int isdigit(int c); 10 | int isxdigit(int c); 11 | int iscntrl(int c); 12 | int isgraph(int c); 13 | int isspace(int c); 14 | int isblank(int c); 15 | int isprint(int c); 16 | int ispunct(int c); 17 | int tolower(int c); 18 | int toupper(int c); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /libc/include/qbe/errno.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | #ifndef _ERRNO_H 3 | #define _ERRNO_H 4 | 5 | extern int errno; 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /libc/include/qbe/signal.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | #ifndef _SIGNAL_H 3 | #define _SIGNAL_H 4 | 5 | void ( *signal(int signum, void (*handler)(int)) ) (int); 6 | int raise(int sig); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /libc/include/signal.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | #ifndef _SIGNAL_H 3 | #define _SIGNAL_H 4 | 5 | #include 6 | 7 | void ( *signal(int signum, void (*handler)(int)) ) (int); 8 | int raise(int sig); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /libc/include/stdarg.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | #ifndef _STDARG_H 3 | #define _STDARG_H 4 | 5 | #define va_list __builtin_va_list 6 | #define va_start(ap, last) __builtin_va_start((ap), (last)) 7 | #define va_end(ap) __builtin_va_end((ap)) 8 | #define va_copy(to, from) __builtin_va_copy((to), (from)) 9 | #define va_arg(to, type) __builtin_va_arg((to), (type)) 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /libc/include/stdbool.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | #ifndef _STDBOOL_H 3 | #define _STDBOOL_H 4 | 5 | #define bool _Bool 6 | #define true ((bool) 1) 7 | #define false ((bool) 0) 8 | #define __bool_true_false_are_defined 1 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /libc/include/stddef.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | #ifndef _STDDEF_H 3 | #define _STDDEF_H 4 | 5 | #include 6 | 7 | #ifndef NULL 8 | #define NULL ((void *) 0) 9 | #endif 10 | 11 | #define offsetof(st, m) ((size_t)&(((st *)0)->m)) 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /libc/include/stdint.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | #ifndef _STDINT_H_ 3 | #define _STDINT_H_ 4 | 5 | #include 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /libc/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 | -------------------------------------------------------------------------------- /libc/include/z80/assert.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | #ifndef _ASSERT_H 3 | #define _ASSERT_H 4 | 5 | #ifndef NDEBUG 6 | #define assert(exp) __assert(exp, #exp, __FILE__, __LINE__) 7 | #endif 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /libc/include/z80/ctype.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | #ifndef _CTYPE_H 3 | #define _CTYPE_H 4 | 5 | int isalnum(int c); 6 | int isalpha(int c); 7 | int islower(int c); 8 | int isupper(int c); 9 | int isdigit(int c); 10 | int isxdigit(int c); 11 | int iscntrl(int c); 12 | int isgraph(int c); 13 | int isspace(int c); 14 | int isblank(int c); 15 | int isprint(int c); 16 | int ispunct(int c); 17 | int tolower(int c); 18 | int toupper(int c); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /libc/include/z80/errno.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | #ifndef _ERRNO_H 3 | #define _ERRNO_H 4 | 5 | extern int errno; 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /libc/include/z80/signal.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | #ifndef _SIGNAL_H 3 | #define _SIGNAL_H 4 | 5 | void ( *signal(int signum, void (*handler)(int)) ) (int); 6 | int raise(int sig); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /libc/src/assert.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | void __assert(char *exp, char *file, long line) 8 | { 9 | fprintf(stderr, "%s:%ld: assertion failed '%s'\n", file, line, exp); 10 | abort(); 11 | } 12 | -------------------------------------------------------------------------------- /libc/src/atexit.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #include 4 | #include 5 | #undef atexit 6 | 7 | extern void (*_exitf[_ATEXIT_MAX])(void); 8 | extern unsigned _exitn; 9 | 10 | int 11 | atexit(void (*fun)(void)) 12 | { 13 | if (_exitn == _ATEXIT_MAX) { 14 | errno = ENOMEN; 15 | return -1; 16 | } 17 | _exitf[_exitn++] = fun; 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /libc/src/atoi.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #include 4 | #include 5 | #undef atoi 6 | 7 | int 8 | atoi(const char *s) 9 | { 10 | int n, sign = -1; 11 | 12 | while(isspace(*s)) 13 | ++s; 14 | 15 | switch(*s) { 16 | case '-': 17 | sign = 1; 18 | case '+': 19 | ++s; 20 | } 21 | 22 | /* Compute n as a negative number to avoid overflow on INT_MIN */ 23 | for (n = 0; isdigit(*s); ++s) 24 | n = 10*n - (*s - '0'); 25 | 26 | return sign * n; 27 | } 28 | 29 | -------------------------------------------------------------------------------- /libc/src/calloc.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #include 4 | #include 5 | 6 | void * 7 | calloc(size_t nmemb, size_t size) 8 | { 9 | size_t nbytes; 10 | void *mem; 11 | 12 | if (!nmemb || !size || nmemb > (size_t)-1/size) 13 | return NULL; 14 | 15 | nbytes = nmemb * size; 16 | if ((mem = malloc(nbytes)) == NULL) 17 | return NULL; 18 | return memset(mem, 0, nbytes); 19 | } 20 | -------------------------------------------------------------------------------- /libc/src/ctype.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #define __USE_MACROS 4 | #include 5 | #undef ctype 6 | 7 | unsigned char __ctype[255] = { 8 | _C,_C,_C,_C,_C,_C,_C,_C, /* 0-7 */ 9 | _C,_C|_S,_C|_S,_C|_S,_C|_S,_C|_S,_C,_C, /* 8-15 */ 10 | _C,_C,_C,_C,_C,_C,_C,_C, /* 16-23 */ 11 | _C,_C,_C,_C,_C,_C,_C,_C, /* 24-31 */ 12 | _S|_SP,_P,_P,_P,_P,_P,_P,_P, /* 32-39 */ 13 | _P,_P,_P,_P,_P,_P,_P,_P, /* 40-47 */ 14 | _D,_D,_D,_D,_D,_D,_D,_D, /* 48-55 */ 15 | _D,_D,_P,_P,_P,_P,_P,_P, /* 56-63 */ 16 | _P,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U, /* 64-71 */ 17 | _U,_U,_U,_U,_U,_U,_U,_U, /* 72-79 */ 18 | _U,_U,_U,_U,_U,_U,_U,_U, /* 80-87 */ 19 | _U,_U,_U,_P,_P,_P,_P,_P, /* 88-95 */ 20 | _P,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L, /* 96-103 */ 21 | _L,_L,_L,_L,_L,_L,_L,_L, /* 104-111 */ 22 | _L,_L,_L,_L,_L,_L,_L,_L, /* 112-119 */ 23 | _L,_L,_L,_P,_P,_P,_P,_C, /* 120-127 */ 24 | }; 25 | -------------------------------------------------------------------------------- /libc/src/exit.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #include 4 | #undef exit 5 | 6 | void (*_exitf[_ATEXIT_MAX])(void); 7 | unsigned _exitn; 8 | 9 | void 10 | exit(int status) 11 | { 12 | while (_exitn > 0) 13 | (*_exitf[--_exitn])(); 14 | _Exit(status); 15 | } 16 | -------------------------------------------------------------------------------- /libc/src/fprintf.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #include 4 | #include 5 | #undef fprintf 6 | 7 | int 8 | fprintf(FILE * restrict fp, const char * restrict fmt, ...) 9 | { 10 | va_list va; 11 | int cnt; 12 | 13 | va_start(va, fmt); 14 | cnt = vfprintf(fp, fmt, va); 15 | va_end(va); 16 | return cnt; 17 | } 18 | -------------------------------------------------------------------------------- /libc/src/isalnum.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #define __USE_MACROS 4 | #include 5 | #undef isalnum 6 | 7 | int 8 | isalnum(int c) 9 | { 10 | return __ctype[(unsigned char) c] & (_U|_L|_D); 11 | } 12 | -------------------------------------------------------------------------------- /libc/src/isalpha.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #define __USE_MACROS 4 | #include 5 | #undef isalpha 6 | 7 | int 8 | isalpha(int c) 9 | { 10 | return __ctype[(unsigned char) c] & (_U|_L); 11 | } 12 | -------------------------------------------------------------------------------- /libc/src/isascii.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #define __USE_MACROS 4 | #include 5 | #undef isascii 6 | 7 | int 8 | isascii(int c) 9 | { 10 | return c <= 0x7f; 11 | } 12 | -------------------------------------------------------------------------------- /libc/src/isblank.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | int 4 | isblank(int c) 5 | { 6 | return (c == ' ') || (c == '\t'); 7 | } 8 | -------------------------------------------------------------------------------- /libc/src/iscntrl.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #define __USE_MACROS 4 | #include 5 | #undef iscntrl 6 | 7 | int 8 | iscntrl(int c) 9 | { 10 | return __ctype[(unsigned char) c] & (_C); 11 | } 12 | -------------------------------------------------------------------------------- /libc/src/isdigit.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #define __USE_MACROS 4 | #include 5 | #undef isdigit 6 | 7 | int 8 | isdigit(int c) 9 | { 10 | return __ctype[(unsigned char) c] & (_D); 11 | } 12 | -------------------------------------------------------------------------------- /libc/src/isgraph.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #define __USE_MACROS 4 | #include 5 | #undef isgraph 6 | 7 | int 8 | isgraph(int c) 9 | { 10 | return __ctype[(unsigned char) c] & (_P|_U|_L|_D); 11 | } 12 | -------------------------------------------------------------------------------- /libc/src/islower.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #define __USE_MACROS 4 | #include 5 | #undef islower 6 | 7 | int 8 | islower(int c) 9 | { 10 | return __ctype[(unsigned char) c] & _L; 11 | } 12 | -------------------------------------------------------------------------------- /libc/src/isprint.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #define __USE_MACROS 4 | #include 5 | #undef isprint 6 | 7 | int 8 | isprint(int c) 9 | { 10 | return __ctype[(unsigned char) c] & (_P|_U|_L|_D|_SP); 11 | } 12 | -------------------------------------------------------------------------------- /libc/src/ispunct.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #define __USE_MACROS 4 | #include 5 | #undef ispunct 6 | 7 | int 8 | ispunct(int c) 9 | { 10 | return __ctype[(unsigned char) c] & (_P); 11 | } 12 | -------------------------------------------------------------------------------- /libc/src/isspace.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #define __USE_MACROS 4 | #include 5 | #undef isspace 6 | 7 | int 8 | isspace(int c) 9 | { 10 | return __ctype[(unsigned char) c] & _S; 11 | } 12 | -------------------------------------------------------------------------------- /libc/src/isupper.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #define __USE_MACROS 4 | #include 5 | #undef isupper 6 | 7 | int 8 | isupper(int c) 9 | { 10 | return __ctype[(unsigned char) c] & _U; 11 | } 12 | -------------------------------------------------------------------------------- /libc/src/isxdigit.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #define __USE_MACROS 4 | #include 5 | #undef isxdigit 6 | 7 | int 8 | isxdigit(int c) 9 | { 10 | return __ctype[(unsigned char) c] & (_D|_X); 11 | } 12 | -------------------------------------------------------------------------------- /libc/src/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 | -------------------------------------------------------------------------------- /libc/src/malloc.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #include 4 | 5 | /* minimum amount of required units */ 6 | #define NALLOC 10000 7 | 8 | typedef union header Header; 9 | union header { 10 | struct hdr { 11 | Header *next; 12 | size_t size; 13 | } h; 14 | /* most restrictive type fixes the union size for alignment */ 15 | _ALIGNTYPE most; 16 | }; 17 | 18 | extern void *_prevchunk(Header *hp); 19 | -------------------------------------------------------------------------------- /libc/src/memchr.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #include 4 | #undef memchr 5 | 6 | void * 7 | memchr(const void *s, int c, size_t n) 8 | { 9 | unsigned char *bp = (char *) s; 10 | 11 | while (n > 0 && *bp++ != c) 12 | --n; 13 | return (n == 0) ? NULL : bp-1; 14 | } 15 | -------------------------------------------------------------------------------- /libc/src/memcmp.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #include 4 | #undef memcmp 5 | 6 | int 7 | memcmp(const void *s1, const void *s2, size_t n) 8 | { 9 | char *s = (char *) s1, *t = (char *) s2; 10 | 11 | while (n > 0 && *s == *t) 12 | --n, ++s, ++t; 13 | return n ? (*s - *t) : 0; 14 | } 15 | -------------------------------------------------------------------------------- /libc/src/memcpy.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #include 4 | #undef memcpy 5 | 6 | void * 7 | memcpy(void * restrict dst, const void * restrict src, size_t n) 8 | { 9 | char *s1 = dst; 10 | const char *s2 = src; 11 | 12 | while (n-- > 0) 13 | *s1++ = *s2++; 14 | return dst; 15 | } 16 | -------------------------------------------------------------------------------- /libc/src/memmove.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #include 4 | #undef memmove 5 | 6 | void * 7 | memmove(void *dst, const void *src, size_t n) 8 | { 9 | char *d = dst, *s = (char *) src; 10 | 11 | if (d < s) { 12 | while (n-- > 0) 13 | *d++ = *s++; 14 | } else { 15 | s += n-1, d += n-1; 16 | while (n-- > 0) 17 | *d-- = *s--; 18 | } 19 | return dst; 20 | } 21 | -------------------------------------------------------------------------------- /libc/src/memset.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #include 4 | #undef memset 5 | 6 | void * 7 | memset(void *s, int c, size_t n) 8 | { 9 | char *m = s; 10 | 11 | while (n-- > 0) 12 | *m++ = c; 13 | return s; 14 | } 15 | -------------------------------------------------------------------------------- /libc/src/printf.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #include 4 | #include 5 | #undef printf 6 | 7 | int 8 | printf(const char * restrict fmt, ...) 9 | { 10 | int cnt; 11 | va_list va; 12 | 13 | va_start(va, fmt); 14 | cnt = vfprintf(stdin, fmt, va); 15 | va_end(va); 16 | return cnt; 17 | } 18 | -------------------------------------------------------------------------------- /libc/src/rand.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #include 4 | #undef rand 5 | 6 | static int next; 7 | 8 | void 9 | srand(unsigned seed) 10 | { 11 | next = seed; 12 | } 13 | 14 | int 15 | rand(void) /* RAND_MAX assumed to be 32767. */ 16 | { 17 | next = next * 1103515245 + 12345; 18 | return (unsigned)(next/65536) % 32768; 19 | } 20 | -------------------------------------------------------------------------------- /libc/src/setlocale.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #include 4 | #include 5 | #undef setlocale 6 | 7 | char * 8 | setlocale(int category, const char *locale) 9 | { 10 | if (category > LC_TIME || category < LC_ALL) 11 | return NULL; 12 | if (!locale || 13 | locale[0] == '\0' || 14 | locale[0] == 'C' && locale[1] == '\0') { 15 | return "C"; 16 | } 17 | return NULL; 18 | } 19 | -------------------------------------------------------------------------------- /libc/src/strcat.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #include 4 | #undef strcat 5 | 6 | char * 7 | strcat(char * restrict dst, const char * restrict src) 8 | { 9 | char *ret = dst; 10 | 11 | while (*dst) 12 | ++dst; 13 | while (*dst++ = *src++) 14 | /* nothing */; 15 | return ret; 16 | } 17 | -------------------------------------------------------------------------------- /libc/src/strchr.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #include 4 | #undef strchr 5 | 6 | char * 7 | strchr(const char *s, int c) 8 | { 9 | while (*s && *s != c) 10 | ++s; 11 | return (*s == c) ? (char *)s : NULL; 12 | } 13 | -------------------------------------------------------------------------------- /libc/src/strcmp.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #include 4 | #undef strcmp 5 | 6 | int 7 | strcmp(const char *s1, const char *s2) 8 | { 9 | while (*s1 && *s2 && *s1 == *s2) 10 | ++s1, ++s2; 11 | return *(unsigned char *)s1 - *(unsigned char *)s2; 12 | } 13 | -------------------------------------------------------------------------------- /libc/src/strcoll.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #include 4 | #undef strcoll 5 | 6 | int 7 | strcoll(const char *s1, const char *s2) 8 | { 9 | while (*s1 && *s2 && *s1 == *s2) 10 | ++s1, ++s2; 11 | return *(unsigned char *) s1 - *(unsigned char *) s2; 12 | } 13 | -------------------------------------------------------------------------------- /libc/src/strcpy.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #include 4 | #undef strcpy 5 | 6 | char * 7 | strcpy(char * restrict dst, const char * restrict src) 8 | { 9 | char *ret = dst; 10 | 11 | while (*dst++ = *src++) 12 | /* nothing */; 13 | return ret; 14 | } 15 | -------------------------------------------------------------------------------- /libc/src/strcspn.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #include 4 | #undef strcspn 5 | 6 | size_t 7 | strcspn(const char *s1, const char *s2) 8 | { 9 | size_t n; 10 | int c; 11 | const char *p; 12 | 13 | for (n = 0; c = *s1++; ++n) { 14 | for (p = s2; *p && *p != c; ++p) 15 | /* nothing */; 16 | if (*p == c) 17 | break; 18 | } 19 | return n; 20 | } 21 | -------------------------------------------------------------------------------- /libc/src/strlen.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #include 4 | #undef strlen 5 | 6 | size_t 7 | strlen(const char *s) 8 | { 9 | const char *t; 10 | 11 | for (t = s; *t; ++t) 12 | /* nothing */; 13 | return t - s; 14 | } 15 | -------------------------------------------------------------------------------- /libc/src/strncat.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #include 4 | #undef strncat 5 | 6 | char * 7 | strncat(char * restrict dst, const char * restrict src, size_t n) 8 | { 9 | char *ret = dst; 10 | 11 | while (*dst) 12 | ++dst; 13 | while (n-- > 0 && *src) 14 | *dst++ = *src++; 15 | *dst = '\0'; 16 | return ret; 17 | } 18 | -------------------------------------------------------------------------------- /libc/src/strncmp.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #include 4 | #undef strncmp 5 | 6 | int 7 | strncmp(const char *s1, const char *s2, size_t n) 8 | { 9 | for (; n && *s1 && *s2 && *s1 == *s2; --n, ++s1, ++s2); 10 | /* nothing */; 11 | return n ? (*(unsigned char *)s1 - *(unsigned char *)s2) : 0; 12 | } 13 | -------------------------------------------------------------------------------- /libc/src/strncpy.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #include 4 | #undef strncpy 5 | 6 | char * 7 | strncpy(char * restrict dst, const char * restrict src, size_t n) 8 | { 9 | char *ret = dst; 10 | 11 | for (; n > 0 && *src; --n) 12 | *dst++ = *src++; 13 | while (n-- > 0) 14 | *dst++ = '\0'; 15 | return ret; 16 | } 17 | -------------------------------------------------------------------------------- /libc/src/strpbrk.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #include 4 | #undef strpbrk 5 | 6 | char * 7 | strpbrk(const char *s1, const char *s2) 8 | { 9 | int c; 10 | const char *p; 11 | 12 | for (; c = *s1; ++s1) { 13 | for (p = s2; *p && *p != c; ++p) 14 | /* nothing */; 15 | if (*p == c) 16 | return s1; 17 | } 18 | return NULL; 19 | } 20 | -------------------------------------------------------------------------------- /libc/src/strrchr.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #include 4 | #undef strrchr 5 | 6 | char * 7 | strrchr(const char *s, int c) 8 | { 9 | const char *t = s; 10 | 11 | while (*t) 12 | ++t; 13 | while (t > s && *t != c) 14 | --t; 15 | return (*t == c) ? (char *)t : NULL; 16 | } 17 | -------------------------------------------------------------------------------- /libc/src/strspn.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #include 4 | #undef strspn 5 | 6 | size_t 7 | strspn(const char *s1, const char *s2) 8 | { 9 | size_t n; 10 | int c; 11 | const char *p; 12 | 13 | for (n = 0; c = *s1++; ++n) { 14 | for (p = s2; *p && *p != c; ++p) 15 | /* nothing */; 16 | if (*p == '\0') 17 | break; 18 | } 19 | return n; 20 | } 21 | -------------------------------------------------------------------------------- /libc/src/strstr.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #include 4 | #undef strstr 5 | 6 | char * 7 | strstr(const char *s1, const char *s2) 8 | { 9 | const char *p, *q; 10 | int c; 11 | 12 | c = *s2++; 13 | if (c == '\0') 14 | return (char *) s1; 15 | 16 | while (*s1) { 17 | if (*s1 != c) { 18 | ++s1; 19 | } else { 20 | p = s1++; 21 | for (q = s2; *q && *s1 == *q; ++s1, ++q) 22 | /* nothing */; 23 | if (*q == '\0') 24 | return (char *) p; 25 | } 26 | } 27 | return NULL; 28 | } 29 | -------------------------------------------------------------------------------- /libc/src/strtok.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #include 4 | #undef strtok 5 | 6 | char * 7 | strtok(char * restrict s, const char * restrict delim) 8 | { 9 | static char *line; 10 | 11 | if (s) 12 | line = s; 13 | if (!s && !line) 14 | return NULL; 15 | 16 | s = line + strspn(line, delim); 17 | if (*s == '\0') 18 | return line = NULL; 19 | 20 | line = s + strcspn(s, delim); 21 | if (*line != '\0') 22 | *line++ = '\0'; 23 | else 24 | line = NULL; 25 | 26 | return s; 27 | } 28 | -------------------------------------------------------------------------------- /libc/src/strxfrm.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #include 4 | #undef strxfrm 5 | 6 | size_t 7 | strxfrm(char * restrict dst, const char * restrict src, size_t n) 8 | { 9 | size_t len = strlen(src); 10 | 11 | if (len < n) 12 | strcpy(dst, src); 13 | return len; 14 | } 15 | -------------------------------------------------------------------------------- /libc/src/sys/amd64-sysv-linux/Makefile: -------------------------------------------------------------------------------- 1 | # See LICENSE file for copyright and license details. 2 | .POSIX: 3 | 4 | include ../../../../config.mk 5 | 6 | SYSTEMINC = /dev/null 7 | include $(SYSTEMINC) 8 | SYSGENINC = /dev/null 9 | include $(SYSGENINC) 10 | 11 | GENASM = $(GENOBJ:.o=.s) 12 | OBJ = 13 | 14 | all: all.bootstrap 15 | all.start: $(SYSOBJ) 16 | 17 | clean: clean.bootstrap 18 | clean.start: 19 | rm -f *.o $(GENASM) system.mk sysgen.mk 20 | 21 | all.bootstrap clean.bootstrap: system.mk sysgen.mk 22 | $(MAKE) -e SYSTEMINC=system.mk SYSGENINC=sysgen.mk \ 23 | $(@:%.bootstrap=%.start) 24 | 25 | system.mk: Makefile syscall.lst 26 | printf '%s ' 'SYSOBJ =' \ 27 | "$$(awk '/^#/{next}{printf "%s.o ", $$2}' syscall.lst)" \ 28 | $(OBJ) \ 29 | > $@ 30 | 31 | sysgen.mk: syscall.lst 32 | printf '%s ' 'GENOBJ =' \ 33 | "$$(awk '/^#/{next}{printf "%s.o ", $$2}' syscall.lst)" \ 34 | > $@ 35 | 36 | $(GENASM): syscall.lst 37 | awk -f syscall.awk < syscall.lst 38 | -------------------------------------------------------------------------------- /libc/src/sys/amd64-sysv-linux/syscall.awk: -------------------------------------------------------------------------------- 1 | # This job is very easy because app and kernel ABI are identical 2 | # until the 4th parameter, so we only have to set the syscall 3 | # number in rax 4 | 5 | /^#/ {next} 6 | {name=$2 ".s" 7 | printf ".global %s\n" \ 8 | "%s:\n" \ 9 | "\tmovq\t$%d,%%rax\n" \ 10 | "\tsyscall\n" \ 11 | "\tret\n", $2, $2, $1 > name 12 | close(name)} 13 | -------------------------------------------------------------------------------- /libc/src/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 | -------------------------------------------------------------------------------- /libc/src/sys/i386-sysv-linux/Makefile: -------------------------------------------------------------------------------- 1 | # See LICENSE file for copyright and license details. 2 | .POSIX: 3 | 4 | include ../../../../config.mk 5 | 6 | SYSTEMINC = /dev/null 7 | include $(SYSTEMINC) 8 | SYSGENINC = /dev/null 9 | include $(SYSGENINC) 10 | 11 | GENASM = $(GENOBJ:.o=.s) 12 | OBJ = 13 | 14 | all: all.bootstrap 15 | all.start: $(SYSOBJ) 16 | 17 | clean: clean.bootstrap 18 | clean.start: 19 | rm -f *.o $(GENASM) system.mk sysgen.mk 20 | 21 | all.bootstrap clean.bootstrap: system.mk sysgen.mk 22 | $(MAKE) -e SYSTEMINC=system.mk SYSGENINC=sysgen.mk \ 23 | $(@:%.bootstrap=%.start) 24 | 25 | system.mk: Makefile syscall.lst 26 | printf '%s ' 'SYSOBJ =' \ 27 | "$$(awk '/^#/{next}{printf "%s.o ", $$2}' syscall.lst)" \ 28 | $(OBJ) \ 29 | > $@ 30 | 31 | sysgen.mk: syscall.lst 32 | printf '%s ' 'GENOBJ =' \ 33 | "$$(awk '/^#/{next}{printf "%s.o ", $$2}' syscall.lst)" \ 34 | > $@ 35 | 36 | $(GENASM): syscall.lst 37 | awk -f syscall.awk < syscall.lst 38 | -------------------------------------------------------------------------------- /libc/src/sys/i386-sysv-linux/syscall.lst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/8l/scc/d28807b385d6ab846793cc497213ac0cdd430224/libc/src/sys/i386-sysv-linux/syscall.lst -------------------------------------------------------------------------------- /libc/src/sys/qbe-linux/Makefile: -------------------------------------------------------------------------------- 1 | # See LICENSE file for copyright and license details. 2 | .POSIX: 3 | 4 | include ../../../../config.mk 5 | 6 | SYSTEMINC = /dev/null 7 | include $(SYSTEMINC) 8 | SYSGENINC = /dev/null 9 | include $(SYSGENINC) 10 | 11 | GENASM = $(GENOBJ:.o=.s) 12 | OBJ = 13 | 14 | all: all.bootstrap 15 | all.start: $(SYSOBJ) 16 | 17 | clean: clean.bootstrap 18 | clean.start: 19 | rm -f *.o $(GENASM) system.mk sysgen.mk 20 | 21 | all.bootstrap clean.bootstrap: system.mk sysgen.mk 22 | $(MAKE) -e SYSTEMINC=system.mk SYSGENINC=sysgen.mk \ 23 | $(@:%.bootstrap=%.start) 24 | 25 | system.mk: Makefile syscall.lst 26 | printf '%s ' 'SYSOBJ =' \ 27 | "$$(awk '/^#/{next}{printf "%s.o ", $$2}' syscall.lst)" \ 28 | $(OBJ) \ 29 | > $@ 30 | 31 | sysgen.mk: syscall.lst 32 | printf '%s ' 'GENOBJ =' \ 33 | "$$(awk '/^#/{next}{printf "%s.o ", $$2}' syscall.lst)" \ 34 | > $@ 35 | 36 | $(GENASM): syscall.lst 37 | awk -f syscall.awk < syscall.lst 38 | -------------------------------------------------------------------------------- /libc/src/sys/qbe-linux/syscall.awk: -------------------------------------------------------------------------------- 1 | # This job is very easy because app and kernel ABI are identical 2 | # until the 4th parameter, so we only have to set the syscall 3 | # number in rax 4 | 5 | /^#/ {next} 6 | {name=$2 ".s" 7 | printf ".global %s\n" \ 8 | "%s:\n" \ 9 | "\tmovq\t$%d,%%rax\n" \ 10 | "\tsyscall\n" \ 11 | "\tret\n", $2, $2, $1 > name 12 | close(name)} 13 | -------------------------------------------------------------------------------- /libc/src/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 | -------------------------------------------------------------------------------- /libc/src/sys/z80-linux/Makefile: -------------------------------------------------------------------------------- 1 | # See LICENSE file for copyright and license details. 2 | .POSIX: 3 | 4 | include ../../../../config.mk 5 | 6 | SYSTEMINC = /dev/null 7 | include $(SYSTEMINC) 8 | SYSGENINC = /dev/null 9 | include $(SYSGENINC) 10 | 11 | GENASM = $(GENOBJ:.o=.s) 12 | OBJ = 13 | 14 | all: all.bootstrap 15 | all.start: $(SYSOBJ) 16 | 17 | clean: clean.bootstrap 18 | clean.start: 19 | rm -f *.o $(GENASM) system.mk sysgen.mk 20 | 21 | all.bootstrap clean.bootstrap: system.mk sysgen.mk 22 | $(MAKE) -e SYSTEMINC=system.mk SYSGENINC=sysgen.mk \ 23 | $(@:%.bootstrap=%.start) 24 | 25 | system.mk: Makefile syscall.lst 26 | printf '%s ' 'SYSOBJ =' \ 27 | "$$(awk '/^#/{next}{printf "%s.o ", $$2}' syscall.lst)" \ 28 | $(OBJ) \ 29 | > $@ 30 | 31 | sysgen.mk: syscall.lst 32 | printf '%s ' 'GENOBJ =' \ 33 | "$$(awk '/^#/{next}{printf "%s.o ", $$2}' syscall.lst)" \ 34 | > $@ 35 | 36 | $(GENASM): syscall.lst 37 | awk -f syscall.awk < syscall.lst 38 | -------------------------------------------------------------------------------- /libc/src/sys/z80-linux/syscall.lst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/8l/scc/d28807b385d6ab846793cc497213ac0cdd430224/libc/src/sys/z80-linux/syscall.lst -------------------------------------------------------------------------------- /libc/src/syscall.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | extern void *_brk(void *addr); 4 | extern int _open(char *path, int flags, int perm); 5 | extern int _close(int fd); 6 | extern int _read(int fd, void *buf, size_t n); 7 | extern int _write(int fd, void *buf, size_t n); 8 | extern int _lseek(int fd, long off, int whence); 9 | extern void _Exit(int status); 10 | extern int raise(int sig); 11 | extern void (*signal(int sig, void (*func)(int)))(int); 12 | -------------------------------------------------------------------------------- /libc/src/tolower.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #define __USE_MACROS 4 | #include 5 | #undef tolower 6 | 7 | int 8 | tolower(int c) 9 | { 10 | return (isupper(c)) ? c | 0x20 : c; 11 | } 12 | -------------------------------------------------------------------------------- /libc/src/toupper.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #define __USE_MACROS 4 | #include 5 | #undef toupper 6 | 7 | int 8 | toupper(int c) 9 | { 10 | return (islower(c)) ? c & ~0x20 : c; 11 | } 12 | -------------------------------------------------------------------------------- /scc: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | PATH="$PWD/cc1:$PWD/cc2" 4 | 5 | cc1 < "$1" | cc2 6 | -------------------------------------------------------------------------------- /tests/0001-sanity.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/0002-expr.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | return 3-3; 6 | } 7 | -------------------------------------------------------------------------------- /tests/0003-local.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | int 4 | main() 5 | { 6 | int x; 7 | 8 | x = 4; 9 | return x - 4; 10 | } 11 | -------------------------------------------------------------------------------- /tests/0004-pointer.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | int 4 | main() 5 | { 6 | int x; 7 | int *p; 8 | 9 | x = 4; 10 | p = &x; 11 | *p = 0; 12 | 13 | return *p; 14 | } 15 | -------------------------------------------------------------------------------- /tests/0005-ifstmt.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | int x; 6 | int *p; 7 | int **pp; 8 | 9 | x = 0; 10 | p = &x; 11 | pp = &p; 12 | 13 | if(*p) 14 | return 1; 15 | if(**pp) 16 | return 1; 17 | else 18 | **pp = 1; 19 | 20 | if(x) 21 | return 0; 22 | else 23 | return 1; 24 | } 25 | -------------------------------------------------------------------------------- /tests/0006-whilestmt.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | int x; 6 | 7 | x = 50; 8 | while (x) 9 | x = x - 1; 10 | return x; 11 | } 12 | -------------------------------------------------------------------------------- /tests/0007-forstmt.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | int x; 6 | 7 | x = 1; 8 | for(x = 10; x; x = x - 1) 9 | ; 10 | if(x) 11 | return 1; 12 | x = 10; 13 | for (;x;) 14 | x = x - 1; 15 | return x; 16 | } 17 | -------------------------------------------------------------------------------- /tests/0008-dowhilestmt.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | int x; 6 | 7 | x = 50; 8 | do 9 | x = x - 1; 10 | while(x); 11 | return x; 12 | } 13 | -------------------------------------------------------------------------------- /tests/0009-expr.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | int x; 6 | 7 | x = 1; 8 | x = x * 10; 9 | x = x / 2; 10 | x = x % 3; 11 | return x - 2; 12 | } 13 | -------------------------------------------------------------------------------- /tests/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/0011-assign.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | int x; 6 | int y; 7 | x = y = 0; 8 | return x; 9 | } 10 | -------------------------------------------------------------------------------- /tests/0012-expr.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | return (2 + 2) * 2 - 8; 6 | } 7 | -------------------------------------------------------------------------------- /tests/0013-addridx.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | int x; 6 | int *p; 7 | 8 | x = 0; 9 | p = &x; 10 | return p[0]; 11 | } 12 | -------------------------------------------------------------------------------- /tests/0014-assignidx.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | int x; 6 | int *p; 7 | 8 | x = 1; 9 | p = &x; 10 | p[0] = 0; 11 | return x; 12 | } 13 | -------------------------------------------------------------------------------- /tests/0015-localarray.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | int arr[2]; 6 | 7 | arr[0] = 1; 8 | arr[1] = 2; 9 | 10 | return arr[0] + arr[1] - 3; 11 | } 12 | -------------------------------------------------------------------------------- /tests/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/0017-struct.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | int 4 | main() 5 | { 6 | struct { int x; int y; } s; 7 | 8 | s.x = 3; 9 | s.y = 5; 10 | return s.y - s.x - 2; 11 | } 12 | -------------------------------------------------------------------------------- /tests/0018-structptr.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | int 4 | main() 5 | { 6 | 7 | struct S { int x; int y; } s; 8 | struct S *p; 9 | 10 | p = &s; 11 | s.x = 1; 12 | p->y = 2; 13 | return p->y + p->x - 3; 14 | } 15 | 16 | -------------------------------------------------------------------------------- /tests/0019-selfrefstruct.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | struct S { struct S *p; int x; } s; 6 | 7 | s.x = 0; 8 | s.p = &s; 9 | return s.p->p->p->p->p->x; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /tests/0020-ptrptr.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | int x, *p, **pp; 6 | 7 | x = 0; 8 | p = &x; 9 | pp = &p; 10 | return **pp; 11 | } 12 | -------------------------------------------------------------------------------- /tests/0021-intfunc.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | foo(int a, int b) 4 | { 5 | return 2 + a - b; 6 | } 7 | 8 | int 9 | main() 10 | { 11 | return foo(1, 3); 12 | } 13 | 14 | -------------------------------------------------------------------------------- /tests/0022-typedef.c: -------------------------------------------------------------------------------- 1 | 2 | typedef int x; 3 | 4 | int 5 | main() 6 | { 7 | x v; 8 | v = 0; 9 | return v; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /tests/0023-global.c: -------------------------------------------------------------------------------- 1 | 2 | int x; 3 | 4 | int 5 | main() 6 | { 7 | x = 0; 8 | return x; 9 | } 10 | 11 | -------------------------------------------------------------------------------- /tests/0024-typedefstruct.c: -------------------------------------------------------------------------------- 1 | 2 | typedef struct { int x; int y; } s; 3 | 4 | s v; 5 | 6 | int 7 | main() 8 | { 9 | v.x = 1; 10 | v.y = 2; 11 | return 3 - v.x - v.y; 12 | } 13 | 14 | -------------------------------------------------------------------------------- /tests/0025-string.c: -------------------------------------------------------------------------------- 1 | 2 | int strlen(char *); 3 | 4 | int 5 | main() 6 | { 7 | char *p; 8 | 9 | p = "hello"; 10 | return strlen(p) - 5; 11 | } 12 | -------------------------------------------------------------------------------- /tests/0026-implicitret.c: -------------------------------------------------------------------------------- 1 | 2 | main() 3 | { 4 | return 0; 5 | } 6 | 7 | -------------------------------------------------------------------------------- /tests/0027-charval.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | char *p; 6 | 7 | p = "hello"; 8 | return p[0] - 104; 9 | } 10 | -------------------------------------------------------------------------------- /tests/0028-bor.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | int x; 6 | 7 | x = 1; 8 | x = x | 4; 9 | return x - 5; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /tests/0029-band.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | int x; 6 | 7 | x = 1; 8 | x = x & 3; 9 | return x - 1; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /tests/0030-bxor.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | int x; 6 | 7 | x = 1; 8 | x = x ^ 3; 9 | return x - 2; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /tests/0031-relop.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | f() 4 | { 5 | return 100; 6 | } 7 | 8 | int 9 | main() 10 | { 11 | if (f() > 1000) 12 | return 1; 13 | if (f() >= 1000) 14 | return 1; 15 | if (1000 < f()) 16 | return 1; 17 | if (1000 <= f()) 18 | return 1; 19 | if (1000 == f()) 20 | return 1; 21 | if (100 != f()) 22 | return 1; 23 | return 0; 24 | } 25 | 26 | -------------------------------------------------------------------------------- /tests/0032-indec.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | zero() 4 | { 5 | return 0; 6 | } 7 | 8 | int 9 | one() 10 | { 11 | return 1; 12 | } 13 | 14 | int 15 | main() 16 | { 17 | int x; 18 | int y; 19 | 20 | x = zero(); 21 | y = ++x; 22 | if (x != 1) 23 | return 1; 24 | if (y != 1) 25 | return 1; 26 | 27 | x = one(); 28 | y = --x; 29 | if (x != 0) 30 | return 1; 31 | if (y != 0) 32 | return 1; 33 | 34 | x = zero(); 35 | y = x++; 36 | if (x != 1) 37 | return 1; 38 | if (y != 0) 39 | return 1; 40 | 41 | x = one(); 42 | y = x--; 43 | if (x != 0) 44 | return 1; 45 | if (y != 1) 46 | return 1; 47 | 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /tests/0033-ptrindec.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | int 4 | main() 5 | { 6 | int arr[2]; 7 | int *p; 8 | 9 | arr[0] = 2; 10 | arr[1] = 3; 11 | p = &arr[0]; 12 | if(*(p++) != 2) 13 | return 1; 14 | if(*(p++) != 3) 15 | return 2; 16 | 17 | p = &arr[1]; 18 | if(*(p--) != 3) 19 | return 1; 20 | if(*(p--) != 2) 21 | return 2; 22 | 23 | p = &arr[0]; 24 | if(*(++p) != 3) 25 | return 1; 26 | 27 | p = &arr[1]; 28 | if(*(--p) != 2) 29 | return 1; 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /tests/0034-logandor.c: -------------------------------------------------------------------------------- 1 | 2 | int g; 3 | 4 | int 5 | effect() 6 | { 7 | g = 1; 8 | return 1; 9 | } 10 | 11 | int 12 | main() 13 | { 14 | int x; 15 | 16 | g = 0; 17 | x = 0; 18 | if(x && effect()) 19 | return 1; 20 | if(g) 21 | return 2; 22 | x = 1; 23 | if(x && effect()) { 24 | if(g != 1) 25 | return 3; 26 | } else { 27 | return 4; 28 | } 29 | g = 0; 30 | x = 1; 31 | if(x || effect()) { 32 | if(g) 33 | return 5; 34 | } else { 35 | return 6; 36 | } 37 | x = 0; 38 | if(x || effect()) { 39 | if(g != 1) 40 | return 7; 41 | } else { 42 | return 8; 43 | } 44 | return 0; 45 | } 46 | 47 | -------------------------------------------------------------------------------- /tests/0035-breakcont.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | int x; 6 | 7 | x = 0; 8 | while(1) 9 | break; 10 | while(1) { 11 | if (x == 5) { 12 | break; 13 | } 14 | x = x + 1; 15 | continue; 16 | } 17 | for (;;) { 18 | if (x == 10) { 19 | break; 20 | } 21 | x = x + 1; 22 | continue; 23 | } 24 | do { 25 | if (x == 15) { 26 | break; 27 | } 28 | x = x + 1; 29 | continue; 30 | } while(1); 31 | return x - 15; 32 | } 33 | 34 | -------------------------------------------------------------------------------- /tests/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/0037-assignop.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | int x; 6 | 7 | x = 0; 8 | x += 2; 9 | x += 2; 10 | if (x != 4) 11 | return 1; 12 | x -= 3; 13 | if (x != 1) 14 | return 2; 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /tests/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/0039-sizeof.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int x; 5 | if((sizeof (int) - 4)) 6 | return 1; 7 | if((sizeof (&x) - 8)) 8 | return 1; 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/0040-cast.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | void *p; 6 | int x; 7 | 8 | x = 2; 9 | p = &x; 10 | 11 | if(*((int*)p) != 2) 12 | return 1; 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /tests/0041-queen.c: -------------------------------------------------------------------------------- 1 | 2 | int *calloc(int, int); 3 | 4 | int N; 5 | int *t; 6 | 7 | int 8 | chk(int x, int y) 9 | { 10 | int i; 11 | int r; 12 | 13 | for (r=i=0; i<8; i++) { 14 | r = r + t[x + 8*i]; 15 | r = r + t[i + 8*y]; 16 | if (x+i < 8 & y+i < 8) 17 | r = r + t[x+i + 8*(y+i)]; 18 | if (x+i < 8 & y-i >= 0) 19 | r = r + t[x+i + 8*(y-i)]; 20 | if (x-i >= 0 & y+i < 8) 21 | r = r + t[x-i + 8*(y+i)]; 22 | if (x-i >= 0 & y-i >= 0) 23 | r = r + t[x-i + 8*(y-i)]; 24 | } 25 | return r; 26 | } 27 | 28 | int 29 | go(int n, int x, int y) 30 | { 31 | if (n == 8) { 32 | N++; 33 | return 0; 34 | } 35 | for (; y<8; y++) { 36 | for (; x<8; x++) 37 | if (chk(x, y) == 0) { 38 | t[x + 8*y]++; 39 | go(n+1, x, y); 40 | t[x + 8*y]--; 41 | } 42 | x = 0; 43 | } 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/0042-prime.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() { 4 | int n; 5 | int t; 6 | int c; 7 | int p; 8 | 9 | c = 0; 10 | n = 2; 11 | while (n < 5000) { 12 | t = 2; 13 | p = 1; 14 | while (t*t <= n) { 15 | if (n % t == 0) 16 | p = 0; 17 | t++; 18 | } 19 | n++; 20 | if (p) 21 | c++; 22 | } 23 | if (c != 669) 24 | return 1; 25 | return 0; 26 | } 27 | 28 | -------------------------------------------------------------------------------- /tests/0043-union.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | int 5 | main() 6 | { 7 | union { int a; int b; } u; 8 | u.a = 1; 9 | u.b = 3; 10 | 11 | if (u.a != 3 || u.b != 3) 12 | return 1; 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /tests/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/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/0046-inits.c: -------------------------------------------------------------------------------- 1 | 2 | int x = 5; 3 | long y = 6; 4 | int *p = &x; 5 | 6 | int 7 | main() 8 | { 9 | if (x != 5) 10 | return 1; 11 | if (y != 6) 12 | return 2; 13 | if (*p != 5) 14 | return 3; 15 | return 0; 16 | } 17 | 18 | -------------------------------------------------------------------------------- /tests/0047-anonexport.c: -------------------------------------------------------------------------------- 1 | 2 | typedef struct { 3 | int a; 4 | union { 5 | int b1; 6 | int b2; 7 | }; 8 | struct { union { struct { int c; }; struct {}; }; }; 9 | struct {}; 10 | struct { 11 | int d; 12 | }; 13 | } s; 14 | 15 | int 16 | main() 17 | { 18 | s v; 19 | 20 | v.a = 1; 21 | v.b1 = 2; 22 | v.c = 3; 23 | v.d = 4; 24 | 25 | if (v.a != 1) 26 | return 1; 27 | if (v.b1 != 2 && v.b2 != 2) 28 | return 2; 29 | if (v.c != 3) 30 | return 3; 31 | if (v.d != 4) 32 | return 4; 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /tests/0048-inits.c: -------------------------------------------------------------------------------- 1 | 2 | struct { int a; int b; int c; } s = {1, 2, 3}; 3 | 4 | int 5 | main() 6 | { 7 | if (s.a != 1) 8 | return 1; 9 | if (s.b != 2) 10 | return 2; 11 | if (s.c != 3) 12 | return 3; 13 | 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /tests/0049-inits.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | struct S {int a; int b;}; 4 | struct S s = { .b = 2, .a = 1}; 5 | 6 | int 7 | main() 8 | { 9 | if(s.a != 1) 10 | return 1; 11 | if(s.b != 2) 12 | return 2; 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /tests/0050-inits.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | int x = 10; 4 | 5 | struct S {int a; int *p;}; 6 | struct S s = { .p = &x, .a = 1}; 7 | 8 | int 9 | main() 10 | { 11 | if(s.a != 1) 12 | return 1; 13 | if(*s.p != 10) 14 | return 2; 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /tests/0051-inits.c: -------------------------------------------------------------------------------- 1 | 2 | struct S1 { 3 | int a; 4 | int b; 5 | }; 6 | 7 | struct S2 { 8 | int a; 9 | int b; 10 | union { 11 | int c; 12 | int d; 13 | }; 14 | struct S1 s; 15 | }; 16 | 17 | struct S2 v = {1, 2, 3, {4, 5}}; 18 | 19 | int 20 | main() 21 | { 22 | if(v.a != 1) 23 | return 1; 24 | if(v.b != 2) 25 | return 2; 26 | if(v.c != 3 || v.d != 3) 27 | return 3; 28 | if(v.s.a != 4) 29 | return 4; 30 | if(v.s.b != 5) 31 | return 5; 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /tests/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/0053-struct.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | struct T { int x; }; 6 | { 7 | struct T s; 8 | s.x = 0; 9 | return s.x; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /tests/0054-struct.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | struct T { int x; } s1; 6 | s1.x = 1; 7 | { 8 | struct T { int y; } s2; 9 | s2.y = 1; 10 | if (s1.x - s2.y != 0) 11 | return 1; 12 | } 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /tests/0055-enum.c: -------------------------------------------------------------------------------- 1 | 2 | enum E { 3 | x, 4 | y, 5 | z, 6 | }; 7 | 8 | int 9 | main() 10 | { 11 | enum E e; 12 | 13 | if(x != 0) 14 | return 1; 15 | if(y != 1) 16 | return 2; 17 | if(z != 2) 18 | return 3; 19 | 20 | e = x; 21 | return e; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /tests/0056-enum.c: -------------------------------------------------------------------------------- 1 | 2 | enum E { 3 | x, 4 | y = 2, 5 | z, 6 | }; 7 | 8 | int 9 | main() 10 | { 11 | enum E e; 12 | 13 | if(x != 0) 14 | return 1; 15 | if(y != 2) 16 | return 2; 17 | if(z != 3) 18 | return 3; 19 | 20 | e = x; 21 | return e; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /tests/0057-duff.c: -------------------------------------------------------------------------------- 1 | 2 | int main() 3 | { 4 | int count, n; 5 | char *from, *to; 6 | char a[39], b[39]; 7 | 8 | for(n = 0; n < 39; n++) { 9 | a[n] = n; 10 | b[n] = 0; 11 | } 12 | from = a; 13 | to = b; 14 | count = 39; 15 | n = (count + 7) / 8; 16 | switch (count % 8) { 17 | case 0: do { *to++ = *from++; 18 | case 7: *to++ = *from++; 19 | case 6: *to++ = *from++; 20 | case 5: *to++ = *from++; 21 | case 4: *to++ = *from++; 22 | case 3: *to++ = *from++; 23 | case 2: *to++ = *from++; 24 | case 1: *to++ = *from++; 25 | } while (--n > 0); 26 | } 27 | for(n = 0; n < 39; n++) 28 | if(a[n] != b[n]) 29 | return 1; 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /tests/0058-bug.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | char a[16], b[16]; 6 | 7 | if(sizeof(a) != sizeof(b)) 8 | return 1; 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/0059-multistring.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | int main() 5 | { 6 | char * s; 7 | 8 | s = "abc" "def"; 9 | if(s[0] != 'a') return 1; 10 | if(s[1] != 'b') return 2; 11 | if(s[2] != 'c') return 3; 12 | if(s[3] != 'd') return 4; 13 | if(s[4] != 'e') return 5; 14 | if(s[5] != 'f') return 6; 15 | if(s[6] != 0) return 7; 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /tests/0060-charlit.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | if ('a' != 97) 6 | return 1; 7 | 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/0061-comments.c: -------------------------------------------------------------------------------- 1 | // line comment 2 | 3 | int 4 | main() 5 | { 6 | /* 7 | multiline 8 | comment 9 | */ 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/0062-include.c: -------------------------------------------------------------------------------- 1 | #include \ 2 | "0062-include.h" 3 | return 0; 4 | } 5 | -------------------------------------------------------------------------------- /tests/0062-include.h: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | -------------------------------------------------------------------------------- /tests/0063-define.c: -------------------------------------------------------------------------------- 1 | #define FOO 0 2 | 3 | int main() 4 | { 5 | return FOO; 6 | } 7 | 8 | -------------------------------------------------------------------------------- /tests/0064-sysinclude.c: -------------------------------------------------------------------------------- 1 | #include <0064-sysinclude.h> 2 | 3 | int 4 | main() 5 | { 6 | return x; 7 | } 8 | -------------------------------------------------------------------------------- /tests/0065-ifdef.c: -------------------------------------------------------------------------------- 1 | 2 | #ifdef FOO 3 | XXX 4 | #ifdef BAR 5 | XXX 6 | #endif 7 | XXX 8 | #endif 9 | 10 | #define FOO 1 11 | 12 | #ifdef FOO 13 | 14 | #ifdef FOO 15 | int x = 0; 16 | #endif 17 | 18 | int 19 | main() 20 | { 21 | return x; 22 | } 23 | #endif 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /tests/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/0067-define.c: -------------------------------------------------------------------------------- 1 | #define X 6 / 2 2 | 3 | int 4 | main() 5 | { 6 | return X - 3; 7 | } 8 | -------------------------------------------------------------------------------- /tests/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/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/0070-cppif.c: -------------------------------------------------------------------------------- 1 | 2 | #if 1 3 | int x = 0; 4 | #endif 5 | 6 | #if 0 7 | int x = 1; 8 | #if 1 9 | X 10 | #endif 11 | #ifndef AAA 12 | X 13 | #endif 14 | #endif 15 | 16 | int main() 17 | { 18 | return x; 19 | } 20 | -------------------------------------------------------------------------------- /tests/0071-cppelif.c: -------------------------------------------------------------------------------- 1 | 2 | #if 0 3 | X 4 | #elif 1 5 | int x = 0; 6 | #else 7 | X 8 | #endif 9 | 10 | int 11 | main() 12 | { 13 | return x; 14 | } 15 | -------------------------------------------------------------------------------- /tests/0072-cppelif.c: -------------------------------------------------------------------------------- 1 | 2 | #if 0 3 | X 4 | #elif 0 5 | X 6 | #elif 1 7 | int x = 0; 8 | #endif 9 | 10 | int 11 | main() 12 | { 13 | return x; 14 | } 15 | -------------------------------------------------------------------------------- /tests/0073-ifndef.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef DEF 4 | int x = 0; 5 | #endif 6 | 7 | #define DEF 8 | 9 | #ifndef DEF 10 | X 11 | #endif 12 | 13 | int 14 | main() 15 | { 16 | return x; 17 | } 18 | -------------------------------------------------------------------------------- /tests/0074-undef.c: -------------------------------------------------------------------------------- 1 | 2 | #define X 1 3 | #undef X 4 | 5 | #ifdef X 6 | FAIL 7 | #endif 8 | 9 | int 10 | main() 11 | { 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /tests/0075-ptraddasn.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | int arr[2]; 6 | int *p; 7 | 8 | p = &arr[0]; 9 | p += 1; 10 | *p = 123; 11 | 12 | if(arr[1] != 123) 13 | return 1; 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /tests/0076-ptrsubasn.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | int arr[2]; 6 | int *p; 7 | 8 | p = &arr[1]; 9 | p -= 1; 10 | *p = 123; 11 | 12 | if(arr[0] != 123) 13 | return 1; 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /tests/0077-defined.c: -------------------------------------------------------------------------------- 1 | 2 | #if defined X 3 | X 4 | #endif 5 | 6 | #if defined(X) 7 | X 8 | #endif 9 | 10 | #if X 11 | X 12 | #endif 13 | 14 | #define X 0 15 | 16 | #if X 17 | X 18 | #endif 19 | 20 | #if defined(X) 21 | int x = 0; 22 | #endif 23 | 24 | #undef X 25 | #define X 1 26 | 27 | #if X 28 | int 29 | main() 30 | { 31 | return 0; 32 | } 33 | #endif 34 | -------------------------------------------------------------------------------- /tests/0079-cond.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | if(0 ? 1 : 0) 6 | return 1; 7 | if(1 ? 0 : 1) 8 | return 2; 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/0080-arrays.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | foo(int x[100]) 4 | { 5 | int y[100]; 6 | int *p; 7 | 8 | y[0] = 2000; 9 | 10 | if(x[0] != 1000) 11 | { 12 | return 1; 13 | } 14 | 15 | p = x; 16 | 17 | if(p[0] != 1000) 18 | { 19 | return 2; 20 | } 21 | 22 | p = y; 23 | 24 | if(p[0] != 2000) 25 | { 26 | return 3; 27 | } 28 | 29 | if(sizeof(x) != sizeof(void*)) 30 | { 31 | return 4; 32 | } 33 | 34 | if(sizeof(y) <= sizeof(x)) 35 | { 36 | return 5; 37 | } 38 | 39 | return 0; 40 | } 41 | 42 | int 43 | main() 44 | { 45 | int x[100]; 46 | x[0] = 1000; 47 | 48 | return foo(x); 49 | } 50 | -------------------------------------------------------------------------------- /tests/Makefile: -------------------------------------------------------------------------------- 1 | .POSIX: 2 | 3 | all clean: 4 | cd error && make -e $@ 5 | cd execute && make -e $@ 6 | -------------------------------------------------------------------------------- /tests/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/chktest.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | trap 'tabs -8;rm -f a.out' 0 1 2 3 15 4 | tabs 40 5 | ulimit -c 0 6 | 7 | for i in $@ 8 | do 9 | printf "%s\t" $i 10 | rm -f a.out 11 | (scc -m qbe "$i" && ./a.out) 2>/dev/null && echo [OK] || echo [FAILED] 12 | done 13 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /tests/error/update.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # See LICENSE file for copyright and license details. 3 | 4 | for i 5 | do 6 | (echo '/^PATTERN/+;/^\./-c' 7 | scc $CFLAGS -w -c $i 2>&1 8 | printf ".\nw\n" 9 | echo w) | 10 | ed -s $i 11 | done 12 | -------------------------------------------------------------------------------- /tests/execute/0001-sanity.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/execute/0002-expr.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | return 3-3; 6 | } 7 | -------------------------------------------------------------------------------- /tests/execute/0003-local.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | int 4 | main() 5 | { 6 | int x; 7 | 8 | x = 4; 9 | return x - 4; 10 | } 11 | -------------------------------------------------------------------------------- /tests/execute/0004-pointer.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | int 4 | main() 5 | { 6 | int x; 7 | int *p; 8 | 9 | x = 4; 10 | p = &x; 11 | *p = 0; 12 | 13 | return *p; 14 | } 15 | -------------------------------------------------------------------------------- /tests/execute/0005-ifstmt.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | int x; 6 | int *p; 7 | int **pp; 8 | 9 | x = 0; 10 | p = &x; 11 | pp = &p; 12 | 13 | if(*p) 14 | return 1; 15 | if(**pp) 16 | return 1; 17 | else 18 | **pp = 1; 19 | 20 | if(x) 21 | return 0; 22 | else 23 | return 1; 24 | } 25 | -------------------------------------------------------------------------------- /tests/execute/0006-whilestmt.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | int x; 6 | 7 | x = 50; 8 | while (x) 9 | x = x - 1; 10 | return x; 11 | } 12 | -------------------------------------------------------------------------------- /tests/execute/0007-forstmt.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | int x; 6 | 7 | x = 1; 8 | for(x = 10; x; x = x - 1) 9 | ; 10 | if(x) 11 | return 1; 12 | x = 10; 13 | for (;x;) 14 | x = x - 1; 15 | return x; 16 | } 17 | -------------------------------------------------------------------------------- /tests/execute/0008-dowhilestmt.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | int x; 6 | 7 | x = 50; 8 | do 9 | x = x - 1; 10 | while(x); 11 | return x; 12 | } 13 | -------------------------------------------------------------------------------- /tests/execute/0009-expr.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | int x; 6 | 7 | x = 1; 8 | x = x * 10; 9 | x = x / 2; 10 | x = x % 3; 11 | return x - 2; 12 | } 13 | -------------------------------------------------------------------------------- /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 | 2 | int 3 | main() 4 | { 5 | int x; 6 | int y; 7 | x = y = 0; 8 | return x; 9 | } 10 | -------------------------------------------------------------------------------- /tests/execute/0012-expr.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | return (2 + 2) * 2 - 8; 6 | } 7 | -------------------------------------------------------------------------------- /tests/execute/0013-addridx.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | int x; 6 | int *p; 7 | 8 | x = 0; 9 | p = &x; 10 | return p[0]; 11 | } 12 | -------------------------------------------------------------------------------- /tests/execute/0014-assignidx.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | int x; 6 | int *p; 7 | 8 | x = 1; 9 | p = &x; 10 | p[0] = 0; 11 | return x; 12 | } 13 | -------------------------------------------------------------------------------- /tests/execute/0015-localarray.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | int arr[2]; 6 | 7 | arr[0] = 1; 8 | arr[1] = 2; 9 | 10 | return arr[0] + arr[1] - 3; 11 | } 12 | -------------------------------------------------------------------------------- /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 | 2 | 3 | int 4 | main() 5 | { 6 | struct { int x; int y; } s; 7 | 8 | s.x = 3; 9 | s.y = 5; 10 | return s.y - s.x - 2; 11 | } 12 | -------------------------------------------------------------------------------- /tests/execute/0018-structptr.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | int 4 | main() 5 | { 6 | 7 | struct S { int x; int y; } s; 8 | struct S *p; 9 | 10 | p = &s; 11 | s.x = 1; 12 | p->y = 2; 13 | return p->y + p->x - 3; 14 | } 15 | 16 | -------------------------------------------------------------------------------- /tests/execute/0019-selfrefstruct.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | struct S { struct S *p; int x; } s; 6 | 7 | s.x = 0; 8 | s.p = &s; 9 | return s.p->p->p->p->p->x; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /tests/execute/0020-ptrptr.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | int x, *p, **pp; 6 | 7 | x = 0; 8 | p = &x; 9 | pp = &p; 10 | return **pp; 11 | } 12 | -------------------------------------------------------------------------------- /tests/execute/0021-intfunc.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | foo(int a, int b) 4 | { 5 | return 2 + a - b; 6 | } 7 | 8 | int 9 | main() 10 | { 11 | return foo(1, 3); 12 | } 13 | 14 | -------------------------------------------------------------------------------- /tests/execute/0022-typedef.c: -------------------------------------------------------------------------------- 1 | 2 | typedef int x; 3 | 4 | int 5 | main() 6 | { 7 | x v; 8 | v = 0; 9 | return v; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /tests/execute/0023-global.c: -------------------------------------------------------------------------------- 1 | 2 | int x; 3 | 4 | int 5 | main() 6 | { 7 | x = 0; 8 | return x; 9 | } 10 | 11 | -------------------------------------------------------------------------------- /tests/execute/0024-typedefstruct.c: -------------------------------------------------------------------------------- 1 | 2 | typedef struct { int x; int y; } s; 3 | 4 | s v; 5 | 6 | int 7 | main() 8 | { 9 | v.x = 1; 10 | v.y = 2; 11 | return 3 - v.x - v.y; 12 | } 13 | 14 | -------------------------------------------------------------------------------- /tests/execute/0025-string.c: -------------------------------------------------------------------------------- 1 | 2 | int strlen(char *); 3 | 4 | int 5 | main() 6 | { 7 | char *p; 8 | 9 | p = "hello"; 10 | return strlen(p) - 5; 11 | } 12 | -------------------------------------------------------------------------------- /tests/execute/0026-implicitret.c: -------------------------------------------------------------------------------- 1 | 2 | main() 3 | { 4 | return 0; 5 | } 6 | 7 | -------------------------------------------------------------------------------- /tests/execute/0027-charval.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | char *p; 6 | 7 | p = "hello"; 8 | return p[0] - 104; 9 | } 10 | -------------------------------------------------------------------------------- /tests/execute/0028-bor.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | int x; 6 | 7 | x = 1; 8 | x = x | 4; 9 | return x - 5; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /tests/execute/0029-band.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | int x; 6 | 7 | x = 1; 8 | x = x & 3; 9 | return x - 1; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /tests/execute/0030-bxor.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | int x; 6 | 7 | x = 1; 8 | x = x ^ 3; 9 | return x - 2; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /tests/execute/0031-relop.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | f() 4 | { 5 | return 100; 6 | } 7 | 8 | int 9 | main() 10 | { 11 | if (f() > 1000) 12 | return 1; 13 | if (f() >= 1000) 14 | return 1; 15 | if (1000 < f()) 16 | return 1; 17 | if (1000 <= f()) 18 | return 1; 19 | if (1000 == f()) 20 | return 1; 21 | if (100 != f()) 22 | return 1; 23 | return 0; 24 | } 25 | 26 | -------------------------------------------------------------------------------- /tests/execute/0032-indec.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | zero() 4 | { 5 | return 0; 6 | } 7 | 8 | int 9 | one() 10 | { 11 | return 1; 12 | } 13 | 14 | int 15 | main() 16 | { 17 | int x; 18 | int y; 19 | 20 | x = zero(); 21 | y = ++x; 22 | if (x != 1) 23 | return 1; 24 | if (y != 1) 25 | return 1; 26 | 27 | x = one(); 28 | y = --x; 29 | if (x != 0) 30 | return 1; 31 | if (y != 0) 32 | return 1; 33 | 34 | x = zero(); 35 | y = x++; 36 | if (x != 1) 37 | return 1; 38 | if (y != 0) 39 | return 1; 40 | 41 | x = one(); 42 | y = x--; 43 | if (x != 0) 44 | return 1; 45 | if (y != 1) 46 | return 1; 47 | 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /tests/execute/0033-ptrindec.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | int 4 | main() 5 | { 6 | int arr[2]; 7 | int *p; 8 | 9 | arr[0] = 2; 10 | arr[1] = 3; 11 | p = &arr[0]; 12 | if(*(p++) != 2) 13 | return 1; 14 | if(*(p++) != 3) 15 | return 2; 16 | 17 | p = &arr[1]; 18 | if(*(p--) != 3) 19 | return 1; 20 | if(*(p--) != 2) 21 | return 2; 22 | 23 | p = &arr[0]; 24 | if(*(++p) != 3) 25 | return 1; 26 | 27 | p = &arr[1]; 28 | if(*(--p) != 2) 29 | return 1; 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /tests/execute/0034-logandor.c: -------------------------------------------------------------------------------- 1 | 2 | int g; 3 | 4 | int 5 | effect() 6 | { 7 | g = 1; 8 | return 1; 9 | } 10 | 11 | int 12 | main() 13 | { 14 | int x; 15 | 16 | g = 0; 17 | x = 0; 18 | if(x && effect()) 19 | return 1; 20 | if(g) 21 | return 2; 22 | x = 1; 23 | if(x && effect()) { 24 | if(g != 1) 25 | return 3; 26 | } else { 27 | return 4; 28 | } 29 | g = 0; 30 | x = 1; 31 | if(x || effect()) { 32 | if(g) 33 | return 5; 34 | } else { 35 | return 6; 36 | } 37 | x = 0; 38 | if(x || effect()) { 39 | if(g != 1) 40 | return 7; 41 | } else { 42 | return 8; 43 | } 44 | return 0; 45 | } 46 | 47 | -------------------------------------------------------------------------------- /tests/execute/0035-breakcont.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | int x; 6 | 7 | x = 0; 8 | while(1) 9 | break; 10 | while(1) { 11 | if (x == 5) { 12 | break; 13 | } 14 | x = x + 1; 15 | continue; 16 | } 17 | for (;;) { 18 | if (x == 10) { 19 | break; 20 | } 21 | x = x + 1; 22 | continue; 23 | } 24 | do { 25 | if (x == 15) { 26 | break; 27 | } 28 | x = x + 1; 29 | continue; 30 | } while(1); 31 | return x - 15; 32 | } 33 | 34 | -------------------------------------------------------------------------------- /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 | 2 | int 3 | main() 4 | { 5 | int x; 6 | 7 | x = 0; 8 | x += 2; 9 | x += 2; 10 | if (x != 4) 11 | return 1; 12 | x -= 1; 13 | if (x != 3) 14 | return 2; 15 | x *= 2; 16 | if (x != 6) 17 | return 3; 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /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; 5 | if((sizeof (int) - 4)) 6 | return 1; 7 | if((sizeof (&x) - 8)) 8 | return 1; 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/execute/0040-cast.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | void *p; 6 | int x; 7 | 8 | x = 2; 9 | p = &x; 10 | 11 | if(*((int*)p) != 2) 12 | return 1; 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /tests/execute/0042-prime.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() { 4 | int n; 5 | int t; 6 | int c; 7 | int p; 8 | 9 | c = 0; 10 | n = 2; 11 | while (n < 5000) { 12 | t = 2; 13 | p = 1; 14 | while (t*t <= n) { 15 | if (n % t == 0) 16 | p = 0; 17 | t++; 18 | } 19 | n++; 20 | if (p) 21 | c++; 22 | } 23 | if (c != 669) 24 | return 1; 25 | return 0; 26 | } 27 | 28 | -------------------------------------------------------------------------------- /tests/execute/0043-union.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | int 5 | main() 6 | { 7 | union { int a; int b; } u; 8 | u.a = 1; 9 | u.b = 3; 10 | 11 | if (u.a != 3 || u.b != 3) 12 | return 1; 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /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 | 2 | int x = 5; 3 | long y = 6; 4 | int *p = &x; 5 | 6 | int 7 | main() 8 | { 9 | if (x != 5) 10 | return 1; 11 | if (y != 6) 12 | return 2; 13 | if (*p != 5) 14 | return 3; 15 | return 0; 16 | } 17 | 18 | -------------------------------------------------------------------------------- /tests/execute/0047-anonexport.c: -------------------------------------------------------------------------------- 1 | 2 | typedef struct { 3 | int a; 4 | union { 5 | int b1; 6 | int b2; 7 | }; 8 | struct { union { struct { int c; }; struct {}; }; }; 9 | struct {}; 10 | struct { 11 | int d; 12 | }; 13 | } s; 14 | 15 | int 16 | main() 17 | { 18 | s v; 19 | 20 | v.a = 1; 21 | v.b1 = 2; 22 | v.c = 3; 23 | v.d = 4; 24 | 25 | if (v.a != 1) 26 | return 1; 27 | if (v.b1 != 2 && v.b2 != 2) 28 | return 2; 29 | if (v.c != 3) 30 | return 3; 31 | if (v.d != 4) 32 | return 4; 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /tests/execute/0048-inits.c: -------------------------------------------------------------------------------- 1 | 2 | struct { int a; int b; int c; } s = {1, 2, 3}; 3 | 4 | int 5 | main() 6 | { 7 | if (s.a != 1) 8 | return 1; 9 | if (s.b != 2) 10 | return 2; 11 | if (s.c != 3) 12 | return 3; 13 | 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /tests/execute/0049-inits.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | struct S {int a; int b;}; 4 | struct S s = { .b = 2, .a = 1}; 5 | 6 | int 7 | main() 8 | { 9 | if(s.a != 1) 10 | return 1; 11 | if(s.b != 2) 12 | return 2; 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /tests/execute/0050-inits.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | int x = 10; 4 | 5 | struct S {int a; int *p;}; 6 | struct S s = { .p = &x, .a = 1}; 7 | 8 | int 9 | main() 10 | { 11 | if(s.a != 1) 12 | return 1; 13 | if(*s.p != 10) 14 | return 2; 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /tests/execute/0051-inits.c: -------------------------------------------------------------------------------- 1 | 2 | struct S1 { 3 | int a; 4 | int b; 5 | }; 6 | 7 | struct S2 { 8 | int a; 9 | int b; 10 | union { 11 | int c; 12 | int d; 13 | }; 14 | struct S1 s; 15 | }; 16 | 17 | struct S2 v = {1, 2, 3, {4, 5}}; 18 | 19 | int 20 | main() 21 | { 22 | if(v.a != 1) 23 | return 1; 24 | if(v.b != 2) 25 | return 2; 26 | if(v.c != 3 || v.d != 3) 27 | return 3; 28 | if(v.s.a != 4) 29 | return 4; 30 | if(v.s.b != 5) 31 | return 5; 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /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 | 2 | int 3 | main() 4 | { 5 | struct T { int x; }; 6 | { 7 | struct T s; 8 | s.x = 0; 9 | return s.x; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /tests/execute/0054-struct.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | struct T { int x; } s1; 6 | s1.x = 1; 7 | { 8 | struct T { int y; } s2; 9 | s2.y = 1; 10 | if (s1.x - s2.y != 0) 11 | return 1; 12 | } 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /tests/execute/0055-enum.c: -------------------------------------------------------------------------------- 1 | 2 | enum E { 3 | x, 4 | y, 5 | z, 6 | }; 7 | 8 | int 9 | main() 10 | { 11 | enum E e; 12 | 13 | if(x != 0) 14 | return 1; 15 | if(y != 1) 16 | return 2; 17 | if(z != 2) 18 | return 3; 19 | 20 | e = x; 21 | return e; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /tests/execute/0056-enum.c: -------------------------------------------------------------------------------- 1 | 2 | enum E { 3 | x, 4 | y = 2, 5 | z, 6 | }; 7 | 8 | int 9 | main() 10 | { 11 | enum E e; 12 | 13 | if(x != 0) 14 | return 1; 15 | if(y != 2) 16 | return 2; 17 | if(z != 3) 18 | return 3; 19 | 20 | e = x; 21 | return e; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /tests/execute/0057-duff.c: -------------------------------------------------------------------------------- 1 | 2 | int main() 3 | { 4 | int count, n; 5 | char *from, *to; 6 | char a[39], b[39]; 7 | 8 | for(n = 0; n < 39; n++) { 9 | a[n] = n; 10 | b[n] = 0; 11 | } 12 | from = a; 13 | to = b; 14 | count = 39; 15 | n = (count + 7) / 8; 16 | switch (count % 8) { 17 | case 0: do { *to++ = *from++; 18 | case 7: *to++ = *from++; 19 | case 6: *to++ = *from++; 20 | case 5: *to++ = *from++; 21 | case 4: *to++ = *from++; 22 | case 3: *to++ = *from++; 23 | case 2: *to++ = *from++; 24 | case 1: *to++ = *from++; 25 | } while (--n > 0); 26 | } 27 | for(n = 0; n < 39; n++) 28 | if(a[n] != b[n]) 29 | return 1; 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /tests/execute/0058-bug.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | char a[16], b[16]; 6 | 7 | if(sizeof(a) != sizeof(b)) 8 | return 1; 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/execute/0059-multistring.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | int main() 5 | { 6 | char * s; 7 | 8 | s = "abc" "def"; 9 | if(s[0] != 'a') return 1; 10 | if(s[1] != 'b') return 2; 11 | if(s[2] != 'c') return 3; 12 | if(s[3] != 'd') return 4; 13 | if(s[4] != 'e') return 5; 14 | if(s[5] != 'f') return 6; 15 | if(s[6] != 0) return 7; 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /tests/execute/0060-charlit.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | if ('a' != 97) 6 | return 1; 7 | 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /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 | 2 | #ifdef FOO 3 | XXX 4 | #ifdef BAR 5 | XXX 6 | #endif 7 | XXX 8 | #endif 9 | 10 | #define FOO 1 11 | 12 | #ifdef FOO 13 | 14 | #ifdef FOO 15 | int x = 0; 16 | #endif 17 | 18 | int 19 | main() 20 | { 21 | return x; 22 | } 23 | #endif 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /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 | 2 | #if 1 3 | int x = 0; 4 | #endif 5 | 6 | #if 0 7 | int x = 1; 8 | #if 1 9 | X 10 | #endif 11 | #ifndef AAA 12 | X 13 | #endif 14 | #endif 15 | 16 | int main() 17 | { 18 | return x; 19 | } 20 | -------------------------------------------------------------------------------- /tests/execute/0071-cppelif.c: -------------------------------------------------------------------------------- 1 | 2 | #if 0 3 | X 4 | #elif 1 5 | int x = 0; 6 | #else 7 | X 8 | #endif 9 | 10 | int 11 | main() 12 | { 13 | return x; 14 | } 15 | -------------------------------------------------------------------------------- /tests/execute/0072-cppelif.c: -------------------------------------------------------------------------------- 1 | 2 | #if 0 3 | X 4 | #elif 0 5 | X 6 | #elif 1 7 | int x = 0; 8 | #endif 9 | 10 | int 11 | main() 12 | { 13 | return x; 14 | } 15 | -------------------------------------------------------------------------------- /tests/execute/0073-ifndef.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef DEF 4 | int x = 0; 5 | #endif 6 | 7 | #define DEF 8 | 9 | #ifndef DEF 10 | X 11 | #endif 12 | 13 | int 14 | main() 15 | { 16 | return x; 17 | } 18 | -------------------------------------------------------------------------------- /tests/execute/0074-undef.c: -------------------------------------------------------------------------------- 1 | 2 | #define X 1 3 | #undef X 4 | 5 | #ifdef X 6 | FAIL 7 | #endif 8 | 9 | int 10 | main() 11 | { 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /tests/execute/0075-ptraddasn.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | int arr[2]; 6 | int *p; 7 | 8 | p = &arr[0]; 9 | p += 1; 10 | *p = 123; 11 | 12 | if(arr[1] != 123) 13 | return 1; 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /tests/execute/0076-ptrsubasn.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | int arr[2]; 6 | int *p; 7 | 8 | p = &arr[1]; 9 | p -= 1; 10 | *p = 123; 11 | 12 | if(arr[0] != 123) 13 | return 1; 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /tests/execute/0077-defined.c: -------------------------------------------------------------------------------- 1 | 2 | #if defined X 3 | X 4 | #endif 5 | 6 | #if defined(X) 7 | X 8 | #endif 9 | 10 | #if X 11 | X 12 | #endif 13 | 14 | #define X 0 15 | 16 | #if X 17 | X 18 | #endif 19 | 20 | #if defined(X) 21 | int x = 0; 22 | #endif 23 | 24 | #undef X 25 | #define X 1 26 | 27 | #if X 28 | int 29 | main() 30 | { 31 | return 0; 32 | } 33 | #endif 34 | -------------------------------------------------------------------------------- /tests/execute/0079-cond.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | if(0 ? 1 : 0) 6 | return 1; 7 | if(1 ? 0 : 1) 8 | return 2; 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/execute/0080-arrays.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | foo(int x[100]) 4 | { 5 | int y[100]; 6 | int *p; 7 | 8 | y[0] = 2000; 9 | 10 | if(x[0] != 1000) 11 | { 12 | return 1; 13 | } 14 | 15 | p = x; 16 | 17 | if(p[0] != 1000) 18 | { 19 | return 2; 20 | } 21 | 22 | p = y; 23 | 24 | if(p[0] != 2000) 25 | { 26 | return 3; 27 | } 28 | 29 | if(sizeof(x) != sizeof(void*)) 30 | { 31 | return 4; 32 | } 33 | 34 | if(sizeof(y) <= sizeof(x)) 35 | { 36 | return 5; 37 | } 38 | 39 | return 0; 40 | } 41 | 42 | int 43 | main() 44 | { 45 | int x[100]; 46 | x[0] = 1000; 47 | 48 | return foo(x); 49 | } 50 | -------------------------------------------------------------------------------- /tests/execute/0081-calls.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | f1(char *p) 4 | { 5 | return *p+1; 6 | } 7 | 8 | int 9 | main() 10 | { 11 | char s = 1; 12 | int v[1000]; 13 | int f1(char *); 14 | 15 | if (f1(&s) != 2) 16 | return 1; 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /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 | 2 | void 3 | voidfn() 4 | { 5 | return; 6 | } 7 | 8 | int 9 | main() 10 | { 11 | voidfn(); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /tests/execute/0084-longlong.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | long long x; 6 | 7 | x = 0; 8 | x = x + 1; 9 | if (x != 1) 10 | return 1; 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /tests/execute/0085-ulonglong.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | unsigned long long x; 6 | 7 | x = 0; 8 | x = x + 1; 9 | if (x != 1) 10 | return 1; 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /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 | 2 | int 3 | main() 4 | { 5 | short x; 6 | 7 | x = 0; 8 | x = x + 1; 9 | if (x != 1) 10 | return 1; 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /tests/execute/0090-fptr.c: -------------------------------------------------------------------------------- 1 | 2 | struct S 3 | { 4 | int (*fptr)(); 5 | }; 6 | 7 | int 8 | foo() 9 | { 10 | return 0; 11 | } 12 | 13 | int 14 | main() 15 | { 16 | struct S v; 17 | 18 | v.fptr = foo; 19 | return v.fptr(); 20 | } 21 | 22 | -------------------------------------------------------------------------------- /tests/execute/0091-fptr.c: -------------------------------------------------------------------------------- 1 | 2 | int (*fptr)() = 0; 3 | 4 | 5 | int 6 | main() 7 | { 8 | if (fptr) 9 | return 1; 10 | return 0; 11 | } 12 | 13 | -------------------------------------------------------------------------------- /tests/execute/0092-fptr.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | zero() 4 | { 5 | return 0; 6 | } 7 | 8 | struct S 9 | { 10 | int (*zerofunc)(); 11 | } s = { &zero }; 12 | 13 | struct S * 14 | anon() 15 | { 16 | return &s; 17 | } 18 | 19 | typedef struct S * (*fty)(); 20 | 21 | fty 22 | go() 23 | { 24 | return &anon; 25 | } 26 | 27 | int 28 | main() 29 | { 30 | return go()()->zerofunc(); 31 | } 32 | -------------------------------------------------------------------------------- /tests/execute/0093-arrayinit.c: -------------------------------------------------------------------------------- 1 | 2 | int a[3] = {0, 1, 2}; 3 | 4 | int 5 | main() 6 | { 7 | if (a[0] != 0) 8 | return 1; 9 | if (a[1] != 1) 10 | return 2; 11 | if (a[2] != 2) 12 | return 3; 13 | 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /tests/execute/0094-arrayinit.c: -------------------------------------------------------------------------------- 1 | 2 | typedef struct { 3 | int v; 4 | int sub[2]; 5 | } S; 6 | 7 | S a[1] = {{1, {2, 3}}}; 8 | 9 | int 10 | main() 11 | { 12 | if (a[0].v != 1) 13 | return 1; 14 | if (a[0].sub[0] != 2) 15 | return 2; 16 | if (a[0].sub[1] != 3) 17 | return 3; 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /tests/execute/0095-arrayselector.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | int a[] = {5, [2] = 2, 3}; 6 | 7 | int 8 | main() 9 | { 10 | if (sizeof(a) != 4*sizeof(int)) 11 | return 1; 12 | 13 | if (a[0] != 5) 14 | return 2; 15 | if (a[1] != 0) 16 | return 3; 17 | if (a[2] != 2) 18 | return 4; 19 | if (a[3] != 3) 20 | return 5; 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /tests/execute/0096-inferredarraysize.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | int a[] = {1, 2, 3, 4}; 4 | 5 | int 6 | main() 7 | { 8 | if (sizeof(a) != 4*sizeof(int)) 9 | return 1; 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /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 | 2 | int x; 3 | int x = 3; 4 | int x; 5 | 6 | int main(); 7 | 8 | void * 9 | foo() 10 | { 11 | return &main; 12 | } 13 | 14 | int 15 | main() 16 | { 17 | if (x != 3) 18 | return 0; 19 | 20 | x = 0; 21 | return x; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /tests/execute/0099-tentative.c: -------------------------------------------------------------------------------- 1 | 2 | int x, x = 3, x; 3 | 4 | int 5 | main() 6 | { 7 | if (x != 3) 8 | return 0; 9 | 10 | x = 0; 11 | return x; 12 | } 13 | 14 | -------------------------------------------------------------------------------- /tests/execute/0100-redeclaremacro.c: -------------------------------------------------------------------------------- 1 | 2 | #define NULL ((void*)0) 3 | #define NULL ((void*)0) 4 | 5 | #define FOO(X, Y) (X + Y + Z) 6 | #define FOO(X, Y) (X + Y + Z) 7 | 8 | #define BAR(X, Y, ...) (X + Y + Z) 9 | #define BAR(X, Y, ...) (X + Y + Z) 10 | 11 | int 12 | main() 13 | { 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /tests/execute/0101-wcharlit.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | return L'\0'; 6 | } 7 | -------------------------------------------------------------------------------- /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 | 2 | int 3 | foo(void) 4 | { 5 | return 0; 6 | } 7 | 8 | int 9 | main() 10 | { 11 | return foo(); 12 | } 13 | -------------------------------------------------------------------------------- /tests/execute/0104-qbebug.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | int c; 6 | c = 0; 7 | do 8 | ; 9 | while (0); 10 | return c; 11 | } 12 | -------------------------------------------------------------------------------- /tests/execute/0105-shl.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | int x; 6 | 7 | x = 1; 8 | if ((x << 1) != 2) 9 | return 1; 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /tests/execute/0106-ppcast.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | int x; 6 | void *foo; 7 | void **bar; 8 | 9 | x = 0; 10 | 11 | foo = (void*)&x; 12 | bar = &foo; 13 | 14 | return **(int**)bar; 15 | } 16 | -------------------------------------------------------------------------------- /tests/execute/0107-bnot.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | int 5 | main() 6 | { 7 | int32_t x; 8 | int64_t l; 9 | 10 | x = 0; 11 | l = 0; 12 | 13 | x = ~x; 14 | if (x != 0xffffffff) 15 | return 1; 16 | 17 | l = ~l; 18 | if (x != 0xffffffffffffffff) 19 | return 2; 20 | 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /tests/execute/0108-bug.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | int 4 | main() 5 | { 6 | int i; 7 | 8 | for(i = 0; i < 10; i++) 9 | if (!i) 10 | continue; 11 | 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /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 | 2 | int 3 | main() 4 | { 5 | short s = 1; 6 | long l = 1; 7 | 8 | s -= l; 9 | return s; 10 | } 11 | -------------------------------------------------------------------------------- /tests/execute/0115-null-comparision.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | return "abc" == (void *)0; 5 | } 6 | -------------------------------------------------------------------------------- /tests/execute/0116-floatcmp.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main() 4 | { 5 | int a = 0; 6 | float f = a + 1; 7 | 8 | return f == a; 9 | } 10 | -------------------------------------------------------------------------------- /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 | 2 | int main(void); 3 | 4 | int 5 | main() 6 | { 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /tests/execute/0119-macrostr.c: -------------------------------------------------------------------------------- 1 | 2 | #define B "b" 3 | 4 | char s[] = "a" B "c"; 5 | 6 | int 7 | main() 8 | { 9 | if (s[0] != 'a') 10 | return 1; 11 | if (s[1] != 'b') 12 | return 2; 13 | if (s[2] != 'c') 14 | return 3; 15 | if (s[3] != '\0') 16 | return 4; 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /tests/execute/0120-funpar.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | f(int f) 4 | { 5 | return f; 6 | } 7 | 8 | int 9 | main() 10 | { 11 | return f(0); 12 | } 13 | -------------------------------------------------------------------------------- /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 | 2 | int f(int a), g(int a), a; 3 | 4 | 5 | int 6 | main() 7 | { 8 | return f(1) - g(1); 9 | } 10 | 11 | int 12 | f(int a) 13 | { 14 | return a; 15 | } 16 | 17 | int 18 | g(int a) 19 | { 20 | return a; 21 | } 22 | -------------------------------------------------------------------------------- /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/Makefile: -------------------------------------------------------------------------------- 1 | .POSIX: 2 | 3 | all: tests 4 | 5 | tests: 6 | CFLAGS='' SCCEXECPATH=../../bin PATH=../../bin:$$PATH ./chktest.sh < scc-tests.lst 7 | clean: 8 | rm -f *.as *.o *.ir *.qbe *core test.log 9 | -------------------------------------------------------------------------------- /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 | trap 'tabs -8;rm -f a.out' 0 1 2 3 15 4 | tabs 40 5 | ulimit -c 0 6 | rm -f test.log 7 | 8 | while read i state 9 | do 10 | echo $i >>test.log 11 | printf "%s\t" $i 12 | printf "%s" $state 13 | rm -f a.out 14 | (scc -Isysinclude $CFLAGS "$i" && ./a.out) 2>test.log && 15 | echo [OK] || echo [FAILED] 16 | done 17 | -------------------------------------------------------------------------------- /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 | 2 | int y = 2; 3 | -------------------------------------------------------------------------------- /tests/include/0064-sysinclude.h: -------------------------------------------------------------------------------- 1 | int x = 0; 2 | 3 | -------------------------------------------------------------------------------- /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 | --------------------------------------------------------------------------------