aboutsummaryrefslogtreecommitdiffstats
path: root/lcc/doc/4.html
blob: 0158d8b18c2790464668f577f7da399f03ab4ed4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>

<head>
<link HREF="mailto:drh@microsoft.com" REV="made" TITLE="David R. Hanson">
<title>The lcc 4.1 Code-Generation Interface</title>
</head>

<body>

<h1>The lcc 4.1 Code-Generation Interface</h1>

<p ALIGN="LEFT"><strong><a HREF="http://www.research.microsoft.com/~cwfraser/">Christopher
W. Fraser</a> and <a HREF="http://www.research.microsoft.com/~drh/">David R. Hanson</a>, <a
HREF="http://www.research.microsoft.com/">Microsoft Research</a></strong></p>

<h2>Contents</h2>

<dir>
  <li><a HREF="#intro">Introduction</a> </li>
  <li><a HREF="#metrics">5.1 Type Metrics</a></li>
  <li><a HREF="#symbols">5.3 Symbols</a> </li>
  <li><a HREF="#operators">5.5 Dag Operators</a></li>
  <li><a HREF="#flags">5.6 Interface Flags</a></li>
  <li><a HREF="#definitions">5.8 Definitions</a></li>
  <li><a HREF="#constants">5.9 Constants</a></li>
  <li><a HREF="#upcalls">5.12 Upcalls</a></li>
</dir>

<h2><a NAME="intro">Introduction</a></h2>

<p>Version 4.1 is the latest release of <a
HREF="http://www.cs.princeton.edu/software/lcc/">lcc</a>, the ANSI C compiler described in
our book <cite>A Retargetable C Compiler: Design and Implementation</cite>
(Addison-Wesley, 1995, ISBN 0-8053-1670-1). This document summarizes the differences
between the 4.1 code-generation interface and the 3.x interface described in Chap. 5 of <cite>A
Retargetable C Compiler</cite>.</p>

<p>Previous versions of lcc supported only three sizes of integers, two sizes of floats,
and insisted that pointers fit in unsigned integers (see Sec. 5.1 of <cite>A Retargetable
C Compiler</cite>). These assumptions simplified the compiler, and were suitable for
32-bit architectures. But on 64-bit architectures, such as the DEC ALPHA, it's natural to
have four sizes of integers and perhaps three sizes of floats, and on 16-bit
architectures, 32-bit pointers don't fit in unsigned integers. Also, the 3.x constaints
limited the use of lcc's back ends for other languages, such as Java.</p>

<p>Version 4.x removes all of these restrictions: It supports any number of sizes for
integers and floats, and the size of pointers need not be related to the size of any of
the integer types. The major changes in the code-generation interface are: 

<ul>
  <li>The number of type suffixes has been reduced to 6.</li>
  <li>Dag operators are composed of a generic operator, a type suffix, and a size.</li>
  <li>Unsigned variants of several operators have been added.</li>
  <li>Several interface functions have new signatures.</li>
</ul>

<p>In addition, version 4.x is written in ANSI C and uses the standard I/O library and
other standard C functions.</p>

<p>The sections below parallel the subsections of Chap. 5 of <cite>A Retargetable C
Compiler</cite> and summarize the differences between the 3.x and 4.x code-generation
interface. Unaffected subsections are omitted. Page citations refer to pages in <cite>A
Retargetable C Compiler</cite>.</p>

<h2><a NAME="metrics">5.1 Type Metrics</a></h2>

<p>There are now 10 metrics in an interface record:</p>

<pre>Metrics charmetric;
Metrics shortmetric;
Metrics intmetric;
Metrics longmetric;
Metrics longlongmetric;
Metrics floatmetric;
Metrics doublemetric;
Metrics longdoublemetric;
Metrics ptrmetric;
Metrics structmetric;</pre>

<p>Each of these specifies the size and alignment of the corresponding type. <code>ptrmetric</code>
describes all pointers.</p>

<h2><a NAME="symbols">5.3 Symbols</a></h2>

