* added compilers lcc and bcc (linux86)
[mascara-docs.git] / compilers / lcc / doc / 4.html
blobc36f280b0d1da99d73253276b9512760964a3266
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
2 <html>
4 <head>
5 <link HREF="mailto:drh@microsoft.com" REV="made" TITLE="David R. Hanson">
6 <title>The lcc 4.1 Code-Generation Interface</title>
7 </head>
9 <body>
11 <h1>The lcc 4.1 Code-Generation Interface</h1>
13 <p ALIGN="LEFT"><strong><a HREF="http://www.research.microsoft.com/~cwfraser/">Christopher
14 W. Fraser</a> and <a HREF="http://www.research.microsoft.com/~drh/">David R. Hanson</a>, <a
15 HREF="http://www.research.microsoft.com/">Microsoft Research</a></strong></p>
17 <h2>Contents</h2>
19 <dir>
20 <li><a HREF="#intro">Introduction</a> </li>
21 <li><a HREF="#metrics">5.1 Type Metrics</a></li>
22 <li><a HREF="#symbols">5.3 Symbols</a> </li>
23 <li><a HREF="#operators">5.5 Dag Operators</a></li>
24 <li><a HREF="#flags">5.6 Interface Flags</a></li>
25 <li><a HREF="#definitions">5.8 Definitions</a></li>
26 <li><a HREF="#constants">5.9 Constants</a></li>
27 <li><a HREF="#upcalls">5.12 Upcalls</a></li>
28 </dir>
30 <h2><a NAME="intro">Introduction</a></h2>
32 <p>Version 4.1 is the latest release of <a
33 HREF="http://www.cs.princeton.edu/software/lcc/">lcc</a>, the ANSI C compiler described in
34 our book <cite>A Retargetable C Compiler: Design and Implementation</cite>
35 (Addison-Wesley, 1995, ISBN 0-8053-1670-1). This document summarizes the differences
36 between the 4.1 code-generation interface and the 3.x interface described in Chap. 5 of <cite>A
37 Retargetable C Compiler</cite>.</p>
39 <p>Previous versions of lcc supported only three sizes of integers, two sizes of floats,
40 and insisted that pointers fit in unsigned integers (see Sec. 5.1 of <cite>A Retargetable
41 C Compiler</cite>). These assumptions simplified the compiler, and were suitable for
42 32-bit architectures. But on 64-bit architectures, such as the DEC ALPHA, it's natural to
43 have four sizes of integers and perhaps three sizes of floats, and on 16-bit
44 architectures, 32-bit pointers don't fit in unsigned integers. Also, the 3.x constaints
45 limited the use of lcc's back ends for other languages, such as Java.</p>
47 <p>Version 4.x removes all of these restrictions: It supports any number of sizes for
48 integers and floats, and the size of pointers need not be related to the size of any of
49 the integer types. The major changes in the code-generation interface are:
51 <ul>
52 <li>The number of type suffixes has been reduced to 6.</li>
53 <li>Dag operators are composed of a generic operator, a type suffix, and a size.</li>
54 <li>Unsigned variants of several operators have been added.</li>
55 <li>Several interface functions have new signatures.</li>
56 </ul>
58 <p>In addition, version 4.x is written in ANSI C and uses the standard I/O library and
59 other standard C functions.</p>
61 <p>The sections below parallel the subsections of Chap. 5 of <cite>A Retargetable C
62 Compiler</cite> and summarize the differences between the 3.x and 4.x code-generation
63 interface. Unaffected subsections are omitted. Page citations refer to pages in <cite>A
64 Retargetable C Compiler</cite>.</p>
66 <h2><a NAME="metrics">5.1 Type Metrics</a></h2>
68 <p>There are now 10 metrics in an interface record:</p>
70 <pre>Metrics charmetric;
71 Metrics shortmetric;
72 Metrics intmetric;
73 Metrics longmetric;
74 Metrics longlongmetric;
75 Metrics floatmetric;
76 Metrics doublemetric;
77 Metrics longdoublemetric;
78 Metrics ptrmetric;
79 Metrics structmetric;</pre>
81 <p>Each of these specifies the size and alignment of the corresponding type. <code>ptrmetric</code>
82 describes all pointers.</p>
84 <h2><a NAME="symbols">5.3 Symbols</a></h2>
86 <p>The actual value of a constant is stored in the <code>u.c.v</code> field of a symbol,
87 which holds a <code>Value</code>:</p>
89 <pre>typedef union value {
90 long i;
91 unsigned long u;
92 long double d;
93 void *p;
94 void (*g)(void);
95 } Value;</pre>
97 <p>The value is stored in the appropriate field according to its type, which is given by
98 the symbol's <code>type</code> field.</p>
100 <h2><a NAME="operators">5.5 Dag Operators</a></h2>
102 <p>The <code>op</code> field a of <code>node</code> structure holds a dag operator, which
103 consists of a generic operator, a type suffix, and a size indicator. The type suffixes
104 are:</p>
106 <pre>enum {
107 F=FLOAT,
108 I=INT,
109 U=UNSIGNED,
110 P=POINTER,
111 V=VOID,
112 B=STRUCT
115 #define sizeop(n) ((n)&lt;&lt;10)</pre>
117 <p>Given a generic operator <code>o</code>, a type suffix <code>t</code>, and a size <code>s</code>,
118 a type- and size-specific operator is formed by <code>o+t+sizeop(s)</code>. For example, <code>ADD+F+sizeop(4)</code>
119 forms the operator <code>ADDF4</code>, which denotes the sum of two 4-byte floats.
120 Similarly, <code>ADD+F+sizeop(8)</code> forms <code>ADDF8</code>, which denotes 8-byte
121 floating addition. In the 3.x code-generation interface, <code>ADDF</code> and <code>ADDD</code>
122 denoted these operations. There was no size indicator in the 3.x operators because the
123 type suffix supplied both a type and a size.</p>
125 <p>Table 5.1 lists each generic operator, its valid type suffixes, and the number of <code>kids</code>
126 and <code>syms</code> that it uses; multiple values for <code>kids</code> indicate
127 type-specific variants. The notations in the <strong>syms</strong> column give the number
128 of <code>syms</code> values and a one-letter code that suggests their uses: 1V indicates
129 that <code>syms[0]</code> points to a symbol for a variable, 1C indicates that <code>syms[0]</code>
130 is a constant, and 1L indicates that <code>syms[0]</code> is a label. For 1S, <code>syms[0]</code>
131 is a constant whose value is a size in bytes; 2S adds <code>syms[1]</code>, which is a
132 constant whose value is an alignment. For most operators, the type suffix and size
133 indicator denote the type and size of operation to perform and the type and size of the
134 result.</p>
136 <table WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0">
137 <tr>
138 <td COLSPAN="6" ALIGN="CENTER"><strong>Table 5.1<img SRC="/~drh/resources/dot_clear.gif"
139 ALT="|" WIDTH="18" HEIGHT="1">Node Operators.</strong></td>
140 </tr>
141 <tr>
142 <td><strong>syms</strong></td>
143 <td><strong>kids</strong></td>
144 <td><strong>Operator</strong></td>
145 <td><strong>Type Suffixes</strong></td>
146 <td><strong>Sizes</strong></td>
147 <td><strong>Operation</strong></td>
148 </tr>
149 <tr>
150 <td>1V</td>
151 <td>0</td>
152 <td><code>ADDRF</code></td>
153 <td><code>...P..</code></td>
154 <td>p</td>
155 <td>address of a parameter</td>
156 </tr>
157 <tr>
158 <td>1V</td>
159 <td>0</td>
160 <td><code>ADDRG</code></td>
161 <td><code>...P..</code></td>
162 <td>p</td>
163 <td>address of a global</td>
164 </tr>
165 <tr>
166 <td>1V</td>
167 <td>0</td>
168 <td><code>ADDRL</code></td>
169 <td><code>...P..</code></td>
170 <td>p</td>
171 <td>address of a local</td>
172 </tr>
173 <tr>
174 <td>1C</td>
175 <td>0</td>
176 <td><code>CNST</code></td>
177 <td><code>FIUP..</code></td>
178 <td>fdx csilh p</td>
179 <td>constant</td>
180 </tr>
181 <tr ALIGN="LEFT" VALIGN="TOP">
182 <td><img SRC="/~drh/resources/dot_clear.gif" ALT="|" WIDTH="1" HEIGHT="12"></td>
183 <td></td>
184 <td></td>
185 <td></td>
186 <td></td>
187 <td></td>
188 </tr>
189 <tr>
190 <td></td>
191 <td>1</td>
192 <td><code>BCOM</code></td>
193 <td><code>.IU...</code></td>
194 <td>ilh</td>
195 <td>bitwise complement</td>
196 </tr>
197 <tr>
198 <td>1S</td>
199 <td>1</td>
200 <td><code>CVF</code></td>
201 <td><code>FI....</code></td>
202 <td>fdx ilh</td>
203 <td>convert from float</td>
204 </tr>
205 <tr>
206 <td>1S</td>
207 <td>1</td>
208 <td><code>CVI</code></td>
209 <td><code>FIU...</code></td>
210 <td>fdx csilh csilhp</td>
211 <td>convert from signed integer</td>
212 </tr>
213 <tr>
214 <td>1S</td>
215 <td>1</td>
216 <td><code>CVP</code></td>
217 <td><code>..U..</code></td>
218 <td>p</td>
219 <td>convert from pointer</td>
220 </tr>
221 <tr>
222 <td>1S</td>
223 <td>1</td>
224 <td><code>CVU</code></td>
225 <td><code>.IUP..</code></td>
226 <td>csilh p</td>
227 <td>convert from unsigned integer</td>
228 </tr>
229 <tr>
230 <td></td>
231 <td>1</td>
232 <td><code>INDIR</code></td>
233 <td><code>FIUP.B</code></td>
234 <td>fdx csilh p</td>
235 <td>fetch</td>
236 </tr>
237 <tr>
238 <td></td>
239 <td>1</td>
240 <td><code>NEG</code></td>
241 <td><code>FI....</code></td>
242 <td>fdx ilh</td>
243 <td>negation</td>
244 </tr>
245 <tr>
246 <td><img SRC="/~drh/resources/dot_clear.gif" ALT="|" WIDTH="1" HEIGHT="12"></td>
247 <td></td>
248 <td></td>
249 <td></td>
250 <td></td>
251 <td></td>
252 </tr>
253 <tr>
254 <td></td>
255 <td>2</td>
256 <td><code>ADD</code></td>
257 <td><code>FIUP..</code></td>
258 <td>fdx ilh ilhp p</td>
259 <td>addition</td>
260 </tr>
261 <tr>
262 <td></td>
263 <td>2</td>
264 <td><code>BAND</code></td>
265 <td><code>.IU...</code></td>
266 <td>ilh</td>
267 <td>bitwise AND</td>
268 </tr>
269 <tr>
270 <td></td>
271 <td>2</td>
272 <td><code>BOR</code></td>
273 <td><code>.IU...</code></td>
274 <td>ilh</td>
275 <td>bitwise inclusive OR</td>
276 </tr>
277 <tr>
278 <td></td>
279 <td>2</td>
280 <td><code>BXOR</code></td>
281 <td><code>.IU...</code></td>
282 <td>ilh</td>
283 <td>bitwise exclusive OR</td>
284 </tr>
285 <tr>
286 <td></td>
287 <td>2</td>
288 <td><code>DIV</code></td>
289 <td><code>FIU...</code></td>
290 <td>fdx ilh</td>
291 <td>division</td>
292 </tr>
293 <tr>
294 <td></td>
295 <td>2</td>
296 <td><code>LSH</code></td>
297 <td><code>.IU...</code></td>
298 <td>ilh</td>
299 <td>left shift</td>
300 </tr>
301 <tr>
302 <td></td>
303 <td>2</td>
304 <td><code>MOD</code></td>
305 <td><code>.IU...</code></td>
306 <td>ilh</td>
307 <td>modulus</td>
308 </tr>
309 <tr>
310 <td></td>
311 <td>2</td>
312 <td><code>MUL</code></td>
313 <td><code>FIU...</code></td>
314 <td>fdx ilh</td>
315 <td>multiplication</td>
316 </tr>
317 <tr>
318 <td></td>
319 <td>2</td>
320 <td><code>RSH</code></td>
321 <td><code>.IU...</code></td>
322 <td>ilh</td>
323 <td>right shift</td>
324 </tr>
325 <tr>
326 <td></td>
327 <td>2</td>
328 <td><code>SUB</code></td>
329 <td><code>FIUP..</code></td>
330 <td>fdx ilh ilhp p</td>
331 <td>subtraction</td>
332 </tr>
333 <tr>
334 <td><img SRC="/~drh/resources/dot_clear.gif" ALT="|" WIDTH="1" HEIGHT="12"></td>
335 <td></td>
336 <td></td>
337 <td></td>
338 <td></td>
339 <td></td>
340 </tr>
341 <tr>
342 <td>2S</td>
343 <td>2</td>
344 <td><code>ASGN</code></td>
345 <td><code>FIUP.B</code></td>
346 <td>fdx csilh p</td>
347 <td>assignment</td>
348 </tr>
349 <tr>
350 <td>1L</td>
351 <td>2</td>
352 <td><code>EQ</code></td>
353 <td><code>FIU...</code></td>
354 <td>fdx ilh ilhp</td>
355 <td>jump if equal</td>
356 </tr>
357 <tr>
358 <td>1L</td>
359 <td>2</td>
360 <td><code>GE</code></td>
361 <td><code>FIU...</code></td>
362 <td>fdx ilh ilhp</td>
363 <td>jump if greater than or equal</td>
364 </tr>
365 <tr>
366 <td>1L</td>
367 <td>2</td>
368 <td><code>GT</code></td>
369 <td><code>FIU...</code></td>
370 <td>fdx ilh ilhp</td>
371 <td>jump if greater than</td>
372 </tr>
373 <tr>
374 <td>1L</td>
375 <td>2</td>
376 <td><code>LE</code></td>
377 <td><code>FIU...</code></td>
378 <td>fdx ilh ilhp</td>
379 <td>jump if less than or equal</td>
380 </tr>
381 <tr>
382 <td>1L</td>
383 <td>2</td>
384 <td><code>LT</code></td>
385 <td><code>FIU...</code></td>
386 <td>fdx ilh ilhp</td>
387 <td>jump if less than</td>
388 </tr>
389 <tr>
390 <td>1L</td>
391 <td>2</td>
392 <td><code>NE</code></td>
393 <td><code>FIU...</code></td>
394 <td>fdx ilh ilhp</td>
395 <td>jump if not equal</td>
396 </tr>
397 <tr>
398 <td></td>
399 <td></td>
400 <td></td>
401 <td></td>
402 <td></td>
403 <td></td>
404 </tr>
405 <tr>
406 <td>2S</td>
407 <td>1</td>
408 <td><code>ARG</code></td>
409 <td><code>FIUP.B</code></td>
410 <td>fdx ilh p</td>
411 <td>argument</td>
412 </tr>
413 <tr>
414 <td>1</td>
415 <td>1 or 2</td>
416 <td><code>CALL</code></td>
417 <td><code>FIUPVB</code></td>
418 <td>fdx ilh p</td>
419 <td>function call</td>
420 </tr>
421 <tr>
422 <td></td>
423 <td>1</td>
424 <td><code>RET</code></td>
425 <td><code>FIUPV.</code></td>
426 <td>fdx ilh p</td>
427 <td>return from function</td>
428 </tr>
429 <tr>
430 <td><img SRC="/~drh/resources/dot_clear.gif" ALT="|" WIDTH="1" HEIGHT="12"></td>
431 <td></td>
432 <td></td>
433 <td></td>
434 <td></td>
435 <td></td>
436 </tr>
437 <tr>
438 <td></td>
439 <td>1</td>
440 <td><code>JUMP</code></td>
441 <td><code>....V.</code></td>
442 <td></td>
443 <td>unconditional jump</td>
444 </tr>
445 <tr>
446 <td>1L</td>
447 <td>0</td>
448 <td><code>LABEL</code></td>
449 <td><code>....V.</code></td>
450 <td></td>
451 <td>label definition</td>
452 </tr>
453 </table>
455 <p>The entries in the <strong>Sizes</strong> column indicate sizes of the operators that
456 back ends must implement. Letters denote the size of float (f), double (d), long double
457 (x), character (c), short integer (s), integer (i), long integer (l), &quot;long
458 long&quot; integer (h) , and pointer (p). These sizes are separated into sets for each
459 type suffix, except that a single set is used for both I and U when the set for I is
460 identical to the set for U.</p>
462 <p>The actual values for the size indicators, fdxcsilhp, depend on the target. A
463 specification like <code>ADDF</code>f denotes the operator <code>ADD+F+sizeop(</code>f<code>)</code>,
464 where &quot;f&quot; is replaced by a target-dependent value, e.g., <code>ADDF4</code> and <code>ADDF8</code>.
465 For example, back ends must implement the following <code>CVI</code> and <code>MUL</code>
466 operators.</p>
468 <blockquote>
469 <p><code>CVIF</code>f <code>CVIF</code>d <code>CVIF</code>x<br>
470 <code>CVII</code>c <code>CVII</code>s <code>CVII</code>i <code>CVII</code>l <code>CVII</code>h<br>
471 <code>CVIU</code>c <code>CVIU</code>s <code>CVIU</code>i <code>CVIU</code>l <code>CVIU</code>h
472 <code>CVIU</code>p<br>
473 <br>
474 <code>MULF</code>f <code>MULF</code>d <code>MULF</code>x<br>
475 <code>MULI</code>i <code>MULI</code>l <code>MULI</code>h<br>
476 <code>MULU</code>i <code>MULU</code>l <code>MULU</code>h</p>
477 </blockquote>
479 <p>On most platforms, there are fewer than three sizes of floats and six sizes of
480 integers, and pointers are usually the same size as one of the integers. And lcc doesn't
481 support the &quot;long long&quot; type, so h is not currently used. So the set of
482 platform-specific operators is usually smaller than the list above suggests. For example,
483 the X86, SPARC, and MIPS back ends implement the following <code>CVI</code> and <code>MUL</code>
484 operators.</p>
486 <blockquote>
487 <p><code>CVIF</code>4 <code>CVIF</code>8<br>
488 <code>CVII</code>1 <code>CVII</code>2 <code>CVII</code>4<br>
489 <code>CVIU</code>1 <code>CVIU</code>2 <code>CVIU</code>4 <br>
490 <br>
491 <code>MULF</code>4 <code>MULF</code>8<br>
492 <code>MULI</code>4<br>
493 <code>MULU</code>4</p>
494 </blockquote>
496 <p>The set of operators is thus target-dependent; for example, <code>ADDI8</code> appears
497 only if the target supports an 8-byte integer type. <a
498 HREF="ftp://ftp.cs.princeton.edu/pub/packages/lcc/contrib/ops.c"><code>ops.c</code></a> is
499 a program that, given a set of sizes, prints the required operators and their values,
500 e.g.,</p>
502 <blockquote>
503 <pre>% <em>ops c=1 s=2 i=4 l=4 h=4 f=4 d=8 x=8 p=4</em>
505 CVIF4=4225 CVIF8=8321
506 CVII1=1157 CVII2=2181 CVII4=4229
507 CVIU1=1158 CVIU2=2182 CVIU4=4230
509 MULF4=4561 MULF8=8657
510 MULI4=4565
511 MULU4=4566
513 131 operators</pre>
514 </blockquote>
516 <p>The type suffix for a conversion operator denotes the type of the result and the size
517 indicator gives the size of the result. For example, <code>CVUI4</code> converts an
518 unsigned (<code>U</code>) to a 4-byte signed integer (<code>I4</code>). The <code>syms[0]</code>
519 field points to a symbol-table entry for a integer constant that gives the size of the
520 source operand. For example, if <code>syms[0]</code> in a <code>CVUI4</code> points to a
521 symbol-table entry for 2, the conversion widens a 2-byte unsigned integer to a 4-byte
522 signed integer. Conversions that widen unsigned integers zero-extend; those that widen
523 signed integers sign-extend.</p>
525 <p>The front end composes conversions between types <em>T</em><sub>1</sub> and <em>T</em><sub>2</sub>
526 by widening <em>T</em><sub>1</sub> to its &quot;supertype&quot;, if necessary, converting
527 that result to <em>T</em><sub>2</sub>'s supertype, then narrowing the result to <em>T</em><sub>2</sub>,
528 if necessary. The following table lists the supertypes; omitted entries are their own
529 supertypes.</p>
531 <blockquote>
532 <table BORDER="0" CELLPADDING="0" CELLSPACING="0">
533 <tr>
534 <td><strong>Type</strong></td>
535 <td><img SRC="/~drh/resources/dot_clear.gif" ALT="|" WIDTH="24" HEIGHT="1"></td>
536 <td><strong>Supertype</strong></td>
537 </tr>
538 <tr>
539 <td>signed char</td>
540 <td></td>
541 <td>int</td>
542 </tr>
543 <tr>
544 <td>signed short</td>
545 <td></td>
546 <td>int</td>
547 </tr>
548 <tr ALIGN="LEFT" VALIGN="TOP">
549 <td>unsigned char</td>
550 <td></td>
551 <td>int, if sizeof (char) &lt; sizeof (int)<br>
552 unsigned, otherwise</td>
553 </tr>
554 <tr ALIGN="LEFT" VALIGN="TOP">
555 <td>unsigned short</td>
556 <td></td>
557 <td>int, if sizeof (short) &lt; sizeof (int)<br>
558 unsigned, otherwise</td>
559 </tr>
560 <tr ALIGN="LEFT" VALIGN="TOP">
561 <td>void *</td>
562 <td></td>
563 <td>an unsigned type as large as a pointer</td>
564 </tr>
565 </table>
566 </blockquote>
568 <p>Pointers are converted to an unsigned type of the same size, even when that type is not
569 one of the integer types.</p>
571 <p>For example, the front end converts a signed short to a float by first converting it to
572 an int and then to a float. It converts an unsigned short to an int with a single <code>CVUI</code>i
573 conversion, when shorts are smaller than ints.</p>
575 <p>There are now signed and unsigned variants of <code>ASGN</code>, <code>INDIR</code>, <code>BCOM</code>,
576 <code>BOR</code>, <code>BXOR</code>, <code>BAND</code>, <code>ARG</code>, <code>CALL</code>,
577 and <code>RET</code> to simplify code generation on platforms that use different
578 instructions or register set for signed and unsigned operations. Likewise there are now
579 pointer variants of <code>ASGN</code>, <code>INDIR</code>, <code>ARG</code>, <code>CALL</code>,
580 and <code>RET</code>.</p>
582 <h2><a NAME="flags">5.6 Interface Flags</a></h2>
584 <pre>unsigned unsigned_char:1;</pre>
586 <p>tells the front end whether plain characters are signed or unsigned. If it's zero, char
587 is a signed type; otherwise, char is an unsigned type.</p>
589 <p>All the interface flags can be set by command-line options, e.g., <code>-Wf-unsigned_char=1</code>
590 causes plain characters to be unsigned.</p>
592 <h2><a NAME="definitions">5.8 Definitions</a></h2>
594 <p>The front end announces local variables by calling</p>
596 <pre>void (*local)(Symbol);</pre>
598 <p>It announces temporaries likewise; these have the symbol's <code>temporary</code> flag
599 set, which indicates that the symbol will be used only in the next call to <code>gen</code>.
600 If a temporary's <code>u.t.cse</code> field is nonnull, it points to the node that
601 computes the value assigned to the temporary; see page 346.</p>
603 <p>The front end calls</p>
605 <pre>void (*address)(Symbol p, Symbol q, long n);</pre>
607 <p>to initialize <code>q</code> to a symbol that represents an address of the form <em>x</em>+<code>n</code>,
608 where <em>x</em> is the address represented by <code>p</code> and the long integer <code>n</code>
609 is positive or negative.</p>
611 <h2><a NAME="constants">5.9 Constants</a></h2>
613 <p>The interface function</p>
615 <pre>void (*defconst)(int suffix, int size, Value v);</pre>
617 <p>initializes constants. defconst emits directives to define a cell and initialize it to
618 a constant value. v is the constant value, suffix identifies the type of the value, and
619 size is the size of the value in bytes. The value of suffix indicates which field of v
620 holds the value, as shown in the following table.</p>
622 <blockquote>
623 <table BORDER="0" CELLPADDING="1" CELLSPACING="1">
624 <tr>
625 <td><strong>suffix</strong></td>
626 <td><img SRC="/~drh/resources/dot_clear.gif" ALT="|" WIDTH="24" HEIGHT="1"></td>
627 <td><strong>v Field</strong></td>
628 <td><img SRC="/~drh/resources/dot_clear.gif" ALT="|" WIDTH="24" HEIGHT="1"></td>
629 <td><strong>size</strong></td>
630 </tr>
631 <tr>
632 <td><code>F</code></td>
633 <td></td>
634 <td><code>v.d</code></td>
635 <td></td>
636 <td>float, double, long double</td>
637 </tr>
638 <tr>
639 <td><code>I</code></td>
640 <td></td>
641 <td><code>v.i</code></td>
642 <td></td>
643 <td>signed char, signed short, signed int, signed long</td>
644 </tr>
645 <tr>
646 <td><code>U</code></td>
647 <td></td>
648 <td><code>v.u</code></td>
649 <td></td>
650 <td>unsigned char, unsigned short, unsigned int, unsigned long</td>
651 </tr>
652 <tr>
653 <td><code>P</code></td>
654 <td></td>
655 <td><code>v.p</code></td>
656 <td></td>
657 <td>void *</td>
658 </tr>
659 </table>
660 </blockquote>
662 <p><code>defconst</code> must narrow <code>v.</code>x when <code>size</code> is less than <code>sizeof</code>
663 <code>v.</code>x; e.g., to emit an unsigned char, <code>defconst</code> should emit <code>(unsigned
664 char)v.i</code>.</p>
666 <h2><a NAME="upcalls">5.12 Upcalls</a></h2>
668 <p>lcc 4.x uses standard I/O and its I/O functions have been changed accordingly. lcc
669 reads input from the standard input, emits code to the standard output, and writes
670 diagnostics to the standard error output. It uses <code>freopen</code> to redirect these
671 streams to explicit files, when necessary.</p>
673 <p><code>bp</code>, <code>outflush</code>, and <code>outs</code> have been eliminated.</p>
675 <pre>extern void fprint(FILE *f, const char *fmt, ...);
676 extern void print(const char *fmt, ...);</pre>
678 <p>print formatted data to file <code>f</code> (<code>fprint</code>) or the standard
679 output (<code>print</code>). These functions are like standard C's <code>printf</code> and
680 <code>fprintf</code>, but support only some of the standard conversion specifiers and do
681 not support flags, precision, and field-width specifications. They support the following
682 new conversion specifiers in addition to those described on page 99.</p>
684 <blockquote>
685 <table BORDER="0" CELLPADDING="0" CELLSPACING="0">
686 <tr>
687 <td><strong>Specifiers</strong></td>
688 <td><img SRC="/~drh/resources/dot_clear.gif" ALT="|" WIDTH="24" HEIGHT="1"></td>
689 <td><strong>Corresponding printf Specifiers</strong></td>
690 </tr>
691 <tr>
692 <td><code>%c</code></td>
693 <td></td>
694 <td><code>%c</code></td>
695 </tr>
696 <tr>
697 <td><code>%d %D</code></td>
698 <td></td>
699 <td><code>%d %ld</code></td>
700 </tr>
701 <tr>
702 <td><code>%u %U</code></td>
703 <td></td>
704 <td><code>%u %lu</code></td>
705 </tr>
706 <tr>
707 <td><code>%x %X</code></td>
708 <td></td>
709 <td><code>%x %lx</code></td>
710 </tr>
711 <tr>
712 <td><code>%f %e %g</code></td>
713 <td></td>
714 <td><code>%e %f %g</code></td>
715 </tr>
716 <tr ALIGN="LEFT" VALIGN="TOP">
717 <td><code>%p</code></td>
718 <td></td>
719 <td>Converts the corresponding void * argument to unsigned long and prints it with the <code>printf</code>
720 <code>%#x</code> specifier or just <code>%x</code> when the argument is null.</td>
721 </tr>
722 <tr ALIGN="LEFT" VALIGN="TOP">
723 <td><code>%I</code></td>
724 <td></td>
725 <td>Prints the number of spaces given by the corresponding argument.</td>
726 </tr>
727 </table>
728 </blockquote>
730 <pre>#define generic(op) ((op)&amp;0x3F0)
731 #define specific(op) ((op)&amp;0x3FF)</pre>
733 <p><code>generic(op)</code> returns the generic variant of <code>op</code>; that is,
734 without its type suffix and size indicator. <code>specific(op)</code> returns the
735 type-specific variant of <code>op</code>; that is, without its size indicator.</p>
737 <p><code>newconst</code> has been replaced by</p>
739 <pre>extern Symbol intconst(int n);</pre>
741 <p>which installs the integer constant <code>n</code> in the symbol table, if necessary,
742 and returns a pointer to the symbol-table entry.</p>
744 <hr>
746 <address>
747 <a HREF="http://www.research.microsoft.com/~cwfraser/">Chris Fraser</a> / <a
748 HREF="mailto:cwfraser@microsoft.com">cwfraser@microsoft.com</a><br>
749 <a HREF="http://www.research.microsoft.com/~drh/">David Hanson</a> / <a
750 HREF="mailto:drh@microsoft.com">drh@microsoft.com</a><br>
751 $Revision: 145 $ $Date: 2001-10-17 16:53:10 -0500 (Wed, 17 Oct 2001) $
752 </address>
753 </body>
754 </html>