466
|
1 <chapter>
|
|
2 <title>The C Compiler System</title>
|
|
3
|
|
4 <section>
|
|
5 <title>Introduction</title>
|
|
6 <para>
|
468
|
7 The "C" programming language is rapidly growing in popularity
|
|
8 and seems destined to become one of the most popular programming
|
|
9 languages used for microcomputers. The rapid rise in the use of C
|
|
10 is not surprising. C is an incredibly versatile and efficient
|
|
11 language that can handle tasks that previously would have required
|
|
12 complex assembly language programming.
|
466
|
13 </para>
|
530
|
14 <para>
|
|
15 C was originally developed at Bell Telephone Laboratories as an
|
|
16 implementation language for the UNIX operating system by Brian
|
|
17 Kernighan and Dennis Ritchie. They also wrote a book titled <quote>The
|
|
18 C Programming Language</quote> which is universally accepted as the standard
|
|
19 for the language. It is an interesting reflection on the language
|
|
20 that although no formal industry-wide <quote>standard</quote> was ever developed
|
|
21 for C, programs written in C tend to be far more portable between
|
|
22 radically different computer systems as compared to so-called
|
|
23 <quote>standardized</quote> languages such as BASIC, COBOL, and PASCAL. The
|
|
24 reason C is so portable is that the language is so inherently
|
|
25 expandable that is some special function is required, the user can
|
|
26 create a portable extension to the language, as opposed to the
|
|
27 common practice of adding additional statements to the language.
|
|
28 For example, the number of special-purpose BASIC dialects defies all
|
|
29 reason. A lesser factor is the underlying UNIX operating system,
|
|
30 which is also sufficiently versatile to discourage bastardization of
|
|
31 the language. Indeed, standard C compilers and Unix are intimately
|
|
32 related.
|
|
33 </para>
|
|
34 <para>
|
|
35 Fortunately, the 6809 microprocessor, the OS-9 operating
|
|
36 system, and the C language form an outstanding combination. The
|
|
37 6809 was specifically designed to efficiently run high-level
|
|
38 languages, and its stack-oriented instruction set and versatile
|
|
39 repertoire of addressing modes handle the C language very well. As
|
|
40 mentioned previously, UNIX and C are closely related, and because
|
|
41 OS-9 is derived from UNIX, it also supports C to the degree that
|
|
42 almost any application written in C can be transported from a UNIX
|
|
43 system to an OS-9 system, recompiled, and correctly executed.
|
|
44 </para>
|
466
|
45 </section>
|
|
46 <section>
|
468
|
47 <title>The Language Implementation</title>
|
466
|
48 <para>
|
468
|
49 OS-9 C is implemented almost exactly as described in 'The C
|
|
50 Programming Language' by Kernighan and Ritchie (hereafter referred
|
|
51 to as K&R).
|
|
52 </para>
|
|
53 <para>
|
|
54 Allthough this version of C follows the specification faithfully,
|
|
55 there are some differences. The differences mostly reflect
|
|
56 parts of C that are obsolete or the constraints imposed by memory
|
|
57 size limitations.
|
466
|
58 </para>
|
530
|
59 </section>
|
472
|
60
|
530
|
61 <section>
|
|
62 <title>Differences from the K & R Specification</title>
|
629
|
63 <itemizedlist spacing="compact">
|
|
64 <listitem><para>
|
|
65 Bit fields are not supported.
|
|
66 </para></listitem>
|
|
67 <listitem><para>
|
|
68 Constant expressions for initializers may include arithmetic
|
|
69 operators only if all the operands are of type INT or CHAR.
|
|
70 </para></listitem>
|
|
71 <listitem><para>
|
|
72 The older forms of assignment operators, '=+' or '=*', which
|
|
73 are recognized by some C compilers, are not supported. You
|
|
74 must use the newer forms '+=','*=' etc.
|
|
75 </para></listitem>
|
|
76 <listitem><para>
|
|
77 "#ifdef (or #ifndef) ...[#else...] #endif" is supported but
|
|
78 "#if <constant expression>" is not.
|
|
79 </para></listitem>
|
|
80 <listitem><para>
|
|
81 It is not possible to extend macro definitions or strings
|
|
82 over more than one line of source code.
|
|
83 </para></listitem>
|
|
84 <listitem><para>
|
|
85 The escape sequence for new-line '\n' refers to the ASCII
|
|
86 carriage return character (used by OS-9 for end-of-line), not
|
|
87 linefeed. (hex 0A). Programs which use '\n' for end-of-line
|
|
88 (which includes all programs in K & R), will still work
|
|
89 properly.
|
|
90 </para></listitem>
|
|
91 </itemizedlist>
|
472
|
92 </section>
|
530
|
93
|
|
94 <section>
|
|
95 <title>Enhancements and Extensions</title>
|
|
96
|
|
97 <section>
|
|
98 <title>The <quote>Direct</quote> Storage Class</title>
|
|
99 <para>
|
629
|
100 The 6809 microprocessor instructions for accessing memory via
|
|
101 an index register or the stack pointer can be relatively short and
|
|
102 fast when they are used in C programs to access "auto" (function
|
|
103 local) variables or function arguments. The instructions for
|
|
104 accessing global variables are normally not so nice and must be four
|
|
105 bytes long and correspondingly slow. However, the 6809 has a nice
|
|
106 feature which helps considerably. Memory, anywhere in a single page
|
|
107 (256 byte block), may be accessed with fast, two byte instructions.
|
|
108 This is called the "direct page", and at any time its location is
|
|
109 specified by the contents of the "direct page register" within the
|
|
110 processor. The linkage editor sorts out where this could be, and
|
|
111 it need not concern the programmer, who only needs to specify for
|
|
112 the compiler which variables should be in the direct page to give
|
|
113 the maximum benefit in code size and execution speed.
|
|
114 </para>
|
|
115 <para>
|
|
116 To this end, a new storage class specifier is recognized by the
|
|
117 compiler. In the manner of K & R page 192, the sc-specifier list
|
|
118 is extended as follows:
|
|
119 <informaltable frame="none">
|
|
120 <tgroup cols="3">
|
|
121 <colspec colwidth="1.0in">
|
|
122 <colspec colwidth="1.0in">
|
|
123 <colspec colwidth="1.0in">
|
|
124 <tbody>
|
|
125 <row>
|
|
126 <entry>Sc-specifier:</entry>
|
|
127 <entry>auto</entry>
|
|
128 <entry></entry>
|
|
129 </row>
|
|
130 <row>
|
|
131 <entry></entry>
|
|
132 <entry>static</entry>
|
|
133 <entry></entry>
|
|
134 </row>
|
|
135 <row>
|
|
136 <entry></entry>
|
|
137 <entry>extern</entry>
|
|
138 <entry></entry>
|
|
139 </row>
|
|
140 <row>
|
|
141 <entry></entry>
|
|
142 <entry>register</entry>
|
|
143 <entry></entry>
|
|
144 </row>
|
|
145 <row>
|
|
146 <entry></entry>
|
|
147 <entry>typedef</entry>
|
|
148 <entry></entry>
|
|
149 </row>
|
|
150 <row>
|
|
151 <entry></entry>
|
|
152 <entry>direct</entry>
|
|
153 <entry>(extension)</entry>
|
|
154 </row>
|
|
155 <row>
|
|
156 <entry></entry>
|
|
157 <entry>extern direct</entry>
|
|
158 <entry>(extension)</entry>
|
|
159 </row>
|
|
160 <row>
|
|
161 <entry></entry>
|
|
162 <entry>static direct</entry>
|
|
163 <entry>(extension)</entry>
|
|
164 </row>
|
|
165 </tbody>
|
|
166 </tgroup>
|
|
167 </informaltable>
|
|
168 The new key word may be used in place of one of the other sc-specifiers,
|
|
169 and its effect is that the variable will be placed in
|
|
170 the direct page. "DIRECT" creates a global direct page variable.
|
|
171 "EXTERN DIRECT" references an EXTERNAL-type direct page variable;
|
|
172 and "STATIC DIRECT" creates a local direct page variable. These new
|
|
173 classed may not be used to declare function arguments. "Direct"
|
|
174 variables can be initialized but will, as with other variables not
|
|
175 explicitly initialized, have the value zero at the start of program
|
|
176 execution. 255 bytes are available in the direct page (the linker
|
|
177 requires one byte). If all the direct variables occupy less than the
|
|
178 full 255 bytes, the remaining global variables will occupy the
|
|
179 balance and memory above if necesary. If too many bytes or storage
|
|
180 are requested in the direct page, the linkage editor will report an
|
|
181 error, and the programmer will have to reduce the use of DIRECT-type
|
|
182 variables to fit the 256 bytes addressable by the 6809.
|
|
183 </para>
|
|
184 <para>
|
|
185 It should be kept in mind that "direct" is unique to this
|
|
186 compiler, and it may not be possible to transport programs written
|
|
187 using "direct" to other environments without modification.
|
530
|
188 </para>
|
|
189 </section>
|
|
190
|
|
191 <section>
|
|
192 <title>Embedded Assembly Language</title>
|
|
193 <para>
|
629
|
194 As versatile as C is, occasionally there are some things that
|
|
195 can only be done (or done at maximum speed) in assembly language.
|
|
196 The OS-9 C compiler permits user-supplied assebly-language
|
|
197 statements to be directly embedded in C source programs.
|
|
198 </para>
|
|
199 <para>
|
|
200 A line beginning with "#asm" switches the compiler into a mode
|
|
201 which passes all subsequent lines directly to the assembly-language
|
|
202 output, until a line beginning with "#endasm" is encountered.
|
|
203 "#endasm" switches the mode back to normal. Care should be
|
|
204 exercised when using this directive so that the correct code section
|
|
205 is adhered to. Normal code from the compiler is in the PSECT (code)
|
|
206 section. If your assembly code uses the VSECT (variable) section,
|
|
207 be sure to put a ENDSECT directive at the end to leave the state
|
|
208 correct for following compiler generated code.
|
530
|
209 </para>
|
|
210 </section>
|
|
211
|
|
212 <section>
|
|
213 <title>Control Character Escape Sequences</title>
|
|
214 <para>
|
629
|
215 The escape sequences for non-printing characters in character
|
|
216 constants and strings (see K & R page 181) are extended as follows:
|
|
217 <programlisting>
|
|
218 linefeed (LF): \l (lower case 'ell')
|
|
219 </programlisting>
|
|
220 This is to distinguish LF (hex 0A) from \n which on OS-9 is the same
|
|
221 as \r (hex 0D).
|
|
222 <programlisting>
|
|
223 bit patterns: \NNN (octal constant)
|
|
224 \dNNN (decimal constant)
|
|
225 \xNN (hexadecimal constant)
|
|
226 </programlisting>
|
|
227 For example, the following all have a value of 255 (decimal):
|
|
228 <programlisting>
|
|
229 \377 \xff \d255
|
|
230 </programlisting>
|
530
|
231 </para>
|
|
232 </section>
|
|
233 </section>
|
|
234
|
|
235 <section>
|
|
236 <title>Implementation-dependent Characteristics</title>
|
|
237 <para>
|
617
|
238 K & R frequently refer to characteristics of the C language
|
|
239 whose exact operations depend on the architacture and instruction
|
|
240 set of the computer actually used. This section contains specific
|
|
241 information regarding this version of C for the 6809 processor.
|
530
|
242 </para>
|
|
243
|
|
244 <section>
|
|
245 <title>Data Representation and Storage Requirements</title>
|
|
246 <para>
|
629
|
247 Each variable type requires a specific amount of memory for
|
|
248 storage. The sizes of the basic types in bytes are as follows:
|
|
249 </para>
|
|
250 <informaltable frame="none">
|
|
251 <tgroup cols="3">
|
|
252 <colspec colwidth="0.8in">
|
|
253 <colspec colwidth="0.4in">
|
|
254 <colspec colwidth="3.0in">
|
|
255 <thead>
|
|
256 <row>
|
|
257 <entry>Data Type</entry>
|
|
258 <entry>Size</entry>
|
|
259 <entry>Internal Representation</entry>
|
|
260 </row>
|
|
261 </thead>
|
|
262 <tbody>
|
|
263 <row>
|
|
264 <entry>CHAR</entry>
|
|
265 <entry>1</entry>
|
|
266 <entry>two's complement binary</entry>
|
|
267 </row>
|
|
268 <row>
|
|
269 <entry>INT</entry>
|
|
270 <entry>2</entry>
|
|
271 <entry>two's complement binary</entry>
|
|
272 </row>
|
|
273 <row>
|
|
274 <entry>UNSIGNED</entry>
|
|
275 <entry>2</entry>
|
|
276 <entry>unsigned binary</entry>
|
|
277 </row>
|
|
278 <row>
|
|
279 <entry>LONG</entry>
|
|
280 <entry>4</entry>
|
|
281 <entry>two's complement binary</entry>
|
|
282 </row>
|
|
283 <row>
|
|
284 <entry>FLOAT</entry>
|
|
285 <entry>4</entry>
|
|
286 <entry>binary floating point (see below)</entry>
|
|
287 </row>
|
|
288 <row>
|
|
289 <entry>DOUBLE</entry>
|
|
290 <entry>8</entry>
|
|
291 <entry>binary floating point (see below)</entry>
|
|
292 </row>
|
|
293 </tbody>
|
|
294 </tgroup>
|
|
295 </informaltable>
|
|
296 <para>
|
|
297 This compiler follows the PDP-1 implementation and format in
|
|
298 that CHARs are converted to INTs by sign extension, "SHORT" or
|
|
299 "SHORT INT" means INT, "LONG INT" means LONG and "LONG FLOAT" means
|
|
300 DOUBLE. The format for DOUBLE values is as follows:
|
|
301 </para>
|
|
302 <screen>
|
|
303 (low byte) (high byte)
|
|
304 +-+---------------------------------------+----------+
|
|
305 ! ! seven byte ! !
|
|
306 ! ! mantissa ! !
|
|
307 +-+---------------------------------------+----------+
|
|
308 ^ sign bit
|
|
309 </screen>
|
|
310 <para>
|
|
311 The for of the mantissa is sign and magnitude with an implied
|
|
312 "1" bit at the sign bit position. The exponent is biased by 128.
|
|
313 The format of a FLOAT is identical, except that the mantissa is only
|
|
314 three bytes long. Conversion from DOUBLE to FLOAT is carried out by
|
|
315 truncating the least significant (right-most) four bytes of the
|
|
316 mantissa. The reverse conversion is done by padding the least
|
|
317 significant four mantissa bytes with zeros.
|
530
|
318 </para>
|
|
319 </section>
|
|
320
|
|
321 <section>
|
|
322 <title>Register Variables</title>
|
|
323 <para>
|
629
|
324 One register variable may be declared in each function. The
|
|
325 only types permitted for register variables are int, unsigned and
|
|
326 pointer. Invalid register variable declarations are ignored; i.e.
|
|
327 the storage class is made auto. For further details see K & R page 81.
|
|
328 </para>
|
|
329 <para>
|
|
330 A considerable saving in code size and speed can be made by
|
|
331 judicious use of a register variable. The most efficient use is
|
|
332 made of it for a pointer or a counter for a loop. However, if a
|
|
333 register variable is used for a complex arithmetic expression, there
|
|
334 is no saving. The "U" register is assigned to register variables.
|
530
|
335 </para>
|
|
336 </section>
|
|
337
|
|
338 <section>
|
|
339 <title>Access To Command Line Parameters</title>
|
|
340 <para>
|
609
|
341 The standard C arguments "argc" and "argv" are available to
|
|
342 "main" as described in K & R page 110. The start-up routine for C
|
|
343 programs ensures that the parameter string passed to it by the
|
|
344 parent process is converted into null-terminated strings as expected
|
|
345 by the program. In addition, it will run together as a single
|
|
346 argument any strings enclosed between single or double quotes ("'" or '"').
|
|
347 If either is part of the string required, then the other
|
|
348 should be used as a delimiter.
|
530
|
349 </para>
|
|
350 </section>
|
|
351 </section>
|
|
352
|
|
353 <section>
|
|
354 <title>System Calls and the Standard Library</title>
|
|
355
|
|
356 <section>
|
|
357 <title>Operating System Calls</title>
|
|
358 <para>
|
629
|
359 The system interface supports almost all the system calls of
|
|
360 both OS-9 and UNIX. In order to facilitate the portability of
|
|
361 programs from UNIX, some of the calls use UNIX names rather than
|
|
362 OS-9 names for the same function. There are a few UNIX calls that
|
|
363 do not have exactly equivalent OS-9 calls. In these cases, the
|
|
364 library function simulates the function of the corresponding UNIX
|
|
365 call. In cases where there are OS-9 calls that do not have UNIX
|
|
366 equivalents, the OS-9 names are used. Details of the calls and a
|
|
367 name cross-reference are provided in the "C System Calls" section of
|
|
368 this manual.
|
530
|
369 </para>
|
|
370 </section>
|
|
371
|
|
372 <section>
|
|
373 <title>The Standard Library</title>
|
|
374 <para>
|
629
|
375 The C compiler includes a very complete library of standard
|
|
376 functions. It is essential for any program which uses functions
|
|
377 from the standard library to have the statement:
|
|
378 <programlisting>
|
|
379 "#include <stdio.h>
|
|
380 </programlisting>
|
|
381 See the "C Standard Library" section of this manual for details on
|
|
382 the standard library functions provided.
|
|
383 </para>
|
|
384 <para>
|
|
385 IMPORTANT NOTE: If output via printf(), fprintf() or sprintf() of
|
|
386 long integers is required, the program MUST call "pflinit()" at some
|
|
387 point; this is necessary so that programs not involving LONGS do not
|
|
388 have the extra LONGs output code appended. Similarly, if FLOATs or
|
|
389 DOUBLEs are to be printed, "pffinit()" MUST be called. These functions
|
|
390 do nothing; existence of calls to them in a program informs
|
|
391 the linker that the relevant routines are also needed.
|
530
|
392 </para>
|
|
393 </section>
|
|
394 </section>
|
|
395
|
|
396 <section>
|
|
397 <title>Run-time Arithmetic Error Handling</title>
|
|
398 <para>
|
629
|
399 K & R leave the treatment of various arithmetic errors open,
|
|
400 merely saying that it is machine dependent. This implementation
|
|
401 deal with a limited number of error conditions in a special way; it
|
|
402 should be assumed that the results of other possible errors are
|
|
403 undefined.
|
|
404 </para>
|
|
405 <para>
|
|
406 Three new system error numbers are defined in <errno.h>:
|
|
407 <programlisting>
|
|
408 #define EFPOVR 40 /* floating point overflow of underflow */
|
|
409 #define EDIVERR 41 /* division by zero */
|
|
410 #define EINTERR 42 /* overflow on conversion of floating point
|
|
411 to long integer */
|
|
412 </programlisting>
|
|
413 </para>
|
|
414 <para>
|
|
415 If one of these conditions occur, the program will send a
|
|
416 signal to itself with the value of one of these errors. If not
|
|
417 caught or ignored, the will cause termination of program with
|
|
418 an error return to the parent process. However, the program can
|
|
419 catch the interrupt using "signal()" or "intercept()" (see C System
|
|
420 Calls), and in this case the service routine has the error number as
|
|
421 its argument.
|
530
|
422 </para>
|
|
423 </section>
|
|
424
|
|
425 <section>
|
|
426 <title>Achieving Maximum Program Performance</title>
|
|
427
|
|
428 <section>
|
|
429 <title>Programming Considerations</title>
|
|
430 <para>
|
617
|
431 Because the 6809 is an 8/16 bit microprocessor, the compiler
|
|
432 can generate efficient code for 8 and 16 bit objects (CHARs, INTs,
|
|
433 etc.). However, code for 32 and 64 bit values (LONGs, FLOATs,
|
|
434 DOUBLEs) can be at least four times longer and slower. Therefore
|
|
435 don't use LONG, FLOAT, or DOUBLE where INT or UNSIGNED will do.
|
|
436 </para>
|
|
437 <para>
|
|
438 The compiler can perform extensive evaluation of constant
|
|
439 expressions provided they involve only constants of type CHAR, INT,
|
|
440 and UNSIGNED. There is no constant expression evaluation at
|
|
441 compile-time (except single constants and "casts" of them) where
|
|
442 there are constants of type LONG, FLOAT, or DOUBLE, therefore,
|
|
443 complex constant expressions involving these types are evaluated at
|
|
444 run time by the compiled program. You should manually compute the
|
|
445 value of constant expressions of these types if speed is essential.
|
530
|
446 </para>
|
|
447 </section>
|
|
448
|
|
449 <section>
|
|
450 <title>The Optimizer Pass</title>
|
|
451 <para>
|
629
|
452 The optimizer pass automatically occurs after the compilation
|
|
453 passes. It reads the assembler source code text and removes
|
|
454 redundant code and searches for code sequences that can be replaced
|
|
455 by shorter and faster equivalents. The optimizer will shorten object
|
|
456 code by about 11% with a significant increase in program execution
|
|
457 speed. The optimizer is recommended for production versions of
|
|
458 debugged programs. Because this pass takes additional time, the "-O"
|
|
459 compiler option can be used to inhibit it during error-checking-only
|
|
460 compilations.
|
530
|
461 </para>
|
|
462 </section>
|
|
463
|
|
464 <section>
|
|
465 <title>The Profiler</title>
|
|
466 <para>
|
629
|
467 The profiler is an optional method used to determine the
|
|
468 frequency of execution of each function in a C program. It allows
|
|
469 you to identify the most-frequently used functions where algorithmic
|
|
470 or C source code programming improvements will yield the greatest
|
|
471 gains.
|
|
472 </para>
|
|
473 <para>
|
|
474 When the "-P" compiler option is selected, code is generated at
|
|
475 the beginning of each function to call the profiler module (called
|
|
476 "_prof"), which counts invocations of each function during program
|
|
477 execution. When the program has terminated, the profiler
|
|
478 automatically prints a list of all functions and the number of times
|
|
479 each was called. The profiler slightly reduces program execution
|
|
480 speed. See "prof.c" source for more information.
|
530
|
481 </para>
|
|
482 </section>
|
|
483 </section>
|
|
484
|
|
485 <section>
|
|
486 <title>C Compiler Component Files and File Usage</title>
|
|
487 <para>
|
629
|
488 Compilation of a C program by cc requires that the following
|
|
489 files be present in the current execution directory (CMDS).
|
|
490 </para>
|
|
491
|
|
492 <table frame="none">
|
|
493 <title>OS-9 Level I Systems</title>
|
|
494 <tgroup cols="2">
|
|
495 <colspec colwidth="1.0in">
|
|
496 <colspec colwidth="3.0in">
|
|
497 <tbody>
|
|
498 <row>
|
|
499 <entry>cc1</entry>
|
|
500 <entry>compiler executive program</entry>
|
|
501 </row>
|
|
502 <row>
|
|
503 <entry>c.prep</entry>
|
|
504 <entry>macro pre-processor</entry>
|
|
505 </row>
|
|
506 <row>
|
|
507 <entry>c.pass1</entry>
|
|
508 <entry>compiler pass 1</entry>
|
|
509 </row>
|
|
510 <row>
|
|
511 <entry>c.pass2</entry>
|
|
512 <entry>compiler pass 2</entry>
|
|
513 </row>
|
|
514 <row>
|
|
515 <entry>c.opt</entry>
|
|
516 <entry>assembly code optimizer</entry>
|
|
517 </row>
|
|
518 <row>
|
|
519 <entry>c.asm</entry>
|
|
520 <entry>relocating assembler</entry>
|
|
521 </row>
|
|
522 <row>
|
|
523 <entry>c.link</entry>
|
|
524 <entry>linkage editor</entry>
|
|
525 </row>
|
|
526 </tbody>
|
|
527 </tgroup>
|
|
528 </table>
|
|
529
|
|
530
|
|
531 <table frame="none">
|
|
532 <title>OS-9 Level II Systems</title>
|
|
533 <tgroup cols="2">
|
|
534 <colspec colwidth="1.0in">
|
|
535 <colspec colwidth="3.0in">
|
|
536 <tbody>
|
|
537 <row>
|
|
538 <entry>cc2</entry>
|
|
539 <entry>compiler executive program</entry>
|
|
540 </row>
|
|
541 <row>
|
|
542 <entry>c.prep</entry>
|
|
543 <entry>macro pre-processor</entry>
|
|
544 </row>
|
|
545 <row>
|
|
546 <entry>c.comp</entry>
|
|
547 <entry>compiler proper</entry>
|
|
548 </row>
|
|
549 <row>
|
|
550 <entry>c.opt</entry>
|
|
551 <entry>assembly code optimizer</entry>
|
|
552 </row>
|
|
553 <row>
|
|
554 <entry>c.asm</entry>
|
|
555 <entry>relocating assembler</entry>
|
|
556 </row>
|
|
557 <row>
|
|
558 <entry>c.link</entry>
|
|
559 <entry>linkage editor</entry>
|
|
560 </row>
|
|
561 </tbody>
|
|
562 </tgroup>
|
|
563 </table>
|
|
564 <para>
|
|
565 In addition a file called "clib.l" contains the standard library,
|
|
566 math functions, and systems library. The file "cstart.r" is
|
|
567 the setup code for compiled programs. Both of these files must be
|
|
568 located in a directory named "LIB" on the system's default mass
|
|
569 storage device, which is specified in the OS-9 "INIT" module and is
|
|
570 usually the disk drive the system is booted from.
|
|
571 </para>
|
|
572 <para>
|
|
573 If, when specifying "#include" files for the pre-processor to
|
|
574 read in, the programmer uses angle brackets, "<" and ">", instead of
|
|
575 parentheses, the file will be sought starting at the "DEFS"
|
|
576 directory on whichever drive is the default system drive for the
|
|
577 system running.
|
530
|
578 </para>
|
|
579
|
|
580 <section>
|
|
581 <title>Temporary Files</title>
|
|
582 <para>
|
629
|
583 A number of temporary files are created in the current data
|
|
584 directory during compilation, and it is important to ensure that
|
|
585 enough space is available on the disk drive. As a rough guide, at
|
|
586 least three times the number of blocks in the largest source file
|
|
587 (and its included files) should be free.
|
|
588 </para>
|
|
589 <para>
|
|
590 The identifiers "etext", "edata", and "end" are predefined in the
|
|
591 linkage editor and may be used to establish the addresses of the end
|
|
592 of executable text, initialized data, and uninitialized data
|
|
593 respectively.
|
530
|
594 </para>
|
|
595 </section>
|
|
596 </section>
|
|
597
|
|
598 <section>
|
|
599 <title>Running the Compiler</title>
|
|
600 <para>
|
629
|
601 The are two commands which inlvoke distinct versions of the
|
|
602 compiler. "cc1" is for OS-9 Level I which uses a two pass compiler,
|
|
603 and, "cc2" is for Level II which causes a single pass version. Both
|
|
604 versions of the compiler works identically, the main difference is
|
|
605 that cc1 has been divided into two passes to fit the smaller memory
|
|
606 size of OS-9 Level I systems. In the following text, "cc" refers to
|
|
607 either "cc1" or "cc2" as appropiate for your system. The syntax of
|
|
608 the command line which calls the compiler is:
|
|
609 </para>
|
|
610 <cmdsynopsis>
|
|
611 <command>cc</command>
|
|
612 <arg>option-flags</arg>
|
|
613 <arg rep="repeat" choice="plain"><replaceable>file</replaceable></arg>
|
|
614 </cmdsynopsis>
|
|
615 <para>
|
|
616 One file at a time can be compiled, or a number of files may be
|
|
617 compiled together. The compiler manages the compilation up
|
|
618 to four stages: pre-processor, compilation to assembler code,
|
|
619 assembly to relocatable code, and linking to binary executable
|
|
620 code (in OS-9 memory module format).
|
|
621 </para>
|
|
622 <para>
|
|
623 The compiler accepts three types of source files, provided each
|
|
624 name on the command line has the relevant postfix as shown below.
|
|
625 Any of the above file types may be mixed on the command line.
|
|
626 </para>
|
|
627 <table frame="none">
|
|
628 <title>File Name Suffix Conventions</title>
|
631
|
629 <tgroup cols="2">
|
629
|
630 <colspec colwidth="0.5in">
|
|
631 <colspec colwidth="3.0in">
|
|
632 <thead>
|
|
633 <row>
|
|
634 <entry>Suffix</entry>
|
|
635 <entry>Usage</entry>
|
|
636 </row>
|
|
637 </thead>
|
|
638 <tbody>
|
|
639 <row>
|
|
640 <entry>.c</entry>
|
|
641 <entry>C source file</entry>
|
|
642 </row>
|
|
643 <row>
|
|
644 <entry>.a</entry>
|
|
645 <entry>assembly language source file</entry>
|
|
646 </row>
|
|
647 <row>
|
|
648 <entry>.r</entry>
|
|
649 <entry>relocatable module</entry>
|
|
650 </row>
|
|
651 <row>
|
|
652 <entry>none</entry>
|
|
653 <entry>executable binary (OS-9 memory module)</entry>
|
|
654 </row>
|
|
655 </tbody>
|
|
656 </tgroup>
|
|
657 </table>
|
|
658 <para>
|
|
659 There are two modes of operation: multible source file and
|
|
660 single source file. The compiler selects the mode by inspecting
|
|
661 the command line. The usual mode is single source and is specified
|
|
662 by having only one source file name on the command line. Of
|
|
663 course, more than one source file may be compiled together by using
|
|
664 the "#include" facility in the source code. In this mode, the
|
|
665 compiler will use the name obtained by removing the postfix from the
|
|
666 name supplied on the command line, and the output file (and the
|
|
667 memory module produced) will have this name. For example:
|
|
668 <screen>
|
|
669 cc prg.c
|
|
670 </screen>
|
|
671 will leave an executable file called "prg" in the current execution
|
|
672 directory.
|
|
673 </para>
|
|
674 <para>
|
|
675 The multiple source mode is specified by having more than one
|
|
676 source file name on the command line. In this mode, the object code
|
|
677 output file will have the name "output" in the current execution
|
|
678 directory, unless a name is given using the "-f=" option (see
|
|
679 below). Also, in multiple source mode, the relocatable modules
|
|
680 generated as intermediate files will be left in the same directories
|
|
681 as their corresponding source files with the postfixes changed to
|
|
682 ".r". For example:
|
|
683 <screen>
|
|
684 cc prg1.c /d0/fred/prg2.c
|
|
685 </screen>
|
|
686 will leave an executable file called "output" in the current
|
|
687 execution directory, one file called "prg1.r" in the current data
|
|
688 directory, and "prg2.r" in "/d0/fred".
|
530
|
689 </para>
|
|
690 </section>
|
|
691
|
472
|
692 <section>
|
|
693 <title>Compiler Option Flags</title>
|
|
694 <para>
|
|
695 The compiler recognizes several command-line option flags which
|
|
696 modify the compilation process where needed. All flags are
|
|
697 recognized before compilation commences so the flags may be placed
|
|
698 anywhere on the command line. Flags may be ran together as in "-ro",
|
|
699 except where a flag is followed by something else; see "-f=" and
|
|
700 "-d" for examples.
|
|
701 </para>
|
|
702 <para>
|
|
703 -A
|
|
704 suppresses assembly, leaving the output as assembler code in a
|
|
705 file whose name is postfixed ".a".
|
|
706 </para>
|
|
707 <para>
|
|
708 -E=<number>
|
|
709 Set the edition number constant byte to the number given. This is
|
|
710 an OS-9 convention for memory modules.
|
|
711 </para>
|
|
712 <para>
|
|
713 -O
|
|
714 inhibits the assembly code optimizer pass. The optimizer will
|
|
715 shorten object code by about 11% with a comparable increase in speed
|
|
716 and is recommended for production versions of de-bugged programs.
|
|
717 </para>
|
|
718 <para>
|
|
719 -P
|
|
720 invokes the profiler to generate function frequency
|
|
721 statistics after program execution.
|
|
722 </para>
|
|
723 <para>
|
|
724 -R
|
|
725 suppresses linking library modules into an executable program.
|
|
726 Outputs are left in files with postfixes ".r".
|
|
727 </para>
|
|
728 <para>
|
|
729 -M=<memory size>
|
|
730 will instruct the linker to allocate <memory size>
|
|
731 for data, stack, and parameter area. Memory size may be expressed
|
|
732 in pages (an integer) or in kilobytes by appending "k" to an
|
|
733 integer. For more details of the use of this option, see the
|
|
734 "Memory Management" section of this manual.
|
|
735 </para>
|
|
736 <para>
|
|
737 -L=<filename>
|
|
738 specifies a library to be searched by the linker
|
|
739 before the Standard Library and system interface.
|
|
740 </para>
|
|
741 <para>
|
|
742 -F=<path>
|
|
743 overrides the above output file naming. The output file
|
|
744 will be left with <filename> as its name. This flag does not make
|
|
745 sense in multiple source mode, and either the -a or -r flag is also
|
|
746 present. The module will be called the last name in <path>.
|
|
747 </para>
|
|
748 <para>
|
|
749 -C
|
|
750 will output the source code as comments with the assembler code.
|
|
751 </para>
|
|
752 <para>
|
|
753 -S
|
|
754 stops the generation of stack-checking code. -S should only be
|
|
755 used with great care when the appication is extremely time-critical
|
|
756 and when the use of the stack by compiler generated code is fully
|
|
757 understood.
|
|
758 </para>
|
|
759 <para>
|
|
760 -D<identifier>
|
|
761 is equivalent to "#define <identifier>" written in
|
|
762 the source file. -D is useful where different versions of a program
|
|
763 are maintained in one source file and differentiated by means of the
|
|
764 "#ifdef" of "#ifndef" pre-processor directives. If the <identifier>
|
|
765 is used as a macro for expansion by the pre-processor, "1"(one) will
|
|
766 be the expanded "value" unless the form "-d<identifier>=<string>" is
|
|
767 used in which case the expansion will be <string>.
|
|
768 </para>
|
|
769 <table frame="none">
|
|
770 <title>Command Line and Option Flag Examples</title>
|
|
771 <tgroup cols="3">
|
|
772 <colspec colwidth="1.5in" colname="c1">
|
|
773 <colspec colwidth="1.5in" colname="c2">
|
|
774 <colspec colwidth="1.5in" colname="c3">
|
|
775 <thead>
|
|
776 <row>
|
|
777 <entry>command line</entry>
|
|
778 <entry>action</entry>
|
|
779 <entry>output file(s)</entry>
|
|
780 </row>
|
|
781 </thead>
|
|
782 <tbody>
|
|
783 <row>
|
|
784 <entry>cc prg.c</entry>
|
|
785 <entry>compile to an executable program</entry>
|
|
786 <entry>prg</entry>
|
|
787 <entry></entry>
|
|
788 </row>
|
|
789 <row>
|
|
790 <entry>cc prg.c -a</entry>
|
|
791 <entry>compile to assembly language source code</entry>
|
|
792 <entry>prg.a</entry>
|
|
793 </row>
|
|
794 <row>
|
|
795 <entry>cc prg.c -r</entry>
|
|
796 <entry>compile to relocatable module</entry>
|
|
797 <entry>prg.r</entry>
|
|
798 </row>
|
|
799 <row>
|
|
800 <entry>cc prg1.c prg2.c prg3.c</entry>
|
|
801 <entry>compile to executable program</entry>
|
|
802 <entry>prg1.r, prg2.r, prg3.r, output</entry>
|
|
803 </row>
|
|
804 <row>
|
|
805 <entry>cc prg1.c prg2.a prg3.r</entry>
|
|
806 <entry>compile prg1.c, assemble prg2.a and combine all into
|
|
807 and executable program</entry>
|
|
808 <entry>prg1.r, prg2.r</entry>
|
|
809 </row>
|
|
810 <row>
|
|
811 <entry>cc prg1.c prg2.c -a</entry>
|
|
812 <entry>compile to assembly language source code</entry>
|
|
813 <entry>prg1.a, prg2.a</entry>
|
|
814 </row>
|
|
815 <row>
|
|
816 <entry>cc prg1.c prg2.c -f=prg</entry>
|
|
817 <entry>compile to executable program</entry>
|
|
818 <entry>prg</entry>
|
|
819 </row>
|
|
820 </tbody>
|
|
821 </tgroup>
|
|
822 </table>
|
|
823
|
466
|
824 </section>
|
|
825 </chapter>
|