use of org.lflang.lf.WidthSpec in project lingua-franca by lf-lang.
the class ASTUtils method getDelayInstance.
/**
* Create a new instance delay instances using the given reactor class.
* The supplied time value is used to override the default interval (which
* is zero).
* If the target supports parametric polymorphism, then a single class may
* be used for each instantiation, in which case a non-empty string must
* be supplied to parameterize the instance.
* A default name ("delay") is assigned to the instantiation, but this
* name must be overridden at the call site, where checks can be done to
* avoid name collisions in the container in which the instantiation is
* to be placed. Such checks (or modifications of the AST) are not
* performed in this method in order to avoid causing concurrent
* modification exceptions.
* @param delayClass The class to create an instantiation for
* @param connection The connection to create a delay instantiation foe
* @param generic A string that denotes the appropriate type parameter,
* which should be null or empty if the target does not support generics.
* @param defineWidthFromConnection If this is true and if the connection
* is a wide connection, then instantiate a bank of delays where the width
* is given by ports involved in the connection. Otherwise, the width will
* be unspecified indicating a variable length.
*/
private static Instantiation getDelayInstance(Reactor delayClass, Connection connection, String generic, Boolean defineWidthFromConnection) {
Delay delay = connection.getDelay();
Instantiation delayInstance = factory.createInstantiation();
delayInstance.setReactorClass(delayClass);
if (!StringExtensions.isNullOrEmpty(generic)) {
TypeParm typeParm = factory.createTypeParm();
typeParm.setLiteral(generic);
delayInstance.getTypeParms().add(typeParm);
}
if (hasMultipleConnections(connection)) {
WidthSpec widthSpec = factory.createWidthSpec();
if (defineWidthFromConnection) {
// to delay the ports first, and then broadcast the output of the delays.
for (VarRef port : connection.getLeftPorts()) {
WidthTerm term = factory.createWidthTerm();
term.setPort(EcoreUtil.copy(port));
widthSpec.getTerms().add(term);
}
} else {
widthSpec.setOfVariableLength(true);
}
delayInstance.setWidthSpec(widthSpec);
}
Assignment assignment = factory.createAssignment();
assignment.setLhs(delayClass.getParameters().get(0));
Value value = factory.createValue();
if (delay.getParameter() != null) {
value.setParameter(delay.getParameter());
} else {
value.setTime(delay.getTime());
}
assignment.getRhs().add(value);
delayInstance.getParameters().add(assignment);
// This has to be overridden.
delayInstance.setName("delay");
return delayInstance;
}
use of org.lflang.lf.WidthSpec in project lingua-franca by lf-lang.
the class PortInstance method setInitialWidth.
/**
* Set the initial multiport width, if this is a multiport, from the widthSpec
* in the definition. This will be set to -1 if the width cannot be determined.
* @param errorReporter For reporting errors.
*/
private void setInitialWidth(ErrorReporter errorReporter) {
// If this is a multiport, determine the width.
WidthSpec widthSpec = definition.getWidthSpec();
if (widthSpec != null) {
if (widthSpec.isOfVariableLength()) {
errorReporter.reportError(definition, "Variable-width multiports not supported (yet): " + definition.getName());
} else {
isMultiport = true;
// Determine the initial width, if possible.
// The width may be given by a parameter or even sum of parameters.
width = 0;
for (WidthTerm term : widthSpec.getTerms()) {
Parameter parameter = term.getParameter();
if (parameter != null) {
Integer parameterValue = parent.initialIntParameterValue(parameter);
// Only a Literal is supported.
if (parameterValue != null) {
width += parameterValue;
} else {
width = -1;
return;
}
} else if (term.getWidth() != 0) {
width += term.getWidth();
} else {
width = -1;
return;
}
}
}
}
}
Aggregations