<p>The actual value of a constant is stored in the <code>u.c.v</code> field of a symbol,
which holds a <code>Value</code>:</p>

<pre>typedef union value {
	long i;
	unsigned long u;
	long double d;
	void *p;
	void (*g)(void);
} Value;</pre>

<p>The value is stored in the appropriate field according to its type, which is given by
the symbol's <code>type</code> field.</p>

<h2><a NAME="operators">5.5 Dag Operators</a></h2>

<p>The <code>op</code> field a of <code>node</code> structure holds a dag operator, which
consists of a generic operator, a type suffix, and a size indicator. The type suffixes
are:</p>

<pre>enum {
	F=FLOAT,
	I=INT,
	U=UNSIGNED,
	P=POINTER,
	V=VOID,
	B=STRUCT
};

#define sizeop(n) ((n)&lt;&lt;10)</pre>

<p>Given a generic operator <code>o</code>, a type suffix <code>t</code>, and a size <code>s</code>,
a type- and size-specific operator is formed by <code>o+t+sizeop(s)</code>. For example, <code>ADD+F+sizeop(4)</code>
forms the operator <code>ADDF4</code>, which denotes the sum of two 4-byte floats.
Similarly, <code>ADD+F+sizeop(8)</code> forms <code>ADDF8</code>, which denotes 8-byte
floating addition. In the 3.x code-generation interface, <code>ADDF</code> and <code>ADDD</code>
denoted these operations. There was no size indicator in the 3.x operators because the
type suffix supplied both a type and a size.</p>

<p>Table 5.1 lists each generic operator, its valid type suffixes, and the number of <code>kids</code>
and <code>syms</code> that it uses; multiple values for <code>kids</code> indicate
type-specific variants. The notations in the <strong>syms</strong> column give the number
of <code>syms</code> values and a one-letter code that suggests their uses: 1V indicates
that <code>syms[0]</code> points to a symbol for a variable, 1C indicates that <code>syms[0]</code>
is a constant, and 1L indicates that <code>syms[0]</code> is a label. For 1S, <code>syms[0]</code>
is a constant whose value is a size in bytes; 2S adds <code>syms[1]</code>, which is a
constant whose value is an alignment. For most operators, the type suffix and size
indicator denote the type and size of operation to perform and the type and size of the
result.</p>

