home *** CD-ROM | disk | FTP | other *** search
/ Solo Programadores 22 / SOLO_22.iso / docs / misc / old / progress.n92 < prev    next >
Encoding:
Text File  |  1996-04-29  |  12.0 KB  |  243 lines

  1.  
  2.              GNAT Project
  3.             GNU-NYU Ada Translator.
  4.  
  5.            GNAT Report 0001-921101
  6.  
  7.               November 1, 1992
  8.  
  9. 1. Introduction.
  10. ----------------
  11.  
  12. This is the first summary of activities of the project since its official
  13. start in July 1992. The goal of the project is the construction of a portable
  14. Ada9X compiler, based on the following three components: 
  15.  
  16. a) The very successful GCC back-end. 
  17.  
  18. b) The Ada/Ed front-end and tasking library.
  19.  
  20. c) The Ada9X extensions developed by the Implementation Analysis Team
  21. (i.e. the NYUADA project) itself) as part of the Ada9X project.  
  22.  
  23. We will demonstrate some of the running portions of the system at the 
  24. Triada92 conference this month in Orlando. To sum up: the parser is complete,
  25. the semantic analyzer handles basic declarations, subprograms and packages,
  26. the tree transformer can process basic declarations and statement forms, all
  27. of which makes it possible to execute very simple programs. We are on
  28. schedule to demonstrate most of the Ada9X functionality at the Ada/Europe
  29. conference in June 1993, and to demonstrate a fully bootstrapped system in
  30. December 1993, which is the end date of the project. 
  31.  
  32. We have focused much of our work on the design and implementation of 
  33. convenient abstract interfaces between phases of the compiler. This is
  34. one of the obvious benefits of the use of Ada, but we were struck by the way
  35. in which the language forced us in this direction, and led us to complete
  36. and polished interfaces first. A small testimonial to the extent to which
  37. the language can influence good design.
  38.  
  39. II. System overview.
  40. --------------------
  41.  
  42. The GNAT system includes the following modules:
  43.  
  44. a) A scanner and parser, written in Ada 83. The parser produces an abstract
  45. syntax tree with sufficient information to reproduce exactly the source
  46. program (including token placement).
  47.  
  48. b) A semantic analyzer, which annotates the AST with type information,
  49. performs name and overload resolution, and a large number of legality
  50. checks. The output of the semantic analyzer is the annotated AST. This
  51. phase is written in Ada 83 as well.
  52.  
  53. c) A tree transformer that traverses the AST and constructs a semantically
  54. equivalent tree, which is input to the GCC back end. This phase is written
  55. in C. Communication between semantics and transformation is by means of a
  56. file (at least conceptually).
  57.  
  58. d) An enhanced GCC back end, which emits all required constraint checks
  59. and recognizes all instructions that may raise hardware exceptions. 
  60.  
  61. e) A library manager. To maximize compatibility with the current library
  62. model of GCC, no separate library file is created, but all necessary library
  63. information is stored directly in .o files, and recreated when needed by
  64. the library manager. We retain the basic principle that the compilation of
  65. one source file produces one object file. This is not a conventional model
  66. for Ada systems, but it will simplify the construction of mixed-language
  67. systems, and will look very familiar to the Unix community.  The library
  68. manager is written in Ada.
  69.  
  70. f) An Ada-specific binder that assembles subunits, performs late inlining
  71. and generic instantiations, and removes unnecessary access-before-elaboration
  72. checks. This is written in Ada.
  73.  
  74. g) A run-time system, whose main components are: tasking, I/O, and exception
  75. handling. Most of this is written in Ada.
  76.  
  77. The following sections detail the design and current status of each of these.
  78.  
  79. III. The Scanner/Parser.
  80. ------------------------
  81.  
  82. The scanner/parser is complete. We have no performance figures yet, but
  83. it appears to be (when compiling itself) more than an order of magnitude
  84. faster than the previous Ada/Ed parser. The current parser derives from 
  85. an Ada 83 syntax checker written by R.B.K.D in assembly language, whose
  86. awesome performance was of the order of 1,000,000 lines/min on a 16 Mz 386.
  87. Even without any more precise figures, we are confident that this will not 
  88. be the bottleneck of the system!
  89.  
  90. The parser uses recursive descent and has an elaborate error recovery
  91. mechanism, which includes heuristics to make use of program indentation
  92. (on the reasonable assumption that most programmers use indentation to
  93. reflect significant aspects of the nesting structure of their program). 
  94. The parser produces almost no cascaded errors on all the ACVC B-tests,
  95. and seems to recover as well as the previous LALR parser of Ada/Ed.
  96. The parser includes an Ada83 switch. Note however that we have no plans
  97. of producing a complete Ada 83 system: our goal is Ada 9X, and we are
  98. NOT starting with an Ada 83 subset.  
  99.  
  100. IV. The Abstract Syntax Tree.
  101. -----------------------------
  102.  
  103. The Scanner/Parser produces an AST and a names table. The low-level details
  104. of the data-structure are hidden by means of a procedural interface, which
  105. includes a retrieval procedure for each non-terminal in the language. All
  106. these retrieval procedures are intended to be inlined, but currently they
  107. include copious tracing and debugging information. In the interest of
  108. efficiency, we have chosen to use very simple data structures to describe the
  109. AST (for example, we make no use of discriminated records) and the code
  110. includes a significant amount of internal consistency checks (essentially,
  111. a small but strategically placed collection of discriminant checks). Some
  112. future version of GNAT, written in Ada 9X, might display an agressive
  113. use of tagged types and type extensions.
  114.  
  115. There is no separate symbol table. Each defining identifier (i.e. the
  116. defining occurrence of a program entity) is annotated with semantic
  117. information, such as its type. Each use occurrence is made to point to the
  118. corresponding defining occurrence, after name resolution. The AST thus
  119. resembles a DIANA representation. Although we have not examined the question
  120. in full detail, it seems that our AST structure will support an ASIS package
  121. with very little effort.
  122.  
  123. Two packages provide interfaces to the AST: Syntax_Info describes the
  124. tree as it is produced by the parser, and Entity_Info describes the
  125. semantic annotations. Both of these interfaces are completely procedural:
  126. no indication of the actual layout of AST nodes is visible to any client of 
  127. front-end. To support the code of the tree transformer, which is written in
  128. C, there are C translations of these packages. The header files for these
  129. are produced automatically (by means of a SPITBOL program) to insure that
  130. they remain consistent with the Ada versions.
  131.  
  132. V. The Semantic Analyzer.
  133. -------------------------
  134.  
  135. The semantic analyzer performs several traversals of the AST, to produce
  136. semantic annotations, apply legality checks, and expand constructs whose
  137. direct translation into the GCC tree form would be awkward (e.g. aggregates). 
  138. The first (and largest) pass of the analyzer performs name, type and
  139. overload resolution, and collects most semantic attributes. This phase is
  140. being written following the general organization of the Ada/Ed front-end
  141. (the SETL version, which includes already such Ada9X features as tagged
  142. types and extensions, and generic formal packages).  We have chosen the
  143. following package structure for this phase: there is one package for each
  144. chapter of the Ada Reference manual, and one driver package. All chapter
  145. packages are subunits of the driver. 
  146.  
  147. package Sem1 is                 -- Driver 
  148.     procedure Analyze (T: Node_ID);        -- top-level procedure.
  149.     package Sem2 is ...                -- pragma handling.
  150.     package Sem3 is ...                -- declarations and types.
  151.     ...
  152. end Sem1;
  153. package body Sem1 is
  154.     ...
  155.     package body Sem2 is separate.
  156.     package body Sem4 is separate.
  157.     ...
  158. end Sem1 ;
  159.     
  160. Use clauses in each proper body simplify the invocation of procedures
  161. that are used everywhere (for example, all packages use Sem4 and Sem8, but
  162. no one needs easy access to the contents of Sem11). 
  163.  
  164. As of 11/1, enough of Sem1, Sem3, Sem5, Sem6, Sem7, and Sem8 is written
  165. to handle scalar declarations and types, control structures, subprograms
  166. and calls, packages, and simple name resolution. The design of overload
  167. resolution data structures and algorithms is complete but not implemented
  168. yet. 
  169.  
  170. VI. The Tree transformer.
  171. -------------------------
  172.  
  173. The tree transformer performs the critical task of mapping the semantics
  174. the AST into the corresponding GCC tree, mimicking the actions of other
  175. GCC front-ends. This is done by traversing the AST and invoking tree
  176. constructors provided in GCC to  build tree fragments that are eventually
  177. assembled into the tree of one complete compilation unit. The traversal of
  178. the AST uses the procedural interfaces described above. The description of
  179. the GCC tree constructors can be found in the GCC documentation, and we will
  180. not say anything about it here, except to indicate that Ada-specific nodes
  181. have been added, to describe constraint checks on expressions and values.
  182. We expect to make a few additional extensions to the GCC tree, but we intend
  183. to keep them to a minimum. For example, the handling of in-out parameters
  184. is done currently by special casing single parameters and by constructing
  185. a record that is passed by reference in the case of multiple in-out parameters.
  186. This can be done without any modifications to the GCC tree structure.
  187.  
  188. On the other hand, semantic details that may be of use to other GCC
  189. languages will be implemented directly in the code generator. This is the
  190. case of exceptions for example, given that they will be used by C++ as well
  191. as Ada.
  192.  
  193. We explored (for the space of a week) the option of writing the transformer
  194. in Ada, with extensive use of the pragma INTERFACE to invoke the GCC
  195. tree constructors. In spite of the appeal of writing more of the system in
  196. Ada, we decided that this would lead to a system that would be exceedingly
  197. difficult to design cleanly, that would be hard to debug, and that would
  198. lead to messy heterogeneous structures.
  199. As of 11/1, the tree transformer can generate the GCC trees corresponding 
  200. to subprograms, simple control structures, and arithmetic expressions. 
  201.  
  202. VIII. The code generator.
  203. -------------------------
  204.  
  205. The GCC back end is of course the largest portion of the system. It includes
  206. a multi-pass retargetable code generator, and has been ported to more than
  207. 25 machines so far. It generates excellent code, comparable (and at times
  208. superior) to that of the best commercial compilers. The architectural
  209. details of each target are encapsulated in a machine description file that
  210. specifies precisely the semantics of all machine operations, in terms of a
  211. common register transfer language. In order to support Ada, the machine
  212. description formalism must be extended to specify more precisely the 
  213. relationship between instructions and exceptions. The code generator must
  214. respect Ada semantics and inhibit code motion where prohibited. Richard Kenner,
  215. the author of several GCC ports, and Richard Stallman, the creator of GCC,
  216. are designing these extensions. 
  217.  
  218. IX. The library manager.
  219. ------------------------
  220.  
  221. Design of the library manager is in its very early stages. We have decided
  222. that the information to be stored in object files is only that found in the
  223. AST, i.e. no GCC-generated information is ever preserved. This means that
  224. the GCC trees that correspond to package specifications appearing in a context
  225. clause are reconstructed rather than just retrieved. This corresponds to
  226. the standard handling of header files in C, and does not seem to be onerous
  227. (but once we have measurements we may change our minds!). Similarly, stack
  228. layout is recomputed as needed. This adds to the cost of compiling proper
  229. bodies of subunits, but given that the compilation of proper bodies requires
  230. reconstructing the visibility environment of the stub, all the declarations
  231. that are visible at the location of the stub must be reprocessed anyway. The
  232. advantage is that the library manager has deal only with one data structure,
  233. namely the AST.
  234.  
  235. VII.  The rest.
  236. ---------------
  237.  
  238. The design of the  binder and run-time system will be described in future
  239. reports. As portions of the system become more stable we will make public
  240. those interfaces that seem mature enough for external consumption.
  241.  
  242.  
  243.