lingua-franca 0.10.1
Lingua Franca code generator
Loading...
Searching...
No Matches
org.lflang.generator.RuntimeRange< T > Class Template Reference

A representation of a range of runtime instance objects (port channels, reactors, reactions, etc.). More...

Inherits Comparable< RuntimeRange<?> >.

Classes

class  Port
 Special case of RuntimeRange for PortInstance. More...

Public Member Functions

int compareTo (RuntimeRange<?> o)
 Compare ranges by first comparing their start offset, and then, if these are equal, comparing their widths.
RuntimeRange< T > head (int newWidth)
 Return a new RuntimeRange that is identical to this range but with width reduced to the specified width.
List< Integer > instances ()
 Return the list of natural identifiers for the runtime instances in this range.
List< NamedInstance<?> > iterationOrder ()
 Return a list containing the instance for this range and all of its parents, not including the top level reactor, in the order in which their banks and multiport channels should be iterated.
RuntimeRange<?> overlap (RuntimeRange<?> range)
 Return a range that is the subset of this range that overlaps with the specified range or null if there is no overlap.
boolean overlaps (RuntimeRange<?> range)
 Return true if the specified range has the same instance as this range and the ranges overlap.
Set< Integer > parentInstances (int n)
 Return a set of identifiers for runtime instances of a parent of this RuntimeRange's instance n levels above this RuntimeRange's instance.
ReactorInstance parentReactor ()
 Return the nearest containing ReactorInstance for this instance.
List< Integer > permutation ()
 Return the permutation vector that indicates the order in which the digits of the permuted mixed-radix representations of indices in this range should be incremented.
List< Integer > radixes ()
 Return the radixes vector containing the width of this instance followed by the widths of its containers, not including the top level, which always has radix 1 and value 0.
 RuntimeRange (T instance, int start, int width, Set< ReactorInstance > interleaved)
 Create a new range representing a range of the specified instance with no interleaving.
 RuntimeRange (T instance, Set< ReactorInstance > interleaved)
 Create a new range representing the full width of the specified instance with no interleaving.
MixedRadixInt startMR ()
 Return the start as a new permuted mixed-radix number.
RuntimeRange< T > tail (int offset)
 Return a new range that represents the leftover elements starting at the specified offset relative to start.
RuntimeRange< T > toggleInterleaved (ReactorInstance reactor)
 Toggle the interleaved status of the specified reactor, which is assumed to be a parent of the instance of this range.
String toString ()

Public Attributes

final T instance
 The instance that this is a range of.
final int maxWidth
 The maximum width of any range with this instance.
final int start
 The start offset of this range.
final int width
 The width of this range.

Package Attributes

Set< ReactorInstance_interleaved = new HashSet<>()
 Record of which levels are interleaved.

Detailed Description

A representation of a range of runtime instance objects (port channels, reactors, reactions, etc.).

This class and its derived classes have the most detailed information about the structure of a Lingua Franca program. There are three levels of detail:

  • The abstract syntax tree (AST).
  • The compile-time instance graph (CIG).
  • The runtime instance graph (RIG).

In the AST, each reactor class is represented once. In the CIG, each reactor class is represented as many times as it is instantiated, except that a bank has only one representation (as in the graphical rendition). Equivalently, each CIG node has a unique full name, even though it may represent many runtime instances. The CIG is represented by NamedInstance and its derived classes. In the RIG, each bank is expanded so each bank member and each port channel is represented.

In general, determining dependencies between reactions requires analysis at the level of the RIG. But a brute-force representation of the RIG can get very large, and for most programs it has a great deal of redundancy. In a fully detailed representation of the RIG, for example, a bank of width N that contains a bank of width M within which there is a reactor R with port P will have N*M runtime instances of the port. If the port is a multiport with width L, then there are N*M*L edges connected to instances of that port, each of which may go to a distinct set of other remote runtime port instances.

This class and its subclasses give a more compact representation of the RIG in most common cases where collections of runtime instances all have the same dependencies or dependencies form a range that can be represented compactly.

A RuntimeRange represents an adjacent set of RIG objects (port channels, reactions reactors). For example, it can represent port channels 2 through 5 in a multiport of width 10. The width in this case is 4. If such a port is contained by one or more banks of reactors, then channels 2 through 5 of one bank member form a contiguous range. If you want channels 2 through 5 of all bank members, then this needs to be represented with multiple ranges.

The maxWidth is the width of the instance multiplied by the widths of each of its containers. For example, if a port of width 4 is contained by a bank of width 2 that is then contained by a bank of width 3, then the maxWidth will be 2*3*4 = 24.

The function iterationOrder returns a list that includes the instance of this range and all its containers, except the top-level reactor (main or federated). The order of this list is the order in which an iteration over the RIG objects represented by this range should be iterated. If the instance is a PortInstance, then this order will depend on whether connections at any level of the hierarchy are interleaved.

