Added FloattextObject from originally code submission which shows that text does...
[AROS.git] / tools / fd2inline / fd2inline.texi
blobbe9b39788b06630a02edb93f1f67746f12d3f746
1 \input texinfo.tex  @c -*-texinfo-*-
2 @c %**start of header
3 @setfilename fd2inline.info
4 @settitle FD2InLine User's Guide
5 @set lastupdate March 22nd, 1998
6 @include version.texi
7 @c %**end of header
9 @dircategory GeekGadgets programming tools
10 @direntry
11 * FD2Inline: (fd2inline).        Creates @samp{GNU CC} @samp{inlines}.
12 @end direntry
13                               
14 @ifinfo
15 This is a user's guide to FD2Inline @value{version}, a parser
16 converting FD files to GCC ``inlines''.
18 Copyright @copyright{} 1996, 1997, 1998 Kamil Iskra
19 Copyright @copyright{} 1999 - 2003 Martin Blom
20 Copyright @copyritht{} 2010 AROS development team
22 Permission is granted to make and distribute verbatim copies of this
23 manual provided the copyright notice and this permission notice are
24 preserved on all copies.
25 @end ifinfo
27 @titlepage
28 @sp 10
29 @center @titlefont{FD2InLine}
30 @subtitle User's Guide to FD2InLine parser
31 @subtitle @value{lastupdate}
32 @author Kamil Iskra
33 @page
34 @end titlepage
36 @ifinfo
37 @node Top, Introduction, (dir), (dir)
38 This is a user's guide to @samp{FD2Inline} @value{version}, a parser
39 that converts the AmigaOS and p.OS shared library @samp{FD} files to
40 format accepted by the @samp{GNU CC}.
42 See file @file{COPYING} for the GNU General Public License.
44 Last updated @value{lastupdate}.
45 @end ifinfo
47 @menu
48 * Introduction::  What is this program for?
49 * Installation::  How to install it?
50 * Usage::         How to use @samp{inlines} and @samp{FD2InLine}?
51 * Rebuilding::    How to recompile it?
52 * Internals::     How do @samp{inlines} work?
53 * History::       What has changed?
54 * Authors::       Who wrote it?
56 * Index::         Concept index.
57 @end menu
59 @node Introduction, Installation, Top, Top
60 @chapter Introduction
61 @cindex Introduction
62 @cindex What FD2InLine is
64 @samp{FD2InLine} is useful if you want to use @samp{GCC} for AmigaOS
65 and p.OS specific development and would like to call the functions in
66 the shared libraries efficiently.
68 The format of calls to the AmigaOS shared library functions differs
69 substantially from the default function call format of C compilers
70 (@pxref{Background}). Therefore, some tricks are necessary if you want
71 to use these functions.
73 The format of calls used in the current development versions of p.OS
74 is much more similar to the call format of C compilers
75 (@pxref{Internals}), nevertheless some tricks are still necessary.
77 @samp{FD2InLine} is a parser that converts @samp{fd} files and
78 @samp{clib} files to @samp{GCC inlines}.
80 @samp{fd} and @samp{clib} files contain information about functions in
81 shared libraries (@pxref{Background}).
83 @samp{FD2InLine} reads these two files and merges the information
84 contained therein, producing an output file suitable for use with the
85 @samp{GCC} compiler.
87 This output file contains so-called @dfn{inlines} --- one for each
88 function entry. Using them, @samp{GCC} can produce very efficient code
89 for making function calls to the AmigaOS and p.OS shared libraries.
91 @quotation
92 @emph{Note:} the term @samp{inlines} is misleading ---
93 @samp{FD2InLine} no longer uses the @code{__inline} feature of
94 @samp{GCC} (@pxref{New format}).
95 @end quotation
97 @node Installation, Usage, Introduction, Top
98 @chapter Installation
99 @cindex Installation
100 @cindex Where to put it
102 The following assumes you have the
103 @file{fd2inline-@value{version}-bin.lha} archive.
105 If you use a recent release of @samp{GCC}, you might not need to
106 install anything. Starting with @samp{GCC} 2.7.2, the new format
107 (@pxref{New format}) of @samp{inlines} should be available with the
108 compiler. However, the separate
109 @file{fd2inline-@value{version}-bin.lha} archive will always contain
110 the latest version of @samp{FD2InLine} and the @samp{inlines}, which
111 might not be the true for the @samp{GeekGadgets} or @samp{Aminet}
112 distributions. @samp{GeekGadgets} distribution might not contain some
113 of the supported 3rd party libraries' @samp{inlines}.
115 The installation is very easy, so there is no Installer script :-).
117 If you have an older version of the @samp{inlines} installed, please
118 remove it now, or you might encounter problems later. Typically, you
119 will have to remove the following subdirectories of the
120 @file{os-include} directory: @file{inline}, @file{pragmas} and
121 @file{proto}.
123 Next, please change your current directory to @file{GG:} (or
124 @file{ADE:} or @file{GNU:}, if you use older distributions) and simply
125 unpack the @file{fd2inline-@value{version}-bin.lha} archive. This
126 should install everything in the right place. More precisely, the
127 headers will go to the @file{include} directory, the libraries to
128 @file{lib}, @file{fd2inline} executable to @file{bin} directory and
129 the @samp{AmigaGuide} documentation to the @file{guide} directory.
131 @node Usage, Rebuilding, Installation, Top
132 @chapter Usage
133 @cindex Usage
135 This chapter describes two aspects of using @samp{FD2InLine}:
137 @menu
138 * Using inlines::    Making efficient function calls.
139 * Using fd2inline::  Creating @samp{inlines}.
140 @end menu
142 @node Using inlines, Using fd2inline, Usage, Usage
143 @section Using inlines
144 @cindex Using inlines
145 @cindex Making efficient calls
147 @menu
148 * Using inlines under AmigaOS::
149 * Using inlines under p.OS::
150 @end menu
152 @node Using inlines under AmigaOS, Using inlines under p.OS, Using inlines, Using inlines
153 @subsection Using inlines under AmigaOS
154 @cindex Using inlines under AmigaOS
156 Using @samp{inlines} under AmigaOS is very simple. If you want to use
157 a library called @samp{foo.library} (or a device called
158 @samp{bar.device}), simply include file @samp{<proto/foo.h>}
159 (@samp{<proto/bar.h>}) and that's it. For example:
161 @example
162 #include <proto/dos.h>
164 int main(void)
166    Delay(100); /* Wait for 2 seconds */
168 @end example
170 Please @emph{always} include @file{proto} files, @emph{not}
171 @file{inline} files --- @file{proto} files often fix some
172 incompatibilities between system headers and @samp{GCC}. Besides, this
173 technique makes your code more portable across various AmigaOS
174 @samp{C} compilers.
176 @cindex Preprocessor symbols under AmigaOS
177 There are a few preprocessor symbols which alter the behaviour of the
178 @samp{proto} and @samp{inline} files:
180 @table @code
181 @item __NOLIBBASE__
182 By default, the @samp{proto} files make external declarations of the
183 library base pointers. You can disable this behaviour by defining
184 @code{__NOLIBBASE__} before including a @samp{proto} file.
186 @cindex __CONSTLIBBASEDECL__
187 @item __CONSTLIBBASEDECL__
188 The external declarations described above declare plain pointer
189 variables. The disadvantage of this is that the library base variable
190 has to be reloaded every time some function is called. If you define
191 @code{__CONSTLIBBASEDECL__} to @code{const}, less reloading will be
192 necessary, and better code will be produced. However, declaring a
193 variable as @code{const} makes altering it impossible, so some dirty
194 hacks are necessary (like defining the variable as plain in one file
195 and altering it only there. However, this will @emph{not} work with
196 base relative code).
198 @cindex <library>_BASE_NAME
199 @item <library>_BASE_NAME
200 Function definitions in the @samp{inline} files refer to the library
201 base variable through the @code{<library>_BASE_NAME} symbol (e.g.,
202 @code{AMIGAGUIDE_BASE_NAME} for @samp{amigaguide.library}). At the top
203 of the @samp{inline} file, this symbol is redefined to the appropriate
204 library base variable name (e.g., @code{AmigaGuideBase}),
205 @emph{unless} it has been already defined. This way, you can make the
206 @samp{inlines} use a field of a structure as a library base, for
207 example.
209 @item NO_INLINE_STDARG
210 This symbol prevents the definition of inline macros for varargs
211 functions (@pxref{Old format}).
213 @cindex _USEOLDEXEC_
214 @item _USEOLDEXEC_
215 This symbol is used only in @file{proto/exec.h}. Unlike @samp{SAS/C},
216 @file{proto/exec.h} uses the @code{SysBase} variable as the
217 @samp{Exec} library base by default. This is usually faster than
218 direct dereferencing of @code{0x00000004} (@pxref{Background}), since
219 it does not require reading from @samp{CHIP} memory (things might be
220 even worse if you use @samp{Enforcer} or @samp{CyberGuard}, which
221 protect the low memory region). However, in some low-level cases (like
222 startup code) you might prefer dereferencing @code{0x00000004}. To do
223 this, define @code{_USEOLDEXEC_} before including @file{proto/exec.h}.
225 @cindex __CLIB_TYPES__
226 @item __CLIB_TYPES__
227 By default, the @samp{stub} files just include the file
228 @file{inline/stubs.h>}, which defines some basic types and forward
229 declares a bunch of structures.  This works for most libraries, but it
230 is not enough some third party libraries and some libraries distributed
231 with AmigaOS 3.5 and later. If you define @code{__CLIB_TYPES__}, some
232 definitions from the clib file will be activated.
233 @end table
235 @node Using inlines under p.OS, , Using inlines under AmigaOS, Using inlines
236 @subsection Using inlines under p.OS
237 @cindex Using inlines under p.OS
239 Using @samp{inlines} under p.OS is just as simple as under AmigaOS.
240 The equivalent of the source presented in the previous section
241 (@pxref{Using inlines under AmigaOS}) would look like this:
243 @example
244 #include <pclib/pDos_protos.h>
246 int main(void)
248    pOS_DosDelay(100); /* Wait for 2 seconds */
250 @end example
252 One significant difference is that one should @emph{always} include
253 @file{pclib} files, not @file{pProto} files --- just opposite to
254 AmigaOS.
256 @cindex Preprocessor symbols under p.OS
257 There are two preprocessor symbols which alter the behaviour of the
258 @samp{pInline} files:
260 @table @code
261 @cindex __<library>_BASE_NAME
262 @item __<library>_BASE_NAME
263 Function definitions in the @samp{pInline} files refer to the library
264 base variable through the @code{__<library>_BASE_NAME} symbol (e.g.,
265 @code{__INTUI_BASE_NAME} for @samp{pintui.library}). At the top of the
266 @samp{pInline} file, this symbol is redefined to the appropriate
267 library base variable name (e.g., @code{gb_IntuiBase}), @emph{unless}
268 it has been already defined. This way, you can make the @samp{inlines}
269 use a field of a structure as a library base, for example.
271 @cindex __<library>_LIB_NAME
272 @item __<library>_LIB_NAME
273 This symbol is defined in the same way as the previous one, and it
274 serves similar purpose. @xref{p.OS format}, for more information.
275 @end table
277 @node Using fd2inline, , Using inlines, Usage
278 @section Using fd2inline
279 @cindex Using FD2Inline
280 @cindex Creating inlines
282 You invoke @samp{FD2InLine} by writing:
284 @example
285 @file{fd2inline} [options] @var{fd-file} @var{clib-file} [[-o] @var{output-file}]
286 @end example
288 The command line arguments have the following meaning:
290 @table @var
291 @item fd-file
292 The name of the input @samp{fd} file.
294 @item clib-file
295 The name of the input @samp{clib} file.
297 @item output-file
298 The name of the output @samp{inline} or @samp{proto}file. If it is not
299 specified (or if @samp{-} is specified), standard output will be used
300 instead. The file name can be preceded by a @samp{-o}, for
301 compatibility with most @samp{UN*X} software.
302 @end table
304 The following options can be specified (anywhere on the command line):
306 @table @samp
307 @item --new
308 Produce new format @samp{inlines}.
310 @item --old
311 Produce old format @samp{inlines}.
313 @item --stubs
314 Produce library stubs.
316 @item --proto
317 Produce @samp{proto} file. If this option is specified, providing
318 @samp{clib} file is not necessary. @samp{fd2inline} will only read
319 @samp{fd} file and will generate a @samp{proto} file, to be put in
320 @file{include/proto} directory.
322 @item --pos
323 Produce p.OS @samp{inlines}. This flag is now obsolete. Use the
324 @samp{--target} option instead.
326 @item --target=TARGET
327 Produce @samp{inlines} for the given target. Valid targets are:
328 @samp{m68k-amigaos}, @samp{m68k-pos}, @samp{ppc-powerup}
329 and @samp{ppc-morphos}.
331 @item --version
332 Print version information and exit.
333 @end table
335 @xref{Internals}, for more information.
337 Example:
339 @example
340 fd2inline GG:os-lib/fd/exec_lib.fd GG:os-include/clib/exec_protos.h -o GG:include/inline/exec.h
341 @end example
343 This will build file @file{exec.h} containing new format
344 @samp{inlines} of @samp{exec.library} in directory
345 @file{GG:include/inline}.
347 If you want to add support for @samp{GCC} to an AmigaOS library, there
348 are a few things you should remember about.
350 Sometimes, @samp{FD2InLine} might not know how to handle a function
351 found in a @samp{clib} file, if this function doesn't have a
352 corresponding entry in the @samp{fd} file. This is most often a case
353 of @samp{varargs} functions (@pxref{Background}), if they use
354 nonstandard naming convention. @samp{FD2InLine} will warn you if it
355 finds such a function. There is an array of such exceptions in
356 @samp{FD2InLine} source code. You should add the name of this function
357 there and send a patch to @samp{FD2InLine} maintainer
358 (@pxref{Authors}), for inclussion in the next release of
359 @samp{FD2InLine}.
361 @samp{FD2InLine} assumes that the type of the base variable is
362 @code{struct Library *}. If it is something different in your case,
363 you should extend an array of exceptions in @samp{FD2InLine} source
364 code (see above).
366 @samp{FD2InLine} handles @code{void} functions in a special way. It
367 recognizes them by the return value --- it has to be @code{void} (the
368 case is not significant). If a @samp{clib} file uses a different
369 convention, it has to be modified before running @samp{FD2InLine}.
371 In addition to creating @samp{inlines} you must also create a
372 @samp{proto} file.
374 The easiest way to do it is to call @samp{FD2InLine} with
375 @samp{--proto} option. Most often, the generated file will be ready to
376 use. Unfortunately, some libraries (like, for example,
377 @samp{dos.library}) have broken header files and @samp{GCC} generates
378 warning messages if you try to use them. To avoid these warnings, you
379 have to include various headers in the @samp{proto} file before
380 including the @samp{clib} file.
382 You might also want to create a @samp{pragmas} file, which might be
383 necessary for badly written @samp{SAS/C} sources. @file{pragmas} are
384 generated automatically during the building of @samp{FD2InLine} by an
385 @samp{AWK} script, so you might either have a look at the
386 @file{fd2inline-@value{version}-src.lha} archive, or simply create
387 @file{pragmas} file by hand.
389 Creating a linker library with stubs might also be useful, in case
390 somebody doesn't want to, or can't, use inline headers.
392 @file{fd2inline-@value{version}-src.lha} contains necessary support
393 for this. For example, to generate a library @file{libexec.a} with
394 @samp{exec.library} stubs, you should type:
396 @example
397 make alllib INCBASE=exec LIBBASE=exec
398 @end example
400 This will create three @file{libexec.a} libraries in @file{lib}
401 subdirectory: plain, base relative and 32-bit base relative one. Of
402 course, this particular example doesn't make much sense since
403 @file{libamiga.a} already contains these stubs.
405 @code{INCBASE} and @code{LIBBASE} specify the base names of the
406 (input) @samp{proto} and @samp{fd} files and the (output) library.
407 This will often be the same, but not always. For example, in the case
408 of @samp{MUI}, @code{INCBASE} has to be set to @code{muimaster}, but
409 @code{LIBBASE} should be set to @code{mui}.
411 @node Rebuilding, Internals, Usage, Top
412 @chapter Rebuilding
413 @cindex Rebuilding
415 First, you have to get the @file{fd2inline-@value{version}-src.lha}
416 archive.
418 Unarchive it. You might either build @samp{FD2InLine} in source
419 directory or in a separate, build directory. The latter is
420 recommended. Type:
422 @example
423 lha -mraxe x fd2inline-@value{version}-src.lha
424 mkdir fd2inline-bin
425 cd fd2inline-bin
426 sh ../fd2inline-@value{version}/configure --prefix=/gg
427 make
428 @end example
430 This should build the @samp{FD2InLine} executable, headers, libraries
431 and so on.
433 Please note that the @samp{fd} files should be available in one of the
434 standard locations. For the AmigaOS @samp{fd} files, this is one of:
435 @file{GG:os-lib/fd/amigaos}, @file{GG:os-lib/fd}, @file{FD:}. For p.OS
436 @samp{fd} files, this is one of @file{GG:os-lib/fd/pos},
437 @file{P:/pOS_FD}. The exact location is determined by the
438 @samp{configure} script. If it doesn't find the @samp{fd} files, it
439 will disable the @file{Makefile} rules that build the @samp{inlines}.
441 You can then type:
443 @example
444 make install
445 @end example
447 This will install @samp{fd2inline}, the @samp{inlines} and the
448 documentation in the appropriate subdirectories of @file{GG:}.
450 The @file{fd2inline-@value{version}-src.lha} archive contains four
451 patches in unified diff format, in directory @file{patches}. They fix
452 bugs in AmigaOS 3.1 headers and @samp{fd} files. Without applying
453 @file{amigaguide_lib.fd.diff} to @samp{amigaguide.library} @samp{fd}
454 file, the produced @samp{inlines} will be broken. Applying
455 @file{timer.h.diff} to @file{devices/timer.h} will prevent collision
456 with IXEmul's @file{sys/time.h}. Two other patches rename an argument
457 name from @code{true} to @code{tf}, since @code{true} is a reserved
458 word in @samp{C++}. Use @code{patch} to apply these patches, for
459 example:
461 @example
462 cd GG:os-lib/fd
463 patch amigaguide_lib.fd <amigaguide_lib.fd.diff
464 @end example
466 @samp{GeekGadgets} distribution contains more complete set of patches.
468 @cindex Source code
469 A few words about the source code:
471 I know, it's not state-of-the-art @samp{C} programming example.
472 However, believe me, it was in @emph{much} worse condition when I took
473 it over. In its current state it is at least readable (if you use tab
474 size 3, as I do :-). I think that rewriting it in @samp{C++} would
475 clean it up considerably (it's already written in @samp{OO} fashion,
476 so this should be quite easy). Using @code{flex} and @code{bison} to
477 create the parser would also be a nice thing, I guess. However, I
478 don't think it's worth the effort. But, if somebody wants to do it:
479 feel free, this is @samp{GNU} software, so everybody can modify it.
481 @node Internals, History, Rebuilding, Top
482 @chapter Internals
483 @cindex Internals
485 This chapter describes the implementation details of @samp{inlines}.
487 @menu
488 * Background::    Function calls in AmigaOS shared libraries.
489 * Old format::    Inlines that use @code{__inline}.
490 * New format::    Inlines that use the preprocessor.
491 * p.OS format::   Inlines used for p.OS.
492 * Stubs format::  Not really inlines, but...
493 @end menu
495 @node Background, Old format, Internals, Internals
496 @section Background
497 @cindex Background
498 @cindex Function calls format in AmigaOS shared libraries
500 This section describes the calling conventions used in the AmigaOS
501 shared libraries.
503 @cindex Libraries
504 User-callable functions in the AmigaOS are organized in
505 @dfn{libraries}.
507 @cindex Library base
508 @cindex Jump table
509 From our point of view, the most important part of a library is the
510 @dfn{library base}. It always resides in RAM and contains library
511 variables and a @dfn{jump table}. The location of the library base
512 varies. You can obtain the library base location of the main system
513 library --- @code{exec.library} --- by dereferencing
514 @code{0x00000004}. Locations of other library bases can be obtained
515 using the @code{OpenLibrary} function of @samp{exec.library}.
517 Without providing unnecessary details, every function in a library has
518 a fixed location in the library's jump table. To call a function, one
519 has to jump to this location.
521 @cindex Function arguments
522 Most functions require some arguments. In @samp{C}, these are usually
523 passed on the CPU stack. However, for some obscure reason, AmigaOS
524 system designers decided that arguments to shared libraries should be
525 passed in CPU registers.
527 @cindex FD files
528 All the information required to make library function calls is
529 provided in @dfn{fd} files. Every shared library should have such a
530 file. It provides the name a library base variable should have, the
531 offset in the jump table where each library function resides, and
532 information about which arguments should be passed in which registers.
534 @cindex CLIB files
535 In order to check if arguments passed to a function have the correct
536 type, the @samp{C} compiler requires function prototypes. These are
537 provided in @dfn{clib} files --- every library should have such a
538 file.
540 @cindex Varargs functions
541 Starting with the AmigaOS release 2.0, certain functions have been
542 provided which accept a variable number of arguments (so-called
543 @dfn{varargs functions}). Actually, these are only @samp{C} language
544 stubs. Internally, all optional arguments have to be put into an array
545 of @samp{long ints} and the address of this array must be passed to a
546 fixed args library function.
548 @cindex Linker libraries
549 To implement calls to shared library functions, compiler vendors have
550 to either use some compiler-dependent tricks to make these calls
551 directly (so-called @dfn{in line}), or provide linker libraries with
552 function stubs, usually written in assembler. In the latter case, a
553 function call from the user's code is compiled as usual --- arguments
554 are passed on the stack. Then, in the linking stage, a library stub
555 gets linked in. When this stub is called during program execution, it
556 moves the arguments from the stack to the appropriate registers and
557 jumps to the library jump table. Needless to say, this is slower than
558 making a call in line.
560 @node Old format, New format, Background, Internals
561 @section Old format
562 @cindex Old inlines format
564 @example
565 extern __inline APTR
566 OpenAmigaGuideA(BASE_PAR_DECL struct NewAmigaGuide *nag, struct TagItem *attrs)
568    BASE_EXT_DECL
569    register APTR res __asm("d0");
570    register struct Library *a6 __asm("a6") = BASE_NAME;
571    register struct NewAmigaGuide *a0 __asm("a0") = nag;
572    register struct TagItem *a1 __asm("a1") = attrs;
573    __asm volatile ("jsr a6@@(-0x36:W)"
574    : "=r" (res)
575    : "r" (a6), "r" (a0), "r" (a1)
576    : "d0", "d1", "a0", "a1", "cc", "memory");
577    return res;
579 @end example
581 In this implementation, the AmigaOS shared library function stubs are
582 external functions. They are defined as @code{__inline}, making
583 @samp{GCC} insert them at every place of call. The mysterious
584 @code{BASE_PAR_DECL} and @code{BASE_EXT_DECL} defines are hacks
585 necessary for local library base support (which is quite hard to
586 achieve, so it will not be described here). The biggest disadvantage
587 of these @samp{inlines} is that compilation becomes very slow,
588 requiring huge amounts of memory. Besides, inlining only works with
589 optimization enabled.
591 @example
592 #ifndef NO_INLINE_STDARG
593 #define OpenAmigaGuide(a0, tags...) \
594    (@{ULONG _tags[] = @{ tags @}; OpenAmigaGuideA((a0), (struct TagItem *)_tags);@})
595 #endif /* !NO_INLINE_STDARG */
596 @end example
598 @cindex Varargs problems
599 The source above shows how @samp{varargs} functions are implemented.
600 Handling them cannot be made using @code{__inline} functions, since
601 @code{__inline} functions require a fixed number of arguments.
602 Therefore, the unique features of the @samp{GCC} preprocessor (such as
603 @samp{varargs macros}) have to be used, instead. This has some
604 drawbacks, unfortunately. Since these are actually preprocessor macros
605 and not function calls, you cannot make tricky things involving the
606 preprocessor inside them. For example:
608 @example
609 #include <proto/amigaguide.h>
611 #define OPENAG_BEG OpenAmigaGuide(
612 #define OPENAG_END , TAG_DONE)
614 void f(void)
616    OPENAG_BEG "a_file.guide" OPENAG_END;
617    OpenAmigaGuide(
618 #ifdef ABC
619       "abc.guide",
620 #else
621       "def.guide",
622 #endif
623       TAG_DONE);
625 @end example
627 Neither of the above @code{OpenAmigaGuide()} calls is handled
628 correctly.
630 In the case of the first call, you get an error:
632 @example
633 unterminated macro call
634 @end example
636 By the time the preprocessor attempts to expand the
637 @code{OpenAmigaGuide} macro, @code{OPENAG_END} is not yet expanded, so
638 the preprocessor cannot find the closing bracket. This code might look
639 contrived, but @samp{MUI}, for example, defines such macros to make
640 code look more pretty.
642 In the case of the second call, you'll see:
644 @example
645 warning: preprocessing directive not recognized within macro arg
646 @end example
648 A workaround would be to either surround entire function calls with
649 conditions, or to conditionally define a preprocessor symbol
650 @code{GUIDE} somewhere above and simply put @code{GUIDE} as a function
651 argument:
653 @example
654 #ifdef ABC
655 #define GUIDE "abc.guide"
656 #else
657 #define GUIDE "def.guide"
658 #endif
660 void f(void)
662 #ifdef ABC
663    OpenAmigaGuide("abc.guide", TAG_DONE);
664 #else
665    OpenAmigaGuide("def.guide", TAG_DONE);
666 #endif
667    OpenAmigaGuide(GUIDE, TAG_DONE);
669 @end example
671 Another problem is that when you pass a pointer as an argument, you
672 get a warning:
674 @example
675 warning: initialization makes integer from pointer without a cast
676 @end example
678 This is because all optional arguments are put as initializers to an
679 array of @code{ULONG}. And, if you attempt to initialize an
680 @code{ULONG} with a pointer without a cast, you get a warning. You can
681 avoid it by explicit casting of all pointer arguments to @code{ULONG}.
683 Because of these drawbacks, @samp{varargs inlines} can be disabled by
684 defining @code{NO_INLINE_STDARG} before including a @samp{proto} file.
685 In such a case, you will need a library with function stubs.
687 @node New format, p.OS format, Old format, Internals
688 @section New format
689 @cindex New inlines format
691 @example
692 #define OpenAmigaGuideA(nag, attrs) \
693    LP2(0x36, APTR, OpenAmigaGuideA, struct NewAmigaGuide *, nag, a0, struct TagItem *, attrs, a1, \
694    , AMIGAGUIDE_BASE_NAME)
695 @end example
697 As you can see, this implementation is much more compact. The
698 @code{LP2} macro (and others) are defined in @file{inline/macros.h},
699 which is included at the beginning of every @samp{inline} file.
701 @example
702 #define LP2(offs, rt, name, t1, v1, r1, t2, v2, r2, bt, bn) \
703 (@{                                                     \
704    t1 _##name##_v1 = (v1);                              \
705    t2 _##name##_v2 = (v2);                              \
706    @{                                                   \
707       register rt _##name##_re __asm("d0");             \
708       register struct Library *const _##name##_bn __asm("a6") = (struct Library*)(bn);\
709       register t1 _n1 __asm(#r1) = _##name##_v1;        \
710       register t2 _n2 __asm(#r2) = _##name##_v2;        \
711       __asm volatile ("jsr a6@@(-"#offs":W)"            \
712       : "=r" (_##name##_re)                             \
713       : "r" (_##name##_bn), "r"(_n1), "r"(_n2)          \
714       : "d0", "d1", "a0", "a1", "cc", "memory");        \
715       _##name##_re;                                     \
716    @}                                                   \
718 @end example
720 If you compare this with the old @samp{inlines} (@pxref{Old format})
721 you will notice many similarities. Indeed, both implementations use
722 the same tricks. This means that there should be little, if any,
723 difference in code quality between old and new @samp{inlines}.
725 With the new @samp{inlines}, however, inlining is performed very
726 early, at the preprocessing stage. This makes compilation much faster,
727 less memory hungry, and independent of the optimization options used.
728 This also makes it very easy to use local library bases --- all that
729 is needed is to define a local variable with the same name as library
730 base.
732 Unfortunately, using the preprocessor instead of the compiler for
733 making function calls has its drawbacks, as described earlier
734 (@pxref{Old format}). There is not much you can do about it apart from
735 modifying your code.
737 Depending on the type of a function, @samp{FD2InLine} generates calls
738 to different @samp{LP} macros.
740 Macros are distinguished by one or more of the qualifiers described
741 below:
743 @table @samp
744 @item digit
745 As you may have already guessed, digit indicates the number of
746 arguments a function accepts. Therefore, it is mandatory.
748 @item NR
749 This indicates a ``no return'' (@code{void}) function.
751 @item A4, A5
752 These two are used when one of the arguments has to be in either the
753 @samp{a4} or @samp{a5} register. In certain situations, these
754 registers have special meaning and have to be handled more carefully.
756 @item UB
757 This indicates ``user base'' --- the library base pointer has to be
758 specified explicitly by the user. Currently, this is used for
759 @samp{cia.resource} only. Since there are two @samp{CIA} chips, the
760 programmer has to specify which one [s]he wants to use.
762 @item FP
763 This means that one of the arguments is of type ``pointer to a
764 function''. To overcome strange @samp{C} syntax rules in this case,
765 inside @samp{FP} macros a @code{typedef} to @code{__fpt} is performed.
766 The @samp{inline} file passes @code{__fpt} as the argument type to the
767 @samp{LP} macro. The actual type of the argument, in a form suitable
768 for a @code{typedef}, is passed as an additional, last argument.
769 @end table
771 As you can see, there could be more than a hundred different
772 variations of the @samp{LP} macros. @file{inline/macros.h} contains
773 only 35, which are used in the current OS version and supported 3rd
774 party libraries. More macros will be added in the future, if needed.
776 If you look carefully at the definition of @code{OpenAmigaGuideA} at
777 the beginning of this section, you might notice that the next to last
778 argument to the @samp{LP} macro is not used. New @samp{inlines} were
779 not implemented in one evening, and they went through many
780 modifications. This unused argument (which was once a type of library
781 base pointer) is provided for backwards compatibility. Actually, there
782 are more unnecessary arguments, like function and argument names, but
783 it was decided to leave them in peace.
785 @node p.OS format, Stubs format, New format, Internals
786 @section p.OS format
787 @cindex p.OS inlines format
788 @cindex Function calls format in p.OS shared libraries
790 p.OS uses a different calling convention than AmigaOS. The most
791 fundamental difference is that, despite the information contained in
792 the @samp{fd} files, the arguments are passed on the stack, not in the
793 CPU registers.
795 @example
796 #define pOS_AllocAudioMapA(channel, par2) \
797         __INLINE_FUN_2(__AUDIO_BASE_NAME, __AUDIO_LIB_NAME, 0x12c, __ARID__ struct pOS_AudioMap*, pOS_AllocAudioMapA, \
798         ULONG, channel, __INLINE_REG_D0, const struct pOS_TagItem*, par2, __INLINE_REG_A0)
799 @end example
801 As you can see, the p.OS @samp{inlines} format largely resembles the
802 new @samp{inlines} format (@pxref{New format}). The most important
803 difference is that all the preprocessor symbols are now prefixed with
804 two underscores @code{__}, in order to prevent user namespace
805 polution, as required by @samp{ANSI C}.
807 @example
808 #define __INLINE_FUN_2(__base, __lib, __offs, __type, __name, __type1, __name1, __reg1, __type2, __name2, __reg2) \
809 ((__type (*)(void*, __type1, __type2)) \
810 *(ULONG*)(((char*)__lib)-__offs))(__base, __name1, __name2)
811 @end example
813 The actual implementation is very simple: no @samp{GNU CC}-specific
814 features are used, every @samp{ANSI C}-compatible compiler should be
815 able to use this inlines format.
817 As you might have already noticed, the register names are passed, but
818 not used. As mentioned earlier in this section, p.OS does not pass the
819 arguments in registers. However, since it is not clear if it will
820 continue to do so, it was decided to pass this redundant information.
822 Another difference when compared to AmigaOS is that p.OS supports
823 library jump tables separated from the library bases. As of this
824 writing, this is only the case of @samp{pexec.library}, where the base
825 pointer is identified by @code{gb_ExecBase}, and the jump table by
826 @code{gb_ExecLib}, both of which are obtained form the
827 @code{gb_DosBase}, passed to every application invoked. For this
828 reason, p.OS @samp{inlines} provide two preprocessor symbols for
829 library identification (@pxref{Using inlines under p.OS}).
831 @node Stubs format, , p.OS format, Internals
832 @section Stubs format
833 @cindex Stubs inlines format
835 Stubs format is very similar to old format (@pxref{Old format}). The
836 functions are not defined as @code{extern}, however.
838 The main difference is the format of the @samp{varargs} functions ---
839 they are plain functions, not preprocessor macros.
841 @example
842 APTR OpenAmigaGuide(struct NewAmigaGuide *nag, int tag, ...)
844    return OpenAmigaGuideA(nag, (struct TagItem *)&tag);
846 @end example
848 This format is not suitable for inlining, and it is not provided for
849 this purpose. It is provided for the building of linker libraries with
850 stubs (@pxref{Using fd2inline}).
852 @node History, Authors, Internals, Top
853 @chapter History
854 @cindex History
855 @cindex What has changed
857 Version 1.37,  April 22:nd, 2003,  Martin Blom
858 @itemize @bullet
859 @item
860 Targets are now specified in such a way that canonical system
861 names (from config.sub) can be used, as well as the short names.
862 @item
863 Added some AROS support (old and stubs do not yet work).
864 @item
865 @samp{--gatestubs} now works for all targets.
866 @item
867 Added @samp{--gateproto}.
868 @item
869 Added @samp{--mode}, @samp{--gateprefix} and @samp{--libprefix}.
870 @end itemize
872 Version 1.36,  February 24:th, 2002,  Martin Blom
873 @itemize @bullet
874 @item
875 Added @samp{--gatestubs} for AmigaOS and MorphOS.
876 @end itemize
878 Version 1.35,  February 2nd, 2002,  Martin Blom
879 @itemize @bullet
880 @item
881 Modified @file{share/ix86be-amithlon/macros.h} to use _CallLib68k().
882 @item
883 When creating stubs or old-style inlines, the macros from
884 @file{inline/macros.h} are now used.
885 @end itemize
887 Version 1.34,  January 6th, 2002,  Martin Blom
888 @itemize @bullet
889 @item
890 Modified @file{share/ix86be-amithlon/macros.h} to use a variable length
891 array for the register structure. This reduces the stack usage
892 dramatically, since variable length arrays are deallocated when it goes
893 out of scope, not when the function returns. I also added a7 to the
894 register structure (it's not used when calling OS functions, though).
895 @end itemize
897 Version 1.33,  December 14th, 2001,  Martin Blom
898 @itemize @bullet
899 @item
900 The @samp{--stubs} option was broken (at least) for ix86be-amithlon and
901 ppc-morphos. In addition, it's now possible to define the preprocessor
902 macro @var{__CLIB_TYPES__} and get all includes and typedefs from the
903 clib file included.
904 @item
905 In order to avoid problems where a parameter name is the same as a typedef,
906 all parameters are now prefixed with three underscores.
907 @end itemize
909 Version 1.32,  December 1st, 2001,  Martin Blom
910 @itemize @bullet
911 @item
912 Inlines and @file{macros.h} for @samp{ix86be-amithlon} now include the
913 unused @var{bt} argument. It made it easier to port libnix that way
914 @enddots{}
915 @end itemize
917 Version 1.31,  October 14th, 2001,  Martin Blom
918 @itemize @bullet
919 @item
920 Added added the @samp{ix86be-amithlon} target.
921 @item
922 Added the varproto code from version 2.00.
923 @item
924 Added more compability options: --powerup and --morphos.
925 @end itemize
927 Version 1.30,  October 11th, 2001,  Martin Blom
928 @itemize @bullet
929 @item
930 Backported some of Ralphs and Emmanuels updates from
931 version 2.00 (the PowerUp and MorphOS support; @samp{--pragma} and
932 @samp{--gatestubs} are not included).
933 @item
934 Added @samp{--quiet}.
935 @item
936 Fixed tag calls declared @code{CONST struct TagItem *} instead of
937 just @code{const struct TagItem *}.
938 @end itemize
940 Version 1.21,  March 22nd, 1998,  Kamil Iskra
941 @itemize @bullet
942 @item
943 Fixed a bug in handling of prototypes where the argument name was the
944 same as the type name (Kamil Iskra, reported by Martin Hauner).
945 @end itemize
947 Version 1.2,  October 26th, 1997,  Kamil Iskra
948 @itemize @bullet
949 @item
950 Added @code{LP10} macro to @file{inline/macros.h}, needed by
951 CyberGraphics (Kriton Kyrimis).
952 @item
953 New version of @file{strsup.h} (Gunther Nikl).
954 @item
955 Integrated support for p.OS (Kamil Iskra).
956 @item
957 Replaced "r" constraints with "rf" in @file{inline/macros.h} to
958 support passing arguments in floating point registers. NOTE: full
959 support in @samp{FD2InLine} is not yet available (Kamil Iskra).
960 @item
961 Modified source structure so that rebuilding @samp{FD2InLine} does not
962 require having it already installed (Kamil Iskra).
963 @item
964 Added consistency checks to prevent @samp{FD2InLine} from crashing
965 when certain parsing errors occur (Kamil Iskra).
966 @end itemize
968 Version 1.11,  January 31st, 1997,  Kamil Iskra
969 @itemize @bullet
970 @item
971 Minor fixes in @file{Makefile.in} for @samp{ADE} tree (Fred Fish).
972 @item
973 Fixed handling of prototypes in which the argument name was the same
974 as the type name (Kamil Iskra, reported by Martin Recktenwald).
975 @item
976 Added support for building 32-bit base relative linker libraries
977 (Kamil Iskra).
978 @item
979 Added a paragraph about @code{void} functions (Kamil Iskra, suggested
980 by Martin Recktenwald).
981 @end itemize
983 Version 1.1,  October 24th, 1996,  Kamil Iskra
984 @itemize @bullet
985 @item
986 Removed a lot of language mistakes from the documentation (Kriton
987 Kyrimis).
988 @item
989 Inlines of @samp{dospath.library}, @samp{screennotify.library},
990 @samp{ums.library} and @samp{wbstart.library} integrated (Martin
991 Steigerwald).
992 @item
993 Inlines of @samp{muimaster.library} integrated (Kamil Iskra).
994 @item
995 Floating point registers @samp{fp0} and @samp{fp1} are now marked as
996 clobbered (Kamil Iskra, reported by Kriton Kyrimis).
997 @item
998 Improved handling of @samp{clib} files, particularly recognition of
999 function prototypes and varargs functions (Kamil Iskra).
1000 @item
1001 Added support for @samp{--proto} and @samp{--version} options. Minor
1002 changes in output file generators, most notably making @samp{proto}
1003 files work with other compilers than @samp{GCC}, too. Finalized
1004 support for building linker libraries (Kamil Iskra, change in
1005 @samp{proto} files suggested by Joop van de Wege).
1006 @end itemize
1008 Version 1.0,  July 14th, 1996,  Kamil Iskra
1009 @itemize @bullet
1010 @item
1011 First officially available version.
1012 @end itemize
1014 @node Authors, Index, History, Top
1015 @chapter Authors
1016 @cindex Authors
1017 @cindex Other parsers
1018 @cindex Reporting bugs
1019 @cindex Address
1020 @cindex Latest version
1022 The first parser for @samp{GCC inlines} was written in @samp{Perl} by
1023 Markus Wild.
1025 It had several limitations, which were apparently hard to fix in
1026 @samp{Perl}. This is why Wolfgang Baron decided to write a new parser
1027 in @samp{C}.
1029 For some reason, however, he never finished it. In early 1995. Rainer
1030 F. Trunz took over its development and ``improved, updated, simply
1031 made it workable'' (quotation from the change log). It still contained
1032 quite a few bugs, though.
1034 In more-or-less the same time, I started a discussion on the
1035 @samp{amiga-gcc-port} mailing list about improving the quality of
1036 @samp{inlines}. The most important idea came from Matthias Fleischer,
1037 who introduced the new format of @samp{inlines} (@pxref{New format}).
1038 Since I started the discussion, I volunteered to make improvements to
1039 the @samp{inlines} parser. Having no idea about programming in
1040 @samp{Perl}, I decided to modify the parser written in @samp{C}. I
1041 fixed all the bugs known to me, added some new features, and wrote
1042 this terribly long documentation :-).
1044 Ralph Schmidt and Emmanuel Lesueur added PowerUp and MorphOS support
1045 (version 2.00).
1047 Martin Blom backported some of their work to version 1.xx and added support
1048 for ix86be-amithlon and AROS.
1050 Not all of the files distributed in the @samp{FD2InLine} archives were
1051 created by me or @samp{FD2InLine}. Most of the files in
1052 @file{include-src/proto} and @file{include-src/inline} (@file{alib.h},
1053 @file{strsub.h} and @file{stubs.h}) were written by Gunther Nikl (with
1054 some modifications by Joerg Hoehle and me).
1056 If you have any comments concerning this work, please write to:
1058 gg-gcc@@ninemoons.com
1060 This is a list to which most of the @samp{GeekGadgets} developers and
1061 activists subscribe, so you are practically guaranteed to get a reply.
1063 However, if, for some reason, you want to contact me personally, you
1064 can do so in one of the following ways:
1066 @itemize @bullet
1067 @item
1068 E-mail (preferred :-):
1070 iskra@@student.uci.agh.edu.pl
1072 Should be valid until October 1999 (at least I hope so :-).
1074 @item
1075 Snail-mail (expect to wait long for a reply :-):
1077 @format
1078 Kamil Iskra
1079 Luzycka 51/258
1080 30-658 Krakow
1081 Poland
1082 @end format
1083 @end itemize
1085 Latest version of this package should always be available on my WWW
1086 page:
1088 @format
1089 http://student.uci.agh.edu.pl/~iskra
1090 @end format
1092 @node Index, , Authors, Top
1093 @chapter Index
1094 @printindex cp
1096 @contents
1097 @bye