<table WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0">
  <tr>
    <td COLSPAN="6" ALIGN="CENTER"><strong>Table 5.1<img SRC="/~drh/resources/dot_clear.gif"
    ALT="|" WIDTH="18" HEIGHT="1">Node Operators.</strong></td>
  </tr>
  <tr>
    <td><strong>syms</strong></td>
    <td><strong>kids</strong></td>
    <td><strong>Operator</strong></td>
    <td><strong>Type Suffixes</strong></td>
    <td><strong>Sizes</strong></td>
    <td><strong>Operation</strong></td>
  </tr>
  <tr>
    <td>1V</td>
    <td>0</td>
    <td><code>ADDRF</code></td>
    <td><code>...P..</code></td>
    <td>p</td>
    <td>address of a parameter</td>
  </tr>
  <tr>
    <td>1V</td>
    <td>0</td>
    <td><code>ADDRG</code></td>
    <td><code>...P..</code></td>
    <td>p</td>
    <td>address of a global</td>
  </tr>
  <tr>
    <td>1V</td>
    <td>0</td>
    <td><code>ADDRL</code></td>
    <td><code>...P..</code></td>
    <td>p</td>
    <td>address of a local</td>
  </tr>
  <tr>
    <td>1C</td>
    <td>0</td>
    <td><code>CNST</code></td>
    <td><code>FIUP..</code></td>
    <td>fdx csilh p</td>
    <td>constant</td>
  </tr>
  <tr ALIGN="LEFT" VALIGN="TOP">
    <td><img SRC="/~drh/resources/dot_clear.gif" ALT="|" WIDTH="1" HEIGHT="12"></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
  </tr>
  <tr>
    <td></td>
    <td>1</td>
    <td><code>BCOM</code></td>
    <td><code>.IU...</code></td>
    <td>ilh</td>
    <td>bitwise complement</td>
  </tr>
  <tr>
    <td>1S</td>
    <td>1</td>
    <td><code>CVF</code></td>
    <td><code>FI....</code></td>
    <td>fdx ilh</td>
    <td>convert from float</td>
  </tr>
  <tr>
    <td>1S</td>
    <td>1</td>
    <td><code>CVI</code></td>
    <td><code>FIU...</code></td>
    <td>fdx csilh csilhp</td>
    <td>convert from signed integer</td>
  </tr>
  <tr>
    <td>1S</td>
    <td>1</td>
    <td><code>CVP</code></td>
    <td><code>..U..</code></td>
    <td>p</td>
    <td>convert from pointer</td>
  </tr>
  <tr>
    <td>1S</td>
    <td>1</td>
    <td><code>CVU</code></td>
    <td><code>.IUP..</code></td>
    <td>csilh p</td>
    <td>convert from unsigned integer</td>
  </tr>
  <tr>
    <td></td>
    <td>1</td>
    <td><code>INDIR</code></td>
    <td><code>FIUP.B</code></td>
    <td>fdx csilh p</td>
    <td>fetch</td>
  </tr>
  <tr>
    <td></td>
    <td>1</td>
    <td><code>NEG</code></td>
    <td><code>FI....</code></td>
    <td>fdx ilh</td>
    <td>negation</td>
  </tr>
  <tr>
    <td><img SRC="/~drh/resources/dot_clear.gif" ALT="|" WIDTH="1" HEIGHT="12"></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
  </tr>
  <tr>
    <td></td>
    <td>2</td>
    <td><code>ADD</code></td>
    <td><code>FIUP..</code></td>
    <td>fdx ilh ilhp p</td>
    <td>addition</td>
  </tr>
  <tr>
    <td></td>
    <td>2</td>
    <td><code>BAND</code></td>
    <td><code>.IU...</code></td>
    <td>ilh</td>
    <td>bitwise AND</td>
  </tr>
  <tr>
    <td></td>
    <td>2</td>
    <td><code>BOR</code></td>
    <td><code>.IU...</code></td>
    <td>ilh</td>
    <td>bitwise inclusive OR</td>
  </tr>
  <tr>
    <td></td>
    <td>2</td>
    <td><code>BXOR</code></td>
    <td><code>.IU...</code></td>
    <td>ilh</td>
    <td>bitwise exclusive OR</td>
  </tr>
  <tr>
    <td></td>
    <td>2</td>
    <td><code>DIV</code></td>
    <td><code>FIU...</code></td>
    <td>fdx ilh</td>
    <td>division</td>
  </tr>
  <tr>
    <td></td>
    <td>2</td>
    <td><code>LSH</code></td>
    <td><code>.IU...</code></td>
    <td>ilh</td>
    <td>left shift</td>
  </tr>
  <tr>
    <td></td>
    <td>2</td>
    <td><code>MOD</code></td>
    <td><code>.IU...</code></td>
    <td>ilh</td>
    <td>modulus</td>
  </tr>
  <tr>
    <td></td>
    <td>2</td>
    <td><code>MUL</code></td>
    <td><code>FIU...</code></td>
    <td>fdx ilh</td>
    <td>multiplication</td>
  </tr>
  <tr>
    <td></td>
    <td>2</td>
    <td><code>RSH</code></td>
    <td><code>.IU...</code></td>
    <td>ilh</td>
    <td>right shift</td>
  </tr>
  <tr>
    <td></td>
    <td>2</td>
    <td><code>SUB</code></td>
    <td><code>FIUP..</code></td>
    <td>fdx ilh ilhp p</td>
    <td>subtraction</td>
  </tr>
  <tr>
    <td><img SRC="/~drh/resources/dot_clear.gif" ALT="|" WIDTH="1" HEIGHT="12"></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
  </tr>
  <tr>
    <td>2S</td>
    <td>2</td>
    <td><code>ASGN</code></td>
    <td><code>FIUP.B</code></td>
    <td>fdx csilh p</td>
    <td>assignment</td>
  </tr>
  <tr>
    <td>1L</td>
    <td>2</td>
    <td><code>EQ</code></td>
    <td><code>FIU...</code></td>
    <td>fdx ilh ilhp</td>
    <td>jump if equal</td>
  </tr>
  <tr>
    <td>1L</td>
    <td>2</td>
    <td><code>GE</code></td>
    <td><code>FIU...</code></td>
    <td>fdx ilh ilhp</td>
    <td>jump if greater than or equal</td>
  </tr>
  <tr>
    <td>1L</td>
    <td>2</td>
    <td><code>GT</code></td>
    <td><code>FIU...</code></td>
    <td>fdx ilh ilhp</td>
    <td>jump if greater than</td>
  </tr>
  <tr>
    <td>1L</td>
    <td>2</td>
    <td><code>LE</code></td>
    <td><code>FIU...</code></td>
    <td>fdx ilh ilhp</td>
    <td>jump if less than or equal</td>
  </tr>
  <tr>
    <td>1L</td>
    <td>2</td>
    <td><code>LT</code></td>
    <td><code>FIU...</code></td>
    <td>fdx ilh ilhp</td>
    <td>jump if less than</td>
  </tr>
  <tr>
    <td>1L</td>
    <td>2</td>
    <td><code>NE</code></td>
    <td><code>FIU...</code></td>
    <td>fdx ilh ilhp</td>
    <td>jump if not equal</td>
  </tr>
  <tr>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
  </tr>
  <tr>
    <td>2S</td>
    <td>1</td>
    <td><code>ARG</code></td>
    <td><code>FIUP.B</code></td>
    <td>fdx ilh p</td>
    <td>argument</td>
  </tr>
  <tr>
    <td>1</td>
    <td>1 or 2</td>
    <td><code>CALL</code></td>
    <td><code>FIUPVB</code></td>
    <td>fdx ilh p</td>
    <td>function call</td>
  </tr>
  <tr>
    <td></td>
    <td>1</td>
    <td><code>RET</code></td>
    <td><code>FIUPV.</code></td>
    <td>fdx ilh p</td>
    <td>return from function</td>
  </tr>
  <tr>
    <td><img SRC="/~drh/resources/dot_clear.gif" ALT="|" WIDTH="1" HEIGHT="12"></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
  </tr>
  <tr>
    <td></td>
    <td>1</td>
    <td><code>JUMP</code></td>
    <td><code>....V.</code></td>
    <td></td>
    <td>unconditional jump</td>
  </tr>
  <tr>
    <td>1L</td>
    <td>0</td>
    <td><code>LABEL</code></td>
    <td><code>....V.</code></td>
    <td></td>
    <td>label definition</td>
  </tr>
