4.html 23 KB

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