Skip to content

Commit

Permalink
Apply spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
lsk567 committed Feb 13, 2025
1 parent 2ca7a20 commit c7a1c30
Show file tree
Hide file tree
Showing 16 changed files with 119 additions and 117 deletions.
1 change: 0 additions & 1 deletion core/src/main/java/org/lflang/AttributeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

import static org.lflang.ast.ASTUtils.factory;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down
5 changes: 2 additions & 3 deletions core/src/main/java/org/lflang/TimeTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ public TimeTag(TimeTag that) {
}

/**
* Whether this time tag represents FOREVER, which is interpreted as the
* maximum TimeValue.
*
* Whether this time tag represents FOREVER, which is interpreted as the maximum TimeValue.
*
* @return True if the tag is FOREVER, false otherwise.
*/
public boolean isForever() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import java.util.PriorityQueue;

/**
* An event queue for analyzing the logical behavior of an LF program
*/
/** An event queue for analyzing the logical behavior of an LF program */
public class EventQueue extends PriorityQueue<Event> {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,4 @@ public boolean isCyclic() {
public boolean isEmpty() {
return (head == null);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package org.lflang.analyses.statespace;

import java.lang.annotation.Target;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.lflang.TimeTag;
import org.lflang.TimeValue;
import org.lflang.ast.ASTUtils;
Expand Down Expand Up @@ -150,7 +148,8 @@ else if (previousTag != null && currentTag.compareTo(previousTag) > 0) {
// Loop period is the time difference between the 1st time
// the node is reached and the 2nd time the node is reached.
diagram.hyperperiod =
diagram.loopNodeNext.getTag().time.toNanoSeconds() - diagram.loopNode.getTag().time.toNanoSeconds();
diagram.loopNodeNext.getTag().time.toNanoSeconds()
- diagram.loopNode.getTag().time.toNanoSeconds();
diagram.addEdge(diagram.loopNode, diagram.tail);
return diagram; // Exit the while loop early.
}
Expand Down Expand Up @@ -229,8 +228,7 @@ else if (!horizon.isForever() && currentTag.compareTo(horizon) > 0) {
// && currentTag.compareTo(previousTag) > 0) is true and then
// the simulation ends, leaving a new node dangling.
if (currentNode != null
&& (previousNode == null
|| previousNode.getTag().compareTo(currentNode.getTag()) < 0)) {
&& (previousNode == null || previousNode.getTag().compareTo(currentNode.getTag()) < 0)) {
diagram.addNode(currentNode);
diagram.tail = currentNode; // Update the current tail.
if (previousNode != null) {
Expand Down Expand Up @@ -270,7 +268,10 @@ public static List<Event> addInitialEvents(
* offset wrt to a phase (e.g., the shutdown phase), not the absolute tag at runtime.
*/
public static void addInitialEventsRecursive(
ReactorInstance reactor, List<Event> events, ExecutionPhase phase, TargetConfig targetConfig) {
ReactorInstance reactor,
List<Event> events,
ExecutionPhase phase,
TargetConfig targetConfig) {
switch (phase) {
case INIT_AND_PERIODIC:
{
Expand All @@ -280,7 +281,10 @@ public static void addInitialEventsRecursive(

// Add the initial timer firings, if exist.
for (TimerInstance timer : reactor.timers) {
events.add(new Event(timer, new TimeTag(TimeValue.fromNanoSeconds(timer.getOffset().toNanoSeconds()), 0L)));
events.add(
new Event(
timer,
new TimeTag(TimeValue.fromNanoSeconds(timer.getOffset().toNanoSeconds()), 0L)));
}
break;
}
Expand Down Expand Up @@ -355,7 +359,8 @@ private static List<Event> popCurrentEvents(EventQueue eventQ, TimeTag currentTa
* Sometimes multiple events can trigger the same reaction, and we do not want to record duplicate
* reaction invocations.
*/
private static Set<ReactionInstance> getReactionsTriggeredByCurrentEvents(List<Event> currentEvents) {
private static Set<ReactionInstance> getReactionsTriggeredByCurrentEvents(
List<Event> currentEvents) {
Set<ReactionInstance> reactions = new HashSet<>();
for (Event e : currentEvents) {
Set<ReactionInstance> dependentReactions = e.getTrigger().getDependentReactions();
Expand Down Expand Up @@ -387,7 +392,8 @@ private static List<Event> createNewEvents(
new Event(
timer,
new TimeTag(
TimeValue.fromNanoSeconds(e.getTag().time.toNanoSeconds() + timer.getPeriod().toNanoSeconds()),
TimeValue.fromNanoSeconds(
e.getTag().time.toNanoSeconds() + timer.getPeriod().toNanoSeconds()),
0L // A time advancement resets microstep to 0.
)));
}
Expand Down Expand Up @@ -416,7 +422,11 @@ private static List<Event> createNewEvents(
if (delay == null) delay = 0L;

// Create and enqueue a new event.
Event e = new Event(downstreamPort, new TimeTag(TimeValue.fromNanoSeconds(currentTag.time.toNanoSeconds() + delay), 0L));
Event e =
new Event(
downstreamPort,
new TimeTag(
TimeValue.fromNanoSeconds(currentTag.time.toNanoSeconds() + delay), 0L));
newEvents.add(e);
}
}
Expand All @@ -430,7 +440,12 @@ else if (effect instanceof ActionInstance && !((ActionInstance) effect).isPhysic
microstep = currentTag.microstep + 1;
}
// Create and enqueue a new event.
Event e = new Event(effect, new TimeTag(TimeValue.fromNanoSeconds(currentTag.time.toNanoSeconds() + min_delay), microstep));
Event e =
new Event(
effect,
new TimeTag(
TimeValue.fromNanoSeconds(currentTag.time.toNanoSeconds() + min_delay),
microstep));
newEvents.add(e);
}
}
Expand All @@ -445,7 +460,7 @@ else if (effect instanceof ActionInstance && !((ActionInstance) effect).isPhysic
* program.
*/
public static List<StateSpaceDiagram> generateStateSpaceDiagrams(
ReactorInstance reactor, TargetConfig targetConfig, Path graphDir) {
ReactorInstance reactor, TargetConfig targetConfig, Path graphDir) {

// Initialize variables
List<StateSpaceDiagram> SSDs;
Expand All @@ -455,12 +470,13 @@ public static List<StateSpaceDiagram> generateStateSpaceDiagrams(
// Generate a state space diagram for the initialization and periodic phase
// of an LF program.
StateSpaceDiagram stateSpaceInitAndPeriodic =
explore(reactor, TimeTag.ZERO, ExecutionPhase.INIT_AND_PERIODIC, targetConfig);
stateSpaceInitAndPeriodic.generateDotFile(graphDir, "state_space_" + ExecutionPhase.INIT_AND_PERIODIC + ".dot");
explore(reactor, TimeTag.ZERO, ExecutionPhase.INIT_AND_PERIODIC, targetConfig);
stateSpaceInitAndPeriodic.generateDotFile(
graphDir, "state_space_" + ExecutionPhase.INIT_AND_PERIODIC + ".dot");

// Split the graph into a list of diagrams.
List<StateSpaceDiagram> splittedDiagrams =
splitInitAndPeriodicDiagrams(stateSpaceInitAndPeriodic);
splitInitAndPeriodicDiagrams(stateSpaceInitAndPeriodic);

// Convert the diagrams into fragments (i.e., having a notion of upstream &
// downstream and carrying object file) and add them to the fragments list.
Expand All @@ -484,8 +500,9 @@ public static List<StateSpaceDiagram> generateStateSpaceDiagrams(
// shutdown phase.
if (targetConfig.get(TimeOutProperty.INSTANCE) != null) {
StateSpaceDiagram stateSpaceShutdownTimeout =
explore(reactor, TimeTag.ZERO, ExecutionPhase.SHUTDOWN_TIMEOUT, targetConfig);
stateSpaceInitAndPeriodic.generateDotFile(graphDir, "state_space_" + ExecutionPhase.SHUTDOWN_TIMEOUT + ".dot");
explore(reactor, TimeTag.ZERO, ExecutionPhase.SHUTDOWN_TIMEOUT, targetConfig);
stateSpaceInitAndPeriodic.generateDotFile(
graphDir, "state_space_" + ExecutionPhase.SHUTDOWN_TIMEOUT + ".dot");
SSDs.add(stateSpaceShutdownTimeout);
}

Expand Down Expand Up @@ -563,4 +580,4 @@ public static ArrayList<StateSpaceDiagram> splitInitAndPeriodicDiagrams(

return diagrams;
}
}
}
12 changes: 6 additions & 6 deletions core/src/main/java/org/lflang/analyses/uclid/UclidGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -1612,12 +1612,12 @@ private void populateLists(ReactorInstance reactor) {
*/
private void computeCT() {

StateSpaceDiagram diagram = StateSpaceExplorer.explore(
this.main,
new TimeTag(TimeValue.fromNanoSeconds(this.horizon), 0L),
ExecutionPhase.INIT_AND_PERIODIC,
targetConfig
);
StateSpaceDiagram diagram =
StateSpaceExplorer.explore(
this.main,
new TimeTag(TimeValue.fromNanoSeconds(this.horizon), 0L),
ExecutionPhase.INIT_AND_PERIODIC,
targetConfig);
diagram.display();

// Generate a dot file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
***************/

package org.lflang.generator.c;
package org.lflang.generator.c;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;

import org.lflang.MessageReporter;
import org.lflang.analyses.statespace.StateSpaceDiagram;
import org.lflang.analyses.statespace.StateSpaceExplorer;
Expand All @@ -39,14 +38,13 @@
import org.lflang.pretvm.PartialSchedule;
import org.lflang.pretvm.Registers;
import org.lflang.target.TargetConfig;
import org.lflang.target.property.TimeOutProperty;
import org.lflang.target.property.WorkersProperty;

public class CScheduleGenerator {

/** File config */
protected final CFileConfig fileConfig;

/** Target configuration */
protected TargetConfig targetConfig;

Expand Down Expand Up @@ -110,7 +108,8 @@ public CScheduleGenerator(
public void doGenerate() {
// Generate a list of state space fragments that captures
// all the behavior of the LF program.
List<StateSpaceDiagram> SSDs = StateSpaceExplorer.generateStateSpaceDiagrams(main, targetConfig, this.graphDir);
List<StateSpaceDiagram> SSDs =
StateSpaceExplorer.generateStateSpaceDiagrams(main, targetConfig, this.graphDir);

// Instantiate object files with SSDs and connect them.
List<PartialSchedule> schedules = new ArrayList<>();
Expand All @@ -127,5 +126,4 @@ public void doGenerate() {
// Create a scheduler.
// StaticScheduler scheduler = createStaticScheduler();
}

}
}
12 changes: 4 additions & 8 deletions core/src/main/java/org/lflang/pretvm/Label.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package org.lflang.pretvm;

import org.lflang.pretvm.instruction.Instruction;

/**
* A memory label of an instruction, similar to labels in C assembly.
* The instructions should have references to the labels, but the labels do not
* need to contain references to the instructions, because when generating
* JAL instructions, we know which phase to jump to. But at that point, concrete
* instructions that carry a label pointing to the phase have not been generated
* yet.
* A memory label of an instruction, similar to labels in C assembly. The instructions should have
* references to the labels, but the labels do not need to contain references to the instructions,
* because when generating JAL instructions, we know which phase to jump to. But at that point,
* concrete instructions that carry a label pointing to the phase have not been generated yet.
*
* @author Shaokai J. Lin
*/
Expand Down
62 changes: 32 additions & 30 deletions core/src/main/java/org/lflang/pretvm/PartialSchedule.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,24 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.lflang.analyses.statespace.StateSpaceDiagram;
import org.lflang.analyses.statespace.StateSpaceExplorer;
import org.lflang.pretvm.dag.Dag;
import org.lflang.pretvm.instruction.BGE;
import org.lflang.pretvm.instruction.Instruction;
import org.lflang.pretvm.instruction.JAL;
import org.lflang.pretvm.register.ReturnAddr;

/**
* A partial schedule contains instructions for one phase of execution, the
* state space diagram of that phase, the DAG, and references to
* upstream/downstream partial schedules.
* A partial schedule contains instructions for one phase of execution, the state space diagram of
* that phase, the DAG, and references to upstream/downstream partial schedules.
*
* @author Shaokai J. Lin
*/
public class PartialSchedule {

/**
* A list of list of instructions, where the inner list is a sequence of instructions
* for a worker, and the outer list is a list of instruction sequences, one for each worker.
* A list of list of instructions, where the inner list is a sequence of instructions for a
* worker, and the outer list is a list of instruction sequences, one for each worker.
*/
private List<List<Instruction>> instructions;

Expand All @@ -41,11 +38,11 @@ public class PartialSchedule {
List<PartialSchedule> downstreams = new ArrayList<>();

/**
* A map from a downstream object file to a transition guard. A transition
* guard is a sequence of instructions encoding conditional branch.
*
* FIXME: All workers for now will evaluate the same guard. This is arguably
* redundant work that needs to be optimized away.
* A map from a downstream object file to a transition guard. A transition guard is a sequence of
* instructions encoding conditional branch.
*
* <p>FIXME: All workers for now will evaluate the same guard. This is arguably redundant work
* that needs to be optimized away.
*/
Map<PartialSchedule, List<Instruction>> guardMap = new HashMap<>();

Expand Down Expand Up @@ -120,34 +117,36 @@ public void display() {
* here would require changing isDefaultTransition() also.
*/
public static void linkSchedulesWithDefaultTransition(
PartialSchedule upstream, PartialSchedule downstream) {
PartialSchedule upstream, PartialSchedule downstream) {
List<Instruction> defaultTransition =
Arrays.asList(
new JAL(
ReturnAddr.ABSTRACT_REGISTER,
Label.getExecutionPhaseLabel(downstream.getPhase()))); // Default transition
Arrays.asList(
new JAL(
ReturnAddr.ABSTRACT_REGISTER,
Label.getExecutionPhaseLabel(downstream.getPhase()))); // Default transition
upstream.addDownstream(downstream, defaultTransition);
downstream.addUpstream(upstream);
}

/** Connect two fragments with a guarded transition. */
public static void linkSchedulesWithGuardedTransition(
PartialSchedule upstream,
PartialSchedule downstream,
List<Instruction> guardedTransition) {
PartialSchedule upstream, PartialSchedule downstream, List<Instruction> guardedTransition) {
upstream.addDownstream(downstream, guardedTransition);
downstream.addUpstream(upstream);
}

/**
* Given a list of partial schedules with non-empty SSDs, link them using
* the phase information in SSDs.
*/
/**
* Given a list of partial schedules with non-empty SSDs, link them using the phase information in
* SSDs.
*/
public static void link(List<PartialSchedule> schedules, Registers registers) {
var init = schedules.stream().filter(it -> it.getPhase() == ExecutionPhase.INIT).findFirst();
var periodic = schedules.stream().filter(it -> it.getPhase() == ExecutionPhase.PERIODIC).findFirst();
var timeout = schedules.stream().filter(it -> it.getPhase() == ExecutionPhase.SHUTDOWN_TIMEOUT).findFirst();

var periodic =
schedules.stream().filter(it -> it.getPhase() == ExecutionPhase.PERIODIC).findFirst();
var timeout =
schedules.stream()
.filter(it -> it.getPhase() == ExecutionPhase.SHUTDOWN_TIMEOUT)
.findFirst();

// If INIT and PERIODIC are present, connect them with a default transition.
if (init.isPresent() && periodic.isPresent()) {
linkSchedulesWithDefaultTransition(init.get(), periodic.get());
Expand All @@ -160,8 +159,11 @@ public static void link(List<PartialSchedule> schedules, Registers registers) {
// Only transition to this fragment when offset >= timeout.
List<Instruction> guardedTransition = new ArrayList<>();
guardedTransition.add(
new BGE(registers.offset, registers.timeout, Label.getExecutionPhaseLabel(ExecutionPhase.SHUTDOWN_TIMEOUT)));

new BGE(
registers.offset,
registers.timeout,
Label.getExecutionPhaseLabel(ExecutionPhase.SHUTDOWN_TIMEOUT)));

// If PERIODIC is present, link PERIODIC to shutdown.
if (periodic.isPresent()) {
linkSchedulesWithGuardedTransition(periodic.get(), timeout.get(), guardedTransition);
Expand All @@ -177,4 +179,4 @@ else if (init.isPresent()) {
}
}
}
}
}
Loading

0 comments on commit c7a1c30

Please sign in to comment.