source: EcnlProtoTool/trunk/tcc-0.9.26/tcc-doc.html@ 286

Last change on this file since 286 was 279, checked in by coas-nagasima, 7 years ago

ファイルを追加、更新。

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/html
File size: 113.3 KB
Line 
1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html401/loose.dtd">
2<html>
3<!-- Created on February 15, 2013 by texi2html 1.82
4texi2html was written by:
5 Lionel Cons <Lionel.Cons@cern.ch> (original author)
6 Karl Berry <karl@freefriends.org>
7 Olaf Bachmann <obachman@mathematik.uni-kl.de>
8 and many others.
9Maintained by: Many creative people.
10Send bugs and suggestions to <texi2html-bug@nongnu.org>
11-->
12<head>
13<title>Tiny C Compiler Reference Documentation</title>
14
15<meta name="description" content="Tiny C Compiler Reference Documentation">
16<meta name="keywords" content="Tiny C Compiler Reference Documentation">
17<meta name="resource-type" content="document">
18<meta name="distribution" content="global">
19<meta name="Generator" content="texi2html 1.82">
20<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
21<style type="text/css">
22<!--
23a.summary-letter {text-decoration: none}
24blockquote.smallquotation {font-size: smaller}
25pre.display {font-family: serif}
26pre.format {font-family: serif}
27pre.menu-comment {font-family: serif}
28pre.menu-preformatted {font-family: serif}
29pre.smalldisplay {font-family: serif; font-size: smaller}
30pre.smallexample {font-size: smaller}
31pre.smallformat {font-family: serif; font-size: smaller}
32pre.smalllisp {font-size: smaller}
33span.roman {font-family:serif; font-weight:normal;}
34span.sansserif {font-family:sans-serif; font-weight:normal;}
35ul.toc {list-style: none}
36-->
37</style>
38
39
40</head>
41
42<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
43
44<a name="Top"></a>
45<table cellpadding="1" cellspacing="1" border="0">
46<tr><td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
47<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
48<td valign="middle" align="left">[<a href="#Concept-Index" title="Index">Index</a>]</td>
49<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
50</tr></table>
51<a name="Tiny-C-Compiler-Reference-Documentation"></a>
52<h1 class="settitle">Tiny C Compiler Reference Documentation</h1>
53
54<p>This manual documents version 0.9.26 of the Tiny C Compiler.
55</p>
56<table class="menu" border="0" cellspacing="0">
57<tr><td align="left" valign="top"><a href="#Introduction">1. Introduction</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Introduction to tcc.
58</td></tr>
59<tr><td align="left" valign="top"><a href="#Invoke">2. Command line invocation</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Invocation of tcc (command line, options).
60</td></tr>
61<tr><td align="left" valign="top"><a href="#Clang">3. C language support</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> ANSI C and extensions.
62</td></tr>
63<tr><td align="left" valign="top"><a href="#asm">4. TinyCC Assembler</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Assembler syntax.
64</td></tr>
65<tr><td align="left" valign="top"><a href="#linker">5. TinyCC Linker</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Output file generation and supported targets.
66</td></tr>
67<tr><td align="left" valign="top"><a href="#Bounds">6. TinyCC Memory and Bound checks</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Automatic bounds-checking of C code.
68</td></tr>
69<tr><td align="left" valign="top"><a href="#Libtcc">7. The <code>libtcc</code> library</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> The libtcc library.
70</td></tr>
71<tr><td align="left" valign="top"><a href="#devel">8. Developer&rsquo;s guide</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Guide for Developers.
72</td></tr>
73</table>
74
75
76<hr size="1">
77<a name="Introduction"></a>
78<table cellpadding="1" cellspacing="1" border="0">
79<tr><td valign="middle" align="left">[<a href="#Top" title="Previous section in reading order"> &lt; </a>]</td>
80<td valign="middle" align="left">[<a href="#Invoke" title="Next section in reading order"> &gt; </a>]</td>
81<td valign="middle" align="left"> &nbsp; </td>
82<td valign="middle" align="left">[<a href="#Top" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
83<td valign="middle" align="left">[<a href="#Top" title="Up section"> Up </a>]</td>
84<td valign="middle" align="left">[<a href="#Invoke" title="Next chapter"> &gt;&gt; </a>]</td>
85<td valign="middle" align="left"> &nbsp; </td>
86<td valign="middle" align="left"> &nbsp; </td>
87<td valign="middle" align="left"> &nbsp; </td>
88<td valign="middle" align="left"> &nbsp; </td>
89<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
90<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
91<td valign="middle" align="left">[<a href="#Concept-Index" title="Index">Index</a>]</td>
92<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
93</tr></table>
94<a name="Introduction-1"></a>
95<h1 class="chapter">1. Introduction</h1>
96
97<p>TinyCC (aka TCC) is a small but hyper fast C compiler. Unlike other C
98compilers, it is meant to be self-relying: you do not need an
99external assembler or linker because TCC does that for you.
100</p>
101<p>TCC compiles so <em>fast</em> that even for big projects <code>Makefile</code>s may
102not be necessary.
103</p>
104<p>TCC not only supports ANSI C, but also most of the new ISO C99
105standard and many GNUC extensions including inline assembly.
106</p>
107<p>TCC can also be used to make <em>C scripts</em>, i.e. pieces of C source
108that you run as a Perl or Python script. Compilation is so fast that
109your script will be as fast as if it was an executable.
110</p>
111<p>TCC can also automatically generate memory and bound checks
112(see section <a href="#Bounds">TinyCC Memory and Bound checks</a>) while allowing all C pointers operations. TCC can do
113these checks even if non patched libraries are used.
114</p>
115<p>With <code>libtcc</code>, you can use TCC as a backend for dynamic code
116generation (see section <a href="#Libtcc">The <code>libtcc</code> library</a>).
117</p>
118<p>TCC mainly supports the i386 target on Linux and Windows. There are alpha
119ports for the ARM (<code>arm-tcc</code>) and the TMS320C67xx targets
120(<code>c67-tcc</code>). More information about the ARM port is available at
121<a href="http://lists.gnu.org/archive/html/tinycc-devel/2003-10/msg00044.html">http://lists.gnu.org/archive/html/tinycc-devel/2003-10/msg00044.html</a>.
122</p>
123<p>For usage on Windows, see also <a href="tcc-win32.txt">tcc-win32.txt</a>.
124</p>
125<hr size="6">
126<a name="Invoke"></a>
127<table cellpadding="1" cellspacing="1" border="0">
128<tr><td valign="middle" align="left">[<a href="#Introduction" title="Previous section in reading order"> &lt; </a>]</td>
129<td valign="middle" align="left">[<a href="#Quick-start" title="Next section in reading order"> &gt; </a>]</td>
130<td valign="middle" align="left"> &nbsp; </td>
131<td valign="middle" align="left">[<a href="#Introduction" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
132<td valign="middle" align="left">[<a href="#Top" title="Up section"> Up </a>]</td>
133<td valign="middle" align="left">[<a href="#Clang" title="Next chapter"> &gt;&gt; </a>]</td>
134<td valign="middle" align="left"> &nbsp; </td>
135<td valign="middle" align="left"> &nbsp; </td>
136<td valign="middle" align="left"> &nbsp; </td>
137<td valign="middle" align="left"> &nbsp; </td>
138<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
139<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
140<td valign="middle" align="left">[<a href="#Concept-Index" title="Index">Index</a>]</td>
141<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
142</tr></table>
143<a name="Command-line-invocation"></a>
144<h1 class="chapter">2. Command line invocation</h1>
145
146<hr size="6">
147<a name="Quick-start"></a>
148<table cellpadding="1" cellspacing="1" border="0">
149<tr><td valign="middle" align="left">[<a href="#Invoke" title="Previous section in reading order"> &lt; </a>]</td>
150<td valign="middle" align="left">[<a href="#Option-summary" title="Next section in reading order"> &gt; </a>]</td>
151<td valign="middle" align="left"> &nbsp; </td>
152<td valign="middle" align="left">[<a href="#Invoke" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
153<td valign="middle" align="left">[<a href="#Invoke" title="Up section"> Up </a>]</td>
154<td valign="middle" align="left">[<a href="#Clang" title="Next chapter"> &gt;&gt; </a>]</td>
155<td valign="middle" align="left"> &nbsp; </td>
156<td valign="middle" align="left"> &nbsp; </td>
157<td valign="middle" align="left"> &nbsp; </td>
158<td valign="middle" align="left"> &nbsp; </td>
159<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
160<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
161<td valign="middle" align="left">[<a href="#Concept-Index" title="Index">Index</a>]</td>
162<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
163</tr></table>
164<h2 class="section">2.1 Quick start</h2>
165
166<table><tr><td>&nbsp;</td><td><pre class="example">usage: tcc [options] [<var>infile1</var> <var>infile2</var>&hellip;] [&lsquo;<samp>-run</samp>&rsquo; <var>infile</var> <var>args</var>&hellip;]
167</pre></td></tr></table>
168
169<p>TCC options are a very much like gcc options. The main difference is that TCC
170can also execute directly the resulting program and give it runtime
171arguments.
172</p>
173<p>Here are some examples to understand the logic:
174</p>
175<dl compact="compact">
176<dt> <code>&lsquo;<samp>tcc -run a.c</samp>&rsquo;</code></dt>
177<dd><p>Compile &lsquo;<tt>a.c</tt>&rsquo; and execute it directly
178</p>
179</dd>
180<dt> <code>&lsquo;<samp>tcc -run a.c arg1</samp>&rsquo;</code></dt>
181<dd><p>Compile a.c and execute it directly. arg1 is given as first argument to
182the <code>main()</code> of a.c.
183</p>
184</dd>
185<dt> <code>&lsquo;<samp>tcc a.c -run b.c arg1</samp>&rsquo;</code></dt>
186<dd><p>Compile &lsquo;<tt>a.c</tt>&rsquo; and &lsquo;<tt>b.c</tt>&rsquo;, link them together and execute them. arg1 is given
187as first argument to the <code>main()</code> of the resulting program.
188</p>
189</dd>
190<dt> <code>&lsquo;<samp>tcc -o myprog a.c b.c</samp>&rsquo;</code></dt>
191<dd><p>Compile &lsquo;<tt>a.c</tt>&rsquo; and &lsquo;<tt>b.c</tt>&rsquo;, link them and generate the executable &lsquo;<tt>myprog</tt>&rsquo;.
192</p>
193</dd>
194<dt> <code>&lsquo;<samp>tcc -o myprog a.o b.o</samp>&rsquo;</code></dt>
195<dd><p>link &lsquo;<tt>a.o</tt>&rsquo; and &lsquo;<tt>b.o</tt>&rsquo; together and generate the executable &lsquo;<tt>myprog</tt>&rsquo;.
196</p>
197</dd>
198<dt> <code>&lsquo;<samp>tcc -c a.c</samp>&rsquo;</code></dt>
199<dd><p>Compile &lsquo;<tt>a.c</tt>&rsquo; and generate object file &lsquo;<tt>a.o</tt>&rsquo;.
200</p>
201</dd>
202<dt> <code>&lsquo;<samp>tcc -c asmfile.S</samp>&rsquo;</code></dt>
203<dd><p>Preprocess with C preprocess and assemble &lsquo;<tt>asmfile.S</tt>&rsquo; and generate
204object file &lsquo;<tt>asmfile.o</tt>&rsquo;.
205</p>
206</dd>
207<dt> <code>&lsquo;<samp>tcc -c asmfile.s</samp>&rsquo;</code></dt>
208<dd><p>Assemble (but not preprocess) &lsquo;<tt>asmfile.s</tt>&rsquo; and generate object file
209&lsquo;<tt>asmfile.o</tt>&rsquo;.
210</p>
211</dd>
212<dt> <code>&lsquo;<samp>tcc -r -o ab.o a.c b.c</samp>&rsquo;</code></dt>
213<dd><p>Compile &lsquo;<tt>a.c</tt>&rsquo; and &lsquo;<tt>b.c</tt>&rsquo;, link them together and generate the object file &lsquo;<tt>ab.o</tt>&rsquo;.
214</p>
215</dd>
216</dl>
217
218<p>Scripting:
219</p>
220<p>TCC can be invoked from <em>scripts</em>, just as shell scripts. You just
221need to add <code>#!/usr/local/bin/tcc -run</code> at the start of your C source:
222</p>
223<table><tr><td>&nbsp;</td><td><pre class="example">#!/usr/local/bin/tcc -run
224#include &lt;stdio.h&gt;
225
226int main()
227{
228 printf(&quot;Hello World\n&quot;);
229 return 0;
230}
231</pre></td></tr></table>
232
233<p>TCC can read C source code from <em>standard input</em> when &lsquo;<samp>-</samp>&rsquo; is used in
234place of &lsquo;<samp>infile</samp>&rsquo;. Example:
235</p>
236<table><tr><td>&nbsp;</td><td><pre class="example">echo 'main(){puts(&quot;hello&quot;);}' | tcc -run -
237</pre></td></tr></table>
238
239<hr size="6">
240<a name="Option-summary"></a>
241<table cellpadding="1" cellspacing="1" border="0">
242<tr><td valign="middle" align="left">[<a href="#Quick-start" title="Previous section in reading order"> &lt; </a>]</td>
243<td valign="middle" align="left">[<a href="#Clang" title="Next section in reading order"> &gt; </a>]</td>
244<td valign="middle" align="left"> &nbsp; </td>
245<td valign="middle" align="left">[<a href="#Invoke" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
246<td valign="middle" align="left">[<a href="#Invoke" title="Up section"> Up </a>]</td>
247<td valign="middle" align="left">[<a href="#Clang" title="Next chapter"> &gt;&gt; </a>]</td>
248<td valign="middle" align="left"> &nbsp; </td>
249<td valign="middle" align="left"> &nbsp; </td>
250<td valign="middle" align="left"> &nbsp; </td>
251<td valign="middle" align="left"> &nbsp; </td>
252<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
253<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
254<td valign="middle" align="left">[<a href="#Concept-Index" title="Index">Index</a>]</td>
255<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
256</tr></table>
257<h2 class="section">2.2 Option summary</h2>
258
259<p>General Options:
260</p>
261<dl compact="compact">
262<dt> &lsquo;<samp>-c</samp>&rsquo;</dt>
263<dd><p>Generate an object file.
264</p>
265</dd>
266<dt> &lsquo;<samp>-o outfile</samp>&rsquo;</dt>
267<dd><p>Put object file, executable, or dll into output file &lsquo;<tt>outfile</tt>&rsquo;.
268</p>
269</dd>
270<dt> &lsquo;<samp>-run source [args...]</samp>&rsquo;</dt>
271<dd><p>Compile file <var>source</var> and run it with the command line arguments
272<var>args</var>. In order to be able to give more than one argument to a
273script, several TCC options can be given <em>after</em> the
274&lsquo;<samp>-run</samp>&rsquo; option, separated by spaces:
275</p><table><tr><td>&nbsp;</td><td><pre class="example">tcc &quot;-run -L/usr/X11R6/lib -lX11&quot; ex4.c
276</pre></td></tr></table>
277<p>In a script, it gives the following header:
278</p><table><tr><td>&nbsp;</td><td><pre class="example">#!/usr/local/bin/tcc -run -L/usr/X11R6/lib -lX11
279</pre></td></tr></table>
280
281</dd>
282<dt> &lsquo;<samp>-dumpversion</samp>&rsquo;</dt>
283<dd><p>Print only the compiler version and nothing else.
284</p>
285</dd>
286<dt> &lsquo;<samp>-v</samp>&rsquo;</dt>
287<dd><p>Display TCC version.
288</p>
289</dd>
290<dt> &lsquo;<samp>-vv</samp>&rsquo;</dt>
291<dd><p>Show included files. As sole argument, print search dirs (as below).
292</p>
293</dd>
294<dt> &lsquo;<samp>-bench</samp>&rsquo;</dt>
295<dd><p>Display compilation statistics.
296</p>
297</dd>
298<dt> &lsquo;<samp>-print-search-dirs</samp>&rsquo;</dt>
299<dd><p>Print the configured installation directory and a list of library
300and include directories tcc will search.
301</p>
302</dd>
303</dl>
304
305<p>Preprocessor options:
306</p>
307<dl compact="compact">
308<dt> &lsquo;<samp>-Idir</samp>&rsquo;</dt>
309<dd><p>Specify an additional include path. Include paths are searched in the
310order they are specified.
311</p>
312<p>System include paths are always searched after. The default system
313include paths are: &lsquo;<tt>/usr/local/include</tt>&rsquo;, &lsquo;<tt>/usr/include</tt>&rsquo;
314and &lsquo;<tt>PREFIX/lib/tcc/include</tt>&rsquo;. (&lsquo;<tt>PREFIX</tt>&rsquo; is usually
315&lsquo;<tt>/usr</tt>&rsquo; or &lsquo;<tt>/usr/local</tt>&rsquo;).
316</p>
317</dd>
318<dt> &lsquo;<samp>-Dsym[=val]</samp>&rsquo;</dt>
319<dd><p>Define preprocessor symbol &lsquo;<samp>sym</samp>&rsquo; to
320val. If val is not present, its value is &lsquo;<samp>1</samp>&rsquo;. Function-like macros can
321also be defined: &lsquo;<samp>-DF(a)=a+1</samp>&rsquo;
322</p>
323</dd>
324<dt> &lsquo;<samp>-Usym</samp>&rsquo;</dt>
325<dd><p>Undefine preprocessor symbol &lsquo;<samp>sym</samp>&rsquo;.
326</p></dd>
327</dl>
328
329<p>Compilation flags:
330</p>
331<p>Note: each of the following warning options has a negative form beginning with
332&lsquo;<samp>-fno-</samp>&rsquo;.
333</p>
334<dl compact="compact">
335<dt> &lsquo;<samp>-funsigned-char</samp>&rsquo;</dt>
336<dd><p>Let the <code>char</code> type be unsigned.
337</p>
338</dd>
339<dt> &lsquo;<samp>-fsigned-char</samp>&rsquo;</dt>
340<dd><p>Let the <code>char</code> type be signed.
341</p>
342</dd>
343<dt> &lsquo;<samp>-fno-common</samp>&rsquo;</dt>
344<dd><p>Do not generate common symbols for uninitialized data.
345</p>
346</dd>
347<dt> &lsquo;<samp>-fleading-underscore</samp>&rsquo;</dt>
348<dd><p>Add a leading underscore at the beginning of each C symbol.
349</p>
350</dd>
351</dl>
352
353<p>Warning options:
354</p>
355<dl compact="compact">
356<dt> &lsquo;<samp>-w</samp>&rsquo;</dt>
357<dd><p>Disable all warnings.
358</p>
359</dd>
360</dl>
361
362<p>Note: each of the following warning options has a negative form beginning with
363&lsquo;<samp>-Wno-</samp>&rsquo;.
364</p>
365<dl compact="compact">
366<dt> &lsquo;<samp>-Wimplicit-function-declaration</samp>&rsquo;</dt>
367<dd><p>Warn about implicit function declaration.
368</p>
369</dd>
370<dt> &lsquo;<samp>-Wunsupported</samp>&rsquo;</dt>
371<dd><p>Warn about unsupported GCC features that are ignored by TCC.
372</p>
373</dd>
374<dt> &lsquo;<samp>-Wwrite-strings</samp>&rsquo;</dt>
375<dd><p>Make string constants be of type <code>const char *</code> instead of <code>char
376*</code>.
377</p>
378</dd>
379<dt> &lsquo;<samp>-Werror</samp>&rsquo;</dt>
380<dd><p>Abort compilation if warnings are issued.
381</p>
382</dd>
383<dt> &lsquo;<samp>-Wall</samp>&rsquo; </dt>
384<dd><p>Activate all warnings, except &lsquo;<samp>-Werror</samp>&rsquo;, &lsquo;<samp>-Wunusupported</samp>&rsquo; and
385&lsquo;<samp>-Wwrite-strings</samp>&rsquo;.
386</p>
387</dd>
388</dl>
389
390<p>Linker options:
391</p>
392<dl compact="compact">
393<dt> &lsquo;<samp>-Ldir</samp>&rsquo;</dt>
394<dd><p>Specify an additional static library path for the &lsquo;<samp>-l</samp>&rsquo; option. The
395default library paths are &lsquo;<tt>/usr/local/lib</tt>&rsquo;, &lsquo;<tt>/usr/lib</tt>&rsquo; and &lsquo;<tt>/lib</tt>&rsquo;.
396</p>
397</dd>
398<dt> &lsquo;<samp>-lxxx</samp>&rsquo;</dt>
399<dd><p>Link your program with dynamic library libxxx.so or static library
400libxxx.a. The library is searched in the paths specified by the
401&lsquo;<samp>-L</samp>&rsquo; option.
402</p>
403</dd>
404<dt> &lsquo;<samp>-Bdir</samp>&rsquo;</dt>
405<dd><p>Set the path where the tcc internal libraries (and include files) can be
406found (default is &lsquo;<tt>PREFIX/lib/tcc</tt>&rsquo;).
407</p>
408</dd>
409<dt> &lsquo;<samp>-shared</samp>&rsquo;</dt>
410<dd><p>Generate a shared library instead of an executable.
411</p>
412</dd>
413<dt> &lsquo;<samp>-soname name</samp>&rsquo;</dt>
414<dd><p>set name for shared library to be used at runtime
415</p>
416</dd>
417<dt> &lsquo;<samp>-static</samp>&rsquo;</dt>
418<dd><p>Generate a statically linked executable (default is a shared linked
419executable).
420</p>
421</dd>
422<dt> &lsquo;<samp>-rdynamic</samp>&rsquo;</dt>
423<dd><p>Export global symbols to the dynamic linker. It is useful when a library
424opened with <code>dlopen()</code> needs to access executable symbols.
425</p>
426</dd>
427<dt> &lsquo;<samp>-r</samp>&rsquo;</dt>
428<dd><p>Generate an object file combining all input files.
429</p>
430</dd>
431<dt> &lsquo;<samp>-Wl,-rpath=path</samp>&rsquo;</dt>
432<dd><p>Put custom seatch path for dynamic libraries into executable.
433</p>
434</dd>
435<dt> &lsquo;<samp>-Wl,--oformat=fmt</samp>&rsquo;</dt>
436<dd><p>Use <var>fmt</var> as output format. The supported output formats are:
437</p><dl compact="compact">
438<dt> <code>elf32-i386</code></dt>
439<dd><p>ELF output format (default)
440</p></dd>
441<dt> <code>binary</code></dt>
442<dd><p>Binary image (only for executable output)
443</p></dd>
444<dt> <code>coff</code></dt>
445<dd><p>COFF output format (only for executable output for TMS320C67xx target)
446</p></dd>
447</dl>
448
449</dd>
450<dt> &lsquo;<samp>-Wl,-subsystem=console/gui/wince/...</samp>&rsquo;</dt>
451<dd><p>Set type for PE (Windows) executables.
452</p>
453</dd>
454<dt> &lsquo;<samp>-Wl,-[Ttext=# | section-alignment=# | file-alignment=# | image-base=# | stack=#]</samp>&rsquo;</dt>
455<dd><p>Modify executable layout.
456</p>
457</dd>
458<dt> &lsquo;<samp>-Wl,-Bsymbolic</samp>&rsquo;</dt>
459<dd><p>Set DT_SYMBOLIC tag.
460</p>
461</dd>
462</dl>
463
464<p>Debugger options:
465</p>
466<dl compact="compact">
467<dt> &lsquo;<samp>-g</samp>&rsquo;</dt>
468<dd><p>Generate run time debug information so that you get clear run time
469error messages: <code> test.c:68: in function 'test5()': dereferencing
470invalid pointer</code> instead of the laconic <code>Segmentation
471fault</code>.
472</p>
473</dd>
474<dt> &lsquo;<samp>-b</samp>&rsquo;</dt>
475<dd><p>Generate additional support code to check
476memory allocations and array/pointer bounds. &lsquo;<samp>-g</samp>&rsquo; is implied. Note
477that the generated code is slower and bigger in this case.
478</p>
479<p>Note: &lsquo;<samp>-b</samp>&rsquo; is only available on i386 for the moment.
480</p>
481</dd>
482<dt> &lsquo;<samp>-bt N</samp>&rsquo;</dt>
483<dd><p>Display N callers in stack traces. This is useful with &lsquo;<samp>-g</samp>&rsquo; or
484&lsquo;<samp>-b</samp>&rsquo;.
485</p>
486</dd>
487</dl>
488
489<p>Misc options:
490</p>
491<dl compact="compact">
492<dt> &lsquo;<samp>-MD</samp>&rsquo;</dt>
493<dd><p>Generate makefile fragment with dependencies.
494</p>
495</dd>
496<dt> &lsquo;<samp>-MF depfile</samp>&rsquo;</dt>
497<dd><p>Use &lsquo;<tt>depfile</tt>&rsquo; as output for -MD.
498</p>
499</dd>
500</dl>
501
502<p>Note: GCC options &lsquo;<samp>-Ox</samp>&rsquo;, &lsquo;<samp>-fx</samp>&rsquo; and &lsquo;<samp>-mx</samp>&rsquo; are
503ignored.
504</p>
505
506<hr size="6">
507<a name="Clang"></a>
508<table cellpadding="1" cellspacing="1" border="0">
509<tr><td valign="middle" align="left">[<a href="#Option-summary" title="Previous section in reading order"> &lt; </a>]</td>
510<td valign="middle" align="left">[<a href="#ANSI-C" title="Next section in reading order"> &gt; </a>]</td>
511<td valign="middle" align="left"> &nbsp; </td>
512<td valign="middle" align="left">[<a href="#Invoke" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
513<td valign="middle" align="left">[<a href="#Top" title="Up section"> Up </a>]</td>
514<td valign="middle" align="left">[<a href="#asm" title="Next chapter"> &gt;&gt; </a>]</td>
515<td valign="middle" align="left"> &nbsp; </td>
516<td valign="middle" align="left"> &nbsp; </td>
517<td valign="middle" align="left"> &nbsp; </td>
518<td valign="middle" align="left"> &nbsp; </td>
519<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
520<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
521<td valign="middle" align="left">[<a href="#Concept-Index" title="Index">Index</a>]</td>
522<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
523</tr></table>
524<a name="C-language-support"></a>
525<h1 class="chapter">3. C language support</h1>
526
527<hr size="6">
528<a name="ANSI-C"></a>
529<table cellpadding="1" cellspacing="1" border="0">
530<tr><td valign="middle" align="left">[<a href="#Clang" title="Previous section in reading order"> &lt; </a>]</td>
531<td valign="middle" align="left">[<a href="#ISOC99-extensions" title="Next section in reading order"> &gt; </a>]</td>
532<td valign="middle" align="left"> &nbsp; </td>
533<td valign="middle" align="left">[<a href="#Clang" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
534<td valign="middle" align="left">[<a href="#Clang" title="Up section"> Up </a>]</td>
535<td valign="middle" align="left">[<a href="#asm" title="Next chapter"> &gt;&gt; </a>]</td>
536<td valign="middle" align="left"> &nbsp; </td>
537<td valign="middle" align="left"> &nbsp; </td>
538<td valign="middle" align="left"> &nbsp; </td>
539<td valign="middle" align="left"> &nbsp; </td>
540<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
541<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
542<td valign="middle" align="left">[<a href="#Concept-Index" title="Index">Index</a>]</td>
543<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
544</tr></table>
545<h2 class="section">3.1 ANSI C</h2>
546
547<p>TCC implements all the ANSI C standard, including structure bit fields
548and floating point numbers (<code>long double</code>, <code>double</code>, and
549<code>float</code> fully supported).
550</p>
551<hr size="6">
552<a name="ISOC99-extensions"></a>
553<table cellpadding="1" cellspacing="1" border="0">
554<tr><td valign="middle" align="left">[<a href="#ANSI-C" title="Previous section in reading order"> &lt; </a>]</td>
555<td valign="middle" align="left">[<a href="#GNU-C-extensions" title="Next section in reading order"> &gt; </a>]</td>
556<td valign="middle" align="left"> &nbsp; </td>
557<td valign="middle" align="left">[<a href="#Clang" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
558<td valign="middle" align="left">[<a href="#Clang" title="Up section"> Up </a>]</td>
559<td valign="middle" align="left">[<a href="#asm" title="Next chapter"> &gt;&gt; </a>]</td>
560<td valign="middle" align="left"> &nbsp; </td>
561<td valign="middle" align="left"> &nbsp; </td>
562<td valign="middle" align="left"> &nbsp; </td>
563<td valign="middle" align="left"> &nbsp; </td>
564<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
565<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
566<td valign="middle" align="left">[<a href="#Concept-Index" title="Index">Index</a>]</td>
567<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
568</tr></table>
569<h2 class="section">3.2 ISOC99 extensions</h2>
570
571<p>TCC implements many features of the new C standard: ISO C99. Currently
572missing items are: complex and imaginary numbers and variable length
573arrays.
574</p>
575<p>Currently implemented ISOC99 features:
576</p>
577<ul>
578<li> 64 bit <code>long long</code> types are fully supported.
579
580</li><li> The boolean type <code>_Bool</code> is supported.
581
582</li><li> <code>__func__</code> is a string variable containing the current
583function name.
584
585</li><li> Variadic macros: <code>__VA_ARGS__</code> can be used for
586 function-like macros:
587<table><tr><td>&nbsp;</td><td><pre class="example"> #define dprintf(level, __VA_ARGS__) printf(__VA_ARGS__)
588</pre></td></tr></table>
589
590<p><code>dprintf</code> can then be used with a variable number of parameters.
591</p>
592</li><li> Declarations can appear anywhere in a block (as in C++).
593
594</li><li> Array and struct/union elements can be initialized in any order by
595 using designators:
596<table><tr><td>&nbsp;</td><td><pre class="example"> struct { int x, y; } st[10] = { [0].x = 1, [0].y = 2 };
597
598 int tab[10] = { 1, 2, [5] = 5, [9] = 9};
599</pre></td></tr></table>
600
601</li><li> Compound initializers are supported:
602<table><tr><td>&nbsp;</td><td><pre class="example"> int *p = (int []){ 1, 2, 3 };
603</pre></td></tr></table>
604<p>to initialize a pointer pointing to an initialized array. The same
605works for structures and strings.
606</p>
607</li><li> Hexadecimal floating point constants are supported:
608<table><tr><td>&nbsp;</td><td><pre class="example"> double d = 0x1234p10;
609</pre></td></tr></table>
610
611<p>is the same as writing
612</p><table><tr><td>&nbsp;</td><td><pre class="example"> double d = 4771840.0;
613</pre></td></tr></table>
614
615</li><li> <code>inline</code> keyword is ignored.
616
617</li><li> <code>restrict</code> keyword is ignored.
618</li></ul>
619
620<hr size="6">
621<a name="GNU-C-extensions"></a>
622<table cellpadding="1" cellspacing="1" border="0">
623<tr><td valign="middle" align="left">[<a href="#ISOC99-extensions" title="Previous section in reading order"> &lt; </a>]</td>
624<td valign="middle" align="left">[<a href="#TinyCC-extensions" title="Next section in reading order"> &gt; </a>]</td>
625<td valign="middle" align="left"> &nbsp; </td>
626<td valign="middle" align="left">[<a href="#Clang" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
627<td valign="middle" align="left">[<a href="#Clang" title="Up section"> Up </a>]</td>
628<td valign="middle" align="left">[<a href="#asm" title="Next chapter"> &gt;&gt; </a>]</td>
629<td valign="middle" align="left"> &nbsp; </td>
630<td valign="middle" align="left"> &nbsp; </td>
631<td valign="middle" align="left"> &nbsp; </td>
632<td valign="middle" align="left"> &nbsp; </td>
633<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
634<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
635<td valign="middle" align="left">[<a href="#Concept-Index" title="Index">Index</a>]</td>
636<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
637</tr></table>
638<h2 class="section">3.3 GNU C extensions</h2>
639
640<p>TCC implements some GNU C extensions:
641</p>
642<ul>
643<li> array designators can be used without &rsquo;=&rsquo;:
644<table><tr><td>&nbsp;</td><td><pre class="example"> int a[10] = { [0] 1, [5] 2, 3, 4 };
645</pre></td></tr></table>
646
647</li><li> Structure field designators can be a label:
648<table><tr><td>&nbsp;</td><td><pre class="example"> struct { int x, y; } st = { x: 1, y: 1};
649</pre></td></tr></table>
650<p>instead of
651</p><table><tr><td>&nbsp;</td><td><pre class="example"> struct { int x, y; } st = { .x = 1, .y = 1};
652</pre></td></tr></table>
653
654</li><li> <code>\e</code> is ASCII character 27.
655
656</li><li> case ranges : ranges can be used in <code>case</code>s:
657<table><tr><td>&nbsp;</td><td><pre class="example"> switch(a) {
658 case 1 &hellip; 9:
659 printf(&quot;range 1 to 9\n&quot;);
660 break;
661 default:
662 printf(&quot;unexpected\n&quot;);
663 break;
664 }
665</pre></td></tr></table>
666
667<a name="index-aligned-attribute"></a>
668<a name="index-packed-attribute"></a>
669<a name="index-section-attribute"></a>
670<a name="index-unused-attribute"></a>
671<a name="index-cdecl-attribute"></a>
672<a name="index-stdcall-attribute"></a>
673<a name="index-regparm-attribute"></a>
674<a name="index-dllexport-attribute"></a>
675
676</li><li> The keyword <code>__attribute__</code> is handled to specify variable or
677function attributes. The following attributes are supported:
678 <ul>
679<li> <code>aligned(n)</code>: align a variable or a structure field to n bytes
680(must be a power of two).
681
682 </li><li> <code>packed</code>: force alignment of a variable or a structure field to
683 1.
684
685 </li><li> <code>section(name)</code>: generate function or data in assembly section
686name (name is a string containing the section name) instead of the default
687section.
688
689 </li><li> <code>unused</code>: specify that the variable or the function is unused.
690
691 </li><li> <code>cdecl</code>: use standard C calling convention (default).
692
693 </li><li> <code>stdcall</code>: use Pascal-like calling convention.
694
695 </li><li> <code>regparm(n)</code>: use fast i386 calling convention. <var>n</var> must be
696between 1 and 3. The first <var>n</var> function parameters are respectively put in
697registers <code>%eax</code>, <code>%edx</code> and <code>%ecx</code>.
698
699 </li><li> <code>dllexport</code>: export function from dll/executable (win32 only)
700
701</li></ul>
702
703<p>Here are some examples:
704</p><table><tr><td>&nbsp;</td><td><pre class="example"> int a __attribute__ ((aligned(8), section(&quot;.mysection&quot;)));
705</pre></td></tr></table>
706
707<p>align variable <code>a</code> to 8 bytes and put it in section <code>.mysection</code>.
708</p>
709<table><tr><td>&nbsp;</td><td><pre class="example"> int my_add(int a, int b) __attribute__ ((section(&quot;.mycodesection&quot;)))
710 {
711 return a + b;
712 }
713</pre></td></tr></table>
714
715<p>generate function <code>my_add</code> in section <code>.mycodesection</code>.
716</p>
717</li><li> GNU style variadic macros:
718<table><tr><td>&nbsp;</td><td><pre class="example"> #define dprintf(fmt, args&hellip;) printf(fmt, ## args)
719
720 dprintf(&quot;no arg\n&quot;);
721 dprintf(&quot;one arg %d\n&quot;, 1);
722</pre></td></tr></table>
723
724</li><li> <code>__FUNCTION__</code> is interpreted as C99 <code>__func__</code>
725(so it has not exactly the same semantics as string literal GNUC
726where it is a string literal).
727
728</li><li> The <code>__alignof__</code> keyword can be used as <code>sizeof</code>
729to get the alignment of a type or an expression.
730
731</li><li> The <code>typeof(x)</code> returns the type of <code>x</code>.
732<code>x</code> is an expression or a type.
733
734</li><li> Computed gotos: <code>&amp;&amp;label</code> returns a pointer of type
735<code>void *</code> on the goto label <code>label</code>. <code>goto *expr</code> can be
736used to jump on the pointer resulting from <code>expr</code>.
737
738</li><li> Inline assembly with asm instruction:
739<a name="index-inline-assembly"></a>
740<a name="index-assembly_002c-inline"></a>
741<a name="index-_005f_005fasm_005f_005f"></a>
742<table><tr><td>&nbsp;</td><td><pre class="example">static inline void * my_memcpy(void * to, const void * from, size_t n)
743{
744int d0, d1, d2;
745__asm__ __volatile__(
746 &quot;rep ; movsl\n\t&quot;
747 &quot;testb $2,%b4\n\t&quot;
748 &quot;je 1f\n\t&quot;
749 &quot;movsw\n&quot;
750 &quot;1:\ttestb $1,%b4\n\t&quot;
751 &quot;je 2f\n\t&quot;
752 &quot;movsb\n&quot;
753 &quot;2:&quot;
754 : &quot;=&amp;c&quot; (d0), &quot;=&amp;D&quot; (d1), &quot;=&amp;S&quot; (d2)
755 :&quot;0&quot; (n/4), &quot;q&quot; (n),&quot;1&quot; ((long) to),&quot;2&quot; ((long) from)
756 : &quot;memory&quot;);
757return (to);
758}
759</pre></td></tr></table>
760
761<a name="index-gas"></a>
762<p>TCC includes its own x86 inline assembler with a <code>gas</code>-like (GNU
763assembler) syntax. No intermediate files are generated. GCC 3.x named
764operands are supported.
765</p>
766</li><li> <code>__builtin_types_compatible_p()</code> and <code>__builtin_constant_p()</code>
767are supported.
768
769</li><li> <code>#pragma pack</code> is supported for win32 compatibility.
770
771</li></ul>
772
773<hr size="6">
774<a name="TinyCC-extensions"></a>
775<table cellpadding="1" cellspacing="1" border="0">
776<tr><td valign="middle" align="left">[<a href="#GNU-C-extensions" title="Previous section in reading order"> &lt; </a>]</td>
777<td valign="middle" align="left">[<a href="#asm" title="Next section in reading order"> &gt; </a>]</td>
778<td valign="middle" align="left"> &nbsp; </td>
779<td valign="middle" align="left">[<a href="#Clang" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
780<td valign="middle" align="left">[<a href="#Clang" title="Up section"> Up </a>]</td>
781<td valign="middle" align="left">[<a href="#asm" title="Next chapter"> &gt;&gt; </a>]</td>
782<td valign="middle" align="left"> &nbsp; </td>
783<td valign="middle" align="left"> &nbsp; </td>
784<td valign="middle" align="left"> &nbsp; </td>
785<td valign="middle" align="left"> &nbsp; </td>
786<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
787<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
788<td valign="middle" align="left">[<a href="#Concept-Index" title="Index">Index</a>]</td>
789<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
790</tr></table>
791<h2 class="section">3.4 TinyCC extensions</h2>
792
793<ul>
794<li> <code>__TINYC__</code> is a predefined macro to <code>1</code> to
795indicate that you use TCC.
796
797</li><li> <code>#!</code> at the start of a line is ignored to allow scripting.
798
799</li><li> Binary digits can be entered (<code>0b101</code> instead of
800<code>5</code>).
801
802</li><li> <code>__BOUNDS_CHECKING_ON</code> is defined if bound checking is activated.
803
804</li></ul>
805
806<hr size="6">
807<a name="asm"></a>
808<table cellpadding="1" cellspacing="1" border="0">
809<tr><td valign="middle" align="left">[<a href="#TinyCC-extensions" title="Previous section in reading order"> &lt; </a>]</td>
810<td valign="middle" align="left">[<a href="#Syntax" title="Next section in reading order"> &gt; </a>]</td>
811<td valign="middle" align="left"> &nbsp; </td>
812<td valign="middle" align="left">[<a href="#Clang" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
813<td valign="middle" align="left">[<a href="#Top" title="Up section"> Up </a>]</td>
814<td valign="middle" align="left">[<a href="#linker" title="Next chapter"> &gt;&gt; </a>]</td>
815<td valign="middle" align="left"> &nbsp; </td>
816<td valign="middle" align="left"> &nbsp; </td>
817<td valign="middle" align="left"> &nbsp; </td>
818<td valign="middle" align="left"> &nbsp; </td>
819<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
820<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
821<td valign="middle" align="left">[<a href="#Concept-Index" title="Index">Index</a>]</td>
822<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
823</tr></table>
824<a name="TinyCC-Assembler"></a>
825<h1 class="chapter">4. TinyCC Assembler</h1>
826
827<p>Since version 0.9.16, TinyCC integrates its own assembler. TinyCC
828assembler supports a gas-like syntax (GNU assembler). You can
829desactivate assembler support if you want a smaller TinyCC executable
830(the C compiler does not rely on the assembler).
831</p>
832<p>TinyCC Assembler is used to handle files with &lsquo;<tt>.S</tt>&rsquo; (C
833preprocessed assembler) and &lsquo;<tt>.s</tt>&rsquo; extensions. It is also used to
834handle the GNU inline assembler with the <code>asm</code> keyword.
835</p>
836<hr size="6">
837<a name="Syntax"></a>
838<table cellpadding="1" cellspacing="1" border="0">
839<tr><td valign="middle" align="left">[<a href="#asm" title="Previous section in reading order"> &lt; </a>]</td>
840<td valign="middle" align="left">[<a href="#Expressions" title="Next section in reading order"> &gt; </a>]</td>
841<td valign="middle" align="left"> &nbsp; </td>
842<td valign="middle" align="left">[<a href="#asm" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
843<td valign="middle" align="left">[<a href="#asm" title="Up section"> Up </a>]</td>
844<td valign="middle" align="left">[<a href="#linker" title="Next chapter"> &gt;&gt; </a>]</td>
845<td valign="middle" align="left"> &nbsp; </td>
846<td valign="middle" align="left"> &nbsp; </td>
847<td valign="middle" align="left"> &nbsp; </td>
848<td valign="middle" align="left"> &nbsp; </td>
849<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
850<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
851<td valign="middle" align="left">[<a href="#Concept-Index" title="Index">Index</a>]</td>
852<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
853</tr></table>
854<h2 class="section">4.1 Syntax</h2>
855
856<p>TinyCC Assembler supports most of the gas syntax. The tokens are the
857same as C.
858</p>
859<ul>
860<li> C and C++ comments are supported.
861
862</li><li> Identifiers are the same as C, so you cannot use &rsquo;.&rsquo; or &rsquo;$&rsquo;.
863
864</li><li> Only 32 bit integer numbers are supported.
865
866</li></ul>
867
868<hr size="6">
869<a name="Expressions"></a>
870<table cellpadding="1" cellspacing="1" border="0">
871<tr><td valign="middle" align="left">[<a href="#Syntax" title="Previous section in reading order"> &lt; </a>]</td>
872<td valign="middle" align="left">[<a href="#Labels" title="Next section in reading order"> &gt; </a>]</td>
873<td valign="middle" align="left"> &nbsp; </td>
874<td valign="middle" align="left">[<a href="#asm" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
875<td valign="middle" align="left">[<a href="#asm" title="Up section"> Up </a>]</td>
876<td valign="middle" align="left">[<a href="#linker" title="Next chapter"> &gt;&gt; </a>]</td>
877<td valign="middle" align="left"> &nbsp; </td>
878<td valign="middle" align="left"> &nbsp; </td>
879<td valign="middle" align="left"> &nbsp; </td>
880<td valign="middle" align="left"> &nbsp; </td>
881<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
882<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
883<td valign="middle" align="left">[<a href="#Concept-Index" title="Index">Index</a>]</td>
884<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
885</tr></table>
886<h2 class="section">4.2 Expressions</h2>
887
888<ul>
889<li> Integers in decimal, octal and hexa are supported.
890
891</li><li> Unary operators: +, -, ~.
892
893</li><li> Binary operators in decreasing priority order:
894
895<ol>
896<li> *, /, %
897</li><li> &amp;, |, ^
898</li><li> +, -
899</li></ol>
900
901</li><li> A value is either an absolute number or a label plus an offset.
902All operators accept absolute values except &rsquo;+&rsquo; and &rsquo;-&rsquo;. &rsquo;+&rsquo; or &rsquo;-&rsquo; can be
903used to add an offset to a label. &rsquo;-&rsquo; supports two labels only if they
904are the same or if they are both defined and in the same section.
905
906</li></ul>
907
908<hr size="6">
909<a name="Labels"></a>
910<table cellpadding="1" cellspacing="1" border="0">
911<tr><td valign="middle" align="left">[<a href="#Expressions" title="Previous section in reading order"> &lt; </a>]</td>
912<td valign="middle" align="left">[<a href="#Directives" title="Next section in reading order"> &gt; </a>]</td>
913<td valign="middle" align="left"> &nbsp; </td>
914<td valign="middle" align="left">[<a href="#asm" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
915<td valign="middle" align="left">[<a href="#asm" title="Up section"> Up </a>]</td>
916<td valign="middle" align="left">[<a href="#linker" title="Next chapter"> &gt;&gt; </a>]</td>
917<td valign="middle" align="left"> &nbsp; </td>
918<td valign="middle" align="left"> &nbsp; </td>
919<td valign="middle" align="left"> &nbsp; </td>
920<td valign="middle" align="left"> &nbsp; </td>
921<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
922<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
923<td valign="middle" align="left">[<a href="#Concept-Index" title="Index">Index</a>]</td>
924<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
925</tr></table>
926<h2 class="section">4.3 Labels</h2>
927
928<ul>
929<li> All labels are considered as local, except undefined ones.
930
931</li><li> Numeric labels can be used as local <code>gas</code>-like labels.
932They can be defined several times in the same source. Use &rsquo;b&rsquo;
933(backward) or &rsquo;f&rsquo; (forward) as suffix to reference them:
934
935<table><tr><td>&nbsp;</td><td><pre class="example"> 1:
936 jmp 1b /* jump to '1' label before */
937 jmp 1f /* jump to '1' label after */
938 1:
939</pre></td></tr></table>
940
941</li></ul>
942
943<hr size="6">
944<a name="Directives"></a>
945<table cellpadding="1" cellspacing="1" border="0">
946<tr><td valign="middle" align="left">[<a href="#Labels" title="Previous section in reading order"> &lt; </a>]</td>
947<td valign="middle" align="left">[<a href="#X86-Assembler" title="Next section in reading order"> &gt; </a>]</td>
948<td valign="middle" align="left"> &nbsp; </td>
949<td valign="middle" align="left">[<a href="#asm" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
950<td valign="middle" align="left">[<a href="#asm" title="Up section"> Up </a>]</td>
951<td valign="middle" align="left">[<a href="#linker" title="Next chapter"> &gt;&gt; </a>]</td>
952<td valign="middle" align="left"> &nbsp; </td>
953<td valign="middle" align="left"> &nbsp; </td>
954<td valign="middle" align="left"> &nbsp; </td>
955<td valign="middle" align="left"> &nbsp; </td>
956<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
957<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
958<td valign="middle" align="left">[<a href="#Concept-Index" title="Index">Index</a>]</td>
959<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
960</tr></table>
961<h2 class="section">4.4 Directives</h2>
962<a name="index-assembler-directives"></a>
963<a name="index-directives_002c-assembler"></a>
964<a name="index-align-directive"></a>
965<a name="index-skip-directive"></a>
966<a name="index-space-directive"></a>
967<a name="index-byte-directive"></a>
968<a name="index-word-directive"></a>
969<a name="index-short-directive"></a>
970<a name="index-int-directive"></a>
971<a name="index-long-directive"></a>
972<a name="index-quad-directive"></a>
973<a name="index-globl-directive"></a>
974<a name="index-global-directive"></a>
975<a name="index-section-directive"></a>
976<a name="index-text-directive"></a>
977<a name="index-data-directive"></a>
978<a name="index-bss-directive"></a>
979<a name="index-fill-directive"></a>
980<a name="index-org-directive"></a>
981<a name="index-previous-directive"></a>
982<a name="index-string-directive"></a>
983<a name="index-asciz-directive"></a>
984<a name="index-ascii-directive"></a>
985
986<p>All directives are preceeded by a &rsquo;.&rsquo;. The following directives are
987supported:
988</p>
989<ul>
990<li> .align n[,value]
991</li><li> .skip n[,value]
992</li><li> .space n[,value]
993</li><li> .byte value1[,...]
994</li><li> .word value1[,...]
995</li><li> .short value1[,...]
996</li><li> .int value1[,...]
997</li><li> .long value1[,...]
998</li><li> .quad immediate_value1[,...]
999</li><li> .globl symbol
1000</li><li> .global symbol
1001</li><li> .section section
1002</li><li> .text
1003</li><li> .data
1004</li><li> .bss
1005</li><li> .fill repeat[,size[,value]]
1006</li><li> .org n
1007</li><li> .previous
1008</li><li> .string string[,...]
1009</li><li> .asciz string[,...]
1010</li><li> .ascii string[,...]
1011</li></ul>
1012
1013<hr size="6">
1014<a name="X86-Assembler"></a>
1015<table cellpadding="1" cellspacing="1" border="0">
1016<tr><td valign="middle" align="left">[<a href="#Directives" title="Previous section in reading order"> &lt; </a>]</td>
1017<td valign="middle" align="left">[<a href="#linker" title="Next section in reading order"> &gt; </a>]</td>
1018<td valign="middle" align="left"> &nbsp; </td>
1019<td valign="middle" align="left">[<a href="#asm" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
1020<td valign="middle" align="left">[<a href="#asm" title="Up section"> Up </a>]</td>
1021<td valign="middle" align="left">[<a href="#linker" title="Next chapter"> &gt;&gt; </a>]</td>
1022<td valign="middle" align="left"> &nbsp; </td>
1023<td valign="middle" align="left"> &nbsp; </td>
1024<td valign="middle" align="left"> &nbsp; </td>
1025<td valign="middle" align="left"> &nbsp; </td>
1026<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
1027<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
1028<td valign="middle" align="left">[<a href="#Concept-Index" title="Index">Index</a>]</td>
1029<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
1030</tr></table>
1031<h2 class="section">4.5 X86 Assembler</h2>
1032<a name="index-assembler"></a>
1033
1034<p>All X86 opcodes are supported. Only ATT syntax is supported (source
1035then destination operand order). If no size suffix is given, TinyCC
1036tries to guess it from the operand sizes.
1037</p>
1038<p>Currently, MMX opcodes are supported but not SSE ones.
1039</p>
1040<hr size="6">
1041<a name="linker"></a>
1042<table cellpadding="1" cellspacing="1" border="0">
1043<tr><td valign="middle" align="left">[<a href="#X86-Assembler" title="Previous section in reading order"> &lt; </a>]</td>
1044<td valign="middle" align="left">[<a href="#ELF-file-generation" title="Next section in reading order"> &gt; </a>]</td>
1045<td valign="middle" align="left"> &nbsp; </td>
1046<td valign="middle" align="left">[<a href="#asm" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
1047<td valign="middle" align="left">[<a href="#Top" title="Up section"> Up </a>]</td>
1048<td valign="middle" align="left">[<a href="#Bounds" title="Next chapter"> &gt;&gt; </a>]</td>
1049<td valign="middle" align="left"> &nbsp; </td>
1050<td valign="middle" align="left"> &nbsp; </td>
1051<td valign="middle" align="left"> &nbsp; </td>
1052<td valign="middle" align="left"> &nbsp; </td>
1053<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
1054<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
1055<td valign="middle" align="left">[<a href="#Concept-Index" title="Index">Index</a>]</td>
1056<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
1057</tr></table>
1058<a name="TinyCC-Linker"></a>
1059<h1 class="chapter">5. TinyCC Linker</h1>
1060<a name="index-linker"></a>
1061
1062<hr size="6">
1063<a name="ELF-file-generation"></a>
1064<table cellpadding="1" cellspacing="1" border="0">
1065<tr><td valign="middle" align="left">[<a href="#linker" title="Previous section in reading order"> &lt; </a>]</td>
1066<td valign="middle" align="left">[<a href="#ELF-file-loader" title="Next section in reading order"> &gt; </a>]</td>
1067<td valign="middle" align="left"> &nbsp; </td>
1068<td valign="middle" align="left">[<a href="#linker" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
1069<td valign="middle" align="left">[<a href="#linker" title="Up section"> Up </a>]</td>
1070<td valign="middle" align="left">[<a href="#Bounds" title="Next chapter"> &gt;&gt; </a>]</td>
1071<td valign="middle" align="left"> &nbsp; </td>
1072<td valign="middle" align="left"> &nbsp; </td>
1073<td valign="middle" align="left"> &nbsp; </td>
1074<td valign="middle" align="left"> &nbsp; </td>
1075<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
1076<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
1077<td valign="middle" align="left">[<a href="#Concept-Index" title="Index">Index</a>]</td>
1078<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
1079</tr></table>
1080<h2 class="section">5.1 ELF file generation</h2>
1081<a name="index-ELF"></a>
1082
1083<p>TCC can directly output relocatable ELF files (object files),
1084executable ELF files and dynamic ELF libraries without relying on an
1085external linker.
1086</p>
1087<p>Dynamic ELF libraries can be output but the C compiler does not generate
1088position independent code (PIC). It means that the dynamic library
1089code generated by TCC cannot be factorized among processes yet.
1090</p>
1091<p>TCC linker eliminates unreferenced object code in libraries. A single pass is
1092done on the object and library list, so the order in which object files and
1093libraries are specified is important (same constraint as GNU ld). No grouping
1094options (&lsquo;<samp>--start-group</samp>&rsquo; and &lsquo;<samp>--end-group</samp>&rsquo;) are supported.
1095</p>
1096<hr size="6">
1097<a name="ELF-file-loader"></a>
1098<table cellpadding="1" cellspacing="1" border="0">
1099<tr><td valign="middle" align="left">[<a href="#ELF-file-generation" title="Previous section in reading order"> &lt; </a>]</td>
1100<td valign="middle" align="left">[<a href="#PE_002di386-file-generation" title="Next section in reading order"> &gt; </a>]</td>
1101<td valign="middle" align="left"> &nbsp; </td>
1102<td valign="middle" align="left">[<a href="#linker" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
1103<td valign="middle" align="left">[<a href="#linker" title="Up section"> Up </a>]</td>
1104<td valign="middle" align="left">[<a href="#Bounds" title="Next chapter"> &gt;&gt; </a>]</td>
1105<td valign="middle" align="left"> &nbsp; </td>
1106<td valign="middle" align="left"> &nbsp; </td>
1107<td valign="middle" align="left"> &nbsp; </td>
1108<td valign="middle" align="left"> &nbsp; </td>
1109<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
1110<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
1111<td valign="middle" align="left">[<a href="#Concept-Index" title="Index">Index</a>]</td>
1112<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
1113</tr></table>
1114<h2 class="section">5.2 ELF file loader</h2>
1115
1116<p>TCC can load ELF object files, archives (.a files) and dynamic
1117libraries (.so).
1118</p>
1119<hr size="6">
1120<a name="PE_002di386-file-generation"></a>
1121<table cellpadding="1" cellspacing="1" border="0">
1122<tr><td valign="middle" align="left">[<a href="#ELF-file-loader" title="Previous section in reading order"> &lt; </a>]</td>
1123<td valign="middle" align="left">[<a href="#GNU-Linker-Scripts" title="Next section in reading order"> &gt; </a>]</td>
1124<td valign="middle" align="left"> &nbsp; </td>
1125<td valign="middle" align="left">[<a href="#linker" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
1126<td valign="middle" align="left">[<a href="#linker" title="Up section"> Up </a>]</td>
1127<td valign="middle" align="left">[<a href="#Bounds" title="Next chapter"> &gt;&gt; </a>]</td>
1128<td valign="middle" align="left"> &nbsp; </td>
1129<td valign="middle" align="left"> &nbsp; </td>
1130<td valign="middle" align="left"> &nbsp; </td>
1131<td valign="middle" align="left"> &nbsp; </td>
1132<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
1133<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
1134<td valign="middle" align="left">[<a href="#Concept-Index" title="Index">Index</a>]</td>
1135<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
1136</tr></table>
1137<h2 class="section">5.3 PE-i386 file generation</h2>
1138<a name="index-PE_002di386"></a>
1139
1140<p>TCC for Windows supports the native Win32 executable file format (PE-i386). It
1141generates EXE files (console and gui) and DLL files.
1142</p>
1143<p>For usage on Windows, see also tcc-win32.txt.
1144</p>
1145<hr size="6">
1146<a name="GNU-Linker-Scripts"></a>
1147<table cellpadding="1" cellspacing="1" border="0">
1148<tr><td valign="middle" align="left">[<a href="#PE_002di386-file-generation" title="Previous section in reading order"> &lt; </a>]</td>
1149<td valign="middle" align="left">[<a href="#Bounds" title="Next section in reading order"> &gt; </a>]</td>
1150<td valign="middle" align="left"> &nbsp; </td>
1151<td valign="middle" align="left">[<a href="#linker" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
1152<td valign="middle" align="left">[<a href="#linker" title="Up section"> Up </a>]</td>
1153<td valign="middle" align="left">[<a href="#Bounds" title="Next chapter"> &gt;&gt; </a>]</td>
1154<td valign="middle" align="left"> &nbsp; </td>
1155<td valign="middle" align="left"> &nbsp; </td>
1156<td valign="middle" align="left"> &nbsp; </td>
1157<td valign="middle" align="left"> &nbsp; </td>
1158<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
1159<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
1160<td valign="middle" align="left">[<a href="#Concept-Index" title="Index">Index</a>]</td>
1161<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
1162</tr></table>
1163<h2 class="section">5.4 GNU Linker Scripts</h2>
1164<a name="index-scripts_002c-linker"></a>
1165<a name="index-linker-scripts"></a>
1166<a name="index-GROUP_002c-linker-command"></a>
1167<a name="index-FILE_002c-linker-command"></a>
1168<a name="index-OUTPUT_005fFORMAT_002c-linker-command"></a>
1169<a name="index-TARGET_002c-linker-command"></a>
1170
1171<p>Because on many Linux systems some dynamic libraries (such as
1172&lsquo;<tt>/usr/lib/libc.so</tt>&rsquo;) are in fact GNU ld link scripts (horrible!),
1173the TCC linker also supports a subset of GNU ld scripts.
1174</p>
1175<p>The <code>GROUP</code> and <code>FILE</code> commands are supported. <code>OUTPUT_FORMAT</code>
1176and <code>TARGET</code> are ignored.
1177</p>
1178<p>Example from &lsquo;<tt>/usr/lib/libc.so</tt>&rsquo;:
1179</p><table><tr><td>&nbsp;</td><td><pre class="example">/* GNU ld script
1180 Use the shared library, but some functions are only in
1181 the static library, so try that secondarily. */
1182GROUP ( /lib/libc.so.6 /usr/lib/libc_nonshared.a )
1183</pre></td></tr></table>
1184
1185<hr size="6">
1186<a name="Bounds"></a>
1187<table cellpadding="1" cellspacing="1" border="0">
1188<tr><td valign="middle" align="left">[<a href="#GNU-Linker-Scripts" title="Previous section in reading order"> &lt; </a>]</td>
1189<td valign="middle" align="left">[<a href="#Libtcc" title="Next section in reading order"> &gt; </a>]</td>
1190<td valign="middle" align="left"> &nbsp; </td>
1191<td valign="middle" align="left">[<a href="#linker" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
1192<td valign="middle" align="left">[<a href="#Top" title="Up section"> Up </a>]</td>
1193<td valign="middle" align="left">[<a href="#Libtcc" title="Next chapter"> &gt;&gt; </a>]</td>
1194<td valign="middle" align="left"> &nbsp; </td>
1195<td valign="middle" align="left"> &nbsp; </td>
1196<td valign="middle" align="left"> &nbsp; </td>
1197<td valign="middle" align="left"> &nbsp; </td>
1198<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
1199<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
1200<td valign="middle" align="left">[<a href="#Concept-Index" title="Index">Index</a>]</td>
1201<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
1202</tr></table>
1203<a name="TinyCC-Memory-and-Bound-checks"></a>
1204<h1 class="chapter">6. TinyCC Memory and Bound checks</h1>
1205<a name="index-bound-checks"></a>
1206<a name="index-memory-checks"></a>
1207
1208<p>This feature is activated with the &lsquo;<samp>-b</samp>&rsquo; (see section <a href="#Invoke">Command line invocation</a>).
1209</p>
1210<p>Note that pointer size is <em>unchanged</em> and that code generated
1211with bound checks is <em>fully compatible</em> with unchecked
1212code. When a pointer comes from unchecked code, it is assumed to be
1213valid. Even very obscure C code with casts should work correctly.
1214</p>
1215<p>For more information about the ideas behind this method, see
1216<a href="http://www.doc.ic.ac.uk/~phjk/BoundsChecking.html">http://www.doc.ic.ac.uk/~phjk/BoundsChecking.html</a>.
1217</p>
1218<p>Here are some examples of caught errors:
1219</p>
1220<dl compact="compact">
1221<dt> Invalid range with standard string function:</dt>
1222<dd><table><tr><td>&nbsp;</td><td><pre class="example">{
1223 char tab[10];
1224 memset(tab, 0, 11);
1225}
1226</pre></td></tr></table>
1227
1228</dd>
1229<dt> Out of bounds-error in global or local arrays:</dt>
1230<dd><table><tr><td>&nbsp;</td><td><pre class="example">{
1231 int tab[10];
1232 for(i=0;i&lt;11;i++) {
1233 sum += tab[i];
1234 }
1235}
1236</pre></td></tr></table>
1237
1238</dd>
1239<dt> Out of bounds-error in malloc&rsquo;ed data:</dt>
1240<dd><table><tr><td>&nbsp;</td><td><pre class="example">{
1241 int *tab;
1242 tab = malloc(20 * sizeof(int));
1243 for(i=0;i&lt;21;i++) {
1244 sum += tab4[i];
1245 }
1246 free(tab);
1247}
1248</pre></td></tr></table>
1249
1250</dd>
1251<dt> Access of freed memory:</dt>
1252<dd><table><tr><td>&nbsp;</td><td><pre class="example">{
1253 int *tab;
1254 tab = malloc(20 * sizeof(int));
1255 free(tab);
1256 for(i=0;i&lt;20;i++) {
1257 sum += tab4[i];
1258 }
1259}
1260</pre></td></tr></table>
1261
1262</dd>
1263<dt> Double free:</dt>
1264<dd><table><tr><td>&nbsp;</td><td><pre class="example">{
1265 int *tab;
1266 tab = malloc(20 * sizeof(int));
1267 free(tab);
1268 free(tab);
1269}
1270</pre></td></tr></table>
1271
1272</dd>
1273</dl>
1274
1275<hr size="6">
1276<a name="Libtcc"></a>
1277<table cellpadding="1" cellspacing="1" border="0">
1278<tr><td valign="middle" align="left">[<a href="#Bounds" title="Previous section in reading order"> &lt; </a>]</td>
1279<td valign="middle" align="left">[<a href="#devel" title="Next section in reading order"> &gt; </a>]</td>
1280<td valign="middle" align="left"> &nbsp; </td>
1281<td valign="middle" align="left">[<a href="#Bounds" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
1282<td valign="middle" align="left">[<a href="#Top" title="Up section"> Up </a>]</td>
1283<td valign="middle" align="left">[<a href="#devel" title="Next chapter"> &gt;&gt; </a>]</td>
1284<td valign="middle" align="left"> &nbsp; </td>
1285<td valign="middle" align="left"> &nbsp; </td>
1286<td valign="middle" align="left"> &nbsp; </td>
1287<td valign="middle" align="left"> &nbsp; </td>
1288<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
1289<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
1290<td valign="middle" align="left">[<a href="#Concept-Index" title="Index">Index</a>]</td>
1291<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
1292</tr></table>
1293<a name="The-libtcc-library"></a>
1294<h1 class="chapter">7. The <code>libtcc</code> library</h1>
1295
1296<p>The <code>libtcc</code> library enables you to use TCC as a backend for
1297dynamic code generation.
1298</p>
1299<p>Read the &lsquo;<tt>libtcc.h</tt>&rsquo; to have an overview of the API. Read
1300&lsquo;<tt>libtcc_test.c</tt>&rsquo; to have a very simple example.
1301</p>
1302<p>The idea consists in giving a C string containing the program you want
1303to compile directly to <code>libtcc</code>. Then you can access to any global
1304symbol (function or variable) defined.
1305</p>
1306<hr size="6">
1307<a name="devel"></a>
1308<table cellpadding="1" cellspacing="1" border="0">
1309<tr><td valign="middle" align="left">[<a href="#Libtcc" title="Previous section in reading order"> &lt; </a>]</td>
1310<td valign="middle" align="left">[<a href="#File-reading" title="Next section in reading order"> &gt; </a>]</td>
1311<td valign="middle" align="left"> &nbsp; </td>
1312<td valign="middle" align="left">[<a href="#Libtcc" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
1313<td valign="middle" align="left">[<a href="#Top" title="Up section"> Up </a>]</td>
1314<td valign="middle" align="left">[<a href="#Concept-Index" title="Next chapter"> &gt;&gt; </a>]</td>
1315<td valign="middle" align="left"> &nbsp; </td>
1316<td valign="middle" align="left"> &nbsp; </td>
1317<td valign="middle" align="left"> &nbsp; </td>
1318<td valign="middle" align="left"> &nbsp; </td>
1319<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
1320<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
1321<td valign="middle" align="left">[<a href="#Concept-Index" title="Index">Index</a>]</td>
1322<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
1323</tr></table>
1324<a name="Developer_0027s-guide"></a>
1325<h1 class="chapter">8. Developer&rsquo;s guide</h1>
1326
1327<p>This chapter gives some hints to understand how TCC works. You can skip
1328it if you do not intend to modify the TCC code.
1329</p>
1330<hr size="6">
1331<a name="File-reading"></a>
1332<table cellpadding="1" cellspacing="1" border="0">
1333<tr><td valign="middle" align="left">[<a href="#devel" title="Previous section in reading order"> &lt; </a>]</td>
1334<td valign="middle" align="left">[<a href="#Lexer" title="Next section in reading order"> &gt; </a>]</td>
1335<td valign="middle" align="left"> &nbsp; </td>
1336<td valign="middle" align="left">[<a href="#devel" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
1337<td valign="middle" align="left">[<a href="#devel" title="Up section"> Up </a>]</td>
1338<td valign="middle" align="left">[<a href="#Concept-Index" title="Next chapter"> &gt;&gt; </a>]</td>
1339<td valign="middle" align="left"> &nbsp; </td>
1340<td valign="middle" align="left"> &nbsp; </td>
1341<td valign="middle" align="left"> &nbsp; </td>
1342<td valign="middle" align="left"> &nbsp; </td>
1343<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
1344<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
1345<td valign="middle" align="left">[<a href="#Concept-Index" title="Index">Index</a>]</td>
1346<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
1347</tr></table>
1348<h2 class="section">8.1 File reading</h2>
1349
1350<p>The <code>BufferedFile</code> structure contains the context needed to read a
1351file, including the current line number. <code>tcc_open()</code> opens a new
1352file and <code>tcc_close()</code> closes it. <code>inp()</code> returns the next
1353character.
1354</p>
1355<hr size="6">
1356<a name="Lexer"></a>
1357<table cellpadding="1" cellspacing="1" border="0">
1358<tr><td valign="middle" align="left">[<a href="#File-reading" title="Previous section in reading order"> &lt; </a>]</td>
1359<td valign="middle" align="left">[<a href="#Parser" title="Next section in reading order"> &gt; </a>]</td>
1360<td valign="middle" align="left"> &nbsp; </td>
1361<td valign="middle" align="left">[<a href="#devel" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
1362<td valign="middle" align="left">[<a href="#devel" title="Up section"> Up </a>]</td>
1363<td valign="middle" align="left">[<a href="#Concept-Index" title="Next chapter"> &gt;&gt; </a>]</td>
1364<td valign="middle" align="left"> &nbsp; </td>
1365<td valign="middle" align="left"> &nbsp; </td>
1366<td valign="middle" align="left"> &nbsp; </td>
1367<td valign="middle" align="left"> &nbsp; </td>
1368<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
1369<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
1370<td valign="middle" align="left">[<a href="#Concept-Index" title="Index">Index</a>]</td>
1371<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
1372</tr></table>
1373<h2 class="section">8.2 Lexer</h2>
1374
1375<p><code>next()</code> reads the next token in the current
1376file. <code>next_nomacro()</code> reads the next token without macro
1377expansion.
1378</p>
1379<p><code>tok</code> contains the current token (see <code>TOK_xxx</code>)
1380constants. Identifiers and keywords are also keywords. <code>tokc</code>
1381contains additional infos about the token (for example a constant value
1382if number or string token).
1383</p>
1384<hr size="6">
1385<a name="Parser"></a>
1386<table cellpadding="1" cellspacing="1" border="0">
1387<tr><td valign="middle" align="left">[<a href="#Lexer" title="Previous section in reading order"> &lt; </a>]</td>
1388<td valign="middle" align="left">[<a href="#Types" title="Next section in reading order"> &gt; </a>]</td>
1389<td valign="middle" align="left"> &nbsp; </td>
1390<td valign="middle" align="left">[<a href="#devel" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
1391<td valign="middle" align="left">[<a href="#devel" title="Up section"> Up </a>]</td>
1392<td valign="middle" align="left">[<a href="#Concept-Index" title="Next chapter"> &gt;&gt; </a>]</td>
1393<td valign="middle" align="left"> &nbsp; </td>
1394<td valign="middle" align="left"> &nbsp; </td>
1395<td valign="middle" align="left"> &nbsp; </td>
1396<td valign="middle" align="left"> &nbsp; </td>
1397<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
1398<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
1399<td valign="middle" align="left">[<a href="#Concept-Index" title="Index">Index</a>]</td>
1400<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
1401</tr></table>
1402<h2 class="section">8.3 Parser</h2>
1403
1404<p>The parser is hardcoded (yacc is not necessary). It does only one pass,
1405except:
1406</p>
1407<ul>
1408<li> For initialized arrays with unknown size, a first pass
1409is done to count the number of elements.
1410
1411</li><li> For architectures where arguments are evaluated in
1412reverse order, a first pass is done to reverse the argument order.
1413
1414</li></ul>
1415
1416<hr size="6">
1417<a name="Types"></a>
1418<table cellpadding="1" cellspacing="1" border="0">
1419<tr><td valign="middle" align="left">[<a href="#Parser" title="Previous section in reading order"> &lt; </a>]</td>
1420<td valign="middle" align="left">[<a href="#Symbols" title="Next section in reading order"> &gt; </a>]</td>
1421<td valign="middle" align="left"> &nbsp; </td>
1422<td valign="middle" align="left">[<a href="#devel" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
1423<td valign="middle" align="left">[<a href="#devel" title="Up section"> Up </a>]</td>
1424<td valign="middle" align="left">[<a href="#Concept-Index" title="Next chapter"> &gt;&gt; </a>]</td>
1425<td valign="middle" align="left"> &nbsp; </td>
1426<td valign="middle" align="left"> &nbsp; </td>
1427<td valign="middle" align="left"> &nbsp; </td>
1428<td valign="middle" align="left"> &nbsp; </td>
1429<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
1430<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
1431<td valign="middle" align="left">[<a href="#Concept-Index" title="Index">Index</a>]</td>
1432<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
1433</tr></table>
1434<h2 class="section">8.4 Types</h2>
1435
1436<p>The types are stored in a single &rsquo;int&rsquo; variable. It was choosen in the
1437first stages of development when tcc was much simpler. Now, it may not
1438be the best solution.
1439</p>
1440<table><tr><td>&nbsp;</td><td><pre class="example">#define VT_INT 0 /* integer type */
1441#define VT_BYTE 1 /* signed byte type */
1442#define VT_SHORT 2 /* short type */
1443#define VT_VOID 3 /* void type */
1444#define VT_PTR 4 /* pointer */
1445#define VT_ENUM 5 /* enum definition */
1446#define VT_FUNC 6 /* function type */
1447#define VT_STRUCT 7 /* struct/union definition */
1448#define VT_FLOAT 8 /* IEEE float */
1449#define VT_DOUBLE 9 /* IEEE double */
1450#define VT_LDOUBLE 10 /* IEEE long double */
1451#define VT_BOOL 11 /* ISOC99 boolean type */
1452#define VT_LLONG 12 /* 64 bit integer */
1453#define VT_LONG 13 /* long integer (NEVER USED as type, only
1454 during parsing) */
1455#define VT_BTYPE 0x000f /* mask for basic type */
1456#define VT_UNSIGNED 0x0010 /* unsigned type */
1457#define VT_ARRAY 0x0020 /* array type (also has VT_PTR) */
1458#define VT_VLA 0x20000 /* VLA type (also has VT_PTR and VT_ARRAY) */
1459#define VT_BITFIELD 0x0040 /* bitfield modifier */
1460#define VT_CONSTANT 0x0800 /* const modifier */
1461#define VT_VOLATILE 0x1000 /* volatile modifier */
1462#define VT_SIGNED 0x2000 /* signed type */
1463
1464#define VT_STRUCT_SHIFT 18 /* structure/enum name shift (14 bits left) */
1465</pre></td></tr></table>
1466
1467<p>When a reference to another type is needed (for pointers, functions and
1468structures), the <code>32 - VT_STRUCT_SHIFT</code> high order bits are used to
1469store an identifier reference.
1470</p>
1471<p>The <code>VT_UNSIGNED</code> flag can be set for chars, shorts, ints and long
1472longs.
1473</p>
1474<p>Arrays are considered as pointers <code>VT_PTR</code> with the flag
1475<code>VT_ARRAY</code> set. Variable length arrays are considered as special
1476arrays and have flag <code>VT_VLA</code> set instead of <code>VT_ARRAY</code>.
1477</p>
1478<p>The <code>VT_BITFIELD</code> flag can be set for chars, shorts, ints and long
1479longs. If it is set, then the bitfield position is stored from bits
1480VT_STRUCT_SHIFT to VT_STRUCT_SHIFT + 5 and the bit field size is stored
1481from bits VT_STRUCT_SHIFT + 6 to VT_STRUCT_SHIFT + 11.
1482</p>
1483<p><code>VT_LONG</code> is never used except during parsing.
1484</p>
1485<p>During parsing, the storage of an object is also stored in the type
1486integer:
1487</p>
1488<table><tr><td>&nbsp;</td><td><pre class="example">#define VT_EXTERN 0x00000080 /* extern definition */
1489#define VT_STATIC 0x00000100 /* static variable */
1490#define VT_TYPEDEF 0x00000200 /* typedef definition */
1491#define VT_INLINE 0x00000400 /* inline definition */
1492#define VT_IMPORT 0x00004000 /* win32: extern data imported from dll */
1493#define VT_EXPORT 0x00008000 /* win32: data exported from dll */
1494#define VT_WEAK 0x00010000 /* win32: data exported from dll */
1495</pre></td></tr></table>
1496
1497<hr size="6">
1498<a name="Symbols"></a>
1499<table cellpadding="1" cellspacing="1" border="0">
1500<tr><td valign="middle" align="left">[<a href="#Types" title="Previous section in reading order"> &lt; </a>]</td>
1501<td valign="middle" align="left">[<a href="#Sections" title="Next section in reading order"> &gt; </a>]</td>
1502<td valign="middle" align="left"> &nbsp; </td>
1503<td valign="middle" align="left">[<a href="#devel" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
1504<td valign="middle" align="left">[<a href="#devel" title="Up section"> Up </a>]</td>
1505<td valign="middle" align="left">[<a href="#Concept-Index" title="Next chapter"> &gt;&gt; </a>]</td>
1506<td valign="middle" align="left"> &nbsp; </td>
1507<td valign="middle" align="left"> &nbsp; </td>
1508<td valign="middle" align="left"> &nbsp; </td>
1509<td valign="middle" align="left"> &nbsp; </td>
1510<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
1511<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
1512<td valign="middle" align="left">[<a href="#Concept-Index" title="Index">Index</a>]</td>
1513<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
1514</tr></table>
1515<h2 class="section">8.5 Symbols</h2>
1516
1517<p>All symbols are stored in hashed symbol stacks. Each symbol stack
1518contains <code>Sym</code> structures.
1519</p>
1520<p><code>Sym.v</code> contains the symbol name (remember
1521an idenfier is also a token, so a string is never necessary to store
1522it). <code>Sym.t</code> gives the type of the symbol. <code>Sym.r</code> is usually
1523the register in which the corresponding variable is stored. <code>Sym.c</code> is
1524usually a constant associated to the symbol like its address for normal
1525symbols, and the number of entries for symbols representing arrays.
1526Variable length array types use <code>Sym.c</code> as a location on the stack
1527which holds the runtime sizeof for the type.
1528</p>
1529<p>Four main symbol stacks are defined:
1530</p>
1531<dl compact="compact">
1532<dt> <code>define_stack</code></dt>
1533<dd><p>for the macros (<code>#define</code>s).
1534</p>
1535</dd>
1536<dt> <code>global_stack</code></dt>
1537<dd><p>for the global variables, functions and types.
1538</p>
1539</dd>
1540<dt> <code>local_stack</code></dt>
1541<dd><p>for the local variables, functions and types.
1542</p>
1543</dd>
1544<dt> <code>global_label_stack</code></dt>
1545<dd><p>for the local labels (for <code>goto</code>).
1546</p>
1547</dd>
1548<dt> <code>label_stack</code></dt>
1549<dd><p>for GCC block local labels (see the <code>__label__</code> keyword).
1550</p>
1551</dd>
1552</dl>
1553
1554<p><code>sym_push()</code> is used to add a new symbol in the local symbol
1555stack. If no local symbol stack is active, it is added in the global
1556symbol stack.
1557</p>
1558<p><code>sym_pop(st,b)</code> pops symbols from the symbol stack <var>st</var> until
1559the symbol <var>b</var> is on the top of stack. If <var>b</var> is NULL, the stack
1560is emptied.
1561</p>
1562<p><code>sym_find(v)</code> return the symbol associated to the identifier
1563<var>v</var>. The local stack is searched first from top to bottom, then the
1564global stack.
1565</p>
1566<hr size="6">
1567<a name="Sections"></a>
1568<table cellpadding="1" cellspacing="1" border="0">
1569<tr><td valign="middle" align="left">[<a href="#Symbols" title="Previous section in reading order"> &lt; </a>]</td>
1570<td valign="middle" align="left">[<a href="#Code-generation" title="Next section in reading order"> &gt; </a>]</td>
1571<td valign="middle" align="left"> &nbsp; </td>
1572<td valign="middle" align="left">[<a href="#devel" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
1573<td valign="middle" align="left">[<a href="#devel" title="Up section"> Up </a>]</td>
1574<td valign="middle" align="left">[<a href="#Concept-Index" title="Next chapter"> &gt;&gt; </a>]</td>
1575<td valign="middle" align="left"> &nbsp; </td>
1576<td valign="middle" align="left"> &nbsp; </td>
1577<td valign="middle" align="left"> &nbsp; </td>
1578<td valign="middle" align="left"> &nbsp; </td>
1579<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
1580<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
1581<td valign="middle" align="left">[<a href="#Concept-Index" title="Index">Index</a>]</td>
1582<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
1583</tr></table>
1584<h2 class="section">8.6 Sections</h2>
1585
1586<p>The generated code and datas are written in sections. The structure
1587<code>Section</code> contains all the necessary information for a given
1588section. <code>new_section()</code> creates a new section. ELF file semantics
1589is assumed for each section.
1590</p>
1591<p>The following sections are predefined:
1592</p>
1593<dl compact="compact">
1594<dt> <code>text_section</code></dt>
1595<dd><p>is the section containing the generated code. <var>ind</var> contains the
1596current position in the code section.
1597</p>
1598</dd>
1599<dt> <code>data_section</code></dt>
1600<dd><p>contains initialized data
1601</p>
1602</dd>
1603<dt> <code>bss_section</code></dt>
1604<dd><p>contains uninitialized data
1605</p>
1606</dd>
1607<dt> <code>bounds_section</code></dt>
1608<dt> <code>lbounds_section</code></dt>
1609<dd><p>are used when bound checking is activated
1610</p>
1611</dd>
1612<dt> <code>stab_section</code></dt>
1613<dt> <code>stabstr_section</code></dt>
1614<dd><p>are used when debugging is actived to store debug information
1615</p>
1616</dd>
1617<dt> <code>symtab_section</code></dt>
1618<dt> <code>strtab_section</code></dt>
1619<dd><p>contain the exported symbols (currently only used for debugging).
1620</p>
1621</dd>
1622</dl>
1623
1624<hr size="6">
1625<a name="Code-generation"></a>
1626<table cellpadding="1" cellspacing="1" border="0">
1627<tr><td valign="middle" align="left">[<a href="#Sections" title="Previous section in reading order"> &lt; </a>]</td>
1628<td valign="middle" align="left">[<a href="#Introduction-2" title="Next section in reading order"> &gt; </a>]</td>
1629<td valign="middle" align="left"> &nbsp; </td>
1630<td valign="middle" align="left">[<a href="#devel" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
1631<td valign="middle" align="left">[<a href="#devel" title="Up section"> Up </a>]</td>
1632<td valign="middle" align="left">[<a href="#Concept-Index" title="Next chapter"> &gt;&gt; </a>]</td>
1633<td valign="middle" align="left"> &nbsp; </td>
1634<td valign="middle" align="left"> &nbsp; </td>
1635<td valign="middle" align="left"> &nbsp; </td>
1636<td valign="middle" align="left"> &nbsp; </td>
1637<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
1638<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
1639<td valign="middle" align="left">[<a href="#Concept-Index" title="Index">Index</a>]</td>
1640<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
1641</tr></table>
1642<h2 class="section">8.7 Code generation</h2>
1643<a name="index-code-generation"></a>
1644
1645<hr size="6">
1646<a name="Introduction-2"></a>
1647<table cellpadding="1" cellspacing="1" border="0">
1648<tr><td valign="middle" align="left">[<a href="#Code-generation" title="Previous section in reading order"> &lt; </a>]</td>
1649<td valign="middle" align="left">[<a href="#The-value-stack" title="Next section in reading order"> &gt; </a>]</td>
1650<td valign="middle" align="left"> &nbsp; </td>
1651<td valign="middle" align="left">[<a href="#devel" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
1652<td valign="middle" align="left">[<a href="#Code-generation" title="Up section"> Up </a>]</td>
1653<td valign="middle" align="left">[<a href="#Concept-Index" title="Next chapter"> &gt;&gt; </a>]</td>
1654<td valign="middle" align="left"> &nbsp; </td>
1655<td valign="middle" align="left"> &nbsp; </td>
1656<td valign="middle" align="left"> &nbsp; </td>
1657<td valign="middle" align="left"> &nbsp; </td>
1658<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
1659<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
1660<td valign="middle" align="left">[<a href="#Concept-Index" title="Index">Index</a>]</td>
1661<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
1662</tr></table>
1663<h3 class="subsection">8.7.1 Introduction</h3>
1664
1665<p>The TCC code generator directly generates linked binary code in one
1666pass. It is rather unusual these days (see gcc for example which
1667generates text assembly), but it can be very fast and surprisingly
1668little complicated.
1669</p>
1670<p>The TCC code generator is register based. Optimization is only done at
1671the expression level. No intermediate representation of expression is
1672kept except the current values stored in the <em>value stack</em>.
1673</p>
1674<p>On x86, three temporary registers are used. When more registers are
1675needed, one register is spilled into a new temporary variable on the stack.
1676</p>
1677<hr size="6">
1678<a name="The-value-stack"></a>
1679<table cellpadding="1" cellspacing="1" border="0">
1680<tr><td valign="middle" align="left">[<a href="#Introduction-2" title="Previous section in reading order"> &lt; </a>]</td>
1681<td valign="middle" align="left">[<a href="#Manipulating-the-value-stack" title="Next section in reading order"> &gt; </a>]</td>
1682<td valign="middle" align="left"> &nbsp; </td>
1683<td valign="middle" align="left">[<a href="#devel" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
1684<td valign="middle" align="left">[<a href="#Code-generation" title="Up section"> Up </a>]</td>
1685<td valign="middle" align="left">[<a href="#Concept-Index" title="Next chapter"> &gt;&gt; </a>]</td>
1686<td valign="middle" align="left"> &nbsp; </td>
1687<td valign="middle" align="left"> &nbsp; </td>
1688<td valign="middle" align="left"> &nbsp; </td>
1689<td valign="middle" align="left"> &nbsp; </td>
1690<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
1691<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
1692<td valign="middle" align="left">[<a href="#Concept-Index" title="Index">Index</a>]</td>
1693<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
1694</tr></table>
1695<h3 class="subsection">8.7.2 The value stack</h3>
1696<a name="index-value-stack_002c-introduction"></a>
1697
1698<p>When an expression is parsed, its value is pushed on the value stack
1699(<var>vstack</var>). The top of the value stack is <var>vtop</var>. Each value
1700stack entry is the structure <code>SValue</code>.
1701</p>
1702<p><code>SValue.t</code> is the type. <code>SValue.r</code> indicates how the value is
1703currently stored in the generated code. It is usually a CPU register
1704index (<code>REG_xxx</code> constants), but additional values and flags are
1705defined:
1706</p>
1707<table><tr><td>&nbsp;</td><td><pre class="example">#define VT_CONST 0x00f0
1708#define VT_LLOCAL 0x00f1
1709#define VT_LOCAL 0x00f2
1710#define VT_CMP 0x00f3
1711#define VT_JMP 0x00f4
1712#define VT_JMPI 0x00f5
1713#define VT_LVAL 0x0100
1714#define VT_SYM 0x0200
1715#define VT_MUSTCAST 0x0400
1716#define VT_MUSTBOUND 0x0800
1717#define VT_BOUNDED 0x8000
1718#define VT_LVAL_BYTE 0x1000
1719#define VT_LVAL_SHORT 0x2000
1720#define VT_LVAL_UNSIGNED 0x4000
1721#define VT_LVAL_TYPE (VT_LVAL_BYTE | VT_LVAL_SHORT | VT_LVAL_UNSIGNED)
1722</pre></td></tr></table>
1723
1724<dl compact="compact">
1725<dt> <code>VT_CONST</code></dt>
1726<dd><p>indicates that the value is a constant. It is stored in the union
1727<code>SValue.c</code>, depending on its type.
1728</p>
1729</dd>
1730<dt> <code>VT_LOCAL</code></dt>
1731<dd><p>indicates a local variable pointer at offset <code>SValue.c.i</code> in the
1732stack.
1733</p>
1734</dd>
1735<dt> <code>VT_CMP</code></dt>
1736<dd><p>indicates that the value is actually stored in the CPU flags (i.e. the
1737value is the consequence of a test). The value is either 0 or 1. The
1738actual CPU flags used is indicated in <code>SValue.c.i</code>.
1739</p>
1740<p>If any code is generated which destroys the CPU flags, this value MUST be
1741put in a normal register.
1742</p>
1743</dd>
1744<dt> <code>VT_JMP</code></dt>
1745<dt> <code>VT_JMPI</code></dt>
1746<dd><p>indicates that the value is the consequence of a conditional jump. For VT_JMP,
1747it is 1 if the jump is taken, 0 otherwise. For VT_JMPI it is inverted.
1748</p>
1749<p>These values are used to compile the <code>||</code> and <code>&amp;&amp;</code> logical
1750operators.
1751</p>
1752<p>If any code is generated, this value MUST be put in a normal
1753register. Otherwise, the generated code won&rsquo;t be executed if the jump is
1754taken.
1755</p>
1756</dd>
1757<dt> <code>VT_LVAL</code></dt>
1758<dd><p>is a flag indicating that the value is actually an lvalue (left value of
1759an assignment). It means that the value stored is actually a pointer to
1760the wanted value.
1761</p>
1762<p>Understanding the use <code>VT_LVAL</code> is very important if you want to
1763understand how TCC works.
1764</p>
1765</dd>
1766<dt> <code>VT_LVAL_BYTE</code></dt>
1767<dt> <code>VT_LVAL_SHORT</code></dt>
1768<dt> <code>VT_LVAL_UNSIGNED</code></dt>
1769<dd><p>if the lvalue has an integer type, then these flags give its real
1770type. The type alone is not enough in case of cast optimisations.
1771</p>
1772</dd>
1773<dt> <code>VT_LLOCAL</code></dt>
1774<dd><p>is a saved lvalue on the stack. <code>VT_LLOCAL</code> should be eliminated
1775ASAP because its semantics are rather complicated.
1776</p>
1777</dd>
1778<dt> <code>VT_MUSTCAST</code></dt>
1779<dd><p>indicates that a cast to the value type must be performed if the value
1780is used (lazy casting).
1781</p>
1782</dd>
1783<dt> <code>VT_SYM</code></dt>
1784<dd><p>indicates that the symbol <code>SValue.sym</code> must be added to the constant.
1785</p>
1786</dd>
1787<dt> <code>VT_MUSTBOUND</code></dt>
1788<dt> <code>VT_BOUNDED</code></dt>
1789<dd><p>are only used for optional bound checking.
1790</p>
1791</dd>
1792</dl>
1793
1794<hr size="6">
1795<a name="Manipulating-the-value-stack"></a>
1796<table cellpadding="1" cellspacing="1" border="0">
1797<tr><td valign="middle" align="left">[<a href="#The-value-stack" title="Previous section in reading order"> &lt; </a>]</td>
1798<td valign="middle" align="left">[<a href="#CPU-dependent-code-generation" title="Next section in reading order"> &gt; </a>]</td>
1799<td valign="middle" align="left"> &nbsp; </td>
1800<td valign="middle" align="left">[<a href="#devel" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
1801<td valign="middle" align="left">[<a href="#Code-generation" title="Up section"> Up </a>]</td>
1802<td valign="middle" align="left">[<a href="#Concept-Index" title="Next chapter"> &gt;&gt; </a>]</td>
1803<td valign="middle" align="left"> &nbsp; </td>
1804<td valign="middle" align="left"> &nbsp; </td>
1805<td valign="middle" align="left"> &nbsp; </td>
1806<td valign="middle" align="left"> &nbsp; </td>
1807<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
1808<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
1809<td valign="middle" align="left">[<a href="#Concept-Index" title="Index">Index</a>]</td>
1810<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
1811</tr></table>
1812<h3 class="subsection">8.7.3 Manipulating the value stack</h3>
1813<a name="index-value-stack"></a>
1814
1815<p><code>vsetc()</code> and <code>vset()</code> pushes a new value on the value
1816stack. If the previous <var>vtop</var> was stored in a very unsafe place(for
1817example in the CPU flags), then some code is generated to put the
1818previous <var>vtop</var> in a safe storage.
1819</p>
1820<p><code>vpop()</code> pops <var>vtop</var>. In some cases, it also generates cleanup
1821code (for example if stacked floating point registers are used as on
1822x86).
1823</p>
1824<p>The <code>gv(rc)</code> function generates code to evaluate <var>vtop</var> (the
1825top value of the stack) into registers. <var>rc</var> selects in which
1826register class the value should be put. <code>gv()</code> is the <em>most
1827important function</em> of the code generator.
1828</p>
1829<p><code>gv2()</code> is the same as <code>gv()</code> but for the top two stack
1830entries.
1831</p>
1832<hr size="6">
1833<a name="CPU-dependent-code-generation"></a>
1834<table cellpadding="1" cellspacing="1" border="0">
1835<tr><td valign="middle" align="left">[<a href="#Manipulating-the-value-stack" title="Previous section in reading order"> &lt; </a>]</td>
1836<td valign="middle" align="left">[<a href="#Optimizations-done" title="Next section in reading order"> &gt; </a>]</td>
1837<td valign="middle" align="left"> &nbsp; </td>
1838<td valign="middle" align="left">[<a href="#devel" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
1839<td valign="middle" align="left">[<a href="#Code-generation" title="Up section"> Up </a>]</td>
1840<td valign="middle" align="left">[<a href="#Concept-Index" title="Next chapter"> &gt;&gt; </a>]</td>
1841<td valign="middle" align="left"> &nbsp; </td>
1842<td valign="middle" align="left"> &nbsp; </td>
1843<td valign="middle" align="left"> &nbsp; </td>
1844<td valign="middle" align="left"> &nbsp; </td>
1845<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
1846<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
1847<td valign="middle" align="left">[<a href="#Concept-Index" title="Index">Index</a>]</td>
1848<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
1849</tr></table>
1850<h3 class="subsection">8.7.4 CPU dependent code generation</h3>
1851<a name="index-CPU-dependent"></a>
1852<p>See the &lsquo;<tt>i386-gen.c</tt>&rsquo; file to have an example.
1853</p>
1854<dl compact="compact">
1855<dt> <code>load()</code></dt>
1856<dd><p>must generate the code needed to load a stack value into a register.
1857</p>
1858</dd>
1859<dt> <code>store()</code></dt>
1860<dd><p>must generate the code needed to store a register into a stack value
1861lvalue.
1862</p>
1863</dd>
1864<dt> <code>gfunc_start()</code></dt>
1865<dt> <code>gfunc_param()</code></dt>
1866<dt> <code>gfunc_call()</code></dt>
1867<dd><p>should generate a function call
1868</p>
1869</dd>
1870<dt> <code>gfunc_prolog()</code></dt>
1871<dt> <code>gfunc_epilog()</code></dt>
1872<dd><p>should generate a function prolog/epilog.
1873</p>
1874</dd>
1875<dt> <code>gen_opi(op)</code></dt>
1876<dd><p>must generate the binary integer operation <var>op</var> on the two top
1877entries of the stack which are guaranted to contain integer types.
1878</p>
1879<p>The result value should be put on the stack.
1880</p>
1881</dd>
1882<dt> <code>gen_opf(op)</code></dt>
1883<dd><p>same as <code>gen_opi()</code> for floating point operations. The two top
1884entries of the stack are guaranted to contain floating point values of
1885same types.
1886</p>
1887</dd>
1888<dt> <code>gen_cvt_itof()</code></dt>
1889<dd><p>integer to floating point conversion.
1890</p>
1891</dd>
1892<dt> <code>gen_cvt_ftoi()</code></dt>
1893<dd><p>floating point to integer conversion.
1894</p>
1895</dd>
1896<dt> <code>gen_cvt_ftof()</code></dt>
1897<dd><p>floating point to floating point of different size conversion.
1898</p>
1899</dd>
1900<dt> <code>gen_bounded_ptr_add()</code></dt>
1901<dt> <code>gen_bounded_ptr_deref()</code></dt>
1902<dd><p>are only used for bounds checking.
1903</p>
1904</dd>
1905</dl>
1906
1907<hr size="6">
1908<a name="Optimizations-done"></a>
1909<table cellpadding="1" cellspacing="1" border="0">
1910<tr><td valign="middle" align="left">[<a href="#CPU-dependent-code-generation" title="Previous section in reading order"> &lt; </a>]</td>
1911<td valign="middle" align="left">[<a href="#Concept-Index" title="Next section in reading order"> &gt; </a>]</td>
1912<td valign="middle" align="left"> &nbsp; </td>
1913<td valign="middle" align="left">[<a href="#devel" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
1914<td valign="middle" align="left">[<a href="#devel" title="Up section"> Up </a>]</td>
1915<td valign="middle" align="left">[<a href="#Concept-Index" title="Next chapter"> &gt;&gt; </a>]</td>
1916<td valign="middle" align="left"> &nbsp; </td>
1917<td valign="middle" align="left"> &nbsp; </td>
1918<td valign="middle" align="left"> &nbsp; </td>
1919<td valign="middle" align="left"> &nbsp; </td>
1920<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
1921<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
1922<td valign="middle" align="left">[<a href="#Concept-Index" title="Index">Index</a>]</td>
1923<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
1924</tr></table>
1925<h2 class="section">8.8 Optimizations done</h2>
1926<a name="index-optimizations"></a>
1927<a name="index-constant-propagation"></a>
1928<a name="index-strength-reduction"></a>
1929<a name="index-comparison-operators"></a>
1930<a name="index-caching-processor-flags"></a>
1931<a name="index-flags_002c-caching"></a>
1932<a name="index-jump-optimization"></a>
1933<p>Constant propagation is done for all operations. Multiplications and
1934divisions are optimized to shifts when appropriate. Comparison
1935operators are optimized by maintaining a special cache for the
1936processor flags. &amp;&amp;, || and ! are optimized by maintaining a special
1937&rsquo;jump target&rsquo; value. No other jump optimization is currently performed
1938because it would require to store the code in a more abstract fashion.
1939</p>
1940<hr size="6">
1941<a name="Concept-Index"></a>
1942<table cellpadding="1" cellspacing="1" border="0">
1943<tr><td valign="middle" align="left">[<a href="#Optimizations-done" title="Previous section in reading order"> &lt; </a>]</td>
1944<td valign="middle" align="left">[ &gt; ]</td>
1945<td valign="middle" align="left"> &nbsp; </td>
1946<td valign="middle" align="left">[<a href="#devel" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
1947<td valign="middle" align="left">[<a href="#Top" title="Up section"> Up </a>]</td>
1948<td valign="middle" align="left">[ &gt;&gt; ]</td>
1949<td valign="middle" align="left"> &nbsp; </td>
1950<td valign="middle" align="left"> &nbsp; </td>
1951<td valign="middle" align="left"> &nbsp; </td>
1952<td valign="middle" align="left"> &nbsp; </td>
1953<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
1954<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
1955<td valign="middle" align="left">[<a href="#Concept-Index" title="Index">Index</a>]</td>
1956<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
1957</tr></table>
1958<h1 class="unnumbered">Concept Index</h1>
1959<table><tr><th valign="top">Jump to: &nbsp; </th><td><a href="#Concept-Index_cp_symbol-1" class="summary-letter"><b>_</b></a>
1960 &nbsp;
1961<br>
1962<a href="#Concept-Index_cp_letter-A" class="summary-letter"><b>A</b></a>
1963 &nbsp;
1964<a href="#Concept-Index_cp_letter-B" class="summary-letter"><b>B</b></a>
1965 &nbsp;
1966<a href="#Concept-Index_cp_letter-C" class="summary-letter"><b>C</b></a>
1967 &nbsp;
1968<a href="#Concept-Index_cp_letter-D" class="summary-letter"><b>D</b></a>
1969 &nbsp;
1970<a href="#Concept-Index_cp_letter-E" class="summary-letter"><b>E</b></a>
1971 &nbsp;
1972<a href="#Concept-Index_cp_letter-F" class="summary-letter"><b>F</b></a>
1973 &nbsp;
1974<a href="#Concept-Index_cp_letter-G" class="summary-letter"><b>G</b></a>
1975 &nbsp;
1976<a href="#Concept-Index_cp_letter-I" class="summary-letter"><b>I</b></a>
1977 &nbsp;
1978<a href="#Concept-Index_cp_letter-J" class="summary-letter"><b>J</b></a>
1979 &nbsp;
1980<a href="#Concept-Index_cp_letter-L" class="summary-letter"><b>L</b></a>
1981 &nbsp;
1982<a href="#Concept-Index_cp_letter-M" class="summary-letter"><b>M</b></a>
1983 &nbsp;
1984<a href="#Concept-Index_cp_letter-O" class="summary-letter"><b>O</b></a>
1985 &nbsp;
1986<a href="#Concept-Index_cp_letter-P" class="summary-letter"><b>P</b></a>
1987 &nbsp;
1988<a href="#Concept-Index_cp_letter-Q" class="summary-letter"><b>Q</b></a>
1989 &nbsp;
1990<a href="#Concept-Index_cp_letter-R" class="summary-letter"><b>R</b></a>
1991 &nbsp;
1992<a href="#Concept-Index_cp_letter-S" class="summary-letter"><b>S</b></a>
1993 &nbsp;
1994<a href="#Concept-Index_cp_letter-T" class="summary-letter"><b>T</b></a>
1995 &nbsp;
1996<a href="#Concept-Index_cp_letter-U" class="summary-letter"><b>U</b></a>
1997 &nbsp;
1998<a href="#Concept-Index_cp_letter-V" class="summary-letter"><b>V</b></a>
1999 &nbsp;
2000<a href="#Concept-Index_cp_letter-W" class="summary-letter"><b>W</b></a>
2001 &nbsp;
2002</td></tr></table>
2003<table border="0" class="index-cp">
2004<tr><td></td><th align="left">Index Entry</th><th align="left"> Section</th></tr>
2005<tr><td colspan="3"> <hr></td></tr>
2006<tr><th><a name="Concept-Index_cp_symbol-1">_</a></th><td></td><td></td></tr>
2007<tr><td></td><td valign="top"><a href="#index-_005f_005fasm_005f_005f">__asm__</a></td><td valign="top"><a href="#GNU-C-extensions">3.3 GNU C extensions</a></td></tr>
2008<tr><td colspan="3"> <hr></td></tr>
2009<tr><th><a name="Concept-Index_cp_letter-A">A</a></th><td></td><td></td></tr>
2010<tr><td></td><td valign="top"><a href="#index-align-directive">align directive</a></td><td valign="top"><a href="#Directives">4.4 Directives</a></td></tr>
2011<tr><td></td><td valign="top"><a href="#index-aligned-attribute">aligned attribute</a></td><td valign="top"><a href="#GNU-C-extensions">3.3 GNU C extensions</a></td></tr>
2012<tr><td></td><td valign="top"><a href="#index-ascii-directive">ascii directive</a></td><td valign="top"><a href="#Directives">4.4 Directives</a></td></tr>
2013<tr><td></td><td valign="top"><a href="#index-asciz-directive">asciz directive</a></td><td valign="top"><a href="#Directives">4.4 Directives</a></td></tr>
2014<tr><td></td><td valign="top"><a href="#index-assembler">assembler</a></td><td valign="top"><a href="#X86-Assembler">4.5 X86 Assembler</a></td></tr>
2015<tr><td></td><td valign="top"><a href="#index-assembler-directives">assembler directives</a></td><td valign="top"><a href="#Directives">4.4 Directives</a></td></tr>
2016<tr><td></td><td valign="top"><a href="#index-assembly_002c-inline">assembly, inline</a></td><td valign="top"><a href="#GNU-C-extensions">3.3 GNU C extensions</a></td></tr>
2017<tr><td colspan="3"> <hr></td></tr>
2018<tr><th><a name="Concept-Index_cp_letter-B">B</a></th><td></td><td></td></tr>
2019<tr><td></td><td valign="top"><a href="#index-bound-checks">bound checks</a></td><td valign="top"><a href="#Bounds">6. TinyCC Memory and Bound checks</a></td></tr>
2020<tr><td></td><td valign="top"><a href="#index-bss-directive">bss directive</a></td><td valign="top"><a href="#Directives">4.4 Directives</a></td></tr>
2021<tr><td></td><td valign="top"><a href="#index-byte-directive">byte directive</a></td><td valign="top"><a href="#Directives">4.4 Directives</a></td></tr>
2022<tr><td colspan="3"> <hr></td></tr>
2023<tr><th><a name="Concept-Index_cp_letter-C">C</a></th><td></td><td></td></tr>
2024<tr><td></td><td valign="top"><a href="#index-caching-processor-flags">caching processor flags</a></td><td valign="top"><a href="#Optimizations-done">8.8 Optimizations done</a></td></tr>
2025<tr><td></td><td valign="top"><a href="#index-cdecl-attribute">cdecl attribute</a></td><td valign="top"><a href="#GNU-C-extensions">3.3 GNU C extensions</a></td></tr>
2026<tr><td></td><td valign="top"><a href="#index-code-generation">code generation</a></td><td valign="top"><a href="#Code-generation">8.7 Code generation</a></td></tr>
2027<tr><td></td><td valign="top"><a href="#index-comparison-operators">comparison operators</a></td><td valign="top"><a href="#Optimizations-done">8.8 Optimizations done</a></td></tr>
2028<tr><td></td><td valign="top"><a href="#index-constant-propagation">constant propagation</a></td><td valign="top"><a href="#Optimizations-done">8.8 Optimizations done</a></td></tr>
2029<tr><td></td><td valign="top"><a href="#index-CPU-dependent">CPU dependent</a></td><td valign="top"><a href="#CPU-dependent-code-generation">8.7.4 CPU dependent code generation</a></td></tr>
2030<tr><td colspan="3"> <hr></td></tr>
2031<tr><th><a name="Concept-Index_cp_letter-D">D</a></th><td></td><td></td></tr>
2032<tr><td></td><td valign="top"><a href="#index-data-directive">data directive</a></td><td valign="top"><a href="#Directives">4.4 Directives</a></td></tr>
2033<tr><td></td><td valign="top"><a href="#index-directives_002c-assembler">directives, assembler</a></td><td valign="top"><a href="#Directives">4.4 Directives</a></td></tr>
2034<tr><td></td><td valign="top"><a href="#index-dllexport-attribute">dllexport attribute</a></td><td valign="top"><a href="#GNU-C-extensions">3.3 GNU C extensions</a></td></tr>
2035<tr><td colspan="3"> <hr></td></tr>
2036<tr><th><a name="Concept-Index_cp_letter-E">E</a></th><td></td><td></td></tr>
2037<tr><td></td><td valign="top"><a href="#index-ELF">ELF</a></td><td valign="top"><a href="#ELF-file-generation">5.1 ELF file generation</a></td></tr>
2038<tr><td colspan="3"> <hr></td></tr>
2039<tr><th><a name="Concept-Index_cp_letter-F">F</a></th><td></td><td></td></tr>
2040<tr><td></td><td valign="top"><a href="#index-FILE_002c-linker-command">FILE, linker command</a></td><td valign="top"><a href="#GNU-Linker-Scripts">5.4 GNU Linker Scripts</a></td></tr>
2041<tr><td></td><td valign="top"><a href="#index-fill-directive">fill directive</a></td><td valign="top"><a href="#Directives">4.4 Directives</a></td></tr>
2042<tr><td></td><td valign="top"><a href="#index-flags_002c-caching">flags, caching</a></td><td valign="top"><a href="#Optimizations-done">8.8 Optimizations done</a></td></tr>
2043<tr><td colspan="3"> <hr></td></tr>
2044<tr><th><a name="Concept-Index_cp_letter-G">G</a></th><td></td><td></td></tr>
2045<tr><td></td><td valign="top"><a href="#index-gas">gas</a></td><td valign="top"><a href="#GNU-C-extensions">3.3 GNU C extensions</a></td></tr>
2046<tr><td></td><td valign="top"><a href="#index-global-directive">global directive</a></td><td valign="top"><a href="#Directives">4.4 Directives</a></td></tr>
2047<tr><td></td><td valign="top"><a href="#index-globl-directive">globl directive</a></td><td valign="top"><a href="#Directives">4.4 Directives</a></td></tr>
2048<tr><td></td><td valign="top"><a href="#index-GROUP_002c-linker-command">GROUP, linker command</a></td><td valign="top"><a href="#GNU-Linker-Scripts">5.4 GNU Linker Scripts</a></td></tr>
2049<tr><td colspan="3"> <hr></td></tr>
2050<tr><th><a name="Concept-Index_cp_letter-I">I</a></th><td></td><td></td></tr>
2051<tr><td></td><td valign="top"><a href="#index-inline-assembly">inline assembly</a></td><td valign="top"><a href="#GNU-C-extensions">3.3 GNU C extensions</a></td></tr>
2052<tr><td></td><td valign="top"><a href="#index-int-directive">int directive</a></td><td valign="top"><a href="#Directives">4.4 Directives</a></td></tr>
2053<tr><td colspan="3"> <hr></td></tr>
2054<tr><th><a name="Concept-Index_cp_letter-J">J</a></th><td></td><td></td></tr>
2055<tr><td></td><td valign="top"><a href="#index-jump-optimization">jump optimization</a></td><td valign="top"><a href="#Optimizations-done">8.8 Optimizations done</a></td></tr>
2056<tr><td colspan="3"> <hr></td></tr>
2057<tr><th><a name="Concept-Index_cp_letter-L">L</a></th><td></td><td></td></tr>
2058<tr><td></td><td valign="top"><a href="#index-linker">linker</a></td><td valign="top"><a href="#linker">5. TinyCC Linker</a></td></tr>
2059<tr><td></td><td valign="top"><a href="#index-linker-scripts">linker scripts</a></td><td valign="top"><a href="#GNU-Linker-Scripts">5.4 GNU Linker Scripts</a></td></tr>
2060<tr><td></td><td valign="top"><a href="#index-long-directive">long directive</a></td><td valign="top"><a href="#Directives">4.4 Directives</a></td></tr>
2061<tr><td colspan="3"> <hr></td></tr>
2062<tr><th><a name="Concept-Index_cp_letter-M">M</a></th><td></td><td></td></tr>
2063<tr><td></td><td valign="top"><a href="#index-memory-checks">memory checks</a></td><td valign="top"><a href="#Bounds">6. TinyCC Memory and Bound checks</a></td></tr>
2064<tr><td colspan="3"> <hr></td></tr>
2065<tr><th><a name="Concept-Index_cp_letter-O">O</a></th><td></td><td></td></tr>
2066<tr><td></td><td valign="top"><a href="#index-optimizations">optimizations</a></td><td valign="top"><a href="#Optimizations-done">8.8 Optimizations done</a></td></tr>
2067<tr><td></td><td valign="top"><a href="#index-org-directive">org directive</a></td><td valign="top"><a href="#Directives">4.4 Directives</a></td></tr>
2068<tr><td></td><td valign="top"><a href="#index-OUTPUT_005fFORMAT_002c-linker-command">OUTPUT_FORMAT, linker command</a></td><td valign="top"><a href="#GNU-Linker-Scripts">5.4 GNU Linker Scripts</a></td></tr>
2069<tr><td colspan="3"> <hr></td></tr>
2070<tr><th><a name="Concept-Index_cp_letter-P">P</a></th><td></td><td></td></tr>
2071<tr><td></td><td valign="top"><a href="#index-packed-attribute">packed attribute</a></td><td valign="top"><a href="#GNU-C-extensions">3.3 GNU C extensions</a></td></tr>
2072<tr><td></td><td valign="top"><a href="#index-PE_002di386">PE-i386</a></td><td valign="top"><a href="#PE_002di386-file-generation">5.3 PE-i386 file generation</a></td></tr>
2073<tr><td></td><td valign="top"><a href="#index-previous-directive">previous directive</a></td><td valign="top"><a href="#Directives">4.4 Directives</a></td></tr>
2074<tr><td colspan="3"> <hr></td></tr>
2075<tr><th><a name="Concept-Index_cp_letter-Q">Q</a></th><td></td><td></td></tr>
2076<tr><td></td><td valign="top"><a href="#index-quad-directive">quad directive</a></td><td valign="top"><a href="#Directives">4.4 Directives</a></td></tr>
2077<tr><td colspan="3"> <hr></td></tr>
2078<tr><th><a name="Concept-Index_cp_letter-R">R</a></th><td></td><td></td></tr>
2079<tr><td></td><td valign="top"><a href="#index-regparm-attribute">regparm attribute</a></td><td valign="top"><a href="#GNU-C-extensions">3.3 GNU C extensions</a></td></tr>
2080<tr><td colspan="3"> <hr></td></tr>
2081<tr><th><a name="Concept-Index_cp_letter-S">S</a></th><td></td><td></td></tr>
2082<tr><td></td><td valign="top"><a href="#index-scripts_002c-linker">scripts, linker</a></td><td valign="top"><a href="#GNU-Linker-Scripts">5.4 GNU Linker Scripts</a></td></tr>
2083<tr><td></td><td valign="top"><a href="#index-section-attribute">section attribute</a></td><td valign="top"><a href="#GNU-C-extensions">3.3 GNU C extensions</a></td></tr>
2084<tr><td></td><td valign="top"><a href="#index-section-directive">section directive</a></td><td valign="top"><a href="#Directives">4.4 Directives</a></td></tr>
2085<tr><td></td><td valign="top"><a href="#index-short-directive">short directive</a></td><td valign="top"><a href="#Directives">4.4 Directives</a></td></tr>
2086<tr><td></td><td valign="top"><a href="#index-skip-directive">skip directive</a></td><td valign="top"><a href="#Directives">4.4 Directives</a></td></tr>
2087<tr><td></td><td valign="top"><a href="#index-space-directive">space directive</a></td><td valign="top"><a href="#Directives">4.4 Directives</a></td></tr>
2088<tr><td></td><td valign="top"><a href="#index-stdcall-attribute">stdcall attribute</a></td><td valign="top"><a href="#GNU-C-extensions">3.3 GNU C extensions</a></td></tr>
2089<tr><td></td><td valign="top"><a href="#index-strength-reduction">strength reduction</a></td><td valign="top"><a href="#Optimizations-done">8.8 Optimizations done</a></td></tr>
2090<tr><td></td><td valign="top"><a href="#index-string-directive">string directive</a></td><td valign="top"><a href="#Directives">4.4 Directives</a></td></tr>
2091<tr><td colspan="3"> <hr></td></tr>
2092<tr><th><a name="Concept-Index_cp_letter-T">T</a></th><td></td><td></td></tr>
2093<tr><td></td><td valign="top"><a href="#index-TARGET_002c-linker-command">TARGET, linker command</a></td><td valign="top"><a href="#GNU-Linker-Scripts">5.4 GNU Linker Scripts</a></td></tr>
2094<tr><td></td><td valign="top"><a href="#index-text-directive">text directive</a></td><td valign="top"><a href="#Directives">4.4 Directives</a></td></tr>
2095<tr><td colspan="3"> <hr></td></tr>
2096<tr><th><a name="Concept-Index_cp_letter-U">U</a></th><td></td><td></td></tr>
2097<tr><td></td><td valign="top"><a href="#index-unused-attribute">unused attribute</a></td><td valign="top"><a href="#GNU-C-extensions">3.3 GNU C extensions</a></td></tr>
2098<tr><td colspan="3"> <hr></td></tr>
2099<tr><th><a name="Concept-Index_cp_letter-V">V</a></th><td></td><td></td></tr>
2100<tr><td></td><td valign="top"><a href="#index-value-stack">value stack</a></td><td valign="top"><a href="#Manipulating-the-value-stack">8.7.3 Manipulating the value stack</a></td></tr>
2101<tr><td></td><td valign="top"><a href="#index-value-stack_002c-introduction">value stack, introduction</a></td><td valign="top"><a href="#The-value-stack">8.7.2 The value stack</a></td></tr>
2102<tr><td colspan="3"> <hr></td></tr>
2103<tr><th><a name="Concept-Index_cp_letter-W">W</a></th><td></td><td></td></tr>
2104<tr><td></td><td valign="top"><a href="#index-word-directive">word directive</a></td><td valign="top"><a href="#Directives">4.4 Directives</a></td></tr>
2105<tr><td colspan="3"> <hr></td></tr>
2106</table>
2107<table><tr><th valign="top">Jump to: &nbsp; </th><td><a href="#Concept-Index_cp_symbol-1" class="summary-letter"><b>_</b></a>
2108 &nbsp;
2109<br>
2110<a href="#Concept-Index_cp_letter-A" class="summary-letter"><b>A</b></a>
2111 &nbsp;
2112<a href="#Concept-Index_cp_letter-B" class="summary-letter"><b>B</b></a>
2113 &nbsp;
2114<a href="#Concept-Index_cp_letter-C" class="summary-letter"><b>C</b></a>
2115 &nbsp;
2116<a href="#Concept-Index_cp_letter-D" class="summary-letter"><b>D</b></a>
2117 &nbsp;
2118<a href="#Concept-Index_cp_letter-E" class="summary-letter"><b>E</b></a>
2119 &nbsp;
2120<a href="#Concept-Index_cp_letter-F" class="summary-letter"><b>F</b></a>
2121 &nbsp;
2122<a href="#Concept-Index_cp_letter-G" class="summary-letter"><b>G</b></a>
2123 &nbsp;
2124<a href="#Concept-Index_cp_letter-I" class="summary-letter"><b>I</b></a>
2125 &nbsp;
2126<a href="#Concept-Index_cp_letter-J" class="summary-letter"><b>J</b></a>
2127 &nbsp;
2128<a href="#Concept-Index_cp_letter-L" class="summary-letter"><b>L</b></a>
2129 &nbsp;
2130<a href="#Concept-Index_cp_letter-M" class="summary-letter"><b>M</b></a>
2131 &nbsp;
2132<a href="#Concept-Index_cp_letter-O" class="summary-letter"><b>O</b></a>
2133 &nbsp;
2134<a href="#Concept-Index_cp_letter-P" class="summary-letter"><b>P</b></a>
2135 &nbsp;
2136<a href="#Concept-Index_cp_letter-Q" class="summary-letter"><b>Q</b></a>
2137 &nbsp;
2138<a href="#Concept-Index_cp_letter-R" class="summary-letter"><b>R</b></a>
2139 &nbsp;
2140<a href="#Concept-Index_cp_letter-S" class="summary-letter"><b>S</b></a>
2141 &nbsp;
2142<a href="#Concept-Index_cp_letter-T" class="summary-letter"><b>T</b></a>
2143 &nbsp;
2144<a href="#Concept-Index_cp_letter-U" class="summary-letter"><b>U</b></a>
2145 &nbsp;
2146<a href="#Concept-Index_cp_letter-V" class="summary-letter"><b>V</b></a>
2147 &nbsp;
2148<a href="#Concept-Index_cp_letter-W" class="summary-letter"><b>W</b></a>
2149 &nbsp;
2150</td></tr></table>
2151
2152<hr size="6">
2153<a name="SEC_Contents"></a>
2154<table cellpadding="1" cellspacing="1" border="0">
2155<tr><td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
2156<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
2157<td valign="middle" align="left">[<a href="#Concept-Index" title="Index">Index</a>]</td>
2158<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
2159</tr></table>
2160<h1>Table of Contents</h1>
2161<div class="contents">
2162
2163<ul class="toc">
2164 <li><a name="toc-Introduction-1" href="#Introduction">1. Introduction</a></li>
2165 <li><a name="toc-Command-line-invocation" href="#Invoke">2. Command line invocation</a>
2166 <ul class="toc">
2167 <li><a name="toc-Quick-start" href="#Quick-start">2.1 Quick start</a></li>
2168 <li><a name="toc-Option-summary" href="#Option-summary">2.2 Option summary</a></li>
2169 </ul></li>
2170 <li><a name="toc-C-language-support" href="#Clang">3. C language support</a>
2171 <ul class="toc">
2172 <li><a name="toc-ANSI-C" href="#ANSI-C">3.1 ANSI C</a></li>
2173 <li><a name="toc-ISOC99-extensions" href="#ISOC99-extensions">3.2 ISOC99 extensions</a></li>
2174 <li><a name="toc-GNU-C-extensions" href="#GNU-C-extensions">3.3 GNU C extensions</a></li>
2175 <li><a name="toc-TinyCC-extensions" href="#TinyCC-extensions">3.4 TinyCC extensions</a></li>
2176 </ul></li>
2177 <li><a name="toc-TinyCC-Assembler" href="#asm">4. TinyCC Assembler</a>
2178 <ul class="toc">
2179 <li><a name="toc-Syntax" href="#Syntax">4.1 Syntax</a></li>
2180 <li><a name="toc-Expressions" href="#Expressions">4.2 Expressions</a></li>
2181 <li><a name="toc-Labels" href="#Labels">4.3 Labels</a></li>
2182 <li><a name="toc-Directives" href="#Directives">4.4 Directives</a></li>
2183 <li><a name="toc-X86-Assembler" href="#X86-Assembler">4.5 X86 Assembler</a></li>
2184 </ul></li>
2185 <li><a name="toc-TinyCC-Linker" href="#linker">5. TinyCC Linker</a>
2186 <ul class="toc">
2187 <li><a name="toc-ELF-file-generation" href="#ELF-file-generation">5.1 ELF file generation</a></li>
2188 <li><a name="toc-ELF-file-loader" href="#ELF-file-loader">5.2 ELF file loader</a></li>
2189 <li><a name="toc-PE_002di386-file-generation" href="#PE_002di386-file-generation">5.3 PE-i386 file generation</a></li>
2190 <li><a name="toc-GNU-Linker-Scripts" href="#GNU-Linker-Scripts">5.4 GNU Linker Scripts</a></li>
2191 </ul></li>
2192 <li><a name="toc-TinyCC-Memory-and-Bound-checks" href="#Bounds">6. TinyCC Memory and Bound checks</a></li>
2193 <li><a name="toc-The-libtcc-library" href="#Libtcc">7. The <code>libtcc</code> library</a></li>
2194 <li><a name="toc-Developer_0027s-guide" href="#devel">8. Developer&rsquo;s guide</a>
2195 <ul class="toc">
2196 <li><a name="toc-File-reading" href="#File-reading">8.1 File reading</a></li>
2197 <li><a name="toc-Lexer" href="#Lexer">8.2 Lexer</a></li>
2198 <li><a name="toc-Parser" href="#Parser">8.3 Parser</a></li>
2199 <li><a name="toc-Types" href="#Types">8.4 Types</a></li>
2200 <li><a name="toc-Symbols" href="#Symbols">8.5 Symbols</a></li>
2201 <li><a name="toc-Sections" href="#Sections">8.6 Sections</a></li>
2202 <li><a name="toc-Code-generation" href="#Code-generation">8.7 Code generation</a>
2203 <ul class="toc">
2204 <li><a name="toc-Introduction-2" href="#Introduction-2">8.7.1 Introduction</a></li>
2205 <li><a name="toc-The-value-stack" href="#The-value-stack">8.7.2 The value stack</a></li>
2206 <li><a name="toc-Manipulating-the-value-stack" href="#Manipulating-the-value-stack">8.7.3 Manipulating the value stack</a></li>
2207 <li><a name="toc-CPU-dependent-code-generation" href="#CPU-dependent-code-generation">8.7.4 CPU dependent code generation</a></li>
2208 </ul></li>
2209 <li><a name="toc-Optimizations-done" href="#Optimizations-done">8.8 Optimizations done</a></li>
2210 </ul></li>
2211 <li><a name="toc-Concept-Index" href="#Concept-Index">Concept Index</a></li>
2212</ul>
2213</div>
2214<hr size="1">
2215<a name="SEC_About"></a>
2216<table cellpadding="1" cellspacing="1" border="0">
2217<tr><td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
2218<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
2219<td valign="middle" align="left">[<a href="#Concept-Index" title="Index">Index</a>]</td>
2220<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
2221</tr></table>
2222<h1>About This Document</h1>
2223<p>
2224 This document was generated by <em>Thomas Preud'homme</em> on <em>February 15, 2013</em> using <a href="http://www.nongnu.org/texi2html/"><em>texi2html 1.82</em></a>.
2225</p>
2226<p>
2227 The buttons in the navigation panels have the following meaning:
2228</p>
2229<table border="1">
2230 <tr>
2231 <th> Button </th>
2232 <th> Name </th>
2233 <th> Go to </th>
2234 <th> From 1.2.3 go to</th>
2235 </tr>
2236 <tr>
2237 <td align="center"> [ &lt; ] </td>
2238 <td align="center">Back</td>
2239 <td>Previous section in reading order</td>
2240 <td>1.2.2</td>
2241 </tr>
2242 <tr>
2243 <td align="center"> [ &gt; ] </td>
2244 <td align="center">Forward</td>
2245 <td>Next section in reading order</td>
2246 <td>1.2.4</td>
2247 </tr>
2248 <tr>
2249 <td align="center"> [ &lt;&lt; ] </td>
2250 <td align="center">FastBack</td>
2251 <td>Beginning of this chapter or previous chapter</td>
2252 <td>1</td>
2253 </tr>
2254 <tr>
2255 <td align="center"> [ Up ] </td>
2256 <td align="center">Up</td>
2257 <td>Up section</td>
2258 <td>1.2</td>
2259 </tr>
2260 <tr>
2261 <td align="center"> [ &gt;&gt; ] </td>
2262 <td align="center">FastForward</td>
2263 <td>Next chapter</td>
2264 <td>2</td>
2265 </tr>
2266 <tr>
2267 <td align="center"> [Top] </td>
2268 <td align="center">Top</td>
2269 <td>Cover (top) of document</td>
2270 <td> &nbsp; </td>
2271 </tr>
2272 <tr>
2273 <td align="center"> [Contents] </td>
2274 <td align="center">Contents</td>
2275 <td>Table of contents</td>
2276 <td> &nbsp; </td>
2277 </tr>
2278 <tr>
2279 <td align="center"> [Index] </td>
2280 <td align="center">Index</td>
2281 <td>Index</td>
2282 <td> &nbsp; </td>
2283 </tr>
2284 <tr>
2285 <td align="center"> [ ? ] </td>
2286 <td align="center">About</td>
2287 <td>About (help)</td>
2288 <td> &nbsp; </td>
2289 </tr>
2290</table>
2291
2292<p>
2293 where the <strong> Example </strong> assumes that the current position is at <strong> Subsubsection One-Two-Three </strong> of a document of the following structure:
2294</p>
2295
2296<ul>
2297 <li> 1. Section One
2298 <ul>
2299 <li>1.1 Subsection One-One
2300 <ul>
2301 <li>...</li>
2302 </ul>
2303 </li>
2304 <li>1.2 Subsection One-Two
2305 <ul>
2306 <li>1.2.1 Subsubsection One-Two-One</li>
2307 <li>1.2.2 Subsubsection One-Two-Two</li>
2308 <li>1.2.3 Subsubsection One-Two-Three &nbsp; &nbsp;
2309 <strong>&lt;== Current Position </strong></li>
2310 <li>1.2.4 Subsubsection One-Two-Four</li>
2311 </ul>
2312 </li>
2313 <li>1.3 Subsection One-Three
2314 <ul>
2315 <li>...</li>
2316 </ul>
2317 </li>
2318 <li>1.4 Subsection One-Four</li>
2319 </ul>
2320 </li>
2321</ul>
2322
2323<hr size="1">
2324<p>
2325 <font size="-1">
2326 This document was generated by <em>Thomas Preud'homme</em> on <em>February 15, 2013</em> using <a href="http://www.nongnu.org/texi2html/"><em>texi2html 1.82</em></a>.
2327 </font>
2328 <br>
2329
2330</p>
2331</body>
2332</html>
Note: See TracBrowser for help on using the repository browser.