Development of a Fortran 90 to C compiler 
Author Message
 Development of a Fortran 90 to C compiler

After taking a course on compilers last fall, I got interested in
writing a fortran 90/95 to C compiler.

The major F90 features handled are user defined types, modules,
and optional arguments to subroutines.  There's no array operations,
but that's next on my list of features to implement.
There is almost no I/O plus many other deficiencies, making it
unsuitable for real programs yet.

I've only tested in under Linux 2.0 with lex and bison, but it should
port easily to other OS's..

The URL is
http://www.*-*-*.com/ ~mdewing/f90toC/

Mark Dewing



Sat, 30 Sep 2000 03:00:00 GMT  
 Development of a Fortran 90 to C compiler


Quote:
>After taking a course on compilers last fall, I got interested in
>writing a Fortran 90/95 to C compiler.
>The URL is
>http://www.ncsa.uiuc.edu/~mdewing/f90toC/

     Interesting.  Does it produce cleaner C thatn "f2c"?

     I'd like to see:

        Smart conversion of array indices from 1-based to 0-based.
        "f2c" just adjusts the base address of the array so 1-based
        indices will work.  This could be done better.  In general,
        subscripts like "TAB(I)" should translate into "tab[i-1]"
        Loops like "DO 100 I=1,100" should translate into
        "for (iminus1=0, iminus1<100; iminus1++)", and should
        the value of "i" actually be needed, it should be computed
        when needed.  This leads to subscript expressions like
        "tab[iminus1+1-1]", which should be optimized before the
        C code is generated.  

        It would also be helpful to have a hint to the translator
        that says "represent this variable as value-1".  You use this
        when an index is passed to a subroutine.

        This would be great for numeric codes.  Readable C would come out.
        Anyone want to put this in "f2c?

                                        John Nagle



Tue, 03 Oct 2000 03:00:00 GMT  
 Development of a Fortran 90 to C compiler

Quote:

>      Interesting.  Does it produce cleaner C thatn "f2c"?

>      I'd like to see:

>    Smart conversion of array indices from 1-based to 0-based.
>    "f2c" just adjusts the base address of the array so 1-based
>    indices will work.  This could be done better.  In general,
>    subscripts like "TAB(I)" should translate into "tab[i-1]"
>    Loops like "DO 100 I=1,100" should translate into
>    "for (iminus1=0, iminus1<100; iminus1++)", and should
>    the value of "i" actually be needed, it should be computed
>    when needed.  This leads to subscript expressions like
>    "tab[iminus1+1-1]", which should be optimized before the
>    C code is generated.  

No, I don't think so.  f2c's primary purpose is to produce neither
optimal nor "clean" (in the sense of human-readable), but working C
code.  If you care about speed, you can use a "more native" Fortran
compiler, like g77.

BTW: Nobody prevents you to use (gasp!) 0-based arrays in Fortran!
(I do this quite often).

Quote:
>    It would also be helpful to have a hint to the translator
>    that says "represent this variable as value-1".  You use this
>    when an index is passed to a subroutine.

NO!  f2c converts *(obsolete) standard Fortran 77* to C, so any of
these hints would be non-portable.

Quote:
>    This would be great for numeric codes.  Readable C would come out.
>    Anyone want to put this in "f2c?

Why in the world do you want to maintain f2c's output instead of its
input?

BTW: AFAIR, some time ago there was some NAG tool to make NAG's f90
output more readable.  (I couldn't compile it on Linux, as it seemed
to require the lex library).  But it is quite likely that one can use
it to also clean up the output of F.

To the original poster: Please go ahead, and keep things simple!
Maybe your work could inspire people how to enhance the free g77
compiler to get a g90 someday...

--
Ciao,
-ha

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
        Harald Anlauf           | Phone:    +49-6151-16-2972 (office)
        TH Darmstadt            |           +49-6151-370157 (private)
        Institut f. Kernphysik  | Fax:      +49-6151-16-2421


        Germany                 |           (PGP public key available)



Tue, 03 Oct 2000 03:00:00 GMT  
 Development of a Fortran 90 to C compiler

Quote:


> >After taking a course on compilers last fall, I got interested in
> >writing a Fortran 90/95 to C compiler.

> >The URL is
> >http://www.ncsa.uiuc.edu/~mdewing/f90toC/

>      Interesting.  Does it produce cleaner C thatn "f2c"?

>      I'd like to see:

>         Smart conversion of array indices from 1-based to 0-based.
>         "f2c" just adjusts the base address of the array so 1-based
>         indices will work.  This could be done better.  In general,
>         subscripts like "TAB(I)" should translate into "tab[i-1]"
>         Loops like "DO 100 I=1,100" should translate into
>         "for (iminus1=0, iminus1<100; iminus1++)", and should
>         the value of "i" actually be needed, it should be computed
>         when needed.  This leads to subscript expressions like
>         "tab[iminus1+1-1]", which should be optimized before the
>         C code is generated.

This is actually how the translated output works (execpt it uses
pointers rather than arrays)
And it does output things like *(tab +iminus1 + 1 -1).
For now I'm hoping that the C compiler is smart enough to optimize
such an expression.
Anyway the main goal is correct code, not fast code.

Mark Dewing



Fri, 06 Oct 2000 03:00:00 GMT  
 Development of a Fortran 90 to C compiler


Quote:


>> >After taking a course on compilers last fall, I got interested in
>> >writing a Fortran 90/95 to C compiler.
>> >The URL is
>> >http://www.ncsa.uiuc.edu/~mdewing/f90toC/

>>      Interesting.  Does it produce cleaner C thatn "f2c"?

>>      I'd like to see:

>>         Smart conversion of array indices from 1-based to 0-based.
>>         "f2c" just adjusts the base address of the array so 1-based
>>         indices will work.  This could be done better.  In general,
>>         subscripts like "TAB(I)" should translate into "tab[i-1]"
>>         Loops like "DO 100 I=1,100" should translate into
>>         "for (iminus1=0, iminus1<100; iminus1++)", and should
>>         the value of "i" actually be needed, it should be computed
>>         when needed.  This leads to subscript expressions like
>>         "tab[iminus1+1-1]", which should be optimized before the
>>         C code is generated.

>This is actually how the translated output works (execpt it uses
>pointers rather than arrays)
>And it does output things like *(tab +iminus1 + 1 -1).
>For now I'm hoping that the C compiler is smart enough to optimize
>such an expression.
>Anyway the main goal is correct code, not fast code.

     That should be optimized OK.  But it's better to output
tab[foo] than *(tab+foo).  Then "tab" can be converted to
a collection class if needed.

     My interest is that I need to port some medium-sized FORTRAN numeric
code to C++, then work on it, making it more object-oriented, reentrant,
and adding exception handling.  So I need clean C++ out.  See
"www.animats.com" for what I'm doing: physical simulation for high-end
animation.

                                        John Nagle
                                        Animats



Fri, 06 Oct 2000 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. fortran iv using fortran 90 compiler

2. Fortran 77 code using Fortran 90 compiler

3. DEC Fortran 90 -> SGI Fortran 90

4. Fortran 90 compiler performance benchmark project

5. About Fortran 90 compilers in Linux

6. looking for free fortran 90 compiler for PCs

7. Sun Fortran 90 compiler error or not?

8. Compiler Test Suite Updated for Intel Fortran 90/95 for Linux

9. fortran 90 compiler for linux RH 7.3

10. fortran 90 compilers

11. Auto parallelization option for fortran 90 compiler

 

 
Powered by phpBB® Forum Software