From: Adam Megacz Date: Sat, 22 Aug 2009 18:40:00 +0000 (-0700) Subject: better colorization of interpreter logs X-Git-Url: http://git.megacz.com/?p=fleet.git;a=commitdiff_plain;h=97dc45abf108f763821ab47d39ab21d05b1fce22 better colorization of interpreter logs --- diff --git a/src/edu/berkeley/fleet/interpreter/Interpreter.java b/src/edu/berkeley/fleet/interpreter/Interpreter.java index e4cfb8a..c43ad40 100644 --- a/src/edu/berkeley/fleet/interpreter/Interpreter.java +++ b/src/edu/berkeley/fleet/interpreter/Interpreter.java @@ -190,7 +190,6 @@ public class Interpreter extends FleetTwoFleet { } public Fleet getFleet() { return Interpreter.this; } public synchronized void sendInstruction(Instruction i) { - Log.dispatch(i); long il = writeInstruction(i, debugShip.getDock("in")); Path path = debugShip.getDock("in").getPath(i.dock.getInstructionDestination(), null); new Packet((InterpreterPath)path, new BitVector(getWordWidth()).set(il), false).send(); diff --git a/src/edu/berkeley/fleet/interpreter/Log.java b/src/edu/berkeley/fleet/interpreter/Log.java index a83d15c..914e524 100644 --- a/src/edu/berkeley/fleet/interpreter/Log.java +++ b/src/edu/berkeley/fleet/interpreter/Log.java @@ -5,7 +5,6 @@ import java.io.*; public class Log { - public static boolean ansi_color = true; public static PrintWriter log = new PrintWriter(new OutputStreamWriter(System.out)); public static boolean quiet = false; @@ -13,9 +12,7 @@ public class Log { if (log==null || quiet) return; try { log.print(o); - } catch (Exception e) { - throw new RuntimeException(e); - } + } catch (Exception e) { throw new RuntimeException(e); } } public static void println() { println(""); } public static void println(Object o) { @@ -23,31 +20,31 @@ public class Log { try { log.println(o); log.flush(); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - /* - public static void dispatch(Dispatchable d) { - println(ANSI.green("dispatch: " + indent(d+"", " "))); - } - */ - public static void dispatch(Instruction d) { - println(ANSI.green("dispatch: " + indent(d+"", " "))); - } - - public static void data(String data, Dock source, Destination dest) { - println((" data: ") + indent(ANSI.purple(data) + - (source==null ? "" : - (" : " + source))+(" -> "+ANSI.purple(""+dest)), " ")); + } catch (Exception e) { throw new RuntimeException(e); } } - public static void token(Dock source, Destination dest) { - println(ANSI.purple(" token: ") + (source + " -> " + ANSI.purple(dest+""))); + public static void packet(Packet p) { + BitVector data = p.getValue(); + Dock source = p.getSource(); + Destination dest = p.getDestination(); + if (dest.getDock().getInstructionDestination()==dest) { + if (p.isToken()) { + println(ANSI.yellow(ANSI.bold(" torpedo: ")) + (source + " -> " + ANSI.yellow(ANSI.bold(dest+"")))); + } else { + Instruction d = source.getShip().getFleet().decodeInstruction(data, source); + println(ANSI.red("dispatch: " + indent(d+"", " "))); + } + } else { + if (p.isToken()) { + println(ANSI.blue(ANSI.bold(" token: ")) + (source + " -> " + ANSI.blue(ANSI.bold(dest+"")))); + } else { + println(indent(ANSI.cyan(" data: "+data) + + (source==null ? "" : + (" : " + source))+(" -> "+ANSI.cyan(""+dest)), " ")); + } + } } - public static String clreol() { return ""; } public static void error(Object o) { println(ANSI.red(o)); } public static String indent(String s, String indent) { diff --git a/src/edu/berkeley/fleet/interpreter/Packet.java b/src/edu/berkeley/fleet/interpreter/Packet.java index 5f44da2..d26b894 100644 --- a/src/edu/berkeley/fleet/interpreter/Packet.java +++ b/src/edu/berkeley/fleet/interpreter/Packet.java @@ -15,11 +15,7 @@ class Packet { } public void send() { - if (isToken) { - Log.token(path.getSource(), path.getDestination()); - } else { - Log.data(value+"", path.getSource(), path.getDestination()); - } + Log.packet(this); ((InterpreterDestination)path.getDestination()).addDataFromFabric(this); } @@ -27,6 +23,10 @@ class Packet { return path.getDestination(); } + public Dock getSource() { + return path.getSource(); + } + public BitVector getSignal() { return path.getSignal(); }