X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Ffleet%2Finterpreter%2FLog.java;h=914e524ed58b5765d15bed8a0a24ddcddb670c8a;hb=97dc45abf108f763821ab47d39ab21d05b1fce22;hp=f3bc864055ef696a52f71bea72ced6ee740a131a;hpb=001225f0c21ce9dc476b89d3c77563f1bd1c4c2c;p=fleet.git diff --git a/src/edu/berkeley/fleet/interpreter/Log.java b/src/edu/berkeley/fleet/interpreter/Log.java index f3bc864..914e524 100644 --- a/src/edu/berkeley/fleet/interpreter/Log.java +++ b/src/edu/berkeley/fleet/interpreter/Log.java @@ -1,61 +1,51 @@ package edu.berkeley.fleet.interpreter; +import edu.berkeley.sbp.util.ANSI; import edu.berkeley.fleet.api.*; -import edu.berkeley.fleet.api.Instruction; 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; public static void print(Object o) { + 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) { + if (log==null || quiet) return; try { log.println(o); log.flush(); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - public static void dispatch(Dispatchable d) { - println(green("dispatch: " + indent(d+"", " "))); - } - public static void dispatch(Instruction d) { - println(green("dispatch: " + indent(d+"", " "))); + } catch (Exception e) { throw new RuntimeException(e); } } - public static void data(String data, BenkoBox source, BenkoBox dest) { - println((" data: ") + indent(purple(data) + - (source==null ? "" : - (" : " + source))+(" -> "+purple(""+dest)), " ")); - } - - public static void token(BenkoBox source, BenkoBox dest) { - println(purple(" token: ") + (source + " -> " + 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 String black(Object o) { if (!ansi_color) return o+""; return o+""; } - public static String red(Object o) { if (!ansi_color) return o+""; return "\033[31m"+o+"\033[0m"; } - public static String green(Object o) { if (!ansi_color) return o+""; return "\033[32m"+o+"\033[0m"; } - public static String yellow(Object o) { if (!ansi_color) return o+""; return "\033[33m"+o+"\033[0m"; } - public static String blue(Object o) { if (!ansi_color) return o+""; return "\033[34m"+o+"\033[0m"; } - public static String purple(Object o) { if (!ansi_color) return o+""; return "\033[35m"+o+"\033[0m"; } - public static String cyan(Object o) { if (!ansi_color) return o+""; return "\033[36m"+o+"\033[0m"; } - public static String invert(Object o) { if (!ansi_color) return o+""; return "\033[7m"+o+"\033[0m"; } - public static String bold(Object o) { if (!ansi_color) return o+""; return "\033[1m"+o+"\033[0m"; } - - public static void error(Object o) { println(red(o)); } + public static void error(Object o) { println(ANSI.red(o)); } public static String indent(String s, String indent) { StringBuffer ret = new StringBuffer();