fab.tools.compiler#
This file contains the base class for any compiler, and derived classes for gcc, gfortran, icc, ifort
Classes
|
This is the base class for a C compiler. |
|
This is the base class for any compiler. |
|
This is the base class for a Fortran compiler. |
|
Class for GNU's gcc compiler. |
|
Class for GNU's gfortran compiler. |
|
Class for the Intel's icc compiler. |
|
Class for Intel's ifort compiler. |
- class fab.tools.compiler.Compiler(name, exec_name, suite, category, compile_flag=None, output_flag=None, omp_flag=None)#
This is the base class for any compiler. It provides flags for
compilation only (-c),
naming the output file (-o),
OpenMP
- Parameters:
name (
str
) – name of the compiler.exec_name (
Union
[str
,Path
]) – name of the executable to start.suite (
str
) – name of the compiler suite this tool belongs to.category (
Category
) – the Category (C_COMPILER or FORTRAN_COMPILER).compile_flag (
Optional
[str
]) – the compilation flag to use when only requesting compilation (not linking). (default:None
)output_flag (
Optional
[str
]) – the compilation flag to use to indicate the name of the output file (default:None
)omp_flag (
Optional
[str
]) – the flag to use to enable OpenMP (default:None
)
- compile_file(input_file, output_file, add_flags=None)#
Compiles a file. It will add the flag for compilation-only automatically, as well as the output directives. The current working directory for the command is set to the folder where the source file lives when compile_file is called. This is done to stop the compiler inserting folder information into the mod files, which would cause them to have different checksums depending on where they live.
- check_available()#
Checks if the compiler is available. While the method in the Tools base class would be sufficient (when using –version), in case of a compiler we also want to store the compiler version. So, re-implement check_available in a way that will automatically store the compiler version for later usage.
- Return type:
- Returns:
whether the compiler is available or not. We do this by requesting the compiler version.
- get_version()#
Try to get the version of the given compiler. # TODO: why return “” when an error happened? # TODO: we need to properly create integers for compiler versions # to (later) allow less and greater than comparisons.
Expects a version in a certain part of the –version output, which must adhere to the n.n.n format, with at least 2 parts.
- Returns:
a version string, e.g ‘6.10.1’, or empty string if a different error happened when trying to get the compiler version.
- Raises:
RuntimeError – if the compiler was not found.
- class fab.tools.compiler.CCompiler(name, exec_name, suite, compile_flag=None, output_flag=None, omp_flag=None)#
This is the base class for a C compiler. It just sets the category of the compiler as convenience.
- Parameters:
name (
str
) – name of the compiler.exec_name (
str
) – name of the executable to start.suite (
str
) – name of the compiler suite.category – the Category (C_COMPILER or FORTRAN_COMPILER).
compile_flag – the compilation flag to use when only requesting compilation (not linking). (default:
None
)output_flag – the compilation flag to use to indicate the name of the output file (default:
None
)omp_flag – the flag to use to enable OpenMP (default:
None
)
- class fab.tools.compiler.FortranCompiler(name, exec_name, suite, module_folder_flag, syntax_only_flag=None, compile_flag=None, output_flag=None, omp_flag=None)#
This is the base class for a Fortran compiler. It is a compiler that needs to support a module output path and support for syntax-only compilation (which will only generate the .mod files).
- Parameters:
name (
str
) – name of the compiler.exec_name (
str
) – name of the executable to start.suite (
str
) – name of the compiler suite.module_folder_flag (
str
) – the compiler flag to indicate where to store created module files.syntax_only_flag – flag to indicate to only do a syntax check. The side effect is that the module files are created. (default:
None
)compile_flag – the compilation flag to use when only requesting compilation (not linking). (default:
None
)output_flag – the compilation flag to use to indicate the name of the output file (default:
None
)omp_flag – the flag to use to enable OpenMP (default:
None
)
- set_module_output_path(path)#
Sets the output path for modules.
- Params path:
the path to the output directory.
- compile_file(input_file, output_file, add_flags=None, syntax_only=False)#
Compiles a file.
- class fab.tools.compiler.Gcc(name='gcc', exec_name='gcc')#
Class for GNU’s gcc compiler.
- class fab.tools.compiler.Gfortran(name='gfortran', exec_name='gfortran')#
Class for GNU’s gfortran compiler.
- class fab.tools.compiler.Icc(name='icc', exec_name='icc')#
Class for the Intel’s icc compiler.