![]() |
lingua-franca 0.10.1
Lingua Franca code generator
|
Generator for Python target. More...
Inherits CGenerator, and org.lflang.generator.c.CCmakeGenerator.SetUpMainTarget.
Public Member Functions | |
| void | doGenerate (Resource resource, LFGeneratorContext context) |
| Generate C code from the Lingua Franca model contained by the specified resource. | |
| void | generateAuxiliaryStructs (CodeBuilder builder, TypeParameterizedReactor tpr, boolean userFacing) |
| Generate the aliases for inputs, outputs, and struct type definitions for actions of the specified reactor in the specified federate. | |
| String | generateDirectives () |
| Generate code that needs to appear at the top of the generated C file, such as #define and #include statements. | |
| String | generatePythonCode (String pyModuleName) |
| Generate the Python code constructed from reactor classes and user-written classes. | |
| Map< Path, CodeMap > | generatePythonFiles (String lfModuleName, String pyModuleName, String pyFileName) throws IOException |
| Generate the necessary Python files. | |
| String | generatePythonReactorClasses () |
| Generate all Python classes if they have a reaction. | |
| String | getCmakeCode (boolean hasMain, String executableName, Stream< String > cSources) |
| Target | getTarget () |
| Returns the Target enum for this generator. | |
| TargetTypes | getTargetTypes () |
| boolean | isOSCompatible () |
| Return true if the host operating system is compatible and otherwise report an error and return false. | |
| void | processProtoFile (String filename) |
| Process a given .proto file. | |
| PythonGenerator (LFGeneratorContext context) | |
Protected Member Functions | |
| void | additionalPostProcessingForModes () |
| void | copyTargetFiles () throws IOException |
| Copy Python specific target code to the src-gen directory. | |
| void | generateMethods (CodeBuilder src, TypeParameterizedReactor reactor) |
| Do nothing. | |
| void | generateParameterInitialization (ReactorInstance instance) |
| Generate runtime initialization code in C for parameters of a given reactor instance. | |
| void | generateReaction (CodeBuilder src, Reaction reaction, TypeParameterizedReactor tpr, int reactionIndex) |
| Generate a reaction function definition for a reactor. | |
| void | generateReactorClassHeaders (TypeParameterizedReactor tpr, String headerName, CodeBuilder header, CodeBuilder src) |
| void | generateReactorInstanceExtension (ReactorInstance instance) |
| Generate code that is executed while the reactor instance is being initialized. | |
| void | generateSelfStructExtension (CodeBuilder selfStructBody, Reactor reactor, CodeBuilder constructorCode) |
| This function is provided to allow extensions of the CGenerator to append the structure of the self struct. | |
| void | generateStateVariableInitializations (ReactorInstance instance) |
| Generate code that initializes the state variables for a given instance. | |
| String | generateTopLevelPreambles (Reactor ignored) |
| Override generate top-level preambles, but put the user preambles in the .py file rather than the C file. | |
| void | generateUserPreamblesForReactor (Reactor reactor, CodeBuilder src) |
| Generate C preambles defined by user for a given reactor Since the Python generator expects preambles written in C, this function is overridden and does nothing. | |
| String | getConflictingConnectionsInModalReactorsBody (VarRef sourceRef, VarRef destRef) |
| PythonDockerGenerator | getDockerGenerator (LFGeneratorContext context) |
| void | handleProtoFiles () |
| boolean | setUpGeneralParameters () |
Package Attributes | |
| String | genericActionType = "generic_action_instance_struct" |
| Generic struct for actions. | |
| String | genericPortType = "generic_port_instance_struct" |
| Generic struct for ports with primitive types and statically allocated arrays in Lingua Franca. | |
Generator for Python target.
This class generates Python code defining each reactor class given in the input .lf file and imported .lf files.
Each class will contain all the reaction functions defined by the user in order, with the necessary ports/actions given as parameters. Moreover, each class will contain all state variables in native Python format.
A backend is also generated using the CGenerator that interacts with the C code library (see CGenerator.xtend). The backend is responsible for passing arguments to the Python reactor functions.
| org.lflang.generator.python.PythonGenerator.PythonGenerator | ( | LFGeneratorContext | context | ) |
|
protected |
|
protected |
Copy Python specific target code to the src-gen directory.
| void org.lflang.generator.python.PythonGenerator.doGenerate | ( | Resource | resource, |
| LFGeneratorContext | context ) |
Generate C code from the Lingua Franca model contained by the specified resource.
This is the main entry point for code generation.
| resource | The resource containing the source code. |
| context | Context relating to invocation of the code generator. |
| void org.lflang.generator.python.PythonGenerator.generateAuxiliaryStructs | ( | CodeBuilder | builder, |
| TypeParameterizedReactor | tpr, | ||
| boolean | userFacing ) |
Generate the aliases for inputs, outputs, and struct type definitions for actions of the specified reactor in the specified federate.
| builder | The code builder. |
| tpr | The concrete reactor class. |
| userFacing | Whether this is user-facing code. |
| String org.lflang.generator.python.PythonGenerator.generateDirectives | ( | ) |
Generate code that needs to appear at the top of the generated C file, such as #define and #include statements.
|
protected |
|
protected |
Generate runtime initialization code in C for parameters of a given reactor instance.
| instance | The reactor instance. |
| String org.lflang.generator.python.PythonGenerator.generatePythonCode | ( | String | pyModuleName | ) |
Generate the Python code constructed from reactor classes and user-written classes.
| Map< Path, CodeMap > org.lflang.generator.python.PythonGenerator.generatePythonFiles | ( | String | lfModuleName, |
| String | pyModuleName, | ||
| String | pyFileName ) throws IOException |
Generate the necessary Python files.
| String org.lflang.generator.python.PythonGenerator.generatePythonReactorClasses | ( | ) |
Generate all Python classes if they have a reaction.
|
protected |
Generate a reaction function definition for a reactor.
This function has a single argument that is a void* pointing to a struct that contains parameters, state variables, inputs (triggering or not), actions (triggering or produced), and outputs.
| src | The code builder. |
| reaction | The reaction. |
| tpr | The reactor. |
| reactionIndex | The position of the reaction within the reactor. |
|
protected |
|
protected |
Generate code that is executed while the reactor instance is being initialized.
This wraps the reaction functions in a Python function.
| instance | The reactor instance. |
|
protected |
This function is provided to allow extensions of the CGenerator to append the structure of the self struct.
| selfStructBody | The body of the self struct |
| reactor | The reactor declaration for the self struct |
| constructorCode | Code that is executed when the reactor is instantiated |
|
protected |
Generate code that initializes the state variables for a given instance.
Unlike parameters, state variables are uniformly initialized for all instances of the same reactor. This task is left to Python code to allow for more liberal state variable assignments.
| instance | The reactor class instance |
|
protected |
Override generate top-level preambles, but put the user preambles in the .py file rather than the C file.
Also handles including the federated execution setup preamble specified in the target config.
|
protected |
Generate C preambles defined by user for a given reactor Since the Python generator expects preambles written in C, this function is overridden and does nothing.
| reactor | The given reactor |
| src | The code builder. |
| String org.lflang.generator.python.PythonGenerator.getCmakeCode | ( | boolean | hasMain, |
| String | executableName, | ||
| Stream< String > | cSources ) |
|
protected |
|
protected |
| Target org.lflang.generator.python.PythonGenerator.getTarget | ( | ) |
Returns the Target enum for this generator.
| TargetTypes org.lflang.generator.python.PythonGenerator.getTargetTypes | ( | ) |
|
protected |
| boolean org.lflang.generator.python.PythonGenerator.isOSCompatible | ( | ) |
Return true if the host operating system is compatible and otherwise report an error and return false.
| void org.lflang.generator.python.PythonGenerator.processProtoFile | ( | String | filename | ) |
Process a given .proto file.
Run, if possible, the proto-c protocol buffer code generator to produce the required .h and .c files.
| filename | Name of the file to process. |
|
protected |
|
package |
Generic struct for actions.
This template is defined as typedef struct { trigger_t* trigger; PyObject* value; bool is_present; bool has_value; lf_token_t* token; FEDERATED_CAPSULE_EXTENSION } generic_action_instance_struct;
See reactor-c/python/lib/pythontarget.h for details.
|
package |
Generic struct for ports with primitive types and statically allocated arrays in Lingua Franca.
This template is defined as typedef struct { bool is_present; lf_sparse_io_record_t* sparse_record; // NULL if there is no sparse record. int destination_channel; // -1 if there is no destination. PyObject* value; int num_destinations; lf_token_t* token; int length; void (destructor) (void value); void* (copy_constructor) (void value); FEDERATED_GENERIC_EXTENSION } generic_port_instance_struct;
See reactor-c/python/lib/pythontarget.h for details.