pyccel.codegen.codegen module#
- class pyccel.codegen.codegen.Codegen(parser, name, language, verbose)[source]#
Bases:
object
Class which handles the generation of code.
The class which handles the generation of code. This is done by creating an appropriate class inheriting from CodePrinter and using it to create strings describing the code that should be printed. This class then takes care of creating the necessary files.
- Parameters:
parser (SemanticParser) – The Pyccel semantic parser for a Python program or module. This contains the annotated AST and additional information about the variables scope.
name (str) – Name of the generated module or program.
language (str) – The language which the printer should print to.
verbose (int) – The level of verbosity.
- property ast#
Returns the AST.
- property body#
Returns the body of the source code, if it is a Program or Module.
- property classes#
Returns the classes if Module.
- export(filename)[source]#
Export code to a file with the requested name.
Generate the code in the target language from the AST and print this code to file. Between 1 and 3 files are generated depending on the AST and the target language. A source file is always generated. In languages with header files, a header file is also generated. Finally if the AST includes a program and the target language is not Python a program source file is also generated. The source and header files are named by appending the extension to the requested filename. The program source file is named by additionally prepending prog_ to the requested filename.
- Parameters:
filename (str) – The base (i.e. no extensions) of the filename of the file where the code should be printed to.
- Returns:
filename (str) – The name of the file where the source code was printed.
prog_filename (str) – The name of the file where the source code for the program was printed.
- get_printer_imports()[source]#
Get the objects that were imported by the current codeprinter.
Get the objects that were imported by the current codeprinter. These imports may affect the necessary compiler commands.
- Returns:
A dictionary mapping the include strings to the import module.
- Return type:
dict[str, Import]
- property imports#
Returns the imports of the source code.
- property interfaces#
Returns the interfaces.
- property is_program#
Returns True if a Program.
- property language#
Returns the used language
- property modules#
Returns the modules if Program.
- property name#
Returns the name associated to the source code
- property parser#
The parser which generated the AST printed by this class.
The parser which generated the AST printed by this class.
- property printer#
The printer which is used to generate code.
The printer which is used by this class to generate code in the target language.
- property routines#
Returns functions/subroutines.
- property variables#
Returns the variables of the source code.