</table>

<p>The entries in the <strong>Sizes</strong> column indicate sizes of the operators that
back ends must implement. Letters denote the size of float (f), double (d), long double
(x), character (c), short integer (s), integer (i), long integer (l), &quot;long
long&quot; integer (h) , and pointer (p). These sizes are separated into sets for each
type suffix, except that a single set is used for both I and U when the set for I is
identical to the set for U.</p>

<p>The actual values for the size indicators, fdxcsilhp, depend on the target. A
specification like <code>ADDF</code>f denotes the operator <code>ADD+F+sizeop(</code>f<code>)</code>,
where &quot;f&quot; is replaced by a target-dependent value, e.g., <code>ADDF4</code> and <code>ADDF8</code>.
For example, back ends must implement the following <code>CVI</code> and <code>MUL</code>
operators.</p>

<blockquote>
  <p><code>CVIF</code>f <code>CVIF</code>d <code>CVIF</code>x<br>
  <code>CVII</code>c <code>CVII</code>s <code>CVII</code>i <code>CVII</code>l <code>CVII</code>h<br>
  <code>CVIU</code>c <code>CVIU</code>s <code>CVIU</code>i <code>CVIU</code>l <code>CVIU</code>h
  <code>CVIU</code>p<br>
  <br>
  <code>MULF</code>f <code>MULF</code>d <code>MULF</code>x<br>
  <code>MULI</code>i <code>MULI</code>l <code>MULI</code>h<br>
  <code>MULU</code>i <code>MULU</code>l <code>MULU</code>h</p>
