From 9d18dfb370470463c12d0ccd003ad9872fbd9a8d Mon Sep 17 00:00:00 2001 From: adam Date: Mon, 3 Nov 2008 11:17:45 +0100 Subject: [PATCH] make LoopFactory() private, rename Context.send() to Context.sendWord() --- src/edu/berkeley/fleet/ir/Context.java | 6 +-- src/edu/berkeley/fleet/ir/New.java | 75 +++++++++++++------------------- 2 files changed, 33 insertions(+), 48 deletions(-) diff --git a/src/edu/berkeley/fleet/ir/Context.java b/src/edu/berkeley/fleet/ir/Context.java index 616d25b..a5a3e09 100644 --- a/src/edu/berkeley/fleet/ir/Context.java +++ b/src/edu/berkeley/fleet/ir/Context.java @@ -108,7 +108,7 @@ public class Context { */ public LoopFactory(Dock dock, int count) { this(dock, count, dock.toString(), null); } public LoopFactory(Dock dock, int count, String friendlyName) { this(dock, count, friendlyName, null); } - public LoopFactory(Dock dock, int count, String friendlyName, LoopFactory prev) { + private LoopFactory(Dock dock, int count, String friendlyName, LoopFactory prev) { this.dock = dock; this.count = count; this.friendlyName = friendlyName; @@ -234,8 +234,8 @@ public class Context { } /** [outboxes only], will fuse with previous instruction if it was a sendToken() */ - public void send(Destination dest) { send(dest, null); } - public void send(Destination dest, BitVector signal) { + public void sendWord(Destination dest) { sendWord(dest, null); } + public void sendWord(Destination dest, BitVector signal) { if (!dock.isOutputDock()) throw new RuntimeException("sendWord() may only be used at output docks"); if (pending_sendToken) flush_pending(); pending_path = dock.getPath(dest, signal); diff --git a/src/edu/berkeley/fleet/ir/New.java b/src/edu/berkeley/fleet/ir/New.java index 2478c46..54a5977 100644 --- a/src/edu/berkeley/fleet/ir/New.java +++ b/src/edu/berkeley/fleet/ir/New.java @@ -31,13 +31,13 @@ public class New { public LoopFactory getLoopFactory(Dock d) { return getLoopFactory(d, 0); } public LoopFactory getNextLoopFactory(Dock d, int count) { LoopFactory lf = loops.get(d); - if (lf!=null) loops.put(d, lf = context.new LoopFactory(d, count, d+"", lf)); + if (lf!=null) loops.put(d, lf = lf.makeNext(count, d+"")); return getLoopFactory(d, count); } public LoopFactory getLoopFactory(Dock d, int count) { LoopFactory lf = loops.get(d); if (lf==null) { - loops.put(d, lf = context.new LoopFactory(d, count, d+"", null)); + loops.put(d, lf = context.new LoopFactory(d, count, d+"")); emitLoops.add(lf); } if (lf.count != count) throw new RuntimeException(); @@ -56,7 +56,6 @@ public class New { public void emit(ArrayList al) { for(Segment s : segments) s.emitPrologue(al); for(Segment s : segments) s.emitInstructions(al); - for(Segment s : segments) s.emitEpilogue(al); for(LoopFactory lf : emitLoops) lf.emit(al); } @@ -84,7 +83,6 @@ public class New { public abstract Dock[] _setInputs(); public void emitPrologue(ArrayList il) { } public abstract void emitInstructions(ArrayList il); - public void emitEpilogue(ArrayList il) { } } public class Debug extends Segment { @@ -97,11 +95,10 @@ public class New { public void emitPrologue(ArrayList il) { } public void emitInstructions(ArrayList il) { LoopFactory lf; - lf = context.new LoopFactory(debugShip.getDock("in"), 0, "debug.in", null); + lf = context.new LoopFactory(debugShip.getDock("in"), 0, "debug.in"); lf.recvWord(); lf.deliver(); } - public void emitEpilogue(ArrayList il) { } } public class Constant extends Segment { @@ -127,8 +124,6 @@ public class New { lf = getNextLoopFactory(fifoShip.getDock("in"), 0); lf.deliver(); } - public void emitEpilogue(ArrayList il) { - } } public class Alu extends Segment { @@ -154,7 +149,7 @@ public class New { recvSendTokenDeliver(alu.getDock("inOp"), inputs[2].getDataDestination()); LoopFactory lf; lf = getLoopFactory(inputs[2], 0); - lf.send(alu.getDock("inOp").getDataDestination()); + lf.sendWord(alu.getDock("inOp").getDataDestination()); lf.recvToken(); } else { LoopFactory lf; @@ -167,16 +162,14 @@ public class New { recvSendTokenDeliver(alu.getDock("in1"), inputs[0].getDataDestination()); LoopFactory lf; lf = getLoopFactory(inputs[0], 0); - lf.send(alu.getDock("in1").getDataDestination()); + lf.sendWord(alu.getDock("in1").getDataDestination()); lf.recvToken(); recvSendTokenDeliver(alu.getDock("in2"), inputs[1].getDataDestination()); lf = getLoopFactory(inputs[1], 0); - lf.send(alu.getDock("in2").getDataDestination()); + lf.sendWord(alu.getDock("in2").getDataDestination()); lf.recvToken(); } - public void emitEpilogue(ArrayList il) { - } } public class Counter extends Segment { @@ -213,11 +206,9 @@ public class New { lf.literal(incr); lf = getNextLoopFactory(alu.getDock("in2"), 0); lf.deliver(); - } - public void emitEpilogue(ArrayList il) { - LoopFactory lf; + lf = getLoopFactory(alu.getDock("out"), 0); - lf.send(alu.getDock("in1").getDataDestination()); + lf.sendWord(alu.getDock("in1").getDataDestination()); lf.collectWord(); } } @@ -254,10 +245,9 @@ public class New { public void emitInstructions(ArrayList il) { LoopFactory lf; - lf = getLoopFactory(alu.getDock("inOp"), 0); - lf.literal(4); // MAX - lf.deliver(); + lf = getLoopFactory(alu.getDock("inOp"), 1); lf.literal(4); // MAX + lf = getNextLoopFactory(alu.getDock("inOp"), 0); lf.deliver(); lf = getLoopFactory(alu.getDock("in1"), 0); @@ -275,13 +265,11 @@ public class New { lf.deliver(); lf = getLoopFactory(inputs[0], 0); - lf.send(alu.getDock("in2").getDataDestination()); - lf.send(alu.getDock("in1").getDataDestination()); + lf.sendWord(alu.getDock("in2").getDataDestination()); + lf.sendWord(alu.getDock("in1").getDataDestination()); lf.recvToken(); lf.recvToken(); } - - public void emitEpilogue(ArrayList il) { } } public class FifoWithInit extends Segment { @@ -297,24 +285,22 @@ public class New { } public void emitPrologue(ArrayList il) { LoopFactory lf; - lf = getLoopFactory(fifoShip.getDock("out"), 1); + lf = getLoopFactory(fifoShip.getDock("in"), 1); lf.literal(init); - lf = getNextLoopFactory(fifoShip.getDock("out"), 0); - lf = getLoopFactory(fifoShip.getDock("in"), 0); + lf.deliver(); + lf = getNextLoopFactory(fifoShip.getDock("in"), 0); + + lf = getLoopFactory(fifoShip.getDock("out"), 0); + lf.collectWord(); } public void emitInstructions(ArrayList il) { LoopFactory lf; lf = getLoopFactory(inputs[0], 0); - lf.send(fifoShip.getDock("in").getDataDestination()); + lf.sendWord(fifoShip.getDock("in").getDataDestination()); lf.recvToken(); recvSendTokenDeliver(fifoShip.getDock("in"), inputs[0].getDataDestination()); } - public void emitEpilogue(ArrayList il) { - LoopFactory lf; - lf = getLoopFactory(fifoShip.getDock("out"), 0); - lf.collectWord(); - } } public class Video extends Segment { @@ -334,18 +320,17 @@ public class New { LoopFactory lf; lf = getLoopFactory(inputs[0]); - lf.send(videoShip.getDock("inX").getDataDestination()); + lf.sendWord(videoShip.getDock("inX").getDataDestination()); lf.recvToken(); lf = getLoopFactory(inputs[1]); - lf.send(videoShip.getDock("inY").getDataDestination()); + lf.sendWord(videoShip.getDock("inY").getDataDestination()); lf.recvToken(); lf = getLoopFactory(inputs[2]); - lf.send(videoShip.getDock("inData").getDataDestination()); + lf.sendWord(videoShip.getDock("inData").getDataDestination()); lf.recvToken(); } - public void emitEpilogue(ArrayList il) { } } public static Dock bouncer(New n, int delt, int start, int min, int max) throws Exception { @@ -384,19 +369,19 @@ public class New { "Fifo", "Fifo", "Fifo", "Fifo", "Fifo", "Fifo", - "alu2", "alu2", - "alu2", "alu2", - "alu2", "alu2", - "alu2", "alu2", - "alu2", "alu2", - "alu2", "alu2", + "Alu", "Alu", + "Alu", "Alu", + "Alu", "Alu", + "Alu", "Alu", + "Alu", "Alu", + "Alu", "Alu", "Video" }, false)); Dock x_pos = bouncer(n, 1, 6, 5, 634); Dock y_pos = bouncer(n, 1, 6, 5, 474); - //Dock color = n.new Constant(2).setInputs(new Dock[0])[0]; - Dock color = n.new Counter(0,1).setInputs(new Dock[0])[0]; + Dock color = n.new Constant(2).setInputs(new Dock[0])[0]; + //Dock color = n.new Counter(0,1).setInputs(new Dock[0])[0]; //debug.setInputs(new Dock[] { x_pos }); Video vid = n.new Video(); -- 1.7.10.4