├── .gitignore ├── COPYING ├── Changelog ├── CodingStyle ├── Makefile ├── README ├── README.md ├── RELICENSING ├── TCCInUEFI.inf ├── TODO ├── VERSION ├── arm-asm.c ├── arm-gen.c ├── arm-link.c ├── arm64-gen.c ├── arm64-link.c ├── c67-gen.c ├── c67-link.c ├── coff.h ├── configure ├── conftest.c ├── elf.h ├── examples ├── ex1.c ├── ex2.c ├── ex3.c ├── ex4.c ├── ex5.c └── uefi │ ├── Makefile │ └── hello.c ├── i386-asm.c ├── i386-asm.h ├── i386-gen.c ├── i386-link.c ├── i386-tok.h ├── il-gen.c ├── il-opcodes.h ├── include ├── float.h ├── stdarg.h ├── stdbool.h ├── stddef.h └── varargs.h ├── lib ├── Makefile ├── alloca-arm.S ├── alloca86-bt.S ├── alloca86.S ├── alloca86_64-bt.S ├── alloca86_64.S ├── armeabi.c ├── armflush.c ├── bcheck.c ├── lib-arm64.c ├── libtcc1.c └── va_list.c ├── libtcc.c ├── libtcc.h ├── pe32.h ├── stab.def ├── stab.h ├── tcc-doc.texi ├── tcc.c ├── tcc.h ├── tccasm.c ├── tcccoff.c ├── tccelf.c ├── tccgen.c ├── tcclib.h ├── tccpe.c ├── tccpp.c ├── tccrun.c ├── tcctok.h ├── tcctools.c ├── tests ├── 42test.h ├── Makefile ├── abitest.c ├── asmtest.S ├── boundtest.c ├── gcctestsuite.sh ├── libtcc_test.c ├── pp │ ├── 01.c │ ├── 01.expect │ ├── 02.c │ ├── 02.expect │ ├── 03.c │ ├── 03.expect │ ├── 04.c │ ├── 04.expect │ ├── 05.c │ ├── 05.expect │ ├── 06.c │ ├── 06.expect │ ├── 07.c │ ├── 07.expect │ ├── 08.c │ ├── 08.expect │ ├── 09.c │ ├── 09.expect │ ├── 10.c │ ├── 10.expect │ ├── 11.c │ ├── 11.expect │ ├── 12.S │ ├── 12.expect │ ├── 13.S │ ├── 13.expect │ ├── 14.c │ ├── 14.expect │ ├── 15.c │ ├── 15.expect │ ├── 16.c │ ├── 16.expect │ ├── 17.c │ ├── 17.expect │ ├── 18.c │ ├── 18.expect │ ├── 19.c │ ├── 19.expect │ ├── 20.c │ ├── 20.expect │ ├── 21.c │ ├── 21.expect │ ├── Makefile │ ├── pp-counter.c │ └── pp-counter.expect ├── tcctest.c ├── tcctest.h ├── testfp.c ├── tests2 │ ├── 00_assignment.c │ ├── 00_assignment.expect │ ├── 01_comment.c │ ├── 01_comment.expect │ ├── 02_printf.c │ ├── 02_printf.expect │ ├── 03_struct.c │ ├── 03_struct.expect │ ├── 04_for.c │ ├── 04_for.expect │ ├── 05_array.c │ ├── 05_array.expect │ ├── 06_case.c │ ├── 06_case.expect │ ├── 07_function.c │ ├── 07_function.expect │ ├── 08_while.c │ ├── 08_while.expect │ ├── 09_do_while.c │ ├── 09_do_while.expect │ ├── 10_pointer.c │ ├── 10_pointer.expect │ ├── 11_precedence.c │ ├── 11_precedence.expect │ ├── 12_hashdefine.c │ ├── 12_hashdefine.expect │ ├── 13_integer_literals.c │ ├── 13_integer_literals.expect │ ├── 14_if.c │ ├── 14_if.expect │ ├── 15_recursion.c │ ├── 15_recursion.expect │ ├── 16_nesting.c │ ├── 16_nesting.expect │ ├── 17_enum.c │ ├── 17_enum.expect │ ├── 18_include.c │ ├── 18_include.expect │ ├── 18_include.h │ ├── 19_pointer_arithmetic.c │ ├── 19_pointer_arithmetic.expect │ ├── 20_pointer_comparison.c │ ├── 20_pointer_comparison.expect │ ├── 21_char_array.c │ ├── 21_char_array.expect │ ├── 22_floating_point.c │ ├── 22_floating_point.expect │ ├── 23_type_coercion.c │ ├── 23_type_coercion.expect │ ├── 24_math_library.c │ ├── 24_math_library.expect │ ├── 25_quicksort.c │ ├── 25_quicksort.expect │ ├── 26_character_constants.c │ ├── 26_character_constants.expect │ ├── 27_sizeof.c │ ├── 27_sizeof.expect │ ├── 28_strings.c │ ├── 28_strings.expect │ ├── 29_array_address.c │ ├── 29_array_address.expect │ ├── 30_hanoi.c │ ├── 30_hanoi.expect │ ├── 31_args.c │ ├── 31_args.expect │ ├── 32_led.c │ ├── 32_led.expect │ ├── 33_ternary_op.c │ ├── 33_ternary_op.expect │ ├── 34_array_assignment.c │ ├── 34_array_assignment.expect │ ├── 35_sizeof.c │ ├── 35_sizeof.expect │ ├── 36_array_initialisers.c │ ├── 36_array_initialisers.expect │ ├── 37_sprintf.c │ ├── 37_sprintf.expect │ ├── 38_multiple_array_index.c │ ├── 38_multiple_array_index.expect │ ├── 39_typedef.c │ ├── 39_typedef.expect │ ├── 40_stdio.c │ ├── 40_stdio.expect │ ├── 41_hashif.c │ ├── 41_hashif.expect │ ├── 42_function_pointer.c │ ├── 42_function_pointer.expect │ ├── 43_void_param.c │ ├── 43_void_param.expect │ ├── 44_scoped_declarations.c │ ├── 44_scoped_declarations.expect │ ├── 45_empty_for.c │ ├── 45_empty_for.expect │ ├── 46_grep.c │ ├── 46_grep.expect │ ├── 47_switch_return.c │ ├── 47_switch_return.expect │ ├── 48_nested_break.c │ ├── 48_nested_break.expect │ ├── 49_bracket_evaluation.c │ ├── 49_bracket_evaluation.expect │ ├── 50_logical_second_arg.c │ ├── 50_logical_second_arg.expect │ ├── 51_static.c │ ├── 51_static.expect │ ├── 52_unnamed_enum.c │ ├── 52_unnamed_enum.expect │ ├── 54_goto.c │ ├── 54_goto.expect │ ├── 55_lshift_type.c │ ├── 55_lshift_type.expect │ ├── 60_errors_and_warnings.c │ ├── 60_errors_and_warnings.expect │ ├── 64_macro_nesting.c │ ├── 64_macro_nesting.expect │ ├── 67_macro_concat.c │ ├── 67_macro_concat.expect │ ├── 70_floating_point_literals.c │ ├── 70_floating_point_literals.expect │ ├── 71_macro_empty_arg.c │ ├── 71_macro_empty_arg.expect │ ├── 72_long_long_constant.c │ ├── 72_long_long_constant.expect │ ├── 73_arm64.c │ ├── 73_arm64.expect │ ├── 75_array_in_struct_init.c │ ├── 75_array_in_struct_init.expect │ ├── 76_dollars_in_identifiers.c │ ├── 76_dollars_in_identifiers.expect │ ├── 77_push_pop_macro.c │ ├── 77_push_pop_macro.expect │ ├── 78_vla_label.c │ ├── 78_vla_label.expect │ ├── 79_vla_continue.c │ ├── 79_vla_continue.expect │ ├── 80_flexarray.c │ ├── 80_flexarray.expect │ ├── 81_types.c │ ├── 81_types.expect │ ├── 82_attribs_position.c │ ├── 82_attribs_position.expect │ ├── 83_utf8_in_identifiers.c │ ├── 83_utf8_in_identifiers.expect │ ├── 84_hex-float.c │ ├── 84_hex-float.expect │ ├── 85_asm-outside-function.c │ ├── 85_asm-outside-function.expect │ ├── 86_memory-model.c │ ├── 86_memory-model.expect │ ├── 87_dead_code.c │ ├── 87_dead_code.expect │ ├── 88_codeopt.c │ ├── 88_codeopt.expect │ ├── 89_nocode_wanted.c │ ├── 89_nocode_wanted.expect │ ├── 90_struct-init.c │ ├── 90_struct-init.expect │ ├── 91_ptr_longlong_arith32.c │ ├── 91_ptr_longlong_arith32.expect │ ├── 92_enum_bitfield.c │ ├── 92_enum_bitfield.expect │ ├── 93_integer_promotion.c │ ├── 93_integer_promotion.expect │ ├── 94_generic.c │ ├── 94_generic.expect │ ├── 95_bitfields.c │ ├── 95_bitfields.expect │ ├── 95_bitfields_ms.c │ ├── 95_bitfields_ms.expect │ ├── 96_nodata_wanted.c │ ├── 96_nodata_wanted.expect │ ├── LICENSE │ └── Makefile └── vla_test.c ├── texi2pod.pl ├── win32 ├── Makefile ├── build-tcc.bat ├── examples │ ├── dll.c │ ├── fib.c │ ├── hello_dll.c │ └── hello_win.c ├── include │ ├── _mingw.h │ ├── assert.h │ ├── conio.h │ ├── ctype.h │ ├── dir.h │ ├── direct.h │ ├── dirent.h │ ├── dos.h │ ├── errno.h │ ├── excpt.h │ ├── fcntl.h │ ├── fenv.h │ ├── inttypes.h │ ├── io.h │ ├── limits.h │ ├── locale.h │ ├── malloc.h │ ├── math.h │ ├── mem.h │ ├── memory.h │ ├── process.h │ ├── sec_api │ │ ├── conio_s.h │ │ ├── crtdbg_s.h │ │ ├── io_s.h │ │ ├── mbstring_s.h │ │ ├── search_s.h │ │ ├── stdio_s.h │ │ ├── stdlib_s.h │ │ ├── stralign_s.h │ │ ├── string_s.h │ │ ├── sys │ │ │ └── timeb_s.h │ │ ├── tchar_s.h │ │ ├── time_s.h │ │ └── wchar_s.h │ ├── setjmp.h │ ├── share.h │ ├── signal.h │ ├── stdint.h │ ├── stdio.h │ ├── stdlib.h │ ├── string.h │ ├── sys │ │ ├── fcntl.h │ │ ├── file.h │ │ ├── locking.h │ │ ├── stat.h │ │ ├── time.h │ │ ├── timeb.h │ │ ├── types.h │ │ ├── unistd.h │ │ └── utime.h │ ├── tcc │ │ └── tcc_libm.h │ ├── tchar.h │ ├── time.h │ ├── vadefs.h │ ├── values.h │ ├── wchar.h │ ├── wctype.h │ └── winapi │ │ ├── basetsd.h │ │ ├── basetyps.h │ │ ├── guiddef.h │ │ ├── poppack.h │ │ ├── pshpack1.h │ │ ├── pshpack2.h │ │ ├── pshpack4.h │ │ ├── pshpack8.h │ │ ├── winbase.h │ │ ├── wincon.h │ │ ├── windef.h │ │ ├── windows.h │ │ ├── winerror.h │ │ ├── wingdi.h │ │ ├── winnt.h │ │ ├── winreg.h │ │ ├── winuser.h │ │ └── winver.h ├── lib │ ├── chkstk.S │ ├── crt1.c │ ├── crt1w.c │ ├── dllcrt1.c │ ├── dllmain.c │ ├── gdi32.def │ ├── kernel32.def │ ├── msvcrt.def │ ├── user32.def │ ├── wincrt1.c │ └── wincrt1w.c └── tcc-win32.txt ├── x86_64-asm.h ├── x86_64-gen.c └── x86_64-link.c /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | \#* 3 | .#* 4 | *.o 5 | *.a 6 | *.exe 7 | *.dll 8 | *.obj 9 | *.pdb 10 | *.lib 11 | *.exp 12 | *.log 13 | *.bz2 14 | *.zip 15 | .gdb_history 16 | a.out 17 | tcc_g 18 | tcc 19 | *-tcc 20 | libtcc*.def 21 | 22 | config*.h 23 | config*.mak 24 | config.texi 25 | conftest* 26 | tags 27 | TAGS 28 | tcc.1 29 | tcc.pod 30 | tcc-doc.html 31 | tcc-doc.info 32 | 33 | win32/doc 34 | win32/libtcc 35 | win32/lib/32 36 | win32/lib/64 37 | win32/include/float.h 38 | win32/include/stdarg.h 39 | win32/include/stdbool.h 40 | win32/include/stddef.h 41 | win32/include/varargs.h 42 | win32/include/tcclib.h 43 | 44 | tests/test.out* 45 | tests/test*.out 46 | tests/tcctest[1234] 47 | tests/tcctest.gcc 48 | tests/*.ref 49 | tests/*.txt 50 | tests/*.gcc 51 | tests/*-cc* 52 | tests/*-tcc* 53 | tests/libtcc_test 54 | tests/vla_test 55 | tests/hello 56 | tests/tests2/fred.txt 57 | -------------------------------------------------------------------------------- /CodingStyle: -------------------------------------------------------------------------------- 1 | 2 | In general, use the same coding style as the surrounding code. 3 | 4 | However, do not make any unnecessary changes as that complicates 5 | the VCS (git) history and makes it harder to merge patches. So 6 | do not modify code just to make it conform to a coding style. 7 | 8 | Indentation 9 | 10 | Turn on a "fill tabs with spaces" option in your editor. 11 | 12 | Remove tabs and trailing spaces from any lines that are modified. 13 | 14 | Note that some files are indented with 2 spaces (when they 15 | have large indentation) while most are indented with 4 spaces. 16 | 17 | Language 18 | 19 | TCC is mostly implemented in C90. Do not use any non-C90 features 20 | that are not already in use. 21 | 22 | Non-C90 features currently in use, as revealed by 23 | ./configure --extra-cflags="-std=c90 -Wpedantic": 24 | 25 | - long long (including "LL" constants) 26 | - inline 27 | - very long string constants 28 | - assignment between function pointer and 'void *' 29 | - "//" comments 30 | - empty macro arguments (DEF_ASMTEST in i386-tok.h) 31 | - unnamed struct and union fields (in struct Sym), a C11 feature 32 | 33 | Testing 34 | 35 | A simple "make test" is sufficient for some simple changes. However, 36 | before committing a change consider performing some of the following 37 | additional tests: 38 | 39 | - Build and run "make test" on several architectures. 40 | 41 | - Build with ./configure --enable-cross. 42 | 43 | - If the generation of relocations has been changed, try compiling 44 | with TCC and linking with GCC/Clang. If the linker has been 45 | modified, try compiling with GCC/Clang and linking with TCC. 46 | 47 | - Test with ASan/UBSan to detect memory corruption and undefined behaviour: 48 | 49 | make clean 50 | ./configure 51 | make 52 | make test 53 | cp libtcc.a libtcc.a.hide 54 | 55 | make clean 56 | ./configure --extra-cflags="-fsanitize=address,undefined -g" 57 | make 58 | cp libtcc.a.hide libtcc.a 59 | make test 60 | 61 | - Test with Valgrind to detect some uses of uninitialised values: 62 | 63 | make clean 64 | ./configure 65 | make 66 | # On Intel, because Valgrind does floating-point arithmetic differently: 67 | ( cd tests && gcc -I.. tcctest.c && valgrind -q ./a.out > test.ref ) 68 | make test TCC="valgrind -q --leak-check=full `pwd`/tcc -B`pwd` -I`pwd`" 69 | 70 | (Because of how VLAs are implemented, invalid reads are expected 71 | with 79_vla_continue.) 72 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | andreiw's tinycc changes 2 | ======================== 3 | 4 | This tree adds: 5 | - some bare minimum OSX support **(merged)**. 6 | - support for generating ARM64 PE32+ images **(not yet merged)**. 7 | - support for generating X64, ARM64, IA32 (untested) and ARM (untested) UEFI images **(not yet merged)**. 8 | - a "Hello, World!" UEFI example in examples/uefi **(not yet merged)**. 9 | - a UEFI-targetting compiler (x86_64-uefi-tcc and arm64-uefi-tcc), that can be built (Tiano EDK2) to be hosted on UEFI **(not yet merged)**. 10 | 11 | OSX support 12 | ----------- 13 | 14 | Today this includes some basic build support (CONFIG_OSX) 15 | in ./configure and ./Makefile. It also makes 16 | the '-run' mode function, allowing tcc to 17 | open up libc.dylib. 18 | 19 | Usage: 20 | 21 | $ ./configure 22 | $ make 23 | $ ./tcc -B. -I./include -I. -I.. -D_ANSI_SOURCE -run examples/ex1.c 24 | Hello World 25 | 26 | ARM64 PE32+ images 27 | ------------------ 28 | 29 | The targets are arm64-win32-tcc and arm64-uefi-tcc. libtcc1 is not built, so this 30 | is only useful for standalone code, such as UEFI images. 31 | 32 | UEFI images 33 | ----------- 34 | 35 | This example requires a Tiano Core source tree: 36 | 37 | #include 38 | 39 | CHAR16 *gHello = L"Hello from a TinyCC compiled UEFI binary!\r\n"; 40 | 41 | EFI_STATUS EFIAPI 42 | _start(EFI_HANDLE Handle, 43 | EFI_SYSTEM_TABLE *SystemTable) 44 | { 45 | SystemTable->ConOut->OutputString(SystemTable->ConOut, gHello); 46 | return EFI_SUCCESS; 47 | } 48 | 49 | Building: 50 | 51 | $ x86_64-win32-tcc -I ../edk2/MdePkg/Include/ -I ../edk2/MdePkg/Include/X64/ efitest.c -Wl,-subsystem=efiapp -nostdlib -o efitest.x64.efi 52 | $ arm64-win32-tcc -I ../edk2/MdePkg/Include/ -I ../edk2/MdePkg/Include/AArch64/ efitest.c -Wl,-subsystem=efiapp -nostdlib -o efitest.aa64.efi 53 | 54 | Or, with the UEFI-targetting compiler, which is is a subset of the win32 compiler. 55 | 56 | $ x86_64-uefi-tcc -I ../edk2/MdePkg/Include/ -I ../edk2/MdePkg/Include/X64/ efitest.c -o efitest.x64.efi 57 | $ arm64-uefi-tcc -I ../edk2/MdePkg/Include/ -I ../edk2/MdePkg/Include/AArch64/ efitest.c -o efitest.aa64.efi 58 | 59 | Running (on the appropriate architecture, of course!): 60 | 61 | fs0:\> efitest.aa64.efi 62 | Hello from a TinyCC compiled UEFI binary! 63 | fs0:\> 64 | 65 | A similar example is already present in examples/uefi. To build: 66 | 67 | $ make -C examples/uefi 68 | 69 | TCC in UEFI 70 | ----------- 71 | 72 | This has only been validated with X64 and AArch64. To build, you need 73 | an EDK2 tree. Use the TCCInUEFI.inf build file. This will get you 74 | a compiler equivalent to x86_64-uefi-tcc/arm64-uefi-tcc. 75 | 76 | Also see https://github.com/andreiw/UefiToolsPkg, which might 77 | be an easier way of building my private TinyCC tree for UEFI. 78 | 79 | fs16:> tcc hello.c 80 | fs16:> hello.efi 81 | Hello, World! 82 | 83 | Note: too lazy to copy headers, so far only tested building pre-processed 84 | files (-E is your friend). 85 | -------------------------------------------------------------------------------- /RELICENSING: -------------------------------------------------------------------------------- 1 | 2 | Relicensing TinyCC 3 | ------------------ 4 | 5 | The authors listed below hereby confirm their agreement to relicense TinyCC 6 | including their past contributions under the following terms: 7 | 8 | 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 22 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | 27 | 28 | Author (name) I agree (YES/NO) Files/Features (optional) 29 | ------------------------------------------------------------------------------ 30 | Adam Sampson YES makefiles 31 | Daniel Glöckner NO arm-gen.c 32 | Daniel Glöckner YES not arm-gen.c 33 | Edmund Grimley Evans YES arm64 34 | Fabrice Bellard YES original author 35 | Frédéric Féret YES x86 64/16 bit asm 36 | grischka YES tccpe.c 37 | Henry Kroll YES 38 | Joe Soroka YES 39 | Kirill Smelkov YES 40 | mingodad YES 41 | Pip Cet YES 42 | Shinichiro Hamaji YES x86_64-gen.c 43 | Vincent Lefèvre YES 44 | Thomas Preud'homme YES arm-gen.c 45 | Timo VJ Lähde (Timppa) ? tiny_libmaker.c 46 | TK ? tcccoff.c c67-gen.c 47 | Urs Janssen YES 48 | waddlesplash YES 49 | Christian Jullien YES Windows Cygwin build and tests 50 | 51 | 52 | ------------------------------------------------------------------------------ 53 | 54 | Please add yourself to the list above (rsp. replace the question mark) 55 | and (after fetching the latest version) commit to the "mob" branch with 56 | commit message: 57 | 58 | Relicensing TinyCC 59 | 60 | Thanks. 61 | -------------------------------------------------------------------------------- /TCCInUEFI.inf: -------------------------------------------------------------------------------- 1 | # 2 | # This Tiano (EDK2) build file will allow you to 3 | # compile TinyCC as a UEFI application. 4 | # 5 | # Only tested with X64 and AArch64. 6 | # 7 | # Note: if building for AArch64, you will need 8 | # SoftFloatLib: https://github.com/andreiw/UefiToolsPkg 9 | # 10 | 11 | [Defines] 12 | INF_VERSION = 0x00010006 13 | BASE_NAME = tcc 14 | FILE_GUID = 4ea97c46-7491-4dfd-b442-747010f3ce5e 15 | MODULE_TYPE = UEFI_APPLICATION 16 | VERSION_STRING = 0.1 17 | ENTRY_POINT = ShellCEntryLib 18 | 19 | [Sources] 20 | tcc.c 21 | 22 | [Packages] 23 | StdLib/StdLib.dec 24 | MdePkg/MdePkg.dec 25 | ShellPkg/ShellPkg.dec 26 | 27 | [LibraryClasses] 28 | LibC 29 | LibStdio 30 | LibMath 31 | LibLocale 32 | DevShell 33 | 34 | [LibraryClasses.AARCH64] 35 | SoftFloatLib 36 | 37 | [BuildOptions] 38 | GCC:*_*_*_CC_FLAGS = -DGCC_MAJOR=`$(CC) -dumpversion | cut -f1 -d.` -DGCC_MINOR=`$(CC) -dumpversion | cut -f2 -d.` -DTCC_VERSION=\"`head $(MODULE_DIR)/VERSION`\" -DCONFIG_TCCDIR=\".\" -DTCC_ALREADY_CONFIGURED -DONE_SOURCE=1 -DCONFIG_TCC_STATIC -DTCC_TARGET_PE -DTCC_TARGET_UEFI -Dstrtof=_strtof 39 | 40 | [BuildOptions.X64] 41 | GCC:*_*_*_CC_FLAGS = -DTCC_TARGET_X86_64 42 | 43 | [BuildOptions.AARCH64] 44 | GCC:*_*_*_CC_FLAGS = -DTCC_TARGET_ARM64 45 | -------------------------------------------------------------------------------- /VERSION: -------------------------------------------------------------------------------- 1 | 0.9.27 2 | -------------------------------------------------------------------------------- /arm-asm.c: -------------------------------------------------------------------------------- 1 | /*************************************************************/ 2 | /* 3 | * ARM dummy assembler for TCC 4 | * 5 | */ 6 | 7 | #ifdef TARGET_DEFS_ONLY 8 | 9 | #define CONFIG_TCC_ASM 10 | #define NB_ASM_REGS 16 11 | 12 | ST_FUNC void g(int c); 13 | ST_FUNC void gen_le16(int c); 14 | ST_FUNC void gen_le32(int c); 15 | 16 | /*************************************************************/ 17 | #else 18 | /*************************************************************/ 19 | 20 | #include "tcc.h" 21 | 22 | static void asm_error(void) 23 | { 24 | tcc_error("ARM asm not implemented."); 25 | } 26 | 27 | /* XXX: make it faster ? */ 28 | ST_FUNC void g(int c) 29 | { 30 | int ind1; 31 | if (nocode_wanted) 32 | return; 33 | ind1 = ind + 1; 34 | if (ind1 > cur_text_section->data_allocated) 35 | section_realloc(cur_text_section, ind1); 36 | cur_text_section->data[ind] = c; 37 | ind = ind1; 38 | } 39 | 40 | ST_FUNC void gen_le16 (int i) 41 | { 42 | g(i); 43 | g(i>>8); 44 | } 45 | 46 | ST_FUNC void gen_le32 (int i) 47 | { 48 | gen_le16(i); 49 | gen_le16(i>>16); 50 | } 51 | 52 | ST_FUNC void gen_expr32(ExprValue *pe) 53 | { 54 | gen_le32(pe->v); 55 | } 56 | 57 | ST_FUNC void asm_opcode(TCCState *s1, int opcode) 58 | { 59 | asm_error(); 60 | } 61 | 62 | ST_FUNC void subst_asm_operand(CString *add_str, SValue *sv, int modifier) 63 | { 64 | asm_error(); 65 | } 66 | 67 | /* generate prolog and epilog code for asm statement */ 68 | ST_FUNC void asm_gen_code(ASMOperand *operands, int nb_operands, 69 | int nb_outputs, int is_output, 70 | uint8_t *clobber_regs, 71 | int out_reg) 72 | { 73 | } 74 | 75 | ST_FUNC void asm_compute_constraints(ASMOperand *operands, 76 | int nb_operands, int nb_outputs, 77 | const uint8_t *clobber_regs, 78 | int *pout_reg) 79 | { 80 | } 81 | 82 | ST_FUNC void asm_clobber(uint8_t *clobber_regs, const char *str) 83 | { 84 | asm_error(); 85 | } 86 | 87 | ST_FUNC int asm_parse_regvar (int t) 88 | { 89 | asm_error(); 90 | return -1; 91 | } 92 | 93 | /*************************************************************/ 94 | #endif /* ndef TARGET_DEFS_ONLY */ 95 | -------------------------------------------------------------------------------- /conftest.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* Define architecture */ 4 | #if defined(__i386__) || defined _M_IX86 5 | # define TRIPLET_ARCH "i386" 6 | #elif defined(__x86_64__) || defined _M_AMD64 7 | # define TRIPLET_ARCH "x86_64" 8 | #elif defined(__arm__) 9 | # define TRIPLET_ARCH "arm" 10 | #elif defined(__aarch64__) 11 | # define TRIPLET_ARCH "aarch64" 12 | #else 13 | # define TRIPLET_ARCH "unknown" 14 | #endif 15 | 16 | /* Define OS */ 17 | #if defined (__linux__) 18 | # define TRIPLET_OS "linux" 19 | #elif defined (__FreeBSD__) || defined (__FreeBSD_kernel__) 20 | # define TRIPLET_OS "kfreebsd" 21 | #elif defined _WIN32 22 | # define TRIPLET_OS "win32" 23 | #elif !defined (__GNU__) 24 | # define TRIPLET_OS "unknown" 25 | #endif 26 | 27 | /* Define calling convention and ABI */ 28 | #if defined (__ARM_EABI__) 29 | # if defined (__ARM_PCS_VFP) 30 | # define TRIPLET_ABI "gnueabihf" 31 | # else 32 | # define TRIPLET_ABI "gnueabi" 33 | # endif 34 | #else 35 | # define TRIPLET_ABI "gnu" 36 | #endif 37 | 38 | #if defined _WIN32 39 | # define TRIPLET TRIPLET_ARCH "-" TRIPLET_OS 40 | #elif defined __GNU__ 41 | # define TRIPLET TRIPLET_ARCH "-" TRIPLET_ABI 42 | #else 43 | # define TRIPLET TRIPLET_ARCH "-" TRIPLET_OS "-" TRIPLET_ABI 44 | #endif 45 | 46 | #if defined(_WIN32) 47 | int _CRT_glob = 0; 48 | #endif 49 | 50 | int main(int argc, char *argv[]) 51 | { 52 | switch(argc == 2 ? argv[1][0] : 0) { 53 | case 'b': 54 | { 55 | volatile unsigned foo = 0x01234567; 56 | puts(*(unsigned char*)&foo == 0x67 ? "no" : "yes"); 57 | break; 58 | } 59 | #ifdef __GNUC__ 60 | case 'm': 61 | printf("%d\n", __GNUC_MINOR__); 62 | break; 63 | case 'v': 64 | printf("%d\n", __GNUC__); 65 | break; 66 | #elif defined __TINYC__ 67 | case 'v': 68 | puts("0"); 69 | break; 70 | case 'm': 71 | printf("%d\n", __TINYC__); 72 | break; 73 | #else 74 | case 'm': 75 | case 'v': 76 | puts("0"); 77 | break; 78 | #endif 79 | case 't': 80 | puts(TRIPLET); 81 | break; 82 | 83 | default: 84 | break; 85 | } 86 | return 0; 87 | } 88 | -------------------------------------------------------------------------------- /examples/ex1.c: -------------------------------------------------------------------------------- 1 | #!/usr/local/bin/tcc -run 2 | #include 3 | 4 | int main() 5 | { 6 | printf("Hello World\n"); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /examples/ex2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define N 20 5 | 6 | int nb_num; 7 | int tab[N]; 8 | int stack_ptr; 9 | int stack_op[N]; 10 | int stack_res[60]; 11 | int result; 12 | 13 | int find(int n, int i1, int a, int b, int op) 14 | { 15 | int i, j; 16 | int c; 17 | 18 | if (stack_ptr >= 0) { 19 | stack_res[3*stack_ptr] = a; 20 | stack_op[stack_ptr] = op; 21 | stack_res[3*stack_ptr+1] = b; 22 | stack_res[3*stack_ptr+2] = n; 23 | if (n == result) 24 | return 1; 25 | tab[i1] = n; 26 | } 27 | 28 | for(i=0;i 2 | 3 | int fib(n) 4 | { 5 | if (n <= 2) 6 | return 1; 7 | else 8 | return fib(n-1) + fib(n-2); 9 | } 10 | 11 | int main(int argc, char **argv) 12 | { 13 | int n; 14 | if (argc < 2) { 15 | printf("usage: fib n\n" 16 | "Compute nth Fibonacci number\n"); 17 | return 1; 18 | } 19 | 20 | n = atoi(argv[1]); 21 | printf("fib(%d) = %d\n", n, fib(n, 2)); 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /examples/ex4.c: -------------------------------------------------------------------------------- 1 | #!/usr/local/bin/tcc -run -L/usr/X11R6/lib -lX11 2 | #include 3 | #include 4 | #include 5 | 6 | /* Yes, TCC can use X11 too ! */ 7 | 8 | int main(int argc, char **argv) 9 | { 10 | Display *display; 11 | Screen *screen; 12 | 13 | display = XOpenDisplay(""); 14 | if (!display) { 15 | fprintf(stderr, "Could not open X11 display\n"); 16 | exit(1); 17 | } 18 | printf("X11 display opened.\n"); 19 | screen = XScreenOfDisplay(display, 0); 20 | printf("width = %d\nheight = %d\ndepth = %d\n", 21 | screen->width, 22 | screen->height, 23 | screen->root_depth); 24 | XCloseDisplay(display); 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /examples/ex5.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | printf("Hello World\n"); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /examples/uefi/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # This builds a simple "Hello, World!" UEFI 3 | # application for X86_64 and Aarch64 4 | # environments. It relies on Tiano Core 5 | # (edk2) headers, which you must provide 6 | # yourself, by checking-out Tiano 7 | # (e.g. https://github.com/tianocore/edk2) 8 | # and tweaking EDK2 below. 9 | # 10 | # EDK2 should point to a Tiano Core (edk2) tree. 11 | # $(CC_blah) should be valid if you built these 12 | # in the top TCC directory. 13 | # 14 | EDK2 ?= ../../../edk2 15 | CC_x86_64 ?= ../../x86_64-uefi-tcc 16 | CC_arm64 ?= ../../arm64-uefi-tcc 17 | 18 | HELLO_X = x86_64 arm64 19 | 20 | TARGETS = $(foreach X,$(HELLO_X),$X-hello.efi) 21 | 22 | INCLUDES = -I $(EDK2)/MdePkg/Include/ 23 | INCLUDES_x86_64 = -I $(EDK2)/MdePkg/Include/X64 24 | INCLUDES_arm64 = -I $(EDK2)/MdePkg/Include/AArch64 25 | 26 | all: $(TARGETS) 27 | 28 | %-hello.efi: hello.c 29 | $(CC_$*) $(INCLUDES) $(INCLUDES_$*) $^ -o $@ 30 | 31 | clean: 32 | rm -rf *~ *.o $(TARGETS) 33 | 34 | .PHONY: clean all -------------------------------------------------------------------------------- /examples/uefi/hello.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #if defined(__aarch64__) 4 | #define ARCH 1 5 | #elif defined(__x86_64__) 6 | #define ARCH 2 7 | #else 8 | #define ARCH 0 9 | #endif 10 | 11 | CHAR16 *gArch[3] = { 12 | L"UNKNOWN", 13 | L"AA64", 14 | L"X64" 15 | }; 16 | 17 | CHAR16 *gHello = L"Hello from a TinyCC compiled "; 18 | 19 | EFI_STATUS EFIAPI 20 | _start(EFI_HANDLE Handle, 21 | EFI_SYSTEM_TABLE *SystemTable) 22 | { 23 | CHAR16 *Bye = L" UEFI binary!\n"; 24 | SystemTable->ConOut->OutputString(SystemTable->ConOut, gHello); 25 | SystemTable->ConOut->OutputString(SystemTable->ConOut, gArch[ARCH]); 26 | SystemTable->ConOut->OutputString(SystemTable->ConOut, Bye); 27 | return EFI_SUCCESS; 28 | } 29 | -------------------------------------------------------------------------------- /include/float.h: -------------------------------------------------------------------------------- 1 | #ifndef _FLOAT_H_ 2 | #define _FLOAT_H_ 3 | 4 | #define FLT_RADIX 2 5 | 6 | /* IEEE float */ 7 | #define FLT_MANT_DIG 24 8 | #define FLT_DIG 6 9 | #define FLT_ROUNDS 1 10 | #define FLT_EPSILON 1.19209290e-07F 11 | #define FLT_MIN_EXP (-125) 12 | #define FLT_MIN 1.17549435e-38F 13 | #define FLT_MIN_10_EXP (-37) 14 | #define FLT_MAX_EXP 128 15 | #define FLT_MAX 3.40282347e+38F 16 | #define FLT_MAX_10_EXP 38 17 | 18 | /* IEEE double */ 19 | #define DBL_MANT_DIG 53 20 | #define DBL_DIG 15 21 | #define DBL_EPSILON 2.2204460492503131e-16 22 | #define DBL_MIN_EXP (-1021) 23 | #define DBL_MIN 2.2250738585072014e-308 24 | #define DBL_MIN_10_EXP (-307) 25 | #define DBL_MAX_EXP 1024 26 | #define DBL_MAX 1.7976931348623157e+308 27 | #define DBL_MAX_10_EXP 308 28 | 29 | /* horrible intel long double */ 30 | #if defined __i386__ || defined __x86_64__ 31 | 32 | #define LDBL_MANT_DIG 64 33 | #define LDBL_DIG 18 34 | #define LDBL_EPSILON 1.08420217248550443401e-19L 35 | #define LDBL_MIN_EXP (-16381) 36 | #define LDBL_MIN 3.36210314311209350626e-4932L 37 | #define LDBL_MIN_10_EXP (-4931) 38 | #define LDBL_MAX_EXP 16384 39 | #define LDBL_MAX 1.18973149535723176502e+4932L 40 | #define LDBL_MAX_10_EXP 4932 41 | 42 | #else 43 | 44 | /* same as IEEE double */ 45 | #define LDBL_MANT_DIG 53 46 | #define LDBL_DIG 15 47 | #define LDBL_EPSILON 2.2204460492503131e-16 48 | #define LDBL_MIN_EXP (-1021) 49 | #define LDBL_MIN 2.2250738585072014e-308 50 | #define LDBL_MIN_10_EXP (-307) 51 | #define LDBL_MAX_EXP 1024 52 | #define LDBL_MAX 1.7976931348623157e+308 53 | #define LDBL_MAX_10_EXP 308 54 | 55 | #endif 56 | 57 | #endif /* _FLOAT_H_ */ 58 | -------------------------------------------------------------------------------- /include/stdarg.h: -------------------------------------------------------------------------------- 1 | #ifndef _STDARG_H 2 | #define _STDARG_H 3 | 4 | #ifdef __x86_64__ 5 | #ifndef _WIN64 6 | 7 | //This should be in sync with the declaration on our lib/libtcc1.c 8 | /* GCC compatible definition of va_list. */ 9 | typedef struct { 10 | unsigned int gp_offset; 11 | unsigned int fp_offset; 12 | union { 13 | unsigned int overflow_offset; 14 | char *overflow_arg_area; 15 | }; 16 | char *reg_save_area; 17 | } __va_list_struct; 18 | 19 | /* Avoid conflicting definition for va_list on musl libc */ 20 | #ifndef __DEFINED_va_list 21 | typedef __va_list_struct va_list[1]; 22 | #define __DEFINED_va_list 23 | #endif 24 | 25 | void __va_start(__va_list_struct *ap, void *fp); 26 | void *__va_arg(__va_list_struct *ap, int arg_type, int size, int align); 27 | 28 | #define va_start(ap, last) __va_start(ap, __builtin_frame_address(0)) 29 | #define va_arg(ap, type) \ 30 | (*(type *)(__va_arg(ap, __builtin_va_arg_types(type), sizeof(type), __alignof__(type)))) 31 | #define va_copy(dest, src) (*(dest) = *(src)) 32 | #define va_end(ap) 33 | 34 | /* avoid conflicting definition for va_list on Macs. */ 35 | #define _VA_LIST_T 36 | 37 | #else /* _WIN64 */ 38 | typedef char *va_list; 39 | #define va_start(ap,last) __builtin_va_start(ap,last) 40 | #define va_arg(ap, t) ((sizeof(t) > 8 || (sizeof(t) & (sizeof(t) - 1))) \ 41 | ? **(t **)((ap += 8) - 8) : *(t *)((ap += 8) - 8)) 42 | #define va_copy(dest, src) ((dest) = (src)) 43 | #define va_end(ap) 44 | #endif 45 | 46 | #elif __arm__ 47 | typedef char *va_list; 48 | #define _tcc_alignof(type) ((int)&((struct {char c;type x;} *)0)->x) 49 | #define _tcc_align(addr,type) (((unsigned)addr + _tcc_alignof(type) - 1) \ 50 | & ~(_tcc_alignof(type) - 1)) 51 | #define va_start(ap,last) ap = ((char *)&(last)) + ((sizeof(last)+3)&~3) 52 | #define va_arg(ap,type) (ap = (void *) ((_tcc_align(ap,type)+sizeof(type)+3) \ 53 | &~3), *(type *)(ap - ((sizeof(type)+3)&~3))) 54 | #define va_copy(dest, src) (dest) = (src) 55 | #define va_end(ap) 56 | 57 | #elif defined(__aarch64__) 58 | typedef struct { 59 | void *__stack; 60 | void *__gr_top; 61 | void *__vr_top; 62 | int __gr_offs; 63 | int __vr_offs; 64 | } va_list; 65 | #define va_start(ap, last) __va_start(ap, last) 66 | #define va_arg(ap, type) __va_arg(ap, type) 67 | #define va_end(ap) 68 | #define va_copy(dest, src) ((dest) = (src)) 69 | 70 | #else /* __i386__ */ 71 | typedef char *va_list; 72 | /* only correct for i386 */ 73 | #define va_start(ap,last) ap = ((char *)&(last)) + ((sizeof(last)+3)&~3) 74 | #define va_arg(ap,type) (ap += (sizeof(type)+3)&~3, *(type *)(ap - ((sizeof(type)+3)&~3))) 75 | #define va_copy(dest, src) (dest) = (src) 76 | #define va_end(ap) 77 | #endif 78 | 79 | /* fix a buggy dependency on GCC in libio.h */ 80 | typedef va_list __gnuc_va_list; 81 | #define _VA_LIST_DEFINED 82 | 83 | #endif /* _STDARG_H */ 84 | -------------------------------------------------------------------------------- /include/stdbool.h: -------------------------------------------------------------------------------- 1 | #ifndef _STDBOOL_H 2 | #define _STDBOOL_H 3 | 4 | /* ISOC99 boolean */ 5 | 6 | #define bool _Bool 7 | #define true 1 8 | #define false 0 9 | #define __bool_true_false_are_defined 1 10 | 11 | #endif /* _STDBOOL_H */ 12 | -------------------------------------------------------------------------------- /include/stddef.h: -------------------------------------------------------------------------------- 1 | #ifndef _STDDEF_H 2 | #define _STDDEF_H 3 | 4 | typedef __SIZE_TYPE__ size_t; 5 | typedef __PTRDIFF_TYPE__ ssize_t; 6 | typedef __WCHAR_TYPE__ wchar_t; 7 | typedef __PTRDIFF_TYPE__ ptrdiff_t; 8 | typedef __PTRDIFF_TYPE__ intptr_t; 9 | typedef __SIZE_TYPE__ uintptr_t; 10 | 11 | #ifndef __int8_t_defined 12 | #define __int8_t_defined 13 | typedef signed char int8_t; 14 | typedef signed short int int16_t; 15 | typedef signed int int32_t; 16 | #ifdef __LP64__ 17 | typedef signed long int int64_t; 18 | #else 19 | typedef signed long long int int64_t; 20 | #endif 21 | typedef unsigned char uint8_t; 22 | typedef unsigned short int uint16_t; 23 | typedef unsigned int uint32_t; 24 | #ifdef __LP64__ 25 | typedef unsigned long int uint64_t; 26 | #else 27 | typedef unsigned long long int uint64_t; 28 | #endif 29 | #endif 30 | 31 | #ifndef NULL 32 | #define NULL ((void*)0) 33 | #endif 34 | 35 | #define offsetof(type, field) ((size_t)&((type *)0)->field) 36 | 37 | void *alloca(size_t size); 38 | 39 | #endif 40 | 41 | /* Older glibc require a wint_t from (when requested 42 | by __need_wint_t, as otherwise stddef.h isn't allowed to 43 | define this type). Note that this must be outside the normal 44 | _STDDEF_H guard, so that it works even when we've included the file 45 | already (without requiring wint_t). Some other libs define _WINT_T 46 | if they've already provided that type, so we can use that as guard. 47 | TCC defines __WINT_TYPE__ for us. */ 48 | #if defined (__need_wint_t) 49 | #ifndef _WINT_T 50 | #define _WINT_T 51 | typedef __WINT_TYPE__ wint_t; 52 | #endif 53 | #undef __need_wint_t 54 | #endif 55 | -------------------------------------------------------------------------------- /include/varargs.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef _VARARGS_H 7 | #define _VARARGS_H 8 | 9 | #error "TinyCC no longer implements ." 10 | #error "Revise your code to use ." 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /lib/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Tiny C Compiler Makefile for libtcc1.a 3 | # 4 | 5 | TOP = .. 6 | include $(TOP)/Makefile 7 | VPATH = $(TOPSRC)/lib $(TOPSRC)/win32/lib 8 | T = $(or $(CROSS_TARGET),$(NATIVE_TARGET),unknown) 9 | X = $(if $(CROSS_TARGET),$(CROSS_TARGET)-) 10 | BIN = $(TOP)/libtcc1$(if $(CROSS_TARGET),-$(CROSS_TARGET)).a 11 | 12 | TCC = $(TOP)/$(X)tcc$(EXESUF) 13 | XCC = $(TCC) 14 | XAR = $(TCC) -ar 15 | XFLAGS-unx = -B$(TOPSRC) 16 | XFLAGS-win = -B$(TOPSRC)/win32 -I$(TOPSRC)/include 17 | XFLAGS = $(XFLAGS$(XCFG)) 18 | XCFG = $(or $(findstring -win,$T),-unx) 19 | 20 | # in order to use gcc, tyoe: make lib-usegcc=yes 21 | armlib-usegcc ?= no 22 | 23 | ifeq "$($(X)$(T)lib-usegcc)" "yes" 24 | XCC = $(CC) 25 | XAR = $(AR) 26 | XFLAGS = $(CFLAGS) -fPIC 27 | endif 28 | 29 | # only for native compiler 30 | $(X)BCHECK_O = bcheck.o 31 | 32 | ifeq ($(CONFIG_musl)$(CONFIG_uClibc),yes) 33 | BCHECK_O = 34 | endif 35 | 36 | ifdef CONFIG_OSX 37 | XFLAGS += -D_ANSI_SOURCE 38 | endif 39 | 40 | I386_O = libtcc1.o alloca86.o alloca86-bt.o 41 | X86_64_O = libtcc1.o alloca86_64.o alloca86_64-bt.o 42 | ARM_O = libtcc1.o armeabi.o alloca-arm.o armflush.o 43 | ARM64_O = lib-arm64.o 44 | WIN_O = crt1.o crt1w.o wincrt1.o wincrt1w.o dllcrt1.o dllmain.o 45 | 46 | OBJ-i386 = $(I386_O) $(BCHECK_O) 47 | OBJ-x86_64 = $(X86_64_O) va_list.o $(BCHECK_O) 48 | OBJ-x86_64-osx = $(X86_64_O) va_list.o 49 | OBJ-i386-win32 = $(I386_O) chkstk.o bcheck.o $(WIN_O) 50 | OBJ-x86_64-win32 = $(X86_64_O) chkstk.o bcheck.o $(WIN_O) 51 | OBJ-arm64 = $(ARM64_O) 52 | OBJ-arm = $(ARM_O) 53 | OBJ-arm-fpa = $(ARM_O) 54 | OBJ-arm-fpa-ld = $(ARM_O) 55 | OBJ-arm-vfp = $(ARM_O) 56 | OBJ-arm-eabi = $(ARM_O) 57 | OBJ-arm-eabihf = $(ARM_O) 58 | OBJ-arm-wince = $(ARM_O) $(WIN_O) 59 | 60 | $(BIN) : $(patsubst %.o,$(X)%.o,$(OBJ-$T)) 61 | $(XAR) rcs $@ $^ 62 | 63 | $(X)%.o : %.c 64 | $(XCC) -c $< -o $@ $(XFLAGS) 65 | 66 | $(X)%.o : %.S 67 | $(XCC) -c $< -o $@ $(XFLAGS) 68 | 69 | $(X)crt1w.o : crt1.c 70 | $(X)wincrt1w.o : wincrt1.c 71 | 72 | clean : 73 | rm -f *.a *.o $(BIN) 74 | -------------------------------------------------------------------------------- /lib/alloca-arm.S: -------------------------------------------------------------------------------- 1 | .text 2 | .align 2 3 | .global alloca 4 | .type alloca, %function 5 | alloca: 6 | #ifdef __TINYC__ 7 | .int 0xe060d00d 8 | .int 0xe3cdd007 9 | .int 0xe1a0000d 10 | .int 0xe1a0f00e 11 | #else 12 | rsb sp, r0, sp 13 | bic sp, sp, #7 14 | mov r0, sp 15 | mov pc, lr 16 | #endif 17 | .size alloca, .-alloca 18 | -------------------------------------------------------------------------------- /lib/alloca86-bt.S: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------- */ 2 | /* alloca86-bt.S */ 3 | 4 | .globl __bound_alloca 5 | 6 | __bound_alloca: 7 | pop %edx 8 | pop %eax 9 | mov %eax, %ecx 10 | add $3,%eax 11 | and $-4,%eax 12 | jz p6 13 | 14 | #ifdef _WIN32 15 | p4: 16 | cmp $4096,%eax 17 | jbe p5 18 | test %eax,-4096(%esp) 19 | sub $4096,%esp 20 | sub $4096,%eax 21 | jmp p4 22 | 23 | p5: 24 | #endif 25 | 26 | sub %eax,%esp 27 | mov %esp,%eax 28 | 29 | push %edx 30 | push %eax 31 | push %ecx 32 | push %eax 33 | call __bound_new_region 34 | add $8, %esp 35 | pop %eax 36 | pop %edx 37 | 38 | p6: 39 | push %edx 40 | push %edx 41 | ret 42 | 43 | /* mark stack as nonexecutable */ 44 | #if defined __ELF__ && defined __linux__ 45 | .section .note.GNU-stack,"",@progbits 46 | #endif 47 | /* ---------------------------------------------- */ 48 | -------------------------------------------------------------------------------- /lib/alloca86.S: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------- */ 2 | /* alloca86.S */ 3 | 4 | .globl alloca 5 | 6 | alloca: 7 | pop %edx 8 | pop %eax 9 | add $3,%eax 10 | and $-4,%eax 11 | jz p3 12 | 13 | #ifdef _WIN32 14 | p1: 15 | cmp $4096,%eax 16 | jbe p2 17 | test %eax,-4096(%esp) 18 | sub $4096,%esp 19 | sub $4096,%eax 20 | jmp p1 21 | p2: 22 | #endif 23 | 24 | sub %eax,%esp 25 | mov %esp,%eax 26 | p3: 27 | push %edx 28 | push %edx 29 | ret 30 | 31 | /* ---------------------------------------------- */ 32 | -------------------------------------------------------------------------------- /lib/alloca86_64-bt.S: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------- */ 2 | /* alloca86_64.S */ 3 | 4 | .globl __bound_alloca 5 | __bound_alloca: 6 | 7 | #ifdef _WIN32 8 | # bound checking is not implemented 9 | pop %rdx 10 | mov %rcx,%rax 11 | add $15,%rax 12 | and $-16,%rax 13 | jz p3 14 | 15 | p1: 16 | cmp $4096,%rax 17 | jbe p2 18 | test %rax,-4096(%rsp) 19 | sub $4096,%rsp 20 | sub $4096,%rax 21 | jmp p1 22 | p2: 23 | 24 | sub %rax,%rsp 25 | mov %rsp,%rax 26 | add $32,%rax 27 | 28 | p3: 29 | push %rdx 30 | ret 31 | #else 32 | pop %rdx 33 | mov %rdi,%rax 34 | mov %rax,%rsi # size, a second parm to the __bound_new_region 35 | 36 | add $15,%rax 37 | and $-16,%rax 38 | jz p3 39 | 40 | 41 | sub %rax,%rsp 42 | mov %rsp,%rdi # pointer, a first parm to the __bound_new_region 43 | mov %rsp,%rax 44 | 45 | push %rdx 46 | push %rax 47 | call __bound_new_region 48 | pop %rax 49 | pop %rdx 50 | 51 | p3: 52 | push %rdx 53 | ret 54 | #endif 55 | 56 | /* ---------------------------------------------- */ 57 | -------------------------------------------------------------------------------- /lib/alloca86_64.S: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------- */ 2 | /* alloca86_64.S */ 3 | 4 | .globl alloca 5 | 6 | alloca: 7 | pop %rdx 8 | #ifdef _WIN32 9 | mov %rcx,%rax 10 | #else 11 | mov %rdi,%rax 12 | #endif 13 | add $15,%rax 14 | and $-16,%rax 15 | jz p3 16 | 17 | #ifdef _WIN32 18 | p1: 19 | cmp $4096,%rax 20 | jbe p2 21 | test %rax,-4096(%rsp) 22 | sub $4096,%rsp 23 | sub $4096,%rax 24 | jmp p1 25 | p2: 26 | #endif 27 | 28 | sub %rax,%rsp 29 | mov %rsp,%rax 30 | p3: 31 | push %rdx 32 | ret 33 | 34 | /* ---------------------------------------------- */ 35 | -------------------------------------------------------------------------------- /lib/armflush.c: -------------------------------------------------------------------------------- 1 | /* armflush.c - flush the instruction cache 2 | 3 | __clear_cache is used in tccrun.c, It is a built-in 4 | intrinsic with gcc. However tcc in order to compile 5 | itself needs this function */ 6 | 7 | #ifdef __TINYC__ 8 | 9 | /* syscall wrapper */ 10 | unsigned syscall(unsigned syscall_nr, ...); 11 | 12 | /* arm-tcc supports only fake asm currently */ 13 | __asm__( 14 | ".global syscall\n" 15 | "syscall:\n" 16 | ".int 0xe92d4080\n" // push {r7, lr} 17 | ".int 0xe1a07000\n" // mov r7, r0 18 | ".int 0xe1a00001\n" // mov r0, r1 19 | ".int 0xe1a01002\n" // mov r1, r2 20 | ".int 0xe1a02003\n" // mov r2, r3 21 | ".int 0xef000000\n" // svc 0x00000000 22 | ".int 0xe8bd8080\n" // pop {r7, pc} 23 | ); 24 | 25 | /* from unistd.h: */ 26 | #if defined(__thumb__) || defined(__ARM_EABI__) 27 | # define __NR_SYSCALL_BASE 0x0 28 | #else 29 | # define __NR_SYSCALL_BASE 0x900000 30 | #endif 31 | #define __ARM_NR_BASE (__NR_SYSCALL_BASE+0x0f0000) 32 | #define __ARM_NR_cacheflush (__ARM_NR_BASE+2) 33 | 34 | #else 35 | 36 | #define _GNU_SOURCE 37 | #include 38 | #include 39 | #include 40 | 41 | #endif 42 | 43 | /* Flushing for tccrun */ 44 | void __clear_cache(void *beginning, void *end) 45 | { 46 | /* __ARM_NR_cacheflush is kernel private and should not be used in user space. 47 | * However, there is no ARM asm parser in tcc so we use it for now */ 48 | #if 1 49 | syscall(__ARM_NR_cacheflush, beginning, end, 0); 50 | #else 51 | __asm__ ("push {r7}\n\t" 52 | "mov r7, #0xf0002\n\t" 53 | "mov r2, #0\n\t" 54 | "swi 0\n\t" 55 | "pop {r7}\n\t" 56 | "ret"); 57 | #endif 58 | } 59 | -------------------------------------------------------------------------------- /lib/va_list.c: -------------------------------------------------------------------------------- 1 | /* va_list.c - tinycc support for va_list on X86_64 */ 2 | 3 | #if defined __x86_64__ 4 | 5 | /* Avoid include files, they may not be available when cross compiling */ 6 | extern void *memset(void *s, int c, __SIZE_TYPE__ n); 7 | extern void abort(void); 8 | 9 | /* This should be in sync with our include/stdarg.h */ 10 | enum __va_arg_type { 11 | __va_gen_reg, __va_float_reg, __va_stack 12 | }; 13 | 14 | /* GCC compatible definition of va_list. */ 15 | typedef struct { 16 | unsigned int gp_offset; 17 | unsigned int fp_offset; 18 | union { 19 | unsigned int overflow_offset; 20 | char *overflow_arg_area; 21 | }; 22 | char *reg_save_area; 23 | } __va_list_struct; 24 | 25 | void __va_start(__va_list_struct *ap, void *fp) 26 | { 27 | memset(ap, 0, sizeof(__va_list_struct)); 28 | *ap = *(__va_list_struct *)((char *)fp - 16); 29 | ap->overflow_arg_area = (char *)fp + ap->overflow_offset; 30 | ap->reg_save_area = (char *)fp - 176 - 16; 31 | } 32 | 33 | void *__va_arg(__va_list_struct *ap, 34 | enum __va_arg_type arg_type, 35 | int size, int align) 36 | { 37 | size = (size + 7) & ~7; 38 | align = (align + 7) & ~7; 39 | switch (arg_type) { 40 | case __va_gen_reg: 41 | if (ap->gp_offset + size <= 48) { 42 | ap->gp_offset += size; 43 | return ap->reg_save_area + ap->gp_offset - size; 44 | } 45 | goto use_overflow_area; 46 | 47 | case __va_float_reg: 48 | if (ap->fp_offset < 128 + 48) { 49 | ap->fp_offset += 16; 50 | return ap->reg_save_area + ap->fp_offset - 16; 51 | } 52 | size = 8; 53 | goto use_overflow_area; 54 | 55 | case __va_stack: 56 | use_overflow_area: 57 | ap->overflow_arg_area += size; 58 | ap->overflow_arg_area = (char*)((long long)(ap->overflow_arg_area + align - 1) & -align); 59 | return ap->overflow_arg_area - size; 60 | 61 | default: /* should never happen */ 62 | abort(); 63 | } 64 | } 65 | #endif 66 | -------------------------------------------------------------------------------- /pe32.h: -------------------------------------------------------------------------------- 1 | /* 2 | * pe32.h - shared PE32(+) definitions. 3 | * 4 | * Copyright (c) 2017 Andrei Warkentin 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | */ 20 | 21 | #ifndef _PE32_H 22 | #define _PE32_H 1 23 | 24 | /* 25 | * PE32(+) subsystem types. 26 | */ 27 | #define IMAGE_SUBSYSTEM_UNKNOWN 0 28 | #define IMAGE_SUBSYSTEM_NATIVE 1 29 | #define IMAGE_SUBSYSTEM_WINDOWS_GUI 2 30 | #define IMAGE_SUBSYSTEM_WINDOWS_CUI 3 31 | #define IMAGE_SUBSYSTEM_OS2_CUI 5 32 | #define IMAGE_SUBSYSTEM_POSIX_CUI 7 33 | #define IMAGE_SUBSYSTEM_NATIVE_WIN9X 8 34 | #define IMAGE_SUBSYSTEM_WINDOWS_CE_GUI 9 35 | #define IMAGE_SUBSYSTEM_EFI_APPLICATION 10 36 | #define IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER 11 37 | #define IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER 12 38 | #define IMAGE_SUBSYSTEM_EFI_ROM 13 39 | #define IMAGE_SUBSYSTEM_XBOX 14 40 | #define IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATION 16 41 | 42 | 43 | /* 44 | * PE32(+) characteristics. 45 | */ 46 | #define IMAGE_FILE_RELOCS_STRIPPED 0x0001 47 | #define IMAGE_FILE_EXECUTABLE_IMAGE 0x0002 48 | #define IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004 49 | #define IMAGE_FILE_LOCAL_SYMS_STRIPPED 0x0008 50 | #define IMAGE_FILE_AGGRESSIVE_WS_TRIM 0x0010 51 | #define IMAGE_FILE_LARGE_ADDRESS_AWARE 0x0020 52 | #define IMAGE_FILE_BYTES_REVERSED_LO 0x0080 53 | #define IMAGE_FILE_32BIT_MACHINE 0x0100 54 | #define IMAGE_FILE_DEBUG_STRIPPED 0x0200 55 | #define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP 0x0400 56 | #define IMAGE_FILE_NET_RUN_FROM_SWAP 0x0800 57 | #define IMAGE_FILE_SYSTEM 0x1000 58 | #define IMAGE_FILE_DLL 0x2000 59 | #define IMAGE_FILE_UP_SYSTEM_ONLY 0x4000 60 | #define IMAGE_FILE_BYTES_REVERSED_HI 0x8000 61 | 62 | #endif /* _PE32_H */ 63 | -------------------------------------------------------------------------------- /stab.h: -------------------------------------------------------------------------------- 1 | #ifndef __GNU_STAB__ 2 | 3 | /* Indicate the GNU stab.h is in use. */ 4 | 5 | #define __GNU_STAB__ 6 | 7 | #define __define_stab(NAME, CODE, STRING) NAME=CODE, 8 | 9 | enum __stab_debug_code 10 | { 11 | #include "stab.def" 12 | LAST_UNUSED_STAB_CODE 13 | }; 14 | 15 | #undef __define_stab 16 | 17 | #endif /* __GNU_STAB_ */ 18 | -------------------------------------------------------------------------------- /tcclib.h: -------------------------------------------------------------------------------- 1 | /* Simple libc header for TCC 2 | * 3 | * Add any function you want from the libc there. This file is here 4 | * only for your convenience so that you do not need to put the whole 5 | * glibc include files on your floppy disk 6 | */ 7 | #ifndef _TCCLIB_H 8 | #define _TCCLIB_H 9 | 10 | #include 11 | #include 12 | 13 | /* stdlib.h */ 14 | void *calloc(size_t nmemb, size_t size); 15 | void *malloc(size_t size); 16 | void free(void *ptr); 17 | void *realloc(void *ptr, size_t size); 18 | int atoi(const char *nptr); 19 | long int strtol(const char *nptr, char **endptr, int base); 20 | unsigned long int strtoul(const char *nptr, char **endptr, int base); 21 | void exit(int); 22 | 23 | /* stdio.h */ 24 | typedef struct __FILE FILE; 25 | #define EOF (-1) 26 | extern FILE *stdin; 27 | extern FILE *stdout; 28 | extern FILE *stderr; 29 | FILE *fopen(const char *path, const char *mode); 30 | FILE *fdopen(int fildes, const char *mode); 31 | FILE *freopen(const char *path, const char *mode, FILE *stream); 32 | int fclose(FILE *stream); 33 | size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream); 34 | size_t fwrite(void *ptr, size_t size, size_t nmemb, FILE *stream); 35 | int fgetc(FILE *stream); 36 | char *fgets(char *s, int size, FILE *stream); 37 | int getc(FILE *stream); 38 | int getchar(void); 39 | char *gets(char *s); 40 | int ungetc(int c, FILE *stream); 41 | int fflush(FILE *stream); 42 | int putchar (int c); 43 | 44 | int printf(const char *format, ...); 45 | int fprintf(FILE *stream, const char *format, ...); 46 | int sprintf(char *str, const char *format, ...); 47 | int snprintf(char *str, size_t size, const char *format, ...); 48 | int asprintf(char **strp, const char *format, ...); 49 | int dprintf(int fd, const char *format, ...); 50 | int vprintf(const char *format, va_list ap); 51 | int vfprintf(FILE *stream, const char *format, va_list ap); 52 | int vsprintf(char *str, const char *format, va_list ap); 53 | int vsnprintf(char *str, size_t size, const char *format, va_list ap); 54 | int vasprintf(char **strp, const char *format, va_list ap); 55 | int vdprintf(int fd, const char *format, va_list ap); 56 | 57 | void perror(const char *s); 58 | 59 | /* string.h */ 60 | char *strcat(char *dest, const char *src); 61 | char *strchr(const char *s, int c); 62 | char *strrchr(const char *s, int c); 63 | char *strcpy(char *dest, const char *src); 64 | void *memcpy(void *dest, const void *src, size_t n); 65 | void *memmove(void *dest, const void *src, size_t n); 66 | void *memset(void *s, int c, size_t n); 67 | char *strdup(const char *s); 68 | size_t strlen(const char *s); 69 | 70 | /* dlfcn.h */ 71 | #define RTLD_LAZY 0x001 72 | #define RTLD_NOW 0x002 73 | #define RTLD_GLOBAL 0x100 74 | 75 | void *dlopen(const char *filename, int flag); 76 | const char *dlerror(void); 77 | void *dlsym(void *handle, char *symbol); 78 | int dlclose(void *handle); 79 | 80 | #endif /* _TCCLIB_H */ 81 | -------------------------------------------------------------------------------- /tests/42test.h: -------------------------------------------------------------------------------- 1 | /* This file is to test compute #include directives. It's named so 2 | that it starts with a pre-processing number which isn't a valid 3 | number (42test.h). Including this must work. */ 4 | #ifndef INC42_FIRST 5 | int have_included_42test_h; 6 | #define INC42_FIRST 7 | #elif !defined INC42_SECOND 8 | #define INC42_SECOND 9 | int have_included_42test_h_second; 10 | #else 11 | #define INC42_THIRD 12 | int have_included_42test_h_third; 13 | #endif 14 | -------------------------------------------------------------------------------- /tests/gcctestsuite.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | TESTSUITE_PATH=$HOME/gcc/gcc-3.2/gcc/testsuite/gcc.c-torture 4 | TCC="./tcc -B. -I. -DNO_TRAMPOLINES" 5 | rm -f tcc.sum tcc.log 6 | nb_failed="0" 7 | 8 | for src in $TESTSUITE_PATH/compile/*.c ; do 9 | echo $TCC -o /tmp/test.o -c $src 10 | $TCC -o /tmp/test.o -c $src >> tcc.log 2>&1 11 | if [ "$?" = "0" ] ; then 12 | result="PASS" 13 | else 14 | result="FAIL" 15 | nb_failed=$(( $nb_failed + 1 )) 16 | fi 17 | echo "$result: $src" >> tcc.sum 18 | done 19 | 20 | for src in $TESTSUITE_PATH/execute/*.c ; do 21 | echo $TCC $src 22 | $TCC $src >> tcc.log 2>&1 23 | if [ "$?" = "0" ] ; then 24 | result="PASS" 25 | else 26 | result="FAIL" 27 | nb_failed=$(( $nb_failed + 1 )) 28 | fi 29 | echo "$result: $src" >> tcc.sum 30 | done 31 | 32 | echo "$nb_failed test(s) failed." >> tcc.sum 33 | echo "$nb_failed test(s) failed." 34 | -------------------------------------------------------------------------------- /tests/libtcc_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Simple Test program for libtcc 3 | * 4 | * libtcc can be useful to use tcc as a "backend" for a code generator. 5 | */ 6 | #include 7 | #include 8 | #include 9 | 10 | #include "libtcc.h" 11 | 12 | /* this function is called by the generated code */ 13 | int add(int a, int b) 14 | { 15 | return a + b; 16 | } 17 | 18 | /* this strinc is referenced by the generated code */ 19 | const char hello[] = "Hello World!"; 20 | 21 | char my_program[] = 22 | "#include \n" /* include the "Simple libc header for TCC" */ 23 | "extern int add(int a, int b);\n" 24 | "#ifdef _WIN32\n" /* dynamically linked data needs 'dllimport' */ 25 | " __attribute__((dllimport))\n" 26 | "#endif\n" 27 | "extern const char hello[];\n" 28 | "int fib(int n)\n" 29 | "{\n" 30 | " if (n <= 2)\n" 31 | " return 1;\n" 32 | " else\n" 33 | " return fib(n-1) + fib(n-2);\n" 34 | "}\n" 35 | "\n" 36 | "int foo(int n)\n" 37 | "{\n" 38 | " printf(\"%s\\n\", hello);\n" 39 | " printf(\"fib(%d) = %d\\n\", n, fib(n));\n" 40 | " printf(\"add(%d, %d) = %d\\n\", n, 2 * n, add(n, 2 * n));\n" 41 | " return 0;\n" 42 | "}\n"; 43 | 44 | int main(int argc, char **argv) 45 | { 46 | TCCState *s; 47 | int i; 48 | int (*func)(int); 49 | 50 | s = tcc_new(); 51 | if (!s) { 52 | fprintf(stderr, "Could not create tcc state\n"); 53 | exit(1); 54 | } 55 | 56 | /* if tcclib.h and libtcc1.a are not installed, where can we find them */ 57 | for (i = 1; i < argc; ++i) { 58 | char *a = argv[i]; 59 | if (a[0] == '-') { 60 | if (a[1] == 'B') 61 | tcc_set_lib_path(s, a+2); 62 | else if (a[1] == 'I') 63 | tcc_add_include_path(s, a+2); 64 | else if (a[1] == 'L') 65 | tcc_add_library_path(s, a+2); 66 | } 67 | } 68 | 69 | /* MUST BE CALLED before any compilation */ 70 | tcc_set_output_type(s, TCC_OUTPUT_MEMORY); 71 | 72 | if (tcc_compile_string(s, my_program) == -1) 73 | return 1; 74 | 75 | /* as a test, we add symbols that the compiled program can use. 76 | You may also open a dll with tcc_add_dll() and use symbols from that */ 77 | tcc_add_symbol(s, "add", add); 78 | tcc_add_symbol(s, "hello", hello); 79 | 80 | /* relocate the code */ 81 | if (tcc_relocate(s, TCC_RELOCATE_AUTO) < 0) 82 | return 1; 83 | 84 | /* get entry symbol */ 85 | func = tcc_get_symbol(s, "foo"); 86 | if (!func) 87 | return 1; 88 | 89 | /* run the code */ 90 | func(32); 91 | 92 | /* delete the state */ 93 | tcc_delete(s); 94 | 95 | return 0; 96 | } 97 | -------------------------------------------------------------------------------- /tests/pp/01.c: -------------------------------------------------------------------------------- 1 | #define hash_hash # ## # 2 | #define mkstr(a) # a 3 | #define in_between(a) mkstr(a) 4 | #define join(c, d) in_between(c hash_hash d) 5 | char p[] = join(x, y); 6 | // char p[] = "x ## y"; 7 | -------------------------------------------------------------------------------- /tests/pp/01.expect: -------------------------------------------------------------------------------- 1 | char p[] = "x ## y"; 2 | -------------------------------------------------------------------------------- /tests/pp/02.c: -------------------------------------------------------------------------------- 1 | #define x 3 2 | #define f(a) f(x * (a)) 3 | #undef x 4 | #define x 2 5 | #define g f 6 | #define z z[0] 7 | #define h g(~ 8 | #define m(a) a(w) 9 | #define w 0,1 10 | #define t(a) a 11 | #define p() int 12 | #define q(x) x 13 | #define r(x,y) x ## y 14 | #define str(x) # x 15 | f(y+1) + f(f(z)) % t(t(g)(0) + t)(1); 16 | g(x+(3,4)-w) | h 5) & m 17 | (f)^m(m); 18 | char c[2][6] = { str(hello), str() }; 19 | /* 20 | * f(2 * (y+1)) + f(2 * (f(2 * (z[0])))) % f(2 * (0)) + t(1); 21 | * f(2 * (2+(3,4)-0,1)) | f(2 * (~ 5)) & f(2 * (0,1))^m(0,1); 22 | * char c[2][6] = { "hello", "" }; 23 | */ 24 | #define L21 f(y+1) + f(f(z)) % t(t(g)(0) + t)(1); 25 | #define L22 g(x+(3,4)-w) | h 5) & m\ 26 | (f)^m(m); 27 | L21 28 | L22 29 | -------------------------------------------------------------------------------- /tests/pp/02.expect: -------------------------------------------------------------------------------- 1 | f(2 * (y+1)) + f(2 * (f(2 * (z[0])))) % f(2 * (0)) + t(1); 2 | f(2 * (2 +(3,4)-0,1)) | f(2 * (~ 5)) & f(2 * (0,1))^m(0,1); 3 | char c[2][6] = { "hello", "" }; 4 | f(2 * (y+1)) + f(2 * (f(2 * (z[0])))) % f(2 * (0)) + t(1); 5 | f(2 * (2 +(3,4)-0,1)) | f(2 * (~ 5)) & f(2 * (0,1))^m(0,1); 6 | -------------------------------------------------------------------------------- /tests/pp/03.c: -------------------------------------------------------------------------------- 1 | #define str(s) # s 2 | #define xstr(s) str(s) 3 | #define debug(s, t) printf("x" # s "= %d, x" # t "= %s", \ 4 | x ## s, x ## t) 5 | #define INCFILE(n) vers ## n 6 | #define glue(a, b) a ## b 7 | #define xglue(a, b) glue(a, b) 8 | #define HIGHLOW "hello" 9 | #define LOW LOW ", world" 10 | debug(1, 2); 11 | fputs(str(strncmp("abc\0d", "abc", '\4') // this goes away 12 | == 0) str(: @\n), s); 13 | \#include xstr(INCFILE(2).h) 14 | glue(HIGH, LOW); 15 | xglue(HIGH, LOW) 16 | -------------------------------------------------------------------------------- /tests/pp/03.expect: -------------------------------------------------------------------------------- 1 | printf("x" "1" "= %d, x" "2" "= %s", x1, x2); 2 | fputs("strncmp(\"abc\\0d\", \"abc\", '\\4') == 0" ": @\n", s); 3 | \#include "vers2.h" 4 | "hello"; 5 | "hello" ", world" 6 | -------------------------------------------------------------------------------- /tests/pp/04.c: -------------------------------------------------------------------------------- 1 | #define foobar 1 2 | #define C(x,y) x##y 3 | #define D(x) (C(x,bar)) 4 | D(foo) 5 | -------------------------------------------------------------------------------- /tests/pp/04.expect: -------------------------------------------------------------------------------- 1 | (1) 2 | -------------------------------------------------------------------------------- /tests/pp/05.c: -------------------------------------------------------------------------------- 1 | #define t(x,y,z) x ## y ## z 2 | #define xxx(s) int s[] = { t(1,2,3), t(,4,5), t(6,,7), t(8,9,), \ 3 | t(10,,), t(,11,), t(,,12), t(,,) }; 4 | 5 | int j[] = { t(1,2,3), t(,4,5), t(6,,7), t(8,9,), 6 | t(10,,), t(,11,), t(,,12), t(,,) }; 7 | xxx(j) 8 | -------------------------------------------------------------------------------- /tests/pp/05.expect: -------------------------------------------------------------------------------- 1 | int j[] = { 123, 45, 67, 89, 2 | 10, 11, 12, }; 3 | int j[] = { 123, 45, 67, 89, 10, 11, 12, }; 4 | -------------------------------------------------------------------------------- /tests/pp/06.c: -------------------------------------------------------------------------------- 1 | #define X(a,b, \ 2 | c,d) \ 3 | foo 4 | 5 | X(1,2,3,4) 6 | -------------------------------------------------------------------------------- /tests/pp/06.expect: -------------------------------------------------------------------------------- 1 | foo 2 | -------------------------------------------------------------------------------- /tests/pp/07.c: -------------------------------------------------------------------------------- 1 | #define a() YES 2 | #define b() a 3 | b() 4 | b()() 5 | -------------------------------------------------------------------------------- /tests/pp/07.expect: -------------------------------------------------------------------------------- 1 | a 2 | YES 3 | -------------------------------------------------------------------------------- /tests/pp/08.c: -------------------------------------------------------------------------------- 1 | // test macro expansion in arguments 2 | #define s_pos s_s.s_pos 3 | #define foo(x) (x) 4 | foo(hej.s_pos) 5 | -------------------------------------------------------------------------------- /tests/pp/08.expect: -------------------------------------------------------------------------------- 1 | (hej.s_s.s_pos) 2 | -------------------------------------------------------------------------------- /tests/pp/09.c: -------------------------------------------------------------------------------- 1 | #define C(a,b,c) a##b##c 2 | #define N(x,y) C(x,_,y) 3 | #define A_O aaaaoooo 4 | N(A,O) 5 | -------------------------------------------------------------------------------- /tests/pp/09.expect: -------------------------------------------------------------------------------- 1 | aaaaoooo 2 | -------------------------------------------------------------------------------- /tests/pp/10.c: -------------------------------------------------------------------------------- 1 | #define f(x) x 2 | #define g(x) f(x) f(x 3 | #define i(x) g(x)) g(x 4 | #define h(x) i(x))) i(x 5 | #define k(x) i(x))) i(x)))) 6 | f(x) 7 | g(x)) 8 | i(x))) 9 | h(x)))) 10 | k(x)))) 11 | -------------------------------------------------------------------------------- /tests/pp/10.expect: -------------------------------------------------------------------------------- 1 | x 2 | x x 3 | x x x x 4 | x x x x x x x x 5 | x x x x x x x x)))) 6 | -------------------------------------------------------------------------------- /tests/pp/11.c: -------------------------------------------------------------------------------- 1 | #define D1(s, ...) s 2 | #define D2(s, ...) s D1(__VA_ARGS__) 3 | #define D3(s, ...) s D2(__VA_ARGS__) 4 | #define D4(s, ...) s D3(__VA_ARGS__) 5 | 6 | D1(a) 7 | D2(a, b) 8 | D3(a, b, c) 9 | D4(a, b, c, d) 10 | 11 | x D4(a, b, c, d) y 12 | x D4(a, b, c) y 13 | x D4(a, b) y 14 | x D4(a) y 15 | x D4() y 16 | 17 | #define GNU_COMMA(X,Y...) X,## Y 18 | 19 | x GNU_COMMA(A,B,C) y 20 | x GNU_COMMA(A,B) y 21 | x GNU_COMMA(A) y 22 | x GNU_COMMA() y 23 | 24 | #define __sun_attr___noreturn__ __attribute__((__noreturn__)) 25 | #define ___sun_attr_inner(__a) __sun_attr_##__a 26 | #define __sun_attr__(__a) ___sun_attr_inner __a 27 | #define __NORETURN __sun_attr__((__noreturn__)) 28 | __NORETURN 29 | #define X(...) 30 | #define Y(...) 1 __VA_ARGS__ 2 31 | Y(X X() ()) 32 | -------------------------------------------------------------------------------- /tests/pp/11.expect: -------------------------------------------------------------------------------- 1 | a 2 | a b 3 | a b c 4 | a b c d 5 | x a b c d y 6 | x a b c y 7 | x a b y 8 | x a y 9 | x y 10 | x A,B,C y 11 | x A,B y 12 | x A y 13 | x y 14 | __attribute__((__noreturn__)) 15 | 1 2 16 | -------------------------------------------------------------------------------- /tests/pp/12.S: -------------------------------------------------------------------------------- 1 | #define SRC(y...) \ 2 | 9999: y; \ 3 | .section __ex_table, "a"; \ 4 | .long 9999b, 6001f ; \ 5 | // .previous 6 | 7 | SRC(1: movw (%esi), %bx) 8 | 6001: 9 | -------------------------------------------------------------------------------- /tests/pp/12.expect: -------------------------------------------------------------------------------- 1 | 9999: 1: movw (%esi), %bx; .section __ex_table, "a"; .long 9999b, 6001f ; 2 | 6001: 3 | -------------------------------------------------------------------------------- /tests/pp/13.S: -------------------------------------------------------------------------------- 1 | # `modelist' label. Each video mode record looks like: 2 | #ifdef AAA 3 | # modelist' label. Each video mode record looks like: 4 | #endif 5 | .text 6 | endtext: 7 | -------------------------------------------------------------------------------- /tests/pp/13.expect: -------------------------------------------------------------------------------- 1 | # `modelist' label. Each video mode record looks like: 2 | .text 3 | endtext: 4 | -------------------------------------------------------------------------------- /tests/pp/14.c: -------------------------------------------------------------------------------- 1 | #define W Z 2 | #define Z(X) W(X,2) 3 | #define Y(X) Z(X) 4 | #define X Y 5 | return X(X(1)); 6 | 7 | #define P Q 8 | #define Q(n) P(n,2) 9 | return P(1); 10 | 11 | #define A (B * B) 12 | #define B (A + A) 13 | return A + B; 14 | -------------------------------------------------------------------------------- /tests/pp/14.expect: -------------------------------------------------------------------------------- 1 | return Z(Z(1,2),2); 2 | return Q(1,2); 3 | return ((A + A) * (A + A)) + ((B * B) + (B * B)); 4 | -------------------------------------------------------------------------------- /tests/pp/15.c: -------------------------------------------------------------------------------- 1 | // insert a space between two tokens if otherwise they 2 | // would form a single token when read back 3 | 4 | #define n(x) x 5 | 6 | return (n(long)n(double))d; 7 | return n(A)n(++)n(+)n(B); 8 | return n(A)n(+)n(++)n(B); 9 | return n(A)n(++)n(+)n(+)n(B); 10 | 11 | // not a hex float 12 | return n(0x1E)n(-1); 13 | 14 | // unlike gcc but correct 15 | XXX: return n(x)+n(x)-n(1)+n(1)-2; 16 | 17 | // unlile gcc, but cannot appear in valid C 18 | XXX: return n(x)n(x)n(1)n(2)n(x); 19 | -------------------------------------------------------------------------------- /tests/pp/15.expect: -------------------------------------------------------------------------------- 1 | return (long double)d; 2 | return A+++B; 3 | return A+ ++B; 4 | return A+++ +B; 5 | return 0x1E -1; 6 | XXX: return x+x-1 +1 -2; 7 | XXX: return x x 1 2 x; 8 | -------------------------------------------------------------------------------- /tests/pp/16.c: -------------------------------------------------------------------------------- 1 | /* The following should warn */ 2 | #define A ... 3 | #define A <<= 4 | -------------------------------------------------------------------------------- /tests/pp/16.expect: -------------------------------------------------------------------------------- 1 | 2 | 16.c:3: warning: A redefined 3 | -------------------------------------------------------------------------------- /tests/pp/17.c: -------------------------------------------------------------------------------- 1 | #define STR1(u) # u 2 | #define pass(a) a 3 | #define __ASM_REG(reg) STR1(one##reg) 4 | #define _ASM_DX __ASM_REG(tok) 5 | X162 pass(__ASM_REG(tok)) 6 | X161 pass(_ASM_DX) 7 | X163 pass(STR1(one##tok)) 8 | 9 | X170 pass(x ## y) 10 | X171 pass(x pass(##) y) 11 | 12 | #define Y(x) Z(x) 13 | #define X Y 14 | X180 return X(X(1)); 15 | -------------------------------------------------------------------------------- /tests/pp/17.expect: -------------------------------------------------------------------------------- 1 | X162 "onetok" 2 | X161 "onetok" 3 | X163 "one##tok" 4 | X170 x ## y 5 | X171 x ## y 6 | X180 return Z(Z(1)); 7 | -------------------------------------------------------------------------------- /tests/pp/18.c: -------------------------------------------------------------------------------- 1 | #define M_RETI_ARG27(x,y,z,aa, ...) aa 2 | #define M_RET_ARG27(...) M_RETI_ARG27(__VA_ARGS__) 3 | #define M_COMMA_P(...) M_RET_ARG27(__VA_ARGS__, 1, 1, 0, useless) 4 | #define M_EMPTYI_DETECT(...) 0, 1, 5 | #define M_EMPTYI_P_C1(...) M_COMMA_P(M_EMPTYI_DETECT __VA_ARGS__ () ) 6 | #define EX 7 | #define empty(x) 8 | #define fnlike(x) yeah x 9 | /* If the following macro is called with empty arg (X183), the use 10 | of 'x' between fnlike and '(' doesn't hinder the recognition of this 11 | being a further fnlike macro invocation. */ 12 | #define usefnlike(x) fnlike x (x) 13 | X181 M_EMPTYI_P_C1() 14 | X182 M_EMPTYI_P_C1(x) 15 | X183 usefnlike() 16 | -------------------------------------------------------------------------------- /tests/pp/18.expect: -------------------------------------------------------------------------------- 1 | X181 1 2 | X182 0 3 | X183 yeah 4 | -------------------------------------------------------------------------------- /tests/pp/19.expect: -------------------------------------------------------------------------------- 1 | X92 M_IFI_1 2 | X93 KO 3 | X94 KO 4 | X95 a 5 | X96 M_IFI_1 6 | X97 ok 7 | X98 (1)(ok, nok) 8 | X99 ok 9 | X1 ok 10 | X2 1 11 | X3 ok 12 | X4 1 13 | X5 nok 14 | X6 ok 15 | -------------------------------------------------------------------------------- /tests/pp/20.c: -------------------------------------------------------------------------------- 1 | /* Various things I encountered while hacking the pre processor */ 2 | #define wrap(x) x 3 | #define pr_warning(fmt, ...) printk(KERN_WARNING fmt, ##__VA_ARGS__) 4 | #define pr_warn(x,y) pr_warning(x,y) 5 | #define net_ratelimited_function(function, ...) function(__VA_ARGS__) 6 | X1 net_ratelimited_function(pr_warn, "pipapo", bla); 7 | X2 net_ratelimited_function(wrap(pr_warn), "bla", foo); 8 | #define two m n 9 | #define chain4(a,b,c,d) a ## b ## c ## d 10 | X2 chain4(two,o,p,q) 11 | X3 chain4(o,two,p,q) 12 | X4 chain4(o,p,two,q) 13 | X5 chain4(o,p,q,two) 14 | -------------------------------------------------------------------------------- /tests/pp/20.expect: -------------------------------------------------------------------------------- 1 | X1 printk(KERN_WARNING "pipapo",bla); 2 | X2 printk(KERN_WARNING "bla",foo); 3 | X2 twoopq 4 | X3 otwopq 5 | X4 optwoq 6 | X5 opqtwo 7 | -------------------------------------------------------------------------------- /tests/pp/21.c: -------------------------------------------------------------------------------- 1 | /* accept 'defined' as result of substitution */ 2 | 3 | ----- 1 ------ 4 | #define AAA 2 5 | #define BBB 6 | #define CCC (defined ( AAA ) && AAA > 1 && !defined BBB) 7 | #if !CCC 8 | OK 9 | #else 10 | NOT OK 11 | #endif 12 | 13 | ----- 2 ------ 14 | #undef BBB 15 | #if CCC 16 | OK 17 | #else 18 | NOT OK 19 | #endif 20 | 21 | ----- 3 ------ 22 | #define DEFINED defined 23 | #define DDD (DEFINED ( AAA ) && AAA > 1 && !DEFINED BBB) 24 | #if (DDD) 25 | OK 26 | #else 27 | NOT OK 28 | #endif 29 | 30 | ----- 4 ------ 31 | #undef AAA 32 | #if !(DDD) 33 | OK 34 | #else 35 | NOT OK 36 | #endif 37 | -------------------------------------------------------------------------------- /tests/pp/21.expect: -------------------------------------------------------------------------------- 1 | ----- 1 ------ 2 | OK 3 | ----- 2 ------ 4 | OK 5 | ----- 3 ------ 6 | OK 7 | ----- 4 ------ 8 | OK 9 | -------------------------------------------------------------------------------- /tests/pp/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # credits: 01..13.c from the pcc cpp-tests suite 3 | # 4 | 5 | TOP = ../.. 6 | include $(TOP)/Makefile 7 | SRC = $(TOPSRC)/tests/pp 8 | VPATH = $(SRC) 9 | 10 | files = $(patsubst %.$1,%.test,$(notdir $(wildcard $(SRC)/*.$1))) 11 | TESTS = $(call files,c) $(call files,S) 12 | 13 | all test : $(sort $(TESTS)) 14 | 15 | DIFF_OPTS = -Nu -b -B -I "^\#" 16 | 17 | # Filter source directory in warnings/errors (out-of-tree builds) 18 | FILTER = 2>&1 | sed 's,$(SRC)/,,g' 19 | 20 | %.test: %.c %.expect 21 | @echo PPTest $* ... 22 | -@$(TCC) -E -P $< $(FILTER) >$*.output 2>&1 ; \ 23 | diff $(DIFF_OPTS) $(SRC)/$*.expect $*.output \ 24 | && rm -f $*.output 25 | 26 | %.test: %.S %.expect 27 | @echo PPTest $* ... 28 | -@$(TCC) -E -P $< $(FILTER) >$*.output 2>&1 ; \ 29 | diff $(DIFF_OPTS) $(SRC)/$*.expect $*.output \ 30 | && rm -f $*.output 31 | 32 | # automatically generate .expect files with gcc: 33 | %.expect: # %.c 34 | gcc -E -P $*.[cS] >$*.expect 2>&1 35 | 36 | # tell make not to delete 37 | .PRECIOUS: %.expect 38 | 39 | clean: 40 | rm -f *.output 41 | 42 | 02.test : DIFF_OPTS += -w 43 | 15.test : DIFF_OPTS += -I"^XXX:" 44 | 45 | # diff options: 46 | # -b ighore space changes 47 | # -w ighore all whitespace 48 | # -B ignore blank lines 49 | # -I ignore lines matching RE 50 | -------------------------------------------------------------------------------- /tests/pp/pp-counter.c: -------------------------------------------------------------------------------- 1 | X1 __COUNTER__ 2 | X2 __COUNTER__ 3 | #if __COUNTER__ 4 | X3 __COUNTER__ 5 | #endif 6 | #define pass(x) x 7 | #define a x __COUNTER__ y 8 | #define a2 pass(__COUNTER__) 9 | #define f(c) c __COUNTER__ 10 | #define apply(d) d d __COUNTER__ x2 f(d) y2 __COUNTER__ 11 | #define _paste(a,b) a ## b 12 | #define paste(a,b) _paste(a,b) 13 | #define _paste3(a,b,c) a ## b ## c 14 | #define doublepaste(a,b) _paste3(a,b,b) 15 | #define str(x) #x 16 | X4 a 17 | X5 f(a) 18 | X6 f(b) 19 | X7 f(__COUNTER__) 20 | X8 apply(a) 21 | X9 apply(f(a)) 22 | X10 apply(__COUNTER__) 23 | X11 apply(a2) 24 | X12 str(__COUNTER__) 25 | X13 paste(x,__COUNTER__) 26 | X14 _paste(x,__COUNTER__) 27 | X15 doublepaste(x,__COUNTER__) 28 | -------------------------------------------------------------------------------- /tests/pp/pp-counter.expect: -------------------------------------------------------------------------------- 1 | X1 0 2 | X2 1 3 | X3 3 4 | X4 x 4 y 5 | X5 x 5 y 6 6 | X6 b 7 7 | X7 8 9 8 | X8 x 10 y x 10 y 11 x2 x 10 y 12 y2 13 9 | X9 x 14 y 15 x 14 y 15 16 x2 x 14 y 15 17 y2 18 10 | X10 19 19 20 x2 19 21 y2 22 11 | X11 23 23 24 x2 23 25 y2 26 12 | X12 "__COUNTER__" 13 | X13 x27 14 | X14 x__COUNTER__ 15 | X15 x2828 16 | -------------------------------------------------------------------------------- /tests/tcctest.h: -------------------------------------------------------------------------------- 1 | static inline const char *get_basefile_from_header(void) 2 | { 3 | return __BASE_FILE__; 4 | } 5 | 6 | static inline const char *get_file_from_header(void) 7 | { 8 | return __FILE__; 9 | } 10 | -------------------------------------------------------------------------------- /tests/tests2/00_assignment.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a; 6 | a = 42; 7 | printf("%d\n", a); 8 | 9 | int b = 64; 10 | printf("%d\n", b); 11 | 12 | int c = 12, d = 34; 13 | printf("%d, %d\n", c, d); 14 | 15 | return 0; 16 | } 17 | 18 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 19 | -------------------------------------------------------------------------------- /tests/tests2/00_assignment.expect: -------------------------------------------------------------------------------- 1 | 42 2 | 64 3 | 12, 34 4 | -------------------------------------------------------------------------------- /tests/tests2/01_comment.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | printf("Hello\n"); 6 | printf("Hello\n"); /* this is a comment */ printf("Hello\n"); 7 | printf("Hello\n"); 8 | // this is also a comment sayhello(); 9 | printf("Hello\n"); 10 | 11 | return 0; 12 | } 13 | 14 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 15 | -------------------------------------------------------------------------------- /tests/tests2/01_comment.expect: -------------------------------------------------------------------------------- 1 | Hello 2 | Hello 3 | Hello 4 | Hello 5 | Hello 6 | -------------------------------------------------------------------------------- /tests/tests2/02_printf.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | printf("Hello world\n"); 6 | 7 | int Count; 8 | for (Count = -5; Count <= 5; Count++) 9 | printf("Count = %d\n", Count); 10 | 11 | printf("String 'hello', 'there' is '%s', '%s'\n", "hello", "there"); 12 | printf("Character 'A' is '%c'\n", 65); 13 | printf("Character 'a' is '%c'\n", 'a'); 14 | 15 | return 0; 16 | } 17 | 18 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 19 | -------------------------------------------------------------------------------- /tests/tests2/02_printf.expect: -------------------------------------------------------------------------------- 1 | Hello world 2 | Count = -5 3 | Count = -4 4 | Count = -3 5 | Count = -2 6 | Count = -1 7 | Count = 0 8 | Count = 1 9 | Count = 2 10 | Count = 3 11 | Count = 4 12 | Count = 5 13 | String 'hello', 'there' is 'hello', 'there' 14 | Character 'A' is 'A' 15 | Character 'a' is 'a' 16 | -------------------------------------------------------------------------------- /tests/tests2/03_struct.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct fred 4 | { 5 | int boris; 6 | int natasha; 7 | }; 8 | 9 | int main() 10 | { 11 | struct fred bloggs; 12 | 13 | bloggs.boris = 12; 14 | bloggs.natasha = 34; 15 | 16 | printf("%d\n", bloggs.boris); 17 | printf("%d\n", bloggs.natasha); 18 | 19 | struct fred jones[2]; 20 | jones[0].boris = 12; 21 | jones[0].natasha = 34; 22 | jones[1].boris = 56; 23 | jones[1].natasha = 78; 24 | 25 | printf("%d\n", jones[0].boris); 26 | printf("%d\n", jones[0].natasha); 27 | printf("%d\n", jones[1].boris); 28 | printf("%d\n", jones[1].natasha); 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /tests/tests2/03_struct.expect: -------------------------------------------------------------------------------- 1 | 12 2 | 34 3 | 12 4 | 34 5 | 56 6 | 78 7 | -------------------------------------------------------------------------------- /tests/tests2/04_for.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int Count; 6 | 7 | for (Count = 1; Count <= 10; Count++) 8 | { 9 | printf("%d\n", Count); 10 | } 11 | 12 | return 0; 13 | } 14 | 15 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 16 | -------------------------------------------------------------------------------- /tests/tests2/04_for.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 4 5 | 5 6 | 6 7 | 7 8 | 8 9 | 9 10 | 10 11 | -------------------------------------------------------------------------------- /tests/tests2/05_array.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int Count; 6 | int Array[10]; 7 | 8 | for (Count = 1; Count <= 10; Count++) 9 | { 10 | Array[Count-1] = Count * Count; 11 | } 12 | 13 | for (Count = 0; Count < 10; Count++) 14 | { 15 | printf("%d\n", Array[Count]); 16 | } 17 | 18 | return 0; 19 | } 20 | 21 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 22 | -------------------------------------------------------------------------------- /tests/tests2/05_array.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 4 3 | 9 4 | 16 5 | 25 6 | 36 7 | 49 8 | 64 9 | 81 10 | 100 11 | -------------------------------------------------------------------------------- /tests/tests2/06_case.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 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 | 29 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 30 | -------------------------------------------------------------------------------- /tests/tests2/06_case.expect: -------------------------------------------------------------------------------- 1 | 0 2 | 0 3 | 1 4 | 1 5 | 2 6 | 2 7 | 3 8 | 0 9 | -------------------------------------------------------------------------------- /tests/tests2/07_function.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int myfunc(int x) 4 | { 5 | return x * x; 6 | } 7 | 8 | void vfunc(int a) 9 | { 10 | printf("a=%d\n", a); 11 | } 12 | 13 | void qfunc() 14 | { 15 | printf("qfunc()\n"); 16 | } 17 | 18 | int main() 19 | { 20 | printf("%d\n", myfunc(3)); 21 | printf("%d\n", myfunc(4)); 22 | 23 | vfunc(1234); 24 | 25 | qfunc(); 26 | 27 | return 0; 28 | } 29 | 30 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 31 | -------------------------------------------------------------------------------- /tests/tests2/07_function.expect: -------------------------------------------------------------------------------- 1 | 9 2 | 16 3 | a=1234 4 | qfunc() 5 | -------------------------------------------------------------------------------- /tests/tests2/08_while.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a; 6 | int p; 7 | int t; 8 | 9 | a = 1; 10 | p = 0; 11 | t = 0; 12 | 13 | while (a < 100) 14 | { 15 | printf("%d\n", a); 16 | t = a; 17 | a = t + p; 18 | p = t; 19 | } 20 | 21 | return 0; 22 | } 23 | 24 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 25 | -------------------------------------------------------------------------------- /tests/tests2/08_while.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 1 3 | 2 4 | 3 5 | 5 6 | 8 7 | 13 8 | 21 9 | 34 10 | 55 11 | 89 12 | -------------------------------------------------------------------------------- /tests/tests2/09_do_while.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a; 6 | int p; 7 | int t; 8 | 9 | a = 1; 10 | p = 0; 11 | t = 0; 12 | 13 | do 14 | { 15 | printf("%d\n", a); 16 | t = a; 17 | a = t + p; 18 | p = t; 19 | } while (a < 100); 20 | 21 | return 0; 22 | } 23 | 24 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 25 | -------------------------------------------------------------------------------- /tests/tests2/09_do_while.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 1 3 | 2 4 | 3 5 | 5 6 | 8 7 | 13 8 | 21 9 | 34 10 | 55 11 | 89 12 | -------------------------------------------------------------------------------- /tests/tests2/10_pointer.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct ziggy 4 | { 5 | int a; 6 | int b; 7 | int c; 8 | } bolshevic; 9 | 10 | int main() 11 | { 12 | int a; 13 | int *b; 14 | int c; 15 | 16 | a = 42; 17 | b = &a; 18 | printf("a = %d\n", *b); 19 | 20 | bolshevic.a = 12; 21 | bolshevic.b = 34; 22 | bolshevic.c = 56; 23 | 24 | printf("bolshevic.a = %d\n", bolshevic.a); 25 | printf("bolshevic.b = %d\n", bolshevic.b); 26 | printf("bolshevic.c = %d\n", bolshevic.c); 27 | 28 | struct ziggy *tsar = &bolshevic; 29 | 30 | printf("tsar->a = %d\n", tsar->a); 31 | printf("tsar->b = %d\n", tsar->b); 32 | printf("tsar->c = %d\n", tsar->c); 33 | 34 | b = &(bolshevic.b); 35 | printf("bolshevic.b = %d\n", *b); 36 | 37 | return 0; 38 | } 39 | 40 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 41 | -------------------------------------------------------------------------------- /tests/tests2/10_pointer.expect: -------------------------------------------------------------------------------- 1 | a = 42 2 | bolshevic.a = 12 3 | bolshevic.b = 34 4 | bolshevic.c = 56 5 | tsar->a = 12 6 | tsar->b = 34 7 | tsar->c = 56 8 | bolshevic.b = 34 9 | -------------------------------------------------------------------------------- /tests/tests2/11_precedence.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 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 | 40 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 41 | -------------------------------------------------------------------------------- /tests/tests2/11_precedence.expect: -------------------------------------------------------------------------------- 1 | 134 2 | 134 3 | 0 4 | 1 5 | 1 6 | 1 7 | 1 8 | 46 9 | 1, 0 10 | 0, 1 11 | 1 12 | 1916 13 | 1916 14 | 64 15 | 4 16 | -------------------------------------------------------------------------------- /tests/tests2/12_hashdefine.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define FRED 12 4 | #define BLOGGS(x) (12*(x)) 5 | 6 | int main() 7 | { 8 | printf("%d\n", FRED); 9 | printf("%d, %d, %d\n", BLOGGS(1), BLOGGS(2), BLOGGS(3)); 10 | 11 | return 0; 12 | } 13 | 14 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 15 | -------------------------------------------------------------------------------- /tests/tests2/12_hashdefine.expect: -------------------------------------------------------------------------------- 1 | 12 2 | 12, 24, 36 3 | -------------------------------------------------------------------------------- /tests/tests2/13_integer_literals.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a = 24680; 6 | int b = 01234567; 7 | int c = 0x2468ac; 8 | int d = 0x2468AC; 9 | int e = 0b010101010101; 10 | 11 | printf("%d\n", a); 12 | printf("%d\n", b); 13 | printf("%d\n", c); 14 | printf("%d\n", d); 15 | printf("%d\n", e); 16 | 17 | return 0; 18 | } 19 | 20 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 21 | -------------------------------------------------------------------------------- /tests/tests2/13_integer_literals.expect: -------------------------------------------------------------------------------- 1 | 24680 2 | 342391 3 | 2386092 4 | 2386092 5 | 1365 6 | -------------------------------------------------------------------------------- /tests/tests2/14_if.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a = 1; 6 | 7 | if (a) 8 | printf("a is true\n"); 9 | else 10 | printf("a is false\n"); 11 | 12 | int b = 0; 13 | if (b) 14 | printf("b is true\n"); 15 | else 16 | printf("b is false\n"); 17 | 18 | return 0; 19 | } 20 | 21 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 22 | -------------------------------------------------------------------------------- /tests/tests2/14_if.expect: -------------------------------------------------------------------------------- 1 | a is true 2 | b is false 3 | -------------------------------------------------------------------------------- /tests/tests2/15_recursion.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int factorial(int i) 4 | { 5 | if (i < 2) 6 | return i; 7 | else 8 | return i * factorial(i - 1); 9 | } 10 | 11 | int main() 12 | { 13 | int Count; 14 | 15 | for (Count = 1; Count <= 10; Count++) 16 | printf("%d\n", factorial(Count)); 17 | 18 | return 0; 19 | } 20 | 21 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 22 | -------------------------------------------------------------------------------- /tests/tests2/15_recursion.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 6 4 | 24 5 | 120 6 | 720 7 | 5040 8 | 40320 9 | 362880 10 | 3628800 11 | -------------------------------------------------------------------------------- /tests/tests2/16_nesting.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 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 | 21 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 22 | -------------------------------------------------------------------------------- /tests/tests2/16_nesting.expect: -------------------------------------------------------------------------------- 1 | 0 0 0 2 | 0 0 1 3 | 0 0 2 4 | 0 1 0 5 | 0 1 1 6 | 0 1 2 7 | 0 2 0 8 | 0 2 1 9 | 0 2 2 10 | 1 0 0 11 | 1 0 1 12 | 1 0 2 13 | 1 1 0 14 | 1 1 1 15 | 1 1 2 16 | 1 2 0 17 | 1 2 1 18 | 1 2 2 19 | -------------------------------------------------------------------------------- /tests/tests2/17_enum.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | enum fred 4 | { 5 | a, 6 | b, 7 | c, 8 | d, 9 | e = 54, 10 | f = 73, 11 | g, 12 | h 13 | }; 14 | 15 | /* All following uses of enum efoo should compile 16 | without warning. While forward enums aren't ISO C, 17 | it's accepted by GCC also in strict mode, and only warned 18 | about with -pedantic. This happens in the real world. */ 19 | /* Strict ISO C doesn't allow this kind of forward declaration of 20 | enums, but GCC accepts it (and gives only pedantic warning), and 21 | it occurs in the wild. */ 22 | enum efoo; 23 | struct Sforward_use { 24 | int (*fmember) (enum efoo x); 25 | }; 26 | 27 | extern enum efoo it_real_fn(void); 28 | enum efoo { 29 | ONE, 30 | TWO, 31 | }; 32 | struct S2 { 33 | enum efoo (*f2) (void); 34 | }; 35 | void should_compile(struct S2 *s) 36 | { 37 | s->f2 = it_real_fn; 38 | } 39 | 40 | enum efoo it_real_fn(void) 41 | { 42 | return TWO; 43 | } 44 | 45 | static unsigned int deref_uintptr(unsigned int *p) 46 | { 47 | return *p; 48 | } 49 | 50 | enum Epositive { 51 | epos_one, epos_two 52 | }; 53 | 54 | int main() 55 | { 56 | enum fred frod; 57 | enum Epositive epos = epos_two; 58 | 59 | printf("%d %d %d %d %d %d %d %d\n", a, b, c, d, e, f, g, h); 60 | /* printf("%d\n", frod); */ 61 | frod = 12; 62 | printf("%d\n", frod); 63 | frod = e; 64 | printf("%d\n", frod); 65 | 66 | /* Following should compile without warning. */ 67 | printf ("enum to int: %u\n", deref_uintptr(&epos)); 68 | 69 | return 0; 70 | } 71 | 72 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 73 | -------------------------------------------------------------------------------- /tests/tests2/17_enum.expect: -------------------------------------------------------------------------------- 1 | 0 1 2 3 54 73 74 75 2 | 12 3 | 54 4 | enum to int: 1 5 | -------------------------------------------------------------------------------- /tests/tests2/18_include.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | printf("including\n"); 6 | #include "18_include.h" 7 | printf("done\n"); 8 | 9 | return 0; 10 | } 11 | 12 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 13 | -------------------------------------------------------------------------------- /tests/tests2/18_include.expect: -------------------------------------------------------------------------------- 1 | including 2 | included 3 | done 4 | -------------------------------------------------------------------------------- /tests/tests2/18_include.h: -------------------------------------------------------------------------------- 1 | printf("included\n"); 2 | -------------------------------------------------------------------------------- /tests/tests2/19_pointer_arithmetic.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a; 6 | int *b; 7 | int *c; 8 | 9 | a = 42; 10 | b = &a; 11 | c = NULL; 12 | 13 | printf("%d\n", *b); 14 | 15 | if (b == NULL) 16 | printf("b is NULL\n"); 17 | else 18 | printf("b is not NULL\n"); 19 | 20 | if (c == NULL) 21 | printf("c is NULL\n"); 22 | else 23 | printf("c is not NULL\n"); 24 | 25 | return 0; 26 | } 27 | 28 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 29 | -------------------------------------------------------------------------------- /tests/tests2/19_pointer_arithmetic.expect: -------------------------------------------------------------------------------- 1 | 42 2 | b is not NULL 3 | c is NULL 4 | -------------------------------------------------------------------------------- /tests/tests2/20_pointer_comparison.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a; 6 | int b; 7 | int *d; 8 | int *e; 9 | d = &a; 10 | e = &b; 11 | a = 12; 12 | b = 34; 13 | printf("%d\n", *d); 14 | printf("%d\n", *e); 15 | printf("%d\n", d == e); 16 | printf("%d\n", d != e); 17 | d = e; 18 | printf("%d\n", d == e); 19 | printf("%d\n", d != e); 20 | 21 | return 0; 22 | } 23 | 24 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 25 | -------------------------------------------------------------------------------- /tests/tests2/20_pointer_comparison.expect: -------------------------------------------------------------------------------- 1 | 12 2 | 34 3 | 0 4 | 1 5 | 1 6 | 0 7 | -------------------------------------------------------------------------------- /tests/tests2/21_char_array.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int x = 'a'; 6 | char y = x; 7 | 8 | char *a = "hello"; 9 | 10 | printf("%s\n", a); 11 | 12 | int c; 13 | c = *a; 14 | 15 | char *b; 16 | for (b = a; *b != 0; b++) 17 | printf("%c: %d\n", *b, *b); 18 | 19 | char destarray[10]; 20 | char *dest = &destarray[0]; 21 | char *src = a; 22 | 23 | while (*src != 0) 24 | *dest++ = *src++; 25 | 26 | *dest = 0; 27 | 28 | printf("copied string is %s\n", destarray); 29 | 30 | return 0; 31 | } 32 | 33 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 34 | -------------------------------------------------------------------------------- /tests/tests2/21_char_array.expect: -------------------------------------------------------------------------------- 1 | hello 2 | h: 104 3 | e: 101 4 | l: 108 5 | l: 108 6 | o: 111 7 | copied string is hello 8 | -------------------------------------------------------------------------------- /tests/tests2/22_floating_point.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | // variables 7 | float a = 12.34 + 56.78; 8 | printf("%f\n", a); 9 | 10 | // infix operators 11 | printf("%f\n", 12.34 + 56.78); 12 | printf("%f\n", 12.34 - 56.78); 13 | printf("%f\n", 12.34 * 56.78); 14 | printf("%f\n", 12.34 / 56.78); 15 | 16 | // comparison operators 17 | printf("%d %d %d %d %d %d\n", 12.34 < 56.78, 12.34 <= 56.78, 12.34 == 56.78, 12.34 >= 56.78, 12.34 > 56.78, 12.34 != 56.78); 18 | printf("%d %d %d %d %d %d\n", 12.34 < 12.34, 12.34 <= 12.34, 12.34 == 12.34, 12.34 >= 12.34, 12.34 > 12.34, 12.34 != 12.34); 19 | printf("%d %d %d %d %d %d\n", 56.78 < 12.34, 56.78 <= 12.34, 56.78 == 12.34, 56.78 >= 12.34, 56.78 > 12.34, 56.78 != 12.34); 20 | 21 | // assignment operators 22 | a = 12.34; 23 | a += 56.78; 24 | printf("%f\n", a); 25 | 26 | a = 12.34; 27 | a -= 56.78; 28 | printf("%f\n", a); 29 | 30 | a = 12.34; 31 | a *= 56.78; 32 | printf("%f\n", a); 33 | 34 | a = 12.34; 35 | a /= 56.78; 36 | printf("%f\n", a); 37 | 38 | // prefix operators 39 | printf("%f\n", +12.34); 40 | printf("%f\n", -12.34); 41 | 42 | // type coercion 43 | a = 2; 44 | printf("%f\n", a); 45 | printf("%f\n", sin(2)); 46 | 47 | return 0; 48 | } 49 | 50 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 51 | -------------------------------------------------------------------------------- /tests/tests2/22_floating_point.expect: -------------------------------------------------------------------------------- 1 | 69.120003 2 | 69.120000 3 | -44.440000 4 | 700.665200 5 | 0.217330 6 | 1 1 0 0 0 1 7 | 0 1 1 1 0 0 8 | 0 0 0 1 1 1 9 | 69.120003 10 | -44.439999 11 | 700.665222 12 | 0.217330 13 | 12.340000 14 | -12.340000 15 | 2.000000 16 | 0.909297 17 | -------------------------------------------------------------------------------- /tests/tests2/23_type_coercion.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void charfunc(char a) 4 | { 5 | printf("char: %c\n", a); 6 | } 7 | 8 | void intfunc(int a) 9 | { 10 | printf("int: %d\n", a); 11 | } 12 | 13 | void floatfunc(float a) 14 | { 15 | printf("float: %f\n", a); 16 | } 17 | 18 | int main() 19 | { 20 | charfunc('a'); 21 | charfunc(98); 22 | charfunc(99.0); 23 | 24 | intfunc('a'); 25 | intfunc(98); 26 | intfunc(99.0); 27 | 28 | floatfunc('a'); 29 | floatfunc(98); 30 | floatfunc(99.0); 31 | 32 | /* printf("%c %d %f\n", 'a', 'b', 'c'); */ 33 | /* printf("%c %d %f\n", 97, 98, 99); */ 34 | /* printf("%c %d %f\n", 97.0, 98.0, 99.0); */ 35 | 36 | char b = 97; 37 | char c = 97.0; 38 | 39 | printf("%d %d\n", b, c); 40 | 41 | int d = 'a'; 42 | int e = 97.0; 43 | 44 | printf("%d %d\n", d, e); 45 | 46 | float f = 'a'; 47 | float g = 97; 48 | 49 | printf("%f %f\n", f, g); 50 | 51 | return 0; 52 | } 53 | 54 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 55 | -------------------------------------------------------------------------------- /tests/tests2/23_type_coercion.expect: -------------------------------------------------------------------------------- 1 | char: a 2 | char: b 3 | char: c 4 | int: 97 5 | int: 98 6 | int: 99 7 | float: 97.000000 8 | float: 98.000000 9 | float: 99.000000 10 | 97 97 11 | 97 97 12 | 97.000000 97.000000 13 | -------------------------------------------------------------------------------- /tests/tests2/24_math_library.c: -------------------------------------------------------------------------------- 1 | #define _ISOC99_SOURCE 1 2 | 3 | #include 4 | #include 5 | 6 | int main() 7 | { 8 | printf("%f\n", sin(0.12)); 9 | printf("%f\n", cos(0.12)); 10 | printf("%f\n", tan(0.12)); 11 | printf("%f\n", asin(0.12)); 12 | printf("%f\n", acos(0.12)); 13 | printf("%f\n", atan(0.12)); 14 | printf("%f\n", sinh(0.12)); 15 | printf("%f\n", cosh(0.12)); 16 | printf("%f\n", tanh(0.12)); 17 | printf("%f\n", exp(0.12)); 18 | printf("%f\n", fabs(-0.12)); 19 | printf("%f\n", log(0.12)); 20 | printf("%f\n", log10(0.12)); 21 | printf("%f\n", pow(0.12, 0.12)); 22 | printf("%f\n", sqrt(0.12)); 23 | printf("%f\n", round(12.34)); 24 | printf("%f\n", ceil(12.34)); 25 | printf("%f\n", floor(12.34)); 26 | 27 | return 0; 28 | } 29 | 30 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 31 | -------------------------------------------------------------------------------- /tests/tests2/24_math_library.expect: -------------------------------------------------------------------------------- 1 | 0.119712 2 | 0.992809 3 | 0.120579 4 | 0.120290 5 | 1.450506 6 | 0.119429 7 | 0.120288 8 | 1.007209 9 | 0.119427 10 | 1.127497 11 | 0.120000 12 | -2.120264 13 | -0.920819 14 | 0.775357 15 | 0.346410 16 | 12.000000 17 | 13.000000 18 | 12.000000 19 | -------------------------------------------------------------------------------- /tests/tests2/25_quicksort.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int array[16]; 4 | 5 | //Swap integer values by array indexes 6 | void swap(int a, int b) 7 | { 8 | int tmp = array[a]; 9 | array[a] = array[b]; 10 | array[b] = tmp; 11 | } 12 | 13 | //Partition the array into two halves and return the 14 | //index about which the array is partitioned 15 | int partition(int left, int right) 16 | { 17 | int pivotIndex = left; 18 | int pivotValue = array[pivotIndex]; 19 | int index = left; 20 | int i; 21 | 22 | swap(pivotIndex, right); 23 | for(i = left; i < right; i++) 24 | { 25 | if(array[i] < pivotValue) 26 | { 27 | swap(i, index); 28 | index += 1; 29 | } 30 | } 31 | swap(right, index); 32 | 33 | return index; 34 | } 35 | 36 | //Quicksort the array 37 | void quicksort(int left, int right) 38 | { 39 | if(left >= right) 40 | return; 41 | 42 | int index = partition(left, right); 43 | quicksort(left, index - 1); 44 | quicksort(index + 1, right); 45 | } 46 | 47 | int main() 48 | { 49 | int i; 50 | 51 | array[0] = 62; 52 | array[1] = 83; 53 | array[2] = 4; 54 | array[3] = 89; 55 | array[4] = 36; 56 | array[5] = 21; 57 | array[6] = 74; 58 | array[7] = 37; 59 | array[8] = 65; 60 | array[9] = 33; 61 | array[10] = 96; 62 | array[11] = 38; 63 | array[12] = 53; 64 | array[13] = 16; 65 | array[14] = 74; 66 | array[15] = 55; 67 | 68 | for (i = 0; i < 16; i++) 69 | printf("%d ", array[i]); 70 | 71 | printf("\n"); 72 | 73 | quicksort(0, 15); 74 | 75 | for (i = 0; i < 16; i++) 76 | printf("%d ", array[i]); 77 | 78 | printf("\n"); 79 | 80 | return 0; 81 | } 82 | 83 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 84 | -------------------------------------------------------------------------------- /tests/tests2/25_quicksort.expect: -------------------------------------------------------------------------------- 1 | 62 83 4 89 36 21 74 37 65 33 96 38 53 16 74 55 2 | 4 16 21 33 36 37 38 53 55 62 65 74 74 83 89 96 3 | -------------------------------------------------------------------------------- /tests/tests2/26_character_constants.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | printf("%d\n", '\1'); 6 | printf("%d\n", '\10'); 7 | printf("%d\n", '\100'); 8 | printf("%d\n", '\x01'); 9 | printf("%d\n", '\x0e'); 10 | printf("%d\n", '\x10'); 11 | printf("%d\n", '\x40'); 12 | printf("test \x40\n"); 13 | 14 | return 0; 15 | } 16 | 17 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 18 | -------------------------------------------------------------------------------- /tests/tests2/26_character_constants.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 8 3 | 64 4 | 1 5 | 14 6 | 16 7 | 64 8 | test @ 9 | -------------------------------------------------------------------------------- /tests/tests2/27_sizeof.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | char a; 6 | int b; 7 | double c; 8 | 9 | printf("%d\n", sizeof(a)); 10 | printf("%d\n", sizeof(b)); 11 | printf("%d\n", sizeof(c)); 12 | 13 | printf("%d\n", sizeof(!a)); 14 | 15 | return 0; 16 | } 17 | 18 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 19 | -------------------------------------------------------------------------------- /tests/tests2/27_sizeof.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 4 3 | 8 4 | 4 5 | -------------------------------------------------------------------------------- /tests/tests2/28_strings.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | char a[10]; 7 | 8 | strcpy(a, "hello"); 9 | printf("%s\n", a); 10 | 11 | strncpy(a, "gosh", 2); 12 | printf("%s\n", a); 13 | 14 | printf("%d\n", strcmp(a, "apple") > 0); 15 | printf("%d\n", strcmp(a, "goere") > 0); 16 | printf("%d\n", strcmp(a, "zebra") < 0); 17 | 18 | printf("%d\n", strlen(a)); 19 | 20 | strcat(a, "!"); 21 | printf("%s\n", a); 22 | 23 | printf("%d\n", strncmp(a, "apple", 2) > 0); 24 | printf("%d\n", strncmp(a, "goere", 2) == 0); 25 | printf("%d\n", strncmp(a, "goerg", 2) == 0); 26 | printf("%d\n", strncmp(a, "zebra", 2) < 0); 27 | 28 | printf("%s\n", strchr(a, 'o')); 29 | printf("%s\n", strrchr(a, 'l')); 30 | printf("%d\n", strrchr(a, 'x') == NULL); 31 | 32 | memset(&a[1], 'r', 4); 33 | printf("%s\n", a); 34 | 35 | memcpy(&a[2], a, 2); 36 | printf("%s\n", a); 37 | 38 | printf("%d\n", memcmp(a, "apple", 4) > 0); 39 | printf("%d\n", memcmp(a, "grgr", 4) == 0); 40 | printf("%d\n", memcmp(a, "zebra", 4) < 0); 41 | 42 | return 0; 43 | } 44 | 45 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 46 | -------------------------------------------------------------------------------- /tests/tests2/28_strings.expect: -------------------------------------------------------------------------------- 1 | hello 2 | gollo 3 | 1 4 | 1 5 | 1 6 | 5 7 | gollo! 8 | 1 9 | 1 10 | 1 11 | 1 12 | ollo! 13 | lo! 14 | 1 15 | grrrr! 16 | grgrr! 17 | 1 18 | 1 19 | 1 20 | -------------------------------------------------------------------------------- /tests/tests2/29_array_address.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | char a[10]; 7 | strcpy(a, "abcdef"); 8 | printf("%s\n", &a[1]); 9 | 10 | return 0; 11 | } 12 | 13 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 14 | -------------------------------------------------------------------------------- /tests/tests2/29_array_address.expect: -------------------------------------------------------------------------------- 1 | bcdef 2 | -------------------------------------------------------------------------------- /tests/tests2/30_hanoi.expect: -------------------------------------------------------------------------------- 1 | Solution of Tower of Hanoi Problem with 4 Disks 2 | 3 | Starting state: 4 | A: 1 2 3 4 5 | B: 0 0 0 0 6 | C: 0 0 0 0 7 | ------------------------------------------ 8 | 9 | 10 | Subsequent states: 11 | 12 | A: 0 2 3 4 13 | B: 0 0 0 0 14 | C: 0 0 0 1 15 | ------------------------------------------ 16 | A: 0 0 3 4 17 | B: 0 0 0 2 18 | C: 0 0 0 1 19 | ------------------------------------------ 20 | A: 0 0 3 4 21 | B: 0 0 1 2 22 | C: 0 0 0 0 23 | ------------------------------------------ 24 | A: 0 0 0 4 25 | B: 0 0 1 2 26 | C: 0 0 0 3 27 | ------------------------------------------ 28 | A: 0 0 1 4 29 | B: 0 0 0 2 30 | C: 0 0 0 3 31 | ------------------------------------------ 32 | A: 0 0 1 4 33 | B: 0 0 0 0 34 | C: 0 0 2 3 35 | ------------------------------------------ 36 | A: 0 0 0 4 37 | B: 0 0 0 0 38 | C: 0 1 2 3 39 | ------------------------------------------ 40 | A: 0 0 0 0 41 | B: 0 0 0 4 42 | C: 0 1 2 3 43 | ------------------------------------------ 44 | A: 0 0 0 0 45 | B: 0 0 1 4 46 | C: 0 0 2 3 47 | ------------------------------------------ 48 | A: 0 0 0 2 49 | B: 0 0 1 4 50 | C: 0 0 0 3 51 | ------------------------------------------ 52 | A: 0 0 1 2 53 | B: 0 0 0 4 54 | C: 0 0 0 3 55 | ------------------------------------------ 56 | A: 0 0 1 2 57 | B: 0 0 3 4 58 | C: 0 0 0 0 59 | ------------------------------------------ 60 | A: 0 0 0 2 61 | B: 0 0 3 4 62 | C: 0 0 0 1 63 | ------------------------------------------ 64 | A: 0 0 0 0 65 | B: 0 2 3 4 66 | C: 0 0 0 1 67 | ------------------------------------------ 68 | A: 0 0 0 0 69 | B: 1 2 3 4 70 | C: 0 0 0 0 71 | ------------------------------------------ 72 | -------------------------------------------------------------------------------- /tests/tests2/31_args.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char **argv) 4 | { 5 | int Count; 6 | 7 | printf("hello world %d\n", argc); 8 | for (Count = 1; Count < argc; Count++) 9 | printf("arg %d: %s\n", Count, argv[Count]); 10 | 11 | return 0; 12 | } 13 | 14 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 15 | -------------------------------------------------------------------------------- /tests/tests2/31_args.expect: -------------------------------------------------------------------------------- 1 | hello world 6 2 | arg 1: arg1 3 | arg 2: arg2 4 | arg 3: arg3 5 | arg 4: arg4 6 | arg 5: arg5 7 | -------------------------------------------------------------------------------- /tests/tests2/32_led.expect: -------------------------------------------------------------------------------- 1 | _ _ _ _ 2 | | _| _| |_| |_ |_ | 3 | | |_ _| | _| |_| | 4 | 5 | -------------------------------------------------------------------------------- /tests/tests2/33_ternary_op.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int Count; 6 | 7 | for (Count = 0; Count < 10; Count++) 8 | { 9 | printf("%d\n", (Count < 5) ? (Count*Count) : (Count * 3)); 10 | } 11 | 12 | return 0; 13 | } 14 | 15 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 16 | -------------------------------------------------------------------------------- /tests/tests2/33_ternary_op.expect: -------------------------------------------------------------------------------- 1 | 0 2 | 1 3 | 4 4 | 9 5 | 16 6 | 15 7 | 18 8 | 21 9 | 24 10 | 27 11 | -------------------------------------------------------------------------------- /tests/tests2/34_array_assignment.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a[4]; 6 | 7 | a[0] = 12; 8 | a[1] = 23; 9 | a[2] = 34; 10 | a[3] = 45; 11 | 12 | printf("%d %d %d %d\n", a[0], a[1], a[2], a[3]); 13 | 14 | int b[4]; 15 | 16 | b = a; 17 | 18 | printf("%d %d %d %d\n", b[0], b[1], b[2], b[3]); 19 | 20 | return 0; 21 | } 22 | 23 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 24 | -------------------------------------------------------------------------------- /tests/tests2/34_array_assignment.expect: -------------------------------------------------------------------------------- 1 | 12 23 34 45 2 | 12 23 34 45 3 | -------------------------------------------------------------------------------- /tests/tests2/35_sizeof.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | char a; 6 | short b; 7 | 8 | printf("%d %d\n", sizeof(char), sizeof(a)); 9 | printf("%d %d\n", sizeof(short), sizeof(b)); 10 | 11 | return 0; 12 | } 13 | 14 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 15 | -------------------------------------------------------------------------------- /tests/tests2/35_sizeof.expect: -------------------------------------------------------------------------------- 1 | 1 1 2 | 2 2 3 | -------------------------------------------------------------------------------- /tests/tests2/36_array_initialisers.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int Count; 6 | 7 | int Array[10] = { 12, 34, 56, 78, 90, 123, 456, 789, 8642, 9753 }; 8 | 9 | for (Count = 0; Count < 10; Count++) 10 | printf("%d: %d\n", Count, Array[Count]); 11 | 12 | int Array2[10] = { 12, 34, 56, 78, 90, 123, 456, 789, 8642, 9753, }; 13 | 14 | for (Count = 0; Count < 10; Count++) 15 | printf("%d: %d\n", Count, Array2[Count]); 16 | 17 | 18 | return 0; 19 | } 20 | 21 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 22 | -------------------------------------------------------------------------------- /tests/tests2/36_array_initialisers.expect: -------------------------------------------------------------------------------- 1 | 0: 12 2 | 1: 34 3 | 2: 56 4 | 3: 78 5 | 4: 90 6 | 5: 123 7 | 6: 456 8 | 7: 789 9 | 8: 8642 10 | 9: 9753 11 | 0: 12 12 | 1: 34 13 | 2: 56 14 | 3: 78 15 | 4: 90 16 | 5: 123 17 | 6: 456 18 | 7: 789 19 | 8: 8642 20 | 9: 9753 21 | -------------------------------------------------------------------------------- /tests/tests2/37_sprintf.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | char Buf[100]; 6 | int Count; 7 | 8 | for (Count = 1; Count <= 20; Count++) 9 | { 10 | sprintf(Buf, "->%02d<-\n", Count); 11 | printf("%s", Buf); 12 | } 13 | 14 | return 0; 15 | } 16 | 17 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 18 | -------------------------------------------------------------------------------- /tests/tests2/37_sprintf.expect: -------------------------------------------------------------------------------- 1 | ->01<- 2 | ->02<- 3 | ->03<- 4 | ->04<- 5 | ->05<- 6 | ->06<- 7 | ->07<- 8 | ->08<- 9 | ->09<- 10 | ->10<- 11 | ->11<- 12 | ->12<- 13 | ->13<- 14 | ->14<- 15 | ->15<- 16 | ->16<- 17 | ->17<- 18 | ->18<- 19 | ->19<- 20 | ->20<- 21 | -------------------------------------------------------------------------------- /tests/tests2/38_multiple_array_index.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 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 | 32 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 33 | -------------------------------------------------------------------------------- /tests/tests2/38_multiple_array_index.expect: -------------------------------------------------------------------------------- 1 | x=0: 1 2 3 4 2 | x=1: 5 6 7 8 3 | x=2: 9 10 11 12 4 | x=3: 13 14 15 16 5 | -------------------------------------------------------------------------------- /tests/tests2/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() 16 | { 17 | MyInt a = 1; 18 | printf("%d\n", a); 19 | 20 | MyFunStruct b; 21 | b.i = 12; 22 | b.j = 34; 23 | printf("%d,%d\n", b.i, b.j); 24 | 25 | MoreFunThanEver c = &b; 26 | printf("%d,%d\n", c->i, c->j); 27 | 28 | return 0; 29 | } 30 | 31 | /* "If the specification of an array type includes any type qualifiers, 32 | the element type is so-qualified, not the array type." */ 33 | 34 | typedef int A[3]; 35 | extern A const ca; 36 | extern const A ca; 37 | extern const int ca[3]; 38 | 39 | typedef A B[1][2]; 40 | extern B const cb; 41 | extern const B cb; 42 | extern const int cb[1][2][3]; 43 | 44 | extern B b; 45 | extern int b[1][2][3]; 46 | 47 | /* Funny but valid function declaration. */ 48 | typedef int functype (int); 49 | extern functype func; 50 | int func(int i) 51 | { 52 | return i + 1; 53 | } 54 | 55 | /* Even funnier function decl and definition using typeof. */ 56 | int set_anon_super(void); 57 | int set_anon_super(void) 58 | { 59 | return 42; 60 | } 61 | typedef int sas_type (void); 62 | extern typeof(set_anon_super) set_anon_super; 63 | extern sas_type set_anon_super; 64 | 65 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 66 | -------------------------------------------------------------------------------- /tests/tests2/39_typedef.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 12,34 3 | 12,34 4 | -------------------------------------------------------------------------------- /tests/tests2/40_stdio.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | FILE *f = fopen("fred.txt", "w"); 6 | fwrite("hello\nhello\n", 1, 12, f); 7 | fclose(f); 8 | 9 | char freddy[7]; 10 | f = fopen("fred.txt", "r"); 11 | if (fread(freddy, 1, 6, f) != 6) 12 | printf("couldn't read fred.txt\n"); 13 | 14 | freddy[6] = '\0'; 15 | fclose(f); 16 | 17 | printf("%s", freddy); 18 | 19 | int InChar; 20 | char ShowChar; 21 | f = fopen("fred.txt", "r"); 22 | while ( (InChar = fgetc(f)) != EOF) 23 | { 24 | ShowChar = InChar; 25 | if (ShowChar < ' ') 26 | ShowChar = '.'; 27 | 28 | printf("ch: %d '%c'\n", InChar, ShowChar); 29 | } 30 | fclose(f); 31 | 32 | f = fopen("fred.txt", "r"); 33 | while ( (InChar = getc(f)) != EOF) 34 | { 35 | ShowChar = InChar; 36 | if (ShowChar < ' ') 37 | ShowChar = '.'; 38 | 39 | printf("ch: %d '%c'\n", InChar, ShowChar); 40 | } 41 | fclose(f); 42 | 43 | f = fopen("fred.txt", "r"); 44 | while (fgets(freddy, sizeof(freddy), f) != NULL) 45 | printf("x: %s", freddy); 46 | 47 | fclose(f); 48 | 49 | return 0; 50 | } 51 | 52 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 53 | -------------------------------------------------------------------------------- /tests/tests2/40_stdio.expect: -------------------------------------------------------------------------------- 1 | hello 2 | ch: 104 'h' 3 | ch: 101 'e' 4 | ch: 108 'l' 5 | ch: 108 'l' 6 | ch: 111 'o' 7 | ch: 10 '.' 8 | ch: 104 'h' 9 | ch: 101 'e' 10 | ch: 108 'l' 11 | ch: 108 'l' 12 | ch: 111 'o' 13 | ch: 10 '.' 14 | ch: 104 'h' 15 | ch: 101 'e' 16 | ch: 108 'l' 17 | ch: 108 'l' 18 | ch: 111 'o' 19 | ch: 10 '.' 20 | ch: 104 'h' 21 | ch: 101 'e' 22 | ch: 108 'l' 23 | ch: 108 'l' 24 | ch: 111 'o' 25 | ch: 10 '.' 26 | x: hello 27 | x: hello 28 | -------------------------------------------------------------------------------- /tests/tests2/41_hashif.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 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 | 85 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 86 | -------------------------------------------------------------------------------- /tests/tests2/41_hashif.expect: -------------------------------------------------------------------------------- 1 | #include test 2 | b 3 | g 4 | i 5 | p 6 | r 7 | -------------------------------------------------------------------------------- /tests/tests2/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 | /* To test what this is supposed to test the destination function 12 | (fprint here) must not be called directly anywhere in the test. */ 13 | int (*fprintfptr)(FILE *, const char *, ...) = &fprintf; 14 | 15 | int main() 16 | { 17 | fprintfptr(stdout, "%d\n", (*f)(24)); 18 | 19 | return 0; 20 | } 21 | 22 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 23 | -------------------------------------------------------------------------------- /tests/tests2/42_function_pointer.expect: -------------------------------------------------------------------------------- 1 | yo 24 2 | 42 3 | -------------------------------------------------------------------------------- /tests/tests2/43_void_param.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void fred(void) 4 | { 5 | printf("yo\n"); 6 | } 7 | 8 | int main() 9 | { 10 | fred(); 11 | 12 | return 0; 13 | } 14 | 15 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 16 | -------------------------------------------------------------------------------- /tests/tests2/43_void_param.expect: -------------------------------------------------------------------------------- 1 | yo 2 | -------------------------------------------------------------------------------- /tests/tests2/44_scoped_declarations.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a; 6 | 7 | for (a = 0; a < 2; a++) 8 | { 9 | int b = a; 10 | } 11 | 12 | printf("it's all good\n"); 13 | 14 | return 0; 15 | } 16 | 17 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 18 | -------------------------------------------------------------------------------- /tests/tests2/44_scoped_declarations.expect: -------------------------------------------------------------------------------- 1 | it's all good 2 | -------------------------------------------------------------------------------- /tests/tests2/45_empty_for.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int Count = 0; 6 | 7 | for (;;) 8 | { 9 | Count++; 10 | printf("%d\n", Count); 11 | if (Count >= 10) 12 | break; 13 | } 14 | 15 | return 0; 16 | } 17 | 18 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 19 | -------------------------------------------------------------------------------- /tests/tests2/45_empty_for.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 4 5 | 5 6 | 6 7 | 7 8 | 8 9 | 9 10 | 10 11 | -------------------------------------------------------------------------------- /tests/tests2/46_grep.expect: -------------------------------------------------------------------------------- 1 | File 46_grep.c: 2 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 3 | 4 | -------------------------------------------------------------------------------- /tests/tests2/47_switch_return.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void fred(int x) 4 | { 5 | switch (x) 6 | { 7 | case 1: printf("1\n"); return; 8 | case 2: printf("2\n"); break; 9 | case 3: printf("3\n"); return; 10 | } 11 | 12 | printf("out\n"); 13 | } 14 | 15 | int main() 16 | { 17 | fred(1); 18 | fred(2); 19 | fred(3); 20 | 21 | return 0; 22 | } 23 | 24 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 25 | -------------------------------------------------------------------------------- /tests/tests2/47_switch_return.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | out 4 | 3 5 | -------------------------------------------------------------------------------- /tests/tests2/48_nested_break.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a; 6 | char b; 7 | 8 | a = 0; 9 | while (a < 2) 10 | { 11 | printf("%d", a++); 12 | break; 13 | 14 | b = 'A'; 15 | while (b < 'C') 16 | { 17 | printf("%c", b++); 18 | } 19 | printf("e"); 20 | } 21 | printf("\n"); 22 | 23 | return 0; 24 | } 25 | 26 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 27 | -------------------------------------------------------------------------------- /tests/tests2/48_nested_break.expect: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /tests/tests2/49_bracket_evaluation.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct point 4 | { 5 | double x; 6 | double y; 7 | }; 8 | 9 | struct point point_array[100]; 10 | 11 | int main() 12 | { 13 | int my_point = 10; 14 | 15 | point_array[my_point].x = 12.34; 16 | point_array[my_point].y = 56.78; 17 | 18 | printf("%f, %f\n", point_array[my_point].x, point_array[my_point].y); 19 | 20 | return 0; 21 | } 22 | 23 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 24 | -------------------------------------------------------------------------------- /tests/tests2/49_bracket_evaluation.expect: -------------------------------------------------------------------------------- 1 | 12.340000, 56.780000 2 | -------------------------------------------------------------------------------- /tests/tests2/50_logical_second_arg.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int fred() 4 | { 5 | printf("fred\n"); 6 | return 0; 7 | } 8 | 9 | int joe() 10 | { 11 | printf("joe\n"); 12 | return 1; 13 | } 14 | 15 | int main() 16 | { 17 | printf("%d\n", fred() && joe()); 18 | printf("%d\n", fred() || joe()); 19 | printf("%d\n", joe() && fred()); 20 | printf("%d\n", joe() || fred()); 21 | printf("%d\n", fred() && (1 + joe())); 22 | printf("%d\n", fred() || (0 + joe())); 23 | printf("%d\n", joe() && (0 + fred())); 24 | printf("%d\n", joe() || (1 + fred())); 25 | 26 | return 0; 27 | } 28 | 29 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 30 | -------------------------------------------------------------------------------- /tests/tests2/50_logical_second_arg.expect: -------------------------------------------------------------------------------- 1 | fred 2 | 0 3 | fred 4 | joe 5 | 1 6 | joe 7 | fred 8 | 0 9 | joe 10 | 1 11 | fred 12 | 0 13 | fred 14 | joe 15 | 1 16 | joe 17 | fred 18 | 0 19 | joe 20 | 1 21 | -------------------------------------------------------------------------------- /tests/tests2/51_static.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int fred = 1234; 4 | static int joe; 5 | 6 | void henry() 7 | { 8 | static int fred = 4567; 9 | 10 | printf("%d\n", fred); 11 | fred++; 12 | } 13 | 14 | int main() 15 | { 16 | printf("%d\n", fred); 17 | henry(); 18 | henry(); 19 | henry(); 20 | henry(); 21 | printf("%d\n", fred); 22 | fred = 8901; 23 | joe = 2345; 24 | printf("%d\n", fred); 25 | printf("%d\n", joe); 26 | 27 | return 0; 28 | } 29 | 30 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 31 | -------------------------------------------------------------------------------- /tests/tests2/51_static.expect: -------------------------------------------------------------------------------- 1 | 1234 2 | 4567 3 | 4568 4 | 4569 5 | 4570 6 | 1234 7 | 8901 8 | 2345 9 | -------------------------------------------------------------------------------- /tests/tests2/52_unnamed_enum.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | enum fred { a, b, c }; 4 | 5 | int main() 6 | { 7 | printf("a=%d\n", a); 8 | printf("b=%d\n", b); 9 | printf("c=%d\n", c); 10 | 11 | enum fred d; 12 | 13 | typedef enum { e, f, g } h; 14 | typedef enum { i, j, k } m; 15 | 16 | printf("e=%d\n", e); 17 | printf("f=%d\n", f); 18 | printf("g=%d\n", g); 19 | 20 | printf("i=%d\n", i); 21 | printf("j=%d\n", j); 22 | printf("k=%d\n", k); 23 | 24 | return 0; 25 | } 26 | 27 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 28 | -------------------------------------------------------------------------------- /tests/tests2/52_unnamed_enum.expect: -------------------------------------------------------------------------------- 1 | a=0 2 | b=1 3 | c=2 4 | e=0 5 | f=1 6 | g=2 7 | i=0 8 | j=1 9 | k=2 10 | -------------------------------------------------------------------------------- /tests/tests2/54_goto.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void fred() 4 | { 5 | printf("In fred()\n"); 6 | goto done; 7 | printf("In middle\n"); 8 | done: 9 | printf("At end\n"); 10 | } 11 | 12 | void joe() 13 | { 14 | int b = 5678; 15 | 16 | printf("In joe()\n"); 17 | 18 | { 19 | int c = 1234; 20 | printf("c = %d\n", c); 21 | goto outer; 22 | printf("uh-oh\n"); 23 | } 24 | 25 | outer: 26 | 27 | printf("done\n"); 28 | } 29 | 30 | void henry() 31 | { 32 | int a; 33 | 34 | printf("In henry()\n"); 35 | goto inner; 36 | 37 | { 38 | int b; 39 | inner: 40 | b = 1234; 41 | printf("b = %d\n", b); 42 | } 43 | 44 | printf("done\n"); 45 | } 46 | 47 | int main() 48 | { 49 | fred(); 50 | joe(); 51 | henry(); 52 | 53 | return 0; 54 | } 55 | 56 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 57 | -------------------------------------------------------------------------------- /tests/tests2/54_goto.expect: -------------------------------------------------------------------------------- 1 | In fred() 2 | At end 3 | In joe() 4 | c = 1234 5 | done 6 | In henry() 7 | b = 1234 8 | done 9 | -------------------------------------------------------------------------------- /tests/tests2/55_lshift_type.c: -------------------------------------------------------------------------------- 1 | /* $Id: lshift-type.c 53089 2012-07-06 11:18:26Z vinc17/ypig $ 2 | 3 | Tests on left-shift type, written by Vincent Lefevre . 4 | 5 | ISO C99 TC3 says: [6.5.7#3] "The integer promotions are performed on 6 | each of the operands. The type of the result is that of the promoted 7 | left operand." 8 | */ 9 | 10 | #include 11 | 12 | #define PTYPE(M) ((M) < 0 || -(M) < 0 ? -1 : 1) * (int) sizeof((M)+0) 13 | #define CHECK(X,T) check(#X, PTYPE(X), PTYPE((X) << (T) 1)) 14 | #define TEST1(X,T) do { CHECK(X,T); CHECK(X,unsigned T); } while (0) 15 | #define TEST2(X) \ 16 | do \ 17 | { \ 18 | TEST1((X),short); \ 19 | TEST1((X),int); \ 20 | TEST1((X),long); \ 21 | TEST1((X),long long); \ 22 | } \ 23 | while (0) 24 | #define TEST3(X,T) do { TEST2((T)(X)); TEST2((unsigned T)(X)); } while (0) 25 | #define TEST4(X) \ 26 | do \ 27 | { \ 28 | TEST3((X),short); \ 29 | TEST3((X),int); \ 30 | TEST3((X),long); \ 31 | TEST3((X),long long); \ 32 | } \ 33 | while (0) 34 | 35 | static int debug, nfailed = 0; 36 | 37 | static void check (const char *s, int arg1, int shift) 38 | { 39 | int failed = arg1 != shift; 40 | if (debug || failed) 41 | printf ("%s %d %d\n", s, arg1, shift); 42 | nfailed += failed; 43 | } 44 | 45 | int main (int argc, char **argv) 46 | { 47 | debug = argc > 1; 48 | TEST4(1); 49 | TEST4(-1); 50 | printf ("%d test(s) failed\n", nfailed); 51 | return nfailed != 0; 52 | } 53 | -------------------------------------------------------------------------------- /tests/tests2/55_lshift_type.expect: -------------------------------------------------------------------------------- 1 | 0 test(s) failed 2 | -------------------------------------------------------------------------------- /tests/tests2/60_errors_and_warnings.c: -------------------------------------------------------------------------------- 1 | #if defined test_56_btype_excess_1 2 | struct A {} int i; 3 | 4 | #elif defined test_57_btype_excess_2 5 | char int i; 6 | 7 | #elif defined test_58_function_redefinition 8 | int f(void) { return 0; } 9 | int f(void) { return 1; } 10 | 11 | #elif defined test_global_redefinition 12 | int xxx = 1; 13 | int xxx; 14 | int xxx = 2; 15 | 16 | #elif defined test_59_function_array 17 | int (*fct)[42](int x); 18 | 19 | #elif defined test_60_enum_redefinition 20 | enum color { RED, GREEN, BLUE }; 21 | enum color { R, G, B }; 22 | enum color c; 23 | 24 | #elif defined test_62_enumerator_redefinition 25 | enum color { RED, GREEN, BLUE }; 26 | enum rgb { RED, G, B}; 27 | enum color c = RED; 28 | 29 | #elif defined test_63_local_enumerator_redefinition 30 | enum { 31 | FOO, 32 | BAR 33 | }; 34 | 35 | int main(void) 36 | { 37 | enum { 38 | FOO = 2, 39 | BAR 40 | }; 41 | 42 | return BAR - FOO; 43 | } 44 | 45 | #elif defined test_61_undefined_enum 46 | enum rgb3 c = 42; 47 | 48 | #elif defined test_74_non_const_init 49 | int i = i++; 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /tests/tests2/60_errors_and_warnings.expect: -------------------------------------------------------------------------------- 1 | [test_56_btype_excess_1] 2 | 60_errors_and_warnings.c:2: error: too many basic types 3 | 4 | [test_57_btype_excess_2] 5 | 60_errors_and_warnings.c:5: error: too many basic types 6 | 7 | [test_58_function_redefinition] 8 | 60_errors_and_warnings.c:9: error: redefinition of 'f' 9 | 10 | [test_global_redefinition] 11 | 60_errors_and_warnings.c:14: error: redefinition of 'xxx' 12 | 13 | [test_59_function_array] 14 | 60_errors_and_warnings.c:17: error: declaration of an array of functions 15 | 16 | [test_60_enum_redefinition] 17 | 60_errors_and_warnings.c:21: error: struct/union/enum already defined 18 | 19 | [test_62_enumerator_redefinition] 20 | 60_errors_and_warnings.c:26: error: redefinition of enumerator 'RED' 21 | 22 | [test_63_local_enumerator_redefinition] 23 | 24 | [test_61_undefined_enum] 25 | 60_errors_and_warnings.c:46: error: unknown type size 26 | 27 | [test_74_non_const_init] 28 | 60_errors_and_warnings.c:49: error: initializer element is not constant 29 | -------------------------------------------------------------------------------- /tests/tests2/64_macro_nesting.c: -------------------------------------------------------------------------------- 1 | #include // printf() 2 | 3 | #define CAT2(a,b) a##b 4 | #define CAT(a,b) CAT2(a,b) 5 | #define AB(x) CAT(x,y) 6 | 7 | int main(void) 8 | { 9 | int xy = 42; 10 | printf("%d\n", CAT(A,B)(x)); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /tests/tests2/64_macro_nesting.expect: -------------------------------------------------------------------------------- 1 | 42 2 | -------------------------------------------------------------------------------- /tests/tests2/67_macro_concat.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define P(A,B) A ## B ; bob 4 | #define Q(A,B) A ## B+ 5 | 6 | int main(void) 7 | { 8 | int bob, jim = 21; 9 | bob = P(jim,) *= 2; 10 | printf("jim: %d, bob: %d\n", jim, bob); 11 | jim = 60 Q(+,)3; 12 | printf("jim: %d\n", jim); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /tests/tests2/67_macro_concat.expect: -------------------------------------------------------------------------------- 1 | jim: 21, bob: 42 2 | jim: 63 3 | -------------------------------------------------------------------------------- /tests/tests2/70_floating_point_literals.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | /* decimal floating constant */ 6 | float fa0 = .123f; 7 | float fa1 = .123E12F; 8 | float fa2 = .123e-12f; 9 | float fa3 = .123e+12f; 10 | printf("%f\n%f\n%f\n%f\n\n", fa0, fa1, fa2, fa3); 11 | 12 | float fb0 = 123.123f; 13 | float fb1 = 123.123E12F; 14 | float fb2 = 123.123e-12f; 15 | float fb3 = 123.123e+12f; 16 | printf("%f\n%f\n%f\n%f\n\n", fb0, fb1, fb2, fb3); 17 | 18 | float fc0 = 123.f; 19 | float fc1 = 123.E12F; 20 | float fc2 = 123.e-12f; 21 | float fc3 = 123.e+12f; 22 | printf("%f\n%f\n%f\n%f\n\n", fc0, fc1, fc2, fc3); 23 | 24 | float fd0 = 123E12F; 25 | float fd1 = 123e-12f; 26 | float fd2 = 123e+12f; 27 | printf("%f\n%f\n%f\n\n", fd0, fd1, fd2); 28 | printf("\n"); 29 | 30 | /* hexadecimal floating constant */ 31 | double da0 = 0X.1ACP12; 32 | double da1 = 0x.1acp-12; 33 | double da2 = 0x.1acp+12; 34 | printf("%f\n%f\n%f\n\n", da0, da1, da2); 35 | 36 | double db0 = 0X1AC.BDP12; 37 | double db1 = 0x1ac.bdp-12; 38 | double db2 = 0x1ac.dbp+12; 39 | printf("%f\n%f\n%f\n\n", db0, db1, db2); 40 | 41 | double dc0 = 0X1AC.P12; 42 | double dc1 = 0x1ac.p-12; 43 | double dc2 = 0x1ac.p+12; 44 | printf("%f\n%f\n%f\n\n", dc0, dc1, dc2); 45 | 46 | double dd0 = 0X1ACP12; 47 | double dd1 = 0x1acp-12; 48 | double dd2 = 0x1acp+12; 49 | printf("%f\n%f\n%f\n\n", dd0, dd1, dd2); 50 | printf("\n"); 51 | 52 | #ifdef __TINYC__ 53 | /* TCC extension 54 | binary floating constant */ 55 | long double la0 = 0B.110101100P12L; 56 | long double la1 = 0b.110101100p-12l; 57 | long double la2 = 0b.110101100p+12l; 58 | printf("%Lf\n%Lf\n%Lf\n\n", la0, la1, la2); 59 | 60 | long double lb0 = 0B110101100.10111101P12L; 61 | long double lb1 = 0b110101100.10111101p-12l; 62 | long double lb2 = 0b110101100.10111101p+12l; 63 | printf("%Lf\n%Lf\n%Lf\n\n", lb0, lb1, lb2); 64 | 65 | long double lc0 = 0B110101100.P12L; 66 | long double lc1 = 0b110101100.p-12l; 67 | long double lc2 = 0b110101100.p+12l; 68 | printf("%Lf\n%Lf\n%Lf\n\n", lc0, lc1, lc2); 69 | 70 | long double ld0 = 0B110101100P12L; 71 | long double ld1 = 0b110101100p-12l; 72 | long double ld2 = 0b110101100p+12l; 73 | printf("%Lf\n%Lf\n%Lf\n\n", ld0, ld1, ld2); 74 | #endif 75 | 76 | return 0; 77 | } 78 | -------------------------------------------------------------------------------- /tests/tests2/70_floating_point_literals.expect: -------------------------------------------------------------------------------- 1 | 0.123000 2 | 122999996416.000000 3 | 0.000000 4 | 122999996416.000000 5 | 6 | 123.123001 7 | 123122997002240.000000 8 | 0.000000 9 | 123122997002240.000000 10 | 11 | 123.000000 12 | 123000003231744.000000 13 | 0.000000 14 | 123000003231744.000000 15 | 16 | 123000003231744.000000 17 | 0.000000 18 | 123000003231744.000000 19 | 20 | 21 | 428.000000 22 | 0.000026 23 | 428.000000 24 | 25 | 1756112.000000 26 | 0.104672 27 | 1756592.000000 28 | 29 | 1753088.000000 30 | 0.104492 31 | 1753088.000000 32 | 33 | 1753088.000000 34 | 0.104492 35 | 1753088.000000 36 | 37 | 38 | 3424.000000 39 | 0.000204 40 | 3424.000000 41 | 42 | 1756112.000000 43 | 0.104672 44 | 1756112.000000 45 | 46 | 1753088.000000 47 | 0.104492 48 | 1753088.000000 49 | 50 | 1753088.000000 51 | 0.104492 52 | 1753088.000000 53 | 54 | -------------------------------------------------------------------------------- /tests/tests2/71_macro_empty_arg.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define T(a,b,c) a b c 4 | 5 | int main(void) 6 | { 7 | printf("%d", T(1,+,2) T(+,,) T(,2,*) T(,7,) T(,,)); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/tests2/71_macro_empty_arg.expect: -------------------------------------------------------------------------------- 1 | 17 2 | -------------------------------------------------------------------------------- /tests/tests2/72_long_long_constant.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | long long int res = 0; 6 | 7 | if (res < -2147483648LL) { 8 | printf("Error: 0 < -2147483648\n"); 9 | return 1; 10 | } 11 | else 12 | if (2147483647LL < res) { 13 | printf("Error: 2147483647 < 0\n"); 14 | return 2; 15 | } 16 | else 17 | printf("long long constant test ok.\n"); 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /tests/tests2/72_long_long_constant.expect: -------------------------------------------------------------------------------- 1 | long long constant test ok. 2 | -------------------------------------------------------------------------------- /tests/tests2/75_array_in_struct_init.expect: -------------------------------------------------------------------------------- 1 | cases[0].c[0]=73400320 2 | cases[0].c[1]=262144 3 | cases[0].c[2]=805567999 4 | cases[0].c[3]=-1 5 | cases[0].b=1 6 | cases[0].e=2 7 | cases[0].k=1 8 | 9 | cases[1].c[0]=879754751 10 | cases[1].c[1]=262144 11 | cases[1].c[2]=262144 12 | cases[1].c[3]=805567999 13 | cases[1].b=2 14 | cases[1].e=3 15 | cases[1].k=2 16 | 17 | cases[2].c[0]=879754751 18 | cases[2].c[1]=805567999 19 | cases[2].c[2]=262144 20 | cases[2].c[3]=805567999 21 | cases[2].b=1 22 | cases[2].e=3 23 | cases[2].k=2 24 | 25 | cases[3].c[0]=879754751 26 | cases[3].c[1]=805830143 27 | cases[3].c[2]=524288 28 | cases[3].c[3]=-1 29 | cases[3].b=1 30 | cases[3].e=2 31 | cases[3].k=1 32 | 33 | cases[4].c[0]=879754751 34 | cases[4].c[1]=805830143 35 | cases[4].c[2]=1048576 36 | cases[4].c[3]=805830143 37 | cases[4].b=1 38 | cases[4].e=3 39 | cases[4].k=1 40 | 41 | cases[5].c[0]=879754751 42 | cases[5].c[1]=805830143 43 | cases[5].c[2]=262144 44 | cases[5].c[3]=262144 45 | cases[5].b=1 46 | cases[5].e=3 47 | cases[5].k=1 48 | 49 | cases[6].c[0]=73400320 50 | cases[6].c[1]=807403007 51 | cases[6].c[2]=807403007 52 | cases[6].c[3]=-1 53 | cases[6].b=1 54 | cases[6].e=2 55 | cases[6].k=1 56 | 57 | cases[7].c[0]=839122431 58 | cases[7].c[1]=2097152 59 | cases[7].c[2]=807403007 60 | cases[7].c[3]=-1 61 | cases[7].b=0 62 | cases[7].e=2 63 | cases[7].k=1 64 | 65 | cases[8].c[0]=67108864 66 | cases[8].c[1]=807403007 67 | cases[8].c[2]=134217728 68 | cases[8].c[3]=-1 69 | cases[8].b=0 70 | cases[8].e=2 71 | cases[8].k=0 72 | 73 | -------------------------------------------------------------------------------- /tests/tests2/76_dollars_in_identifiers.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define $(x) x 4 | #define $fred 10 5 | #define joe$ 20 6 | #define hen$y 30 7 | 8 | #define $10(x) x*10 9 | #define _$10(x) x/10 10 | 11 | int main() 12 | { 13 | printf("fred=%d\n", $fred); 14 | printf("joe=%d\n", joe$); 15 | printf("henry=%d\n", hen$y); 16 | 17 | printf("fred2=%d\n", $($fred)); 18 | printf("joe2=%d\n", $(joe$)); 19 | printf("henry2=%d\n", $(hen$y)); 20 | 21 | printf("fred10=%d\n", $10($fred)); 22 | printf("joe_10=%d\n", _$10(joe$)); 23 | 24 | int $ = 10; 25 | int a100$ = 100; 26 | int a$$ = 1000; 27 | int a$c$b = 2121; 28 | int $100 = 10000; 29 | const char *$$$ = "money"; 30 | 31 | printf("local=%d\n", $); 32 | printf("a100$=%d\n", a100$); 33 | printf("a$$=%d\n", a$$); 34 | printf("a$c$b=%d\n", a$c$b); 35 | printf("$100=%d\n", $100); 36 | printf("$$$=%s", $$$); 37 | 38 | return 0; 39 | } 40 | 41 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 42 | -------------------------------------------------------------------------------- /tests/tests2/76_dollars_in_identifiers.expect: -------------------------------------------------------------------------------- 1 | fred=10 2 | joe=20 3 | henry=30 4 | fred2=10 5 | joe2=20 6 | henry2=30 7 | fred10=100 8 | joe_10=2 9 | local=10 10 | a100$=100 11 | a$$=1000 12 | a$c$b=2121 13 | $100=10000 14 | $$$=money 15 | -------------------------------------------------------------------------------- /tests/tests2/77_push_pop_macro.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | /* must not affect how #pragma ppop_macro works */ 6 | #define pop_macro foobar1 7 | 8 | /* must not affect how #pragma push_macro works */ 9 | #define push_macro foobar2 10 | 11 | #undef abort 12 | #define abort "111" 13 | printf("abort = %s\n", abort); 14 | 15 | #pragma push_macro("abort") 16 | #undef abort 17 | #define abort "222" 18 | printf("abort = %s\n", abort); 19 | 20 | #pragma push_macro("abort") 21 | #undef abort 22 | #define abort "333" 23 | printf("abort = %s\n", abort); 24 | 25 | #pragma pop_macro("abort") 26 | printf("abort = %s\n", abort); 27 | 28 | #pragma pop_macro("abort") 29 | printf("abort = %s\n", abort); 30 | } 31 | -------------------------------------------------------------------------------- /tests/tests2/77_push_pop_macro.expect: -------------------------------------------------------------------------------- 1 | abort = 111 2 | abort = 222 3 | abort = 333 4 | abort = 222 5 | abort = 111 6 | -------------------------------------------------------------------------------- /tests/tests2/78_vla_label.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* This test segfaults as of April 27, 2015. */ 4 | void f1(int argc) 5 | { 6 | char test[argc]; 7 | if(0) 8 | label: 9 | printf("boom!\n"); 10 | if(argc-- == 0) 11 | return; 12 | goto label; 13 | } 14 | 15 | /* This segfaulted on 2015-11-19. */ 16 | void f2(void) 17 | { 18 | goto start; 19 | { 20 | int a[1 && 1]; /* not a variable-length array */ 21 | int b[1 || 1]; /* not a variable-length array */ 22 | int c[1 ? 1 : 1]; /* not a variable-length array */ 23 | start: 24 | a[0] = 0; 25 | b[0] = 0; 26 | c[0] = 0; 27 | } 28 | } 29 | 30 | void f3(void) 31 | { 32 | printf("%d\n", 0 ? printf("x1\n") : 11); 33 | printf("%d\n", 1 ? 12 : printf("x2\n")); 34 | printf("%d\n", 0 && printf("x3\n")); 35 | printf("%d\n", 1 || printf("x4\n")); 36 | } 37 | 38 | int main() 39 | { 40 | f1(2); 41 | f2(); 42 | f3(); 43 | 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /tests/tests2/78_vla_label.expect: -------------------------------------------------------------------------------- 1 | boom! 2 | boom! 3 | 11 4 | 12 5 | 0 6 | 1 7 | -------------------------------------------------------------------------------- /tests/tests2/79_vla_continue.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int f(void) 4 | { 5 | return 5; 6 | } 7 | 8 | void test1() 9 | { 10 | int count = 10; 11 | void *addr[10]; 12 | for(;count--;) { 13 | int a[f()]; 14 | 15 | addr[count] = a; 16 | 17 | continue; 18 | } 19 | 20 | if(addr[9] == addr[0]) { 21 | printf("OK\n"); 22 | } else { 23 | printf("NOT OK\n"); 24 | } 25 | } 26 | 27 | void test2() 28 | { 29 | int count = 10; 30 | void *addr[count]; 31 | for(;count--;) { 32 | int a[f()]; 33 | 34 | addr[count] = a; 35 | 36 | continue; 37 | } 38 | 39 | if(addr[9] == addr[0]) { 40 | printf("OK\n"); 41 | } else { 42 | printf("NOT OK\n"); 43 | } 44 | } 45 | 46 | void test3() 47 | { 48 | int count = 10; 49 | void *addr[count]; 50 | while(count--) { 51 | int a[f()]; 52 | 53 | addr[count] = a; 54 | 55 | continue; 56 | } 57 | 58 | if(addr[9] == addr[0]) { 59 | printf("OK\n"); 60 | } else { 61 | printf("NOT OK\n"); 62 | } 63 | } 64 | 65 | void test4() 66 | { 67 | int count = 10; 68 | void *addr[count]; 69 | do { 70 | int a[f()]; 71 | 72 | addr[--count] = a; 73 | 74 | continue; 75 | } while (count); 76 | 77 | if(addr[9] == addr[0]) { 78 | printf("OK\n"); 79 | } else { 80 | printf("NOT OK\n"); 81 | } 82 | } 83 | 84 | void test5() 85 | { 86 | int count = 10; 87 | int a[f()]; 88 | int c[f()]; 89 | 90 | c[0] = 42; 91 | 92 | for(;count--;) { 93 | int b[f()]; 94 | int i; 95 | for (i=0; i 2 | struct wchar { 3 | char *data; char mem[]; 4 | }; 5 | struct wint { 6 | char *data; int mem[]; 7 | }; 8 | int f1char (void) { 9 | char s[9]="nonono"; 10 | struct wchar q = {"bugs"}; 11 | return !s[0]; 12 | } 13 | int f1int (void) { 14 | char s[9]="nonono"; 15 | struct wint q = {"bugs"}; 16 | return !s[0]; 17 | } 18 | int main (void) { 19 | char s[9]="nonono"; 20 | static struct wchar q = {"bugs", {'c'}}; 21 | //printf ("tcc has %s %s\n", s, q.data); 22 | if (f1char() || f1int()) 23 | printf ("bla\n"); 24 | return !s[0]; 25 | } 26 | -------------------------------------------------------------------------------- /tests/tests2/80_flexarray.expect: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andreiw/tinycc/e6ac7b766aa12a0f8b6e63d621f65a5267d88114/tests/tests2/80_flexarray.expect -------------------------------------------------------------------------------- /tests/tests2/81_types.c: -------------------------------------------------------------------------------- 1 | /* The following are all valid decls, even though some subtypes 2 | are incomplete. */ 3 | enum E *e; 4 | const enum E *e1; 5 | enum E const *e2; 6 | struct S *s; 7 | const struct S *s1; 8 | struct S const *s2; 9 | 10 | /* Various strangely looking declarators, which are all valid 11 | and have to map to the same numbered typedefs. */ 12 | typedef int (*fptr1)(); 13 | int f1 (int (), int); 14 | typedef int (*fptr2)(int x); 15 | int f2 (int (int x), int); 16 | typedef int (*fptr3)(int); 17 | int f3 (int (int), int); 18 | typedef int (*fptr4[4])(int); 19 | int f4 (int (*[4])(int), int); 20 | typedef int (*fptr5)(fptr1); 21 | int f5 (int (int()), fptr1); 22 | int f1 (fptr1 fp, int i) 23 | { 24 | return (*fp)(i); 25 | } 26 | int f2 (fptr2 fp, int i) 27 | { 28 | return (*fp)(i); 29 | } 30 | int f3 (fptr3 fp, int i) 31 | { 32 | return (*fp)(i); 33 | } 34 | int f4 (fptr4 fp, int i) 35 | { 36 | return (*fp[i])(i); 37 | } 38 | int f5 (fptr5 fp, fptr1 i) 39 | { 40 | return fp(i); 41 | } 42 | int f8 (int ([4]), int); 43 | int main () { return 0; } 44 | -------------------------------------------------------------------------------- /tests/tests2/81_types.expect: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andreiw/tinycc/e6ac7b766aa12a0f8b6e63d621f65a5267d88114/tests/tests2/81_types.expect -------------------------------------------------------------------------------- /tests/tests2/82_attribs_position.c: -------------------------------------------------------------------------------- 1 | typedef unsigned short uint16_t; 2 | typedef unsigned char uint8_t; 3 | 4 | typedef union Unaligned16a { 5 | uint16_t u; 6 | uint8_t b[2]; 7 | } __attribute__((packed)) Unaligned16a; 8 | 9 | typedef union __attribute__((packed)) Unaligned16b { 10 | uint16_t u; 11 | uint8_t b[2]; 12 | } Unaligned16b; 13 | 14 | extern void foo (void) __attribute__((stdcall)); 15 | void __attribute__((stdcall)) foo (void) 16 | { 17 | } 18 | 19 | int main () { return 0; } 20 | -------------------------------------------------------------------------------- /tests/tests2/82_attribs_position.expect: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andreiw/tinycc/e6ac7b766aa12a0f8b6e63d621f65a5267d88114/tests/tests2/82_attribs_position.expect -------------------------------------------------------------------------------- /tests/tests2/83_utf8_in_identifiers.c: -------------------------------------------------------------------------------- 1 | #include 2 | double привет=0.1; 3 | int Lefèvre=2; 4 | int main(){ 5 | printf("привет=%g\n",привет); 6 | printf("Lefèvre=%d\n",Lefèvre); 7 | return 0; 8 | } 9 | // pcc & tcc only 10 | -------------------------------------------------------------------------------- /tests/tests2/83_utf8_in_identifiers.expect: -------------------------------------------------------------------------------- 1 | привет=0.1 2 | Lefèvre=2 3 | -------------------------------------------------------------------------------- /tests/tests2/84_hex-float.c: -------------------------------------------------------------------------------- 1 | extern int printf(const char *format, ...); 2 | 3 | #define ACPI_TYPE_INVALID 0x1E 4 | #define NUM_NS_TYPES ACPI_TYPE_INVALID+1 5 | int array[NUM_NS_TYPES]; 6 | 7 | #define n 0xe 8 | int main() 9 | { 10 | printf("n+1 = %d\n", n+1); 11 | // printf("n+1 = %d\n", 0xe+1); 12 | } 13 | -------------------------------------------------------------------------------- /tests/tests2/84_hex-float.expect: -------------------------------------------------------------------------------- 1 | n+1 = 15 2 | -------------------------------------------------------------------------------- /tests/tests2/85_asm-outside-function.c: -------------------------------------------------------------------------------- 1 | extern int printf (const char *, ...); 2 | extern void vide(void); 3 | __asm__("vide: ret"); 4 | 5 | int main() { 6 | vide(); 7 | printf ("okay\n"); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/tests2/85_asm-outside-function.expect: -------------------------------------------------------------------------------- 1 | okay 2 | -------------------------------------------------------------------------------- /tests/tests2/86_memory-model.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int 4 | main() 5 | { 6 | #if defined(__LLP64__) 7 | if (sizeof(short) == 2 8 | && sizeof(int) == 4 9 | && sizeof(long int) == 4 10 | && sizeof(long long int) == 8 11 | && sizeof(void*) == 8) { 12 | (void)printf("Ok\n"); 13 | } else { 14 | (void)printf("KO __LLP64__\n"); 15 | } 16 | #elif defined(__LP64__) 17 | if (sizeof(short) == 2 18 | && sizeof(int) == 4 19 | && sizeof(long int) == 8 20 | && sizeof(long long int) == 8 21 | && sizeof(void*) == 8) { 22 | (void)printf("Ok\n"); 23 | } else { 24 | (void)printf("KO __LP64__\n"); 25 | } 26 | #elif defined(__ILP32__) 27 | if (sizeof(short) == 2 28 | && sizeof(int) == 4 29 | && sizeof(long int) == 4 30 | && sizeof(void*) == 4) { 31 | (void)printf("Ok\n"); 32 | } else { 33 | (void)printf("KO __ILP32__\n"); 34 | } 35 | #else 36 | (void)printf("KO no __*LP*__ defined.\n"); 37 | #endif 38 | } 39 | -------------------------------------------------------------------------------- /tests/tests2/86_memory-model.expect: -------------------------------------------------------------------------------- 1 | Ok 2 | -------------------------------------------------------------------------------- /tests/tests2/87_dead_code.expect: -------------------------------------------------------------------------------- 1 | timeout=2 2 | timeout=1 3 | boo 4 | yeah 5 | twice 6 | once 7 | twice 8 | SEtwice 9 | SEonce 10 | SEtwice 11 | twice2 12 | once2 13 | twice2 14 | twice3 15 | once3 16 | twice3 17 | caseok 18 | caseok2 19 | -------------------------------------------------------------------------------- /tests/tests2/88_codeopt.c: -------------------------------------------------------------------------------- 1 | /* Check some way in where code suppression caused various 2 | miscompilations. */ 3 | extern int printf (const char *, ...); 4 | typedef unsigned long size_t; 5 | 6 | size_t _brk_start, _brk_end; 7 | void * extend_brk(size_t size, size_t align) 8 | { 9 | size_t mask = align - 1; 10 | void *ret = 0; 11 | 12 | do { 13 | if (__builtin_expect(!!(_brk_start == 0), 0)) 14 | do { 15 | printf("wrong1\n"); 16 | } while (0); 17 | } while (0); 18 | _brk_end = (_brk_end + mask) & ~mask; 19 | ret = (void *)_brk_end; 20 | _brk_end += size; 21 | 22 | return ret; 23 | } 24 | 25 | static void get_args (int a, int b) 26 | { 27 | if (a != 1) 28 | printf("wrong2\n"); 29 | else 30 | printf("okay\n"); 31 | } 32 | 33 | void bla(void) 34 | { 35 | int __ret = 42; 36 | ({ 37 | if (__builtin_expect(!!(0), 0)) { 38 | if (__builtin_expect(!!__ret, 0)) 39 | printf("wrong3\n"); 40 | int x = !!(__ret); 41 | } 42 | __ret; 43 | }); 44 | get_args(!!__ret, sizeof(__ret)); 45 | } 46 | 47 | _Bool chk(unsigned long addr, unsigned long limit, unsigned long size) 48 | { 49 | _Bool ret; 50 | /* This just needs to compile, no runtime test. (And it doesn't compile 51 | only with certain internal checking added that's not committed). */ 52 | if (0) 53 | ret = 0 != (!!(addr > limit - size)); 54 | } 55 | 56 | int main() 57 | { 58 | void *r; 59 | _brk_start = 1024; 60 | _brk_end = 1024; 61 | r = extend_brk (4096, 16); 62 | if (!r) 63 | printf("wrong4\n"); 64 | else 65 | printf("okay\n"); 66 | bla(); 67 | return 0; 68 | } 69 | -------------------------------------------------------------------------------- /tests/tests2/88_codeopt.expect: -------------------------------------------------------------------------------- 1 | okay 2 | okay 3 | -------------------------------------------------------------------------------- /tests/tests2/89_nocode_wanted.c: -------------------------------------------------------------------------------- 1 | extern int printf(const char *format, ...); 2 | static void kb_wait_1(void) 3 | { 4 | unsigned long timeout = 2; 5 | do { 6 | (1 ? 7 | printf("timeout=%ld\n", timeout) : 8 | ({ 9 | while (1) 10 | printf("error\n"); 11 | }) 12 | ); 13 | timeout--; 14 | } while (timeout); 15 | } 16 | static void kb_wait_2(void) 17 | { 18 | unsigned long timeout = 2; 19 | do { 20 | (1 ? 21 | printf("timeout=%ld\n", timeout) : 22 | ({ 23 | for (;;) 24 | printf("error\n"); 25 | }) 26 | ); 27 | timeout--; 28 | } while (timeout); 29 | } 30 | static void kb_wait_2_1(void) 31 | { 32 | unsigned long timeout = 2; 33 | do { 34 | (1 ? 35 | printf("timeout=%ld\n", timeout) : 36 | ({ 37 | do { 38 | printf("error\n"); 39 | } while (1); 40 | }) 41 | ); 42 | timeout--; 43 | } while (timeout); 44 | } 45 | static void kb_wait_2_2(void) 46 | { 47 | unsigned long timeout = 2; 48 | do { 49 | (1 ? 50 | printf("timeout=%ld\n", timeout) : 51 | ({ 52 | label: 53 | printf("error\n"); 54 | goto label; 55 | }) 56 | ); 57 | timeout--; 58 | } while (timeout); 59 | } 60 | static void kb_wait_3(void) 61 | { 62 | unsigned long timeout = 2; 63 | do { 64 | (1 ? 65 | printf("timeout=%ld\n", timeout) : 66 | ({ 67 | int i = 1; 68 | goto label; 69 | i = i + 2; 70 | label: 71 | i = i + 3; 72 | }) 73 | ); 74 | timeout--; 75 | } while (timeout); 76 | } 77 | static void kb_wait_4(void) 78 | { 79 | unsigned long timeout = 2; 80 | do { 81 | (1 ? 82 | printf("timeout=%ld\n", timeout) : 83 | ({ 84 | switch(timeout) { 85 | case 2: 86 | printf("timeout is 2"); 87 | break; 88 | case 1: 89 | printf("timeout is 1"); 90 | break; 91 | default: 92 | printf("timeout is 0?"); 93 | break; 94 | }; 95 | // return; 96 | }) 97 | ); 98 | timeout--; 99 | } while (timeout); 100 | } 101 | int main() 102 | { 103 | printf("begin\n"); 104 | kb_wait_1(); 105 | kb_wait_2(); 106 | kb_wait_2_1(); 107 | kb_wait_2_2(); 108 | kb_wait_3(); 109 | kb_wait_4(); 110 | printf("end\n"); 111 | return 0; 112 | } 113 | -------------------------------------------------------------------------------- /tests/tests2/89_nocode_wanted.expect: -------------------------------------------------------------------------------- 1 | begin 2 | timeout=2 3 | timeout=1 4 | timeout=2 5 | timeout=1 6 | timeout=2 7 | timeout=1 8 | timeout=2 9 | timeout=1 10 | timeout=2 11 | timeout=1 12 | timeout=2 13 | timeout=1 14 | end 15 | -------------------------------------------------------------------------------- /tests/tests2/90_struct-init.expect: -------------------------------------------------------------------------------- 1 | ce: 1 12 2 | gs: 1 2 3 4 3 | gs2: 1 2 3 4 4 | gt: 68 65 6c 6c 6f 0 0 0 0 0 0 0 0 0 0 0 2a 5 | gu: 3 5 6 7 8 4 68 75 68 75 0 0 0 0 0 0 0 0 0 0 0 0 2b 6 | gu2: 3 5 6 7 8 4 68 75 68 75 0 0 0 0 0 0 0 0 0 0 0 0 2b 7 | gu3: 3 5 6 7 8 4 68 75 68 75 0 0 0 0 0 0 0 0 0 0 0 0 2b 8 | gu4: 3 5 6 7 0 5 62 6c 61 0 0 0 0 0 0 0 0 0 0 0 0 0 2c 9 | gs3: 1 2 3 4 10 | gv: 3 4 5 6 68 61 68 61 0 0 0 0 0 0 0 0 0 0 0 0 2d 2e 11 | gv2: 7 8 9 a 68 69 68 69 0 0 0 0 0 0 0 0 0 0 0 0 2f 30 12 | gv3: 7 8 9 a 68 6f 68 6f 0 0 0 0 0 0 0 0 0 0 0 0 31 32 13 | sinit16: 1 0 0 0 2 0 0 0 14 | gw: 1 2 3 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 15 | gsu: 5 6 16 | guv: 6 5 0 0 17 | guv.b: 5 18 | guv2: 8 7 0 0 19 | guv3: 7 8 0 0 20 | phdr: 6 5 4 3 0 0 0 0 0 0 0 0 0 0 0 0 9 8 7 6 0 0 0 0 0 0 0 0 0 0 0 0 21 | ls: 1 2 3 4 22 | ls2: 1 2 3 4 23 | lt: 68 65 6c 6c 6f 0 0 0 0 0 0 0 0 0 0 0 2a 24 | lu: 3 5 6 7 8 4 68 75 68 75 0 0 0 0 0 0 0 0 0 0 0 0 2b 25 | lu1: 3 1 2 3 4 4 68 75 68 75 0 0 0 0 0 0 0 0 0 0 0 0 2b 26 | lu2: 3 1 2 3 4 4 68 75 68 75 0 0 0 0 0 0 0 0 0 0 0 0 2b 27 | ls21: 1 2 3 4 28 | lu21: 3 1 2 3 4 4 68 75 68 75 0 0 0 0 0 0 0 0 0 0 0 0 2b 29 | lu22: 3 1 2 3 4 4 68 75 68 75 0 0 0 0 0 0 0 0 0 0 0 0 2b 30 | lu3: 3 5 6 7 8 4 68 75 68 75 0 0 0 0 0 0 0 0 0 0 0 0 2b 31 | lu4: 3 5 6 7 0 5 62 6c 61 0 0 0 0 0 0 0 0 0 0 0 0 0 2c 32 | ls3: 1 2 3 4 33 | lv: 3 4 5 6 68 61 68 61 0 0 0 0 0 0 0 0 0 0 0 0 2d 2e 34 | lv2: 1 2 3 4 68 69 68 69 0 0 0 0 0 0 0 0 0 0 0 0 2f 30 35 | lv3: 7 8 9 a 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 32 36 | lt2: 0 9 9 9 43 43 43 43 42 42 42 0 0 0 0 0 1 37 | flow: 9 8 7 6 0 0 0 0 0 0 0 0 0 0 0 0 6 5 4 3 0 0 0 0 0 0 0 0 0 0 0 0 38 | one 39 | two 40 | three 41 | sea_fill0: okay 42 | sea_fill1: okay 43 | sea_fill2: okay 44 | -------------------------------------------------------------------------------- /tests/tests2/91_ptr_longlong_arith32.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | char t[] = "012345678"; 3 | 4 | int main(void) 5 | { 6 | char *data = t; 7 | unsigned long long r = 4; 8 | unsigned a = 5; 9 | unsigned long long b = 12; 10 | 11 | *(unsigned*)(data + r) += a - b; 12 | 13 | printf("data = \"%s\"\n", data); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /tests/tests2/91_ptr_longlong_arith32.expect: -------------------------------------------------------------------------------- 1 | data = "0123-5678" 2 | -------------------------------------------------------------------------------- /tests/tests2/92_enum_bitfield.c: -------------------------------------------------------------------------------- 1 | /* This checks if enums needing 8 bit but only having positive 2 | values are correctly zero extended (instead of sign extended) 3 | when stored into/loaded from a 8 bit bit-field of enum type (which 4 | itself is implementation defined, so isn't necessarily supported by all 5 | other compilers). */ 6 | enum tree_code { 7 | SOME_CODE = 148, /* has bit 7 set, and hence all further enum values as well */ 8 | LAST_AND_UNUSED_TREE_CODE 9 | }; 10 | typedef union tree_node *tree; 11 | struct tree_common 12 | { 13 | union tree_node *chain; 14 | union tree_node *type; 15 | enum tree_code code : 8; 16 | unsigned side_effects_flag : 1; 17 | }; 18 | union tree_node 19 | { 20 | struct tree_common common; 21 | }; 22 | enum c_tree_code { 23 | C_DUMMY_TREE_CODE = LAST_AND_UNUSED_TREE_CODE, 24 | STMT_EXPR, 25 | LAST_C_TREE_CODE 26 | }; 27 | enum cplus_tree_code { 28 | CP_DUMMY_TREE_CODE = LAST_C_TREE_CODE, 29 | AMBIG_CONV, 30 | LAST_CPLUS_TREE_CODE 31 | }; 32 | 33 | extern int printf(const char *, ...); 34 | int blah(){return 0;} 35 | 36 | int convert_like_real (tree convs) 37 | { 38 | switch (((enum tree_code) (convs)->common.code)) 39 | { 40 | case AMBIG_CONV: /* This has bit 7 set, which must not be the sign 41 | bit in tree_common.code, i.e. the bitfield must 42 | be somehow marked unsigned. */ 43 | return blah(); 44 | default: 45 | break; 46 | }; 47 | printf("unsigned enum bit-fields broken\n"); 48 | } 49 | 50 | int main() 51 | { 52 | union tree_node convs; 53 | 54 | convs.common.code = AMBIG_CONV; 55 | convert_like_real (&convs); 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /tests/tests2/92_enum_bitfield.expect: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andreiw/tinycc/e6ac7b766aa12a0f8b6e63d621f65a5267d88114/tests/tests2/92_enum_bitfield.expect -------------------------------------------------------------------------------- /tests/tests2/93_integer_promotion.c: -------------------------------------------------------------------------------- 1 | /* integer promotion */ 2 | 3 | int printf(const char*, ...); 4 | #define promote(s) printf(" %ssigned : %s\n", (s) - 100 < 0 ? " " : "un", #s); 5 | 6 | int main (void) 7 | { 8 | struct { 9 | unsigned ub:3; 10 | unsigned u:32; 11 | unsigned long long ullb:35; 12 | unsigned long long ull:64; 13 | unsigned char c; 14 | } s = { 1, 1, 1 }; 15 | 16 | promote(s.ub); 17 | promote(s.u); 18 | promote(s.ullb); 19 | promote(s.ull); 20 | promote(s.c); 21 | printf("\n"); 22 | 23 | promote((1 ? s.ub : 1)); 24 | promote((1 ? s.u : 1)); 25 | promote((1 ? s.ullb : 1)); 26 | promote((1 ? s.ull : 1)); 27 | promote((1 ? s.c : 1)); 28 | printf("\n"); 29 | 30 | promote(s.ub << 1); 31 | promote(s.u << 1); 32 | promote(s.ullb << 1); 33 | promote(s.ull << 1); 34 | promote(s.c << 1); 35 | printf("\n"); 36 | 37 | promote(+s.ub); 38 | promote(+s.u); 39 | promote(+s.ullb); 40 | promote(+s.ull); 41 | promote(+s.c); 42 | printf("\n"); 43 | 44 | promote(-s.ub); 45 | promote(-s.u); 46 | promote(-s.ullb); 47 | promote(-s.ull); 48 | promote(-s.c); 49 | printf("\n"); 50 | 51 | promote(~s.ub); 52 | promote(~s.u); 53 | promote(~s.ullb); 54 | promote(~s.ull); 55 | promote(~s.c); 56 | printf("\n"); 57 | 58 | promote(!s.ub); 59 | promote(!s.u); 60 | promote(!s.ullb); 61 | promote(!s.ull); 62 | promote(!s.c); 63 | printf("\n"); 64 | 65 | promote(+(unsigned)s.ub); 66 | promote(-(unsigned)s.ub); 67 | promote(~(unsigned)s.ub); 68 | promote(!(unsigned)s.ub); 69 | 70 | return 0; 71 | } 72 | -------------------------------------------------------------------------------- /tests/tests2/93_integer_promotion.expect: -------------------------------------------------------------------------------- 1 | signed : s.ub 2 | unsigned : s.u 3 | signed : s.ullb 4 | unsigned : s.ull 5 | signed : s.c 6 | 7 | signed : (1 ? s.ub : 1) 8 | unsigned : (1 ? s.u : 1) 9 | signed : (1 ? s.ullb : 1) 10 | unsigned : (1 ? s.ull : 1) 11 | signed : (1 ? s.c : 1) 12 | 13 | signed : s.ub << 1 14 | unsigned : s.u << 1 15 | signed : s.ullb << 1 16 | unsigned : s.ull << 1 17 | signed : s.c << 1 18 | 19 | signed : +s.ub 20 | unsigned : +s.u 21 | signed : +s.ullb 22 | unsigned : +s.ull 23 | signed : +s.c 24 | 25 | signed : -s.ub 26 | unsigned : -s.u 27 | signed : -s.ullb 28 | unsigned : -s.ull 29 | signed : -s.c 30 | 31 | signed : ~s.ub 32 | unsigned : ~s.u 33 | signed : ~s.ullb 34 | unsigned : ~s.ull 35 | signed : ~s.c 36 | 37 | signed : !s.ub 38 | signed : !s.u 39 | signed : !s.ullb 40 | signed : !s.ull 41 | signed : !s.c 42 | 43 | unsigned : +(unsigned)s.ub 44 | unsigned : -(unsigned)s.ub 45 | unsigned : ~(unsigned)s.ub 46 | signed : !(unsigned)s.ub 47 | -------------------------------------------------------------------------------- /tests/tests2/94_generic.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | const int a = 0; 4 | 5 | struct a { 6 | int a; 7 | }; 8 | 9 | struct b { 10 | int a; 11 | }; 12 | 13 | int a_f() 14 | { 15 | return 20; 16 | } 17 | 18 | int b_f() 19 | { 20 | return 10; 21 | } 22 | 23 | typedef int int_type1; 24 | 25 | #define gen_sw(a) _Generic(a, const char *: 1, default: 8, int: 123); 26 | 27 | int main() 28 | { 29 | int i = 0; 30 | signed long int l = 2; 31 | struct b titi; 32 | const int * const ptr; 33 | const char *ti; 34 | int_type1 i2; 35 | 36 | i = _Generic(a, int: a_f, const int: b_f)(); 37 | printf("%d\n", i); 38 | i = _Generic(a, int: a_f() / 2, const int: b_f() / 2); 39 | printf("%d\n", i); 40 | i = _Generic(ptr, int *:1, int * const:2, default:20); 41 | printf("%d\n", i); 42 | i = gen_sw(a); 43 | printf("%d\n", i); 44 | i = _Generic(titi, struct a:1, struct b:2, default:20); 45 | printf("%d\n", i); 46 | i = _Generic(i2, char: 1, int : 0); 47 | printf("%d\n", i); 48 | i = _Generic(a, char:1, int[4]:2, default:5); 49 | printf("%d\n", i); 50 | i = _Generic(17, int :1, int **:2); 51 | printf("%d\n", i); 52 | i = _Generic(17L, int :1, long :2, long long : 3); 53 | printf("%d\n", i); 54 | i = _Generic("17, io", char *: 3, const char *: 1); 55 | printf("%d\n", i); 56 | i = _Generic(ti, const unsigned char *:1, const char *:4, char *:3, 57 | const signed char *:2); 58 | printf("%d\n", i); 59 | printf("%s\n", _Generic(i + 2L, long: "long", int: "int", 60 | long long: "long long")); 61 | i = _Generic(l, long: 1, int: 2); 62 | printf("%d\n", i); 63 | return 0; 64 | } 65 | -------------------------------------------------------------------------------- /tests/tests2/94_generic.expect: -------------------------------------------------------------------------------- 1 | 20 2 | 10 3 | 20 4 | 123 5 | 2 6 | 0 7 | 5 8 | 1 9 | 2 10 | 3 11 | 4 12 | long 13 | 1 -------------------------------------------------------------------------------- /tests/tests2/95_bitfields_ms.c: -------------------------------------------------------------------------------- 1 | #define MS_BITFIELDS 1 2 | #include "95_bitfields.c" 3 | -------------------------------------------------------------------------------- /tests/tests2/96_nodata_wanted.c: -------------------------------------------------------------------------------- 1 | /*****************************************************************************/ 2 | /* test 'nodata_wanted' data output suppression */ 3 | 4 | #if defined test_static_data_error 5 | void foo() { 6 | if (1) { 7 | static short w = (int)&foo; /* initializer not computable */ 8 | } 9 | } 10 | 11 | #elif defined test_static_nodata_error 12 | void foo() { 13 | if (0) { 14 | static short w = (int)&foo; /* initializer not computable */ 15 | } 16 | } 17 | 18 | #elif defined test_global_data_error 19 | void foo(); 20 | static short w = (int)&foo; /* initializer not computable */ 21 | 22 | 23 | #elif defined test_local_data_noerror 24 | void foo() { 25 | short w = &foo; /* 2 cast warnings */ 26 | } 27 | 28 | #elif defined test_data_suppression_off || defined test_data_suppression_on 29 | 30 | #if defined test_data_suppression_on 31 | # define SKIP 1 32 | #else 33 | # define SKIP 0 34 | #endif 35 | 36 | #include 37 | /* some gcc headers #define __attribute__ to empty if it's not gcc */ 38 | #undef __attribute__ 39 | 40 | int main() 41 | { 42 | __label__ ts0, te0, ts1, te1; 43 | int tl, dl; 44 | 45 | static char ds0 = 0; 46 | static char de0 = 0; 47 | /* get reference size of empty jmp */ 48 | ts0:; 49 | if (!SKIP) {} 50 | te0:; 51 | dl = -(&de0 - &ds0); 52 | tl = -(&&te0 - &&ts0); 53 | 54 | /* test data and code suppression */ 55 | static char ds1 = 0; 56 | ts1:; 57 | if (!SKIP) { 58 | static void *p = (void*)&main; 59 | static char cc[] = "static string"; 60 | static double d = 8.0; 61 | 62 | static struct __attribute__((packed)) { 63 | unsigned x : 12; 64 | unsigned char y : 7; 65 | unsigned z : 28, a: 4, b: 5; 66 | } s = { 0x333,0x44,0x555555,6,7 }; 67 | 68 | printf("data:\n"); 69 | printf(" %d - %.1f - %.1f - %s - %s\n", 70 | sizeof 8.0, 8.0, d, __FUNCTION__, cc); 71 | printf(" %x %x %x %x %x\n", 72 | s.x, s.y, s.z, s.a, s.b); 73 | } 74 | te1:; 75 | static char de1 = 0; 76 | 77 | dl += &de1 - &ds1; 78 | tl += &&te1 - &&ts1; 79 | printf("size of data/text:\n %s/%s\n", 80 | dl ? "non-zero":"zero", tl ? "non-zero":"zero"); 81 | printf("# %d/%d\n", dl, tl); 82 | } 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /tests/tests2/96_nodata_wanted.expect: -------------------------------------------------------------------------------- 1 | [test_static_data_error] 2 | 96_nodata_wanted.c:7: error: initializer element is not computable at load time 3 | 4 | [test_static_nodata_error] 5 | 96_nodata_wanted.c:14: error: initializer element is not computable at load time 6 | 7 | [test_global_data_error] 8 | 96_nodata_wanted.c:20: error: initializer element is not computable at load time 9 | 10 | [test_local_data_noerror] 11 | 96_nodata_wanted.c:25: warning: assignment makes integer from pointer without a cast 12 | 96_nodata_wanted.c:25: warning: nonportable conversion from pointer to char/short 13 | 14 | [test_data_suppression_off] 15 | data: 16 | 8 - 8.0 - 8.0 - main - static string 17 | 333 44 555555 6 7 18 | size of data/text: 19 | non-zero/non-zero 20 | # 111/193 21 | 22 | [test_data_suppression_on] 23 | size of data/text: 24 | zero/zero 25 | # 0/0 26 | -------------------------------------------------------------------------------- /tests/tests2/LICENSE: -------------------------------------------------------------------------------- 1 | The tests in this directory are either directly copied from the picoc project or 2 | are subsequently modified and added to for the purpose of TinyCC project. All 3 | these modifications are licensed under the same terms as TinyCC as specified in 4 | the file COPYING. 5 | 6 | === picoc license === 7 | 8 | Copyright (c) 2009-2011, Zik Saleeba 9 | All rights reserved. 10 | 11 | Redistribution and use in source and binary forms, with or without 12 | modification, are permitted provided that the following conditions are 13 | met: 14 | 15 | * Redistributions of source code must retain the above copyright 16 | notice, this list of conditions and the following disclaimer. 17 | 18 | * Redistributions in binary form must reproduce the above copyright 19 | notice, this list of conditions and the following disclaimer in 20 | the documentation and/or other materials provided with the 21 | distribution. 22 | 23 | * Neither the name of the Zik Saleeba nor the names of its 24 | contributors may be used to endorse or promote products derived 25 | from this software without specific prior written permission. 26 | 27 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 30 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 31 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 32 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 33 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 34 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 35 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 36 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 37 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | -------------------------------------------------------------------------------- /tests/vla_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Test that allocating a variable length array in a loop 3 | * does not use up a linear amount of memory 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #define LOOP_COUNT 1000 11 | #define ARRAY_SIZE 100 12 | 13 | /* Overwrite a VLA. This will overwrite the return address if SP is incorrect */ 14 | void smash(char *p, int n) { 15 | memset(p, 0, n); 16 | } 17 | 18 | int test1(int n) { 19 | int i; 20 | char *array_ptrs[LOOP_COUNT]; 21 | 22 | for (i = 0; i < LOOP_COUNT; ++i) { 23 | char test[n]; 24 | smash(test, n); 25 | array_ptrs[i] = test; 26 | } 27 | 28 | return (array_ptrs[0]-array_ptrs[LOOP_COUNT-1] < n) ? 0 : 1; 29 | } 30 | 31 | /* ensure goto does not circumvent array free */ 32 | int test2(int n) { 33 | char *array_ptrs[LOOP_COUNT]; 34 | 35 | int i = 0; 36 | loop:; 37 | char test[n]; 38 | smash(test, n); 39 | if (i >= LOOP_COUNT) 40 | goto end; 41 | array_ptrs[i] = test; 42 | ++i; 43 | goto loop; 44 | 45 | end: 46 | smash(test, n); 47 | char test2[n]; 48 | smash(test2, n); 49 | return (array_ptrs[0] - array_ptrs[LOOP_COUNT-1] < n) ? 0 : 1; 50 | } 51 | 52 | int test3(int n) { 53 | char test[n]; 54 | smash(test, n); 55 | goto label; 56 | label: 57 | smash(test, n); 58 | char test2[n]; 59 | smash(test2, n); 60 | return (test-test2 >= n) ? 0 : 1; 61 | } 62 | 63 | #define RUN_TEST(t) \ 64 | if (!testname || (strcmp(#t, testname) == 0)) { \ 65 | fputs(#t "... ", stdout); \ 66 | fflush(stdout); \ 67 | if (t(ARRAY_SIZE) == 0) { \ 68 | fputs("success\n", stdout); \ 69 | } else { \ 70 | fputs("failure\n", stdout); \ 71 | retval = EXIT_FAILURE; \ 72 | } \ 73 | } 74 | 75 | int main(int argc, char **argv) { 76 | const char *testname = NULL; 77 | int retval = EXIT_SUCCESS; 78 | if (argc > 1) 79 | testname = argv[1]; 80 | RUN_TEST(test1) 81 | RUN_TEST(test2) 82 | RUN_TEST(test3) 83 | return retval; 84 | } 85 | -------------------------------------------------------------------------------- /win32/examples/dll.c: -------------------------------------------------------------------------------- 1 | //+--------------------------------------------------------------------------- 2 | // 3 | // dll.c - Windows DLL example - dynamically linked part 4 | // 5 | 6 | #include 7 | 8 | __declspec(dllexport) const char *hello_data = "(not set)"; 9 | 10 | __declspec(dllexport) void hello_func (void) 11 | { 12 | MessageBox (0, hello_data, "From DLL", MB_ICONINFORMATION); 13 | } 14 | -------------------------------------------------------------------------------- /win32/examples/fib.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include // atoi() 3 | 4 | int fib(n) 5 | { 6 | if (n <= 2) 7 | return 1; 8 | else 9 | return fib(n-1) + fib(n-2); 10 | } 11 | 12 | int main(int argc, char **argv) 13 | { 14 | int n; 15 | if (argc < 2) { 16 | printf("usage: fib n\n" 17 | "Compute nth Fibonacci number\n"); 18 | return 1; 19 | } 20 | 21 | n = atoi(argv[1]); 22 | printf("fib(%d) = %d\n", n, fib(n)); 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /win32/examples/hello_dll.c: -------------------------------------------------------------------------------- 1 | //+--------------------------------------------------------------------------- 2 | // 3 | // HELLO_DLL.C - Windows DLL example - main application part 4 | // 5 | 6 | #include 7 | 8 | void hello_func (void); 9 | __declspec(dllimport) extern const char *hello_data; 10 | 11 | int WINAPI WinMain( 12 | HINSTANCE hInstance, 13 | HINSTANCE hPrevInstance, 14 | LPSTR lpCmdLine, 15 | int nCmdShow) 16 | { 17 | hello_data = "Hello World!"; 18 | hello_func(); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /win32/include/assert.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef __ASSERT_H_ 7 | #define __ASSERT_H_ 8 | 9 | #include <_mingw.h> 10 | #ifdef __cplusplus 11 | #include 12 | #endif 13 | 14 | #ifdef NDEBUG 15 | #ifndef assert 16 | #define assert(_Expression) ((void)0) 17 | #endif 18 | #else 19 | 20 | #ifndef _CRT_TERMINATE_DEFINED 21 | #define _CRT_TERMINATE_DEFINED 22 | void __cdecl __MINGW_NOTHROW exit(int _Code) __MINGW_ATTRIB_NORETURN; 23 | _CRTIMP void __cdecl __MINGW_NOTHROW _exit(int _Code) __MINGW_ATTRIB_NORETURN; 24 | #if !defined __NO_ISOCEXT /* extern stub in static libmingwex.a */ 25 | /* C99 function name */ 26 | void __cdecl _Exit(int) __MINGW_ATTRIB_NORETURN; 27 | __CRT_INLINE __MINGW_ATTRIB_NORETURN void __cdecl _Exit(int status) 28 | { _exit(status); } 29 | #endif 30 | 31 | #pragma push_macro("abort") 32 | #undef abort 33 | void __cdecl __declspec(noreturn) abort(void); 34 | #pragma pop_macro("abort") 35 | 36 | #endif 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | 43 | extern void __cdecl _wassert(const wchar_t *_Message,const wchar_t *_File,unsigned _Line); 44 | extern void __cdecl _assert(const char *, const char *, unsigned); 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #ifndef assert 51 | //#define assert(_Expression) (void)((!!(_Expression)) || (_wassert(_CRT_WIDE(#_Expression),_CRT_WIDE(__FILE__),__LINE__),0)) 52 | #define assert(e) ((e) ? (void)0 : _assert(#e, __FILE__, __LINE__)) 53 | #endif 54 | 55 | #endif 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /win32/include/dir.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | /* 7 | * dir.h 8 | * 9 | * This file OBSOLESCENT and only provided for backward compatibility. 10 | * Please use io.h instead. 11 | * 12 | * This file is part of the Mingw32 package. 13 | * 14 | * Contributors: 15 | * Created by Colin Peters 16 | * Mumit Khan 17 | * 18 | * THIS SOFTWARE IS NOT COPYRIGHTED 19 | * 20 | * This source code is offered for use in the public domain. You may 21 | * use, modify or distribute it freely. 22 | * 23 | * This code is distributed in the hope that it will be useful but 24 | * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY 25 | * DISCLAIMED. This includes but is not limited to warranties of 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 27 | * 28 | */ 29 | 30 | #include 31 | 32 | -------------------------------------------------------------------------------- /win32/include/direct.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef _INC_DIRECT 7 | #define _INC_DIRECT 8 | 9 | #include <_mingw.h> 10 | #include 11 | 12 | #pragma pack(push,_CRT_PACKING) 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | #ifndef _DISKFREE_T_DEFINED 19 | #define _DISKFREE_T_DEFINED 20 | struct _diskfree_t { 21 | unsigned total_clusters; 22 | unsigned avail_clusters; 23 | unsigned sectors_per_cluster; 24 | unsigned bytes_per_sector; 25 | }; 26 | #endif 27 | 28 | _CRTIMP char *__cdecl _getcwd(char *_DstBuf,int _SizeInBytes); 29 | _CRTIMP char *__cdecl _getdcwd(int _Drive,char *_DstBuf,int _SizeInBytes); 30 | char *__cdecl _getdcwd_nolock(int _Drive,char *_DstBuf,int _SizeInBytes); 31 | _CRTIMP int __cdecl _chdir(const char *_Path); 32 | _CRTIMP int __cdecl _mkdir(const char *_Path); 33 | _CRTIMP int __cdecl _rmdir(const char *_Path); 34 | _CRTIMP int __cdecl _chdrive(int _Drive); 35 | _CRTIMP int __cdecl _getdrive(void); 36 | _CRTIMP unsigned long __cdecl _getdrives(void); 37 | 38 | #ifndef _GETDISKFREE_DEFINED 39 | #define _GETDISKFREE_DEFINED 40 | _CRTIMP unsigned __cdecl _getdiskfree(unsigned _Drive,struct _diskfree_t *_DiskFree); 41 | #endif 42 | 43 | #ifndef _WDIRECT_DEFINED 44 | #define _WDIRECT_DEFINED 45 | _CRTIMP wchar_t *__cdecl _wgetcwd(wchar_t *_DstBuf,int _SizeInWords); 46 | _CRTIMP wchar_t *__cdecl _wgetdcwd(int _Drive,wchar_t *_DstBuf,int _SizeInWords); 47 | wchar_t *__cdecl _wgetdcwd_nolock(int _Drive,wchar_t *_DstBuf,int _SizeInWords); 48 | _CRTIMP int __cdecl _wchdir(const wchar_t *_Path); 49 | _CRTIMP int __cdecl _wmkdir(const wchar_t *_Path); 50 | _CRTIMP int __cdecl _wrmdir(const wchar_t *_Path); 51 | #endif 52 | 53 | #ifndef NO_OLDNAMES 54 | 55 | #define diskfree_t _diskfree_t 56 | 57 | char *__cdecl getcwd(char *_DstBuf,int _SizeInBytes); 58 | int __cdecl chdir(const char *_Path); 59 | int __cdecl mkdir(const char *_Path); 60 | int __cdecl rmdir(const char *_Path); 61 | #endif 62 | 63 | #ifdef __cplusplus 64 | } 65 | #endif 66 | 67 | #pragma pack(pop) 68 | #endif 69 | -------------------------------------------------------------------------------- /win32/include/dos.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef _INC_DOS 7 | #define _INC_DOS 8 | 9 | #include <_mingw.h> 10 | #include 11 | 12 | #pragma pack(push,_CRT_PACKING) 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | #ifndef _DISKFREE_T_DEFINED 19 | #define _DISKFREE_T_DEFINED 20 | 21 | struct _diskfree_t { 22 | unsigned total_clusters; 23 | unsigned avail_clusters; 24 | unsigned sectors_per_cluster; 25 | unsigned bytes_per_sector; 26 | }; 27 | #endif 28 | 29 | #define _A_NORMAL 0x00 30 | #define _A_RDONLY 0x01 31 | #define _A_HIDDEN 0x02 32 | #define _A_SYSTEM 0x04 33 | #define _A_SUBDIR 0x10 34 | #define _A_ARCH 0x20 35 | 36 | #ifndef _GETDISKFREE_DEFINED 37 | #define _GETDISKFREE_DEFINED 38 | _CRTIMP unsigned __cdecl _getdiskfree(unsigned _Drive,struct _diskfree_t *_DiskFree); 39 | #endif 40 | 41 | #if (defined(_X86_) && !defined(__x86_64)) 42 | void __cdecl _disable(void); 43 | void __cdecl _enable(void); 44 | #endif 45 | 46 | #ifndef NO_OLDNAMES 47 | #define diskfree_t _diskfree_t 48 | #endif 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | #pragma pack(pop) 55 | #endif 56 | -------------------------------------------------------------------------------- /win32/include/errno.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef _INC_ERRNO 7 | #define _INC_ERRNO 8 | 9 | #include <_mingw.h> 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | #ifndef _CRT_ERRNO_DEFINED 16 | #define _CRT_ERRNO_DEFINED 17 | _CRTIMP extern int *__cdecl _errno(void); 18 | #define errno (*_errno()) 19 | 20 | errno_t __cdecl _set_errno(int _Value); 21 | errno_t __cdecl _get_errno(int *_Value); 22 | #endif 23 | 24 | #define EPERM 1 25 | #define ENOENT 2 26 | #define ESRCH 3 27 | #define EINTR 4 28 | #define EIO 5 29 | #define ENXIO 6 30 | #define E2BIG 7 31 | #define ENOEXEC 8 32 | #define EBADF 9 33 | #define ECHILD 10 34 | #define EAGAIN 11 35 | #define ENOMEM 12 36 | #define EACCES 13 37 | #define EFAULT 14 38 | #define EBUSY 16 39 | #define EEXIST 17 40 | #define EXDEV 18 41 | #define ENODEV 19 42 | #define ENOTDIR 20 43 | #define EISDIR 21 44 | #define ENFILE 23 45 | #define EMFILE 24 46 | #define ENOTTY 25 47 | #define EFBIG 27 48 | #define ENOSPC 28 49 | #define ESPIPE 29 50 | #define EROFS 30 51 | #define EMLINK 31 52 | #define EPIPE 32 53 | #define EDOM 33 54 | #define EDEADLK 36 55 | #define ENAMETOOLONG 38 56 | #define ENOLCK 39 57 | #define ENOSYS 40 58 | #define ENOTEMPTY 41 59 | 60 | #ifndef RC_INVOKED 61 | #if !defined(_SECURECRT_ERRCODE_VALUES_DEFINED) 62 | #define _SECURECRT_ERRCODE_VALUES_DEFINED 63 | #define EINVAL 22 64 | #define ERANGE 34 65 | #define EILSEQ 42 66 | #define STRUNCATE 80 67 | #endif 68 | #endif 69 | 70 | #define EDEADLOCK EDEADLK 71 | 72 | #ifdef __cplusplus 73 | } 74 | #endif 75 | #endif 76 | -------------------------------------------------------------------------------- /win32/include/fcntl.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #include <_mingw.h> 7 | 8 | #include 9 | 10 | #ifndef _INC_FCNTL 11 | #define _INC_FCNTL 12 | 13 | #define _O_RDONLY 0x0000 14 | #define _O_WRONLY 0x0001 15 | #define _O_RDWR 0x0002 16 | #define _O_APPEND 0x0008 17 | #define _O_CREAT 0x0100 18 | #define _O_TRUNC 0x0200 19 | #define _O_EXCL 0x0400 20 | #define _O_TEXT 0x4000 21 | #define _O_BINARY 0x8000 22 | #define _O_WTEXT 0x10000 23 | #define _O_U16TEXT 0x20000 24 | #define _O_U8TEXT 0x40000 25 | #define _O_ACCMODE (_O_RDONLY|_O_WRONLY|_O_RDWR) 26 | 27 | #define _O_RAW _O_BINARY 28 | #define _O_NOINHERIT 0x0080 29 | #define _O_TEMPORARY 0x0040 30 | #define _O_SHORT_LIVED 0x1000 31 | 32 | #define _O_SEQUENTIAL 0x0020 33 | #define _O_RANDOM 0x0010 34 | 35 | #if !defined(NO_OLDNAMES) || defined(_POSIX) 36 | #define O_RDONLY _O_RDONLY 37 | #define O_WRONLY _O_WRONLY 38 | #define O_RDWR _O_RDWR 39 | #define O_APPEND _O_APPEND 40 | #define O_CREAT _O_CREAT 41 | #define O_TRUNC _O_TRUNC 42 | #define O_EXCL _O_EXCL 43 | #define O_TEXT _O_TEXT 44 | #define O_BINARY _O_BINARY 45 | #define O_RAW _O_BINARY 46 | #define O_TEMPORARY _O_TEMPORARY 47 | #define O_NOINHERIT _O_NOINHERIT 48 | #define O_SEQUENTIAL _O_SEQUENTIAL 49 | #define O_RANDOM _O_RANDOM 50 | #define O_ACCMODE _O_ACCMODE 51 | #endif 52 | #endif 53 | -------------------------------------------------------------------------------- /win32/include/locale.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef _INC_LOCALE 7 | #define _INC_LOCALE 8 | 9 | #include <_mingw.h> 10 | 11 | #pragma pack(push,_CRT_PACKING) 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | #ifndef NULL 18 | #ifdef __cplusplus 19 | #define NULL 0 20 | #else 21 | #define NULL ((void *)0) 22 | #endif 23 | #endif 24 | 25 | #define LC_ALL 0 26 | #define LC_COLLATE 1 27 | #define LC_CTYPE 2 28 | #define LC_MONETARY 3 29 | #define LC_NUMERIC 4 30 | #define LC_TIME 5 31 | 32 | #define LC_MIN LC_ALL 33 | #define LC_MAX LC_TIME 34 | 35 | #ifndef _LCONV_DEFINED 36 | #define _LCONV_DEFINED 37 | struct lconv { 38 | char *decimal_point; 39 | char *thousands_sep; 40 | char *grouping; 41 | char *int_curr_symbol; 42 | char *currency_symbol; 43 | char *mon_decimal_point; 44 | char *mon_thousands_sep; 45 | char *mon_grouping; 46 | char *positive_sign; 47 | char *negative_sign; 48 | char int_frac_digits; 49 | char frac_digits; 50 | char p_cs_precedes; 51 | char p_sep_by_space; 52 | char n_cs_precedes; 53 | char n_sep_by_space; 54 | char p_sign_posn; 55 | char n_sign_posn; 56 | }; 57 | #endif 58 | 59 | #ifndef _CONFIG_LOCALE_SWT 60 | #define _CONFIG_LOCALE_SWT 61 | 62 | #define _ENABLE_PER_THREAD_LOCALE 0x1 63 | #define _DISABLE_PER_THREAD_LOCALE 0x2 64 | #define _ENABLE_PER_THREAD_LOCALE_GLOBAL 0x10 65 | #define _DISABLE_PER_THREAD_LOCALE_GLOBAL 0x20 66 | #define _ENABLE_PER_THREAD_LOCALE_NEW 0x100 67 | #define _DISABLE_PER_THREAD_LOCALE_NEW 0x200 68 | 69 | #endif 70 | 71 | int __cdecl _configthreadlocale(int _Flag); 72 | char *__cdecl setlocale(int _Category,const char *_Locale); 73 | _CRTIMP struct lconv *__cdecl localeconv(void); 74 | _locale_t __cdecl _get_current_locale(void); 75 | _locale_t __cdecl _create_locale(int _Category,const char *_Locale); 76 | void __cdecl _free_locale(_locale_t _Locale); 77 | _locale_t __cdecl __get_current_locale(void); 78 | _locale_t __cdecl __create_locale(int _Category,const char *_Locale); 79 | void __cdecl __free_locale(_locale_t _Locale); 80 | 81 | #ifndef _WLOCALE_DEFINED 82 | #define _WLOCALE_DEFINED 83 | _CRTIMP wchar_t *__cdecl _wsetlocale(int _Category,const wchar_t *_Locale); 84 | #endif 85 | 86 | #ifdef __cplusplus 87 | } 88 | #endif 89 | 90 | #pragma pack(pop) 91 | #endif 92 | -------------------------------------------------------------------------------- /win32/include/mem.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | /* 7 | * This file is part of the Mingw32 package. 8 | * 9 | * mem.h maps to string.h 10 | */ 11 | #ifndef __STRICT_ANSI__ 12 | #include 13 | #endif 14 | -------------------------------------------------------------------------------- /win32/include/memory.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef _INC_MEMORY 7 | #define _INC_MEMORY 8 | 9 | #include <_mingw.h> 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | #ifndef _CONST_RETURN 16 | #define _CONST_RETURN 17 | #endif 18 | 19 | #define _WConst_return _CONST_RETURN 20 | 21 | #ifndef _CRT_MEMORY_DEFINED 22 | #define _CRT_MEMORY_DEFINED 23 | _CRTIMP void *__cdecl _memccpy(void *_Dst,const void *_Src,int _Val,size_t _MaxCount); 24 | _CONST_RETURN void *__cdecl memchr(const void *_Buf ,int _Val,size_t _MaxCount); 25 | _CRTIMP int __cdecl _memicmp(const void *_Buf1,const void *_Buf2,size_t _Size); 26 | _CRTIMP int __cdecl _memicmp_l(const void *_Buf1,const void *_Buf2,size_t _Size,_locale_t _Locale); 27 | int __cdecl memcmp(const void *_Buf1,const void *_Buf2,size_t _Size); 28 | void *__cdecl memcpy(void *_Dst,const void *_Src,size_t _Size); 29 | void *__cdecl memset(void *_Dst,int _Val,size_t _Size); 30 | 31 | #ifndef NO_OLDNAMES 32 | void *__cdecl memccpy(void *_Dst,const void *_Src,int _Val,size_t _Size); 33 | int __cdecl memicmp(const void *_Buf1,const void *_Buf2,size_t _Size); 34 | #endif 35 | #endif 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | #endif 41 | -------------------------------------------------------------------------------- /win32/include/sec_api/conio_s.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | 7 | #ifndef _INC_CONIO_S 8 | #define _INC_CONIO_S 9 | 10 | #include 11 | 12 | #if defined(MINGW_HAS_SECURE_API) 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | _CRTIMP errno_t __cdecl _cgets_s(char *_Buffer,size_t _Size,size_t *_SizeRead); 19 | _CRTIMP int __cdecl _cprintf_s(const char *_Format,...); 20 | _CRTIMP int __cdecl _cscanf_s(const char *_Format,...); 21 | _CRTIMP int __cdecl _cscanf_s_l(const char *_Format,_locale_t _Locale,...); 22 | _CRTIMP int __cdecl _vcprintf_s(const char *_Format,va_list _ArgList); 23 | _CRTIMP int __cdecl _cprintf_s_l(const char *_Format,_locale_t _Locale,...); 24 | _CRTIMP int __cdecl _vcprintf_s_l(const char *_Format,_locale_t _Locale,va_list _ArgList); 25 | 26 | #ifndef _WCONIO_DEFINED_S 27 | #define _WCONIO_DEFINED_S 28 | _CRTIMP errno_t __cdecl _cgetws_s(wchar_t *_Buffer,size_t _SizeInWords,size_t *_SizeRead); 29 | _CRTIMP int __cdecl _cwprintf_s(const wchar_t *_Format,...); 30 | _CRTIMP int __cdecl _cwscanf_s(const wchar_t *_Format,...); 31 | _CRTIMP int __cdecl _cwscanf_s_l(const wchar_t *_Format,_locale_t _Locale,...); 32 | _CRTIMP int __cdecl _vcwprintf_s(const wchar_t *_Format,va_list _ArgList); 33 | _CRTIMP int __cdecl _cwprintf_s_l(const wchar_t *_Format,_locale_t _Locale,...); 34 | _CRTIMP int __cdecl _vcwprintf_s_l(const wchar_t *_Format,_locale_t _Locale,va_list _ArgList); 35 | #endif 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif 42 | #endif 43 | -------------------------------------------------------------------------------- /win32/include/sec_api/crtdbg_s.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | 7 | #ifndef _INC_CRTDBG_S 8 | #define _INC_CRTDBG_S 9 | 10 | #include 11 | 12 | #if defined(MINGW_HAS_SECURE_API) 13 | 14 | #define _dupenv_s_dbg(ps1,size,s2,t,f,l) _dupenv_s(ps1,size,s2) 15 | #define _wdupenv_s_dbg(ps1,size,s2,t,f,l) _wdupenv_s(ps1,size,s2) 16 | 17 | #endif 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /win32/include/sec_api/io_s.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef _INC_IO_S 7 | #define _INC_IO_S 8 | 9 | #include 10 | 11 | #if defined(MINGW_HAS_SECURE_API) 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | _CRTIMP errno_t __cdecl _access_s(const char *_Filename,int _AccessMode); 18 | _CRTIMP errno_t __cdecl _chsize_s(int _FileHandle,__int64 _Size); 19 | _CRTIMP errno_t __cdecl _mktemp_s(char *_TemplateName,size_t _Size); 20 | _CRTIMP errno_t __cdecl _umask_s(int _NewMode,int *_OldMode); 21 | 22 | #ifndef _WIO_S_DEFINED 23 | #define _WIO_S_DEFINED 24 | _CRTIMP errno_t __cdecl _waccess_s(const wchar_t *_Filename,int _AccessMode); 25 | _CRTIMP errno_t __cdecl _wmktemp_s(wchar_t *_TemplateName,size_t _SizeInWords); 26 | #endif 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | 32 | #endif 33 | #endif 34 | -------------------------------------------------------------------------------- /win32/include/sec_api/search_s.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef _INC_SEARCH_S 7 | #define _INC_SEARCH_S 8 | 9 | #include 10 | 11 | #if defined(MINGW_HAS_SECURE_API) 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | _CRTIMP void *__cdecl _lfind_s(const void *_Key,const void *_Base,unsigned int *_NumOfElements,size_t _SizeOfElements,int (__cdecl *_PtFuncCompare)(void *,const void *,const void *),void *_Context); 18 | _CRTIMP void *__cdecl _lsearch_s(const void *_Key,void *_Base,unsigned int *_NumOfElements,size_t _SizeOfElements,int (__cdecl *_PtFuncCompare)(void *,const void *,const void *),void *_Context); 19 | 20 | #ifdef __cplusplus 21 | } 22 | #endif 23 | 24 | #endif 25 | #endif 26 | -------------------------------------------------------------------------------- /win32/include/sec_api/stralign_s.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef __STRALIGN_H_S_ 7 | #define __STRALIGN_H_S_ 8 | 9 | #include 10 | 11 | #if defined(MINGW_HAS_SECURE_API) 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | #if !defined(I_X86_) && defined(_WSTRING_S_DEFINED) 18 | #if defined(__cplusplus) && defined(_WConst_Return) 19 | static __inline PUWSTR ua_wcscpy_s(PUWSTR Destination,size_t DestinationSize,PCUWSTR Source) { 20 | if(WSTR_ALIGNED(Source) && WSTR_ALIGNED(Destination)) return (wcscpy_s((PWSTR)Destination,DestinationSize,(PCWSTR)Source)==0 ? Destination : NULL); 21 | return uaw_wcscpy((PCUWSTR)String,Character); 22 | } 23 | #endif 24 | #endif 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | #endif 30 | #endif 31 | -------------------------------------------------------------------------------- /win32/include/sec_api/string_s.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef _INC_STRING_S 7 | #define _INC_STRING_S 8 | 9 | #include 10 | 11 | #if defined(MINGW_HAS_SECURE_API) 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | _CRTIMP errno_t __cdecl _strset_s(char *_Dst,size_t _DstSize,int _Value); 18 | _CRTIMP errno_t __cdecl _strerror_s(char *_Buf,size_t _SizeInBytes,const char *_ErrMsg); 19 | _CRTIMP errno_t __cdecl _strlwr_s(char *_Str,size_t _Size); 20 | _CRTIMP errno_t __cdecl _strlwr_s_l(char *_Str,size_t _Size,_locale_t _Locale); 21 | _CRTIMP errno_t __cdecl _strnset_s(char *_Str,size_t _Size,int _Val,size_t _MaxCount); 22 | _CRTIMP errno_t __cdecl _strupr_s(char *_Str,size_t _Size); 23 | _CRTIMP errno_t __cdecl _strupr_s_l(char *_Str,size_t _Size,_locale_t _Locale); 24 | #ifndef _WSTRING_S_DEFINED 25 | #define _WSTRING_S_DEFINED 26 | _CRTIMP wchar_t *__cdecl wcstok_s(wchar_t *_Str,const wchar_t *_Delim,wchar_t **_Context); 27 | _CRTIMP errno_t __cdecl _wcserror_s(wchar_t *_Buf,size_t _SizeInWords,int _ErrNum); 28 | _CRTIMP errno_t __cdecl __wcserror_s(wchar_t *_Buffer,size_t _SizeInWords,const wchar_t *_ErrMsg); 29 | _CRTIMP errno_t __cdecl _wcsnset_s(wchar_t *_Dst,size_t _DstSizeInWords,wchar_t _Val,size_t _MaxCount); 30 | _CRTIMP errno_t __cdecl _wcsset_s(wchar_t *_Str,size_t _SizeInWords,wchar_t _Val); 31 | _CRTIMP errno_t __cdecl _wcslwr_s(wchar_t *_Str,size_t _SizeInWords); 32 | _CRTIMP errno_t __cdecl _wcslwr_s_l(wchar_t *_Str,size_t _SizeInWords,_locale_t _Locale); 33 | _CRTIMP errno_t __cdecl _wcsupr_s(wchar_t *_Str,size_t _Size); 34 | _CRTIMP errno_t __cdecl _wcsupr_s_l(wchar_t *_Str,size_t _Size,_locale_t _Locale); 35 | #endif 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | #endif 41 | #endif 42 | -------------------------------------------------------------------------------- /win32/include/sec_api/sys/timeb_s.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | 7 | #ifndef _TIMEB_H_S 8 | #define _TIMEB_H_S 9 | 10 | #include 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #if defined(MINGW_HAS_SECURE_API) 17 | 18 | #ifdef _USE_32BIT_TIME_T 19 | #define _ftime_s _ftime32_s 20 | #else 21 | #define _ftime_s _ftime64_s 22 | #endif 23 | 24 | _CRTIMP errno_t __cdecl _ftime32_s(struct __timeb32 *_Time); 25 | #if _INTEGRAL_MAX_BITS >= 64 26 | _CRTIMP errno_t __cdecl _ftime64_s(struct __timeb64 *_Time); 27 | #endif 28 | #endif 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /win32/include/sec_api/time_s.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef _TIME_H__S 7 | #define _TIME_H__S 8 | 9 | #include 10 | 11 | #if defined(MINGW_HAS_SECURE_API) 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | _CRTIMP errno_t __cdecl _ctime32_s(char *_Buf,size_t _SizeInBytes,const __time32_t *_Time); 18 | _CRTIMP errno_t __cdecl _gmtime32_s(struct tm *_Tm,const __time32_t *_Time); 19 | _CRTIMP errno_t __cdecl _localtime32_s(struct tm *_Tm,const __time32_t *_Time); 20 | _CRTIMP errno_t __cdecl _strdate_s(char *_Buf,size_t _SizeInBytes); 21 | _CRTIMP errno_t __cdecl _strtime_s(char *_Buf ,size_t _SizeInBytes); 22 | #if _INTEGRAL_MAX_BITS >= 64 23 | _CRTIMP errno_t __cdecl _ctime64_s(char *_Buf,size_t _SizeInBytes,const __time64_t *_Time); 24 | _CRTIMP errno_t __cdecl _gmtime64_s(struct tm *_Tm,const __time64_t *_Time); 25 | _CRTIMP errno_t __cdecl _localtime64_s(struct tm *_Tm,const __time64_t *_Time); 26 | #endif 27 | 28 | #ifndef _WTIME_S_DEFINED 29 | #define _WTIME_S_DEFINED 30 | _CRTIMP errno_t __cdecl _wasctime_s(wchar_t *_Buf,size_t _SizeInWords,const struct tm *_Tm); 31 | _CRTIMP errno_t __cdecl _wctime32_s(wchar_t *_Buf,size_t _SizeInWords,const __time32_t *_Time); 32 | _CRTIMP errno_t __cdecl _wstrdate_s(wchar_t *_Buf,size_t _SizeInWords); 33 | _CRTIMP errno_t __cdecl _wstrtime_s(wchar_t *_Buf,size_t _SizeInWords); 34 | #if _INTEGRAL_MAX_BITS >= 64 35 | _CRTIMP errno_t __cdecl _wctime64_s(wchar_t *_Buf,size_t _SizeInWords,const __time64_t *_Time); 36 | #endif 37 | 38 | #if !defined (RC_INVOKED) && !defined (_INC_WTIME_S_INL) 39 | #define _INC_WTIME_S_INL 40 | #ifdef _USE_32BIT_TIME_T 41 | __CRT_INLINE errno_t __cdecl _wctime_s(wchar_t *_Buffer,size_t _SizeInWords,const time_t *_Time) { return _wctime32_s(_Buffer,_SizeInWords,_Time); } 42 | #else 43 | __CRT_INLINE errno_t __cdecl _wctime_s(wchar_t *_Buffer,size_t _SizeInWords,const time_t *_Time) { return _wctime64_s(_Buffer,_SizeInWords,_Time); } 44 | #endif 45 | #endif 46 | #endif 47 | 48 | #ifndef RC_INVOKED 49 | #ifdef _USE_32BIT_TIME_T 50 | __CRT_INLINE errno_t __cdecl localtime_s(struct tm *_Tm,const time_t *_Time) { return _localtime32_s(_Tm,_Time); } 51 | #else 52 | __CRT_INLINE errno_t __cdecl localtime_s(struct tm *_Tm,const time_t *_Time) { return _localtime64_s(_Tm,_Time); } 53 | #endif 54 | #endif 55 | 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | 60 | #endif 61 | #endif 62 | -------------------------------------------------------------------------------- /win32/include/share.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef _INC_SHARE 7 | #define _INC_SHARE 8 | 9 | #ifndef _WIN32 10 | #error Only Win32 target is supported! 11 | #endif 12 | 13 | #define _SH_COMPAT 0x00 14 | #define _SH_DENYRW 0x10 15 | #define _SH_DENYWR 0x20 16 | #define _SH_DENYRD 0x30 17 | #define _SH_DENYNO 0x40 18 | #define _SH_SECURE 0x80 19 | 20 | #ifndef NO_OLDNAMES 21 | #define SH_COMPAT _SH_COMPAT 22 | #define SH_DENYRW _SH_DENYRW 23 | #define SH_DENYWR _SH_DENYWR 24 | #define SH_DENYRD _SH_DENYRD 25 | #define SH_DENYNO _SH_DENYNO 26 | #endif 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /win32/include/signal.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef _INC_SIGNAL 7 | #define _INC_SIGNAL 8 | 9 | #include <_mingw.h> 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | #ifndef _SIG_ATOMIC_T_DEFINED 16 | #define _SIG_ATOMIC_T_DEFINED 17 | typedef int sig_atomic_t; 18 | #endif 19 | 20 | #define NSIG 23 21 | 22 | #define SIGHUP 1 /* hangup */ 23 | #define SIGINT 2 24 | #define SIGQUIT 3 /* quit */ 25 | #define SIGILL 4 26 | #define SIGTRAP 5 /* trace trap (not reset when caught) */ 27 | #define SIGIOT 6 /* IOT instruction */ 28 | #define SIGABRT 6 /* used by abort, replace SIGIOT in the future */ 29 | #define SIGEMT 7 /* EMT instruction */ 30 | #define SIGFPE 8 31 | #define SIGKILL 9 /* kill (cannot be caught or ignored) */ 32 | #define SIGBUS 10 /* bus error */ 33 | #define SIGSEGV 11 34 | #define SIGSYS 12 /* bad argument to system call */ 35 | #define SIGPIPE 13 /* write on a pipe with no one to read it */ 36 | #ifdef __USE_MINGW_ALARM 37 | #define SIGALRM 14 /* alarm clock */ 38 | #endif 39 | #define SIGTERM 15 40 | #define SIGBREAK 21 41 | #define SIGABRT2 22 42 | 43 | #define SIGABRT_COMPAT 6 44 | 45 | typedef void (*__p_sig_fn_t)(int); 46 | 47 | #define SIG_DFL (__p_sig_fn_t)0 48 | #define SIG_IGN (__p_sig_fn_t)1 49 | #define SIG_GET (__p_sig_fn_t)2 50 | #define SIG_SGE (__p_sig_fn_t)3 51 | #define SIG_ACK (__p_sig_fn_t)4 52 | #define SIG_ERR (__p_sig_fn_t)-1 53 | 54 | extern void **__cdecl __pxcptinfoptrs(void); 55 | #define _pxcptinfoptrs (*__pxcptinfoptrs()) 56 | 57 | __p_sig_fn_t __cdecl signal(int _SigNum,__p_sig_fn_t _Func); 58 | int __cdecl raise(int _SigNum); 59 | 60 | #ifdef __cplusplus 61 | } 62 | #endif 63 | #endif 64 | -------------------------------------------------------------------------------- /win32/include/sys/fcntl.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | /* 7 | * This file is part of the Mingw32 package. 8 | * 9 | * This fcntl.h maps to the root fcntl.h 10 | */ 11 | #ifndef __STRICT_ANSI__ 12 | #include 13 | #endif 14 | -------------------------------------------------------------------------------- /win32/include/sys/file.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | /* 7 | * This file is part of the Mingw32 package. 8 | * 9 | * This file.h maps to the root fcntl.h 10 | * TODO? 11 | */ 12 | #ifndef __STRICT_ANSI__ 13 | #include 14 | #endif 15 | -------------------------------------------------------------------------------- /win32/include/sys/locking.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef _INC_LOCKING 7 | #define _INC_LOCKING 8 | 9 | #ifndef _WIN32 10 | #error Only Win32 target is supported! 11 | #endif 12 | 13 | /* All the headers include this file. */ 14 | #include <_mingw.h> 15 | 16 | #define _LK_UNLCK 0 17 | #define _LK_LOCK 1 18 | #define _LK_NBLCK 2 19 | #define _LK_RLCK 3 20 | #define _LK_NBRLCK 4 21 | 22 | #ifndef NO_OLDNAMES 23 | #define LK_UNLCK _LK_UNLCK 24 | #define LK_LOCK _LK_LOCK 25 | #define LK_NBLCK _LK_NBLCK 26 | #define LK_RLCK _LK_RLCK 27 | #define LK_NBRLCK _LK_NBRLCK 28 | #endif 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /win32/include/sys/time.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | 7 | #ifndef _SYS_TIME_H_ 8 | #define _SYS_TIME_H_ 9 | 10 | #include 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #ifndef __STRICT_ANSI__ 17 | #ifndef _TIMEVAL_DEFINED /* also in winsock[2].h */ 18 | #define _TIMEVAL_DEFINED 19 | struct timeval { 20 | long tv_sec; 21 | long tv_usec; 22 | }; 23 | #define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) 24 | #define timercmp(tvp, uvp, cmp) \ 25 | (((tvp)->tv_sec != (uvp)->tv_sec) ? \ 26 | ((tvp)->tv_sec cmp (uvp)->tv_sec) : \ 27 | ((tvp)->tv_usec cmp (uvp)->tv_usec)) 28 | #define timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0 29 | #endif /* _TIMEVAL_DEFINED */ 30 | 31 | #ifndef _TIMEZONE_DEFINED /* also in sys/time.h */ 32 | #define _TIMEZONE_DEFINED 33 | /* Provided for compatibility with code that assumes that 34 | the presence of gettimeofday function implies a definition 35 | of struct timezone. */ 36 | struct timezone 37 | { 38 | int tz_minuteswest; /* of Greenwich */ 39 | int tz_dsttime; /* type of dst correction to apply */ 40 | }; 41 | 42 | extern int __cdecl mingw_gettimeofday (struct timeval *p, struct timezone *z); 43 | 44 | #endif 45 | 46 | /* 47 | Implementation as per: 48 | The Open Group Base Specifications, Issue 6 49 | IEEE Std 1003.1, 2004 Edition 50 | 51 | The timezone pointer arg is ignored. Errors are ignored. 52 | */ 53 | #ifndef _GETTIMEOFDAY_DEFINED 54 | #define _GETTIMEOFDAY_DEFINED 55 | int __cdecl gettimeofday(struct timeval *__restrict__, 56 | void *__restrict__ /* tzp (unused) */); 57 | #endif 58 | 59 | #endif /* __STRICT_ANSI__ */ 60 | 61 | #ifdef __cplusplus 62 | } 63 | #endif 64 | 65 | /* Adding timespec definition. */ 66 | #include 67 | 68 | 69 | #endif /* _SYS_TIME_H_ */ 70 | -------------------------------------------------------------------------------- /win32/include/sys/timeb.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef _TIMEB_H_ 7 | #define _TIMEB_H_ 8 | 9 | #include <_mingw.h> 10 | 11 | #ifndef _WIN32 12 | #error Only Win32 target is supported! 13 | #endif 14 | 15 | #pragma pack(push,_CRT_PACKING) 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | #ifndef _CRTIMP 22 | #define _CRTIMP __declspec(dllimport) 23 | #endif 24 | 25 | #ifndef __TINYC__ /* gr */ 26 | #ifdef _USE_32BIT_TIME_T 27 | #ifdef _WIN64 28 | #undef _USE_32BIT_TIME_T 29 | #endif 30 | #else 31 | #if _INTEGRAL_MAX_BITS < 64 32 | #define _USE_32BIT_TIME_T 33 | #endif 34 | #endif 35 | #endif 36 | 37 | #ifndef _TIME32_T_DEFINED 38 | typedef long __time32_t; 39 | #define _TIME32_T_DEFINED 40 | #endif 41 | 42 | #ifndef _TIME64_T_DEFINED 43 | #if _INTEGRAL_MAX_BITS >= 64 44 | typedef __int64 __time64_t; 45 | #endif 46 | #define _TIME64_T_DEFINED 47 | #endif 48 | 49 | #ifndef _TIME_T_DEFINED 50 | #ifdef _USE_32BIT_TIME_T 51 | typedef __time32_t time_t; 52 | #else 53 | typedef __time64_t time_t; 54 | #endif 55 | #define _TIME_T_DEFINED 56 | #endif 57 | 58 | #ifndef _TIMEB_DEFINED 59 | #define _TIMEB_DEFINED 60 | 61 | struct __timeb32 { 62 | __time32_t time; 63 | unsigned short millitm; 64 | short timezone; 65 | short dstflag; 66 | }; 67 | 68 | #ifndef NO_OLDNAMES 69 | struct timeb { 70 | time_t time; 71 | unsigned short millitm; 72 | short timezone; 73 | short dstflag; 74 | }; 75 | #endif 76 | 77 | #if _INTEGRAL_MAX_BITS >= 64 78 | struct __timeb64 { 79 | __time64_t time; 80 | unsigned short millitm; 81 | short timezone; 82 | short dstflag; 83 | }; 84 | #endif 85 | 86 | #ifdef _USE_32BIT_TIME_T 87 | #define _timeb __timeb32 88 | //gr #define _ftime _ftime32 89 | #define _ftime32 _ftime 90 | #else 91 | #define _timeb __timeb64 92 | #define _ftime _ftime64 93 | #endif 94 | #endif 95 | 96 | _CRTIMP void __cdecl _ftime32(struct __timeb32 *_Time); 97 | #if _INTEGRAL_MAX_BITS >= 64 98 | _CRTIMP void __cdecl _ftime64(struct __timeb64 *_Time); 99 | #endif 100 | 101 | #ifndef _TIMESPEC_DEFINED 102 | #define _TIMESPEC_DEFINED 103 | struct timespec { 104 | time_t tv_sec; /* Seconds */ 105 | long tv_nsec; /* Nanoseconds */ 106 | }; 107 | 108 | struct itimerspec { 109 | struct timespec it_interval; /* Timer period */ 110 | struct timespec it_value; /* Timer expiration */ 111 | }; 112 | #endif 113 | 114 | #if !defined (RC_INVOKED) && !defined (NO_OLDNAMES) 115 | #ifdef _USE_32BIT_TIME_T 116 | __CRT_INLINE void __cdecl ftime(struct timeb *_Tmb) { 117 | _ftime32((struct __timeb32 *)_Tmb); 118 | } 119 | #else 120 | __CRT_INLINE void __cdecl ftime(struct timeb *_Tmb) { 121 | _ftime64((struct __timeb64 *)_Tmb); 122 | } 123 | #endif 124 | #endif 125 | 126 | #ifdef __cplusplus 127 | } 128 | #endif 129 | 130 | #pragma pack(pop) 131 | 132 | #include 133 | #endif 134 | -------------------------------------------------------------------------------- /win32/include/sys/types.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef _INC_TYPES 7 | #define _INC_TYPES 8 | 9 | #ifndef _WIN32 10 | #error Only Win32 target is supported! 11 | #endif 12 | 13 | #include <_mingw.h> 14 | 15 | #ifndef __TINYC__ /* gr */ 16 | #ifdef _USE_32BIT_TIME_T 17 | #ifdef _WIN64 18 | #undef _USE_32BIT_TIME_T 19 | #endif 20 | #else 21 | #if _INTEGRAL_MAX_BITS < 64 22 | #define _USE_32BIT_TIME_T 23 | #endif 24 | #endif 25 | #endif 26 | 27 | #ifndef _TIME32_T_DEFINED 28 | #define _TIME32_T_DEFINED 29 | typedef long __time32_t; 30 | #endif 31 | 32 | #ifndef _TIME64_T_DEFINED 33 | #define _TIME64_T_DEFINED 34 | #if _INTEGRAL_MAX_BITS >= 64 35 | typedef __int64 __time64_t; 36 | #endif 37 | #endif 38 | 39 | #ifndef _TIME_T_DEFINED 40 | #define _TIME_T_DEFINED 41 | #ifdef _USE_32BIT_TIME_T 42 | typedef __time32_t time_t; 43 | #else 44 | typedef __time64_t time_t; 45 | #endif 46 | #endif 47 | 48 | #ifndef _INO_T_DEFINED 49 | #define _INO_T_DEFINED 50 | typedef unsigned short _ino_t; 51 | #ifndef NO_OLDNAMES 52 | typedef unsigned short ino_t; 53 | #endif 54 | #endif 55 | 56 | #ifndef _DEV_T_DEFINED 57 | #define _DEV_T_DEFINED 58 | typedef unsigned int _dev_t; 59 | #ifndef NO_OLDNAMES 60 | typedef unsigned int dev_t; 61 | #endif 62 | #endif 63 | 64 | #ifndef _PID_T_ 65 | #define _PID_T_ 66 | #ifndef _WIN64 67 | typedef int _pid_t; 68 | #else 69 | typedef __int64 _pid_t; 70 | #endif 71 | 72 | #ifndef NO_OLDNAMES 73 | typedef _pid_t pid_t; 74 | #endif 75 | #endif /* Not _PID_T_ */ 76 | 77 | #ifndef _MODE_T_ 78 | #define _MODE_T_ 79 | typedef unsigned short _mode_t; 80 | 81 | #ifndef NO_OLDNAMES 82 | typedef _mode_t mode_t; 83 | #endif 84 | #endif /* Not _MODE_T_ */ 85 | 86 | #ifndef _OFF_T_DEFINED 87 | #define _OFF_T_DEFINED 88 | #ifndef _OFF_T_ 89 | #define _OFF_T_ 90 | typedef long _off_t; 91 | #if !defined(NO_OLDNAMES) || defined(_POSIX) 92 | typedef long off_t; 93 | #endif 94 | #endif 95 | #endif 96 | 97 | #ifndef _OFF64_T_DEFINED 98 | #define _OFF64_T_DEFINED 99 | typedef long long _off64_t; 100 | #if !defined(NO_OLDNAMES) || defined(_POSIX) 101 | typedef long long off64_t; 102 | #endif 103 | #endif 104 | 105 | #ifndef _TIMESPEC_DEFINED 106 | #define _TIMESPEC_DEFINED 107 | struct timespec { 108 | time_t tv_sec; /* Seconds */ 109 | long tv_nsec; /* Nanoseconds */ 110 | }; 111 | 112 | struct itimerspec { 113 | struct timespec it_interval; /* Timer period */ 114 | struct timespec it_value; /* Timer expiration */ 115 | }; 116 | #endif 117 | 118 | #endif 119 | -------------------------------------------------------------------------------- /win32/include/sys/unistd.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | /* 7 | * This file is part of the Mingw32 package. 8 | * 9 | * unistd.h maps (roughly) to io.h 10 | */ 11 | #ifndef __STRICT_ANSI__ 12 | #include 13 | #endif 14 | 15 | -------------------------------------------------------------------------------- /win32/include/vadefs.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef _INC_VADEFS 7 | #define _INC_VADEFS 8 | 9 | //!__TINYC__: GNUC specific stuff removed 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /win32/include/values.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TODO: Nothing here yet. Should provide UNIX compatibility constants 3 | * comparible to those in limits.h and float.h. 4 | */ 5 | -------------------------------------------------------------------------------- /win32/include/winapi/basetyps.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #if !defined(_BASETYPS_H_) 7 | #define _BASETYPS_H_ 8 | 9 | #ifdef __cplusplus 10 | #define EXTERN_C extern "C" 11 | #else 12 | #define EXTERN_C extern 13 | #endif 14 | 15 | #define STDMETHODCALLTYPE WINAPI 16 | #define STDMETHODVCALLTYPE __cdecl 17 | 18 | #define STDAPICALLTYPE WINAPI 19 | #define STDAPIVCALLTYPE __cdecl 20 | 21 | #define STDAPI EXTERN_C HRESULT WINAPI 22 | #define STDAPI_(type) EXTERN_C type WINAPI 23 | 24 | #define STDMETHODIMP HRESULT WINAPI 25 | #define STDMETHODIMP_(type) type WINAPI 26 | 27 | #define STDAPIV EXTERN_C HRESULT STDAPIVCALLTYPE 28 | #define STDAPIV_(type) EXTERN_C type STDAPIVCALLTYPE 29 | 30 | #define STDMETHODIMPV HRESULT STDMETHODVCALLTYPE 31 | #define STDMETHODIMPV_(type) type STDMETHODVCALLTYPE 32 | 33 | #if defined(__cplusplus) && !defined(CINTERFACE) 34 | 35 | #define __STRUCT__ struct 36 | #define STDMETHOD(method) virtual HRESULT WINAPI method 37 | #define STDMETHOD_(type,method) virtual type WINAPI method 38 | #define STDMETHODV(method) virtual HRESULT STDMETHODVCALLTYPE method 39 | #define STDMETHODV_(type,method) virtual type STDMETHODVCALLTYPE method 40 | #define PURE = 0 41 | #define THIS_ 42 | #define THIS void 43 | #define DECLARE_INTERFACE(iface) __STRUCT__ iface 44 | #define DECLARE_INTERFACE_(iface,baseiface) __STRUCT__ iface : public baseiface 45 | #else 46 | 47 | #ifndef __OBJC__ 48 | #define interface struct 49 | #endif 50 | 51 | #define STDMETHOD(method) HRESULT (WINAPI *method) 52 | #define STDMETHOD_(type,method) type (WINAPI *method) 53 | #define STDMETHODV(method) HRESULT (STDMETHODVCALLTYPE *method) 54 | #define STDMETHODV_(type,method) type (STDMETHODVCALLTYPE *method) 55 | 56 | #define PURE 57 | #define THIS_ INTERFACE *This, 58 | #define THIS INTERFACE *This 59 | #ifdef CONST_VTABLE 60 | #define DECLARE_INTERFACE(iface) typedef struct iface { \ 61 | const struct iface##Vtbl *lpVtbl; } iface; \ 62 | typedef const struct iface##Vtbl iface##Vtbl; \ 63 | const struct iface##Vtbl 64 | #else 65 | #define DECLARE_INTERFACE(iface) typedef struct iface { \ 66 | struct iface##Vtbl *lpVtbl; \ 67 | } iface; \ 68 | typedef struct iface##Vtbl iface##Vtbl; \ 69 | struct iface##Vtbl 70 | #endif 71 | #define DECLARE_INTERFACE_(iface,baseiface) DECLARE_INTERFACE(iface) 72 | #endif 73 | 74 | #include 75 | 76 | #ifndef _ERROR_STATUS_T_DEFINED 77 | #define _ERROR_STATUS_T_DEFINED 78 | typedef unsigned long error_status_t; 79 | #endif 80 | 81 | #ifndef _WCHAR_T_DEFINED 82 | typedef unsigned short wchar_t; 83 | #define _WCHAR_T_DEFINED 84 | #endif 85 | #endif 86 | -------------------------------------------------------------------------------- /win32/include/winapi/poppack.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #if !(defined(lint) || defined(RC_INVOKED)) 7 | #pragma pack(pop) 8 | #endif 9 | -------------------------------------------------------------------------------- /win32/include/winapi/pshpack1.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #if !(defined(lint) || defined(RC_INVOKED)) 7 | #pragma pack(push,1) 8 | #endif 9 | -------------------------------------------------------------------------------- /win32/include/winapi/pshpack2.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #if !(defined(lint) || defined(RC_INVOKED)) 7 | #pragma pack(push,2) 8 | #endif 9 | -------------------------------------------------------------------------------- /win32/include/winapi/pshpack4.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #if !(defined(lint) || defined(RC_INVOKED)) 7 | #pragma pack(push,4) 8 | #endif 9 | -------------------------------------------------------------------------------- /win32/include/winapi/pshpack8.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #if !(defined(lint) || defined(RC_INVOKED)) 7 | #pragma pack(push,8) 8 | #endif 9 | -------------------------------------------------------------------------------- /win32/include/winapi/windows.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef _WINDOWS_ 7 | #define _WINDOWS_ 8 | 9 | #ifndef WIN32_LEAN_AND_MEAN 10 | #define WIN32_LEAN_AND_MEAN 1 11 | #endif 12 | 13 | #ifndef WINVER 14 | #define WINVER 0x0502 15 | #endif 16 | 17 | #include <_mingw.h> 18 | 19 | #ifndef _INC_WINDOWS 20 | #define _INC_WINDOWS 21 | 22 | #if defined(RC_INVOKED) && !defined(NOWINRES) 23 | 24 | #include 25 | #else 26 | 27 | #ifdef RC_INVOKED 28 | #define NOATOM 29 | #define NOGDI 30 | #define NOGDICAPMASKS 31 | #define NOMETAFILE 32 | #define NOMINMAX 33 | #define NOMSG 34 | #define NOOPENFILE 35 | #define NORASTEROPS 36 | #define NOSCROLL 37 | #define NOSOUND 38 | #define NOSYSMETRICS 39 | #define NOTEXTMETRIC 40 | #define NOWH 41 | #define NOCOMM 42 | #define NOKANJI 43 | #define NOCRYPT 44 | #define NOMCX 45 | #endif 46 | 47 | #if !defined(I_X86_) && !defined(_IA64_) && !defined(_AMD64_) && (defined(_X86_) && !defined(__x86_64)) 48 | #define I_X86_ 49 | #endif 50 | 51 | #if !defined(I_X86_) && !defined(_IA64_) && !defined(_AMD64_) && defined(__x86_64) 52 | #define _AMD64_ 53 | #endif 54 | 55 | #if !defined(I_X86_) && !(defined(_X86_) && !defined(__x86_64)) && !defined(_AMD64_) && defined(__ia64__) 56 | #if !defined(_IA64_) 57 | #define _IA64_ 58 | #endif 59 | #endif 60 | 61 | #ifndef RC_INVOKED 62 | #include 63 | #include 64 | #endif 65 | 66 | #include 67 | #include 68 | #include 69 | #include 70 | //gr #include 71 | #include 72 | #include 73 | #include 74 | //gr #include 75 | 76 | #ifndef WIN32_LEAN_AND_MEAN 77 | #include 78 | #include 79 | #include 80 | #include 81 | #include 82 | #include 83 | #include 84 | #include 85 | #include 86 | #include 87 | #include 88 | #ifndef NOCRYPT 89 | #include 90 | #include 91 | #include 92 | #endif 93 | 94 | #ifndef NOUSER 95 | #ifndef NOGDI 96 | #include 97 | #ifdef INC_OLE1 98 | #include 99 | #else 100 | #include 101 | #endif 102 | #include 103 | #endif 104 | #endif 105 | #endif 106 | 107 | //gr #include 108 | 109 | #ifdef INC_OLE2 110 | #include 111 | #endif 112 | 113 | #ifndef NOSERVICE 114 | #include 115 | #endif 116 | 117 | #ifndef NOMCX 118 | #include 119 | #endif 120 | 121 | #ifndef NOIME 122 | #include 123 | #endif 124 | 125 | #endif 126 | #endif 127 | #endif 128 | -------------------------------------------------------------------------------- /win32/lib/crt1.c: -------------------------------------------------------------------------------- 1 | // ============================================= 2 | // crt1.c 3 | 4 | // _UNICODE for tchar.h, UNICODE for API 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | #define _UNKNOWN_APP 0 11 | #define _CONSOLE_APP 1 12 | #define _GUI_APP 2 13 | 14 | #define _MCW_PC 0x00030000 // Precision Control 15 | #define _PC_24 0x00020000 // 24 bits 16 | #define _PC_53 0x00010000 // 53 bits 17 | #define _PC_64 0x00000000 // 64 bits 18 | 19 | typedef struct 20 | { 21 | int newmode; 22 | } _startupinfo; 23 | 24 | #ifdef _UNICODE 25 | #define __tgetmainargs __wgetmainargs 26 | #define _tstart _wstart 27 | #define _tmain wmain 28 | #define _runtmain _runwmain 29 | #else 30 | #define __tgetmainargs __getmainargs 31 | #define _tstart _start 32 | #define _tmain main 33 | #define _runtmain _runmain 34 | #endif 35 | 36 | int __cdecl __tgetmainargs(int *pargc, _TCHAR ***pargv, _TCHAR ***penv, int globb, _startupinfo*); 37 | void __cdecl __set_app_type(int apptype); 38 | unsigned int __cdecl _controlfp(unsigned int new_value, unsigned int mask); 39 | extern int _tmain(int argc, _TCHAR * argv[], _TCHAR * env[]); 40 | 41 | /* Allow command-line globbing with "int _dowildcard = 1;" in the user source */ 42 | int _dowildcard; 43 | 44 | void _tstart(void) 45 | { 46 | __TRY__ 47 | int argc, ret; 48 | _TCHAR **argv; 49 | _TCHAR **env; 50 | _startupinfo start_info; 51 | 52 | // Sets the current application type 53 | __set_app_type(_CONSOLE_APP); 54 | 55 | // Set default FP precision to 53 bits (8-byte double) 56 | // _MCW_PC (Precision control) is not supported on 57 | // the ARM and x64 architectures 58 | #ifdef __i386 59 | _controlfp(_PC_53, _MCW_PC); 60 | #endif 61 | 62 | start_info.newmode = 0; 63 | __tgetmainargs( &argc, &argv, &env, _dowildcard, &start_info); 64 | ret = _tmain(argc, argv, env); 65 | exit(ret); 66 | } 67 | 68 | int _runtmain(int argc, /* as tcc passed in */ char **argv) 69 | { 70 | #ifdef UNICODE 71 | int wargc; 72 | _TCHAR **wargv, **wenv; 73 | _startupinfo start_info = {0}; 74 | 75 | __tgetmainargs(&wargc, &wargv, &wenv, _dowildcard, &start_info); 76 | /* may be wrong when tcc has received wildcards (*.c) */ 77 | if (argc < wargc) 78 | wargv += wargc - argc; 79 | else 80 | argc = wargc; 81 | #define argv wargv 82 | #endif 83 | 84 | #ifdef __i386 85 | _controlfp(_PC_53, _MCW_PC); 86 | #endif 87 | return _tmain(argc, argv, _tenviron); 88 | } 89 | 90 | // ============================================= 91 | -------------------------------------------------------------------------------- /win32/lib/crt1w.c: -------------------------------------------------------------------------------- 1 | #define _UNICODE 1 2 | #define UNICODE 1 3 | #include "crt1.c" 4 | -------------------------------------------------------------------------------- /win32/lib/dllcrt1.c: -------------------------------------------------------------------------------- 1 | //+--------------------------------------------------------------------------- 2 | 3 | #include 4 | 5 | BOOL WINAPI DllMain (HINSTANCE hDll, DWORD dwReason, LPVOID lpReserved); 6 | 7 | BOOL WINAPI _dllstart(HINSTANCE hDll, DWORD dwReason, LPVOID lpReserved) 8 | { 9 | BOOL bRet; 10 | bRet = DllMain (hDll, dwReason, lpReserved); 11 | return bRet; 12 | } 13 | 14 | -------------------------------------------------------------------------------- /win32/lib/dllmain.c: -------------------------------------------------------------------------------- 1 | //+--------------------------------------------------------------------------- 2 | 3 | #include 4 | 5 | BOOL WINAPI DllMain (HINSTANCE hDll, DWORD dwReason, LPVOID lpReserved) 6 | { 7 | return TRUE; 8 | } 9 | 10 | -------------------------------------------------------------------------------- /win32/lib/wincrt1.c: -------------------------------------------------------------------------------- 1 | //+--------------------------------------------------------------------------- 2 | 3 | // _UNICODE for tchar.h, UNICODE for API 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | #define __UNKNOWN_APP 0 10 | #define __CONSOLE_APP 1 11 | #define __GUI_APP 2 12 | void __set_app_type(int); 13 | void _controlfp(unsigned a, unsigned b); 14 | 15 | #ifdef _UNICODE 16 | #define __tgetmainargs __wgetmainargs 17 | #define _twinstart _wwinstart 18 | #define _runtwinmain _runwwinmain 19 | int APIENTRY wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int); 20 | #else 21 | #define __tgetmainargs __getmainargs 22 | #define _twinstart _winstart 23 | #define _runtwinmain _runwinmain 24 | #endif 25 | 26 | typedef struct 27 | { 28 | int newmode; 29 | } _startupinfo; // CLI Vs GUI 30 | 31 | int __cdecl __tgetmainargs(int *pargc, _TCHAR ***pargv, _TCHAR ***penv, int globb, _startupinfo*); 32 | 33 | int _twinstart(void) 34 | { 35 | __TRY__ 36 | _TCHAR *szCmd; 37 | STARTUPINFO startinfo; 38 | int fShow; 39 | int ret; 40 | 41 | __set_app_type(__GUI_APP); 42 | _controlfp(0x10000, 0x30000); 43 | 44 | szCmd = GetCommandLine(); 45 | if (szCmd) { 46 | while (__T(' ') == *szCmd) 47 | szCmd++; 48 | if (__T('\"') == *szCmd) { 49 | while (*++szCmd) 50 | if (__T('\"') == *szCmd) { 51 | szCmd++; 52 | break; 53 | } 54 | } else { 55 | while (*szCmd && __T(' ') != *szCmd) 56 | szCmd++; 57 | } 58 | while (__T(' ') == *szCmd) 59 | szCmd++; 60 | } 61 | 62 | GetStartupInfo(&startinfo); 63 | fShow = startinfo.wShowWindow; 64 | if (0 == (startinfo.dwFlags & STARTF_USESHOWWINDOW)) 65 | fShow = SW_SHOWDEFAULT; 66 | 67 | ret = _tWinMain(GetModuleHandle(NULL), NULL, szCmd, fShow); 68 | exit(ret); 69 | } 70 | 71 | int _runtwinmain(int argc, /* as tcc passed in */ char **argv) 72 | { 73 | _TCHAR *szCmd, *p; 74 | 75 | #ifdef UNICODE 76 | int wargc; 77 | _TCHAR **wargv, **wenv; 78 | _startupinfo start_info = {0}; 79 | 80 | __tgetmainargs(&wargc, &wargv, &wenv, 0, &start_info); 81 | if (argc < wargc) 82 | wargv += wargc - argc; 83 | else 84 | argc = wargc; 85 | #define argv wargv 86 | #endif 87 | 88 | p = GetCommandLine(); 89 | szCmd = NULL; 90 | if (argc > 1) 91 | szCmd = _tcsstr(p, argv[1]); 92 | if (NULL == szCmd) 93 | szCmd = __T(""); 94 | else if (szCmd > p && szCmd[-1] == __T('\"')) 95 | --szCmd; 96 | _controlfp(0x10000, 0x30000); 97 | return _tWinMain(GetModuleHandle(NULL), NULL, szCmd, SW_SHOWDEFAULT); 98 | } 99 | -------------------------------------------------------------------------------- /win32/lib/wincrt1w.c: -------------------------------------------------------------------------------- 1 | #define _UNICODE 1 2 | #define UNICODE 1 3 | #include "wincrt1.c" 4 | --------------------------------------------------------------------------------