Select Git revision
MergeActors.jrag
-
Anders Nilsson authoredAnders Nilsson authored
MergeActors.jrag 1.88 KiB
/* -*-Java-*- */
/*
* Copyright (C) 2009 Anders Nilsson <anders.nilsson@cs.lth.se>
*
* This file is part of Actors model compiler.
*/
import java.util.HashSet;
aspect MergeActors {
void Element.mergeActors() {}
public void Start.mergeActors() {
getSpecification().mergeActors();
}
void Specification.mergeActors() {
for (Element e : getElements()) {
e.mergeActors();
}
}
void XDF.mergeActors() {
HashSet<Instance> schedule = genStaticSchedule(new HashSet<Instance>());
HashSet<Connection> cons = getConnections(new HashSet<Connection>());
for (Instance i : schedule) {
while (i.next != null) {
for (Connection c : cons) {
if (c.getSource() == i && c.getDest() == i.next) {
// Check port names and perform actual actor
// merge. Then set remove_me flag so that this
// connection will be removed from the actor
// network.
c.remove_me = true;
}
}
i.setName(i.name()+"_"+i.next.name());
i.next = i.next.next;
}
}
}
void Connection.mergeActors() {
Instance src = getSource();
Instance dest = getDest();
if (dest.isSDF() && src.isSDF()) {
src.merge(dest);
src.setName(src.name()+"_"+dest.name());
}
}
void Instance.merge(Instance inst) {}
}
aspect Misc {
syn HashSet<Connection> Element.getConnections(HashSet<Connection> set) = set;
eq XDF.getConnections(HashSet<Connection> set) {
for (Element e : getElements()) {
set = e.getConnections(set);
}
return set;
}
eq Connection.getConnections(HashSet<Connection> set) {
set.add(this);
return set;
}
}
aspect Rewrites {
boolean Connection.remove_me = false;
rewrite Connection {
when (remove_me) to ComplexElement {
return new ComplexElement();
}
}
}