1
2
3
4 package joeq.Compiler.Dataflow;
5
6 import java.util.Comparator;
7 import joeq.Compiler.Quad.BasicBlock;
8 import jwutil.collections.Pair;
9
10 public class BBComparator implements Comparator {
11
12 public static final BBComparator INSTANCE = new BBComparator();
13 private BBComparator() {}
14
15
16
17
18 public int compare(Object o1, Object o2) {
19 if (o1 == o2) return 0;
20 int r;
21 BasicBlock a, b;
22 if (o1 instanceof Pair) {
23 a = (BasicBlock) ((Pair) o1).left;
24 if (o2 instanceof Pair) {
25 BasicBlock a2 = (BasicBlock) ((Pair) o1).right;
26 b = (BasicBlock) ((Pair) o2).left;
27 BasicBlock b2 = (BasicBlock) ((Pair) o2).right;
28 r = compare(a, b);
29 if (r == 0) r = compare(a2, b2);
30 return r;
31 } else {
32 b = (BasicBlock) o2;
33 }
34 } else {
35 a = (BasicBlock) o1;
36 if (o2 instanceof Pair) {
37 b = (BasicBlock) ((Pair) o2).left;
38 } else {
39 b = (BasicBlock) o2;
40 }
41 }
42 r = compare(a, b);
43 if (r == 0) r = (o2 instanceof Pair)?1:-1;
44 return r;
45 }
46
47 public int compare(BasicBlock bb1, BasicBlock bb2) {
48 if (bb1 == bb2) return 0;
49 else if (bb1.getID() < bb2.getID()) return -1;
50 else return 1;
51 }
52
53 }