![]() |
lingua-franca 0.10.1
Lingua Franca code generator
|
A collection of utilities for C code generation. More...
Inherited by org.lflang.generator.python.PyUtil.
Classes | |
| interface | ReportCommandErrors |
| A ReportCommandErrors is a way to analyze command output and report any errors that it describes. More... | |
Static Public Member Functions | |
| static String | actionRef (ActionInstance instance, String runtimeIndex) |
| Return a reference to the action struct of the specified action instance. | |
| static HashSet< String > | allIncludes (TypeParameterizedReactor tpr) |
| Given a reactor Class, return a set of include names for interacting reactors which includes all instantiations of base class that it extends. | |
| static String | bankIndex (ReactorInstance instance) |
| Return a default name of a variable to refer to the bank index of a reactor in a bank. | |
| static String | bankIndexName (ReactorInstance instance) |
| Return a default name of a variable to refer to the bank index of a reactor in a bank. | |
| static String | channelIndex (PortInstance port) |
| Return a default name of a variable to refer to the channel index of a port in a bank. | |
| static String | channelIndexName (PortInstance port) |
| Return a default name of a variable to refer to the channel index of a port in a bank. | |
| static void | deleteBinFiles (FileConfig fileConfig) |
| Remove files in the bin directory that may have been created. | |
| static int | fixedSizeArrayTypeLength (InferredType type) |
| Given a type for an input or output, if it is a fixed-size array (declared with type[int]), then return the int and otherwise return 1, which is the default length for non-arrays and variable-size arrays. | |
| static String | generateWidthVariable (String var) |
| static String | getEnvironmentStruct (CEnclaveInstance inst) |
| Return a string representing a global C variable that is the struct of the environment of the specified enclave. | |
| static String | getEnvironmentStructPtr (ReactorInstance inst) |
| Return a string representing a pointer to the C variable that is the struct of the environment of the specified enclave. | |
| static String | getName (TypeParameterizedReactor reactor) |
| Return the name of the reactor. | |
| static String | getShortenedName (ReactorInstance instance) |
| Return the full name of the specified instance without the leading name of the top-level reactor, unless this is the top-level reactor, in which case return its name. | |
| static String | internalIncludeGuard (TypeParameterizedReactor tpr) |
| Return the name used in the internal (non-user-facing) include guard for the given reactor. | |
| static boolean | isFixedSizeArrayType (InferredType type) |
| Given a type for an input or output, return true if it is a fixed-size array (declared with type[int]). | |
| static boolean | isTokenType (InferredType type) |
| Given a type for an input or output, return true if it should be carried by a lf_token_t struct rather than the type itself. | |
| static String | multiportWidthExpression (Variable variable) |
| If the argument is a multiport, then return a string that gives the width as an expression, and otherwise, return null. | |
| static String | portRef (PortInstance port) |
| Return a reference to the port on the self struct of the port's parent. | |
| static String | portRef (PortInstance port, boolean isNested, boolean includeChannelIndex, String runtimeIndex, String bankIndex, String channelIndex) |
| Return a reference to the specified port. | |
| static String | portRef (PortInstance port, String runtimeIndex, String bankIndex, String channelIndex) |
| Return a reference to the port on the self struct of the port's parent using the specified index variables. | |
| static String | portRefInReaction (VarRef reference, Integer bankIndex, Integer multiportIndex) |
| Return code for referencing a port within a reaction body possibly indexed by a bank index and/or a multiport index. | |
| static String | portRefName (PortInstance port) |
| Return a reference to a port without any channel indexing. | |
| static String | portRefName (PortInstance port, String runtimeIndex, String bankIndex, String channelIndex) |
| Return the portRef without the channel indexing. | |
| static String | portRefNested (PortInstance port) |
| Return a port reference to a port on the self struct of the parent of the port's parent. | |
| static String | portRefNested (PortInstance port, String runtimeIndex, String bankIndex, String channelIndex) |
| Return a reference to the port on the self struct of the parent of the port's parent. | |
| static String | portRefNestedName (PortInstance port) |
| Return a reference to the port on the self struct of the parent of the port's parent, but without the channel indexing, even if it is a multiport. | |
| static String | portRefNestedName (PortInstance port, String runtimeIndex, String bankIndex, String channelIndex) |
| Return a reference to the port on the self struct of the parent of the port's parent, but without the channel indexing, even if it is a multiport. | |
| static String | reactionRef (ReactionInstance reaction) |
| Return a reference to the reaction entry on the self struct of the parent of the specified reaction. | |
| static String | reactionRef (ReactionInstance reaction, String runtimeIndex) |
| Return a reference to the reaction entry on the self struct of the parent of the specified reaction. | |
| static String | reactorRef (ReactorInstance instance) |
| Return a reference to the "self" struct of the specified reactor instance. | |
| static String | reactorRef (ReactorInstance instance, String runtimeIndex) |
| Return a reference to the "self" struct of the specified reactor instance. | |
| static String | reactorRefName (ReactorInstance instance) |
| Return the name of the array of "self" structs of the specified reactor instance. | |
| static String | reactorRefNested (ReactorInstance reactor) |
| For situations where a reaction reacts to or reads from an output of a contained reactor or sends to an input of a contained reactor, then the container's self struct will have a field (or an array of fields if the contained reactor is a bank) that is a struct with fields corresponding to those inputs and outputs. | |
| static String | reactorRefNested (ReactorInstance reactor, String runtimeIndex, String bankIndex) |
| For situations where a reaction reacts to or reads from an output of a contained reactor or sends to an input of a contained reactor, then the container's self struct will have a field (or an array of fields if the contained reactor is a bank) that is a struct with fields corresponding to those inputs and outputs. | |
| static String | rootType (String type) |
| If the type specification of the form type[], type*, or type, return the type. | |
| static void | runBuildCommand (FileConfig fileConfig, TargetConfig targetConfig, GeneratorCommandFactory commandFactory, MessageReporter messageReporter, ReportCommandErrors reportCommandErrors, LFGeneratorContext.Mode mode) |
| Run the custom build command specified with the "build" parameter. | |
| static String | runtimeIndex (ReactorInstance reactor) |
| Return an expression that, when evaluated, gives the index of a runtime instance of the specified ReactorInstance. | |
| static String | selfType (ReactorInstance instance) |
| Construct a unique type for the "self" struct of the class of the given reactor. | |
| static String | selfType (TypeParameterizedReactor reactor) |
| Return a unique type for the "self" struct of the specified reactor class from the reactor class. | |
| static String | triggerRef (TriggerInstance<? extends Variable > instance) |
| Return a reference to the trigger_t struct of the specified trigger instance (input port or action). | |
| static String | triggerRef (TriggerInstance<? extends Variable > instance, String runtimeIndex) |
| Return a reference to the trigger_t struct of the specified trigger instance (input port or action). | |
| static String | triggerRefNested (PortInstance port) |
| Return a reference to the trigger_t struct for the specified port of a contained reactor. | |
| static String | triggerRefNested (PortInstance port, String runtimeIndex, String bankIndex) |
| Return a reference to the trigger_t struct for the specified port of a contained reactor. | |
Static Public Attributes | |
| static final String | ENVIRONMENT_VARIABLE_NAME = "environments" |
| static final String | NUM_ENVIRONMENT_VARIABLE_NAME = "num_environments" |
| static final String | RTI_BIN_SUFFIX = "_RTI" |
| Suffix that when appended to the name of a federated reactor yields the name of its corresponding RTI executable. | |
| static final String | RTI_DISTRIBUTION_SCRIPT_SUFFIX = "_distribute.sh" |
| Suffix that when appended to the name of a federated reactor yields the name of its corresponding distribution script. | |
A collection of utilities for C code generation.
This class codifies the coding conventions for the C target code generator. I.e., it defines how variables are named and referenced.
|
static |
Return a reference to the action struct of the specified action instance.
This action_base_t struct is on the self struct.
| instance | The action instance. |
| runtimeIndex | An optional index variable name to use to address runtime instances. |
|
static |
Given a reactor Class, return a set of include names for interacting reactors which includes all instantiations of base class that it extends.
|
static |
Return a default name of a variable to refer to the bank index of a reactor in a bank.
This has the form uniqueID_i, where uniqueID is an identifier for the instance that is guaranteed to be different from the ID of any other instance in the program. If the instance is not a bank, return "0".
| instance | A reactor instance. |
|
static |
Return a default name of a variable to refer to the bank index of a reactor in a bank.
This has the form uniqueID_i, where uniqueID is an identifier for the instance that is guaranteed to be different from the ID of any other instance in the program.
| instance | A reactor instance. |
|
static |
Return a default name of a variable to refer to the channel index of a port in a bank.
This has the form uniqueID_c where uniqueID is an identifier for the instance that is guaranteed to be different from the ID of any other instance in the program. If the port is not a multiport, then return the string "0".
|
static |
Return a default name of a variable to refer to the channel index of a port in a bank.
This is has the form uniqueID_c where uniqueID is an identifier for the instance that is guaranteed to be different from the ID of any other instance in the program.
|
static |
Remove files in the bin directory that may have been created.
Call this if a compilation occurs so that files from a previous version do not accidentally get executed.
| fileConfig |
|
static |
Given a type for an input or output, if it is a fixed-size array (declared with type[int]), then return the int and otherwise return 1, which is the default length for non-arrays and variable-size arrays.
| type | The type specification |
|
static |
|
static |
Return a string representing a global C variable that is the struct of the environment of the specified enclave.
| inst | The enclave instance. |
|
static |
Return a string representing a pointer to the C variable that is the struct of the environment of the specified enclave.
| inst | The enclave instance. |
|
static |
Return the name of the reactor.
A _main is appended to the name if the reactor is main (to allow for instantiations that have the same name as the main reactor or the .lf file).
|
static |
Return the full name of the specified instance without the leading name of the top-level reactor, unless this is the top-level reactor, in which case return its name.
| instance | The instance. |
|
static |
Return the name used in the internal (non-user-facing) include guard for the given reactor.
|
static |
Given a type for an input or output, return true if it is a fixed-size array (declared with type[int]).
For such types, the memory is allocated in the output struct.
| type | The type specification. |
|
static |
Given a type for an input or output, return true if it should be carried by a lf_token_t struct rather than the type itself.
It should be carried by such a struct if the type ends with * (it is a pointer) or [] (it is a array with unspecified length).
| type | The type specification. |
|
static |
If the argument is a multiport, then return a string that gives the width as an expression, and otherwise, return null.
The string will be empty if the width is variable (specified as '[]'). Otherwise, if is a single term or a sum of terms (separated by '+'), where each term is either an integer or a parameter reference in the target language.
|
static |
Return a reference to the port on the self struct of the port's parent.
This is used when an input port triggers a reaction in the port's parent or when an output port is written to by a reaction in the port's parent. This is equivalent to calling portRef(port, false, true, null, null).
| port | An instance of the port to be referenced. |
|
static |
Return a reference to the specified port.
The returned string will have one of the following forms:
where k is the runtime index of either the port's parent or the port's parent's parent, the latter when isNested is true. The index j is present if the parent is a bank, and the index i is present if the port is a multiport.
The first two forms are used if isNested is false, and the remaining four are used if isNested is true. Set isNested to true when referencing a port belonging to a contained reactor.
| port | The port. |
| isNested | True to return a reference relative to the parent's parent. |
| includeChannelIndex | True to include the channel index at the end. |
| runtimeIndex | A variable name to use to index the runtime instance or null to use the default, the string returned by CUtil#runtimeIndex(ReactorInstance). |
| bankIndex | A variable name to use to index the bank or null to use the default, the string returned by CUtil#bankIndex(ReactorInstance). |
| channelIndex | A variable name to use to index the channel or null to use the default, the string returned by CUtil#channelIndex(PortInstance). |
|
static |
Return a reference to the port on the self struct of the port's parent using the specified index variables.
This is used when an input port triggers a reaction in the port's parent or when an output port is written to by a reaction in the port's parent. This is equivalent to calling portRef(port, false, true, bankIndex, channelIndex).
| port | An instance of the port to be referenced. |
| runtimeIndex | A variable name to use to index the runtime instance or null to use the default, the string returned by CUtil#runtimeIndex(ReactorInstance). |
| bankIndex | A variable name to use to index the bank or null to use the default, the string returned by CUtil#bankIndex(ReactorInstance). |
| channelIndex | A variable name to use to index the channel or null to use the default, the string returned by CUtil#channelIndex(PortInstance). |
|
static |
Return code for referencing a port within a reaction body possibly indexed by a bank index and/or a multiport index.
If the provided reference is not a port, then this returns the string "ERROR: not a port."
| reference | The reference to the port. |
| bankIndex | A bank index or null or negative if not in a bank. |
| multiportIndex | A multiport index or null or negative if not in a multiport. |
|
static |
Return a reference to a port without any channel indexing.
This is useful for deriving a reference to the _width variable.
| port | An instance of the port to be referenced. |
|
static |
Return the portRef without the channel indexing.
This is useful for deriving a reference to the _width variable.
| port | An instance of the port to be referenced. |
| runtimeIndex | A variable name to use to index the runtime instance or null to use the default, the string returned by CUtil#runtimeIndex(ReactorInstance). |
| bankIndex | A variable name to use to index the bank or null to use the default, the string returned by CUtil#bankIndex(ReactorInstance). |
| channelIndex | A variable name to use to index the channel or null to use the default, the string returned by CUtil#channelIndex(PortInstance). |
|
static |
Return a port reference to a port on the self struct of the parent of the port's parent.
This is used when an input port is written to by a reaction in the parent of the port's parent, or when an output port triggers a reaction in the parent of the port's parent. This is equivalent to calling portRef(port, true, true, null, null, null).
| port | The port. |
|
static |
Return a reference to the port on the self struct of the parent of the port's parent.
This is used when an input port is written to by a reaction in the parent of the port's parent, or when an output port triggers a reaction in the parent of the port's parent. This is equivalent to calling portRef(port, true, true, runtimeIndex, bankIndex, channelIndex).
| port | The port. |
| runtimeIndex | A variable name to use to index the runtime instance or null to use the default, the string returned by CUtil#runtimeIndex(ReactorInstance). |
| bankIndex | A variable name to use to index the bank or null to use the default, the string returned by CUtil#bankIndex(ReactorInstance). |
| channelIndex | A variable name to use to index the channel or null to use the default, the string returned by CUtil#channelIndex(PortInstance). |
|
static |
Return a reference to the port on the self struct of the parent of the port's parent, but without the channel indexing, even if it is a multiport.
This is used when an input port is written to by a reaction in the parent of the port's parent, or when an output port triggers a reaction in the parent of the port's parent. This is equivalent to calling portRef(port, true, false, null, null, null).
| port | The port. |
|
static |
Return a reference to the port on the self struct of the parent of the port's parent, but without the channel indexing, even if it is a multiport.
This is used when an input port is written to by a reaction in the parent of the port's parent, or when an output port triggers a reaction in the parent of the port's parent. This is equivalent to calling portRefNested(port, true, false, runtimeIndex, bankIndex, channelIndex).
| port | The port. |
| runtimeIndex | A variable name to use to index the runtime instance or null to use the default, the string returned by CUtil#runtimeIndex(ReactorInstance). |
| bankIndex | A variable name to use to index the bank or null to use the default, the string returned by CUtil#bankIndex(ReactorInstance). |
| channelIndex | A variable name to use to index the channel or null to use the default, the string returned by CUtil#channelIndex(PortInstance). |
|
static |
Return a reference to the reaction entry on the self struct of the parent of the specified reaction.
| reaction | The reaction. |
|
static |
Return a reference to the reaction entry on the self struct of the parent of the specified reaction.
| reaction | The reaction. |
| runtimeIndex | An index into the array of self structs for the parent. |
|
static |
Return a reference to the "self" struct of the specified reactor instance.
The returned string has the form self[j], where self is the name of the array of self structs for this reactor instance and j is the expression returned by runtimeIndex(ReactorInstance) or 0 if there are no banks.
| instance | The reactor instance. |
Reimplemented in org.lflang.generator.python.PyUtil.
|
static |
Return a reference to the "self" struct of the specified reactor instance.
The returned string has the form self[runtimeIndex], where self is the name of the array of self structs for this reactor instance. If runtimeIndex is null, then it is replaced by the expression returned by runtimeIndex(ReactorInstance) or 0 if there are no banks.
| instance | The reactor instance. |
| runtimeIndex | An optional expression to use to address bank members. If this is null, the expression used will be that returned by runtimeIndex(ReactorInstance). |
Reimplemented in org.lflang.generator.python.PyUtil.
|
static |
Return the name of the array of "self" structs of the specified reactor instance.
This is similar to reactorRef(ReactorInstance) except that it does not index into the array.
| instance | The reactor instance. |
Reimplemented in org.lflang.generator.python.PyUtil.
|
static |
For situations where a reaction reacts to or reads from an output of a contained reactor or sends to an input of a contained reactor, then the container's self struct will have a field (or an array of fields if the contained reactor is a bank) that is a struct with fields corresponding to those inputs and outputs.
This method returns a reference to that struct or array of structs. Note that the returned reference is not to the self struct of the contained reactor. Use reactorRef(ReactorInstance) for that.
| reactor | The contained reactor. |
|
static |
For situations where a reaction reacts to or reads from an output of a contained reactor or sends to an input of a contained reactor, then the container's self struct will have a field (or an array of fields if the contained reactor is a bank) that is a struct with fields corresponding to those inputs and outputs.
This method returns a reference to that struct or array of structs. Note that the returned reference is not to the self struct of the contained reactor. Use CUtil#reactorRef(ReactorInstance) for that.
| reactor | The contained reactor. |
| runtimeIndex | A variable name to use to index the runtime instance or null to use the default, the string returned by CUtil#runtimeIndex(ReactorInstance). |
| bankIndex | A variable name to use to index the bank or null to use the default, the string returned by CUtil#bankIndex(ReactorInstance). |
|
static |
If the type specification of the form type[], type*, or type, return the type.
| type | A string describing the type. |
|
static |
Run the custom build command specified with the "build" parameter.
This command is executed in the same directory as the source file.
The following environment variables will be available to the command:
|
static |
Return an expression that, when evaluated, gives the index of a runtime instance of the specified ReactorInstance.
If the reactor is not within any banks, then this will return "0". Otherwise, it will return an expression that evaluates a mixed-radix number d0w0, d1w1, ... , dnwn, where n is the depth minus one of the reactor. The radixes, w0 to wn, are the widths of this reactor, its parent reactor, on up to the top-level reactor. Since the top-level reactor is never a bank, dn = 0 and wn = 1. The digits, di, are either 0 (of the parent is not a bank) or the variable name returned by bankIndexName(ReactorInstance) if the parent is a bank. The returned expression, when evaluated, will yield the following value:
d0 + w0 * (d1 + w1 * ( ... (dn-1 + wn-1 * dn) ... )
| reactor | The reactor. |
|
static |
Construct a unique type for the "self" struct of the class of the given reactor.
|
static |
Return a unique type for the "self" struct of the specified reactor class from the reactor class.
| reactor | The reactor class. |
|
static |
Return a reference to the trigger_t struct of the specified trigger instance (input port or action).
This trigger_t struct is on the self struct.
| instance | The port or action instance. |
|
static |
Return a reference to the trigger_t struct of the specified trigger instance (input port or action).
This trigger_t struct is on the self struct.
| instance | The port or action instance. |
| runtimeIndex | An optional index variable name to use to address runtime instances. |
|
static |
Return a reference to the trigger_t struct for the specified port of a contained reactor.
| port | The output port of a contained reactor. |
|
static |
Return a reference to the trigger_t struct for the specified port of a contained reactor.
| port | The output port of a contained reactor. |
| runtimeIndex | An optional index variable name to use to index the runtime instance of the port's parent's parent, or null to get the default returned by CUtil#runtimeIndex(ReactorInstance). |
| bankIndex | An optional index variable name to use to index the the bank of the port's parent, or null to get the default returned by CUtil#bankIndex(ReactorInstance). |
|
static |
|
static |
|
static |
Suffix that when appended to the name of a federated reactor yields the name of its corresponding RTI executable.
|
static |
Suffix that when appended to the name of a federated reactor yields the name of its corresponding distribution script.