</blockquote>

<p>On most platforms, there are fewer than three sizes of floats and six sizes of
integers, and pointers are usually the same size as one of the integers. And lcc doesn't
support the &quot;long long&quot; type, so h is not currently used. So the set of
platform-specific operators is usually smaller than the list above suggests. For example,
the X86, SPARC, and MIPS back ends implement the following <code>CVI</code> and <code>MUL</code>
operators.</p>

<blockquote>
  <p><code>CVIF</code>4 <code>CVIF</code>8<br>
  <code>CVII</code>1 <code>CVII</code>2 <code>CVII</code>4<br>
  <code>CVIU</code>1 <code>CVIU</code>2 <code>CVIU</code>4 <br>
  <br>
  <code>MULF</code>4 <code>MULF</code>8<br>
  <code>MULI</code>4<br>
  <code>MULU</code>4</p>
</blockquote>

<p>The set of operators is thus target-dependent; for example, <code>ADDI8</code> appears
only if the target supports an 8-byte integer type. <a
HREF="ftp://ftp.cs.princeton.edu/pub/packages/lcc/contrib/ops.c"><code>ops.c</code></a> is
a program that, given a set of sizes, prints the required operators and their values,
e.g.,</p>

<blockquote>
  <pre>% <em>ops c=1 s=2 i=4 l=4 h=4 f=4 d=8 x=8 p=4</em>
...
 CVIF4=4225 CVIF8=8321
 CVII1=1157 CVII2=2181 CVII4=4229
 CVIU1=1158 CVIU2=2182 CVIU4=4230
...
 MULF4=4561 MULF8=8657
 MULI4=4565
 MULU4=4566
...
131 operators</pre>
</blockquote>

<p>The type suffix for a conversion operator denotes the type of the result and the size
indicator gives the size of the result. For example, <code>CVUI4</code> converts an
unsigned (<code>U</code>) to a 4-byte signed integer (<code>I4</code>). The <code>syms[0]</code>
field points to a symbol-table entry for a integer constant that gives the size of the
source operand. For example, if <code>syms[0]</code> in a <code>CVUI4</code> points to a
symbol-table entry for 2, the conversion widens a 2-byte unsigned integer to a 4-byte
signed integer. Conversions that widen unsigned integers zero-extend; those that widen
signed integers sign-extend.</p>

<p>The front end composes conversions between types <em>T</em><sub>1</sub> and <em>T</em><sub>2</sub>
by widening <em>T</em><sub>1</sub> to it's &quot;supertype&quot;, if necessary, converting
that result to <em>T</em><sub>2</sub>'s supertype, then narrowing the result to <em>T</em><sub>2</sub>,
if necessary. The following table lists the supertypes; omitted entries are their own
supertypes.</p>

<blockquote>
  <table BORDER="0" CELLPADDING="0" CELLSPACING="0">
    <tr>
      <td><strong>Type</strong></td>
      <td><img SRC="/~drh/resources/dot_clear.gif" ALT="|" WIDTH="24" HEIGHT="1"></td>
      <td><strong>Supertype</strong></td>
    </tr>
    <tr>
      <td>signed char</td>
      <td></td>
      <td>int</td>
    </tr>
    <tr>
      <td>signed short</td>
      <td></td>
      <td>int</td>
    </tr>
    <tr ALIGN="LEFT" VALIGN="TOP">
      <td>unsigned char</td>
      <td></td>
      <td>int, if sizeof (char) &lt; sizeof (int)<br>
      unsigned, otherwise</td>
    </tr>
    <tr ALIGN="LEFT" VALIGN="TOP">
      <td>unsigned short</td>
      <td></td>
      <td>int, if sizeof (short) &lt; sizeof (int)<br>
      unsigned, otherwise</td>
    </tr>
    <tr ALIGN="LEFT" VALIGN="TOP">
      <td>void *</td>
      <td></td>
      <td>an unsigned type as large as a pointer</td>
    </tr>
  </table>
