These types are part of a Monotone Analysis Framework, @see see for example this set of slides . The types form a lattice; @see a symmetric comple
| 22 | */ |
| 23 | |
| 24 | public class Type { |
| 25 | static final HashMap<Type,Type> INTERN = new HashMap<>(); |
| 26 | |
| 27 | // ---------------------------------------------------------- |
| 28 | // Simple types are implemented fully here. "Simple" means: the code and |
| 29 | // type hierarchy are simple, not that the Type is conceptually simple. |
| 30 | static final byte TBOT = 0; // Bottom (ALL) |
| 31 | static final byte TTOP = 1; // Top (ANY) |
| 32 | static final byte TCTRL = 2; // Ctrl flow bottom |
| 33 | static final byte TXCTRL = 3; // Ctrl flow top (mini-lattice: any-xctrl-ctrl-all) |
| 34 | static final byte TSIMPLE = 4; // End of the Simple Types |
| 35 | static final byte TINT = 5; // All Integers; see TypeInteger |
| 36 | static final byte TTUPLE = 6; // Tuples; finite collections of unrelated Types, kept in parallel |
| 37 | static final byte TMEM = 7; // Whole-memory token |
| 38 | static final byte TMEMPTR = 8; // Memory pointer type |
| 39 | static final byte TSTRUCT = 9; // Structs; tuples with named fields |
| 40 | static final byte TFLD =10; // Fields into struct |
| 41 | |
| 42 | public final byte _type; |
| 43 | |
| 44 | public boolean is_simple() { return _type < TSIMPLE; } |
| 45 | private static final String[] STRS = new String[]{"Bot","Top","Ctrl","~Ctrl"}; |
| 46 | protected Type(byte type) { _type = type; } |
| 47 | |
| 48 | public static final Type BOTTOM = new Type( TBOT ).intern(); // ALL |
| 49 | public static final Type TOP = new Type( TTOP ).intern(); // ANY |
| 50 | public static final Type CONTROL = new Type( TCTRL ).intern(); // Ctrl |
| 51 | public static final Type XCONTROL = new Type( TXCTRL ).intern(); // ~Ctrl |
| 52 | public static Type[] gather() { |
| 53 | ArrayList<Type> ts = new ArrayList<>(); |
| 54 | ts.add(BOTTOM); |
| 55 | ts.add(CONTROL); |
| 56 | Field.gather(ts); |
| 57 | TypeInteger.gather(ts); |
| 58 | TypeMem.gather(ts); |
| 59 | TypeMemPtr.gather(ts); |
| 60 | TypeStruct.gather(ts); |
| 61 | TypeTuple.gather(ts); |
| 62 | int sz = ts.size(); |
| 63 | for( int i = 0; i < sz; i++ ) |
| 64 | ts.add(ts.get(i).dual()); |
| 65 | return ts.toArray(new Type[ts.size()]); |
| 66 | } |
| 67 | |
| 68 | // Is high or on the lattice centerline. |
| 69 | public boolean isHighOrConst() { return _type==TTOP || _type==TXCTRL; } |
| 70 | |
| 71 | // Strict constant values, things on the lattice centerline. |
| 72 | // Excludes both high and low values |
| 73 | public boolean isConstant() { return false; } |
| 74 | |
| 75 | /** |
| 76 | * Display Type name in a format that's good for IR printer |
| 77 | */ |
| 78 | public StringBuilder typeName( StringBuilder sb) { return print(sb); } |
| 79 | |
| 80 | public Type makeInit() { return null; } |
| 81 |