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 TFLT = 6; // All Integers; see TypeInteger |
| 37 | static final byte TTUPLE = 7; // Tuples; finite collections of unrelated Types, kept in parallel |
| 38 | static final byte TMEM = 8; // All memory (alias 0) or A slice of memory - with specific alias |
| 39 | static final byte TMEMPTR = 9; // Memory pointer type |
| 40 | static final byte TSTRUCT =10; // Structs; tuples with named fields |
| 41 | static final byte TFLD =11; // Fields into struct |
| 42 | |
| 43 | public final byte _type; |
| 44 | |
| 45 | public boolean is_simple() { return _type < TSIMPLE; } |
| 46 | private static final String[] STRS = new String[]{"Bot","Top","Ctrl","~Ctrl"}; |
| 47 | protected Type(byte type) { _type = type; } |
| 48 | |
| 49 | public static final Type BOTTOM = new Type( TBOT ).intern(); // ALL |
| 50 | public static final Type TOP = new Type( TTOP ).intern(); // ANY |
| 51 | public static final Type CONTROL = new Type( TCTRL ).intern(); // Ctrl |
| 52 | public static final Type XCONTROL = new Type( TXCTRL ).intern(); // ~Ctrl |
| 53 | public static Type[] gather() { |
| 54 | ArrayList<Type> ts = new ArrayList<>(); |
| 55 | ts.add(BOTTOM); |
| 56 | ts.add(CONTROL); |
| 57 | Field.gather(ts); |
| 58 | TypeInteger.gather(ts); |
| 59 | TypeFloat.gather(ts); |
| 60 | TypeMem.gather(ts); |
| 61 | TypeMemPtr.gather(ts); |
| 62 | TypeStruct.gather(ts); |
| 63 | TypeTuple.gather(ts); |
| 64 | int sz = ts.size(); |
| 65 | for( int i = 0; i < sz; i++ ) |
| 66 | ts.add(ts.get(i).dual()); |
| 67 | return ts.toArray(new Type[ts.size()]); |
| 68 | } |
| 69 | |
| 70 | // Is high or on the lattice centerline. |
| 71 | public boolean isHigh () { return _type==TTOP || _type==TXCTRL; } |
| 72 | public boolean isHighOrConst() { return _type==TTOP || _type==TXCTRL; } |
| 73 | |
| 74 | // Strict constant values, things on the lattice centerline. |
| 75 | // Excludes both high and low values |
| 76 | public boolean isConstant() { return false; } |
| 77 | |
| 78 | /** |
| 79 | * Display Type name in a format that's good for IR printer |
| 80 | */ |
| 81 | public StringBuilder typeName( StringBuilder sb) { return print(sb); } |