Skip to content
Snippets Groups Projects
Commit 6db494f9 authored by Anders Nilsson's avatar Anders Nilsson
Browse files

Working on implement merging of actors

parent 9b0bb4bd
No related branches found
No related tags found
No related merge requests found
/* -*-Java-*- */
/*
* Copyright (C) 2009 Anders Nilsson <anders.nilsson@cs.lth.se>
*
* This file is part of Actors model compiler.
*/
import xdfAST.Start;
import xdfAST.Instance;
import java.util.HashSet;
public class MergeActors extends XdfParser {
public static void main(String args[]) {
Start ast = parse(args);
// ast.genSSR(System.out);
// HashSet<Instance> l = ast.genStaticSchedule(new HashSet<Instance>());
// System.out.println("\n\n");
// for (Instance i: l){
// do {
// System.out.print(i.name()+" -> ");
// i = i.next;
// } while (i != null);
// System.out.println();
// }
ast.mergeActors();
ast.prettyPrint("",System.out);
}
}
......@@ -26,16 +26,46 @@ public class SSRAnalysis extends XdfParser {
System.out.println();
}
System.out.println("\n\n");
String s = genScheduleXML(l);
System.out.println(s);
}
static String genScheduleXML(HashSet<Instance> set) {
StringBuffer sb = new StringBuffer();
int ind = 0;
sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
sb.append("<Schedule>\n");
ind++;
for (Instance i: set){
sb.append(ind(ind));
sb.append("<StaticSequence>\n");
ind++;
do {
sb.append(ind(ind));
sb.append("<Instance>");
sb.append(i.name());
sb.append("</Instance>\n");
i = i.next;
} while (i != null);
ind--;
sb.append(ind(ind));
sb.append("</StaticSequence>\n");
}
ind--;
sb.append("</Schedule>\n");
return sb.toString();
}
static String ind(int level) {
StringBuffer sb = new StringBuffer();
for (int i=0; i<level; i++) {
sb.append(" ");
}
return sb.toString();
}
}
/* -*-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();
}
}
}
\ No newline at end of file
......@@ -144,6 +144,10 @@ aspect misc {
return new Note(); // Probably better than returning null
}
void Instance.setName(String s) {
getUIDNote().setValue(s);
}
syn String Element.kind() = "";
eq Note.kind() {
for (Attribute a : getAttributes()) {
......@@ -169,6 +173,14 @@ aspect misc {
return "";
}
void Note.setValue(String s) {
for (Attribute a : getAttributes()) {
if (a instanceof value) {
a.getAttrValue().setLITERAL(unfix(s));
}
}
}
syn String ComplexElement.id() = "";
eq Instance.id() {
for (int i=0; i<getNumAttribute(); i++) {
......@@ -186,6 +198,12 @@ aspect misc {
}
return s;
}
static String ASTNode.unfix(String s) {
if (s.indexOf('"') != 0) {
return "\""+s+"\"";
}
return s;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment