From: Lucretia on 9 May 2007 10:37 Hi, I started to implement the Ada/CS from the Crafting a compiler in C book. I was doing this from scratch, but I decided that I'd rather implement a real subset using the real rules from the standard. So, now I'm looking into implementing an Ada 2005 subset. I don't want to get into a flamewar over reasons why/not to do this, I'd just like to do it ;D and not have this thread go massively off topic ;) Ok, here are my aims, in no particular order: * Similar Ada/CS subset, but based on the Ada 2005 standard. * Use ANTLR for the front-end. * Restrict the input to ASCII. * Use LLVM for the back-end. * Also look into writing a back end from scratch (not a priority and only for experience). * Allow the use of multiple compilation units in 1 operating system file. * Also allow GNAT *.ad[sb] files. * Experiment with libraries. I've read some older threads from 1994-1995 which cover how older compilers implemented a repository based Ada standard library in which compilations units were added to. But I'm interested in seeing how I can get the compiler to not have to reparse other source files (when with'd) in order to compile a unit. Also, I'd like to see how static/shared libraries can be implemented/ used to extend the Ada standard library. I don't want to have to have tons of source files lying around for a static/shared library, I honestly don't see the need. Surely, it's possible to build a compiler that can get the information it needs from the library itself (or at least a companion library rather than a ton of different ALI files)? Now, I'd really like to hear from people who have implemented an Ada compiler and people who have used other compilers (I've only used GNAT). Basically, I'm interested in how other implementations handle the library. Note that there are 2 ideas of library here: 1) The standard Ada library. 2) Link/shared libraries found on operating systems. Thanks, Luke.
From: Dmitry A. Kazakov on 9 May 2007 12:51 On 9 May 2007 07:37:31 -0700, Lucretia wrote: > I've read some older threads from 1994-1995 which cover how older > compilers implemented a repository based Ada standard library in which > compilations units were added to. > > But I'm interested in seeing how I can get the compiler to not have to > reparse other source files (when with'd) in order to compile a unit. Why should it? Certainly, you would have some intermediate representation which includes symbolic tables and other stuff the compiler creates after semantic analysis before code generation. A compiled library unit will have this stored in some appropriate format. An interesting issue is cross-platform library units, I was playing with this idea, but came to no conclusion. > Also, I'd like to see how static/shared libraries can be implemented/ > used to extend the Ada standard library. I don't think it is a good idea to mix Ada libraries and object/dynamic-linking libraries, at least in existing OS'es. In some OO OS with advanced containers it could work. But still, these are two different abstraction levels. Object code is too close to the hardware. The library units should probably be kept on the other side. > I don't want to have to have > tons of source files lying around for a static/shared library, I > honestly don't see the need. Surely, it's possible to build a compiler > that can get the information it needs from the library itself (or at > least a companion library rather than a ton of different ALI files)? Or a database, for that matter... > Now, I'd really like to hear from people who have implemented an Ada > compiler and people who have used other compilers (I've only used > GNAT). Basically, I'm interested in how other implementations handle > the library. Note that there are 2 ideas of library here: > > 1) The standard Ada library. > 2) Link/shared libraries found on operating systems. I remember RSX-11 in which macro and object libraries were handled by the same librarian tool. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de
From: Lucretia on 9 May 2007 13:21 On May 9, 5:51 pm, "Dmitry A. Kazakov" <mail...(a)dmitry-kazakov.de> wrote: > > But I'm interested in seeing how I can get the compiler to not have to > > reparse other source files (when with'd) in order to compile a unit. > > Why should it? Certainly, you would have some intermediate representation > which includes symbolic tables and other stuff the compiler creates after > semantic analysis before code generation. A compiled library unit will have > this stored in some appropriate format. True, but is it possible to include dependency info within the object itself? > An interesting issue is cross-platform library units, I was playing with > this idea, but came to no conclusion. LLVM would be capable of this. > > Also, I'd like to see how static/shared libraries can be implemented/ > > used to extend the Ada standard library. > > I don't think it is a good idea to mix Ada libraries and > object/dynamic-linking libraries, at least in existing OS'es. In some OO OS > with advanced containers it could work. But still, these are two different > abstraction levels. Object code is too close to the hardware. The library > units should probably be kept on the other side. Why? Are you saying that it would be better to store libraries in IR rather than binary form? For a linux based compiler (for example) you still need to be able to link with binary libs, and I do think it's necessary to be able to build a shared lib with an Ada compiler - this would not be possible with IR, unless the whole OS worked in this way. > > I don't want to have to have > > tons of source files lying around for a static/shared library, I > > honestly don't see the need. Surely, it's possible to build a compiler > > that can get the information it needs from the library itself (or at > > least a companion library rather than a ton of different ALI files)? > > Or a database, for that matter... Like the old Ada library? I was actually thinking, if I couldn't embed the other information required by the compiler into the final object, then a separate "lib" containing only this informaton would be necessary. > > Now, I'd really like to hear from people who have implemented an Ada > > compiler and people who have used other compilers (I've only used > > GNAT). Basically, I'm interested in how other implementations handle > > the library. Note that there are 2 ideas of library here: > > > 1) The standard Ada library. > > 2) Link/shared libraries found on operating systems. > > I remember RSX-11 in which macro and object libraries were handled by the > same librarian tool. RSX-11 is before my time, got any more info on this? Thanks, Luke.
From: Robert A Duff on 9 May 2007 16:48 Lucretia <lucretia9(a)lycos.co.uk> writes: > But I'm interested in seeing how I can get the compiler to not have to > reparse other source files (when with'd) in order to compile a unit. Presumably by storing information (symbol tables and whatnot) in permanent disk files. If you do that, I think you should design it as a _pure_ optimization. That is, the system should behave exactly as if everything is compiled from source every time, except that it's faster. Don't mimic the Ada 83 compilers that had a notion of "compiling things into the library", where a source file sitting right there in the source directory is ignored, unless "compiled into...". If you do this, you need to design a permanent (on disk) representation that is small. I think it's possible, but it's not easy -- the "obvious" representation of symbol tables will be 10 times larger than the source code. If it's 10 times larger, then it defeats the purpose -- reading it in from disk will be slower than re-analyzing the original source code. You also suggested storing the info in the object files. Yes, that is possible, given a reasonable object file format that allows arbitrary information to be stored, in addition to the actual machine code. Building a complete Ada implementation is a daunting task (many person-years). You said you're doing a subset of Ada 2005, and I assume you're doing this "just for fun". Keep your subset small, or you will never finish. - Bob
From: Gautier on 9 May 2007 17:15
Hello, You seem to look for a model where each unit compilation ands into a file that contains, roughly, the following information (with overlaps): - the specification, "digested" - the contents of the .ali file - unit dependencies - time stamps to check need of recompilations - the compiled code (the .o object file itself). This model exists and works fine (esp., less files and a way faster compilation!), it is the one of Turbo Pascal's .TPU files (~1988...) and its descendants (TPW, Delphi). You just have to take a close look at it. No need to reinvent anything... ______________________________________________________________ Gautier -- http://www.mysunrise.ch/users/gdm/index.htm Ada programming -- http://www.mysunrise.ch/users/gdm/gsoft.htm NB: For a direct answer, e-mail address on the Web site! |