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

Almost works to merge actors, still some problem with variable declarations.

parent c547b1fa
No related branches found
No related tags found
No related merge requests found
...@@ -512,16 +512,18 @@ aspect GenPrettyPrinter { ...@@ -512,16 +512,18 @@ aspect GenPrettyPrinter {
} }
public void XsAttribute.genPrettyPrinter(PrintStream pStream) { public void XsAttribute.genPrettyPrinter(PrintStream pStream) {
String name = fixName(name()); // String name = fixName(name());
pStream.println(" public void "+name+".prettyPrint(String indent, PrintStream pStream) {"); String name = name();
pStream.println(" public void "+fixName(name)+".prettyPrint(String indent, PrintStream pStream) {");
pStream.println(" pStream.print(\" "+name()+"=\");"); pStream.println(" pStream.print(\" "+name()+"=\");");
pStream.println(" getAttrValue().prettyPrint(indent,pStream);"); pStream.println(" getAttrValue().prettyPrint(indent,pStream);");
pStream.println(" }\n"); pStream.println(" }\n");
} }
public void XsElement.genPrettyPrinter(PrintStream pStream) { public void XsElement.genPrettyPrinter(PrintStream pStream) {
String name = fixName(name()); // String name = fixName(name());
pStream.println(" public void "+name+".prettyPrint(String ind, PrintStream pStream) {"); String name = name();
pStream.println(" public void "+fixName(name)+".prettyPrint(String ind, PrintStream pStream) {");
pStream.println(" pStream.print(ind+\"<"+name+" \");"); pStream.println(" pStream.print(ind+\"<"+name+" \");");
pStream.println(" for (int i=0; i<getNumAttribute(); i++) {"); pStream.println(" for (int i=0; i<getNumAttribute(); i++) {");
pStream.println(" getAttribute(i).prettyPrint(ind,pStream);"); pStream.println(" getAttribute(i).prettyPrint(ind,pStream);");
......
...@@ -122,7 +122,19 @@ ...@@ -122,7 +122,19 @@
<Port kind="Output" name="Out"> <Port kind="Output" name="Out">
<Type name="int"/> <Type name="int"/>
</Port> </Port>
<Action text-begin-col="7" text-begin-line="3" text-end-col="28" text-end-line="3"> <Decl assignable="Yes" kind="Variable" name="tmp" text-begin-col=""
text-begin-line=""
text-end-col="15"
text-end-line="2">
<Type name="int"/>
<Expr kind="Let">
<Expr kind="Literal" literal-kind="Integer" text-begin-col="15" text-begin-line="2"
text-end-col="15"
text-end-line="2"
value="0"/>
</Expr>
</Decl>
<Action text-begin-col="7" text-begin-line="3" text-end-col="4" text-end-line="6">
<Input kind="Elements" port="In" text-begin-col="14" text-begin-line="3" <Input kind="Elements" port="In" text-begin-col="14" text-begin-line="3"
text-end-col="16" text-end-col="16"
text-end-line="3"> text-end-line="3">
...@@ -130,7 +142,7 @@ ...@@ -130,7 +142,7 @@
<Type name="int"/> <Type name="int"/>
</Decl> </Decl>
</Input> </Input>
<Output port="Out" text-begin-col="22" text-begin-line="3" text-end-col="26" <Output port="Out" text-begin-col="22" text-begin-line="3" text-end-col="28"
text-end-line="3"> text-end-line="3">
<Expr kind="Let"> <Expr kind="Let">
<Expr kind="BinOpSeq" text-begin-col="23" text-begin-line="3" text-end-col="25" <Expr kind="BinOpSeq" text-begin-col="23" text-begin-line="3" text-end-col="25"
...@@ -139,13 +151,26 @@ ...@@ -139,13 +151,26 @@
text-end-col="23" text-end-col="23"
text-end-line="3"/> text-end-line="3"/>
<Op name="+"/> <Op name="+"/>
<Expr kind="Literal" literal-kind="Integer" text-begin-col="25" text-begin-line="3" <Expr kind="Var" name="tmp" text-begin-col="25" text-begin-line="3" text-end-col="25"
text-end-col="25" text-end-line="3"/>
text-end-line="3"
value="1"/>
</Expr> </Expr>
</Expr> </Expr>
</Output> </Output>
<Stmt kind="Assign" name="tmp" text-begin-col="3" text-begin-line="5"
text-end-col="17"
text-end-line="5">
<Expr kind="Let">
<Expr kind="BinOpSeq" text-begin-col="10" text-begin-line="5" text-end-col="16"
text-end-line="5">
<Expr kind="Var" name="tmp" text-begin-col="10" text-begin-line="5" text-end-col="10"
text-end-line="5"/>
<Op name="+"/>
<Expr kind="Var" name="$local$x" text-begin-col="16" text-begin-line="5"
text-end-col="16"
text-end-line="5"/>
</Expr>
</Expr>
</Stmt>
</Action> </Action>
<Note kind="filepath" value="/work/csandersn/actors/example//AddOne.cal"/> <Note kind="filepath" value="/work/csandersn/actors/example//AddOne.cal"/>
</Actor> </Actor>
...@@ -198,139 +223,6 @@ ...@@ -198,139 +223,6 @@
</Attribute> </Attribute>
</Instance> </Instance>
<Instance id="$id_n$3"> <Instance id="$id_n$3">
<Note kind="UID" value="SubOne_0"/>
<Note kind="instanceHierarchy"/>
<Class name="SubOne"/>
<Note kind="sourceLoaded" value="true"/>
<Note kind="className" value="SubOne"/>
<Actor name="SubOne">
<Port kind="Input" name="In">
<Type name="int"/>
</Port>
<Port kind="Output" name="Out">
<Type name="int"/>
</Port>
<Action text-begin-col="7" text-begin-line="3" text-end-col="28" text-end-line="3">
<Input kind="Elements" port="In" text-begin-col="14" text-begin-line="3"
text-end-col="16"
text-end-line="3">
<Decl kind="Input" name="$local$x">
<Type name="int"/>
</Decl>
</Input>
<Output port="Out" text-begin-col="22" text-begin-line="3" text-end-col="26"
text-end-line="3">
<Expr kind="Let">
<Expr kind="BinOpSeq" text-begin-col="23" text-begin-line="3" text-end-col="25"
text-end-line="3">
<Expr kind="Var" name="$local$x" text-begin-col="23" text-begin-line="3"
text-end-col="23"
text-end-line="3"/>
<Op name="-"/>
<Expr kind="Literal" literal-kind="Integer" text-begin-col="25" text-begin-line="3"
text-end-col="25"
text-end-line="3"
value="1"/>
</Expr>
</Expr>
</Output>
</Action>
<Note kind="filepath" value="/work/csandersn/actors/example//SubOne.cal"/>
</Actor>
<Attribute kind="Value" name="clockDomain">
<Expr kind="Literal" literal-kind="String" value="CLK"/>
</Attribute>
</Instance>
<Instance id="$id_n$4">
<Note kind="UID" value="AddFiveOnce_0"/>
<Note kind="instanceHierarchy"/>
<Class name="AddFiveOnce"/>
<Note kind="sourceLoaded" value="true"/>
<Note kind="className" value="AddFiveOnce"/>
<Actor name="AddFiveOnce">
<Port kind="Input" name="In">
<Type name="int"/>
</Port>
<Port kind="Output" name="Out">
<Type name="int"/>
</Port>
<Action text-begin-col="9" text-begin-line="3" text-end-col="30" text-end-line="3">
<QID name="init">
<ID name="init"/>
</QID>
<Input kind="Elements" port="In" text-begin-col="16" text-begin-line="3"
text-end-col="18"
text-end-line="3">
<Decl kind="Input" name="$local$x">
<Type name="int"/>
</Decl>
</Input>
<Output port="Out" text-begin-col="24" text-begin-line="3" text-end-col="28"
text-end-line="3">
<Expr kind="Let">
<Expr kind="BinOpSeq" text-begin-col="25" text-begin-line="3" text-end-col="27"
text-end-line="3">
<Expr kind="Var" name="$local$x" text-begin-col="25" text-begin-line="3"
text-end-col="25"
text-end-line="3"/>
<Op name="+"/>
<Expr kind="Literal" literal-kind="Integer" text-begin-col="27" text-begin-line="3"
text-end-col="27"
text-end-line="3"
value="5"/>
</Expr>
</Expr>
</Output>
</Action>
<Action text-begin-col="8" text-begin-line="5" text-end-col="27" text-end-line="5">
<QID name="run">
<ID name="run"/>
</QID>
<Input kind="Elements" port="In" text-begin-col="15" text-begin-line="5"
text-end-col="17"
text-end-line="5">
<Decl kind="Input" name="$local$x">
<Type name="int"/>
</Decl>
</Input>
<Output port="Out" text-begin-col="23" text-begin-line="5" text-end-col="25"
text-end-line="5">
<Expr kind="Let">
<Expr kind="Var" name="$local$x" text-begin-col="24" text-begin-line="5"
text-end-col="24"
text-end-line="5"/>
</Expr>
</Output>
</Action>
<Note kind="filepath" value="/work/csandersn/actors/example//AddFiveOnce.cal"/>
<Schedule initial-state="init" kind="fsm" text-begin-col="3" text-begin-line="7"
text-end-col="3"
text-end-line="10">
<Transition from="init" text-begin-col="4" text-begin-line="8" text-end-col="23"
text-end-line="8"
to="run">
<ActionTags text-begin-col="" text-begin-line="" text-end-col="" text-end-line="">
<QID name="init">
<ID name="init"/>
</QID>
</ActionTags>
</Transition>
<Transition from="run" text-begin-col="2" text-begin-line="9" text-end-col="19"
text-end-line="9"
to="run">
<ActionTags text-begin-col="" text-begin-line="" text-end-col="" text-end-line="">
<QID name="run">
<ID name="run"/>
</QID>
</ActionTags>
</Transition>
</Schedule>
</Actor>
<Attribute kind="Value" name="clockDomain">
<Expr kind="Literal" literal-kind="String" value="CLK"/>
</Attribute>
</Instance>
<Instance id="$id_n$5">
<Note kind="UID" value="art_Sink_txt_0"/> <Note kind="UID" value="art_Sink_txt_0"/>
<Note kind="instanceHierarchy"/> <Note kind="instanceHierarchy"/>
<Class name="art_Sink_txt"/> <Class name="art_Sink_txt"/>
...@@ -410,8 +302,6 @@ ...@@ -410,8 +302,6 @@
<Connection dst="$id_n$1" dst-port="In" src="$id_n$0" src-port="Out"/> <Connection dst="$id_n$1" dst-port="In" src="$id_n$0" src-port="Out"/>
<Connection dst="$id_n$2" dst-port="In" src="$id_n$1" src-port="Out"/> <Connection dst="$id_n$2" dst-port="In" src="$id_n$1" src-port="Out"/>
<Connection dst="$id_n$3" dst-port="In" src="$id_n$2" src-port="Out"/> <Connection dst="$id_n$3" dst-port="In" src="$id_n$2" src-port="Out"/>
<Connection dst="$id_n$4" dst-port="In" src="$id_n$3" src-port="Out"/>
<Connection dst="$id_n$5" dst-port="In" src="$id_n$4" src-port="Out"/>
<Note kind="Directive" name="default-type-name"> <Note kind="Directive" name="default-type-name">
<Expr kind="Literal" literal-kind="String" value="int"/> <Expr kind="Literal" literal-kind="String" value="int"/>
</Note> </Note>
......
...@@ -27,6 +27,7 @@ aspect MergeActors { ...@@ -27,6 +27,7 @@ aspect MergeActors {
for (Instance i : schedule) { for (Instance i : schedule) {
while (i.next != null) { while (i.next != null) {
System.out.println("Searching connections for: "+i.name()+" "+i.next.name()); System.out.println("Searching connections for: "+i.name()+" "+i.next.name());
String srcPort="",dstPort="";
for (Connection c : cons) { for (Connection c : cons) {
System.out.println(" "+c.getSource().name()+" "+c.getDest().name()); System.out.println(" "+c.getSource().name()+" "+c.getDest().name());
if (c.getSource() == i && c.getDest() == i.next) { if (c.getSource() == i && c.getDest() == i.next) {
...@@ -35,6 +36,8 @@ aspect MergeActors { ...@@ -35,6 +36,8 @@ aspect MergeActors {
// merge. Then set remove_me flag so that this // merge. Then set remove_me flag so that this
// connection will be removed from the actor // connection will be removed from the actor
// network. // network.
srcPort = c.srcPort();
dstPort = c.dstPort();
c.remove_me = true; c.remove_me = true;
c.is$Final(false); c.is$Final(false);
} else if (c.getSource() == i.next) { } else if (c.getSource() == i.next) {
...@@ -43,7 +46,7 @@ aspect MergeActors { ...@@ -43,7 +46,7 @@ aspect MergeActors {
} }
System.out.println("Merging "+i.name()+":"+i.next.name()); System.out.println("Merging "+i.name()+":"+i.next.name());
i.isMerged(true); i.isMerged(true);
i.merge(i.next); i.merge(i.next,srcPort,dstPort);
i.setName(i.name()+"_"+i.next.name()); i.setName(i.name()+"_"+i.next.name());
i.next.disabled = true; i.next.disabled = true;
i.next = i.next.next; i.next = i.next.next;
...@@ -56,9 +59,9 @@ aspect MergeActors { ...@@ -56,9 +59,9 @@ aspect MergeActors {
} }
} }
void Instance.merge(Instance inst) { void Instance.merge(Instance inst,String srcPort, String dstPort) {
if (isMerged()) { if (isMerged()) {
xlimInstance().merge(inst.xlimInstance()); xlimInstance().merge(inst.xlimInstance(),srcPort,dstPort);
} }
} }
...@@ -116,6 +119,7 @@ aspect Misc { ...@@ -116,6 +119,7 @@ aspect Misc {
inst.add(this); inst.add(this);
return inst; return inst;
} }
} }
aspect Rewrites { aspect Rewrites {
......
...@@ -112,6 +112,23 @@ aspect ActorLookup { ...@@ -112,6 +112,23 @@ aspect ActorLookup {
} }
return ""; return "";
} }
String Connection.dstPort() {
for (Attribute a : getAttributes()) {
if (a instanceof dst_port) {
return fix(a.getAttrValue().getLITERAL());
}
}
return "";
}
String Connection.srcPort() {
for (Attribute a : getAttributes()) {
if (a instanceof src_port) {
return fix(a.getAttrValue().getLITERAL());
}
}
return "";
}
} }
aspect misc { aspect misc {
......
...@@ -232,7 +232,7 @@ aspect PrettyPrinter { ...@@ -232,7 +232,7 @@ aspect PrettyPrinter {
} }
public void actor_port.prettyPrint(String ind, PrintStream pStream) { public void actor_port.prettyPrint(String ind, PrintStream pStream) {
pStream.print(ind+"<actor_port "); pStream.print(ind+"<actor-port ");
for (int i=0; i<getNumAttribute(); i++) { for (int i=0; i<getNumAttribute(); i++) {
getAttribute(i).prettyPrint(ind,pStream); getAttribute(i).prettyPrint(ind,pStream);
} }
...@@ -244,7 +244,7 @@ aspect PrettyPrinter { ...@@ -244,7 +244,7 @@ aspect PrettyPrinter {
for (int i=0; i<getNumElement(); i++) { for (int i=0; i<getNumElement(); i++) {
getElement(i).prettyPrint(newInd,pStream); getElement(i).prettyPrint(newInd,pStream);
} }
pStream.println(ind+"</actor_port> "); pStream.println(ind+"</actor-port> ");
} }
} }
......
...@@ -9,17 +9,28 @@ ...@@ -9,17 +9,28 @@
import java.util.HashSet; import java.util.HashSet;
aspect Merge { aspect Merge {
public void Start.merge(Start dest) { public void Start.merge(Start dest, String srcPort, String dstPort) {
getSpecification().getDesign().merge(dest.getSpecification().getDesign()); getSpecification().getDesign().merge(dest.getSpecification().getDesign(),srcPort,dstPort);
} }
public void EmptyStart.merge(Start dest) {} public void EmptyStart.merge(Start dest, String srcPort, String dstPort) {}
public void design.merge(design dest) { public void design.merge(design dest, String srcPort, String dstPort) {
HashSet<module> ops = dest.getActions(new HashSet<module>()); HashSet<module> ops = dest.getActions(new HashSet<module>());
System.out.println("Adding actions from: "+dest.name()+" to: "+name()); System.out.println("Adding actions from: "+dest.name()+" to: "+name());
String varName = "\""+name()+"_out\"";
setName(name()+"_"+dest.name()); setName(name()+"_"+dest.name());
List<Element> eList = getElements(); List<Element> eList = getElements();
stateVar var = new stateVar();
initValue init = new initValue();
var.setAttributeList(new List().add(new name(new AttrValue(varName))).
add(new sourceName(new AttrValue(varName))));
eList.insertChild(var,0);
// Re-set pinWrite with shared variable
for (module m : getActions(new HashSet<module>())) {
m.setOutVar(varName,srcPort);
}
for (module o : ops) { for (module o : ops) {
o.setInVar(varName,dstPort);
o.setName(dest.name()+"_"+o.name()); o.setName(dest.name()+"_"+o.name());
System.out.println(" Adding "+o.name()); System.out.println(" Adding "+o.name());
eList.insertChild(o,eList.getNumChild()-2); eList.insertChild(o,eList.getNumChild()-2);
...@@ -51,6 +62,37 @@ aspect Actions { ...@@ -51,6 +62,37 @@ aspect Actions {
} }
return ops; return ops;
} }
void module.setOutVar(String varName,String srcPort) {
for (Element e : getElements()) {
e.setOutVar(varName, srcPort);
}
}
void Element.setOutVar(String varName, String srcPort){}
void operation.setOutVar(String varName, String srcPort) {
if (kind().equals("pinWrite")) {
setAttributeList(new List().add(new kind(new AttrValue("\"assign\""))).
add(new target(new AttrValue(varName))));
}
}
void module.setInVar(String varName,String srcPort) {
for (Element e : getElements()) {
e.setInVar(varName, srcPort);
}
}
void Element.setInVar(String varName, String srcPort){}
void operation.setInVar(String varName, String srcPort) {
if (kind().equals("pinRead")) {
String src = getElement(0).source();
setAttributeList(new List().add(new kind(new AttrValue("\"assign\""))).
add(new target(new AttrValue(unfix(src)))));
port newPort = new port();
newPort.setAttributeList(new List().add(new dir(new AttrValue("\"in\""))).
add(new source(new AttrValue(varName))));
setElementList(new List().add(newPort));
}
}
} }
aspect ActionScheduler { aspect ActionScheduler {
...@@ -74,7 +116,32 @@ aspect ActionScheduler { ...@@ -74,7 +116,32 @@ aspect ActionScheduler {
return kind().equals("action-scheduler"); return kind().equals("action-scheduler");
} }
void Element.addTaskCall(module m) {}
void module.addTaskCall(module m) { void module.addTaskCall(module m) {
System.out.println("Looking in: "+kind());
if (hasTaskCall()) {
operation o = new operation();
o.setAttributeList(new List().add(new kind(new AttrValue("\"taskCall\""))).
add(new target(new AttrValue(unfix(m.name())))));
addElement(o);
} else {
for (Element e : getElements()) {
e.addTaskCall(m);
}
}
}
syn boolean Element.hasTaskCall() = false;
eq module.hasTaskCall() {
for (Element e : getElements()) {
if (e instanceof operation) {
System.out.println(" "+e.kind());
}
if (e instanceof operation && e.kind().equals("taskCall")) {
return true;
}
} }
return false;
} }
}
...@@ -64,7 +64,7 @@ aspect Misc { ...@@ -64,7 +64,7 @@ aspect Misc {
} }
void Attribute.setName(String name) {} void Attribute.setName(String name) {}
void name.setName(String name) { void name.setName(String name) {
getAttrValue().setLITERAL(fix(name)); getAttrValue().setLITERAL(unfix(name));
} }
...@@ -75,6 +75,13 @@ aspect Misc { ...@@ -75,6 +75,13 @@ aspect Misc {
return s; return s;
} }
static String ASTNode.unfix(String s) {
if (s.indexOf('"') != 0) {
return "\""+s+"\"";
}
return s;
}
syn design Specification.getDesign() { syn design Specification.getDesign() {
for (Element e : getElements()) { for (Element e : getElements()) {
if (e instanceof design) { if (e instanceof design) {
...@@ -83,6 +90,29 @@ aspect Misc { ...@@ -83,6 +90,29 @@ aspect Misc {
} }
return null; return null;
} }
syn String Element.kind() = "";
eq ComplexElement.kind() {
for (Attribute a : getAttributes()) {
if (a.isKind()) {
return fix(a.getAttrValue().getLITERAL());
}
}
return "";
}
syn boolean Attribute.isKind() = false;
eq kind.isKind() = true;
syn String Element.source() = "";
eq ComplexElement.source() {
for (Attribute a : getAttributes()) {
if (a instanceof source) {
return fix(a.getAttrValue().getLITERAL());
}
}
return "";
}
} }
aspect Fixes { aspect Fixes {
......
...@@ -10,11 +10,13 @@ abstract Thing : ComplexElement ::=; ...@@ -10,11 +10,13 @@ abstract Thing : ComplexElement ::=;
abstract Element; abstract Element;
ComplexElement : Element ::= Attribute* Element*; ComplexElement : Element ::= Attribute* Element*;
ValueElement : ComplexElement; ValueElement : ComplexElement;
__DefaultElement__ : ComplexElement ::= <TAG>;
abstract SimpleElement : Element; abstract SimpleElement : Element;
StringElement : SimpleElement ::= <LITERAL>; StringElement : SimpleElement ::= <LITERAL>;
IntElement : SimpleElement ::= <LITERAL>; IntElement : SimpleElement ::= <LITERAL>;
FloatElement : SimpleElement ::= <LITERAL>; FloatElement : SimpleElement ::= <LITERAL>;
Attribute ::= AttrValue; Attribute ::= AttrValue;
__DefaultAttribute__ : Attribute ::= <NAME>;
AttrValue ::= <LITERAL>; AttrValue ::= <LITERAL>;
Encoding : Attribute ::=; Encoding : Attribute ::=;
Version : Attribute ::=; Version : Attribute ::=;
......
...@@ -246,7 +246,7 @@ void ElementList() #List : {} ...@@ -246,7 +246,7 @@ void ElementList() #List : {}
void AttributeList() #List : {} void AttributeList() #List : {}
{ {
(Attribute())* (LOOKAHEAD(2) Attribute())*
} }
void AttrValue() #AttrValue : { Token t; } void AttrValue() #AttrValue : { Token t; }
...@@ -287,6 +287,7 @@ void Element() : {} ...@@ -287,6 +287,7 @@ void Element() : {}
| stateVar() | stateVar()
| note() | note()
| initValue() | initValue()
| __DefaultElement__()
)) ))
| SimpleElement() | SimpleElement()
} }
...@@ -321,6 +322,18 @@ void StringElement() #StringElement : { Token t;String s; } ...@@ -321,6 +322,18 @@ void StringElement() #StringElement : { Token t;String s; }
} }
{jjtThis.setLITERAL(s);} {jjtThis.setLITERAL(s);}
} }
void __DefaultElement__() #__DefaultElement__ : { Token t;String s; }
{
t = <IDENTIFIER> AttributeList()
(">" ElementList() "</" <IDENTIFIER> ">" | ElementList() "/>")
{
s = t.image;
if (getToken(1).kind != GT ) {
s += getData();
}
}
{jjtThis.setTAG(s);}
}
void Attribute() : {} void Attribute() : {}
{ {
Encoding() Encoding()
...@@ -342,9 +355,15 @@ void Attribute() : {} ...@@ -342,9 +355,15 @@ void Attribute() : {}
| value() | value()
| autostart() | autostart()
| size() | size()
| __DefaultAttribute__()
} }
void __DefaultAttribute__() # __DefaultAttribute__ : {Token t;}
{
t=<IDENTIFIER> "=" AttrValue()
{jjtThis.setNAME(t.image);}
}
void portName() #portName : {} void portName() #portName : {}
{ {
<portName> "=" AttrValue() <portName> "=" AttrValue()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment