├── VERSION ├── tests ├── tests2 │ ├── 43_void_param.expect │ ├── 48_nested_break.expect │ ├── 64_macro_nesting.expect │ ├── 27_sizeof.expect │ ├── 29_array_address.expect │ ├── 35_sizeof.expect │ ├── 57_btype_excess-2.c │ ├── 18_include.h │ ├── 61_undefined_enum.c │ ├── 63_local_enumerator_redefinition.expect │ ├── 00_assignment.expect │ ├── 12_hashdefine.expect │ ├── 14_if.expect │ ├── 39_typedef.expect │ ├── 42_function_pointer.expect │ ├── 55_lshift_type.expect │ ├── 56_btype_excess-1.c │ ├── 44_scoped_declarations.expect │ ├── 47_switch_return.expect │ ├── 59_function_array.c │ ├── 07_function.expect │ ├── 17_enum.expect │ ├── 18_include.expect │ ├── 49_bracket_evaluation.expect │ ├── 67_macro_concat.expect │ ├── 03_struct.expect │ ├── 34_array_assignment.expect │ ├── 06_case.expect │ ├── 41_hashif.expect │ ├── 66_macro_concat_end.c │ ├── 01_comment.expect │ ├── 19_pointer_arithmetic.expect │ ├── 20_pointer_comparison.expect │ ├── 65_macro_concat_start.c │ ├── 13_integer_literals.expect │ ├── 56_btype_excess-1.expect │ ├── 57_btype_excess-2.expect │ ├── 04_for.expect │ ├── 61_undefined_enum.expect │ ├── 26_character_constants.expect │ ├── 51_static.expect │ ├── 05_array.expect │ ├── 45_empty_for.expect │ ├── 46_grep.expect │ ├── 58_function_redefinition.expect │ ├── 59_function_array.expect │ ├── 66_macro_concat_end.expect │ ├── 08_while.expect │ ├── 33_ternary_op.expect │ ├── 60_enum_redefinition.expect │ ├── 65_macro_concat_start.expect │ ├── 09_do_while.expect │ ├── 52_unnamed_enum.expect │ ├── 38_multiple_array_index.expect │ ├── 60_enum_redefinition.c │ ├── 62_enumerator_redefinition.expect │ ├── 15_recursion.expect │ ├── 21_char_array.expect │ ├── 31_args.expect │ ├── 54_goto.expect │ ├── 68_macro_param_list_err_1.expect │ ├── 69_macro_param_list_err_2.expect │ ├── 32_led.expect │ ├── 62_enumerator_redefinition.c │ ├── 25_quicksort.expect │ ├── 58_function_redefinition.c │ ├── 11_precedence.expect │ ├── 10_pointer.expect │ ├── 28_strings.expect │ ├── 50_logical_second_arg.expect │ ├── 23_type_coercion.expect │ ├── 16_nesting.expect │ ├── 64_macro_nesting.c │ ├── 63_local_enumerator_redefinition.c │ ├── 68_macro_param_list_err_1.c │ ├── 69_macro_param_list_err_2.c │ ├── 43_void_param.c │ ├── 18_include.c │ ├── 37_sprintf.expect │ ├── 36_array_initialisers.expect │ ├── 29_array_address.c │ ├── 22_floating_point.expect │ ├── 04_for.c │ ├── 24_math_library.expect │ ├── 35_sizeof.c │ ├── 02_printf.expect │ ├── 44_scoped_declarations.c │ ├── 12_hashdefine.c │ ├── 27_sizeof.c │ ├── 33_ternary_op.c │ ├── 42_function_pointer.c │ ├── 45_empty_for.c │ ├── 67_macro_concat.c │ ├── 00_assignment.c │ ├── 31_args.c │ ├── 37_sprintf.c │ ├── 01_comment.c │ ├── 08_while.c │ ├── 09_do_while.c │ ├── 14_if.c │ ├── 15_recursion.c │ ├── 16_nesting.c │ ├── 26_character_constants.c │ ├── 05_array.c │ ├── 13_integer_literals.c │ ├── 34_array_assignment.c │ ├── 47_switch_return.c │ ├── 40_stdio.expect │ ├── 48_nested_break.c │ ├── 02_printf.c │ ├── 07_function.c │ ├── 49_bracket_evaluation.c │ ├── 20_pointer_comparison.c │ ├── 17_enum.c │ ├── 19_pointer_arithmetic.c │ ├── 36_array_initialisers.c │ ├── 51_static.c │ ├── 52_unnamed_enum.c │ ├── 06_case.c │ ├── 39_typedef.c │ ├── 38_multiple_array_index.c │ ├── 21_char_array.c │ ├── 03_struct.c │ ├── 50_logical_second_arg.c │ ├── 24_math_library.c │ ├── 10_pointer.c │ ├── 54_goto.c │ ├── 11_precedence.c │ ├── 23_type_coercion.c │ ├── 28_strings.c │ ├── 40_stdio.c │ ├── 41_hashif.c │ ├── 22_floating_point.c │ ├── 25_quicksort.c │ ├── 55_lshift_type.c │ ├── 30_hanoi.expect │ ├── LICENSE │ ├── Makefile │ └── 30_hanoi.c ├── tcctest.py ├── gcctestsuite.sh ├── libtcc_test.c ├── vla_test.c └── boundtest.c ├── config.texi.in ├── Changelog ├── arm-gen.c ├── i386-asm.c ├── RELICENSING ├── examples ├── ex5.c ├── ex1.c ├── ex3.c ├── ex4.c └── ex2.c ├── win32 ├── include │ ├── values.h │ ├── winapi │ │ ├── specstrings.h │ │ ├── poppack.h │ │ ├── pshpack1.h │ │ ├── pshpack2.h │ │ ├── pshpack4.h │ │ ├── pshpack8.h │ │ ├── intrin.h │ │ ├── tvout.h │ │ ├── windows.h │ │ ├── basetyps.h │ │ ├── reason.h │ │ └── guiddef.h │ ├── vadefs.h │ ├── mem.h │ ├── sys │ │ ├── unistd.h │ │ ├── fcntl.h │ │ ├── file.h │ │ ├── locking.h │ │ ├── time.h │ │ ├── types.h │ │ ├── timeb.h │ │ └── utime.h │ ├── sec_api │ │ ├── crtdbg_s.h │ │ ├── sys │ │ │ └── timeb_s.h │ │ ├── search_s.h │ │ ├── stralign_s.h │ │ ├── io_s.h │ │ ├── conio_s.h │ │ ├── string_s.h │ │ ├── time_s.h │ │ ├── mbstring_s.h │ │ └── stdlib_s.h │ ├── share.h │ ├── dir.h │ ├── dos.h │ ├── memory.h │ ├── fcntl.h │ ├── assert.h │ ├── errno.h │ ├── signal.h │ ├── direct.h │ ├── locale.h │ ├── limits.h │ ├── fenv.h │ ├── dirent.h │ ├── _mingw.h │ ├── excpt.h │ └── setjmp.h ├── lib │ ├── dllmain.c │ ├── dllcrt1.c │ ├── crt1.c │ └── wincrt1.c ├── examples │ ├── dll.c │ ├── fib.c │ └── hello_dll.c └── build-tcc.bat ├── config.h.in ├── include ├── stdbool.h ├── varargs.h ├── stddef.h ├── float.h └── stdarg.h ├── lib ├── alloca-arm.S ├── alloca86.S ├── alloca86_64.S ├── alloca86-bt.S └── Makefile ├── stab.h ├── .gitignore ├── conftest.c ├── README.md ├── tcclib.h ├── README ├── TODO └── libtcc.h /VERSION: -------------------------------------------------------------------------------- 1 | 0.9.26 2 | -------------------------------------------------------------------------------- /tests/tests2/43_void_param.expect: -------------------------------------------------------------------------------- 1 | yo 2 | -------------------------------------------------------------------------------- /tests/tests2/48_nested_break.expect: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /tests/tests2/64_macro_nesting.expect: -------------------------------------------------------------------------------- 1 | 42 2 | -------------------------------------------------------------------------------- /config.texi.in: -------------------------------------------------------------------------------- 1 | @set VERSION ${TCC_VERSION} 2 | -------------------------------------------------------------------------------- /tests/tests2/27_sizeof.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 4 3 | 8 4 | -------------------------------------------------------------------------------- /tests/tests2/29_array_address.expect: -------------------------------------------------------------------------------- 1 | bcdef 2 | -------------------------------------------------------------------------------- /tests/tests2/35_sizeof.expect: -------------------------------------------------------------------------------- 1 | 1 1 2 | 2 2 3 | -------------------------------------------------------------------------------- /tests/tests2/57_btype_excess-2.c: -------------------------------------------------------------------------------- 1 | char int i; 2 | -------------------------------------------------------------------------------- /tests/tests2/18_include.h: -------------------------------------------------------------------------------- 1 | printf("included\n"); 2 | -------------------------------------------------------------------------------- /tests/tests2/61_undefined_enum.c: -------------------------------------------------------------------------------- 1 | enum rgb c = 42; 2 | -------------------------------------------------------------------------------- /tests/tests2/63_local_enumerator_redefinition.expect: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/tests2/00_assignment.expect: -------------------------------------------------------------------------------- 1 | 42 2 | 64 3 | 12, 34 4 | -------------------------------------------------------------------------------- /tests/tests2/12_hashdefine.expect: -------------------------------------------------------------------------------- 1 | 12 2 | 12, 24, 36 3 | -------------------------------------------------------------------------------- /tests/tests2/14_if.expect: -------------------------------------------------------------------------------- 1 | a is true 2 | b is false 3 | -------------------------------------------------------------------------------- /tests/tests2/39_typedef.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 12,34 3 | 12,34 4 | -------------------------------------------------------------------------------- /tests/tests2/42_function_pointer.expect: -------------------------------------------------------------------------------- 1 | yo 24 2 | 42 3 | -------------------------------------------------------------------------------- /tests/tests2/55_lshift_type.expect: -------------------------------------------------------------------------------- 1 | 0 test(s) failed 2 | -------------------------------------------------------------------------------- /tests/tests2/56_btype_excess-1.c: -------------------------------------------------------------------------------- 1 | struct A {} int i; 2 | -------------------------------------------------------------------------------- /tests/tests2/44_scoped_declarations.expect: -------------------------------------------------------------------------------- 1 | it's all good 2 | -------------------------------------------------------------------------------- /tests/tests2/47_switch_return.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | out 4 | 3 5 | -------------------------------------------------------------------------------- /tests/tests2/59_function_array.c: -------------------------------------------------------------------------------- 1 | int (*fct)[42](int x); 2 | -------------------------------------------------------------------------------- /tests/tests2/07_function.expect: -------------------------------------------------------------------------------- 1 | 9 2 | 16 3 | a=1234 4 | qfunc() 5 | -------------------------------------------------------------------------------- /tests/tests2/17_enum.expect: -------------------------------------------------------------------------------- 1 | 0 1 2 3 54 73 74 75 2 | 12 3 | 54 4 | -------------------------------------------------------------------------------- /tests/tests2/18_include.expect: -------------------------------------------------------------------------------- 1 | including 2 | included 3 | done 4 | -------------------------------------------------------------------------------- /tests/tests2/49_bracket_evaluation.expect: -------------------------------------------------------------------------------- 1 | 12.340000, 56.780000 2 | -------------------------------------------------------------------------------- /tests/tests2/67_macro_concat.expect: -------------------------------------------------------------------------------- 1 | jim: 21, bob: 42 2 | jim: 63 3 | -------------------------------------------------------------------------------- /Changelog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gfwilliams/tinycc/HEAD/Changelog -------------------------------------------------------------------------------- /arm-gen.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gfwilliams/tinycc/HEAD/arm-gen.c -------------------------------------------------------------------------------- /i386-asm.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gfwilliams/tinycc/HEAD/i386-asm.c -------------------------------------------------------------------------------- /tests/tests2/03_struct.expect: -------------------------------------------------------------------------------- 1 | 12 2 | 34 3 | 12 4 | 34 5 | 56 6 | 78 7 | -------------------------------------------------------------------------------- /tests/tests2/34_array_assignment.expect: -------------------------------------------------------------------------------- 1 | 12 23 34 45 2 | 12 23 34 45 3 | -------------------------------------------------------------------------------- /RELICENSING: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gfwilliams/tinycc/HEAD/RELICENSING -------------------------------------------------------------------------------- /tests/tests2/06_case.expect: -------------------------------------------------------------------------------- 1 | 0 2 | 0 3 | 1 4 | 1 5 | 2 6 | 2 7 | 3 8 | 0 9 | -------------------------------------------------------------------------------- /tests/tests2/41_hashif.expect: -------------------------------------------------------------------------------- 1 | #include test 2 | b 3 | g 4 | i 5 | p 6 | r 7 | -------------------------------------------------------------------------------- /tests/tests2/66_macro_concat_end.c: -------------------------------------------------------------------------------- 1 | #define paste(A,B) A B## 2 | paste(x,y) 3 | -------------------------------------------------------------------------------- /tests/tests2/01_comment.expect: -------------------------------------------------------------------------------- 1 | Hello 2 | Hello 3 | Hello 4 | Hello 5 | Hello 6 | -------------------------------------------------------------------------------- /tests/tests2/19_pointer_arithmetic.expect: -------------------------------------------------------------------------------- 1 | 42 2 | b is not NULL 3 | c is NULL 4 | -------------------------------------------------------------------------------- /tests/tests2/20_pointer_comparison.expect: -------------------------------------------------------------------------------- 1 | 12 2 | 34 3 | 0 4 | 1 5 | 1 6 | 0 7 | -------------------------------------------------------------------------------- /tests/tests2/65_macro_concat_start.c: -------------------------------------------------------------------------------- 1 | #define paste(A,B) ##A B 2 | paste(x,y) 3 | -------------------------------------------------------------------------------- /tests/tests2/13_integer_literals.expect: -------------------------------------------------------------------------------- 1 | 24680 2 | 342391 3 | 2386092 4 | 2386092 5 | 1365 6 | -------------------------------------------------------------------------------- /tests/tests2/56_btype_excess-1.expect: -------------------------------------------------------------------------------- 1 | 56_btype_excess-1.c:1: error: too many basic types 2 | -------------------------------------------------------------------------------- /tests/tests2/57_btype_excess-2.expect: -------------------------------------------------------------------------------- 1 | 57_btype_excess-2.c:1: error: too many basic types 2 | -------------------------------------------------------------------------------- /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/61_undefined_enum.expect: -------------------------------------------------------------------------------- 1 | 61_undefined_enum.c:1: error: unknown struct/union/enum 2 | -------------------------------------------------------------------------------- /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/51_static.expect: -------------------------------------------------------------------------------- 1 | 1234 2 | 4567 3 | 4568 4 | 4569 5 | 4570 6 | 1234 7 | 8901 8 | 2345 9 | -------------------------------------------------------------------------------- /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/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/58_function_redefinition.expect: -------------------------------------------------------------------------------- 1 | 58_function_redefinition.c:7: error: redefinition of 'f' 2 | -------------------------------------------------------------------------------- /tests/tests2/59_function_array.expect: -------------------------------------------------------------------------------- 1 | 59_function_array.c:1: error: declaration of an array of functions 2 | -------------------------------------------------------------------------------- /tests/tests2/66_macro_concat_end.expect: -------------------------------------------------------------------------------- 1 | 66_macro_concat_end.c:2: error: '##' invalid at end of macro 2 | -------------------------------------------------------------------------------- /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/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/60_enum_redefinition.expect: -------------------------------------------------------------------------------- 1 | 60_enum_redefinition.c:2: error: struct/union/enum already defined 2 | -------------------------------------------------------------------------------- /tests/tests2/65_macro_concat_start.expect: -------------------------------------------------------------------------------- 1 | 65_macro_concat_start.c:1: error: '##' invalid at start of macro 2 | -------------------------------------------------------------------------------- /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/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/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/60_enum_redefinition.c: -------------------------------------------------------------------------------- 1 | enum color {RED, GREEN, BLUE}; 2 | enum color {R, G, B}; 3 | 4 | enum color c; 5 | -------------------------------------------------------------------------------- /tests/tests2/62_enumerator_redefinition.expect: -------------------------------------------------------------------------------- 1 | 62_enumerator_redefinition.c:2: error: redefinition of enumerator 'RED' 2 | -------------------------------------------------------------------------------- /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/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/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/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/68_macro_param_list_err_1.expect: -------------------------------------------------------------------------------- 1 | 68_macro_param_list_err_1.c:2: error: '(' may not appear in parameter list 2 | -------------------------------------------------------------------------------- /tests/tests2/69_macro_param_list_err_2.expect: -------------------------------------------------------------------------------- 1 | 69_macro_param_list_err_2.c:2: error: '/' may not appear in parameter list 2 | -------------------------------------------------------------------------------- /tests/tests2/32_led.expect: -------------------------------------------------------------------------------- 1 | _ _ _ _ 2 | | _| _| |_| |_ |_ | 3 | | |_ _| | _| |_| | 4 | 5 | -------------------------------------------------------------------------------- /tests/tests2/62_enumerator_redefinition.c: -------------------------------------------------------------------------------- 1 | enum color {RED, GREEN, BLUE}; 2 | enum rgb {RED, G, B}; 3 | 4 | enum color c = RED; 5 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /examples/ex5.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | printf("Hello World\n"); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /tests/tests2/58_function_redefinition.c: -------------------------------------------------------------------------------- 1 | int f(void) 2 | { 3 | return 0; 4 | } 5 | 6 | int f(void) 7 | { 8 | return 1; 9 | } 10 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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/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/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 | -------------------------------------------------------------------------------- /config.h.in: -------------------------------------------------------------------------------- 1 | #define CONFIG_TCCDIR "${CONFIG_TCCDIR}" 2 | #define TCC_VERSION "${TCC_VERSION}" 3 | 4 | #cmakedefine CONFIG_WIN32 5 | #cmakedefine CONFIG_WIN64 6 | #cmakedefine CONFIG_TCC_BCHECK 7 | #cmakedefine CONFIG_TCC_ASSERT 8 | -------------------------------------------------------------------------------- /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/64_macro_nesting.c: -------------------------------------------------------------------------------- 1 | #define CAT2(a,b) a##b 2 | #define CAT(a,b) CAT2(a,b) 3 | #define AB(x) CAT(x,y) 4 | 5 | int main(void) 6 | { 7 | int xy = 42; 8 | printf("%d\n", CAT(A,B)(x)); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/tests2/63_local_enumerator_redefinition.c: -------------------------------------------------------------------------------- 1 | enum { 2 | FOO, 3 | BAR 4 | }; 5 | 6 | int main(void) 7 | { 8 | enum { 9 | FOO = 2, 10 | BAR 11 | }; 12 | 13 | return BAR - FOO; 14 | } 15 | -------------------------------------------------------------------------------- /tests/tests2/68_macro_param_list_err_1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define hexCh(c (c >= 10 ? 'a' + c - 10 : '0' + c) 3 | 4 | int main(void) 5 | { 6 | int c = 0xa; 7 | printf("hex: %c\n", hexCh(c)); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/tests2/69_macro_param_list_err_2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define hexCh(c/3) (c >= 10 ? 'a' + c - 10 : '0' + c) 3 | 4 | int main(void) 5 | { 6 | int c = 0xa; 7 | printf("hex: %c\n", hexCh(c)); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /lib/alloca-arm.S: -------------------------------------------------------------------------------- 1 | .text 2 | .align 2 3 | .global alloca 4 | .type alloca, %function 5 | alloca: 6 | rsb sp, r0, sp 7 | bic sp, sp, #7 8 | mov r0, sp 9 | mov pc, lr 10 | .size alloca, .-alloca 11 | .section .note.GNU-stack,"",%progbits 12 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /win32/lib/dllmain.c: -------------------------------------------------------------------------------- 1 | //+--------------------------------------------------------------------------- 2 | 3 | #include 4 | 5 | BOOL WINAPI DllMain (HANDLE hDll, DWORD dwReason, LPVOID lpReserved) 6 | { 7 | return TRUE; 8 | } 9 | 10 | -------------------------------------------------------------------------------- /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/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/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/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/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/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 | -------------------------------------------------------------------------------- /win32/include/winapi/specstrings.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 | #define __specstrings 8 | -------------------------------------------------------------------------------- /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/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/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/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/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 | return 0; 14 | } 15 | 16 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 17 | -------------------------------------------------------------------------------- /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/42_function_pointer.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int fred(int p) 4 | { 5 | printf("yo %d\n", p); 6 | return 42; 7 | } 8 | 9 | int (*f)(int) = &fred; 10 | 11 | int main() 12 | { 13 | printf("%d\n", (*f)(24)); 14 | 15 | return 0; 16 | } 17 | 18 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 19 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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/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/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 | -------------------------------------------------------------------------------- /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/examples/dll.c: -------------------------------------------------------------------------------- 1 | //+--------------------------------------------------------------------------- 2 | // 3 | // dll.c - Windows DLL example - dynamically linked part 4 | // 5 | 6 | #include 7 | #define DLL_EXPORT __declspec(dllexport) 8 | 9 | DLL_EXPORT void HelloWorld (void) 10 | { 11 | MessageBox (0, "Hello World!", "From DLL", MB_ICONINFORMATION); 12 | } 13 | -------------------------------------------------------------------------------- /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/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/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 | -------------------------------------------------------------------------------- /win32/include/winapi/intrin.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 __INTRIN_H_ 7 | #define __INTRIN_H_ 8 | 9 | //!__TINYC__: intrinsic stuff removed 10 | 11 | #endif /* end __INTRIN_H_ */ 12 | -------------------------------------------------------------------------------- /win32/lib/dllcrt1.c: -------------------------------------------------------------------------------- 1 | //+--------------------------------------------------------------------------- 2 | 3 | #include 4 | 5 | BOOL WINAPI DllMain (HANDLE hDll, DWORD dwReason, LPVOID lpReserved); 6 | 7 | BOOL WINAPI _dllstart(HANDLE hDll, DWORD dwReason, LPVOID lpReserved) 8 | { 9 | BOOL bRet; 10 | bRet = DllMain (hDll, dwReason, lpReserved); 11 | return bRet; 12 | } 13 | 14 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /win32/examples/fib.c: -------------------------------------------------------------------------------- 1 | #include 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)); 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /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/examples/hello_dll.c: -------------------------------------------------------------------------------- 1 | //+--------------------------------------------------------------------------- 2 | // 3 | // HELLO_DLL.C - Windows DLL example - main application part 4 | // 5 | 6 | #include 7 | 8 | void HelloWorld (void); 9 | 10 | int WINAPI WinMain( 11 | HINSTANCE hInstance, 12 | HINSTANCE hPrevInstance, 13 | LPSTR lpCmdLine, 14 | int nCmdShow) 15 | { 16 | HelloWorld(); 17 | return 0; 18 | } 19 | 20 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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/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/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/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/tcctest.py: -------------------------------------------------------------------------------- 1 | import subprocess 2 | import sys 3 | import difflib 4 | 5 | def main(): 6 | reference = subprocess.check_output([sys.argv[1]]) 7 | compare = subprocess.check_output(sys.argv[2:]) 8 | failed = False 9 | for line in difflib.unified_diff(reference.split('\n'), compare.split('\n'), fromfile='cc', tofile='tcc', lineterm=''): 10 | failed = True 11 | print line 12 | sys.exit(1 if failed else 0) 13 | 14 | if __name__ == '__main__': 15 | main() 16 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /examples/ex3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 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, 2)); 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /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 | int main() 16 | { 17 | enum fred frod; 18 | 19 | printf("%d %d %d %d %d %d %d %d\n", a, b, c, d, e, f, g, h); 20 | /* printf("%d\n", frod); */ 21 | frod = 12; 22 | printf("%d\n", frod); 23 | frod = e; 24 | printf("%d\n", frod); 25 | 26 | return 0; 27 | } 28 | 29 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 30 | -------------------------------------------------------------------------------- /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/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/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/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 32 | -------------------------------------------------------------------------------- /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/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/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/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 TCC_TARGET_PE 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 | /* mark stack as nonexecutable */ 32 | #if defined __ELF__ && defined __linux__ 33 | .section .note.GNU-stack,"",@progbits 34 | #endif 35 | /* ---------------------------------------------- */ 36 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /tests/tests2/24_math_library.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | printf("%f\n", sin(0.12)); 7 | printf("%f\n", cos(0.12)); 8 | printf("%f\n", tan(0.12)); 9 | printf("%f\n", asin(0.12)); 10 | printf("%f\n", acos(0.12)); 11 | printf("%f\n", atan(0.12)); 12 | printf("%f\n", sinh(0.12)); 13 | printf("%f\n", cosh(0.12)); 14 | printf("%f\n", tanh(0.12)); 15 | printf("%f\n", exp(0.12)); 16 | printf("%f\n", fabs(-0.12)); 17 | printf("%f\n", log(0.12)); 18 | printf("%f\n", log10(0.12)); 19 | printf("%f\n", pow(0.12, 0.12)); 20 | printf("%f\n", sqrt(0.12)); 21 | printf("%f\n", round(12.34)); 22 | printf("%f\n", ceil(12.34)); 23 | printf("%f\n", floor(12.34)); 24 | 25 | return 0; 26 | } 27 | 28 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 29 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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/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 | -------------------------------------------------------------------------------- /lib/alloca86_64.S: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------- */ 2 | /* alloca86_64.S */ 3 | 4 | .globl alloca 5 | 6 | alloca: 7 | pop %rdx 8 | #ifdef TCC_TARGET_PE 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 TCC_TARGET_PE 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 | #ifdef TCC_TARGET_PE 31 | add $32,%rax 32 | #endif 33 | 34 | p3: 35 | push %rdx 36 | ret 37 | 38 | /* mark stack as nonexecutable */ 39 | #if defined __ELF__ && defined __linux__ 40 | .section .note.GNU-stack,"",@progbits 41 | #endif 42 | /* ---------------------------------------------- */ 43 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.a 3 | tcc_g 4 | tcc 5 | /*-tcc 6 | tc2.c 7 | doc 8 | tc3s.c 9 | p3.c 10 | tc1.c 11 | error.c 12 | i386-gen1.c 13 | test.out1 14 | test.out1b 15 | test.out2 16 | test.out2b 17 | test.out3 18 | test.out3b 19 | web.sh 20 | memdebug.c 21 | bench 22 | Makefile.uClibc 23 | boundtest 24 | prog.ref 25 | test.ref 26 | test.out 27 | tcc-doc.html 28 | ideas 29 | tcctest.ref 30 | linux.tcc 31 | ldtest 32 | libtcc_test 33 | instr.S 34 | p.c 35 | p2.c 36 | tcctest[1234] 37 | test[1234].out 38 | tests/tcclib.h 39 | tests/tcctest.cc 40 | tests/weaktest.*.o.txt 41 | tests/tests2/fred.txt 42 | tests/tests2/*.exe 43 | tests/hello 44 | tests/abitest-*cc 45 | tests/vla_test 46 | .gdb_history 47 | tcc.1 48 | tcc.pod 49 | config.h 50 | config.mak 51 | config.texi 52 | tags 53 | .DS_Store 54 | *.swp 55 | lib/x86_64 56 | lib/i386 57 | lib/x86_64-win32 58 | lib/i386-win32 59 | lib/arm 60 | tcc-doc.info 61 | conftest* 62 | tiny_libmaker 63 | *.dSYM 64 | *~ 65 | 66 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 TCC_TARGET_PE 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 | -------------------------------------------------------------------------------- /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/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/lib/crt1.c: -------------------------------------------------------------------------------- 1 | // ============================================= 2 | // crt1.c 3 | 4 | #include 5 | 6 | #define __UNKNOWN_APP 0 7 | #define __CONSOLE_APP 1 8 | #define __GUI_APP 2 9 | void __set_app_type(int); 10 | void _controlfp(unsigned a, unsigned b); 11 | 12 | typedef struct 13 | { 14 | int newmode; 15 | } _startupinfo; 16 | 17 | int __getmainargs(int *pargc, char ***pargv, char ***penv, int globb, _startupinfo*); 18 | int main(int argc, char **argv, char **env); 19 | 20 | int _start(void) 21 | { 22 | __TRY__ 23 | int argc; char **argv; char **env; 24 | _startupinfo start_info = {0}; 25 | 26 | _controlfp(0x10000, 0x30000); 27 | __set_app_type(__CONSOLE_APP); 28 | 29 | if (! __getmainargs(&argc, &argv, &env, 0, &start_info)) 30 | { 31 | int ret; 32 | 33 | ret = main(argc, argv, env); 34 | exit(ret); 35 | } 36 | // __getmainargs failed because possible few memory on the heap. 37 | // end with exit code of 3, similar to abort() 38 | ExitProcess(3); 39 | } 40 | 41 | // ============================================= 42 | -------------------------------------------------------------------------------- /tests/tests2/28_strings.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | char a[10]; 8 | 9 | strcpy(a, "hello"); 10 | printf("%s\n", a); 11 | 12 | strncpy(a, "gosh", 2); 13 | printf("%s\n", a); 14 | 15 | printf("%d\n", strcmp(a, "apple") > 0); 16 | printf("%d\n", strcmp(a, "goere") > 0); 17 | printf("%d\n", strcmp(a, "zebra") < 0); 18 | 19 | printf("%d\n", strlen(a)); 20 | 21 | strcat(a, "!"); 22 | printf("%s\n", a); 23 | 24 | printf("%d\n", strncmp(a, "apple", 2) > 0); 25 | printf("%d\n", strncmp(a, "goere", 2) == 0); 26 | printf("%d\n", strncmp(a, "goerg", 2) == 0); 27 | printf("%d\n", strncmp(a, "zebra", 2) < 0); 28 | 29 | printf("%s\n", index(a, 'o')); 30 | printf("%s\n", rindex(a, 'l')); 31 | printf("%d\n", rindex(a, 'x') == NULL); 32 | 33 | memset(&a[1], 'r', 4); 34 | printf("%s\n", a); 35 | 36 | memcpy(&a[2], a, 2); 37 | printf("%s\n", a); 38 | 39 | printf("%d\n", memcmp(a, "apple", 4) > 0); 40 | printf("%d\n", memcmp(a, "grgr", 4) == 0); 41 | printf("%d\n", memcmp(a, "zebra", 4) < 0); 42 | 43 | return 0; 44 | } 45 | 46 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 47 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | typedef signed long long int int64_t; 17 | typedef unsigned char uint8_t; 18 | typedef unsigned short int uint16_t; 19 | typedef unsigned int uint32_t; 20 | typedef unsigned long long int uint64_t; 21 | #endif 22 | 23 | #define NULL ((void*)0) 24 | #define offsetof(type, field) ((size_t)&((type *)0)->field) 25 | 26 | void *alloca(size_t size); 27 | 28 | #endif 29 | 30 | /* Older glibc require a wint_t from (when requested 31 | by __need_wint_t, as otherwise stddef.h isn't allowed to 32 | define this type). Note that this must be outside the normal 33 | _STDDEF_H guard, so that it works even when we've included the file 34 | already (without requiring wint_t). Some other libs define _WINT_T 35 | if they've already provided that type, so we can use that as guard. 36 | TCC defines __WINT_TYPE__ for us. */ 37 | #if defined (__need_wint_t) 38 | #ifndef _WINT_T 39 | #define _WINT_T 40 | typedef __WINT_TYPE__ wint_t; 41 | #endif 42 | #undef __need_wint_t 43 | #endif 44 | -------------------------------------------------------------------------------- /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/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 | extern void __cdecl _wassert(const wchar_t *_Message,const wchar_t *_File,unsigned _Line); 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | #ifndef assert 49 | #define assert(_Expression) (void)((!!(_Expression)) || (_wassert(_CRT_WIDE(#_Expression),_CRT_WIDE(__FILE__),__LINE__),0)) 50 | #endif 51 | 52 | #endif 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /win32/lib/wincrt1.c: -------------------------------------------------------------------------------- 1 | //+--------------------------------------------------------------------------- 2 | 3 | #include 4 | #include 5 | 6 | #define __UNKNOWN_APP 0 7 | #define __CONSOLE_APP 1 8 | #define __GUI_APP 2 9 | void __set_app_type(int); 10 | void _controlfp(unsigned a, unsigned b); 11 | 12 | int _winstart(void) 13 | { 14 | __TRY__ 15 | char *szCmd; 16 | STARTUPINFO startinfo; 17 | int fShow; 18 | int ret; 19 | 20 | __set_app_type(__GUI_APP); 21 | _controlfp(0x10000, 0x30000); 22 | 23 | szCmd = GetCommandLine(); 24 | if (szCmd) { 25 | while (' ' == *szCmd) 26 | szCmd++; 27 | if ('\"' == *szCmd) { 28 | while (*++szCmd) 29 | if ('\"' == *szCmd) { 30 | szCmd++; 31 | break; 32 | } 33 | } else { 34 | while (*szCmd && ' ' != *szCmd) 35 | szCmd++; 36 | } 37 | while (' ' == *szCmd) 38 | szCmd++; 39 | } 40 | 41 | GetStartupInfo(&startinfo); 42 | fShow = startinfo.wShowWindow; 43 | if (0 == (startinfo.dwFlags & STARTF_USESHOWWINDOW)) 44 | fShow = SW_SHOWDEFAULT; 45 | 46 | ret = WinMain(GetModuleHandle(NULL), NULL, szCmd, fShow); 47 | exit(ret); 48 | } 49 | 50 | int _runwinmain(int argc, char **argv) 51 | { 52 | char *szCmd, *p; 53 | 54 | p = GetCommandLine(); 55 | szCmd = NULL; 56 | if (argc > 1) 57 | szCmd = strstr(p, argv[1]); 58 | if (NULL == szCmd) 59 | szCmd = ""; 60 | else if (szCmd > p && szCmd[-1] == '\"') 61 | --szCmd; 62 | _controlfp(0x10000, 0x30000); 63 | return WinMain(GetModuleHandle(NULL), NULL, szCmd, SW_SHOWDEFAULT); 64 | } 65 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /conftest.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* Define architecture */ 4 | #if defined(__i386__) 5 | # define TRIPLET_ARCH "i386" 6 | #elif defined(__x86_64__) 7 | # define TRIPLET_ARCH "x86_64" 8 | #elif defined(__arm__) 9 | # define TRIPLET_ARCH "arm" 10 | #else 11 | # define TRIPLET_ARCH "unknown" 12 | #endif 13 | 14 | /* Define OS */ 15 | #if defined (__linux__) 16 | # define TRIPLET_OS "linux" 17 | #elif defined (__FreeBSD__) || defined (__FreeBSD_kernel__) 18 | # define TRIPLET_OS "kfreebsd" 19 | #elif !defined (__GNU__) 20 | # define TRIPLET_OS "unknown" 21 | #endif 22 | 23 | /* Define calling convention and ABI */ 24 | #if defined (__ARM_EABI__) 25 | # if defined (__ARM_PCS_VFP) 26 | # define TRIPLET_ABI "gnueabihf" 27 | # else 28 | # define TRIPLET_ABI "gnueabi" 29 | # endif 30 | #else 31 | # define TRIPLET_ABI "gnu" 32 | #endif 33 | 34 | #ifdef __GNU__ 35 | # define TRIPLET TRIPLET_ARCH "-" TRIPLET_ABI 36 | #else 37 | # define TRIPLET TRIPLET_ARCH "-" TRIPLET_OS "-" TRIPLET_ABI 38 | #endif 39 | 40 | #if defined(_WIN32) 41 | int _CRT_glob = 0; 42 | #endif 43 | 44 | int main(int argc, char *argv[]) 45 | { 46 | switch(argc == 2 ? argv[1][0] : 0) { 47 | case 'b': 48 | { 49 | volatile unsigned foo = 0x01234567; 50 | puts(*(unsigned char*)&foo == 0x67 ? "no" : "yes"); 51 | break; 52 | } 53 | #ifdef __GNUC__ 54 | case 'm': 55 | printf("%d\n", __GNUC_MINOR__); 56 | break; 57 | case 'v': 58 | printf("%d\n", __GNUC__); 59 | break; 60 | #else 61 | case 'm': 62 | case 'v': 63 | puts("0"); 64 | break; 65 | #endif 66 | case 't': 67 | puts(TRIPLET); 68 | break; 69 | case -1: 70 | /* to test -Wno-unused-result */ 71 | fread(NULL, 1, 1, NULL); 72 | break; 73 | } 74 | return 0; 75 | } 76 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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 | char my_program[] = 19 | "int fib(int n)\n" 20 | "{\n" 21 | " if (n <= 2)\n" 22 | " return 1;\n" 23 | " else\n" 24 | " return fib(n-1) + fib(n-2);\n" 25 | "}\n" 26 | "\n" 27 | "int foo(int n)\n" 28 | "{\n" 29 | " printf(\"Hello World!\\n\");\n" 30 | " printf(\"fib(%d) = %d\\n\", n, fib(n));\n" 31 | " printf(\"add(%d, %d) = %d\\n\", n, 2 * n, add(n, 2 * n));\n" 32 | " return 0;\n" 33 | "}\n"; 34 | 35 | int main(int argc, char **argv) 36 | { 37 | TCCState *s; 38 | int (*func)(int); 39 | 40 | s = tcc_new(); 41 | if (!s) { 42 | fprintf(stderr, "Could not create tcc state\n"); 43 | exit(1); 44 | } 45 | 46 | /* if tcclib.h and libtcc1.a are not installed, where can we find them */ 47 | if (argc == 2 && !memcmp(argv[1], "lib_path=",9)) 48 | tcc_set_lib_path(s, argv[1]+9); 49 | 50 | /* MUST BE CALLED before any compilation */ 51 | tcc_set_output_type(s, TCC_OUTPUT_MEMORY); 52 | 53 | if (tcc_compile_string(s, my_program) == -1) 54 | return 1; 55 | 56 | /* as a test, we add a symbol that the compiled program can use. 57 | You may also open a dll with tcc_add_dll() and use symbols from that */ 58 | tcc_add_symbol(s, "add", add); 59 | 60 | /* relocate the code */ 61 | if (tcc_relocate(s, TCC_RELOCATE_AUTO) < 0) 62 | return 1; 63 | 64 | /* get entry symbol */ 65 | func = tcc_get_symbol(s, "foo"); 66 | if (!func) 67 | return 1; 68 | 69 | /* run the code */ 70 | func(32); 71 | 72 | /* delete the state */ 73 | tcc_delete(s); 74 | 75 | return 0; 76 | } 77 | -------------------------------------------------------------------------------- /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/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/build-tcc.bat: -------------------------------------------------------------------------------- 1 | @rem ---------------------------------------------------- 2 | @rem batch file to build tcc using mingw gcc 3 | @rem ---------------------------------------------------- 4 | 5 | @set /p VERSION= < ..\VERSION 6 | echo>..\config.h #define TCC_VERSION "%VERSION%" 7 | 8 | @rem @if _%PROCESSOR_ARCHITEW6432%_==_AMD64_ goto x86_64 9 | @if _%PROCESSOR_ARCHITECTURE%_==_AMD64_ goto x86_64 10 | 11 | @set target=-DTCC_TARGET_PE -DTCC_TARGET_I386 12 | @set CC=gcc -Os -s -fno-strict-aliasing 13 | @set P=32 14 | @goto tools 15 | 16 | :x86_64 17 | @set target=-DTCC_TARGET_PE -DTCC_TARGET_X86_64 18 | @rem mingw 64 has an ICE with -Os 19 | @set CC=x86_64-pc-mingw32-gcc -O0 -s -fno-strict-aliasing 20 | @set P=64 21 | @goto tools 22 | 23 | :tools 24 | %CC% %target% tools/tiny_impdef.c -o tiny_impdef.exe 25 | %CC% %target% tools/tiny_libmaker.c -o tiny_libmaker.exe 26 | 27 | :libtcc 28 | if not exist libtcc mkdir libtcc 29 | copy ..\libtcc.h libtcc\libtcc.h 30 | %CC% %target% -shared -DLIBTCC_AS_DLL -DONE_SOURCE ../libtcc.c -o libtcc.dll -Wl,-out-implib,libtcc/libtcc.a 31 | tiny_impdef libtcc.dll -o libtcc/libtcc.def 32 | 33 | :tcc 34 | %CC% %target% ../tcc.c -o tcc.exe -ltcc -Llibtcc 35 | 36 | :copy_std_includes 37 | copy ..\include\*.h include 38 | 39 | :libtcc1.a 40 | .\tcc %target% -c ../lib/libtcc1.c 41 | .\tcc %target% -c lib/crt1.c 42 | .\tcc %target% -c lib/wincrt1.c 43 | .\tcc %target% -c lib/dllcrt1.c 44 | .\tcc %target% -c lib/dllmain.c 45 | .\tcc %target% -c lib/chkstk.S 46 | goto lib%P% 47 | 48 | :lib32 49 | .\tcc %target% -c ../lib/alloca86.S 50 | .\tcc %target% -c ../lib/alloca86-bt.S 51 | .\tcc %target% -c ../lib/bcheck.c 52 | tiny_libmaker lib/libtcc1.a libtcc1.o alloca86.o alloca86-bt.o crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o bcheck.o 53 | @goto the_end 54 | 55 | :lib64 56 | .\tcc %target% -c ../lib/alloca86_64.S 57 | tiny_libmaker lib/libtcc1.a libtcc1.o alloca86_64.o crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o 58 | 59 | :the_end 60 | del *.o 61 | 62 | :makedoc 63 | echo>..\config.texi @set VERSION %VERSION% 64 | if not exist doc md doc 65 | makeinfo --html --no-split -o doc\tcc-doc.html ../tcc-doc.texi 66 | copy tcc-win32.txt doc 67 | copy ..\tests\libtcc_test.c examples 68 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | typedef __va_list_struct va_list[1]; 20 | 21 | void __va_start(__va_list_struct *ap, void *fp); 22 | void *__va_arg(__va_list_struct *ap, int arg_type, int size, int align); 23 | 24 | #define va_start(ap, last) __va_start(ap, __builtin_frame_address(0)) 25 | #define va_arg(ap, type) \ 26 | (*(type *)(__va_arg(ap, __builtin_va_arg_types(type), sizeof(type), __alignof__(type)))) 27 | #define va_copy(dest, src) (*(dest) = *(src)) 28 | #define va_end(ap) 29 | 30 | #else /* _WIN64 */ 31 | typedef char *va_list; 32 | #define va_start(ap,last) __builtin_va_start(ap,last) 33 | #define va_arg(ap,type) (ap += 8, sizeof(type)<=8 ? *(type*)ap : **(type**)ap) 34 | #define va_copy(dest, src) ((dest) = (src)) 35 | #define va_end(ap) 36 | #endif 37 | 38 | #elif __arm__ 39 | typedef char *va_list; 40 | #define _tcc_alignof(type) ((int)&((struct {char c;type x;} *)0)->x) 41 | #define _tcc_align(addr,type) (((unsigned)addr + _tcc_alignof(type) - 1) \ 42 | & ~(_tcc_alignof(type) - 1)) 43 | #define va_start(ap,last) ap = ((char *)&(last)) + ((sizeof(last)+3)&~3) 44 | #define va_arg(ap,type) (ap = (void *) ((_tcc_align(ap,type)+sizeof(type)+3) \ 45 | &~3), *(type *)(ap - ((sizeof(type)+3)&~3))) 46 | #define va_copy(dest, src) (dest) = (src) 47 | #define va_end(ap) 48 | 49 | #else /* __i386__ */ 50 | typedef char *va_list; 51 | /* only correct for i386 */ 52 | #define va_start(ap,last) ap = ((char *)&(last)) + ((sizeof(last)+3)&~3) 53 | #define va_arg(ap,type) (ap += (sizeof(type)+3)&~3, *(type *)(ap - ((sizeof(type)+3)&~3))) 54 | #define va_copy(dest, src) (dest) = (src) 55 | #define va_end(ap) 56 | #endif 57 | 58 | /* fix a buggy dependency on GCC in libio.h */ 59 | typedef va_list __gnuc_va_list; 60 | #define _VA_LIST_DEFINED 61 | 62 | #endif /* _STDARG_H */ 63 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ARM Thumb output 2 | ============== 3 | 4 | **This is a very old piece or work which only works very minimally** Please see 5 | https://git.erlendjs.no/erlendjs/tinycc as it appears to be a lot more capable 6 | 7 | To use this: 8 | 9 | * Configure it with cross-compilation enabled, then use any ARM target 10 | * I've been using `./arm-linux-gnueabi-tcc -nostdinc -nostdlib -c test.c -o test.o` to compile, and `arm-none-eabi-objdump -S test.o` to dump the output 11 | * I was comparing it with what I got from `arm-none-eabi-gcc -mlittle-endian -mthumb -mcpu=cortex-m3 -mfix-cortex-m3-ldrd -mfloat-abi=soft -nostdinc -nostdlib -c test.c -o test.o` 12 | 13 | In terms of implementation: 14 | 15 | * Everything is in `arm-gen.c`. 16 | * `tcc-gen.c` has a single mod, which adds one to the symbol address (signifying that the symbol is Thumb, not ARM). There must be a nicer way of doing this, but hey - proof of concept. 17 | * I added `ot()` which outputs a thumb instruction - the original `o()` would output a 32 bit ARM instruction - so every call to `o()` needs replacing with a thumb equivalent 18 | * The function prolog/epilog is hacked up at the moment so only works with very basic stuff (no stack pushing) 19 | * `encbranch`/`decbranch`/`gsym_addr` **do** seem to work, but encbranch won't work reliably for conditional branches as these have less bits for the address 20 | 21 | Would be nice: 22 | 23 | * Ideally we'd start out with a new `thumb-gen.c` containing stubs - it would get rid of the [RELICENSING](RELICENSING) issue 24 | * Find a way to separate ARM and Thumb code gen (ideally separate files), and maybe make TCC respect the `-mthumb` switch like GCC does (rather than having a separate binary). 25 | 26 | 27 | ### test.sh 28 | 29 | ``` 30 | #!/bin/bash 31 | arm-none-eabi-gcc -mlittle-endian -mthumb -mcpu=cortex-m3 -mfix-cortex-m3-ldrd -mfloat-abi=soft -nostdinc -nostdlib -c test.c -o test.o 32 | echo ------------------------------------------------ 33 | echo GCC 34 | echo ------------------------------------------------ 35 | arm-none-eabi-objdump -S test.o 36 | mv test.o test-gcc.o 37 | 38 | 39 | ./arm-linux-gnueabi-tcc -nostdinc -nostdlib -c test.c -o test.o 40 | echo ------------------------------------------------ 41 | echo TCC 42 | echo ------------------------------------------------ 43 | arm-none-eabi-objdump -S test.o 44 | mv test.o test-tcc.o 45 | ``` 46 | 47 | ### test.c 48 | 49 | ``` 50 | // test.c 51 | int foobar() { 52 | return 4; 53 | } 54 | ``` 55 | 56 | 57 | ### Original README 58 | 59 | is [here](README) 60 | -------------------------------------------------------------------------------- /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/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/winapi/tvout.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 __TVOUT__ 7 | #define __TVOUT__ 8 | 9 | #include 10 | 11 | typedef struct _VIDEOPARAMETERS { 12 | GUID Guid; 13 | ULONG dwOffset; 14 | ULONG dwCommand; 15 | ULONG dwFlags; 16 | ULONG dwMode; 17 | ULONG dwTVStandard; 18 | ULONG dwAvailableModes; 19 | ULONG dwAvailableTVStandard; 20 | ULONG dwFlickerFilter; 21 | ULONG dwOverScanX; 22 | ULONG dwOverScanY; 23 | ULONG dwMaxUnscaledX; 24 | ULONG dwMaxUnscaledY; 25 | ULONG dwPositionX; 26 | ULONG dwPositionY; 27 | ULONG dwBrightness; 28 | ULONG dwContrast; 29 | ULONG dwCPType; 30 | ULONG dwCPCommand; 31 | ULONG dwCPStandard; 32 | ULONG dwCPKey; 33 | ULONG bCP_APSTriggerBits; 34 | UCHAR bOEMCopyProtection[256]; 35 | } VIDEOPARAMETERS,*PVIDEOPARAMETERS,*LPVIDEOPARAMETERS; 36 | 37 | #define VP_COMMAND_GET 0x0001 38 | #define VP_COMMAND_SET 0x0002 39 | 40 | #define VP_FLAGS_TV_MODE 0x0001 41 | #define VP_FLAGS_TV_STANDARD 0x0002 42 | #define VP_FLAGS_FLICKER 0x0004 43 | #define VP_FLAGS_OVERSCAN 0x0008 44 | #define VP_FLAGS_MAX_UNSCALED 0x0010 45 | #define VP_FLAGS_POSITION 0x0020 46 | #define VP_FLAGS_BRIGHTNESS 0x0040 47 | #define VP_FLAGS_CONTRAST 0x0080 48 | #define VP_FLAGS_COPYPROTECT 0x0100 49 | 50 | #define VP_MODE_WIN_GRAPHICS 0x0001 51 | #define VP_MODE_TV_PLAYBACK 0x0002 52 | 53 | #define VP_TV_STANDARD_NTSC_M 0x0001 54 | #define VP_TV_STANDARD_NTSC_M_J 0x0002 55 | #define VP_TV_STANDARD_PAL_B 0x0004 56 | #define VP_TV_STANDARD_PAL_D 0x0008 57 | #define VP_TV_STANDARD_PAL_H 0x0010 58 | #define VP_TV_STANDARD_PAL_I 0x0020 59 | #define VP_TV_STANDARD_PAL_M 0x0040 60 | #define VP_TV_STANDARD_PAL_N 0x0080 61 | #define VP_TV_STANDARD_SECAM_B 0x0100 62 | #define VP_TV_STANDARD_SECAM_D 0x0200 63 | #define VP_TV_STANDARD_SECAM_G 0x0400 64 | #define VP_TV_STANDARD_SECAM_H 0x0800 65 | #define VP_TV_STANDARD_SECAM_K 0x1000 66 | #define VP_TV_STANDARD_SECAM_K1 0x2000 67 | #define VP_TV_STANDARD_SECAM_L 0x4000 68 | #define VP_TV_STANDARD_WIN_VGA 0x8000 69 | #define VP_TV_STANDARD_NTSC_433 0x00010000 70 | #define VP_TV_STANDARD_PAL_G 0x00020000 71 | #define VP_TV_STANDARD_PAL_60 0x00040000 72 | #define VP_TV_STANDARD_SECAM_L1 0x00080000 73 | 74 | #define VP_CP_TYPE_APS_TRIGGER 0x0001 75 | #define VP_CP_TYPE_MACROVISION 0x0002 76 | #define VP_CP_CMD_ACTIVATE 0x0001 77 | #define VP_CP_CMD_DEACTIVATE 0x0002 78 | #define VP_CP_CMD_CHANGE 0x0004 79 | #endif 80 | -------------------------------------------------------------------------------- /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 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/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 WINVER 10 | #define WINVER 0x0502 11 | #endif 12 | 13 | #include <_mingw.h> 14 | 15 | #ifndef _INC_WINDOWS 16 | #define _INC_WINDOWS 17 | 18 | #if defined(RC_INVOKED) && !defined(NOWINRES) 19 | 20 | #include 21 | #else 22 | 23 | #ifdef RC_INVOKED 24 | #define NOATOM 25 | #define NOGDI 26 | #define NOGDICAPMASKS 27 | #define NOMETAFILE 28 | #define NOMINMAX 29 | #define NOMSG 30 | #define NOOPENFILE 31 | #define NORASTEROPS 32 | #define NOSCROLL 33 | #define NOSOUND 34 | #define NOSYSMETRICS 35 | #define NOTEXTMETRIC 36 | #define NOWH 37 | #define NOCOMM 38 | #define NOKANJI 39 | #define NOCRYPT 40 | #define NOMCX 41 | #endif 42 | 43 | #if !defined(I_X86_) && !defined(_IA64_) && !defined(_AMD64_) && (defined(_X86_) && !defined(__x86_64)) 44 | #define I_X86_ 45 | #endif 46 | 47 | #if !defined(I_X86_) && !defined(_IA64_) && !defined(_AMD64_) && defined(__x86_64) 48 | #define _AMD64_ 49 | #endif 50 | 51 | #if !defined(I_X86_) && !(defined(_X86_) && !defined(__x86_64)) && !defined(_AMD64_) && defined(__ia64__) 52 | #if !defined(_IA64_) 53 | #define _IA64_ 54 | #endif 55 | #endif 56 | 57 | #ifndef RC_INVOKED 58 | #include 59 | #include 60 | #endif 61 | 62 | #include 63 | #include 64 | #include 65 | #include 66 | #include 67 | #include 68 | #include 69 | #include 70 | #include 71 | 72 | #ifndef WIN32_LEAN_AND_MEAN 73 | #include 74 | #include 75 | #include 76 | #include 77 | #include 78 | #include 79 | #include 80 | #include 81 | #include 82 | #include 83 | #include 84 | #ifndef NOCRYPT 85 | #include 86 | #include 87 | #include 88 | #endif 89 | 90 | #ifndef NOUSER 91 | #ifndef NOGDI 92 | #include 93 | #ifdef INC_OLE1 94 | #include 95 | #else 96 | #include 97 | #endif 98 | #include 99 | #endif 100 | #endif 101 | #endif 102 | 103 | #include 104 | 105 | #ifdef INC_OLE2 106 | #include 107 | #endif 108 | 109 | #ifndef NOSERVICE 110 | #include 111 | #endif 112 | 113 | #ifndef NOMCX 114 | #include 115 | #endif 116 | 117 | #ifndef NOIME 118 | #include 119 | #endif 120 | 121 | #endif 122 | #endif 123 | #endif 124 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | 43 | int printf(const char *format, ...); 44 | int fprintf(FILE *stream, const char *format, ...); 45 | int sprintf(char *str, const char *format, ...); 46 | int snprintf(char *str, size_t size, const char *format, ...); 47 | int asprintf(char **strp, const char *format, ...); 48 | int dprintf(int fd, const char *format, ...); 49 | int vprintf(const char *format, va_list ap); 50 | int vfprintf(FILE *stream, const char *format, va_list ap); 51 | int vsprintf(char *str, const char *format, va_list ap); 52 | int vsnprintf(char *str, size_t size, const char *format, va_list ap); 53 | int vasprintf(char **strp, const char *format, va_list ap); 54 | int vdprintf(int fd, const char *format, va_list ap); 55 | 56 | void perror(const char *s); 57 | 58 | /* string.h */ 59 | char *strcat(char *dest, const char *src); 60 | char *strchr(const char *s, int c); 61 | char *strrchr(const char *s, int c); 62 | char *strcpy(char *dest, const char *src); 63 | void *memcpy(void *dest, const void *src, size_t n); 64 | void *memmove(void *dest, const void *src, size_t n); 65 | void *memset(void *s, int c, size_t n); 66 | char *strdup(const char *s); 67 | 68 | /* dlfcn.h */ 69 | #define RTLD_LAZY 0x001 70 | #define RTLD_NOW 0x002 71 | #define RTLD_GLOBAL 0x100 72 | 73 | void *dlopen(const char *filename, int flag); 74 | const char *dlerror(void); 75 | void *dlsym(void *handle, char *symbol); 76 | int dlclose(void *handle); 77 | 78 | #endif /* _TCCLIB_H */ 79 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /lib/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Tiny C Compiler Makefile for libtcc1.a 3 | # 4 | 5 | TOP = .. 6 | include $(TOP)/Makefile 7 | VPATH = $(top_srcdir)/lib $(top_srcdir)/win32/lib 8 | 9 | ifndef TARGET # native library 10 | ifdef CONFIG_WIN64 11 | TARGET = x86_64-win32 12 | else 13 | ifdef CONFIG_WIN32 14 | TARGET = i386-win32 15 | else 16 | ifeq ($(ARCH),i386) 17 | TARGET = i386 18 | ifneq ($(TARGETOS),Darwin) 19 | XCC = $(CC) 20 | endif 21 | else 22 | ifeq ($(ARCH),x86-64) 23 | TARGET = x86_64 24 | ifneq ($(TARGETOS),Darwin) 25 | XCC = $(CC) 26 | endif 27 | else 28 | ifeq ($(ARCH),arm) 29 | TARGET = arm 30 | XCC = $(CC) 31 | endif 32 | endif 33 | endif 34 | endif 35 | endif 36 | BCHECK_O = bcheck.o 37 | endif 38 | 39 | DIR = $(TARGET) 40 | 41 | native : ../libtcc1.a 42 | cross : $(DIR)/libtcc1.a 43 | 44 | native : TCC = $(TOP)/tcc$(EXESUF) 45 | cross : TCC = $(TOP)/$(TARGET)-tcc$(EXESUF) 46 | 47 | I386_O = libtcc1.o alloca86.o alloca86-bt.o $(BCHECK_O) 48 | X86_64_O = libtcc1.o alloca86_64.o 49 | ARM_O = libtcc1.o armeabi.o alloca-arm.o 50 | WIN32_O = $(I386_O) crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o 51 | WIN64_O = $(X86_64_O) crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o 52 | 53 | # build TCC runtime library to contain PIC code, so it can be linked 54 | # into shared libraries 55 | PICFLAGS = -fPIC 56 | 57 | ifeq "$(TARGET)" "i386-win32" 58 | OBJ = $(addprefix $(DIR)/,$(WIN32_O)) 59 | TGT = -DTCC_TARGET_I386 -DTCC_TARGET_PE 60 | XCC = $(TCC) -B$(top_srcdir)/win32 -I$(top_srcdir)/include 61 | XAR = $(DIR)/tiny_libmaker$(EXESUF) 62 | PICFLAGS = 63 | else 64 | ifeq "$(TARGET)" "x86_64-win32" 65 | OBJ = $(addprefix $(DIR)/,$(WIN64_O)) 66 | TGT = -DTCC_TARGET_X86_64 -DTCC_TARGET_PE 67 | XCC = $(TCC) -B$(top_srcdir)/win32 -I$(top_srcdir)/include 68 | XAR = $(DIR)/tiny_libmaker$(EXESUF) 69 | PICFLAGS = 70 | else 71 | ifeq "$(TARGET)" "i386" 72 | OBJ = $(addprefix $(DIR)/,$(I386_O)) 73 | TGT = -DTCC_TARGET_I386 74 | XCC ?= $(TCC) -B$(TOP) 75 | else 76 | ifeq "$(TARGET)" "x86_64" 77 | OBJ = $(addprefix $(DIR)/,$(X86_64_O)) 78 | TGT = -DTCC_TARGET_X86_64 79 | XCC ?= $(TCC) -B$(TOP) 80 | else 81 | ifeq "$(TARGET)" "arm" 82 | OBJ = $(addprefix $(DIR)/,$(ARM_O)) 83 | TGT = -DTCC_TARGET_ARM 84 | XCC ?= $(TCC) -B$(TOP) 85 | else 86 | $(error libtcc1.a not supported on target '$(TARGET)') 87 | endif 88 | endif 89 | endif 90 | endif 91 | endif 92 | 93 | XFLAGS = $(CPPFLAGS) $(CFLAGS) $(PICFLAGS) $(TGT) 94 | 95 | ifeq ($(TARGETOS),Darwin) 96 | XAR = $(DIR)/tiny_libmaker$(EXESUF) 97 | XFLAGS += -D_ANSI_SOURCE 98 | BCHECK_O = 99 | endif 100 | 101 | ifdef XAR 102 | AR = $(XAR) 103 | endif 104 | 105 | $(DIR)/libtcc1.a ../libtcc1.a : $(OBJ) $(XAR) 106 | $(AR) rcs $@ $(OBJ) 107 | $(DIR)/%.o : %.c 108 | $(XCC) -c $< -o $@ $(XFLAGS) 109 | $(DIR)/%.o : %.S 110 | $(XCC) -c $< -o $@ $(XFLAGS) 111 | $(DIR)/%$(EXESUF) : $(TOP)/win32/tools/%.c 112 | $(CC) -o $@ $< $(XFLAGS) $(LDFLAGS) 113 | 114 | $(OBJ) $(XAR) : $(DIR)/exists 115 | $(DIR)/exists : 116 | mkdir -p $(DIR) 117 | @echo $@ > $@ 118 | 119 | clean : 120 | rm -rfv i386-win32 x86_64-win32 i386 x86_64 121 | -------------------------------------------------------------------------------- /win32/include/limits.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 | #ifndef _INC_LIMITS 9 | #define _INC_LIMITS 10 | 11 | /* 12 | * File system limits 13 | * 14 | * TODO: NAME_MAX and OPEN_MAX are file system limits or not? Are they the 15 | * same as FILENAME_MAX and FOPEN_MAX from stdio.h? 16 | * NOTE: Apparently the actual size of PATH_MAX is 260, but a space is 17 | * required for the NUL. TODO: Test? 18 | */ 19 | #define PATH_MAX (259) 20 | 21 | #define CHAR_BIT 8 22 | #define SCHAR_MIN (-128) 23 | #define SCHAR_MAX 127 24 | #define UCHAR_MAX 0xff 25 | 26 | #define CHAR_MIN SCHAR_MIN 27 | #define CHAR_MAX SCHAR_MAX 28 | 29 | #define MB_LEN_MAX 5 30 | #define SHRT_MIN (-32768) 31 | #define SHRT_MAX 32767 32 | #define USHRT_MAX 0xffff 33 | #define INT_MIN (-2147483647 - 1) 34 | #define INT_MAX 2147483647 35 | #define UINT_MAX 0xffffffff 36 | #define LONG_MIN (-2147483647L - 1) 37 | #define LONG_MAX 2147483647L 38 | #define ULONG_MAX 0xffffffffUL 39 | #define LLONG_MAX 9223372036854775807ll 40 | #define LLONG_MIN (-9223372036854775807ll - 1) 41 | #define ULLONG_MAX 0xffffffffffffffffull 42 | 43 | #if _INTEGRAL_MAX_BITS >= 8 44 | #define _I8_MIN (-127 - 1) 45 | #define _I8_MAX 127i8 46 | #define _UI8_MAX 0xffu 47 | #endif 48 | 49 | #if _INTEGRAL_MAX_BITS >= 16 50 | #define _I16_MIN (-32767 - 1) 51 | #define _I16_MAX 32767i16 52 | #define _UI16_MAX 0xffffu 53 | #endif 54 | 55 | #if _INTEGRAL_MAX_BITS >= 32 56 | #define _I32_MIN (-2147483647 - 1) 57 | #define _I32_MAX 2147483647 58 | #define _UI32_MAX 0xffffffffu 59 | #endif 60 | 61 | #if defined(__GNUC__) 62 | #undef LONG_LONG_MAX 63 | #define LONG_LONG_MAX 9223372036854775807ll 64 | #undef LONG_LONG_MIN 65 | #define LONG_LONG_MIN (-LONG_LONG_MAX-1) 66 | #undef ULONG_LONG_MAX 67 | #define ULONG_LONG_MAX (2ull * LONG_LONG_MAX + 1ull) 68 | #endif 69 | 70 | #if _INTEGRAL_MAX_BITS >= 64 71 | #define _I64_MIN (-9223372036854775807ll - 1) 72 | #define _I64_MAX 9223372036854775807ll 73 | #define _UI64_MAX 0xffffffffffffffffull 74 | #endif 75 | 76 | #ifndef SIZE_MAX 77 | #ifdef _WIN64 78 | #define SIZE_MAX _UI64_MAX 79 | #else 80 | #define SIZE_MAX UINT_MAX 81 | #endif 82 | #endif 83 | 84 | #ifdef _POSIX_ 85 | #define _POSIX_ARG_MAX 4096 86 | #define _POSIX_CHILD_MAX 6 87 | #define _POSIX_LINK_MAX 8 88 | #define _POSIX_MAX_CANON 255 89 | #define _POSIX_MAX_INPUT 255 90 | #define _POSIX_NAME_MAX 14 91 | #define _POSIX_NGROUPS_MAX 0 92 | #define _POSIX_OPEN_MAX 16 93 | #define _POSIX_PATH_MAX 255 94 | #define _POSIX_PIPE_BUF 512 95 | #define _POSIX_SSIZE_MAX 32767 96 | #define _POSIX_STREAM_MAX 8 97 | #define _POSIX_TZNAME_MAX 3 98 | #define ARG_MAX 14500 99 | #define LINK_MAX 1024 100 | #define MAX_CANON _POSIX_MAX_CANON 101 | #define MAX_INPUT _POSIX_MAX_INPUT 102 | #define NAME_MAX 255 103 | #define NGROUPS_MAX 16 104 | #define OPEN_MAX 32 105 | #define PATH_MAX 512 106 | #define PIPE_BUF _POSIX_PIPE_BUF 107 | #define SSIZE_MAX _POSIX_SSIZE_MAX 108 | #define STREAM_MAX 20 109 | #define TZNAME_MAX 10 110 | #endif 111 | #endif 112 | -------------------------------------------------------------------------------- /tests/tests2/Makefile: -------------------------------------------------------------------------------- 1 | TOP = ../.. 2 | include $(TOP)/Makefile 3 | 4 | ifdef CONFIG_WIN32 5 | TCCFLAGS = -B$(top_srcdir)/win32 -I$(top_srcdir)/include -L$(TOP) 6 | else 7 | TCCFLAGS = -B$(TOP) -I$(top_srcdir)/include -lm 8 | endif 9 | 10 | ifeq ($(TARGETOS),Darwin) 11 | CFLAGS += -Wl,-flat_namespace,-undefined,warning 12 | TCCFLAGS += -D_ANSI_SOURCE 13 | export MACOSX_DEPLOYMENT_TARGET:=10.2 14 | endif 15 | 16 | TCC = $(TOP)/tcc $(TCCFLAGS) 17 | 18 | TESTS = \ 19 | 00_assignment.test \ 20 | 01_comment.test \ 21 | 02_printf.test \ 22 | 03_struct.test \ 23 | 04_for.test \ 24 | 05_array.test \ 25 | 06_case.test \ 26 | 07_function.test \ 27 | 08_while.test \ 28 | 09_do_while.test \ 29 | 10_pointer.test \ 30 | 11_precedence.test \ 31 | 12_hashdefine.test \ 32 | 13_integer_literals.test \ 33 | 14_if.test \ 34 | 15_recursion.test \ 35 | 16_nesting.test \ 36 | 17_enum.test \ 37 | 18_include.test \ 38 | 19_pointer_arithmetic.test \ 39 | 20_pointer_comparison.test \ 40 | 21_char_array.test \ 41 | 22_floating_point.test \ 42 | 23_type_coercion.test \ 43 | 24_math_library.test \ 44 | 25_quicksort.test \ 45 | 26_character_constants.test \ 46 | 27_sizeof.test \ 47 | 28_strings.test \ 48 | 29_array_address.test \ 49 | 30_hanoi.test \ 50 | 31_args.test \ 51 | 32_led.test \ 52 | 33_ternary_op.test \ 53 | 34_array_assignment.test \ 54 | 35_sizeof.test \ 55 | 36_array_initialisers.test \ 56 | 37_sprintf.test \ 57 | 38_multiple_array_index.test \ 58 | 39_typedef.test \ 59 | 40_stdio.test \ 60 | 41_hashif.test \ 61 | 42_function_pointer.test \ 62 | 43_void_param.test \ 63 | 44_scoped_declarations.test \ 64 | 45_empty_for.test \ 65 | 46_grep.test \ 66 | 47_switch_return.test \ 67 | 48_nested_break.test \ 68 | 49_bracket_evaluation.test \ 69 | 50_logical_second_arg.test \ 70 | 51_static.test \ 71 | 52_unnamed_enum.test \ 72 | 54_goto.test \ 73 | 55_lshift_type.test \ 74 | 56_btype_excess-1.test \ 75 | 57_btype_excess-2.test \ 76 | 58_function_redefinition.test \ 77 | 59_function_array.test \ 78 | 60_enum_redefinition.test \ 79 | 61_undefined_enum.test \ 80 | 62_enumerator_redefinition.test \ 81 | 63_local_enumerator_redefinition.test \ 82 | 64_macro_nesting.test \ 83 | 65_macro_concat_start.test \ 84 | 66_macro_concat_end.test \ 85 | 67_macro_concat.test \ 86 | 68_macro_param_list_err_1.test \ 87 | 69_macro_param_list_err_2.test 88 | 89 | # 34_array_assignment.test -- array assignment is not in C standard 90 | 91 | SKIP = 34_array_assignment.test 92 | 93 | # some tests do not pass on all platforms, remove them for now 94 | ifeq ($(TARGETOS),Darwin) 95 | SKIP += 40_stdio.test 96 | endif 97 | ifdef CONFIG_WIN32 98 | SKIP += 24_math_library.test # don't have round() 99 | SKIP += 28_strings.test # don't have r/index() / strings.h 100 | endif 101 | 102 | # Some tests might need arguments 103 | ARGS = 104 | 31_args.test : ARGS = arg1 arg2 arg3 arg4 arg5 105 | 46_grep.test : ARGS = '[^* ]*[:a:d: ]+\:\*-/: $$' 46_grep.c 106 | 107 | all test: $(filter-out $(SKIP),$(TESTS)) 108 | 109 | %.test: %.c %.expect 110 | @echo Test: $*... 111 | 112 | @$(TCC) -run $< $(ARGS) >$*.output 2>&1 || true 113 | @diff -bu $*.expect $*.output && rm -f $*.output 114 | 115 | @($(TCC) $< -o $*.exe && ./$*.exe $(ARGS)) >$*.output2 2>&1 || true 116 | @diff -bu $*.expect $*.output2 && rm -f $*.output2 $*.exe 117 | 118 | clean: 119 | rm -vf fred.txt *.output* *.exe 120 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | Tiny C Compiler - C Scripting Everywhere - The Smallest ANSI C compiler 2 | ----------------------------------------------------------------------- 3 | 4 | Features: 5 | -------- 6 | 7 | - SMALL! You can compile and execute C code everywhere, for example on 8 | rescue disks. 9 | 10 | - FAST! tcc generates optimized x86 code. No byte code 11 | overhead. Compile, assemble and link about 7 times faster than 'gcc 12 | -O0'. 13 | 14 | - UNLIMITED! Any C dynamic library can be used directly. TCC is 15 | heading torward full ISOC99 compliance. TCC can of course compile 16 | itself. 17 | 18 | - SAFE! tcc includes an optional memory and bound checker. Bound 19 | checked code can be mixed freely with standard code. 20 | 21 | - Compile and execute C source directly. No linking or assembly 22 | necessary. Full C preprocessor included. 23 | 24 | - C script supported : just add '#!/usr/local/bin/tcc -run' at the first 25 | line of your C source, and execute it directly from the command 26 | line. 27 | 28 | Documentation: 29 | ------------- 30 | 31 | 1) Installation on a i386/x86_64/arm Linux/OSX/FreeBSD host (for Windows read tcc-win32.txt) 32 | 33 | Note: For OSX and FreeBSD, gmake should be used instead of make. 34 | 35 | ./configure 36 | make 37 | make test 38 | make install 39 | 40 | Alternatively, out-of-tree builds are supported: you may use different 41 | directories to hold build objects, kept separate from your source tree: 42 | 43 | mkdir _build 44 | cd _build 45 | ../configure 46 | make 47 | make test 48 | make install 49 | 50 | Texi2html must be installed to compile the doc. 51 | By default, tcc is installed in /usr/local/bin. 52 | ./configure --help shows configuration options. 53 | 54 | 55 | 2) Introduction 56 | 57 | We assume here that you know ANSI C. Look at the example ex1.c to know 58 | what the programs look like. 59 | 60 | The include file can be used if you want a small basic libc 61 | include support (especially useful for floppy disks). Of course, you 62 | can also use standard headers, although they are slower to compile. 63 | 64 | You can begin your C script with '#!/usr/local/bin/tcc -run' on the first 65 | line and set its execute bits (chmod a+x your_script). Then, you can 66 | launch the C code as a shell or perl script :-) The command line 67 | arguments are put in 'argc' and 'argv' of the main functions, as in 68 | ANSI C. 69 | 70 | 3) Examples 71 | 72 | ex1.c: simplest example (hello world). Can also be launched directly 73 | as a script: './ex1.c'. 74 | 75 | ex2.c: more complicated example: find a number with the four 76 | operations given a list of numbers (benchmark). 77 | 78 | ex3.c: compute fibonacci numbers (benchmark). 79 | 80 | ex4.c: more complicated: X11 program. Very complicated test in fact 81 | because standard headers are being used ! As for ex1.c, can also be launched 82 | directly as a script: './ex4.c'. 83 | 84 | ex5.c: 'hello world' with standard glibc headers. 85 | 86 | tcc.c: TCC can of course compile itself. Used to check the code 87 | generator. 88 | 89 | tcctest.c: auto test for TCC which tests many subtle possible bugs. Used 90 | when doing 'make test'. 91 | 92 | 4) Full Documentation 93 | 94 | Please read tcc-doc.html to have all the features of TCC. 95 | 96 | Additional information is available for the Windows port in tcc-win32.txt. 97 | 98 | License: 99 | ------- 100 | 101 | TCC is distributed under the GNU Lesser General Public License (see 102 | COPYING file). 103 | 104 | Fabrice Bellard. 105 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | TODO list: 2 | 3 | Bugs: 4 | 5 | - fix macro substitution with nested definitions (ShangHongzhang) 6 | - FPU st(0) is left unclean (kwisatz haderach). Incompatible with 7 | optimized gcc/msc code 8 | 9 | - constructors 10 | - cast bug (Peter Wang) 11 | - define incomplete type if defined several times (Peter Wang). 12 | - test binutils/gcc compile 13 | - tci patch + argument. 14 | - see -lxxx bug (Michael Charity). 15 | - see transparent union pb in /urs/include/sys/socket.h 16 | - precise behaviour of typeof with arrays ? (__put_user macro) 17 | but should suffice for most cases) 18 | - handle '? x, y : z' in unsized variable initialization (',' is 19 | considered incorrectly as separator in preparser) 20 | - transform functions to function pointers in function parameters 21 | (net/ipv4/ip_output.c) 22 | - fix function pointer type display 23 | - check lcc test suite -> fix bitfield binary operations 24 | - check section alignment in C 25 | - fix invalid cast in comparison 'if (v == (int8_t)v)' 26 | - finish varargs.h support (gcc 3.2 testsuite issue) 27 | - fix static functions declared inside block 28 | - fix multiple unions init 29 | - sizeof, alignof, typeof can still generate code in some cases. 30 | - Fix the remaining libtcc memory leaks. 31 | - make libtcc fully reentrant (except for the compilation stage itself). 32 | 33 | Bound checking: 34 | 35 | - '-b' bug. 36 | - fix bound exit on RedHat 7.3 37 | - setjmp is not supported properly in bound checking. 38 | - fix bound check code with '&' on local variables (currently done 39 | only for local arrays). 40 | - bound checking and float/long long/struct copy code. bound 41 | checking and symbol + offset optimization 42 | 43 | Missing features: 44 | 45 | - disable-asm and disable-bcheck options 46 | - __builtin_expect() 47 | - improve '-E' option. 48 | - atexit (Nigel Horne) 49 | - packed attribute 50 | - C99: add complex types (gcc 3.2 testsuite issue) 51 | - postfix compound literals (see 20010124-1.c) 52 | 53 | Optimizations: 54 | 55 | - suppress specific anonymous symbol handling 56 | - more parse optimizations (=even faster compilation) 57 | - memory alloc optimizations (=even faster compilation) 58 | - optimize VT_LOCAL + const 59 | - better local variables handling (needed for other targets) 60 | 61 | Not critical: 62 | 63 | - C99: fix multiple compound literals inits in blocks (ISOC99 64 | normative example - only relevant when using gotos! -> must add 65 | boolean variable to tell if compound literal was already 66 | initialized). 67 | - add PowerPC or ARM code generator and improve codegen for RISC (need 68 | to suppress VT_LOCAL and use a base register instead). 69 | - interactive mode / integrated debugger 70 | - fix preprocessor symbol redefinition 71 | - better constant opt (&&, ||, ?:) 72 | - add portable byte code generator and interpreter for other 73 | unsupported architectures. 74 | - C++: variable declaration in for, minimal 'class' support. 75 | - win32: __intxx. use resolve for bchecked malloc et al. 76 | check exception code (exception filter func). 77 | - handle void (__attribute__() *ptr)() 78 | 79 | Fixed (probably): 80 | 81 | - bug with defines: 82 | #define spin_lock(lock) do { } while (0) 83 | #define wq_spin_lock spin_lock 84 | #define TEST() wq_spin_lock(a) 85 | - typedefs can be structure fields 86 | - see bugfixes.diff + improvement.diff from Daniel Glockner 87 | - long long constant evaluation 88 | - add alloca() 89 | - gcc '-E' option. 90 | - #include_next support for /usr/include/limits ? 91 | - function pointers/lvalues in ? : (linux kernel net/core/dev.c) 92 | - win32: add __stdcall, check GetModuleHandle for dlls. 93 | -------------------------------------------------------------------------------- /win32/include/fenv.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 _FENV_H_ 7 | #define _FENV_H_ 8 | 9 | #include <_mingw.h> 10 | 11 | /* FPU status word exception flags */ 12 | #define FE_INVALID 0x01 13 | #define FE_DENORMAL 0x02 14 | #define FE_DIVBYZERO 0x04 15 | #define FE_OVERFLOW 0x08 16 | #define FE_UNDERFLOW 0x10 17 | #define FE_INEXACT 0x20 18 | #define FE_ALL_EXCEPT (FE_INVALID | FE_DENORMAL | FE_DIVBYZERO \ 19 | | FE_OVERFLOW | FE_UNDERFLOW | FE_INEXACT) 20 | 21 | /* FPU control word rounding flags */ 22 | #define FE_TONEAREST 0x0000 23 | #define FE_DOWNWARD 0x0400 24 | #define FE_UPWARD 0x0800 25 | #define FE_TOWARDZERO 0x0c00 26 | 27 | /* The MXCSR exception flags are the same as the 28 | FE flags. */ 29 | #define __MXCSR_EXCEPT_FLAG_SHIFT 0 30 | 31 | /* How much to shift FE status word exception flags 32 | to get MXCSR rounding flags, */ 33 | #define __MXCSR_ROUND_FLAG_SHIFT 3 34 | 35 | #ifndef RC_INVOKED 36 | /* 37 | For now, support only for the basic abstraction of flags that are 38 | either set or clear. fexcept_t could be structure that holds more 39 | info about the fp environment. 40 | */ 41 | typedef unsigned short fexcept_t; 42 | 43 | /* This 32-byte struct represents the entire floating point 44 | environment as stored by fnstenv or fstenv, augmented by 45 | the contents of the MXCSR register, as stored by stmxcsr 46 | (if CPU supports it). */ 47 | typedef struct 48 | { 49 | unsigned short __control_word; 50 | unsigned short __unused0; 51 | unsigned short __status_word; 52 | unsigned short __unused1; 53 | unsigned short __tag_word; 54 | unsigned short __unused2; 55 | unsigned int __ip_offset; /* instruction pointer offset */ 56 | unsigned short __ip_selector; 57 | unsigned short __opcode; 58 | unsigned int __data_offset; 59 | unsigned short __data_selector; 60 | unsigned short __unused3; 61 | unsigned int __mxcsr; /* contents of the MXCSR register */ 62 | } fenv_t; 63 | 64 | 65 | /*The C99 standard (7.6.9) allows us to define implementation-specific macros for 66 | different fp environments */ 67 | 68 | /* The default Intel x87 floating point environment (64-bit mantissa) */ 69 | #define FE_PC64_ENV ((const fenv_t *)-1) 70 | 71 | /* The floating point environment set by MSVCRT _fpreset (53-bit mantissa) */ 72 | #define FE_PC53_ENV ((const fenv_t *)-2) 73 | 74 | /* The FE_DFL_ENV macro is required by standard. 75 | fesetenv will use the environment set at app startup.*/ 76 | #define FE_DFL_ENV ((const fenv_t *) 0) 77 | 78 | #ifdef __cplusplus 79 | extern "C" { 80 | #endif 81 | 82 | /*TODO: Some of these could be inlined */ 83 | /* 7.6.2 Exception */ 84 | 85 | extern int __cdecl feclearexcept (int); 86 | extern int __cdecl fegetexceptflag (fexcept_t * flagp, int excepts); 87 | extern int __cdecl feraiseexcept (int excepts ); 88 | extern int __cdecl fesetexceptflag (const fexcept_t *, int); 89 | extern int __cdecl fetestexcept (int excepts); 90 | 91 | /* 7.6.3 Rounding */ 92 | 93 | extern int __cdecl fegetround (void); 94 | extern int __cdecl fesetround (int mode); 95 | 96 | /* 7.6.4 Environment */ 97 | 98 | extern int __cdecl fegetenv(fenv_t * envp); 99 | extern int __cdecl fesetenv(const fenv_t * ); 100 | extern int __cdecl feupdateenv(const fenv_t *); 101 | extern int __cdecl feholdexcept(fenv_t *); 102 | 103 | #ifdef __cplusplus 104 | } 105 | #endif 106 | #endif /* Not RC_INVOKED */ 107 | 108 | #endif /* ndef _FENV_H */ 109 | -------------------------------------------------------------------------------- /win32/include/winapi/reason.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 SENTINEL_Reason 7 | #define SENTINEL_Reason 8 | 9 | #define SHTDN_REASON_FLAG_COMMENT_REQUIRED 0x01000000 10 | #define SHTDN_REASON_FLAG_DIRTY_PROBLEM_ID_REQUIRED 0x02000000 11 | #define SHTDN_REASON_FLAG_CLEAN_UI 0x04000000 12 | #define SHTDN_REASON_FLAG_DIRTY_UI 0x08000000 13 | #define SHTDN_REASON_FLAG_USER_DEFINED 0x40000000 14 | #define SHTDN_REASON_FLAG_PLANNED 0x80000000 15 | #define SHTDN_REASON_MAJOR_OTHER 0x00000000 16 | #define SHTDN_REASON_MAJOR_NONE 0x00000000 17 | #define SHTDN_REASON_MAJOR_HARDWARE 0x00010000 18 | #define SHTDN_REASON_MAJOR_OPERATINGSYSTEM 0x00020000 19 | #define SHTDN_REASON_MAJOR_SOFTWARE 0x00030000 20 | #define SHTDN_REASON_MAJOR_APPLICATION 0x00040000 21 | #define SHTDN_REASON_MAJOR_SYSTEM 0x00050000 22 | #define SHTDN_REASON_MAJOR_POWER 0x00060000 23 | #define SHTDN_REASON_MAJOR_LEGACY_API 0x00070000 24 | #define SHTDN_REASON_MINOR_OTHER 0x00000000 25 | #define SHTDN_REASON_MINOR_NONE 0x000000ff 26 | #define SHTDN_REASON_MINOR_MAINTENANCE 0x00000001 27 | #define SHTDN_REASON_MINOR_INSTALLATION 0x00000002 28 | #define SHTDN_REASON_MINOR_UPGRADE 0x00000003 29 | #define SHTDN_REASON_MINOR_RECONFIG 0x00000004 30 | #define SHTDN_REASON_MINOR_HUNG 0x00000005 31 | #define SHTDN_REASON_MINOR_UNSTABLE 0x00000006 32 | #define SHTDN_REASON_MINOR_DISK 0x00000007 33 | #define SHTDN_REASON_MINOR_PROCESSOR 0x00000008 34 | #define SHTDN_REASON_MINOR_NETWORKCARD 0x00000009 35 | #define SHTDN_REASON_MINOR_POWER_SUPPLY 0x0000000a 36 | #define SHTDN_REASON_MINOR_CORDUNPLUGGED 0x0000000b 37 | #define SHTDN_REASON_MINOR_ENVIRONMENT 0x0000000c 38 | #define SHTDN_REASON_MINOR_HARDWARE_DRIVER 0x0000000d 39 | #define SHTDN_REASON_MINOR_OTHERDRIVER 0x0000000e 40 | #define SHTDN_REASON_MINOR_BLUESCREEN 0x0000000F 41 | #define SHTDN_REASON_MINOR_SERVICEPACK 0x00000010 42 | #define SHTDN_REASON_MINOR_HOTFIX 0x00000011 43 | #define SHTDN_REASON_MINOR_SECURITYFIX 0x00000012 44 | #define SHTDN_REASON_MINOR_SECURITY 0x00000013 45 | #define SHTDN_REASON_MINOR_NETWORK_CONNECTIVITY 0x00000014 46 | #define SHTDN_REASON_MINOR_WMI 0x00000015 47 | #define SHTDN_REASON_MINOR_SERVICEPACK_UNINSTALL 0x00000016 48 | #define SHTDN_REASON_MINOR_HOTFIX_UNINSTALL 0x00000017 49 | #define SHTDN_REASON_MINOR_SECURITYFIX_UNINSTALL 0x00000018 50 | #define SHTDN_REASON_MINOR_MMC 0x00000019 51 | #define SHTDN_REASON_MINOR_SYSTEMRESTORE 0x0000001a 52 | #define SHTDN_REASON_MINOR_TERMSRV 0x00000020 53 | #define SHTDN_REASON_MINOR_DC_PROMOTION 0x00000021 54 | #define SHTDN_REASON_MINOR_DC_DEMOTION 0x00000022 55 | #define SHTDN_REASON_UNKNOWN SHTDN_REASON_MINOR_NONE 56 | #define SHTDN_REASON_LEGACY_API (SHTDN_REASON_MAJOR_LEGACY_API | SHTDN_REASON_FLAG_PLANNED) 57 | #define SHTDN_REASON_VALID_BIT_MASK 0xc0ffffff 58 | 59 | #define PCLEANUI (SHTDN_REASON_FLAG_PLANNED | SHTDN_REASON_FLAG_CLEAN_UI) 60 | #define UCLEANUI (SHTDN_REASON_FLAG_CLEAN_UI) 61 | #define PDIRTYUI (SHTDN_REASON_FLAG_PLANNED | SHTDN_REASON_FLAG_DIRTY_UI) 62 | #define UDIRTYUI (SHTDN_REASON_FLAG_DIRTY_UI) 63 | 64 | #define MAX_REASON_NAME_LEN 64 65 | #define MAX_REASON_DESC_LEN 256 66 | #define MAX_REASON_BUGID_LEN 32 67 | #define MAX_REASON_COMMENT_LEN 512 68 | #define SHUTDOWN_TYPE_LEN 32 69 | 70 | #define POLICY_SHOWREASONUI_NEVER 0 71 | #define POLICY_SHOWREASONUI_ALWAYS 1 72 | #define POLICY_SHOWREASONUI_WORKSTATIONONLY 2 73 | #define POLICY_SHOWREASONUI_SERVERONLY 3 74 | 75 | #define SNAPSHOT_POLICY_NEVER 0 76 | #define SNAPSHOT_POLICY_ALWAYS 1 77 | #define SNAPSHOT_POLICY_UNPLANNED 2 78 | 79 | #define MAX_NUM_REASONS 256 80 | #endif 81 | -------------------------------------------------------------------------------- /libtcc.h: -------------------------------------------------------------------------------- 1 | #ifndef LIBTCC_H 2 | #define LIBTCC_H 3 | 4 | #ifndef LIBTCCAPI 5 | # define LIBTCCAPI 6 | #endif 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | struct TCCState; 13 | 14 | typedef struct TCCState TCCState; 15 | 16 | /* create a new TCC compilation context */ 17 | LIBTCCAPI TCCState *tcc_new(void); 18 | 19 | /* free a TCC compilation context */ 20 | LIBTCCAPI void tcc_delete(TCCState *s); 21 | 22 | /* set CONFIG_TCCDIR at runtime */ 23 | LIBTCCAPI void tcc_set_lib_path(TCCState *s, const char *path); 24 | 25 | /* set error/warning display callback */ 26 | LIBTCCAPI void tcc_set_error_func(TCCState *s, void *error_opaque, 27 | void (*error_func)(void *opaque, const char *msg)); 28 | 29 | /* set options as from command line (multiple supported) */ 30 | LIBTCCAPI int tcc_set_options(TCCState *s, const char *str); 31 | 32 | /*****************************/ 33 | /* preprocessor */ 34 | 35 | /* add include path */ 36 | LIBTCCAPI int tcc_add_include_path(TCCState *s, const char *pathname); 37 | 38 | /* add in system include path */ 39 | LIBTCCAPI int tcc_add_sysinclude_path(TCCState *s, const char *pathname); 40 | 41 | /* define preprocessor symbol 'sym'. Can put optional value */ 42 | LIBTCCAPI void tcc_define_symbol(TCCState *s, const char *sym, const char *value); 43 | 44 | /* undefine preprocess symbol 'sym' */ 45 | LIBTCCAPI void tcc_undefine_symbol(TCCState *s, const char *sym); 46 | 47 | /*****************************/ 48 | /* compiling */ 49 | 50 | /* add a file (C file, dll, object, library, ld script). Return -1 if error. */ 51 | LIBTCCAPI int tcc_add_file(TCCState *s, const char *filename); 52 | 53 | /* compile a string containing a C source. Return -1 if error. */ 54 | LIBTCCAPI int tcc_compile_string(TCCState *s, const char *buf); 55 | 56 | /*****************************/ 57 | /* linking commands */ 58 | 59 | /* set output type. MUST BE CALLED before any compilation */ 60 | LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type); 61 | #define TCC_OUTPUT_MEMORY 0 /* output will be run in memory (default) */ 62 | #define TCC_OUTPUT_EXE 1 /* executable file */ 63 | #define TCC_OUTPUT_DLL 2 /* dynamic library */ 64 | #define TCC_OUTPUT_OBJ 3 /* object file */ 65 | #define TCC_OUTPUT_PREPROCESS 4 /* only preprocess (used internally) */ 66 | 67 | /* equivalent to -Lpath option */ 68 | LIBTCCAPI int tcc_add_library_path(TCCState *s, const char *pathname); 69 | 70 | /* the library name is the same as the argument of the '-l' option */ 71 | LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname); 72 | 73 | /* add a symbol to the compiled program */ 74 | LIBTCCAPI int tcc_add_symbol(TCCState *s, const char *name, const void *val); 75 | 76 | /* output an executable, library or object file. DO NOT call 77 | tcc_relocate() before. */ 78 | LIBTCCAPI int tcc_output_file(TCCState *s, const char *filename); 79 | 80 | /* link and run main() function and return its value. DO NOT call 81 | tcc_relocate() before. */ 82 | LIBTCCAPI int tcc_run(TCCState *s, int argc, char **argv); 83 | 84 | /* do all relocations (needed before using tcc_get_symbol()) */ 85 | LIBTCCAPI int tcc_relocate(TCCState *s1, void *ptr); 86 | /* possible values for 'ptr': 87 | - TCC_RELOCATE_AUTO : Allocate and manage memory internally 88 | - NULL : return required memory size for the step below 89 | - memory address : copy code to memory passed by the caller 90 | returns -1 if error. */ 91 | #define TCC_RELOCATE_AUTO (void*)1 92 | 93 | /* return symbol value or NULL if not found */ 94 | LIBTCCAPI void *tcc_get_symbol(TCCState *s, const char *name); 95 | 96 | #ifdef __cplusplus 97 | } 98 | #endif 99 | 100 | #endif 101 | -------------------------------------------------------------------------------- /win32/include/sec_api/mbstring_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_MBSTRING_S 7 | #define _INC_MBSTRING_S 8 | 9 | #include 10 | 11 | #if defined(MINGW_HAS_SECURE_API) 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | #ifndef _MBSTRING_S_DEFINED 18 | #define _MBSTRING_S_DEFINED 19 | _CRTIMP errno_t __cdecl _mbscat_s(unsigned char *_Dst,size_t _DstSizeInBytes,const unsigned char *_Src); 20 | _CRTIMP errno_t __cdecl _mbscat_s_l(unsigned char *_Dst,size_t _DstSizeInBytes,const unsigned char *_Src,_locale_t _Locale); 21 | _CRTIMP errno_t __cdecl _mbscpy_s(unsigned char *_Dst,size_t _DstSizeInBytes,const unsigned char *_Src); 22 | _CRTIMP errno_t __cdecl _mbscpy_s_l(unsigned char *_Dst,size_t _DstSizeInBytes,const unsigned char *_Src,_locale_t _Locale); 23 | _CRTIMP errno_t __cdecl _mbslwr_s(unsigned char *_Str,size_t _SizeInBytes); 24 | _CRTIMP errno_t __cdecl _mbslwr_s_l(unsigned char *_Str,size_t _SizeInBytes,_locale_t _Locale); 25 | _CRTIMP errno_t __cdecl _mbsnbcat_s(unsigned char *_Dst,size_t _DstSizeInBytes,const unsigned char *_Src,size_t _MaxCount); 26 | _CRTIMP errno_t __cdecl _mbsnbcat_s_l(unsigned char *_Dst,size_t _DstSizeInBytes,const unsigned char *_Src,size_t _MaxCount,_locale_t _Locale); 27 | _CRTIMP errno_t __cdecl _mbsnbcpy_s(unsigned char *_Dst,size_t _DstSizeInBytes,const unsigned char *_Src,size_t _MaxCount); 28 | _CRTIMP errno_t __cdecl _mbsnbcpy_s_l(unsigned char *_Dst,size_t _DstSizeInBytes,const unsigned char *_Src,size_t _MaxCount,_locale_t _Locale); 29 | _CRTIMP errno_t __cdecl _mbsnbset_s(unsigned char *_Dst,size_t _DstSizeInBytes,unsigned int _Ch,size_t _MaxCount); 30 | _CRTIMP errno_t __cdecl _mbsnbset_s_l(unsigned char *_Dst,size_t _DstSizeInBytes,unsigned int _Ch,size_t _MaxCount,_locale_t _Locale); 31 | _CRTIMP errno_t __cdecl _mbsncat_s(unsigned char *_Dst,size_t _DstSizeInBytes,const unsigned char *_Src,size_t _MaxCount); 32 | _CRTIMP errno_t __cdecl _mbsncat_s_l(unsigned char *_Dst,size_t _DstSizeInBytes,const unsigned char *_Src,size_t _MaxCount,_locale_t _Locale); 33 | _CRTIMP errno_t __cdecl _mbsncpy_s(unsigned char *_Dst,size_t _DstSizeInBytes,const unsigned char *_Src,size_t _MaxCount); 34 | _CRTIMP errno_t __cdecl _mbsncpy_s_l(unsigned char *_Dst,size_t _DstSizeInBytes,const unsigned char *_Src,size_t _MaxCount,_locale_t _Locale); 35 | _CRTIMP errno_t __cdecl _mbsnset_s(unsigned char *_Dst,size_t _DstSizeInBytes,unsigned int _Val,size_t _MaxCount); 36 | _CRTIMP errno_t __cdecl _mbsnset_s_l(unsigned char *_Dst,size_t _DstSizeInBytes,unsigned int _Val,size_t _MaxCount,_locale_t _Locale); 37 | _CRTIMP errno_t __cdecl _mbsset_s(unsigned char *_Dst,size_t _DstSizeInBytes,unsigned int _Val); 38 | _CRTIMP errno_t __cdecl _mbsset_s_l(unsigned char *_Dst,size_t _DstSizeInBytes,unsigned int _Val,_locale_t _Locale); 39 | _CRTIMP unsigned char *__cdecl _mbstok_s(unsigned char *_Str,const unsigned char *_Delim,unsigned char **_Context); 40 | _CRTIMP unsigned char *__cdecl _mbstok_s_l(unsigned char *_Str,const unsigned char *_Delim,unsigned char **_Context,_locale_t _Locale); 41 | _CRTIMP errno_t __cdecl _mbsupr_s(unsigned char *_Str,size_t _SizeInBytes); 42 | _CRTIMP errno_t __cdecl _mbsupr_s_l(unsigned char *_Str,size_t _SizeInBytes,_locale_t _Locale); 43 | _CRTIMP errno_t __cdecl _mbccpy_s(unsigned char *_Dst,size_t _DstSizeInBytes,int *_PCopied,const unsigned char *_Src); 44 | _CRTIMP errno_t __cdecl _mbccpy_s_l(unsigned char *_Dst,size_t _DstSizeInBytes,int *_PCopied,const unsigned char *_Src,_locale_t _Locale); 45 | #endif 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | 51 | #endif 52 | #endif 53 | -------------------------------------------------------------------------------- /tests/tests2/30_hanoi.c: -------------------------------------------------------------------------------- 1 | /* example from http://barnyard.syr.edu/quickies/hanoi.c */ 2 | 3 | /* hanoi.c: solves the tower of hanoi problem. (Programming exercise.) */ 4 | /* By Terry R. McConnell (12/2/97) */ 5 | /* Compile: cc -o hanoi hanoi.c */ 6 | 7 | /* This program does no error checking. But then, if it's right, 8 | it's right ... right ? */ 9 | 10 | 11 | /* The original towers of hanoi problem seems to have been originally posed 12 | by one M. Claus in 1883. There is a popular legend that goes along with 13 | it that has been often repeated and paraphrased. It goes something like this: 14 | In the great temple at Benares there are 3 golden spikes. On one of them, 15 | God placed 64 disks increasing in size from bottom to top, at the beginning 16 | of time. Since then, and to this day, the priest on duty constantly transfers 17 | disks, one at a time, in such a way that no larger disk is ever put on top 18 | of a smaller one. When the disks have been transferred entirely to another 19 | spike the Universe will come to an end in a large thunderclap. 20 | 21 | This paraphrases the original legend due to DeParville, La Nature, Paris 1884, 22 | Part I, 285-286. For this and further information see: Mathematical 23 | Recreations & Essays, W.W. Rouse Ball, MacMillan, NewYork, 11th Ed. 1967, 24 | 303-305. 25 | * 26 | * 27 | */ 28 | 29 | #include 30 | #include 31 | 32 | #define TRUE 1 33 | #define FALSE 0 34 | 35 | /* This is the number of "disks" on tower A initially. Taken to be 64 in the 36 | * legend. The number of moves required, in general, is 2^N - 1. For N = 64, 37 | * this is 18,446,744,073,709,551,615 */ 38 | #define N 4 39 | 40 | /* These are the three towers. For example if the state of A is 0,1,3,4, that 41 | * means that there are three discs on A of sizes 1, 3, and 4. (Think of right 42 | * as being the "down" direction.) */ 43 | int A[N], B[N], C[N]; 44 | 45 | void Hanoi(int,int*,int*,int*); 46 | 47 | /* Print the current configuration of A, B, and C to the screen */ 48 | void PrintAll() 49 | { 50 | int i; 51 | 52 | printf("A: "); 53 | for(i=0;i 8 | 9 | #ifndef __STRICT_ANSI__ 10 | 11 | #ifndef _DIRENT_H_ 12 | #define _DIRENT_H_ 13 | 14 | 15 | #pragma pack(push,_CRT_PACKING) 16 | 17 | #include 18 | 19 | #ifndef RC_INVOKED 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | struct dirent 26 | { 27 | long d_ino; /* Always zero. */ 28 | unsigned short d_reclen; /* Always zero. */ 29 | unsigned short d_namlen; /* Length of name in d_name. */ 30 | char* d_name; /* File name. */ 31 | /* NOTE: The name in the dirent structure points to the name in the 32 | * finddata_t structure in the DIR. */ 33 | }; 34 | 35 | /* 36 | * This is an internal data structure. Good programmers will not use it 37 | * except as an argument to one of the functions below. 38 | * dd_stat field is now int (was short in older versions). 39 | */ 40 | typedef struct 41 | { 42 | /* disk transfer area for this dir */ 43 | struct _finddata_t dd_dta; 44 | 45 | /* dirent struct to return from dir (NOTE: this makes this thread 46 | * safe as long as only one thread uses a particular DIR struct at 47 | * a time) */ 48 | struct dirent dd_dir; 49 | 50 | /* _findnext handle */ 51 | long dd_handle; 52 | 53 | /* 54 | * Status of search: 55 | * 0 = not started yet (next entry to read is first entry) 56 | * -1 = off the end 57 | * positive = 0 based index of next entry 58 | */ 59 | int dd_stat; 60 | 61 | /* given path for dir with search pattern (struct is extended) */ 62 | char dd_name[1]; 63 | } DIR; 64 | 65 | DIR* __cdecl opendir (const char*); 66 | struct dirent* __cdecl readdir (DIR*); 67 | int __cdecl closedir (DIR*); 68 | void __cdecl rewinddir (DIR*); 69 | long __cdecl telldir (DIR*); 70 | void __cdecl seekdir (DIR*, long); 71 | 72 | 73 | /* wide char versions */ 74 | 75 | struct _wdirent 76 | { 77 | long d_ino; /* Always zero. */ 78 | unsigned short d_reclen; /* Always zero. */ 79 | unsigned short d_namlen; /* Length of name in d_name. */ 80 | wchar_t* d_name; /* File name. */ 81 | /* NOTE: The name in the dirent structure points to the name in the * wfinddata_t structure in the _WDIR. */ 82 | }; 83 | 84 | /* 85 | * This is an internal data structure. Good programmers will not use it 86 | * except as an argument to one of the functions below. 87 | */ 88 | typedef struct 89 | { 90 | /* disk transfer area for this dir */ 91 | struct _wfinddata_t dd_dta; 92 | 93 | /* dirent struct to return from dir (NOTE: this makes this thread 94 | * safe as long as only one thread uses a particular DIR struct at 95 | * a time) */ 96 | struct _wdirent dd_dir; 97 | 98 | /* _findnext handle */ 99 | long dd_handle; 100 | 101 | /* 102 | * Status of search: 103 | * 0 = not started yet (next entry to read is first entry) 104 | * -1 = off the end 105 | * positive = 0 based index of next entry 106 | */ 107 | int dd_stat; 108 | 109 | /* given path for dir with search pattern (struct is extended) */ 110 | wchar_t dd_name[1]; 111 | } _WDIR; 112 | 113 | 114 | 115 | _WDIR* __cdecl _wopendir (const wchar_t*); 116 | struct _wdirent* __cdecl _wreaddir (_WDIR*); 117 | int __cdecl _wclosedir (_WDIR*); 118 | void __cdecl _wrewinddir (_WDIR*); 119 | long __cdecl _wtelldir (_WDIR*); 120 | void __cdecl _wseekdir (_WDIR*, long); 121 | 122 | 123 | #ifdef __cplusplus 124 | } 125 | #endif 126 | 127 | #endif /* Not RC_INVOKED */ 128 | 129 | #pragma pack(pop) 130 | 131 | #endif /* Not _DIRENT_H_ */ 132 | 133 | 134 | #endif /* Not __STRICT_ANSI__ */ 135 | 136 | -------------------------------------------------------------------------------- /win32/include/_mingw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * _mingw.h 3 | * 4 | * This file is for TinyCC and not part of the Mingw32 package. 5 | * 6 | * THIS SOFTWARE IS NOT COPYRIGHTED 7 | * 8 | * This source code is offered for use in the public domain. You may 9 | * use, modify or distribute it freely. 10 | * 11 | * This code is distributed in the hope that it will be useful but 12 | * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY 13 | * DISCLAIMED. This includes but is not limited to warranties of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 15 | * 16 | */ 17 | 18 | #ifndef __MINGW_H 19 | #define __MINGW_H 20 | 21 | /* some winapi files define these before including _mingw.h --> */ 22 | #undef __cdecl 23 | #undef _X86_ 24 | #undef WIN32 25 | /* <-- */ 26 | 27 | #include 28 | #include 29 | 30 | #define __int8 char 31 | #define __int16 short 32 | #define __int32 int 33 | #define __int64 long long 34 | 35 | #define __cdecl __attribute__((__cdecl__)) 36 | #define __declspec(x) __attribute__((x)) 37 | #define __unaligned __attribute__((packed)) 38 | #define __fastcall __attribute__((fastcall)) 39 | 40 | #define __MSVCRT__ 1 41 | #undef _MSVCRT_ 42 | #define __MINGW_IMPORT extern __declspec(dllimport) 43 | #define __MINGW_ATTRIB_NORETURN 44 | #define __MINGW_ATTRIB_CONST 45 | #define __MINGW_ATTRIB_DEPRECATED 46 | #define __MINGW_ATTRIB_MALLOC 47 | #define __MINGW_ATTRIB_PURE 48 | #define __MINGW_ATTRIB_NONNULL(arg) 49 | #define __MINGW_NOTHROW 50 | #define __GNUC_VA_LIST 51 | 52 | #define _CRTIMP extern 53 | #define __CRT_INLINE extern __inline__ 54 | 55 | #define _CRT_ALIGN(x) __attribute__((aligned(x))) 56 | #define DECLSPEC_ALIGN(x) __attribute__((aligned(x))) 57 | #define _CRT_PACKING 8 58 | #define __CRT_UNALIGNED 59 | #define _CONST_RETURN 60 | 61 | #define __CRT_STRINGIZE(_Value) #_Value 62 | #define _CRT_STRINGIZE(_Value) __CRT_STRINGIZE(_Value) 63 | #define __CRT_WIDE(_String) L ## _String 64 | #define _CRT_WIDE(_String) __CRT_WIDE(_String) 65 | 66 | #ifdef _WIN64 67 | #define __stdcall 68 | #define _AMD64_ 1 69 | #define __x86_64 1 70 | #define USE_MINGW_SETJMP_TWO_ARGS 71 | #define mingw_getsp tinyc_getbp 72 | #define __TRY__ 73 | #else 74 | #define __stdcall __attribute__((__stdcall__)) 75 | #define _X86_ 1 76 | #define WIN32 1 77 | #define _USE_32BIT_TIME_T 78 | #define __TRY__ void __try__(void**), *_sehrec[6]; __try__(_sehrec); 79 | #endif 80 | 81 | /* in stddef.h */ 82 | #define _SIZE_T_DEFINED 83 | #define _SSIZE_T_DEFINED 84 | #define _PTRDIFF_T_DEFINED 85 | #define _WCHAR_T_DEFINED 86 | #define _UINTPTR_T_DEFINED 87 | #define _INTPTR_T_DEFINED 88 | 89 | #define _INTEGRAL_MAX_BITS 64 90 | 91 | typedef long __time32_t; 92 | #define _TIME32_T_DEFINED 93 | typedef __int64 __time64_t; 94 | #define _TIME64_T_DEFINED 95 | #ifdef _USE_32BIT_TIME_T 96 | typedef __time32_t time_t; 97 | #define _TIME_T_DEFINED 98 | #else 99 | typedef __time64_t time_t; 100 | #define _TIME_T_DEFINED 101 | #endif 102 | 103 | typedef unsigned long size_t; 104 | #define _SIZE_T_DEFINED 105 | typedef long ssize_t; 106 | #define _SSIZE_T_DEFINED 107 | 108 | typedef unsigned int wint_t; 109 | typedef unsigned short wctype_t; 110 | #define _WCTYPE_T_DEFINED 111 | typedef unsigned short wchar_t; 112 | #define _WCHAR_T_DEFINED 113 | 114 | typedef int errno_t; 115 | #define _ERRCODE_DEFINED 116 | 117 | typedef struct threadlocaleinfostruct *pthreadlocinfo; 118 | typedef struct threadmbcinfostruct *pthreadmbcinfo; 119 | typedef struct localeinfo_struct _locale_tstruct,*_locale_t; 120 | 121 | /* for winapi */ 122 | #define _ANONYMOUS_UNION 123 | #define _ANONYMOUS_STRUCT 124 | #define DECLSPEC_NORETURN 125 | #define DECLARE_STDCALL_P(type) __stdcall type 126 | #define NOSERVICE 1 127 | #define NOMCX 1 128 | #define NOIME 1 129 | #ifndef WIN32_LEAN_AND_MEAN 130 | # define WIN32_LEAN_AND_MEAN 1 131 | #endif 132 | #ifndef WINVER 133 | # define WINVER 0x0502 134 | #endif 135 | #ifndef _WIN32_WINNT 136 | # define _WIN32_WINNT 0x502 137 | #endif 138 | 139 | #endif /* __MINGW_H */ 140 | -------------------------------------------------------------------------------- /win32/include/sys/utime.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_UTIME 7 | #define _INC_UTIME 8 | 9 | #ifndef _WIN32 10 | #error Only Win32 target is supported! 11 | #endif 12 | 13 | #include <_mingw.h> 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 _WCHAR_T_DEFINED 26 | typedef unsigned short wchar_t; 27 | #define _WCHAR_T_DEFINED 28 | #endif 29 | 30 | #ifndef __TINYC__ /* gr */ 31 | #ifdef _USE_32BIT_TIME_T 32 | #ifdef _WIN64 33 | #undef _USE_32BIT_TIME_T 34 | #endif 35 | #else 36 | #if _INTEGRAL_MAX_BITS < 64 37 | #define _USE_32BIT_TIME_T 38 | #endif 39 | #endif 40 | #endif 41 | 42 | #ifndef _TIME32_T_DEFINED 43 | #define _TIME32_T_DEFINED 44 | typedef long __time32_t; 45 | #endif 46 | 47 | #ifndef _TIME64_T_DEFINED 48 | #define _TIME64_T_DEFINED 49 | #if _INTEGRAL_MAX_BITS >= 64 50 | typedef __int64 __time64_t; 51 | #endif 52 | #endif 53 | 54 | #ifndef _TIME_T_DEFINED 55 | #define _TIME_T_DEFINED 56 | #ifdef _USE_32BIT_TIME_T 57 | typedef __time32_t time_t; 58 | #else 59 | typedef __time64_t time_t; 60 | #endif 61 | #endif 62 | 63 | #ifndef _UTIMBUF_DEFINED 64 | #define _UTIMBUF_DEFINED 65 | 66 | struct _utimbuf { 67 | time_t actime; 68 | time_t modtime; 69 | }; 70 | 71 | struct __utimbuf32 { 72 | __time32_t actime; 73 | __time32_t modtime; 74 | }; 75 | 76 | #if _INTEGRAL_MAX_BITS >= 64 77 | struct __utimbuf64 { 78 | __time64_t actime; 79 | __time64_t modtime; 80 | }; 81 | #endif 82 | 83 | #ifndef NO_OLDNAMES 84 | struct utimbuf { 85 | time_t actime; 86 | time_t modtime; 87 | }; 88 | 89 | struct utimbuf32 { 90 | __time32_t actime; 91 | __time32_t modtime; 92 | }; 93 | #endif 94 | #endif 95 | 96 | _CRTIMP int __cdecl _utime32(const char *_Filename,struct __utimbuf32 *_Time); 97 | _CRTIMP int __cdecl _futime32(int _FileDes,struct __utimbuf32 *_Time); 98 | _CRTIMP int __cdecl _wutime32(const wchar_t *_Filename,struct __utimbuf32 *_Time); 99 | #if _INTEGRAL_MAX_BITS >= 64 100 | _CRTIMP int __cdecl _utime64(const char *_Filename,struct __utimbuf64 *_Time); 101 | _CRTIMP int __cdecl _futime64(int _FileDes,struct __utimbuf64 *_Time); 102 | _CRTIMP int __cdecl _wutime64(const wchar_t *_Filename,struct __utimbuf64 *_Time); 103 | #endif 104 | 105 | #ifndef RC_INVOKED 106 | #ifdef _USE_32BIT_TIME_T 107 | __CRT_INLINE int __cdecl _utime(const char *_Filename,struct _utimbuf *_Utimbuf) { 108 | return _utime32(_Filename,(struct __utimbuf32 *)_Utimbuf); 109 | } 110 | __CRT_INLINE int __cdecl _futime(int _Desc,struct _utimbuf *_Utimbuf) { 111 | return _futime32(_Desc,(struct __utimbuf32 *)_Utimbuf); 112 | } 113 | __CRT_INLINE int __cdecl _wutime(const wchar_t *_Filename,struct _utimbuf *_Utimbuf) { 114 | return _wutime32(_Filename,(struct __utimbuf32 *)_Utimbuf); 115 | } 116 | #else 117 | __CRT_INLINE int __cdecl _utime(const char *_Filename,struct _utimbuf *_Utimbuf) { 118 | return _utime64(_Filename,(struct __utimbuf64 *)_Utimbuf); 119 | } 120 | __CRT_INLINE int __cdecl _futime(int _Desc,struct _utimbuf *_Utimbuf) { 121 | return _futime64(_Desc,(struct __utimbuf64 *)_Utimbuf); 122 | } 123 | __CRT_INLINE int __cdecl _wutime(const wchar_t *_Filename,struct _utimbuf *_Utimbuf) { 124 | return _wutime64(_Filename,(struct __utimbuf64 *)_Utimbuf); 125 | } 126 | #endif 127 | 128 | #ifndef NO_OLDNAMES 129 | #ifdef _USE_32BIT_TIME_T 130 | __CRT_INLINE int __cdecl utime(const char *_Filename,struct utimbuf *_Utimbuf) { 131 | return _utime32(_Filename,(struct __utimbuf32 *)_Utimbuf); 132 | } 133 | #else 134 | __CRT_INLINE int __cdecl utime(const char *_Filename,struct utimbuf *_Utimbuf) { 135 | return _utime64(_Filename,(struct __utimbuf64 *)_Utimbuf); 136 | } 137 | #endif 138 | #endif 139 | #endif 140 | 141 | #ifdef __cplusplus 142 | } 143 | #endif 144 | 145 | #pragma pack(pop) 146 | #endif 147 | -------------------------------------------------------------------------------- /win32/include/sec_api/stdlib_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_STDLIB_S 7 | #define _INC_STDLIB_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 _dupenv_s(char **_PBuffer,size_t *_PBufferSizeInBytes,const char *_VarName); 18 | _CRTIMP errno_t __cdecl _itoa_s(int _Value,char *_DstBuf,size_t _Size,int _Radix); 19 | #if _INTEGRAL_MAX_BITS >= 64 20 | _CRTIMP errno_t __cdecl _i64toa_s(__int64 _Val,char *_DstBuf,size_t _Size,int _Radix); 21 | _CRTIMP errno_t __cdecl _ui64toa_s(unsigned __int64 _Val,char *_DstBuf,size_t _Size,int _Radix); 22 | #endif 23 | _CRTIMP errno_t __cdecl _ltoa_s(long _Val,char *_DstBuf,size_t _Size,int _Radix); 24 | _CRTIMP errno_t __cdecl mbstowcs_s(size_t *_PtNumOfCharConverted,wchar_t *_DstBuf,size_t _SizeInWords,const char *_SrcBuf,size_t _MaxCount); 25 | _CRTIMP errno_t __cdecl _mbstowcs_s_l(size_t *_PtNumOfCharConverted,wchar_t *_DstBuf,size_t _SizeInWords,const char *_SrcBuf,size_t _MaxCount,_locale_t _Locale); 26 | _CRTIMP errno_t __cdecl _ultoa_s(unsigned long _Val,char *_DstBuf,size_t _Size,int _Radix); 27 | _CRTIMP errno_t __cdecl _wctomb_s_l(int *_SizeConverted,char *_MbCh,size_t _SizeInBytes,wchar_t _WCh,_locale_t _Locale); 28 | _CRTIMP errno_t __cdecl wcstombs_s(size_t *_PtNumOfCharConverted,char *_Dst,size_t _DstSizeInBytes,const wchar_t *_Src,size_t _MaxCountInBytes); 29 | _CRTIMP errno_t __cdecl _wcstombs_s_l(size_t *_PtNumOfCharConverted,char *_Dst,size_t _DstSizeInBytes,const wchar_t *_Src,size_t _MaxCountInBytes,_locale_t _Locale); 30 | 31 | #ifndef _WSTDLIB_S_DEFINED 32 | #define _WSTDLIB_S_DEFINED 33 | _CRTIMP errno_t __cdecl _itow_s (int _Val,wchar_t *_DstBuf,size_t _SizeInWords,int _Radix); 34 | _CRTIMP errno_t __cdecl _ltow_s (long _Val,wchar_t *_DstBuf,size_t _SizeInWords,int _Radix); 35 | _CRTIMP errno_t __cdecl _ultow_s (unsigned long _Val,wchar_t *_DstBuf,size_t _SizeInWords,int _Radix); 36 | _CRTIMP errno_t __cdecl _wgetenv_s(size_t *_ReturnSize,wchar_t *_DstBuf,size_t _DstSizeInWords,const wchar_t *_VarName); 37 | _CRTIMP errno_t __cdecl _wdupenv_s(wchar_t **_Buffer,size_t *_BufferSizeInWords,const wchar_t *_VarName); 38 | #if _INTEGRAL_MAX_BITS >= 64 39 | _CRTIMP errno_t __cdecl _i64tow_s(__int64 _Val,wchar_t *_DstBuf,size_t _SizeInWords,int _Radix); 40 | _CRTIMP errno_t __cdecl _ui64tow_s(unsigned __int64 _Val,wchar_t *_DstBuf,size_t _SizeInWords,int _Radix); 41 | #endif 42 | #endif 43 | 44 | #ifndef _POSIX_ 45 | _CRTIMP errno_t __cdecl _ecvt_s(char *_DstBuf,size_t _Size,double _Val,int _NumOfDights,int *_PtDec,int *_PtSign); 46 | _CRTIMP errno_t __cdecl _fcvt_s(char *_DstBuf,size_t _Size,double _Val,int _NumOfDec,int *_PtDec,int *_PtSign); 47 | _CRTIMP errno_t __cdecl _gcvt_s(char *_DstBuf,size_t _Size,double _Val,int _NumOfDigits); 48 | _CRTIMP errno_t __cdecl _makepath_s(char *_PathResult,size_t _Size,const char *_Drive,const char *_Dir,const char *_Filename,const char *_Ext); 49 | _CRTIMP errno_t __cdecl _putenv_s(const char *_Name,const char *_Value); 50 | _CRTIMP errno_t __cdecl _searchenv_s(const char *_Filename,const char *_EnvVar,char *_ResultPath,size_t _SizeInBytes); 51 | _CRTIMP errno_t __cdecl _splitpath_s(const char *_FullPath,char *_Drive,size_t _DriveSize,char *_Dir,size_t _DirSize,char *_Filename,size_t _FilenameSize,char *_Ext,size_t _ExtSize); 52 | 53 | #ifndef _WSTDLIBP_S_DEFINED 54 | #define _WSTDLIBP_S_DEFINED 55 | _CRTIMP errno_t __cdecl _wmakepath_s(wchar_t *_PathResult,size_t _SizeInWords,const wchar_t *_Drive,const wchar_t *_Dir,const wchar_t *_Filename,const wchar_t *_Ext); 56 | _CRTIMP errno_t __cdecl _wputenv_s(const wchar_t *_Name,const wchar_t *_Value); 57 | _CRTIMP errno_t __cdecl _wsearchenv_s(const wchar_t *_Filename,const wchar_t *_EnvVar,wchar_t *_ResultPath,size_t _SizeInWords); 58 | _CRTIMP errno_t __cdecl _wsplitpath_s(const wchar_t *_FullPath,wchar_t *_Drive,size_t _DriveSizeInWords,wchar_t *_Dir,size_t _DirSizeInWords,wchar_t *_Filename,size_t _FilenameSizeInWords,wchar_t *_Ext,size_t _ExtSizeInWords); 59 | #endif 60 | #endif 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | 66 | #endif 67 | #endif 68 | -------------------------------------------------------------------------------- /win32/include/excpt.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_EXCPT 7 | #define _INC_EXCPT 8 | 9 | #include <_mingw.h> 10 | 11 | #pragma pack(push,_CRT_PACKING) 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | struct _EXCEPTION_POINTERS; 18 | 19 | #ifndef EXCEPTION_DISPOSITION 20 | #define EXCEPTION_DISPOSITION int 21 | #endif 22 | #define ExceptionContinueExecution 0 23 | #define ExceptionContinueSearch 1 24 | #define ExceptionNestedException 2 25 | #define ExceptionCollidedUnwind 3 26 | 27 | #if (defined(_X86_) && !defined(__x86_64)) 28 | struct _EXCEPTION_RECORD; 29 | struct _CONTEXT; 30 | 31 | EXCEPTION_DISPOSITION __cdecl _except_handler(struct _EXCEPTION_RECORD *_ExceptionRecord,void *_EstablisherFrame,struct _CONTEXT *_ContextRecord,void *_DispatcherContext); 32 | #elif defined(__ia64__) 33 | 34 | typedef struct _EXCEPTION_POINTERS *Exception_info_ptr; 35 | struct _EXCEPTION_RECORD; 36 | struct _CONTEXT; 37 | struct _DISPATCHER_CONTEXT; 38 | 39 | _CRTIMP EXCEPTION_DISPOSITION __cdecl __C_specific_handler (struct _EXCEPTION_RECORD *_ExceptionRecord,unsigned __int64 _MemoryStackFp,unsigned __int64 _BackingStoreFp,struct _CONTEXT *_ContextRecord,struct _DISPATCHER_CONTEXT *_DispatcherContext,unsigned __int64 _GlobalPointer); 40 | #elif defined(__x86_64) 41 | 42 | struct _EXCEPTION_RECORD; 43 | struct _CONTEXT; 44 | #endif 45 | 46 | #define GetExceptionCode _exception_code 47 | #define exception_code _exception_code 48 | #define GetExceptionInformation (struct _EXCEPTION_POINTERS *)_exception_info 49 | #define exception_info (struct _EXCEPTION_POINTERS *)_exception_info 50 | #define AbnormalTermination _abnormal_termination 51 | #define abnormal_termination _abnormal_termination 52 | 53 | unsigned long __cdecl _exception_code(void); 54 | void *__cdecl _exception_info(void); 55 | int __cdecl _abnormal_termination(void); 56 | 57 | #define EXCEPTION_EXECUTE_HANDLER 1 58 | #define EXCEPTION_CONTINUE_SEARCH 0 59 | #define EXCEPTION_CONTINUE_EXECUTION -1 60 | 61 | /* CRT stuff */ 62 | typedef void (__cdecl * _PHNDLR)(int); 63 | 64 | struct _XCPT_ACTION { 65 | unsigned long XcptNum; 66 | int SigNum; 67 | _PHNDLR XcptAction; 68 | }; 69 | 70 | extern struct _XCPT_ACTION _XcptActTab[]; 71 | extern int _XcptActTabCount; 72 | extern int _XcptActTabSize; 73 | extern int _First_FPE_Indx; 74 | extern int _Num_FPE; 75 | 76 | int __cdecl __CppXcptFilter(unsigned long _ExceptionNum,struct _EXCEPTION_POINTERS * _ExceptionPtr); 77 | int __cdecl _XcptFilter(unsigned long _ExceptionNum,struct _EXCEPTION_POINTERS * _ExceptionPtr); 78 | 79 | /* 80 | * The type of function that is expected as an exception handler to be 81 | * installed with _try1. 82 | */ 83 | typedef EXCEPTION_DISPOSITION (*PEXCEPTION_HANDLER)(struct _EXCEPTION_RECORD*, void*, struct _CONTEXT*, void*); 84 | 85 | #ifndef HAVE_NO_SEH 86 | /* 87 | * This is not entirely necessary, but it is the structure installed by 88 | * the _try1 primitive below. 89 | */ 90 | typedef struct _EXCEPTION_REGISTRATION { 91 | struct _EXCEPTION_REGISTRATION *prev; 92 | EXCEPTION_DISPOSITION (*handler)(struct _EXCEPTION_RECORD*, void*, struct _CONTEXT*, void*); 93 | } EXCEPTION_REGISTRATION, *PEXCEPTION_REGISTRATION; 94 | 95 | typedef EXCEPTION_REGISTRATION EXCEPTION_REGISTRATION_RECORD; 96 | typedef PEXCEPTION_REGISTRATION PEXCEPTION_REGISTRATION_RECORD; 97 | #endif 98 | 99 | #if (defined(_X86_) && !defined(__x86_64)) 100 | #define __try1(pHandler) \ 101 | __asm__ ("pushl %0;pushl %%fs:0;movl %%esp,%%fs:0;" : : "g" (pHandler)); 102 | 103 | #define __except1 \ 104 | __asm__ ("movl (%%esp),%%eax;movl %%eax,%%fs:0;addl $8,%%esp;" \ 105 | : : : "%eax"); 106 | #elif defined(__x86_64) 107 | #define __try1(pHandler) \ 108 | __asm__ ("pushq %0;pushq %%gs:0;movq %%rsp,%%gs:0;" : : "g" (pHandler)); 109 | 110 | #define __except1 \ 111 | __asm__ ("movq (%%rsp),%%rax;movq %%rax,%%gs:0;addq $16,%%rsp;" \ 112 | : : : "%rax"); 113 | #else 114 | #define __try1(pHandler) 115 | #define __except1 116 | #endif 117 | 118 | #ifdef __cplusplus 119 | } 120 | #endif 121 | 122 | #pragma pack(pop) 123 | #endif 124 | -------------------------------------------------------------------------------- /tests/boundtest.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define NB_ITS 1000000 5 | //#define NB_ITS 1 6 | #define TAB_SIZE 100 7 | 8 | int tab[TAB_SIZE]; 9 | int ret_sum; 10 | char tab3[256]; 11 | 12 | int test1(void) 13 | { 14 | int i, sum = 0; 15 | for(i=0;i= 2) 222 | index = atoi(argv[1]); 223 | /* well, we also use bounds on this ! */ 224 | ftest = table_test[index]; 225 | ftest(); 226 | 227 | return 0; 228 | } 229 | 230 | /* 231 | * without bound 0.77 s 232 | * with bounds 4.73 233 | */ 234 | -------------------------------------------------------------------------------- /win32/include/setjmp.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_SETJMP 7 | #define _INC_SETJMP 8 | 9 | #include <_mingw.h> 10 | 11 | #pragma pack(push,_CRT_PACKING) 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | #if (defined(_X86_) && !defined(__x86_64)) 18 | 19 | #define _JBLEN 16 20 | #define _JBTYPE int 21 | 22 | typedef struct __JUMP_BUFFER { 23 | unsigned long Ebp; 24 | unsigned long Ebx; 25 | unsigned long Edi; 26 | unsigned long Esi; 27 | unsigned long Esp; 28 | unsigned long Eip; 29 | unsigned long Registration; 30 | unsigned long TryLevel; 31 | unsigned long Cookie; 32 | unsigned long UnwindFunc; 33 | unsigned long UnwindData[6]; 34 | } _JUMP_BUFFER; 35 | #elif defined(__ia64__) 36 | typedef _CRT_ALIGN(16) struct _SETJMP_FLOAT128 { 37 | __int64 LowPart; 38 | __int64 HighPart; 39 | } SETJMP_FLOAT128; 40 | 41 | #define _JBLEN 33 42 | typedef SETJMP_FLOAT128 _JBTYPE; 43 | 44 | typedef struct __JUMP_BUFFER { 45 | 46 | unsigned long iAReserved[6]; 47 | 48 | unsigned long Registration; 49 | unsigned long TryLevel; 50 | unsigned long Cookie; 51 | unsigned long UnwindFunc; 52 | 53 | unsigned long UnwindData[6]; 54 | 55 | SETJMP_FLOAT128 FltS0; 56 | SETJMP_FLOAT128 FltS1; 57 | SETJMP_FLOAT128 FltS2; 58 | SETJMP_FLOAT128 FltS3; 59 | SETJMP_FLOAT128 FltS4; 60 | SETJMP_FLOAT128 FltS5; 61 | SETJMP_FLOAT128 FltS6; 62 | SETJMP_FLOAT128 FltS7; 63 | SETJMP_FLOAT128 FltS8; 64 | SETJMP_FLOAT128 FltS9; 65 | SETJMP_FLOAT128 FltS10; 66 | SETJMP_FLOAT128 FltS11; 67 | SETJMP_FLOAT128 FltS12; 68 | SETJMP_FLOAT128 FltS13; 69 | SETJMP_FLOAT128 FltS14; 70 | SETJMP_FLOAT128 FltS15; 71 | SETJMP_FLOAT128 FltS16; 72 | SETJMP_FLOAT128 FltS17; 73 | SETJMP_FLOAT128 FltS18; 74 | SETJMP_FLOAT128 FltS19; 75 | __int64 FPSR; 76 | __int64 StIIP; 77 | __int64 BrS0; 78 | __int64 BrS1; 79 | __int64 BrS2; 80 | __int64 BrS3; 81 | __int64 BrS4; 82 | __int64 IntS0; 83 | __int64 IntS1; 84 | __int64 IntS2; 85 | __int64 IntS3; 86 | __int64 RsBSP; 87 | __int64 RsPFS; 88 | __int64 ApUNAT; 89 | __int64 ApLC; 90 | __int64 IntSp; 91 | __int64 IntNats; 92 | __int64 Preds; 93 | 94 | } _JUMP_BUFFER; 95 | #elif defined(__x86_64) 96 | typedef _CRT_ALIGN(16) struct _SETJMP_FLOAT128 { 97 | unsigned __int64 Part[2]; 98 | } SETJMP_FLOAT128; 99 | 100 | #define _JBLEN 16 101 | typedef SETJMP_FLOAT128 _JBTYPE; 102 | 103 | typedef struct _JUMP_BUFFER { 104 | unsigned __int64 Frame; 105 | unsigned __int64 Rbx; 106 | unsigned __int64 Rsp; 107 | unsigned __int64 Rbp; 108 | unsigned __int64 Rsi; 109 | unsigned __int64 Rdi; 110 | unsigned __int64 R12; 111 | unsigned __int64 R13; 112 | unsigned __int64 R14; 113 | unsigned __int64 R15; 114 | unsigned __int64 Rip; 115 | unsigned __int64 Spare; 116 | SETJMP_FLOAT128 Xmm6; 117 | SETJMP_FLOAT128 Xmm7; 118 | SETJMP_FLOAT128 Xmm8; 119 | SETJMP_FLOAT128 Xmm9; 120 | SETJMP_FLOAT128 Xmm10; 121 | SETJMP_FLOAT128 Xmm11; 122 | SETJMP_FLOAT128 Xmm12; 123 | SETJMP_FLOAT128 Xmm13; 124 | SETJMP_FLOAT128 Xmm14; 125 | SETJMP_FLOAT128 Xmm15; 126 | } _JUMP_BUFFER; 127 | #endif 128 | #ifndef _JMP_BUF_DEFINED 129 | typedef _JBTYPE jmp_buf[_JBLEN]; 130 | #define _JMP_BUF_DEFINED 131 | #endif 132 | 133 | void * __cdecl __attribute__ ((__nothrow__)) mingw_getsp(void); 134 | 135 | #ifdef USE_MINGW_SETJMP_TWO_ARGS 136 | #ifndef _INC_SETJMPEX 137 | #define setjmp(BUF) _setjmp((BUF),mingw_getsp()) 138 | int __cdecl __attribute__ ((__nothrow__)) _setjmp(jmp_buf _Buf,void *_Ctx); 139 | #else 140 | #undef setjmp 141 | #define setjmp(BUF) _setjmpex((BUF),mingw_getsp()) 142 | #define setjmpex(BUF) _setjmpex((BUF),mingw_getsp()) 143 | int __cdecl __attribute__ ((__nothrow__)) _setjmpex(jmp_buf _Buf,void *_Ctx); 144 | #endif 145 | #else 146 | #ifndef _INC_SETJMPEX 147 | #define setjmp _setjmp 148 | #endif 149 | int __cdecl __attribute__ ((__nothrow__)) setjmp(jmp_buf _Buf); 150 | #endif 151 | 152 | __declspec(noreturn) __attribute__ ((__nothrow__)) void __cdecl ms_longjmp(jmp_buf _Buf,int _Value)/* throw(...)*/; 153 | __declspec(noreturn) __attribute__ ((__nothrow__)) void __cdecl longjmp(jmp_buf _Buf,int _Value); 154 | 155 | #ifdef __cplusplus 156 | } 157 | #endif 158 | 159 | #pragma pack(pop) 160 | #endif 161 | -------------------------------------------------------------------------------- /win32/include/winapi/guiddef.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 GUID_DEFINED 7 | #define GUID_DEFINED 8 | typedef struct _GUID { 9 | unsigned long Data1; 10 | unsigned short Data2; 11 | unsigned short Data3; 12 | unsigned char Data4[8 ]; 13 | } GUID; 14 | #endif 15 | 16 | #ifndef FAR 17 | #define FAR 18 | #endif 19 | 20 | #ifndef DECLSPEC_SELECTANY 21 | #define DECLSPEC_SELECTANY __declspec(selectany) 22 | #endif 23 | 24 | #ifndef EXTERN_C 25 | #ifdef __cplusplus 26 | #define EXTERN_C extern "C" 27 | #else 28 | #define EXTERN_C extern 29 | #endif 30 | #endif 31 | 32 | #ifdef DEFINE_GUID 33 | #undef DEFINE_GUID 34 | #endif 35 | 36 | #ifdef INITGUID 37 | #ifdef __cplusplus 38 | #define DEFINE_GUID(name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) EXTERN_C const GUID DECLSPEC_SELECTANY name = { l,w1,w2,{ b1,b2,b3,b4,b5,b6,b7,b8 } } 39 | #else 40 | #define DEFINE_GUID(name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) const GUID DECLSPEC_SELECTANY name = { l,w1,w2,{ b1,b2,b3,b4,b5,b6,b7,b8 } } 41 | #endif 42 | #else 43 | #define DEFINE_GUID(name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) EXTERN_C const GUID name 44 | #endif 45 | 46 | #define DEFINE_OLEGUID(name,l,w1,w2) DEFINE_GUID(name,l,w1,w2,0xC0,0,0,0,0,0,0,0x46) 47 | 48 | #ifndef _GUIDDEF_H_ 49 | #define _GUIDDEF_H_ 50 | 51 | #ifndef __LPGUID_DEFINED__ 52 | #define __LPGUID_DEFINED__ 53 | typedef GUID *LPGUID; 54 | #endif 55 | 56 | #ifndef __LPCGUID_DEFINED__ 57 | #define __LPCGUID_DEFINED__ 58 | typedef const GUID *LPCGUID; 59 | #endif 60 | 61 | #ifndef __IID_DEFINED__ 62 | #define __IID_DEFINED__ 63 | 64 | typedef GUID IID; 65 | typedef IID *LPIID; 66 | #define IID_NULL GUID_NULL 67 | #define IsEqualIID(riid1,riid2) IsEqualGUID(riid1,riid2) 68 | typedef GUID CLSID; 69 | typedef CLSID *LPCLSID; 70 | #define CLSID_NULL GUID_NULL 71 | #define IsEqualCLSID(rclsid1,rclsid2) IsEqualGUID(rclsid1,rclsid2) 72 | typedef GUID FMTID; 73 | typedef FMTID *LPFMTID; 74 | #define FMTID_NULL GUID_NULL 75 | #define IsEqualFMTID(rfmtid1,rfmtid2) IsEqualGUID(rfmtid1,rfmtid2) 76 | 77 | #ifdef __midl_proxy 78 | #define __MIDL_CONST 79 | #else 80 | #define __MIDL_CONST const 81 | #endif 82 | 83 | #ifndef _REFGUID_DEFINED 84 | #define _REFGUID_DEFINED 85 | #ifdef __cplusplus 86 | #define REFGUID const GUID & 87 | #else 88 | #define REFGUID const GUID *__MIDL_CONST 89 | #endif 90 | #endif 91 | 92 | #ifndef _REFIID_DEFINED 93 | #define _REFIID_DEFINED 94 | #ifdef __cplusplus 95 | #define REFIID const IID & 96 | #else 97 | #define REFIID const IID *__MIDL_CONST 98 | #endif 99 | #endif 100 | 101 | #ifndef _REFCLSID_DEFINED 102 | #define _REFCLSID_DEFINED 103 | #ifdef __cplusplus 104 | #define REFCLSID const IID & 105 | #else 106 | #define REFCLSID const IID *__MIDL_CONST 107 | #endif 108 | #endif 109 | 110 | #ifndef _REFFMTID_DEFINED 111 | #define _REFFMTID_DEFINED 112 | #ifdef __cplusplus 113 | #define REFFMTID const IID & 114 | #else 115 | #define REFFMTID const IID *__MIDL_CONST 116 | #endif 117 | #endif 118 | #endif 119 | 120 | #ifndef _SYS_GUID_OPERATORS_ 121 | #define _SYS_GUID_OPERATORS_ 122 | #include 123 | 124 | #ifdef __cplusplus 125 | __inline int InlineIsEqualGUID(REFGUID rguid1,REFGUID rguid2) { 126 | return (((unsigned long *) &rguid1)[0]==((unsigned long *) &rguid2)[0] && ((unsigned long *) &rguid1)[1]==((unsigned long *) &rguid2)[1] && 127 | ((unsigned long *) &rguid1)[2]==((unsigned long *) &rguid2)[2] && ((unsigned long *) &rguid1)[3]==((unsigned long *) &rguid2)[3]); 128 | } 129 | __inline int IsEqualGUID(REFGUID rguid1,REFGUID rguid2) { return !memcmp(&rguid1,&rguid2,sizeof(GUID)); } 130 | #else 131 | #define InlineIsEqualGUID(rguid1,rguid2) (((unsigned long *) rguid1)[0]==((unsigned long *) rguid2)[0] && ((unsigned long *) rguid1)[1]==((unsigned long *) rguid2)[1] && ((unsigned long *) rguid1)[2]==((unsigned long *) rguid2)[2] && ((unsigned long *) rguid1)[3]==((unsigned long *) rguid2)[3]) 132 | #define IsEqualGUID(rguid1,rguid2) (!memcmp(rguid1,rguid2,sizeof(GUID))) 133 | #endif 134 | 135 | #ifdef __INLINE_ISEQUAL_GUID 136 | #undef IsEqualGUID 137 | #define IsEqualGUID(rguid1,rguid2) InlineIsEqualGUID(rguid1,rguid2) 138 | #endif 139 | 140 | #define IsEqualIID(riid1,riid2) IsEqualGUID(riid1,riid2) 141 | #define IsEqualCLSID(rclsid1,rclsid2) IsEqualGUID(rclsid1,rclsid2) 142 | 143 | #if !defined _SYS_GUID_OPERATOR_EQ_ && !defined _NO_SYS_GUID_OPERATOR_EQ_ 144 | #define _SYS_GUID_OPERATOR_EQ_ 145 | #ifdef __cplusplus 146 | __inline int operator==(REFGUID guidOne,REFGUID guidOther) { return IsEqualGUID(guidOne,guidOther); } 147 | __inline int operator!=(REFGUID guidOne,REFGUID guidOther) { return !(guidOne==guidOther); } 148 | #endif 149 | #endif 150 | #endif 151 | #endif 152 | --------------------------------------------------------------------------------