G95-XML Homepage

Philippe Marguinaud

G95-XML provides a fortran parser based on the well known g95 ( by Andy Vaught, see g95 website ). The original g95 parser has been modified to output not only all the exact semantics of any Fortran 95 program in XML, but also the layout of the source code. G95-XML brings in the power of a real Fortran compiler for source code analysis.

The aim is to be able to analyse any Fortran code, and provide capabilities to inspect Fortran code, modify Fortran source code, generate new code, interface automatically with other languages, etc...

  1. What has been achieved so far ?
  2. How does it work ?
  3. Source code browser
  4. Howto
  5. Download
  6. Acknowledgements

1. What has been achieved so far ?

2. How does it work ?

The XML output of the g95-xml parser, though describing very acurately Fortran code is pretty hard to deal with. I have written Perl scripts to handle its output and make something usable out of it.

The approach I used was to write scripts so that I could reproduce a compiling environment; therefore, g95-xml provides scripts named f95, ar, ld. All these Perl scripts behave like a Fortran compiler and associated binary management utilities.

For instance, parsing a Fortran source file named main.f90 is just the matter of typing ( assuming g95-xml's f95, ar, ld are in your PATH ):

$ f95 -c -html -keep-xml main.f90
$ ls -l main.* 
-rw-rw-r-- 1 phi001 phi001    50 avr 26 19:42 main.f90
-rw-r--r-- 1 phi001 phi001 24576 avr 26 19:49 main.o
-rw-r--r-- 1 phi001 phi001  5075 avr 26 19:49 main.xml

The command we issued produced an XML file containing the full description of our source code, and a .o file which contains the table of global symbols of main.f90 and a frozen Perl structure which has been re-built from the XML.

The -html option was added to generate HTML code for this Fortran unit; it is embedded in the .o file.

Hence you see that you can parse your Fortran code using the Makefile ( or a more elaborate build system ) you have already written.

3. Source code browser

The Fortran source browser has been designed to work under Apache+mod_perl. However, I have managed to adapt it to work with CGI and provide a little demo on sourceforge. Below is a list of Fortran modules ( provided by fortran.com ) which have been compiled with g95-xml. Almost all Fortran entities ( even operators ) are clickable. Note that if you click on a local variable holding Ctrl+Shift, you will get the Perl object reconstructed from XML. Block starting and ending keywords are clickable too ( for instance `do i = 1, n' has a clickable `do' ).
big_integer_module.f95Source XML Browse
celf.f90Source XML Browse
gen_ll.f90Source XML Browse
integer_set.f90Source XML Browse
iso_varying_string.f95Source XML Browse
kiss.f90Source XML Browse
qsort_c.f95Source XML Browse
quick_sort1.fSource XML Browse
quick_sort2.fSource XML Browse
random1.fSource XML Browse
random2.fSource XML Browse
roman_numerals.f90Source XML Browse
unix_time.fSource XML Browse

Please note that the Apache+mod_perl browser is much more easier to use; its possible to browse executables and libraries as well. In fact, it is possible to configure Apache so that a particular handler takes care of some requests ( and let others to the standard Apache webserver ). I use this feature so that regular files and directories be served directly by Apache, and .exe, .o, .a files be processed by a dedicated handler.

4. Howto

You can download the howto here.

5. Download

You can download the latest version of g95-xml here.

6. Acknowledgements

I would like to express my gratitude to Andy Vaught, who wrote a very nice piece of software and allowed everybody to use it and access its source code.