├── .gitignore ├── src ├── lib │ ├── vm_lib │ │ ├── errno.c │ │ ├── include │ │ │ ├── memory.h │ │ │ ├── unistd.h │ │ │ ├── stdbool.h │ │ │ ├── errno.h │ │ │ ├── stddef.h │ │ │ ├── sys │ │ │ │ └── stat.h │ │ │ ├── stdarg.h │ │ │ ├── assert.h │ │ │ ├── ctype.h │ │ │ ├── limits.h │ │ │ ├── stdlib.h │ │ │ └── string.h │ │ ├── libc.c │ │ ├── README │ │ └── makefile │ ├── obj │ │ ├── arm │ │ │ ├── README │ │ │ ├── pic │ │ │ │ └── README │ │ │ └── libc.so │ │ ├── mips │ │ │ ├── README │ │ │ ├── pic │ │ │ │ └── README │ │ │ └── libc.so │ │ ├── x64 │ │ │ ├── README │ │ │ ├── pic │ │ │ │ └── README │ │ │ └── libc.so │ │ ├── x86 │ │ │ ├── README │ │ │ ├── pic │ │ │ │ └── README │ │ │ └── libc.so │ │ ├── vm32 │ │ │ └── README │ │ └── vm64 │ │ │ └── README │ ├── errno.c │ ├── include │ │ ├── memory.h │ │ ├── stdbool.h │ │ ├── sys │ │ │ ├── types.h │ │ │ ├── wait.h │ │ │ ├── time.h │ │ │ ├── times.h │ │ │ ├── ioctl.h │ │ │ └── stat.h │ │ ├── stddef.h │ │ ├── utime.h │ │ ├── assert.h │ │ ├── signal.h │ │ ├── iso646.h │ │ ├── ctype.h │ │ ├── fcntl.h │ │ ├── getopt.h │ │ ├── termios.h │ │ ├── ar.h │ │ ├── unistd.h │ │ ├── limits.h │ │ └── time.h │ ├── times.c │ ├── ioctl.c │ ├── fcntl.c │ ├── wait.c │ ├── stime.c │ ├── termios.c │ ├── init.c │ ├── signal.c │ ├── stat.c │ ├── assert.c │ ├── utime.c │ ├── README │ ├── crt0_x86.asm │ ├── crt0_x64.asm │ ├── crt0_mips.asm │ ├── crt0_arm.asm │ ├── arm_memcpy.asm │ ├── raw_syscall_mips.asm │ ├── raw_syscall_x64.asm │ ├── raw_syscall_x86.asm │ ├── mips_memcpy.asm │ ├── raw_syscall_arm.asm │ ├── setjmp_arm.asm │ ├── setjmp_mips.asm │ ├── setjmp_x86.asm │ └── setjmp_x64.asm ├── tests │ ├── execute │ │ ├── other │ │ │ ├── T-Rex-master │ │ │ │ ├── .gitignore │ │ │ │ ├── README.txt │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── history.txt │ │ │ │ ├── testme.sh │ │ │ │ └── trex.expect │ │ │ ├── c4 │ │ │ │ ├── c4.expect │ │ │ │ ├── hello.c │ │ │ │ ├── README.md │ │ │ │ └── testme.sh │ │ │ ├── abc-compiler │ │ │ │ ├── README.txt │ │ │ │ ├── abc.expect │ │ │ │ ├── examples │ │ │ │ │ ├── 1_var.b │ │ │ │ │ ├── 4_goto.b │ │ │ │ │ ├── 2_ext.b │ │ │ │ │ ├── printargs.b │ │ │ │ │ ├── 3_fun.b │ │ │ │ │ └── 5_while.b │ │ │ │ ├── Makefile │ │ │ │ ├── link.ld │ │ │ │ └── testme.sh │ │ │ ├── ELFkickers │ │ │ │ ├── README.txt │ │ │ │ ├── test_elf │ │ │ │ ├── objres.expect │ │ │ │ ├── ebfc │ │ │ │ │ ├── bf │ │ │ │ │ │ ├── hello.b │ │ │ │ │ │ └── quine.b │ │ │ │ │ ├── gen.h │ │ │ │ │ ├── Makefile │ │ │ │ │ └── progbits.c │ │ │ │ ├── elfls │ │ │ │ │ ├── Makefile │ │ │ │ │ └── README │ │ │ │ ├── objres │ │ │ │ │ └── Makefile │ │ │ │ ├── rebind │ │ │ │ │ └── Makefile │ │ │ │ ├── elfrw │ │ │ │ │ └── Makefile │ │ │ │ ├── ebfc.expect │ │ │ │ ├── INSTALL │ │ │ │ └── Makefile │ │ │ ├── crypto-simple │ │ │ │ ├── README.txt │ │ │ │ ├── c │ │ │ │ │ ├── c_aes.expect │ │ │ │ │ ├── c_des.expect │ │ │ │ │ ├── c_des.bat │ │ │ │ │ └── c_aes.bat │ │ │ │ ├── testme.sh │ │ │ │ └── README.md │ │ │ ├── tiny-AES128-C │ │ │ │ ├── README.txt │ │ │ │ ├── testme.sh │ │ │ │ ├── aes.expect │ │ │ │ ├── Makefile │ │ │ │ ├── aes.h │ │ │ │ └── unlicense.txt │ │ │ ├── crypto-algorithms │ │ │ │ ├── README.txt │ │ │ │ ├── crypto.expect │ │ │ │ ├── src │ │ │ │ │ ├── rot-13.h │ │ │ │ │ ├── md2.h │ │ │ │ │ ├── base64.h │ │ │ │ │ ├── md5.h │ │ │ │ │ ├── sha1.h │ │ │ │ │ ├── arcfour.h │ │ │ │ │ ├── sha256.h │ │ │ │ │ ├── rot-13.c │ │ │ │ │ └── blowfish.h │ │ │ │ └── testme.sh │ │ │ ├── README.txt │ │ │ └── bzip2 │ │ │ │ └── testme.sh │ │ ├── AES │ │ │ ├── README.txt │ │ │ └── README.md │ │ ├── cc65 │ │ │ └── README.txt │ │ ├── llvm │ │ │ ├── README.txt │ │ │ ├── nestedloop.c │ │ │ └── merge.c │ │ ├── picoc_tcc │ │ │ ├── README.txt │ │ │ ├── 42_function_pointer.c │ │ │ ├── 16_nesting.c │ │ │ ├── 06_case.c │ │ │ ├── 38_multiple_array_index.c │ │ │ ├── 39_typedef.c │ │ │ ├── 03_struct.c │ │ │ ├── 11_precedence.c │ │ │ └── 41_hashif.c │ │ ├── arr1.c │ │ ├── README.txt │ │ ├── conditional.c │ │ ├── spill2.c │ │ ├── stat_init4.c │ │ ├── mac_eol.c │ │ ├── obfuscated.c │ │ ├── typedef1.c │ │ ├── empty_param.c │ │ ├── switch_def_zero.c │ │ ├── typedef2.c │ │ ├── typedef3.c │ │ ├── while.c │ │ ├── tent.c │ │ ├── tags.c │ │ ├── dos_eol.c │ │ ├── fptr.c │ │ ├── func_cast.c │ │ ├── void_cond.c │ │ ├── fold.c │ │ ├── fib.c │ │ ├── nested_calls.c │ │ ├── endian.c │ │ ├── return_struct.c │ │ ├── scope.c │ │ ├── aggregates_and_extern.c │ │ ├── for.c │ │ ├── inc1.c │ │ ├── do.c │ │ ├── vararg_struct.c │ │ ├── pascal.c │ │ ├── type_spec.c │ │ ├── if.c │ │ ├── ackermann.c │ │ ├── factorial.c │ │ ├── spill.c │ │ ├── rot13.c │ │ ├── goto.c │ │ ├── algol.c │ │ ├── ret_ptr_to_arr.c │ │ ├── string.c │ │ ├── stat_init3.c │ │ ├── josephus.c │ │ ├── cont_flow.c │ │ ├── duff_dev.c │ │ ├── qsort.c │ │ ├── queen.c │ │ ├── queen2.c │ │ ├── multi_dim_param.c │ │ ├── auto_init.c │ │ ├── loop.c │ │ ├── cope.c │ │ ├── libtest.c │ │ ├── stat_init.c │ │ ├── sieve.c │ │ ├── union.c │ │ ├── mixed_type.c │ │ └── cond_incl.c │ ├── analyze │ │ ├── README.txt │ │ ├── incomplete.c │ │ ├── lvalue.c │ │ ├── intconv.c │ │ ├── clash.c │ │ └── tags.c │ └── compile │ │ ├── c-algorithms │ │ ├── AUTHORS │ │ ├── README.txt │ │ ├── gencov │ │ ├── COPYING │ │ ├── hash-pointer.c │ │ ├── hash-int.c │ │ ├── Makefile.am │ │ ├── compare-pointer.c │ │ └── hash-int.h │ │ ├── AnsiLove-C-master │ │ ├── README.txt │ │ ├── strtolower.c │ │ ├── filesize.h │ │ ├── strtolower.h │ │ ├── CMakeLists.txt │ │ ├── AUTHORS │ │ ├── explode.h │ │ ├── filesize.c │ │ └── explode.c │ │ ├── README.txt │ │ └── sassert │ │ ├── conditional.c │ │ └── usual_arith_conv.c ├── opt.h ├── ast2c.h ├── luxld │ ├── arm.h │ ├── x64.h │ ├── x86.h │ ├── mips.h │ ├── out.h │ ├── copy.h │ ├── README │ └── makefile ├── sassert.h ├── arm_cgen │ ├── arm_cgen.h │ └── makefile ├── x64_cgen │ ├── x64_cgen.h │ └── makefile ├── x86_cgen │ ├── x86_cgen.h │ └── makefile ├── mips_cgen │ ├── mips_cgen.h │ └── makefile ├── vm32_cgen │ ├── vm32_cgen.h │ └── makefile ├── vm64_cgen │ ├── vm64_cgen.h │ └── makefile ├── luxdvr │ ├── vm32.conf │ ├── vm64.conf │ ├── x64.conf │ ├── x86.conf │ ├── glibc_x64.conf │ ├── arm.conf │ ├── glibc_x86.conf │ ├── mips.conf │ ├── musl_mips.conf │ ├── musl_x64.conf │ ├── musl_x86.conf │ ├── makefile │ ├── musl_arm.conf │ ├── glibc_arm.conf │ └── glibc_mips.conf ├── luxvm │ ├── operations.h │ ├── as.h │ └── makefile ├── loc.h ├── tools │ ├── makefile │ └── regex.h ├── util │ ├── arena.h │ ├── makefile │ ├── ELF_util.h │ ├── str.h │ ├── bset.h │ └── util.h ├── error.h ├── imp_lim.h ├── luxarm │ └── makefile ├── luxmips │ └── makefile ├── stmt.h ├── luxx86 │ └── makefile ├── luxcc.h ├── opt.c ├── dflow.h ├── pre.h ├── expr.h └── error.c ├── scripts ├── self_x64.sh ├── self_x86.sh ├── test_com_x64.sh ├── test_com_x86.sh ├── runarmelexe.sh ├── test_exe_x64.sh ├── test_exe_x86.sh ├── runmipselexe.sh ├── find_diff.sh ├── testall.sh ├── testall_vm.sh ├── testall_x86.sh ├── testall_x64.sh ├── self_copy.sh ├── testall_arm.sh ├── testall_mips.sh ├── self_arm.sh ├── self_mips.sh ├── self_vm.sh ├── test_com_xXX.sh ├── test_com_vm.sh ├── self1_arm.sh ├── self2_arm.sh ├── self1_mips.sh ├── self_xXX.sh ├── self2_mips.sh ├── self1_vm.sh └── self2_vm.sh └── doc └── res ├── img1.png ├── img2.png ├── img3.png ├── img4.png └── img5.png /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.bak 3 | *.a 4 | -------------------------------------------------------------------------------- /src/lib/vm_lib/errno.c: -------------------------------------------------------------------------------- 1 | int errno; 2 | -------------------------------------------------------------------------------- /src/lib/obj/arm/README: -------------------------------------------------------------------------------- 1 | ARM library files. 2 | -------------------------------------------------------------------------------- /src/lib/obj/mips/README: -------------------------------------------------------------------------------- 1 | MIPS library files. 2 | -------------------------------------------------------------------------------- /src/lib/obj/x64/README: -------------------------------------------------------------------------------- 1 | x64 library files. 2 | -------------------------------------------------------------------------------- /src/lib/obj/x86/README: -------------------------------------------------------------------------------- 1 | x86 library files. 2 | -------------------------------------------------------------------------------- /src/lib/obj/vm32/README: -------------------------------------------------------------------------------- 1 | LuxVM32 library files. 2 | -------------------------------------------------------------------------------- /src/lib/obj/vm64/README: -------------------------------------------------------------------------------- 1 | LuxVM64 library files. 2 | -------------------------------------------------------------------------------- /src/lib/errno.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int errno; 4 | -------------------------------------------------------------------------------- /src/lib/obj/arm/pic/README: -------------------------------------------------------------------------------- 1 | ARM library files (pic version). 2 | -------------------------------------------------------------------------------- /src/lib/obj/x64/pic/README: -------------------------------------------------------------------------------- 1 | x64 library files (pic version). 2 | -------------------------------------------------------------------------------- /src/lib/obj/x86/pic/README: -------------------------------------------------------------------------------- 1 | x86 library files (pic version). 2 | -------------------------------------------------------------------------------- /src/lib/obj/mips/pic/README: -------------------------------------------------------------------------------- 1 | MIPS library files (pic version). 2 | -------------------------------------------------------------------------------- /src/tests/execute/other/T-Rex-master/.gitignore: -------------------------------------------------------------------------------- 1 | tags 2 | build 3 | -------------------------------------------------------------------------------- /src/tests/execute/AES/README.txt: -------------------------------------------------------------------------------- 1 | from https://github.com/dhuertas/AES 2 | -------------------------------------------------------------------------------- /scripts/self_x64.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | /bin/bash scripts/self_xXX.sh -mx64 3 | -------------------------------------------------------------------------------- /scripts/self_x86.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | /bin/bash scripts/self_xXX.sh -mx86 3 | -------------------------------------------------------------------------------- /src/tests/execute/cc65/README.txt: -------------------------------------------------------------------------------- 1 | Some test programs from cc65 test suite. 2 | -------------------------------------------------------------------------------- /src/tests/execute/llvm/README.txt: -------------------------------------------------------------------------------- 1 | Some benchmarks from LLVM's test-suite. 2 | -------------------------------------------------------------------------------- /src/tests/execute/other/c4/c4.expect: -------------------------------------------------------------------------------- 1 | hello, world 2 | exit(0) cycle = 9 3 | -------------------------------------------------------------------------------- /doc/res/img1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/moneytech/LuxCC/HEAD/doc/res/img1.png -------------------------------------------------------------------------------- /doc/res/img2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/moneytech/LuxCC/HEAD/doc/res/img2.png -------------------------------------------------------------------------------- /doc/res/img3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/moneytech/LuxCC/HEAD/doc/res/img3.png -------------------------------------------------------------------------------- /doc/res/img4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/moneytech/LuxCC/HEAD/doc/res/img4.png -------------------------------------------------------------------------------- /doc/res/img5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/moneytech/LuxCC/HEAD/doc/res/img5.png -------------------------------------------------------------------------------- /scripts/test_com_x64.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | /bin/bash scripts/test_com_xXX.sh -mx64 3 | -------------------------------------------------------------------------------- /scripts/test_com_x86.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | /bin/bash scripts/test_com_xXX.sh -mx86 3 | -------------------------------------------------------------------------------- /src/tests/execute/other/abc-compiler/README.txt: -------------------------------------------------------------------------------- 1 | from https://github.com/aap/abc 2 | -------------------------------------------------------------------------------- /scripts/runarmelexe.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | qemu-arm -L /usr/arm-linux-gnueabi $1 4 | -------------------------------------------------------------------------------- /scripts/test_exe_x64.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | /bin/bash scripts/test_exe_xXX.sh -mx64 $1 3 | -------------------------------------------------------------------------------- /scripts/test_exe_x86.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | /bin/bash scripts/test_exe_xXX.sh -mx86 $1 3 | -------------------------------------------------------------------------------- /src/tests/execute/AES/README.md: -------------------------------------------------------------------------------- 1 | AES 2 | === 3 | 4 | AES algorithm implementation using C -------------------------------------------------------------------------------- /src/tests/execute/picoc_tcc/README.txt: -------------------------------------------------------------------------------- 1 | Some test programs from picoc/tcc test suite. 2 | -------------------------------------------------------------------------------- /src/opt.h: -------------------------------------------------------------------------------- 1 | #ifndef OPT_H_ 2 | #define OPT_H_ 3 | 4 | void opt_main(void); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /src/tests/analyze/README.txt: -------------------------------------------------------------------------------- 1 | These test are meant to be run using the program 'tester'. 2 | -------------------------------------------------------------------------------- /src/tests/compile/c-algorithms/AUTHORS: -------------------------------------------------------------------------------- 1 | Simon Howard 2 | -------------------------------------------------------------------------------- /src/tests/compile/c-algorithms/README.txt: -------------------------------------------------------------------------------- 1 | from https://github.com/fragglet/c-algorithms 2 | -------------------------------------------------------------------------------- /src/tests/execute/other/ELFkickers/README.txt: -------------------------------------------------------------------------------- 1 | from https://github.com/BR903/ELFkickers 2 | -------------------------------------------------------------------------------- /src/tests/execute/other/T-Rex-master/README.txt: -------------------------------------------------------------------------------- 1 | from https://github.com/kimperator/T-Rex 2 | -------------------------------------------------------------------------------- /src/lib/obj/arm/libc.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/moneytech/LuxCC/HEAD/src/lib/obj/arm/libc.so -------------------------------------------------------------------------------- /src/lib/obj/x64/libc.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/moneytech/LuxCC/HEAD/src/lib/obj/x64/libc.so -------------------------------------------------------------------------------- /src/lib/obj/x86/libc.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/moneytech/LuxCC/HEAD/src/lib/obj/x86/libc.so -------------------------------------------------------------------------------- /src/tests/compile/AnsiLove-C-master/README.txt: -------------------------------------------------------------------------------- 1 | from https://github.com/ansilove/AnsiLove-C 2 | -------------------------------------------------------------------------------- /src/tests/execute/other/crypto-simple/README.txt: -------------------------------------------------------------------------------- 1 | from https://github.com/chrishulbert/crypto 2 | -------------------------------------------------------------------------------- /src/tests/execute/other/tiny-AES128-C/README.txt: -------------------------------------------------------------------------------- 1 | from https://github.com/kokke/tiny-AES128-C 2 | -------------------------------------------------------------------------------- /src/lib/obj/mips/libc.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/moneytech/LuxCC/HEAD/src/lib/obj/mips/libc.so -------------------------------------------------------------------------------- /src/lib/include/memory.h: -------------------------------------------------------------------------------- 1 | #ifndef _MEMORY_H 2 | #define _MEMORY_H 3 | 4 | #include 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /src/lib/vm_lib/include/memory.h: -------------------------------------------------------------------------------- 1 | #ifndef _MEMORY_H 2 | #define _MEMORY_H 3 | 4 | #include 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /src/lib/vm_lib/include/unistd.h: -------------------------------------------------------------------------------- 1 | #ifndef _UNISTD_H 2 | #define _UNISTD_H 3 | 4 | int isatty(int fd); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /src/tests/analyze/incomplete.c: -------------------------------------------------------------------------------- 1 | struct A bar(void) { } // @ error "return type is an incomplete type" 2 | 3 | int xyz; 4 | -------------------------------------------------------------------------------- /src/ast2c.h: -------------------------------------------------------------------------------- 1 | #ifndef AST2C_H_ 2 | #define AST2C_H_ 3 | 4 | #include "parser.h" 5 | 6 | char *ast2c(ExecNode *n); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /scripts/runmipselexe.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | qemu-mipsel /usr/mipsel-linux-gnu/lib/ld.so.1 --library-path /usr/mipsel-linux-gnu/lib $1 4 | -------------------------------------------------------------------------------- /src/tests/execute/other/ELFkickers/test_elf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/moneytech/LuxCC/HEAD/src/tests/execute/other/ELFkickers/test_elf -------------------------------------------------------------------------------- /src/tests/execute/other/c4/hello.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | printf("hello, world\n"); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /src/lib/vm_lib/libc.c: -------------------------------------------------------------------------------- 1 | #include "stdio.c" 2 | #include "string.c" 3 | #include "ctype.c" 4 | /*#include "errno.c"*/ 5 | #include "stdlib.c" 6 | -------------------------------------------------------------------------------- /scripts/find_diff.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | for file in $(find src/tests/self/ | grep '\.c') ; do 4 | cmp "${file%.*}.s" "${file%.*}.s2" 5 | done 6 | -------------------------------------------------------------------------------- /src/luxld/arm.h: -------------------------------------------------------------------------------- 1 | #ifndef ARM_H_ 2 | #define ARM_H_ 3 | 4 | #define ARM_PLT_ENTRY_NB 16 5 | 6 | void arm_apply_relocs(void); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/luxld/x64.h: -------------------------------------------------------------------------------- 1 | #ifndef X64_H_ 2 | #define X64_H_ 3 | 4 | #define X64_PLT_ENTRY_NB 16 5 | 6 | void x64_apply_relocs(void); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/luxld/x86.h: -------------------------------------------------------------------------------- 1 | #ifndef X86_H_ 2 | #define X86_H_ 3 | 4 | #define X86_PLT_ENTRY_NB 16 5 | 6 | void x86_apply_relocs(void); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/sassert.h: -------------------------------------------------------------------------------- 1 | #ifndef _SASSERT_H 2 | #define _SASSERT_H 3 | 4 | #define _ASSERT_TYPE 0 5 | #define _ASSERT_IMMUTABLE 1 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /src/tests/execute/other/ELFkickers/objres.expect: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/moneytech/LuxCC/HEAD/src/tests/execute/other/ELFkickers/objres.expect -------------------------------------------------------------------------------- /src/tests/execute/other/abc-compiler/abc.expect: -------------------------------------------------------------------------------- 1 | 6 2 | hello, world! 3 | hello, world! 4 | 1 args: 5 | src/tests/execute/other/abc-compiler/out1 6 | -------------------------------------------------------------------------------- /src/arm_cgen/arm_cgen.h: -------------------------------------------------------------------------------- 1 | #ifndef ARM_CGEN_H_ 2 | #define ARM_CGEN_H_ 3 | 4 | #include 5 | 6 | void arm_cgen(FILE *outf); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/luxld/mips.h: -------------------------------------------------------------------------------- 1 | #ifndef MIPS_H_ 2 | #define MIPS_H_ 3 | 4 | #define MIPS_PLT_ENTRY_NB 32 5 | 6 | void mips_apply_relocs(void); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/x64_cgen/x64_cgen.h: -------------------------------------------------------------------------------- 1 | #ifndef X64_CGEN_H_ 2 | #define X64_CGEN_H_ 3 | 4 | #include 5 | 6 | void x64_cgen(FILE *outf); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/x86_cgen/x86_cgen.h: -------------------------------------------------------------------------------- 1 | #ifndef X86_CGEN_H_ 2 | #define X86_CGEN_H_ 3 | 4 | #include 5 | 6 | void x86_cgen(FILE *outf); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/mips_cgen/mips_cgen.h: -------------------------------------------------------------------------------- 1 | #ifndef MIPS_CGEN_H_ 2 | #define MIPS_CGEN_H_ 3 | 4 | #include 5 | 6 | void mips_cgen(FILE *outf); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/vm32_cgen/vm32_cgen.h: -------------------------------------------------------------------------------- 1 | #ifndef VM32_CGEN_H_ 2 | #define VM32_CGEN_H_ 3 | 4 | #include 5 | 6 | void vm32_cgen(FILE *outf); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/vm64_cgen/vm64_cgen.h: -------------------------------------------------------------------------------- 1 | #ifndef VM64_CGEN_H_ 2 | #define VM64_CGEN_H_ 3 | 4 | #include 5 | 6 | void vm64_cgen(FILE *outf); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/lib/include/stdbool.h: -------------------------------------------------------------------------------- 1 | #ifndef _STDBOOL 2 | #define _STDBOOL 3 | 4 | typedef unsigned char bool; 5 | #define true 1 6 | #define false 0 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/lib/times.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | clock_t times(struct tms *buf) 5 | { 6 | return syscall(SYS_times, buf); 7 | } 8 | -------------------------------------------------------------------------------- /src/lib/vm_lib/include/stdbool.h: -------------------------------------------------------------------------------- 1 | #ifndef _STDBOOL 2 | #define _STDBOOL 3 | 4 | typedef unsigned char bool; 5 | #define true 1 6 | #define false 0 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/tests/compile/README.txt: -------------------------------------------------------------------------------- 1 | Compiler Acceptance/Rejection/Crash Testing. 2 | 3 | Look at the file `README.txt' in a directory to see where the sources come from. 4 | -------------------------------------------------------------------------------- /src/tests/execute/other/abc-compiler/examples/1_var.b: -------------------------------------------------------------------------------- 1 | main() { 2 | auto a, b, c, sum; 3 | 4 | a = 1; b = 2; c = 3; 5 | sum = a+b+c; 6 | putnumb(sum); 7 | } 8 | -------------------------------------------------------------------------------- /src/tests/execute/other/abc-compiler/examples/4_goto.b: -------------------------------------------------------------------------------- 1 | main() { 2 | auto c; 3 | /*read: 4 | c= getchar(); 5 | putchar(c); 6 | if(c != '*n') goto read;*/ 7 | } 8 | -------------------------------------------------------------------------------- /src/luxld/out.h: -------------------------------------------------------------------------------- 1 | #ifndef OUT_H_ 2 | #define OUT_H_ 3 | 4 | #include 5 | 6 | void write_ELF_file_32(FILE *outf); 7 | void write_ELF_file_64(FILE *outf); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /src/tests/execute/arr1.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | char x[0xFFFFFFFF / 16777216]; 6 | printf("%lu\n", sizeof(x)); 7 | 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /src/lib/ioctl.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int ioctl(int fd, unsigned long request, void *arg) 5 | { 6 | return syscall(SYS_ioctl, fd, request, arg); 7 | } 8 | -------------------------------------------------------------------------------- /src/tests/execute/README.txt: -------------------------------------------------------------------------------- 1 | These test should be compiled and the resultant binaries, when executed, should 2 | produce the same results as those binaries compiled with a reference compiler. 3 | -------------------------------------------------------------------------------- /src/lib/fcntl.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int open(const char *pathname, int flags, mode_t mode) 5 | { 6 | return syscall(SYS_open, pathname, flags, mode); 7 | } 8 | -------------------------------------------------------------------------------- /src/lib/wait.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | pid_t waitpid(pid_t pid, int *status, int options) 5 | { 6 | return syscall(SYS_waitpid, pid, status, options); 7 | } 8 | -------------------------------------------------------------------------------- /src/luxdvr/vm32.conf: -------------------------------------------------------------------------------- 1 | luxcc: src 2 | luxasvm: src/luxvm 3 | luxldvm: src/luxvm 4 | crt0.o: src/lib/obj/vm32, /usr/local/lib/luxcc/obj/vm32 5 | libc.o: src/lib/obj/vm32, /usr/local/lib/luxcc/obj/vm32 6 | -------------------------------------------------------------------------------- /src/luxdvr/vm64.conf: -------------------------------------------------------------------------------- 1 | luxcc: src 2 | luxasvm: src/luxvm 3 | luxldvm: src/luxvm 4 | crt0.o: src/lib/obj/vm64, /usr/local/lib/luxcc/obj/vm64 5 | libc.o: src/lib/obj/vm64, /usr/local/lib/luxcc/obj/vm64 6 | -------------------------------------------------------------------------------- /src/tests/execute/conditional.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | printf("%lld\n", 0 ? 1LL : 2); 6 | printf("%lld\n", 1 ? 1 : 2LL); 7 | 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /src/tests/execute/other/ELFkickers/ebfc/bf/hello.b: -------------------------------------------------------------------------------- 1 | +++++++++[->+>+++++>++++++>+<<<<] 2 | >>>[->++>++>++>++<<<<] 3 | 4 | >>----.---.>..>+++.<<<< 5 | <-.------------.> 6 | >++.>>>.+++.<.<-.<< 7 | <<+. 8 | -------------------------------------------------------------------------------- /src/lib/stime.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int utimes(const char *filename, const struct timeval times[2]) 5 | { 6 | return syscall(SYS_utimes, filename, times); 7 | } 8 | -------------------------------------------------------------------------------- /src/tests/execute/spill2.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int x, *p = &x; 4 | 5 | int main(void) 6 | { 7 | x = 2; 8 | printf("%d\n", x**p); 9 | x = 0; 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /src/tests/execute/stat_init4.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | static char op1[256], op2[256]; 6 | static char *op[2] = { op1, op2 }; 7 | 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /src/lib/termios.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int tcflush(int fd, int queue_selector) 6 | { 7 | return ioctl(fd, TCFLSH, (void *)queue_selector); 8 | } 9 | -------------------------------------------------------------------------------- /src/tests/execute/other/abc-compiler/examples/2_ext.b: -------------------------------------------------------------------------------- 1 | main() { 2 | extrn a, b, c; 3 | putchar(a); putchar(b); putchar(c); putchar('!*n'); 4 | } 5 | 6 | a 'hell'; 7 | b 'o, w'; 8 | c 'orld'; 9 | 10 | -------------------------------------------------------------------------------- /src/lib/include/sys/types.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_TYPES_H 2 | #define _SYS_TYPES_H 3 | 4 | typedef unsigned int mode_t; 5 | typedef long int off_t; 6 | typedef int ssize_t; 7 | typedef int pid_t; 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /src/tests/execute/mac_eol.c: -------------------------------------------------------------------------------- 1 | #include /\ * */ # /* */ defi\ ne FO\ O 10\ 20 char test_string[] = "abc\ pqt\ xyz"; int main(void) { printf("%d\n", FOO); printf("%s\n", test_string); return 0; } -------------------------------------------------------------------------------- /src/tests/execute/other/crypto-algorithms/README.txt: -------------------------------------------------------------------------------- 1 | from https://github.com/B-Con/crypto-algorithms 2 | 3 | Note: the '.expect' file is what I get with clang. With gcc I get the same but the Base64 tests fail. 4 | -------------------------------------------------------------------------------- /src/lib/vm_lib/include/errno.h: -------------------------------------------------------------------------------- 1 | #ifndef _ERRNO_H 2 | #define _ERRNO_H 3 | 4 | #define EDOM 33 5 | #define EILSEQ 84 6 | #define ERANGE 34 7 | 8 | extern int *errno; 9 | #define errno (*errno) 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /src/tests/execute/obfuscated.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /\ 4 | * 5 | */ # /* 6 | */ defi\ 7 | ne FO\ 8 | O 10\ 9 | 20 10 | 11 | int main(void) 12 | { 13 | printf("%d\n", FOO); 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /src/lib/include/sys/wait.h: -------------------------------------------------------------------------------- 1 | #ifndef _WAIT_H 2 | #define _WAIT_H 3 | 4 | #include 5 | 6 | #define WEXITSTATUS(s) (((s)>>8) & 0xFF) 7 | 8 | pid_t waitpid(pid_t pid, int *status, int options); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /src/lib/init.c: -------------------------------------------------------------------------------- 1 | void __libc_init(void) 2 | { 3 | extern void __set_std_buffering(void); /* stdio.c */ 4 | extern void __set_up_heap(void); /* stdlib.c */ 5 | 6 | __set_std_buffering(); 7 | __set_up_heap(); 8 | } 9 | -------------------------------------------------------------------------------- /src/tests/execute/other/crypto-algorithms/crypto.expect: -------------------------------------------------------------------------------- 1 | AES Tests: SUCCEEDED 2 | ARCFOUR tests: SUCCEEDED 3 | Base64 tests: PASSED 4 | Blowfish tests: SUCCEEDED 5 | DES test: SUCCEEDED 6 | MD2 tests: SUCCEEDED 7 | ROT-13 tests: SUCCEEDED 8 | -------------------------------------------------------------------------------- /src/tests/execute/other/abc-compiler/examples/printargs.b: -------------------------------------------------------------------------------- 1 | main() { 2 | extrn argv; 3 | auto i; 4 | 5 | i = 1; 6 | printf("%d args:*n", argv[0]); 7 | while (i <= argv[0]) 8 | printf("%s*n", argv[i++]); 9 | return(0); 10 | } 11 | -------------------------------------------------------------------------------- /src/tests/execute/typedef1.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | typedef int A[]; 6 | A a = { 1, 2 }, b = { 3, 4, 5 }; 7 | 8 | printf("%lu %lu\n", sizeof(a), sizeof(b)); 9 | 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /src/luxld/copy.h: -------------------------------------------------------------------------------- 1 | #ifndef COPY_H_ 2 | #define COPY_H_ 3 | 4 | #include "luxld.h" 5 | 6 | Elf32_Addr new_copy_reloc_32(char *symname, Elf32_Sym *syment); 7 | Elf64_Addr new_copy_reloc_64(char *symname, Elf64_Sym *syment); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /src/tests/execute/empty_param.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void foo(); 4 | 5 | int main() 6 | { 7 | void (*fp)() = foo; 8 | fp(); 9 | return 0; 10 | } 11 | 12 | void foo() 13 | { 14 | printf("Hello and bye!\n"); 15 | } 16 | -------------------------------------------------------------------------------- /src/tests/execute/other/README.txt: -------------------------------------------------------------------------------- 1 | These tests require of customized scripts ('testme.sh' files). 2 | 3 | Currently, these are only run for the x86 backend. 4 | 5 | Look at the file `README.txt' in a directory to see where the sources come from. 6 | -------------------------------------------------------------------------------- /src/luxdvr/x64.conf: -------------------------------------------------------------------------------- 1 | luxcc: src 2 | luxasx86: src/luxx86 3 | luxld: src/luxld 4 | crt0.o: src/lib/obj/x64, /usr/local/lib/luxcc/obj/x64 5 | libc.a: src/lib/obj/x64, /usr/local/lib/luxcc/obj/x64 6 | libc.so: src/lib/obj/x64, /usr/local/lib/luxcc/obj/x64 7 | -------------------------------------------------------------------------------- /src/tests/execute/switch_def_zero.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int x; 4 | 5 | int main(void) 6 | { 7 | switch (x) { 8 | case 0: 9 | default: 10 | printf("OK\n"); 11 | break; 12 | } 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /src/tests/execute/other/abc-compiler/examples/3_fun.b: -------------------------------------------------------------------------------- 1 | main() { 2 | extrn a, b, c, d; 3 | put2char(a,b); 4 | put2char(c,d); 5 | } 6 | 7 | put2char(x,y) { 8 | putchar(x); 9 | putchar(y); 10 | } 11 | 12 | a 'hell'; b 'o, w'; c 'orld'; d '!*n'; 13 | 14 | -------------------------------------------------------------------------------- /src/lib/signal.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int raise(int sig) 6 | { 7 | return kill(getpid(), sig); 8 | } 9 | 10 | int kill(pid_t pid, int sig) 11 | { 12 | return syscall(SYS_kill, pid, sig); 13 | } 14 | -------------------------------------------------------------------------------- /src/tests/execute/typedef2.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef int A[3]; 4 | 5 | struct S { 6 | A x, y; 7 | }; 8 | 9 | int main(void) 10 | { 11 | struct S s = { {1, 2, 3}, {4, 5, 6} }; 12 | printf("%lu\n", sizeof(s)); 13 | 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /src/tests/execute/other/ELFkickers/elfls/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for elfls 2 | 3 | CC = gcc 4 | CFLAGS = -Wall -Wextra -I../elfrw 5 | 6 | elfls: elfls.c ../elfrw/libelfrw.a 7 | 8 | ../elfrw/libelfrw.a: 9 | $(MAKE) -C ../elfrw libelfrw.a 10 | 11 | clean: 12 | rm -f elfls 13 | -------------------------------------------------------------------------------- /src/lib/include/sys/time.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_TIME_H 2 | #define _SYS_TIME_H 3 | 4 | struct timeval { 5 | long tv_sec; /* seconds */ 6 | long tv_usec; /* microseconds */ 7 | }; 8 | 9 | int utimes(const char *filename, const struct timeval times[2]); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /src/tests/execute/other/ELFkickers/objres/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for objres 2 | 3 | CC = gcc 4 | CFLAGS = -Wall -Wextra -I../elfrw 5 | 6 | objres: objres.c ../elfrw/libelfrw.a 7 | 8 | ../elfrw/libelfrw.a: 9 | $(MAKE) -C ../elfrw libelfrw.a 10 | 11 | clean: 12 | rm -f objres 13 | -------------------------------------------------------------------------------- /src/tests/execute/other/ELFkickers/rebind/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for rebind 2 | 3 | CC = gcc 4 | CFLAGS = -Wall -Wextra -I../elfrw 5 | 6 | rebind: rebind.c ../elfrw/libelfrw.a 7 | 8 | ../elfrw/libelfrw.a: 9 | $(MAKE) -C ../elfrw libelfrw.a 10 | 11 | clean: 12 | rm -f rebind 13 | -------------------------------------------------------------------------------- /src/lib/include/stddef.h: -------------------------------------------------------------------------------- 1 | #ifndef _STDDEF_H 2 | #define _STDDEF_H 3 | 4 | #define NULL ((void *)0) 5 | 6 | typedef long ptrdiff_t; 7 | typedef unsigned long size_t; 8 | typedef long wchar_t; 9 | 10 | #define offsetof(type, member) ((size_t)&(((type *)0)->member)) 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /src/luxvm/operations.h: -------------------------------------------------------------------------------- 1 | #ifndef OPERATIONS_H_ 2 | #define OPERATIONS_H_ 3 | 4 | typedef struct Operation Operation; 5 | struct Operation { 6 | char *str; 7 | int opcode; 8 | int has_operand; 9 | }; 10 | 11 | Operation *lookup_operation(char *op_str); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /src/tests/compile/c-algorithms/gencov: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Simple shell script to generate a coverage report. 4 | # 5 | 6 | cd $(dirname $0) 7 | 8 | for d in *.c; do 9 | obj=`echo $d | sed "s/^/libcalgtest_a-/" | sed "s/.c$/.o/"` 10 | 11 | gcov -b -o $obj $d 12 | done 13 | 14 | -------------------------------------------------------------------------------- /src/tests/execute/other/abc-compiler/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS=-Wall -Wextra 2 | b: b0.o b1.o 3 | cc b0.o b1.o -o b 4 | b0.o: b0.c b.h 5 | b1.o: b1.c b.h 6 | 7 | libs: 8 | ./abc -c brt.s lib.b 9 | 10 | install: b abc 11 | cp abc $(HOME)/bin 12 | 13 | %.o: %.s 14 | as --32 $^ -o $@ 15 | 16 | -------------------------------------------------------------------------------- /src/tests/execute/other/abc-compiler/examples/5_while.b: -------------------------------------------------------------------------------- 1 | main() { 2 | /*auto c; 3 | while (1) { 4 | while ( (c=getchar()) != ' ') 5 | if (putchar(c) == '*n') exit(); 6 | putchar( '*n' ); 7 | while ( (c=getchar()) == ' '); 8 | if (putchar(c)=='*n') exit(); 9 | }*/ 10 | } 11 | -------------------------------------------------------------------------------- /src/tests/execute/picoc_tcc/42_function_pointer.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int fred(int p) 4 | { 5 | printf("yo %d\n", p); 6 | return 42; 7 | } 8 | 9 | int (*f)(int) = &fred; 10 | 11 | int main(void) 12 | { 13 | printf("%d\n", (*f)(24)); 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /src/tests/execute/typedef3.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef char Char; 4 | 5 | static void panic(const Char *); 6 | 7 | static void panic(const Char *a) 8 | { 9 | printf(a); 10 | } 11 | 12 | int main(void) 13 | { 14 | panic("hello world!\n"); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /src/lib/stat.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int stat(const char *path, struct stat *buf) 5 | { 6 | return syscall(SYS_stat, path, buf); 7 | } 8 | 9 | int chmod(const char *path, mode_t mode) 10 | { 11 | return syscall(SYS_chmod, path, mode); 12 | } 13 | -------------------------------------------------------------------------------- /src/lib/vm_lib/include/stddef.h: -------------------------------------------------------------------------------- 1 | #ifndef _STDDEF_H 2 | #define _STDDEF_H 3 | 4 | #define NULL (void *)0 5 | 6 | typedef long ptrdiff_t; 7 | typedef unsigned long size_t; 8 | typedef long wchar_t; 9 | 10 | #define offsetof(type, member) ((size_t)&(((type *)0)->member)) 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /src/loc.h: -------------------------------------------------------------------------------- 1 | #ifndef LOC_H_ 2 | #define LOC_H_ 3 | 4 | typedef struct Location Location; 5 | 6 | void location_init(void); 7 | void location_new(char *id, int offset); 8 | int location_get_offset(char *id); 9 | void location_pop_scope(void); 10 | void location_push_scope(void); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /src/tests/execute/while.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | int a; 6 | long long e; 7 | 8 | a = 10; 9 | while (a) 10 | printf("%d", a), a--; 11 | 12 | e = 10; 13 | while (e) 14 | printf("%lld\n", e), e--; 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /src/lib/include/utime.h: -------------------------------------------------------------------------------- 1 | #ifndef _UTIME_H 2 | #define _UTIME_H 3 | 4 | #include 5 | 6 | struct utimbuf { 7 | time_t actime; /* access time */ 8 | time_t modtime; /* modification time */ 9 | }; 10 | 11 | int utime(const char *filename, const struct utimbuf *times); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /src/luxdvr/x86.conf: -------------------------------------------------------------------------------- 1 | luxcc: src 2 | luxasx86: src/luxx86 3 | luxld: src/luxld 4 | liblux.o: src/lib/obj/x86, /usr/local/lib/luxcc/obj/x86 5 | crt0.o: src/lib/obj/x86, /usr/local/lib/luxcc/obj/x86 6 | libc.a: src/lib/obj/x86, /usr/local/lib/luxcc/obj/x86 7 | libc.so: src/lib/obj/x86, /usr/local/lib/luxcc/obj/x86 8 | -------------------------------------------------------------------------------- /src/lib/include/assert.h: -------------------------------------------------------------------------------- 1 | #ifndef _ASSERT_H 2 | #define _ASSERT_H 3 | 4 | void __assert(const char *, const char *, int); 5 | 6 | #ifndef NDEBUG 7 | #define assert(expr) ((expr) ? (void)0 : __assert(__FILE__, __func__, __LINE__)) 8 | #else 9 | #define assert(expr) ((void)0) 10 | #endif 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /src/luxvm/as.h: -------------------------------------------------------------------------------- 1 | #ifndef AS_H_ 2 | #define AS_H_ 3 | 4 | enum { /* Symbol.kind */ 5 | LOCAL_SYM, 6 | GLOBAL_SYM, 7 | EXTERN_SYM 8 | }; 9 | 10 | enum { 11 | DATA_SEG, 12 | TEXT_SEG, 13 | BSS_SEG 14 | }; 15 | 16 | #define MAX_SYM_LEN 64 /* symbol name max length */ 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /src/tests/execute/tent.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int x1[]; 4 | 5 | struct foo x2; 6 | struct foo { char i[3]; }; 7 | 8 | static struct bar x3; 9 | struct bar { int i[3]; }; 10 | 11 | static int x4[]; /* rejected by gcc when invoked with -pedantic */ 12 | 13 | int main(void) 14 | { 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /scripts/testall.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if uname -i | grep -q "i386"; then 4 | /bin/bash scripts/testall_x86.sh 5 | else 6 | /bin/bash scripts/testall_x64.sh 7 | fi 8 | /bin/bash scripts/testall_vm.sh 9 | /bin/bash scripts/testall_mips.sh 10 | /bin/bash scripts/testall_arm.sh 11 | src/tools/tester src/tests/analyze/*.c 12 | -------------------------------------------------------------------------------- /src/tests/execute/other/crypto-simple/c/c_aes.expect: -------------------------------------------------------------------------------- 1 | Test AES 2 | 3 | Key: 12345612345612345612345612345612 4 | Original: abcdefabcdefabcdefabcdefabcdefab 5 | Encrypted should be: 85E5A3D7356A61E29A8AFA559AD67102 6 | Encrypted: 85e5a3d7356a61e29a8afa559ad67102 7 | Decrypted: abcdefabcdefabcdefabcdefabcdefab 8 | -------------------------------------------------------------------------------- /src/luxdvr/glibc_x64.conf: -------------------------------------------------------------------------------- 1 | luxcc: src 2 | luxasx86: src/luxx86 3 | 4 | # Paths for Ubuntu 14.04 (64-bits). Modify if necessary. 5 | crt1.o: /usr/lib/x86_64-linux-gnu 6 | crti.o: /usr/lib/x86_64-linux-gnu 7 | crtn.o: /usr/lib/x86_64-linux-gnu 8 | libc.so.6: /lib/x86_64-linux-gnu 9 | libc_nonshared.a: /usr/lib/x86_64-linux-gnu 10 | -------------------------------------------------------------------------------- /src/tests/execute/tags.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct A { /* (1) */ 4 | int a[2]; 5 | } x; 6 | 7 | int main(void) 8 | { 9 | struct A; /* hides (1) */ 10 | struct A *y; 11 | struct A { 12 | int a[3]; 13 | }; 14 | printf("%lu != %lu\n", sizeof(x), sizeof(*y)); 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /src/tools/makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | CFLAGS=-c -g -Wall 3 | OBJS = tester.o regex.o 4 | 5 | all: tester 6 | 7 | tester: tester.o regex.o 8 | $(CC) -o tester tester.o regex.o 9 | .c.o: 10 | $(CC) $(CFLAGS) $*.c 11 | clean: 12 | rm -f $(OBJS) tester 13 | 14 | tester.o: regex.h 15 | regex.o: regex.h 16 | 17 | .PHONY: all clean 18 | -------------------------------------------------------------------------------- /src/lib/assert.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #define MSG "Assertion failed in file %s, function %s(), line %d\n" 7 | 8 | void __assert(const char *file, const char *func, int line) 9 | { 10 | fprintf(stderr, MSG, file, func, line); 11 | abort(); 12 | } 13 | -------------------------------------------------------------------------------- /src/tests/execute/dos_eol.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /\ 4 | * 5 | */ # /* 6 | */ defi\ 7 | ne FO\ 8 | O 10\ 9 | 20 10 | 11 | char test_string[] = "abc\ 12 | pqt\ 13 | xyz"; 14 | 15 | int main(void) 16 | { 17 | printf("%d\n", FOO); 18 | printf("%s\n", test_string); 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /src/lib/include/signal.h: -------------------------------------------------------------------------------- 1 | #ifndef _SIGNAL_H 2 | #define _SIGNAL_H 3 | 4 | #include 5 | 6 | #define SIGABRT 6 7 | 8 | // =========== 9 | // Standard C 10 | // =========== 11 | 12 | int raise(int sig); 13 | 14 | // =========== 15 | // POSIX 16 | // =========== 17 | 18 | int kill(pid_t pid, int sig); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /src/lib/include/iso646.h: -------------------------------------------------------------------------------- 1 | #ifndef _ISO646_H 2 | #define _ISO646_H 3 | 4 | #define and && 5 | #define and_eq &= 6 | #define bitand & 7 | #define bitor | 8 | #define compl ~ 9 | #define not ! 10 | #define not_eq != 11 | #define or || 12 | #define or_eq |= 13 | #define xor ^ 14 | #define xor_eq ^= 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /src/tests/execute/fptr.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void foo(int x) { printf("foo(%d)\n", x); } 4 | 5 | int main(void) 6 | { 7 | foo(1); 8 | (*foo)(2); 9 | (**foo)(3); 10 | (***foo)(4); 11 | (****foo)(5); 12 | (***&foo)(6); 13 | (**&foo)(7); 14 | (*&foo)(8); 15 | (&foo)(9); 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /src/tests/execute/func_cast.c: -------------------------------------------------------------------------------- 1 | int main(void) 2 | { 3 | /* 4 | * Example from 'Expert C Programming: Deep C Secrets'. 5 | */ 6 | extern int printf(const char *, ...); 7 | void *f = (void *)printf; 8 | 9 | (*(int (*)(const char *, ...))f)("Bite my shorts. Also my chars and ints\n"); 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /src/tests/execute/other/T-Rex-master/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | project(crul C) 3 | 4 | ADD_LIBRARY(trex STATIC trex) 5 | 6 | SET(BUILD_TREX_TESTS ON CACHE BOOL "Build Tests") 7 | 8 | if(BUILD_TREX_TESTS) 9 | ADD_EXECUTABLE(trex_test test) 10 | TARGET_LINK_LIBRARIES(trex_test trex) 11 | endif(BUILD_TREX_TESTS) 12 | -------------------------------------------------------------------------------- /src/tests/execute/void_cond.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void foo(void) 4 | { 5 | printf("foo()\n"); 6 | } 7 | 8 | void bar(void) 9 | { 10 | printf("bar()\n"); 11 | } 12 | 13 | int main(void) 14 | { 15 | int x; 16 | 17 | x = 0; 18 | x ? foo():bar(); 19 | x = 1; 20 | x ? foo():bar(); 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /src/tests/execute/other/c4/README.md: -------------------------------------------------------------------------------- 1 | c4 - C in four functions 2 | ======================== 3 | 4 | An exercise in minimalism. 5 | 6 | Try the following: 7 | 8 | gcc -o c4 c4.c (you may need the -m32 option on 64bit machines) 9 | ./c4 hello.c 10 | ./c4 -s hello.c 11 | 12 | ./c4 c4.c hello.c 13 | ./c4 c4.c c4.c hello.c 14 | 15 | -------------------------------------------------------------------------------- /src/tests/execute/other/crypto-simple/c/c_des.expect: -------------------------------------------------------------------------------- 1 | Test Triple DES (2-block CBC, with variant key) 2 | 3 | Key: 68addfd661150e8c1c102f6ba2a8754a 4 | Variant key: 2c6d9b1625d54a4c58d06babe668318a 5 | Original: bf54499d8f3e8a49a134bc5875c14679 6 | Encrypted: 11b96c137ef10b7f5343e70402e0a7f3 7 | Decrypted: bf54499d8f3e8a49a134bc5875c14679 8 | -------------------------------------------------------------------------------- /src/util/arena.h: -------------------------------------------------------------------------------- 1 | #ifndef ARENA_H_ 2 | #define ARENA_H_ 3 | 4 | /* growable memory arena */ 5 | typedef struct Arena Arena; 6 | 7 | Arena *arena_new(unsigned size, int zero); 8 | void *arena_alloc(Arena *a, unsigned n); 9 | void arena_reset(Arena *a); 10 | void arena_destroy(Arena *a); 11 | void arena_set_nom_siz(Arena *a, unsigned size); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /src/luxdvr/arm.conf: -------------------------------------------------------------------------------- 1 | luxcc: src 2 | luxasarm: src/luxarm 3 | luxld: src/luxld 4 | luxmemcpy.o: src/lib/obj/arm, /usr/local/lib/luxcc/obj/arm 5 | liblux.o: src/lib/obj/arm, /usr/local/lib/luxcc/obj/arm 6 | crt0.o: src/lib/obj/arm, /usr/local/lib/luxcc/obj/arm 7 | libc.a: src/lib/obj/arm, /usr/local/lib/luxcc/obj/arm 8 | libc.so: src/lib/obj/arm, /usr/local/lib/luxcc/obj/arm 9 | -------------------------------------------------------------------------------- /src/tests/execute/picoc_tcc/16_nesting.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | int x, y, z; 6 | 7 | for (x = 0; x < 2; x++) 8 | { 9 | for (y = 0; y < 3; y++) 10 | { 11 | for (z = 0; z < 3; z++) 12 | { 13 | printf("%d %d %d\n", x, y, z); 14 | } 15 | } 16 | } 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /src/lib/vm_lib/include/sys/stat.h: -------------------------------------------------------------------------------- 1 | #ifndef _STAT_H 2 | #define _STAT_H 3 | 4 | #if defined __LP64__ 5 | #define _STAT_STRUCT_SIZE 144 /* in 64-bit glibc */ 6 | #else 7 | #define _STAT_STRUCT_SIZE 88 /* in 32-bit glibc */ 8 | #endif 9 | 10 | struct stat { 11 | char a[_STAT_STRUCT_SIZE]; 12 | }; 13 | 14 | int stat(const char *path, struct stat *buf); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /src/luxdvr/glibc_x86.conf: -------------------------------------------------------------------------------- 1 | luxcc: src 2 | luxasx86: src/luxx86 3 | liblux.o: src/lib/obj/x86, /usr/local/lib/luxcc/obj/x86 4 | 5 | # Paths for Ubuntu 12.04 (32-bits). Modify if necessary. 6 | crt1.o: /usr/lib/i386-linux-gnu 7 | crti.o: /usr/lib/i386-linux-gnu 8 | crtn.o: /usr/lib/i386-linux-gnu 9 | libc.so.6: /lib/i386-linux-gnu 10 | libc_nonshared.a: /usr/lib/i386-linux-gnu 11 | -------------------------------------------------------------------------------- /src/luxdvr/mips.conf: -------------------------------------------------------------------------------- 1 | luxcc: src 2 | luxasmips: src/luxmips 3 | luxld: src/luxld 4 | luxmemcpy.o: src/lib/obj/mips, /usr/local/lib/luxcc/obj/mips 5 | liblux.o: src/lib/obj/mips, /usr/local/lib/luxcc/obj/mips 6 | crt0.o: src/lib/obj/mips, /usr/local/lib/luxcc/obj/mips 7 | libc.a: src/lib/obj/mips, /usr/local/lib/luxcc/obj/mips 8 | libc.so: src/lib/obj/mips, /usr/local/lib/luxcc/obj/mips 9 | -------------------------------------------------------------------------------- /src/lib/include/sys/times.h: -------------------------------------------------------------------------------- 1 | #ifndef _TIMES_H 2 | #define _TIMES_H 3 | 4 | #include 5 | 6 | struct tms { 7 | clock_t tms_utime; /* user time */ 8 | clock_t tms_stime; /* system time */ 9 | clock_t tms_cutime; /* user time of children */ 10 | clock_t tms_cstime; /* system time of children */ 11 | }; 12 | 13 | clock_t times(struct tms *buf); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /src/util/makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | CFLAGS=-c -g -fwrapv -Wall -Wconversion -Wno-switch -Wno-parentheses -Wno-sign-conversion 3 | 4 | all: arena.o bset.o ELF_util.o str.o util.o 5 | 6 | .c.o: 7 | $(CC) $(CFLAGS) $*.c 8 | 9 | clean: 10 | rm -f *.o 11 | 12 | arena.o: arena.h 13 | bset.o: bset.h 14 | ELF_util.o: ELF_util.h 15 | str.o: str.h 16 | util.o: util.h 17 | 18 | .PHONY: all clean 19 | -------------------------------------------------------------------------------- /src/tests/execute/other/abc-compiler/link.ld: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT("elf32-i386") 2 | OUTPUT_ARCH(i386) 3 | 4 | ENTRY(start) 5 | 6 | SECTIONS 7 | { 8 | . = 0x400000; 9 | .text : { *(.text) } 10 | . = 0x8000000; 11 | .data : { 12 | *(.data) 13 | __bsymb = .; 14 | *(.bsymb) 15 | __ebsymb = .; 16 | } 17 | . = ALIGN(16); 18 | __bss = .; 19 | .bss : { *(.bss) } 20 | __ebss = .; 21 | } 22 | -------------------------------------------------------------------------------- /src/tests/execute/fold.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | int si; 6 | unsigned ui; 7 | 8 | si = -1; 9 | ui = (unsigned)-1; 10 | 11 | printf("%d\n", si*2); 12 | printf("%u\n", ui*2); 13 | 14 | printf("%d\n", si/2); 15 | printf("%u\n", ui/2); 16 | 17 | printf("%d\n", si%2); 18 | printf("%u\n", ui%2); 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /src/lib/vm_lib/include/stdarg.h: -------------------------------------------------------------------------------- 1 | #ifndef _STDARG_H 2 | #define _STDARG_H 3 | 4 | #define _INTSIZEOF(n) ((sizeof(n)+sizeof(int)-1) & ~(sizeof(int)-1)) 5 | 6 | typedef char *va_list; 7 | 8 | #define va_start(ap, last) (ap = (char *)&(last)) 9 | #define va_arg(ap, type) (ap-=_INTSIZEOF(type), *(type *)(ap)) 10 | #define va_copy(dest, src) (dest) = (src) 11 | #define va_end(ap) 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /src/vm32_cgen/makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | CFLAGS=-c -g -fwrapv -Wall -Wconversion -Wno-switch -Wno-parentheses -Wno-sign-conversion 3 | 4 | all: vm32_cgen.c vm32_cgen.h ../decl.h ../parser.h ../lexer.h ../pre.h ../expr.h ../stmt.h \ 5 | ../imp_lim.h ../error.h ../loc.h ../util/util.h ../util/arena.h ../util/str.h 6 | $(CC) $(CFLAGS) vm32_cgen.c 7 | 8 | clean: 9 | rm -f *.o 10 | 11 | .PHONY: all clean 12 | -------------------------------------------------------------------------------- /src/vm64_cgen/makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | CFLAGS=-c -g -fwrapv -Wall -Wconversion -Wno-switch -Wno-parentheses -Wno-sign-conversion 3 | 4 | all: vm64_cgen.c vm64_cgen.c ../decl.h ../parser.h ../lexer.h ../pre.h ../expr.h ../stmt.h \ 5 | ../imp_lim.h ../error.h ../loc.h ../util/util.h ../util/arena.h ../util/str.h 6 | $(CC) $(CFLAGS) vm64_cgen.c 7 | 8 | clean: 9 | rm -f *.o 10 | 11 | .PHONY: all clean 12 | -------------------------------------------------------------------------------- /src/error.h: -------------------------------------------------------------------------------- 1 | #ifndef ERROR_H_ 2 | #define ERROR_H_ 3 | 4 | #define ERROR_COLOR "\x1b[1;31m" 5 | #define WARNING_COLOR "\x1b[1;33m" 6 | #define INFO_COLOR "\x1b[1;37m" 7 | #define RESET_ATTR "\x1b[0m" 8 | 9 | void emit_error(int fatal, char *file, int line, int column, char *fmt, ...); 10 | void emit_warning(char *file, int line, int column, char *fmt, ...); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /src/tests/execute/fib.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int fib(int n) 4 | { 5 | if (n < 2) 6 | return n; 7 | else 8 | return fib(n-1) + fib(n-2); 9 | } 10 | 11 | int fib2(int n) { return (n<2 ? n : fib(n-1)+fib(n-2)); } 12 | 13 | int main(void) 14 | { 15 | int t = 0; 16 | 17 | while(t < 20) 18 | printf("fib(%d)=%d\n", t, fib(t)), ++t; 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /src/arm_cgen/makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | CFLAGS=-c -g -fwrapv -Wall -Wconversion -Wno-switch -Wno-parentheses -Wno-sign-conversion 3 | 4 | all: arm_cgen.c arm_cgen.h ../decl.h ../parser.h ../lexer.h ../pre.h ../expr.h ../ic.h \ 5 | ../imp_lim.h ../error.h ../dflow.h ../util/util.h ../util/arena.h ../util/bset.h ../util/str.h 6 | $(CC) $(CFLAGS) arm_cgen.c 7 | 8 | clean: 9 | rm -f *.o 10 | 11 | .PHONY: all clean 12 | -------------------------------------------------------------------------------- /src/tests/execute/nested_calls.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int f(int x1, int x2, int x3, int x4, int x5) 4 | { 5 | return x1+x2+x3+x4+x5; 6 | } 7 | 8 | int main(void) 9 | { 10 | printf("%d\n", f(f(f(15, 25, 35, 45, 55), 66, 77, 88, 99), f(1000, 2000, 3000, 4000, 5000), 11 | f(9323, 2504, 7732, 203, 123), f(f(44, 1990, 3003, 101, 102), 843, 12, 1200, 388), 729)); 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /src/x64_cgen/makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | CFLAGS=-c -g -fwrapv -Wall -Wconversion -Wno-switch -Wno-parentheses -Wno-sign-conversion 3 | 4 | all: x64_cgen.c x64_cgen.h ../decl.h ../parser.h ../lexer.h ../pre.h ../expr.h ../ic.h \ 5 | ../imp_lim.h ../error.h ../dflow.h ../util/util.h ../util/arena.h ../util/bset.h ../util/str.h 6 | $(CC) $(CFLAGS) x64_cgen.c 7 | 8 | clean: 9 | rm -f *.o 10 | 11 | .PHONY: all clean 12 | -------------------------------------------------------------------------------- /src/x86_cgen/makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | CFLAGS=-c -g -fwrapv -Wall -Wconversion -Wno-switch -Wno-parentheses -Wno-sign-conversion 3 | 4 | all: x86_cgen.c x86_cgen.h ../decl.h ../parser.h ../lexer.h ../pre.h ../expr.h ../ic.h \ 5 | ../imp_lim.h ../error.h ../dflow.h ../util/util.h ../util/arena.h ../util/bset.h ../util/str.h 6 | $(CC) $(CFLAGS) x86_cgen.c 7 | 8 | clean: 9 | rm -f *.o 10 | 11 | .PHONY: all clean 12 | -------------------------------------------------------------------------------- /src/mips_cgen/makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | CFLAGS=-c -g -fwrapv -Wall -Wconversion -Wno-switch -Wno-parentheses -Wno-sign-conversion 3 | 4 | all: mips_cgen.c mips_cgen.h ../decl.h ../parser.h ../lexer.h ../pre.h ../expr.h ../ic.h \ 5 | ../imp_lim.h ../error.h ../dflow.h ../util/util.h ../util/arena.h ../util/bset.h ../util/str.h 6 | $(CC) $(CFLAGS) mips_cgen.c 7 | 8 | clean: 9 | rm -f *.o 10 | 11 | .PHONY: all clean 12 | -------------------------------------------------------------------------------- /src/tests/execute/endian.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | unsigned x = 0xAABBCCDD; 6 | unsigned char *p; 7 | 8 | for (p = &x; p < (unsigned char *)&x+4; p++) 9 | printf("%x\n", *p); 10 | 11 | /* again */ 12 | p = &x; 13 | printf("%x\n", p[0]); 14 | printf("%x\n", p[1]); 15 | printf("%x\n", p[2]); 16 | printf("%x\n", p[3]); 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /src/tests/execute/return_struct.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef struct { 4 | char s[32]; 5 | } S; 6 | 7 | S f3(void) 8 | { 9 | S r = { "hello world" }; 10 | return r; 11 | } 12 | 13 | S f2(void) 14 | { 15 | return f3(); 16 | } 17 | 18 | S f1(void) 19 | { 20 | return f2(); 21 | } 22 | 23 | int main(void) 24 | { 25 | S x = f1(); 26 | printf("%s\n", x.s); 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /src/tests/execute/scope.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int x = 1; 4 | 5 | int main(void) 6 | { 7 | printf("%d\n", x); 8 | x = 2; 9 | printf("%d\n", x); 10 | { 11 | int x; 12 | x = 3; 13 | printf("%d\n", x); 14 | { 15 | int x; 16 | x = 4; 17 | printf("%d\n", x); 18 | } 19 | } 20 | printf("%d\n", x); 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /src/lib/include/ctype.h: -------------------------------------------------------------------------------- 1 | #ifndef _CTYPE_H 2 | #define _CTYPE_H 3 | 4 | int isalnum(int c); 5 | int isalpha(int c); 6 | int isblank(int c); 7 | int iscntrl(int c); 8 | int isdigit(int c); 9 | int isgraph(int c); 10 | int islower(int c); 11 | int isprint(int c); 12 | int ispunct(int c); 13 | int isspace(int c); 14 | int isupper(int c); 15 | int isxdigit(int c); 16 | 17 | int tolower(int c); 18 | int toupper(int c); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /src/tests/execute/aggregates_and_extern.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef struct A A; 4 | 5 | struct A { 6 | int x; 7 | int y; 8 | }; 9 | 10 | extern A g; /* install_external_id() is called */ 11 | A g = { 10, 20 }; /* analyze_init_declarator() should update the 12 | previously installed entry */ 13 | 14 | int main(void) 15 | { 16 | printf("%d %d\n", g.x, g.y); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /src/tests/execute/for.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | int a; 6 | long long e; 7 | 8 | for (a = 10; a >= 0; a--) 9 | printf(">%d\n", a); 10 | 11 | for (e = 10; e >= 0; e--) 12 | printf(">>%lld\n", e); 13 | 14 | for (a = 10; ; a--) 15 | if (!a) 16 | break; 17 | else 18 | printf(">>>%d\n", a); 19 | printf(">>>>%d\n", a); 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /scripts/testall_vm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if uname -i | grep -q "i386"; then 4 | CURRTAR="VM32" 5 | else 6 | CURRTAR="VM64" 7 | fi 8 | echo "=============================" 9 | echo " START $CURRTAR TESTS" 10 | echo "=============================" 11 | 12 | scripts/self_vm.sh && 13 | scripts/test_exe_vm.sh && 14 | scripts/test_com_vm.sh 15 | 16 | echo "=============================" 17 | echo " END $CURRTAR TESTS" 18 | echo "=============================" 19 | -------------------------------------------------------------------------------- /src/imp_lim.h: -------------------------------------------------------------------------------- 1 | #ifndef IMP_LIM_H_ 2 | #define IMP_LIM_H_ 3 | 4 | /* 5 | * Some implementation limits (not necessarily standard-compliant). 6 | */ 7 | 8 | #define MAX_NEST 16 /* maximum block nesting level (blocks without locals don't count) */ 9 | #define MAX_SWITCH_NEST 16 10 | #define MAX_LOG_LINE_LEN 4095 11 | #define MAX_CASE_LABELS 1024 /* for a single switch statement */ 12 | #define MAX_GOTOS_PER_FUNC 64 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /src/luxdvr/musl_mips.conf: -------------------------------------------------------------------------------- 1 | luxcc: src 2 | luxasmips: src/luxasmips 3 | liblux.o: src/lib/obj/mips, /usr/local/lib/luxcc/obj/mips 4 | luxmemcpy.o: src/lib/obj/mips, /usr/local/lib/luxcc/obj/mips 5 | 6 | # 7 | # Compile or get these files from somewhere and adjust the paths. 8 | # You can get precompiled libraries from here: http://landley.net/aboriginal/ 9 | # 10 | crt1.o: /lib 11 | crti.o: /lib 12 | crtn.o: /lib 13 | libc.so: /lib 14 | libc.a: /lib 15 | libgcc.a: /lib 16 | -------------------------------------------------------------------------------- /src/luxdvr/musl_x64.conf: -------------------------------------------------------------------------------- 1 | luxcc: src 2 | luxasx86: src/luxx86 3 | luxld: src/luxld 4 | liblux.o: src/lib/obj/x64, /usr/local/lib/luxcc/obj/x64 5 | 6 | # musl's default installation paths 7 | crt1.o: /usr/local/musl/lib 8 | crti.o: /usr/local/musl/lib 9 | crtn.o: /usr/local/musl/lib 10 | libc.so: /usr/local/musl/lib 11 | libc.a: /usr/local/musl/lib 12 | # this one will need to be modified, generally to something like /usr/lib/gcc// 13 | libgcc.a: /lib 14 | -------------------------------------------------------------------------------- /src/luxdvr/musl_x86.conf: -------------------------------------------------------------------------------- 1 | luxcc: src 2 | luxasx86: src/luxx86 3 | luxld: src/luxld 4 | liblux.o: src/lib/obj/x86, /usr/local/lib/luxcc/obj/x86 5 | 6 | # musl's default installation paths 7 | crt1.o: /usr/local/musl/lib 8 | crti.o: /usr/local/musl/lib 9 | crtn.o: /usr/local/musl/lib 10 | libc.so: /usr/local/musl/lib 11 | libc.a: /usr/local/musl/lib 12 | # this one will need to be modified, generally to something like /usr/lib/gcc// 13 | libgcc.a: /lib 14 | -------------------------------------------------------------------------------- /src/lib/include/fcntl.h: -------------------------------------------------------------------------------- 1 | #ifndef _FCNTL_H 2 | #define _FCNTL_H 3 | 4 | #include 5 | 6 | /* access modes */ 7 | #define O_RDONLY 0 8 | #define O_WRONLY 1 9 | #define O_RDWR 2 10 | /* file creation flags */ 11 | #define O_CREAT 0x040 12 | #define O_EXCL 0x080 13 | #define O_TRUNC 0x200 14 | #define O_NOCTTY 0x100 15 | /* file status flags */ 16 | #define O_APPEND 0x400 17 | 18 | int open(const char *pathname, int flags, mode_t mode); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /src/tests/analyze/lvalue.c: -------------------------------------------------------------------------------- 1 | int main(void) 2 | { 3 | int a; 4 | int *b; 5 | int c[10]; 6 | struct A { 7 | int k; 8 | } d, e(void), *f(void); 9 | 10 | &"abc"; 11 | 12 | &123; // @ error "invalid operand to &" 13 | 14 | &a; 15 | &(a); 16 | 17 | &*b; 18 | 19 | &c; 20 | &c[0]; 21 | 22 | d.k++; 23 | 24 | e().k++; // @ error "expression is not modifiable" 25 | 26 | f()->k++; 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /src/luxdvr/makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | CFLAGS=-c -g -Wall 3 | OBJS = luxdvr.o 4 | 5 | all: luxdvr 6 | 7 | luxdvr: luxdvr.o ../util/util.o ../util/str.o 8 | $(CC) -o luxdvr luxdvr.o ../util/util.o ../util/str.o 9 | 10 | ../util/util.o: 11 | make -C ../util util.o 12 | 13 | ../util/str.o: 14 | make -C ../util str.o 15 | 16 | .c.o: 17 | $(CC) $(CFLAGS) $*.c 18 | 19 | clean: 20 | rm -f $(OBJS) luxdvr 21 | 22 | luxdvr.o: ../util/util.h ../util/str.h 23 | 24 | .PHONY: all clean 25 | -------------------------------------------------------------------------------- /src/tests/execute/other/c4/testme.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | CC="src/luxdvr/luxdvr -q $1" 3 | TESTDIR=`dirname $0` 4 | 5 | $CC $CFLAGS $TESTDIR/c4.c -o $TESTDIR/c4 &>/dev/null 6 | rm -f $TESTDIR/c4.output 7 | $TESTDIR/c4 $TESTDIR/hello.c >$TESTDIR/c4.output 8 | rm -f $TESTDIR/c4 9 | 10 | if ! cmp -s $TESTDIR/c4.output $TESTDIR/c4.expect ; then 11 | echo "C4 compiler failed!" 12 | exit 1 13 | elif [ ! "$LUX_QUIET" = "1" ] ; then 14 | echo "C4 compiler succeeded!" 15 | fi 16 | exit 0 17 | -------------------------------------------------------------------------------- /src/lib/utime.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int utime(const char *filename, const struct utimbuf *times) 5 | { 6 | #ifdef __arm__ 7 | #include 8 | struct timeval tvp[2]; 9 | 10 | tvp[0].tv_sec = times->actime; 11 | tvp[0].tv_usec = 0; 12 | tvp[1].tv_sec = times->modtime; 13 | tvp[1].tv_usec = 0; 14 | 15 | return utimes(filename, tvp); 16 | #else 17 | return syscall(SYS_utime, filename, times); 18 | #endif 19 | } 20 | -------------------------------------------------------------------------------- /src/luxdvr/musl_arm.conf: -------------------------------------------------------------------------------- 1 | luxcc: src 2 | luxasarm: src/luxarm 3 | liblux.o: src/lib/obj/arm, /usr/local/lib/luxcc/obj/arm 4 | luxmemcpy.o: src/lib/obj/arm, /usr/local/lib/luxcc/obj/arm 5 | 6 | # 7 | # Compile or get these files from somewhere and adjust the paths. 8 | # You can get precompiled libraries from here: http://landley.net/aboriginal/ 9 | # 10 | crt1.o: /lib 11 | crti.o: /lib 12 | crtn.o: /lib 13 | libc.so: /lib 14 | libc.a: /lib 15 | libgcc.a: /lib 16 | libgcc_eh.a: /lib 17 | -------------------------------------------------------------------------------- /src/tests/execute/inc1.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | char c1; 6 | unsigned char c2; 7 | 8 | c1 = -128; 9 | printf("%d\n", --c1); 10 | printf("%d\n", c1); 11 | 12 | c1 = -128; 13 | printf("%d\n", c1++); 14 | printf("%d\n", c1); 15 | 16 | c2 = 255; 17 | printf("%d\n", ++c2); 18 | printf("%d\n", c2); 19 | 20 | c2 = 255; 21 | printf("%d\n", c2++); 22 | printf("%d\n", c2); 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /scripts/testall_x86.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "=============================" 4 | echo " START i386 TESTS" 5 | echo "=============================" 6 | 7 | if /bin/bash scripts/self_x86.sh ; then 8 | mv src/luxcc src/luxcc_tmp 9 | cp src/tests/self/luxcc2.out src/luxcc 10 | scripts/test_exe_x86.sh && scripts/test_com_x86.sh 11 | mv src/luxcc_tmp src/luxcc 12 | fi 13 | 14 | echo "=============================" 15 | echo " END i386 TESTS" 16 | echo "=============================" 17 | -------------------------------------------------------------------------------- /src/tests/execute/other/T-Rex-master/history.txt: -------------------------------------------------------------------------------- 1 | ===version 1.3 2 | -fixed a bug for GCC users(thx Brendan) 3 | 4 | ===version 1.2 5 | -added word boundary match \b and \B 6 | -added vertical tab escape \v 7 | -\w now also matches '_' (underscore) 8 | -fixed greediness for * and + 9 | 10 | ===version 1.1 , April 1, 2004 11 | -fixed some minor bug 12 | -added predefined character classes(\w,\W,\s,\S etc...) 13 | 14 | ===version 1.0 , February 23, 2004 15 | -first public realase -------------------------------------------------------------------------------- /scripts/testall_x64.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "=============================" 4 | echo " START x86_64 TESTS" 5 | echo "=============================" 6 | 7 | if /bin/bash scripts/self_x64.sh ; then 8 | mv src/luxcc src/luxcc_tmp 9 | cp src/tests/self/luxcc2.out src/luxcc 10 | scripts/test_exe_x64.sh && scripts/test_com_x64.sh 11 | mv src/luxcc_tmp src/luxcc 12 | fi 13 | 14 | echo "=============================" 15 | echo " END x86_64 TESTS" 16 | echo "=============================" 17 | -------------------------------------------------------------------------------- /src/tests/execute/other/crypto-simple/c/c_des.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | rem You may want to update the paths below depending on your version of VS 3 | set path=%path%;C:\Program Files\Microsoft Visual Studio 8\VC\bin 4 | set path=%path%;C:\Program Files\Microsoft Visual Studio 8\Common7\IDE 5 | set lib=%lib%;C:\Program Files\Microsoft Visual Studio 8\VC\lib 6 | set include=%include%;C:\Program Files\Microsoft Visual Studio 8\VC\include 7 | 8 | cl c_des.c 9 | del c_des.obj 10 | c_des.exe 11 | pause 12 | -------------------------------------------------------------------------------- /src/lib/vm_lib/include/assert.h: -------------------------------------------------------------------------------- 1 | #ifndef _ASSERT_H 2 | #define _ASSERT_H 3 | 4 | #include /* for exit() */ 5 | #include /* for fprintf() */ 6 | 7 | #ifndef NDEBUG 8 | #define assert(expression)\ 9 | do\ 10 | if (!(expression))\ 11 | fprintf(stderr, "Assertion failed in file %s, function %s(), line %d\n", __FILE__, __func__, __LINE__),\ 12 | exit(1);\ 13 | while (0) 14 | #else 15 | #define assert(expression) ((void)0) 16 | #endif 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /src/tests/execute/do.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | int a; 6 | long long e; 7 | 8 | a = 10; 9 | do 10 | printf(">%d\n", a); 11 | while (a--); 12 | 13 | e = 10; 14 | do 15 | printf(">>%lld\n", e); 16 | while (e--); 17 | 18 | a = 10; 19 | do 20 | if (!a--) 21 | break; 22 | else 23 | printf(">>>%d\n", a); 24 | while (1); 25 | printf(">>>>%d\n", a); 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /src/tests/execute/vararg_struct.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | typedef struct { 5 | short x, y, z; 6 | } A; 7 | 8 | void foo(int n, ...) 9 | { 10 | va_list ap; 11 | A x; 12 | 13 | va_start(ap, n); 14 | x = va_arg(ap, A); 15 | va_end(ap); 16 | 17 | printf("x=%d\n", x.x); 18 | printf("y=%d\n", x.y); 19 | printf("z=%d\n", x.z); 20 | } 21 | 22 | int main(void) 23 | { 24 | A s = { 15, 25, 35 }; 25 | foo(1, s); 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /scripts/self_copy.sh: -------------------------------------------------------------------------------- 1 | mkdir -p src/tests/self 2 | cp src/*.c src/*.h src/tests/self/ 3 | cp -r src/util/ src/tests/self/ 4 | rm -f src/tests/self/util/ELF_util.c src/tests/self/util/ELF_util.h 5 | cp -r src/vm32_cgen/ src/tests/self/ 6 | cp -r src/vm64_cgen/ src/tests/self/ 7 | mkdir -p src/tests/self/luxvm 8 | cp src/luxvm/vm.h src/tests/self/luxvm/ 9 | cp -r src/x86_cgen/ src/tests/self/ 10 | cp -r src/x64_cgen/ src/tests/self/ 11 | cp -r src/mips_cgen/ src/tests/self/ 12 | cp -r src/arm_cgen/ src/tests/self/ 13 | -------------------------------------------------------------------------------- /src/lib/vm_lib/include/ctype.h: -------------------------------------------------------------------------------- 1 | #ifndef _CTYPE_H 2 | #define _CTYPE_H 3 | 4 | /* 5 | * Note: commented out functions are not implemented. 6 | */ 7 | 8 | int isalnum(int c); 9 | int isalpha(int c); 10 | int isblank(int c); 11 | int iscntrl(int c); 12 | int isdigit(int c); 13 | int isgraph(int c); 14 | int islower(int c); 15 | int isprint(int c); 16 | int ispunct(int c); 17 | int isspace(int c); 18 | int isupper(int c); 19 | int isxdigit(int c); 20 | int tolower(int c); 21 | int toupper(int c); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /src/luxdvr/glibc_arm.conf: -------------------------------------------------------------------------------- 1 | luxcc: src 2 | luxasarm: src/luxarm 3 | luxmemcpy.o: src/lib/obj/arm, /usr/local/lib/luxcc/obj/arm 4 | liblux.o: src/lib/obj/arm, /usr/local/lib/luxcc/obj/arm 5 | # 6 | # One can get these files by installing the following packages: libc6-armel-cross libc6-dev-armel-cross 7 | # 8 | crt1.o: /usr/arm-linux-gnueabi/lib 9 | crti.o: /usr/arm-linux-gnueabi/lib 10 | crtn.o: /usr/arm-linux-gnueabi/lib 11 | libc_nonshared.a: /usr/arm-linux-gnueabi/lib 12 | libc.so.6: /usr/arm-linux-gnueabi/lib 13 | -------------------------------------------------------------------------------- /src/tests/execute/pascal.c: -------------------------------------------------------------------------------- 1 | /* http://rosettacode.org/wiki/Pascal's_triangle#C */ 2 | 3 | #include 4 | 5 | void pascaltriangle(unsigned int n) 6 | { 7 | unsigned int c, i, j, k; 8 | 9 | for(i=0; i < n; i++) { 10 | c = 1; 11 | for(j=1; j <= 2*(n-1-i); j++) printf(" "); 12 | for(k=0; k <= i; k++) { 13 | printf("%3d ", c); 14 | c = c * (i-k)/(k+1); 15 | } 16 | printf("\n"); 17 | } 18 | } 19 | 20 | int main(void) 21 | { 22 | pascaltriangle(8); 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /src/luxarm/makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | CFLAGS=-c -g -Wall -Wno-switch -Wno-sign-conversion 3 | 4 | all: luxasarm 5 | 6 | luxasarm: luxasarm.o ../util/util.o ../util/ELF_util.o 7 | $(CC) -o luxasarm luxasarm.o ../util/util.o ../util/ELF_util.o 8 | 9 | ../util/util.o: 10 | make -C ../util util.o 11 | 12 | ../util/ELF_util.o: 13 | make -C ../util ELF_util.o 14 | 15 | .c.o: 16 | $(CC) $(CFLAGS) $*.c 17 | 18 | clean: 19 | rm -f *.o luxasarm 20 | 21 | luxasarm.o: ../util/util.h ../util/ELF_util.h 22 | 23 | .PHONY: all clean 24 | -------------------------------------------------------------------------------- /src/luxmips/makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | CFLAGS=-c -g -Wall -Wno-switch -Wno-sign-conversion 3 | 4 | all: luxasmips 5 | 6 | luxasmips: luxasmips.o ../util/util.o ../util/ELF_util.o 7 | $(CC) -o luxasmips luxasmips.o ../util/util.o ../util/ELF_util.o 8 | 9 | ../util/util.o: 10 | make -C ../util util.o 11 | 12 | ../util/ELF_util.o: 13 | make -C ../util ELF_util.o 14 | 15 | .c.o: 16 | $(CC) $(CFLAGS) $*.c 17 | 18 | clean: 19 | rm -f *.o luxasmips 20 | 21 | luxasmips.o: ../util/util.h ../util/ELF_util.h 22 | 23 | .PHONY: all clean 24 | -------------------------------------------------------------------------------- /src/tests/execute/picoc_tcc/06_case.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | int Count; 6 | 7 | for (Count = 0; Count < 4; Count++) 8 | { 9 | printf("%d\n", Count); 10 | switch (Count) 11 | { 12 | case 1: 13 | printf("%d\n", 1); 14 | break; 15 | 16 | case 2: 17 | printf("%d\n", 2); 18 | break; 19 | 20 | default: 21 | printf("%d\n", 0); 22 | break; 23 | } 24 | } 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /src/lib/README: -------------------------------------------------------------------------------- 1 | I have included a precompiled shared libc at obj//libc.so so you don't have 2 | to install any cross-compiler to get one. 3 | 4 | I currently cannot use luxcc to compile the libraries because it does not generate 5 | position-independent code (PIC) as required for shared libraries. 6 | 7 | If you want to compile the libraries from source you can install the required 8 | cross-compiler and do 9 | 10 | make -f makefile.shared 11 | 12 | Check makefile.shared's variables to see what cross-compiler is required for each arch. 13 | -------------------------------------------------------------------------------- /src/tests/compile/AnsiLove-C-master/strtolower.c: -------------------------------------------------------------------------------- 1 | // 2 | // strtolower.m 3 | // AnsiLove/C 4 | // 5 | // Copyright (C) 2011-2015 Stefan Vogt, Brian Cassidy, Frederic Cambus. 6 | // All rights reserved. 7 | // 8 | // This source code is licensed under the BSD 3-Clause License. 9 | // See the file LICENSE for details. 10 | // 11 | 12 | #include "strtolower.h" 13 | 14 | char *strtolower(char *str) 15 | { 16 | char *p; 17 | for (p = str; *p != '\0'; ++p) 18 | { 19 | *p = tolower(*p); 20 | } 21 | return str; 22 | } 23 | -------------------------------------------------------------------------------- /src/tests/execute/type_spec.c: -------------------------------------------------------------------------------- 1 | /* 2 | * analyze_decl_specs() was forgetting to copy pointers 3 | * and this led to a crash further in the processing. 4 | */ 5 | 6 | typedef int int2; 7 | struct A { int a; long b; }; 8 | union B { int a; long b; }; 9 | enum C { ONE, TWO }; 10 | struct D { 11 | char a; 12 | int b; 13 | } const s; 14 | 15 | int main(int argc, char *argv[]) 16 | { 17 | int2 const *x0; 18 | struct A const *x1; 19 | union B const x2; 20 | enum C const x3; 21 | struct D x; 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /src/lib/include/sys/ioctl.h: -------------------------------------------------------------------------------- 1 | #ifndef _IOCTL_H 2 | #define _IOCTL_H 3 | 4 | #if defined __i386__ || defined __x86_64__ || defined __arm__ 5 | /* 6 | * More values and corresponding `arg' type 7 | * for these platforms can be found here: 8 | * http://man7.org/linux/man-pages/man2/ioctl_list.2.html 9 | */ 10 | #define TCGETS 0x00005401 11 | #define TCFLSH 0x0000540B 12 | #elif defined __mips__ 13 | #define TCFLSH 0x00005407 14 | #define TCGETS 0x0000540D 15 | #endif 16 | 17 | int ioctl(int fd, unsigned long request, void *arg); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /scripts/testall_arm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "=============================" 4 | echo " START ARM TESTS" 5 | echo "=============================" 6 | 7 | # assume default installation paths 8 | if [ ! -d "/usr/arm-linux-gnueabi/" ] ; then 9 | echo "Cannot find ARM cross libraries" 10 | elif ! which qemu-arm >/dev/null ; then 11 | echo "Cannot find qemu-arm" 12 | else 13 | scripts/self_arm.sh && 14 | scripts/test_exe_arm.sh 15 | fi 16 | 17 | echo "=============================" 18 | echo " END ARM TESTS" 19 | echo "=============================" 20 | -------------------------------------------------------------------------------- /src/tests/compile/AnsiLove-C-master/filesize.h: -------------------------------------------------------------------------------- 1 | // 2 | // filesize.h 3 | // AnsiLove/C 4 | // 5 | // Copyright (C) 2011-2015 Stefan Vogt, Brian Cassidy, Frederic Cambus. 6 | // All rights reserved. 7 | // 8 | // This source code is licensed under the BSD 3-Clause License. 9 | // See the file LICENSE for details. 10 | // 11 | 12 | #include 13 | #include 14 | 15 | #ifndef filesize_h 16 | #define filesize_h 17 | 18 | // Returns size of a file at a given path as integer. 19 | 20 | size_t filesize(char *filepath); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /src/tests/execute/if.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | int a; 6 | long long e; 7 | 8 | a = 0; 9 | if (a) 10 | printf("A\n"); 11 | else 12 | printf("B\n"); 13 | a = 1; 14 | if (a) 15 | printf("C\n"); 16 | else 17 | printf("D\n"); 18 | 19 | e = 0; 20 | if (e) 21 | printf(">A\n"); 22 | else 23 | printf(">B\n"); 24 | e = 1; 25 | if (e) 26 | printf(">C\n"); 27 | else 28 | printf(">D\n"); 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /src/luxld/README: -------------------------------------------------------------------------------- 1 | Linker with support for i386, x86_64, MIPS, and ARM. 2 | 3 | Static and shared libraries are supported. 4 | 5 | Just a minimal set of input relocations are supported, mostly the ones that are emitted 6 | by the corresponding assemblers. The only output relocations are of type R_*_JUMP_SLOT 7 | and R_*_COPY. 8 | 9 | This linker is primarily used to link against our own libc. It can be used to link against 10 | musl too (at least in i386). 11 | 12 | glibc almost sure is not going to work because of the input relocations of the crt*.o files. 13 | -------------------------------------------------------------------------------- /src/tests/execute/other/T-Rex-master/testme.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | CC="src/luxdvr/luxdvr -q $1" 3 | TESTDIR=`dirname $0` 4 | 5 | rm -f $TESTDIR/trex.output 6 | if ! $CC $CFLAGS $TESTDIR/test.c $TESTDIR/trex.c -o $TESTDIR/out1 &>/dev/null ; then 7 | echo "Failed to compile T-Rex" 8 | exit 1 9 | fi 10 | $TESTDIR/out1 >$TESTDIR/trex.output 11 | rm -f $TESTDIR/out1 12 | 13 | if ! cmp -s $TESTDIR/trex.output $TESTDIR/trex.expect ; then 14 | echo "T-Rex failed!" 15 | exit 1 16 | elif [ ! "$LUX_QUIET" = "1" ] ; then 17 | echo "T-Rex succeeded!" 18 | fi 19 | exit 0 20 | -------------------------------------------------------------------------------- /scripts/testall_mips.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "=============================" 4 | echo " START MIPS TESTS" 5 | echo "=============================" 6 | 7 | # assume default installation paths 8 | if [ ! -d "/usr/mipsel-linux-gnu/" ] ; then 9 | echo "Cannot find MIPS cross libraries" 10 | elif ! which qemu-mipsel >/dev/null ; then 11 | echo "Cannot find qemu-mipsel" 12 | else 13 | scripts/self_mips.sh && 14 | scripts/test_exe_mips.sh 15 | fi 16 | 17 | echo "=============================" 18 | echo " END MIPS TESTS" 19 | echo "=============================" 20 | -------------------------------------------------------------------------------- /src/tests/execute/ackermann.c: -------------------------------------------------------------------------------- 1 | // #include 2 | int printf(const char *, ...); 3 | 4 | int ackermann(int m, int n) 5 | { 6 | if (m == 0) 7 | return n+1; 8 | else if (n == 0) 9 | return ackermann(m-1, 1); 10 | else 11 | return ackermann(m-1, ackermann(m, n-1)); 12 | } 13 | 14 | int main(void) 15 | { 16 | printf("ackermann(2, 2) = %d\n", ackermann(2, 2)); // 7 17 | printf("ackermann(3, 2) = %d\n", ackermann(3, 2)); // 29 18 | printf("ackermann(3, 3) = %d\n", ackermann(3, 3)); // 61 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /src/tests/execute/other/crypto-simple/c/c_aes.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | rem You may want to update the paths below depending on your version of VS 3 | set path=%path%;C:\Program Files\Microsoft Visual Studio 8\VC\bin 4 | set path=%path%;C:\Program Files\Microsoft Visual Studio 8\Common7\IDE 5 | set lib=%lib%;C:\Program Files\Microsoft Visual Studio 8\VC\lib 6 | set include=%include%;C:\Program Files\Microsoft Visual Studio 8\VC\include 7 | rem The /Tp option compiles it as C++ to get the advantage of C99 features 8 | cl /Tp c_aes.c 9 | del c_aes.obj 10 | c_aes.exe 11 | pause 12 | -------------------------------------------------------------------------------- /src/tests/execute/other/tiny-AES128-C/testme.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | CC="src/luxdvr/luxdvr -q $1" 3 | TESTDIR=`dirname $0` 4 | 5 | rm -f $TESTDIR/aes.output 6 | if ! $CC $TESTDIR/test.c $TESTDIR/aes.c -o $TESTDIR/out1 &>/dev/null ; then 7 | echo "Failed to compile Tiny AES128" 8 | exit 1 9 | fi 10 | $TESTDIR/out1 >$TESTDIR/aes.output 11 | rm -f $TESTDIR/out1 12 | 13 | if ! cmp -s $TESTDIR/aes.output $TESTDIR/aes.expect ; then 14 | echo "Tiny AES128 failed!" 15 | exit 1 16 | elif [ ! "$LUX_QUIET" = "1" ] ; then 17 | echo "Tiny AES128 succeeded!" 18 | fi 19 | exit 0 20 | -------------------------------------------------------------------------------- /src/tests/execute/other/tiny-AES128-C/aes.expect: -------------------------------------------------------------------------------- 1 | CBC encrypt: SUCCESS! 2 | CBC decrypt: SUCCESS! 3 | ECB decrypt: SUCCESS! 4 | ECB decrypt: SUCCESS! 5 | ECB encrypt verbose: 6 | 7 | plain text: 8 | 6bc1bee22e409f96e93d7e117393172a 9 | ae2d8a571e03ac9c9eb76fac45af8e51 10 | 30c81c46a35ce411e5fbc1191a0a52ef 11 | f69f2445df4f9b17ad2b417be66c3710 12 | 13 | key: 14 | 2b7e151628aed2a6abf7158809cf4f3c 15 | 16 | ciphertext: 17 | 3ad77bb40d7a3660a89ecaf32466ef97 18 | f5d3d58503b9699de785895a96fdbaaf 19 | 43b1cd7f598ece23881b00e3ed030688 20 | 7b0c785e27e8ad3f8223207104725dd4 21 | 22 | -------------------------------------------------------------------------------- /src/tests/execute/picoc_tcc/38_multiple_array_index.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | int a[4][4]; 6 | int b = 0; 7 | int x; 8 | int y; 9 | 10 | for (x = 0; x < 4; x++) 11 | { 12 | for (y = 0; y < 4; y++) 13 | { 14 | b++; 15 | a[x][y] = b; 16 | } 17 | } 18 | 19 | for (x = 0; x < 4; x++) 20 | { 21 | printf("x=%d: ", x); 22 | for (y = 0; y < 4; y++) 23 | { 24 | printf("%d ", a[x][y]); 25 | } 26 | printf("\n"); 27 | } 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /src/luxdvr/glibc_mips.conf: -------------------------------------------------------------------------------- 1 | luxcc: src 2 | luxasmips: src/luxmips 3 | luxmemcpy.o: src/lib/obj/mips, /usr/local/lib/luxcc/obj/mips 4 | liblux.o: src/lib/obj/mips, /usr/local/lib/luxcc/obj/mips 5 | # 6 | # One can get these files by installing the following packages: linux-libc-dev-mipsel-cross libc6-mipsel-cross libc6-dev-mipsel-cross 7 | # 8 | crt1.o: /usr/mipsel-linux-gnu/lib 9 | crti.o: /usr/mipsel-linux-gnu/lib 10 | crtn.o: /usr/mipsel-linux-gnu/lib 11 | libc.so.6: /usr/mipsel-linux-gnu/lib 12 | libc_nonshared.a: /usr/mipsel-linux-gnu/lib 13 | ld.so.1: /usr/mipsel-linux-gnu/lib 14 | -------------------------------------------------------------------------------- /src/tests/execute/factorial.c: -------------------------------------------------------------------------------- 1 | // #include 2 | int printf(const char *, ...); 3 | 4 | int factorial(int x) 5 | { 6 | int fact; 7 | if (x > 0) { 8 | fact = 1; 9 | do 10 | fact = fact*x--; 11 | while (x != 0); 12 | } 13 | return fact; 14 | } 15 | 16 | int rfactorial(int x) 17 | { 18 | if (x > 1) 19 | return x*rfactorial(x-1); 20 | else 21 | return 1; 22 | } 23 | 24 | int main(void) 25 | { 26 | printf("%d\n", factorial(5)); 27 | printf("%d\n", rfactorial(5)); 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /src/tests/compile/AnsiLove-C-master/strtolower.h: -------------------------------------------------------------------------------- 1 | // 2 | // strtolower.h 3 | // AnsiLove/C 4 | // 5 | // Copyright (C) 2011-2015 Stefan Vogt, Brian Cassidy, Frederic Cambus. 6 | // All rights reserved. 7 | // 8 | // This source code is licensed under the BSD 3-Clause License. 9 | // See the file LICENSE for details. 10 | // 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | #ifndef strtolower_h 17 | #define strtolower_h 18 | 19 | // In-place modification of a string to be all lower case. 20 | 21 | char *strtolower(char *str); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /src/tests/execute/picoc_tcc/39_typedef.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef int MyInt; 4 | 5 | struct FunStruct 6 | { 7 | int i; 8 | int j; 9 | }; 10 | 11 | typedef struct FunStruct MyFunStruct; 12 | 13 | typedef MyFunStruct *MoreFunThanEver; 14 | 15 | int main(void) 16 | { 17 | MyInt a = 1; 18 | MyFunStruct b; 19 | MoreFunThanEver c = &b; 20 | printf("%d\n", a); 21 | 22 | // MyFunStruct b; 23 | b.i = 12; 24 | b.j = 34; 25 | printf("%d,%d\n", b.i, b.j); 26 | 27 | // MoreFunThanEver c = &b; 28 | printf("%d,%d\n", c->i, c->j); 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /src/tests/execute/spill.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int x; 4 | 5 | void foo(int *p) 6 | { 7 | printf("%d\n", *p); 8 | } 9 | 10 | void bar(void) 11 | { 12 | printf("%d\n", x); 13 | } 14 | 15 | int main(void) 16 | { 17 | int y; 18 | 19 | /* Test liveness / register spilling */ 20 | 21 | y = 1234; 22 | foo(&y); 23 | y = 0; 24 | 25 | x = 9999; 26 | bar(); 27 | x = 0; 28 | 29 | y = 4321; 30 | if (1) 31 | foo(&y); 32 | y = 0; 33 | 34 | x = 8888; 35 | if (1) 36 | bar(); 37 | x = 0; 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /src/stmt.h: -------------------------------------------------------------------------------- 1 | #ifndef STMT_H_ 2 | #define STMT_H_ 3 | 4 | #include "parser.h" 5 | 6 | void stmt_init(void); 7 | void stmt_done(void); 8 | void analyze_labeled_statement(ExecNode *s, int in_switch); 9 | void analyze_selection_statement(ExecNode *s); 10 | void analyze_iteration_statement(ExecNode *s); 11 | void analyze_jump_statement(ExecNode *s, int in_loop, int in_switch); 12 | void set_return_type(TypeExp *ds, TypeExp *dct); 13 | void empty_label_table(void); 14 | void resolve_gotos(void); 15 | void increase_switch_nesting_level(ExecNode *e); 16 | int decrease_switch_nesting_level(void); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /src/util/ELF_util.h: -------------------------------------------------------------------------------- 1 | #ifndef ELF_UTIL_ 2 | #define ELF_UTIL_ 3 | 4 | #include 5 | 6 | typedef struct StrTab StrTab; 7 | StrTab *strtab_new(void); 8 | void strtab_destroy(StrTab *tab); 9 | int strtab_append(StrTab *tab, char *str); 10 | int strtab_write(StrTab *tab, FILE *fp); 11 | unsigned strtab_get_size(StrTab *tab); 12 | int strtab_get_offset(StrTab *tab, char *str); 13 | char *strtab_get_string(StrTab *tab, int offs); 14 | void strtab_copy(StrTab *tab, char *dest); 15 | 16 | unsigned long elf_hash(const unsigned char *name); 17 | unsigned elf_get_nbucket(unsigned nsym); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /src/luxx86/makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | CFLAGS=-c -g -Wall -Wno-switch -Wno-sign-conversion 3 | 4 | all: luxasx86 5 | 6 | luxasx86: luxasx86.o ../util/util.o ../util/arena.o ../util/ELF_util.o 7 | $(CC) -o luxasx86 luxasx86.o ../util/util.o ../util/arena.o ../util/ELF_util.o 8 | 9 | ../util/util.o: 10 | make -C ../util util.o 11 | 12 | ../util/arena.o: 13 | make -C ../util arena.o 14 | 15 | ../util/ELF_util.o: 16 | make -C ../util ELF_util.o 17 | 18 | .c.o: 19 | $(CC) $(CFLAGS) $*.c 20 | 21 | clean: 22 | rm -f *.o luxasx86 23 | 24 | luxasx86.o: ../util/ELF_util.h ../util/util.h ../util/arena.h 25 | 26 | .PHONY: all clean 27 | -------------------------------------------------------------------------------- /src/lib/crt0_x86.asm: -------------------------------------------------------------------------------- 1 | extern __libc_init, main, exit 2 | 3 | section .bss 4 | __argc: 5 | resd 1 6 | __argv: 7 | resd 1 8 | global __env 9 | __env: 10 | resd 1 11 | 12 | section .text 13 | global _start 14 | _start: 15 | ; get argc 16 | mov eax, [esp] 17 | mov [__argc], eax 18 | ; get argv 19 | lea edx, [esp+4] 20 | mov [__argv], edx 21 | ; get env 22 | lea eax, [edx+eax*4+4] 23 | mov [__env], eax 24 | 25 | call __libc_init 26 | 27 | ; do exit(main(argc, argv)) 28 | push dword [__argv] 29 | push dword [__argc] 30 | call main 31 | push eax 32 | call exit 33 | -------------------------------------------------------------------------------- /src/lib/include/getopt.h: -------------------------------------------------------------------------------- 1 | #ifndef _GETOPT_H 2 | #define _GETOPT_H 3 | 4 | #define no_argument 0 5 | #define required_argument 1 6 | /*#define optional_argument 2*/ 7 | 8 | extern char *optarg; 9 | extern int optind, opterr, optopt; 10 | 11 | struct option { 12 | const char *name; 13 | int has_arg; 14 | int *flag; 15 | int val; 16 | }; 17 | 18 | int getopt_long(int argc, char *const *argv, const char *shortopts, const struct option *longopts, int *indexptr); 19 | /*int getopt_long_only(int argc, char *const *argv, const char *shortopts, const struct option *longopts, int *indexptr);*/ 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /src/lib/crt0_x64.asm: -------------------------------------------------------------------------------- 1 | extern __libc_init, main, exit 2 | 3 | section .bss 4 | __argc: 5 | resd 1 6 | align 8 7 | __argv: 8 | resq 1 9 | global __env 10 | __env: 11 | resq 1 12 | 13 | section .text 14 | global _start 15 | _start: 16 | ; get argc 17 | mov rax, [rsp] 18 | mov [__argc], eax 19 | ; get argv 20 | lea rdx, [rsp+8] 21 | mov [__argv], rdx 22 | ; get env 23 | lea rax, [rdx+rax*8+8] 24 | mov [__env], rax 25 | 26 | call __libc_init 27 | 28 | ; do exit(main(argc, argv)) 29 | mov rdi, [__argc] 30 | mov rsi, [__argv] 31 | call main 32 | mov rdi, rax 33 | call exit 34 | -------------------------------------------------------------------------------- /src/tests/execute/other/abc-compiler/testme.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | CC="src/luxdvr/luxdvr -q $1" 3 | TESTDIR=`dirname $0` 4 | 5 | $CC $TESTDIR/b0.c $TESTDIR/b1.c -o $TESTDIR/b &>/dev/null 6 | $TESTDIR/abc -c $TESTDIR/brt.s $TESTDIR/lib.b &>/dev/null 7 | 8 | rm -f $TESTDIR/abc.output 9 | for file in $TESTDIR/examples/*.b ; do 10 | $TESTDIR/abc -o $TESTDIR/out1 $file 11 | $TESTDIR/out1 >>$TESTDIR/abc.output 12 | done 13 | rm -f $TESTDIR/out1 14 | 15 | if ! cmp -s $TESTDIR/abc.output $TESTDIR/abc.expect ; then 16 | echo "B compiler failed!" 17 | exit 1 18 | elif [ ! "$LUX_QUIET" = "1" ] ; then 19 | echo "B compiler succeeded!" 20 | fi 21 | exit 0 22 | -------------------------------------------------------------------------------- /src/util/str.h: -------------------------------------------------------------------------------- 1 | #ifndef STR_H_ 2 | #define STR_H_ 3 | 4 | #include 5 | #include 6 | 7 | typedef struct String String; 8 | 9 | /* 10 | * siz is the initial size; 11 | * the string will grow automatically when necessary. 12 | */ 13 | String *string_new(unsigned siz); 14 | void string_free(String *s); 15 | int string_printf(String *s, char *fmt, ...); 16 | int string_vprintf(String *s, char *fmt, va_list ap); 17 | void string_write(String *s, FILE *fp); 18 | void string_clear(String *s); 19 | char *string_curr(String *s); 20 | unsigned string_get_pos(String *s); 21 | void string_set_pos(String *s, unsigned n); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /src/tests/execute/other/T-Rex-master/trex.expect: -------------------------------------------------------------------------------- 1 | [0]link 2 | [1]link.html 3 | [2]link 4 | match! 3 sub matches 5 | ============================= 6 | Simple matching string cases. 7 | Test string: Match some part of this string. 8 | Test 1: missing letter 9 | True negative: No matches for 'soe'. 10 | Test 2: missing space 11 | True negative: No matches for 'matchs'. 12 | Test 3a: case mismatch 13 | True negative: No matches for 'match'. 14 | Test 3b: case match 15 | True positive: String 'Match' matched. 16 | Test 4: unused character 17 | True negative: No matches for '!'. 18 | Test 5: single character 19 | True positive: String '.' matched. 20 | -------------------------------------------------------------------------------- /scripts/self_arm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | /bin/bash scripts/self_copy.sh 4 | 5 | echo "== Self-compilation test begins... ==" 6 | 7 | # phase 1 8 | if ! /bin/bash scripts/self1_arm.sh ; then 9 | echo "Phase 1 failed!" 10 | exit 1 11 | else 12 | echo "Phase 1 succeeded!" 13 | fi 14 | 15 | # phase 2 16 | if ! /bin/bash scripts/self2_arm.sh ; then 17 | echo "Phase 2 failed!" 18 | exit 1 19 | else 20 | echo "Phase 2 succeeded!" 21 | fi 22 | 23 | # compare binaries 24 | if cmp -s src/tests/self/luxcc1 src/tests/self/luxcc2 ; then 25 | echo "== Self-compilation test succeeded! ==" 26 | exit 0 27 | else 28 | echo "== Self-compilation test failed! ==" 29 | exit 1 30 | fi 31 | -------------------------------------------------------------------------------- /scripts/self_mips.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | /bin/bash scripts/self_copy.sh 4 | 5 | echo "== Self-compilation test begins... ==" 6 | 7 | # phase 1 8 | if ! /bin/bash scripts/self1_mips.sh ; then 9 | echo "Phase 1 failed!" 10 | exit 1 11 | else 12 | echo "Phase 1 succeeded!" 13 | fi 14 | 15 | # phase 2 16 | if ! /bin/bash scripts/self2_mips.sh ; then 17 | echo "Phase 2 failed!" 18 | exit 1 19 | else 20 | echo "Phase 2 succeeded!" 21 | fi 22 | 23 | # compare binaries 24 | if cmp -s src/tests/self/luxcc1 src/tests/self/luxcc2 ; then 25 | echo "== Self-compilation test succeeded! ==" 26 | exit 0 27 | else 28 | echo "== Self-compilation test failed! ==" 29 | exit 1 30 | fi 31 | -------------------------------------------------------------------------------- /scripts/self_vm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | /bin/bash scripts/self_copy.sh 4 | 5 | echo "== Self-compilation test begins... ==" 6 | 7 | # phase 1 8 | if ! /bin/bash scripts/self1_vm.sh ; then 9 | echo "Phase 1 failed!" 10 | exit 1 11 | else 12 | echo "Phase 1 succeeded!" 13 | fi 14 | 15 | # phase 2 16 | if ! /bin/bash scripts/self2_vm.sh ; then 17 | echo "Phase 2 failed!" 18 | exit 1 19 | else 20 | echo "Phase 2 succeeded!" 21 | fi 22 | 23 | # compare binaries 24 | if cmp -s src/tests/self/luxcc1.vme src/tests/self/luxcc2.vme ; then 25 | echo "== Self-compilation test succeeded! ==" 26 | exit 0 27 | else 28 | echo "== Self-compilation test failed! ==" 29 | exit 1 30 | fi 31 | -------------------------------------------------------------------------------- /scripts/test_com_xXX.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | CC1=src/luxcc 3 | CFLAGS="-q $1" 4 | TESTS_PATH=src/tests/compile 5 | 6 | fail_counter=0 7 | fail_files="" 8 | pass_counter=0 9 | 10 | echo "== Compilation tests begin... ==" 11 | 12 | for file in $(find $TESTS_PATH/ | grep '\.c') ; do 13 | if [ ! "$LUX_QUIET" = "1" ] ; then 14 | echo $file 15 | fi 16 | 17 | $CC1 $CFLAGS $file &>/dev/null 18 | 19 | if [ "$?" != "0" ] ; then 20 | echo "failed: $file" 21 | let fail_counter=fail_counter+1 22 | fail_files="$fail_files $file" 23 | else 24 | let pass_counter=pass_counter+1 25 | fi 26 | done 27 | 28 | echo "== Compilation tests results: PASS: $pass_counter, FAIL: $fail_counter ==" 29 | -------------------------------------------------------------------------------- /src/tests/execute/other/ELFkickers/elfls/README: -------------------------------------------------------------------------------- 1 | elfls is a simple utility that displays an ELF file's program and 2 | section header tables. These tables serve as a roadmap to the rest of 3 | an ELF file's contents. The purpose of elfls is to provide a quick, 4 | top-level view of an ELF file's organization. 5 | 6 | If requested, elfls will also display the file's dependencies and 7 | source code filenames. 8 | 9 | The output is a bit terse, similar to the long format of ls, and 10 | therefore also a bit cryptic. Refer to the man page for a full 11 | description of the program's output. 12 | 13 | For more in-depth information regarding a file's contents, objdump or 14 | readelf should be used. 15 | -------------------------------------------------------------------------------- /src/tests/analyze/intconv.c: -------------------------------------------------------------------------------- 1 | int main(void) 2 | { 3 | char a = 255; /* @ warning "255 to -1" */ 4 | unsigned char b = 511; /* @ warning "511 to 255" */ 5 | short c = 65535; /* @ warning "65535 to -1" */ 6 | unsigned short d = 131071; /* @ warning "131071 to 65535" */ 7 | int e = 4294967295; /* @ warning "4294967295 to -1" */ 8 | unsigned f = 8589934591; /* @ warning "8589934591 to 4294967295" */ 9 | long g = 4294967295; /* @ warning "4294967295 to -1" */ 10 | unsigned long h = 8589934591; /* @ warning "8589934591 to 4294967295" */ 11 | unsigned long long j = 18446744073709551616U; /* @ warning "integer constant is too large for its type" */ 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /src/tests/execute/llvm/nestedloop.c: -------------------------------------------------------------------------------- 1 | /* -*- mode: c -*- 2 | * $Id$ 3 | * http://www.bagley.org/~doug/shootout/ 4 | */ 5 | 6 | #include 7 | #include 8 | 9 | #define SMALL_PROBLEM_SIZE 10 | 11 | int 12 | main(int argc, char *argv[]) { 13 | #ifdef SMALL_PROBLEM_SIZE 14 | #define LENGTH 30 15 | #else 16 | #define LENGTH 46 17 | #endif 18 | int n = ((argc == 2) ? atoi(argv[1]) : LENGTH); 19 | int a, b, c, d, e, f, x=0; 20 | 21 | for (a=0; a 11 | #include 12 | 13 | #ifndef TRUE 14 | #define TRUE 1 15 | #define FALSE 0 16 | #endif 17 | 18 | /* Allocates memory. 19 | */ 20 | #define xalloc(p, n) (((p) = realloc((p), (n))) ? (p) \ 21 | : (assert(!"Out of memory!"), (void*)0)) 22 | 23 | /* Allocates memory for a part's contents. 24 | */ 25 | #define palloc(p) (xalloc((p)->part, (p)->size)) 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /src/tests/execute/other/bzip2/testme.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | CC="src/luxdvr/luxdvr -q $1" 3 | TESTDIR=`dirname $0` 4 | 5 | if ! $CC $TESTDIR/bzip2.c -o $TESTDIR/bzip2 &>/dev/null ; then 6 | echo "Failed to compile bzip2" 7 | exit 1 8 | fi 9 | 10 | # compress and decompress the source 11 | $TESTDIR/bzip2 -c $TESTDIR/bzip2.c >$TESTDIR/out.bz2 12 | $TESTDIR/bzip2 -d -c $TESTDIR/out.bz2 >$TESTDIR/_bzip2.c 13 | cmp -s $TESTDIR/bzip2.c $TESTDIR/_bzip2.c 14 | RES=$? 15 | 16 | # clean 17 | rm -f $TESTDIR/out.bz2 $TESTDIR/_bzip2.c $TESTDIR/bzip2 18 | 19 | # compare 20 | if [ "$RES" != "0" ] ; then 21 | echo "bzip2 failed!" 22 | exit 1 23 | elif [ ! "$LUX_QUIET" = "1" ] ; then 24 | echo "bzip2 succeeded!" 25 | fi 26 | exit 0 27 | -------------------------------------------------------------------------------- /src/tests/execute/picoc_tcc/03_struct.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct fred 4 | { 5 | int boris; 6 | int natasha; 7 | }; 8 | 9 | int main(void) 10 | { 11 | struct fred bloggs; 12 | struct fred jones[2]; 13 | 14 | bloggs.boris = 12; 15 | bloggs.natasha = 34; 16 | 17 | printf("%d\n", bloggs.boris); 18 | printf("%d\n", bloggs.natasha); 19 | 20 | // struct fred jones[2]; 21 | jones[0].boris = 12; 22 | jones[0].natasha = 34; 23 | jones[1].boris = 56; 24 | jones[1].natasha = 78; 25 | 26 | printf("%d\n", jones[0].boris); 27 | printf("%d\n", jones[0].natasha); 28 | printf("%d\n", jones[1].boris); 29 | printf("%d\n", jones[1].natasha); 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /src/tests/execute/rot13.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* 4 | * Rot13 encryption 5 | */ 6 | void rot13(char *p) 7 | { 8 | int i = 0, n; 9 | while (p[i] != '\0') { 10 | if (p[i]<'A' || p[i]>'a'+26) { 11 | ++i; 12 | } else { 13 | if (p[i] < 'a') 14 | n = 'A'; 15 | else 16 | n = 'a'; 17 | p[i] = (p[i]-n+13)%26+n; 18 | ++i; 19 | } 20 | } 21 | } 22 | 23 | int main(void) 24 | { 25 | // char s[32]; 26 | // scanf("%s", s); 27 | char s[] = "hello world"; 28 | rot13(s); 29 | printf("Encrypted string: %s\n", s); 30 | rot13(s); 31 | printf("Original string: %s\n", s); 32 | } 33 | -------------------------------------------------------------------------------- /src/tests/execute/goto.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void foo(void) 4 | { 5 | printf("jumping to forth\n"); 6 | goto forth; 7 | back: 8 | printf("in back; returning\n"); 9 | return; 10 | printf("unprinted\n"); 11 | forth: 12 | printf("in forth; jumping to back\n"); 13 | goto back; 14 | printf("unprinted\n"); 15 | } 16 | 17 | void bar(void) 18 | { 19 | typedef int typedef_name_and_label; 20 | typedef_name_and_label i; 21 | 22 | i = 0; 23 | typedef_name_and_label: 24 | loop: 25 | if (i >= 5) 26 | goto end; 27 | printf("%d\n", i++); 28 | goto loop; 29 | end:; 30 | } 31 | 32 | int main(void) 33 | { 34 | foo(); 35 | bar(); 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /src/tests/compile/AnsiLove-C-master/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 2.6) 2 | 3 | project (ansilove C) 4 | 5 | include(CheckFunctionExists) 6 | include_directories(/usr/local/include /usr/pkg/include) 7 | 8 | check_function_exists(strtonum HAVE_STRTONUM) 9 | 10 | find_library(LIB_GD NAMES gd REQUIRED) 11 | 12 | set (SRC src/main.c src/albinfonts.c src/ansilove.c src/explode.c src/filesize.c src/strtolower.c src/substr.c) 13 | 14 | if(NOT HAVE_STRTONUM) 15 | set (SRC ${SRC} compat/strtonum.c) 16 | endif() 17 | 18 | add_definitions(-Wall -Wextra -std=c99 -pedantic) 19 | add_executable(ansilove ${SRC}) 20 | 21 | target_link_libraries(ansilove ${LIB_GD} m) 22 | 23 | install(TARGETS ansilove DESTINATION bin) 24 | -------------------------------------------------------------------------------- /src/tests/execute/other/ELFkickers/elfrw/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for libelfrw.a 2 | 3 | CC = gcc 4 | CFLAGS = -Wall -Wextra -O3 -fno-common -fno-stack-protector 5 | 6 | LIBOBJS = elfrw.o elfrw_dyn.o elfrw_ehdr.o elfrw_phdr.o elfrw_rel.o \ 7 | elfrw_shdr.o elfrw_sym.o elfrw_ver.o 8 | 9 | libelfrw.a: $(LIBOBJS) 10 | ar crs $@ $^ 11 | 12 | elfrw.o: elfrw.c elfrw.h elfrw_int.h 13 | elfrw_dyn.o: elfrw_dyn.c elfrw_int.h 14 | elfrw_ehdr.o: elfrw_ehdr.c elfrw_int.h 15 | elfrw_phdr.o: elfrw_phdr.c elfrw_int.h 16 | elfrw_rel.o: elfrw_rel.c elfrw_int.h 17 | elfrw_shdr.o: elfrw_shdr.c elfrw_int.h 18 | elfrw_sym.o: elfrw_sym.c elfrw_int.h 19 | elfrw_ver.o: elfrw_ver.c elfrw_int.h 20 | 21 | clean: 22 | rm -f libelfrw.a $(LIBOBJS) 23 | -------------------------------------------------------------------------------- /src/tests/execute/algol.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define STRING char * 4 | #define IF if ( 5 | #define THEN ) { 6 | #define ELSE } else { 7 | #define FI ; } 8 | #define WHILE while ( 9 | #define DO ) { 10 | #define OD ; } 11 | #define INT int 12 | #define BEGIN { 13 | #define END } 14 | #define PRINT printf ( 15 | #define PEND ) ; 16 | 17 | INT compare(STRING s1, STRING s2) 18 | BEGIN 19 | WHILE *s1++ == *s2 20 | DO IF *s2++ == 0 21 | THEN return (0); 22 | FI 23 | OD 24 | return (*--s1 - *s2); 25 | END 26 | 27 | INT main(void) 28 | BEGIN 29 | PRINT "%d\n", compare("apple", "apple") PEND 30 | PRINT "%d\n", compare("hello", "world") PEND 31 | END 32 | -------------------------------------------------------------------------------- /src/tests/execute/ret_ptr_to_arr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int (*f1(void))[5] 5 | { 6 | int (*p)[5]; 7 | 8 | p = malloc(sizeof(int)*5); 9 | (*p)[3] = 1234; 10 | return p; 11 | } 12 | 13 | int (*f2(void))[5][10] 14 | { 15 | int (*p)[5][10]; 16 | 17 | p = malloc(sizeof(int)*5*10); 18 | (*p)[1][2] = 4321; 19 | return p; 20 | } 21 | 22 | int main(void) 23 | { 24 | int (*r1)[5]; 25 | int (*r2)[5][10]; 26 | 27 | r1 = f1(); 28 | printf("%d\n", (*r1)[3]); 29 | printf("%d\n", r1[0][3]); 30 | 31 | r2 = f2(); 32 | printf("%d\n", (*r2)[1][2]); 33 | printf("%d\n", r2[0][1][2]); 34 | 35 | free(r1); 36 | free(r2); 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /src/lib/crt0_arm.asm: -------------------------------------------------------------------------------- 1 | .extern __libc_init, main, exit 2 | 3 | .bss 4 | __argc: 5 | .res #4 6 | __argv: 7 | .res #4 8 | .global __env 9 | __env: 10 | .res #4 11 | 12 | .text 13 | $a: 14 | .global _start 15 | _start: 16 | ; get argc 17 | ldr r0, [r13] 18 | ldr r3, =__argc 19 | str r0, [r3] 20 | ; get argv 21 | add r1, r13, #4 22 | ldr r3, =__argv 23 | str r1, [r3] 24 | ; get env 25 | add r0, r1, r0, LSL #2 26 | add r0, r0, #4 27 | ldr r3, =__env 28 | str r0, [r3] 29 | 30 | bl __libc_init 31 | 32 | ; do exit(main(argc, argv)) 33 | ldr r0, =__argc 34 | ldr r0, [r0] 35 | ldr r1, =__argv 36 | ldr r1, [r1] 37 | bl main 38 | bl exit 39 | 40 | .ltorg 41 | -------------------------------------------------------------------------------- /src/tests/execute/string.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define A "xyz" 4 | 5 | char test_string1[] = A "abc" "pqt"; 6 | char test_string2[] = "abc" A "pqt"; 7 | char test_string3[] = "abc" "pqt" A; 8 | char test_string4[] = "abc\ 9 | pqt\ 10 | xyz"; 11 | char test_string5[] = "abc"/* NOP */"pqt"; 12 | 13 | int main(void) 14 | { 15 | printf("%s\n", test_string1); 16 | printf("%s\n", test_string2); 17 | printf("%s\n", test_string3); 18 | printf("%s\n", test_string4); 19 | printf("%s\n", test_string5); 20 | 21 | printf("\x41\x42\x43\n"); 22 | printf("\101\102\103\n"); 23 | printf("\"test1\"\n"); 24 | printf("\\test2\\\n"); 25 | 26 | printf("'\\377'=%d '\\xff'=%d\n", '\377', '\xff'); 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /scripts/test_com_vm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | CC=src/luxcc 3 | TESTS_PATH=src/tests/compile 4 | if uname -i | grep -q "i386"; then 5 | CC="$CC -q -mvm32" 6 | else 7 | CC="$CC -q -mvm64" 8 | fi 9 | 10 | fail_counter=0 11 | fail_files="" 12 | pass_counter=0 13 | 14 | echo "== Compilation tests begin... ==" 15 | 16 | for file in $(find $TESTS_PATH/ | grep '\.c') ; do 17 | if [ ! "$LUX_QUIET" = "1" ] ; then 18 | echo $file 19 | fi 20 | 21 | $CC $file >/dev/null 22 | 23 | if [ "$?" != "0" ] ; then 24 | echo "failed: $file" 25 | let fail_counter=fail_counter+1 26 | fail_files="$fail_files $file" 27 | else 28 | let pass_counter=pass_counter+1 29 | fi 30 | done 31 | 32 | echo "== Compilation tests results: PASS: $pass_counter, FAIL: $fail_counter ==" 33 | -------------------------------------------------------------------------------- /src/lib/arm_memcpy.asm: -------------------------------------------------------------------------------- 1 | ; 2 | ; memcpy() function used by the ARM code generator. 3 | ; It doesn't modify any register. 4 | ; It expects arguments on the stack as follows: 5 | ; dest: sp+0 6 | ; src: sp+4 7 | ; n: sp+8 8 | ; 9 | .global __lux_arm_memcpy 10 | __lux_arm_memcpy: 11 | ; save registers 12 | stmdb r13!, {r4, r5, r6, r7} 13 | ; load arguments 14 | ldr r4, [r13, #16] 15 | ldr r5, [r13, #20] 16 | ldr r6, [r13, #24] 17 | top: 18 | ; copy 19 | cmp r6, #0 20 | ble done 21 | ldrb r7, [r5], #1 22 | strb r7, [r4], #1 23 | sub r6, r6, #1 24 | b top 25 | done: 26 | ; restore registers 27 | ldmia r13!, {r4, r5, r6, r7} 28 | ; remove arguments 29 | add r13, r13, #12 30 | mov r15, r14 31 | -------------------------------------------------------------------------------- /src/lib/include/termios.h: -------------------------------------------------------------------------------- 1 | #ifndef _TERMIOS_H 2 | #define _TERMIOS_H 3 | 4 | typedef unsigned char cc_t; 5 | typedef unsigned int speed_t; 6 | typedef unsigned int tcflag_t; 7 | 8 | struct termios { 9 | tcflag_t c_iflag; /* input mode flags */ 10 | tcflag_t c_oflag; /* output mode flags */ 11 | tcflag_t c_cflag; /* control mode flags */ 12 | tcflag_t c_lflag; /* local mode flags */ 13 | cc_t c_line; /* line discipline */ 14 | cc_t c_cc[32]; /* control characters */ 15 | speed_t c_ispeed; /* input speed */ 16 | speed_t c_ospeed; /* output speed */ 17 | }; 18 | 19 | #define TCIFLUSH 0 20 | #define TCOFLUSH 1 21 | #define TCIOFLUSH 2 22 | 23 | int tcflush(int fd, int queue_selector); 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /src/lib/include/ar.h: -------------------------------------------------------------------------------- 1 | #ifndef _AR_H 2 | #define _AR_H 3 | 4 | #define ARMAG "!\n" /* magic string */ 5 | #define SARMAG 8 /* length of magic string */ 6 | #define ARFMAG "`\n" /* header trailer string */ 7 | 8 | struct ar_hdr { /* file member header */ 9 | char ar_name[16]; /* '/' terminated file member name */ 10 | char ar_date[12]; /* file member date */ 11 | char ar_uid[6]; /* file member user identification */ 12 | char ar_gid[6]; /* file member group identification */ 13 | char ar_mode[8]; /* file member mode (octal) */ 14 | char ar_size[10]; /* file member size */ 15 | char ar_fmag[2]; /* header trailer string */ 16 | }; 17 | 18 | #endif /* ar.h */ 19 | -------------------------------------------------------------------------------- /src/tests/execute/other/crypto-simple/testme.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | CC="src/luxdvr/luxdvr -q $1" 3 | TESTDIR=`dirname $0` 4 | 5 | fail_counter=0 6 | 7 | for file in $TESTDIR/c/*.c ; do 8 | if ! $CC $file -o $TESTDIR/out1 &>/dev/null ; then 9 | echo "Failed to compile $file" 10 | let fail_counter=fail_counter+1 11 | continue 12 | fi 13 | 14 | $TESTDIR/out1 >"${file%.*}.output" 15 | 16 | if ! cmp -s "${file%.*}.output" "${file%.*}.expect" ; then 17 | echo "Simple crypto failed with $file" 18 | let fail_counter=fail_counter+1 19 | fi 20 | done 21 | rm -f $TESTDIR/out1 22 | 23 | if [ "$fail_counter" != "0" ] ; then 24 | echo "Simple crypto failed!" 25 | exit 1 26 | elif [ ! "$LUX_QUIET" = "1" ] ; then 27 | echo "Simple crypto succeeded!" 28 | fi 29 | exit 0 30 | -------------------------------------------------------------------------------- /src/tests/execute/stat_init3.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* 4 | * 6.6#10 5 | * The semantic rules for the evaluation of a constant expression are the same as for 6 | * nonconstant expressions. 7 | */ 8 | int i0 = 2 || 1/0; 9 | int i1 = 0 && 1/0; 10 | int i2 = 2 ? 1 : 1/0; 11 | int i3 = 0 ? 1/0 : 1; 12 | 13 | /* address of object: true or false? */ 14 | int *p0 = 0 && &i0; 15 | int *p1 = &i0 && 0; 16 | int *p2 = (int *)(1 || &i0); 17 | int *p3 = (int *)(&i0 || 1); 18 | 19 | int main(void) 20 | { 21 | printf("%d\n", i0); 22 | printf("%d\n", i1); 23 | printf("%d\n", i2); 24 | printf("%d\n", i3); 25 | 26 | printf("0x%lx\n", p0); 27 | printf("0x%lx\n", p1); 28 | printf("0x%lx\n", p2); 29 | printf("0x%lx\n", p3); 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /src/lib/vm_lib/README: -------------------------------------------------------------------------------- 1 | This directory contains a restricted version of the C standard library 2 | that is used by the VM targets. 3 | 4 | This version of the library contains mainly functions that are required 5 | for self-compilation and to run the tests. 6 | 7 | It is implemented upon the facilities reachable through the VM's `LibCall' 8 | instruction. 9 | 10 | The sources come mainly from: 11 | * The Sanos kernel: http://www.jbox.dk/sanos/source/lib/ 12 | * The Linux kernel: https://www.kernel.org/pub/linux/kernel/ 13 | 14 | Note: when invoking the compiler (`luxcc') directly (instead of through 15 | the driver) one needs to pass a `-I' option pointing to this directory 16 | so the compiler fetchs the correct headers for this version of the library. 17 | The driver does this automatically. 18 | -------------------------------------------------------------------------------- /src/luxcc.h: -------------------------------------------------------------------------------- 1 | #ifndef LUXCC_H_ 2 | #define LUXCC_H_ 3 | 4 | enum { 5 | ARCH_X86, 6 | ARCH_X64, 7 | ARCH_VM32, 8 | ARCH_VM64, 9 | ARCH_MIPS, 10 | ARCH_ARM, 11 | }; 12 | 13 | extern unsigned warning_count; 14 | extern unsigned error_count; 15 | extern int disable_warnings; 16 | extern int colored_diagnostics; 17 | extern int targeting_arch64; 18 | extern int target_arch; 19 | extern int include_liblux; 20 | extern int include_libc; 21 | extern char *cg_outpath; 22 | extern char *cfg_outpath; 23 | extern char *cfg_function_to_print; 24 | extern char *ic_outpath; 25 | extern char *ic_function_to_print; 26 | extern unsigned stat_number_of_pre_tokens; 27 | extern unsigned stat_number_of_c_tokens; 28 | extern unsigned stat_number_of_ast_nodes; 29 | extern int verbose_asm; 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /src/tests/compile/AnsiLove-C-master/AUTHORS: -------------------------------------------------------------------------------- 1 | _ __ ____ ___________ __________ ____ __ _ 2 | .________ //_ ANSilOVE _\\ ._____ 3 | ____/\ ___| _/___/\ __ _____. _ ____/\ _| \ ____ 4 | / .__\\ \ | _ //___ _)_. \_ |____ \\ | // ___/ 5 | / __/ \ \ |__ \/ \ |_ | | \ | \ / __)____ 6 | /____| \_|\_____|_________/__ `/ |______ //_______/____/______ / 7 | |______/ _ __ __________ \/ _______ \/ ________ __ _ yop \/ 8 | 9 | 10 | Ansilove/C is developed by : 11 | 12 | Stefan Vogt 13 | Brian Cassidy 14 | Frederic Cambus 15 | -------------------------------------------------------------------------------- /src/tests/execute/josephus.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Program that solves the Josephus problem. 3 | * From 'Algorithms in C' by Robert Sedgewick. 4 | */ 5 | #include 6 | #include 7 | 8 | typedef struct node* link; 9 | 10 | struct node { 11 | int item; 12 | link next; 13 | }; 14 | 15 | int main(void) 16 | { 17 | int i, N = 9, M = 5; 18 | link t = malloc(sizeof *t), x = t; 19 | 20 | t->item = 1; 21 | t->next = t; 22 | for (i = 2; i <= N; i++) { 23 | x = (x->next = malloc(sizeof *x)); 24 | x->item = i; 25 | x->next = t; 26 | } 27 | while (x != x->next) { 28 | for (i = 1; i < M; i++) 29 | x = x->next; 30 | x->next = x->next->next; 31 | N--; 32 | } 33 | printf("%d\n", x->item); 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /src/tests/execute/llvm/merge.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void merge_sort(int m, int n, int X[], int Y[], int Z[]) 4 | { 5 | int i = 0, j = 0, k = 0; /* index variables for X, Y, and Z */ 6 | while ((i < m) && (j < n)) 7 | if (X[i] <= Y[j]) /* find largest of two */ 8 | Z[k++] = X[i++]; /* copy and update indices */ 9 | else 10 | Z[k++] = Y[j++]; /* copy and update indices */ 11 | /* copy remainder of input array */ 12 | if (i < m) 13 | while (i < m) 14 | Z[k++] = X[i++]; 15 | else 16 | while (j < n) 17 | Z[k++] = Y[j++]; 18 | } 19 | 20 | int main(void) 21 | { 22 | int a1[5] = {55, 100, 532, 6111, 94343}; 23 | int a2[3] = {4, 777, 7000}; 24 | int a3[8], i; 25 | merge_sort(5, 3, a1, a2, a3); 26 | for (i = 0; i < 8; i++) 27 | printf("%d ", a3[i]); 28 | printf("\n"); 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /src/lib/include/unistd.h: -------------------------------------------------------------------------------- 1 | #ifndef _UNISTD_H 2 | #define _UNISTD_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #define STDIN_FILENO 0 9 | #define STDOUT_FILENO 1 10 | #define STDERR_FILENO 2 11 | 12 | #ifndef SEEK_SET 13 | #define SEEK_SET 0 14 | #define SEEK_CUR 1 15 | #define SEEK_END 2 16 | #endif 17 | 18 | int close(int fd); 19 | off_t lseek(int fd, off_t offset, int whence); 20 | ssize_t read(int fd, void *buf, size_t count); 21 | ssize_t write(int fd, const void *buf, size_t count); 22 | void _exit(int status); 23 | int brk(void *addr); 24 | void *sbrk(intptr_t increment); 25 | int isatty(int fd); 26 | int unlink(const char *pathname); 27 | pid_t getpid(void); 28 | pid_t fork(void); 29 | int execve(const char *filename, char *const argv[], char *const envp[]); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /src/luxld/makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | CFLAGS=-c -g -Wall -Wno-switch 3 | OBJS=luxld.o x86.o x64.o arm.o mips.o out.o copy.o 4 | 5 | all: luxld 6 | 7 | luxld: $(OBJS) 8 | $(CC) -o luxld $(OBJS) ../util/util.o ../util/ELF_util.o 9 | 10 | ../util/util.o: 11 | make -C ../util util.o 12 | 13 | ../util/ELF_util.o: 14 | make -C ../util ELF_util.o 15 | 16 | .c.o: 17 | $(CC) $(CFLAGS) $*.c 18 | 19 | clean: 20 | rm -f $(OBJS) luxld 21 | 22 | luxld.o: luxld.h x86.h x64.h mips.h arm.h ../util/util.h ../util/ELF_util.h 23 | x86.o: x86.h luxld.h copy.h ../util/util.h 24 | x64.o: x64.h luxld.h copy.h ../util/util.h 25 | mips.o: mips.h luxld.h copy.h ../util/util.h 26 | arm.o: arm.h luxld.h copy.h ../util/util.h 27 | out.o: out.h luxld.h ../util/util.h ../util/ELF_util.h 28 | copy.o: copy.h luxld.h ../util/util.h 29 | 30 | .PHONY: all clean 31 | -------------------------------------------------------------------------------- /src/tests/execute/cont_flow.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | int x = 1; 6 | top: 7 | switch (x) { 8 | case 0: 9 | x = 2; 10 | goto top; 11 | case 1: 12 | x = 0; 13 | goto top; 14 | case 2: 15 | x = -1; 16 | goto top; 17 | default: 18 | break; 19 | } 20 | printf("x=%d\n", x); 21 | for (x = 0; ; x++) 22 | if (x == 10) 23 | goto exit; 24 | exit: 25 | printf("x=%d\n", x); 26 | for (x = 0; ; ) { 27 | switch (x) { 28 | case 0: 29 | x++; 30 | continue; 31 | case 1: 32 | x++; 33 | continue; 34 | case 2: 35 | break; 36 | } 37 | break; 38 | } 39 | printf("x=%d\n", x); 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /src/tests/execute/other/ELFkickers/ebfc/bf/quine.b: -------------------------------------------------------------------------------- 1 | ->+>+++>>+>++>+>+++>>+>++>>>+>+>+>++>+>>>>+++>+>>++>+>+++>>++>++>>+>>+>++>++>+>>>>+++>+>>>>++>++>>>>+>>++>+>+++>>>++>>++++++>>+>>++>+>>>>+++>>+++++>>+>+++>>>++>>++>>+>>++>+>+++>>>++>>+++++++++++++>>+>>++>+>+++>+>+++>>>++>>++++>>+>>++>+>>>>+++>>+++++>>>>++>>>>+>+>++>>+++>+>>>>+++>+>>>>+++>+>>>>+++>>++>++>+>+++>+>++>++>>>>>>++>+>+++>>>>>+++>>>++>+>+++>+>+>++>>>>>>++>>>+>>>++>+>>>>+++>+>>>+>>++>+>++++++++++++++++++>>>>+>+>>>+>>++>+>+++>>>++>>++++++++>>+>>++>+>>>>+++>>++++++>>>+>++>>+++>+>+>++>+>+++>>>>>+++>>>+>+>>++>+>+++>>>++>>++++++++>>+>>++>+>>>>+++>>++++>>+>+++>>>>>>++>+>+++>>+>++>>>>+>+>++>+>>>>+++>>+++>>>+[[->>+<<]<+]+++++[->+++++++++<]>.[+]>>[<<+++++++[->+++++++++<]>-.------------------->-[-<.<+>>]<[+]<+>>>]<<<[-[-[-[>>+<++++++[->+++++<]]>++++++++++++++<]>+++<]++++++[->+++++++<]>+<<<-[->>>++<<<]>[->>.<<]<<] -------------------------------------------------------------------------------- /src/tests/compile/c-algorithms/COPYING: -------------------------------------------------------------------------------- 1 | 2 | Copyright (c) 2005-2008, Simon Howard 3 | 4 | Permission to use, copy, modify, and/or distribute this software 5 | for any purpose with or without fee is hereby granted, provided 6 | that the above copyright notice and this permission notice appear 7 | in all copies. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 10 | WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 11 | WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 12 | AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR 13 | CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 14 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 15 | NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 16 | CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | -------------------------------------------------------------------------------- /src/tests/execute/duff_dev.c: -------------------------------------------------------------------------------- 1 | // #include 2 | int printf(const char *, ...); 3 | 4 | #define SWITCH_LENGTH 8 5 | 6 | /* 7 | * Duff's device loop unrolling. 8 | */ 9 | void duff_device(int *dest, int *src, int len) 10 | { 11 | int n = (len+SWITCH_LENGTH-1)/SWITCH_LENGTH; /* number of iterations */ 12 | switch (len % SWITCH_LENGTH) { 13 | case 0: 14 | do { 15 | *dest++ = *src++; 16 | case 7: *dest++ = *src++; 17 | case 6: *dest++ = *src++; 18 | case 5: *dest++ = *src++; 19 | case 4: *dest++ = *src++; 20 | case 3: *dest++ = *src++; 21 | case 2: *dest++ = *src++; 22 | case 1: *dest++ = *src++; 23 | } while (--n > 0); 24 | } 25 | } 26 | 27 | int main(void) 28 | { 29 | int s[] = {1, 2, 3, 4, 5}, d[5], i; 30 | duff_device(d, s, 5); 31 | for (i = 0; i < 5; i++) 32 | printf("%d\n", d[i]); 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /src/tests/execute/other/ELFkickers/ebfc.expect: -------------------------------------------------------------------------------- 1 | hello, world 2 | ->+>+++>>+>++>+>+++>>+>++>>>+>+>+>++>+>>>>+++>+>>++>+>+++>>++>++>>+>>+>++>++>+>>>>+++>+>>>>++>++>>>>+>>++>+>+++>>>++>>++++++>>+>>++>+>>>>+++>>+++++>>+>+++>>>++>>++>>+>>++>+>+++>>>++>>+++++++++++++>>+>>++>+>+++>+>+++>>>++>>++++>>+>>++>+>>>>+++>>+++++>>>>++>>>>+>+>++>>+++>+>>>>+++>+>>>>+++>+>>>>+++>>++>++>+>+++>+>++>++>>>>>>++>+>+++>>>>>+++>>>++>+>+++>+>+>++>>>>>>++>>>+>>>++>+>>>>+++>+>>>+>>++>+>++++++++++++++++++>>>>+>+>>>+>>++>+>+++>>>++>>++++++++>>+>>++>+>>>>+++>>++++++>>>+>++>>+++>+>+>++>+>+++>>>>>+++>>>+>+>>++>+>+++>>>++>>++++++++>>+>>++>+>>>>+++>>++++>>+>+++>>>>>>++>+>+++>>+>++>>>>+>+>++>+>>>>+++>>+++>>>+[[->>+<<]<+]+++++[->+++++++++<]>.[+]>>[<<+++++++[->+++++++++<]>-.------------------->-[-<.<+>>]<[+]<+>>>]<<<[-[-[-[>>+<++++++[->+++++<]]>++++++++++++++<]>+++<]++++++[->+++++++<]>+<<<-[->>>++<<<]>[->>.<<]<<] -------------------------------------------------------------------------------- /src/tests/execute/other/crypto-algorithms/src/rot-13.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * Filename: rot-13.h 3 | * Author: Brad Conte (brad AT bradconte.com) 4 | * Copyright: 5 | * Disclaimer: This code is presented "as is" without any guarantees. 6 | * Details: Defines the API for the corresponding ROT-13 implementation. 7 | *********************************************************************/ 8 | 9 | #ifndef ROT13_H 10 | #define ROT13_H 11 | 12 | /*************************** HEADER FILES ***************************/ 13 | #include 14 | 15 | /*********************** FUNCTION DECLARATIONS **********************/ 16 | // Performs IN PLACE rotation of the input. Assumes input is NULL terminated. 17 | // Preserves each charcter's case. Ignores non alphabetic characters. 18 | void rot13(char str[]); 19 | 20 | #endif // ROT13_H 21 | -------------------------------------------------------------------------------- /src/tests/execute/qsort.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void swap(int v[], int i, int j) 4 | { 5 | int temp; 6 | temp = v[i]; 7 | v[i] = v[j]; 8 | v[j] = temp; 9 | } 10 | 11 | void quick_sort(int v[], int left, int right) 12 | { 13 | int i, last; 14 | if (left >= right) 15 | return; 16 | swap(v, left, (left+right)/2); 17 | last = left; 18 | for (i = left+1; i <= right; i++) 19 | if (v[i] < v[left]) 20 | swap(v, ++last, i); 21 | swap(v, left, last); 22 | quick_sort(v, left, last - 1); 23 | quick_sort(v, last+1, right); 24 | } 25 | 26 | int main(void) 27 | { 28 | // int a[5], i; 29 | // printf("Enter five numbers to sort:\n"); 30 | // for (i = 0; i < 5; i++) 31 | // scanf("%d", &a[i]); 32 | int a[5] = { 4, 2, 5, 1, 3 }, i; 33 | quick_sort(a, 0, 4); 34 | for (i = 0; i < 5; i++) 35 | printf("%d ", a[i]); 36 | printf("\n"); 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /src/tests/execute/picoc_tcc/11_precedence.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | int a; 6 | int b; 7 | int c; 8 | int d; 9 | int e; 10 | int f; 11 | int x; 12 | int y; 13 | 14 | a = 12; 15 | b = 34; 16 | c = 56; 17 | d = 78; 18 | e = 0; 19 | f = 1; 20 | 21 | printf("%d\n", c + d); 22 | printf("%d\n", (y = c + d)); 23 | printf("%d\n", e || e && f); 24 | printf("%d\n", e || f && f); 25 | printf("%d\n", e && e || f); 26 | printf("%d\n", e && f || f); 27 | printf("%d\n", a && f | f); 28 | printf("%d\n", a | b ^ c & d); 29 | printf("%d, %d\n", a == a, a == b); 30 | printf("%d, %d\n", a != a, a != b); 31 | printf("%d\n", a != b && c != d); 32 | printf("%d\n", a + b * c / f); 33 | printf("%d\n", a + b * c / f); 34 | printf("%d\n", (4 << 4)); 35 | printf("%d\n", (64 >> 4)); 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /src/util/bset.h: -------------------------------------------------------------------------------- 1 | #ifndef BSET_H_ 2 | #define BSET_H_ 3 | 4 | typedef struct BSet BSet; 5 | 6 | BSet *bset_new(int nmemb); 7 | void bset_free(BSet *s); 8 | void bset_cpy(BSet *s1, BSet *s2); /* s1 = s2 */ 9 | void bset_clear(BSet *s); 10 | int bset_eq(BSet *s1, BSet *s2); 11 | void bset_union(BSet *s1, BSet *s2); /* s1 = s1 U s2 */ 12 | void bset_inters(BSet *s1, BSet *s2); /* s1 = s1 ∩ s2 */ 13 | void bset_diff(BSet *s1, BSet *s2); /* s1 = s1 \ s2 */ 14 | int bset_member(BSet *s, int e); 15 | void bset_insert(BSet *s, int e); 16 | void bset_delete(BSet *s, int e); 17 | int bset_card(BSet *s); /* |s| */ 18 | /* 19 | * Return the position of the next rightmost '1', or -1 if there is none. 20 | * Note the least-significant bit is at position zero. 21 | */ 22 | int bset_iterate(BSet *s); 23 | void bset_fill(BSet *s, int n); /* give membership to everything up to (and excluding) n */ 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /src/util/util.h: -------------------------------------------------------------------------------- 1 | #ifndef UTIL_H_ 2 | #define UTIL_H_ 3 | 4 | #define TRUE 1 5 | #define FALSE 0 6 | 7 | #if DEBUG 8 | #define DEBUG_PRINTF(...) fprintf(stderr, __VA_ARGS__) 9 | #else 10 | #define DEBUG_PRINTF(...) 11 | #endif 12 | 13 | #define TERMINATE(...) fprintf(stderr, __VA_ARGS__), fprintf(stderr, "\n"), exit(EXIT_FAILURE) 14 | 15 | #define equal(s, t) (strcmp((s), (t)) == 0) 16 | #define not_equal(s, t) (strcmp((s), (t)) != 0) 17 | 18 | #define NELEMS(a) (sizeof(a)/sizeof(a[0])) 19 | #define is_po2(x) (x!=0 && (x & (x-1))==0) 20 | #define MAX(a, b) ((a) > (b) ? (a) : (b)) 21 | 22 | unsigned long hash2(unsigned long k); 23 | unsigned hash(char *s); 24 | int round_up(int num, int mul); 25 | int ilog2(unsigned val); 26 | int file_exists(char *file_path); 27 | char *replace_extension(char *fname, char *newext); 28 | int be_atoi(char *s); 29 | char *read_file(char *path); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /src/lib/include/sys/stat.h: -------------------------------------------------------------------------------- 1 | #ifndef _STAT_H 2 | #define _STAT_H 3 | 4 | #include 5 | 6 | /* File mode bits */ 7 | #define S_IRWXU 00700 8 | #define S_IRUSR 00400 9 | #define S_IWUSR 00200 10 | #define S_IXUSR 00100 11 | #define S_IRWXG 00070 12 | #define S_IRGRP 00040 13 | #define S_IWGRP 00020 14 | #define S_IXGRP 00010 15 | #define S_IRWXO 00007 16 | #define S_IROTH 00004 17 | #define S_IWOTH 00002 18 | #define S_IXOTH 00001 19 | #define S_ISUID 04000 20 | #define S_ISGID 02000 21 | #define S_ISVTX 01000 22 | 23 | /* Hopefully this value should be big enough for all supported archs. */ 24 | #define _STAT_STRUCT_SIZE 256 25 | 26 | struct stat { 27 | union { 28 | char _buf[_STAT_STRUCT_SIZE]; 29 | long long _align; 30 | } _s; 31 | }; 32 | 33 | int stat(const char *path, struct stat *buf); 34 | int chmod(const char *path, mode_t mode); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /src/lib/vm_lib/makefile: -------------------------------------------------------------------------------- 1 | CC=../../luxcc 2 | VM32AS=../../luxvm/luxasvm -vm32 3 | VM64AS=../../luxvm/luxasvm -vm64 4 | LIBC_SRC_FILES=libc.c ctype.c errno.c stdio.c stdlib.c string.c 5 | 6 | all: crt0 libc 7 | 8 | # 9 | # LuxVM stuff. 10 | # 11 | 12 | crt0: ../obj/vm32/crt0.o ../obj/vm64/crt0.o 13 | 14 | ../obj/vm32/crt0.o: crt0_32.s 15 | $(VM32AS) crt0_32.s -o ../obj/vm32/crt0.o 16 | 17 | ../obj/vm64/crt0.o: crt0_64.s 18 | $(VM64AS) crt0_64.s -o ../obj/vm64/crt0.o 19 | 20 | libc: ../obj/vm32/libc.o ../obj/vm64/libc.o 21 | 22 | ../obj/vm32/libc.o: $(LIBC_SRC_FILES) 23 | $(CC) -q -mvm32 libc.c -o libc.s && $(VM32AS) libc.s -o ../obj/vm32/libc.o && rm libc.s 24 | 25 | ../obj/vm64/libc.o: $(LIBC_SRC_FILES) 26 | $(CC) -q -mvm64 libc.c -o libc.s && $(VM64AS) libc.s -o ../obj/vm64/libc.o && rm libc.s 27 | 28 | clean: 29 | rm -f ../obj/vm32/*.o 30 | rm -f ../obj/vm64/*.o 31 | 32 | .PHONY: all clean crt0 libc 33 | -------------------------------------------------------------------------------- /src/opt.c: -------------------------------------------------------------------------------- 1 | #define DEBUG 0 2 | #include "opt.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "util/util.h" 8 | #include "ic.h" 9 | #include "expr.h" 10 | #include "util/bset.h" 11 | 12 | void opt_main(void) 13 | { 14 | unsigned n1; 15 | 16 | for (n1 = 0; n1 < cg_nodes_counter; n1++) { 17 | unsigned n2; 18 | 19 | for (n2 = cg_node(n1).bb_i; n2 <= cg_node(n1).bb_f; n2++) { 20 | unsigned i; 21 | 22 | for (i = cfg_node(n2).leader; i <= cfg_node(n2).last; i++) { 23 | unsigned tar, arg1, arg2; 24 | 25 | tar = instruction(i).tar; 26 | arg1 = instruction(i).arg1; 27 | arg2 = instruction(i).arg2; 28 | 29 | switch (instruction(i).op) { 30 | ; 31 | } 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/tests/execute/other/crypto-algorithms/testme.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | CC="src/luxdvr/luxdvr -q $1" 3 | TESTDIR=`dirname $0` 4 | OBJS="" 5 | 6 | for file in $TESTDIR/src/*.c ; do 7 | if ! $CC -c $file -o "${file%.*}.o" &>/dev/null ; then 8 | echo "Crypto: failed to compile $file" 9 | exit 1 10 | else 11 | OBJS="$OBJS ${file%.*}.o" 12 | fi 13 | done 14 | 15 | ar rcs $TESTDIR/libcrypto.a $OBJS 16 | 17 | rm -f $TESTDIR/crypto.output 18 | for file in $TESTDIR/test/*.c ; do 19 | if ! $CC -i $TESTDIR/src $file $TESTDIR/libcrypto.a -o $TESTDIR/out1 &>/dev/null ; then 20 | echo "Crypto: failed to compile $file" 21 | continue 22 | fi 23 | $TESTDIR/out1 >>$TESTDIR/crypto.output 24 | done 25 | rm -f $TESTDIR/out1 26 | 27 | if ! cmp -s $TESTDIR/crypto.output $TESTDIR/crypto.expect ; then 28 | echo "Crypto failed!" 29 | exit 1 30 | elif [ ! "$LUX_QUIET" = "1" ] ; then 31 | echo "Crypto succeeded!" 32 | fi 33 | exit 0 34 | -------------------------------------------------------------------------------- /src/tests/execute/queen.c: -------------------------------------------------------------------------------- 1 | /* from: http://rosettacode.org/wiki/N-queens_problem#C */ 2 | #include 3 | 4 | int abs2(int x) 5 | { 6 | return (x < 0) ? -x : x; 7 | } 8 | 9 | int count = 0; 10 | void solve(int n, int col, int *hist) 11 | { 12 | int i, j; 13 | 14 | if (col == n) { 15 | printf("\nNo. %d\n-----\n", ++count); 16 | for (i = 0; i < n; i++, printf("\n")) 17 | for (j = 0; j < n; j++) 18 | printf("%c", j == hist[i] ? 'Q' : ((i + j) & 1) ? ' ' : '.'); 19 | 20 | return; 21 | } 22 | 23 | #define attack(i, j) (hist[j] == i || abs2(hist[j] - i) == col - j) 24 | for (i = 0, j = 0; i < n; i++) { 25 | for (j = 0; j < col && !attack(i, j); j++) 26 | ; 27 | if (j < col) 28 | continue; 29 | 30 | hist[col] = i; 31 | solve(n, col + 1, hist); 32 | } 33 | } 34 | 35 | int main(void) 36 | { 37 | int hist[8]; 38 | solve(8, 0, hist); 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /src/tests/compile/AnsiLove-C-master/explode.h: -------------------------------------------------------------------------------- 1 | // 2 | // explode.h 3 | // AnsiLove/C 4 | // 5 | // Copyright (C) 2011-2015 Stefan Vogt, Brian Cassidy, Frederic Cambus. 6 | // All rights reserved. 7 | // 8 | // This source code is licensed under the BSD 3-Clause License. 9 | // See the file LICENSE for details. 10 | // 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #ifndef explode_h 18 | #define explode_h 19 | 20 | // Converts a delimited string into a string array. Other than PHP's 21 | // explode() function it will return an integer of strings found. I 22 | // consider this as much better approach as you can access the strings 23 | // via array pointer and you don't have to determine how many string 24 | // instances were stored overall as this is what you're getting. 25 | 26 | int32_t explode(char ***arr_ptr, char delimiter, char *str); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /src/tests/execute/other/ELFkickers/INSTALL: -------------------------------------------------------------------------------- 1 | To build one of the programs, just go to its subdirectory and run 2 | make. There's no configure script, since the programs by their nature 3 | are written for x86 Linux. 4 | 5 | (Some of the programs are architecture and Unix-flavor-neutral, and so 6 | could be used on other configurations. However I have not had the 7 | opportunity to test my code on anything but x86 Linux, so I can make 8 | no guarantees.) 9 | 10 | A top-level makefile is also provided. All it does is recursively 11 | invoke the makefile in each subdirectory, and then copy the programs 12 | and man pages to their own directories (bin and doc, respectively). 13 | You can feel free to ignore it. The top-level makefile also provides a 14 | default installation step, but as each program is self-contained, you 15 | can just use cp(1) to manually install the programs and/or man pages 16 | to the destination of your choice. 17 | -------------------------------------------------------------------------------- /src/tests/execute/queen2.c: -------------------------------------------------------------------------------- 1 | /* from: http://rosettacode.org/wiki/N-queens_problem#C */ 2 | #include 3 | #include 4 | 5 | typedef unsigned uint; 6 | uint full, *qs, count = 0, nn; 7 | 8 | void solve(uint d, uint c, uint l, uint r) 9 | { 10 | uint b, a, *s; 11 | if (!d) { 12 | count++; 13 | printf("\nNo. %d\n===========\n", count); 14 | for (a = 0; a < nn; a++, printf("\n")) 15 | for (b = 0; b < nn; b++, printf(" ")) 16 | printf("%c", " -QQ"[((b == qs[a])<<1)|((a + b)&1)]); 17 | return; 18 | } 19 | 20 | a = (c | (l <<= 1) | (r >>= 1)) & full; 21 | if (a != full) 22 | for (*(s = qs + --d) = 0, b = 1; b <= full; (*s)++, b <<= 1) 23 | if (!(b & a)) solve(d, b|c, b|l, b|r); 24 | } 25 | 26 | int main(void) 27 | { 28 | nn = 8; 29 | qs = calloc(nn, sizeof(int)); 30 | full = (1U << nn) - 1; 31 | 32 | solve(nn, 0, 0, 0); 33 | printf("\nSolutions: %d\n", count); 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /src/dflow.h: -------------------------------------------------------------------------------- 1 | #ifndef DFLOW_H_ 2 | #define DFLOW_H_ 3 | 4 | void dflow_Dom(unsigned fn); 5 | void dflow_LiveOut(unsigned fn); 6 | // void dflow_ReachIn(unsigned fn, int is_last); 7 | 8 | extern unsigned char *liveness_and_next_use; 9 | void compute_liveness_and_next_use(void); 10 | 11 | #define TAR_LIVE_MASK 0x01 12 | #define AR1_LIVE_MASK 0x02 13 | #define AR2_LIVE_MASK 0x04 14 | #define TAR_NEXT_MASK 0x08 15 | #define AR1_NEXT_MASK 0x10 16 | #define AR2_NEXT_MASK 0x20 17 | 18 | #define tar_liveness(i) (liveness_and_next_use[i] & TAR_LIVE_MASK) 19 | #define arg1_liveness(i) (liveness_and_next_use[i] & AR1_LIVE_MASK) 20 | #define arg2_liveness(i) (liveness_and_next_use[i] & AR2_LIVE_MASK) 21 | #define tar_next_use(i) (liveness_and_next_use[i] & TAR_NEXT_MASK) 22 | #define arg1_next_use(i) (liveness_and_next_use[i] & AR1_NEXT_MASK) 23 | #define arg2_next_use(i) (liveness_and_next_use[i] & AR2_NEXT_MASK) 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /src/tests/execute/multi_dim_param.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void func_1(int a[2][3][5]) 4 | { 5 | printf("%d\n", a[1][2][3]); 6 | } 7 | 8 | void func_2(int a[][3][5]) 9 | { 10 | printf("%d\n", a[1][2][3]); 11 | } 12 | 13 | void func_3(int (*a)[3][5]) 14 | { 15 | printf("%d\n", a[1][2][3]); 16 | } 17 | 18 | int main(void) 19 | { 20 | int a[2][3][5] = { 21 | { { 10, 20, 30, 40, 50 } , 22 | { 60, 70, 80, 90, 100 } , 23 | { 110, 120, 130, 140, 150 } }, 24 | { { 160, 170, 180, 190, 200 } , 25 | { 210, 220, 230, 240, 250 } , 26 | { 260, 270, 280, 290, 300 } }, 27 | }; 28 | int (*p)[3][5] = a; 29 | int (*q)[2][3][5] = &a; 30 | 31 | func_1(a); 32 | func_2(a); 33 | func_3(a); 34 | 35 | func_1(p); 36 | func_2(p); 37 | func_3(p); 38 | 39 | func_1(*q); 40 | func_2(*q); 41 | func_3(*q); 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /src/lib/include/limits.h: -------------------------------------------------------------------------------- 1 | #ifndef _LIMITS_H 2 | #define _LIMITS_H 3 | 4 | #define CHAR_BIT 8 5 | 6 | #define CHAR_MIN (-128) 7 | #define CHAR_MAX 127 8 | 9 | #define SCHAR_MIN (-128) 10 | #define SCHAR_MAX 127 11 | 12 | #define UCHAR_MAX 255 13 | 14 | #define SHRT_MIN (-32768) 15 | #define SHRT_MAX 32767 16 | #define USHRT_MAX 65535 17 | 18 | #define INT_MIN (-2147483647-1) 19 | #define INT_MAX 2147483647 20 | #define UINT_MAX 4294967295U 21 | 22 | #ifdef __LP64__ 23 | #define LONG_MIN (-9223372036854775807L-1L) 24 | #define LONG_MAX 9223372036854775807L 25 | #define ULONG_MAX 18446744073709551615UL 26 | #else 27 | #define LONG_MIN (-2147483647L-1L) 28 | #define LONG_MAX 2147483647L 29 | #define ULONG_MAX 4294967295UL 30 | #endif 31 | 32 | #define LLONG_MIN (-9223372036854775807LL-1LL) 33 | #define LLONG_MAX 9223372036854775807LL 34 | #define ULLONG_MAX 18446744073709551615ULL 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /src/lib/vm_lib/include/limits.h: -------------------------------------------------------------------------------- 1 | #ifndef _LIMITS_H 2 | #define _LIMITS_H 3 | 4 | #define CHAR_BIT 8 5 | 6 | #define CHAR_MIN (-128) 7 | #define CHAR_MAX 127 8 | 9 | #define SCHAR_MIN (-128) 10 | #define SCHAR_MAX 127 11 | 12 | #define UCHAR_MAX 255 13 | 14 | #define SHRT_MIN (-32768) 15 | #define SHRT_MAX 32767 16 | #define USHRT_MAX 65535 17 | 18 | #define INT_MIN (-2147483648) 19 | #define INT_MAX 2147483647 20 | #define UINT_MAX 4294967295U 21 | 22 | #ifdef __LP64__ 23 | #define LONG_MIN (-9223372036854775807L-1L) 24 | #define LONG_MAX 9223372036854775807L 25 | #define ULONG_MAX 18446744073709551615UL 26 | #else 27 | #define LONG_MIN (-2147483648L) 28 | #define LONG_MAX 2147483647L 29 | #define ULONG_MAX 4294967295UL 30 | #endif 31 | 32 | #define LLONG_MIN (-9223372036854775807LL-1LL) 33 | #define LLONG_MAX 9223372036854775807LL 34 | #define ULLONG_MAX 18446744073709551615ULL 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /src/tests/execute/other/ELFkickers/Makefile: -------------------------------------------------------------------------------- 1 | # The top-level makefile simply invokes all the other makefiles 2 | 3 | prefix = /usr/local 4 | 5 | PROGRAMS = elfls objres rebind sstrip elftoc ebfc infect 6 | 7 | all: $(PROGRAMS) 8 | 9 | bin/%: 10 | mkdir -p bin 11 | $(MAKE) -C$* $* 12 | cp $*/$* $@ 13 | 14 | doc/%.1: 15 | mkdir -p doc 16 | cp $*/$*.1 $@ 17 | 18 | elfls: bin/elfls doc/elfls.1 19 | objres: bin/objres doc/objres.1 20 | rebind: bin/rebind doc/rebind.1 21 | sstrip: bin/sstrip doc/sstrip.1 22 | elftoc: bin/elftoc doc/elftoc.1 23 | ebfc: bin/ebfc doc/ebfc.1 24 | infect: bin/infect doc/infect.1 25 | 26 | install: $(PROGRAMS) 27 | mkdir -p $(DESTDIR)$(prefix)/bin 28 | cp bin/* $(DESTDIR)$(prefix)/bin/. 29 | mkdir -p $(DESTDIR)$(prefix)/share/man/man1 30 | cp doc/* $(DESTDIR)$(prefix)/share/man/man1/. 31 | 32 | clean: 33 | for dir in elfrw $(PROGRAMS) ; do $(MAKE) -C$$dir clean ; done 34 | rm -f $(PROGRAMS:%=bin/%) $(PROGRAMS:%=doc/%.1) 35 | -------------------------------------------------------------------------------- /src/tests/execute/other/crypto-simple/README.md: -------------------------------------------------------------------------------- 1 | Crypto Implementations 2 | ====================== 3 | 4 | This is my collection of various cryptographic techniques implemented in various languages. 5 | The idea is for these to be simple and thoroughly commented, with a document explaining how they work, so that you can learn how the magic of cryptography actually isn't really all that difficult to understand. 6 | They're certainly not intended for production use. There are lots of better pre-existing libraries for that. 7 | 8 | Documents 9 | --------- 10 | Documentation is in here, as well as on my scribd account: 11 | 12 | * [How to Implement AES in Ruby](http://www.scribd.com/doc/33686967/How-to-Implement-AES-in-Ruby) 13 | * [How to Implement DES in Ruby](http://www.scribd.com/doc/33810102/How-to-Implement-DES-in-Ruby) 14 | 15 | Blog 16 | ---- 17 | I also have these tutorials on my blog: 18 | 19 | * [http://splinter.com.au/blog](http://splinter.com.au/blog) -------------------------------------------------------------------------------- /src/tools/regex.h: -------------------------------------------------------------------------------- 1 | #ifndef REGEX_H_ 2 | #define REGEX_H_ 3 | 4 | /* 5 | * regex_match: search for regex anywhere in text. 6 | * Return value: 7 | * - 1: match 8 | * - 0: no match 9 | * - -1: error (call regex_get_error to get more info) 10 | */ 11 | int regex_match(char *regex, char *text); 12 | 13 | /* 14 | * regex_match2: search for regex anywhere in text. 15 | * If there is a match, start and end are set to point 16 | * to the beginning and end of the matched text. 17 | * Otherwise they are left unmodified. 18 | * Return value: same as regex_match. 19 | */ 20 | int regex_match2(char *regex, char *text, char **start, char **end); 21 | 22 | /* 23 | * regex_get_error: get a string that describes the most recent error. 24 | * This function should only be called after regex_match or regex_match2 returned -1. 25 | * The returned string must not be modified by the application. 26 | */ 27 | const char *regex_get_error(void); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /src/tests/compile/sassert/conditional.c: -------------------------------------------------------------------------------- 1 | #include "../../sassert.h" 2 | 3 | int main(void) 4 | { 5 | char *pc; 6 | int *pi; 7 | void *pv; 8 | 9 | const char *pcc; 10 | volatile char *pvc; 11 | const int *pci; 12 | const void *pcv; 13 | 14 | // char *const *pcpc; 15 | // int *const *pcpi; 16 | // void *const *pcpv; 17 | 18 | __static_assert(_ASSERT_TYPE, 1 ? pc : pc, char *); 19 | __static_assert(_ASSERT_TYPE, 1 ? pi : pi, int *); 20 | __static_assert(_ASSERT_TYPE, 1 ? pv : pv, void *); 21 | __static_assert(_ASSERT_TYPE, 1 ? pc : pi, char *); 22 | __static_assert(_ASSERT_TYPE, 1 ? pc : pv, void *); 23 | __static_assert(_ASSERT_TYPE, 1 ? pcc : pc, const char *); 24 | __static_assert(_ASSERT_TYPE, 1 ? pcc : pvc, const volatile char *); 25 | __static_assert(_ASSERT_TYPE, 1 ? pci : pcv, const void *); 26 | __static_assert(_ASSERT_TYPE, 1 ? pvc : pcv, const volatile void *); 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /src/luxvm/makefile: -------------------------------------------------------------------------------- 1 | GETARCH = $(shell uname -i) 2 | CC=gcc 3 | CFLAGS=-c -g -Wall -Wextra -Wconversion 4 | ifeq ($(GETARCH),i386) 5 | VMOBJ = vm32.o 6 | else 7 | VMOBJ = vm64.o 8 | endif 9 | 10 | all: luxvm luxasvm luxldvm 11 | 12 | luxvm: $(VMOBJ) ../util/util.o operations.o 13 | $(CC) -o luxvm $(VMOBJ) ../util/util.o operations.o 14 | 15 | luxasvm: as.o ../util/util.o operations.o 16 | $(CC) -o luxasvm as.o ../util/util.o operations.o 17 | 18 | luxldvm: ld.o ../util/arena.o ../util/util.o 19 | $(CC) -o luxldvm ld.o ../util/arena.o ../util/util.o 20 | 21 | ../util/arena.o: 22 | make -C ../util arena.o 23 | 24 | ../util/util.o: 25 | make -C ../util util.o 26 | 27 | .c.o: 28 | $(CC) $(CFLAGS) $*.c 29 | 30 | clean: 31 | rm -f *.o luxvm luxasvm luxldvm 32 | 33 | $(VMOBJ): vm.h as.h operations.h 34 | as.o: as.h vm.h ../util/util.h operations.h 35 | ld.o: as.h ../util/arena.h ../util/util.h 36 | operations.o: operations.h ../util/util.h vm.h 37 | 38 | .PHONY: all clean 39 | -------------------------------------------------------------------------------- /src/pre.h: -------------------------------------------------------------------------------- 1 | #ifndef PRE_H_ 2 | #define PRE_H_ 3 | 4 | typedef enum { 5 | PRE_TOK_EOF, 6 | PRE_TOK_PUNCTUATOR, 7 | PRE_TOK_NUM, 8 | PRE_TOK_ID, 9 | PRE_TOK_CHACON, 10 | PRE_TOK_STRLIT, 11 | PRE_TOK_NL, 12 | PRE_TOK_OTHER, 13 | PRE_TOK_MACRO_REENABLER 14 | } PreToken; 15 | 16 | typedef struct PreTokenNode PreTokenNode; 17 | struct PreTokenNode { 18 | PreToken token; 19 | char *lexeme, *src_file; 20 | int src_line, src_column; 21 | char next_char; /* needed to distinguish between 22 | "name(" and "name (" in #define */ 23 | char deleted; /* TRUE/FALSE */ 24 | PreTokenNode *next; 25 | }; 26 | typedef enum { 27 | SIMPLE_MACRO, 28 | PARAMETERIZED_MACRO 29 | } MacroKind; 30 | 31 | PreTokenNode *preprocess(char *source_file); 32 | void install_macro(MacroKind kind, char *name, PreTokenNode *rep, PreTokenNode *params); 33 | void add_angle_dir(char *dir); 34 | void add_quote_dir(char *dir); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /src/lib/raw_syscall_mips.asm: -------------------------------------------------------------------------------- 1 | %section .text 2 | 3 | ; long __raw_syscall_0(long); 4 | %global __raw_syscall_0 5 | __raw_syscall_0: 6 | move $2, $4 7 | syscall 8 | jr $31 9 | nop 10 | 11 | ; long __raw_syscall_1(long, long); 12 | %global __raw_syscall_1 13 | __raw_syscall_1: 14 | move $2, $4 15 | move $4, $5 16 | syscall 17 | jr $31 18 | nop 19 | 20 | ; long __raw_syscall_2(long, long, long); 21 | %global __raw_syscall_2 22 | __raw_syscall_2: 23 | move $2, $4 24 | move $4, $5 25 | move $5, $6 26 | syscall 27 | jr $31 28 | nop 29 | 30 | ; long __raw_syscall_3(long, long, long, long); 31 | %global __raw_syscall_3 32 | __raw_syscall_3: 33 | move $2, $4 34 | move $4, $5 35 | move $5, $6 36 | move $6, $7 37 | syscall 38 | jr $31 39 | nop 40 | 41 | ; long __raw_syscall_4(long, long, long, long, long); 42 | %global __raw_syscall_4 43 | __raw_syscall_4: 44 | ; currently not needed 45 | jr $31 46 | nop 47 | -------------------------------------------------------------------------------- /src/lib/raw_syscall_x64.asm: -------------------------------------------------------------------------------- 1 | section .text 2 | 3 | ; long __raw_syscall_0(long); 4 | global __raw_syscall_0 5 | __raw_syscall_0: 6 | mov rax, rdi 7 | syscall 8 | ret 9 | 10 | ; long __raw_syscall_1(long, long); 11 | global __raw_syscall_1 12 | __raw_syscall_1: 13 | mov rax, rdi 14 | mov rdi, rsi 15 | syscall 16 | ret 17 | 18 | ; long __raw_syscall_2(long, long, long); 19 | global __raw_syscall_2 20 | __raw_syscall_2: 21 | mov rax, rdi 22 | mov rdi, rsi 23 | mov rsi, rdx 24 | syscall 25 | ret 26 | 27 | ; long __raw_syscall_3(long, long, long, long); 28 | global __raw_syscall_3 29 | __raw_syscall_3: 30 | mov rax, rdi 31 | mov rdi, rsi 32 | mov rsi, rdx 33 | mov rdx, rcx 34 | syscall 35 | ret 36 | 37 | ; long __raw_syscall_4(long, long, long, long, long); 38 | global __raw_syscall_4 39 | __raw_syscall_4: 40 | mov rax, rdi 41 | mov rdi, rsi 42 | mov rsi, rdx 43 | mov rdx, rcx 44 | mov r10, r8 45 | syscall 46 | ret 47 | -------------------------------------------------------------------------------- /src/tests/execute/auto_init.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | struct A { 6 | int a; 7 | union { 8 | char b[5]; 9 | char c; 10 | } d; 11 | short e; 12 | } s = { 1, { "abcd" }, 2 }, q = s; 13 | 14 | int m[3][2][1] = { 15 | { { 'A' }, { 'B' } }, 16 | { { 'C' }, /*zero*/ }, 17 | /*zero, zero*/ 18 | }; 19 | 20 | char msg1[] = "hello world!"; 21 | char msg2[] = { "hello again!" }; 22 | 23 | struct { 24 | char nonz1; 25 | short nonz2; 26 | int nonz3; 27 | char z1; 28 | short z2; 29 | int z3; 30 | } sz = { 1, 1, 1 /*,zero, zero, zero*/ }; 31 | 32 | printf("%d %s %c %d\n", q.a, s.d.b, q.d.c, s.e); 33 | printf("%c %c %c %d\n", m[0][0][0], m[0][1][0], m[1][0][0], m[2][1][0]); 34 | printf("%s\n", msg1); 35 | printf("%s\n", msg2); 36 | printf("%d %d %d %d %d %d\n", sz.nonz1, sz.nonz2, sz.nonz3, sz.z1, sz.z2, sz.z3); 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /src/tests/execute/loop.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | /* from tcc test suite */ 6 | int i; 7 | i = 0; 8 | while (i < 10) 9 | printf("%d", i++); 10 | printf("\n"); 11 | for(i = 0; i < 10; i++) 12 | printf("%d", i); 13 | printf("\n"); 14 | i = 0; 15 | do 16 | printf("%d", i++); 17 | while (i < 10); 18 | printf("\n"); 19 | 20 | /* break/continue tests */ 21 | i = 0; 22 | while (1) { 23 | if (i == 6) 24 | break; 25 | i++; 26 | if (i == 3) 27 | continue; 28 | printf("%d", i); 29 | } 30 | printf("\n"); 31 | i = 0; 32 | do { 33 | if (i == 6) 34 | break; 35 | i++; 36 | if (i == 3) 37 | continue; 38 | printf("%d", i); 39 | } while(1); 40 | printf("\n"); 41 | for(i = 1; i < 7; i++) { 42 | if (i == 3) 43 | continue; 44 | printf("%d", i); 45 | } 46 | printf("\n"); 47 | 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /src/tests/analyze/clash.c: -------------------------------------------------------------------------------- 1 | int x0; 2 | typedef int x0; // @ error "`x0' redeclared as different kind of symbol" 3 | 4 | typedef int x1; 5 | int x1; // @ error "`x1' redeclared as different kind of symbol" 6 | 7 | typedef int x2; 8 | typedef int x2; // @ error "redefinition of typedef `x2'" 9 | 10 | int x3; 11 | enum { x3 }; // @ error "`x3' redeclared as different kind of symbol" 12 | 13 | enum { x4 }; 14 | int x4; // @ error "`x4' redeclared as different kind of symbol" 15 | 16 | enum { x5 }; 17 | enum { x5 }; // @ error "redeclaration of enumerator `x5'" 18 | 19 | void foo(void) 20 | { 21 | int x6; 22 | int x6; // @ error "redeclaration of `x6' with no linkage" 23 | 24 | static int x7; 25 | static int x7; // @ error "redeclaration of `x7' with no linkage" 26 | 27 | extern int x8; 28 | extern int x8; 29 | 30 | int x9; 31 | extern int x9; // @ error "extern declaration of `x9' follows declaration with no linkage" 32 | 33 | extern int x10; 34 | int x10; // @ error "declaration of `x10' with no linkage follows extern declaration" 35 | } 36 | -------------------------------------------------------------------------------- /src/tests/execute/cope.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int fact(int x) 4 | { 5 | return (x > 1) ? x*fact(x-1) : 1; 6 | } 7 | 8 | int ipow(int x, int y) 9 | { 10 | int p; 11 | for (--y, p=x; y > 0; --y) 12 | p *= x; 13 | return p; 14 | } 15 | 16 | /* compute number of permutations (allow repetition) */ 17 | int PR(int n, int r) 18 | { 19 | return ipow(n, r); 20 | } 21 | 22 | /* compute number of permutations (don't allow repetition) */ 23 | int P(int n, int r) 24 | { 25 | return fact(n)/fact(n-r); 26 | } 27 | 28 | /* compute number of combinations (allow repetition) */ 29 | int CR(int n, int r) 30 | { 31 | return fact(n+r-1)/(r*fact(n-1)); 32 | } 33 | 34 | /* compute number of combinations (don't allow repetition) */ 35 | int C(int n, int r) 36 | { 37 | return fact(n)/(fact(r)*fact(n-r)); 38 | } 39 | 40 | int main(void) 41 | { 42 | printf("PR(3, 2) = %d\n", PR(3, 2)); 43 | printf("P(3, 2) = %d\n", P(3, 2)); 44 | printf("CR(3, 2) = %d\n", CR(3, 2)); 45 | printf("C(3, 2) = %d\n", C(3, 2)); 46 | 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /src/tests/execute/other/ELFkickers/ebfc/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for ebfc 2 | 3 | CC = gcc 4 | CFLAGS = -Wall -Wextra -Wno-missing-field-initializers 5 | 6 | ebfc: ebfc.o brainfuck.o libelfparts.a 7 | 8 | ebfc.o: ebfc.c elfparts.h ebfc.h 9 | brainfuck.o: brainfuck.c elfparts.h ebfc.h 10 | 11 | libelfparts.a: elfparts.o ehdr.o phdrtab.o shdrtab.o progbits.o \ 12 | strtab.o symtab.o hash.o rel.o got.o dynamic.o 13 | ar crs libelfparts.a $^ 14 | 15 | elfparts.o: elfparts.c elfparts.h gen.h 16 | ehdr.o: ehdr.c elfparts.h gen.h 17 | phdrtab.o: phdrtab.c elfparts.h gen.h 18 | shdrtab.o: shdrtab.c elfparts.h gen.h 19 | progbits.o: progbits.c elfparts.h gen.h 20 | strtab.o: strtab.c elfparts.h gen.h 21 | symtab.o: symtab.c elfparts.h gen.h 22 | hash.o: hash.c elfparts.h gen.h 23 | rel.o: rel.c elfparts.h gen.h 24 | got.o: got.c elfparts.h gen.h 25 | dynamic.o: dynamic.c elfparts.h gen.h 26 | 27 | clean: 28 | rm -f elfparts.o ehdr.o phdrtab.o shdrtab.o progbits.o strtab.o 29 | rm -f symtab.o hash.o rel.o got.o dynamic.o ebfc.o brainfuck.o 30 | rm -f ebfc libelfparts.a 31 | -------------------------------------------------------------------------------- /src/tests/compile/c-algorithms/hash-pointer.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2005-2008, Simon Howard 4 | 5 | Permission to use, copy, modify, and/or distribute this software 6 | for any purpose with or without fee is hereby granted, provided 7 | that the above copyright notice and this permission notice appear 8 | in all copies. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 11 | WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 12 | WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 13 | AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR 14 | CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 15 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 16 | NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 17 | CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 | 19 | */ 20 | 21 | #include 22 | 23 | #include "hash-pointer.h" 24 | 25 | /* Hash function for a generic pointer */ 26 | 27 | unsigned int pointer_hash(void *location) 28 | { 29 | return (unsigned int) (unsigned long) location; 30 | } 31 | 32 | -------------------------------------------------------------------------------- /src/tests/compile/AnsiLove-C-master/filesize.c: -------------------------------------------------------------------------------- 1 | // 2 | // filesize.m 3 | // AnsiLove/C 4 | // 5 | // Copyright (C) 2011-2015 Stefan Vogt, Brian Cassidy, Frederic Cambus. 6 | // All rights reserved. 7 | // 8 | // This source code is licensed under the BSD 3-Clause License. 9 | // See the file LICENSE for details. 10 | // 11 | 12 | #include "filesize.h" 13 | 14 | size_t filesize(char *filepath) 15 | { 16 | // pointer to file at path 17 | size_t size; 18 | FILE *file; 19 | 20 | // To properly determine the size, we open it in binary mode. 21 | file = fopen(filepath, "rb"); 22 | 23 | if(file != NULL) 24 | { 25 | // Error while seeking to end of file? 26 | if(fseek(file, 0, SEEK_END)) { 27 | rewind(file); 28 | fclose(file); 29 | return -1; 30 | } 31 | 32 | size = ftell(file); 33 | // Close file and return the file size. 34 | rewind(file); 35 | fclose(file); 36 | return size; 37 | } 38 | 39 | // In case we encounter an error. 40 | return -1; 41 | } 42 | -------------------------------------------------------------------------------- /src/tests/execute/other/tiny-AES128-C/Makefile: -------------------------------------------------------------------------------- 1 | #CC = avr-gcc 2 | #CFLAGS = -Wall -mmcu=atmega16 -Os -Wl,-Map,test.map 3 | #OBJCOPY = avr-objcopy 4 | CC = gcc 5 | CFLAGS = -Wall -Os -Wl,-Map,test.map 6 | OBJCOPY = objcopy 7 | 8 | # include path to AVR library 9 | INCLUDE_PATH = /usr/lib/avr/include 10 | # splint static check 11 | SPLINT = splint test.c aes.c -I$(INCLUDE_PATH) +charindex -unrecog 12 | 13 | .SILENT: 14 | .PHONY: lint clean 15 | 16 | 17 | rom.hex : test.out 18 | # copy object-code to new image and format in hex 19 | $(OBJCOPY) -j .text -O ihex test.out rom.hex 20 | 21 | test.o : test.c 22 | # compiling test.c 23 | $(CC) $(CFLAGS) -c test.c -o test.o 24 | 25 | aes.o : aes.h aes.c 26 | # compiling aes.c 27 | $(CC) $(CFLAGS) -c aes.c -o aes.o 28 | 29 | test.out : aes.o test.o 30 | # linking object code to binary 31 | $(CC) $(CFLAGS) aes.o test.o -o test.out 32 | 33 | small: test.out 34 | $(OBJCOPY) -j .text -O ihex test.out rom.hex 35 | 36 | clean: 37 | rm -f *.OBJ *.LST *.o *.gch *.out *.hex *.map 38 | 39 | lint: 40 | $(call SPLINT) 41 | -------------------------------------------------------------------------------- /src/tests/compile/c-algorithms/hash-int.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2005-2008, Simon Howard 4 | 5 | Permission to use, copy, modify, and/or distribute this software 6 | for any purpose with or without fee is hereby granted, provided 7 | that the above copyright notice and this permission notice appear 8 | in all copies. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 11 | WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 12 | WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 13 | AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR 14 | CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 15 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 16 | NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 17 | CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 | 19 | */ 20 | 21 | #include "hash-int.h" 22 | 23 | /* Hash function for a pointer to an integer */ 24 | 25 | unsigned int int_hash(void *vlocation) 26 | { 27 | int *location; 28 | 29 | location = (int *) vlocation; 30 | 31 | return (unsigned int) *location; 32 | } 33 | 34 | -------------------------------------------------------------------------------- /src/lib/raw_syscall_x86.asm: -------------------------------------------------------------------------------- 1 | section .text 2 | 3 | ; long __raw_syscall_0(long); 4 | global __raw_syscall_0 5 | __raw_syscall_0: 6 | push ebx 7 | mov eax, [esp+8] 8 | int byte 0x80 9 | pop ebx 10 | ret 11 | 12 | ; long __raw_syscall_1(long, long); 13 | global __raw_syscall_1 14 | __raw_syscall_1: 15 | push ebx 16 | mov eax, [esp+8] 17 | mov ebx, [esp+12] 18 | int byte 0x80 19 | pop ebx 20 | ret 21 | 22 | ; long __raw_syscall_2(long, long, long); 23 | global __raw_syscall_2 24 | __raw_syscall_2: 25 | push ebx 26 | mov eax, [esp+8] 27 | mov ebx, [esp+12] 28 | mov ecx, [esp+16] 29 | int byte 0x80 30 | pop ebx 31 | ret 32 | 33 | ; long __raw_syscall_3(long, long, long, long); 34 | global __raw_syscall_3 35 | __raw_syscall_3: 36 | push ebx 37 | mov eax, [esp+8] 38 | mov ebx, [esp+12] 39 | mov ecx, [esp+16] 40 | mov edx, [esp+20] 41 | int byte 0x80 42 | pop ebx 43 | ret 44 | 45 | ; long __raw_syscall_4(long, long, long, long, long); 46 | global __raw_syscall_4 47 | __raw_syscall_4: 48 | ; currently not needed 49 | ret 50 | -------------------------------------------------------------------------------- /src/lib/mips_memcpy.asm: -------------------------------------------------------------------------------- 1 | ; 2 | ; void __lux_mips_memcpy(void *dest, void *src, unsigned n); 3 | ; 4 | ; memcpy() function used by the MIPS code generator. 5 | ; It doesn't modify any register. 6 | ; It neither needs of the argument space that is generally 7 | ; allocated by the caller for register arguments. 8 | ; It expects arguments on the stack as follows: 9 | ; dest: $sp+0 10 | ; src: $sp+4 11 | ; n: $sp+8 12 | ; 13 | %global __lux_mips_memcpy 14 | __lux_mips_memcpy: 15 | ; save registers 16 | addu $29, $29, -16 17 | sw $8, 0($29) 18 | sw $9, 4($29) 19 | sw $10, 8($29) 20 | sw $11, 12($29) 21 | 22 | ; load arguments 23 | lw $8, 16($29) 24 | lw $9, 20($29) 25 | lw $10, 24($29) 26 | top: 27 | ; copy 28 | blez $10, done 29 | nop 30 | lb $11, 0($9) 31 | sb $11, 0($8) 32 | addu $8, $8, 1 33 | addu $9, $9, 1 34 | addu $10, $10, -1 35 | b top 36 | nop 37 | 38 | done: 39 | ; restore registers 40 | lw $8, 0($29) 41 | lw $9, 4($29) 42 | lw $10, 8($29) 43 | lw $11, 12($29) 44 | ; remove saved registers + arguments 45 | addu $29, $29, 28 46 | 47 | jr $31 48 | nop 49 | -------------------------------------------------------------------------------- /scripts/self1_arm.sh: -------------------------------------------------------------------------------- 1 | COMPILER="src/luxcc -q -marm" 2 | ASSEMBLER=src/luxarm/luxasarm 3 | LINKER="src/luxld/luxld -melf_armel -I/usr/arm-linux-gnueabi/lib/ld-linux.so.3" 4 | RUNC="src/lib/obj/arm/crt0.o src/lib/obj/arm/luxmemcpy.o src/lib/obj/arm/liblux.o" 5 | LIBC="src/lib/obj/arm/libc.so" 6 | OUTPROG=luxcc1 7 | 8 | fail_counter=0 9 | pass_counter=0 10 | object_files="" 11 | 12 | for file in $(find src/tests/self/ | grep '\.c') ; do 13 | if [ ! "$LUX_QUIET" = "1" ] ; then 14 | echo $file 15 | fi 16 | 17 | # compile 18 | $COMPILER $file -o "${file%.*}.s" 2>/dev/null 19 | if [ "$?" != "0" ] ; then 20 | echo "Compiler failed with file $file" 21 | let fail_counter=fail_counter+1 22 | continue 23 | fi 24 | 25 | # assemble 26 | $ASSEMBLER "${file%.*}.s" -o "${file%.*}.o" 2>/dev/null 27 | if [ "$?" != "0" ] ; then 28 | echo "Assembler failed with file $file" 29 | let fail_counter=fail_counter+1 30 | continue 31 | fi 32 | object_files="$object_files ${file%.*}.o" 33 | 34 | let pass_counter=pass_counter+1 35 | done 36 | 37 | # link 38 | if [ "$fail_counter" = "0" ]; then 39 | $LINKER -o src/tests/self/$OUTPROG $RUNC $object_files $LIBC 40 | exit $? 41 | fi 42 | 43 | exit 1 44 | -------------------------------------------------------------------------------- /src/tests/compile/AnsiLove-C-master/explode.c: -------------------------------------------------------------------------------- 1 | // 2 | // explode.m 3 | // AnsiLove/C 4 | // 5 | // Copyright (C) 2011-2015 Stefan Vogt, Brian Cassidy, Frederic Cambus. 6 | // All rights reserved. 7 | // 8 | // This source code is licensed under the BSD 3-Clause License. 9 | // See the file LICENSE for details. 10 | // 11 | 12 | #include "explode.h" 13 | 14 | int32_t explode(char ***arr_ptr, char delimiter, char *str) 15 | { 16 | char *src = str, *end, *dst; 17 | char **arr; 18 | int32_t size = 1, i; 19 | 20 | while ((end = strchr(src, delimiter)) != NULL) 21 | { 22 | ++size; 23 | src = end + 1; 24 | } 25 | 26 | arr = malloc(size * sizeof(char *) + (strlen(str) + 1) * sizeof(char)); 27 | 28 | src = str; 29 | dst = (char *) arr + size * sizeof(char *); 30 | for (i = 0; i < size; ++i) 31 | { 32 | if ((end = strchr(src, delimiter)) == NULL) 33 | end = src + strlen(src); 34 | arr[i] = dst; 35 | strncpy(dst, src, end - src); 36 | dst[end - src] = '\0'; 37 | dst += end - src + 1; 38 | src = end + 1; 39 | } 40 | *arr_ptr = arr; 41 | 42 | return size; 43 | } 44 | -------------------------------------------------------------------------------- /src/tests/execute/other/tiny-AES128-C/aes.h: -------------------------------------------------------------------------------- 1 | #ifndef _AES_H_ 2 | #define _AES_H_ 3 | 4 | #include 5 | 6 | 7 | // #define the macros below to 1/0 to enable/disable the mode of operation. 8 | // 9 | // CBC enables AES128 encryption in CBC-mode of operation and handles 0-padding. 10 | // ECB enables the basic ECB 16-byte block algorithm. Both can be enabled simultaneously. 11 | 12 | // The #ifndef-guard allows it to be configured before #include'ing or at compile time. 13 | #ifndef CBC 14 | #define CBC 1 15 | #endif 16 | 17 | #ifndef ECB 18 | #define ECB 1 19 | #endif 20 | 21 | 22 | 23 | #if defined(ECB) && ECB 24 | 25 | void AES128_ECB_encrypt(uint8_t* input, const uint8_t* key, uint8_t *output); 26 | void AES128_ECB_decrypt(uint8_t* input, const uint8_t* key, uint8_t *output); 27 | 28 | #endif // #if defined(ECB) && ECB 29 | 30 | 31 | #if defined(CBC) && CBC 32 | 33 | void AES128_CBC_encrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length, const uint8_t* key, const uint8_t* iv); 34 | void AES128_CBC_decrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length, const uint8_t* key, const uint8_t* iv); 35 | 36 | #endif // #if defined(CBC) && CBC 37 | 38 | 39 | 40 | #endif //_AES_H_ 41 | -------------------------------------------------------------------------------- /scripts/self2_arm.sh: -------------------------------------------------------------------------------- 1 | COMPILER="qemu-arm src/tests/self/luxcc1 -q -marm" 2 | ASSEMBLER=src/luxarm/luxasarm 3 | LINKER="src/luxld/luxld -melf_armel -I/usr/arm-linux-gnueabi/lib/ld-linux.so.3" 4 | RUNC="src/lib/obj/arm/crt0.o src/lib/obj/arm/luxmemcpy.o src/lib/obj/arm/liblux.o" 5 | LIBC="src/lib/obj/arm/libc.so" 6 | OUTPROG=luxcc2 7 | 8 | fail_counter=0 9 | pass_counter=0 10 | object_files="" 11 | 12 | for file in $(find src/tests/self/ | grep '\.c') ; do 13 | if [ ! "$LUX_QUIET" = "1" ] ; then 14 | echo $file 15 | fi 16 | 17 | # compile 18 | $COMPILER $file -o "${file%.*}.s" 2>/dev/null 19 | if [ "$?" != "0" ] ; then 20 | echo "Compiler failed with file $file" 21 | let fail_counter=fail_counter+1 22 | continue 23 | fi 24 | 25 | # assemble 26 | $ASSEMBLER "${file%.*}.s" -o "${file%.*}.o" 2>/dev/null 27 | if [ "$?" != "0" ] ; then 28 | echo "Assembler failed with file $file" 29 | let fail_counter=fail_counter+1 30 | continue 31 | fi 32 | object_files="$object_files ${file%.*}.o" 33 | 34 | let pass_counter=pass_counter+1 35 | done 36 | 37 | # link 38 | if [ "$fail_counter" = "0" ]; then 39 | $LINKER -o src/tests/self/$OUTPROG $RUNC $object_files $LIBC 40 | exit $? 41 | fi 42 | 43 | exit 1 44 | -------------------------------------------------------------------------------- /src/lib/raw_syscall_arm.asm: -------------------------------------------------------------------------------- 1 | .text 2 | 3 | ; long __raw_syscall_0(long); 4 | .global __raw_syscall_0 5 | __raw_syscall_0: 6 | stmdb r13!, {r7, r14} 7 | mov r7, r0 8 | swi #0 9 | ldmia r13!, {r7, r15} 10 | 11 | ; long __raw_syscall_1(long, long); 12 | .global __raw_syscall_1 13 | __raw_syscall_1: 14 | stmdb r13!, {r7, r14} 15 | mov r7, r0 16 | mov r0, r1 17 | swi #0 18 | ldmia r13!, {r7, r15} 19 | 20 | ; long __raw_syscall_2(long, long, long); 21 | .global __raw_syscall_2 22 | __raw_syscall_2: 23 | stmdb r13!, {r7, r14} 24 | mov r7, r0 25 | mov r0, r1 26 | mov r1, r2 27 | swi #0 28 | ldmia r13!, {r7, r15} 29 | 30 | ; long __raw_syscall_3(long, long, long, long); 31 | .global __raw_syscall_3 32 | __raw_syscall_3: 33 | stmdb r13!, {r7, r14} 34 | mov r7, r0 35 | mov r0, r1 36 | mov r1, r2 37 | mov r2, r3 38 | swi #0 39 | ldmia r13!, {r7, r15} 40 | 41 | ; long __raw_syscall_4(long, long, long, long, long); 42 | .global __raw_syscall_4 43 | __raw_syscall_4: 44 | stmdb r13!, {r7, r14} 45 | mov r7, r0 46 | mov r0, r1 47 | mov r1, r2 48 | mov r2, r3 49 | ldr r3, [r13, #8] 50 | swi #0 51 | ldmia r13!, {r7, r15} 52 | -------------------------------------------------------------------------------- /src/tests/execute/libtest.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int icmp1(const void *p1, const void *p2) 6 | { 7 | int32_t i1 = *(int32_t *)p1; 8 | int32_t i2 = *(int32_t *)p2; 9 | 10 | if (i1 > i2) 11 | return 1; 12 | else if (i1 < i2) 13 | return -1; 14 | return 0; 15 | } 16 | 17 | int icmp2(const void *p1, const void *p2) 18 | { 19 | int64_t l1 = *(int64_t *)p1; 20 | int64_t l2 = *(int64_t *)p2; 21 | 22 | if (l1 > l2) 23 | return 1; 24 | else if (l1 < l2) 25 | return -1; 26 | return 0; 27 | } 28 | 29 | int main(void) 30 | { 31 | int32_t i; 32 | int32_t ia[] = { 3, 1, 5, 2, 4 }, ikey; 33 | int64_t la[] = { 8, 6, 10, 7, 9 }, lkey; 34 | 35 | qsort(ia, 5, sizeof(ia[0]), icmp1); 36 | for (i = 0; i < 5; i++) 37 | printf("%d\n", ia[i]); 38 | ikey = 5; 39 | printf(">>>%d\n", *(int32_t *)bsearch(&ikey, ia, 5, sizeof(ia[0]), icmp1)); 40 | 41 | qsort(la, 5, sizeof(la[0]), icmp2); 42 | for (i = 0; i < 5; i++) 43 | printf("%lld\n", la[i]); 44 | lkey = 6; 45 | printf(">>>%lld\n", *(int64_t *)bsearch(&lkey, la, 5, sizeof(la[0]), icmp2)); 46 | 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /scripts/self1_mips.sh: -------------------------------------------------------------------------------- 1 | COMPILER="src/luxcc -q -mmips" 2 | ASSEMBLER=src/luxmips/luxasmips 3 | LINKER="src/luxld/luxld -melf_mipsel -I/usr/mipsel-linux-gnu/lib/ld.so.1" 4 | RUNC="src/lib/obj/mips/crt0.o src/lib/obj/mips/luxmemcpy.o src/lib/obj/mips/liblux.o" 5 | #LIBC="src/lib/obj/mips/libc.a" 6 | LIBC="src/lib/obj/mips/libc.so" 7 | OUTPROG=luxcc1 8 | 9 | fail_counter=0 10 | pass_counter=0 11 | object_files="" 12 | 13 | for file in $(find src/tests/self/ | grep '\.c') ; do 14 | if [ ! "$LUX_QUIET" = "1" ] ; then 15 | echo $file 16 | fi 17 | 18 | # compile 19 | $COMPILER $file -o "${file%.*}.s" 2>/dev/null 20 | if [ "$?" != "0" ] ; then 21 | echo "Compiler failed with file $file" 22 | let fail_counter=fail_counter+1 23 | continue 24 | fi 25 | 26 | # assemble 27 | $ASSEMBLER "${file%.*}.s" -o "${file%.*}.o" 2>/dev/null 28 | if [ "$?" != "0" ] ; then 29 | echo "Assembler failed with file $file" 30 | let fail_counter=fail_counter+1 31 | continue 32 | fi 33 | object_files="$object_files ${file%.*}.o" 34 | 35 | let pass_counter=pass_counter+1 36 | done 37 | 38 | # link 39 | if [ "$fail_counter" = "0" ]; then 40 | $LINKER -o src/tests/self/$OUTPROG $RUNC $object_files $LIBC 41 | exit $? 42 | fi 43 | 44 | exit 1 45 | -------------------------------------------------------------------------------- /src/tests/compile/c-algorithms/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | check_LIBRARIES=libcalgtest.a 3 | lib_LTLIBRARIES=libcalg.la 4 | 5 | MAIN_HEADERFILES = libcalg.h 6 | 7 | CALG_HEADERFILES=\ 8 | arraylist.h compare-int.h hash-int.h hash-table.h set.h \ 9 | avl-tree.h compare-pointer.h hash-pointer.h list.h slist.h \ 10 | queue.h compare-string.h hash-string.h trie.h binary-heap.h \ 11 | bloom-filter.h binomial-heap.h rb-tree.h 12 | 13 | SRC=\ 14 | arraylist.c compare-pointer.c hash-pointer.c list.c slist.c \ 15 | avl-tree.c compare-string.c hash-string.c queue.c trie.c \ 16 | compare-int.c hash-int.c hash-table.c set.c binary-heap.c \ 17 | bloom-filter.c binomial-heap.c rb-tree.c 18 | 19 | libcalgtest_a_CFLAGS=$(TEST_CFLAGS) -DALLOC_TESTING -I../test -g 20 | libcalgtest_a_SOURCES=$(SRC) $(MAIN_HEADERFILES) 21 | 22 | libcalg_la_CFLAGS=$(MAIN_CFLAGS) 23 | libcalg_la_SOURCES=$(SRC) $(MAIN_HEADERFILES) $(CALG_HEADERFILES) 24 | 25 | headerfilesdir=$(includedir)/libcalg-1.0 26 | headerfiles_HEADERS=$(MAIN_HEADERFILES) 27 | 28 | calgheaderfilesdir=$(headerfilesdir)/libcalg 29 | calgheaderfiles_HEADERS=$(CALG_HEADERFILES) 30 | 31 | EXTRA_DIST=gencov 32 | 33 | -------------------------------------------------------------------------------- /src/tests/execute/picoc_tcc/41_hashif.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | printf("#include test\n"); 6 | 7 | #if 1 8 | #if 0 9 | printf("a\n"); 10 | #else 11 | printf("b\n"); 12 | #endif 13 | #else 14 | #if 0 15 | printf("c\n"); 16 | #else 17 | printf("d\n"); 18 | #endif 19 | #endif 20 | 21 | #if 0 22 | #if 1 23 | printf("e\n"); 24 | #else 25 | printf("f\n"); 26 | #endif 27 | #else 28 | #if 1 29 | printf("g\n"); 30 | #else 31 | printf("h\n"); 32 | #endif 33 | #endif 34 | 35 | #define DEF 36 | 37 | #ifdef DEF 38 | #ifdef DEF 39 | printf("i\n"); 40 | #else 41 | printf("j\n"); 42 | #endif 43 | #else 44 | #ifdef DEF 45 | printf("k\n"); 46 | #else 47 | printf("l\n"); 48 | #endif 49 | #endif 50 | 51 | #ifndef DEF 52 | #ifndef DEF 53 | printf("m\n"); 54 | #else 55 | printf("n\n"); 56 | #endif 57 | #else 58 | #ifndef DEF 59 | printf("o\n"); 60 | #else 61 | printf("p\n"); 62 | #endif 63 | #endif 64 | 65 | #define ONE 1 66 | #define ZERO 0 67 | 68 | #if ONE 69 | #if ZERO 70 | printf("q\n"); 71 | #else 72 | printf("r\n"); 73 | #endif 74 | #else 75 | #if ZERO 76 | printf("s\n"); 77 | #else 78 | printf("t\n"); 79 | #endif 80 | #endif 81 | 82 | return 0; 83 | } 84 | -------------------------------------------------------------------------------- /scripts/self_xXX.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | TEST_PATH=src/tests/self 4 | DVR=src/luxdvr/luxdvr 5 | CC1=$TEST_PATH/luxcc1.out 6 | CC2=$TEST_PATH/luxcc2.out 7 | ASM_TMP=$TEST_PATH/asm_tmp.asm 8 | CFLAGS="-q -alt-asm-tmp $ASM_TMP $1" 9 | CGENS="$TEST_PATH/vm32_cgen/*.c $TEST_PATH/vm64_cgen/*.c $TEST_PATH/x86_cgen/*.c $TEST_PATH/x64_cgen/*.c $TEST_PATH/mips_cgen/*.c $TEST_PATH/arm_cgen/*.c" 10 | 11 | /bin/bash scripts/self_copy.sh 12 | 13 | echo "== Self-compilation test begins... ==" 14 | 15 | # phase 1 16 | $DVR $CFLAGS $TEST_PATH/*.c $TEST_PATH/util/*.c $CGENS -o $CC1 &>/dev/null 17 | if [ "$?" != "0" ] ; then 18 | echo "Phase 1 failed!" 19 | exit 1 20 | else 21 | echo "Phase 1 succeeded!" 22 | fi 23 | 24 | # phase 2 25 | mv src/luxcc src/luxcc_tmp 26 | cp $CC1 src/luxcc 27 | $DVR $CFLAGS $TEST_PATH/*.c $TEST_PATH/util/*.c $CGENS -o $CC2 &>/dev/null 28 | if [ "$?" != "0" ] ; then 29 | echo "Phase 2 failed!" 30 | mv src/luxcc_tmp src/luxcc 31 | exit 1 32 | else 33 | echo "Phase 2 succeeded!" 34 | mv src/luxcc_tmp src/luxcc 35 | fi 36 | 37 | # compare binaries 38 | if cmp -s $CC1 $CC2 ; then 39 | echo "== Self-compilation test succeeded! ==" 40 | exit 0 41 | else 42 | echo "== Self-compilation test failed! ==" 43 | exit 1 44 | fi 45 | -------------------------------------------------------------------------------- /src/tests/execute/other/crypto-algorithms/src/md2.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * Filename: md2.h 3 | * Author: Brad Conte (brad AT bradconte.com) 4 | * Copyright: 5 | * Disclaimer: This code is presented "as is" without any guarantees. 6 | * Details: Defines the API for the corresponding MD2 implementation. 7 | *********************************************************************/ 8 | 9 | #ifndef MD2_H 10 | #define MD2_H 11 | 12 | /*************************** HEADER FILES ***************************/ 13 | #include 14 | 15 | /****************************** MACROS ******************************/ 16 | #define MD2_BLOCK_SIZE 16 17 | 18 | /**************************** DATA TYPES ****************************/ 19 | typedef unsigned char BYTE; // 8-bit byte 20 | 21 | typedef struct { 22 | BYTE data[16]; 23 | BYTE state[48]; 24 | BYTE checksum[16]; 25 | int len; 26 | } MD2_CTX; 27 | 28 | /*********************** FUNCTION DECLARATIONS **********************/ 29 | void md2_init(MD2_CTX *ctx); 30 | void md2_update(MD2_CTX *ctx, const BYTE data[], size_t len); 31 | void md2_final(MD2_CTX *ctx, BYTE hash[]); // size of hash must be MD2_BLOCK_SIZE 32 | 33 | #endif // MD2_H 34 | -------------------------------------------------------------------------------- /src/tests/execute/stat_init.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct A { 4 | int a; 5 | union { 6 | char b[5]; 7 | char c; 8 | } d; 9 | short e; 10 | } s = { 1, { "abcd" }, 2 }; 11 | 12 | int m[3][2][1] = { 13 | { { 'A' }, { 'B' } }, 14 | { { 'C' }, /*zero*/ }, 15 | /*zero, zero*/ 16 | }, (*mp)[2][1] = m+1; 17 | 18 | char msg[] = "hello world!", *msg2 = msg+6; 19 | 20 | struct { 21 | char nonz1; 22 | short nonz2; 23 | int nonz3; 24 | char z1; 25 | short z2; 26 | int z3; 27 | } sz = { 1, 1, 1 /*,zero, zero, zero*/ }; 28 | 29 | unsigned char x1 = 0xAABBCCDD; 30 | unsigned short x2 = 0xAABBCCDD; 31 | unsigned int x3 = 0xAABBCCDD; 32 | 33 | int foo(void) { return 199; } 34 | int (*fp)(void) = foo; 35 | 36 | int main(void) 37 | { 38 | printf("%d %s %c %d\n", s.a, s.d.b, s.d.c, s.e); 39 | printf("%c %c %c %d\n", m[0][0][0], m[0][1][0], m[1][0][0], m[2][1][0]); 40 | printf("%c\n", mp[0][0][0]); 41 | printf("%s\n", msg); 42 | printf("%lu\n", sizeof(msg)); 43 | printf("%s\n", msg2); 44 | printf("%d %d %d %d %d %d\n", sz.nonz1, sz.nonz2, sz.nonz3, sz.z1, sz.z2, sz.z3); 45 | printf("%x %x %x\n", x1, x2, x3); 46 | printf("%d\n", fp()); 47 | 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /scripts/self2_mips.sh: -------------------------------------------------------------------------------- 1 | COMPILER="qemu-mipsel -L /usr/mipsel-linux-gnu/ src/tests/self/luxcc1 -q -mmips" 2 | ASSEMBLER=src/luxmips/luxasmips 3 | LINKER="src/luxld/luxld -melf_mipsel -I/usr/mipsel-linux-gnu/lib/ld.so.1" 4 | RUNC="src/lib/obj/mips/crt0.o src/lib/obj/mips/luxmemcpy.o src/lib/obj/mips/liblux.o" 5 | #LIBC="src/lib/obj/mips/libc.a" 6 | LIBC="src/lib/obj/mips/libc.so" 7 | OUTPROG=luxcc2 8 | 9 | fail_counter=0 10 | pass_counter=0 11 | object_files="" 12 | 13 | for file in $(find src/tests/self/ | grep '\.c') ; do 14 | if [ ! "$LUX_QUIET" = "1" ] ; then 15 | echo $file 16 | fi 17 | 18 | # compile 19 | $COMPILER $file -o "${file%.*}.s" 2>/dev/null 20 | if [ "$?" != "0" ] ; then 21 | echo "Compiler failed with file $file" 22 | let fail_counter=fail_counter+1 23 | continue 24 | fi 25 | 26 | # assemble 27 | $ASSEMBLER "${file%.*}.s" -o "${file%.*}.o" 2>/dev/null 28 | if [ "$?" != "0" ] ; then 29 | echo "Assembler failed with file $file" 30 | let fail_counter=fail_counter+1 31 | continue 32 | fi 33 | object_files="$object_files ${file%.*}.o" 34 | 35 | let pass_counter=pass_counter+1 36 | done 37 | 38 | # link 39 | if [ "$fail_counter" = "0" ]; then 40 | $LINKER -o src/tests/self/$OUTPROG $RUNC $object_files $LIBC 41 | exit $? 42 | fi 43 | 44 | exit 1 45 | -------------------------------------------------------------------------------- /src/lib/vm_lib/include/stdlib.h: -------------------------------------------------------------------------------- 1 | #ifndef _STDLIB_H 2 | #define _STDLIB_H 3 | 4 | #include /* for size_t, wchar_t, NULL */ 5 | 6 | #define EXIT_FAILURE 1 /* Failing exit status. */ 7 | #define EXIT_SUCCESS 0 /* Successful exit status. */ 8 | 9 | /* Numeric conversion functions */ 10 | int atoi(const char *nptr); 11 | long int strtol(const char *nptr, char **endptr, int base); 12 | long long int strtoll(const char *nptr, char **endptr, int base); 13 | unsigned long int strtoul(const char *nptr, char **endptr, int base); 14 | unsigned long long int strtoull(const char *nptr, char **endptr, int base); 15 | 16 | /* Memory management functions */ 17 | void *calloc(size_t nmemb, size_t size); 18 | void free(void *ptr); 19 | void *malloc(size_t size); 20 | void *realloc(void *ptr, size_t size); 21 | 22 | /* Communication with the environment */ 23 | void exit(int status); 24 | char *getenv(const char *name); 25 | 26 | /* Searching and sorting utilities */ 27 | void *bsearch(const void *key, const void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *)); 28 | void qsort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *)); 29 | 30 | /* POSIX */ 31 | long int random(void); 32 | void srandom(unsigned int seed); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /src/lib/vm_lib/include/string.h: -------------------------------------------------------------------------------- 1 | #ifndef _STRING_H 2 | #define _STRING_H 3 | 4 | #include /* for size_t, NULL */ 5 | 6 | /* Copying functions */ 7 | void *memcpy(void *s1, const void *s2, size_t n); 8 | void *memmove(void *s1, const void *s2, size_t n); 9 | char *strcpy(char *s1, const char *s2); 10 | char *strncpy(char *s1, const char *s2, size_t n); 11 | 12 | /* Concatenation functions */ 13 | char *strcat(char *s1, const char *s2); 14 | char *strncat(char *s1, const char *s2, size_t n); 15 | 16 | /* Comparison functions */ 17 | int memcmp(const void *s1, const void *s2, size_t n); 18 | int strcmp(const char *s1, const char *s2); 19 | int strncmp(const char *s1, const char *s2, size_t n); 20 | 21 | /* Search functions */ 22 | void *memchr(const void *s, int c, size_t n); 23 | char *strchr(const char *s, int c); 24 | char *strpbrk(const char *s1, const char *s2); 25 | char *strrchr(const char *s, int c); 26 | size_t strspn(const char *s1, const char *s2); 27 | char *strstr(const char *s1, const char *s2); 28 | char *strtok(char *s1, const char *s2); 29 | 30 | /* Miscellaneous functions */ 31 | void *memset(void *s, int c, size_t n); 32 | size_t strlen(const char *s); 33 | 34 | /* POSIX */ 35 | char *strdup(const char *s); 36 | size_t strnlen(const char *s, size_t maxlen); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /src/lib/setjmp_arm.asm: -------------------------------------------------------------------------------- 1 | .text 2 | 3 | ; arm jmp_buf: 4 | ; 5 | ; typedef struct { 6 | ; long long _align; 7 | ; int _sp; 8 | ; int _v1; 9 | ; int _v2; 10 | ; int _v3; 11 | ; int _v4; 12 | ; int _v5; 13 | ; int _v6; 14 | ; int _v7; 15 | ; int _v8; 16 | ; int _lr; 17 | ; } jmp_buf[1]; 18 | 19 | ; int setjmp(jmp_buf env); 20 | .global setjmp:function 21 | setjmp: 22 | ; fill buf 23 | str r13, [r0, #8] 24 | str r4, [r0, #12] 25 | str r5, [r0, #16] 26 | str r6, [r0, #20] 27 | str r7, [r0, #24] 28 | str r8, [r0, #28] 29 | str r9, [r0, #32] 30 | str r10, [r0, #36] 31 | str r11, [r0, #40] 32 | str r14, [r0, #44] 33 | ; a direct invocation to setjmp() returns zero 34 | eor r0, r0, r0 35 | mov r15, r14 36 | 37 | ; void longjmp(jmp_buf env, int val); 38 | .global longjmp:function 39 | longjmp: 40 | ; restore registers 41 | ldr r13, [r0, #8] 42 | ldr r4, [r0, #12] 43 | ldr r5, [r0, #16] 44 | ldr r6, [r0, #20] 45 | ldr r7, [r0, #24] 46 | ldr r8, [r0, #28] 47 | ldr r9, [r0, #32] 48 | ldr r10, [r0, #36] 49 | ldr r11, [r0, #40] 50 | ldr r14, [r0, #44] 51 | ; we always return != zero 52 | cmp r1, #0 53 | bne done 54 | ldr r1, =#1 55 | done: 56 | mov r15, r14 57 | 58 | -------------------------------------------------------------------------------- /src/lib/setjmp_mips.asm: -------------------------------------------------------------------------------- 1 | %section .text 2 | 3 | ; mips jmp_buf: 4 | ; 5 | ; typedef struct { 6 | ; int _sp; 7 | ; int _fp; 8 | ; int _s0; 9 | ; int _s1; 10 | ; int _s2; 11 | ; int _s3; 12 | ; int _s4; 13 | ; int _s5; 14 | ; int _s6; 15 | ; int _s7; 16 | ; int _pc; 17 | ; } jmp_buf[1]; 18 | 19 | ; int setjmp(jmp_buf env); 20 | %global setjmp:function 21 | setjmp: 22 | ; fill buf 23 | sw $29, 0($4) 24 | sw $30, 4($4) 25 | sw $16, 8($4) 26 | sw $17, 12($4) 27 | sw $18, 16($4) 28 | sw $19, 20($4) 29 | sw $20, 24($4) 30 | sw $21, 28($4) 31 | sw $22, 32($4) 32 | sw $23, 36($4) 33 | sw $31, 40($4) 34 | ; a direct invocation to setjmp() returns zero 35 | move $2, $0 36 | jr $31 37 | nop 38 | 39 | ; void longjmp(jmp_buf env, int val); 40 | %global longjmp:function 41 | longjmp: 42 | ; restore registers 43 | lw $29, 0($4) 44 | lw $30, 4($4) 45 | lw $16, 8($4) 46 | lw $17, 12($4) 47 | lw $18, 16($4) 48 | lw $19, 20($4) 49 | lw $20, 24($4) 50 | lw $21, 28($4) 51 | lw $22, 32($4) 52 | lw $23, 36($4) 53 | lw $31, 40($4) 54 | ; we always return != zero 55 | bne $5, $0, done 56 | nop 57 | li $5, 1 58 | done: 59 | move $2, $5 60 | jr $31 61 | nop 62 | 63 | -------------------------------------------------------------------------------- /src/tests/compile/c-algorithms/compare-pointer.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2005-2008, Simon Howard 4 | 5 | Permission to use, copy, modify, and/or distribute this software 6 | for any purpose with or without fee is hereby granted, provided 7 | that the above copyright notice and this permission notice appear 8 | in all copies. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 11 | WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 12 | WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 13 | AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR 14 | CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 15 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 16 | NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 17 | CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 | 19 | */ 20 | 21 | #include "compare-pointer.h" 22 | 23 | /* Comparison functions for a generic void pointer */ 24 | 25 | int pointer_equal(void *location1, void *location2) 26 | { 27 | return location1 == location2; 28 | } 29 | 30 | int pointer_compare(void *location1, void *location2) 31 | { 32 | if (location1 < location2) { 33 | return -1; 34 | } else if (location1 > location2) { 35 | return 1; 36 | } else { 37 | return 0; 38 | } 39 | } 40 | 41 | 42 | -------------------------------------------------------------------------------- /src/tests/execute/other/crypto-algorithms/src/base64.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * Filename: base64.h 3 | * Author: Brad Conte (brad AT bradconte.com) 4 | * Copyright: 5 | * Disclaimer: This code is presented "as is" without any guarantees. 6 | * Details: Defines the API for the corresponding Base64 implementation. 7 | *********************************************************************/ 8 | 9 | #ifndef BASE64_H 10 | #define BASE64_H 11 | 12 | /*************************** HEADER FILES ***************************/ 13 | #include 14 | 15 | /**************************** DATA TYPES ****************************/ 16 | typedef unsigned char BYTE; // 8-bit byte 17 | 18 | /*********************** FUNCTION DECLARATIONS **********************/ 19 | // Returns the size of the output. If called with out = NULL, will just return 20 | // the size of what the output would have been (without a terminating NULL). 21 | size_t base64_encode(const BYTE in[], BYTE out[], size_t len, int newline_flag); 22 | 23 | // Returns the size of the output. If called with out = NULL, will just return 24 | // the size of what the output would have been (without a terminating NULL). 25 | size_t base64_decode(const BYTE in[], BYTE out[], size_t len); 26 | 27 | #endif // BASE64_H 28 | -------------------------------------------------------------------------------- /src/lib/setjmp_x86.asm: -------------------------------------------------------------------------------- 1 | section .text 2 | 3 | ; i386 jmp_buf: 4 | ; 5 | ; typedef struct { 6 | ; int _ebx; 7 | ; int _ebp; 8 | ; int _esp; 9 | ; int _edi; 10 | ; int _esi; 11 | ; int _eip; 12 | ; } jmp_buf[1]; 13 | 14 | ; int setjmp(jmp_buf env); 15 | global setjmp:function 16 | setjmp: 17 | mov edx, [esp+4] ; edx = &env 18 | mov eax, [esp] ; eax = return address 19 | ; fill buf 20 | mov [edx+0], ebx 21 | mov [edx+4], ebp 22 | mov [edx+8], esp 23 | mov [edx+12], edi 24 | mov [edx+16], esi 25 | mov [edx+20], eax 26 | ; a direct invocation to setjmp() returns zero 27 | xor eax, eax 28 | ret 29 | 30 | ; void longjmp(jmp_buf env, int val); 31 | global longjmp:function 32 | longjmp: 33 | mov edx, [esp+4] ; edx = &env 34 | mov eax, [esp+8] ; eax = val 35 | ; restore stack pointer 36 | mov esp, [edx+8] 37 | ; set our return address to be the same as the return 38 | ; address of the setjmp() call that filled this buffer 39 | mov ebx, [edx+20] 40 | mov [esp], ebx 41 | ; restore the other regs 42 | mov ebx, [edx+0] 43 | mov ebp, [edx+4] 44 | mov edi, [edx+12] 45 | mov esi, [edx+16] 46 | ; we always return != zero 47 | or eax, eax 48 | jne .done 49 | mov eax, 1 50 | .done: 51 | ret 52 | 53 | -------------------------------------------------------------------------------- /src/tests/analyze/tags.c: -------------------------------------------------------------------------------- 1 | struct A1 { 2 | int x; 3 | }; 4 | void f0(void) 5 | { 6 | struct A1; // new incomplete type 7 | struct A1 x; // @ error "`x' has no linkage and incomplete type" 8 | } 9 | 10 | 11 | struct A2 { 12 | int x; 13 | }; 14 | void f1(void) 15 | { 16 | struct A2 x; // no new type, references the previous 17 | } 18 | 19 | 20 | void f2(void) 21 | { 22 | struct A3 x; // @ error "`x' has no linkage and incomplete type" 23 | } 24 | 25 | 26 | struct A4; // new incomplete type 27 | struct A4 { 28 | int x; 29 | }; // type completed 30 | struct A4; // no new type 31 | struct A4 a4s; // OK 32 | 33 | 34 | struct A5 { 35 | int x; 36 | }; 37 | void f3(void) 38 | { 39 | struct A5 x; 40 | struct A5; // new incomplete type 41 | struct A5 x2; // @ error "`x2' has no linkage and incomplete type" 42 | } 43 | 44 | union A6 { 45 | int x; 46 | }; 47 | void f4(void) 48 | { 49 | struct A6 x; // @ error "use of `A6' with tag type that does not match previous declaration" 50 | } 51 | 52 | struct A7; 53 | void f5(void) 54 | { 55 | struct A7 *x; // no new type, references the previous 56 | } 57 | 58 | 59 | void f6(struct A8); 60 | // A8 goes out of scope... 61 | void f6(struct A8); // @ error "conflicting types" 62 | 63 | 64 | struct A9; 65 | void f7(struct A9); 66 | void f7(struct A9); 67 | -------------------------------------------------------------------------------- /src/tests/execute/other/tiny-AES128-C/unlicense.txt: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /src/expr.h: -------------------------------------------------------------------------------- 1 | #ifndef EXPR_H_ 2 | #define EXPR_H_ 3 | 4 | #include "parser.h" 5 | 6 | #define LLONG_RANK 5 7 | #define LONG_RANK 4 8 | #define INT_RANK 3 9 | #define SHORT_RANK 2 10 | #define CHAR_RANK 1 11 | 12 | void analyze_primary_expression(ExecNode *e); 13 | void analyze_postfix_expression(ExecNode *e); 14 | void analyze_unary_expression(ExecNode *e); 15 | void analyze_cast_expression(ExecNode *e); 16 | void analyze_multiplicative_expression(ExecNode *e); 17 | void analyze_additive_expression(ExecNode *e); 18 | void analyze_assignment_expression(ExecNode *e); 19 | void analyze_bitwise_operator(ExecNode *e); 20 | void analyze_relational_equality_expression(ExecNode *e); 21 | void analyze_logical_operator(ExecNode *e); 22 | void analyze_conditional_expression(ExecNode *e); 23 | void analyze_expression(ExecNode *e); 24 | 25 | int can_assign_to(Declaration *dest_ty, ExecNode *e); 26 | long long eval_const_expr(ExecNode *e, int is_addr, int is_iconst); 27 | int is_signed_int(Token ty); 28 | int is_unsigned_int(Token ty); 29 | int is_integer(Token ty); 30 | int is_pointer(Token op); 31 | int get_rank(Token ty); 32 | TypeExp *get_type_node(Token ty); 33 | Token get_type_category(Declaration *d); 34 | Token get_promoted_type(Token int_ty); 35 | unsigned get_alignment(Declaration *ty); 36 | unsigned get_sizeof(Declaration *ty); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /src/lib/include/time.h: -------------------------------------------------------------------------------- 1 | #ifndef _TIME_H 2 | #define _TIME_H 3 | 4 | #include /* for NULL, size_t */ 5 | 6 | #define CLOCKS_PER_SEC ((clock_t)1000000) /* as defined by POSIX */ 7 | 8 | typedef long int clock_t; 9 | typedef long int time_t; 10 | 11 | struct tm { 12 | int tm_sec; /* seconds after the minute -- [0, 60] */ 13 | int tm_min; /* minutes after the hour -- [0, 59] */ 14 | int tm_hour; /* hours since midnight -- [0, 23] */ 15 | int tm_mday; /* day of the month -- [1, 31] */ 16 | int tm_mon; /* months since January -- [0, 11] */ 17 | int tm_year; /* year since 1900 */ 18 | int tm_wday; /* days since Sunday -- [0, 6] */ 19 | int tm_yday; /* days since January 1 -- [0, 365] */ 20 | int tm_isdst; /* Daylight Saving Time flag */ 21 | }; 22 | 23 | /* Time manipulation functions */ 24 | clock_t clock(void); 25 | /*double difftime(time_t time1, time_t time0);*/ 26 | /*time_t mktime(struct tm *timeptr);*/ 27 | time_t time(time_t *timer); 28 | 29 | /* Time conversion functions */ 30 | char *asctime(const struct tm *timeptr); 31 | /*char *ctime(const time_t *timer);*/ 32 | /*struct tm *gmtime(const time_t *timer);*/ 33 | /*struct tm *localtime(const time_t *timer);*/ 34 | /*size_t strftime(char *s, size_t maxsize, const char *format, const struct tm *timeptr);*/ 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /src/tests/execute/sieve.c: -------------------------------------------------------------------------------- 1 | /* sieve of Eratosthenes. From: http://c2.com/cgi/wiki?SieveOfEratosthenes */ 2 | #include 3 | #include 4 | 5 | int main(void) 6 | { 7 | int top_value = 100; 8 | int count = top_value - 1; 9 | int *array = calloc(top_value + 1, sizeof(int)); 10 | int i, prime, multiple; 11 | /* mark each int as potentially prime */ 12 | for (i=2; i <= top_value; ++i) 13 | array[i] = 1; 14 | /* for each starting prime, mark its every multiple as non-prime */ 15 | for (prime = 2; prime <= top_value; ++prime) 16 | { 17 | if (array[prime]) 18 | for (multiple = 2*prime; multiple <= top_value; multiple += prime) 19 | if (array[multiple]) { 20 | array[multiple] = 0; 21 | --count; 22 | } 23 | } 24 | /* Now that we have marked all multiples of primes as non-prime, print */ 25 | /* the remaining numbers that fell through the sieve, and are thus prime */ 26 | for (i=2; i <= top_value; ++i) 27 | { 28 | if (array[i]) 29 | printf("%d ", i); 30 | } 31 | printf("\n\n %d primes up to %d found.\n", count, top_value); 32 | exit(0); 33 | } 34 | -------------------------------------------------------------------------------- /src/tests/execute/other/crypto-algorithms/src/md5.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * Filename: md5.h 3 | * Author: Brad Conte (brad AT bradconte.com) 4 | * Copyright: 5 | * Disclaimer: This code is presented "as is" without any guarantees. 6 | * Details: Defines the API for the corresponding MD5 implementation. 7 | *********************************************************************/ 8 | 9 | #ifndef MD5_H 10 | #define MD5_H 11 | 12 | /*************************** HEADER FILES ***************************/ 13 | #include 14 | 15 | /****************************** MACROS ******************************/ 16 | #define MD5_BLOCK_SIZE 16 // MD5 outputs a 16 byte digest 17 | 18 | /**************************** DATA TYPES ****************************/ 19 | typedef unsigned char BYTE; // 8-bit byte 20 | typedef unsigned int WORD; // 32-bit word, change to "long" for 16-bit machines 21 | 22 | typedef struct { 23 | BYTE data[64]; 24 | WORD datalen; 25 | unsigned long /*long*/ bitlen; 26 | WORD state[4]; 27 | } MD5_CTX; 28 | 29 | /*********************** FUNCTION DECLARATIONS **********************/ 30 | void md5_init(MD5_CTX *ctx); 31 | void md5_update(MD5_CTX *ctx, const BYTE data[], size_t len); 32 | void md5_final(MD5_CTX *ctx, BYTE hash[]); 33 | 34 | #endif // MD5_H 35 | -------------------------------------------------------------------------------- /src/error.c: -------------------------------------------------------------------------------- 1 | #include "error.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "luxcc.h" 7 | 8 | void emit_error(int fatal, char *file, int line, int column, char *fmt, ...) 9 | { 10 | va_list args; 11 | 12 | /*if (fatal) 13 | fprintf(stderr, "An unrecoverable error occurred\n");*/ 14 | 15 | if (!colored_diagnostics || !isatty(fileno(stderr))) 16 | fprintf(stderr, "%s:%d:%d: error: ", file, line, column); 17 | else 18 | fprintf(stderr, INFO_COLOR "%s:%d:%d: " ERROR_COLOR "error: " RESET_ATTR, file, line, column); 19 | 20 | va_start(args, fmt); 21 | vfprintf(stderr, fmt, args); 22 | va_end(args); 23 | 24 | fprintf(stderr, "\n"); 25 | 26 | if (fatal) 27 | exit(EXIT_FAILURE); 28 | 29 | ++error_count; 30 | } 31 | 32 | void emit_warning(char *file, int line, int column, char *fmt, ...) 33 | { 34 | va_list args; 35 | 36 | if (disable_warnings) 37 | return; 38 | 39 | if (colored_diagnostics) 40 | fprintf(stderr, INFO_COLOR "%s:%d:%d: " WARNING_COLOR "warning: " RESET_ATTR, file, line, column); 41 | else 42 | fprintf(stderr, "%s:%d:%d: warning: ", file, line, column); 43 | 44 | va_start(args, fmt); 45 | vfprintf(stderr, fmt, args); 46 | va_end(args); 47 | 48 | fprintf(stderr, "\n"); 49 | 50 | ++warning_count; 51 | } 52 | -------------------------------------------------------------------------------- /src/tests/execute/other/crypto-algorithms/src/sha1.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * Filename: sha1.h 3 | * Author: Brad Conte (brad AT bradconte.com) 4 | * Copyright: 5 | * Disclaimer: This code is presented "as is" without any guarantees. 6 | * Details: Defines the API for the corresponding SHA1 implementation. 7 | *********************************************************************/ 8 | 9 | #ifndef SHA1_H 10 | #define SHA1_H 11 | 12 | /*************************** HEADER FILES ***************************/ 13 | #include 14 | 15 | /****************************** MACROS ******************************/ 16 | #define SHA1_BLOCK_SIZE 20 // SHA1 outputs a 20 byte digest 17 | 18 | /**************************** DATA TYPES ****************************/ 19 | typedef unsigned char BYTE; // 8-bit byte 20 | typedef unsigned int WORD; // 32-bit word, change to "long" for 16-bit machines 21 | 22 | typedef struct { 23 | BYTE data[64]; 24 | WORD datalen; 25 | unsigned long /*long*/ bitlen; 26 | WORD state[5]; 27 | WORD k[4]; 28 | } SHA1_CTX; 29 | 30 | /*********************** FUNCTION DECLARATIONS **********************/ 31 | void sha1_init(SHA1_CTX *ctx); 32 | void sha1_update(SHA1_CTX *ctx, const BYTE data[], size_t len); 33 | void sha1_final(SHA1_CTX *ctx, BYTE hash[]); 34 | 35 | #endif // SHA1_H 36 | -------------------------------------------------------------------------------- /src/tests/execute/other/ELFkickers/ebfc/progbits.c: -------------------------------------------------------------------------------- 1 | /* progbits.c: parts containing segments of the program. 2 | * 3 | * Copyright (C) 1999-2001 by Brian Raiter, under the GNU General 4 | * Public License. No warranty. See COPYING for details. 5 | */ 6 | 7 | #include 8 | #include 9 | #include "elfparts.h" 10 | #include "gen.h" 11 | 12 | /* Generic setup of the elfpart structure. 13 | */ 14 | static void new(elfpart *part) 15 | { 16 | part->shtype = SHT_PROGBITS; 17 | } 18 | 19 | /* Set up the elfpart structure for a text segment. 20 | */ 21 | static void textnew(elfpart *part) 22 | { 23 | new(part); 24 | part->flags = PF_R | PF_X; 25 | part->shname = ".text"; 26 | } 27 | 28 | /* Set up the elfpart structure for a data segment. 29 | */ 30 | static void datanew(elfpart *part) 31 | { 32 | new(part); 33 | part->flags = PF_R | PF_W; 34 | part->shname = ".data"; 35 | } 36 | 37 | /* Set up the elfpart structure for a bss segment. 38 | */ 39 | static void bssnew(elfpart *part) 40 | { 41 | datanew(part); 42 | part->shtype = SHT_NOBITS; 43 | part->shname = ".bss"; 44 | } 45 | 46 | /* The progbits elfpart structures. 47 | */ 48 | elfpart part_progbits = { new, NULL, NULL, NULL }; 49 | elfpart part_text = { textnew, NULL, NULL, NULL }; 50 | elfpart part_data = { datanew, NULL, NULL, NULL }; 51 | elfpart part_bss = { bssnew, NULL, NULL, NULL }; 52 | -------------------------------------------------------------------------------- /src/tests/execute/other/crypto-algorithms/src/arcfour.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * Filename: arcfour.h 3 | * Author: Brad Conte (brad AT bradconte.com) 4 | * Copyright: 5 | * Disclaimer: This code is presented "as is" without any guarantees. 6 | * Details: Defines the API for the corresponding ARCFOUR implementation. 7 | *********************************************************************/ 8 | 9 | #ifndef ARCFOUR_H 10 | #define ARCFOUR_H 11 | 12 | /*************************** HEADER FILES ***************************/ 13 | #include 14 | 15 | /**************************** DATA TYPES ****************************/ 16 | typedef unsigned char BYTE; // 8-bit byte 17 | 18 | /*********************** FUNCTION DECLARATIONS **********************/ 19 | // Input: state - the state used to generate the keystream 20 | // key - Key to use to initialize the state 21 | // len - length of key in bytes (valid lenth is 1 to 256) 22 | void arcfour_key_setup(BYTE state[], const BYTE key[], int len); 23 | 24 | // Pseudo-Random Generator Algorithm 25 | // Input: state - the state used to generate the keystream 26 | // out - Must be allocated to be of at least "len" length 27 | // len - number of bytes to generate 28 | void arcfour_generate_stream(BYTE state[], BYTE out[], size_t len); 29 | 30 | #endif // ARCFOUR_H 31 | -------------------------------------------------------------------------------- /src/tests/execute/other/crypto-algorithms/src/sha256.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * Filename: sha256.h 3 | * Author: Brad Conte (brad AT bradconte.com) 4 | * Copyright: 5 | * Disclaimer: This code is presented "as is" without any guarantees. 6 | * Details: Defines the API for the corresponding SHA1 implementation. 7 | *********************************************************************/ 8 | 9 | #ifndef SHA256_H 10 | #define SHA256_H 11 | 12 | /*************************** HEADER FILES ***************************/ 13 | #include 14 | 15 | /****************************** MACROS ******************************/ 16 | #define SHA256_BLOCK_SIZE 32 // SHA256 outputs a 32 byte digest 17 | 18 | /**************************** DATA TYPES ****************************/ 19 | typedef unsigned char BYTE; // 8-bit byte 20 | typedef unsigned int WORD; // 32-bit word, change to "long" for 16-bit machines 21 | 22 | typedef struct { 23 | BYTE data[64]; 24 | WORD datalen; 25 | unsigned long /*long*/ bitlen; 26 | WORD state[8]; 27 | } SHA256_CTX; 28 | 29 | /*********************** FUNCTION DECLARATIONS **********************/ 30 | void sha256_init(SHA256_CTX *ctx); 31 | void sha256_update(SHA256_CTX *ctx, const BYTE data[], size_t len); 32 | void sha256_final(SHA256_CTX *ctx, BYTE hash[]); 33 | 34 | #endif // SHA256_H 35 | -------------------------------------------------------------------------------- /scripts/self1_vm.sh: -------------------------------------------------------------------------------- 1 | COMPILER=src/luxcc 2 | ASSEMBLER=src/luxvm/luxasvm 3 | LINKER=src/luxvm/luxldvm 4 | OUTPROG=luxcc1.vme 5 | if uname -i | grep -q "i386"; then 6 | COMPILER="$COMPILER -q -mvm32 -Isrc/lib/vm_lib/include" 7 | ASSEMBLER="$ASSEMBLER -vm32" 8 | LINKER="$LINKER -vm32" 9 | LIBC=src/lib/obj/vm32/libc.o 10 | RUNC=src/lib/obj/vm32/crt0.o 11 | else 12 | COMPILER="$COMPILER -q -mvm64 -Isrc/lib/vm_lib/include" 13 | ASSEMBLER="$ASSEMBLER -vm64" 14 | LINKER="$LINKER -vm64" 15 | LIBC=src/lib/obj/vm64/libc.o 16 | RUNC=src/lib/obj/vm64/crt0.o 17 | fi 18 | 19 | fail_counter=0 20 | pass_counter=0 21 | object_files="" 22 | 23 | for file in $(find src/tests/self/ | grep '\.c') ; do 24 | if [ ! "$LUX_QUIET" = "1" ] ; then 25 | echo $file 26 | fi 27 | 28 | # compile 29 | $COMPILER $file -o "${file%.*}.s" 2>/dev/null 30 | if [ "$?" != "0" ] ; then 31 | echo "Compiler failed with file $file" 32 | let fail_counter=fail_counter+1 33 | continue 34 | fi 35 | 36 | # assemble 37 | $ASSEMBLER "${file%.*}.s" -o "${file%.*}.o" 2>/dev/null 38 | if [ "$?" != "0" ] ; then 39 | echo "Assembler failed with file $file" 40 | let fail_counter=fail_counter+1 41 | continue 42 | fi 43 | object_files="$object_files ${file%.*}.o" 44 | 45 | let pass_counter=pass_counter+1 46 | done 47 | 48 | # link 49 | if [ "$fail_counter" = "0" ]; then 50 | $LINKER -o src/tests/self/$OUTPROG $RUNC $object_files $LIBC 51 | exit $? 52 | fi 53 | 54 | exit 1 55 | -------------------------------------------------------------------------------- /src/tests/execute/other/crypto-algorithms/src/rot-13.c: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * Filename: rot-13.c 3 | * Author: Brad Conte (brad AT bradconte.com) 4 | * Copyright: 5 | * Disclaimer: This code is presented "as is" without any guarantees. 6 | * Details: Implementation of the ROT-13 encryption algorithm. 7 | Algorithm specification can be found here: 8 | * 9 | This implementation uses little endian byte order. 10 | *********************************************************************/ 11 | 12 | /*************************** HEADER FILES ***************************/ 13 | #include 14 | #include "rot-13.h" 15 | 16 | /*********************** FUNCTION DEFINITIONS ***********************/ 17 | void rot13(char str[]) 18 | { 19 | int case_type, idx, len; 20 | 21 | for (idx = 0, len = strlen(str); idx < len; idx++) { 22 | // Only process alphabetic characters. 23 | if (str[idx] < 'A' || (str[idx] > 'Z' && str[idx] < 'a') || str[idx] > 'z') 24 | continue; 25 | // Determine if the char is upper or lower case. 26 | if (str[idx] >= 'a') 27 | case_type = 'a'; 28 | else 29 | case_type = 'A'; 30 | // Rotate the char's value, ensuring it doesn't accidentally "fall off" the end. 31 | str[idx] = (str[idx] + 13) % (case_type + 26); 32 | if (str[idx] < 26) 33 | str[idx] += case_type; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/tests/execute/union.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef union Point3 Point3; 4 | union Point3 { 5 | struct { int x, y, z; } c1; 6 | int c2[3]; 7 | }; 8 | 9 | Point3 create_point(int x, int y, int z) 10 | { 11 | Point3 p = { { x, y, z } }; 12 | return p; 13 | } 14 | 15 | Point3 add_points3(Point3 a, Point3 b) 16 | { 17 | a.c2[0] += b.c1.x; 18 | a.c1.y += b.c2[1]; 19 | a.c2[2] += b.c1.z; 20 | return a; 21 | } 22 | 23 | void modif_union(Point3 *p) 24 | { 25 | p->c1.x = 10; 26 | p->c2[1] = 20; 27 | p->c1.z = 30; 28 | } 29 | 30 | typedef union { 31 | unsigned x; 32 | unsigned short word[2]; 33 | unsigned char byte[4]; 34 | } A; 35 | 36 | int main(void) 37 | { 38 | Point3 a = create_point(15, 27, 32), b, c; 39 | A n = { 0xAABBCCDD }; 40 | 41 | b.c1.x = 5; 42 | b.c2[1] = 3; 43 | b.c1.z = 8; 44 | printf("%d %d %d\n", a.c1.x, a.c1.y, a.c1.z); 45 | printf("%d %d %d\n", b.c2[0], b.c2[1], b.c2[2]); 46 | 47 | c = add_points3(a, b); 48 | printf("%d %d %d\n", c.c1.x, c.c1.y, c.c1.z); 49 | modif_union(&c); 50 | printf("%d %d %d\n", c.c2[0], c.c2[1], c.c2[2]); 51 | 52 | printf("%d %d %d\n", a.c1.x, a.c1.y, a.c1.z); 53 | printf("%d %d %d\n", b.c2[0], b.c2[1], b.c2[2]); 54 | 55 | printf("%x\n", n.x); 56 | printf("%x%x\n", n.word[0], n.word[1]); 57 | printf("%x%x%x%x\n", n.byte[0], n.byte[1], n.byte[2], n.byte[3]); 58 | 59 | return 0; 60 | } 61 | -------------------------------------------------------------------------------- /src/tests/execute/other/crypto-algorithms/src/blowfish.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * Filename: blowfish.h 3 | * Author: Brad Conte (brad AT bradconte.com) 4 | * Copyright: 5 | * Disclaimer: This code is presented "as is" without any guarantees. 6 | * Details: Defines the API for the corresponding Blowfish implementation. 7 | *********************************************************************/ 8 | 9 | #ifndef BLOWFISH_H 10 | #define BLOWFISH_H 11 | 12 | /*************************** HEADER FILES ***************************/ 13 | #include 14 | 15 | /****************************** MACROS ******************************/ 16 | #define BLOWFISH_BLOCK_SIZE 8 // Blowfish operates on 8 bytes at a time 17 | 18 | /**************************** DATA TYPES ****************************/ 19 | typedef unsigned char BYTE; // 8-bit byte 20 | typedef unsigned int WORD; // 32-bit word, change to "long" for 16-bit machines 21 | 22 | typedef struct { 23 | WORD p[18]; 24 | WORD s[4][256]; 25 | } BLOWFISH_KEY; 26 | 27 | /*********************** FUNCTION DECLARATIONS **********************/ 28 | void blowfish_key_setup(const BYTE user_key[], BLOWFISH_KEY *keystruct, size_t len); 29 | void blowfish_encrypt(const BYTE in[], BYTE out[], const BLOWFISH_KEY *keystruct); 30 | void blowfish_decrypt(const BYTE in[], BYTE out[], const BLOWFISH_KEY *keystruct); 31 | 32 | #endif // BLOWFISH_H 33 | -------------------------------------------------------------------------------- /scripts/self2_vm.sh: -------------------------------------------------------------------------------- 1 | COMPILER="src/luxvm/luxvm src/tests/self/luxcc1.vme" 2 | ASSEMBLER=src/luxvm/luxasvm 3 | LINKER=src/luxvm/luxldvm 4 | OUTPROG=luxcc2.vme 5 | if uname -i | grep -q "i386"; then 6 | COMPILER="$COMPILER -q -mvm32 -Isrc/lib/vm_lib/include" 7 | ASSEMBLER="$ASSEMBLER -vm32" 8 | LINKER="$LINKER -vm32" 9 | LIBC=src/lib/obj/vm32/libc.o 10 | RUNC=src/lib/obj/vm32/crt0.o 11 | else 12 | COMPILER="$COMPILER -q -mvm64 -Isrc/lib/vm_lib/include" 13 | ASSEMBLER="$ASSEMBLER -vm64" 14 | LINKER="$LINKER -vm64" 15 | LIBC=src/lib/obj/vm64/libc.o 16 | RUNC=src/lib/obj/vm64/crt0.o 17 | fi 18 | 19 | fail_counter=0 20 | pass_counter=0 21 | object_files="" 22 | 23 | for file in $(find src/tests/self/ | grep '\.c') ; do 24 | if [ ! "$LUX_QUIET" = "1" ] ; then 25 | echo $file 26 | fi 27 | 28 | # compile 29 | $COMPILER $file -o "${file%.*}.s2" 2>/dev/null 30 | if [ "$?" != "0" ] ; then 31 | echo "Compiler failed with file $file" 32 | let fail_counter=fail_counter+1 33 | continue 34 | fi 35 | 36 | # assemble 37 | $ASSEMBLER "${file%.*}.s2" -o "${file%.*}.o" 2>/dev/null 38 | if [ "$?" != "0" ] ; then 39 | echo "Assembler failed with file $file" 40 | let fail_counter=fail_counter+1 41 | continue 42 | fi 43 | object_files="$object_files ${file%.*}.o" 44 | 45 | let pass_counter=pass_counter+1 46 | done 47 | 48 | # link 49 | if [ "$fail_counter" = "0" ]; then 50 | $LINKER -o src/tests/self/$OUTPROG $RUNC $object_files $LIBC 51 | exit $? 52 | fi 53 | 54 | exit 1 55 | -------------------------------------------------------------------------------- /src/lib/setjmp_x64.asm: -------------------------------------------------------------------------------- 1 | section .text 2 | 3 | ; x86_64 jmp_buf: 4 | ; 5 | ; typedef struct { 6 | ; long _rbx; 7 | ; long _rbp; 8 | ; long _rsp; 9 | ; long _r12; 10 | ; long _r13; 11 | ; long _r14; 12 | ; long _r15; 13 | ; long _rip; 14 | ; } jmp_buf[1]; 15 | 16 | ; int setjmp(jmp_buf env); 17 | global setjmp:function 18 | setjmp: 19 | mov rdx, rdi ; rdx = &env 20 | mov rax, [rsp] ; rax = return address 21 | ; fill buf 22 | mov [rdx+0], rbx 23 | mov [rdx+8], rbp 24 | mov [rdx+16], rsp 25 | mov [rdx+24], r12 26 | mov [rdx+32], r13 27 | mov [rdx+40], r14 28 | mov [rdx+48], r15 29 | mov [rdx+56], rax 30 | ; a direct invocation to setjmp() returns zero 31 | xor eax, eax 32 | ret 33 | 34 | ; void longjmp(jmp_buf env, int val); 35 | global longjmp:function 36 | longjmp: 37 | mov rdx, rdi ; rdx = &env 38 | mov rax, rsi ; rax = val 39 | ; restore stack pointer 40 | mov rsp, [rdx+16] 41 | ; set our return address to be the same as the return 42 | ; address of the setjmp() call that filled this buffer 43 | mov rbx, [rdx+56] 44 | mov [rsp], rbx 45 | ; restore the other regs 46 | mov rbx, [rdx+0] 47 | mov rbp, [rdx+8] 48 | mov r12, [rdx+24] 49 | mov r13, [rdx+32] 50 | mov r14, [rdx+40] 51 | mov r15, [rdx+48] 52 | ; we always return != zero 53 | or eax, eax 54 | jne .done 55 | mov eax, 1 56 | .done: 57 | ret 58 | 59 | -------------------------------------------------------------------------------- /src/tests/compile/sassert/usual_arith_conv.c: -------------------------------------------------------------------------------- 1 | #include "../../sassert.h" 2 | 3 | int main(void) 4 | { 5 | char a; 6 | unsigned char b; 7 | short c; 8 | unsigned short d; 9 | int e; 10 | unsigned int f; 11 | long g; 12 | unsigned long h; 13 | long long i; 14 | unsigned long long j; 15 | 16 | __static_assert(_ASSERT_TYPE, a+a, int); 17 | __static_assert(_ASSERT_TYPE, e+d, int); 18 | 19 | __static_assert(_ASSERT_TYPE, e+g, long); 20 | __static_assert(_ASSERT_TYPE, e+i, long long); 21 | __static_assert(_ASSERT_TYPE, g+i, long long); 22 | __static_assert(_ASSERT_TYPE, f+h, unsigned long); 23 | __static_assert(_ASSERT_TYPE, f+j, unsigned long long); 24 | __static_assert(_ASSERT_TYPE, h+j, unsigned long long); 25 | 26 | __static_assert(_ASSERT_TYPE, e+f, unsigned); 27 | __static_assert(_ASSERT_TYPE, e+h, unsigned long); 28 | __static_assert(_ASSERT_TYPE, e+j, unsigned long long); 29 | __static_assert(_ASSERT_TYPE, g+h, unsigned long); 30 | __static_assert(_ASSERT_TYPE, g+j, unsigned long long); 31 | __static_assert(_ASSERT_TYPE, i+j, unsigned long long); 32 | 33 | __static_assert(_ASSERT_TYPE, i+f, long long); 34 | #ifdef __LP64__ 35 | __static_assert(_ASSERT_TYPE, g+f, long); 36 | __static_assert(_ASSERT_TYPE, i+h, unsigned long long); 37 | #else 38 | __static_assert(_ASSERT_TYPE, g+f, unsigned long); 39 | __static_assert(_ASSERT_TYPE, i+h, long long); 40 | #endif 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /src/tests/execute/mixed_type.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | int i1, i2, i3; 6 | long long ll1, ll2, ll3; 7 | unsigned u1, u2, u3; 8 | unsigned long long ull1, ull2, ull3; 9 | 10 | i1 = 10; 11 | i2 = -20; 12 | ll1 = 2199023255552; 13 | ll2 = 8589934592; 14 | ll3 = -1; 15 | u1 = 100; 16 | u2 = 4294967295; 17 | ull1 = 1099511627776; 18 | ull2 = 9223372036854775808ULL; 19 | ull3 = 18446744073709551615ULL; 20 | // 21 | printf("%lld\n", i1+i2+ll1); 22 | printf("%lld\n", i1+i2+ll2); 23 | printf("%lld\n", i1+i2+ll3); 24 | 25 | i3 = i1+i2; 26 | printf("%lld\n", i3+ll1); 27 | printf("%lld\n", i3+ll2); 28 | printf("%lld\n", i3+ll3); 29 | 30 | printf("%llu\n", i1+i2+ull1); 31 | printf("%llu\n", i1+i2+ull2); 32 | printf("%llu\n", i1+i2+ull3); 33 | 34 | i3 = i1+i2; 35 | printf("%llu\n", i3+ull1); 36 | printf("%llu\n", i3+ull2); 37 | printf("%llu\n", i3+ull3); 38 | // 39 | printf("%lld\n", u1+u2+ll1); 40 | printf("%lld\n", u1+u2+ll2); 41 | printf("%lld\n", u1+u2+ll3); 42 | 43 | u3 = u1+u2; 44 | printf("%lld\n", u3+ll1); 45 | printf("%lld\n", u3+ll2); 46 | printf("%lld\n", u3+ll3); 47 | 48 | printf("%llu\n", u1+u2+ull1); 49 | printf("%llu\n", u1+u2+ull2); 50 | printf("%llu\n", u1+u2+ull3); 51 | 52 | u3 = u1+u2; 53 | printf("%llu\n", u3+ull1); 54 | printf("%llu\n", u3+ull2); 55 | printf("%llu\n", u3+ull3); 56 | 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /src/tests/compile/c-algorithms/hash-int.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2005-2008, Simon Howard 4 | 5 | Permission to use, copy, modify, and/or distribute this software 6 | for any purpose with or without fee is hereby granted, provided 7 | that the above copyright notice and this permission notice appear 8 | in all copies. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 11 | WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 12 | WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 13 | AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR 14 | CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 15 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 16 | NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 17 | CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 | 19 | */ 20 | 21 | /** 22 | * @file hash-int.h 23 | * 24 | * Hash function for a pointer to an integer. See @ref int_hash. 25 | */ 26 | 27 | #ifndef ALGORITHM_HASH_INT_H 28 | #define ALGORITHM_HASH_INT_H 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | /** 35 | * Generate a hash key for a pointer to an integer. The value pointed 36 | * at is used to generate the key. 37 | * 38 | * @param location The pointer. 39 | * @return A hash key for the value at the location. 40 | */ 41 | 42 | unsigned int int_hash(void *location); 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | #endif /* #ifndef ALGORITHM_HASH_INT_H */ 49 | 50 | -------------------------------------------------------------------------------- /src/tests/execute/cond_incl.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | #define T 1 6 | #define F 0 7 | #define U 8 | 9 | #ifdef U 10 | printf("1\n"); 11 | #endif 12 | #undef U 13 | #ifndef U 14 | printf("2\n"); 15 | #endif 16 | 17 | #if defined U || defined T 18 | printf("3\n"); 19 | #endif 20 | #if defined T && defined U 21 | printf("4\n"); 22 | #else 23 | printf("5\n"); 24 | #endif 25 | 26 | #if 1+(T ? 1 : -1) 27 | printf("6\n"); 28 | #endif 29 | #if 1+(F ? 1 : -1) 30 | printf("7\n"); 31 | #endif 32 | 33 | #if (10+2*-5+1<<20) && F 34 | printf("8\n"); 35 | #elif T && 3*-1+6 || 1 36 | printf("9\n"); 37 | #endif 38 | 39 | #if 1 | 0 40 | printf("10\n"); 41 | #endif 42 | #if 1 ^ 0 43 | printf("11\n"); 44 | #endif 45 | #if 1 & 0 46 | printf("12\n"); 47 | #elif 0 & 1 48 | printf("13\n"); 49 | #else 50 | printf("14\n"); 51 | #endif 52 | 53 | #if T == F 54 | printf("15\n"); 55 | #endif 56 | #if T != F 57 | printf("15\n"); 58 | #endif 59 | 60 | #if 10 > 20 61 | printf("15\n"); 62 | #elif 20 < 10 63 | printf("16\n"); 64 | #elif 20 <= 10 65 | printf("17\n"); 66 | #elif 10 >= 20 67 | printf("18\n"); 68 | #else 69 | printf("19\n"); 70 | #endif 71 | 72 | #if 16777216<<7 == 274877906944>>7 73 | printf("20\n"); 74 | #endif 75 | 76 | #if 10+20*2 == 160/2-30 77 | printf("21\n"); 78 | #endif 79 | 80 | #if !!-(-5) && ~+0 81 | printf("22\n"); 82 | #endif 83 | 84 | #if UNK+UNK2 == UNK3*2 85 | printf("23\n"); 86 | #endif 87 | 88 | return 0; 89 | } 90 | --------------------------------------------------------------------------------