The simplest Ranges are those where the corresponding CIG node represents only one runtime instance (its instance is not (deeply) within a bank and is not a multiport). In this case, the RuntimeRange and all the objects returned by iterationOrder will have width 1.

In a more complex instance, consider a bank A of width 2 that contains a bank B of width 2 that contains a port instance P with width 2. . There are a total of 8 instances of P, which we can name:

A0.B0.P0 A0.B0.P1 A0.B1.P0 A0.B1.P1 A1.B0.P0 A1.B0.P1 A1.B1.P0 A1.B1.P1

If there is no interleaving, iterationOrder() returns [P, B, A], indicating that they should be iterated by incrementing the index of P first, then the index of B, then the index of A, as done above.

If the connection within B to port P is interleaved, then the order of iteration order will be [B, P, A], resulting in the list:

A0.B0.P0 A0.B1.P0 A0.B0.P1 A0.B1.P1 A1.B0.P0 A1.B1.P0 A1.B0.P1 A1.B1.P1

If the connection within A to B is also interleaved, then the order will be [A, B, P], resulting in the list:

A0.B0.P0 A1.B0.P0 A0.B1.P0 A1.B1.P0 A0.B0.P1 A1.B0.P1 A0.B1.P1 A1.B1.P1

Finally, if the connection within A to B is interleaved, but not the connection within B to P, then the order will be [A, P, B], resulting in the list:

A0.B0.P0 A1.B0.P0 A0.B0.P1 A1.B0.P1 A0.B1.P0 A1.B1.P0 A0.B1.P1 A1.B1.P1

A RuntimeRange is a contiguous subset of one of the above lists, given by a start offset and a width that is less than or equal to maxWidth.

Each element of the above lists can be represented as a permuted mixed-radix (PMR) number, where the low-order digit has radix equal to the width of P, the second digit has radix equal to the width of B, and the final digit has radix equal to the width of A. Each PMR has a permutation vector that defines how to increment PMR number. This permutation vector is derived from the iteration order as follows. When there is no interleaving, the iteration order is [P, B, A], and the permutation vector is [0, 1, 2]. When there is interleaving, the permutation vector simply specifies the iteration order. For example, if the iteration order is [A, P, B], then the permutation vector is [2, 0, 1], indicating that digit 2 of the PMR (corresponding to A) should be incremented first, then digit 0 (for P), then digit 1 (for B).

For a RuntimeRange with width greater than 1, the head() and tail() functions split the range.

This class and subclasses are designed to be immutable. Modifications always return a new RuntimeRange.

Author
Edward A. Lee

Constructor & Destructor Documentation

◆ RuntimeRange() [1/2]

org.lflang.generator.RuntimeRange< T >.RuntimeRange ( T instance,
Set< ReactorInstance > interleaved )

Create a new range representing the full width of the specified instance with no interleaving.

The instances will be a list with the specified instance first, its parent next, and on up the hierarchy until the depth 1 parent (the top-level reactor is not included because it can never be a bank).

Parameters
instanceThe instance.
interleavedA list of parents that are interleaved or null if none.

◆ RuntimeRange() [2/2]

org.lflang.generator.RuntimeRange< T >.RuntimeRange ( T instance,
int start,
int width,
Set< ReactorInstance > interleaved )

Create a new range representing a range of the specified instance with no interleaving.

The instances will be a list with the specified instance first, its parent next, and on up the hierarchy until the depth 1 parent (the top-level reactor is not included because it can never be a bank).

Parameters
instanceThe instance over which this is a range (port, reaction, etc.)
startThe starting index for the range.
widthThe width of the range or 0 to specify the maximum possible width.
interleavedA list of parents that are interleaved or null if none.

Member Function Documentation

◆ compareTo()

int org.lflang.generator.RuntimeRange< T >.compareTo ( RuntimeRange<?> o)

Compare ranges by first comparing their start offset, and then, if these are equal, comparing their widths.

This comparison is meaningful only for ranges that have the same instances. Note that this can return 0 even if equals() does not return true.

Parameters
oThe range to compare to.

◆ head()

RuntimeRange< T > org.lflang.generator.RuntimeRange< T >.head ( int newWidth)

Return a new RuntimeRange that is identical to this range but with width reduced to the specified width.

If the new width is greater than or equal to the width of this range, then return this range. If the newWidth is 0 or negative, return null.

Parameters
newWidthThe new width.

◆ instances()

List< Integer > org.lflang.generator.RuntimeRange< T >.instances ( )

Return the list of natural identifiers for the runtime instances in this range.

Each returned identifier is an integer representation of the mixed-radix number [d0, ... , dn] with radices [w0, ... , wn], where d0 is the bank or channel index of this RuntimeRange's instance, which has width w0, and dn is the bank index of its topmost parent below the top-level (main) reactor, which has width wn. The depth of this RuntimeRange's instance, therefore, is n - 1. The order of the returned list is the order in which the runtime instances should be iterated.

