MCPcopy Create free account
hub / github.com/SeaOfNodes/Simple / Type

Class Type

chapter16/src/main/java/com/seaofnodes/simple/type/Type.java:24–202  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

22 */
23
24public 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 static final byte TARRAY =12; // Array
43
44 public final byte _type;
45
46 public boolean is_simple() { return _type < TSIMPLE; }
47 private static final String[] STRS = new String[]{"Bot","Top","Ctrl","~Ctrl"};
48 protected Type(byte type) { _type = type; }
49
50 public static final Type BOTTOM = new Type( TBOT ).intern(); // ALL
51 public static final Type TOP = new Type( TTOP ).intern(); // ANY
52 public static final Type CONTROL = new Type( TCTRL ).intern(); // Ctrl
53 public static final Type XCONTROL = new Type( TXCTRL ).intern(); // ~Ctrl
54 public static Type[] gather() {
55 ArrayList<Type> ts = new ArrayList<>();
56 ts.add(BOTTOM);
57 ts.add(CONTROL);
58 Field.gather(ts);
59 TypeInteger.gather(ts);
60 TypeFloat.gather(ts);
61 TypeMem.gather(ts);
62 TypeMemPtr.gather(ts);
63 TypeStruct.gather(ts);
64 TypeTuple.gather(ts);
65 int sz = ts.size();
66 for( int i = 0; i < sz; i++ )
67 ts.add(ts.get(i).dual());
68 return ts.toArray(new Type[ts.size()]);
69 }
70
71 // Is high or on the lattice centerline.
72 public boolean isHigh () { return _type==TTOP || _type==TXCTRL; }
73 public boolean isHighOrConst() { return _type==TTOP || _type==TXCTRL; }
74
75 // Strict constant values, things on the lattice centerline.
76 // Excludes both high and low values
77 public boolean isConstant() { return false; }
78
79 /**
80 * Display Type name in a format that's good for IR printer
81 */

Callers

nothing calls this directly

Calls 1

internMethod · 0.45

Tested by

no test coverage detected