home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 6 / IOPROG_06.ISO / ada / gnatinfo.txt < prev    next >
Encoding:
Text File  |  1996-06-17  |  93.6 KB  |  2,132 lines

  1.  
  2.  
  3. ------------------------------------------------------------------------------
  4. --                                                                          --
  5. --                              GNAT DOCUMENTS                              --
  6. --                                                                          --
  7. --                                I N T R O                                 --
  8. --                                                                          --
  9. --                            $Revision: 1.103 $                            --
  10. --                                                                          --
  11. --   Copyright (C) 1992,1993,1994,1995,1996 Free Software Foundation, Inc.  --
  12. --                                                                          --
  13. -- GNAT is free software;  you can  redistribute it  and/or modify it under --
  14. -- terms of the  GNU General Public License as published  by the Free Soft- --
  15. -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
  16. -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
  17. -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
  18. -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
  19. -- for  more details.  You should have  received  a copy of the GNU General --
  20. -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
  21. -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
  22. -- MA 02111-1307, USA.                                                      --
  23. --                                                                          --
  24. -- GNAT was originally developed  by the GNAT team at  New York University. --
  25. -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
  26. --                                                                          --
  27. ------------------------------------------------------------------------------
  28.  
  29.    Note: Version 1.103 of this document corresponds to the public release
  30.          of GNAT 3.07.
  31.  
  32. Contents.
  33. ---------
  34.    What is Ada 95 ?
  35.    What is GNAT ?
  36.    Public GNAT Releases.
  37.    Running GNAT.
  38.    A small example.
  39.    Using gcc to compile.
  40.    Using gcc for syntax checking.
  41.    Using gcc for semantics checking.
  42.    GNAT Options.  
  43.    Constraint Checking and Pragma Suppress.
  44.    Software Overflow Checking.
  45.    Using the binder.
  46.    Gnatlink.
  47.    Building a Program where the Main Program is not in Ada
  48.    Search Paths and the Run Time Library (RTL).
  49.    Gnatmake (*new features*).
  50.    Order of Compilation Issues.
  51.    File Name Rules.
  52.    GNAT specific pragmas.
  53.    pragma Source_File_Name.
  54.    Machine Code Insertions
  55.    Gnatk8.
  56.    Compiling Files With Several Compilation Units.
  57.    Cross Reference Tool.
  58.    Implementation of Intrinsic Functions.
  59.    Getting Internal Debugging Information.
  60.    GNAT Trouble-Shooting.
  61.    Using gdb.
  62.    Performance Considerations.
  63.    New WARNING messages related to accessibility checks and private packages
  64.    Features supported/unsupported.
  65.    Files.
  66.    Ada Mode for Emacs.
  67.    Copyright considerations.
  68.    How to get in touch with us.
  69.    Schedule.
  70.    A short gnat paper.
  71.    Ada information resources on the Internet.
  72.    The GNAT development team.
  73. ------------------------------------------------------------------------------ 
  74.  
  75. What is Ada 95 ?
  76. ----------------
  77.  
  78. Ada 95 is the latest  Ada standard. It is also  the first ISO and ANSI
  79. standard   programming  language   to   fully  support object-oriented
  80. programming. Ada 95  is fully upward compatible with  Ada 83  (ISO 87)
  81. and has the  same robust  foundation in  Software Engineering. At  the
  82. same time, it provides up-to-date features for today's megaprogramming
  83. tasks, including:
  84.  
  85.    - object-oriented programming, inheritance, polymorphism and dynamic
  86.      dispatching, within the strong-typing discipline of Ada 83.
  87.  
  88.    - Hierarchical program libraries, for composition of subsystems and
  89.      support of multiple implementations.
  90.  
  91.    - Well-defined support for interfacing to other languages such as C,
  92.      Fortran and COBOL.
  93.  
  94.    - Support for specialized application areas such as:
  95.      System Programming, Real-Time Systems, Distributed Systems,
  96.      Information Systems, and Scientific Programming.
  97.  
  98. All of this makes Ada 95 into the  ideal language for large industrial
  99. projects.  The ease    with which Ada   95  can interface  with  other
  100. languages  make it  an ideal  choice   as well  for  the multilanguage
  101. systems of today and the coming century.
  102.  
  103. What is GNAT ?
  104. --------------
  105.  
  106. GNAT is an industrial-quality Ada 95 compiler, integrated into the GCC
  107. retargetable compiler system.  GNAT  is a complete compiler, validated
  108. on several platforms, that includes support for all the Ada 95 annexes
  109. specified in the Ada Reference manual. Because of its integration into
  110. the  GCC   system,   GNAT  is   available  on   a   large   number  of
  111. hardware/operating system  platforms,    and  can   be  used  as     a
  112. cross-compiler from any  of its targets to any  other  one. Because of
  113. the  common code-generator   technology   of GCC,  GNAT  has excellent
  114. support for multi-language programming: Ada, C, C++, Fortran, etc.
  115.  
  116. GNAT  also  represents  a substantial improvement  in  Ada compilation
  117. technology.  Its  open-system  philosophy stands in contrast  with the
  118. opaque approach of  older  Ada compilers.  There   are  no hidden  and
  119. complex central libraries  whose use  requires  a totally new set   of
  120. commands,   and no  rigid development environments    that often force
  121. needless recompilations.  While preserving all of Ada's safety, GNAT's
  122. source-based model  provides the  flexibility and efficiency typically
  123. encountered   in  C development  environments.    Furthermore,  GNAT's
  124. flexibility greatly  facilitates its  integration  within  third-party
  125. development environments and  CASE    tools.  A number   of   standard
  126. editors,  debuggers,  profilers, memory   analyzers, test  coverage or
  127. configuration-management tools,   etc.  can be used  with  GNAT, which
  128. coexists confortably with familiar programming tools (unlike older Ada
  129. compilation systems).
  130.  
  131. GCC is a highly portable compilation  system with multiple front-ends,
  132. advanced cross-compilation features,  and a common code generator with
  133. multiple targets.  Originally  designed as  a compiler  for  C, it now
  134. includes front ends  for  C++, Objective-C, Fortran77,  Pascal, Chill,
  135. and most  recently  Ada 95.  The  innovative architecture   of the GCC
  136. back end allows new hardware targets to be described compactly, for use
  137. by a machine-independent   and  language-independent  multi-pass  code
  138. generator.  This technique produces code of excellent quality both for
  139. CISC machines such as the Intel x86 and Motorola 68K families, and for
  140. RISC machines such as the Power/PC, the DEC Alpha, the HP-PA RISC, the
  141. RS6000, and the MIPS R4000.
  142.  
  143. Public GNAT Releases.
  144. ---------------------
  145.  
  146. GNAT is not public domain software. GNAT, like GCC, is covered by the GPL
  147. (General Public Licence) which preserves the freedom of the software
  148. community by guaranteeing that GNAT and its sources will always be freely
  149. available.  This greatly helps the spread of GNAT and Ada 95 technology in
  150. research and academic environments and allows its free evaluation before
  151. industrial deployment.
  152.  
  153. Public GNAT releases in various ftp sites around the world are made at 6 to 8
  154. week intervals.
  155.  
  156. If you intend to evaluate GNAT for industrial or commercial use please get in
  157. touch with `support@gnat.com'.
  158.  
  159. Running GNAT.
  160. -------------
  161.  
  162. Three steps are needed to create an executable file from an Ada source file:
  163. it must first be compiled, it then must go through the gnat binder, and then
  164. all appropriate object files are linked together to produce an executable.  A
  165. tool has been provided to combine all these steps into one command.
  166.  
  167. A small example.
  168. ----------------
  169.  
  170. The file hello.adb contains the source of our modest version of the "Hello
  171. World" program.  Other components of this program are contained in the GNAT
  172. Runtime Library (RTL).  You needn't mention the files containing these other
  173. components but you can find the sources (g-io.ads, g-io.adb, and a-cio.c) in
  174. the RTL source directory (described below).
  175.  
  176. The file hello.adb can be found in the current distribution in the examples
  177. directory.  Here is the command for building and running it:
  178.  
  179.             gnatmake hello
  180.  
  181. create the executable called "hello" or "hello.exe" in your current directory.
  182.  
  183. Typing
  184.  
  185.       hello
  186.  
  187. will allow you to verify that the system is alive and willing to enter into 
  188. a primitive dialogue.
  189.  
  190. In the above example, Gnatmake performs the following steps (Since this
  191. documentation is for systems running Unix and also for those running DOS,
  192. IBM OS/2 2.x and Windows NT, in places where the instructions differ a
  193. prefix "Unix:" or "OS/2:" or "DOS:" indicates what is relevant for each
  194. system):
  195.  
  196.             gcc -c hello.adb
  197.             gnatbind -x hello.ali
  198.       Unix: gnatlink -o hello hello.ali
  199.       OS/2: gnatlink -o hello.exe hello.ali
  200.       DOS : gnatlink -o hello.exe hello.ali
  201.  
  202. The gcc switch -c indicates that we only want to compile, not link. As the
  203. example suggests, the gcc command recognizes the extension .adb as an
  204. indication of an Ada source file and calls the appropriate programs to
  205. generate an object file (hello.o or hello.obj) and an Ada Library
  206. Information (ALI) file (hello.ali) containing dependency information used
  207. by the binder to verify consistency and determine order of elaboration.
  208. The "ali" extension is recognized by gnatbind (see below) as the ALI file
  209. of the main procedure or function, and gnatbind uses it to create a file
  210. called the bind file, and to gather all the needed object files for
  211. linking.
  212.  
  213. Gnatbind creates a file b_hello.c which contains the calls to the necessary
  214. elaboration procedures.  This information is collected from the closure of
  215. all ALI files determinable from the root ALI file (hello.ali).  A list of
  216. all dependent object files is also generated and appended to the end of the
  217. bind file.
  218.  
  219. Gnatlink compiles b_hello and links the b_hello object file with all the
  220. object files listed in the bind file.  After the link is completed, both
  221. b_hello.c and b_hello.o (b_hello.obj) are removed by default. If -g was
  222. specified on the call to gnatlink, the two files are not removed since it
  223. is assumed they might be required for debugging.  Linking is accomplished
  224. by calling gcc with the needed object files and libraries to link the
  225. executable.  The -o switch is passed to the linker to name the resulting
  226. executable file.
  227.  
  228. (Note that gnatbl is obsolete and has been replaced by gnatlink.  The
  229. gnatbind step must now be performed separately.  This is done automatically
  230. by gnatmake.  For the DOS version of gnatlink, the extra step of running
  231. a modified coff2exe is incorporated, which will create a stripped executable.
  232. In order to lessen the proliferation of normally unused files, the 
  233. extensionless COFF version is also automatically deleted unless -g is 
  234. specified.)
  235.  
  236. Using gcc to compile.
  237. ---------------------
  238.  
  239. In the usual procedures for using GNAT, Ada source programs are compiled into
  240. object files using the driver program 'gcc' with the option '-c' (compile
  241. only). Gcc recognizes the ada filename extensions .ads and .adb (discussed
  242. more thoroughly below) and calls the actual compiler, 'gnat1' to compile the
  243. source file.  Gcc has many switches explained in your gcc documentation.  In
  244. addition, gcc passes certain switches to gnat1.  These (with a couple of
  245. exceptional abbreviations) are spelled on the gcc command line by "-gnatXXX".
  246. Thus
  247.  
  248.         gcc -c -gnata foo.adb
  249.  
  250. causes gcc to call the Ada compiler gnat1 with gnat1's '-a' switch; the '-c'
  251. is understood by gcc to mean that it is done after producing the object file
  252. (it won't try to link).  The output of this command are the object and ALI
  253. files for foo.
  254.  
  255. In the future, the gcc and the GNAT-specific switches may be more fully
  256. integrated.  At this time, there is the "-gnatXXX" mechanism for passing
  257. switches through to gnat1.  Some of these switches are described in
  258. specific sections of this document; a more complete discussion is in the
  259. options section below.  Note that gcc passes these switches to gnat1
  260. with the "gnat" prefix, where it is stripped off.  This means that
  261. when gnat1 is executed the "gnat" prefix is required; but in all of the
  262. documentation the switches are described without the prefix.
  263.  
  264. Three gcc options are translated to gnat1 arguments when seen on the gcc
  265. command line.  These are "k8" (file name limit), "83" (Ada83 syntax) and
  266. "w" (warning mode). Thus, the following commands are identical:
  267.  
  268.      gcc -ws -k8 file.adb
  269.      gcc -gnatws -gnatk8 file.adb
  270.  
  271. i.e., both of them suppress warning messages from GNAT, and expect file names
  272. to be 8 characters long at most (see below for usage).
  273.  
  274. In addition, the following gcc switches are passed through and recognized by 
  275. gnat1 with the same effects as in cc1 (as for C files): "-g*" (other than
  276. "-gnat*"); "-O*"; "-p"; "-pg"; "-f*"; "-d*"; "-S".  For example, 
  277.  
  278.       gcc -c -g math.adb
  279.  
  280. will generate debugging information that can be used with the debugger gdb
  281. (see below).
  282.  
  283. The other flags that control gcc itself (notably -B and -c) and the 
  284. assembler, behave as usual. Please consult your GCC documentation for details.
  285.  
  286. Using gcc for syntax checking
  287. ------------------------------
  288.  
  289. The current release of GNAT implements the full Ada 95 grammar as described in 
  290. annotated Ada Reference Manual for Ada 95 (AARM, version 5.95). We think the
  291. parser gives excellent error messages (try it and see!) and is pleasantly 
  292. fast (again, try and see!).
  293.  
  294. To run GNAT in syntax checking only mode, use the switch "s",
  295. that is to say, enter the command:
  296.  
  297.     gcc -c -gnats file
  298.  
  299. where file is the name of the file to be checked. (Under Unix, wild cards can
  300. be used to check a set of files, as in *.adb.)  Note that the 'compile only'
  301. flag has to be given for gcc, as well as the 'syntax only' flag, which is
  302. GNAT-specific.  We will remove this redundancy in subsequent releases. 
  303.  
  304. The syntax checker is quite robust.  If you find an error message you think
  305. could be improved, let us know (see separate section below).  Of course, no
  306. compiler can ever have perfect error messages (that would involve mind
  307. reading), but we are committed to doing as well as possible, so we are happy
  308. to get suggestions in this department.
  309.  
  310. Using gcc for semantics checking
  311. --------------------------------
  312.  
  313. The command to perform semantic checking is:
  314.  
  315.     gcc -c -gnatc file
  316.  
  317. To operate in this mode, since WITH'ed files must be accessed, the GNAT
  318. semantic restrictions on file structuring must be followed:
  319.  
  320.      o    The needed source files must be accessible.  See the section
  321.         on search paths below.
  322.  
  323.      o    Each file must contain only one compilation unit.
  324.     See the section below on file name rules.
  325.  
  326.      o    The file name and unit name must match as described below, under
  327.         File name rules.
  328.  
  329. Note that the use of search paths and the flexibility of the File name
  330. rules will increase in the future as described in the sections on these
  331. facilities.
  332.  
  333. Note that the 'report errors immediately' switch ("-e", i.e., "-gnate" on the
  334. gcc command line) will help pinpoint the source of the trouble if the system
  335. misbehaves.
  336.  
  337. GNAT Options.
  338. -------------
  339.  
  340. Error reporting, as well as other aspects of the behavior of the system,
  341. are controlled by the following flags. All of these must be entered with
  342. the prefix '-gnat'. For example, '-gnatv83' specifies verbose mode for
  343. output, and Ada83 syntax checking. 
  344.  
  345.   a      Assertions enabled. Pragma Assert and Debug to be activated.
  346.   b      Generate brief messages to stderr even if verbose mode set.
  347.   c      Check syntax and semantics only (no code generation attempted)
  348.   e      Error messages generated immediately, not saved up till end
  349.   f      Full errors. Normally only the first error on each line is reported.
  350.   g      GNAT style checks enabled - col alignment, spacing, capitalization.
  351.       See any source file for examples.
  352.   i?      Identifier char set (?=1/2/3/4/8/p/f/n/w) default = i1 (Latin-1)
  353.         1-4 = Latin 1-4, p = IBM PC, f/n = full/no, upper w=wide_character
  354.   j?      Wide character encoding method (?=n/h/u/s/e)
  355.   knnn      Limit file names to nnn characters (k = krunch)
  356.   l      Output full source listing with embedded error messages
  357.   mnnn      Limit number of detected errors to nnn (1-999)
  358.   n      Inlining of subprograms (apply pragma Inline across units)
  359.   o       Enable integer overflow checking using range checks
  360.   p      Automatic suppression of all run-time checks mentioned in LRM 11.7
  361.   q       Don't quit, try semantics, even if parse errors
  362.   r      Reference manual column layout required
  363.   s      Syntax check only
  364.   t       Tree output file to be generated
  365.   u      List units for this compilation
  366.   v      Verbose mode. Full error output with source lines to stdout.
  367.   w?      Warning mode. s = suppress, e = treat as error
  368.   x?      Cross-reference level and switches (?=1/2/3/4/5/9/b/s)
  369.   z?      Distribution stub generation (r/s for receiver/sender stubs)
  370.   83      Enforce Ada 83 restrictions
  371.   sfile      Source file names (wild cards allowed for multiple files)
  372.  
  373. Some of these options are explained in more detail elsewhere in this document.
  374.  
  375. For first-time users, and for first-compilation attempts, the following mode
  376. of operation is recommended:
  377.  
  378.       gcc -c -gnatc lets_try_this.adb
  379.  
  380. Constraint Checking and Pragma Suppress
  381. ---------------------------------------
  382. In the current version there are some checks performed that are mentioned in
  383. the LRM in section 11.7. These are:
  384.  
  385. range checks on signed integer and enumeration types
  386.   (assignment, in parameters and initial values in object declarations)
  387. index checks
  388. access checks
  389.  
  390. To disable constraint checks, compile the program with the "-gnatp"
  391. option. This is equivalent to having Pragma suppress applied to
  392. everything. Gdb can be used to find where the exception was raised.  See the
  393. section on "Using gdb" for further information.
  394.  
  395. Arithmetic Overflow Checking
  396. ----------------------------
  397.  
  398. Compiling with the default options results in code that performs range
  399. checking against constraints (see -gnatp for suppressing such checks).
  400. However, the default mode does not enable checking for arithmetic overflow
  401. and division by zero.
  402.  
  403. If this checking is required, then the -gnato switch should be set. This
  404. causes appropriate additional code to be generated to check for both
  405. overflow and division by zero (resulting in raising Constraint_Error as
  406. required by the Ada semantics).
  407.  
  408. Note that the -gnato switch does not affect the code generated for any
  409. floating-point operations; it applies only to integer operations. For
  410. floating-point, GNAT has Machine_Overflows set to False, and the normal
  411. mode of operation is to generate IEEE NaN and infinite values on overflow
  412. or invalid operations (such as dividing 0.0 by 0.0)
  413.  
  414. The checks generated by -gnato are quite expensive, which is why they
  415. are not the generated by default. This is because GCC does not yet use
  416. specialized hardware features (flags, sticky flags, traps etc.) for the
  417. detection of integer overflow. Eventually we plan to implement more
  418. efficient integer overflow checking in the future.
  419.  
  420. Using the Binder.
  421. -----------------
  422.  
  423. In the "Hello World" example above, the second step (performed by gnatmake)
  424. is to create the bind file with the command:
  425.  
  426.        gnatbind -x hello.ali
  427.  
  428. This command generates a file named b_hello.c which needs to be compiled
  429. and linked together with hello.o (or hello.obj).  The file b_hello.c
  430. contains a program that calls all of the elaboration routines for all of
  431. the units required by the subprogram whose ALI file is given on the command
  432. line.  Then it calls the Ada subprogram itself.  By default, this C
  433. function is called "main".  (For other options, see the section on options
  434. below.)  The program gnatbind works by recursively processing the ALI files
  435. of all of the units that are needed.  These ALI files are found using the
  436. search path mechanism described below.  Since object and ALI files are
  437. always kept together, the object files needed for linking are found at the
  438. same time and are listed in a comment at the end of the bind file.  This is
  439. where gnatlink finds the list of object files required.
  440.  
  441. The options of gnatbind are summarized below.
  442.  
  443. Usage: gnatbind switches lfile
  444.  
  445.   -b      Generate brief messages to stderr even if verbose mode set
  446.   -c      Check only, no generation of binder output file
  447.   -e      Output complete list of elaboration order dependencies
  448.   -aOdir  Specify library files search path
  449.   -aIdir  Specify source files search path
  450.   -Idir   Specify source & library files search path
  451.   -I-     Don't look for sources & library files in default directory
  452.   -l      Output chosen elaboration order
  453.   -mnnn   Limit number of detected errors to nnn (1-999)
  454.   -n      No main program
  455.   -o file give the Output name (default is b_xxx.c) 
  456.   -s      Require all source files to be present
  457.   -t      Ignore time stamp errors
  458.   -v      Verbose mode. Error messages,header, summary output to stdout
  459.   -wx     Warning mode. (x=s/e for suppress/treat as error)
  460.   -x      Exclude source files (check object consistency only)
  461.   lfile   Library file names
  462.  
  463. Gnatlink
  464. --------
  465.   gnatlink
  466.        [-o exec_name]
  467.        [-v]                  -- verbose mode
  468.        [-g]                  -- include debugging information
  469.        [-gnatlink name]      -- full name for the linker (gcc)
  470.        [list of objects]     -- non Ada binaries
  471.        [linker options]      -- other options for the linker
  472.  
  473. The program gnatlink provides for linking using the GNAT RTL.  The typical
  474. use of GNAT (currently -- in the presence of gnatlink) to construct a
  475. program consisting of a mix of Ada and C sources is to compile all of the
  476. sources using "gcc -c" to generate object (.o or .obj) files.  In the case
  477. of Ada sources, ALI files with the extension .ali are also produced.  Then
  478. gnatbind is used to produce the bind file.  Finally, gnatlink constructs
  479. the executable.  All arguments to gnatlink are simply passed through to gcc
  480. to link the objects together, with the exception of a file name with the
  481. .ali extension.  Such an argument is presumed to be the ALI file of the
  482. main procedure of the program.  When gnatlink sees a .ali file it compiles
  483. the associated bind file, extracts a list of needed object files from that
  484. bind file, and replaces the .ali argument with the a list of object files
  485. (the result of compiling the bind file and the list extracted from the bind
  486. file) in the gcc command it makes.  As a quick illustration consider a
  487. program comprising main.adb, foo.adb and bar.c.  After compiling these
  488. sources into object files, the command (under Unix)
  489.  
  490. gnatlink -o main main.ali bar.o
  491.  
  492. would cause gnatlink to:
  493.   assume the presence of the bind file b_main.c
  494.   call "gcc -c b_main.c"
  495.   call "gcc -o main b_main.o main.o foo.o bar.o (+ gnat library args)"
  496.  
  497. In the last step, the "main.ali" argument has been replaced by all of the
  498. object files needed by main (the binder file, main itself, and foo -- upon
  499. which main depends). All other gnatlink arguments are passed through
  500. unchanged to gcc.  Finally a -L and a -l argument are added to the end of
  501. the gcc call to point it to the gnatlib library.  (Under OS/2, the command
  502. line and behavior of gnatlink is similar.)  (Under DOS, the additional step
  503. of calling "coff2exe main" is done, which will create a stripped executable.)
  504.  
  505. [-o exec_name]
  506.   Under unix if the -o option is omitted the executable is called the name of
  507.   the main unit. So "gnatlink try.ali" will create an executable called try.
  508.   Under DOS and OS/2 it would create an exectuable called try.exe.
  509.  
  510. [-v]
  511.   The verbose option is most useful when the user wants to see what set of
  512.   object files that are being used in the link step.
  513.  
  514. [-g]
  515.   The option to include debugging information causes the C bind file, i.e.
  516.   b_foo.c, to be compiled with -g. In addition the b_foo.c and b_foo.o file
  517.   will not be removed (without -g the default action is to remove the binder
  518.   generated files). Additionally on DOS, it causes the COFF output file to
  519.   be preserved and on Windows NT causes extra debugging information to be
  520.   linked into the executable. Note that on DOS it is impractical to debug
  521.   without gnatlinking with -g, since the debugger only works on COFF files.
  522.  
  523. [-gnatlink name]      -- full name for the linker (gcc)
  524.  
  525. Building a Program where the Main Program is not in Ada
  526. -------------------------------------------------------
  527.  
  528. To build a program where the main program is not in Ada, we compile the
  529. Ada units as usual. Then bind using gnatbind with the -n switch, and
  530. then gnatlink mentioning the object files for the main program.
  531. Consider the following example:
  532.  
  533.   Main program (m.c)
  534.  
  535.     main()
  536.     {
  537.       adainit();
  538.       Header();
  539.       adafinal();
  540.     }
  541.  
  542.   Ada subroutine (header.adb)
  543.  
  544.     with Text_IO; use Text_IO;
  545.     procedure Header is
  546.     begin
  547.        put_line ("Header");
  548.     end;
  549.     pragma Export (C, Header, "Header");
  550.  
  551.     Compile the units
  552.     
  553.       gcc -c m.c
  554.       gcc -c header.adb
  555.     
  556.     Bind
  557.     
  558.       gnatbind -n header.ali
  559.     
  560.     Link
  561.     
  562.       gnatlink header.ali m.o
  563.     
  564.     Run
  565.     
  566.       header
  567.  
  568. Notes:
  569.   If more than one Ada routine is called from the non-Ada main program,
  570.   then the ali files for all such Ada routines must be supplied to the
  571.   binder. The binder will take care of any transitively referenced
  572.   units (e.g. if B with's C, then mentioning b.ali will automatically
  573.   cause c.ali to be also read, but if C is only mentioned by the main
  574.   program, then c.ali must appear on the gnatbind line).
  575.  
  576.   The name of the program is by default the name of the ali file given
  577.   to the gnatlink command. This can be changed using a -o switch.
  578.  
  579.   The calls to adainit and adafinal ensure that the Ada code is properly
  580.   elaborated, and that any required finalization at the end of the run
  581.   is properly performed.
  582.  
  583. Search paths and the Run Time Library (RTL)
  584. -------------------------------------------
  585.  
  586. With GNAT's source based library system, the compiler must be able to
  587. find source files for units that are needed by the unit being
  588. compiled.  Also, during binding, ALI files are needed to do the
  589. required checking of compilation order and to determine elaboration
  590. requirements.  Both the compiler and binder use search paths to
  591. locate the files that they need. The rules are straightforward.
  592.  
  593. The compiler compiles one source file whose name must be given explicitly
  594. on the command line (i.e. there is no searching done for this file).  All
  595. other source files that are needed (the most common being the specs of
  596. WITH'ed units) are found by looking in the following directories: 
  597.  
  598.    o The first directory searched is the directory containing the source
  599.      file of the main unit being compiled (the file name on the command
  600.      line). This directory is the current working directory only if the
  601.      input file contains no relative or absolute path information.
  602.      Otherwise if the input file is specified as dir/file then the first
  603.      directory searched is dir.
  604.      Note, however, that option `-I-' inhibits the use of this directory
  605.      as the default search  directory. You can still have this
  606.      directory on your search path, but this must be explicitely
  607.      requested with a -Idir flag if -I- is specified. See below for -I.
  608.  
  609.    o Next, the compiler looks in each directory named by a "-I" option
  610.      given to gcc (in the order given on the command line).
  611.  
  612.    o Then the compiler looks in each of the directories listed in the value
  613.      of the ADA_INCLUDE_PATH environment variable.  This value is constructed
  614.      exactly as the PATH environment variable -- a list of directory names
  615.      separated by ':' or ';' (Unix or OS/2, respectively) characters. Under
  616.      OS/2, this mechanism is used to locate the RTL source files in place of
  617.      the default location described next for Unix.
  618.  
  619.    o (Unix only) Finally the compiler looks in the default location for
  620.      the GNAT Run Time Library (RTL) source files that is determined at the
  621.      time that GNAT is built and installed on your system.
  622.  
  623. The compiler outputs its object files and ALI files in the current working
  624. directory (NOTE: the object file can be redirected with the -o option;
  625. however, gcc and gnat1 have not been coordinated on this so the ALI file
  626. will not go to the right place -- DON'T DO THIS).
  627.  
  628. The binder takes the name of an ALI file as its argument and needs to locate
  629. other ALI files in its recursive processing.  These are found in the
  630. following directories:
  631.  
  632.    o The first directory searched is the directory containing the ALI
  633.      file named in the command line. This directory is the current
  634.      working directory only if the input ALI file contains no relative or
  635.      absolute path information. Otherwise if the input ALI file is
  636.      specified as dir/ali-file then the first directory searched is dir.
  637.      Note, that option `-I-' inhibits the use of this directory
  638.      as the default search  directory. You can still have this
  639.      directory on your search path, but this must be explicitely
  640.      requested with a -Idir or -aOdir flag if -I- is specified.
  641.  
  642.    o Next, the binder looks in directories named in "-Idir" or
  643.      "-aOdir" options on the gnatbind command line (in the order given).
  644.  
  645.    o Next, the binder looks in each of the directories listed in the value
  646.      of the ADA_OBJECTS_PATH environment variable.  This value is constructed
  647.      exactly as the PATH environment variable -- a list of directory names
  648.      separated by ':' or ';' (Unix or OS/2, respectively) characters. Under
  649.      OS/2, this mechanism is used to locate the RTL object files in place of
  650.      the default location described next for Unix.
  651.  
  652.    o (Unix only) Finally the binder looks in the default location for
  653.      the GNAT Run Time Library (RTL) object files that is determined at the
  654.      time that GNAT is built and installed on your system.
  655.  
  656. If the binder is requested to locate source files (for time stamp
  657. verification) the source files are located using the mechanism for
  658. source files described above. Specifically, the directory where the
  659. gnatbind command was invoked is searched first (unless -I- is
  660. present), then the directories specified with -I or -aI, then those in
  661. ADA_INCLUDE_PATH, etc.  Because no source file is specified to the
  662. binder, the first directory which is searched for sources is the
  663. current working directory. To avoid searching this directory use -I-.
  664. The difference betwen flags -aI, -aO and -I is that -aI specifies source
  665. files search path (ada includes), -aO specifies library/object files
  666. search path (ada objects), while -I implies both -aI and -aO.
  667.  
  668. The binder generates the bind file (a C language source file) in the
  669. current working directory.
  670.  
  671. The packages Ada, System, and Interfaces and their children make up the GNAT
  672. Run Time Library, together with the simple System.IO package used in the "Hello
  673. World" example.  The sources for these units are needed by the compiler
  674. and are kept together in one directory (not all of the bodies are needed,
  675. but all of the sources are kept together anyway).  The ALI files and object
  676. files generated by compiling the RTL are needed by the binder and the linker,
  677. and are kept together in one directory (typically different from the
  678. directory containing the sources).  In a normal installation, the user will
  679. not need to specify these directory names when compiling or binding (or
  680. binding and linking with gnatbind/gnatlink -- though the call to the linker
  681. contains explicit pathnames of the object files).  Either the environment
  682. variables (OS/2) or the builtin defaults will cause these files to be found.
  683.  
  684. Besides the assistance in using the RTL, a major use of search paths is
  685. in compiling sources from multiple directories.  This can make development
  686. environments much more flexible.
  687.  
  688. The user might use the search paths to experiment with alternative RTLs, or
  689. to create new libraries (not the technical Ada meaning here).
  690.  
  691. Gnatmake
  692. --------
  693.  
  694. In the following command line description we use BNF notation.
  695. [X] means zero or one occurrence of X.
  696. {Y} means zero, one or arbitrarily many occurrences of Y.
  697.  *  stands for any sequence of characters.
  698.  
  699.   gnatmake [-a] [-c] [-f] [-jnum] [-k] [-M] [-o exec_name] [-n] [-q] [-v] 
  700.            [compiler_switch]
  701.            { [-Adir] [-aOdir] [-aIdir] [-Idir] [-I-] [-Ldir] }
  702.            name
  703.            { [-cargs options] [-bargs options] [-largs options] }
  704.  
  705. The purpose of gnatmake is to automatically determine and (re)compile
  706. the set of Ada sources needed by some ada compilation unit, Unit.  An
  707. ada source needed by Unit is recompiled if its corresponding object
  708. file is obsolete with respect to the current sources. The bind and
  709. link steps are also performed if objects were found to be out-of-date.
  710. In previous versions of gnatmake the bind and link steps were always
  711. performed. This was, at times, inconvenient. The latest gnatmake will
  712. perform the bind and link step only if some object file is more
  713. recent than the executable (this also correctly works if you use the
  714. -o option of gnatmake. See below fro the -o option).
  715.  
  716. There are two ways to specify the actual compilation unit:
  717.  
  718.   * By giving the full name of the source file containing it
  719.     ("gnatmake  file.adb" or "gnatmake  dir/file.adb" or
  720.      "gnatmake  file.ads" or "gnatmake  dir/file.ads" or in general 
  721.      "gnatmake  file.*"   or "gnatmake  dir/file.*")
  722.  
  723.   * As above but you can omit the .adb or .ads suffix
  724.     (`gnatmake file or `gnatmake dir/file)
  725.  
  726. To decide whether gnatmake needs to recompile a source file, gnatmake
  727. needs to locate other source files as well as the corresponding
  728. object/library files. The search for source files is done in *exactly*
  729. the same fashion as for gcc, whereas the search for object/library
  730. files is done *exactly* like for the binder (both are described in the
  731. section on search paths above). In particular the switches -I, -I-,
  732. -aI and -aO are directly available in gnatmake (see below).
  733.  
  734. The only missing precision is the definition of the default
  735. source/library search directory for gnatmake.
  736.  
  737. For library/object files the default search directory (ie the
  738. directory where object/library files are searched first) is the
  739. directory where gnatmake was invoked (ie "."). By using switch -I-
  740. you can disable lookup in this default directory.
  741.  
  742. For source files if the user types 
  743.  
  744.         gnatmake  -aIdir_2 ... -aIdir_n  dir_1/file
  745.    or   gnatmake  -aIdir_2 ... -aIdir_n  dir_1/file.adb
  746.  
  747. the search path seen by gnatmake is dir_1 dir_2 ... dir_n (note that
  748. dir_1 may be ".") and the default source search directory is dir_1.
  749. To disable initial search in dir_1 use -I-.  The only difference
  750. between the two gnatmake calls above is that in the first call
  751. gnatmake will look for file.adb/file.ads in dir_1 dir_2 ... dir_n,
  752. whereas in the second call gnatmake will look for file.adb only in
  753. dir_1 and will fail if it cannot find it there.
  754.  
  755. Please note that you cannot use -I- if you give the full source name
  756. of the main unit (ie "gnatmake -I- ... file.adb" is forbidden) because
  757. gnatmake will be unable to recreate the same source search path for
  758. subsequent calls to gcc.
  759.  
  760. Note that gnatmake will invoke gcc in the directory where gnatmake was
  761. invoked. This means that all object and library files that will be
  762. generated from the various compilations will be output to the current
  763. directory. For the time being there is no way to redirect this output
  764. to some other directory (unless you move it there yourself). To build
  765. several executables which share a common set of sources you need to
  766. create a separate directory for each executable and generate the
  767. executable in that directory. To select the appropriate sources use
  768. the -aI, -I and -I- switches (see below). Note that the switches -aL
  769. and -aO will allow to specify the location of object and ALI files
  770. which already exist and do not have to be recreated.
  771.  
  772. Because gnamake invokes gcc in the current
  773.  
  774. gnatmake switches are of 4 kinds:
  775.  
  776.   * gnatmake switches. These switches directly control gnatmake's behavior.
  777.   * gcc switches. These switches are passed as is to gcc by gnatmake.
  778.   * Source & library search path switches.
  779.   * General compiler, binder & linker switches.
  780.  
  781. All gnatmake output (except for -M) is to stderr. The output produced
  782. by the -M switch is to standard output.
  783.  
  784. gnatmake switches:
  785.  
  786. [-a]
  787.    Consider all files. Considers all files in the make process, even
  788.    the GNAT internal system files (for instance the predefined Ada
  789.    library files). By default gnatmake does not check these internal
  790.    files (don't worry this is safe, if there is an installation
  791.    problem this will be caught when gnatmake binds your program).
  792.    You may have to set this switch if you are working on gnat itself.
  793.    For the vast majority of gnatmake users you never need to set this flag.
  794.    Note that by default "gnatmake -a" compiles all GNAT internal files
  795.    with "gcc -c -gnatg" rather than just "gcc -c".
  796.  
  797. [-c]
  798.    Compile only. Do not perform binding and linking. If the root unit
  799.    specified by unit_or_file_name is not a main unit this is the default.
  800.    Otherwise gnatmake will attempt binding and linking unless all objects
  801.    are up to date and the executable is more recent than the objects.
  802.  
  803. [-f]
  804.    Force recompilations. Recompile all sources even though some object
  805.    files may be up to date but don't recompile predefined units or GNAT
  806.    internal files unless the -a switch is set.
  807.  
  808. [-jnum]
  809.    Use "num" processes to carry out the (re)complations. If you have a
  810.    multiprocessor machine compilations will occur in parallel.
  811.    In the event of compilation errors, messages from various
  812.    compilations might get interspersed (but gnatmake will give you the
  813.    full ordered list of failing compiles at the end). This can at
  814.    times be annoying. To get a clean list of error messages don't use -j.
  815.  
  816. [-k]
  817.    Keep going. Continue as much as possible after a compilation error.
  818.    To ease the programmers's take in case of compilation errors, the
  819.    list of sources for which the compile fails is given when gnatmake
  820.    terminates.
  821.  
  822. [-M]
  823.    Checks if all objects are up to date. If they are "gnatmake -M"
  824.    outputs the object dependences to standard output in a form that
  825.    can be directly exploited in a Makefile. By default each source file
  826.    is prefixed with its (relative or absolute) directory name. This
  827.    name is whatever was specified in the various -aI -I switches.
  828.    If you use "gnatmake -M -q" (see flag -q below) then only the source
  829.    file names without relative path are output. If you just invoke
  830.    "gnatmake -M" dependencies of the GNAT internal system files are
  831.    omitted. This is typically what you want. If you use "gnatmake -a -M"
  832.    dependencies of the gnat internal files are also listed. Note that
  833.    dependencies of the objects in external Ada libraries (see switch
  834.    -aLdir below) are never reported.
  835.  
  836. [-n]
  837.    Don't compile, bind or link. Checks if all objects are up to date.
  838.    If they are "gnatmake -n" reports that no recompilations needed.
  839.    Otherwise "gnatmake -n" stops and prints the full name of the first
  840.    encountered file that needs to be recompiled. Note that if you specify
  841.    "-n -f" together, gnatmake will return the full name of the main unit.
  842.         
  843. [-o exec_name]
  844.   Output executable name. The name of the final executable program will
  845.   be "exec_name". Like for gnatlink if the -o option is omitted the
  846.   default name for the executable will be the name of the input file
  847.   without the suffix (Unix systems) or the name of the input file with
  848.   an ".exe" extension (DOS and OS/2). Note that exec_name can be
  849.   prefixed with a relative or absolute directory path.
  850.  
  851. [-q]
  852.    Quiet. Without this flag set the commands carried out by gnatmake are
  853.    displayed. Flag -q has a special use when flag -M is also set. See
  854.    -M above.
  855.  
  856. [-v] 
  857.    Verbose. Motivates all (re)compilations (ie gives *one* reason for
  858.    (re)compiling a source file).
  859.  
  860.  
  861. gcc switches:
  862.    The switch -g or any upper case switch (other than -A, or -L)
  863.    or switch that is more than one character is passed to gcc
  864.    (e.g. -O, -gnato, etc.)
  865.  
  866.  
  867. Source & Library search path switches:
  868.  
  869. [-aL]
  870.    Ada Library. gnatmake tries to locate the bodies of all compilation units
  871.    in the program. If the program uses an Ada library containing only the
  872.    objects and library information for its units (i.e. the sources for the
  873.    corresponding bodies are unavailable) gnatmake will fail. To avoid
  874.    this use flag -aL. It instructs gnatmake to skip compilation units
  875.    whose ali information has been located in directory "dir".  Another
  876.    reason for skiping units in Ada libraries is efficiency.  It would be
  877.    very wasteful for gnatmake to systematically check the consistency of
  878.    every external Ada library used in a program. The binder is already in
  879.    charge of catching potential inconsistencies. Note that this switch
  880.    allows to have missing *bodies* for the units that are in your library.
  881.    You still need to locate the specs for these units. Switches -aIdir
  882.    or -I below can be used for this purpose.
  883.  
  884. [-Adir]
  885.    Equivalent to "-aLdir -aIdir". See below for -aI.
  886.  
  887. [-aOdir]
  888.    When looking for library and object files look also into directory
  889.    "dir". The order in which library files search is undertaken is
  890.    described in section "Search Paths and the Run Time Library" above.
  891.  
  892. [-aIdir]
  893.    When looking for source files look also into directory "dir".
  894.  
  895. [-Idir]
  896.    Equivalent to "-aOdir -aIdir".
  897.  
  898. [-I-]
  899.    Do not look for source, library or object files in the default directory.
  900.  
  901. [-Ldir]
  902.    Add directory "dir" to the list of directories in which the linker
  903.    will search for libraries. This is equivalent to typing -largs -Ldir.
  904.    See below for the meaning of -largs.
  905.  
  906.  
  907. General compiler, binder or linker switches:
  908.  
  909. [-cargs options] 
  910.    Compiler arguments. gnatmake allows you to pass some switches
  911.    directly to gcc. These switches have been given above under
  912.    `gcc switches'. If you want to pass other arguments to gcc
  913.    type "gnatmake ... unit -cargs c_opts ..." and gnatmake will
  914.    invoke gcc with "c_opts" in its parameter list. The list "c_opts"
  915.    is terminated upon encounter of another -cargs, -bargs or -largs.
  916.    
  917. [-bargs options]
  918.    Binder arguments. Without -bargs, gnatmake simply uses "gnatbind
  919.    unit.ali" to bind. Otherwise gnatmake uses "gnatbind b_opts
  920.    unit.ali". "b_opts" is akin to "c_opts" above but is obtained from
  921.    "-bargs options".
  922.  
  923. [-largs options]
  924.    Linker arguments.  Without -largs, gnatmake simply uses "gnatlink
  925.    unit.ali" to link. Otherwise gnatmake uses "gnatlink l_opts unit.ali".
  926.    "l_opts" is akin to "c_opts" and "b_opts" above but is obtained from
  927.    "-largs options". Note that you are not allowed to use the -o
  928.    option within a -largs. Use the -o option which is directly
  929.    provided by gnatmake to give a specific name to your executable.
  930.  
  931.  
  932. NOTES:
  933.  
  934. 1. gnatmake examines both an ali file and its corresponding object file
  935. for consistency. If an ali is more recent than its corresponding object,
  936. or the object is missing, the corresponding source will be recompiled.
  937. Note that gnatmake expects an ali and the corresponding object file
  938. to be in the same directory.
  939.  
  940. 2. If there are no recompilations gnatmake tells you so, unless you've
  941. used -q, in which case gnatmake is silent. Thus when you type
  942. "gnatmake -n -q unit", gnatmake will either return the full path name
  943. of the first file that needs to be recompiled, or it will be silent. Thus
  944. "gnatmake -n -q" can be used as input to further tools.
  945.   
  946. 3. If the user types "gnatmake file.adb" where file.adb is the body 
  947. of a generic unit, then gnatmake will recompile file.adb systematically
  948. because it finds no ali and then will stop. In particular beware that
  949. in this case "gnatmake -n -q file.adb" will always return "file.adb".
  950.  
  951. 4. If you gnatmake a spec that has a body (say "unit.ads") or a sub-unit
  952.    you will get
  953.  
  954.        % gnatmake unit.ads
  955.        gcc -c unit.ads
  956.        No code generated for t1 (spec) in file t1.ads
  957.        gnatmake: *** compilation failed.
  958.  
  959.    The compilation "fails" because specs or sub-units generate no
  960.    code. To avoid the message use the -gnatc flag (semantics only).
  961.  
  962.        % gnatmake -gnatc unit.ads
  963.        gcc -c -gnatc unit.ads
  964.  
  965. 5. gnatmake has been designed to make the use of Ada libraries
  966.    particularly convenient. Assume you have an Ada library organized
  967.    as follows: obj-dir contains the objects and ALI information for
  968.    of your Ada compilation units, whereas include-dir contains the
  969.    specs of these units, but no bodies. Then to compile a unit
  970.    stored in main.adb, which uses this Ada library you would just type
  971.  
  972.        % gnatmake  -aI"include-dir"  -aL"obj-dir"  main
  973.  
  974. 6. If you type
  975.  
  976.        % gnatmake -aO"dir2" file.adb
  977.  
  978.    and "dir2" contains an up-to-date file.ali file.adb will not be
  979.    recompiled.
  980.  
  981. 7. If you type
  982.  
  983.        % gnatmake -I- -Idir file
  984.  
  985.    gnatmake will look for file.ali in "dir" only. This means that if
  986.    file.ali is obsolete, gnatmake will recompile file.adb in the
  987.    current directory but will not be able to re-read file.ali because
  988.    library file search was disabled in the current directory by -I-.
  989.    In this even, gnatmake will warn you and will keep going but will
  990.    not perform the bind and link steps.
  991.  
  992. 8. The switch -M can be very useful if, after having created an
  993.    executable, you want to know which source files were used and
  994.    in which directory they lie. For this just type
  995.  
  996.        % gnatmake whatever-switches file-name
  997.  
  998.    this will generate the executable. Then add the -M switch to see
  999.    the exact list of dependencies
  1000.  
  1001.        % gnatmake -M whatever-switches file-name
  1002.    
  1003. Order of Compilation Issues.
  1004. ----------------------------
  1005.  
  1006. If, in our example, there were a spec for the hello procedure, it would
  1007. be contained in the file "hello.ads"; yet this file would not need to be
  1008. explicitly compiled.  This is the result of the model we chose to implement
  1009. library management. Details of the model can be found in file gnote1. Some of
  1010. the unexpected consequences of the model (unexpected from the point of view
  1011. of existing Ada compiler systems) are the following: 
  1012.  
  1013.      o    There is no point in compiling generics or specifications (except for
  1014.     package specifications with no bodies), since these are compiled as
  1015.     needed by clients. If you do attempt a useless compilation, you will
  1016.     get a warning message. It is also useless to compile subunits in this
  1017.     mode, since they are compiled as needed by the parent.
  1018.  
  1019.      o    There are no order of compilation requirements, and performing a
  1020.     compilation never obsoletes anything. The only way you can obsolete
  1021.     something and require recompilations is if one of the relevant source
  1022.     files is modified.
  1023.  
  1024.      o    There is no library as such, apart from the .ali files, whose format 
  1025.     is also described in libfmt.ads. For now, we find it convenient to
  1026.     create separate .ali files, but eventually the information therein may
  1027.     be incorporated into the object file directly.
  1028.  
  1029.      o    When you compile a unit, the source files for the specs of all 
  1030.     units that it WITH's, all its subunits, and the bodies of any
  1031.     generics it instantiates must be around (findable by the search
  1032.         paths mechanism described above), or you will get a fatal error
  1033.     message.
  1034.  
  1035. The above may seem surprising. Just to provide one immediate assurance,
  1036. all of this does not mean that we are violating Ada's strict consistency 
  1037. rules; they are enforced instead by the binder. 
  1038.  
  1039. File Name Rules
  1040. ---------------
  1041.  
  1042. Operating in default mode, GNAT requires that file names match compilation unit
  1043. names. The default matching rules are as follows:
  1044.  
  1045.      o    The file name is obtained by replacing dots in the unit name with
  1046.     minus signs, and adding a suffix distinguishing bodies and specs.
  1047.     The suffix for specs is ".ads" and for bodies is ".adb".
  1048.  
  1049.     For example, files containing the unit very_long_unit_name would be
  1050.         called:
  1051.  
  1052.         very_long_unit_name.ads
  1053.         very_long_unit_name.adb
  1054.  
  1055.     on systems supporting long file names.
  1056.  
  1057.      o    When running under systems which permit only short file names,
  1058.         (like DOS and OS/2 under FAT) the file name itself needs to be
  1059.         crunched to 8 characters. You can always find out the name it expects
  1060.  
  1061.     by running gnatk8 or compiling it (since it warns you if it's wrong).
  1062.  
  1063.         So in DOS or OS/2 under FAT the filenames above would be crunched to:
  1064.             velounna.ads
  1065.             velounna.adb
  1066.  
  1067.         (The full details of the crunching algorithm are in source code of
  1068.          krunch.ads and krunch.adb)
  1069.  
  1070.      Under DOS -gnatk8 is the default, so crunching always takes place.
  1071.      On all systems the RTL files are all crunched to 8 characters.
  1072.  
  1073. GNAT specific pragmas and attributes
  1074. ------------------------------------
  1075.  
  1076. Full documentation of the GNAT specific pragmas and attributes can be found
  1077. in the file features which is included in all releases of GNAT.
  1078.  
  1079. pragma Source_File_Name
  1080. -----------------------
  1081.  
  1082. The source file name pragma allows a program to override the normal
  1083. naming convention. It is a configuration pragma, and so has the usual
  1084. applicability of configuration pragmas (i.e. it applies to either an
  1085. entire partition, or to all units in a compilation, or to a single
  1086. unit, depending on how it is used. The form of the pragma is:
  1087.  
  1088. pragma Source_File_Name (
  1089.     [UNIT_NAME =>] unit_NAME,
  1090.     [BODY_FILE_NAME | SPEC_FILE_NAME] => STRING_LITERAL)
  1091.  
  1092. The given unit name is mapped to the given file name. The identifier
  1093. for the second argument is required, and indicates whether this is
  1094. the file name for the spec or for the body.
  1095.  
  1096. Any number of Source_File_Name pragmas can be put in a file called
  1097. gnat.adc and will apply to compilations in the current directory.
  1098.  
  1099. Unless the extension of the filename is ".ads", ".adb", or ".ada",
  1100. you must prefix the filename with "-x ada" on the gcc command you
  1101. use to compile it.  That prefix applies to all subsequent filenames
  1102. on the command unless you disable it with "-x none".
  1103.  
  1104. Machine Code Insertions
  1105. -----------------------
  1106.  
  1107. Package Machine_Code provides machine code support as described in the
  1108. RM in two separate forms:
  1109.  
  1110.   Machine code statements, consisting of qualified expressions that
  1111.   fit the requirements of RM section 13.8.
  1112.  
  1113.   An intrinsic callable procedure, providing an alternative mechanism
  1114.   of including machine instructions in a subprogram.
  1115.  
  1116. The two features are similar, and both closely related to the mechanism
  1117. provided by the asm instruction in the GNU C cmpiler. Full understanding
  1118. and use of the facilities in this package requires understanding the asm
  1119. instruction as described in "Using and Porting GNU CC" by Richard Stallman.
  1120.  
  1121. Calls to the function Asm and the procedure Asm have identical semantic
  1122. restrictions and effects as described below.  Both are provided so that
  1123. the procedure call can be used as a statement, and the function call
  1124. can be used to form a code_statement.
  1125.  
  1126. The first example given in the GNU CC documentation is the C asm
  1127. instruction:
  1128.  
  1129.    asm ("fsinx %1 %0" : "=f" (result) : "f" (angle));
  1130.  
  1131. The equivalent can be written for GNAT as:
  1132.  
  1133.    Asm ("fsinx %1 %0",
  1134.         My_Float'Asm_Output ("=f", access),
  1135.         My_Float'Asm_Input  ("f",  angle));
  1136.  
  1137. The first argument to Asm is the assembler template, and is identical
  1138. to what is used in GNU CC. This string must be a static expression.
  1139.  
  1140. The second argument is the output operand list. It is either a single
  1141. Asm_Output attribute reference, or a list of such references enclosed
  1142. in parentheses (technically an array aggregate of such references).
  1143.  
  1144. The Asm_Output attribute denotes a function that takes two parameters.
  1145. The first is a string, the second is the name of a variable of the type
  1146. designated by the attribute prefix. The first (string) argument is
  1147. required to be a static expression and designates the constraint for
  1148. the parameter (e.g. what kind of register is required). The second
  1149. argument is the variable to be updated with the result. The possible
  1150. values for constraint are the same as those used in the RTL, and are
  1151. dependent on the configuration file used to build the GCC back end.
  1152.  
  1153. If there are no output operands, then this argument may either be
  1154. omitted, or explicitly given as No_Output_Operands.
  1155.  
  1156. Note: the second argument of My_Float'Asm_Output functions as though
  1157. it were an OUT parameter, which is a little curious, but all names
  1158. have the form of expressions, so there is no syntactic irregularity,
  1159. even though normally functions would not be permitted OUT parameters.
  1160.  
  1161. The third argument is the list of input operands. It is either a single
  1162. Asm_Input attribute reference, or a list of such references enclosed
  1163. in parentheses (technically an array aggregate of such references).
  1164.  
  1165. The Asm_Input attribute denotes a function that takes two parameters.
  1166. The first is a string, the second is an expression of the type
  1167. designated by the prefix. The first (string) argument is required
  1168. to be a static expression, and is the constraint for the parameter,
  1169. (e.g. what kind of register is required). The second argument is the
  1170. value to be used as the input argument. The possible values for the
  1171. constrant are the same as those used in the RTL, and are dependent
  1172. on the configuration file used to built the GCC back end.
  1173.  
  1174. If there are no input operands, then this argument may either be
  1175. omitted, or explicitly given as No_Input_Operands.
  1176.  
  1177. The fourth argument, not present in the above example, is a list of
  1178. register names, called the "clobber" argument. This argument, if
  1179. given, must be a static string expression, and is a space or comma
  1180. separated list of names of registers that must be considered destroyed as
  1181. a result of the Asm call. If this argument is the null string (the default
  1182. value), then the code generator assumes that no additional registers are
  1183. destroyed.
  1184.  
  1185. The fifth argument, not present in the above example, called the "volatile"
  1186. argument, is by default False, it can be set to the literal value True to
  1187. indicate to the code generator that all optimizations with respect to the
  1188. instruction specified should be suppressed, and that in particular, for an
  1189. instruction that has outputs, the instruction will still be generated, even
  1190. if none of the outputs are used. See the full description in the GCC manual
  1191. for further details.
  1192.  
  1193. The Asm subprograms may be used in two ways. First the procedure forms can
  1194. be used anywhere a procedure call would be valid, and correspond to what the
  1195. RM calls "intrinsic" routines. Such calls can be used to intersperse machine
  1196. instructions with other Ada statements.
  1197.  
  1198. Second, the function forms, which return a (dummy) value of the
  1199. limited private type Asm_Insn, can be used in code statements,
  1200. and indeed this is the only context where such calls are allowed.
  1201. Code statements appear as aggregates of the form:
  1202.  
  1203.    Asm_Insn'(Asm ( .....));
  1204.    Asm_Insn'(Asm_Volatile (....));
  1205.  
  1206. In accordance with RM rules, such code statements are allowed only
  1207. within subprograms whose entire body consists of such statements.
  1208. It is not permissible to intermix such statements with other Ada
  1209. statements.
  1210.  
  1211. Typically the form using intrinsic procedure calls is more convenient
  1212. and more flexible. The code statement form is provided to meet the
  1213. RM suggestion that such a facility should be made available.
  1214.  
  1215. The following is the exact syntax of the call to asm (of course if named
  1216. notation is used, the arguments may be given in arbitrary order, following
  1217. the normal rules for use of positional and named arguments)
  1218.  
  1219.   ASM_CALL ::= asm (
  1220.                    [Template =>] static_string_EXPRESSION
  1221.                  [,[Outputs  =>] OUTPUT_OPERAND_LIST      ]
  1222.                  [,[Inputs   =>] INPUT_OPERAND_LIST       ]
  1223.                  [,[Clobber  =>] static_string_EXPRESSION ]
  1224.                  [,[Volatile =>] static_boolean_EXPRESSION] )
  1225.  
  1226.   OUTPUT_OPERAND_LIST ::=
  1227.     No_Output_Operands
  1228.   | OUTPUT_OPERAND_ATTRIBUTE
  1229.   | (OUTPUT_OPERAND_ATTRIBUTE {,OUTPUT_OPERAND_ATTRIBUTE})
  1230.  
  1231.   OUTPUT_OPERAND_ATTRIBUTE ::=
  1232.     SUBTYPE_MARK'Asm_Output (static_string_EXPRESSION, NAME)
  1233.  
  1234.   INPUT_OPERAND_LIST ::=
  1235.     No_Input_Operands
  1236.   | INPUT_OPERAND_ATTRIBUTE
  1237.   | (INPUT_OPERAND_ATTRIBUTE {,INPUT_OPERAND_ATTRIBUTE})
  1238.  
  1239.   INPUT_OPERAND_ATTRIBUTE ::=
  1240.     SUBTYPE_MARK'Asm_Input (static_string_EXPRESSION, EXPRESSION)
  1241.  
  1242. Gnatk8.
  1243. -------
  1244.  
  1245. As mentioned in the previous section, gnatk8 can be used to find out what
  1246. the krunched name of a file should be when using the -k8 (-gnatk8) option.
  1247.  
  1248. The first argument can now be an Ada name with dots or it can be the Gnat
  1249. name of the unit where the dots representing child units or subunit are
  1250. replaced by hypens. The only confusion arises if a name ends .ads or
  1251. .adb, and we take this to be an extension if there are no other dots in the
  1252. name and the whole name is in lower case.
  1253.  
  1254. The second argument represents the length of the krunched name. The default
  1255. without any argument given is 8 characters. A length of zero stands for
  1256. unlimited, i.e. no chop except for system files which are always 8.
  1257.  
  1258. Examples:
  1259.    gnatk8 very_long_unit_name.ads       ---->  velounna.ads
  1260.    gnatk8 very_long_unit_name.ads 6     ---->  vlunna.ads
  1261.    gnatk8 very_long_unit_name.ads 0     ---->  very_long_unit_name.ads
  1262.    gnatk8 grandparent-parent-child.ads  ---->  grparchi.ads
  1263.    gnatk8 grandparent.parent.child      ---->  grparchi
  1264.  
  1265. Note:
  1266.    gnatk8 grandparent.parent.child.adb  -----> grpachad
  1267. Here the .adb at the end is taken as part of the unit name as explained in
  1268. one of the preceeding paragraphs above.
  1269.  
  1270. Compiling Files With Several Compilation Units.
  1271. -----------------------------------------------
  1272.  
  1273. GNAT can only deal with files that contain a single Ada compilation unit.
  1274. However, since it is an established style for certain types of programs
  1275. to contain more than one compilation in a file, such as in test suites,
  1276. a simple utility program, "gnatchop", is provided to preprocess the file
  1277. and split it several other files, one for each compilation unit.
  1278. gnatchop takes a filename with any extension. This name can basically
  1279. be anything.
  1280.  
  1281. Usage : gnatchop [-k] [-r] [-s] [-w] filename [directory]
  1282.  
  1283.   k         limit filenames to 8 characters
  1284.   r         generate source reference pragmas
  1285.   s         generate a compilation script
  1286.   w         overwrite existing filenames
  1287.   filename  source file
  1288.   directory directory to place split files (default is the current directory)
  1289.  
  1290. For example, assume archive contains package spec part1, package body
  1291. part1, package spec part2, package body part2.adb and subprogram part3 in
  1292. any sequence.
  1293.  
  1294. "gnatchop archive" will create five files in the current directory called
  1295. part1.ads, part1.adb, part2.ads, part2.adb, part3.adb. The optional directory
  1296. argument places all the split files in that directory rather than the current
  1297. directory. The directory must already exist otherwise gnatchop will reject it.
  1298.  
  1299. If at least one of the files to be split already exists, gnatchop will issue a
  1300. message and exit unless the -w flag is used to overwrite existing files.
  1301.  
  1302. The -r flag causes source reference pragmas to be generated at the start of
  1303. each file written. These pragmas will cause error message references and
  1304. debugging source information to refer back to the original unchopped files.
  1305. This is appropriate if you intend to maintain the program in unchopped form.
  1306.  
  1307. The -s flag generates a script which can be used to compile all the units
  1308. contained in the original source file.
  1309.  
  1310.   Suppose that you wanted to compile all the units contained in a given file
  1311.   called "archive" with some specific options like -gnatv, -O2 and -g. The
  1312.   gnatchop with -s option will generate a script with the appropriate
  1313.   extension depending on the the operating system. Then the script is
  1314.   invoked with the options following at the end as given below.
  1315.  
  1316.   gnatchop -s archive
  1317.   In Unix:  sh archive.sh -gnatv -O2 -g 
  1318.   In Dos :  archive.bat -gnatv -O2 -g
  1319.   In OS/2:  archive.cmd -gnatv -O2 -g
  1320.  
  1321. The -k flag krunches the names of the units to be 8 characters followed by the
  1322. ads or adb extension.
  1323.  
  1324. Currently, if you want to specify more than one flag, you need to specify
  1325. them separately.  For example, if you want to split archive.adb and specify
  1326. both the -s and the -w flags, type "gnatchop -s -w archive" instead of
  1327. "gnatchop -sw archive". This limitation will be lifted in the near future.
  1328.  
  1329. Note: gnatchop works fine for the case of a single compilation unit in a
  1330. file, and this is useful in dealing with files that do not have names
  1331. satisfying the GNAT naming requirements.
  1332.  
  1333. Cross Reference Tool.
  1334. ---------------------
  1335.  
  1336. The GNAT system provides a standalone tool, gnatf, which allows for
  1337. syntax and semantics checking without any code generation. This is
  1338. somewhat faster than using "gcc -gnatc". 
  1339.  
  1340. Note: the standard gnat options that do not concern code generation are
  1341.       still available in gnatf. However, they should not be preceeded by
  1342.       -gnat, so to do syntax only checking with gnatf, use `gnatf -s file.adb'
  1343.       not `gnatf -gnats file.adb'.
  1344.  
  1345. The real point of gnatf is that it contains a cross reference (xref)
  1346. tool.  The goal of the xref tool is:
  1347.  
  1348.  1. Give precise information about all declared entities
  1349.     (where they are defined and where they are used).
  1350.     This is particularly useful in the ada emacs mode
  1351.     that you will find with the distribution (see Ada Emacs
  1352.     Mode below).
  1353.  
  1354.  2. Emit warnings if an entity is defined but never used or
  1355.     a with clause is unnecessary, misplaced or redundant
  1356.     (more on this later).
  1357.  
  1358.  3. In the future this tool will be the backbone of a smart
  1359.     recompilation system which should reduce the number of
  1360.     recompilations in the event of minor source code
  1361.     modifications.
  1362.  
  1363. Usage : gnatf [-x[1-6]] files
  1364.  
  1365.   files The list of Ada source files to cross reference.
  1366.  
  1367. -x[1-6] The -x[1-6] flags control the amount of information given
  1368.         by the xref tool. Flags -x1 and -x2 control the level of
  1369.         warnings generated. These warnings are output on standard
  1370.         error (usually the screen). Flags -x1 and -x2 do not cause
  1371.         any cross reference information to be generated.
  1372.         Flags -x[345] distribute cross reference information across
  1373.         several files. Specifically for each file "f.adb" (resp. "f.ads")
  1374.         in the `files' list we create a file "f.xrb" (resp. "f.xrs")
  1375.         containing all cross reference information (more on this below).
  1376.     Flag -x6 centralizes and stores this information in the single
  1377.         file "X.ref".
  1378.  
  1379. Flags usage:
  1380.  
  1381.   -x1       Issues warnings for unnecessary, misplaced or redundant
  1382.             ``with'' clauses. Specifically, a warning message is
  1383.             generated in the following cases:
  1384.  
  1385.               - A compilation unit which is withed but never used
  1386.                 (this works with child library units as well).
  1387.  
  1388.               - A compilation unit which is withed in a body (resp.
  1389.                 subunit) if the same with clause already appears in
  1390.                 the spec (resp. spec or body for subunits).
  1391.  
  1392.               - A compilation unit which is withed within a spec
  1393.                 but is used only by the body or a subunit.
  1394.  
  1395.   -x2       Issues warnings on unused entities, that is entities that
  1396.             are declared but never used. Note that we give *no*
  1397.             warnings for unreferenced entities like:
  1398.  
  1399.               - Record fields, since they could be referenced indirectly
  1400.                 by an aggregate.
  1401.  
  1402.               - Enumeration entities, since they could be referenced
  1403.                 indirectly by enumeration ranges:
  1404.                      for i in Color'First .. Color'Last
  1405.  
  1406.               - Loop parameters
  1407.                     for I in 1 .. 80 loop
  1408.                        Put ('x');
  1409.                     end loop;
  1410.  
  1411.   -x[345]   Generate cross-reference information. Flag -x3 gives the most
  1412.             succinct xref information, -x5 the most comprehensive. Flag -x4
  1413.             gives more information than -x3 but not as much as -x5. The
  1414.             information given by flags -x3 and -x4 will be used in the smart
  1415.             recompilation system currently under development and will
  1416.             be described hereafter. Flag -x5 lists all entities defined or
  1417.             used in the analyzed compilation units. It gives the source
  1418.             location of their definition and all their uses in the analyzed
  1419.             units.
  1420.  
  1421.   -x6       The cross reference output is the same as with -x5 except that
  1422.             with -x6 all cross reference information is stored in the single
  1423.             file "X.ref" and the entity kind of each cross referenced entity
  1424.             is also given.
  1425.  
  1426. Cross reference information and smart recompilation
  1427.  
  1428.   The cross reference information gathered by flags -x3 and -x4 is a
  1429.   subset of the information specified by flag -x5. The -x[34]
  1430.   information is specifically tailored to the smart recompilation system
  1431.   currently under development.  When flags -x3 or -x4 are selected, then
  1432.   for each compilation unit "Unit" analyzed by the xref tool we gather
  1433.   the following information:
  1434.  
  1435.     * The full graph of the source files directly or indirectly loaded as
  1436.       a result of compiling "Unit" along with their time stamp. This graph
  1437.       includes the with-ed unit graph rooted at "Unit" but contains also
  1438.       other units automatically loaded by gnat during code generation
  1439.       (generic bodies, subunits, bodies of inlined subprograms). This graph
  1440.       is created only for flags -x[345].
  1441.  
  1442.     * The list of entities that can be exported from "Unit" to other Ada
  1443.       sources along with their line and column of definition and use in
  1444.       "Unit".
  1445.  
  1446.       If "Unit" is a subprogram or package spec, the notion of exported
  1447.       entity matches the set of entities listed therein. If "Unit" is a
  1448.       package body with no generics or inlined subprograms then no entities
  1449.       are exported. In general, however, the set of entities exported from
  1450.       "Unit" is the set of entities that are needed across compilation units
  1451.       by gnat when generating code. Specifically inlined subprogram bodies
  1452.       or generic bodies are always exported since these are inlined at the
  1453.       point of use or instantiation. The same happens for subunits, which are
  1454.       inlined in the parent unit.
  1455.  
  1456.       The difference between flags -x3 and -x4 is that -x3 omits all
  1457.       generic bodies or inlined subprograms from the exported entities,
  1458.       while flag -x4 includes them. Both -x3 and -x4 consider subunits as
  1459.       exported entities.
  1460.  
  1461.       In addition we only consider outermost visible entities to be
  1462.       exported. That is a record or enumeration type may be exported but its
  1463.       inner fields or enumeration literals are never considered exported
  1464.       entities. Likewise for subprogram parameters and discriminants.
  1465.  
  1466.     * The list of entities *directly* imported by "Unit" from other Ada
  1467.       sources, along with their lines and columns where they are used in
  1468.       "Unit".
  1469.  
  1470.       The notion of imported entities falls off the notion of exported
  1471.       entities (what is exported by one unit may be imported by another).
  1472.  
  1473. Cross reference file structure:
  1474.  
  1475.   The xref file is divided into various sections. There is one section
  1476.   for each compilation unit explicitly requested in `files'. We
  1477.   call these units, the RUs, short for requested units.  There is also
  1478.   one section for each AU, short for auxiliary unit, that is, those
  1479.   compilation units that get implicitly loaded by the compiler, but
  1480.   whose compilation has not been explicitly requested by the user.
  1481.   Specs of withed packages are typical auxiliary units.
  1482.  
  1483.   All entities exported by RUs (flags -x3 and -x4) or all entities
  1484.   belonging to RUs (flags -x5 and -x6) appear in the xref file(s).
  1485.  
  1486.   However, only the entities defined in AUs that are imported in RUs
  1487.   appear in the xref file. Their order is the order of declaration in
  1488.   the source files.
  1489.  
  1490.   The sections in the xref referring to RUs and AUs are respectively denoted:
  1491.  
  1492.             %% unit.ad[sb]     for a RU.
  1493.  
  1494.             -- unit.ad[sb]     for an AU.
  1495.  
  1496.   Note: An entitiy defined inside a generic and used through a generic
  1497.   instantiation, is listed under the xref section of the generic unit.
  1498.  
  1499.   Example: Follows a list of files and the corresponding cross reference.
  1500.   ^^^^^^^
  1501.                         test.adb
  1502.                         ^^^^^^^^
  1503.             01  with Part1;  --  unused
  1504.             02  with Part2; use Part2;
  1505.             03  procedure Test is
  1506.             04
  1507.             05     Thing : Number;
  1508.             06     type Client is record
  1509.             07        Number : Integer;
  1510.             08        State  : Boolean;
  1511.             09     end record;
  1512.             10     type Color is (Red, Green);  -- unused
  1513.             11     My_Client : Client;
  1514.             12
  1515.             13  begin
  1516.             14     My_Client.Number := 1;
  1517.             15     My_Client.State  := True;
  1518.             16     Thing := 20;
  1519.             17     Thing := Thing + Thing;
  1520.             18  end;
  1521.                       part1.ads
  1522.                ^^^^^^^^^
  1523.             01  package Part1 is
  1524.             02     type Useless is new Integer;
  1525.             03  end;
  1526.                       part2.ads
  1527.                   ^^^^^^
  1528.             01  package Part2 is
  1529.             02     type Number is new Integer range 1 .. 1000;
  1530.             03     The_Number : constant := 42;
  1531.             04  end;
  1532.  
  1533.   The result of invoking `gnatf -x5 test.adb' is the following
  1534.   (just skim the "test.xrb", explanations follow):
  1535.  
  1536.                     Warnings on stderr (the screen)
  1537.                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  1538.              test.adb:1:06: warning: "Part1" withed but unused.
  1539.              test.adb:3:11: warning: "Test" unused
  1540.              test.adb:10:09: warning: "Color" unused
  1541.  
  1542.                            test.xrb
  1543.                            ^^^^^^^^
  1544.              01 V "SGNAT v1.0      "
  1545.              02 test.adb                941012154746 2 3 
  1546.              03 part1.ads               941012154531 
  1547.              04 part2.ads               941012154620 
  1548.              05 
  1549.              06 %% test.adb
  1550.              07 test 3:11 
  1551.              08 thing 5:4 
  1552.              09  {16:4 17:4 17:13 17:21}
  1553.              10 client 6:9 
  1554.              11  {11:16}
  1555.              12 client.number 7:7 
  1556.              13  {14:14}
  1557.              14 client.state 8:7 
  1558.              15  {15:14}
  1559.              16 color 10:9 
  1560.              17 red 10:19 
  1561.              18 green 10:24 
  1562.              19 my_client 11:4 
  1563.              20  {14:4 15:4}
  1564.              21 
  1565.              22 -- part1.ads
  1566.              23 part1 1:9 
  1567.              24  {1:6}
  1568.              25 
  1569.              26 -- part2.ads
  1570.              27 part2 1:9 
  1571.              28  {2:6 2:17}
  1572.              29 number 2:9 
  1573.              30  {5:14}
  1574.  
  1575.   Explanations:
  1576.   ^^^^^^^^^^^^
  1577.   File "Test" is the only RU (requested unit). AUs (auxiliary
  1578.   units are packages "Part1" and "Part2". First the graph of
  1579.   the loaded units with their time stamps is given
  1580.  
  1581.              02 test.adb                941012154746 2 3 
  1582.              03 part1.ads               941012154531 
  1583.              04 part2.ads               941012154620 
  1584.  
  1585.   Unit "Test" requires the loading of units "Part1" and "Part2"
  1586.   (the second and third units listed in the inclusion graph).
  1587.   Entry:
  1588.              06 %% test.adb
  1589.              07 [...]
  1590.              08 thing 5:4 
  1591.              09  {16:4 17:4 17:13 17:21}
  1592.  
  1593.   means that "Thing" is an entity (a variable) defined in line 5
  1594.   column 4 and used in line 16 column 4, line 17 columns 4, 13 and 21
  1595.   in file "test.adb". 
  1596.  
  1597.   Note that entity "Useless" may be used in units other than "Test"
  1598.   but that information is not contained in the "test.xrb" since "Test"
  1599.   does not use "Useless".
  1600.  
  1601. Implementation of Intrinsic Functions.
  1602. --------------------------------------
  1603. GNAT version 1.79 begins to implement intrinsic functions. In particular,
  1604. the shift functions predefined in Interfaces are now implemented.
  1605.  
  1606. The implementation is quite general. You can define shift operations (i.e.
  1607. one of the five operations, Shift_Left, Shift_Right, Shift_Right_Arithmetic,
  1608. Rotate_Left, Rotate_Right) on any integer type, signed or unsigned, whose
  1609. Size is 8, 16, 32 or 64 bits, and then provide an appropriate pragma Import
  1610. Intrinsic, and everything will work.
  1611.  
  1612. In other words, the package Interfaces is not using any special magic, and
  1613. you can do exactly what it does to make shift operations available for any
  1614. integer types that meet the size criteria (shift operations for wierd-sized
  1615. integers seem too marginal to worry about!)
  1616.  
  1617. Example:
  1618.  
  1619.    type My_Type is new Integer;
  1620.  
  1621.    function Shift_Left (Val : My_Type; Count : Natural) return My_Type;
  1622.    pragma Import (Intrinsic, Shift_Left);
  1623.  
  1624. The exact requirements on the pragma Import are as follows:
  1625.  
  1626.   The function must have one of the five standard names
  1627.  
  1628.   There must be two arguments
  1629.  
  1630.   The first argument can be of any integer type with a size of 8, 16, 32, 64
  1631.   either signed or unsigned.
  1632.  
  1633.   The return type must be the same as the first argument type
  1634.  
  1635.   The second argument (the shift count), can be of any integer type
  1636.  
  1637. Getting Internal Debugging Information.
  1638. ---------------------------------------
  1639.  
  1640. Most compilers have secret internal debugging switches and modes. GNAT is
  1641. no exception, except that nothing about GNAT is secret. A summary and full
  1642. description of all the compiler/binder debug flags can be found in the file
  1643. debug.adb. You will have to get the sources of the compiler to see the full
  1644. detailed effects of these, but feel free to experiment with them.
  1645.  
  1646. The switches that print the source of the program (reconstructed from the
  1647. internal tree) are of general interest, as are the options to print the full
  1648. internal tree, and the entity table (that is to say, the symbol table
  1649. information). 
  1650.  
  1651. GNAT Trouble-Shooting. 
  1652. ----------------------
  1653.  
  1654. There are several things you can do when GNAT does the unexpected while
  1655. compiling your Ada program, such as aborting with a segmentation fault or
  1656. illegal memory access, raising an internal exception, or otherwise
  1657. terminating abnormally. The following strategies are presented in increasing
  1658. order of difficulty, corresponding to the sophistication of the user, and her
  1659. curiosity about the functioning of the compiler.
  1660.  
  1661.   1. run gcc with the -gnatf and -gnate switches.
  1662.      The 'f' switch causes all errors on a given line to be reported. In
  1663.      its absence, only the first error on a line is displayed. 
  1664.  
  1665.      The 'e' switch causes errors to be displayed as soon as they are 
  1666.      encountered, rather than after compilation is terminated.
  1667.  
  1668. Often this will be enough to identify the construct that produced the crash.
  1669.  
  1670.   2. run gcc with -v (verbose) switch. In this mode, gcc produces ongoing 
  1671.      information about progress of the compilation and in particular the name 
  1672.      of each procedure as it begins to generate code for it. This switch
  1673.      allows you to find which Ada procedure it was compiling when it ran into 
  1674.      a code generation problem. 
  1675.  
  1676.   3. run gcc with the -gnatdc switch. This is a GNAT-specific switch that
  1677.      does for the front-end what -v does for the back-end. The system prints
  1678.      the name of each unit, either compilation unit or nested unit, as it
  1679.      is being analyzed. 
  1680.  
  1681.   4. On systems that have gdb available (like most Unix systems), you can run
  1682.      gdb directly on the gnat1 executable. Gnat1 is the front-end of
  1683.      GNAT, and can be run independently (normally it is just called from gcc).
  1684.      You can use gdb on gnat1 as you would on a C program (but see below for
  1685.      caveats). The "where" command is the first line of attack; the variable
  1686.      "lineno"  (seen by "print lineno") used by the second phase of gnat1
  1687.      and by the gcc back-end, indicates the source line at which the execution
  1688.      stopped, and "input_filename" the name of the source file.
  1689.  
  1690. Using gdb
  1691. ---------
  1692.  
  1693. Gdb has been modified to handle most of Ada properly. Forthcoming Gdb
  1694. releases will be ada-aware. For the time being the distribution contains the
  1695. appropriate gdb patches (for more info send an e-mail to
  1696. report@gnat.com). Note that you can still debug your Ada programs by using
  1697. Gdb, even if you have not yet installed the `Ada aware' Gdb patches provided
  1698. you use the standard C syntax in Gdb and use the following naming conventions
  1699. to find the Ada entities defined in your program:
  1700.  
  1701. a)  The names of all entities (variables, subprograms, etc.) are converted to
  1702.     lower case. 
  1703.  
  1704. b)  Entities that appear in library package declarations have the name
  1705.     package_name__subprogram_name (Note the two underscores separating 
  1706.     package name from subprogram name). 
  1707.  
  1708. Exceptions can be caught by breaking in the "__gnat_raise" routine and then
  1709. doing a "bt" or "where" command.
  1710.  
  1711. PERFORMANCE CONSIDERATIONS
  1712. --------------------------
  1713.  
  1714. The GNAT system provides a number of options that allow a trade off between
  1715.  
  1716.    o  performance of the generated code
  1717.    o  speed of compilation
  1718.    o  minimization of dependencies and recompilation
  1719.    o  degree of runtime checking
  1720.  
  1721. The defaults if no options are selected are aimed at improving the speed
  1722. of compilation and minimizing dependences at the expense of performance
  1723. of the generated code:
  1724.  
  1725.    o  no optimization
  1726.    o  no inlining of subprogram calls
  1727.    o  all runtime checks enabled except overflow and elaboration checks
  1728.  
  1729. These options are suitable for most program development purposes. This
  1730. section of the documentation describes how these options can be modified.
  1731.  
  1732. Runtime Checks
  1733. --------------
  1734.  
  1735. The default is to include all runtime checks except arithmetic overflow
  1736. checking for integer operations (including division by zero), and checks
  1737. for access before elaboration on subprogram calls.
  1738.  
  1739. Two gcc switches allow this default to be modified:
  1740.  
  1741.   -gnatp     
  1742.  
  1743.     This switch suppresses all runtime checks. This will improve the
  1744.     performance of the code at the expense of safety in the presence
  1745.     of invalid data or program bugs.
  1746.  
  1747.   -gnato
  1748.  
  1749.     This switch enables overflow checking for integer operations and checks
  1750.     for access before elaboration on subprogram calls. This will generate
  1751.     slower and larger executable programs.
  1752.  
  1753. Our experience is that the default is suitable for most development purposes.
  1754. The reason that we treat integer overflow and elaboration checks specially is
  1755. that these are quite expensive, and in our experience are not so important as
  1756. other runtime checks in the development process. 
  1757.  
  1758. Note that the setting of the switches controls the default setting of the
  1759. checks. They may be modified using either Suppress (to remove checks) or
  1760. Unsuppress (to add back suppressed checks) pragmas in the program source.
  1761.  
  1762. Optimization Levels
  1763. -------------------
  1764.  
  1765. The default is optimization off. This results in the fastest compile times,
  1766. but GNAT makes absolutely no attempt to optimize, and the generated programs
  1767. are considerably larger and slower. The switch
  1768.  
  1769.    -On
  1770.  
  1771. where n is an integer from 0 to 3, can be used on the GCC command to control
  1772. the optimization level:
  1773.  
  1774.    -O0    no optimization (the default)
  1775.  
  1776.    -O1    medium level optimization
  1777.  
  1778.    -O2    full optimization
  1779.  
  1780.    -O3    full optimization, and also attempt automatic inlining of small
  1781.           subprograms within a unit (see next section for further details).
  1782.  
  1783. The penalty in compilation time, and the improvement in execution time, both
  1784. depend on the particular application and the hardware environment. You should
  1785. experiment to find the best level for your application.
  1786.  
  1787. Note: unlike the case with some other compiler systems, GCC has been tested
  1788. extensively at all optimization levels. There are some bugs which appear only
  1789. with optimization turned on, but there have also been bugs which show up only
  1790. in unoptimized code. Selecting a lower level of optimization does not improve
  1791. the reliability of the code generator, which in practice is highly reliable
  1792. at all optimization levels.
  1793.  
  1794. Inlining of Subprograms
  1795. -----------------------
  1796.  
  1797. A call to a subprogram in the current unit is inlined if all the following
  1798. conditions are met:
  1799.  
  1800.     o  The optimization level is at least -O1
  1801.  
  1802.     o  The called subprogram is suitable for inlining. It must be
  1803.        small enough and not contain nested subprograms or anything
  1804.        else that GCC cannot support in inlined subprograms.
  1805.  
  1806.     o  The call occurs after the definition of the body of the subprogram.
  1807.  
  1808.     o  Either pragma Inline applies to the subprogram, or it is very small
  1809.        and automatic inlining (optimization level -O3) is specified.
  1810.  
  1811. Calls to subprograms in with'ed units are normally not inlined. To achieve
  1812. this level of inlining, the following conditions must be true.
  1813.  
  1814.     o  The optimization level is at least -O1
  1815.  
  1816.     o  The called subprogram is suitable for inlining. It must be
  1817.        small enough and not contain nested subprograms or anything
  1818.        else that GCC cannot support in inlined subprograms.
  1819.  
  1820.     o  The call appears in a body (not in a package spec).
  1821.  
  1822.     o  There is a pragma Inline for the subprogram
  1823.  
  1824.     o  The -gnatn switch is used in the GCC command line
  1825.  
  1826. Note that specifying the -gnatn switch causes additional compilation
  1827. dependencies. Consider the following:
  1828.  
  1829.  
  1830.    package R is
  1831.      procedure Q;
  1832.      pragma Inline Q;
  1833.    end R;
  1834.  
  1835.    package body R is
  1836.      ...
  1837.    end R;
  1838.  
  1839.    with R;
  1840.    procedure Main is
  1841.    begin
  1842.      ...
  1843.      R.Q;
  1844.    end Main;
  1845.  
  1846. With the default behavior (no -gnatn switch specified), the compilation of
  1847. the Main procedure depends only on its own source, main.adb, and the spec
  1848. of the package in file r.ads. This means that editing the body of R does
  1849. not require recompiling Main.
  1850.  
  1851. On the other hand, the call R.Q is not inlined under these circumstances. If
  1852. the -gnatn switch is present when Main is compiled, then the call will be
  1853. inlined if the body of Q is small enough, but now Main depends on the body
  1854. of R in r.adb as well as the spec. This means that if the body is edited,
  1855. then the main program must be recompiled. Note that this extra dependency
  1856. occurs whether or not the call is in fact inlined by GCC.
  1857.  
  1858. Note: the GCC switch -fno-inline can be used to prevent all inlining. This
  1859. switch overrides all other conditions, and ensures that no inlining occurs.
  1860. The extra dependencies resulting from -gnatn will still be active, even if
  1861. the -fno-inline switch is used.
  1862.  
  1863. New WARNING messages related to accessibility checks and private packages
  1864. -------------------------------------------------------------------------
  1865.  
  1866. GNAT version 2.05 implements two new checks that we anticipate will cause
  1867. some problems to existing programs.
  1868.  
  1869. First, static accessibility checks are implemented. These catch two common
  1870. errors:
  1871.  
  1872.    Improper use of 'Access attribute. These can usually be "corrected" by
  1873.    the use of 'Unchecked_Access in the variable case, but good Ada style
  1874.    says that the use of 'Unchecked_Access should be restricted, just like
  1875.    the use of Unchecked_Conversion. Unchecked_Access can lead to dangling
  1876.    pointers, and at the least careful analysis is needed.
  1877.  
  1878.    The invalid use of 'Access for subprograms is harder to fix in a
  1879.    "legitimate" manner. GNAT provides the 'Unrestricted_Access attribute
  1880.    that can be applied to subprograms in defiance of the accessibility
  1881.    rules (e.g. to create downward closures), but this attribute is not
  1882.    portable, and, as described by Bob Duff "naughty". So think twice at
  1883.    least before casually "fixing" your problem this way. Dangling
  1884.    subprogram pointers are particularly unpleasant. Another alternative
  1885.    is to use a generic, and pass the subprogram as a generic formal
  1886.    subprogram.
  1887.  
  1888.    The other common error is the derivation of a tagged type at a deeper
  1889.    nesting level than the parent type. This is also illegal (because it
  1890.    could cause dangling hidden subprogram pointers in dispatch tables).
  1891.    GNAT is not about to provide a way around this error, you must
  1892.    restructure your program. The simplest approach is to define all
  1893.    tagged types at the library level.
  1894.  
  1895.    Note in particular that all controlled types are derived from library
  1896.    level types, and so can only be declared at the library level. This is
  1897.    such a common case, that we have special-cased the error message.
  1898.  
  1899. The second new check is for the (mis)use of private packages. This caused
  1900. some unwelcome surprises in the GNAT code itself. Again, the only proper
  1901. remedy is to restructure (or possibly reconsider the use of private
  1902. packages). The critical rule is that specs cannot with a private package
  1903. unless they are themselves private.
  1904.  
  1905. We are thinking of introducing a pragma that would provide some protection
  1906. for withing packages that are not intended to be public, but are needed in
  1907. specs, stay tuned!
  1908.  
  1909. Meanwhile, in version 2.05, these error messages are warnings, but take care,
  1910. they are really illegalities, and in 2.06 they will be changed to be error
  1911. messages instead of warnings, so you have one version to clean up your act
  1912. with respect to accessibility and private packages!
  1913.  
  1914. Features supported/unsupported
  1915. ------------------------------
  1916.  
  1917. A full listing of features supported/unsupported is available separately in
  1918. the file "features" included in the distribution. Note that this usually
  1919. changes with each distribution, so read often.
  1920.  
  1921. Files.
  1922. ------
  1923.  
  1924. If you want to examine the workings of the GNAT system, the following
  1925. haiku-like description of its organization might be of minimal use:
  1926.  
  1927. File with prefix "sc" contain the lexical scanner.
  1928.  
  1929. All files prefixed with "par" are components of the parser. The numbers 
  1930. correspond to chapters of the Ada 83 LRM (or the corresponding sections of 
  1931. the Ada 95 LRM).  For example, parsing of select statements can be found 
  1932. in par-ch9.
  1933.  
  1934. All files prefixed with "sem" perform semantic analysis. Same numbering scheme.
  1935. For example, all issues involving context clauses can be found in sem_ch10.
  1936.  
  1937. All files prefixed with "exp" perform AST normalization and expansion. 
  1938. For example, the construction of record initialization procedures is 
  1939. done in exp_ch3.
  1940.  
  1941. The files prefixed with "bind" implement the binder, which verifies the
  1942. consistency of the compilation, determines an order of elaboration, and
  1943. generates the bind file.
  1944.  
  1945. The file atree details the low-level data structures used by the front-end.
  1946. The file sinfo details the structure of the AST as produced by the parser.
  1947. The file einfo details the attributes of all entities, computed during
  1948. semantic analysis.
  1949.  
  1950. Library management issues are dealt with in files with prefix "lib".
  1951.  
  1952. Files with prefix a- are GNAT-specific C files. They are the components of
  1953. Gigi (gnat-to-gnu), the program that translates the Ada AST into gcc tree 
  1954. fragments. Gigi makes use of C versions of atree, einfo and sinfo, called 
  1955. a-atree.[ch], a-einfo.[ch] and a-sinfo.h respectively.
  1956.  
  1957. All the other .c files are modifications of common GCC files. 
  1958.  
  1959. Happy browsing!
  1960.  
  1961. Ada Mode for Emacs
  1962. ------------------
  1963.  
  1964. In the subdirectory `emacs-ada-mode' you will find a bunch of files
  1965. implementing an Ada mode under Gnu emacs. The mode is still under
  1966. development, but a number of features are complete. For instance, the
  1967. Ada mode has the same indenting friendliness that C programmers get
  1968. with the c-mode, you can toggle between spec and body with a few
  1969. keystrokes, etc. This mode also uses gnatf to be able to point to an
  1970. entity with the mouse, click it and open a window with its definition.
  1971. This mode is copywrited by Markus Heritsch and Rolf Ebert.
  1972.  
  1973. Copyright Considerations
  1974. ------------------------
  1975.  
  1976. Everything is copyrighted using the GNU public license. This means that you
  1977. can copy everything freely, but you can't incorporate the code directly
  1978. into a commercial program. For more information on the GNU license,
  1979. see the file header. One important note is that it is possible to use
  1980. GNAT to generate software that is not itself covered by the GNU license.
  1981. This is because all library and runtime units are covered by a modified
  1982. version of the GPL which explicitly permits this use.
  1983.  
  1984. Submitting Bug Reports
  1985. ======================
  1986.  
  1987. We welcome bug reports, they are of course a vital part of the process of
  1988. getting GNAT into solid shape. You will help us (and make it more likely
  1989. that you receive a timely response) if you follow these guidelines. We
  1990. try to process all bug reports from both users supported by Ada Core
  1991. Technologies, and from unsupported users. Naturally supported users have
  1992. our priority attention, so we cannot guarantee any specific response for
  1993. unsupported users.
  1994.  
  1995. We only receive bug reports by internet, addressed to report@gnat.com.
  1996. At the moment we cannot process bug reports from any other source.
  1997.  
  1998. Note: if you believe you have found a GCC (C language or configuration
  1999. file) bug rather than an GNAT (Ada language) bug please report it to
  2000. bug-gcc@prep.ai.mit.edu.  If you have found a bug when using GCC to
  2001. compile C++, please report it to bug-g++@prep.ai.mit.edu.
  2002.  
  2003. Please put one bug in a message, and add a short but specific subject (a
  2004. general subject like "GNAT bug" is not so useful, a title like "bug in
  2005. visibility with generics" is more useful).
  2006.  
  2007. Please include full sources. We can't duplicate errors without the full
  2008. sources. Include all sources in the single email message with appropriate
  2009. indications in the multiple file cases, see below.
  2010.  
  2011. Please send all sources in plain ASCII form, we can't process compressed,
  2012. uuencoded etc. messages in our current form (they have to go through extra
  2013. steps, and easily get lost, separated from the author etc during this process).
  2014.  
  2015. Please include COMPLETE identification of the version of the system you are
  2016. running.
  2017.  
  2018. To be maximally helpful, for a report that contains multiple separate
  2019. compilation units, and hence multiple files, submit them in the form of
  2020. a single file that is acceptable input to gnatchop (used to be called gnatsplit
  2021. on versions of GNAT prior to 1.80), i.e. contains no non-Ada text. If you use
  2022. banners to separate the files, make sure they are composed entirely of blank
  2023. lines or Ada comments.
  2024.  
  2025. If you want to be maximally helpful, try to reduce your example to a simple one
  2026. but DON'T spend too much time doing this. Especially when you are reporting
  2027. a blow up during compilation, rather than bad code generated, we can in 
  2028. practice work with big sources if you have trouble narrowing things down.
  2029.  
  2030. If a bug involves incorrect operation of the generated code, then the first
  2031. thing the program should do is to output a line indicating the expected
  2032. output or behavior. If at all possible, do a test later on that prints
  2033. out "passed" or "failed" depending on the behavior. Of course it may not
  2034. always be possible to structure a test this way, but that's the most 
  2035. convenient form (for obvious reasons!)
  2036.  
  2037. When we receive a bug report, we take a preliminary look to categorize it
  2038. into one of the following:
  2039.  
  2040.    1.  Pilot error, documentation problems, installation problems etc.
  2041.  
  2042.    2.  Interesting comment, suggestion etc, but not a bug
  2043.  
  2044.    3.  Bug that we already know about
  2045.  
  2046.    4.  Bug that is already fixed in our development version
  2047.  
  2048.    5.  Obvious bug that we correct immediately in our development version
  2049.  
  2050.    6.  Real genuine new unfixed bug.
  2051.  
  2052. In the first 5 cases, you will get a message telling you the status. In the
  2053. 6th case only, we assign a bug tracking number of the form mmdd-nnn, where
  2054. mmdd is the date of receipt, and nnn is a serial number (highest value so
  2055. far 005, but you never know!) In this case, the release notes will tell you
  2056. what the status of the bug is, and also we will send you a message when it
  2057. is fixed.
  2058.  
  2059. To send reports to us on the system, or ask questions, send messages to
  2060.  
  2061.     report@gnat.com
  2062.  
  2063. To contact team members, send messages to:
  2064.  
  2065.     banner@gnat.com
  2066.     comar@gnat.com
  2067.     cruz@gnat.com
  2068.     dewar@gnat.com
  2069.     dismukes@gnat.com
  2070.     kenner@gnat.com
  2071.     rupp@gnat.com
  2072.     schenker@gnat.com
  2073.     schonberg@gnat.com
  2074.  
  2075. or visit our home page at http://www.gnat.com
  2076.  
  2077. To obtain electronically the latest version of the system, FTP from:
  2078.  
  2079.     cs.nyu.edu (directory pub/gnat)
  2080.  
  2081. This FTP directory also includes full sources for the system, full
  2082. documentation and technical notes, as well as executables of the system
  2083. for several targets. We are sorry that our limited resources do not allow
  2084. us to distribute the system through other media.
  2085.  
  2086. We trust that this information will be mirrored at other FTP sites around 
  2087. the world (we encourage such mirroring to occur), which will make it easier
  2088. for users in other continents to obtain the GNAT system without heavy
  2089. communication uncertainties.
  2090.  
  2091. A short gnat paper
  2092. ------------------
  2093.  
  2094. A TeX file of a short paper describing something about the GNAT project is
  2095. included under the name gnatdoc1.tex.
  2096.  
  2097. Ada Information Resources On the Internet
  2098. ---------------------------------------
  2099.  
  2100. There is a wealth of Ada-related information available on the Internet.
  2101. The simplest way to access it is via a World Wide Web (WWW) browser
  2102. such as Mosaic or Netscape. Start up your browser and "open"
  2103. the following URLs that interest you:
  2104.  
  2105. http://www.gnat.com
  2106.   The home page of Ada Core Technologies, the maintainers of GNAT
  2107.  
  2108. http://lglwww.epfl.ch/Ada/
  2109.   The Ada WWW server in Lausanne, Switzerland; this server has
  2110.   a wealth of Ada-related information.
  2111.  
  2112. http://lglwww.epfl.ch/Ada/FAQ/comp-lang-ada.html
  2113.   Ada frequently-asked questions (FAQs).
  2114.  
  2115. http://lglwww.epfl.ch/Ada/Tutorials/Lovelace/lovelace.html
  2116.   Lovelace, a free interactive Ada 95 tutorial.
  2117.  
  2118. http://lglwww.epfl.ch/Ada/Resources/Books/Textbooks.html
  2119.   An annotated list of Ada-oriented textbooks.
  2120.  
  2121. http://wuarchive.wustl.edu/languages/ada/
  2122.   The Public Ada Library (PAL); this contains lots of software.
  2123.  
  2124. http://sw-eng.falls-church.va.us/
  2125.   The Ada Information Clearinghouse.
  2126.  
  2127. http://www.acm.org/sigada/
  2128.   The Association for Computing Machinery (ACM)'s SIGAda home page.
  2129.  
  2130. There is also a newsgroup, comp.lang.ada, specifically
  2131. dedicated to Ada.
  2132.