</blockquote>

<p>Pointers are converted to an unsigned type of the same size, even when that type is not
one of the integer types.</p>

<p>For example, the front end converts a signed short to a float by first converting it to
an int and then to a float. It converts an unsigned short to an int with a single <code>CVUI</code>i
conversion, when shorts are smaller than ints.</p>

<p>There are now signed and unsigned variants of <code>ASGN</code>, <code>INDIR</code>, <code>BCOM</code>,
<code>BOR</code>, <code>BXOR</code>, <code>BAND</code>, <code>ARG</code>, <code>CALL</code>,
and <code>RET</code> to simplify code generation on platforms that use different
instructions or register set for signed and unsigned operations. Likewise there are now
pointer variants of <code>ASGN</code>, <code>INDIR</code>, <code>ARG</code>, <code>CALL</code>,
and <code>RET</code>.</p>

<h2><a NAME="flags">5.6 Interface Flags</a></h2>

<pre>unsigned unsigned_char:1;</pre>

<p>tells the front end whether plain characters are signed or unsigned. If it's zero, char
is a signed type; otherwise, char is an unsigned type.</p>

<p>All the interface flags can be set by command-line options, e.g., <code>-Wf-unsigned_char=1</code>
causes plain characters to be unsigned.</p>

<h2><a NAME="definitions">5.8 Definitions</a></h2>

<p>The front end announces local variables by calling</p>

<pre>void (*local)(Symbol);</pre>

<p>It announces temporaries likewise; these have the symbol's <code>temporary</code> flag
set, which indicates that the symbol will be used only in the next call to <code>gen</code>.
If a temporary's <code>u.t.cse</code> field is nonnull, it points to the node that
computes the value assigned to the temporary; see page 346.</p>

<p>The front end calls</p>

<pre>void (*address)(Symbol p, Symbol q, long n);</pre>

<p>to initialize <code>q</code> to a symbol that represents an address of the form <em>x</em>+<code>n</code>,
where <em>x</em> is the address represented by <code>p</code> and the long integer <code>n</code>
is positive or negative.</p>

<h2><a NAME="constants">5.9 Constants</a></h2>

<p>The interface function</p>

<pre>void (*defconst)(int suffix, int size, Value v);</pre>

<p>initializes constants. defconst emits directives to define a cell and initialize it to
a constant value. v is the constant value, suffix identifies the type of the value, and
size is the size of the value in bytes. The value of suffix indicates which field of v
holds the value, as shown in the following table.</p>

<blockquote>
  <table BORDER="0" CELLPADDING="1" CELLSPACING="1">
    <tr>
      <td><strong>suffix</strong></td>
      <td><img SRC="/~drh/resources/dot_clear.gif" ALT="|" WIDTH="24" HEIGHT="1"></td>
      <td><strong>v Field</strong></td>
      <td><img SRC="/~drh/resources/dot_clear.gif" ALT="|" WIDTH="24" HEIGHT="1"></td>
      <td><strong>size</strong></td>
    </tr>
    <tr>
      <td><code>F</code></td>
      <td></td>
      <td><code>v.d</code></td>
      <td></td>
      <td>float, double, long double</td>
    </tr>
    <tr>
      <td><code>I</code></td>
      <td></td>
      <td><code>v.i</code></td>
      <td></td>
      <td>signed char, signed short, signed int, signed long</td>
    </tr>
    <tr>
      <td><code>U</code></td>
      <td></td>
      <td><code>v.u</code></td>
      <td></td>
      <td>unsigned char, unsigned short, unsigned int, unsigned long</td>
    </tr>
    <tr>
      <td><code>P</code></td>
      <td></td>
      <td><code>v.p</code></td>
      <td></td>
      <td>void *</td>
    </tr>
  </table>
