home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / ada / 3309 < prev    next >
Encoding:
Text File  |  1992-11-19  |  12.9 KB  |  266 lines

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