Using the Code Generator

The basic workflow for using the code generator is detailed below, and can be summarised as:

  1. Make some change to the code to be generated, either by modifying the JSON configuration files or by modifying templates or even the generator library itself.
  2. Run the generator.
  3. Integrate the generated source code into the main Fortran library.

Defining the code to be generated

What the code generator produces can be controlled either by configuration files, or modifying the generator itself. Modifying configuration files is covered in Adding New Operators or Intrinsic Functions.

Running the generator

The generator can be run from the top-level directory using the Makefile:

make -C generator

This will produce 4 files in the directory generator/generated/:

  • interface_operators.i: interface blocks for overloaded operators.
  • implementation_operators.f90: overloaded operator implementations.
  • interface_intrinsics.i: interface blocks for overloaded intrinsic functions.
  • implementation_intrinsics.f90: overloaded intrinsic function implementations.

Despite the file extensions, all 4 files contain Fortran code, the extensions are simply part of a naming convention.

Integrating generated code into the Fortran library

Once you have generated new files, you will want to integrate the generated code into the main Fortran library.

Warning

Make sure you carefully check the generated code is correct before proceeding. It is worthwhile looking at both the generator output, and the difference between each output and the existing file in src/include/, for example:

diff generated/implementation_operators.f90 src/include/implementation_operators.f90

This way you can be sure that you have achieved the change you wanted without changing something else you didn’t expect to change.

To integrate the generated code all you need to do is copy/move the generated files from generator/generated/ to src/include/:

cp generator/generated/* src/include/

Once you have done this you should rebuild the library:

make clean
make

Now you can run the tests and verify that the new code works as expected:

cd tests
make test