/programs/develop/ktcc/trunk/source/tests/CMakeLists.txt |
---|
0,0 → 1,138 |
include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}) |
set(TCC_CFLAGS -I${CMAKE_SOURCE_DIR} -I${CMAKE_SOURCE_DIR}/include -B${CMAKE_BINARY_DIR}) |
if(WIN32) |
set(TCC_CFLAGS ${TCC_CFLAGS} -I${CMAKE_SOURCE_DIR}/win32/include) |
else() |
set(TCC_MATH_LDFLAGS -lm) |
set(LIBTCC_EXTRA_LIBS dl) |
set(LIBTCC_LDFLAGS -ldl -lm -Wl,-rpath=${CMAKE_BINARY_DIR}) |
endif() |
add_executable(abitest-cc abitest.c) |
target_link_libraries(abitest-cc libtcc ${LIBTCC_EXTRA_LIBS}) |
add_test(NAME abitest-cc WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMAND abitest-cc lib_path=${CMAKE_BINARY_DIR} include=${CMAKE_SOURCE_DIR}/include) |
set(ABITEST_TCC abitest-tcc${CMAKE_EXECUTABLE_SUFFIX}) |
get_property(LIBTCC_LIB TARGET libtcc PROPERTY LOCATION) |
add_custom_command(OUTPUT ${ABITEST_TCC} COMMAND tcc ${TCC_CFLAGS} -g ${CMAKE_CURRENT_SOURCE_DIR}/abitest.c ${LIBTCC_LDFLAGS} ${LIBTCC_LIB} -o ${ABITEST_TCC} DEPENDS tcc ${CMAKE_CURRENT_SOURCE_DIR}/abitest.c) |
add_custom_target(abitest-tcc-exe ALL DEPENDS ${ABITEST_TCC}) |
add_test(NAME abitest-tcc WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${ABITEST_TCC} lib_path=${CMAKE_BINARY_DIR} include=${CMAKE_SOURCE_DIR}/include) |
set(VLA_TEST vla_test${CMAKE_EXECUTABLE_SUFFIX}) |
add_custom_command(OUTPUT ${VLA_TEST} COMMAND tcc ${TCC_CFLAGS} -g ${CMAKE_CURRENT_SOURCE_DIR}/vla_test.c -o ${VLA_TEST} DEPENDS tcc ${CMAKE_CURRENT_SOURCE_DIR}/vla_test.c) |
add_custom_target(vla_test-exe ALL DEPENDS ${VLA_TEST}) |
add_test(vla_test vla_test) |
add_executable(tcctest-cc tcctest.c) |
target_link_libraries(tcctest-cc libtcc) |
set_target_properties(tcctest-cc PROPERTIES COMPILE_FLAGS -std=gnu99) |
find_package(PythonInterp) |
if(PYTHONINTERP_FOUND) |
set(TCC_TEST_CFLAGS ${TCC_CFLAGS} -B${CMAKE_BINARY_DIR} -I${CMAKE_BINARY_DIR}) |
if(WIN32) |
set(TCC_TEST_CFLAGS ${TCC_TEST_CFLAGS} -I${CMAKE_SOURCE_DIR}/win32/include/winapi) |
endif() |
set(TCC_TEST_SOURCE ${TCC_TEST_CFLAGS} ${TCC_MATH_LDFLAGS} -run ${CMAKE_CURRENT_SOURCE_DIR}/tcctest.c) |
set(TCC_TEST_RUN ${TCC_TEST_CFLAGS} ${TCC_NATIVE_FLAGS} -DONE_SOURCE -run ${CMAKE_SOURCE_DIR}/tcc.c) |
get_property(TCC TARGET tcc PROPERTY LOCATION) |
get_property(TCCTESTCC TARGET tcctest-cc PROPERTY LOCATION) |
set(TCCTEST_PY ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tcctest.py ${TCCTESTCC}) |
add_test(test1 ${TCCTEST_PY} ${TCC} ${TCC_TEST_SOURCE}) |
add_test(test2 ${TCCTEST_PY} ${TCC} ${TCC_TEST_RUN} ${TCC_TEST_SOURCE}) |
add_test(test3 ${TCCTEST_PY} ${TCC} ${TCC_TEST_RUN} ${TCC_TEST_RUN} ${TCC_TEST_SOURCE}) |
# Object + link output |
set(TEST4 test4${CMAKE_EXECUTABLE_SUFFIX}) |
add_custom_command(OUTPUT test4.o COMMAND tcc ${TCC_TEST_CFLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/tcctest.c -c -o test4.o DEPENDS tcc ${CMAKE_CURRENT_SOURCE_DIR}/tcctest.c) |
add_custom_command(OUTPUT ${TEST4} COMMAND tcc ${TCC_TEST_CFLAGS} test4.o -o ${TEST4} DEPENDS tcc test4.o) |
add_custom_target(test4-exe ALL DEPENDS ${TEST4}) |
add_test(test4 ${TCCTEST_PY} ${CMAKE_CURRENT_BINARY_DIR}/${TEST4}) |
# Dynamic output |
set(TEST5 test5${CMAKE_EXECUTABLE_SUFFIX}) |
add_custom_command(OUTPUT ${TEST5} COMMAND tcc ${TCC_TEST_CFLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/tcctest.c -o ${TEST5} DEPENDS tcc ${CMAKE_CURRENT_SOURCE_DIR}/tcctest.c) |
add_custom_target(test5-exe ALL DEPENDS ${TEST5}) |
add_test(test5 ${TCCTEST_PY} ${CMAKE_CURRENT_BINARY_DIR}/${TEST5}) |
if(TCC_BCHECK) |
# Dynamic output + bound check |
set(TEST6 test6${CMAKE_EXECUTABLE_SUFFIX}) |
add_custom_command(OUTPUT ${TEST6} COMMAND tcc ${TCC_TEST_CFLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/tcctest.c -b -o ${TEST6} DEPENDS tcc ${CMAKE_CURRENT_SOURCE_DIR}/tcctest.c) |
add_custom_target(test6-exe ALL DEPENDS ${TEST6}) |
add_test(test6 ${TCCTEST_PY} ${CMAKE_CURRENT_BINARY_DIR}/${TEST6}) |
endif() |
if(0) |
# Static output |
set(TEST7 test7${CMAKE_EXECUTABLE_SUFFIX}) |
add_custom_command(OUTPUT ${TEST7} COMMAND tcc ${TCC_TEST_CFLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/tcctest.c -static -o ${TEST7} DEPENDS tcc ${CMAKE_CURRENT_SOURCE_DIR}/tcctest.c) |
add_custom_target(test7-exe ALL DEPENDS ${TEST7}) |
add_test(test7 ${TCCTEST_PY} ${CMAKE_CURRENT_BINARY_DIR}/${TEST7}) |
endif() |
endif() |
set(MORETESTS |
00_assignment |
01_comment |
02_printf |
03_struct |
04_for |
05_array |
06_case |
07_function |
08_while |
09_do_while |
10_pointer |
11_precedence |
12_hashdefine |
13_integer_literals |
14_if |
15_recursion |
16_nesting |
17_enum |
18_include |
19_pointer_arithmetic |
20_pointer_comparison |
21_char_array |
22_floating_point |
23_type_coercion |
24_math_library |
25_quicksort |
26_character_constants |
27_sizeof |
28_strings |
29_array_address |
31_args |
32_led |
33_ternary_op |
35_sizeof |
36_array_initialisers |
37_sprintf |
38_multiple_array_index |
39_typedef |
40_stdio |
41_hashif |
42_function_pointer |
43_void_param |
44_scoped_declarations |
45_empty_for |
47_switch_return |
48_nested_break |
49_bracket_evaluation |
50_logical_second_arg |
51_static |
52_unnamed_enum |
54_goto |
55_lshift_type |
) |
if(WIN32) |
list(REMOVE_ITEM MORETESTS 24_math_library) |
list(REMOVE_ITEM MORETESTS 28_strings) |
endif() |
foreach(testfile ${MORETESTS}) |
add_test(NAME ${testfile} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests2 |
COMMAND tcc ${TCC_CFLAGS} ${TCC_MATH_LDFLAGS} -run ${testfile}.c - arg1 arg2 arg3 arg4 | ${DIFF} - ${testfile}.expect) |
endforeach() |
/programs/develop/ktcc/trunk/source/tests/Makefile |
---|
0,0 → 1,255 |
# |
# Tiny C Compiler Makefile - tests |
# |
TOP = .. |
include $(TOP)/Makefile |
SRCDIR = $(top_srcdir)/tests |
VPATH = $(SRCDIR) $(top_srcdir) |
# clear CFLAGS and LDFLAGS |
CFLAGS := |
LDFLAGS := |
# what tests to run |
TESTS = \ |
hello-exe \ |
hello-run \ |
libtest \ |
test3 \ |
abitest \ |
vla_test-run \ |
tests2-dir pp-dir |
BTESTS = test1b test3b btest |
ifdef CONFIG_CROSS |
TESTS += hello-cross |
endif |
# test4 -- problem with -static |
# asmtest -- minor differences with gcc |
# btest -- works on i386 (including win32) |
# bounds-checking is supported only on i386 |
ifneq ($(ARCH),i386) |
TESTS := $(filter-out $(BTESTS),$(TESTS)) |
endif |
ifdef CONFIG_WIN32 |
TESTS := $(filter-out $(BTESTS),$(TESTS)) |
endif |
ifeq ($(TARGETOS),Darwin) |
TESTS := $(filter-out hello-exe test3 $(BTESTS),$(TESTS)) |
endif |
ifeq (,$(filter arm64 i386 x86-64,$(ARCH))) |
TESTS := $(filter-out vla_test-run,$(TESTS)) |
endif |
ifeq ($(CONFIG_arm_eabi),yes) |
TESTS := $(filter-out test3,$(TESTS)) |
endif |
ifdef DISABLE_STATIC |
export LD_LIBRARY_PATH:=$(CURDIR)/.. |
endif |
ifeq ($(TARGETOS),Darwin) |
CFLAGS+=-Wl,-flat_namespace,-undefined,warning |
export MACOSX_DEPLOYMENT_TARGET:=10.2 |
NATIVE_DEFINES+=-D_ANSI_SOURCE |
endif |
# run local version of tcc with local libraries and includes |
TCCFLAGS = -B$(TOP) -I$(TOP) -I$(top_srcdir) -I$(top_srcdir)/include -L$(TOP) |
ifdef CONFIG_WIN32 |
TCCFLAGS = -B$(top_srcdir)/win32 -I$(top_srcdir) -I$(top_srcdir)/include -L$(TOP) |
endif |
XTCCFLAGS = -B$(TOP) -B$(top_srcdir)/win32 -I$(TOP) -I$(top_srcdir) -I$(top_srcdir)/include |
TCC = $(TOP)/tcc $(TCCFLAGS) |
RUN_TCC = $(NATIVE_DEFINES) -DONE_SOURCE -run $(top_srcdir)/tcc.c $(TCCFLAGS) |
DISAS = objdump -d |
# libtcc test |
ifdef LIBTCC1 |
ifdef CONFIG_WIN32 |
LIBTCC1:=$(TOP)/win32/libtcc/libtcc.a |
else |
LIBTCC1:=$(TOP)/$(LIBTCC1) |
endif |
endif |
all test : $(TESTS) |
hello-exe: ../examples/ex1.c |
@echo ------------ $@ ------------ |
$(TCC) $< -o hello$(EXESUF) || ($(TOP)/tcc -vv; exit 1) && ./hello$(EXESUF) |
hello-cross: ../examples/ex1.c |
@echo ------------ $@ ------------ |
for XTCC in $(PROGS_CROSS) ; \ |
do echo -n "Test of $$XTCC... "; \ |
out=$$($(TOP)/$$XTCC $(XTCCFLAGS) -c $< 2>&1); \ |
test $$? -ne 0 && { echo "Failed\n$$out\n" ; $(TOP)/$$XTCC -vv; exit 1; } ; \ |
echo "Success"; \ |
done |
hello-run: ../examples/ex1.c |
@echo ------------ $@ ------------ |
$(TCC) -run $< |
libtest: libtcc_test$(EXESUF) $(LIBTCC1) |
@echo ------------ $@ ------------ |
./libtcc_test$(EXESUF) $(TCCFLAGS) |
libtcc_test$(EXESUF): libtcc_test.c $(top_builddir)/$(LIBTCC) |
$(CC) -o $@ $^ $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) $(LIBS) $(LINK_LIBTCC) $(LDFLAGS) -I$(top_srcdir) |
%-dir: |
@echo ------------ $@ ------------ |
$(MAKE) -k -C $* |
# test.ref - generate using cc |
test.ref: tcctest.c |
$(CC) -o tcctest.cc $< -I$(top_srcdir) $(CPPFLAGS) -w $(CFLAGS) $(NATIVE_DEFINES) -std=gnu99 -O0 -fno-omit-frame-pointer $(LDFLAGS) |
./tcctest.cc > $@ |
# auto test |
test1 test1b: tcctest.c test.ref |
@echo ------------ $@ ------------ |
$(TCC) -run $< > test.out1 |
@diff -u test.ref test.out1 && echo "Auto Test OK" |
# iterated test2 (compile tcc then compile tcctest.c !) |
test2 test2b: tcctest.c test.ref |
@echo ------------ $@ ------------ |
$(TCC) $(RUN_TCC) $(RUN_TCC) -run $< > test.out2 |
@diff -u test.ref test.out2 && echo "Auto Test2 OK" |
# iterated test3 (compile tcc then compile tcc then compile tcctest.c !) |
test3 test3b: tcctest.c test.ref |
@echo ------------ $@ ------------ |
$(TCC) $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -run $< > test.out3 |
@diff -u test.ref test.out3 && echo "Auto Test3 OK" |
test%b : TCCFLAGS += -b |
# binary output test |
test4: tcctest.c test.ref |
@echo ------------ $@ ------------ |
# object + link output |
$(TCC) -c -o tcctest3.o $< |
$(TCC) -o tcctest3 tcctest3.o |
./tcctest3 > test3.out |
@if diff -u test.ref test3.out ; then echo "Object Auto Test OK"; fi |
# dynamic output |
$(TCC) -o tcctest1 $< |
./tcctest1 > test1.out |
@if diff -u test.ref test1.out ; then echo "Dynamic Auto Test OK"; fi |
# dynamic output + bound check |
$(TCC) -b -o tcctest4 $< |
./tcctest4 > test4.out |
@if diff -u test.ref test4.out ; then echo "BCheck Auto Test OK"; fi |
# static output |
$(TCC) -static -o tcctest2 $< |
./tcctest2 > test2.out |
@if diff -u test.ref test2.out ; then echo "Static Auto Test OK"; fi |
# memory and bound check auto test |
BOUNDS_OK = 1 4 8 10 14 |
BOUNDS_FAIL= 2 5 7 9 11 12 13 15 |
btest: boundtest.c |
@echo ------------ $@ ------------ |
@for i in $(BOUNDS_OK); do \ |
echo ; echo --- boundtest $$i ---; \ |
if $(TCC) -b -run $< $$i ; then \ |
echo succeeded as expected; \ |
else\ |
echo Failed positive test $$i ; exit 1 ; \ |
fi ;\ |
done ;\ |
for i in $(BOUNDS_FAIL); do \ |
echo ; echo --- boundtest $$i ---; \ |
if $(TCC) -b -run $< $$i ; then \ |
echo Failed negative test $$i ; exit 1 ;\ |
else\ |
echo failed as expected; \ |
fi ;\ |
done ;\ |
echo; echo Bound test OK |
# speed test |
speedtest: ex2 ex3 |
@echo ------------ $@ ------------ |
time ./ex2 1238 2 3 4 10 13 4 |
time $(TCC) -run $(top_srcdir)/examples/ex2.c 1238 2 3 4 10 13 4 |
time ./ex3 35 |
time $(TCC) -run $(top_srcdir)/examples/ex3.c 35 |
weaktest: tcctest.c test.ref |
$(TCC) -c $< -o weaktest.tcc.o $(CPPFLAGS) $(CFLAGS) |
$(CC) -c $< -o weaktest.cc.o -I. $(CPPFLAGS) -w $(CFLAGS) |
objdump -t weaktest.tcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.tcc.o.txt |
objdump -t weaktest.cc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.cc.o.txt |
diff weaktest.cc.o.txt weaktest.tcc.o.txt && echo "Weak Auto Test OK" |
ex%: $(top_srcdir)/examples/ex%.c |
$(CC) -o $@ $< $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) |
# tiny assembler testing |
asmtest.ref: asmtest.S |
$(CC) -m32 -Wa,-W -o asmtest.ref.o -c asmtest.S |
objdump -D asmtest.ref.o > asmtest.ref |
asmtest: asmtest.ref |
@echo ------------ $@ ------------ |
$(TCC) -c asmtest.S |
objdump -D asmtest.o > asmtest.out |
@if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi |
# Check that code generated by libtcc is binary compatible with |
# that generated by CC |
abitest-cc$(EXESUF): abitest.c $(top_builddir)/$(LIBTCC) |
$(CC) -o $@ $^ $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) $(LIBS) $(LINK_LIBTCC) $(LDFLAGS) -I$(top_srcdir) |
abitest-tcc$(EXESUF): abitest.c libtcc.c |
$(TCC) -o $@ $^ $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) -DONE_SOURCE $(LIBS) $(LDFLAGS) -I$(top_srcdir) |
ABITESTS := abitest-cc$(EXESUF) |
ifneq ($(CONFIG_arm_eabi),yes) # not ARM soft-float |
ABITESTS += abitest-tcc$(EXESUF) |
endif |
abitest: $(ABITESTS) |
@echo ------------ $@ ------------ |
./abitest-cc$(EXESUF) $(TCCFLAGS) |
if [ "$(CONFIG_arm_eabi)" != "yes" ]; then ./abitest-tcc$(EXESUF) $(TCCFLAGS); fi |
vla_test$(EXESUF): vla_test.c |
$(TCC) -o $@ $^ $(CPPFLAGS) $(CFLAGS) |
vla_test-run: vla_test$(EXESUF) |
@echo ------------ $@ ------------ |
./vla_test$(EXESUF) |
# targets for development |
%.bin: %.c tcc |
$(TCC) -g -o $@ $< |
$(DISAS) $@ |
instr: instr.o |
objdump -d instr.o |
instr.o: instr.S |
$(CC) -o $@ -c $< -O2 -Wall -g |
cache: tcc_g |
cachegrind ./tcc_g -o /tmp/linpack -lm bench/linpack.c |
vg_annotate tcc.c > /tmp/linpack.cache.log |
# clean |
clean: |
$(MAKE) -C tests2 $@ |
rm -vf *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.cc \ |
*-cc *-tcc *.exe \ |
hello libtcc_test vla_test tcctest[1234] ex? tcc_g |
/programs/develop/ktcc/trunk/source/tests/abitest.c |
---|
0,0 → 1,673 |
#include "libtcc.h" |
#include <stdlib.h> |
#include <stdio.h> |
#include <string.h> |
#include <stdarg.h> |
#define EXIT_SUCCESS 0 |
#define EXIT_FAILURE (-1) |
// MinGW has 80-bit rather than 64-bit long double which isn't compatible with TCC or MSVC |
#if defined(_WIN32) && defined(__GNUC__) |
#define LONG_DOUBLE double |
#define LONG_DOUBLE_LITERAL(x) x |
#else |
#define LONG_DOUBLE long double |
#define LONG_DOUBLE_LITERAL(x) x ## L |
#endif |
static int g_argc; |
static char **g_argv; |
static void set_options(TCCState *s, int argc, char **argv) |
{ |
int i; |
for (i = 1; i < argc; ++i) { |
char *a = argv[i]; |
if (a[0] == '-') { |
if (a[1] == 'B') |
tcc_set_lib_path(s, a+2); |
else if (a[1] == 'I') |
tcc_add_include_path(s, a+2); |
else if (a[1] == 'L') |
tcc_add_library_path(s, a+2); |
} |
} |
} |
typedef int (*callback_type) (void*); |
/* |
* Compile source code and call a callback with a pointer to the symbol "f". |
*/ |
static int run_callback(const char *src, callback_type callback) { |
TCCState *s; |
int result; |
void *ptr; |
s = tcc_new(); |
if (!s) |
return -1; |
set_options(s, g_argc, g_argv); |
if (tcc_set_output_type(s, TCC_OUTPUT_MEMORY) == -1) |
return -1; |
if (tcc_compile_string(s, src) == -1) |
return -1; |
if (tcc_relocate(s, TCC_RELOCATE_AUTO) == -1) |
return -1; |
ptr = tcc_get_symbol(s, "f"); |
if (!ptr) |
return -1; |
result = callback(ptr); |
tcc_delete(s); |
return result; |
} |
#define STR2(x) #x |
#define STR(x) STR2(x) |
#define RET_PRIMITIVE_TEST(name, type, val) \ |
static int ret_ ## name ## _test_callback(void *ptr) { \ |
type (*callback) (type) = (type(*)(type))ptr; \ |
type x = val; \ |
type y = callback(x); \ |
return (y == x+x) ? 0 : -1; \ |
} \ |
\ |
static int ret_ ## name ## _test(void) { \ |
const char *src = STR(type) " f(" STR(type) " x) {return x+x;}"; \ |
return run_callback(src, ret_ ## name ## _test_callback); \ |
} |
RET_PRIMITIVE_TEST(int, int, 70000) |
RET_PRIMITIVE_TEST(longlong, long long, 4333369356528LL) |
RET_PRIMITIVE_TEST(float, float, 63.0) |
RET_PRIMITIVE_TEST(double, double, 14789798.0) |
RET_PRIMITIVE_TEST(longdouble, LONG_DOUBLE, LONG_DOUBLE_LITERAL(378943892.0)) |
/* |
* ret_2float_test: |
* |
* On x86-64, a struct with 2 floats should be packed into a single |
* SSE register (VT_DOUBLE is used for this purpose). |
*/ |
typedef struct ret_2float_test_type_s {float x, y;} ret_2float_test_type; |
typedef ret_2float_test_type (*ret_2float_test_function_type) (ret_2float_test_type); |
static int ret_2float_test_callback(void *ptr) { |
ret_2float_test_function_type f = (ret_2float_test_function_type)ptr; |
ret_2float_test_type a = {10, 35}; |
ret_2float_test_type r; |
r = f(a); |
return ((r.x == a.x*5) && (r.y == a.y*3)) ? 0 : -1; |
} |
static int ret_2float_test(void) { |
const char *src = |
"typedef struct ret_2float_test_type_s {float x, y;} ret_2float_test_type;" |
"ret_2float_test_type f(ret_2float_test_type a) {\n" |
" ret_2float_test_type r = {a.x*5, a.y*3};\n" |
" return r;\n" |
"}\n"; |
return run_callback(src, ret_2float_test_callback); |
} |
/* |
* ret_2double_test: |
* |
* On x86-64, a struct with 2 doubles should be passed in two SSE |
* registers. |
*/ |
typedef struct ret_2double_test_type_s {double x, y;} ret_2double_test_type; |
typedef ret_2double_test_type (*ret_2double_test_function_type) (ret_2double_test_type); |
static int ret_2double_test_callback(void *ptr) { |
ret_2double_test_function_type f = (ret_2double_test_function_type)ptr; |
ret_2double_test_type a = {10, 35}; |
ret_2double_test_type r; |
r = f(a); |
return ((r.x == a.x*5) && (r.y == a.y*3)) ? 0 : -1; |
} |
static int ret_2double_test(void) { |
const char *src = |
"typedef struct ret_2double_test_type_s {double x, y;} ret_2double_test_type;" |
"ret_2double_test_type f(ret_2double_test_type a) {\n" |
" ret_2double_test_type r = {a.x*5, a.y*3};\n" |
" return r;\n" |
"}\n"; |
return run_callback(src, ret_2double_test_callback); |
} |
/* |
* ret_8plus2double_test: |
* |
* This catches a corner case in the x86_64 ABI code: the first 7 |
* arguments fit into registers, the 8th doesn't, but the 9th argument |
* fits into the 8th XMM register. |
* |
* Note that the purpose of the 10th argument is to avoid a situation |
* in which gcc would accidentally put the double at the right |
* address, thus causing a success message even though TCC actually |
* generated incorrect code. |
*/ |
typedef ret_2double_test_type (*ret_8plus2double_test_function_type) (double, double, double, double, double, double, double, ret_2double_test_type, double, double); |
static int ret_8plus2double_test_callback(void *ptr) { |
ret_8plus2double_test_function_type f = (ret_8plus2double_test_function_type)ptr; |
ret_2double_test_type a = {10, 35}; |
ret_2double_test_type r; |
r = f(0, 0, 0, 0, 0, 0, 0, a, 37, 38); |
return ((r.x == 37) && (r.y == 37)) ? 0 : -1; |
} |
static int ret_8plus2double_test(void) { |
const char *src = |
"typedef struct ret_2double_test_type_s {double x, y;} ret_2double_test_type;" |
"ret_2double_test_type f(double x1, double x2, double x3, double x4, double x5, double x6, double x7, ret_2double_test_type a, double x8, double x9) {\n" |
" ret_2double_test_type r = { x8, x8 };\n" |
" return r;\n" |
"}\n"; |
return run_callback(src, ret_8plus2double_test_callback); |
} |
/* |
* ret_mixed_test: |
* |
* On x86-64, a struct with a double and a 64-bit integer should be |
* passed in one SSE register and one integer register. |
*/ |
typedef struct ret_mixed_test_type_s {double x; long long y;} ret_mixed_test_type; |
typedef ret_mixed_test_type (*ret_mixed_test_function_type) (ret_mixed_test_type); |
static int ret_mixed_test_callback(void *ptr) { |
ret_mixed_test_function_type f = (ret_mixed_test_function_type)ptr; |
ret_mixed_test_type a = {10, 35}; |
ret_mixed_test_type r; |
r = f(a); |
return ((r.x == a.x*5) && (r.y == a.y*3)) ? 0 : -1; |
} |
static int ret_mixed_test(void) { |
const char *src = |
"typedef struct ret_mixed_test_type_s {double x; long long y;} ret_mixed_test_type;" |
"ret_mixed_test_type f(ret_mixed_test_type a) {\n" |
" ret_mixed_test_type r = {a.x*5, a.y*3};\n" |
" return r;\n" |
"}\n"; |
return run_callback(src, ret_mixed_test_callback); |
} |
/* |
* ret_mixed2_test: |
* |
* On x86-64, a struct with two floats and two 32-bit integers should |
* be passed in one SSE register and one integer register. |
*/ |
typedef struct ret_mixed2_test_type_s {float x,x2; int y,y2;} ret_mixed2_test_type; |
typedef ret_mixed2_test_type (*ret_mixed2_test_function_type) (ret_mixed2_test_type); |
static int ret_mixed2_test_callback(void *ptr) { |
ret_mixed2_test_function_type f = (ret_mixed2_test_function_type)ptr; |
ret_mixed2_test_type a = {10, 5, 35, 7 }; |
ret_mixed2_test_type r; |
r = f(a); |
return ((r.x == a.x*5) && (r.y == a.y*3)) ? 0 : -1; |
} |
static int ret_mixed2_test(void) { |
const char *src = |
"typedef struct ret_mixed2_test_type_s {float x, x2; int y,y2;} ret_mixed2_test_type;" |
"ret_mixed2_test_type f(ret_mixed2_test_type a) {\n" |
" ret_mixed2_test_type r = {a.x*5, 0, a.y*3, 0};\n" |
" return r;\n" |
"}\n"; |
return run_callback(src, ret_mixed2_test_callback); |
} |
/* |
* ret_mixed3_test: |
* |
* On x86-64, this struct should be passed in two integer registers. |
*/ |
typedef struct ret_mixed3_test_type_s {float x; int y; float x2; int y2;} ret_mixed3_test_type; |
typedef ret_mixed3_test_type (*ret_mixed3_test_function_type) (ret_mixed3_test_type); |
static int ret_mixed3_test_callback(void *ptr) { |
ret_mixed3_test_function_type f = (ret_mixed3_test_function_type)ptr; |
ret_mixed3_test_type a = {10, 5, 35, 7 }; |
ret_mixed3_test_type r; |
r = f(a); |
return ((r.x == a.x*5) && (r.y2 == a.y*3)) ? 0 : -1; |
} |
static int ret_mixed3_test(void) { |
const char *src = |
"typedef struct ret_mixed3_test_type_s {float x; int y; float x2; int y2;} ret_mixed3_test_type;" |
"ret_mixed3_test_type f(ret_mixed3_test_type a) {\n" |
" ret_mixed3_test_type r = {a.x*5, 0, 0, a.y*3};\n" |
" return r;\n" |
"}\n"; |
return run_callback(src, ret_mixed3_test_callback); |
} |
/* |
* reg_pack_test: return a small struct which should be packed into |
* registers (Win32) during return. |
*/ |
typedef struct reg_pack_test_type_s {int x, y;} reg_pack_test_type; |
typedef reg_pack_test_type (*reg_pack_test_function_type) (reg_pack_test_type); |
static int reg_pack_test_callback(void *ptr) { |
reg_pack_test_function_type f = (reg_pack_test_function_type)ptr; |
reg_pack_test_type a = {10, 35}; |
reg_pack_test_type r; |
r = f(a); |
return ((r.x == a.x*5) && (r.y == a.y*3)) ? 0 : -1; |
} |
static int reg_pack_test(void) { |
const char *src = |
"typedef struct reg_pack_test_type_s {int x, y;} reg_pack_test_type;" |
"reg_pack_test_type f(reg_pack_test_type a) {\n" |
" reg_pack_test_type r = {a.x*5, a.y*3};\n" |
" return r;\n" |
"}\n"; |
return run_callback(src, reg_pack_test_callback); |
} |
/* |
* reg_pack_longlong_test: return a small struct which should be packed into |
* registers (x86-64) during return. |
*/ |
typedef struct reg_pack_longlong_test_type_s {long long x, y;} reg_pack_longlong_test_type; |
typedef reg_pack_longlong_test_type (*reg_pack_longlong_test_function_type) (reg_pack_longlong_test_type); |
static int reg_pack_longlong_test_callback(void *ptr) { |
reg_pack_longlong_test_function_type f = (reg_pack_longlong_test_function_type)ptr; |
reg_pack_longlong_test_type a = {10, 35}; |
reg_pack_longlong_test_type r; |
r = f(a); |
return ((r.x == a.x*5) && (r.y == a.y*3)) ? 0 : -1; |
} |
static int reg_pack_longlong_test(void) { |
const char *src = |
"typedef struct reg_pack_longlong_test_type_s {long long x, y;} reg_pack_longlong_test_type;" |
"reg_pack_longlong_test_type f(reg_pack_longlong_test_type a) {\n" |
" reg_pack_longlong_test_type r = {a.x*5, a.y*3};\n" |
" return r;\n" |
"}\n"; |
return run_callback(src, reg_pack_longlong_test_callback); |
} |
/* |
* ret_6plus2longlong_test: |
* |
* This catches a corner case in the x86_64 ABI code: the first 5 |
* arguments fit into registers, the 6th doesn't, but the 7th argument |
* fits into the 6th argument integer register, %r9. |
* |
* Note that the purpose of the 10th argument is to avoid a situation |
* in which gcc would accidentally put the longlong at the right |
* address, thus causing a success message even though TCC actually |
* generated incorrect code. |
*/ |
typedef reg_pack_longlong_test_type (*ret_6plus2longlong_test_function_type) (long long, long long, long long, long long, long long, reg_pack_longlong_test_type, long long, long long); |
static int ret_6plus2longlong_test_callback(void *ptr) { |
ret_6plus2longlong_test_function_type f = (ret_6plus2longlong_test_function_type)ptr; |
reg_pack_longlong_test_type a = {10, 35}; |
reg_pack_longlong_test_type r; |
r = f(0, 0, 0, 0, 0, a, 37, 38); |
return ((r.x == 37) && (r.y == 37)) ? 0 : -1; |
} |
static int ret_6plus2longlong_test(void) { |
const char *src = |
"typedef struct reg_pack_longlong_test_type_s {long long x, y;} reg_pack_longlong_test_type;" |
"reg_pack_longlong_test_type f(long long x1, long long x2, long long x3, long long x4, long long x5, reg_pack_longlong_test_type a, long long x8, long long x9) {\n" |
" reg_pack_longlong_test_type r = { x8, x8 };\n" |
" return r;\n" |
"}\n"; |
return run_callback(src, ret_6plus2longlong_test_callback); |
} |
/* |
* sret_test: Create a struct large enough to be returned via sret |
* (hidden pointer as first function argument) |
*/ |
typedef struct sret_test_type_s {long long a, b, c;} sret_test_type; |
typedef sret_test_type (*sret_test_function_type) (sret_test_type); |
static int sret_test_callback(void *ptr) { |
sret_test_function_type f = (sret_test_function_type)(ptr); |
sret_test_type x = {5436LL, 658277698LL, 43878957LL}; |
sret_test_type r = f(x); |
return ((r.a==x.a*35)&&(r.b==x.b*19)&&(r.c==x.c*21)) ? 0 : -1; |
} |
static int sret_test(void) { |
const char *src = |
"typedef struct sret_test_type_s {long long a, b, c;} sret_test_type;\n" |
"sret_test_type f(sret_test_type x) {\n" |
" sret_test_type r = {x.a*35, x.b*19, x.c*21};\n" |
" return r;\n" |
"}\n"; |
return run_callback(src, sret_test_callback); |
} |
/* |
* one_member_union_test: |
* |
* In the x86-64 ABI a union should always be passed on the stack. However |
* it appears that a single member union is treated by GCC as its member. |
*/ |
typedef union one_member_union_test_type_u {int x;} one_member_union_test_type; |
typedef one_member_union_test_type (*one_member_union_test_function_type) (one_member_union_test_type); |
static int one_member_union_test_callback(void *ptr) { |
one_member_union_test_function_type f = (one_member_union_test_function_type)ptr; |
one_member_union_test_type a, b; |
a.x = 34; |
b = f(a); |
return (b.x == a.x*2) ? 0 : -1; |
} |
static int one_member_union_test(void) { |
const char *src = |
"typedef union one_member_union_test_type_u {int x;} one_member_union_test_type;\n" |
"one_member_union_test_type f(one_member_union_test_type a) {\n" |
" one_member_union_test_type b;\n" |
" b.x = a.x * 2;\n" |
" return b;\n" |
"}\n"; |
return run_callback(src, one_member_union_test_callback); |
} |
/* |
* two_member_union_test: |
* |
* In the x86-64 ABI a union should always be passed on the stack. |
*/ |
typedef union two_member_union_test_type_u {int x; long y;} two_member_union_test_type; |
typedef two_member_union_test_type (*two_member_union_test_function_type) (two_member_union_test_type); |
static int two_member_union_test_callback(void *ptr) { |
two_member_union_test_function_type f = (two_member_union_test_function_type)ptr; |
two_member_union_test_type a, b; |
a.x = 34; |
b = f(a); |
return (b.x == a.x*2) ? 0 : -1; |
} |
static int two_member_union_test(void) { |
const char *src = |
"typedef union two_member_union_test_type_u {int x; long y;} two_member_union_test_type;\n" |
"two_member_union_test_type f(two_member_union_test_type a) {\n" |
" two_member_union_test_type b;\n" |
" b.x = a.x * 2;\n" |
" return b;\n" |
"}\n"; |
return run_callback(src, two_member_union_test_callback); |
} |
/* |
* Win64 calling convetntion test. |
*/ |
typedef struct many_struct_test_type_s {long long a, b, c;} many_struct_test_type; |
typedef many_struct_test_type (*many_struct_test_function_type) (many_struct_test_type,many_struct_test_type,many_struct_test_type,many_struct_test_type,many_struct_test_type,many_struct_test_type); |
static int many_struct_test_callback(void *ptr) { |
many_struct_test_function_type f = (many_struct_test_function_type)ptr; |
many_struct_test_type v = {1, 2, 3}; |
many_struct_test_type r = f(v,v,v,v,v,v); |
return ((r.a == 6) && (r.b == 12) && (r.c == 18))?0:-1; |
} |
static int many_struct_test(void) { |
const char *src = |
"typedef struct many_struct_test_type_s {long long a, b, c;} many_struct_test_type;\n" |
"many_struct_test_type f(many_struct_test_type x1, many_struct_test_type x2, many_struct_test_type x3, many_struct_test_type x4, many_struct_test_type x5, many_struct_test_type x6) {\n" |
" many_struct_test_type y;\n" |
" y.a = x1.a + x2.a + x3.a + x4.a + x5.a + x6.a;\n" |
" y.b = x1.b + x2.b + x3.b + x4.b + x5.b + x6.b;\n" |
" y.c = x1.c + x2.c + x3.c + x4.c + x5.c + x6.c;\n" |
" return y;\n" |
"}\n"; |
return run_callback(src, many_struct_test_callback); |
} |
/* |
* Win64 calling convention test. |
*/ |
typedef struct many_struct_test_2_type_s {int a, b;} many_struct_test_2_type; |
typedef many_struct_test_2_type (*many_struct_test_2_function_type) (many_struct_test_2_type,many_struct_test_2_type,many_struct_test_2_type,many_struct_test_2_type,many_struct_test_2_type,many_struct_test_2_type); |
static int many_struct_test_2_callback(void *ptr) { |
many_struct_test_2_function_type f = (many_struct_test_2_function_type)ptr; |
many_struct_test_2_type v = {1,2}; |
many_struct_test_2_type r = f(v,v,v,v,v,v); |
return ((r.a == 6) && (r.b == 12))?0:-1; |
} |
static int many_struct_test_2(void) { |
const char *src = |
"typedef struct many_struct_test_2_type_s {int a, b;} many_struct_test_2_type;\n" |
"many_struct_test_2_type f(many_struct_test_2_type x1, many_struct_test_2_type x2, many_struct_test_2_type x3, many_struct_test_2_type x4, many_struct_test_2_type x5, many_struct_test_2_type x6) {\n" |
" many_struct_test_2_type y;\n" |
" y.a = x1.a + x2.a + x3.a + x4.a + x5.a + x6.a;\n" |
" y.b = x1.b + x2.b + x3.b + x4.b + x5.b + x6.b;\n" |
" return y;\n" |
"}\n"; |
return run_callback(src, many_struct_test_2_callback); |
} |
/* |
* Win64 calling convention test. |
*/ |
typedef struct many_struct_test_3_type_s {int a, b;} many_struct_test_3_type; |
typedef many_struct_test_3_type (*many_struct_test_3_function_type) (many_struct_test_3_type,many_struct_test_3_type,many_struct_test_3_type,many_struct_test_3_type,many_struct_test_3_type,many_struct_test_3_type, ...); |
typedef struct many_struct_test_3_struct_type { many_struct_test_3_function_type f; many_struct_test_3_function_type *f2; } many_struct_test_3_struct_type; |
static void many_struct_test_3_dummy(double d, ...) |
{ |
volatile double x = d; |
} |
static int many_struct_test_3_callback(void *ptr) { |
many_struct_test_3_struct_type s = { ptr, }; |
many_struct_test_3_struct_type *s2 = &s; |
s2->f2 = &s2->f; |
many_struct_test_3_dummy(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, &s2); |
many_struct_test_3_function_type f = *(s2->f2); |
many_struct_test_3_type v = {1,2}; |
many_struct_test_3_type r = (*((s2->f2=&f)+0))(v,v,v,v,v,v,1.0); |
return ((r.a == 6) && (r.b == 12))?0:-1; |
} |
static int many_struct_test_3(void) { |
const char *src = |
"typedef struct many_struct_test_3_type_s {int a, b;} many_struct_test_3_type;\n" |
"many_struct_test_3_type f(many_struct_test_3_type x1, many_struct_test_3_type x2, many_struct_test_3_type x3, many_struct_test_3_type x4, many_struct_test_3_type x5, many_struct_test_3_type x6, ...) {\n" |
" many_struct_test_3_type y;\n" |
" y.a = x1.a + x2.a + x3.a + x4.a + x5.a + x6.a;\n" |
" y.b = x1.b + x2.b + x3.b + x4.b + x5.b + x6.b;\n" |
" return y;\n" |
"}\n"; |
return run_callback(src, many_struct_test_3_callback); |
} |
/* |
* stdarg_test: Test variable argument list ABI |
*/ |
typedef struct {long long a, b, c;} stdarg_test_struct_type; |
typedef void (*stdarg_test_function_type) (int,int,int,...); |
static int stdarg_test_callback(void *ptr) { |
stdarg_test_function_type f = (stdarg_test_function_type)ptr; |
int x; |
double y; |
stdarg_test_struct_type z = {1, 2, 3}, w; |
f(10, 10, 5, |
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, &x, |
1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, &y, |
z, z, z, z, z, &w); |
return ((x == 55) && (y == 55) && (w.a == 5) && (w.b == 10) && (w.c == 15)) ? 0 : -1; |
} |
static int stdarg_test(void) { |
const char *src = |
"#include <stdarg.h>\n" |
"typedef struct {long long a, b, c;} stdarg_test_struct_type;\n" |
"void f(int n_int, int n_float, int n_struct, ...) {\n" |
" int i, ti = 0;\n" |
" double td = 0.0;\n" |
" stdarg_test_struct_type ts = {0,0,0}, tmp;\n" |
" va_list ap;\n" |
" va_start(ap, n_struct);\n" |
" for (i = 0, ti = 0; i < n_int; ++i)\n" |
" ti += va_arg(ap, int);\n" |
" *va_arg(ap, int*) = ti;\n" |
" for (i = 0, td = 0; i < n_float; ++i)\n" |
" td += va_arg(ap, double);\n" |
" *va_arg(ap, double*) = td;\n" |
" for (i = 0; i < n_struct; ++i) {\n" |
" tmp = va_arg(ap, stdarg_test_struct_type);\n" |
" ts.a += tmp.a; ts.b += tmp.b; ts.c += tmp.c;" |
" }\n" |
" *va_arg(ap, stdarg_test_struct_type*) = ts;\n" |
" va_end(ap);" |
"}\n"; |
return run_callback(src, stdarg_test_callback); |
} |
/* |
* Test Win32 stdarg handling, since the calling convention will pass a pointer |
* to the struct and the stdarg pointer must point to that pointer initially. |
*/ |
typedef struct {long long a, b, c;} stdarg_struct_test_struct_type; |
typedef int (*stdarg_struct_test_function_type) (stdarg_struct_test_struct_type a, ...); |
static int stdarg_struct_test_callback(void *ptr) { |
stdarg_struct_test_function_type f = (stdarg_struct_test_function_type)ptr; |
stdarg_struct_test_struct_type v = {10, 35, 99}; |
int x = f(v, 234); |
return (x == 378) ? 0 : -1; |
} |
static int stdarg_struct_test(void) { |
const char *src = |
"#include <stdarg.h>\n" |
"typedef struct {long long a, b, c;} stdarg_struct_test_struct_type;\n" |
"int f(stdarg_struct_test_struct_type a, ...) {\n" |
" va_list ap;\n" |
" va_start(ap, a);\n" |
" int z = va_arg(ap, int);\n" |
" va_end(ap);\n" |
" return z + a.a + a.b + a.c;\n" |
"}\n"; |
return run_callback(src, stdarg_struct_test_callback); |
} |
/* Test that x86-64 arranges the stack correctly for arguments with alignment >8 bytes */ |
typedef LONG_DOUBLE (*arg_align_test_callback_type) (LONG_DOUBLE,int,LONG_DOUBLE,int,LONG_DOUBLE); |
static int arg_align_test_callback(void *ptr) { |
arg_align_test_callback_type f = (arg_align_test_callback_type)ptr; |
long double x = f(12, 0, 25, 0, 37); |
return (x == 74) ? 0 : -1; |
} |
static int arg_align_test(void) { |
const char *src = |
"long double f(long double a, int b, long double c, int d, long double e) {\n" |
" return a + c + e;\n" |
"}\n"; |
return run_callback(src, arg_align_test_callback); |
} |
/* |
#define RUN_TEST(t) \ |
if (!testname || (strcmp(#t, testname) == 0)) { \ |
fputs(#t "... ", stdout); \ |
fflush(stdout); \ |
if (t() == 0) { \ |
fputs("success\n", stdout); \ |
} else { \ |
fputs("failure\n", stdout); \ |
retval = EXIT_FAILURE; \ |
} \ |
} |
*/ |
#define RUN_TEST(t) \ |
if (!testname || (strcmp(#t, testname) == 0)) { \ |
printf(#t "... \n"); \ |
if (t() == 0) { \ |
printf("success\n"); \ |
} else { \ |
printf("failure\n"); \ |
retval = EXIT_FAILURE; \ |
} \ |
} |
int main(int argc, char **argv) { |
int i; |
const char *testname = NULL; |
int retval = EXIT_SUCCESS; |
/* if tcclib.h and libtcc1.a are not installed, where can we find them */ |
for (i = 1; i < argc; ++i) { |
if (!memcmp(argv[i], "run_test=", 9)) |
testname = argv[i] + 9; |
} |
g_argv = argv, g_argc = argc; |
RUN_TEST(ret_int_test); |
RUN_TEST(ret_longlong_test); |
RUN_TEST(ret_float_test); |
RUN_TEST(ret_double_test); |
RUN_TEST(ret_longdouble_test); |
RUN_TEST(ret_2float_test); |
RUN_TEST(ret_2double_test); |
/* RUN_TEST(ret_8plus2double_test); currently broken on x86_64 */ |
/* RUN_TEST(ret_6plus2longlong_test); currently broken on x86_64 */ |
/* RUN_TEST(ret_mixed_test); currently broken on x86_64 */ |
/* RUN_TEST(ret_mixed2_test); currently broken on x86_64 */ |
RUN_TEST(ret_mixed3_test); |
RUN_TEST(reg_pack_test); |
RUN_TEST(reg_pack_longlong_test); |
RUN_TEST(sret_test); |
RUN_TEST(one_member_union_test); |
RUN_TEST(two_member_union_test); |
RUN_TEST(many_struct_test); |
RUN_TEST(many_struct_test_2); |
RUN_TEST(many_struct_test_3); |
RUN_TEST(stdarg_test); |
RUN_TEST(stdarg_struct_test); |
RUN_TEST(arg_align_test); |
return retval; |
} |
/programs/develop/ktcc/trunk/source/tests/asmtest.S |
---|
0,0 → 1,611 |
# gas comment with ``gnu'' style quotes |
/* some directive tests */ |
.byte 0xff |
.byte 1, 2, 3 |
.short 1, 2, 3 |
.word 1, 2, 3 |
.long 1, 2, 3 |
.int 1, 2, 3 |
.align 8 |
.byte 1 |
/* .align 16, 0x90 gas is too clever for us with 0x90 fill */ |
.align 16, 0x91 /* 0x91 tests the non-clever behaviour */ |
.skip 3 |
.skip 15, 0x90 |
.string "hello\0world" |
/* some label tests */ |
movl %eax, %ebx |
L1: |
movl %eax, %ebx |
mov 0x10000, %eax |
L2: |
movl $L2 - L1, %ecx |
var1: |
nop ; nop ; nop ; nop |
mov var1, %eax |
/* instruction tests */ |
movl %eax, %ebx |
mov 0x10000, %eax |
mov 0x10000, %ax |
mov 0x10000, %al |
mov %al, 0x10000 |
mov $1, %edx |
mov $1, %dx |
mov $1, %dl |
movb $2, 0x100(%ebx,%edx,2) |
movw $2, 0x100(%ebx,%edx,2) |
movl $2, 0x100(%ebx,%edx,2) |
movl %eax, 0x100(%ebx,%edx,2) |
movl 0x100(%ebx,%edx,2), %edx |
movw %ax, 0x100(%ebx,%edx,2) |
mov %eax, 0x12(,%edx,2) |
mov %cr3, %edx |
mov %ecx, %cr3 |
movl %cr3, %eax |
movl %tr3, %eax |
movl %db3, %ebx |
movl %dr6, %eax |
movl %fs, %ecx |
movl %ebx, %fs |
movsbl 0x1000, %eax |
movsbw 0x1000, %ax |
movswl 0x1000, %eax |
movzbl 0x1000, %eax |
movzbw 0x1000, %ax |
movzwl 0x1000, %eax |
movzb 0x1000, %eax |
movzb 0x1000, %ax |
pushl %eax |
pushw %ax |
push %eax |
push %cs |
push %gs |
push $1 |
push $100 |
popl %eax |
popw %ax |
pop %eax |
pop %ds |
pop %fs |
xchg %eax, %ecx |
xchg %edx, %eax |
xchg %bx, 0x10000 |
xchg 0x10000, %ebx |
xchg 0x10000, %dl |
in $100, %al |
in $100, %ax |
in $100, %eax |
in %dx, %al |
in %dx, %ax |
in %dx, %eax |
inb %dx |
inw %dx |
inl %dx |
out %al, $100 |
out %ax, $100 |
out %eax, $100 |
/* NOTE: gas is bugged here, so size must be added */ |
outb %al, %dx |
outw %ax, %dx |
outl %eax, %dx |
leal 0x1000(%ebx), %ecx |
lea 0x1000(%ebx), %ecx |
les 0x2000, %eax |
lds 0x2000, %ebx |
lfs 0x2000, %ecx |
lgs 0x2000, %edx |
lss 0x2000, %edx |
addl $0x123, %eax |
add $0x123, %ebx |
addl $0x123, 0x100 |
addl $0x123, 0x100(%ebx) |
addl $0x123, 0x100(%ebx,%edx,2) |
addl $0x123, 0x100(%esp) |
addl $0x123, (3*8)(%esp) |
addl $0x123, (%ebp) |
addl $0x123, (%esp) |
cmpl $0x123, (%esp) |
add %eax, (%ebx) |
add (%ebx), %eax |
or %dx, (%ebx) |
or (%ebx), %si |
add %cl, (%ebx) |
add (%ebx), %dl |
inc %edx |
incl 0x10000 |
incb 0x10000 |
dec %dx |
test $1, %al |
test $1, %cl |
testl $1, 0x1000 |
testb $1, 0x1000 |
testw $1, 0x1000 |
test %eax, %ebx |
test %eax, 0x1000 |
test 0x1000, %edx |
not %edx |
notw 0x10000 |
notl 0x10000 |
notb 0x10000 |
neg %edx |
negw 0x10000 |
negl 0x10000 |
negb 0x10000 |
imul %ecx |
mul %edx |
mulb %cl |
imul %eax, %ecx |
imul 0x1000, %cx |
imul $10, %eax, %ecx |
imul $10, %ax, %cx |
imul $10, %eax |
imul $0x1100000, %eax |
imul $1, %eax |
idivw 0x1000 |
div %ecx |
div %bl |
div %ecx, %eax |
shl %edx |
shl $10, %edx |
shl %cl, %edx |
shld $1, %eax, %edx |
shld %cl, %eax, %edx |
shld %eax, %edx |
shrd $1, %eax, %edx |
shrd %cl, %eax, %edx |
shrd %eax, %edx |
L4: |
call 0x1000 |
call L4 |
call *%eax |
call *0x1000 |
call func1 |
.global L5,L6 |
L5: |
L6: |
lcall $0x100, $0x1000 |
jmp 0x1000 |
jmp *%eax |
jmp *0x1000 |
ljmp $0x100, $0x1000 |
ret |
retl |
ret $10 |
retl $10 |
lret |
lret $10 |
enter $1234, $10 |
L3: |
jo 0x1000 |
jnp 0x1001 |
jne 0x1002 |
jg 0x1003 |
jo L3 |
jnp L3 |
jne L3 |
jg L3 |
loopne L3 |
loopnz L3 |
loope L3 |
loopz L3 |
loop L3 |
jecxz L3 |
seto %al |
setc %al |
setcb %al |
setnp 0x1000 |
setl 0xaaaa |
setg %dl |
fadd |
fadd %st(1), %st |
fadd %st(0), %st(1) |
fadd %st(3) |
fmul %st(0),%st(0) |
fmul %st(0),%st(1) |
faddp %st(5) |
faddp |
faddp %st(1), %st |
fadds 0x1000 |
fiadds 0x1002 |
faddl 0x1004 |
fiaddl 0x1006 |
fmul |
fmul %st(1), %st |
fmul %st(3) |
fmulp %st(5) |
fmulp |
fmulp %st(1), %st |
fmuls 0x1000 |
fimuls 0x1002 |
fmull 0x1004 |
fimull 0x1006 |
fsub |
fsub %st(1), %st |
fsub %st(3) |
fsubp %st(5) |
fsubp |
fsubp %st(1), %st |
fsubs 0x1000 |
fisubs 0x1002 |
fsubl 0x1004 |
fisubl 0x1006 |
fsubr |
fsubr %st(1), %st |
fsubr %st(3) |
fsubrp %st(5) |
fsubrp |
fsubrp %st(1), %st |
fsubrs 0x1000 |
fisubrs 0x1002 |
fsubrl 0x1004 |
fisubrl 0x1006 |
fdiv |
fdiv %st(1), %st |
fdiv %st(3) |
fdivp %st(5) |
fdivp |
fdivp %st(1), %st |
fdivs 0x1000 |
fidivs 0x1002 |
fdivl 0x1004 |
fidivl 0x1006 |
fcom %st(3) |
fcoms 0x1000 |
ficoms 0x1002 |
fcoml 0x1004 |
ficoml 0x1006 |
fcomp %st(5) |
fcomp |
fcompp |
fcomps 0x1000 |
ficomps 0x1002 |
fcompl 0x1004 |
ficompl 0x1006 |
fld %st(5) |
fldl 0x1000 |
flds 0x1002 |
fildl 0x1004 |
fst %st(4) |
fstp %st(6) |
fstpt 0x1006 |
fbstp 0x1008 |
fxch |
fxch %st(4) |
fucom %st(6) |
fucomp %st(3) |
fucompp |
finit |
fninit |
fldcw 0x1000 |
fnstcw 0x1002 |
fstcw 0x1002 |
fnstsw 0x1004 |
fnstsw (%eax) |
fstsw 0x1004 |
fstsw (%eax) |
fnclex |
fclex |
fnstenv 0x1000 |
fstenv 0x1000 |
fldenv 0x1000 |
fnsave 0x1002 |
fsave 0x1000 |
frstor 0x1000 |
ffree %st(7) |
ffreep %st(6) |
ftst |
fxam |
fld1 |
fldl2t |
fldl2e |
fldpi |
fldlg2 |
fldln2 |
fldz |
f2xm1 |
fyl2x |
fptan |
fpatan |
fxtract |
fprem1 |
fdecstp |
fincstp |
fprem |
fyl2xp1 |
fsqrt |
fsincos |
frndint |
fscale |
fsin |
fcos |
fchs |
fabs |
fnop |
fwait |
bswap %edx |
xadd %ecx, %edx |
xaddb %dl, 0x1000 |
xaddw %ax, 0x1000 |
xaddl %eax, 0x1000 |
cmpxchg %ecx, %edx |
cmpxchgb %dl, 0x1000 |
cmpxchgw %ax, 0x1000 |
cmpxchgl %eax, 0x1000 |
invlpg 0x1000 |
cmpxchg8b 0x1002 |
fcmovb %st(5), %st |
fcmove %st(5), %st |
fcmovbe %st(5), %st |
fcmovu %st(5), %st |
fcmovnb %st(5), %st |
fcmovne %st(5), %st |
fcmovnbe %st(5), %st |
fcmovnu %st(5), %st |
fcomi %st(5), %st |
fucomi %st(5), %st |
fcomip %st(5), %st |
fucomip %st(5), %st |
cmovo 0x1000, %eax |
cmovs 0x1000, %eax |
cmovns %edx, %edi |
int $3 |
int $0x10 |
pusha |
popa |
clc |
cld |
cli |
clts |
cmc |
lahf |
sahf |
pushfl |
popfl |
pushf |
popf |
stc |
std |
sti |
aaa |
aas |
daa |
das |
aad |
aam |
cbw |
cwd |
cwde |
cdq |
cbtw |
cwtd |
cwtl |
cltd |
leave |
int3 |
into |
iret |
rsm |
hlt |
wait |
nop |
/* XXX: handle prefixes */ |
#if 0 |
aword |
addr16 |
#endif |
lock |
rep |
repe |
repz |
repne |
repnz |
nop |
lock ;negl (%eax) |
wait ;pushf |
rep ;stosb |
repe ;lodsb |
repz ;cmpsb |
repne;movsb |
repnz;outsb |
/* handle one-line prefix + ops */ |
lock negl (%eax) |
wait pushf |
rep stosb |
repe lodsb |
repz cmpsb |
repne movsb |
repnz outsb |
invd |
wbinvd |
cpuid |
wrmsr |
rdtsc |
rdmsr |
rdpmc |
ud2 |
emms |
movd %edx, %mm3 |
movd 0x1000, %mm2 |
movd %mm4, %ecx |
movd %mm5, 0x1000 |
movq 0x1000, %mm2 |
movq %mm4, 0x1000 |
pand 0x1000, %mm3 |
pand %mm4, %mm5 |
psllw $1, %mm6 |
psllw 0x1000, %mm7 |
psllw %mm2, %mm7 |
xlat |
cmpsb |
scmpw |
insl |
outsw |
lodsb |
slodl |
movsb |
movsl |
smovb |
scasb |
sscaw |
stosw |
sstol |
bsf 0x1000, %ebx |
bsr 0x1000, %ebx |
bt %edx, 0x1000 |
btl $2, 0x1000 |
btc %edx, 0x1000 |
btcl $2, 0x1000 |
btr %edx, 0x1000 |
btrl $2, 0x1000 |
bts %edx, 0x1000 |
btsl $2, 0x1000 |
boundl %edx, 0x10000 |
boundw %bx, 0x1000 |
arpl %bx, 0x1000 |
lar 0x1000, %eax |
lgdt 0x1000 |
lidt 0x1000 |
lldt 0x1000 |
lmsw 0x1000 |
lsl 0x1000, %ecx |
ltr 0x1000 |
sgdt 0x1000 |
sidt 0x1000 |
sldt 0x1000 |
smsw 0x1000 |
str 0x1000 |
verr 0x1000 |
verw 0x1000 |
push %ds |
pushw %ds |
pushl %ds |
pop %ds |
popw %ds |
popl %ds |
fxsave 1(%ebx) |
fxrstor 1(%ecx) |
pushl $1 |
pushw $1 |
push $1 |
#ifdef __ASSEMBLER__ // should be defined, for S files |
inc %eax |
#endif |
ft1: ft2: ft3: ft4: ft5: ft6: ft7: ft8: ft9: |
xor %eax, %eax |
ret |
.type ft1,STT_FUNC |
.type ft2,@STT_FUNC |
.type ft3,%STT_FUNC |
.type ft4,"STT_FUNC" |
.type ft5,function |
.type ft6,@function |
.type ft7,%function |
.type ft8,"function" |
pause |
/programs/develop/ktcc/trunk/source/tests/boundtest.c |
---|
0,0 → 1,285 |
#include <stdlib.h> |
#include <stdio.h> |
#include <string.h> |
#define NB_ITS 1000000 |
//#define NB_ITS 1 |
#define TAB_SIZE 100 |
int tab[TAB_SIZE]; |
int ret_sum; |
char tab3[256]; |
int test1(void) |
{ |
int i, sum = 0; |
for(i=0;i<TAB_SIZE;i++) { |
sum += tab[i]; |
} |
return sum; |
} |
/* error */ |
int test2(void) |
{ |
int i, sum = 0; |
for(i=0;i<TAB_SIZE + 1;i++) { |
sum += tab[i]; |
} |
return sum; |
} |
/* actually, profiling test */ |
int test3(void) |
{ |
int sum; |
int i, it; |
sum = 0; |
for(it=0;it<NB_ITS;it++) { |
for(i=0;i<TAB_SIZE;i++) { |
sum += tab[i]; |
} |
} |
return sum; |
} |
/* ok */ |
int test4(void) |
{ |
int i, sum = 0; |
int *tab4; |
fprintf(stderr, "%s start\n", __FUNCTION__); |
tab4 = malloc(20 * sizeof(int)); |
for(i=0;i<20;i++) { |
sum += tab4[i]; |
} |
free(tab4); |
fprintf(stderr, "%s end\n", __FUNCTION__); |
return sum; |
} |
/* error */ |
int test5(void) |
{ |
int i, sum = 0; |
int *tab4; |
fprintf(stderr, "%s start\n", __FUNCTION__); |
tab4 = malloc(20 * sizeof(int)); |
for(i=0;i<21;i++) { |
sum += tab4[i]; |
} |
free(tab4); |
fprintf(stderr, "%s end\n", __FUNCTION__); |
return sum; |
} |
/* error */ |
/* XXX: currently: bug */ |
int test6(void) |
{ |
int i, sum = 0; |
int *tab4; |
tab4 = malloc(20 * sizeof(int)); |
free(tab4); |
for(i=0;i<21;i++) { |
sum += tab4[i]; |
} |
return sum; |
} |
/* error */ |
int test7(void) |
{ |
int i, sum = 0; |
int *p; |
for(i=0;i<TAB_SIZE + 1;i++) { |
p = &tab[i]; |
if (i == TAB_SIZE) |
printf("i=%d %x\n", i, p); |
sum += *p; |
} |
return sum; |
} |
/* ok */ |
int test8(void) |
{ |
int i, sum = 0; |
int tab[10]; |
for(i=0;i<10;i++) { |
sum += tab[i]; |
} |
return sum; |
} |
/* error */ |
int test9(void) |
{ |
int i, sum = 0; |
char tab[10]; |
for(i=0;i<11;i++) { |
sum += tab[i]; |
} |
return sum; |
} |
/* ok */ |
int test10(void) |
{ |
char tab[10]; |
char tab1[10]; |
memset(tab, 0, 10); |
memcpy(tab, tab1, 10); |
memmove(tab, tab1, 10); |
return 0; |
} |
/* error */ |
int test11(void) |
{ |
char tab[10]; |
memset(tab, 0, 11); |
return 0; |
} |
/* error */ |
int test12(void) |
{ |
void *ptr; |
ptr = malloc(10); |
free(ptr); |
free(ptr); |
return 0; |
} |
/* error */ |
int test13(void) |
{ |
char pad1 = 0; |
char tab[10]; |
char pad2 = 0; |
memset(tab, 'a', sizeof(tab)); |
return strlen(tab); |
} |
int test14(void) |
{ |
char *p = alloca(TAB_SIZE); |
memset(p, 'a', TAB_SIZE); |
p[TAB_SIZE-1] = 0; |
return strlen(p); |
} |
/* error */ |
int test15(void) |
{ |
char *p = alloca(TAB_SIZE-1); |
memset(p, 'a', TAB_SIZE); |
p[TAB_SIZE-1] = 0; |
return strlen(p); |
} |
/* ok */ |
int test16() |
{ |
char *demo = "This is only a test."; |
char *p; |
fprintf(stderr, "%s start\n", __FUNCTION__); |
p = alloca(16); |
strcpy(p,"12345678901234"); |
printf("alloca: p is %s\n", p); |
/* Test alloca embedded in a larger expression */ |
printf("alloca: %s\n", strcpy(alloca(strlen(demo)+1),demo) ); |
fprintf(stderr, "%s end\n", __FUNCTION__); |
} |
/* error */ |
int test17() |
{ |
char *demo = "This is only a test."; |
char *p; |
fprintf(stderr, "%s start\n", __FUNCTION__); |
p = alloca(16); |
strcpy(p,"12345678901234"); |
printf("alloca: p is %s\n", p); |
/* Test alloca embedded in a larger expression */ |
printf("alloca: %s\n", strcpy(alloca(strlen(demo)),demo) ); |
fprintf(stderr, "%s end\n", __FUNCTION__); |
} |
int (*table_test[])(void) = { |
test1, |
test2, |
test3, |
test4, |
test5, |
test6, |
test7, |
test8, |
test9, |
test10, |
test11, |
test12, |
test13, |
test14, |
test15, |
test16, |
test17, |
}; |
int main(int argc, char **argv) |
{ |
int index; |
int (*ftest)(void); |
int index_max = sizeof(table_test)/sizeof(table_test[0]); |
if (argc < 2) { |
printf( |
"test TCC bound checking system\n" |
"usage: boundtest N\n" |
" 1 <= N <= %d\n", index_max); |
exit(1); |
} |
index = 0; |
if (argc >= 2) |
index = atoi(argv[1]) - 1; |
if ((index < 0) || (index >= index_max)) { |
printf("N is outside of the valid range (%d)\n", index); |
exit(2); |
} |
/* well, we also use bounds on this ! */ |
ftest = table_test[index]; |
ftest(); |
return 0; |
} |
/* |
* without bound 0.77 s |
* with bounds 4.73 |
*/ |
/programs/develop/ktcc/trunk/source/tests/gcctestsuite.sh |
---|
0,0 → 1,33 |
#!/bin/sh |
TESTSUITE_PATH=$HOME/gcc/gcc-3.2/gcc/testsuite/gcc.c-torture |
TCC="./tcc -B. -I. -DNO_TRAMPOLINES" |
rm -f tcc.sum tcc.log |
nb_failed="0" |
for src in $TESTSUITE_PATH/compile/*.c ; do |
echo $TCC -o /tmp/test.o -c $src |
$TCC -o /tmp/test.o -c $src >> tcc.log 2>&1 |
if [ "$?" = "0" ] ; then |
result="PASS" |
else |
result="FAIL" |
nb_failed=$(( $nb_failed + 1 )) |
fi |
echo "$result: $src" >> tcc.sum |
done |
for src in $TESTSUITE_PATH/execute/*.c ; do |
echo $TCC $src |
$TCC $src >> tcc.log 2>&1 |
if [ "$?" = "0" ] ; then |
result="PASS" |
else |
result="FAIL" |
nb_failed=$(( $nb_failed + 1 )) |
fi |
echo "$result: $src" >> tcc.sum |
done |
echo "$nb_failed test(s) failed." >> tcc.sum |
echo "$nb_failed test(s) failed." |
/programs/develop/ktcc/trunk/source/tests/libtcc_test.c |
---|
0,0 → 1,88 |
/* |
* Simple Test program for libtcc |
* |
* libtcc can be useful to use tcc as a "backend" for a code generator. |
*/ |
#include <stdlib.h> |
#include <stdio.h> |
#include <string.h> |
#include "libtcc.h" |
/* this function is called by the generated code */ |
int add(int a, int b) |
{ |
return a + b; |
} |
char my_program[] = |
"#include <tcclib.h>\n" /* include the "Simple libc header for TCC" */ |
"extern int add(int a, int b);\n" |
"int fib(int n)\n" |
"{\n" |
" if (n <= 2)\n" |
" return 1;\n" |
" else\n" |
" return fib(n-1) + fib(n-2);\n" |
"}\n" |
"\n" |
"int foo(int n)\n" |
"{\n" |
" printf(\"Hello World!\\n\");\n" |
" printf(\"fib(%d) = %d\\n\", n, fib(n));\n" |
" printf(\"add(%d, %d) = %d\\n\", n, 2 * n, add(n, 2 * n));\n" |
" return 0;\n" |
"}\n"; |
int main(int argc, char **argv) |
{ |
TCCState *s; |
int i; |
int (*func)(int); |
s = tcc_new(); |
if (!s) { |
fprintf(stderr, "Could not create tcc state\n"); |
exit(1); |
} |
/* if tcclib.h and libtcc1.a are not installed, where can we find them */ |
for (i = 1; i < argc; ++i) { |
char *a = argv[i]; |
if (a[0] == '-') { |
if (a[1] == 'B') |
tcc_set_lib_path(s, a+2); |
else if (a[1] == 'I') |
tcc_add_include_path(s, a+2); |
else if (a[1] == 'L') |
tcc_add_library_path(s, a+2); |
} |
} |
/* MUST BE CALLED before any compilation */ |
tcc_set_output_type(s, TCC_OUTPUT_MEMORY); |
if (tcc_compile_string(s, my_program) == -1) |
return 1; |
/* as a test, we add a symbol that the compiled program can use. |
You may also open a dll with tcc_add_dll() and use symbols from that */ |
tcc_add_symbol(s, "add", add); |
/* relocate the code */ |
if (tcc_relocate(s, TCC_RELOCATE_AUTO) < 0) |
return 1; |
/* get entry symbol */ |
func = tcc_get_symbol(s, "foo"); |
if (!func) |
return 1; |
/* run the code */ |
func(32); |
/* delete the state */ |
tcc_delete(s); |
return 0; |
} |
/programs/develop/ktcc/trunk/source/tests/pp/01.c |
---|
0,0 → 1,6 |
#define hash_hash # ## # |
#define mkstr(a) # a |
#define in_between(a) mkstr(a) |
#define join(c, d) in_between(c hash_hash d) |
char p[] = join(x, y); |
// char p[] = "x ## y"; |
/programs/develop/ktcc/trunk/source/tests/pp/01.expect |
---|
0,0 → 1,0 |
char p[] = "x ## y"; |
/programs/develop/ktcc/trunk/source/tests/pp/02.c |
---|
0,0 → 1,28 |
#define x 3 |
#define f(a) f(x * (a)) |
#undef x |
#define x 2 |
#define g f |
#define z z[0] |
#define h g(~ |
#define m(a) a(w) |
#define w 0,1 |
#define t(a) a |
#define p() int |
#define q(x) x |
#define r(x,y) x ## y |
#define str(x) # x |
f(y+1) + f(f(z)) % t(t(g)(0) + t)(1); |
g(x+(3,4)-w) | h 5) & m |
(f)^m(m); |
char c[2][6] = { str(hello), str() }; |
/* |
* f(2 * (y+1)) + f(2 * (f(2 * (z[0])))) % f(2 * (0)) + t(1); |
* f(2 * (2+(3,4)-0,1)) | f(2 * (~ 5)) & f(2 * (0,1))^m(0,1); |
* char c[2][6] = { "hello", "" }; |
*/ |
#define L21 f(y+1) + f(f(z)) % t(t(g)(0) + t)(1); |
#define L22 g(x+(3,4)-w) | h 5) & m\ |
(f)^m(m); |
L21 |
L22 |
/programs/develop/ktcc/trunk/source/tests/pp/02.expect |
---|
0,0 → 1,5 |
f(2 * (y+1)) + f(2 * (f(2 * (z[0])))) % f(2 * (0)) + t(1); |
f(2 * (2+(3,4)-0,1)) | f(2 * (~ 5)) & f(2 * (0,1))^m(0,1); |
char c[2][6] = { "hello", "" }; |
f(2 * (y+1)) + f(2 * (f(2 * (z[0])))) % f(2 * (0)) + t(1); |
f(2 * (2+(3,4)-0,1)) | f(2 * (~ 5)) & f(2 * (0,1))^m(0,1); |
/programs/develop/ktcc/trunk/source/tests/pp/03.c |
---|
0,0 → 1,15 |
#define str(s) # s |
#define xstr(s) str(s) |
#define debug(s, t) printf("x" # s "= %d, x" # t "= %s", \ |
x ## s, x ## t) |
#define INCFILE(n) vers ## n |
#define glue(a, b) a ## b |
#define xglue(a, b) glue(a, b) |
#define HIGHLOW "hello" |
#define LOW LOW ", world" |
debug(1, 2); |
fputs(str(strncmp("abc\0d", "abc", '\4') // this goes away |
== 0) str(: @\n), s); |
\#include xstr(INCFILE(2).h) |
glue(HIGH, LOW); |
xglue(HIGH, LOW) |
/programs/develop/ktcc/trunk/source/tests/pp/03.expect |
---|
0,0 → 1,5 |
printf("x" "1" "= %d, x" "2" "= %s", x1, x2); |
fputs("strncmp(\"abc\\0d\", \"abc\", '\\4') == 0" ": @\n", s); |
\#include "vers2.h" |
"hello"; |
"hello" ", world" |
/programs/develop/ktcc/trunk/source/tests/pp/04.c |
---|
0,0 → 1,4 |
#define foobar 1 |
#define C(x,y) x##y |
#define D(x) (C(x,bar)) |
D(foo) |
/programs/develop/ktcc/trunk/source/tests/pp/04.expect |
---|
0,0 → 1,0 |
(1) |
/programs/develop/ktcc/trunk/source/tests/pp/05.c |
---|
0,0 → 1,7 |
#define t(x,y,z) x ## y ## z |
#define xxx(s) int s[] = { t(1,2,3), t(,4,5), t(6,,7), t(8,9,), \ |
t(10,,), t(,11,), t(,,12), t(,,) }; |
int j[] = { t(1,2,3), t(,4,5), t(6,,7), t(8,9,), |
t(10,,), t(,11,), t(,,12), t(,,) }; |
xxx(j) |
/programs/develop/ktcc/trunk/source/tests/pp/05.expect |
---|
0,0 → 1,3 |
int j[] = { 123, 45, 67, 89, |
10, 11, 12, }; |
int j[] = { 123, 45, 67, 89, 10, 11, 12, }; |
/programs/develop/ktcc/trunk/source/tests/pp/06.c |
---|
0,0 → 1,5 |
#define X(a,b, \ |
c,d) \ |
foo |
X(1,2,3,4) |
/programs/develop/ktcc/trunk/source/tests/pp/06.expect |
---|
0,0 → 1,0 |
foo |
/programs/develop/ktcc/trunk/source/tests/pp/07.c |
---|
0,0 → 1,4 |
#define a() YES |
#define b() a |
b() |
b()() |
/programs/develop/ktcc/trunk/source/tests/pp/07.expect |
---|
0,0 → 1,2 |
a |
YES |
/programs/develop/ktcc/trunk/source/tests/pp/08.c |
---|
0,0 → 1,4 |
// test macro expansion in arguments |
#define s_pos s_s.s_pos |
#define foo(x) (x) |
foo(hej.s_pos) |
/programs/develop/ktcc/trunk/source/tests/pp/08.expect |
---|
0,0 → 1,0 |
(hej.s_s.s_pos) |
/programs/develop/ktcc/trunk/source/tests/pp/09.c |
---|
0,0 → 1,4 |
#define C(a,b,c) a##b##c |
#define N(x,y) C(x,_,y) |
#define A_O aaaaoooo |
N(A,O) |
/programs/develop/ktcc/trunk/source/tests/pp/09.expect |
---|
0,0 → 1,0 |
aaaaoooo |
/programs/develop/ktcc/trunk/source/tests/pp/10.c |
---|
0,0 → 1,10 |
#define f(x) x |
#define g(x) f(x) f(x |
#define i(x) g(x)) g(x |
#define h(x) i(x))) i(x |
#define k(x) i(x))) i(x)))) |
f(x) |
g(x)) |
i(x))) |
h(x)))) |
k(x)))) |
/programs/develop/ktcc/trunk/source/tests/pp/10.expect |
---|
0,0 → 1,5 |
x |
x x |
x x x x |
x x x x x x x x |
x x x x x x x x)))) |
/programs/develop/ktcc/trunk/source/tests/pp/11.c |
---|
0,0 → 1,31 |
#define D1(s, ...) s |
#define D2(s, ...) s D1(__VA_ARGS__) |
#define D3(s, ...) s D2(__VA_ARGS__) |
#define D4(s, ...) s D3(__VA_ARGS__) |
D1(a) |
D2(a, b) |
D3(a, b, c) |
D4(a, b, c, d) |
x D4(a, b, c, d) y |
x D4(a, b, c) y |
x D4(a, b) y |
x D4(a) y |
x D4() y |
#define GNU_COMMA(X,Y...) X,## Y |
x GNU_COMMA(A,B,C) y |
x GNU_COMMA(A,B) y |
x GNU_COMMA(A) y |
x GNU_COMMA() y |
#define __sun_attr___noreturn__ __attribute__((__noreturn__)) |
#define ___sun_attr_inner(__a) __sun_attr_##__a |
#define __sun_attr__(__a) ___sun_attr_inner __a |
#define __NORETURN __sun_attr__((__noreturn__)) |
__NORETURN |
#define X(...) |
#define Y(...) 1 __VA_ARGS__ 2 |
Y(X X() ()) |
/programs/develop/ktcc/trunk/source/tests/pp/11.expect |
---|
0,0 → 1,15 |
a |
a b |
a b c |
a b c d |
x a b c d y |
x a b c y |
x a b y |
x a y |
x y |
x A,B,C y |
x A,B y |
x A y |
x y |
__attribute__((__noreturn__)) |
1 2 |
/programs/develop/ktcc/trunk/source/tests/pp/12.S |
---|
0,0 → 1,8 |
#define SRC(y...) \ |
9999: y; \ |
.section __ex_table, "a"; \ |
.long 9999b, 6001f ; \ |
// .previous |
SRC(1: movw (%esi), %bx) |
6001: |
/programs/develop/ktcc/trunk/source/tests/pp/12.expect |
---|
0,0 → 1,2 |
9999: 1: movw (%esi), %bx; .section __ex_table, "a"; .long 9999b, 6001f ; |
6001: |
/programs/develop/ktcc/trunk/source/tests/pp/13.S |
---|
0,0 → 1,6 |
# `modelist' label. Each video mode record looks like: |
#ifdef AAA |
# modelist' label. Each video mode record looks like: |
#endif |
.text |
endtext: |
/programs/develop/ktcc/trunk/source/tests/pp/13.expect |
---|
0,0 → 1,6 |
# `modelist' label. Each video mode record looks like: |
.text |
endtext: |
/programs/develop/ktcc/trunk/source/tests/pp/Makefile |
---|
0,0 → 1,45 |
# |
# credits: 01..13.c from the pcc cpp-tests suite |
# |
TCC = ../../tcc |
TESTS = $(patsubst %.c,%.test,$(wildcard *.c)) |
TESTS += $(patsubst %.S,%.test,$(wildcard *.S)) |
all test : $(TESTS) |
%.test: %.c %.expect |
@echo PPTest $* ... |
@$(TCC) -E -P $< >$*.output 2>&1 ; \ |
diff -Nu -b -B -I "^#" $(EXTRA_DIFF_OPTS) $*.expect $*.output \ |
&& rm -f $*.output |
%.test: %.S %.expect |
@echo PPTest $* ... |
@$(TCC) -E -P $< >$*.output 2>&1 ; \ |
diff -Nu -b -B -I "^#" $(EXTRA_DIFF_OPTS) $*.expect $*.output \ |
&& rm -f $*.output |
# automatically generate .expect files with gcc: |
%.expect: %.c |
gcc -E -P $*.c >$*.expect 2>&1 |
%.expect: %.S |
gcc -E -P $*.S >$*.expect 2>&1 |
# tell make not to delete |
.PRECIOUS: %.expect |
clean: |
rm -vf *.output |
# 02.test : EXTRA_DIFF_OPTS = -w |
# 03.test : EXTRA_DIFF_OPTS = -w |
# 04.test : EXTRA_DIFF_OPTS = -w |
# 10.test : EXTRA_DIFF_OPTS = -w |
# diff options: |
# -b ighore space changes |
# -w ighore all whitespace |
# -B ignore blank lines |
# -I <RE> ignore lines matching RE |
/programs/develop/ktcc/trunk/source/tests/tcctest.c |
---|
0,0 → 1,2869 |
/* |
* TCC auto test program |
*/ |
#include "../config.h" |
#include <stddef.h> |
#include <stdarg.h> |
#if GCC_MAJOR >= 3 |
/* Unfortunately, gcc version < 3 does not handle that! */ |
#define ALL_ISOC99 |
/* only gcc 3 handles _Bool correctly */ |
#define BOOL_ISOC99 |
/* gcc 2.95.3 does not handle correctly CR in strings or after strays */ |
#define CORRECT_CR_HANDLING |
#endif |
#if defined(_WIN32) |
#define LONG_LONG_FORMAT "%lld" |
#define ULONG_LONG_FORMAT "%llu" |
#else |
#define LONG_LONG_FORMAT "%Ld" |
#define ULONG_LONG_FORMAT "%Lu" |
#endif |
// MinGW has 80-bit rather than 64-bit long double which isn't compatible with TCC or MSVC |
#if defined(_WIN32) && defined(__GNUC__) |
#define LONG_DOUBLE double |
#define LONG_DOUBLE_LITERAL(x) x |
#else |
#define LONG_DOUBLE long double |
#define LONG_DOUBLE_LITERAL(x) x ## L |
#endif |
/* deprecated and no longer supported in gcc 3.3 */ |
//#define ACCEPT_CR_IN_STRINGS |
/* __VA_ARGS__ and __func__ support */ |
#define C99_MACROS |
/* test various include syntaxes */ |
#define TCCLIB_INC <tcclib.h> |
#define TCCLIB_INC1 <tcclib |
#define TCCLIB_INC2 h> |
#define TCCLIB_INC3 "tcclib" |
#include TCCLIB_INC |
#include TCCLIB_INC1.TCCLIB_INC2 |
#include TCCLIB_INC1.h> |
/* gcc 3.2 does not accept that (bug ?) */ |
//#include TCCLIB_INC3 ".h" |
#include <tcclib.h> |
#include "tcclib.h" |
void intdiv_test(); |
void string_test(); |
void expr_test(); |
void macro_test(); |
void recursive_macro_test(); |
void scope_test(); |
void forward_test(); |
void funcptr_test(); |
void loop_test(); |
void switch_test(); |
void goto_test(); |
void enum_test(); |
void typedef_test(); |
void struct_test(); |
void array_test(); |
void expr_ptr_test(); |
void bool_test(); |
void expr2_test(); |
void constant_expr_test(); |
void expr_cmp_test(); |
void char_short_test(); |
void init_test(void); |
void compound_literal_test(void); |
int kr_test(); |
void struct_assign_test(void); |
void cast_test(void); |
void bitfield_test(void); |
void c99_bool_test(void); |
void float_test(void); |
void longlong_test(void); |
void manyarg_test(void); |
void stdarg_test(void); |
void whitespace_test(void); |
void relocation_test(void); |
void old_style_function(void); |
void alloca_test(void); |
void c99_vla_test(int size1, int size2); |
void sizeof_test(void); |
void typeof_test(void); |
void local_label_test(void); |
void statement_expr_test(void); |
void asm_test(void); |
void builtin_test(void); |
void weak_test(void); |
void global_data_test(void); |
void cmp_comparison_test(void); |
void math_cmp_test(void); |
void callsave_test(void); |
void builtin_frame_address_test(void); |
int fib(int n); |
void num(int n); |
void forward_ref(void); |
int isid(int c); |
/* Line joining happens before tokenization, so the following |
must be parsed as ellipsis. */ |
void funny_line_continuation (int, ..\ |
. ); |
char via_volatile (char); |
#define A 2 |
#define N 1234 + A |
#define pf printf |
#define M1(a, b) (a) + (b) |
#define str\ |
(s) # s |
#define glue(a, b) a ## b |
#define xglue(a, b) glue(a, b) |
#define HIGHLOW "hello" |
#define LOW LOW ", world" |
static int onetwothree = 123; |
#define onetwothree4 onetwothree |
#define onetwothree xglue(onetwothree,4) |
#define min(a, b) ((a) < (b) ? (a) : (b)) |
#ifdef C99_MACROS |
#define dprintf(level,...) printf(__VA_ARGS__) |
#endif |
/* gcc vararg macros */ |
#define dprintf1(level, fmt, args...) printf(fmt, ## args) |
#define MACRO_NOARGS() |
#define AAA 3 |
#undef AAA |
#define AAA 4 |
#if 1 |
#define B3 1 |
#elif 1 |
#define B3 2 |
#elif 0 |
#define B3 3 |
#else |
#define B3 4 |
#endif |
#define __INT64_C(c) c ## LL |
#define INT64_MIN (-__INT64_C(9223372036854775807)-1) |
int qq(int x) |
{ |
return x + 40; |
} |
#define qq(x) x |
#define spin_lock(lock) do { } while (0) |
#define wq_spin_lock spin_lock |
#define TEST2() wq_spin_lock(a) |
#define UINT_MAX ((unsigned) -1) |
void intdiv_test(void) |
{ |
printf("18/21=%u\n", 18/21); |
printf("18%%21=%u\n", 18%21); |
printf("41/21=%u\n", 41/21); |
printf("41%%21=%u\n", 41%21); |
printf("42/21=%u\n", 42/21); |
printf("42%%21=%u\n", 42%21); |
printf("43/21=%u\n", 43/21); |
printf("43%%21=%u\n", 43%21); |
printf("126/21=%u\n", 126/21); |
printf("126%%21=%u\n", 126%21); |
printf("131/21=%u\n", 131/21); |
printf("131%%21=%u\n", 131%21); |
printf("(UINT_MAX/2+3)/2=%u\n", (UINT_MAX/2+3)/2); |
printf("(UINT_MAX/2+3)%%2=%u\n", (UINT_MAX/2+3)%2); |
printf("18/-21=%u\n", 18/-21); |
printf("18%%-21=%u\n", 18%-21); |
printf("41/-21=%u\n", 41/-21); |
printf("41%%-21=%u\n", 41%-21); |
printf("42/-21=%u\n", 42/-21); |
printf("42%%-21=%u\n", 42%-21); |
printf("43/-21=%u\n", 43/-21); |
printf("43%%-21=%u\n", 43%-21); |
printf("126/-21=%u\n", 126/-21); |
printf("126%%-21=%u\n", 126%-21); |
printf("131/-21=%u\n", 131/-21); |
printf("131%%-21=%u\n", 131%-21); |
printf("(UINT_MAX/2+3)/-2=%u\n", (UINT_MAX/2+3)/-2); |
printf("(UINT_MAX/2+3)%%-2=%u\n", (UINT_MAX/2+3)%-2); |
printf("-18/21=%u\n", -18/21); |
printf("-18%%21=%u\n", -18%21); |
printf("-41/21=%u\n", -41/21); |
printf("-41%%21=%u\n", -41%21); |
printf("-42/21=%u\n", -42/21); |
printf("-42%%21=%u\n", -42%21); |
printf("-43/21=%u\n", -43/21); |
printf("-43%%21=%u\n", -43%21); |
printf("-126/21=%u\n", -126/21); |
printf("-126%%21=%u\n", -126%21); |
printf("-131/21=%u\n", -131/21); |
printf("-131%%21=%u\n", -131%21); |
printf("-(UINT_MAX/2+3)/2=%u\n", (0-(UINT_MAX/2+3))/2); |
printf("-(UINT_MAX/2+3)%%2=%u\n", (0-(UINT_MAX/2+3))%2); |
printf("-18/-21=%u\n", -18/-21); |
printf("-18%%-21=%u\n", -18%-21); |
printf("-41/-21=%u\n", -41/-21); |
printf("-41%%-21=%u\n", -41%-21); |
printf("-42/-21=%u\n", -42/-21); |
printf("-42%%-21=%u\n", -42%-21); |
printf("-43/-21=%u\n", -43/-21); |
printf("-43%%-21=%u\n", -43%-21); |
printf("-126/-21=%u\n", -126/-21); |
printf("-126%%-21=%u\n", -126%-21); |
printf("-131/-21=%u\n", -131/-21); |
printf("-131%%-21=%u\n", -131%-21); |
printf("-(UINT_MAX/2+3)/-2=%u\n", (0-(UINT_MAX/2+3))/-2); |
printf("-(UINT_MAX/2+3)%%-2=%u\n", (0-(UINT_MAX/2+3))%-2); |
} |
void macro_test(void) |
{ |
printf("macro:\n"); |
pf("N=%d\n", N); |
printf("aaa=%d\n", AAA); |
printf("min=%d\n", min(1, min(2, -1))); |
printf("s1=%s\n", glue(HIGH, LOW)); |
printf("s2=%s\n", xglue(HIGH, LOW)); |
printf("s3=%s\n", str("c")); |
printf("s4=%s\n", str(a1)); |
printf("B3=%d\n", B3); |
printf("onetwothree=%d\n", onetwothree); |
#ifdef A |
printf("A defined\n"); |
#endif |
#ifdef B |
printf("B defined\n"); |
#endif |
#ifdef A |
printf("A defined\n"); |
#else |
printf("A not defined\n"); |
#endif |
#ifdef B |
printf("B defined\n"); |
#else |
printf("B not defined\n"); |
#endif |
#ifdef A |
printf("A defined\n"); |
#ifdef B |
printf("B1 defined\n"); |
#else |
printf("B1 not defined\n"); |
#endif |
#else |
printf("A not defined\n"); |
#ifdef B |
printf("B2 defined\n"); |
#else |
printf("B2 not defined\n"); |
#endif |
#endif |
#if 1+1 |
printf("test true1\n"); |
#endif |
#if 0 |
printf("test true2\n"); |
#endif |
#if 1-1 |
printf("test true3\n"); |
#endif |
#if defined(A) |
printf("test trueA\n"); |
#endif |
#if defined(B) |
printf("test trueB\n"); |
#endif |
#if 0 |
printf("test 0\n"); |
#elif 0 |
printf("test 1\n"); |
#elif 2 |
printf("test 2\n"); |
#else |
printf("test 3\n"); |
#endif |
MACRO_NOARGS(); |
#ifdef __LINE__ |
printf("__LINE__ defined\n"); |
#endif |
printf("__LINE__=%d __FILE__=%s\n", |
__LINE__, __FILE__); |
#if 0 |
#line 200 |
printf("__LINE__=%d __FILE__=%s\n", |
__LINE__, __FILE__); |
#line 203 "test" |
printf("__LINE__=%d __FILE__=%s\n", |
__LINE__, __FILE__); |
#line 227 "tcctest.c" |
#endif |
/* not strictly preprocessor, but we test it there */ |
#ifdef C99_MACROS |
printf("__func__ = %s\n", __func__); |
dprintf(1, "vaarg=%d\n", 1); |
#endif |
dprintf1(1, "vaarg1\n"); |
dprintf1(1, "vaarg1=%d\n", 2); |
dprintf1(1, "vaarg1=%d %d\n", 1, 2); |
/* gcc extension */ |
printf("func='%s'\n", __FUNCTION__); |
/* complicated macros in glibc */ |
printf("INT64_MIN=" LONG_LONG_FORMAT "\n", INT64_MIN); |
{ |
int a; |
a = 1; |
glue(a+, +); |
printf("a=%d\n", a); |
glue(a <, <= 2); |
printf("a=%d\n", a); |
} |
/* macro function with argument outside the macro string */ |
#define MF_s MF_hello |
#define MF_hello(msg) printf("%s\n",msg) |
#define MF_t printf("tralala\n"); MF_hello |
MF_s("hi"); |
MF_t("hi"); |
/* test macro substituion inside args (should not eat stream) */ |
printf("qq=%d\n", qq(qq)(2)); |
/* test zero argument case. NOTE: gcc 2.95.x does not accept a |
null argument without a space. gcc 3.2 fixes that. */ |
#define qq1(x) 1 |
printf("qq1=%d\n", qq1( )); |
/* comment with stray handling *\ |
/ |
/* this is a valid *\/ comment */ |
/* this is a valid comment *\*/ |
// this is a valid\ |
comment |
/* test function macro substitution when the function name is |
substituted */ |
TEST2(); |
/* And again when the name and parenthes are separated by a |
comment. */ |
TEST2 /* the comment */ (); |
} |
static void print_num(char *fn, int line, int num) { |
printf("fn %s, line %d, num %d\n", fn, line, num); |
} |
void recursive_macro_test(void) |
{ |
#define ELF32_ST_TYPE(val) ((val) & 0xf) |
#define ELF32_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf)) |
#define STB_WEAK 2 /* Weak symbol */ |
#define ELFW(type) ELF##32##_##type |
printf("%d\n", ELFW(ST_INFO)(STB_WEAK, ELFW(ST_TYPE)(123))); |
#define WRAP(x) x |
#define print_num(x) print_num(__FILE__,__LINE__,x) |
print_num(123); |
WRAP(print_num(123)); |
WRAP(WRAP(print_num(123))); |
static struct recursive_macro { int rm_field; } G; |
#define rm_field (G.rm_field) |
printf("rm_field = %d\n", rm_field); |
printf("rm_field = %d\n", WRAP(rm_field)); |
WRAP((printf("rm_field = %d %d\n", rm_field, WRAP(rm_field)))); |
} |
int op(a,b) |
{ |
return a / b; |
} |
int ret(a) |
{ |
if (a == 2) |
return 1; |
if (a == 3) |
return 2; |
return 0; |
} |
void ps(const char *s) |
{ |
int c; |
while (1) { |
c = *s; |
if (c == 0) |
break; |
printf("%c", c); |
s++; |
} |
} |
const char foo1_string[] = "\ |
bar\n\ |
test\14\ |
1"; |
void string_test() |
{ |
unsigned int b; |
printf("string:\n"); |
printf("\141\1423\143\n");/* dezdez test */ |
printf("\x41\x42\x43\x3a\n"); |
printf("c=%c\n", 'r'); |
printf("wc=%C 0x%lx %C\n", L'a', L'\x1234', L'c'); |
printf("foo1_string='%s'\n", foo1_string); |
#if 0 |
printf("wstring=%S\n", L"abc"); |
printf("wstring=%S\n", L"abc" L"def" "ghi"); |
printf("'\\377'=%d '\\xff'=%d\n", '\377', '\xff'); |
printf("L'\\377'=%d L'\\xff'=%d\n", L'\377', L'\xff'); |
#endif |
ps("test\n"); |
b = 32; |
while ((b = b + 1) < 96) { |
printf("%c", b); |
} |
printf("\n"); |
printf("fib=%d\n", fib(33)); |
b = 262144; |
while (b != 0x80000000) { |
num(b); |
b = b * 2; |
} |
} |
void loop_test() |
{ |
int i; |
i = 0; |
while (i < 10) |
printf("%d", i++); |
printf("\n"); |
for(i = 0; i < 10;i++) |
printf("%d", i); |
printf("\n"); |
i = 0; |
do { |
printf("%d", i++); |
} while (i < 10); |
printf("\n"); |
char count = 123; |
/* c99 for loop init test */ |
for (size_t count = 1; count < 3; count++) |
printf("count=%d\n", count); |
printf("count = %d\n", count); |
/* break/continue tests */ |
i = 0; |
while (1) { |
if (i == 6) |
break; |
i++; |
if (i == 3) |
continue; |
printf("%d", i); |
} |
printf("\n"); |
/* break/continue tests */ |
i = 0; |
do { |
if (i == 6) |
break; |
i++; |
if (i == 3) |
continue; |
printf("%d", i); |
} while(1); |
printf("\n"); |
for(i = 0;i < 10;i++) { |
if (i == 3) |
continue; |
printf("%d", i); |
} |
printf("\n"); |
} |
typedef int typedef_and_label; |
void goto_test() |
{ |
int i; |
static void *label_table[3] = { &&label1, &&label2, &&label3 }; |
printf("goto:\n"); |
i = 0; |
/* This needs to parse as label, not as start of decl. */ |
typedef_and_label: |
s_loop: |
if (i >= 10) |
goto s_end; |
printf("%d", i); |
i++; |
goto s_loop; |
s_end: |
printf("\n"); |
/* we also test computed gotos (GCC extension) */ |
for(i=0;i<3;i++) { |
goto *label_table[i]; |
label1: |
printf("label1\n"); |
goto next; |
label2: |
printf("label2\n"); |
goto next; |
label3: |
printf("label3\n"); |
next: ; |
} |
} |
enum { |
E0, |
E1 = 2, |
E2 = 4, |
E3, |
E4, |
}; |
enum test { |
E5 = 1000, |
}; |
void enum_test() |
{ |
enum test b1; |
printf("enum:\n%d %d %d %d %d %d\n", |
E0, E1, E2, E3, E4, E5); |
b1 = 1; |
printf("b1=%d\n", b1); |
} |
typedef int *my_ptr; |
typedef int mytype1; |
typedef int mytype2; |
void typedef_test() |
{ |
my_ptr a; |
mytype1 mytype2; |
int b; |
a = &b; |
*a = 1234; |
printf("typedef:\n"); |
printf("a=%d\n", *a); |
mytype2 = 2; |
printf("mytype2=%d\n", mytype2); |
} |
void forward_test() |
{ |
printf("forward:\n"); |
forward_ref(); |
forward_ref(); |
} |
void forward_ref(void) |
{ |
printf("forward ok\n"); |
} |
typedef struct struct1 { |
int f1; |
int f2, f3; |
union union1 { |
int v1; |
int v2; |
} u; |
char str[3]; |
} struct1; |
struct struct2 { |
int a; |
char b; |
}; |
union union2 { |
int w1; |
int w2; |
}; |
struct struct1 st1, st2; |
int main(int argc, char **argv) |
{ |
string_test(); |
expr_test(); |
macro_test(); |
recursive_macro_test(); |
scope_test(); |
forward_test(); |
funcptr_test(); |
loop_test(); |
switch_test(); |
goto_test(); |
enum_test(); |
typedef_test(); |
struct_test(); |
array_test(); |
expr_ptr_test(); |
bool_test(); |
expr2_test(); |
constant_expr_test(); |
expr_cmp_test(); |
char_short_test(); |
init_test(); |
compound_literal_test(); |
kr_test(); |
struct_assign_test(); |
cast_test(); |
bitfield_test(); |
c99_bool_test(); |
float_test(); |
longlong_test(); |
manyarg_test(); |
stdarg_test(); |
whitespace_test(); |
relocation_test(); |
old_style_function(); |
// alloca_test(); |
c99_vla_test(5, 2); |
sizeof_test(); |
typeof_test(); |
statement_expr_test(); |
local_label_test(); |
asm_test(); |
builtin_test(); |
#ifndef _WIN32 |
// weak_test(); |
#endif |
global_data_test(); |
cmp_comparison_test(); |
math_cmp_test(); |
callsave_test(); |
builtin_frame_address_test(); |
intdiv_test(); |
if (via_volatile (42) != 42) |
printf ("via_volatile broken\n"); |
return 0; |
} |
int tab[3]; |
int tab2[3][2]; |
int g; |
void f1(g) |
{ |
printf("g1=%d\n", g); |
} |
void scope_test() |
{ |
printf("scope:\n"); |
g = 2; |
f1(1); |
printf("g2=%d\n", g); |
{ |
int g; |
g = 3; |
printf("g3=%d\n", g); |
{ |
int g; |
g = 4; |
printf("g4=%d\n", g); |
} |
} |
printf("g5=%d\n", g); |
} |
void array_test() |
{ |
int i, j, a[4]; |
printf("array:\n"); |
printf("sizeof(a) = %d\n", sizeof(a)); |
printf("sizeof(\"a\") = %d\n", sizeof("a")); |
#ifdef C99_MACROS |
printf("sizeof(__func__) = %d\n", sizeof(__func__)); |
#endif |
printf("sizeof tab %d\n", sizeof(tab)); |
printf("sizeof tab2 %d\n", sizeof tab2); |
tab[0] = 1; |
tab[1] = 2; |
tab[2] = 3; |
printf("%d %d %d\n", tab[0], tab[1], tab[2]); |
for(i=0;i<3;i++) |
for(j=0;j<2;j++) |
tab2[i][j] = 10 * i + j; |
for(i=0;i<3*2;i++) { |
printf(" %3d", ((int *)tab2)[i]); |
} |
printf("\n"); |
printf("sizeof(size_t)=%d\n", sizeof(size_t)); |
printf("sizeof(ptrdiff_t)=%d\n", sizeof(ptrdiff_t)); |
} |
void expr_test() |
{ |
int a, b; |
a = 0; |
printf("%d\n", a += 1); |
printf("%d\n", a -= 2); |
printf("%d\n", a *= 31232132); |
printf("%d\n", a /= 4); |
printf("%d\n", a %= 20); |
printf("%d\n", a &= 6); |
printf("%d\n", a ^= 7); |
printf("%d\n", a |= 8); |
printf("%d\n", a >>= 3); |
printf("%d\n", a <<= 4); |
a = 22321; |
b = -22321; |
printf("%d\n", a + 1); |
printf("%d\n", a - 2); |
printf("%d\n", a * 312); |
printf("%d\n", a / 4); |
printf("%d\n", b / 4); |
printf("%d\n", (unsigned)b / 4); |
printf("%d\n", a % 20); |
printf("%d\n", b % 20); |
printf("%d\n", (unsigned)b % 20); |
printf("%d\n", a & 6); |
printf("%d\n", a ^ 7); |
printf("%d\n", a | 8); |
printf("%d\n", a >> 3); |
printf("%d\n", b >> 3); |
printf("%d\n", (unsigned)b >> 3); |
printf("%d\n", a << 4); |
printf("%d\n", ~a); |
printf("%d\n", -a); |
printf("%d\n", +a); |
printf("%d\n", 12 + 1); |
printf("%d\n", 12 - 2); |
printf("%d\n", 12 * 312); |
printf("%d\n", 12 / 4); |
printf("%d\n", 12 % 20); |
printf("%d\n", 12 & 6); |
printf("%d\n", 12 ^ 7); |
printf("%d\n", 12 | 8); |
printf("%d\n", 12 >> 2); |
printf("%d\n", 12 << 4); |
printf("%d\n", ~12); |
printf("%d\n", -12); |
printf("%d\n", +12); |
printf("%d %d %d %d\n", |
isid('a'), |
isid('g'), |
isid('T'), |
isid('(')); |
} |
int isid(int c) |
{ |
return (c >= 'a' & c <= 'z') | (c >= 'A' & c <= 'Z') | c == '_'; |
} |
/**********************/ |
int vstack[10], *vstack_ptr; |
void vpush(int vt, int vc) |
{ |
*vstack_ptr++ = vt; |
*vstack_ptr++ = vc; |
} |
void vpop(int *ft, int *fc) |
{ |
*fc = *--vstack_ptr; |
*ft = *--vstack_ptr; |
} |
void expr2_test() |
{ |
int a, b; |
printf("expr2:\n"); |
vstack_ptr = vstack; |
vpush(1432432, 2); |
vstack_ptr[-2] &= ~0xffffff80; |
vpop(&a, &b); |
printf("res= %d %d\n", a, b); |
} |
void constant_expr_test() |
{ |
int a; |
printf("constant_expr:\n"); |
a = 3; |
printf("%d\n", a * 16); |
printf("%d\n", a * 1); |
printf("%d\n", a + 0); |
} |
int tab4[10]; |
void expr_ptr_test() |
{ |
int *p, *q; |
int i = -1; |
printf("expr_ptr:\n"); |
p = tab4; |
q = tab4 + 10; |
printf("diff=%d\n", q - p); |
p++; |
printf("inc=%d\n", p - tab4); |
p--; |
printf("dec=%d\n", p - tab4); |
++p; |
printf("inc=%d\n", p - tab4); |
--p; |
printf("dec=%d\n", p - tab4); |
printf("add=%d\n", p + 3 - tab4); |
printf("add=%d\n", 3 + p - tab4); |
/* check if 64bit support is ok */ |
q = p = 0; |
q += i; |
printf("%p %p %ld\n", q, p, p-q); |
printf("%d %d %d %d %d %d\n", |
p == q, p != q, p < q, p <= q, p >= q, p > q); |
i = 0xf0000000; |
p += i; |
printf("%p %p %ld\n", q, p, p-q); |
printf("%d %d %d %d %d %d\n", |
p == q, p != q, p < q, p <= q, p >= q, p > q); |
p = (int *)((char *)p + 0xf0000000); |
printf("%p %p %ld\n", q, p, p-q); |
printf("%d %d %d %d %d %d\n", |
p == q, p != q, p < q, p <= q, p >= q, p > q); |
p += 0xf0000000; |
printf("%p %p %ld\n", q, p, p-q); |
printf("%d %d %d %d %d %d\n", |
p == q, p != q, p < q, p <= q, p >= q, p > q); |
{ |
struct size12 { |
int i, j, k; |
}; |
struct size12 s[2], *sp = s; |
int i, j; |
sp->i = 42; |
sp++; |
j = -1; |
printf("%d\n", sp[j].i); |
} |
} |
void expr_cmp_test() |
{ |
int a, b; |
printf("constant_expr:\n"); |
a = -1; |
b = 1; |
printf("%d\n", a == a); |
printf("%d\n", a != a); |
printf("%d\n", a < b); |
printf("%d\n", a <= b); |
printf("%d\n", a <= a); |
printf("%d\n", b >= a); |
printf("%d\n", a >= a); |
printf("%d\n", b > a); |
printf("%d\n", (unsigned)a < b); |
printf("%d\n", (unsigned)a <= b); |
printf("%d\n", (unsigned)a <= a); |
printf("%d\n", (unsigned)b >= a); |
printf("%d\n", (unsigned)a >= a); |
printf("%d\n", (unsigned)b > a); |
} |
struct empty { |
}; |
struct aligntest1 { |
char a[10]; |
}; |
struct aligntest2 { |
int a; |
char b[10]; |
}; |
struct aligntest3 { |
double a, b; |
}; |
struct aligntest4 { |
double a[0]; |
}; |
void struct_test() |
{ |
struct1 *s; |
union union2 u; |
printf("struct:\n"); |
printf("sizes: %d %d %d %d\n", |
sizeof(struct struct1), |
sizeof(struct struct2), |
sizeof(union union1), |
sizeof(union union2)); |
st1.f1 = 1; |
st1.f2 = 2; |
st1.f3 = 3; |
printf("st1: %d %d %d\n", |
st1.f1, st1.f2, st1.f3); |
st1.u.v1 = 1; |
st1.u.v2 = 2; |
printf("union1: %d\n", st1.u.v1); |
u.w1 = 1; |
u.w2 = 2; |
printf("union2: %d\n", u.w1); |
s = &st2; |
s->f1 = 3; |
s->f2 = 2; |
s->f3 = 1; |
printf("st2: %d %d %d\n", |
s->f1, s->f2, s->f3); |
printf("str_addr=%x\n", (int)st1.str - (int)&st1.f1); |
/* align / size tests */ |
printf("aligntest1 sizeof=%d alignof=%d\n", |
sizeof(struct aligntest1), __alignof__(struct aligntest1)); |
printf("aligntest2 sizeof=%d alignof=%d\n", |
sizeof(struct aligntest2), __alignof__(struct aligntest2)); |
printf("aligntest3 sizeof=%d alignof=%d\n", |
sizeof(struct aligntest3), __alignof__(struct aligntest3)); |
printf("aligntest4 sizeof=%d alignof=%d\n", |
sizeof(struct aligntest4), __alignof__(struct aligntest4)); |
/* empty structures (GCC extension) */ |
printf("sizeof(struct empty) = %d\n", sizeof(struct empty)); |
printf("alignof(struct empty) = %d\n", __alignof__(struct empty)); |
} |
/* XXX: depend on endianness */ |
void char_short_test() |
{ |
int var1, var2; |
printf("char_short:\n"); |
var1 = 0x01020304; |
var2 = 0xfffefdfc; |
printf("s8=%d %d\n", |
*(char *)&var1, *(char *)&var2); |
printf("u8=%d %d\n", |
*(unsigned char *)&var1, *(unsigned char *)&var2); |
printf("s16=%d %d\n", |
*(short *)&var1, *(short *)&var2); |
printf("u16=%d %d\n", |
*(unsigned short *)&var1, *(unsigned short *)&var2); |
printf("s32=%d %d\n", |
*(int *)&var1, *(int *)&var2); |
printf("u32=%d %d\n", |
*(unsigned int *)&var1, *(unsigned int *)&var2); |
*(char *)&var1 = 0x08; |
printf("var1=%x\n", var1); |
*(short *)&var1 = 0x0809; |
printf("var1=%x\n", var1); |
*(int *)&var1 = 0x08090a0b; |
printf("var1=%x\n", var1); |
} |
/******************/ |
typedef struct Sym { |
int v; |
int t; |
int c; |
struct Sym *next; |
struct Sym *prev; |
} Sym; |
#define ISLOWER(c) ('a' <= (c) && (c) <= 'z') |
#define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) |
static int toupper1(int a) |
{ |
return TOUPPER(a); |
} |
void bool_test() |
{ |
int *s, a, b, t, f, i; |
a = 0; |
s = (void*)0; |
printf("!s=%d\n", !s); |
if (!s || !s[0]) |
a = 1; |
printf("a=%d\n", a); |
printf("a=%d %d %d\n", 0 || 0, 0 || 1, 1 || 1); |
printf("a=%d %d %d\n", 0 && 0, 0 && 1, 1 && 1); |
printf("a=%d %d\n", 1 ? 1 : 0, 0 ? 1 : 0); |
#if 1 && 1 |
printf("a1\n"); |
#endif |
#if 1 || 0 |
printf("a2\n"); |
#endif |
#if 1 ? 0 : 1 |
printf("a3\n"); |
#endif |
#if 0 ? 0 : 1 |
printf("a4\n"); |
#endif |
a = 4; |
printf("b=%d\n", a + (0 ? 1 : a / 2)); |
/* test register spilling */ |
a = 10; |
b = 10; |
a = (a + b) * ((a < b) ? |
((b - a) * (a - b)): a + b); |
printf("a=%d\n", a); |
/* test complex || or && expressions */ |
t = 1; |
f = 0; |
a = 32; |
printf("exp=%d\n", f == (32 <= a && a <= 3)); |
printf("r=%d\n", (t || f) + (t && f)); |
/* test ? : cast */ |
{ |
int aspect_on; |
int aspect_native = 65536; |
double bfu_aspect = 1.0; |
int aspect; |
for(aspect_on = 0; aspect_on < 2; aspect_on++) { |
aspect=aspect_on?(aspect_native*bfu_aspect+0.5):65535UL; |
printf("aspect=%d\n", aspect); |
} |
} |
/* test ? : GCC extension */ |
{ |
static int v1 = 34 ? : -1; /* constant case */ |
static int v2 = 0 ? : -1; /* constant case */ |
int a = 30; |
printf("%d %d\n", v1, v2); |
printf("%d %d\n", a - 30 ? : a * 2, a + 1 ? : a * 2); |
} |
/* again complex expression */ |
for(i=0;i<256;i++) { |
if (toupper1 (i) != TOUPPER (i)) |
printf("error %d\n", i); |
} |
} |
/* GCC accepts that */ |
static int tab_reinit[]; |
static int tab_reinit[10]; |
//int cinit1; /* a global variable can be defined several times without error ! */ |
int cinit1; |
int cinit1; |
int cinit1 = 0; |
int *cinit2 = (int []){3, 2, 1}; |
void compound_literal_test(void) |
{ |
int *p, i; |
char *q, *q3; |
printf("compound_test:\n"); |
p = (int []){1, 2, 3}; |
for(i=0;i<3;i++) |
printf(" %d", p[i]); |
printf("\n"); |
for(i=0;i<3;i++) |
printf("%d", cinit2[i]); |
printf("\n"); |
q = "tralala1"; |
printf("q1=%s\n", q); |
q = (char *){ "tralala2" }; |
printf("q2=%s\n", q); |
q3 = (char *){ q }; |
printf("q3=%s\n", q3); |
q = (char []){ "tralala3" }; |
printf("q4=%s\n", q); |
#ifdef ALL_ISOC99 |
p = (int []){1, 2, cinit1 + 3}; |
for(i=0;i<3;i++) |
printf(" %d", p[i]); |
printf("\n"); |
for(i=0;i<3;i++) { |
p = (int []){1, 2, 4 + i}; |
printf("%d %d %d\n", |
p[0], |
p[1], |
p[2]); |
} |
#endif |
} |
/* K & R protos */ |
kr_func1(a, b) |
{ |
return a + b; |
} |
int kr_func2(a, b) |
{ |
return a + b; |
} |
kr_test() |
{ |
printf("kr_test:\n"); |
printf("func1=%d\n", kr_func1(3, 4)); |
printf("func2=%d\n", kr_func2(3, 4)); |
return 0; |
} |
void num(int n) |
{ |
char *tab, *p; |
tab = (char*)malloc(20); |
p = tab; |
while (1) { |
*p = 48 + (n % 10); |
p++; |
n = n / 10; |
if (n == 0) |
break; |
} |
while (p != tab) { |
p--; |
printf("%c", *p); |
} |
printf("\n"); |
free(tab); |
} |
/* structure assignment tests */ |
struct structa1 { |
int f1; |
char f2; |
}; |
struct structa1 ssta1; |
void struct_assign_test1(struct structa1 s1, int t, float f) |
{ |
printf("%d %d %d %f\n", s1.f1, s1.f2, t, f); |
} |
struct structa1 struct_assign_test2(struct structa1 s1, int t) |
{ |
s1.f1 += t; |
s1.f2 -= t; |
return s1; |
} |
void struct_assign_test(void) |
{ |
struct S { |
struct structa1 lsta1, lsta2; |
int i; |
} s, *ps; |
ps = &s; |
ps->i = 4; |
#if 0 |
printf("struct_assign_test:\n"); |
s.lsta1.f1 = 1; |
s.lsta1.f2 = 2; |
printf("%d %d\n", s.lsta1.f1, s.lsta1.f2); |
s.lsta2 = s.lsta1; |
printf("%d %d\n", s.lsta2.f1, s.lsta2.f2); |
#else |
s.lsta2.f1 = 1; |
s.lsta2.f2 = 2; |
#endif |
struct_assign_test1(ps->lsta2, 3, 4.5); |
printf("before call: %d %d\n", s.lsta2.f1, s.lsta2.f2); |
ps->lsta2 = struct_assign_test2(ps->lsta2, ps->i); |
printf("after call: %d %d\n", ps->lsta2.f1, ps->lsta2.f2); |
static struct { |
void (*elem)(); |
} t[] = { |
/* XXX: we should allow this even without braces */ |
{ struct_assign_test } |
}; |
printf("%d\n", struct_assign_test == t[0].elem); |
} |
/* casts to short/char */ |
void cast1(char a, short b, unsigned char c, unsigned short d) |
{ |
printf("%d %d %d %d\n", a, b, c, d); |
} |
char bcast; |
short scast; |
void cast_test() |
{ |
int a; |
char c; |
char tab[10]; |
unsigned b,d; |
short s; |
char *p = NULL; |
p -= 0x700000000042; |
printf("cast_test:\n"); |
a = 0xfffff; |
cast1(a, a, a, a); |
a = 0xffffe; |
printf("%d %d %d %d\n", |
(char)(a + 1), |
(short)(a + 1), |
(unsigned char)(a + 1), |
(unsigned short)(a + 1)); |
printf("%d %d %d %d\n", |
(char)0xfffff, |
(short)0xfffff, |
(unsigned char)0xfffff, |
(unsigned short)0xfffff); |
a = (bcast = 128) + 1; |
printf("%d\n", a); |
a = (scast = 65536) + 1; |
printf("%d\n", a); |
printf("sizeof(c) = %d, sizeof((int)c) = %d\n", sizeof(c), sizeof((int)c)); |
/* test cast from unsigned to signed short to int */ |
b = 0xf000; |
d = (short)b; |
printf("((unsigned)(short)0x%08x) = 0x%08x\n", b, d); |
b = 0xf0f0; |
d = (char)b; |
printf("((unsigned)(char)0x%08x) = 0x%08x\n", b, d); |
/* test implicit int casting for array accesses */ |
c = 0; |
tab[1] = 2; |
tab[c] = 1; |
printf("%d %d\n", tab[0], tab[1]); |
/* test implicit casting on some operators */ |
printf("sizeof(+(char)'a') = %d\n", sizeof(+(char)'a')); |
printf("sizeof(-(char)'a') = %d\n", sizeof(-(char)'a')); |
printf("sizeof(~(char)'a') = %d\n", sizeof(-(char)'a')); |
/* from pointer to integer types */ |
printf("%d %d %ld %ld %lld %lld\n", |
(int)p, (unsigned int)p, |
(long)p, (unsigned long)p, |
(long long)p, (unsigned long long)p); |
/* from integers to pointers */ |
printf("%p %p %p %p\n", |
(void *)a, (void *)b, (void *)c, (void *)d); |
} |
/* initializers tests */ |
struct structinit1 { |
int f1; |
char f2; |
short f3; |
int farray[3]; |
}; |
int sinit1 = 2; |
int sinit2 = { 3 }; |
int sinit3[3] = { 1, 2, {{3}}, }; |
int sinit4[3][2] = { {1, 2}, {3, 4}, {5, 6} }; |
int sinit5[3][2] = { 1, 2, 3, 4, 5, 6 }; |
int sinit6[] = { 1, 2, 3 }; |
int sinit7[] = { [2] = 3, [0] = 1, 2 }; |
char sinit8[] = "hello" "trala"; |
struct structinit1 sinit9 = { 1, 2, 3 }; |
struct structinit1 sinit10 = { .f2 = 2, 3, .f1 = 1 }; |
struct structinit1 sinit11 = { .f2 = 2, 3, .f1 = 1, |
#ifdef ALL_ISOC99 |
.farray[0] = 10, |
.farray[1] = 11, |
.farray[2] = 12, |
#endif |
}; |
char *sinit12 = "hello world"; |
char *sinit13[] = { |
"test1", |
"test2", |
"test3", |
}; |
char sinit14[10] = { "abc" }; |
int sinit15[3] = { sizeof(sinit15), 1, 2 }; |
struct { int a[3], b; } sinit16[] = { { 1 }, 2 }; |
struct bar { |
char *s; |
int len; |
} sinit17[] = { |
"a1", 4, |
"a2", 1 |
}; |
int sinit18[10] = { |
[2 ... 5] = 20, |
2, |
[8] = 10, |
}; |
struct complexinit0 { |
int a; |
int b; |
}; |
struct complexinit { |
int a; |
const struct complexinit0 *b; |
}; |
const static struct complexinit cix[] = { |
[0] = { |
.a = 2000, |
.b = (const struct complexinit0[]) { |
{ 2001, 2002 }, |
{ 2003, 2003 }, |
{} |
} |
} |
}; |
struct complexinit2 { |
int a; |
int b[]; |
}; |
struct complexinit2 cix20; |
struct complexinit2 cix21 = { |
.a = 3000, |
.b = { 3001, 3002, 3003 } |
}; |
struct complexinit2 cix22 = { |
.a = 4000, |
.b = { 4001, 4002, 4003, 4004, 4005, 4006 } |
}; |
void init_test(void) |
{ |
int linit1 = 2; |
int linit2 = { 3 }; |
int linit4[3][2] = { {1, 2}, {3, 4}, {5, 6} }; |
int linit6[] = { 1, 2, 3 }; |
int i, j; |
char linit8[] = "hello" "trala"; |
int linit12[10] = { 1, 2 }; |
int linit13[10] = { 1, 2, [7] = 3, [3] = 4, }; |
char linit14[10] = "abc"; |
int linit15[10] = { linit1, linit1 + 1, [6] = linit1 + 2, }; |
struct linit16 { int a1, a2, a3, a4; } linit16 = { 1, .a3 = 2 }; |
int linit17 = sizeof(linit17); |
printf("init_test:\n"); |
printf("sinit1=%d\n", sinit1); |
printf("sinit2=%d\n", sinit2); |
printf("sinit3=%d %d %d %d\n", |
sizeof(sinit3), |
sinit3[0], |
sinit3[1], |
sinit3[2] |
); |
printf("sinit6=%d\n", sizeof(sinit6)); |
printf("sinit7=%d %d %d %d\n", |
sizeof(sinit7), |
sinit7[0], |
sinit7[1], |
sinit7[2] |
); |
printf("sinit8=%s\n", sinit8); |
printf("sinit9=%d %d %d\n", |
sinit9.f1, |
sinit9.f2, |
sinit9.f3 |
); |
printf("sinit10=%d %d %d\n", |
sinit10.f1, |
sinit10.f2, |
sinit10.f3 |
); |
printf("sinit11=%d %d %d %d %d %d\n", |
sinit11.f1, |
sinit11.f2, |
sinit11.f3, |
sinit11.farray[0], |
sinit11.farray[1], |
sinit11.farray[2] |
); |
for(i=0;i<3;i++) |
for(j=0;j<2;j++) |
printf("[%d][%d] = %d %d %d\n", |
i, j, sinit4[i][j], sinit5[i][j], linit4[i][j]); |
printf("linit1=%d\n", linit1); |
printf("linit2=%d\n", linit2); |
printf("linit6=%d\n", sizeof(linit6)); |
printf("linit8=%d %s\n", sizeof(linit8), linit8); |
printf("sinit12=%s\n", sinit12); |
printf("sinit13=%d %s %s %s\n", |
sizeof(sinit13), |
sinit13[0], |
sinit13[1], |
sinit13[2]); |
printf("sinit14=%s\n", sinit14); |
for(i=0;i<10;i++) printf(" %d", linit12[i]); |
printf("\n"); |
for(i=0;i<10;i++) printf(" %d", linit13[i]); |
printf("\n"); |
for(i=0;i<10;i++) printf(" %d", linit14[i]); |
printf("\n"); |
for(i=0;i<10;i++) printf(" %d", linit15[i]); |
printf("\n"); |
printf("%d %d %d %d\n", |
linit16.a1, |
linit16.a2, |
linit16.a3, |
linit16.a4); |
/* test that initialisation is done after variable declare */ |
printf("linit17=%d\n", linit17); |
printf("sinit15=%d\n", sinit15[0]); |
printf("sinit16=%d %d\n", sinit16[0].a[0], sinit16[1].a[0]); |
printf("sinit17=%s %d %s %d\n", |
sinit17[0].s, sinit17[0].len, |
sinit17[1].s, sinit17[1].len); |
for(i=0;i<10;i++) |
printf("%x ", sinit18[i]); |
printf("\n"); |
/* complex init check */ |
printf("cix: %d %d %d %d %d %d %d\n", |
cix[0].a, |
cix[0].b[0].a, cix[0].b[0].b, |
cix[0].b[1].a, cix[0].b[1].b, |
cix[0].b[2].a, cix[0].b[2].b); |
printf("cix2: %d %d\n", cix21.b[2], cix22.b[5]); |
printf("sizeof cix20 %d, cix21 %d, sizeof cix22 %d\n", sizeof cix20, sizeof cix21, sizeof cix22); |
} |
void switch_test() |
{ |
int i; |
for(i=0;i<15;i++) { |
switch(i) { |
case 0: |
case 1: |
printf("a"); |
break; |
default: |
printf("%d", i); |
break; |
case 8 ... 12: |
printf("c"); |
break; |
case 3: |
printf("b"); |
break; |
} |
} |
printf("\n"); |
} |
/* ISOC99 _Bool type */ |
void c99_bool_test(void) |
{ |
#ifdef BOOL_ISOC99 |
int a; |
_Bool b; |
printf("bool_test:\n"); |
printf("sizeof(_Bool) = %d\n", sizeof(_Bool)); |
a = 3; |
printf("cast: %d %d %d\n", (_Bool)10, (_Bool)0, (_Bool)a); |
b = 3; |
printf("b = %d\n", b); |
b++; |
printf("b = %d\n", b); |
#endif |
} |
void bitfield_test(void) |
{ |
int a; |
short sa; |
unsigned char ca; |
struct sbf1 { |
int f1 : 3; |
int : 2; |
int f2 : 1; |
int : 0; |
int f3 : 5; |
int f4 : 7; |
unsigned int f5 : 7; |
} st1; |
printf("bitfield_test:"); |
printf("sizeof(st1) = %d\n", sizeof(st1)); |
st1.f1 = 3; |
st1.f2 = 1; |
st1.f3 = 15; |
a = 120; |
st1.f4 = a; |
st1.f5 = a; |
st1.f5++; |
printf("%d %d %d %d %d\n", |
st1.f1, st1.f2, st1.f3, st1.f4, st1.f5); |
sa = st1.f5; |
ca = st1.f5; |
printf("%d %d\n", sa, ca); |
st1.f1 = 7; |
if (st1.f1 == -1) |
printf("st1.f1 == -1\n"); |
else |
printf("st1.f1 != -1\n"); |
if (st1.f2 == -1) |
printf("st1.f2 == -1\n"); |
else |
printf("st1.f2 != -1\n"); |
/* bit sizes below must be bigger than 32 since GCC doesn't allow |
long-long bitfields whose size is not bigger than int */ |
struct sbf2 { |
long long f1 : 45; |
long long : 2; |
long long f2 : 35; |
unsigned long long f3 : 38; |
} st2; |
st2.f1 = 0x123456789ULL; |
a = 120; |
st2.f2 = (long long)a << 25; |
st2.f3 = a; |
st2.f2++; |
printf("%lld %lld %lld\n", st2.f1, st2.f2, st2.f3); |
} |
#ifdef __x86_64__ |
#define FLOAT_FMT "%f\n" |
#else |
/* x86's float isn't compatible with GCC */ |
#define FLOAT_FMT "%.5f\n" |
#endif |
/* declare strto* functions as they are C99 */ |
double strtod(const char *nptr, char **endptr); |
#if defined(_WIN32) |
float strtof(const char *nptr, char **endptr) {return (float)strtod(nptr, endptr);} |
LONG_DOUBLE strtold(const char *nptr, char **endptr) {return (LONG_DOUBLE)strtod(nptr, endptr);} |
#else |
float strtof(const char *nptr, char **endptr); |
LONG_DOUBLE strtold(const char *nptr, char **endptr); |
#endif |
#define FTEST(prefix, typename, type, fmt)\ |
void prefix ## cmp(type a, type b)\ |
{\ |
printf("%d %d %d %d %d %d\n",\ |
a == b,\ |
a != b,\ |
a < b,\ |
a > b,\ |
a >= b,\ |
a <= b);\ |
printf(fmt " " fmt " " fmt " " fmt " " fmt " " fmt " " fmt "\n",\ |
a,\ |
b,\ |
a + b,\ |
a - b,\ |
a * b,\ |
a / b,\ |
-a);\ |
printf(fmt "\n", ++a);\ |
printf(fmt "\n", a++);\ |
printf(fmt "\n", a);\ |
b = 0;\ |
printf("%d %d\n", !a, !b);\ |
}\ |
void prefix ## fcast(type a)\ |
{\ |
float fa;\ |
double da;\ |
LONG_DOUBLE la;\ |
int ia;\ |
long long llia;\ |
unsigned int ua;\ |
unsigned long long llua;\ |
type b;\ |
fa = a;\ |
da = a;\ |
la = a;\ |
printf("ftof: %f %f %Lf\n", fa, da, la);\ |
ia = (int)a;\ |
llia = (long long)a;\ |
a = (a >= 0) ? a : -a;\ |
ua = (unsigned int)a;\ |
llua = (unsigned long long)a;\ |
printf("ftoi: %d %u %lld %llu\n", ia, ua, llia, llua);\ |
ia = -1234;\ |
ua = 0x81234500;\ |
llia = -0x123456789012345LL;\ |
llua = 0xf123456789012345LLU;\ |
b = ia;\ |
printf("itof: " fmt "\n", b);\ |
b = ua;\ |
printf("utof: " fmt "\n", b);\ |
b = llia;\ |
printf("lltof: " fmt "\n", b);\ |
b = llua;\ |
printf("ulltof: " fmt "\n", b);\ |
}\ |
\ |
float prefix ## retf(type a) { return a; }\ |
double prefix ## retd(type a) { return a; }\ |
LONG_DOUBLE prefix ## retld(type a) { return a; }\ |
\ |
void prefix ## call(void)\ |
{\ |
printf("float: " FLOAT_FMT, prefix ## retf(42.123456789));\ |
printf("double: %f\n", prefix ## retd(42.123456789));\ |
printf("long double: %Lf\n", prefix ## retld(42.123456789));\ |
printf("strto%s: %f\n", #prefix, (double)strto ## prefix("1.2", NULL));\ |
}\ |
\ |
void prefix ## signed_zeros(void) \ |
{\ |
type x = 0.0, y = -0.0, n, p;\ |
if (x == y)\ |
printf ("Test 1.0 / x != 1.0 / y returns %d (should be 1).\n",\ |
1.0 / x != 1.0 / y);\ |
else\ |
printf ("x != y; this is wrong!\n");\ |
\ |
n = -x;\ |
if (x == n)\ |
printf ("Test 1.0 / x != 1.0 / -x returns %d (should be 1).\n",\ |
1.0 / x != 1.0 / n);\ |
else\ |
printf ("x != -x; this is wrong!\n");\ |
\ |
p = +y;\ |
if (x == p)\ |
printf ("Test 1.0 / x != 1.0 / +y returns %d (should be 1).\n",\ |
1.0 / x != 1.0 / p);\ |
else\ |
printf ("x != +y; this is wrong!\n");\ |
p = -y;\ |
if (x == p)\ |
printf ("Test 1.0 / x != 1.0 / -y returns %d (should be 0).\n",\ |
1.0 / x != 1.0 / p);\ |
else\ |
printf ("x != -y; this is wrong!\n");\ |
}\ |
void prefix ## test(void)\ |
{\ |
printf("testing '%s'\n", #typename);\ |
prefix ## cmp(1, 2.5);\ |
prefix ## cmp(2, 1.5);\ |
prefix ## cmp(1, 1);\ |
prefix ## fcast(234.6);\ |
prefix ## fcast(-2334.6);\ |
prefix ## call();\ |
prefix ## signed_zeros();\ |
} |
FTEST(f, float, float, "%f") |
FTEST(d, double, double, "%f") |
FTEST(ld, long double, LONG_DOUBLE, "%Lf") |
double ftab1[3] = { 1.2, 3.4, -5.6 }; |
void float_test(void) |
{ |
#if !defined(__arm__) || defined(__ARM_PCS_VFP) |
float fa, fb; |
double da, db; |
int a; |
unsigned int b; |
printf("float_test:\n"); |
printf("sizeof(float) = %d\n", sizeof(float)); |
printf("sizeof(double) = %d\n", sizeof(double)); |
printf("sizeof(long double) = %d\n", sizeof(LONG_DOUBLE)); |
ftest(); |
dtest(); |
ldtest(); |
printf("%f %f %f\n", ftab1[0], ftab1[1], ftab1[2]); |
printf("%f %f %f\n", 2.12, .5, 2.3e10); |
// printf("%f %f %f\n", 0x1234p12, 0x1e23.23p10, 0x12dp-10); |
da = 123; |
printf("da=%f\n", da); |
fa = 123; |
printf("fa=%f\n", fa); |
a = 4000000000; |
da = a; |
printf("da = %f\n", da); |
b = 4000000000; |
db = b; |
printf("db = %f\n", db); |
#endif |
} |
int fib(int n) |
{ |
if (n <= 2) |
return 1; |
else |
return fib(n-1) + fib(n-2); |
} |
void funcptr_test() |
{ |
void (*func)(int); |
int a; |
struct { |
int dummy; |
void (*func)(int); |
} st1; |
printf("funcptr:\n"); |
func = # |
(*func)(12345); |
func = num; |
a = 1; |
a = 1; |
func(12345); |
/* more complicated pointer computation */ |
st1.func = num; |
st1.func(12346); |
printf("sizeof1 = %d\n", sizeof(funcptr_test)); |
printf("sizeof2 = %d\n", sizeof funcptr_test); |
printf("sizeof3 = %d\n", sizeof(&funcptr_test)); |
printf("sizeof4 = %d\n", sizeof &funcptr_test); |
} |
void lloptest(long long a, long long b) |
{ |
unsigned long long ua, ub; |
ua = a; |
ub = b; |
/* arith */ |
printf("arith: " LONG_LONG_FORMAT " " LONG_LONG_FORMAT " " LONG_LONG_FORMAT "\n", |
a + b, |
a - b, |
a * b); |
if (b != 0) { |
printf("arith1: " LONG_LONG_FORMAT " " LONG_LONG_FORMAT "\n", |
a / b, |
a % b); |
} |
/* binary */ |
printf("bin: " LONG_LONG_FORMAT " " LONG_LONG_FORMAT " " LONG_LONG_FORMAT "\n", |
a & b, |
a | b, |
a ^ b); |
/* tests */ |
printf("test: %d %d %d %d %d %d\n", |
a == b, |
a != b, |
a < b, |
a > b, |
a >= b, |
a <= b); |
printf("utest: %d %d %d %d %d %d\n", |
ua == ub, |
ua != ub, |
ua < ub, |
ua > ub, |
ua >= ub, |
ua <= ub); |
/* arith2 */ |
a++; |
b++; |
printf("arith2: " LONG_LONG_FORMAT " " LONG_LONG_FORMAT "\n", a, b); |
printf("arith2: " LONG_LONG_FORMAT " " LONG_LONG_FORMAT "\n", a++, b++); |
printf("arith2: " LONG_LONG_FORMAT " " LONG_LONG_FORMAT "\n", --a, --b); |
printf("arith2: " LONG_LONG_FORMAT " " LONG_LONG_FORMAT "\n", a, b); |
b = ub = 0; |
printf("not: %d %d %d %d\n", !a, !ua, !b, !ub); |
} |
void llshift(long long a, int b) |
{ |
printf("shift: " LONG_LONG_FORMAT " " LONG_LONG_FORMAT " " LONG_LONG_FORMAT "\n", |
(unsigned long long)a >> b, |
a >> b, |
a << b); |
printf("shiftc: " LONG_LONG_FORMAT " " LONG_LONG_FORMAT " " LONG_LONG_FORMAT "\n", |
(unsigned long long)a >> 3, |
a >> 3, |
a << 3); |
printf("shiftc: " LONG_LONG_FORMAT " " LONG_LONG_FORMAT " " LONG_LONG_FORMAT "\n", |
(unsigned long long)a >> 35, |
a >> 35, |
a << 35); |
} |
void llfloat(void) |
{ |
float fa; |
double da; |
LONG_DOUBLE lda; |
long long la, lb, lc; |
unsigned long long ula, ulb, ulc; |
la = 0x12345678; |
ula = 0x72345678; |
la = (la << 20) | 0x12345; |
ula = ula << 33; |
printf("la=" LONG_LONG_FORMAT " ula=" ULONG_LONG_FORMAT "\n", la, ula); |
fa = la; |
da = la; |
lda = la; |
printf("lltof: %f %f %Lf\n", fa, da, lda); |
la = fa; |
lb = da; |
lc = lda; |
printf("ftoll: " LONG_LONG_FORMAT " " LONG_LONG_FORMAT " " LONG_LONG_FORMAT "\n", la, lb, lc); |
fa = ula; |
da = ula; |
lda = ula; |
printf("ulltof: %f %f %Lf\n", fa, da, lda); |
ula = fa; |
ulb = da; |
ulc = lda; |
printf("ftoull: " ULONG_LONG_FORMAT " " ULONG_LONG_FORMAT " " ULONG_LONG_FORMAT "\n", ula, ulb, ulc); |
} |
long long llfunc1(int a) |
{ |
return a * 2; |
} |
struct S { |
int id; |
char item; |
}; |
long long int value(struct S *v) |
{ |
return ((long long int)v->item); |
} |
void longlong_test(void) |
{ |
long long a, b, c; |
int ia; |
unsigned int ua; |
printf("longlong_test:\n"); |
printf("sizeof(long long) = %d\n", sizeof(long long)); |
ia = -1; |
ua = -2; |
a = ia; |
b = ua; |
printf(LONG_LONG_FORMAT " " LONG_LONG_FORMAT "\n", a, b); |
printf(LONG_LONG_FORMAT " " LONG_LONG_FORMAT " " LONG_LONG_FORMAT " %Lx\n", |
(long long)1, |
(long long)-2, |
1LL, |
0x1234567812345679); |
a = llfunc1(-3); |
printf(LONG_LONG_FORMAT "\n", a); |
lloptest(1000, 23); |
lloptest(0xff, 0x1234); |
b = 0x72345678 << 10; |
lloptest(-3, b); |
llshift(0x123, 5); |
llshift(-23, 5); |
b = 0x72345678LL << 10; |
llshift(b, 47); |
llfloat(); |
#if 1 |
b = 0x12345678; |
a = -1; |
c = a + b; |
printf("%Lx\n", c); |
#endif |
/* long long reg spill test */ |
{ |
struct S a; |
a.item = 3; |
printf("%lld\n", value(&a)); |
} |
lloptest(0x80000000, 0); |
/* another long long spill test */ |
{ |
long long *p, v; |
v = 1; |
p = &v; |
p[0]++; |
printf("%lld\n", *p); |
} |
a = 68719476720LL; |
b = 4294967295LL; |
printf("%d %d %d %d\n", a > b, a < b, a >= b, a <= b); |
printf(LONG_LONG_FORMAT "\n", 0x123456789LLU); |
} |
void manyarg_test(void) |
{ |
LONG_DOUBLE ld = 1234567891234LL; |
printf("manyarg_test:\n"); |
printf("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f\n", |
1, 2, 3, 4, 5, 6, 7, 8, |
0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0); |
printf("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f " |
LONG_LONG_FORMAT " " LONG_LONG_FORMAT " %f %f\n", |
1, 2, 3, 4, 5, 6, 7, 8, |
0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0, |
1234567891234LL, 987654321986LL, |
42.0, 43.0); |
printf("%Lf %d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f " |
LONG_LONG_FORMAT " " LONG_LONG_FORMAT " %f %f\n", |
ld, 1, 2, 3, 4, 5, 6, 7, 8, |
0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0, |
1234567891234LL, 987654321986LL, |
42.0, 43.0); |
printf("%d %d %d %d %d %d %d %d %Lf\n", |
1, 2, 3, 4, 5, 6, 7, 8, ld); |
printf("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f " |
LONG_LONG_FORMAT " " LONG_LONG_FORMAT "%f %f %Lf\n", |
1, 2, 3, 4, 5, 6, 7, 8, |
0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0, |
1234567891234LL, 987654321986LL, |
42.0, 43.0, ld); |
printf("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f " |
"%Lf " LONG_LONG_FORMAT " " LONG_LONG_FORMAT " %f %f %Lf\n", |
1, 2, 3, 4, 5, 6, 7, 8, |
0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0, |
ld, 1234567891234LL, 987654321986LL, |
42.0, 43.0, ld); |
} |
void vprintf1(const char *fmt, ...) |
{ |
va_list ap, aq; |
const char *p; |
int c, i; |
double d; |
long long ll; |
LONG_DOUBLE ld; |
va_start(aq, fmt); |
va_copy(ap, aq); |
p = fmt; |
for(;;) { |
c = *p; |
if (c == '\0') |
break; |
p++; |
if (c == '%') { |
c = *p; |
switch(c) { |
case '\0': |
goto the_end; |
case 'd': |
i = va_arg(ap, int); |
printf("%d", i); |
break; |
case 'f': |
d = va_arg(ap, double); |
printf("%f", d); |
break; |
case 'l': |
ll = va_arg(ap, long long); |
printf(LONG_LONG_FORMAT, ll); |
break; |
case 'F': |
ld = va_arg(ap, LONG_DOUBLE); |
printf("%Lf", ld); |
break; |
} |
p++; |
} else { |
putchar(c); |
} |
} |
the_end: |
va_end(aq); |
va_end(ap); |
} |
struct myspace { |
short int profile; |
}; |
void stdarg_for_struct(struct myspace bob, ...) |
{ |
struct myspace george, bill; |
va_list ap; |
short int validate; |
va_start(ap, bob); |
bill = va_arg(ap, struct myspace); |
george = va_arg(ap, struct myspace); |
validate = va_arg(ap, int); |
printf("stdarg_for_struct: %d %d %d %d\n", |
bob.profile, bill.profile, george.profile, validate); |
va_end(ap); |
} |
void stdarg_test(void) |
{ |
LONG_DOUBLE ld = 1234567891234LL; |
struct myspace bob; |
vprintf1("%d %d %d\n", 1, 2, 3); |
vprintf1("%f %d %f\n", 1.0, 2, 3.0); |
vprintf1("%l %l %d %f\n", 1234567891234LL, 987654321986LL, 3, 1234.0); |
vprintf1("%F %F %F\n", LONG_DOUBLE_LITERAL(1.2), LONG_DOUBLE_LITERAL(2.3), LONG_DOUBLE_LITERAL(3.4)); |
vprintf1("%d %f %l %F %d %f %l %F\n", |
1, 1.2, 3LL, LONG_DOUBLE_LITERAL(4.5), 6, 7.8, 9LL, LONG_DOUBLE_LITERAL(0.1)); |
vprintf1("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f\n", |
1, 2, 3, 4, 5, 6, 7, 8, |
0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8); |
vprintf1("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f\n", |
1, 2, 3, 4, 5, 6, 7, 8, |
0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0); |
vprintf1("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f " |
"%l %l %f %f\n", |
1, 2, 3, 4, 5, 6, 7, 8, |
0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0, |
1234567891234LL, 987654321986LL, |
42.0, 43.0); |
vprintf1("%F %d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f " |
"%l %l %f %f\n", |
ld, 1, 2, 3, 4, 5, 6, 7, 8, |
0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0, |
1234567891234LL, 987654321986LL, |
42.0, 43.0); |
vprintf1("%d %d %d %d %d %d %d %d %F\n", |
1, 2, 3, 4, 5, 6, 7, 8, ld); |
vprintf1("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f " |
"%l %l %f %f %F\n", |
1, 2, 3, 4, 5, 6, 7, 8, |
0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0, |
1234567891234LL, 987654321986LL, |
42.0, 43.0, ld); |
vprintf1("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f " |
"%F %l %l %f %f %F\n", |
1, 2, 3, 4, 5, 6, 7, 8, |
0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0, |
ld, 1234567891234LL, 987654321986LL, |
42.0, 43.0, ld); |
bob.profile = 42; |
stdarg_for_struct(bob, bob, bob, bob.profile); |
} |
void whitespace_test(void) |
{ |
char *str; |
+#if 1 |
+ pri\ |
+ntf("whitspace:\n"); |
+#endif |
+ pf("N=%d\n", 2); |
+ |
+#ifdef CORRECT_CR_HANDLING |
+ pri\ |
+ntf("aaa=%d\n", 3); |
+#endif |
+ |
+ pri\ |
+\ |
+ntf("min=%d\n", 4); |
+ |
+#ifdef ACCEPT_CR_IN_STRINGS |
+ printf("len1=%d\n", strlen(" |
+")); |
+#ifdef CORRECT_CR_HANDLING |
+ str = " |
+"; |
+ printf("len1=%d str[0]=%d\n", strlen(str), str[0]); |
+#endif |
+a |
+")); |
+#endif /* ACCEPT_CR_IN_STRINGS */ |
+} |
+ |
+int reltab[3] = { 1, 2, 3 }; |
+ |
+int *rel1 = &reltab[1]; |
+int *rel2 = &reltab[2]; |
+ |
+void relocation_test(void) |
+{ |
+ printf("*rel1=%d\n", *rel1); |
+ printf("*rel2=%d\n", *rel2); |
+} |
+ |
+void old_style_f(a,b,c) |
+ int a, b; |
+ double c; |
+{ |
+ printf("a=%d b=%d b=%f\n", a, b, c); |
+} |
+ |
+void decl_func1(int cmpfn()) |
+{ |
+ printf("cmpfn=%lx\n", (long)cmpfn); |
+} |
+ |
+void decl_func2(cmpfn) |
+int cmpfn(); |
+{ |
+ printf("cmpfn=%lx\n", (long)cmpfn); |
+} |
+ |
+void old_style_function(void) |
+{ |
+ old_style_f((void *)1, 2, 3.0); |
+ decl_func1(NULL); |
+ decl_func2(NULL); |
+} |
+ |
+#ifdef _0 |
+void alloca_test() |
+{ |
+#if defined __i386__ || defined __x86_64__ || defined __arm__ |
+ char *p = alloca(16); |
+ strcpy(p,"123456789012345"); |
+ printf("alloca: p is %s\n", p); |
+ char *demo = "This is only a test.\n"; |
+ /* Test alloca embedded in a larger expression */ |
+ printf("alloca: %s\n", strcpy(alloca(strlen(demo)+1),demo) ); |
+#endif |
+} |
+#endif |
+ |
+void *bounds_checking_is_enabled() |
+{ |
+ char ca[10], *cp = ca-1; |
+ return (ca != cp + 1) ? cp : NULL; |
+} |
+ |
+typedef int constant_negative_array_size_as_compile_time_assertion_idiom[(1 ? 2 : 0) - 1]; |
+ |
+void c99_vla_test(int size1, int size2) |
+{ |
+#if defined __i386__ || defined __x86_64__ |
+ int size = size1 * size2; |
+ int tab1[size][2], tab2[10][2]; |
+ void *tab1_ptr, *tab2_ptr, *bad_ptr; |
+ |
+ /* "size" should have been 'captured' at tab1 declaration, |
+ so modifying it should have no effect on VLA behaviour. */ |
+ size = size-1; |
+ |
+ printf("Test C99 VLA 1 (sizeof): "); |
+ printf("%s\n", (sizeof tab1 == size1 * size2 * 2 * sizeof(int)) ? "PASSED" : "FAILED"); |
+ tab1_ptr = tab1; |
+ tab2_ptr = tab2; |
+ printf("Test C99 VLA 2 (ptrs subtract): "); |
+ printf("%s\n", (tab2 - tab1 == (tab2_ptr - tab1_ptr) / (sizeof(int) * 2)) ? "PASSED" : "FAILED"); |
+ printf("Test C99 VLA 3 (ptr add): "); |
+ printf("%s\n", &tab1[5][1] == (tab1_ptr + (5 * 2 + 1) * sizeof(int)) ? "PASSED" : "FAILED"); |
+ printf("Test C99 VLA 4 (ptr access): "); |
+ tab1[size1][1] = 42; |
+ printf("%s\n", (*((int *) (tab1_ptr + (size1 * 2 + 1) * sizeof(int))) == 42) ? "PASSED" : "FAILED"); |
+ |
+ printf("Test C99 VLA 5 (bounds checking (might be disabled)): "); |
+ if (bad_ptr = bounds_checking_is_enabled()) { |
+ int *t1 = &tab1[size1 * size2 - 1][3]; |
+ int *t2 = &tab2[9][3]; |
+ printf("%s ", bad_ptr == t1 ? "PASSED" : "FAILED"); |
+ printf("%s ", bad_ptr == t2 ? "PASSED" : "FAILED"); |
+ |
+ char*c1 = 1 + sizeof(tab1) + (char*)tab1; |
+ char*c2 = 1 + sizeof(tab2) + (char*)tab2; |
+ printf("%s ", bad_ptr == c1 ? "PASSED" : "FAILED"); |
+ printf("%s ", bad_ptr == c2 ? "PASSED" : "FAILED"); |
+ |
+ int *i1 = tab1[-1]; |
+ int *i2 = tab2[-1]; |
+ printf("%s ", bad_ptr == i1 ? "PASSED" : "FAILED"); |
+ printf("%s ", bad_ptr == i2 ? "PASSED" : "FAILED"); |
+ |
+ int *x1 = tab1[size1 * size2 + 1]; |
+ int *x2 = tab2[10 + 1]; |
+ printf("%s ", bad_ptr == x1 ? "PASSED" : "FAILED"); |
+ printf("%s ", bad_ptr == x2 ? "PASSED" : "FAILED"); |
+ } else { |
+ printf("PASSED PASSED PASSED PASSED PASSED PASSED PASSED PASSED "); |
+ } |
+ printf("\n"); |
+#endif |
+} |
+ |
+typedef __SIZE_TYPE__ uintptr_t; |
+ |
+void sizeof_test(void) |
+{ |
+ int a; |
+ int **ptr; |
+ |
+ printf("sizeof(int) = %d\n", sizeof(int)); |
+ printf("sizeof(unsigned int) = %d\n", sizeof(unsigned int)); |
+ printf("sizeof(long) = %d\n", sizeof(long)); |
+ printf("sizeof(unsigned long) = %d\n", sizeof(unsigned long)); |
+ printf("sizeof(short) = %d\n", sizeof(short)); |
+ printf("sizeof(unsigned short) = %d\n", sizeof(unsigned short)); |
+ printf("sizeof(char) = %d\n", sizeof(char)); |
+ printf("sizeof(unsigned char) = %d\n", sizeof(unsigned char)); |
+ printf("sizeof(func) = %d\n", sizeof sizeof_test()); |
+ a = 1; |
+ printf("sizeof(a++) = %d\n", sizeof a++); |
+ printf("a=%d\n", a); |
+ ptr = NULL; |
+ printf("sizeof(**ptr) = %d\n", sizeof (**ptr)); |
+ |
+ /* The type of sizeof should be as large as a pointer, actually |
+ it should be size_t. */ |
+ printf("sizeof(sizeof(int) = %d\n", sizeof(sizeof(int))); |
+ uintptr_t t = 1; |
+ uintptr_t t2; |
+ /* Effectively <<32, but defined also on 32bit machines. */ |
+ t <<= 16; |
+ t <<= 16; |
+ t++; |
+ /* This checks that sizeof really can be used to manipulate |
+ uintptr_t objects, without truncation. */ |
+ t2 = t & -sizeof(uintptr_t); |
+ printf ("%lu %lu\n", t, t2); |
+ |
+ /* some alignof tests */ |
+ printf("__alignof__(int) = %d\n", __alignof__(int)); |
+ printf("__alignof__(unsigned int) = %d\n", __alignof__(unsigned int)); |
+ printf("__alignof__(short) = %d\n", __alignof__(short)); |
+ printf("__alignof__(unsigned short) = %d\n", __alignof__(unsigned short)); |
+ printf("__alignof__(char) = %d\n", __alignof__(char)); |
+ printf("__alignof__(unsigned char) = %d\n", __alignof__(unsigned char)); |
+ printf("__alignof__(func) = %d\n", __alignof__ sizeof_test()); |
+} |
+ |
+void typeof_test(void) |
+{ |
+ double a; |
+ typeof(a) b; |
+ typeof(float) c; |
+ |
+ a = 1.5; |
+ b = 2.5; |
+ c = 3.5; |
+ printf("a=%f b=%f c=%f\n", a, b, c); |
+} |
+ |
+void statement_expr_test(void) |
+{ |
+ int a, i; |
+ |
+ a = 0; |
+ for(i=0;i<10;i++) { |
+ a += 1 + |
+ ( { int b, j; |
+ b = 0; |
+ for(j=0;j<5;j++) |
+ b += j; b; |
+ } ); |
+ } |
+ printf("a=%d\n", a); |
+ |
+} |
+ |
+void local_label_test(void) |
+{ |
+ int a; |
+ goto l1; |
+ l2: |
+ a = 1 + ({ |
+ __label__ l1, l2, l3, l4; |
+ goto l1; |
+ l4: |
+ printf("aa1\n"); |
+ goto l3; |
+ l2: |
+ printf("aa3\n"); |
+ goto l4; |
+ l1: |
+ printf("aa2\n"); |
+ goto l2; |
+ l3:; |
+ 1; |
+ }); |
+ printf("a=%d\n", a); |
+ return; |
+ l4: |
+ printf("bb1\n"); |
+ goto l2; |
+ l1: |
+ printf("bb2\n"); |
+ goto l4; |
+} |
+ |
+/* inline assembler test */ |
+#ifdef __i386__ |
+ |
+/* from linux kernel */ |
+static char * strncat1(char * dest,const char * src,size_t count) |
+{ |
+int d0, d1, d2, d3; |
+__asm__ __volatile__( |
+ "repne\n\t" |
+ "scasb\n\t" |
+ "decl %1\n\t" |
+ "movl %8,%3\n" |
+ "1:\tdecl %3\n\t" |
+ "js 2f\n\t" |
+ "lodsb\n\t" |
+ "stosb\n\t" |
+ "testb %%al,%%al\n\t" |
+ "jne 1b\n" |
+ "2:\txorl %2,%2\n\t" |
+ "stosb" |
+ : "=&S" (d0), "=&D" (d1), "=&a" (d2), "=&c" (d3) |
+ : "0" (src),"1" (dest),"2" (0),"3" (0xffffffff), "g" (count) |
+ : "memory"); |
+return dest; |
+} |
+ |
+static char * strncat2(char * dest,const char * src,size_t count) |
+{ |
+int d0, d1, d2, d3; |
+__asm__ __volatile__( |
+ "repne scasb\n\t" /* one-line repne prefix + string op */ |
+ "decl %1\n\t" |
+ "movl %8,%3\n" |
+ "1:\tdecl %3\n\t" |
+ "js 2f\n\t" |
+ "lodsb\n\t" |
+ "stosb\n\t" |
+ "testb %%al,%%al\n\t" |
+ "jne 1b\n" |
+ "2:\txorl %2,%2\n\t" |
+ "stosb" |
+ : "=&S" (d0), "=&D" (d1), "=&a" (d2), "=&c" (d3) |
+ : "0" (src),"1" (dest),"2" (0),"3" (0xffffffff), "g" (count) |
+ : "memory"); |
+return dest; |
+} |
+ |
+static inline void * memcpy1(void * to, const void * from, size_t n) |
+{ |
+int d0, d1, d2; |
+__asm__ __volatile__( |
+ "rep ; movsl\n\t" |
+ "testb $2,%b4\n\t" |
+ "je 1f\n\t" |
+ "movsw\n" |
+ "1:\ttestb $1,%b4\n\t" |
+ "je 2f\n\t" |
+ "movsb\n" |
+ "2:" |
+ : "=&c" (d0), "=&D" (d1), "=&S" (d2) |
+ :"0" (n/4), "q" (n),"1" ((long) to),"2" ((long) from) |
+ : "memory"); |
+return (to); |
+} |
+ |
+static inline void * memcpy2(void * to, const void * from, size_t n) |
+{ |
+int d0, d1, d2; |
+__asm__ __volatile__( |
+ "rep movsl\n\t" /* one-line rep prefix + string op */ |
+ "testb $2,%b4\n\t" |
+ "je 1f\n\t" |
+ "movsw\n" |
+ "1:\ttestb $1,%b4\n\t" |
+ "je 2f\n\t" |
+ "movsb\n" |
+ "2:" |
+ : "=&c" (d0), "=&D" (d1), "=&S" (d2) |
+ :"0" (n/4), "q" (n),"1" ((long) to),"2" ((long) from) |
+ : "memory"); |
+return (to); |
+} |
+ |
+static __inline__ void sigaddset1(unsigned int *set, int _sig) |
+{ |
+ __asm__("btsl %1,%0" : "=m"(*set) : "Ir"(_sig - 1) : "cc"); |
+} |
+ |
+static __inline__ void sigdelset1(unsigned int *set, int _sig) |
+{ |
+ asm("btrl %1,%0" : "=m"(*set) : "Ir"(_sig - 1) : "cc"); |
+} |
+ |
+static __inline__ __const__ unsigned int swab32(unsigned int x) |
+{ |
+ __asm__("xchgb %b0,%h0\n\t" /* swap lower bytes */ |
+ "rorl $16,%0\n\t" /* swap words */ |
+ "xchgb %b0,%h0" /* swap higher bytes */ |
+ :"=q" (x) |
+ : "0" (x)); |
+ return x; |
+} |
+ |
+static __inline__ unsigned long long mul64(unsigned int a, unsigned int b) |
+{ |
+ unsigned long long res; |
+ __asm__("mull %2" : "=A" (res) : "a" (a), "r" (b)); |
+ return res; |
+} |
+ |
+static __inline__ unsigned long long inc64(unsigned long long a) |
+{ |
+ unsigned long long res; |
+ __asm__("addl $1, %%eax ; adcl $0, %%edx" : "=A" (res) : "A" (a)); |
+ return res; |
+} |
+ |
+unsigned int set; |
+ |
+void asm_test(void) |
+{ |
+ char buf[128]; |
+ unsigned int val; |
+ |
+ printf("inline asm:\n"); |
+ /* test the no operand case */ |
+ asm volatile ("xorl %eax, %eax"); |
+ |
+ memcpy1(buf, "hello", 6); |
+ strncat1(buf, " worldXXXXX", 3); |
+ printf("%s\n", buf); |
+ |
+ memcpy2(buf, "hello", 6); |
+ strncat2(buf, " worldXXXXX", 3); |
+ printf("%s\n", buf); |
+ |
+ /* 'A' constraint test */ |
+ printf("mul64=0x%Lx\n", mul64(0x12345678, 0xabcd1234)); |
+ printf("inc64=0x%Lx\n", inc64(0x12345678ffffffff)); |
+ |
+ set = 0xff; |
+ sigdelset1(&set, 2); |
+ sigaddset1(&set, 16); |
+ /* NOTE: we test here if C labels are correctly restored after the |
+ asm statement */ |
+ goto label1; |
+ label2: |
+ __asm__("btsl %1,%0" : "=m"(set) : "Ir"(20) : "cc"); |
+#ifdef __GNUC__ // works strange with GCC 4.3 |
+ set=0x1080fd; |
+#endif |
+ printf("set=0x%x\n", set); |
+ val = 0x01020304; |
+ printf("swab32(0x%08x) = 0x%0x\n", val, swab32(val)); |
+ return; |
+ label1: |
+ goto label2; |
+} |
+ |
+#else |
+ |
+void asm_test(void) |
+{ |
+} |
+ |
+#endif |
+ |
+#define COMPAT_TYPE(type1, type2) \ |
+{\ |
+ printf("__builtin_types_compatible_p(%s, %s) = %d\n", #type1, #type2, \ |
+ __builtin_types_compatible_p (type1, type2));\ |
+} |
+ |
+int constant_p_var; |
+ |
+void builtin_test(void) |
+{ |
+#if GCC_MAJOR >= 3 |
+ COMPAT_TYPE(int, int); |
+ COMPAT_TYPE(int, unsigned int); |
+ COMPAT_TYPE(int, char); |
+ COMPAT_TYPE(int, const int); |
+ COMPAT_TYPE(int, volatile int); |
+ COMPAT_TYPE(int *, int *); |
+ COMPAT_TYPE(int *, void *); |
+ COMPAT_TYPE(int *, const int *); |
+ COMPAT_TYPE(char *, unsigned char *); |
+ COMPAT_TYPE(char *, signed char *); |
+ COMPAT_TYPE(char *, char *); |
+/* space is needed because tcc preprocessor introduces a space between each token */ |
+ COMPAT_TYPE(char * *, void *); |
+#endif |
+ printf("res = %d\n", __builtin_constant_p(1)); |
+ printf("res = %d\n", __builtin_constant_p(1 + 2)); |
+ printf("res = %d\n", __builtin_constant_p(&constant_p_var)); |
+ printf("res = %d\n", __builtin_constant_p(constant_p_var)); |
+} |
+ |
+//#ifndef _WIN32 |
+#ifdef __0 |
+extern int __attribute__((weak)) weak_f1(void); |
+extern int __attribute__((weak)) weak_f2(void); |
+extern int weak_f3(void); |
+extern int __attribute__((weak)) weak_v1; |
+extern int __attribute__((weak)) weak_v2; |
+extern int weak_v3; |
+ |
+extern int (*weak_fpa)() __attribute__((weak)); |
+extern int __attribute__((weak)) (*weak_fpb)(); |
+extern __attribute__((weak)) int (*weak_fpc)(); |
+ |
+extern int weak_asm_f1(void) asm("weak_asm_f1x") __attribute((weak)); |
+extern int __attribute((weak)) weak_asm_f2(void) asm("weak_asm_f2x") ; |
+extern int __attribute((weak)) weak_asm_f3(void) asm("weak_asm_f3x") __attribute((weak)); |
+extern int weak_asm_v1 asm("weak_asm_v1x") __attribute((weak)); |
+extern int __attribute((weak)) weak_asm_v2 asm("weak_asm_v2x") ; |
+extern int __attribute((weak)) weak_asm_v3(void) asm("weak_asm_v3x") __attribute((weak)); |
+ |
+static const size_t dummy = 0; |
+extern __typeof(dummy) weak_dummy1 __attribute__((weak, alias("dummy"))); |
+extern __typeof(dummy) __attribute__((weak, alias("dummy"))) weak_dummy2; |
+extern __attribute__((weak, alias("dummy"))) __typeof(dummy) weak_dummy3; |
+ |
+int some_lib_func(void); |
+int dummy_impl_of_slf(void) { return 444; } |
+int some_lib_func(void) __attribute__((weak, alias("dummy_impl_of_slf"))); |
+ |
+int weak_toolate() __attribute__((weak)); |
+int weak_toolate() { return 0; } |
+ |
+void __attribute__((weak)) weak_test(void) |
+{ |
+ printf("weak_f1=%d\n", weak_f1 ? weak_f1() : 123); |
+ printf("weak_f2=%d\n", weak_f2 ? weak_f2() : 123); |
+ printf("weak_f3=%d\n", weak_f3 ? weak_f3() : 123); |
+ printf("weak_v1=%d\n",&weak_v1 ? weak_v1 : 123); |
+ printf("weak_v2=%d\n",&weak_v2 ? weak_v2 : 123); |
+ printf("weak_v3=%d\n",&weak_v3 ? weak_v3 : 123); |
+ |
+ printf("weak_fpa=%d\n",&weak_fpa ? weak_fpa() : 123); |
+ printf("weak_fpb=%d\n",&weak_fpb ? weak_fpb() : 123); |
+ printf("weak_fpc=%d\n",&weak_fpc ? weak_fpc() : 123); |
+ |
+ printf("weak_asm_f1=%d\n", weak_asm_f1 != NULL); |
+ printf("weak_asm_f2=%d\n", weak_asm_f2 != NULL); |
+ printf("weak_asm_f3=%d\n", weak_asm_f3 != NULL); |
+ printf("weak_asm_v1=%d\n",&weak_asm_v1 != NULL); |
+ printf("weak_asm_v2=%d\n",&weak_asm_v2 != NULL); |
+ printf("weak_asm_v3=%d\n",&weak_asm_v3 != NULL); |
+} |
+ |
+int __attribute__((weak)) weak_f2() { return 222; } |
+int __attribute__((weak)) weak_f3() { return 333; } |
+int __attribute__((weak)) weak_v2 = 222; |
+int __attribute__((weak)) weak_v3 = 333; |
+#endif |
+ |
+void const_func(const int a) |
+{ |
+} |
+ |
+void const_warn_test(void) |
+{ |
+ const_func(1); |
+} |
+ |
+struct condstruct { |
+ int i; |
+}; |
+ |
+int getme (struct condstruct *s, int i) |
+{ |
+ int i1 = (i == 0 ? 0 : s)->i; |
+ int i2 = (i == 0 ? s : 0)->i; |
+ int i3 = (i == 0 ? (void*)0 : s)->i; |
+ int i4 = (i == 0 ? s : (void*)0)->i; |
+ return i1 + i2 + i3 + i4; |
+} |
+ |
+struct global_data |
+{ |
+ int a[40]; |
+ int *b[40]; |
+}; |
+ |
+struct global_data global_data; |
+ |
+int global_data_getstuff (int *, int); |
+ |
+void global_data_callit (int i) |
+{ |
+ *global_data.b[i] = global_data_getstuff (global_data.b[i], 1); |
+} |
+ |
+int global_data_getstuff (int *p, int i) |
+{ |
+ return *p + i; |
+} |
+ |
+void global_data_test (void) |
+{ |
+ global_data.a[0] = 42; |
+ global_data.b[0] = &global_data.a[0]; |
+ global_data_callit (0); |
+ printf ("%d\n", global_data.a[0]); |
+} |
+ |
+struct cmpcmpS |
+{ |
+ unsigned char fill : 3; |
+ unsigned char b1 : 1; |
+ unsigned char b2 : 1; |
+ unsigned char fill2 : 3; |
+}; |
+ |
+int glob1, glob2, glob3; |
+ |
+void compare_comparisons (struct cmpcmpS *s) |
+{ |
+ if (s->b1 != (glob1 == glob2) |
+ || (s->b2 != (glob1 == glob3))) |
+ printf ("comparing comparisons broken\n"); |
+} |
+ |
+void cmp_comparison_test(void) |
+{ |
+ struct cmpcmpS s; |
+ s.b1 = 1; |
+ glob1 = 42; glob2 = 42; |
+ s.b2 = 0; |
+ glob3 = 43; |
+ compare_comparisons (&s); |
+} |
+ |
+int fcompare (double a, double b, int code) |
+{ |
+ switch (code) { |
+ case 0: return a == b; |
+ case 1: return a != b; |
+ case 2: return a < b; |
+ case 3: return a >= b; |
+ case 4: return a > b; |
+ case 5: return a <= b; |
+ } |
+} |
+ |
+void math_cmp_test(void) |
+{ |
+ double nan = 0.0/0.0; |
+ double one = 1.0; |
+ double two = 2.0; |
+ int comp = 0; |
+#define bug(a,b,op,iop,part) printf("Test broken: %s %s %s %s %d\n", #a, #b, #op, #iop, part) |
+ |
+ /* This asserts that "a op b" is _not_ true, but "a iop b" is true. |
+ And it does this in various ways so that all code generation paths |
+ are checked (generating inverted tests, or non-inverted tests, or |
+ producing a 0/1 value without jumps (that's done in the fcompare |
+ function). */ |
+#define FCMP(a,b,op,iop,code) \ |
+ if (fcompare (a,b,code)) \ |
+ bug (a,b,op,iop,1); \ |
+ if (a op b) \ |
+ bug (a,b,op,iop,2); \ |
+ if (a iop b) \ |
+ ; \ |
+ else \ |
+ bug (a,b,op,iop,3); \ |
+ if ((a op b) || comp) \ |
+ bug (a,b,op,iop,4); \ |
+ if ((a iop b) || comp) \ |
+ ; \ |
+ else \ |
+ bug (a,b,op,iop,5); |
+ |
+ /* Equality tests. */ |
+ FCMP(nan, nan, ==, !=, 0); |
+ FCMP(one, two, ==, !=, 0); |
+ FCMP(one, one, !=, ==, 1); |
+ /* Non-equality is a bit special. */ |
+ if (!fcompare (nan, nan, 1)) |
+ bug (nan, nan, !=, ==, 6); |
+ |
+ /* Relational tests on numbers. */ |
+ FCMP(two, one, <, >=, 2); |
+ FCMP(one, two, >=, <, 3); |
+ FCMP(one, two, >, <=, 4); |
+ FCMP(two, one, <=, >, 5); |
+ |
+ /* Relational tests on NaNs. Note that the inverse op here is |
+ always !=, there's no operator in C that is equivalent to !(a < b), |
+ when NaNs are involved, same for the other relational ops. */ |
+ FCMP(nan, nan, <, !=, 2); |
+ FCMP(nan, nan, >=, !=, 3); |
+ FCMP(nan, nan, >, !=, 4); |
+ FCMP(nan, nan, <=, !=, 5); |
+} |
+ |
+double get100 () { return 100.0; } |
+ |
+void callsave_test(void) |
+{ |
+#if defined __i386__ || defined __x86_64__ || defined __arm__ |
+ int i, s; double *d; double t; |
+ s = sizeof (double); |
+ printf ("callsavetest: %d\n", s); |
+ d = alloca (sizeof(double)); |
+ d[0] = 10.0; |
+ /* x86-64 had a bug were the next call to get100 would evict |
+ the lvalue &d[0] as VT_LLOCAL, and the reload would be done |
+ in int type, not pointer type. When alloca returns a pointer |
+ with the high 32 bit set (which is likely on x86-64) the access |
+ generates a segfault. */ |
+ i = d[0] > get100 (); |
+ printf ("%d\n", i); |
+#endif |
+} |
+ |
+ |
+void bfa3(ptrdiff_t str_offset) |
+{ |
+ printf("bfa3: %s\n", (char *)__builtin_frame_address(3) + str_offset); |
+} |
+void bfa2(ptrdiff_t str_offset) |
+{ |
+ printf("bfa2: %s\n", (char *)__builtin_frame_address(2) + str_offset); |
+ bfa3(str_offset); |
+} |
+void bfa1(ptrdiff_t str_offset) |
+{ |
+ printf("bfa1: %s\n", (char *)__builtin_frame_address(1) + str_offset); |
+ bfa2(str_offset); |
+} |
+ |
+void builtin_frame_address_test(void) |
+{ |
+/* builtin_frame_address fails on ARM with gcc which make test3 fail */ |
+#ifndef __arm__ |
+ char str[] = "__builtin_frame_address"; |
+ char *fp0 = __builtin_frame_address(0); |
+ |
+ printf("str: %s\n", str); |
+ bfa1(str-fp0); |
+#endif |
+} |
+ |
+char via_volatile (char i) |
+{ |
+ char volatile vi; |
+ vi = i; |
+ return vi; |
+} |
/programs/develop/ktcc/trunk/source/tests/tcctest.py |
---|
0,0 → 1,15 |
import subprocess |
import sys |
import difflib |
def main(): |
reference = subprocess.check_output([sys.argv[1]]) |
compare = subprocess.check_output(sys.argv[2:]) |
failed = False |
for line in difflib.unified_diff(reference.split('\n'), compare.split('\n'), fromfile='cc', tofile='tcc', lineterm=''): |
failed = True |
print line |
sys.exit(1 if failed else 0) |
if __name__ == '__main__': |
main() |
/programs/develop/ktcc/trunk/source/tests/tests2/000_cvttoftol.c |
---|
0,0 → 1,9 |
#include<stdio.h> |
int main() { |
int t1 = 176401255; |
float f = 0.25f; |
int t2a = (int)(t1 * f); // must be 44100313 |
int t2b = (int)(t1 * (float)0.25f); |
printf("t2a=%d t2b=%d \n",t2a,t2b); |
return 0; |
} |
/programs/develop/ktcc/trunk/source/tests/tests2/00_assignment.c |
---|
0,0 → 1,18 |
#include <stdio.h> |
int main() |
{ |
int a; |
a = 42; |
printf("%d\n", a); |
int b = 64; |
printf("%d\n", b); |
int c = 12, d = 34; |
printf("%d, %d\n", c, d); |
return 0; |
} |
// vim: set expandtab ts=4 sw=3 sts=3 tw=80 : |
/programs/develop/ktcc/trunk/source/tests/tests2/00_assignment.expect |
---|
0,0 → 1,3 |
42 |
64 |
12, 34 |
/programs/develop/ktcc/trunk/source/tests/tests2/01_comment.c |
---|
0,0 → 1,14 |
#include <stdio.h> |
int main() |
{ |
printf("Hello\n"); |
printf("Hello\n"); /* this is a comment */ printf("Hello\n"); |
printf("Hello\n"); |
// this is also a comment sayhello(); |
printf("Hello\n"); |
return 0; |
} |
// vim: set expandtab ts=4 sw=3 sts=3 tw=80 : |
/programs/develop/ktcc/trunk/source/tests/tests2/01_comment.expect |
---|
0,0 → 1,5 |
Hello |
Hello |
Hello |
Hello |
Hello |
/programs/develop/ktcc/trunk/source/tests/tests2/02_printf.c |
---|
0,0 → 1,18 |
#include <stdio.h> |
int main() |
{ |
printf("Hello world\n"); |
int Count; |
for (Count = -5; Count <= 5; Count++) |
printf("Count = %d\n", Count); |
printf("String 'hello', 'there' is '%s', '%s'\n", "hello", "there"); |
printf("Character 'A' is '%c'\n", 65); |
printf("Character 'a' is '%c'\n", 'a'); |
return 0; |
} |
// vim: set expandtab ts=4 sw=3 sts=3 tw=80 : |
/programs/develop/ktcc/trunk/source/tests/tests2/02_printf.expect |
---|
0,0 → 1,15 |
Hello world |
Count = -5 |
Count = -4 |
Count = -3 |
Count = -2 |
Count = -1 |
Count = 0 |
Count = 1 |
Count = 2 |
Count = 3 |
Count = 4 |
Count = 5 |
String 'hello', 'there' is 'hello', 'there' |
Character 'A' is 'A' |
Character 'a' is 'a' |
/programs/develop/ktcc/trunk/source/tests/tests2/03_struct.c |
---|
0,0 → 1,31 |
#include <stdio.h> |
struct fred |
{ |
int boris; |
int natasha; |
}; |
int main() |
{ |
struct fred bloggs; |
bloggs.boris = 12; |
bloggs.natasha = 34; |
printf("%d\n", bloggs.boris); |
printf("%d\n", bloggs.natasha); |
struct fred jones[2]; |
jones[0].boris = 12; |
jones[0].natasha = 34; |
jones[1].boris = 56; |
jones[1].natasha = 78; |
printf("%d\n", jones[0].boris); |
printf("%d\n", jones[0].natasha); |
printf("%d\n", jones[1].boris); |
printf("%d\n", jones[1].natasha); |
return 0; |
} |
/programs/develop/ktcc/trunk/source/tests/tests2/03_struct.expect |
---|
0,0 → 1,6 |
12 |
34 |
12 |
34 |
56 |
78 |
/programs/develop/ktcc/trunk/source/tests/tests2/04_for.c |
---|
0,0 → 1,15 |
#include <stdio.h> |
int main() |
{ |
int Count; |
for (Count = 1; Count <= 10; Count++) |
{ |
printf("%d\n", Count); |
} |
return 0; |
} |
// vim: set expandtab ts=4 sw=3 sts=3 tw=80 : |
/programs/develop/ktcc/trunk/source/tests/tests2/04_for.expect |
---|
0,0 → 1,10 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
/programs/develop/ktcc/trunk/source/tests/tests2/05_array.c |
---|
0,0 → 1,21 |
#include <stdio.h> |
int main() |
{ |
int Count; |
int Array[10]; |
for (Count = 1; Count <= 10; Count++) |
{ |
Array[Count-1] = Count * Count; |
} |
for (Count = 0; Count < 10; Count++) |
{ |
printf("%d\n", Array[Count]); |
} |
return 0; |
} |
// vim: set expandtab ts=4 sw=3 sts=3 tw=80 : |
/programs/develop/ktcc/trunk/source/tests/tests2/05_array.expect |
---|
0,0 → 1,10 |
1 |
4 |
9 |
16 |
25 |
36 |
49 |
64 |
81 |
100 |
/programs/develop/ktcc/trunk/source/tests/tests2/06_case.c |
---|
0,0 → 1,29 |
#include <stdio.h> |
int main() |
{ |
int Count; |
for (Count = 0; Count < 4; Count++) |
{ |
printf("%d\n", Count); |
switch (Count) |
{ |
case 1: |
printf("%d\n", 1); |
break; |
case 2: |
printf("%d\n", 2); |
break; |
default: |
printf("%d\n", 0); |
break; |
} |
} |
return 0; |
} |
// vim: set expandtab ts=4 sw=3 sts=3 tw=80 : |
/programs/develop/ktcc/trunk/source/tests/tests2/06_case.expect |
---|
0,0 → 1,8 |
1 |
1 |
2 |
2 |
3 |
/programs/develop/ktcc/trunk/source/tests/tests2/07_function.c |
---|
0,0 → 1,30 |
#include <stdio.h> |
int myfunc(int x) |
{ |
return x * x; |
} |
void vfunc(int a) |
{ |
printf("a=%d\n", a); |
} |
void qfunc() |
{ |
printf("qfunc()\n"); |
} |
int main() |
{ |
printf("%d\n", myfunc(3)); |
printf("%d\n", myfunc(4)); |
vfunc(1234); |
qfunc(); |
return 0; |
} |
// vim: set expandtab ts=4 sw=3 sts=3 tw=80 : |
/programs/develop/ktcc/trunk/source/tests/tests2/07_function.expect |
---|
0,0 → 1,4 |
9 |
16 |
a=1234 |
qfunc() |
/programs/develop/ktcc/trunk/source/tests/tests2/08_while.c |
---|
0,0 → 1,24 |
#include <stdio.h> |
int main() |
{ |
int a; |
int p; |
int t; |
a = 1; |
p = 0; |
t = 0; |
while (a < 100) |
{ |
printf("%d\n", a); |
t = a; |
a = t + p; |
p = t; |
} |
return 0; |
} |
// vim: set expandtab ts=4 sw=3 sts=3 tw=80 : |
/programs/develop/ktcc/trunk/source/tests/tests2/08_while.expect |
---|
0,0 → 1,11 |
1 |
1 |
2 |
3 |
5 |
8 |
13 |
21 |
34 |
55 |
89 |
/programs/develop/ktcc/trunk/source/tests/tests2/09_do_while.c |
---|
0,0 → 1,24 |
#include <stdio.h> |
int main() |
{ |
int a; |
int p; |
int t; |
a = 1; |
p = 0; |
t = 0; |
do |
{ |
printf("%d\n", a); |
t = a; |
a = t + p; |
p = t; |
} while (a < 100); |
return 0; |
} |
// vim: set expandtab ts=4 sw=3 sts=3 tw=80 : |
/programs/develop/ktcc/trunk/source/tests/tests2/09_do_while.expect |
---|
0,0 → 1,11 |
1 |
1 |
2 |
3 |
5 |
8 |
13 |
21 |
34 |
55 |
89 |
/programs/develop/ktcc/trunk/source/tests/tests2/10_pointer.c |
---|
0,0 → 1,40 |
#include <stdio.h> |
struct ziggy |
{ |
int a; |
int b; |
int c; |
} bolshevic; |
int main() |
{ |
int a; |
int *b; |
int c; |
a = 42; |
b = &a; |
printf("a = %d\n", *b); |
bolshevic.a = 12; |
bolshevic.b = 34; |
bolshevic.c = 56; |
printf("bolshevic.a = %d\n", bolshevic.a); |
printf("bolshevic.b = %d\n", bolshevic.b); |
printf("bolshevic.c = %d\n", bolshevic.c); |
struct ziggy *tsar = &bolshevic; |
printf("tsar->a = %d\n", tsar->a); |
printf("tsar->b = %d\n", tsar->b); |
printf("tsar->c = %d\n", tsar->c); |
b = &(bolshevic.b); |
printf("bolshevic.b = %d\n", *b); |
return 0; |
} |
// vim: set expandtab ts=4 sw=3 sts=3 tw=80 : |
/programs/develop/ktcc/trunk/source/tests/tests2/10_pointer.expect |
---|
0,0 → 1,8 |
a = 42 |
bolshevic.a = 12 |
bolshevic.b = 34 |
bolshevic.c = 56 |
tsar->a = 12 |
tsar->b = 34 |
tsar->c = 56 |
bolshevic.b = 34 |
/programs/develop/ktcc/trunk/source/tests/tests2/11_precedence.c |
---|
0,0 → 1,40 |
#include <stdio.h> |
int main() |
{ |
int a; |
int b; |
int c; |
int d; |
int e; |
int f; |
int x; |
int y; |
a = 12; |
b = 34; |
c = 56; |
d = 78; |
e = 0; |
f = 1; |
printf("%d\n", c + d); |
printf("%d\n", (y = c + d)); |
printf("%d\n", e || e && f); |
printf("%d\n", e || f && f); |
printf("%d\n", e && e || f); |
printf("%d\n", e && f || f); |
printf("%d\n", a && f | f); |
printf("%d\n", a | b ^ c & d); |
printf("%d, %d\n", a == a, a == b); |
printf("%d, %d\n", a != a, a != b); |
printf("%d\n", a != b && c != d); |
printf("%d\n", a + b * c / f); |
printf("%d\n", a + b * c / f); |
printf("%d\n", (4 << 4)); |
printf("%d\n", (64 >> 4)); |
return 0; |
} |
// vim: set expandtab ts=4 sw=3 sts=3 tw=80 : |
/programs/develop/ktcc/trunk/source/tests/tests2/11_precedence.expect |
---|
0,0 → 1,15 |
134 |
134 |
1 |
1 |
1 |
1 |
46 |
1, 0 |
0, 1 |
1 |
1916 |
1916 |
64 |
4 |
/programs/develop/ktcc/trunk/source/tests/tests2/12_hashdefine.c |
---|
0,0 → 1,14 |
#include <stdio.h> |
#define FRED 12 |
#define BLOGGS(x) (12*(x)) |
int main() |
{ |
printf("%d\n", FRED); |
printf("%d, %d, %d\n", BLOGGS(1), BLOGGS(2), BLOGGS(3)); |
return 0; |
} |
// vim: set expandtab ts=4 sw=3 sts=3 tw=80 : |
/programs/develop/ktcc/trunk/source/tests/tests2/12_hashdefine.expect |
---|
0,0 → 1,2 |
12 |
12, 24, 36 |
/programs/develop/ktcc/trunk/source/tests/tests2/13_integer_literals.c |
---|
0,0 → 1,20 |
#include <stdio.h> |
int main() |
{ |
int a = 24680; |
int b = 01234567; |
int c = 0x2468ac; |
int d = 0x2468AC; |
int e = 0b010101010101; |
printf("%d\n", a); |
printf("%d\n", b); |
printf("%d\n", c); |
printf("%d\n", d); |
printf("%d\n", e); |
return 0; |
} |
// vim: set expandtab ts=4 sw=3 sts=3 tw=80 : |
/programs/develop/ktcc/trunk/source/tests/tests2/13_integer_literals.expect |
---|
0,0 → 1,5 |
24680 |
342391 |
2386092 |
2386092 |
1365 |
/programs/develop/ktcc/trunk/source/tests/tests2/14_if.c |
---|
0,0 → 1,21 |
#include <stdio.h> |
int main() |
{ |
int a = 1; |
if (a) |
printf("a is true\n"); |
else |
printf("a is false\n"); |
int b = 0; |
if (b) |
printf("b is true\n"); |
else |
printf("b is false\n"); |
return 0; |
} |
// vim: set expandtab ts=4 sw=3 sts=3 tw=80 : |
/programs/develop/ktcc/trunk/source/tests/tests2/14_if.expect |
---|
0,0 → 1,2 |
a is true |
b is false |
/programs/develop/ktcc/trunk/source/tests/tests2/15_recursion.c |
---|
0,0 → 1,21 |
#include <stdio.h> |
int factorial(int i) |
{ |
if (i < 2) |
return i; |
else |
return i * factorial(i - 1); |
} |
int main() |
{ |
int Count; |
for (Count = 1; Count <= 10; Count++) |
printf("%d\n", factorial(Count)); |
return 0; |
} |
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ |
/programs/develop/ktcc/trunk/source/tests/tests2/15_recursion.expect |
---|
0,0 → 1,10 |
1 |
2 |
6 |
24 |
120 |
720 |
5040 |
40320 |
362880 |
3628800 |
/programs/develop/ktcc/trunk/source/tests/tests2/16_nesting.c |
---|
0,0 → 1,21 |
#include <stdio.h> |
int main() |
{ |
int x, y, z; |
for (x = 0; x < 2; x++) |
{ |
for (y = 0; y < 3; y++) |
{ |
for (z = 0; z < 3; z++) |
{ |
printf("%d %d %d\n", x, y, z); |
} |
} |
} |
return 0; |
} |
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ |
/programs/develop/ktcc/trunk/source/tests/tests2/16_nesting.expect |
---|
0,0 → 1,18 |
0 0 0 |
0 0 1 |
0 0 2 |
0 1 0 |
0 1 1 |
0 1 2 |
0 2 0 |
0 2 1 |
0 2 2 |
1 0 0 |
1 0 1 |
1 0 2 |
1 1 0 |
1 1 1 |
1 1 2 |
1 2 0 |
1 2 1 |
1 2 2 |
/programs/develop/ktcc/trunk/source/tests/tests2/17_enum.c |
---|
0,0 → 1,29 |
#include <stdio.h> |
enum fred |
{ |
a, |
b, |
c, |
d, |
e = 54, |
f = 73, |
g, |
h |
}; |
int main() |
{ |
enum fred frod; |
printf("%d %d %d %d %d %d %d %d\n", a, b, c, d, e, f, g, h); |
/* printf("%d\n", frod); */ |
frod = 12; |
printf("%d\n", frod); |
frod = e; |
printf("%d\n", frod); |
return 0; |
} |
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ |
/programs/develop/ktcc/trunk/source/tests/tests2/17_enum.expect |
---|
0,0 → 1,3 |
0 1 2 3 54 73 74 75 |
12 |
54 |
/programs/develop/ktcc/trunk/source/tests/tests2/18_include.c |
---|
0,0 → 1,12 |
#include <stdio.h> |
int main() |
{ |
printf("including\n"); |
#include "18_include.h" |
printf("done\n"); |
return 0; |
} |
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ |
/programs/develop/ktcc/trunk/source/tests/tests2/18_include.expect |
---|
0,0 → 1,3 |
including |
included |
done |
/programs/develop/ktcc/trunk/source/tests/tests2/18_include.h |
---|
0,0 → 1,0 |
printf("included\n"); |
/programs/develop/ktcc/trunk/source/tests/tests2/19_pointer_arithmetic.c |
---|
0,0 → 1,28 |
#include <stdio.h> |
int main() |
{ |
int a; |
int *b; |
int *c; |
a = 42; |
b = &a; |
c = NULL; |
printf("%d\n", *b); |
if (b == NULL) |
printf("b is NULL\n"); |
else |
printf("b is not NULL\n"); |
if (c == NULL) |
printf("c is NULL\n"); |
else |
printf("c is not NULL\n"); |
return 0; |
} |
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ |
/programs/develop/ktcc/trunk/source/tests/tests2/19_pointer_arithmetic.expect |
---|
0,0 → 1,3 |
42 |
b is not NULL |
c is NULL |
/programs/develop/ktcc/trunk/source/tests/tests2/20_pointer_comparison.c |
---|
0,0 → 1,24 |
#include <stdio.h> |
int main() |
{ |
int a; |
int b; |
int *d; |
int *e; |
d = &a; |
e = &b; |
a = 12; |
b = 34; |
printf("%d\n", *d); |
printf("%d\n", *e); |
printf("%d\n", d == e); |
printf("%d\n", d != e); |
d = e; |
printf("%d\n", d == e); |
printf("%d\n", d != e); |
return 0; |
} |
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ |
/programs/develop/ktcc/trunk/source/tests/tests2/20_pointer_comparison.expect |
---|
0,0 → 1,6 |
12 |
34 |
1 |
1 |
/programs/develop/ktcc/trunk/source/tests/tests2/21_char_array.c |
---|
0,0 → 1,33 |
#include <stdio.h> |
int main() |
{ |
int x = 'a'; |
char y = x; |
char *a = "hello"; |
printf("%s\n", a); |
int c; |
c = *a; |
char *b; |
for (b = a; *b != 0; b++) |
printf("%c: %d\n", *b, *b); |
char destarray[10]; |
char *dest = &destarray[0]; |
char *src = a; |
while (*src != 0) |
*dest++ = *src++; |
*dest = 0; |
printf("copied string is %s\n", destarray); |
return 0; |
} |
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ |
/programs/develop/ktcc/trunk/source/tests/tests2/21_char_array.expect |
---|
0,0 → 1,7 |
hello |
h: 104 |
e: 101 |
l: 108 |
l: 108 |
o: 111 |
copied string is hello |
/programs/develop/ktcc/trunk/source/tests/tests2/22_floating_point.c |
---|
0,0 → 1,50 |
#include <stdio.h> |
#include <math.h> |
int main() |
{ |
// variables |
float a = 12.34 + 56.78; |
printf("%f\n", a); |
// infix operators |
printf("%f\n", 12.34 + 56.78); |
printf("%f\n", 12.34 - 56.78); |
printf("%f\n", 12.34 * 56.78); |
printf("%f\n", 12.34 / 56.78); |
// comparison operators |
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); |
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); |
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); |
// assignment operators |
a = 12.34; |
a += 56.78; |
printf("%f\n", a); |
a = 12.34; |
a -= 56.78; |
printf("%f\n", a); |
a = 12.34; |
a *= 56.78; |
printf("%f\n", a); |
a = 12.34; |
a /= 56.78; |
printf("%f\n", a); |
// prefix operators |
printf("%f\n", +12.34); |
printf("%f\n", -12.34); |
// type coercion |
a = 2; |
printf("%f\n", a); |
printf("%f\n", sin(2)); |
return 0; |
} |
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ |
/programs/develop/ktcc/trunk/source/tests/tests2/22_floating_point.expect |
---|
0,0 → 1,16 |
69.120003 |
69.120000 |
-44.440000 |
700.665200 |
0.217330 |
1 1 0 0 0 1 |
0 1 1 1 0 0 |
0 0 0 1 1 1 |
69.120003 |
-44.439999 |
700.665222 |
0.217330 |
12.340000 |
-12.340000 |
2.000000 |
0.909297 |
/programs/develop/ktcc/trunk/source/tests/tests2/23_type_coercion.c |
---|
0,0 → 1,54 |
#include <stdio.h> |
void charfunc(char a) |
{ |
printf("char: %c\n", a); |
} |
void intfunc(int a) |
{ |
printf("int: %d\n", a); |
} |
void floatfunc(float a) |
{ |
printf("float: %f\n", a); |
} |
int main() |
{ |
charfunc('a'); |
charfunc(98); |
charfunc(99.0); |
intfunc('a'); |
intfunc(98); |
intfunc(99.0); |
floatfunc('a'); |
floatfunc(98); |
floatfunc(99.0); |
/* printf("%c %d %f\n", 'a', 'b', 'c'); */ |
/* printf("%c %d %f\n", 97, 98, 99); */ |
/* printf("%c %d %f\n", 97.0, 98.0, 99.0); */ |
char b = 97; |
char c = 97.0; |
printf("%d %d\n", b, c); |
int d = 'a'; |
int e = 97.0; |
printf("%d %d\n", d, e); |
float f = 'a'; |
float g = 97; |
printf("%f %f\n", f, g); |
return 0; |
} |
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ |
/programs/develop/ktcc/trunk/source/tests/tests2/23_type_coercion.expect |
---|
0,0 → 1,12 |
char: a |
char: b |
char: c |
int: 97 |
int: 98 |
int: 99 |
float: 97.000000 |
float: 98.000000 |
float: 99.000000 |
97 97 |
97 97 |
97.000000 97.000000 |
/programs/develop/ktcc/trunk/source/tests/tests2/24_math_library.c |
---|
0,0 → 1,30 |
#define _ISOC99_SOURCE 1 |
#include <stdio.h> |
#include <math.h> |
int main() |
{ |
printf("%f\n", sin(0.12)); |
printf("%f\n", cos(0.12)); |
printf("%f\n", tan(0.12)); |
printf("%f\n", asin(0.12)); |
printf("%f\n", acos(0.12)); |
printf("%f\n", atan(0.12)); |
printf("%f\n", sinh(0.12)); |
printf("%f\n", cosh(0.12)); |
printf("%f\n", tanh(0.12)); |
printf("%f\n", exp(0.12)); |
printf("%f\n", fabs(-0.12)); |
printf("%f\n", log(0.12)); |
printf("%f\n", log10(0.12)); |
printf("%f\n", pow(0.12, 0.12)); |
printf("%f\n", sqrt(0.12)); |
printf("%f\n", round(12.34)); |
printf("%f\n", ceil(12.34)); |
printf("%f\n", floor(12.34)); |
return 0; |
} |
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ |
/programs/develop/ktcc/trunk/source/tests/tests2/24_math_library.expect |
---|
0,0 → 1,18 |
0.119712 |
0.992809 |
0.120579 |
0.120290 |
1.450506 |
0.119429 |
0.120288 |
1.007209 |
0.119427 |
1.127497 |
0.120000 |
-2.120264 |
-0.920819 |
0.775357 |
0.346410 |
12.000000 |
13.000000 |
12.000000 |
/programs/develop/ktcc/trunk/source/tests/tests2/25_quicksort.c |
---|
0,0 → 1,83 |
#include <stdio.h> |
int array[16]; |
//Swap integer values by array indexes |
void swap(int a, int b) |
{ |
int tmp = array[a]; |
array[a] = array[b]; |
array[b] = tmp; |
} |
//Partition the array into two halves and return the |
//index about which the array is partitioned |
int partition(int left, int right) |
{ |
int pivotIndex = left; |
int pivotValue = array[pivotIndex]; |
int index = left; |
int i; |
swap(pivotIndex, right); |
for(i = left; i < right; i++) |
{ |
if(array[i] < pivotValue) |
{ |
swap(i, index); |
index += 1; |
} |
} |
swap(right, index); |
return index; |
} |
//Quicksort the array |
void quicksort(int left, int right) |
{ |
if(left >= right) |
return; |
int index = partition(left, right); |
quicksort(left, index - 1); |
quicksort(index + 1, right); |
} |
int main() |
{ |
int i; |
array[0] = 62; |
array[1] = 83; |
array[2] = 4; |
array[3] = 89; |
array[4] = 36; |
array[5] = 21; |
array[6] = 74; |
array[7] = 37; |
array[8] = 65; |
array[9] = 33; |
array[10] = 96; |
array[11] = 38; |
array[12] = 53; |
array[13] = 16; |
array[14] = 74; |
array[15] = 55; |
for (i = 0; i < 16; i++) |
printf("%d ", array[i]); |
printf("\n"); |
quicksort(0, 15); |
for (i = 0; i < 16; i++) |
printf("%d ", array[i]); |
printf("\n"); |
return 0; |
} |
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ |
/programs/develop/ktcc/trunk/source/tests/tests2/25_quicksort.expect |
---|
0,0 → 1,2 |
62 83 4 89 36 21 74 37 65 33 96 38 53 16 74 55 |
4 16 21 33 36 37 38 53 55 62 65 74 74 83 89 96 |
/programs/develop/ktcc/trunk/source/tests/tests2/26_character_constants.c |
---|
0,0 → 1,17 |
#include <stdio.h> |
int main() |
{ |
printf("%d\n", '\1'); |
printf("%d\n", '\10'); |
printf("%d\n", '\100'); |
printf("%d\n", '\x01'); |
printf("%d\n", '\x0e'); |
printf("%d\n", '\x10'); |
printf("%d\n", '\x40'); |
printf("test \x40\n"); |
return 0; |
} |
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ |
/programs/develop/ktcc/trunk/source/tests/tests2/26_character_constants.expect |
---|
0,0 → 1,8 |
1 |
8 |
64 |
1 |
14 |
16 |
64 |
test @ |
/programs/develop/ktcc/trunk/source/tests/tests2/27_sizeof.c |
---|
0,0 → 1,18 |
#include <stdio.h> |
int main() |
{ |
char a; |
int b; |
double c; |
printf("%d\n", sizeof(a)); |
printf("%d\n", sizeof(b)); |
printf("%d\n", sizeof(c)); |
printf("%d\n", sizeof(!a)); |
return 0; |
} |
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ |
/programs/develop/ktcc/trunk/source/tests/tests2/27_sizeof.expect |
---|
0,0 → 1,4 |
1 |
4 |
8 |
4 |
/programs/develop/ktcc/trunk/source/tests/tests2/28_strings.c |
---|
0,0 → 1,48 |
#include <stdio.h> |
#include <string.h> |
//#include <strings.h> |
#define index(a,b) strchr(a,b) |
#define rindex(a,b) strrchr(a,b) |
int main() |
{ |
char a[10]; |
strcpy(a, "hello"); |
printf("%s\n", a); |
strncpy(a, "gosh", 2); |
printf("%s\n", a); |
printf("%d\n", strcmp(a, "apple") > 0); |
printf("%d\n", strcmp(a, "goere") > 0); |
printf("%d\n", strcmp(a, "zebra") < 0); |
printf("%d\n", strlen(a)); |
strcat(a, "!"); |
printf("%s\n", a); |
printf("%d\n", strncmp(a, "apple", 2) > 0); |
printf("%d\n", strncmp(a, "goere", 2) == 0); |
printf("%d\n", strncmp(a, "goerg", 2) == 0); |
printf("%d\n", strncmp(a, "zebra", 2) < 0); |
printf("%s\n", index(a, 'o')); |
printf("%s\n", rindex(a, 'l')); |
printf("%d\n", rindex(a, 'x') == NULL); |
memset(&a[1], 'r', 4); |
printf("%s\n", a); |
memcpy(&a[2], a, 2); |
printf("%s\n", a); |
printf("%d\n", memcmp(a, "apple", 4) > 0); |
printf("%d\n", memcmp(a, "grgr", 4) == 0); |
printf("%d\n", memcmp(a, "zebra", 4) < 0); |
return 0; |
} |
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ |
/programs/develop/ktcc/trunk/source/tests/tests2/28_strings.expect |
---|
0,0 → 1,19 |
hello |
gollo |
1 |
1 |
1 |
5 |
gollo! |
1 |
1 |
1 |
1 |
ollo! |
lo! |
1 |
grrrr! |
grgrr! |
1 |
1 |
1 |
/programs/develop/ktcc/trunk/source/tests/tests2/29_array_address.c |
---|
0,0 → 1,13 |
#include <stdio.h> |
#include <string.h> |
int main() |
{ |
char a[10]; |
strcpy(a, "abcdef"); |
printf("%s\n", &a[1]); |
return 0; |
} |
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ |
/programs/develop/ktcc/trunk/source/tests/tests2/29_array_address.expect |
---|
0,0 → 1,0 |
bcdef |
/programs/develop/ktcc/trunk/source/tests/tests2/30_hanoi.c |
---|
0,0 → 1,122 |
/* example from http://barnyard.syr.edu/quickies/hanoi.c */ |
/* hanoi.c: solves the tower of hanoi problem. (Programming exercise.) */ |
/* By Terry R. McConnell (12/2/97) */ |
/* Compile: cc -o hanoi hanoi.c */ |
/* This program does no error checking. But then, if it's right, |
it's right ... right ? */ |
/* The original towers of hanoi problem seems to have been originally posed |
by one M. Claus in 1883. There is a popular legend that goes along with |
it that has been often repeated and paraphrased. It goes something like this: |
In the great temple at Benares there are 3 golden spikes. On one of them, |
God placed 64 disks increasing in size from bottom to top, at the beginning |
of time. Since then, and to this day, the priest on duty constantly transfers |
disks, one at a time, in such a way that no larger disk is ever put on top |
of a smaller one. When the disks have been transferred entirely to another |
spike the Universe will come to an end in a large thunderclap. |
This paraphrases the original legend due to DeParville, La Nature, Paris 1884, |
Part I, 285-286. For this and further information see: Mathematical |
Recreations & Essays, W.W. Rouse Ball, MacMillan, NewYork, 11th Ed. 1967, |
303-305. |
* |
* |
*/ |
#include <stdio.h> |
#include <stdlib.h> |
#define TRUE 1 |
#define FALSE 0 |
/* This is the number of "disks" on tower A initially. Taken to be 64 in the |
* legend. The number of moves required, in general, is 2^N - 1. For N = 64, |
* this is 18,446,744,073,709,551,615 */ |
#define N 4 |
/* These are the three towers. For example if the state of A is 0,1,3,4, that |
* means that there are three discs on A of sizes 1, 3, and 4. (Think of right |
* as being the "down" direction.) */ |
int A[N], B[N], C[N]; |
void Hanoi(int,int*,int*,int*); |
/* Print the current configuration of A, B, and C to the screen */ |
void PrintAll() |
{ |
int i; |
printf("A: "); |
for(i=0;i<N;i++)printf(" %d ",A[i]); |
printf("\n"); |
printf("B: "); |
for(i=0;i<N;i++)printf(" %d ",B[i]); |
printf("\n"); |
printf("C: "); |
for(i=0;i<N;i++)printf(" %d ",C[i]); |
printf("\n"); |
printf("------------------------------------------\n"); |
return; |
} |
/* Move the leftmost nonzero element of source to dest, leave behind 0. */ |
/* Returns the value moved (not used.) */ |
int Move(int *source, int *dest) |
{ |
int i = 0, j = 0; |
while (i<N && (source[i])==0) i++; |
while (j<N && (dest[j])==0) j++; |
dest[j-1] = source[i]; |
source[i] = 0; |
PrintAll(); /* Print configuration after each move. */ |
return dest[j-1]; |
} |
/* Moves first n nonzero numbers from source to dest using the rules of Hanoi. |
Calls itself recursively. |
*/ |
void Hanoi(int n,int *source, int *dest, int *spare) |
{ |
int i; |
if(n==1){ |
Move(source,dest); |
return; |
} |
Hanoi(n-1,source,spare,dest); |
Move(source,dest); |
Hanoi(n-1,spare,dest,source); |
return; |
} |
int main() |
{ |
int i; |
/* initialize the towers */ |
for(i=0;i<N;i++)A[i]=i+1; |
for(i=0;i<N;i++)B[i]=0; |
for(i=0;i<N;i++)C[i]=0; |
printf("Solution of Tower of Hanoi Problem with %d Disks\n\n",N); |
/* Print the starting state */ |
printf("Starting state:\n"); |
PrintAll(); |
printf("\n\nSubsequent states:\n\n"); |
/* Do it! Use A = Source, B = Destination, C = Spare */ |
Hanoi(N,A,B,C); |
return 0; |
} |
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ |
/programs/develop/ktcc/trunk/source/tests/tests2/30_hanoi.expect |
---|
0,0 → 1,71 |
Solution of Tower of Hanoi Problem with 4 Disks |
Starting state: |
A: 1 2 3 4 |
B: 0 0 0 0 |
C: 0 0 0 0 |
------------------------------------------ |
Subsequent states: |
A: 0 2 3 4 |
B: 0 0 0 0 |
C: 0 0 0 1 |
------------------------------------------ |
A: 0 0 3 4 |
B: 0 0 0 2 |
C: 0 0 0 1 |
------------------------------------------ |
A: 0 0 3 4 |
B: 0 0 1 2 |
C: 0 0 0 0 |
------------------------------------------ |
A: 0 0 0 4 |
B: 0 0 1 2 |
C: 0 0 0 3 |
------------------------------------------ |
A: 0 0 1 4 |
B: 0 0 0 2 |
C: 0 0 0 3 |
------------------------------------------ |
A: 0 0 1 4 |
B: 0 0 0 0 |
C: 0 0 2 3 |
------------------------------------------ |
A: 0 0 0 4 |
B: 0 0 0 0 |
C: 0 1 2 3 |
------------------------------------------ |
A: 0 0 0 0 |
B: 0 0 0 4 |
C: 0 1 2 3 |
------------------------------------------ |
A: 0 0 0 0 |
B: 0 0 1 4 |
C: 0 0 2 3 |
------------------------------------------ |
A: 0 0 0 2 |
B: 0 0 1 4 |
C: 0 0 0 3 |
------------------------------------------ |
A: 0 0 1 2 |
B: 0 0 0 4 |
C: 0 0 0 3 |
------------------------------------------ |
A: 0 0 1 2 |
B: 0 0 3 4 |
C: 0 0 0 0 |
------------------------------------------ |
A: 0 0 0 2 |
B: 0 0 3 4 |
C: 0 0 0 1 |
------------------------------------------ |
A: 0 0 0 0 |
B: 0 2 3 4 |
C: 0 0 0 1 |
------------------------------------------ |
A: 0 0 0 0 |
B: 1 2 3 4 |
C: 0 0 0 0 |
------------------------------------------ |
/programs/develop/ktcc/trunk/source/tests/tests2/31_args.c |
---|
0,0 → 1,14 |
#include <stdio.h> |
int main(int argc, char **argv) |
{ |
int Count; |
printf("hello world %d\n", argc); |
for (Count = 1; Count < argc; Count++) |
printf("arg %d: %s\n", Count, argv[Count]); |
return 0; |
} |
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ |
/programs/develop/ktcc/trunk/source/tests/tests2/31_args.expect |
---|
0,0 → 1,6 |
hello world 6 |
arg 1: arg1 |
arg 2: arg2 |
arg 3: arg3 |
arg 4: arg4 |
arg 5: arg5 |
/programs/develop/ktcc/trunk/source/tests/tests2/32_led.c |
---|
0,0 → 1,266 |
/* example from http://barnyard.syr.edu/quickies/led.c */ |
/* led.c: print out number as if on 7 line led display. I.e., write integer |
given on command line like this: |
_ _ _ |
| _| _| |_| |_ |
| |_ _| | _| etc. |
We assume the terminal behaves like a classical teletype. So the top |
lines of all digits have to be printed first, then the middle lines of |
all digits, etc. |
By Terry R. McConnell |
compile: cc -o led led.c |
If you just want to link in the subroutine print_led that does all the |
work, compile with -DNO_MAIN, and declare the following in any source file |
that uses the call: |
extern void print_led(unsigned long x, char *buf); |
Bug: you cannot call repeatedly to print more than one number to a line. |
That would require curses or some other terminal API that allows moving the |
cursor to a previous line. |
*/ |
#include <stdlib.h> |
#include <stdio.h> |
#define MAX_DIGITS 32 |
#define NO_MAIN |
/* Print the top line of the digit d into buffer. |
Does not null terminate buffer. */ |
void topline(int d, char *p){ |
*p++ = ' '; |
switch(d){ |
/* all these have _ on top line */ |
case 0: |
case 2: |
case 3: |
case 5: |
case 7: |
case 8: |
case 9: |
*p++ = '_'; |
break; |
default: |
*p++=' '; |
} |
*p++=' '; |
} |
/* Print the middle line of the digit d into the buffer. |
Does not null terminate. */ |
void midline(int d, char *p){ |
switch(d){ |
/* those that have leading | on middle line */ |
case 0: |
case 4: |
case 5: |
case 6: |
case 8: |
case 9: |
*p++='|'; |
break; |
default: |
*p++=' '; |
} |
switch(d){ |
/* those that have _ on middle line */ |
case 2: |
case 3: |
case 4: |
case 5: |
case 6: |
case 8: |
case 9: |
*p++='_'; |
break; |
default: |
*p++=' '; |
} |
switch(d){ |
/* those that have closing | on middle line */ |
case 0: |
case 1: |
case 2: |
case 3: |
case 4: |
case 7: |
case 8: |
case 9: |
*p++='|'; |
break; |
default: |
*p++=' '; |
} |
} |
/* Print the bottom line of the digit d. Does not null terminate. */ |
void botline(int d, char *p){ |
switch(d){ |
/* those that have leading | on bottom line */ |
case 0: |
case 2: |
case 6: |
case 8: |
*p++='|'; |
break; |
default: |
*p++=' '; |
} |
switch(d){ |
/* those that have _ on bottom line */ |
case 0: |
case 2: |
case 3: |
case 5: |
case 6: |
case 8: |
*p++='_'; |
break; |
default: |
*p++=' '; |
} |
switch(d){ |
/* those that have closing | on bottom line */ |
case 0: |
case 1: |
case 3: |
case 4: |
case 5: |
case 6: |
case 7: |
case 8: |
case 9: |
*p++='|'; |
break; |
default: |
*p++=' '; |
} |
} |
/* Write the led representation of integer to string buffer. */ |
void print_led(unsigned long x, char *buf) |
{ |
int i=0,n; |
static int d[MAX_DIGITS]; |
/* extract digits from x */ |
n = ( x == 0L ? 1 : 0 ); /* 0 is a digit, hence a special case */ |
while(x){ |
d[n++] = (int)(x%10L); |
if(n >= MAX_DIGITS)break; |
x = x/10L; |
} |
/* print top lines of all digits */ |
for(i=n-1;i>=0;i--){ |
topline(d[i],buf); |
buf += 3; |
*buf++=' '; |
} |
*buf++='\n'; /* move teletype to next line */ |
/* print middle lines of all digits */ |
for(i=n-1;i>=0;i--){ |
midline(d[i],buf); |
buf += 3; |
*buf++=' '; |
} |
*buf++='\n'; |
/* print bottom lines of all digits */ |
for(i=n-1;i>=0;i--){ |
botline(d[i],buf); |
buf += 3; |
*buf++=' '; |
} |
*buf++='\n'; |
*buf='\0'; |
} |
int main() |
{ |
char buf[5*MAX_DIGITS]; |
print_led(1234567, buf); |
printf("%s\n",buf); |
return 0; |
} |
#ifndef NO_MAIN |
int main(int argc, char **argv) |
{ |
int i=0,n; |
long x; |
static int d[MAX_DIGITS]; |
char buf[5*MAX_DIGITS]; |
if(argc != 2){ |
fprintf(stderr,"led: usage: led integer\n"); |
return 1; |
} |
/* fetch argument from command line */ |
x = atol(argv[1]); |
/* sanity check */ |
if(x<0){ |
fprintf(stderr,"led: %d must be non-negative\n",x); |
return 1; |
} |
print_led(x,buf); |
printf("%s\n",buf); |
return 0; |
} |
#endif |
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ |
/programs/develop/ktcc/trunk/source/tests/tests2/32_led.expect |
---|
0,0 → 1,4 |
_ _ _ _ |
| _| _| |_| |_ |_ | |
| |_ _| | _| |_| | |
/programs/develop/ktcc/trunk/source/tests/tests2/33_ternary_op.c |
---|
0,0 → 1,15 |
#include <stdio.h> |
int main() |
{ |
int Count; |
for (Count = 0; Count < 10; Count++) |
{ |
printf("%d\n", (Count < 5) ? (Count*Count) : (Count * 3)); |
} |
return 0; |
} |
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ |
/programs/develop/ktcc/trunk/source/tests/tests2/33_ternary_op.expect |
---|
0,0 → 1,10 |
1 |
4 |
9 |
16 |
15 |
18 |
21 |
24 |
27 |
/programs/develop/ktcc/trunk/source/tests/tests2/34_array_assignment.c |
---|
0,0 → 1,23 |
#include <stdio.h> |
int main() |
{ |
int a[4]; |
a[0] = 12; |
a[1] = 23; |
a[2] = 34; |
a[3] = 45; |
printf("%d %d %d %d\n", a[0], a[1], a[2], a[3]); |
int b[4]; |
b = a; |
printf("%d %d %d %d\n", b[0], b[1], b[2], b[3]); |
return 0; |
} |
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ |
/programs/develop/ktcc/trunk/source/tests/tests2/34_array_assignment.expect |
---|
0,0 → 1,2 |
12 23 34 45 |
12 23 34 45 |
/programs/develop/ktcc/trunk/source/tests/tests2/35_sizeof.c |
---|
0,0 → 1,14 |
#include <stdio.h> |
int main() |
{ |
char a; |
short b; |
printf("%d %d\n", sizeof(char), sizeof(a)); |
printf("%d %d\n", sizeof(short), sizeof(b)); |
return 0; |
} |
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ |
/programs/develop/ktcc/trunk/source/tests/tests2/35_sizeof.expect |
---|
0,0 → 1,2 |
1 1 |
2 2 |
/programs/develop/ktcc/trunk/source/tests/tests2/36_array_initialisers.c |
---|
0,0 → 1,21 |
#include <stdio.h> |
int main() |
{ |
int Count; |
int Array[10] = { 12, 34, 56, 78, 90, 123, 456, 789, 8642, 9753 }; |
for (Count = 0; Count < 10; Count++) |
printf("%d: %d\n", Count, Array[Count]); |
int Array2[10] = { 12, 34, 56, 78, 90, 123, 456, 789, 8642, 9753, }; |
for (Count = 0; Count < 10; Count++) |
printf("%d: %d\n", Count, Array2[Count]); |
return 0; |
} |
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ |
/programs/develop/ktcc/trunk/source/tests/tests2/36_array_initialisers.expect |
---|
0,0 → 1,20 |
0: 12 |
1: 34 |
2: 56 |
3: 78 |
4: 90 |
5: 123 |
6: 456 |
7: 789 |
8: 8642 |
9: 9753 |
0: 12 |
1: 34 |
2: 56 |
3: 78 |
4: 90 |
5: 123 |
6: 456 |
7: 789 |
8: 8642 |
9: 9753 |
/programs/develop/ktcc/trunk/source/tests/tests2/37_sprintf.c |
---|
0,0 → 1,17 |
#include <stdio.h> |
int main() |
{ |
char Buf[100]; |
int Count; |
for (Count = 1; Count <= 20; Count++) |
{ |
sprintf(Buf, "->%02d<-\n", Count); |
printf("%s", Buf); |
} |
return 0; |
} |
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ |
/programs/develop/ktcc/trunk/source/tests/tests2/37_sprintf.expect |
---|
0,0 → 1,20 |
->01<- |
->02<- |
->03<- |
->04<- |
->05<- |
->06<- |
->07<- |
->08<- |
->09<- |
->10<- |
->11<- |
->12<- |
->13<- |
->14<- |
->15<- |
->16<- |
->17<- |
->18<- |
->19<- |
->20<- |
/programs/develop/ktcc/trunk/source/tests/tests2/38_multiple_array_index.c |
---|
0,0 → 1,32 |
#include <stdio.h> |
int main() |
{ |
int a[4][4]; |
int b = 0; |
int x; |
int y; |
for (x = 0; x < 4; x++) |
{ |
for (y = 0; y < 4; y++) |
{ |
b++; |
a[x][y] = b; |
} |
} |
for (x = 0; x < 4; x++) |
{ |
printf("x=%d: ", x); |
for (y = 0; y < 4; y++) |
{ |
printf("%d ", a[x][y]); |
} |
printf("\n"); |
} |
return 0; |
} |
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ |
/programs/develop/ktcc/trunk/source/tests/tests2/38_multiple_array_index.expect |
---|
0,0 → 1,4 |
x=0: 1 2 3 4 |
x=1: 5 6 7 8 |
x=2: 9 10 11 12 |
x=3: 13 14 15 16 |
/programs/develop/ktcc/trunk/source/tests/tests2/39_typedef.c |
---|
0,0 → 1,47 |
#include <stdio.h> |
typedef int MyInt; |
struct FunStruct |
{ |
int i; |
int j; |
}; |
typedef struct FunStruct MyFunStruct; |
typedef MyFunStruct *MoreFunThanEver; |
int main() |
{ |
MyInt a = 1; |
printf("%d\n", a); |
MyFunStruct b; |
b.i = 12; |
b.j = 34; |
printf("%d,%d\n", b.i, b.j); |
MoreFunThanEver c = &b; |
printf("%d,%d\n", c->i, c->j); |
return 0; |
} |
/* "If the specification of an array type includes any type qualifiers, |
the element type is so-qualified, not the array type." */ |
typedef int A[3]; |
extern A const ca; |
extern const A ca; |
extern const int ca[3]; |
typedef A B[1][2]; |
extern B const cb; |
extern const B cb; |
extern const int cb[1][2][3]; |
extern B b; |
extern int b[1][2][3]; |
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ |
/programs/develop/ktcc/trunk/source/tests/tests2/39_typedef.expect |
---|
0,0 → 1,3 |
1 |
12,34 |
12,34 |
/programs/develop/ktcc/trunk/source/tests/tests2/40_stdio.c |
---|
0,0 → 1,52 |
#include <stdio.h> |
int main() |
{ |
FILE *f = fopen("fred.txt", "w"); |
fwrite("hello\nhello\n", 1, 12, f); |
fclose(f); |
char freddy[7]; |
f = fopen("fred.txt", "r"); |
if (fread(freddy, 1, 6, f) != 6) |
printf("couldn't read fred.txt\n"); |
freddy[6] = '\0'; |
fclose(f); |
printf("%s", freddy); |
int InChar; |
char ShowChar; |
f = fopen("fred.txt", "r"); |
while ( (InChar = fgetc(f)) != EOF) |
{ |
ShowChar = InChar; |
if (ShowChar < ' ') |
ShowChar = '.'; |
printf("ch: %d '%c'\n", InChar, ShowChar); |
} |
fclose(f); |
f = fopen("fred.txt", "r"); |
while ( (InChar = getc(f)) != EOF) |
{ |
ShowChar = InChar; |
if (ShowChar < ' ') |
ShowChar = '.'; |
printf("ch: %d '%c'\n", InChar, ShowChar); |
} |
fclose(f); |
f = fopen("fred.txt", "r"); |
while (fgets(freddy, sizeof(freddy), f) != NULL) |
printf("x: %s", freddy); |
fclose(f); |
return 0; |
} |
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ |
/programs/develop/ktcc/trunk/source/tests/tests2/40_stdio.expect |
---|
0,0 → 1,27 |
hello |
ch: 104 'h' |
ch: 101 'e' |
ch: 108 'l' |
ch: 108 'l' |
ch: 111 'o' |
ch: 10 '.' |
ch: 104 'h' |
ch: 101 'e' |
ch: 108 'l' |
ch: 108 'l' |
ch: 111 'o' |
ch: 10 '.' |
ch: 104 'h' |
ch: 101 'e' |
ch: 108 'l' |
ch: 108 'l' |
ch: 111 'o' |
ch: 10 '.' |
ch: 104 'h' |
ch: 101 'e' |
ch: 108 'l' |
ch: 108 'l' |
ch: 111 'o' |
ch: 10 '.' |
x: hello |
x: hello |
/programs/develop/ktcc/trunk/source/tests/tests2/41_hashif.c |
---|
0,0 → 1,85 |
#include <stdio.h> |
int main() |
{ |
printf("#include test\n"); |
#if 1 |
#if 0 |
printf("a\n"); |
#else |
printf("b\n"); |
#endif |
#else |
#if 0 |
printf("c\n"); |
#else |
printf("d\n"); |
#endif |
#endif |
#if 0 |
#if 1 |
printf("e\n"); |
#else |
printf("f\n"); |
#endif |
#else |
#if 1 |
printf("g\n"); |
#else |
printf("h\n"); |
#endif |
#endif |
#define DEF |
#ifdef DEF |
#ifdef DEF |
printf("i\n"); |
#else |
printf("j\n"); |
#endif |
#else |
#ifdef DEF |
printf("k\n"); |
#else |
printf("l\n"); |
#endif |
#endif |
#ifndef DEF |
#ifndef DEF |
printf("m\n"); |
#else |
printf("n\n"); |
#endif |
#else |
#ifndef DEF |
printf("o\n"); |
#else |
printf("p\n"); |
#endif |
#endif |
#define ONE 1 |
#define ZERO 0 |
#if ONE |
#if ZERO |
printf("q\n"); |
#else |
printf("r\n"); |
#endif |
#else |
#if ZERO |
printf("s\n"); |
#else |
printf("t\n"); |
#endif |
#endif |
return 0; |
} |
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ |
/programs/develop/ktcc/trunk/source/tests/tests2/41_hashif.expect |
---|
0,0 → 1,6 |
#include test |
b |
g |
i |
p |
r |
/programs/develop/ktcc/trunk/source/tests/tests2/42_function_pointer.c |
---|
0,0 → 1,18 |
#include <stdio.h> |
int fred(int p) |
{ |
printf("yo %d\n", p); |
return 42; |
} |
int (*f)(int) = &fred; |
int main() |
{ |
printf("%d\n", (*f)(24)); |
return 0; |
} |
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ |
/programs/develop/ktcc/trunk/source/tests/tests2/42_function_pointer.expect |
---|
0,0 → 1,2 |
yo 24 |
42 |
/programs/develop/ktcc/trunk/source/tests/tests2/43_void_param.c |
---|
0,0 → 1,15 |
#include <stdio.h> |
void fred(void) |
{ |
printf("yo\n"); |
} |
int main() |
{ |
fred(); |
return 0; |
} |
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ |
/programs/develop/ktcc/trunk/source/tests/tests2/43_void_param.expect |
---|
0,0 → 1,0 |
yo |
/programs/develop/ktcc/trunk/source/tests/tests2/44_scoped_declarations.c |
---|
0,0 → 1,17 |
#include <stdio.h> |
int main() |
{ |
int a; |
for (a = 0; a < 2; a++) |
{ |
int b = a; |
} |
printf("it's all good\n"); |
return 0; |
} |
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ |
/programs/develop/ktcc/trunk/source/tests/tests2/44_scoped_declarations.expect |
---|
0,0 → 1,0 |
it's all good |
/programs/develop/ktcc/trunk/source/tests/tests2/45_empty_for.c |
---|
0,0 → 1,18 |
#include <stdio.h> |
int main() |
{ |
int Count = 0; |
for (;;) |
{ |
Count++; |
printf("%d\n", Count); |
if (Count >= 10) |
break; |
} |
return 0; |
} |
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ |
/programs/develop/ktcc/trunk/source/tests/tests2/45_empty_for.expect |
---|
0,0 → 1,10 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
/programs/develop/ktcc/trunk/source/tests/tests2/46_grep.c |
---|
0,0 → 1,569 |
/* |
* The information in this document is subject to change |
* without notice and should not be construed as a commitment |
* by Digital Equipment Corporation or by DECUS. |
* |
* Neither Digital Equipment Corporation, DECUS, nor the authors |
* assume any responsibility for the use or reliability of this |
* document or the described software. |
* |
* Copyright (C) 1980, DECUS |
* |
* General permission to copy or modify, but not for profit, is |
* hereby granted, provided that the above copyright notice is |
* included and reference made to the fact that reproduction |
* privileges were granted by DECUS. |
*/ |
#include <stdio.h> |
#include <stdlib.h> |
#include <ctype.h> // tolower() |
/* |
* grep |
* |
* Runs on the Decus compiler or on vms, On vms, define as: |
* grep :== "$disk:[account]grep" (native) |
* grep :== "$disk:[account]grep grep" (Decus) |
* See below for more information. |
*/ |
char *documentation[] = { |
"grep searches a file for a given pattern. Execute by", |
" grep [flags] regular_expression file_list\n", |
"Flags are single characters preceded by '-':", |
" -c Only a count of matching lines is printed", |
" -f Print file name for matching lines switch, see below", |
" -n Each line is preceded by its line number", |
" -v Only print non-matching lines\n", |
"The file_list is a list of files (wildcards are acceptable on RSX modes).", |
"\nThe file name is normally printed if there is a file given.", |
"The -f flag reverses this action (print name no file, not if more).\n", |
0 }; |
char *patdoc[] = { |
"The regular_expression defines the pattern to search for. Upper- and", |
"lower-case are always ignored. Blank lines never match. The expression", |
"should be quoted to prevent file-name translation.", |
"x An ordinary character (not mentioned below) matches that character.", |
"'\\' The backslash quotes any character. \"\\$\" matches a dollar-sign.", |
"'^' A circumflex at the beginning of an expression matches the", |
" beginning of a line.", |
"'$' A dollar-sign at the end of an expression matches the end of a line.", |
"'.' A period matches any character except \"new-line\".", |
"':a' A colon matches a class of characters described by the following", |
"':d' character. \":a\" matches any alphabetic, \":d\" matches digits,", |
"':n' \":n\" matches alphanumerics, \": \" matches spaces, tabs, and", |
"': ' other control characters, such as new-line.", |
"'*' An expression followed by an asterisk matches zero or more", |
" occurrences of that expression: \"fo*\" matches \"f\", \"fo\"", |
" \"foo\", etc.", |
"'+' An expression followed by a plus sign matches one or more", |
" occurrences of that expression: \"fo+\" matches \"fo\", etc.", |
"'-' An expression followed by a minus sign optionally matches", |
" the expression.", |
"'[]' A string enclosed in square brackets matches any character in", |
" that string, but no others. If the first character in the", |
" string is a circumflex, the expression matches any character", |
" except \"new-line\" and the characters in the string. For", |
" example, \"[xyz]\" matches \"xx\" and \"zyx\", while \"[^xyz]\"", |
" matches \"abc\" but not \"axb\". A range of characters may be", |
" specified by two characters separated by \"-\". Note that,", |
" [a-z] matches alphabetics, while [z-a] never matches.", |
"The concatenation of regular expressions is a regular expression.", |
0}; |
#define LMAX 512 |
#define PMAX 256 |
#define CHAR 1 |
#define BOL 2 |
#define EOL 3 |
#define ANY 4 |
#define CLASS 5 |
#define NCLASS 6 |
#define STAR 7 |
#define PLUS 8 |
#define MINUS 9 |
#define ALPHA 10 |
#define DIGIT 11 |
#define NALPHA 12 |
#define PUNCT 13 |
#define RANGE 14 |
#define ENDPAT 15 |
int cflag=0, fflag=0, nflag=0, vflag=0, nfile=0, debug=0; |
char *pp, lbuf[LMAX], pbuf[PMAX]; |
char *cclass(); |
char *pmatch(); |
void store(int); |
void error(char *); |
void badpat(char *, char *, char *); |
int match(void); |
/*** Display a file name *******************************/ |
void file(char *s) |
{ |
printf("File %s:\n", s); |
} |
/*** Report unopenable file ****************************/ |
void cant(char *s) |
{ |
fprintf(stderr, "%s: cannot open\n", s); |
} |
/*** Give good help ************************************/ |
void help(char **hp) |
{ |
char **dp; |
for (dp = hp; *dp; ++dp) |
printf("%s\n", *dp); |
} |
/*** Display usage summary *****************************/ |
void usage(char *s) |
{ |
fprintf(stderr, "?GREP-E-%s\n", s); |
fprintf(stderr, |
"Usage: grep [-cfnv] pattern [file ...]. grep ? for help\n"); |
exit(1); |
} |
/*** Compile the pattern into global pbuf[] ************/ |
void compile(char *source) |
{ |
char *s; /* Source string pointer */ |
char *lp; /* Last pattern pointer */ |
int c; /* Current character */ |
int o; /* Temp */ |
char *spp; /* Save beginning of pattern */ |
s = source; |
if (debug) |
printf("Pattern = \"%s\"\n", s); |
pp = pbuf; |
while (c = *s++) { |
/* |
* STAR, PLUS and MINUS are special. |
*/ |
if (c == '*' || c == '+' || c == '-') { |
if (pp == pbuf || |
(o=pp[-1]) == BOL || |
o == EOL || |
o == STAR || |
o == PLUS || |
o == MINUS) |
badpat("Illegal occurrence op.", source, s); |
store(ENDPAT); |
store(ENDPAT); |
spp = pp; /* Save pattern end */ |
while (--pp > lp) /* Move pattern down */ |
*pp = pp[-1]; /* one byte */ |
*pp = (c == '*') ? STAR : |
(c == '-') ? MINUS : PLUS; |
pp = spp; /* Restore pattern end */ |
continue; |
} |
/* |
* All the rest. |
*/ |
lp = pp; /* Remember start */ |
switch(c) { |
case '^': |
store(BOL); |
break; |
case '$': |
store(EOL); |
break; |
case '.': |
store(ANY); |
break; |
case '[': |
s = cclass(source, s); |
break; |
case ':': |
if (*s) { |
switch(tolower(c = *s++)) { |
case 'a': |
case 'A': |
store(ALPHA); |
break; |
case 'd': |
case 'D': |
store(DIGIT); |
break; |
case 'n': |
case 'N': |
store(NALPHA); |
break; |
case ' ': |
store(PUNCT); |
break; |
default: |
badpat("Unknown : type", source, s); |
} |
break; |
} |
else badpat("No : type", source, s); |
case '\\': |
if (*s) |
c = *s++; |
default: |
store(CHAR); |
store(tolower(c)); |
} |
} |
store(ENDPAT); |
store(0); /* Terminate string */ |
if (debug) { |
for (lp = pbuf; lp < pp;) { |
if ((c = (*lp++ & 0377)) < ' ') |
printf("\\%o ", c); |
else printf("%c ", c); |
} |
printf("\n"); |
} |
} |
/*** Compile a class (within []) ***********************/ |
char *cclass(char *source, char *src) |
/* char *source; // Pattern start -- for error msg. */ |
/* char *src; // Class start */ |
{ |
char *s; /* Source pointer */ |
char *cp; /* Pattern start */ |
int c; /* Current character */ |
int o; /* Temp */ |
s = src; |
o = CLASS; |
if (*s == '^') { |
++s; |
o = NCLASS; |
} |
store(o); |
cp = pp; |
store(0); /* Byte count */ |
while ((c = *s++) && c!=']') { |
if (c == '\\') { /* Store quoted char */ |
if ((c = *s++) == '\0') /* Gotta get something */ |
badpat("Class terminates badly", source, s); |
else store(tolower(c)); |
} |
else if (c == '-' && |
(pp - cp) > 1 && *s != ']' && *s != '\0') { |
c = pp[-1]; /* Range start */ |
pp[-1] = RANGE; /* Range signal */ |
store(c); /* Re-store start */ |
c = *s++; /* Get end char and*/ |
store(tolower(c)); /* Store it */ |
} |
else { |
store(tolower(c)); /* Store normal char */ |
} |
} |
if (c != ']') |
badpat("Unterminated class", source, s); |
if ((c = (pp - cp)) >= 256) |
badpat("Class too large", source, s); |
if (c == 0) |
badpat("Empty class", source, s); |
*cp = c; |
return(s); |
} |
/*** Store an entry in the pattern buffer **************/ |
void store(int op) |
{ |
if (pp >= &pbuf[PMAX]) |
error("Pattern too complex\n"); |
*pp++ = op; |
} |
/*** Report a bad pattern specification ****************/ |
void badpat(char *message, char *source, char *stop) |
/* char *message; // Error message */ |
/* char *source; // Pattern start */ |
/* char *stop; // Pattern end */ |
{ |
fprintf(stderr, "-GREP-E-%s, pattern is\"%s\"\n", message, source); |
fprintf(stderr, "-GREP-E-Stopped at byte %ld, '%c'\n", |
stop-source, stop[-1]); |
error("?GREP-E-Bad pattern\n"); |
} |
/*** Scan the file for the pattern in pbuf[] ***********/ |
void grep(FILE *fp, char *fn) |
/* FILE *fp; // File to process */ |
/* char *fn; // File name (for -f option) */ |
{ |
int lno, count, m; |
lno = 0; |
count = 0; |
while (fgets(lbuf, LMAX, fp)) { |
++lno; |
m = match(); |
if ((m && !vflag) || (!m && vflag)) { |
++count; |
if (!cflag) { |
if (fflag && fn) { |
file(fn); |
fn = 0; |
} |
if (nflag) |
printf("%d\t", lno); |
printf("%s\n", lbuf); |
} |
} |
} |
if (cflag) { |
if (fflag && fn) |
file(fn); |
printf("%d\n", count); |
} |
} |
/*** Match line (lbuf) with pattern (pbuf) return 1 if match ***/ |
int match() |
{ |
char *l; /* Line pointer */ |
for (l = lbuf; *l; ++l) { |
if (pmatch(l, pbuf)) |
return(1); |
} |
return(0); |
} |
/*** Match partial line with pattern *******************/ |
char *pmatch(char *line, char *pattern) |
/* char *line; // (partial) line to match */ |
/* char *pattern; // (partial) pattern to match */ |
{ |
char *l; /* Current line pointer */ |
char *p; /* Current pattern pointer */ |
char c; /* Current character */ |
char *e; /* End for STAR and PLUS match */ |
int op; /* Pattern operation */ |
int n; /* Class counter */ |
char *are; /* Start of STAR match */ |
l = line; |
if (debug > 1) |
printf("pmatch(\"%s\")\n", line); |
p = pattern; |
while ((op = *p++) != ENDPAT) { |
if (debug > 1) |
printf("byte[%ld] = 0%o, '%c', op = 0%o\n", |
l-line, *l, *l, op); |
switch(op) { |
case CHAR: |
if (tolower(*l++) != *p++) |
return(0); |
break; |
case BOL: |
if (l != lbuf) |
return(0); |
break; |
case EOL: |
if (*l != '\0') |
return(0); |
break; |
case ANY: |
if (*l++ == '\0') |
return(0); |
break; |
case DIGIT: |
if ((c = *l++) < '0' || (c > '9')) |
return(0); |
break; |
case ALPHA: |
c = tolower(*l++); |
if (c < 'a' || c > 'z') |
return(0); |
break; |
case NALPHA: |
c = tolower(*l++); |
if (c >= 'a' && c <= 'z') |
break; |
else if (c < '0' || c > '9') |
return(0); |
break; |
case PUNCT: |
c = *l++; |
if (c == 0 || c > ' ') |
return(0); |
break; |
case CLASS: |
case NCLASS: |
c = tolower(*l++); |
n = *p++ & 0377; |
do { |
if (*p == RANGE) { |
p += 3; |
n -= 2; |
if (c >= p[-2] && c <= p[-1]) |
break; |
} |
else if (c == *p++) |
break; |
} while (--n > 1); |
if ((op == CLASS) == (n <= 1)) |
return(0); |
if (op == CLASS) |
p += n - 2; |
break; |
case MINUS: |
e = pmatch(l, p); /* Look for a match */ |
while (*p++ != ENDPAT); /* Skip over pattern */ |
if (e) /* Got a match? */ |
l = e; /* Yes, update string */ |
break; /* Always succeeds */ |
case PLUS: /* One or more ... */ |
if ((l = pmatch(l, p)) == 0) |
return(0); /* Gotta have a match */ |
case STAR: /* Zero or more ... */ |
are = l; /* Remember line start */ |
while (*l && (e = pmatch(l, p))) |
l = e; /* Get longest match */ |
while (*p++ != ENDPAT); /* Skip over pattern */ |
while (l >= are) { /* Try to match rest */ |
if (e = pmatch(l, p)) |
return(e); |
--l; /* Nope, try earlier */ |
} |
return(0); /* Nothing else worked */ |
default: |
printf("Bad op code %d\n", op); |
error("Cannot happen -- match\n"); |
} |
} |
return(l); |
} |
/*** Report an error ***********************************/ |
void error(char *s) |
{ |
fprintf(stderr, "%s", s); |
exit(1); |
} |
/*** Main program - parse arguments & grep *************/ |
int main(int argc, char **argv) |
{ |
char *p; |
int c, i; |
int gotpattern; |
FILE *f; |
if (argc <= 1) |
usage("No arguments"); |
if (argc == 2 && argv[1][0] == '?' && argv[1][1] == 0) { |
help(documentation); |
help(patdoc); |
return 0; |
} |
nfile = argc-1; |
gotpattern = 0; |
for (i=1; i < argc; ++i) { |
p = argv[i]; |
if (*p == '-') { |
++p; |
while (c = *p++) { |
switch(tolower(c)) { |
case '?': |
help(documentation); |
break; |
case 'C': |
case 'c': |
++cflag; |
break; |
case 'D': |
case 'd': |
++debug; |
break; |
case 'F': |
case 'f': |
++fflag; |
break; |
case 'n': |
case 'N': |
++nflag; |
break; |
case 'v': |
case 'V': |
++vflag; |
break; |
default: |
usage("Unknown flag"); |
} |
} |
argv[i] = 0; |
--nfile; |
} else if (!gotpattern) { |
compile(p); |
argv[i] = 0; |
++gotpattern; |
--nfile; |
} |
} |
if (!gotpattern) |
usage("No pattern"); |
if (nfile == 0) |
// grep(stdin, 0); |
; |
else { |
fflag = fflag ^ (nfile > 0); |
for (i=1; i < argc; ++i) { |
if (p = argv[i]) { |
if ((f=fopen(p, "r")) == NULL) |
cant(p); |
else { |
grep(f, p); |
fclose(f); |
} |
} |
} |
} |
return 0; |
} |
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ |
/programs/develop/ktcc/trunk/source/tests/tests2/46_grep.expect |
---|
0,0 → 1,3 |
File 46_grep.c: |
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ |
/programs/develop/ktcc/trunk/source/tests/tests2/47_switch_return.c |
---|
0,0 → 1,24 |
#include <stdio.h> |
void fred(int x) |
{ |
switch (x) |
{ |
case 1: printf("1\n"); return; |
case 2: printf("2\n"); break; |
case 3: printf("3\n"); return; |
} |
printf("out\n"); |
} |
int main() |
{ |
fred(1); |
fred(2); |
fred(3); |
return 0; |
} |
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ |
/programs/develop/ktcc/trunk/source/tests/tests2/47_switch_return.expect |
---|
0,0 → 1,4 |
1 |
2 |
out |
3 |
/programs/develop/ktcc/trunk/source/tests/tests2/48_nested_break.c |
---|
0,0 → 1,26 |
#include <stdio.h> |
int main() |
{ |
int a; |
char b; |
a = 0; |
while (a < 2) |
{ |
printf("%d", a++); |
break; |
b = 'A'; |
while (b < 'C') |
{ |
printf("%c", b++); |
} |
printf("e"); |
} |
printf("\n"); |
return 0; |
} |
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ |
/programs/develop/ktcc/trunk/source/tests/tests2/48_nested_break.expect |
---|
0,0 → 1,0 |
/programs/develop/ktcc/trunk/source/tests/tests2/49_bracket_evaluation.c |
---|
0,0 → 1,23 |
#include <stdio.h> |
struct point |
{ |
double x; |
double y; |
}; |
struct point point_array[100]; |
int main() |
{ |
int my_point = 10; |
point_array[my_point].x = 12.34; |
point_array[my_point].y = 56.78; |
printf("%f, %f\n", point_array[my_point].x, point_array[my_point].y); |
return 0; |
} |
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ |
/programs/develop/ktcc/trunk/source/tests/tests2/49_bracket_evaluation.expect |
---|
0,0 → 1,0 |
12.340000, 56.780000 |
/programs/develop/ktcc/trunk/source/tests/tests2/50_logical_second_arg.c |
---|
0,0 → 1,29 |
#include <stdio.h> |
int fred() |
{ |
printf("fred\n"); |
return 0; |
} |
int joe() |
{ |
printf("joe\n"); |
return 1; |
} |
int main() |
{ |
printf("%d\n", fred() && joe()); |
printf("%d\n", fred() || joe()); |
printf("%d\n", joe() && fred()); |
printf("%d\n", joe() || fred()); |
printf("%d\n", fred() && (1 + joe())); |
printf("%d\n", fred() || (0 + joe())); |
printf("%d\n", joe() && (0 + fred())); |
printf("%d\n", joe() || (1 + fred())); |
return 0; |
} |
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ |
/programs/develop/ktcc/trunk/source/tests/tests2/50_logical_second_arg.expect |
---|
0,0 → 1,20 |
fred |
fred |
joe |
1 |
joe |
fred |
joe |
1 |
fred |
fred |
joe |
1 |
joe |
fred |
joe |
1 |
/programs/develop/ktcc/trunk/source/tests/tests2/51_static.c |
---|
0,0 → 1,30 |
#include <stdio.h> |
static int fred = 1234; |
static int joe; |
void henry() |
{ |
static int fred = 4567; |
printf("%d\n", fred); |
fred++; |
} |
int main() |
{ |
printf("%d\n", fred); |
henry(); |
henry(); |
henry(); |
henry(); |
printf("%d\n", fred); |
fred = 8901; |
joe = 2345; |
printf("%d\n", fred); |
printf("%d\n", joe); |
return 0; |
} |
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ |
/programs/develop/ktcc/trunk/source/tests/tests2/51_static.expect |
---|
0,0 → 1,8 |
1234 |
4567 |
4568 |
4569 |
4570 |
1234 |
8901 |
2345 |
/programs/develop/ktcc/trunk/source/tests/tests2/52_unnamed_enum.c |
---|
0,0 → 1,27 |
#include <stdio.h> |
enum fred { a, b, c }; |
int main() |
{ |
printf("a=%d\n", a); |
printf("b=%d\n", b); |
printf("c=%d\n", c); |
enum fred d; |
typedef enum { e, f, g } h; |
typedef enum { i, j, k } m; |
printf("e=%d\n", e); |
printf("f=%d\n", f); |
printf("g=%d\n", g); |
printf("i=%d\n", i); |
printf("j=%d\n", j); |
printf("k=%d\n", k); |
return 0; |
} |
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ |
/programs/develop/ktcc/trunk/source/tests/tests2/52_unnamed_enum.expect |
---|
0,0 → 1,9 |
a=0 |
b=1 |
c=2 |
e=0 |
f=1 |
g=2 |
i=0 |
j=1 |
k=2 |
/programs/develop/ktcc/trunk/source/tests/tests2/54_goto.c |
---|
0,0 → 1,56 |
#include <stdio.h> |
void fred() |
{ |
printf("In fred()\n"); |
goto done; |
printf("In middle\n"); |
done: |
printf("At end\n"); |
} |
void joe() |
{ |
int b = 5678; |
printf("In joe()\n"); |
{ |
int c = 1234; |
printf("c = %d\n", c); |
goto outer; |
printf("uh-oh\n"); |
} |
outer: |
printf("done\n"); |
} |
void henry() |
{ |
int a; |
printf("In henry()\n"); |
goto inner; |
{ |
int b; |
inner: |
b = 1234; |
printf("b = %d\n", b); |
} |
printf("done\n"); |
} |
int main() |
{ |
fred(); |
joe(); |
henry(); |
return 0; |
} |
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ |
/programs/develop/ktcc/trunk/source/tests/tests2/54_goto.expect |
---|
0,0 → 1,8 |
In fred() |
At end |
In joe() |
c = 1234 |
done |
In henry() |
b = 1234 |
done |
/programs/develop/ktcc/trunk/source/tests/tests2/55_lshift_type.c |
---|
0,0 → 1,52 |
/* $Id: lshift-type.c 53089 2012-07-06 11:18:26Z vinc17/ypig $ |
Tests on left-shift type, written by Vincent Lefevre <vincent@vinc17.net>. |
ISO C99 TC3 says: [6.5.7#3] "The integer promotions are performed on |
each of the operands. The type of the result is that of the promoted |
left operand." |
*/ |
#include <stdio.h> |
#define PTYPE(M) ((M) < 0 || -(M) < 0 ? -1 : 1) * (int) sizeof((M)+0) |
#define CHECK(X,T) check(#X, PTYPE(X), PTYPE((X) << (T) 1)) |
#define TEST1(X,T) do { CHECK(X,T); CHECK(X,unsigned T); } while (0) |
#define TEST2(X) \ |
do \ |
{ \ |
TEST1((X),short); \ |
TEST1((X),int); \ |
TEST1((X),long); \ |
TEST1((X),long long); \ |
} \ |
while (0) |
#define TEST3(X,T) do { TEST2((T)(X)); TEST2((unsigned T)(X)); } while (0) |
#define TEST4(X) \ |
do \ |
{ \ |
TEST3((X),short); \ |
TEST3((X),int); \ |
TEST3((X),long); \ |
TEST3((X),long long); \ |
} \ |
while (0) |
static int debug, nfailed = 0; |
static void check (const char *s, int arg1, int shift) |
{ |
int failed = arg1 != shift; |
if (debug || failed) |
printf ("%s %d %d\n", s, arg1, shift); |
nfailed += failed; |
} |
int main (int argc, char **argv) |
{ |
debug = argc > 1; |
TEST4(1); |
TEST4(-1); |
printf ("%d test(s) failed\n", nfailed); |
return nfailed != 0; |
} |
/programs/develop/ktcc/trunk/source/tests/tests2/55_lshift_type.expect |
---|
0,0 → 1,0 |
0 test(s) failed |
/programs/develop/ktcc/trunk/source/tests/tests2/56_btype_excess-1.c |
---|
0,0 → 1,0 |
struct A {} int i; |
/programs/develop/ktcc/trunk/source/tests/tests2/56_btype_excess-1.expect |
---|
0,0 → 1,0 |
56_btype_excess-1.c:1: error: too many basic types |
/programs/develop/ktcc/trunk/source/tests/tests2/57_btype_excess-2.c |
---|
0,0 → 1,0 |
char int i; |
/programs/develop/ktcc/trunk/source/tests/tests2/57_btype_excess-2.expect |
---|
0,0 → 1,0 |
57_btype_excess-2.c:1: error: too many basic types |
/programs/develop/ktcc/trunk/source/tests/tests2/58_function_redefinition.c |
---|
0,0 → 1,9 |
int f(void) |
{ |
return 0; |
} |
int f(void) |
{ |
return 1; |
} |
/programs/develop/ktcc/trunk/source/tests/tests2/58_function_redefinition.expect |
---|
0,0 → 1,0 |
58_function_redefinition.c:7: error: redefinition of 'f' |
/programs/develop/ktcc/trunk/source/tests/tests2/59_function_array.c |
---|
0,0 → 1,0 |
int (*fct)[42](int x); |
/programs/develop/ktcc/trunk/source/tests/tests2/59_function_array.expect |
---|
0,0 → 1,0 |
59_function_array.c:1: error: declaration of an array of functions |
/programs/develop/ktcc/trunk/source/tests/tests2/60_enum_redefinition.c |
---|
0,0 → 1,4 |
enum color {RED, GREEN, BLUE}; |
enum color {R, G, B}; |
enum color c; |
/programs/develop/ktcc/trunk/source/tests/tests2/60_enum_redefinition.expect |
---|
0,0 → 1,0 |
60_enum_redefinition.c:2: error: struct/union/enum already defined |
/programs/develop/ktcc/trunk/source/tests/tests2/61_undefined_enum.c |
---|
0,0 → 1,0 |
enum rgb c = 42; |
/programs/develop/ktcc/trunk/source/tests/tests2/61_undefined_enum.expect |
---|
0,0 → 1,0 |
61_undefined_enum.c:1: error: unknown type size |
/programs/develop/ktcc/trunk/source/tests/tests2/62_enumerator_redefinition.c |
---|
0,0 → 1,4 |
enum color {RED, GREEN, BLUE}; |
enum rgb {RED, G, B}; |
enum color c = RED; |
/programs/develop/ktcc/trunk/source/tests/tests2/62_enumerator_redefinition.expect |
---|
0,0 → 1,0 |
62_enumerator_redefinition.c:2: error: redefinition of enumerator 'RED' |
/programs/develop/ktcc/trunk/source/tests/tests2/63_local_enumerator_redefinition.c |
---|
0,0 → 1,14 |
enum { |
FOO, |
BAR |
}; |
int main(void) |
{ |
enum { |
FOO = 2, |
BAR |
}; |
return BAR - FOO; |
} |
/programs/develop/ktcc/trunk/source/tests/tests2/63_local_enumerator_redefinition.expect |
---|
--- tests2/64_macro_nesting.c (nonexistent) |
+++ tests2/64_macro_nesting.c (revision 6429) |
@@ -0,0 +1,12 @@ |
+#include <stdio.h> // printf() |
+ |
+#define CAT2(a,b) a##b |
+#define CAT(a,b) CAT2(a,b) |
+#define AB(x) CAT(x,y) |
+ |
+int main(void) |
+{ |
+ int xy = 42; |
+ printf("%d\n", CAT(A,B)(x)); |
+ return 0; |
+} |
/programs/develop/ktcc/trunk/source/tests/tests2/64_macro_nesting.expect |
---|
0,0 → 1,0 |
42 |
/programs/develop/ktcc/trunk/source/tests/tests2/67_macro_concat.c |
---|
0,0 → 1,14 |
#include <stdio.h> |
#define P(A,B) A ## B ; bob |
#define Q(A,B) A ## B+ |
int main(void) |
{ |
int bob, jim = 21; |
bob = P(jim,) *= 2; |
printf("jim: %d, bob: %d\n", jim, bob); |
jim = 60 Q(+,)3; |
printf("jim: %d\n", jim); |
return 0; |
} |
/programs/develop/ktcc/trunk/source/tests/tests2/67_macro_concat.expect |
---|
0,0 → 1,2 |
jim: 21, bob: 42 |
jim: 63 |
/programs/develop/ktcc/trunk/source/tests/tests2/70_floating_point_literals.c |
---|
0,0 → 1,77 |
#include <stdio.h> |
int main() |
{ |
/* decimal floating constant */ |
float fa0 = .123f; |
float fa1 = .123E12F; |
float fa2 = .123e-12f; |
float fa3 = .123e+12f; |
printf("%f\n%f\n%f\n%f\n\n", fa0, fa1, fa2, fa3); |
float fb0 = 123.123f; |
float fb1 = 123.123E12F; |
float fb2 = 123.123e-12f; |
float fb3 = 123.123e+12f; |
printf("%f\n%f\n%f\n%f\n\n", fb0, fb1, fb2, fb3); |
float fc0 = 123.f; |
float fc1 = 123.E12F; |
float fc2 = 123.e-12f; |
float fc3 = 123.e+12f; |
printf("%f\n%f\n%f\n%f\n\n", fc0, fc1, fc2, fc3); |
float fd0 = 123E12F; |
float fd1 = 123e-12f; |
float fd2 = 123e+12f; |
printf("%f\n%f\n%f\n\n", fd0, fd1, fd2); |
printf("\n"); |
/* hexadecimal floating constant */ |
double da0 = 0X.1ACP12; |
double da1 = 0x.1acp-12; |
double da2 = 0x.1acp+12; |
printf("%f\n%f\n%f\n\n", da0, da1, da2); |
double db0 = 0X1AC.BDP12; |
double db1 = 0x1ac.bdp-12; |
double db2 = 0x1ac.dbp+12; |
printf("%f\n%f\n%f\n\n", db0, db1, db2); |
double dc0 = 0X1AC.P12; |
double dc1 = 0x1ac.p-12; |
double dc2 = 0x1ac.p+12; |
printf("%f\n%f\n%f\n\n", dc0, dc1, dc2); |
double dd0 = 0X1ACP12; |
double dd1 = 0x1acp-12; |
double dd2 = 0x1acp+12; |
printf("%f\n%f\n%f\n\n", dd0, dd1, dd2); |
printf("\n"); |
#ifdef __TINYC__ |
/* TCC extension |
binary floating constant */ |
long double la0 = 0B.110101100P12L; |
long double la1 = 0b.110101100p-12l; |
long double la2 = 0b.110101100p+12l; |
printf("%Lf\n%Lf\n%Lf\n\n", la0, la1, la2); |
long double lb0 = 0B110101100.10111101P12L; |
long double lb1 = 0b110101100.10111101p-12l; |
long double lb2 = 0b110101100.10111101p+12l; |
printf("%Lf\n%Lf\n%Lf\n\n", lb0, lb1, lb2); |
long double lc0 = 0B110101100.P12L; |
long double lc1 = 0b110101100.p-12l; |
long double lc2 = 0b110101100.p+12l; |
printf("%Lf\n%Lf\n%Lf\n\n", lc0, lc1, lc2); |
long double ld0 = 0B110101100P12L; |
long double ld1 = 0b110101100p-12l; |
long double ld2 = 0b110101100p+12l; |
printf("%Lf\n%Lf\n%Lf\n\n", ld0, ld1, ld2); |
#endif |
return 0; |
} |
/programs/develop/ktcc/trunk/source/tests/tests2/70_floating_point_literals.expect |
---|
0,0 → 1,53 |
0.123000 |
122999996416.000000 |
0.000000 |
122999996416.000000 |
123.123001 |
123122997002240.000000 |
0.000000 |
123122997002240.000000 |
123.000000 |
123000003231744.000000 |
0.000000 |
123000003231744.000000 |
123000003231744.000000 |
0.000000 |
123000003231744.000000 |
428.000000 |
0.000026 |
428.000000 |
1756112.000000 |
0.104672 |
1756592.000000 |
1753088.000000 |
0.104492 |
1753088.000000 |
1753088.000000 |
0.104492 |
1753088.000000 |
3424.000000 |
0.000204 |
3424.000000 |
1756112.000000 |
0.104672 |
1756112.000000 |
1753088.000000 |
0.104492 |
1753088.000000 |
1753088.000000 |
0.104492 |
1753088.000000 |
/programs/develop/ktcc/trunk/source/tests/tests2/71_macro_empty_arg.c |
---|
0,0 → 1,9 |
#include <stdio.h> |
#define T(a,b,c) a b c |
int main(void) |
{ |
printf("%d", T(1,+,2) T(+,,) T(,2,*) T(,7,) T(,,)); |
return 0; |
} |
/programs/develop/ktcc/trunk/source/tests/tests2/71_macro_empty_arg.expect |
---|
0,0 → 1,0 |
17 |
/programs/develop/ktcc/trunk/source/tests/tests2/72_long_long_constant.c |
---|
0,0 → 1,19 |
#include <stdio.h> |
int main() |
{ |
long long int res = 0; |
if (res < -2147483648LL) { |
printf("Error: 0 < -2147483648\n"); |
return 1; |
} |
else |
if (2147483647LL < res) { |
printf("Error: 2147483647 < 0\n"); |
return 2; |
} |
else |
printf("long long constant test ok.\n"); |
return 0; |
} |
/programs/develop/ktcc/trunk/source/tests/tests2/72_long_long_constant.expect |
---|
0,0 → 1,0 |
long long constant test ok. |
/programs/develop/ktcc/trunk/source/tests/tests2/73_arm64.c |
---|
0,0 → 1,527 |
// This program is designed to test some arm64-specific things, such as the |
// calling convention, but should give the same results on any architecture. |
#include <stdarg.h> |
#include <stdint.h> |
#include <stdio.h> |
struct s1 { char x[1]; } s1 = { "0" }; |
struct s2 { char x[2]; } s2 = { "12" }; |
struct s3 { char x[3]; } s3 = { "345" }; |
struct s4 { char x[4]; } s4 = { "6789" }; |
struct s5 { char x[5]; } s5 = { "abcde" }; |
struct s6 { char x[6]; } s6 = { "fghijk" }; |
struct s7 { char x[7]; } s7 = { "lmnopqr" }; |
struct s8 { char x[8]; } s8 = { "stuvwxyz" }; |
struct s9 { char x[9]; } s9 = { "ABCDEFGHI" }; |
struct s10 { char x[10]; } s10 = { "JKLMNOPQRS" }; |
struct s11 { char x[11]; } s11 = { "TUVWXYZ0123" }; |
struct s12 { char x[12]; } s12 = { "456789abcdef" }; |
struct s13 { char x[13]; } s13 = { "ghijklmnopqrs" }; |
struct s14 { char x[14]; } s14 = { "tuvwxyzABCDEFG" }; |
struct s15 { char x[15]; } s15 = { "HIJKLMNOPQRSTUV" }; |
struct s16 { char x[16]; } s16 = { "WXYZ0123456789ab" }; |
struct s17 { char x[17]; } s17 = { "cdefghijklmnopqrs" }; |
struct hfa11 { float a; } hfa11 = { 11.1 }; |
struct hfa12 { float a, b; } hfa12 = { 12.1, 12.2 }; |
struct hfa13 { float a, b, c; } hfa13 = { 13.1, 13.2, 13.3 }; |
struct hfa14 { float a, b, c, d; } hfa14 = { 14.1, 14.2, 14.3, 14.4 }; |
struct hfa21 { double a; } hfa21 = { 21.1 }; |
struct hfa22 { double a, b; } hfa22 = { 22.1, 22.2 }; |
struct hfa23 { double a, b, c; } hfa23 = { 23.1, 23.2, 23.3 }; |
struct hfa24 { double a, b, c, d; } hfa24 = { 24.1, 24.2, 24.3, 24.4 }; |
struct hfa31 { long double a; } hfa31 = { 31.1 }; |
struct hfa32 { long double a, b; } hfa32 = { 32.1, 32.2 }; |
struct hfa33 { long double a, b, c; } hfa33 = { 33.1, 33.2, 33.3 }; |
struct hfa34 { long double a, b, c, d; } hfa34 = { 34.1, 34.2, 34.3, 34.4 }; |
void fa_s1(struct s1 a) { printf("%.1s\n", a.x); } |
void fa_s2(struct s2 a) { printf("%.2s\n", a.x); } |
void fa_s3(struct s3 a) { printf("%.3s\n", a.x); } |
void fa_s4(struct s4 a) { printf("%.4s\n", a.x); } |
void fa_s5(struct s5 a) { printf("%.5s\n", a.x); } |
void fa_s6(struct s6 a) { printf("%.6s\n", a.x); } |
void fa_s7(struct s7 a) { printf("%.7s\n", a.x); } |
void fa_s8(struct s8 a) { printf("%.8s\n", a.x); } |
void fa_s9(struct s9 a) { printf("%.9s\n", a.x); } |
void fa_s10(struct s10 a) { printf("%.10s\n", a.x); } |
void fa_s11(struct s11 a) { printf("%.11s\n", a.x); } |
void fa_s12(struct s12 a) { printf("%.12s\n", a.x); } |
void fa_s13(struct s13 a) { printf("%.13s\n", a.x); } |
void fa_s14(struct s14 a) { printf("%.14s\n", a.x); } |
void fa_s15(struct s15 a) { printf("%.15s\n", a.x); } |
void fa_s16(struct s16 a) { printf("%.16s\n", a.x); } |
void fa_s17(struct s17 a) { printf("%.17s\n", a.x); } |
void fa_hfa11(struct hfa11 a) |
{ printf("%.1f\n", a.a); } |
void fa_hfa12(struct hfa12 a) |
{ printf("%.1f %.1f\n", a.a, a.a); } |
void fa_hfa13(struct hfa13 a) |
{ printf("%.1f %.1f %.1f\n", a.a, a.b, a.c); } |
void fa_hfa14(struct hfa14 a) |
{ printf("%.1f %.1f %.1f %.1f\n", a.a, a.b, a.c, a.d); } |
void fa_hfa21(struct hfa21 a) |
{ printf("%.1f\n", a.a); } |
void fa_hfa22(struct hfa22 a) |
{ printf("%.1f %.1f\n", a.a, a.a); } |
void fa_hfa23(struct hfa23 a) |
{ printf("%.1f %.1f %.1f\n", a.a, a.b, a.c); } |
void fa_hfa24(struct hfa24 a) |
{ printf("%.1f %.1f %.1f %.1f\n", a.a, a.b, a.c, a.d); } |
void fa_hfa31(struct hfa31 a) |
{ printf("%.1Lf\n", a.a); } |
void fa_hfa32(struct hfa32 a) |
{ printf("%.1Lf %.1Lf\n", a.a, a.a); } |
void fa_hfa33(struct hfa33 a) |
{ printf("%.1Lf %.1Lf %.1Lf\n", a.a, a.b, a.c); } |
void fa_hfa34(struct hfa34 a) |
{ printf("%.1Lf %.1Lf %.1Lf %.1Lf\n", a.a, a.b, a.c, a.d); } |
void fa1(struct s8 a, struct s9 b, struct s10 c, struct s11 d, |
struct s12 e, struct s13 f) |
{ |
printf("%.3s %.3s %.3s %.3s %.3s %.3s\n", a.x, b.x, c.x, d.x, e.x, f.x); |
} |
void fa2(struct s9 a, struct s10 b, struct s11 c, struct s12 d, |
struct s13 e, struct s14 f) |
{ |
printf("%.3s %.3s %.3s %.3s %.3s %.3s\n", a.x, b.x, c.x, d.x, e.x, f.x); |
} |
void fa3(struct hfa14 a, struct hfa23 b, struct hfa32 c) |
{ |
printf("%.1f %.1f %.1f %.1f %.1Lf %.1Lf\n", |
a.a, a.d, b.a, b.c, c.a, c.b); |
} |
void fa4(struct s1 a, struct hfa14 b, struct s2 c, struct hfa24 d, |
struct s3 e, struct hfa34 f) |
{ |
printf("%.1s %.1f %.1f %.2s %.1f %.1f %.3s %.1Lf %.1Lf\n", |
a.x, b.a, b.d, c.x, d.a, d.d, e.x, f.a, f.d); |
} |
void arg(void) |
{ |
printf("Arguments:\n"); |
fa_s1(s1); |
fa_s2(s2); |
fa_s3(s3); |
fa_s4(s4); |
fa_s5(s5); |
fa_s6(s6); |
fa_s7(s7); |
fa_s8(s8); |
fa_s9(s9); |
fa_s10(s10); |
fa_s11(s11); |
fa_s12(s12); |
fa_s13(s13); |
fa_s14(s14); |
fa_s15(s15); |
fa_s16(s16); |
fa_s17(s17); |
fa_hfa11(hfa11); |
fa_hfa12(hfa12); |
fa_hfa13(hfa13); |
fa_hfa14(hfa14); |
fa_hfa21(hfa21); |
fa_hfa22(hfa22); |
fa_hfa23(hfa23); |
fa_hfa24(hfa24); |
fa_hfa31(hfa31); |
fa_hfa32(hfa32); |
fa_hfa33(hfa33); |
fa_hfa34(hfa34); |
fa1(s8, s9, s10, s11, s12, s13); |
fa2(s9, s10, s11, s12, s13, s14); |
fa3(hfa14, hfa23, hfa32); |
fa4(s1, hfa14, s2, hfa24, s3, hfa34); |
} |
struct s1 fr_s1(void) { return s1; } |
struct s2 fr_s2(void) { return s2; } |
struct s3 fr_s3(void) { return s3; } |
struct s4 fr_s4(void) { return s4; } |
struct s5 fr_s5(void) { return s5; } |
struct s6 fr_s6(void) { return s6; } |
struct s7 fr_s7(void) { return s7; } |
struct s8 fr_s8(void) { return s8; } |
struct s9 fr_s9(void) { return s9; } |
struct s10 fr_s10(void) { return s10; } |
struct s11 fr_s11(void) { return s11; } |
struct s12 fr_s12(void) { return s12; } |
struct s13 fr_s13(void) { return s13; } |
struct s14 fr_s14(void) { return s14; } |
struct s15 fr_s15(void) { return s15; } |
struct s16 fr_s16(void) { return s16; } |
struct s17 fr_s17(void) { return s17; } |
struct hfa11 fr_hfa11(void) { return hfa11; } |
struct hfa12 fr_hfa12(void) { return hfa12; } |
struct hfa13 fr_hfa13(void) { return hfa13; } |
struct hfa14 fr_hfa14(void) { return hfa14; } |
struct hfa21 fr_hfa21(void) { return hfa21; } |
struct hfa22 fr_hfa22(void) { return hfa22; } |
struct hfa23 fr_hfa23(void) { return hfa23; } |
struct hfa24 fr_hfa24(void) { return hfa24; } |
struct hfa31 fr_hfa31(void) { return hfa31; } |
struct hfa32 fr_hfa32(void) { return hfa32; } |
struct hfa33 fr_hfa33(void) { return hfa33; } |
struct hfa34 fr_hfa34(void) { return hfa34; } |
void ret(void) |
{ |
struct s1 t1 = fr_s1(); |
struct s2 t2 = fr_s2(); |
struct s3 t3 = fr_s3(); |
struct s4 t4 = fr_s4(); |
struct s5 t5 = fr_s5(); |
struct s6 t6 = fr_s6(); |
struct s7 t7 = fr_s7(); |
struct s8 t8 = fr_s8(); |
struct s9 t9 = fr_s9(); |
struct s10 t10 = fr_s10(); |
struct s11 t11 = fr_s11(); |
struct s12 t12 = fr_s12(); |
struct s13 t13 = fr_s13(); |
struct s14 t14 = fr_s14(); |
struct s15 t15 = fr_s15(); |
struct s16 t16 = fr_s16(); |
struct s17 t17 = fr_s17(); |
printf("Return values:\n"); |
printf("%.1s\n", t1.x); |
printf("%.2s\n", t2.x); |
printf("%.3s\n", t3.x); |
printf("%.4s\n", t4.x); |
printf("%.5s\n", t5.x); |
printf("%.6s\n", t6.x); |
printf("%.7s\n", t7.x); |
printf("%.8s\n", t8.x); |
printf("%.9s\n", t9.x); |
printf("%.10s\n", t10.x); |
printf("%.11s\n", t11.x); |
printf("%.12s\n", t12.x); |
printf("%.13s\n", t13.x); |
printf("%.14s\n", t14.x); |
printf("%.15s\n", t15.x); |
printf("%.16s\n", t16.x); |
printf("%.17s\n", t17.x); |
printf("%.1f\n", fr_hfa11().a); |
printf("%.1f %.1f\n", fr_hfa12().a, fr_hfa12().b); |
printf("%.1f %.1f\n", fr_hfa13().a, fr_hfa13().c); |
printf("%.1f %.1f\n", fr_hfa14().a, fr_hfa14().d); |
printf("%.1f\n", fr_hfa21().a); |
printf("%.1f %.1f\n", fr_hfa22().a, fr_hfa22().b); |
printf("%.1f %.1f\n", fr_hfa23().a, fr_hfa23().c); |
printf("%.1f %.1f\n", fr_hfa24().a, fr_hfa24().d); |
printf("%.1Lf\n", fr_hfa31().a); |
printf("%.1Lf %.1Lf\n", fr_hfa32().a, fr_hfa32().b); |
printf("%.1Lf %.1Lf\n", fr_hfa33().a, fr_hfa33().c); |
printf("%.1Lf %.1Lf\n", fr_hfa34().a, fr_hfa34().d); |
} |
int match(const char **s, const char *f) |
{ |
const char *p = *s; |
for (p = *s; *f && *f == *p; f++, p++) |
; |
if (!*f) { |
*s = p - 1; |
return 1; |
} |
return 0; |
} |
void myprintf(const char *format, ...) |
{ |
const char *s; |
va_list ap; |
va_start(ap, format); |
for (s = format; *s; s++) { |
if (match(&s, "%7s")) { |
struct s7 t7 = va_arg(ap, struct s7); |
printf("%.7s", t7.x); |
} |
else if (match(&s, "%9s")) { |
struct s9 t9 = va_arg(ap, struct s9); |
printf("%.9s", t9.x); |
} |
else if (match(&s, "%hfa11")) { |
struct hfa11 x = va_arg(ap, struct hfa11); |
printf("%.1f,%.1f", x.a, x.a); |
} |
else if (match(&s, "%hfa12")) { |
struct hfa12 x = va_arg(ap, struct hfa12); |
printf("%.1f,%.1f", x.a, x.b); |
} |
else if (match(&s, "%hfa13")) { |
struct hfa13 x = va_arg(ap, struct hfa13); |
printf("%.1f,%.1f", x.a, x.c); |
} |
else if (match(&s, "%hfa14")) { |
struct hfa14 x = va_arg(ap, struct hfa14); |
printf("%.1f,%.1f", x.a, x.d); |
} |
else if (match(&s, "%hfa21")) { |
struct hfa21 x = va_arg(ap, struct hfa21); |
printf("%.1f,%.1f", x.a, x.a); |
} |
else if (match(&s, "%hfa22")) { |
struct hfa22 x = va_arg(ap, struct hfa22); |
printf("%.1f,%.1f", x.a, x.b); |
} |
else if (match(&s, "%hfa23")) { |
struct hfa23 x = va_arg(ap, struct hfa23); |
printf("%.1f,%.1f", x.a, x.c); |
} |
else if (match(&s, "%hfa24")) { |
struct hfa24 x = va_arg(ap, struct hfa24); |
printf("%.1f,%.1f", x.a, x.d); |
} |
else if (match(&s, "%hfa31")) { |
struct hfa31 x = va_arg(ap, struct hfa31); |
printf("%.1Lf,%.1Lf", x.a, x.a); |
} |
else if (match(&s, "%hfa32")) { |
struct hfa32 x = va_arg(ap, struct hfa32); |
printf("%.1Lf,%.1Lf", x.a, x.b); |
} |
else if (match(&s, "%hfa33")) { |
struct hfa33 x = va_arg(ap, struct hfa33); |
printf("%.1Lf,%.1Lf", x.a, x.c); |
} |
else if (match(&s, "%hfa34")) { |
struct hfa34 x = va_arg(ap, struct hfa34); |
printf("%.1Lf,%.1Lf", x.a, x.d); |
} |
else |
putchar(*s); |
} |
putchar('\n'); |
} |
void stdarg(void) |
{ |
printf("stdarg:\n"); |
myprintf("%9s %9s %9s %9s %9s %9s", s9, s9, s9, s9, s9, s9); |
myprintf("%7s %9s %9s %9s %9s %9s", s7, s9, s9, s9, s9, s9); |
myprintf("HFA long double:"); |
myprintf("%hfa34 %hfa34 %hfa34 %hfa34", hfa34, hfa34, hfa34, hfa34); |
myprintf("%hfa33 %hfa34 %hfa34 %hfa34", hfa33, hfa34, hfa34, hfa34); |
myprintf("%hfa32 %hfa34 %hfa34 %hfa34", hfa32, hfa34, hfa34, hfa34); |
myprintf("%hfa31 %hfa34 %hfa34 %hfa34", hfa31, hfa34, hfa34, hfa34); |
myprintf("%hfa32 %hfa33 %hfa33 %hfa33 %hfa33", |
hfa32, hfa33, hfa33, hfa33, hfa33); |
myprintf("%hfa31 %hfa33 %hfa33 %hfa33 %hfa33", |
hfa31, hfa33, hfa33, hfa33, hfa33); |
myprintf("%hfa33 %hfa33 %hfa33 %hfa33", |
hfa33, hfa33, hfa33, hfa33); |
myprintf("%hfa34 %hfa32 %hfa32 %hfa32 %hfa32", |
hfa34, hfa32, hfa32, hfa32, hfa32); |
myprintf("%hfa33 %hfa32 %hfa32 %hfa32 %hfa32", |
hfa33, hfa32, hfa32, hfa32, hfa32); |
myprintf("%hfa34 %hfa32 %hfa31 %hfa31 %hfa31 %hfa31", |
hfa34, hfa32, hfa31, hfa31, hfa31, hfa31); |
myprintf("HFA double:"); |
myprintf("%hfa24 %hfa24 %hfa24 %hfa24", hfa24, hfa24, hfa24, hfa24); |
myprintf("%hfa23 %hfa24 %hfa24 %hfa24", hfa23, hfa24, hfa24, hfa24); |
myprintf("%hfa22 %hfa24 %hfa24 %hfa24", hfa22, hfa24, hfa24, hfa24); |
myprintf("%hfa21 %hfa24 %hfa24 %hfa24", hfa21, hfa24, hfa24, hfa24); |
myprintf("%hfa22 %hfa23 %hfa23 %hfa23 %hfa23", |
hfa22, hfa23, hfa23, hfa23, hfa23); |
myprintf("%hfa21 %hfa23 %hfa23 %hfa23 %hfa23", |
hfa21, hfa23, hfa23, hfa23, hfa23); |
myprintf("%hfa23 %hfa23 %hfa23 %hfa23", |
hfa23, hfa23, hfa23, hfa23); |
myprintf("%hfa24 %hfa22 %hfa22 %hfa22 %hfa22", |
hfa24, hfa22, hfa22, hfa22, hfa22); |
myprintf("%hfa23 %hfa22 %hfa22 %hfa22 %hfa22", |
hfa23, hfa22, hfa22, hfa22, hfa22); |
myprintf("%hfa24 %hfa22 %hfa21 %hfa21 %hfa21 %hfa21", |
hfa24, hfa22, hfa21, hfa21, hfa21, hfa21); |
myprintf("HFA float:"); |
myprintf("%hfa14 %hfa14 %hfa14 %hfa14", hfa14, hfa14, hfa14, hfa14); |
myprintf("%hfa13 %hfa14 %hfa14 %hfa14", hfa13, hfa14, hfa14, hfa14); |
myprintf("%hfa12 %hfa14 %hfa14 %hfa14", hfa12, hfa14, hfa14, hfa14); |
myprintf("%hfa11 %hfa14 %hfa14 %hfa14", hfa11, hfa14, hfa14, hfa14); |
myprintf("%hfa12 %hfa13 %hfa13 %hfa13 %hfa13", |
hfa12, hfa13, hfa13, hfa13, hfa13); |
myprintf("%hfa11 %hfa13 %hfa13 %hfa13 %hfa13", |
hfa11, hfa13, hfa13, hfa13, hfa13); |
myprintf("%hfa13 %hfa13 %hfa13 %hfa13", |
hfa13, hfa13, hfa13, hfa13); |
myprintf("%hfa14 %hfa12 %hfa12 %hfa12 %hfa12", |
hfa14, hfa12, hfa12, hfa12, hfa12); |
myprintf("%hfa13 %hfa12 %hfa12 %hfa12 %hfa12", |
hfa13, hfa12, hfa12, hfa12, hfa12); |
myprintf("%hfa14 %hfa12 %hfa11 %hfa11 %hfa11 %hfa11", |
hfa14, hfa12, hfa11, hfa11, hfa11, hfa11); |
} |
void pll(unsigned long long x) |
{ |
printf("%llx\n", x); |
} |
void movi(void) |
{ |
printf("MOVI:\n"); |
pll(0); |
pll(0xabcd); |
pll(0xabcd0000); |
pll(0xabcd00000000); |
pll(0xabcd000000000000); |
pll(0xffffabcd); |
pll(0xabcdffff); |
pll(0xffffffffffffabcd); |
pll(0xffffffffabcdffff); |
pll(0xffffabcdffffffff); |
pll(0xabcdffffffffffff); |
pll(0xaaaaaaaa); |
pll(0x5555555555555555); |
pll(0x77777777); |
pll(0x3333333333333333); |
pll(0xf8f8f8f8); |
pll(0x1e1e1e1e1e1e1e1e); |
pll(0x3f803f80); |
pll(0x01ff01ff01ff01ff); |
pll(0x007fffc0); |
pll(0x03fff80003fff800); |
pll(0x0007fffffffffe00); |
pll(0xabcd1234); |
pll(0xabcd00001234); |
pll(0xabcd000000001234); |
pll(0xabcd12340000); |
pll(0xabcd000012340000); |
pll(0xabcd123400000000); |
pll(0xffffffffabcd1234); |
pll(0xffffabcdffff1234); |
pll(0xabcdffffffff1234); |
pll(0xffffabcd1234ffff); |
pll(0xabcdffff1234ffff); |
pll(0xabcd1234ffffffff); |
pll(0xffffef0123456789); |
pll(0xabcdef012345ffff); |
pll(0xabcdef0123456789); |
} |
static uint32_t addip0(uint32_t x) { return x + 0; } |
static uint64_t sublp0(uint64_t x) { return x - 0; } |
static uint32_t addip123(uint32_t x) { return x + 123; } |
static uint64_t addlm123(uint64_t x) { return x + -123; } |
static uint64_t sublp4095(uint64_t x) { return x - 4095; } |
static uint32_t subim503808(uint32_t x) { return x - -503808; } |
static uint64_t addp12345(uint64_t x) { return x + 12345; } |
static uint32_t subp12345(uint32_t x) { return x - 12345; } |
static uint32_t mvni(uint32_t x) { return 0xffffffff - x; } |
static uint64_t negl(uint64_t x) { return 0 - x; } |
static uint32_t rsbi123(uint32_t x) { return 123 - x; } |
static uint64_t rsbl123(uint64_t x) { return 123 - x; } |
static uint32_t andi0(uint32_t x) { return x & 0; } |
static uint64_t andlm1(uint64_t x) { return x & -1; } |
static uint64_t orrl0(uint64_t x) { return x | 0; } |
static uint32_t orrim1(uint32_t x) { return x | -1; } |
static uint32_t eori0(uint32_t x) { return x ^ 0; } |
static uint64_t eorlm1(uint64_t x) { return x ^ -1; } |
static uint32_t and0xf0(uint32_t x) { return x & 0xf0; } |
static uint64_t orr0xf0(uint64_t x) { return x | 0xf0; } |
static uint64_t eor0xf0(uint64_t x) { return x ^ 0xf0; } |
static uint32_t lsli0(uint32_t x) { return x << 0; } |
static uint32_t lsri0(uint32_t x) { return x >> 0; } |
static int64_t asrl0(int64_t x) { return x >> 0; } |
static uint32_t lsli1(uint32_t x) { return x << 1; } |
static uint32_t lsli31(uint32_t x) { return x << 31; } |
static uint64_t lsll1(uint64_t x) { return x << 1; } |
static uint64_t lsll63(uint64_t x) { return x << 63; } |
static uint32_t lsri1(uint32_t x) { return x >> 1; } |
static uint32_t lsri31(uint32_t x) { return x >> 31; } |
static uint64_t lsrl1(uint64_t x) { return x >> 1; } |
static uint64_t lsrl63(uint64_t x) { return x >> 63; } |
static int32_t asri1(int32_t x) { return x >> 1; } |
static int32_t asri31(int32_t x) { return x >> 31; } |
static int64_t asrl1(int64_t x) { return x >> 1; } |
static int64_t asrl63(int64_t x) { return x >> 63; } |
void opi(void) |
{ |
int x = 1000; |
pll(addip0(x)); |
pll(sublp0(x)); |
pll(addip123(x)); |
pll(addlm123(x)); |
pll(sublp4095(x)); |
pll(subim503808(x)); |
pll(addp12345(x)); |
pll(subp12345(x)); |
pll(mvni(x)); |
pll(negl(x)); |
pll(rsbi123(x)); |
pll(rsbl123(x)); |
pll(andi0(x)); |
pll(andlm1(x)); |
pll(orrl0(x)); |
pll(orrim1(x)); |
pll(eori0(x)); |
pll(eorlm1(x)); |
pll(and0xf0(x)); |
pll(orr0xf0(x)); |
pll(eor0xf0(x)); |
pll(lsli0(x)); |
pll(lsri0(x)); |
pll(asrl0(x)); |
pll(lsli1(x)); |
pll(lsli31(x)); |
pll(lsll1(x)); |
pll(lsll63(x)); |
pll(lsri1(x)); |
pll(lsri31(x)); |
pll(lsrl1(x)); |
pll(lsrl63(x)); |
pll(asri1(x)); |
pll(asri31(x)); |
pll(asrl1(x)); |
pll(asrl63(x)); |
} |
void pcs(void) |
{ |
arg(); |
ret(); |
stdarg(); |
movi(); |
opi(); |
} |
int main() |
{ |
pcs(); |
return 0; |
} |
/programs/develop/ktcc/trunk/source/tests/tests2/73_arm64.expect |
---|
0,0 → 1,174 |
Arguments: |
12 |
345 |
6789 |
abcde |
fghijk |
lmnopqr |
stuvwxyz |
ABCDEFGHI |
JKLMNOPQRS |
TUVWXYZ0123 |
456789abcdef |
ghijklmnopqrs |
tuvwxyzABCDEFG |
HIJKLMNOPQRSTUV |
WXYZ0123456789ab |
cdefghijklmnopqrs |
11.1 |
12.1 12.1 |
13.1 13.2 13.3 |
14.1 14.2 14.3 14.4 |
21.1 |
22.1 22.1 |
23.1 23.2 23.3 |
24.1 24.2 24.3 24.4 |
31.1 |
32.1 32.1 |
33.1 33.2 33.3 |
34.1 34.2 34.3 34.4 |
stu ABC JKL TUV 456 ghi |
ABC JKL TUV 456 ghi tuv |
14.1 14.4 23.1 23.3 32.1 32.2 |
0 14.1 14.4 12 24.1 24.4 345 34.1 34.4 |
Return values: |
12 |
345 |
6789 |
abcde |
fghijk |
lmnopqr |
stuvwxyz |
ABCDEFGHI |
JKLMNOPQRS |
TUVWXYZ0123 |
456789abcdef |
ghijklmnopqrs |
tuvwxyzABCDEFG |
HIJKLMNOPQRSTUV |
WXYZ0123456789ab |
cdefghijklmnopqrs |
11.1 |
12.1 12.2 |
13.1 13.3 |
14.1 14.4 |
21.1 |
22.1 22.2 |
23.1 23.3 |
24.1 24.4 |
31.1 |
32.1 32.2 |
33.1 33.3 |
34.1 34.4 |
stdarg: |
ABCDEFGHI ABCDEFGHI ABCDEFGHI ABCDEFGHI ABCDEFGHI ABCDEFGHI |
lmnopqr ABCDEFGHI ABCDEFGHI ABCDEFGHI ABCDEFGHI ABCDEFGHI |
HFA long double: |
34.1,34.4 34.1,34.4 34.1,34.4 34.1,34.4 |
33.1,33.3 34.1,34.4 34.1,34.4 34.1,34.4 |
32.1,32.2 34.1,34.4 34.1,34.4 34.1,34.4 |
31.1,31.1 34.1,34.4 34.1,34.4 34.1,34.4 |
32.1,32.2 33.1,33.3 33.1,33.3 33.1,33.3 33.1,33.3 |
31.1,31.1 33.1,33.3 33.1,33.3 33.1,33.3 33.1,33.3 |
33.1,33.3 33.1,33.3 33.1,33.3 33.1,33.3 |
34.1,34.4 32.1,32.2 32.1,32.2 32.1,32.2 32.1,32.2 |
33.1,33.3 32.1,32.2 32.1,32.2 32.1,32.2 32.1,32.2 |
34.1,34.4 32.1,32.2 31.1,31.1 31.1,31.1 31.1,31.1 31.1,31.1 |
HFA double: |
24.1,24.4 24.1,24.4 24.1,24.4 24.1,24.4 |
23.1,23.3 24.1,24.4 24.1,24.4 24.1,24.4 |
22.1,22.2 24.1,24.4 24.1,24.4 24.1,24.4 |
21.1,21.1 24.1,24.4 24.1,24.4 24.1,24.4 |
22.1,22.2 23.1,23.3 23.1,23.3 23.1,23.3 23.1,23.3 |
21.1,21.1 23.1,23.3 23.1,23.3 23.1,23.3 23.1,23.3 |
23.1,23.3 23.1,23.3 23.1,23.3 23.1,23.3 |
24.1,24.4 22.1,22.2 22.1,22.2 22.1,22.2 22.1,22.2 |
23.1,23.3 22.1,22.2 22.1,22.2 22.1,22.2 22.1,22.2 |
24.1,24.4 22.1,22.2 21.1,21.1 21.1,21.1 21.1,21.1 21.1,21.1 |
HFA float: |
14.1,14.4 14.1,14.4 14.1,14.4 14.1,14.4 |
13.1,13.3 14.1,14.4 14.1,14.4 14.1,14.4 |
12.1,12.2 14.1,14.4 14.1,14.4 14.1,14.4 |
11.1,11.1 14.1,14.4 14.1,14.4 14.1,14.4 |
12.1,12.2 13.1,13.3 13.1,13.3 13.1,13.3 13.1,13.3 |
11.1,11.1 13.1,13.3 13.1,13.3 13.1,13.3 13.1,13.3 |
13.1,13.3 13.1,13.3 13.1,13.3 13.1,13.3 |
14.1,14.4 12.1,12.2 12.1,12.2 12.1,12.2 12.1,12.2 |
13.1,13.3 12.1,12.2 12.1,12.2 12.1,12.2 12.1,12.2 |
14.1,14.4 12.1,12.2 11.1,11.1 11.1,11.1 11.1,11.1 11.1,11.1 |
MOVI: |
abcd |
abcd0000 |
abcd00000000 |
abcd000000000000 |
ffffabcd |
abcdffff |
ffffffffffffabcd |
ffffffffabcdffff |
ffffabcdffffffff |
abcdffffffffffff |
aaaaaaaa |
5555555555555555 |
77777777 |
3333333333333333 |
f8f8f8f8 |
1e1e1e1e1e1e1e1e |
3f803f80 |
1ff01ff01ff01ff |
7fffc0 |
3fff80003fff800 |
7fffffffffe00 |
abcd1234 |
abcd00001234 |
abcd000000001234 |
abcd12340000 |
abcd000012340000 |
abcd123400000000 |
ffffffffabcd1234 |
ffffabcdffff1234 |
abcdffffffff1234 |
ffffabcd1234ffff |
abcdffff1234ffff |
abcd1234ffffffff |
ffffef0123456789 |
abcdef012345ffff |
abcdef0123456789 |
3e8 |
3e8 |
463 |
36d |
fffffffffffff3e9 |
7b3e8 |
3421 |
ffffd3af |
fffffc17 |
fffffffffffffc18 |
fffffc93 |
fffffffffffffc93 |
3e8 |
3e8 |
ffffffff |
3e8 |
fffffffffffffc17 |
e0 |
3f8 |
318 |
3e8 |
3e8 |
3e8 |
7d0 |
7d0 |
1f4 |
1f4 |
1f4 |
1f4 |
/programs/develop/ktcc/trunk/source/tests/tests2/74_nocode_wanted.c |
---|
0,0 → 1,0 |
int i = i++; |
/programs/develop/ktcc/trunk/source/tests/tests2/74_nocode_wanted.expect |
---|
0,0 → 1,0 |
74_nocode_wanted.c:1: error: initializer element is not constant |
/programs/develop/ktcc/trunk/source/tests/tests2/75_array_in_struct_init.c |
---|
0,0 → 1,33 |
#include <stdio.h> |
/* This test is a snippet from the J interpreter */ |
typedef long I; |
typedef struct{I c[4];I b,e,k;} PT; |
PT cases[] = { |
((I)4194304L +(I)2097152L +(I)67108864L), (I)262144L, (((I)1L +(I)256L +(I)4L +(I)8L +(I)16L +(I)64L +(I)128L +(I)268435456L +(I)536870912L +(I)1024L +(I)4096L +(I)8192L +(I)16384L)+((I)2L +(I)131072L +(I)2048L)+(I)32L +(I)32768L +(I)65536L), -1L, 1,2,1, |
((I)+4194304L +(I)2097152L +(I)67108864L)+( (I)524288L +(I)262144L +(((I)1L +(I)256L +(I)4L +(I)8L +(I)16L +(I)64L +(I)128L +(I)268435456L +(I)536870912L +(I)1024L +(I)4096L +(I)8192L +(I)16384L)+((I)2L +(I)131072L +(I)2048L)+(I)32L +(I)32768L +(I)65536L)), (I)262144L, (I)262144L, (((I)1L +(I)256L +(I)4L +(I)8L +(I)16L +(I)64L +(I)128L +(I)268435456L +(I)536870912L +(I)1024L +(I)4096L +(I)8192L +(I)16384L)+((I)2L +(I)131072L +(I)2048L)+(I)32L +(I)32768L +(I)65536L), 2,3,2, |
((I)4194304L +(I)2097152L +(I)67108864L)+( (I)524288L +(I)262144L +(((I)1L +(I)256L +(I)4L +(I)8L +(I)16L +(I)64L +(I)128L +(I)268435456L +(I)536870912L +(I)1024L +(I)4096L +(I)8192L +(I)16384L)+((I)2L +(I)131072L +(I)2048L)+(I)32L +(I)32768L +(I)65536L)), (((I)1L +(I)256L +(I)4L +(I)8L +(I)16L +(I)64L +(I)128L +(I)268435456L +(I)536870912L +(I)1024L +(I)4096L +(I)8192L +(I)16384L)+((I)2L +(I)131072L +(I)2048L)+(I)32L +(I)32768L +(I)65536L), (I)262144L, (((I)1L +(I)256L +(I)4L +(I)8L +(I)16L +(I)64L +(I)128L +(I)268435456L +(I)536870912L +(I)1024L +(I)4096L +(I)8192L +(I)16384L)+((I)2L +(I)131072L +(I)2048L)+(I)32L +(I)32768L +(I)65536L), 1,3,2, |
((I)4194304L +(I)2097152L +(I)67108864L)+( (I)524288L +(I)262144L +(((I)1L +(I)256L +(I)4L +(I)8L +(I)16L +(I)64L +(I)128L +(I)268435456L +(I)536870912L +(I)1024L +(I)4096L +(I)8192L +(I)16384L)+((I)2L +(I)131072L +(I)2048L)+(I)32L +(I)32768L +(I)65536L)), (I)262144L +(((I)1L +(I)256L +(I)4L +(I)8L +(I)16L +(I)64L +(I)128L +(I)268435456L +(I)536870912L +(I)1024L +(I)4096L +(I)8192L +(I)16384L)+((I)2L +(I)131072L +(I)2048L)+(I)32L +(I)32768L +(I)65536L), (I)524288L, -1L, 1,2,1, |
((I)4194304L +(I)2097152L +(I)67108864L)+( (I)524288L +(I)262144L +(((I)1L +(I)256L +(I)4L +(I)8L +(I)16L +(I)64L +(I)128L +(I)268435456L +(I)536870912L +(I)1024L +(I)4096L +(I)8192L +(I)16384L)+((I)2L +(I)131072L +(I)2048L)+(I)32L +(I)32768L +(I)65536L)), (I)262144L +(((I)1L +(I)256L +(I)4L +(I)8L +(I)16L +(I)64L +(I)128L +(I)268435456L +(I)536870912L +(I)1024L +(I)4096L +(I)8192L +(I)16384L)+((I)2L +(I)131072L +(I)2048L)+(I)32L +(I)32768L +(I)65536L), (I)1048576L, (I)262144L +(((I)1L +(I)256L +(I)4L +(I)8L +(I)16L +(I)64L +(I)128L +(I)268435456L +(I)536870912L +(I)1024L +(I)4096L +(I)8192L +(I)16384L)+((I)2L +(I)131072L +(I)2048L)+(I)32L +(I)32768L +(I)65536L), 1,3,1, |
((I)4194304L +(I)2097152L +(I)67108864L)+( (I)524288L +(I)262144L +(((I)1L +(I)256L +(I)4L +(I)8L +(I)16L +(I)64L +(I)128L +(I)268435456L +(I)536870912L +(I)1024L +(I)4096L +(I)8192L +(I)16384L)+((I)2L +(I)131072L +(I)2048L)+(I)32L +(I)32768L +(I)65536L)), (I)262144L +(((I)1L +(I)256L +(I)4L +(I)8L +(I)16L +(I)64L +(I)128L +(I)268435456L +(I)536870912L +(I)1024L +(I)4096L +(I)8192L +(I)16384L)+((I)2L +(I)131072L +(I)2048L)+(I)32L +(I)32768L +(I)65536L), (I)262144L, (I)262144L, 1,3,1, |
((I)4194304L +(I)2097152L +(I)67108864L), ((I)1048576L +(I)524288L +(I)262144L +(((I)1L +(I)256L +(I)4L +(I)8L +(I)16L +(I)64L +(I)128L +(I)268435456L +(I)536870912L +(I)1024L +(I)4096L +(I)8192L +(I)16384L)+((I)2L +(I)131072L +(I)2048L)+(I)32L +(I)32768L +(I)65536L)), ((I)1048576L +(I)524288L +(I)262144L +(((I)1L +(I)256L +(I)4L +(I)8L +(I)16L +(I)64L +(I)128L +(I)268435456L +(I)536870912L +(I)1024L +(I)4096L +(I)8192L +(I)16384L)+((I)2L +(I)131072L +(I)2048L)+(I)32L +(I)32768L +(I)65536L)), -1L, 1,2,1, |
(I)33554432L +(((I)1L +(I)256L +(I)4L +(I)8L +(I)16L +(I)64L +(I)128L +(I)268435456L +(I)536870912L +(I)1024L +(I)4096L +(I)8192L +(I)16384L)+((I)2L +(I)131072L +(I)2048L)+(I)32L +(I)32768L +(I)65536L), (I)2097152L, ((I)1048576L +(I)524288L +(I)262144L +(((I)1L +(I)256L +(I)4L +(I)8L +(I)16L +(I)64L +(I)128L +(I)268435456L +(I)536870912L +(I)1024L +(I)4096L +(I)8192L +(I)16384L)+((I)2L +(I)131072L +(I)2048L)+(I)32L +(I)32768L +(I)65536L)), -1L, 0,2,1, |
(I)67108864L, ((I)1048576L +(I)524288L +(I)262144L +(((I)1L +(I)256L +(I)4L +(I)8L +(I)16L +(I)64L +(I)128L +(I)268435456L +(I)536870912L +(I)1024L +(I)4096L +(I)8192L +(I)16384L)+((I)2L +(I)131072L +(I)2048L)+(I)32L +(I)32768L +(I)65536L)), (I)134217728L, -1L, 0,2,0, |
}; |
int main() { |
int i, j; |
for(j=0; j < sizeof(cases)/sizeof(cases[0]); j++) { |
for(i=0; i < sizeof(cases->c)/sizeof(cases->c[0]); i++) |
printf("cases[%d].c[%d]=%ld\n", j, i, cases[j].c[i]); |
printf("cases[%d].b=%ld\n", j, cases[j].b); |
printf("cases[%d].e=%ld\n", j, cases[j].e); |
printf("cases[%d].k=%ld\n", j, cases[j].k); |
printf("\n"); |
} |
return 0; |
} |
/programs/develop/ktcc/trunk/source/tests/tests2/75_array_in_struct_init.expect |
---|
0,0 → 1,72 |
cases[0].c[0]=73400320 |
cases[0].c[1]=262144 |
cases[0].c[2]=805567999 |
cases[0].c[3]=-1 |
cases[0].b=1 |
cases[0].e=2 |
cases[0].k=1 |
cases[1].c[0]=879754751 |
cases[1].c[1]=262144 |
cases[1].c[2]=262144 |
cases[1].c[3]=805567999 |
cases[1].b=2 |
cases[1].e=3 |
cases[1].k=2 |
cases[2].c[0]=879754751 |
cases[2].c[1]=805567999 |
cases[2].c[2]=262144 |
cases[2].c[3]=805567999 |
cases[2].b=1 |
cases[2].e=3 |
cases[2].k=2 |
cases[3].c[0]=879754751 |
cases[3].c[1]=805830143 |
cases[3].c[2]=524288 |
cases[3].c[3]=-1 |
cases[3].b=1 |
cases[3].e=2 |
cases[3].k=1 |
cases[4].c[0]=879754751 |
cases[4].c[1]=805830143 |
cases[4].c[2]=1048576 |
cases[4].c[3]=805830143 |
cases[4].b=1 |
cases[4].e=3 |
cases[4].k=1 |
cases[5].c[0]=879754751 |
cases[5].c[1]=805830143 |
cases[5].c[2]=262144 |
cases[5].c[3]=262144 |
cases[5].b=1 |
cases[5].e=3 |
cases[5].k=1 |
cases[6].c[0]=73400320 |
cases[6].c[1]=807403007 |
cases[6].c[2]=807403007 |
cases[6].c[3]=-1 |
cases[6].b=1 |
cases[6].e=2 |
cases[6].k=1 |
cases[7].c[0]=839122431 |
cases[7].c[1]=2097152 |
cases[7].c[2]=807403007 |
cases[7].c[3]=-1 |
cases[7].b=0 |
cases[7].e=2 |
cases[7].k=1 |
cases[8].c[0]=67108864 |
cases[8].c[1]=807403007 |
cases[8].c[2]=134217728 |
cases[8].c[3]=-1 |
cases[8].b=0 |
cases[8].e=2 |
cases[8].k=0 |
/programs/develop/ktcc/trunk/source/tests/tests2/76_dollars_in_identifiers.c |
---|
0,0 → 1,41 |
#include <stdio.h> |
#define $(x) x |
#define $fred 10 |
#define joe$ 20 |
#define hen$y 30 |
#define $10(x) x*10 |
#define _$10(x) x/10 |
int main() |
{ |
printf("fred=%d\n", $fred); |
printf("joe=%d\n", joe$); |
printf("henry=%d\n", hen$y); |
printf("fred2=%d\n", $($fred)); |
printf("joe2=%d\n", $(joe$)); |
printf("henry2=%d\n", $(hen$y)); |
printf("fred10=%d\n", $10($fred)); |
printf("joe_10=%d\n", _$10(joe$)); |
int $ = 10; |
int a100$ = 100; |
int a$$ = 1000; |
int a$c$b = 2121; |
int $100 = 10000; |
const char *$$$ = "money"; |
printf("local=%d\n", $); |
printf("a100$=%d\n", a100$); |
printf("a$$=%d\n", a$$); |
printf("a$c$b=%d\n", a$c$b); |
printf("$100=%d\n", $100); |
printf("$$$=%s", $$$); |
return 0; |
} |
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ |
/programs/develop/ktcc/trunk/source/tests/tests2/76_dollars_in_identifiers.expect |
---|
0,0 → 1,14 |
fred=10 |
joe=20 |
henry=30 |
fred2=10 |
joe2=20 |
henry2=30 |
fred10=100 |
joe_10=2 |
local=10 |
a100$=100 |
a$$=1000 |
a$c$b=2121 |
$100=10000 |
$$$=money |
/programs/develop/ktcc/trunk/source/tests/tests2/77_push_pop_macro.c |
---|
0,0 → 1,30 |
#include <stdio.h> |
int main() |
{ |
/* must not affect how #pragma ppop_macro works */ |
#define pop_macro foobar1 |
/* must not affect how #pragma push_macro works */ |
#define push_macro foobar2 |
#undef abort |
#define abort "111" |
printf("abort = %s\n", abort); |
#pragma push_macro("abort") |
#undef abort |
#define abort "222" |
printf("abort = %s\n", abort); |
#pragma push_macro("abort") |
#undef abort |
#define abort "333" |
printf("abort = %s\n", abort); |
#pragma pop_macro("abort") |
printf("abort = %s\n", abort); |
#pragma pop_macro("abort") |
printf("abort = %s\n", abort); |
} |
/programs/develop/ktcc/trunk/source/tests/tests2/77_push_pop_macro.expect |
---|
0,0 → 1,5 |
abort = 111 |
abort = 222 |
abort = 333 |
abort = 222 |
abort = 111 |
/programs/develop/ktcc/trunk/source/tests/tests2/78_vla_label.c |
---|
0,0 → 1,45 |
#include <stdio.h> |
/* This test segfaults as of April 27, 2015. */ |
void f1(int argc) |
{ |
char test[argc]; |
if(0) |
label: |
printf("boom!\n"); |
if(argc-- == 0) |
return; |
goto label; |
} |
/* This segfaulted on 2015-11-19. */ |
void f2(void) |
{ |
goto start; |
{ |
int a[1 && 1]; /* not a variable-length array */ |
int b[1 || 1]; /* not a variable-length array */ |
int c[1 ? 1 : 1]; /* not a variable-length array */ |
start: |
a[0] = 0; |
b[0] = 0; |
c[0] = 0; |
} |
} |
void f3(void) |
{ |
printf("%d\n", 0 ? printf("x1\n") : 11); |
printf("%d\n", 1 ? 12 : printf("x2\n")); |
printf("%d\n", 0 && printf("x3\n")); |
printf("%d\n", 1 || printf("x4\n")); |
} |
int main() |
{ |
f1(2); |
f2(); |
f3(); |
return 0; |
} |
/programs/develop/ktcc/trunk/source/tests/tests2/78_vla_label.expect |
---|
0,0 → 1,6 |
boom! |
boom! |
11 |
12 |
1 |
/programs/develop/ktcc/trunk/source/tests/tests2/79_vla_continue.c |
---|
0,0 → 1,116 |
#include <stdio.h> |
int f(void) |
{ |
return 5; |
} |
void test1() |
{ |
int count = 10; |
void *addr[10]; |
for(;count--;) { |
int a[f()]; |
addr[count] = a; |
continue; |
} |
if(addr[9] == addr[0]) { |
printf("OK\n"); |
} else { |
printf("NOT OK\n"); |
} |
} |
void test2() |
{ |
int count = 10; |
void *addr[count]; |
for(;count--;) { |
int a[f()]; |
addr[count] = a; |
continue; |
} |
if(addr[9] == addr[0]) { |
printf("OK\n"); |
} else { |
printf("NOT OK\n"); |
} |
} |
void test3() |
{ |
int count = 10; |
void *addr[count]; |
while(count--) { |
int a[f()]; |
addr[count] = a; |
continue; |
} |
if(addr[9] == addr[0]) { |
printf("OK\n"); |
} else { |
printf("NOT OK\n"); |
} |
} |
void test4() |
{ |
int count = 10; |
void *addr[count]; |
do { |
int a[f()]; |
addr[--count] = a; |
continue; |
} while (count); |
if(addr[9] == addr[0]) { |
printf("OK\n"); |
} else { |
printf("NOT OK\n"); |
} |
} |
void test5() |
{ |
int count = 10; |
int a[f()]; |
int c[f()]; |
c[0] = 42; |
for(;count--;) { |
int b[f()]; |
int i; |
for (i=0; i<f(); i++) { |
b[i] = count; |
} |
} |
if (c[0] == 42) { |
printf("OK\n"); |
} else { |
printf("NOT OK\n"); |
} |
} |
int main(void) |
{ |
test1(); |
test2(); |
test3(); |
test4(); |
test5(); |
return 0; |
} |
/programs/develop/ktcc/trunk/source/tests/tests2/79_vla_continue.expect |
---|
0,0 → 1,5 |
OK |
OK |
OK |
OK |
OK |
/programs/develop/ktcc/trunk/source/tests/tests2/80_flexarray.c |
---|
0,0 → 1,25 |
#include <stdio.h> |
struct wchar { |
char *data; char mem[]; |
}; |
struct wint { |
char *data; int mem[]; |
}; |
int f1char (void) { |
char s[9]="nonono"; |
struct wchar q = {"bugs"}; |
return !s[0]; |
} |
int f1int (void) { |
char s[9]="nonono"; |
struct wint q = {"bugs"}; |
return !s[0]; |
} |
int main (void) { |
char s[9]="nonono"; |
static struct wchar q = {"bugs", {'c'}}; |
//printf ("tcc has %s %s\n", s, q.data); |
if (f1char() || f1int()) |
printf ("bla\n"); |
return !s[0]; |
} |
/programs/develop/ktcc/trunk/source/tests/tests2/80_flexarray.expect |
---|
--- tests2/81_types.c (nonexistent) |
+++ tests2/81_types.c (revision 6429) |
@@ -0,0 +1,9 @@ |
+/* The following are all valid decls, even though some subtypes |
+ are incomplete. */ |
+enum E *e; |
+const enum E *e1; |
+enum E const *e2; |
+struct S *s; |
+const struct S *s1; |
+struct S const *s2; |
+int main () { return 0; } |
/programs/develop/ktcc/trunk/source/tests/tests2/81_types.expect |
---|
--- tests2/82_attribs_position.c (nonexistent) |
+++ tests2/82_attribs_position.c (revision 6429) |
@@ -0,0 +1,14 @@ |
+typedef unsigned short uint16_t; |
+typedef unsigned char uint8_t; |
+ |
+typedef union Unaligned16a { |
+ uint16_t u; |
+ uint8_t b[2]; |
+} __attribute__((packed)) Unaligned16a; |
+ |
+typedef union __attribute__((packed)) Unaligned16b { |
+ uint16_t u; |
+ uint8_t b[2]; |
+} Unaligned16b; |
+ |
+int main () { return 0; } |
/programs/develop/ktcc/trunk/source/tests/tests2/82_attribs_position.expect |
---|
--- tests2/82_nocode_wanted.c (nonexistent) |
+++ tests2/82_nocode_wanted.c (revision 6429) |
@@ -0,0 +1,80 @@ |
+extern int printf(const char *format, ...); |
+static void kb_wait_1(void) |
+{ |
+ unsigned long timeout = 2; |
+ do { |
+ (1 ? |
+ printf("timeout=%ld\n", timeout) : |
+ ({ |
+ while (1) |
+ printf("error\n"); |
+ }) |
+ ); |
+ timeout--; |
+ } while (timeout); |
+} |
+static void kb_wait_2(void) |
+{ |
+ unsigned long timeout = 2; |
+ do { |
+ (1 ? |
+ printf("timeout=%ld\n", timeout) : |
+ ({ |
+ for (;;) |
+ printf("error\n"); |
+ }) |
+ ); |
+ timeout--; |
+ } while (timeout); |
+} |
+static void kb_wait_3(void) |
+{ |
+ unsigned long timeout = 2; |
+ do { |
+ (1 ? |
+ printf("timeout=%ld\n", timeout) : |
+ ({ |
+ int i = 1; |
+ goto label; |
+ i = i + 2; |
+ label: |
+ i = i + 3; |
+ }) |
+ ); |
+ timeout--; |
+ } while (timeout); |
+} |
+static void kb_wait_4(void) |
+{ |
+ unsigned long timeout = 2; |
+ do { |
+ (1 ? |
+ printf("timeout=%ld\n", timeout) : |
+ ({ |
+ switch(timeout) { |
+ case 2: |
+ printf("timeout is 2"); |
+ break; |
+ case 1: |
+ printf("timeout is 1"); |
+ break; |
+ default: |
+ printf("timeout is 0?"); |
+ break; |
+ }; |
+ // return; |
+ }) |
+ ); |
+ timeout--; |
+ } while (timeout); |
+} |
+int main() |
+{ |
+ printf("begin\n"); |
+ kb_wait_1(); |
+ kb_wait_2(); |
+ kb_wait_3(); |
+ kb_wait_4(); |
+ printf("end\n"); |
+ return 0; |
+} |
/programs/develop/ktcc/trunk/source/tests/tests2/82_nocode_wanted.expect |
---|
0,0 → 1,10 |
begin |
timeout=2 |
timeout=1 |
timeout=2 |
timeout=1 |
timeout=2 |
timeout=1 |
timeout=2 |
timeout=1 |
end |
/programs/develop/ktcc/trunk/source/tests/tests2/83_utf8_in_identifiers.c |
---|
0,0 → 1,9 |
#include <stdio.h> |
double привет=0.1; |
int Lefèvre=2; |
int main(){ |
printf("привет=%f\n",привет); |
printf("Lefèvre=%d\n",Lefèvre); |
return 0; |
} |
// pcc & tcc only |
/programs/develop/ktcc/trunk/source/tests/tests2/83_utf8_in_identifiers.expect |
---|
0,0 → 1,2 |
привет=0.1 |
Lefèvre=2 |
/programs/develop/ktcc/trunk/source/tests/tests2/LICENSE |
---|
0,0 → 1,37 |
The tests in this directory are either directly copied from the picoc project or |
are subsequently modified and added to for the purpose of TinyCC project. All |
these modifications are licensed under the same terms as TinyCC as specified in |
the file COPYING. |
=== picoc license === |
Copyright (c) 2009-2011, Zik Saleeba |
All rights reserved. |
Redistribution and use in source and binary forms, with or without |
modification, are permitted provided that the following conditions are |
met: |
* Redistributions of source code must retain the above copyright |
notice, this list of conditions and the following disclaimer. |
* Redistributions in binary form must reproduce the above copyright |
notice, this list of conditions and the following disclaimer in |
the documentation and/or other materials provided with the |
distribution. |
* Neither the name of the Zik Saleeba nor the names of its |
contributors may be used to endorse or promote products derived |
from this software without specific prior written permission. |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
/programs/develop/ktcc/trunk/source/tests/tests2/Makefile |
---|
0,0 → 1,76 |
TOP = ../.. |
include $(TOP)/Makefile |
# clear CFLAGS and LDFLAGS |
CFLAGS := |
LDFLAGS := |
ifdef CONFIG_WIN32 |
TCCFLAGS = -B$(top_srcdir)/win32 -I$(top_srcdir)/include -L$(TOP) |
else |
TCCFLAGS = -B$(TOP) -I$(top_srcdir)/include -lm |
endif |
ifeq ($(TARGETOS),Darwin) |
CFLAGS += -Wl,-flat_namespace,-undefined,warning |
TCCFLAGS += -D_ANSI_SOURCE |
export MACOSX_DEPLOYMENT_TARGET:=10.2 |
endif |
TCC = $(TOP)/tcc $(TCCFLAGS) |
TESTS = $(patsubst %.c,%.test,$(sort $(wildcard *.c))) |
# 34_array_assignment.test -- array assignment is not in C standard |
SKIP = 34_array_assignment.test |
# some tests do not pass on all platforms, remove them for now |
ifeq ($(CONFIG_arm_eabi),yes) # not ARM soft-float |
SKIP += 22_floating_point.test |
endif |
ifeq ($(TARGETOS),Darwin) |
SKIP += 40_stdio.test |
endif |
ifdef CONFIG_WIN32 |
SKIP += 24_math_library.test # don't have round() |
SKIP += 28_strings.test # don't have r/index() / strings.h |
endif |
ifeq ($(ARCH),x86-64) |
SKIP += 73_arm64.test |
endif |
# Some tests might need arguments |
ARGS = |
31_args.test : ARGS = arg1 arg2 arg3 arg4 arg5 |
46_grep.test : ARGS = '[^* ]*[:a:d: ]+\:\*-/: $$' 46_grep.c |
# Some tests might need different flags |
FLAGS = |
76_dollars_in_identifiers.test : FLAGS = -fdollars-in-identifiers |
# Filter some always-warning |
FILTER = |
ifeq (-$(findstring arm,$(ARCH))-,-arm-) |
FILTER = 2>&1 | grep -v 'warning: soft float ABI currently not supported' |
endif |
all test: $(filter-out $(SKIP),$(TESTS)) |
%.test: %.c %.expect |
@echo Test: $*... |
# test -run |
@$(TCC) $(FLAGS) -run $< $(ARGS) $(FILTER) >$*.output 2>&1 || true |
@diff -Nbu $*.expect $*.output && rm -f $*.output |
# test exe (disabled for speed) |
# @($(TCC) $(FLAGS) $< -o $*.exe && ./$*.exe $(ARGS)) $(FiLTER) >$*.output2 2>&1 ; \ |
# diff -Nbu $*.expect $*.output2 && rm -f $*.output2 $*.exe |
# automatically generate .expect files with gcc: |
%.expect : |
(gcc $*.c -o a.exe && ./a.exe $(ARGS)) >$*.expect 2>&1; rm -f a.exe |
# tell make not to delete |
.PRECIOUS: %.expect |
clean: |
rm -vf fred.txt *.output a.exe |
/programs/develop/ktcc/trunk/source/tests/vla_test.c |
---|
0,0 → 1,84 |
/* |
* Test that allocating a variable length array in a loop |
* does not use up a linear amount of memory |
*/ |
#include <stdlib.h> |
#include <stdio.h> |
#include <string.h> |
#define LOOP_COUNT 1000 |
#define ARRAY_SIZE 100 |
/* Overwrite a VLA. This will overwrite the return address if SP is incorrect */ |
void smash(char *p, int n) { |
memset(p, 0, n); |
} |
int test1(int n) { |
int i; |
char *array_ptrs[LOOP_COUNT]; |
for (i = 0; i < LOOP_COUNT; ++i) { |
char test[n]; |
smash(test, n); |
array_ptrs[i] = test; |
} |
return (array_ptrs[0]-array_ptrs[LOOP_COUNT-1] < n) ? 0 : 1; |
} |
/* ensure goto does not circumvent array free */ |
int test2(int n) { |
char *array_ptrs[LOOP_COUNT]; |
int i = 0; |
loop:; |
char test[n]; |
smash(test, n); |
if (i >= LOOP_COUNT) |
goto end; |
array_ptrs[i] = test; |
++i; |
goto loop; |
end: |
smash(test, n); |
char test2[n]; |
smash(test2, n); |
return (array_ptrs[0] - array_ptrs[LOOP_COUNT-1] < n) ? 0 : 1; |
} |
int test3(int n) { |
char test[n]; |
smash(test, n); |
goto label; |
label: |
smash(test, n); |
char test2[n]; |
smash(test2, n); |
return (test-test2 >= n) ? 0 : 1; |
} |
#define RUN_TEST(t) \ |
if (!testname || (strcmp(#t, testname) == 0)) { \ |
fputs(#t "... ", stdout); \ |
fflush(stdout); \ |
if (t(ARRAY_SIZE) == 0) { \ |
fputs("success\n", stdout); \ |
} else { \ |
fputs("failure\n", stdout); \ |
retval = EXIT_FAILURE; \ |
} \ |
} |
int main(int argc, char **argv) { |
const char *testname = NULL; |
int retval = EXIT_SUCCESS; |
if (argc > 1) |
testname = argv[1]; |
RUN_TEST(test1) |
RUN_TEST(test2) |
RUN_TEST(test3) |
return retval; |
} |