comp.lang.ada
 help / color / mirror / Atom feed
* How does GNAT (or GCC) compile ADA code?
@ 1998-10-15  0:00 Arun Mangalam
  1998-10-16  0:00 ` dennison
  0 siblings, 1 reply; 5+ messages in thread
From: Arun Mangalam @ 1998-10-15  0:00 UTC (permalink / raw)


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.




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How does GNAT (or GCC) compile ADA code?
  1998-10-15  0:00 How does GNAT (or GCC) compile ADA code? Arun Mangalam
@ 1998-10-16  0:00 ` dennison
  1998-10-16  0:00   ` dewarr
  1998-10-22  0:00   ` Van Snyder
  0 siblings, 2 replies; 5+ messages in thread
From: dennison @ 1998-10-16  0:00 UTC (permalink / raw)


In article <asmang-1510981424440001@192.168.0.22>,
  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.

--
T.E.D.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How does GNAT (or GCC) compile ADA code?
  1998-10-16  0:00 ` dennison
@ 1998-10-16  0:00   ` dewarr
  1998-10-22  0:00   ` Van Snyder
  1 sibling, 0 replies; 5+ messages in thread
From: dewarr @ 1998-10-16  0:00 UTC (permalink / raw)


In article <707h7o$cvl$1@nnrp1.dejanews.com>,
  dennison@telepath.com wrote:
> In article <asmang-1510981424440001@192.168.0.22>,
>   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.


This is more or less correct, but is wrong in one important respect. The
intermediate form into which the Ada is translated for code generation is
in semantic terms certainly not lower level than C, and indeed in some
important respects, considerably higher semantic level than C (it has a
much more advanced type model for example).

Robert Dewar

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How does GNAT (or GCC) compile ADA code?
  1998-10-16  0:00 ` dennison
  1998-10-16  0:00   ` dewarr
@ 1998-10-22  0:00   ` Van Snyder
  1998-10-22  0:00     ` dennison
  1 sibling, 1 reply; 5+ messages in thread
From: Van Snyder @ 1998-10-22  0:00 UTC (permalink / raw)


In article <707h7o$cvl$1@nnrp1.dejanews.com>, dennison@telepath.com writes:
> In article <asmang-1510981424440001@192.168.0.22>,
>   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




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How does GNAT (or GCC) compile ADA code?
  1998-10-22  0:00   ` Van Snyder
@ 1998-10-22  0:00     ` dennison
  0 siblings, 0 replies; 5+ messages in thread
From: dennison @ 1998-10-22  0:00 UTC (permalink / raw)


In article <70lttj$mrp@netline.jpl.nasa.gov>,
  vsnyder@vanpcjpl.nasa.gov (Van Snyder) wrote:
> In article <707h7o$cvl$1@nnrp1.dejanews.com>, dennison@telepath.com writes:
> > 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.

I'm sure there are folks here much better aquainted with what the gcc backend
is capable of than myself. But as far as I understand it, the answer is *no*.
That is why if you hang out here long enough you are bound to here Robert
Dewar mention that a gcc compiled C executable should have little significant
difference from a gnat compiled Ada executable if the two perform the same
operations. If you know what you are doing, you can even make them produce
the exact same executables.

In theory that does mean gnat is missing out on a lot of extra optimization
it could be doing. In practice gcc already has very good (and certianly the
most thouroughly tested) optimization because of all the work that is done on
it for C code. Just getting a custom back-end up to gcc's level would be a
great deal of work.


--
T.E.D.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~1998-10-22  0:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-10-15  0:00 How does GNAT (or GCC) compile ADA code? Arun Mangalam
1998-10-16  0:00 ` dennison
1998-10-16  0:00   ` dewarr
1998-10-22  0:00   ` Van Snyder
1998-10-22  0:00     ` dennison

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox