pyccel.codegen package¶
Submodules¶
pyccel.codegen.cmake module¶
pyccel.codegen.codegen module¶
-
class
pyccel.codegen.codegen.
Codegen
(expr, name)[source]¶ Bases:
object
Abstract class for code generator.
-
ast
¶ Returns the AST.
-
body
¶ Returns the body of the source code, if it is a Program or Module.
-
classes
¶ Returns the classes if Module.
-
code
¶ Returns the generated code.
-
expr
¶ Returns the AST after Module/Program treatment.
-
imports
¶ Returns the imports of the source code.
-
interfaces
¶ Returns the interfaces.
-
is_module
¶ Returns True if a Module.
-
is_program
¶ Returns True if a Program.
-
kind
¶ Returns the kind of the source code: Module, Program or None.
-
language
¶ Returns the used language
-
modules
¶ Returns the modules if Program.
-
name
¶ Returns the name associated to the source code
-
routines
¶ Returns functions/subroutines.
-
variables
¶ Returns the variables of the source code.
-
pyccel.codegen.compiler module¶
-
class
pyccel.codegen.compiler.
Compiler
(codegen, compiler, flags=None, accelerator=None, binary=None, debug=False, inline=False, include=[], libdir=[], libs=[], ignored_modules=[])[source]¶ Bases:
object
Base class for Code compiler for the Pyccel Grammar
-
accelerator
¶ Returns the used accelerator
-
binary
¶ Returns the used binary
-
codegen
¶ Returns the used codegen
-
compiler
¶ Returns the used compiler
-
debug
¶ Returns True if in debug mode
-
flags
¶ Returns the used flags
-
ignored_modules
¶ Returns ignored modules
-
include
¶ Returns include paths
-
inline
¶ Returns True if in inline mode
-
libdir
¶ Returns lib paths
-
libs
¶ Returns libraries to link with
-
-
pyccel.codegen.compiler.
clean
(filename)[source]¶ removes the generated files: .pyccel and .f90
- filename: str
- name of the file to parse.
-
pyccel.codegen.compiler.
execute_file
(binary)[source]¶ Execute a binary file.
- binary: str
- the name of the binary file
-
pyccel.codegen.compiler.
get_extension
(language)[source]¶ returns the extension of a given language.
- language: str
- low-level target language used in the conversion
-
pyccel.codegen.compiler.
make_tmp_file
(filename, output_dir=None)[source]¶ returns a temporary file of extension .pyccel that will be decorated with indent/dedent so that textX can find the blocks easily.
- filename: str
- name of the file to parse.
- output_dir: str
- directory to store pyccel file
-
pyccel.codegen.compiler.
preprocess
(filename, filename_out)[source]¶ The input python file will be decorated with indent/dedent so that textX can find the blocks easily. This function will write the output code in filename_out.
- filename: str
- name of the file to parse.
- filename_out: str
- name of the temporary file that will be parsed by textX.
pyccel.codegen.utilities module¶
-
pyccel.codegen.utilities.
compile_fortran
(filename, compiler, flags, binary=None, verbose=False, modules=[], is_module=False, libs=[], output='')[source]¶ Compiles the generated file.
- verbose: bool
- talk more
-
pyccel.codegen.utilities.
construct_flags
(compiler, fflags=None, debug=False, accelerator=None, include=[], libdir=[])[source]¶ Constructs compiling flags for a given compiler.
- fflags: str
- Fortran compiler flags. Default is -O3
- compiler: str
- used compiler for the target language.
- accelerator: str
- name of the selected accelerator. One among (‘openmp’, ‘openacc’)
- debug: bool
- add some useful prints that may help for debugging.
- include: list
- list of include directories paths
- libdir: list
- list of lib directories paths
-
pyccel.codegen.utilities.
execute_pyccel
(filename, compiler=None, fflags=None, debug=False, verbose=False, accelerator=None, include=[], libdir=[], modules=[], libs=[], binary=None, output='')[source]¶ Executes the full process: - parsing the python code - annotating the python code - converting from python to fortran - compiling the fortran code.
pyccel.codegen.utilities_old module¶
-
pyccel.codegen.utilities_old.
build_cmakelists
(src_dir, libname, files, force=True, libs=[], programs=[])[source]¶
-
pyccel.codegen.utilities_old.
build_file
(filename, language, compiler, execute=False, accelerator=None, debug=False, lint=False, verbose=False, show=False, inline=False, name=None, output_dir=None, ignored_modules=['numpy', 'scipy', 'sympy'], pyccel_modules=[], include=[], libdir=[], libs=[], single_file=True)[source]¶ User friendly interface for code generation.
- filename: str
- name of the file to load.
- language: str
- low-level target language used in the conversion
- compiler: str
- used compiler for the target language.
- execute: bool
- execute the generated code, after compiling if True.
- accelerator: str
- name of the selected accelerator. One among (‘openmp’, ‘openacc’)
- debug: bool
- add some useful prints that may help for debugging.
- lint: bool
- uses PyLint for static verification, if True.
- verbose: bool
- talk more
- show: bool
- prints the generated code if True
- inline: bool
- set to True, if the file is being load inside a python session.
- name: str
- name of the generated module or program. If not given, ‘main’ will be used in the case of a program, and ‘pyccel_m_${filename}’ in the case of a module.
- ignored_modules: list
- list of modules to ignore (like ‘numpy’, ‘sympy’). These modules do not have a correspondence in Fortran.
- pyccel_modules: list
- list of modules supplied by the user.
- include: list
- list of include directories paths
- libdir: list
- list of lib directories paths
- libs: list
- list of libraries to link with
Example
>>> from pyccel.codegen import build_file >>> code = ''' ... n = int() ... n = 10 ... ... x = int() ... x = 0 ... for i in range(0,n): ... for j in range(0,n): ... x = x + i*j ... ''' >>> filename = "test.py" >>> f = open(filename, "w") >>> f.write(code) >>> f.close() >>> build_file(filename, "fortran", "gfortran", show=True, name="main") ========Fortran_Code======== program main implicit none integer :: i integer :: x integer :: j integer :: n n = 10 x = 0 do i = 0, n - 1, 1 do j = 0, n - 1, 1 x = i*j + x end do end do end ============================
-
pyccel.codegen.utilities_old.
build_testing_cmakelists
(src_dir, project, files, force=True, libs=[])[source]¶
-
pyccel.codegen.utilities_old.
construct_tree
(filename, ignored_modules)[source]¶ Constructs a tree of dependencies given a file to process.
-
pyccel.codegen.utilities_old.
execute_file
(binary)[source]¶ Execute a binary file.
- binary: str
- the name of the binary file
-
pyccel.codegen.utilities_old.
generate_project_conf
(srcdir, project, **settings)[source]¶ Generates a conf.py file for the project.
-
pyccel.codegen.utilities_old.
generate_project_init
(srcdir, project, **settings)[source]¶ Generates a __init__.py file for the project.
-
pyccel.codegen.utilities_old.
generate_project_main
(srcdir, project, extensions, force=True)[source]¶
-
pyccel.codegen.utilities_old.
get_extension_external_path
(ext)[source]¶ Finds the path of a pyccel extension external files.
an external file to pyccel, is any low level code associated to its header(s).
-
pyccel.codegen.utilities_old.
get_extension_path
(ext, module=None, is_external=False)[source]¶ Finds the path of a pyccel extension (.py or .pyh). A specific module can also be given.
-
pyccel.codegen.utilities_old.
get_extension_testing_path
(ext)[source]¶ Finds the path of a pyccel extension tests.
-
pyccel.codegen.utilities_old.
get_parallel_path
(ext, module=None)[source]¶ Finds the path of a pyccel parallel package (.py or .pyh). A specific module can also be given.
-
pyccel.codegen.utilities_old.
get_stdlib_external_path
(ext, module=None)[source]¶ Finds the path of a pyccel stdlib external package (.py or .pyh). A specific module can also be given.
-
pyccel.codegen.utilities_old.
initialize_project
(base_dir, project, libname, settings, verbose=False)[source]¶
-
pyccel.codegen.utilities_old.
load_extension
(ext, output_dir, clean=True, modules=None, silent=True, language='fortran', testing=True)[source]¶ Load module(s) from a given pyccel extension.
- ext: str
- a pyccel extension is always of the form pyccelext-xxx where ‘xxx’ is the extension name.
- output_dir: str
- directory where to store the generated files
- clean: Bool
- remove all tempororay files of extension pyccel
- modules: list, str
- a list of modules or a module. every module must be a string.
- silent: bool
- talk more
- language: str
- target language
- testing: bool
- enable unit tests
Examples
>>> load_extension('math', 'extensions', silent=False) >>> load_extension('math', 'extensions', modules=['bsplines']) >>> load_extension('math', 'extensions', modules='quadratures')
-
pyccel.codegen.utilities_old.
load_module
(filename, language='fortran', compiler='gfortran', accelerator=None, debug=False, verbose=False, show=False, inline=False, name=None, output_dir=None, ignored_modules=['numpy', 'scipy', 'sympy'], pyccel_modules=[], include=[], libdir=[], libs=[], single_file=True)[source]¶ Loads a given filename in a Python session. The file will be parsed, compiled and wrapped into python, using f2py.
- filename: str
- name of the file to load.
- language: str
- low-level target language used in the conversion
- compiled: str
- used compiler for the target language.
Example
>>> from pyccel.codegen import load_module >>> code = ''' ... def f(n): ... n = int() ... x = int() ... x = 0 ... for i in range(0,n): ... for j in range(0,n): ... x = x + i*j ... print("x = ", x) ... ''' >>> filename = "test.py" >>> f = open(filename, "w") >>> f.write(code) >>> f.close() >>> module = load_module(filename="test.py") >>> module.f(5) x = 100