</blockquote>

<p><code>defconst</code> must narrow <code>v.</code>x when <code>size</code> is less than <code>sizeof</code>
<code>v.</code>x; e.g., to emit an unsigned char, <code>defconst</code> should emit <code>(unsigned
char)v.i</code>.</p>

<h2><a NAME="upcalls">5.12 Upcalls</a></h2>

<p>lcc 4.x uses standard I/O and its I/O functions have been changed accordingly. lcc
reads input from the standard input, emits code to the standard output, and writes
diagnostics to the standard error output. It uses <code>freopen</code> to redirect these
streams to explicit files, when necessary.</p>

<p><code>bp</code>, <code>outflush</code>, and <code>outs</code> have been eliminated.</p>

<pre>extern void fprint(FILE *f, const char *fmt, ...);
extern void  print(const char *fmt, ...);</pre>

<p>print formatted data to file <code>f</code> (<code>fprint</code>) or the standard
output (<code>print</code>). These functions are like standard C's <code>printf</code> and
<code>fprintf</code>, but support only some of the standard conversion specifiers and do
not support flags, precision, and field-width specifications. They support the following
new conversion specifiers in addition to those described on page 99.</p>

<blockquote>
  <table BORDER="0" CELLPADDING="0" CELLSPACING="0">
    <tr>
      <td><strong>Specifiers</strong></td>
      <td><img SRC="/~drh/resources/dot_clear.gif" ALT="|" WIDTH="24" HEIGHT="1"></td>
      <td><strong>Corresponding printf Specifiers</strong></td>
    </tr>
    <tr>
      <td><code>%c</code></td>
      <td></td>
      <td><code>%c</code></td>
    </tr>
    <tr>
      <td><code>%d %D</code></td>
      <td></td>
      <td><code>%d %ld</code></td>
    </tr>
    <tr>
      <td><code>%u %U</code></td>
      <td></td>
      <td><code>%u %lu</code></td>
    </tr>
    <tr>
      <td><code>%x %X</code></td>
      <td></td>
      <td><code>%x %lx</code></td>
    </tr>
    <tr>
      <td><code>%f %e %g</code></td>
      <td></td>
      <td><code>%e %f %g</code></td>
    </tr>
    <tr ALIGN="LEFT" VALIGN="TOP">
      <td><code>%p</code></td>
      <td></td>
      <td>Converts the corresponding void * argument to unsigned long and prints it with the <code>printf</code>
      <code>%#x</code> specifier or just <code>%x</code> when the argument is null.</td>
    </tr>
    <tr ALIGN="LEFT" VALIGN="TOP">
      <td><code>%I</code></td>
      <td></td>
      <td>Prints the number of spaces given by the corresponding argument.</td>
    </tr>
  </table>
</blockquote>

<pre>#define generic(op)  ((op)&amp;0x3F0)
#define specific(op) ((op)&amp;0x3FF)</pre>

<p><code>generic(op)</code> returns the generic variant of <code>op</code>; that is,
without its type suffix and size indicator. <code>specific(op)</code> returns the
type-specific variant of <code>op</code>; that is, without its size indicator.</p>

<p><code>newconst</code> has been replaced by</p>

<pre>extern Symbol intconst(int n);</pre>

<p>which installs the integer constant <code>n</code> in the symbol table, if necessary,
and returns a pointer to the symbol-table entry.</p>

<hr>

<address>
  <a HREF="http://www.research.microsoft.com/~cwfraser/">Chris Fraser</a> / <a
  HREF="mailto:cwfraser@microsoft.com">cwfraser@microsoft.com</a><br>
  <a HREF="http://www.research.microsoft.com/~drh/">David Hanson</a> / <a
  HREF="mailto:drh@microsoft.com">drh@microsoft.com</a><br>
  $Revision: 145 $ $Date: 2001-10-17 16:53:10 -0500 (Wed, 17 Oct 2001) $ 
</address>
</body>
</html>