DbgUtils.java 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package com.oblivm.backend.gc;
  2. import com.oblivm.backend.flexsc.CompEnv;
  3. import com.oblivm.backend.gc.regular.GCEva;
  4. import com.oblivm.backend.gc.regular.GCGen;
  5. public class DbgUtils {
  6. static void debugMsg(CompEnv<GCSignal> env, String msg) {
  7. if (env instanceof GCEva)
  8. System.err.println(msg);
  9. }
  10. static void debugVal(CompEnv<GCSignal> env, GCSignal bs, String msg) throws Exception {
  11. if (env instanceof GCGen) {
  12. bs.send(((GCGen) env).channel);
  13. GCGen.R.send(((GCGen) env).channel);
  14. } else {
  15. int x;
  16. GCSignal glb = GCSignal.receive(((GCEva) env).channel);
  17. GCSignal R = GCSignal.receive(((GCEva) env).channel);
  18. if (bs.equals(glb))
  19. x = 0;
  20. else if (bs.equals(R.xor(glb)))
  21. x = 1;
  22. else
  23. throw new Exception(String.format("bad label: %s", bs.toHexStr()));
  24. System.out.println(String.format("%s = %d", msg, x));
  25. }
  26. }
  27. static void debugLabel(CompEnv<GCSignal> env, GCSignal bs, String msg) {
  28. if (env instanceof GCGen) {
  29. System.err.println(String.format("[%s] %s, %s", msg, bs.toHexStr(), GCGen.R.xor(bs).toHexStr()));
  30. } else
  31. System.out.println(String.format("[%s] %s", msg, bs.toHexStr()));
  32. }
  33. }