History

update

bellard committed 23 years ago

Commit 75e743d1 parent 7808b404 files · +347 −24Browse files

Unified · Split

4 files
  1. Makefile +20 −13
  2. TODO +21 −9
  3. tcc-doc.texi +126 −1
  4. tcctest.c +180 −1
Makefile+20−13
@@ -13,7 +13,7 @@ CFLAGS+=-m386 -malign-functions=0 -mpreferred-stack-boundary=2 · 12 unmodified lines
13CFLAGS+=-DCONFIG_TCC_PREFIX=\"$(prefix)\"13CFLAGS+=-DCONFIG_TCC_PREFIX=\"$(prefix)\"
14DISAS=objdump -d14DISAS=objdump -d
15INSTALL=install15INSTALL=install
16VERSION=0.9.1516VERSION=0.9.16
17 17
18# run local version of tcc with local libraries and includes18# run local version of tcc with local libraries and includes
19TCC=./tcc -B. -I.19TCC=./tcc -B. -I.
@@ -103,7 +103,7 @@ ex3: ex3.c · 83 unmodified lines
103 103
104# Native Tiny C Compiler104# Native Tiny C Compiler
105 105
106tcc_g: tcc.c i386-gen.c tccelf.c tcctok.h libtcc.h Makefile106tcc_g: tcc.c i386-gen.c tccelf.c tccasm.c i386-asm.c tcctok.h libtcc.h i386-asm.h Makefile
107 gcc $(CFLAGS) -o $@ $< $(LIBS)107 gcc $(CFLAGS) -o $@ $< $(LIBS)
108 108
109tcc: tcc_g109tcc: tcc_g
@@ -128,17 +128,9 @@ install: tcc libtcc1.o bcheck.o · 18 unmodified lines
128clean:128clean:
129 rm -f *~ *.o tcc tcc1 tcct tcc_g tcctest.ref *.bin *.i ex2 \129 rm -f *~ *.o tcc tcc1 tcct tcc_g tcctest.ref *.bin *.i ex2 \
130 core gmon.out test.out test.ref a.out tcc_p \130 core gmon.out test.out test.ref a.out tcc_p \
131 *.exe iltcc iltcc_g tcc-doc.html \131 *.exe tcc-doc.html \
132 tcctest[1234] test[1234].out132 tcctest[1234] test[1234].out
133 133
134# IL TCC
135
136iltcc_g: tcc.c il-gen.c bcheck.c Makefile
137 gcc $(CFLAGS) -DTCC_TARGET_IL -o $@ $< $(LIBS)
138
139iltcc: iltcc_g
140 strip -s -R .comment -R .note -o $@ $<
141
142# win32 TCC134# win32 TCC
143tcc_g.exe: tcc.c i386-gen.c bcheck.c Makefile135tcc_g.exe: tcc.c i386-gen.c bcheck.c Makefile
144 i386-mingw32msvc-gcc $(CFLAGS) -DCONFIG_TCC_STATIC -o $@ $<136 i386-mingw32msvc-gcc $(CFLAGS) -DCONFIG_TCC_STATIC -o $@ $<
@@ -176,6 +168,22 @@ libtest: libtcc_test · 31 unmodified lines
176instr: instr.o168instr: instr.o
177 objdump -d instr.o169 objdump -d instr.o
178 170
171# tiny assembler testing
172
173asmtest.ref: asmtest.S
174 gcc -c -o asmtest.ref.o asmtest.S
175 objdump -D asmtest.ref.o > $@
176
177# XXX: we compute tcc.c to go faster during development !
178asmtest.out: asmtest.S tcc
179# ./tcc tcc.c -c asmtest.S
180#asmtest.out: asmtest.S tcc
181 ./tcc -c asmtest.S
182 objdump -D asmtest.o > $@
183
184asmtest: asmtest.out asmtest.ref
185 @if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
186
179instr.o: instr.S187instr.o: instr.S
180 gcc -O2 -Wall -g -c -o $@ $<188 gcc -O2 -Wall -g -c -o $@ $<
181 189
@@ -191,9 +199,8 @@ FILES= Makefile Makefile.uClibc \ · 9 unmodified lines
191 README TODO COPYING \199 README TODO COPYING \
192 Changelog tcc-doc.texi tcc-doc.html \200 Changelog tcc-doc.texi tcc-doc.html \
193 tcc.1 \201 tcc.1 \
194 tcc.c i386-gen.c tccelf.c tcctok.h \202 tcc.c i386-gen.c tccelf.c tcctok.h tccasm.c i386-asm.c i386-asm.h\
195 bcheck.c libtcc1.c \203 bcheck.c libtcc1.c \
196 il-opcodes.h il-gen.c \
197 elf.h stab.h stab.def \204 elf.h stab.h stab.def \
198 stddef.h stdarg.h stdbool.h float.h varargs.h \205 stddef.h stdarg.h stdbool.h float.h varargs.h \
199 tcclib.h libtcc.h libtcc_test.c \206 tcclib.h libtcc.h libtcc_test.c \
TODO+21−9
@@ -1,21 +1,33 @@
1TODO list:1TODO list:
2 2
3- add statment expressions (linux kernel compilation)3- fix asm without input/output (no % preprocessing)
4- implement minimal 'asm' extension (linux kernel compilation)4- handle inline functions as macros.
5- handle static inline, then normal prototype.5- see transparent union pb in /urs/include/sys/socket.h
6- precise behaviour of typeof with arrays ? (__put_user macro)
7- #include_next support for /usr/include/limits ?
8 but should suffice for most cases)
9- handle '? x, y : z' in reversed function arguments or unsized
10 variable initialization (',' is considered incorrectly as separator
11 in preparser) : change func argument code generator ?
12- function pointers/lvalues in ? : (linux kernel net/core/dev.c)
13- add A x86 asm constraint (linux asm-i386/div64.h)
14- transform functions to function pointers in function parameters (net/ipv4/ip_output.c)
15- fix function pointer type display
16- fix bound exit on RedHat 7.3
17- fix static link on RedHat 7.3
18- check lcc test suite -> fix bitfield binary operations
19- check section alignment in C
20- fix invalid cast in comparison 'if (v == (int8_t)v)'
21- packed attribute
22- look at patches from Scott Lafferty
23- look at bugs from Jason Petrasko.
6- support link once trick (gcc 3.2 / glibc compilation issue)24- support link once trick (gcc 3.2 / glibc compilation issue)
7- finish varargs.h support (gcc 3.2 testsuite issue)25- finish varargs.h support (gcc 3.2 testsuite issue)
8- add alloca()26- add alloca()
9- fix static functions declared inside block27- fix static functions declared inside block
10- fix bitfield binary operations
11- C99: add variable size arrays (gcc 3.2 testsuite issue)28- C99: add variable size arrays (gcc 3.2 testsuite issue)
12- C99: add complex types (gcc 3.2 testsuite issue)29- C99: add complex types (gcc 3.2 testsuite issue)
13- ignore __extension__ keyword (see 20010328-1.c).
14- Add __restrict keyword (20010611-1.c).
15- postfix compound literals (see 20010124-1.c)30- postfix compound literals (see 20010124-1.c)
16- handle '? x, y : z' in reversed function arguments or unsized
17 variable initialization (',' is considered incorrectly as separator
18 in preparser) : use a "record" parse mode ?
19- fix multiple unions init31- fix multiple unions init
20- test includes in libtcc_test.32- test includes in libtcc_test.
21- look at GCC 3.2 compatibility problems.33- look at GCC 3.2 compatibility problems.
tcc-doc.texi+126−1
@@ -17,7 +17,7 @@ TCC compiles so @emph{fast} that even for big projects @code{Makefile}s may · 16 unmodified lines
17not be necessary. 17not be necessary.
18 18
19TCC not only supports ANSI C, but also most of the new ISO C9919TCC not only supports ANSI C, but also most of the new ISO C99
20standard and many GNUC extensions.20standard and many GNUC extensions including inline assembly.
21 21
22TCC can also be used to make @emph{C scripts}, i.e. pieces of C source22TCC can also be used to make @emph{C scripts}, i.e. pieces of C source
23that you run as a Perl or Python script. Compilation is so fast that23that you run as a Perl or Python script. Compilation is so fast that
@@ -70,6 +70,14 @@ link a.o and b.o together and generate the executable myprog. · 46 unmodified lines
70@item tcc -c a.c70@item tcc -c a.c
71Compile a.c and generate object file a.o71Compile a.c and generate object file a.o
72 72
73@item tcc -c asmfile.S
74Preprocess with C preprocess and assemble asmfile.S and generate
75object file asmfile.o.
76
77@item tcc -c asmfile.s
78Assemble (but not preprocess) asmfile.s and generate object file
79asmfile.o.
80
73@item tcc -r -o ab.o a.c b.c81@item tcc -r -o ab.o a.c b.c
74Compile a.c and b.c, link them together and generate the object file ab.o.82Compile a.c and b.c, link them together and generate the object file ab.o.
75 83
@@ -332,6 +340,31 @@ to get the alignment of a type or an expression. · 256 unmodified lines
332@code{void *} on the goto label @code{label}. @code{goto *expr} can be340@code{void *} on the goto label @code{label}. @code{goto *expr} can be
333used to jump on the pointer resulting from @code{expr}.341used to jump on the pointer resulting from @code{expr}.
334 342
343@item Inline assembly with asm instruction:
344@example
345static inline void * my_memcpy(void * to, const void * from, size_t n)
346{
347int d0, d1, d2;
348__asm__ __volatile__(
349 "rep ; movsl\n\t"
350 "testb $2,%b4\n\t"
351 "je 1f\n\t"
352 "movsw\n"
353 "1:\ttestb $1,%b4\n\t"
354 "je 2f\n\t"
355 "movsb\n"
356 "2:"
357 : "=&c" (d0), "=&D" (d1), "=&S" (d2)
358 :"0" (n/4), "q" (n),"1" ((long) to),"2" ((long) from)
359 : "memory");
360return (to);
361}
362@end example
363
364TCC includes its own x86 inline assembler with a @code{gas}-like (GNU
365assembler) syntax. No intermediate files are generated. GCC 3.x named
366operands are supported.
367
335@end itemize368@end itemize
336 369
337@section TinyCC extensions370@section TinyCC extensions
@@ -350,6 +383,98 @@ indicate that you use TCC. · 12 unmodified lines
350 383
351@end itemize384@end itemize
352 385
386@chapter TinyCC Assembler
387
388Since version 0.9.16, TinyCC integrates its own assembler. TinyCC
389assembler supports a gas-like syntax (GNU assembler). You can
390desactivate assembler support if you want a smaller TinyCC executable
391(the C compiler does not rely on the assembler).
392
393TinyCC Assembler is used to handle files with @file{.S} (C
394preprocessed assembler) and @file{.s} extensions. It is also used to
395handle the GNU inline assembler with the @code{asm} keyword.
396
397@section Syntax
398
399TinyCC Assembler supports most of the gas syntax. The tokens are the
400same as C.
401
402@itemize
403
404@item C and C++ comments are supported.
405
406@item Identifiers are the same as C, so you cannot use '.' or '$'.
407
408@item Only 32 bit integer numbers are supported.
409
410@end itemize
411
412@section Expressions
413
414@itemize
415
416@item Integers in decimal, octal and hexa are supported.
417
418@item Unary operators: +, -, ~.
419
420@item Binary operators in decreasing priority order:
421
422@enumerate
423@item *, /, %
424@item &, |, ^
425@item +, -
426@end enumerate
427
428@item A value is either an absolute number or a label plus an offset.
429All operators accept absolute values except '+' and '-'. '+' or '-' can be
430used to add an offset to a label. '-' supports two labels only if they
431are the same or if they are both defined and in the same section.
432
433@end itemize
434
435@section Labels
436
437@itemize
438
439@item All labels are considered as local, except undefined ones.
440
441@item Numeric labels can be used as local @code{gas}-like labels.
442They can be defined several times in the same source. Use 'b'
443(backward) or 'f' (forward) as suffix to reference them:
444
445@example
446 1:
447 jmp 1b /* jump to '1' label before */
448 jmp 1f /* jump to '1' label after */
449 1:
450@end example
451
452@end itemize
453
454@section Directives
455
456All directives are preceeded by a '.'. The following directives are
457supported:
458
459@itemize
460@item .align n[,value]
461@item .skip n[,value]
462@item .space n[,value]
463@item .byte value1[,value2...]
464@item .word value1[,value2...]
465@item .short value1[,value2...]
466@item .int value1[,value2...]
467@item .long value1[,value2...]
468@end itemize
469
470@section X86 Assembler
471
472All X86 opcodes are supported. Only ATT syntax is supported (source
473then destination operand order). If no size suffix is given, TinyCC
474tries to guess it from the operand sizes.
475
476Currently, MMX opcodes are supported but not SSE ones.
477
353@chapter TinyCC Linker478@chapter TinyCC Linker
354 479
355@section ELF file generation480@section ELF file generation
tcctest.c+180−1
@@ -67,6 +67,9 @@ void relocation_test(void); · 66 unmodified lines
67void old_style_function(void);67void old_style_function(void);
68void sizeof_test(void);68void sizeof_test(void);
69void typeof_test(void);69void typeof_test(void);
70void local_label_test(void);
71void statement_expr_test(void);
72void asm_test(void);
70 73
71int fib(int n);74int fib(int n);
72void num(int n);75void num(int n);
@@ -200,7 +203,7 @@ void macro_test(void) · 127 unmodified lines
200#line 203 "test" 203#line 203 "test"
201 printf("__LINE__=%d __FILE__=%s\n",204 printf("__LINE__=%d __FILE__=%s\n",
202 __LINE__, __FILE__);205 __LINE__, __FILE__);
203#line 200 "tcctest.c"206#line 206 "tcctest.c"
204 207
205 /* not strictly preprocessor, but we test it there */208 /* not strictly preprocessor, but we test it there */
206#ifdef C99_MACROS209#ifdef C99_MACROS
@@ -467,6 +470,9 @@ int main(int argc, char **argv) · 260 unmodified lines
467 old_style_function();470 old_style_function();
468 sizeof_test();471 sizeof_test();
469 typeof_test();472 typeof_test();
473 statement_expr_test();
474 local_label_test();
475 asm_test();
470 return 0; 476 return 0;
471}477}
472 478
@@ -839,6 +845,16 @@ void bool_test() · 366 unmodified lines
839 }845 }
840 }846 }
841 847
848 /* test ? : GCC extension */
849 {
850 static int v1 = 34 ? : -1; /* constant case */
851 static int v2 = 0 ? : -1; /* constant case */
852 int a = 30;
853
854 printf("%d %d\n", v1, v2);
855 printf("%d %d\n", a - 30 ? : a * 2, a + 1 ? : a * 2);
856 }
857
842 /* again complex expression */858 /* again complex expression */
843 for(i=0;i<256;i++) {859 for(i=0;i<256;i++) {
844 if (toupper1 (i) != TOUPPER (i))860 if (toupper1 (i) != TOUPPER (i))
@@ -846,7 +862,13 @@ void bool_test() · 1 unmodified line
846 }862 }
847}863}
848 864
865/* GCC accepts that */
866static int tab_reinit[];
867static int tab_reinit[10];
849 868
869//int cinit1; /* a global variable can be defined several times without error ! */
870int cinit1;
871int cinit1;
850int cinit1 = 0;872int cinit1 = 0;
851int *cinit2 = (int []){3, 2, 1};873int *cinit2 = (int []){3, 2, 1};
852 874
@@ -1072,6 +1094,12 @@ struct bar { · 219 unmodified lines
1072 "a2", 11094 "a2", 1
1073};1095};
1074 1096
1097int sinit18[10] = {
1098 [2 ... 5] = 20,
1099 2,
1100 [8] = 10,
1101};
1102
1075void init_test(void)1103void init_test(void)
1076{1104{
1077 int linit1 = 2;1105 int linit1 = 2;
@@ -1161,8 +1189,12 @@ void init_test(void) · 83 unmodified lines
1161 printf("sinit17=%s %d %s %d\n",1189 printf("sinit17=%s %d %s %d\n",
1162 sinit17[0].s, sinit17[0].len,1190 sinit17[0].s, sinit17[0].len,
1163 sinit17[1].s, sinit17[1].len);1191 sinit17[1].s, sinit17[1].len);
1192 for(i=0;i<10;i++)
1193 printf("%x ", sinit18[i]);
1194 printf("\n");
1164}1195}
1165 1196
1197
1166void switch_test()1198void switch_test()
1167{1199{
1168 int i;1200 int i;
@@ -1659,3 +1691,150 @@ void typeof_test(void) · 490 unmodified lines
1659 c = 3.5;1691 c = 3.5;
1660 printf("a=%f b=%f c=%f\n", a, b, c);1692 printf("a=%f b=%f c=%f\n", a, b, c);
1661}1693}
1694
1695void statement_expr_test(void)
1696{
1697 int a, i;
1698
1699 a = 0;
1700 for(i=0;i<10;i++) {
1701 a += 1 +
1702 ( { int b, j;
1703 b = 0;
1704 for(j=0;j<5;j++)
1705 b += j; b;
1706 } );
1707 }
1708 printf("a=%d\n", a);
1709
1710}
1711
1712void local_label_test(void)
1713{
1714 int a;
1715 goto l1;
1716 l2:
1717 a = 1 + ({
1718 __label__ l1, l2, l3;
1719 goto l4;
1720 l5:
1721 printf("aa1\n");
1722 goto l1;
1723 l2:
1724 printf("aa3\n");
1725 goto l3;
1726 l1:
1727 printf("aa2\n");
1728 goto l2;
1729 l3:;
1730 1;
1731 });
1732 printf("a=%d\n", a);
1733 return;
1734 l1:
1735 printf("bb1\n");
1736 goto l2;
1737 l4:
1738 printf("bb2\n");
1739 goto l5;
1740}
1741
1742/* inline assembler test */
1743#ifdef __i386__
1744
1745/* from linux kernel */
1746static char * strncat1(char * dest,const char * src,size_t count)
1747{
1748int d0, d1, d2, d3;
1749__asm__ __volatile__(
1750 "repne\n\t"
1751 "scasb\n\t"
1752 "decl %1\n\t"
1753 "movl %8,%3\n"
1754 "1:\tdecl %3\n\t"
1755 "js 2f\n\t"
1756 "lodsb\n\t"
1757 "stosb\n\t"
1758 "testb %%al,%%al\n\t"
1759 "jne 1b\n"
1760 "2:\txorl %2,%2\n\t"
1761 "stosb"
1762 : "=&S" (d0), "=&D" (d1), "=&a" (d2), "=&c" (d3)
1763 : "0" (src),"1" (dest),"2" (0),"3" (0xffffffff), "g" (count)
1764 : "memory");
1765return dest;
1766}
1767
1768static inline void * memcpy1(void * to, const void * from, size_t n)
1769{
1770int d0, d1, d2;
1771__asm__ __volatile__(
1772 "rep ; movsl\n\t"
1773 "testb $2,%b4\n\t"
1774 "je 1f\n\t"
1775 "movsw\n"
1776 "1:\ttestb $1,%b4\n\t"
1777 "je 2f\n\t"
1778 "movsb\n"
1779 "2:"
1780 : "=&c" (d0), "=&D" (d1), "=&S" (d2)
1781 :"0" (n/4), "q" (n),"1" ((long) to),"2" ((long) from)
1782 : "memory");
1783return (to);
1784}
1785
1786static __inline__ void sigaddset1(unsigned int *set, int _sig)
1787{
1788 __asm__("btsl %1,%0" : "=m"(*set) : "Ir"(_sig - 1) : "cc");
1789}
1790
1791static __inline__ void sigdelset1(unsigned int *set, int _sig)
1792{
1793 asm("btrl %1,%0" : "=m"(*set) : "Ir"(_sig - 1) : "cc");
1794}
1795
1796static __inline__ __const__ unsigned int swab32(unsigned int x)
1797{
1798 __asm__("xchgb %b0,%h0\n\t" /* swap lower bytes */
1799 "rorl $16,%0\n\t" /* swap words */
1800 "xchgb %b0,%h0" /* swap higher bytes */
1801 :"=q" (x)
1802 : "0" (x));
1803 return x;
1804}
1805
1806unsigned int set;
1807
1808void asm_test(void)
1809{
1810 char buf[128];
1811 unsigned int val;
1812
1813 printf("inline asm:\n");
1814 memcpy1(buf, "hello", 6);
1815 strncat1(buf, " worldXXXXX", 3);
1816 printf("%s\n", buf);
1817
1818 set = 0xff;
1819 sigdelset1(&set, 2);
1820 sigaddset1(&set, 16);
1821 /* NOTE: we test here if C labels are correctly restored after the
1822 asm statement */
1823 goto label1;
1824 label2:
1825 __asm__("btsl %1,%0" : "=m"(set) : "Ir"(20) : "cc");
1826 printf("set=0x%x\n", set);
1827 val = 0x01020304;
1828 printf("swab32(0x%08x) = 0x%0x\n", val, swab32(val));
1829 return;
1830 label1:
1831 goto label2;
1832}
1833
1834#else
1835
1836void asm_test(void)
1837{
1838}
1839
1840#endif

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t