From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,362cb73a2f180232 X-Google-Attributes: gid103376,public From: vsnyder@vanpcjpl.nasa.gov (Van Snyder) Subject: Re: How does GNAT (or GCC) compile ADA code? Date: 1998/10/22 Message-ID: <70lttj$mrp@netline.jpl.nasa.gov>#1/1 X-Deja-AN: 403747204 Content-Transfer-Encoding: 7bit Sender: vsnyder@vanpc (Van Snyder) References: <707h7o$cvl$1@nnrp1.dejanews.com> Content-Type: text/plain; charset=US-ASCII Organization: Jet Propulsion Laboratory - Pasadena CA Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 1998-10-22T00:00:00+00:00 List-Id: In article <707h7o$cvl$1@nnrp1.dejanews.com>, dennison@telepath.com writes: > In article , > asmang@mail.wm.edu (Arun Mangalam) wrote: > > I don't really know how GCC is the backend for GNAT. Does gcc translate > > Ada code into c and then compile c into machine language, or is it from > > Ada code directly to machine language code? I'm just curious, and since I > > don't have gcc installed, I was wondering if someone can either explain > > this or direct me to a place where I can find this out for myself. Thank > > you for any help. > > Most compilers don't translate source directly into machine code. Instead they > first translate the source code into a very low-level (yes, even lower-level > than C :-) ) intermediate form that is somewhat machine-independent. Most > optimizations then get performed on that intermediate code. In the final step > the "backend" of the compiler translates the intermediate form into the > appropriate machine code for the target cpu. > > All forms of gcc, including gnat, gnu fortran, gnu pascal, etc. do this. One > of the nice things about this approach is that it makes porting easier. Only > the back-end code generator needs to be changed to port the compiler to a new > architecture. It also makes it easier to create new compilers, as multiple > compilers can use the same back-end. > > So here's what gnat does. It converts (translates, compiles, whatever term > you prefer) Ada source code into the special intermediate form that the gcc > backend understands. Then it has the gcc backend do optimizations and machine > code generation. Does the gcc backend understand that C and C++ pointers can point _anywhere_, while Ada and Fortran 90 pointers are quite disciplined? The important consequence of this observation is that optimization becomes possible. The inability to optimize pointers is the primary reason that C and C++ programs are generally slower than equivalent Fortran 90 programs. To my knowledge, there are no Fortran 90 compilers that use the gcc backend. -- What fraction of Americans believe | Van Snyder Wrestling is real and NASA is fake? | vsnyder@math.jpl.nasa.gov