◆ iterationOrder()

List< NamedInstance<?> > org.lflang.generator.RuntimeRange< T >.iterationOrder ( )

Return a list containing the instance for this range and all of its parents, not including the top level reactor, in the order in which their banks and multiport channels should be iterated.

For each depth at which the connection is interleaved, that parent will appear before this instance in depth order (shallower to deeper). For each depth at which the connection is not interleaved, that parent will appear after this instance in reverse depth order (deeper to shallower).

◆ overlap()

Return a range that is the subset of this range that overlaps with the specified range or null if there is no overlap.

◆ overlaps()

boolean org.lflang.generator.RuntimeRange< T >.overlaps ( RuntimeRange<?> range)

Return true if the specified range has the same instance as this range and the ranges overlap.

Parameters
rangeThe range to check for overlap.

◆ parentInstances()

Set< Integer > org.lflang.generator.RuntimeRange< T >.parentInstances ( int n)

Return a set of identifiers for runtime instances of a parent of this RuntimeRange's instance n levels above this RuntimeRange's instance.

If n == 1, for example, then this return the identifiers for the parent ReactorInstance.

This returns a list of natural identifiers, as defined below, for the instances within the range.

The resulting list can be used to count the number of distinct runtime instances of this RuntimeRange's instance (using n == 0) or any of its parents that lie within the range and to provide an index into an array of runtime instances.

Each natural identifier is the integer value of a mixed-radix number defined as follows:

  • The low-order digit is the index of the runtime instance of i within its container. If the NamedInstance is a PortInstance, this will be the multiport channel or 0 if it is not a multiport. If the NamedInstance is a ReactorInstance, then it will be the bank index or 0 if the reactor is not a bank. The radix for this digit will be the multiport width or bank width or 1 if the NamedInstance is neither a multiport nor a bank.
  • The next digit will be the bank index of the container of the specified NamedInstance or 0 if it is not a bank.
  • The remaining digits will be bank indices of containers up to but not including the top-level reactor (there is no point in including the top-level reactor because it is never a bank).
  • Each index that is returned can be used as an index into an array of runtime instances that is assumed to be in a natural order.
Parameters
nThe number of levels up of the parent. This is required to be less than the depth of this RuntimeRange's instance or an exception will be thrown.

◆ parentReactor()

Return the nearest containing ReactorInstance for this instance.

If this instance is a ReactorInstance, then return it. Otherwise, return its parent.

◆ permutation()

List< Integer > org.lflang.generator.RuntimeRange< T >.permutation ( )

Return the permutation vector that indicates the order in which the digits of the permuted mixed-radix representations of indices in this range should be incremented.

◆ radixes()

List< Integer > org.lflang.generator.RuntimeRange< T >.radixes ( )

Return the radixes vector containing the width of this instance followed by the widths of its containers, not including the top level, which always has radix 1 and value 0.

◆ startMR()

Return the start as a new permuted mixed-radix number.

For any instance that is neither a multiport nor a bank, the corresponding digit will be 0.

◆ tail()

RuntimeRange< T > org.lflang.generator.RuntimeRange< T >.tail ( int offset)

Return a new range that represents the leftover elements starting at the specified offset relative to start.

If start + offset is greater than or equal to the width, then this returns null. If this offset is 0 then this returns this range unmodified.

Parameters
offsetThe number of elements to consume.

◆ toggleInterleaved()

RuntimeRange< T > org.lflang.generator.RuntimeRange< T >.toggleInterleaved ( ReactorInstance reactor)

Toggle the interleaved status of the specified reactor, which is assumed to be a parent of the instance of this range.

If it was previously interleaved, make it not interleaved and vice versa. This returns a new RuntimeRange.

Parameters
reactorThe parent reactor at which to toggle interleaving.

◆ toString()

String org.lflang.generator.RuntimeRange< T >.toString ( )

Member Data Documentation

◆ _interleaved

Set<ReactorInstance> org.lflang.generator.RuntimeRange< T >._interleaved = new HashSet<>()
package

Record of which levels are interleaved.

◆ instance

final T org.lflang.generator.RuntimeRange< T >.instance

The instance that this is a range of.

◆ maxWidth

final int org.lflang.generator.RuntimeRange< T >.maxWidth

The maximum width of any range with this instance.

◆ start

final int org.lflang.generator.RuntimeRange< T >.start

The start offset of this range.

◆ width

final int org.lflang.generator.RuntimeRange< T >.width

The width of this range.


The documentation for this class was generated from the following file:
  • /Users/runner/work/lingua-franca/lingua-franca/core/src/main/java/org/lflang/generator/RuntimeRange.java