History

update

bellard committed 24 years ago

Commit ebe9e871 parent fd20e743 files · +199 −64Browse files

Unified · Split

3 files
  1. README +12 −24
  2. TODO +10 −8
  3. tcc-doc.texi +177 −32
README+12−24
@@ -15,6 +15,9 @@ Features: · 14 unmodified lines
15 heading torward full ISOC99 compliance. TCC can of course compile15 heading torward full ISOC99 compliance. TCC can of course compile
16 itself.16 itself.
17 17
18- SAFE! tcc includes an optional memory and bound checker. Bound
19 checked code can be mixed freely with standard code.
20
18- Compile and execute C source directly. No linking or assembly21- Compile and execute C source directly. No linking or assembly
19 necessary. Full C preprocessor included. 22 necessary. Full C preprocessor included.
20 23
@@ -27,7 +30,7 @@ Documentation: · 6 unmodified lines
27 30
281) Installation311) Installation
29 32
30***TCC currently only works on Linux x86***.33*** TCC currently only works on Linux x86 with glibc >= 2.1 ***.
31 34
32Type 'make install' to compile and install tcc in /usr/local/bin and35Type 'make install' to compile and install tcc in /usr/local/bin and
33/usr/local/lib/tcc.36/usr/local/lib/tcc.
@@ -49,21 +52,7 @@ launch the C code as a shell or perl script :-) The command line · 15 unmodified lines
49arguments are put in 'argc' and 'argv' of the main functions, as in52arguments are put in 'argc' and 'argv' of the main functions, as in
50ANSI C.53ANSI C.
51 54
523) Invokation553) Examples
53
54'-Idir' : specify an additionnal include path. The
55default ones are: /usr/include, /usr/lib/tcc, /usr/local/lib/tcc.
56
57'-Dsym' : define preprocessor symbol 'sym' to 1.
58
59'-lxxx' : dynamically link your program with library
60libxxx.so. Standard library paths are checked, including those
61specificed with LD_LIBRARY_PATH.
62
63'-i file' : compile C source 'file' before main C source. With this
64command, multiple C files can be compiled and linked together.
65
664) Examples
67 56
68ex1.c: simplest example (hello world). Can also be launched directly57ex1.c: simplest example (hello world). Can also be launched directly
69as a script: './ex1.c'.58as a script: './ex1.c'.
@@ -84,7 +73,7 @@ generator. · 14 unmodified lines
84prog.c: auto test for TCC which tests many subtle possible bugs. Used73prog.c: auto test for TCC which tests many subtle possible bugs. Used
85when doing 'make test'.74when doing 'make test'.
86 75
875) Full Documentation764) Full Documentation
88 77
89Please read tcc-doc.html to have all the features of TCC.78Please read tcc-doc.html to have all the features of TCC.
90 79
@@ -105,7 +94,7 @@ assembly), but it allows to be very fast and surprisingly not so · 14 unmodified lines
105complicated.94complicated.
106 95
107The TCC code generator is register based. It means that it could even96The TCC code generator is register based. It means that it could even
108generate good code for RISC processors. On x86, three temporary97generate not so bad code for RISC processors. On x86, three temporary
109registers are used. When more registers are needed, one register is98registers are used. When more registers are needed, one register is
110flushed in a new local variable.99flushed in a new local variable.
111 100
@@ -113,13 +102,12 @@ Constant propagation is done for all operations. Multiplications and · 1 unmodified line
113divisions are optimized to shifts when appropriate. Comparison102divisions are optimized to shifts when appropriate. Comparison
114operators are optimized by maintaining a special cache for the103operators are optimized by maintaining a special cache for the
115processor flags. &&, || and ! are optimized by maintaining a special104processor flags. &&, || and ! are optimized by maintaining a special
116'jmp target' value. No other jmp optimization is currently performed105'jump target' value. No other jump optimization is currently performed
117because it would require to store the code in a more abstract fashion.106because it would require to store the code in a more abstract fashion.
118 107
119The types and values descriptions are stored in a single 'int'108The types are stored in a single 'int' variable (see VT_xxx
120variable (see VT_xxx constants). It was choosen in the first stages of109constants). It was choosen in the first stages of development when tcc
121development when tcc was much simpler. Now, it may not be the best110was much simpler. Now, it may not be the best solution.
122solution.
123 111
124License:112License:
125-------113-------
@@ -130,4 +118,4 @@ file). · 4 unmodified lines
130I accept only patches where you give your copyright explicitely to me118I accept only patches where you give your copyright explicitely to me
131to simplify licensing issues.119to simplify licensing issues.
132 120
133Fabrice Bellard - Nov 17, 2001.121Fabrice Bellard.
TODO+10−8
@@ -1,25 +1,27 @@
1TODO list:1TODO list:
2 2
3Critical:3Critical:
4- finish float/double support. add function type convertion.4- optimize slightly bound checking when doing addition + dereference.
5- section generation and GNUC __attributte__ handling.5- better section generator (suppress some mmaps).
6- D option with '=' handling6- To check: bound checking and float/long long/struct copy code
7- 0 is pointer - fix type compare
8- To check: 'sizeof' may not work if too complex expression is given.7- To check: 'sizeof' may not work if too complex expression is given.
9- fix 'char' and 'short' casts (only in function parameters and in8- fix bound check code with '&' on local variables (currently done
10 assignment).9 only for local arrays).
11 10
12Not critical:11Not critical:
13 12
14- interactive mode13- add PowerPC or ARM code generator and improve codegen for RISC (need
14 to suppress VT_LOCAL and use a base register instead).
15- interactive mode / integrated debugger
15- fix multiple compound literals inits in blocks (ISOC99 normative16- fix multiple compound literals inits in blocks (ISOC99 normative
16 example - only relevant when using gotos! -> must add boolean17 example - only relevant when using gotos! -> must add boolean
17 variable to tell if compound literal was already initialized).18 variable to tell if compound literal was already initialized).
19- add more bounds checked functions (strcpy, ...)
18- fix L"\x1234" wide string case (need to store them as utf8 ?)20- fix L"\x1234" wide string case (need to store them as utf8 ?)
19- fix preprocessor symbol redefinition21- fix preprocessor symbol redefinition
20- better constant opt (&&, ||, ?:)22- better constant opt (&&, ||, ?:)
21- add ELF executable and shared library output option (would be needed23- add ELF executable and shared library output option (would be needed
22 for completness!).24 for completness!).
23- add PowerPC code generator.25- D option with all #define cases (needs C parser)
24- add portable byte code generator and interpreter for other26- add portable byte code generator and interpreter for other
25 unsupported architectures.27 unsupported architectures.
tcc-doc.texi+177−32
@@ -14,49 +14,51 @@ Tiny C Compiler Reference Documentation · 13 unmodified lines
14 14
15<h2>Introduction</h2>15<h2>Introduction</h2>
16 16
17TinyCC (aka TCC) is a small but very fast C compiler. Unlike other C17TinyCC (aka TCC) is a small but hyper fast C compiler. Unlike other C
18compilers, it is meant to be self-suffisant: you do not need an18compilers, it is meant to be self-suffisant: you do not need an
19external assembler or linker because TCC does that for you.19external assembler or linker because TCC does that for you.
20<P>20<P>
21 21TCC compiles so <em>fast</em> that even for big projects <tt>Makefile</tt>s may
22TCC compiles so fast that even for big projects <tt>Makefile</tt>s may
23not be necessary. 22not be necessary.
24<P>23<P>
24TCC not only supports ANSI C, but also most of the new ISO C99
25standard and many GNUC extensions.
26<P>
25TCC can also be used to make <I>C scripts</I>,27TCC can also be used to make <I>C scripts</I>,
26i.e. pieces of C source that you run as a Perl or Python28i.e. pieces of C source that you run as a Perl or Python
27script. Compilation is so fast that your script will be as fast as if29script. Compilation is so fast that your script will be as fast as if
28it was an executable.30it was an executable.
31<P>
32TCC can also automatically generate <A HREF="#bounds">memory and bound
33checks</A> while allowing all C pointers operations. TCC can do these
34checks even if non patched libraries are used.
35</P>
29 36
30<h2>Exact differences with ANSI C</h2>37<h2>Full ANSI C support</h2>
31 38
32TCC implements almost all the ANSI C standard, except floating points39TCC implements all the ANSI C standard, including structure bit fields
33numbers.40and floating point numbers (<tt>long double</tt>, <tt>double</tt>, and
41<tt>float</tt> fully supported). The following limitations are known:
34 42
35<ul>43<ul>
36 <li> The preprocessor tokens are the same as C. It means that in some44 <li> The preprocessor tokens are the same as C. It means that in some
37 rare cases, preprocessed numbers are not handled exactly as in ANSI45 rare cases, preprocessed numbers are not handled exactly as in ANSI
38 C. This approach has the advantage of being simpler and FAST!46 C. This approach has the advantage of being simpler and FAST!
39
40 <li> Floating point numbers are not fully supported yet (some
41 implicit casts are missing).
42
43 <li> Some typing errors are not signaled.
44</ul>47</ul>
45 48
46<h2>ISOC99 extensions</h2>49<h2>ISOC99 extensions</h2>
47 50
48TCC implements many features of the new C standard: ISO C99. Currently51TCC implements many features of the new C standard: ISO C99. Currently
49missing items are: complex and imaginary numbers (will come with ANSI52missing items are: complex and imaginary numbers and variable length
50C floating point numbers), <tt>long long</tt>s and variable length
51arrays.53arrays.
52 54
53Currently implemented ISOC99 features:55Currently implemented ISOC99 features:
54 56
55<ul>57<ul>
56 58
57<li> <tt>'inline'</tt> keyword is ignored.59<li> 64 bit <tt>'long long'</tt> types are fully supported.
58 60
59<li> <tt>'restrict'</tt> keyword is ignored.61<li> The boolean type <tt>'_Bool'</tt> is supported.
60 62
61<li> <tt>'__func__'</tt> is a string variable containing the current63<li> <tt>'__func__'</tt> is a string variable containing the current
62function name.64function name.
@@ -68,7 +70,7 @@ function name. · 5 unmodified lines
68</PRE>70</PRE>
69<tt>dprintf</tt> can then be used with a variable number of parameters.71<tt>dprintf</tt> can then be used with a variable number of parameters.
70 72
71<li> Declarations can appear anywhere in a block as in C++.73<li> Declarations can appear anywhere in a block (as in C++).
72 74
73<li> Array and struct/union elements can be initialized in any order by75<li> Array and struct/union elements can be initialized in any order by
74 using designators:76 using designators:
@@ -85,11 +87,6 @@ function name. · 10 unmodified lines
85to initialize a pointer pointing to an initialized array. The same87to initialize a pointer pointing to an initialized array. The same
86works for structures and strings.88works for structures and strings.
87 89
88<li> The boolean type <tt>'_Bool'</tt> is supported.
89
90<li> <tt>'long long'</tt> types not supported yet, except in type
91 definition or <tt>'sizeof'</tt>.
92
93<li> Hexadecimal floating point constants are supported:90<li> Hexadecimal floating point constants are supported:
94<PRE>91<PRE>
95 double d = 0x1234p10;92 double d = 0x1234p10;
@@ -98,11 +95,15 @@ is the same as writing · 2 unmodified lines
98<PRE>95<PRE>
99 double d = 4771840.0;96 double d = 4771840.0;
100</PRE>97</PRE>
98
99<li> <tt>'inline'</tt> keyword is ignored.
100
101<li> <tt>'restrict'</tt> keyword is ignored.
101</ul>102</ul>
102 103
103<h2>GNU C extensions</h2>104<h2>GNU C extensions</h2>
104 105
105TCC implements some GNU C extensions which are found in many C sources:106TCC implements some GNU C extensions:
106 107
107<ul>108<ul>
108 109
@@ -122,6 +123,45 @@ instead of · 13 unmodified lines
122 123
123<li> <tt>'\e'</tt> is ASCII character 27.124<li> <tt>'\e'</tt> is ASCII character 27.
124 125
126<li> case ranges : ranges can be used in <tt>case</tt>s:
127<PRE>
128 switch(a) {
129 case 1 ... 9:
130 printf("range 1 to 9\n");
131 break;
132 default:
133 printf("unexpected\n");
134 break;
135 }
136</PRE>
137
138<li> The keyword <tt>__attribute__</tt> is handled to specify variable or
139function attributes. The following attributes are supported:
140 <ul>
141 <li> <tt>aligned(n)</tt>: align data to n bytes (must be a power of two).
142
143 <li> <tt>section(name)</tt>: generate function or data in assembly
144 section name (name is a string containing the section name) instead
145 of the default section.
146
147 <li> <tt>unused</tt>: specify that the variable or the function is unused.
148 </ul>
149<BR>
150Here are some examples:
151<PRE>
152 int a __attribute__ ((aligned(8), section(".mysection")));
153</PRE>
154<BR>
155align variable <tt>'a'</tt> to 8 bytes and put it in section <tt>.mysection</tt>.
156
157<PRE>
158 int my_add(int a, int b) __attribute__ ((section(".mycodesection")))
159 {
160 return a + b;
161 }
162</PRE>
163<BR>
164generate function <tt>'my_add'</tt> in section <tt>.mycodesection</tt>.
125</ul>165</ul>
126 166
127<h2>TinyCC extensions</h2>167<h2>TinyCC extensions</h2>
@@ -138,35 +178,140 @@ indicate that you use TCC. · 10 unmodified lines
138<li> Binary digits can be entered (<tt>'0b101'</tt> instead of178<li> Binary digits can be entered (<tt>'0b101'</tt> instead of
139<tt>'5'</tt>).179<tt>'5'</tt>).
140 180
181<li> <tt>__BOUNDS_CHECKING_ON</tt> is defined if bound checking is activated.
182
141</ul>183</ul>
142 184
143<h2> Command line invokation </h2>185<h2>TinyCC Memory and Bound checks</h2>
186<A NAME="bounds"></a>
187
188This feature is activated with the <A HREF="#invoke"><tt>'-b'</tt>
189option</A>.
190<P>
191Note that pointer size is <em>unchanged</em> and that code generated
192with bound checks is <em>fully compatible</em> with unchecked
193code. When a pointer comes from unchecked code, it is assumed to be
194valid. Even very obscure C code with casts should work correctly.
195</P>
196<P> To have more information about the ideas behind this method, <A
197HREF="http://www.doc.ic.ac.uk/~phjk/BoundsChecking.html">check
198here</A>.
199</P>
200<P>
201Here are some examples of catched errors:
202</P>
203<TABLE BORDER=1>
204<TR>
205<TD>
206<PRE>
207{
208 char tab[10];
209 memset(tab, 0, 11);
210}
211</PRE>
212</TD><TD VALIGN=TOP>Invalid range with standard string function</TD>
213
214<TR>
215<TD>
216<PRE>
217{
218 int tab[10];
219 for(i=0;i<11;i++) {
220 sum += tab[i];
221 }
222}
223</PRE>
224</TD><TD VALIGN=TOP>Bound error in global or local arrays</TD>
225
226<TR>
227<TD>
228<PRE>
229{
230 int *tab;
231 tab = malloc(20 * sizeof(int));
232 for(i=0;i<21;i++) {
233 sum += tab4[i];
234 }
235 free(tab);
236}
237</PRE>
238</TD><TD VALIGN=TOP>Bound error in allocated data</TD>
239
240<TR>
241<TD>
242<PRE>
243{
244 int *tab;
245 tab = malloc(20 * sizeof(int));
246 free(tab);
247 for(i=0;i<20;i++) {
248 sum += tab4[i];
249 }
250}
251</PRE>
252</TD><TD VALIGN=TOP>Access to a freed region</TD>
253
254<TR>
255<TD>
256<PRE>
257{
258 int *tab;
259 tab = malloc(20 * sizeof(int));
260 free(tab);
261 free(tab);
262}
263</PRE>
264</TD><TD VALIGN=TOP>Freeing an already freed region</TD>
265
266</TABLE>
267
268<h2> Command line invocation </h2>
269<A NAME="invoke"></a>
144 270
145<PRE>271<PRE>
146usage: tcc [-Idir] [-Dsym] [-llib] [-i infile] infile [infile_args...]272usage: tcc [-Idir] [-Dsym[=val]] [-Usym] [-llib] [-g] [-b]
273 [-i infile] infile [infile_args...]
147</PRE>274</PRE>
148 275
149<table>276<table>
150<tr><td>'-Idir'</td> 277<tr><td>'-Idir'</td>
151<td>specify an additionnal include path. The default ones are:278<td>Specify an additionnal include path. The default ones are:
152/usr/include, /usr/lib/tcc, /usr/local/lib/tcc.</td>279/usr/include, /usr/lib/tcc, /usr/local/lib/tcc.</td>
153 280
154<tr><td>'-Dsym'</td>281<tr><td>'-Dsym[=val]'</td> <td>Define preprocessor symbol 'sym' to
155<td>define preprocessor symbol 'sym' to 1.</td>282val. If val is not present, its value is '1'. NOTE: currently, only
283integer and strings are supported as values</td>
284
285<tr><td>'-Usym'</td> <td>Undefine preprocessor symbol 'sym'.</td>
156 286
157<tr><td>'-lxxx'</td>287<tr><td>'-lxxx'</td>
158<td>dynamically link your program with library288<td>Dynamically link your program with library
159libxxx.so. Standard library paths are checked, including those289libxxx.so. Standard library paths are checked, including those
160specificed with LD_LIBRARY_PATH.</td>290specified with LD_LIBRARY_PATH.</td>
291
292<tr><td>'-g'</td>
293<td>Generate run time debug information so that you get clear run time
294error messages: <tt> test.c:68: in function 'test5()': dereferencing
295invalid pointer</tt> instead of the laconic <tt>Segmentation
296fault</tt>.
297</td>
298
299<tr><td>'-b'</td> <td>Generate additionnal support code to check
300memory allocations and array/pointer bounds. '-g' is implied. Note
301that the generated code is slower and bigger in this case.
302</td>
161 303
162<tr><td>'-i file'</td>304<tr><td>'-i file'</td>
163<td>compile C source 'file' before main C source. With this305<td>Compile C source 'file' before main C source. With this
164command, multiple C files can be compiled and linked together.</td>306command, multiple C files can be compiled and linked together.</td>
165</table>307</table>
308<br>
309Note: the <tt>'-o file'</tt> option to generate an ELF executable is
310currently unsupported.
166 311
167<hr>312<hr>
168Copyright (c) 2001 Fabrice Bellard <hr>313Copyright (c) 2001, 2002 Fabrice Bellard <hr>
169Fabrice Bellard - <em> fabrice.bellard at free.fr </em> - <A HREF="http://fabrice.bellard.free.fr/"> http://fabrice.bellard.free.fr/ </A> - <A HREF="http://www.tinycc.org/"> http://www.tinycc.org/ </A>314Fabrice Bellard - <em> fabrice.bellard at free.fr </em> - <A HREF="http://bellard.org/"> http://bellard.org/ </A> - <A HREF="http://www.tinycc.org/"> http://www.tinycc.org/ </A>
170 315
171</body>316</body>
172</html>317</html>

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