summaryrefslogtreecommitdiff
path: root/chapter25
diff options
context:
space:
mode:
Diffstat (limited to 'chapter25')
-rw-r--r--chapter25/src/main/java/com/seaofnodes/simple/Parser.java3
-rw-r--r--chapter25/src/main/java/com/seaofnodes/simple/codegen/CodeGen.java3
-rw-r--r--chapter25/src/main/java/com/seaofnodes/simple/codegen/ElfExpr.java87
-rw-r--r--chapter25/src/main/java/com/seaofnodes/simple/codegen/IFG.java4
-rw-r--r--chapter25/src/main/java/com/seaofnodes/simple/codegen/RegAlloc.java2
-rw-r--r--chapter25/src/main/java/com/seaofnodes/simple/codegen/Serialize.java4
-rw-r--r--chapter25/src/main/java/com/seaofnodes/simple/node/CheckCastMach.java20
-rw-r--r--chapter25/src/main/java/com/seaofnodes/simple/node/CheckCastNode.java82
-rw-r--r--chapter25/src/main/java/com/seaofnodes/simple/node/LoadNode.java1
-rw-r--r--chapter25/src/main/java/com/seaofnodes/simple/node/MachConcreteNode.java5
-rw-r--r--chapter25/src/main/java/com/seaofnodes/simple/node/MemMergeNode.java2
-rw-r--r--chapter25/src/main/java/com/seaofnodes/simple/node/Node.java6
-rw-r--r--chapter25/src/main/java/com/seaofnodes/simple/node/PtrToIntNode.java7
-rw-r--r--chapter25/src/main/java/com/seaofnodes/simple/node/StoreNode.java2
-rw-r--r--chapter25/src/main/java/com/seaofnodes/simple/node/StructNode.java60
-rw-r--r--chapter25/src/main/java/com/seaofnodes/simple/node/cpus/arm/MemOpARM.java5
-rw-r--r--chapter25/src/main/java/com/seaofnodes/simple/node/cpus/arm/arm.java1
-rw-r--r--chapter25/src/main/java/com/seaofnodes/simple/node/cpus/riscv/MemOpRISC.java4
-rw-r--r--chapter25/src/main/java/com/seaofnodes/simple/node/cpus/riscv/riscv.java1
-rw-r--r--chapter25/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/MemOpX86.java5
-rw-r--r--chapter25/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/x86_64_v2.java1
-rw-r--r--chapter25/src/main/java/com/seaofnodes/simple/print/JSViewer.java1
-rw-r--r--chapter25/src/main/java/com/seaofnodes/simple/type/Type.java10
-rw-r--r--chapter25/src/main/java/com/seaofnodes/simple/type/TypeConAry.java10
-rw-r--r--chapter25/src/main/java/com/seaofnodes/simple/type/TypeFloat.java4
-rw-r--r--chapter25/src/main/java/com/seaofnodes/simple/type/TypeInteger.java2
-rw-r--r--chapter25/src/main/java/com/seaofnodes/simple/type/TypeMem.java2
-rw-r--r--chapter25/src/main/java/com/seaofnodes/simple/type/TypePtr.java2
-rw-r--r--chapter25/src/main/java/com/seaofnodes/simple/type/TypeStruct.java2
-rw-r--r--chapter25/src/main/java/com/seaofnodes/simple/type/TypeTuple.java6
-rw-r--r--chapter25/src/test/java/com/seaofnodes/simple/Eval2.java1
31 files changed, 36 insertions, 309 deletions
diff --git a/chapter25/src/main/java/com/seaofnodes/simple/Parser.java b/chapter25/src/main/java/com/seaofnodes/simple/Parser.java
index 98093a77..e87fec35 100644
--- a/chapter25/src/main/java/com/seaofnodes/simple/Parser.java
+++ b/chapter25/src/main/java/com/seaofnodes/simple/Parser.java
@@ -999,9 +999,6 @@ public class Parser {
// Auto-widen array to i64 (cast ptr to raw int bits)
if( t == TypeInteger.BOT && expr._type instanceof TypeMemPtr tmp && tmp._obj.isAry() )
return peep(new AddNode(peep(new PtrToIntNode(expr)),off(tmp._obj,"[]")));
- // Null check has to eventually pass
- if( t == Type.NIL && expr._type instanceof TypeMemPtr tmp && tmp.notNull() )
- return peep(new CheckCastNode(t,null,expr));
// Widen ints to floats, narrow wide types
return peep(new ConvertNode(t,expr));
}
diff --git a/chapter25/src/main/java/com/seaofnodes/simple/codegen/CodeGen.java b/chapter25/src/main/java/com/seaofnodes/simple/codegen/CodeGen.java
index bcefe996..a83b82a1 100644
--- a/chapter25/src/main/java/com/seaofnodes/simple/codegen/CodeGen.java
+++ b/chapter25/src/main/java/com/seaofnodes/simple/codegen/CodeGen.java
@@ -84,7 +84,8 @@ public class CodeGen {
assert _compunits.size()==1;
for( CompUnit cu : _compunits.values() )
return cu;
- throw Utils.TODO();
+ assert false : "no compilation unit";
+ return null;
}
// True when fidx is published through a public field of a public class.
diff --git a/chapter25/src/main/java/com/seaofnodes/simple/codegen/ElfExpr.java b/chapter25/src/main/java/com/seaofnodes/simple/codegen/ElfExpr.java
deleted file mode 100644
index 9d9b8a1c..00000000
--- a/chapter25/src/main/java/com/seaofnodes/simple/codegen/ElfExpr.java
+++ /dev/null
@@ -1,87 +0,0 @@
-package com.seaofnodes.simple.codegen;
-
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-
-public class ElfExpr {
- public static void main(String[] args) {
- try (FileOutputStream fos = new FileOutputStream("hello.o")) {
- ByteBuffer buffer = ByteBuffer.allocate(512);
- buffer.order(ByteOrder.LITTLE_ENDIAN);
-
- // === ELF HEADER (64 bytes) ===
- buffer.put(new byte[]{
- 0x7F, 'E', 'L', 'F', // ELF Magic
- 2, 1, 1, 0, // 64-bit, little-endian, version
- 0, 0, 0, 0, 0, 0, 0, // ABI padding
- 2, 0, // Type: Executable (ET_EXEC)
- 0x3E, 0x00, // Machine: x86-64
- 1, 0, 0, 0, // ELF version
- 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Entry point
- 0, 0, 0, 0, 0, 0, 0, 0, // Program header offset
- 64, 0, 0, 0, 0, 0, 0, 0, // Section header offset
- 0, 0, 0, 0, // Flags
- 64, 0, // ELF header size
- 0, 0, // Program header entry size
- 0, 0, // Number of program header entries
- 40, 0, // Section header entry size
- 2, 0, // Number of section headers
- 1, 0 // Section header string table index
- });
-
- // === .TEXT SECTION (Executable Code) ===
- byte[] textSection = {
- // sys_write (write(1, message, 13))
- (byte) 0x48, (byte) 0xC7, (byte) 0xC0, 0x01, 0x00, 0x00, 0x00, // mov rax, 1
- (byte) 0x48, (byte) 0xC7, (byte) 0xC7, 0x01, 0x00, 0x00, 0x00, // mov rdi, 1
- (byte) 0x48, (byte) 0xBE, (byte)0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // mov rsi, message
- (byte) 0x48, (byte) 0xC7, (byte) 0xC2, 0x0D, 0x00, 0x00, 0x00, // mov rdx, 13
- (byte) 0x0F, (byte) 0x05, // syscall
-
- // sys_exit (exit(0))
- (byte) 0x48, (byte) 0xC7, (byte) 0xC0, 0x3C, 0x00, 0x00, 0x00, // mov rax, 60
- (byte) 0x48, (byte) 0x31, (byte) 0xFF, // xor rdi, rdi
- (byte) 0x0F, (byte) 0x05 // syscall
- };
-
- // Append section data
- buffer.position(256);
- buffer.put(textSection);
-
- // === STRING MESSAGE (.data Section) ===
- byte[] message = "Hello, World!\n".getBytes();
- buffer.position(400);
- buffer.put(message);
-
- // === SECTION HEADERS ===
- buffer.position(64);
-
- // Null Section (required as first entry)
- buffer.put(new byte[40]);
-
- // .text Section
- buffer.putInt(1); // Offset in section string table (".text")
- buffer.putInt(1); // Type: SHT_PROGBITS
- buffer.putLong(6); // Flags: Executable | Allocatable
- buffer.putLong(0); // Virtual address
- buffer.putLong(256); // Offset to section data
- buffer.putLong(textSection.length); // Section size
- buffer.putInt(0); // Link
- buffer.putInt(0); // Info
- buffer.putLong(4); // Address alignment
- buffer.putLong(0); // No extra entries
-
- // === SECTION HEADER STRING TABLE ===
- buffer.position(500);
- buffer.put(".text".getBytes());
- buffer.put((byte) 0x00); // Null terminator
-
- fos.write(buffer.array());
- System.out.println("ELF object file 'hello.o' created.");
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-}
diff --git a/chapter25/src/main/java/com/seaofnodes/simple/codegen/IFG.java b/chapter25/src/main/java/com/seaofnodes/simple/codegen/IFG.java
index 2b559a38..e4e9dd69 100644
--- a/chapter25/src/main/java/com/seaofnodes/simple/codegen/IFG.java
+++ b/chapter25/src/main/java/com/seaofnodes/simple/codegen/IFG.java
@@ -224,9 +224,7 @@ abstract public class IFG {
selfConflict(alloc,n,lrg,TMP.get(lrg));
}
private static void selfConflict(RegAlloc alloc, Node n, LRG lrg, Node prior) {
- // Casts never produce a *new* value, just lift our understanding of the value.
- // They do not force self-conflicts.
- if( prior!=null && prior != n && !(n instanceof CheckCastNode) ) {
+ if( prior!=null && prior != n ) {
lrg.selfConflict(prior);
lrg.selfConflict(n);
alloc.fail(lrg); // 2 unrelated values live at once same live range; self-conflict
diff --git a/chapter25/src/main/java/com/seaofnodes/simple/codegen/RegAlloc.java b/chapter25/src/main/java/com/seaofnodes/simple/codegen/RegAlloc.java
index 0d5b9e7b..6650b19c 100644
--- a/chapter25/src/main/java/com/seaofnodes/simple/codegen/RegAlloc.java
+++ b/chapter25/src/main/java/com/seaofnodes/simple/codegen/RegAlloc.java
@@ -753,6 +753,6 @@ public class RegAlloc {
if( lrg(n)!=null && lrg(n)._reg == defreg )
return false; // Clobbered
}
- throw Utils.TODO();
+ throw Utils.TODO("Should not reach here");
}
}
diff --git a/chapter25/src/main/java/com/seaofnodes/simple/codegen/Serialize.java b/chapter25/src/main/java/com/seaofnodes/simple/codegen/Serialize.java
index 7c230f9c..ee5c48df 100644
--- a/chapter25/src/main/java/com/seaofnodes/simple/codegen/Serialize.java
+++ b/chapter25/src/main/java/com/seaofnodes/simple/codegen/Serialize.java
@@ -438,10 +438,6 @@ abstract public class Serialize {
for( Node n : code._start._outputs ) {
if( n instanceof ConstantNode con && !visit.get(con._nid) ) {
for( Node use : con.outs() ) {
- // Special case for Cast:BOT which is basically a double-indirect constant
- if( use instanceof CheckCastNode cast && cast.in(0)==null )
- for( Node useuse : cast.outs() )
- conUsed(cast,useuse,visit,cons);
// PtrToInt is another zero-code value rooted at a global
// constant. Its array-body Add is the value used by the
// function, so include that extra link in the ownership
diff --git a/chapter25/src/main/java/com/seaofnodes/simple/node/CheckCastMach.java b/chapter25/src/main/java/com/seaofnodes/simple/node/CheckCastMach.java
deleted file mode 100644
index 9943c7b4..00000000
--- a/chapter25/src/main/java/com/seaofnodes/simple/node/CheckCastMach.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.seaofnodes.simple.node;
-
-import com.seaofnodes.simple.codegen.CodeGen;
-import com.seaofnodes.simple.codegen.Encoding;
-import com.seaofnodes.simple.codegen.RegMask;
-import com.seaofnodes.simple.type.Type;
-import com.seaofnodes.simple.util.SB;
-
-/**
- * Cast a pointer to read-only
- */
-public class CheckCastMach extends CheckCastNode implements MachNode {
- public CheckCastMach( CheckCastNode n ) { super(n); }
- @Override public String op() { return label(); }
- @Override public RegMask regmap(int i) { assert i==1; return RegMask.FULL; }
- @Override public RegMask outregmap() { return RegMask.FULL; }
- @Override public int twoAddress( ) { return in(1)._type==Type.BOTTOM ? 0 : 1; }
- @Override public void encoding( Encoding enc ) { }
- @Override public void asm(CodeGen code, SB sb) { sb.p(code.reg(in(1))); }
-}
diff --git a/chapter25/src/main/java/com/seaofnodes/simple/node/CheckCastNode.java b/chapter25/src/main/java/com/seaofnodes/simple/node/CheckCastNode.java
deleted file mode 100644
index 900ee70e..00000000
--- a/chapter25/src/main/java/com/seaofnodes/simple/node/CheckCastNode.java
+++ /dev/null
@@ -1,82 +0,0 @@
-package com.seaofnodes.simple.node;
-
-import com.seaofnodes.simple.Parser;
-import com.seaofnodes.simple.type.*;
-import com.seaofnodes.simple.util.BAOS;
-
-import java.util.BitSet;
-import java.util.HashMap;
-import java.util.IdentityHashMap;
-
-// Upcast (join) the input to a t. Used after guard test to lift an input.
-// Can also be used to make a type-assertion if ctrl is null.
-public class CheckCastNode extends TypeNode {
- public CheckCastNode(Type t, Node ctrl, Node in) { super(t,ctrl, in); }
-
- public CheckCastNode(CheckCastNode c) {
- super(c); // Call parent copy constructor
- setType(compute()); // Ensure type is recomputed
- }
- @Override public Tag serialTag() { return Tag.CheckCast; }
- @Override public void packed( BAOS baos, HashMap<String,Integer> strs, HashMap<Type,Integer> types, IdentityHashMap<Node, Integer> anodes ) {
- baos.packed2(types.get(_con)); // NPE if fails lookup
- }
- static Node make( BAOS bais, Type[] types) { return new CheckCastNode(types[bais.packed2()], null, null); }
-
- @Override public String label() { return "("+_con.str()+")"; }
-
- @Override
- public String uniqueName() { return "CheckCast_" + _nid; }
-
- @Override public boolean isPinned() { return in(0)!=null; }
-
- @Override
- public StringBuilder _print1(StringBuilder sb, BitSet visited) {
- return in(1)._print0(sb.append(label()), visited);
- }
-
- @Override
- public Type compute() {
- // Cast array to int
- Type t1 = in(1)._type;
- if( _con == TypeInteger.BOT && t1 instanceof TypeMemPtr tmp && tmp._obj.isAry() )
- return _con;
-
- // If unconditional, it must collapse (or error)
- if( in(0)==null )
- return _con;
- // If conditional, return the join. The guard test ensures
- // the join is correct.
- return t1.join(_con);
- }
-
- @Override
- public Node idealize() {
- return in(1)._type.isa(_con) ? in(1) : null;
- }
-
- @Override
- public Parser.ParseException err() {
- // Has a condition to test, so OK
- if( in(0) != null ) return null;
- if( in(1)._type != Type.BOTTOM )
- // No condition to test, so this must optimize away
- return Parser.error( "Type " + in(1)._type.str() + " is not of declared type " + _con.str(), null );
- // Only happens for un-initialized refs that must init.
- // Allow uses of initializing stores, but other uses represent a
- // partially initialized field, and should error
- boolean bad = false;
- StoreNode init=null;
- for( Node use : _outputs )
- if( (use instanceof StoreNode st && st._init && !((TypeMemPtr)st.ptr()._type)._obj._name.startsWith("class") ) )
- init = st;
- else if( (use instanceof StoreNode st && st.val() instanceof CheckCastNode cast && cast.in(1)._type == Type.BOTTOM) )
- /*bogus init store in constructor*/;
- else bad = true;
- if( !bad ) return null;
- if( init==null ) return null; // Error somewhere else
- // Expecting an init store
- TypeMemPtr ptr = (TypeMemPtr)init.ptr()._type;
- throw Parser.error("'"+ptr._obj._name+"' is not fully initialized, field '" + init._name + "' is only partially set in the constructor", init._loc);
- }
-}
diff --git a/chapter25/src/main/java/com/seaofnodes/simple/node/LoadNode.java b/chapter25/src/main/java/com/seaofnodes/simple/node/LoadNode.java
index 4ff2bd82..73c288e6 100644
--- a/chapter25/src/main/java/com/seaofnodes/simple/node/LoadNode.java
+++ b/chapter25/src/main/java/com/seaofnodes/simple/node/LoadNode.java
@@ -192,7 +192,6 @@ public class LoadNode extends MemOpNode {
case CallEndNode cend: addDep(mproj); break outer; // TODO: Bypass no-alias call
default: throw Utils.TODO();
}
- case CheckCastNode cast: mem = cast.in(1); break;
case MemMergeNode merge: mem = merge.alias(_alias); break;
case EscapeNode esc:
if( esc.self()==ptr ) // Proved equal
diff --git a/chapter25/src/main/java/com/seaofnodes/simple/node/MachConcreteNode.java b/chapter25/src/main/java/com/seaofnodes/simple/node/MachConcreteNode.java
index 9440a7ea..c2dcae0b 100644
--- a/chapter25/src/main/java/com/seaofnodes/simple/node/MachConcreteNode.java
+++ b/chapter25/src/main/java/com/seaofnodes/simple/node/MachConcreteNode.java
@@ -1,7 +1,6 @@
package com.seaofnodes.simple.node;
import com.seaofnodes.simple.type.Type;
-import com.seaofnodes.simple.util.Utils;
import java.io.ByteArrayOutputStream;
import java.util.BitSet;
@@ -13,8 +12,8 @@ public abstract class MachConcreteNode extends Node implements MachNode {
public MachConcreteNode(Node[]nodes) { super(nodes); }
@Override public String label() { return op(); }
- @Override public Type compute () { throw Utils.TODO(); }
- @Override public Node idealize() { throw Utils.TODO(); }
+ @Override public Type compute () { throw new AssertionError("Do not call compute on "+getClass().getSimpleName()); }
+ @Override public Node idealize() { throw new AssertionError("Do not call idealize on "+getClass().getSimpleName()); }
@Override public StringBuilder _print1(StringBuilder sb, BitSet visited) {
sb.append("(").append(op()).append(",");
diff --git a/chapter25/src/main/java/com/seaofnodes/simple/node/MemMergeNode.java b/chapter25/src/main/java/com/seaofnodes/simple/node/MemMergeNode.java
index e4e7d607..aad3e677 100644
--- a/chapter25/src/main/java/com/seaofnodes/simple/node/MemMergeNode.java
+++ b/chapter25/src/main/java/com/seaofnodes/simple/node/MemMergeNode.java
@@ -133,8 +133,6 @@ public class MemMergeNode extends Node {
// Fold defaults into the default
boolean progress=false, allDefault=true;
for( int i=2; i<nIns(); i++ ) {
- if( in(i) instanceof CheckCastNode cast )
- { setDef(i,cast.in(1)); progress=true; }
if( in(1) == in(i) && in(1) != null ) { setDef(i,null); progress=true; }
else { allDefault=false; }
}
diff --git a/chapter25/src/main/java/com/seaofnodes/simple/node/Node.java b/chapter25/src/main/java/com/seaofnodes/simple/node/Node.java
index 1ce8382a..27f41cff 100644
--- a/chapter25/src/main/java/com/seaofnodes/simple/node/Node.java
+++ b/chapter25/src/main/java/com/seaofnodes/simple/node/Node.java
@@ -79,12 +79,12 @@ public abstract class Node implements Cloneable {
// Disk/serialized opcode tags
public enum Tag {
Add,And,EQ,NE,LT,LE,ULT,
- CallEnd,Call,CheckCast,ConFldOff,Con,CProj,
+ CallEnd,Call,ConFldOff,Con,CProj,
Div,Escape,Extern,Fun,FunPtr,If,Load,Loop,
MemMerge,Minus,Mul,
New,Never,Not,Or,Parm,Phi,Proj,
ReadOnly,Return,Region,RoundF32,
- Sar,Shl,Shr,Start,Stop,Store,Struct,Sub,ToFloat,
+ Sar,Shl,Shr,Start,Stop,Store,Sub,ToFloat,
XCtrl,Xor,StartCU,StopCU,Guard,MemPhi,BulkMemPhi,PtrToInt;
public static final Tag[] VALS = values();
public Node make( BAOS bais, String[] strs, Type[] types, GlobalBits fileAliases, GlobalBits aliases ) {
@@ -121,7 +121,6 @@ public abstract class Node implements Cloneable {
case Call -> CallNode.make(bais);
case CallEnd-> CallEndNode.make(bais ,types);
- case CheckCast -> CheckCastNode.make(bais,types);
case CProj -> CProjNode.make(bais,strs);
case Con -> ConstantNode.make(bais ,types);
case Escape-> EscapeNode.make(bais ,types);
@@ -140,7 +139,6 @@ public abstract class Node implements Cloneable {
case Stop -> StopNode.make(bais);
case StartCU-> StartCUNode.make(bais,strs,types);
case StopCU -> StopCUNode.make(bais);
- case Struct-> StructNode.make(bais, types);
case Region-> RegionNode.make(bais);
default -> throw Utils.TODO();
diff --git a/chapter25/src/main/java/com/seaofnodes/simple/node/PtrToIntNode.java b/chapter25/src/main/java/com/seaofnodes/simple/node/PtrToIntNode.java
index d781620b..02f77f36 100644
--- a/chapter25/src/main/java/com/seaofnodes/simple/node/PtrToIntNode.java
+++ b/chapter25/src/main/java/com/seaofnodes/simple/node/PtrToIntNode.java
@@ -10,10 +10,9 @@ import java.util.BitSet;
/**
* Reinterpret a non-null managed pointer as its raw integer address.
*
- * This node changes representation families but emits no code. In particular,
- * it is not a {@link CheckCastNode}: no control-dependent proof can turn a
- * pointer into an integer. Array-to-C-pointer conversion adds the array body
- * offset separately.
+ * This node changes representation families but emits no code. No
+ * control-dependent proof can turn a pointer into an integer; array-to-C-pointer
+ * conversion adds the array body offset separately.
*/
public class PtrToIntNode extends Node {
public PtrToIntNode(Node ptr) { super(null,ptr); }
diff --git a/chapter25/src/main/java/com/seaofnodes/simple/node/StoreNode.java b/chapter25/src/main/java/com/seaofnodes/simple/node/StoreNode.java
index bd268af2..04fbc781 100644
--- a/chapter25/src/main/java/com/seaofnodes/simple/node/StoreNode.java
+++ b/chapter25/src/main/java/com/seaofnodes/simple/node/StoreNode.java
@@ -110,8 +110,6 @@ public class StoreNode extends MemOpNode {
@Override
public Node idealize() {
- assert !(mem() instanceof CheckCastNode);
-
// Freeze the semantic Store variant as soon as the pointer exposes a
// canonical field declaration. Waiting until after structural memory
// peeps can lose the declaration to a flow-sensitive constant field
diff --git a/chapter25/src/main/java/com/seaofnodes/simple/node/StructNode.java b/chapter25/src/main/java/com/seaofnodes/simple/node/StructNode.java
deleted file mode 100644
index 4dcc695f..00000000
--- a/chapter25/src/main/java/com/seaofnodes/simple/node/StructNode.java
+++ /dev/null
@@ -1,60 +0,0 @@
-package com.seaofnodes.simple.node;
-
-import com.seaofnodes.simple.type.*;
-import com.seaofnodes.simple.util.BAOS;
-import com.seaofnodes.simple.util.Utils;
-import java.util.BitSet;
-import java.util.HashMap;
-import java.util.IdentityHashMap;
-
-/**
- * Build a compound object
- */
-public class StructNode extends Node {
-
- public final TypeStruct _ts;
- public StructNode(TypeStruct ts) { _ts=ts; assert !ts._open; }
- @Override public Tag serialTag() { return Tag.Struct; }
- @Override public void packed( BAOS baos, HashMap<String,Integer> strs, HashMap<Type,Integer> types, IdentityHashMap<Node, Integer> anodes ) {
- //baos.packed1(nIns());
- //baos.packed2(_label==null ? 0 : strs.get(_label));
- //baos.packed2(types.get(_type)); // Write _type not _minType, which can be higher
- throw Utils.TODO();
- }
- static Node make( BAOS bais, Type[] types) {
- //Node[] ins = new Node[bais.packed1()];
- //return new StructNode(types[bais.packed2()], ins);
- throw Utils.TODO();
- }
-
- @Override
- public StringBuilder _print1(StringBuilder sb, BitSet visited) {
- if( _ts==null ) return sb.append("STRUCT?");
- sb.append(_ts._name).append(" { ");
- for( int i=0; i<nIns(); i++ ) {
- sb.append(_ts._fields[i]._fname).append(":");
- sb.append(in(i)==null ? Type.BOTTOM : in(i)._type);
- sb.append("; ");
- }
- sb.setLength(sb.length()-2);
- return sb.append("}");
- }
-
- @Override
- public TypeStruct compute() {
- if( _ts==null ) return TypeStruct.BOT;
- Field[] fs = new Field[_ts._fields.length];
- for( int i=0; i<fs.length; i++ )
- fs[i] = _ts._fields[i].makeFrom(in(i)==null ? Type.TOP : in(i)._type);
- return TypeStruct.make(_ts._name,false,fs);
- }
-
- @Override
- public Node idealize() { return null; }
-
- @Override
- public boolean eq(Node n) { return _ts == ((StructNode)n)._ts; }
-
- @Override
- int hash() { return _ts==null ? 0 : _ts.hashCode(); }
-}
diff --git a/chapter25/src/main/java/com/seaofnodes/simple/node/cpus/arm/MemOpARM.java b/chapter25/src/main/java/com/seaofnodes/simple/node/cpus/arm/MemOpARM.java
index 08bdf974..25402018 100644
--- a/chapter25/src/main/java/com/seaofnodes/simple/node/cpus/arm/MemOpARM.java
+++ b/chapter25/src/main/java/com/seaofnodes/simple/node/cpus/arm/MemOpARM.java
@@ -4,7 +4,6 @@ import com.seaofnodes.simple.codegen.*;
import com.seaofnodes.simple.node.*;
import com.seaofnodes.simple.type.*;
import com.seaofnodes.simple.util.SB;
-import com.seaofnodes.simple.util.Utils;
import java.lang.StringBuilder;
import java.util.BitSet;
@@ -36,8 +35,8 @@ public abstract class MemOpARM extends MemOpNode implements MachNode {
@Override public StringBuilder _printMach(StringBuilder sb, BitSet visited) { return sb.append(".").append(_name); }
- @Override public Type compute() { throw Utils.TODO(); }
- @Override public Node idealize() { throw Utils.TODO(); }
+ @Override public Type compute() { throw new AssertionError("Do not call compute on "+getClass().getSimpleName()); }
+ @Override public Node idealize() { throw new AssertionError("Do not call idealize on "+getClass().getSimpleName()); }
int size() { return _bytes; }
diff --git a/chapter25/src/main/java/com/seaofnodes/simple/node/cpus/arm/arm.java b/chapter25/src/main/java/com/seaofnodes/simple/node/cpus/arm/arm.java
index 852fbdb1..20343fb4 100644
--- a/chapter25/src/main/java/com/seaofnodes/simple/node/cpus/arm/arm.java
+++ b/chapter25/src/main/java/com/seaofnodes/simple/node/cpus/arm/arm.java
@@ -685,7 +685,6 @@ public class arm extends Machine {
case AndNode and -> and(and);
case BoolNode bool -> cmp(bool);
case CallNode call -> call(call);
- case CheckCastNode cast -> new CheckCastMach(cast);
case PtrToIntNode ptr -> new PtrToIntMach(ptr);
case GuardNode guard -> new GuardMach(guard);
case CallEndNode cend-> new CallEndMach(cend);
diff --git a/chapter25/src/main/java/com/seaofnodes/simple/node/cpus/riscv/MemOpRISC.java b/chapter25/src/main/java/com/seaofnodes/simple/node/cpus/riscv/MemOpRISC.java
index 79f22fb8..5fcba6f8 100644
--- a/chapter25/src/main/java/com/seaofnodes/simple/node/cpus/riscv/MemOpRISC.java
+++ b/chapter25/src/main/java/com/seaofnodes/simple/node/cpus/riscv/MemOpRISC.java
@@ -27,8 +27,8 @@ public abstract class MemOpRISC extends MemOpNode implements MachNode {
@Override public StringBuilder _printMach(StringBuilder sb, BitSet visited) { return sb.append(".").append(_name); }
- @Override public Type compute() { throw Utils.TODO(); }
- @Override public Node idealize() { throw Utils.TODO(); }
+ @Override public Type compute() { throw new AssertionError("Do not call compute on "+getClass().getSimpleName()); }
+ @Override public Node idealize() { throw new AssertionError("Do not call idealize on "+getClass().getSimpleName()); }
// func3 is based on load/store size and extend
abstract int func3();
diff --git a/chapter25/src/main/java/com/seaofnodes/simple/node/cpus/riscv/riscv.java b/chapter25/src/main/java/com/seaofnodes/simple/node/cpus/riscv/riscv.java
index 078a7693..27141d21 100644
--- a/chapter25/src/main/java/com/seaofnodes/simple/node/cpus/riscv/riscv.java
+++ b/chapter25/src/main/java/com/seaofnodes/simple/node/cpus/riscv/riscv.java
@@ -335,7 +335,6 @@ public class riscv extends Machine {
case AndNode and -> and(and);
case BoolNode bool -> cmp(bool);
case CallNode call -> call(call);
- case CheckCastNode cast -> new CheckCastMach(cast);
case PtrToIntNode ptr -> new PtrToIntMach(ptr);
case GuardNode guard -> new GuardMach(guard);
case CallEndNode cend -> new CallEndMach(cend);
diff --git a/chapter25/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/MemOpX86.java b/chapter25/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/MemOpX86.java
index bfaf7a91..87cc6e35 100644
--- a/chapter25/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/MemOpX86.java
+++ b/chapter25/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/MemOpX86.java
@@ -4,7 +4,6 @@ import com.seaofnodes.simple.codegen.*;
import com.seaofnodes.simple.node.*;
import com.seaofnodes.simple.type.*;
import com.seaofnodes.simple.util.SB;
-import com.seaofnodes.simple.util.Utils;
import java.lang.StringBuilder;
import java.util.BitSet;
@@ -59,8 +58,8 @@ public abstract class MemOpX86 extends MemOpNode implements MachNode {
}
@Override public String label() { return op(); }
- @Override public Type compute() { throw Utils.TODO(); }
- @Override public Node idealize() { throw Utils.TODO(); }
+ @Override public Type compute() { throw new AssertionError("Do not call compute on "+getClass().getSimpleName()); }
+ @Override public Node idealize() { throw new AssertionError("Do not call idealize on "+getClass().getSimpleName()); }
// Register mask allowed on input i.
@Override public RegMask regmap(int i) {
diff --git a/chapter25/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/x86_64_v2.java b/chapter25/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/x86_64_v2.java
index 4cabefca..5b70834c 100644
--- a/chapter25/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/x86_64_v2.java
+++ b/chapter25/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/x86_64_v2.java
@@ -376,7 +376,6 @@ public class x86_64_v2 extends Machine {
case CProjNode c -> new CProjNode(c);
case CallEndNode cend -> new CallEndMach(cend);
case CallNode call -> call(call);
- case CheckCastNode cast -> new CheckCastMach(cast);
case PtrToIntNode ptr -> new PtrToIntMach(ptr);
case GuardNode guard -> new GuardMach(guard);
case ConstantNode con -> con(con);
diff --git a/chapter25/src/main/java/com/seaofnodes/simple/print/JSViewer.java b/chapter25/src/main/java/com/seaofnodes/simple/print/JSViewer.java
index 0f34af2e..204b2642 100644
--- a/chapter25/src/main/java/com/seaofnodes/simple/print/JSViewer.java
+++ b/chapter25/src/main/java/com/seaofnodes/simple/print/JSViewer.java
@@ -256,7 +256,6 @@ public class JSViewer implements AutoCloseable {
return switch( n ) {
case CFGNode cfg -> "yellow";
case NewNode nnn -> "lightgreen";
- case StructNode s -> "lightgreen";
default -> typeColor(n._type);
};
}
diff --git a/chapter25/src/main/java/com/seaofnodes/simple/type/Type.java b/chapter25/src/main/java/com/seaofnodes/simple/type/Type.java
index 509326bb..fbbfbada 100644
--- a/chapter25/src/main/java/com/seaofnodes/simple/type/Type.java
+++ b/chapter25/src/main/java/com/seaofnodes/simple/type/Type.java
@@ -229,8 +229,8 @@ public class Type /*implements Cloneable*/ {
}
// At/Set child at 'idx' to t
- public Type at( int idx ) { throw Utils.TODO(); }
- public void set( int idx, Type t ) { throw Utils.TODO(); }
+ public Type at( int idx ) { throw Utils.TODO("Should not reach here: type has no children"); }
+ public void set( int idx, Type t ) { throw Utils.TODO("Should not reach here: type has no children"); }
public int nkids() { return 0; } // Number of kids
@@ -322,7 +322,7 @@ public class Type /*implements Cloneable*/ {
case TXCTRL-> TCTRL;
case TNIL -> TXNIL;
case TXNIL -> TNIL;
- default -> throw Utils.TODO(); // Should not reach here
+ default -> throw Utils.TODO("Should not reach here: unknown simple type");
});
}
@@ -548,7 +548,7 @@ public class Type /*implements Cloneable*/ {
case TCTRL -> CONTROL;
case TXCTRL->XCONTROL;
case TNIL -> NIL;
- default -> throw Utils.TODO();
+ default -> throw Utils.TODO("Should not reach here: unknown simple type tag");
};
}
@@ -572,7 +572,7 @@ public class Type /*implements Cloneable*/ {
case TFLD -> Field .packed( off, bais, strs );
case TSTRUCT -> TypeStruct .packed( off, bais, strs );
case TTUPLE -> TypeTuple .packed( off, bais );
- default -> throw Utils.TODO();
+ default -> throw Utils.TODO("Should not reach here: unknown packed type tag");
};
}
diff --git a/chapter25/src/main/java/com/seaofnodes/simple/type/TypeConAry.java b/chapter25/src/main/java/com/seaofnodes/simple/type/TypeConAry.java
index 2a0a817e..29e65c94 100644
--- a/chapter25/src/main/java/com/seaofnodes/simple/type/TypeConAry.java
+++ b/chapter25/src/main/java/com/seaofnodes/simple/type/TypeConAry.java
@@ -43,7 +43,7 @@ public abstract class TypeConAry<A> extends TypeScalar {
return ti.meet(e);
return this;
}
- throw Utils.TODO();
+ throw Utils.TODO("Should not reach here: constant array meet with non-element type");
}
@Override public boolean isHigh() { return this==TOP; }
@@ -65,10 +65,10 @@ public abstract class TypeConAry<A> extends TypeScalar {
}
// Generic element _type
public int elemT() { return TBOT; }
- public long at8(int idx) { throw Utils.TODO(); }
- public int len() { throw Utils.TODO(); }
- @Override public int log_size() { throw Utils.TODO(); }
- public void write( BAOS baos ) { throw Utils.TODO(); }
+ public long at8(int idx) { throw Utils.TODO("Should not reach here: abstract constant array has no elements"); }
+ public int len() { throw Utils.TODO("Should not reach here: abstract constant array has no length"); }
+ @Override public int log_size() { throw Utils.TODO("Should not reach here: abstract constant array has no element size"); }
+ public void write( BAOS baos ) { throw Utils.TODO("Should not reach here: abstract constant array cannot be written"); }
// Reserve tags for u8 array
@Override int TAGOFF() { return 1; }
diff --git a/chapter25/src/main/java/com/seaofnodes/simple/type/TypeFloat.java b/chapter25/src/main/java/com/seaofnodes/simple/type/TypeFloat.java
index 1325b707..d410e9cf 100644
--- a/chapter25/src/main/java/com/seaofnodes/simple/type/TypeFloat.java
+++ b/chapter25/src/main/java/com/seaofnodes/simple/type/TypeFloat.java
@@ -53,7 +53,7 @@ public class TypeFloat extends TypeScalar {
case 0 -> ""+_con+((float)_con==_con ? "f" : "");
case 32 -> "f32";
case 64 -> "flt";
- default -> throw Utils.TODO();
+ default -> throw Utils.TODO("Should not reach here: unknown float size");
};
}
private boolean isF32() { return ((float)_con)==_con; }
@@ -116,7 +116,7 @@ public class TypeFloat extends TypeScalar {
case 0 -> F64;
case 1 -> F32;
case 2 -> constant(Double.longBitsToDouble(bais.packed8()));
- default -> throw Utils.TODO();
+ default -> throw Utils.TODO("Should not reach here: unknown float type tag");
};
}
diff --git a/chapter25/src/main/java/com/seaofnodes/simple/type/TypeInteger.java b/chapter25/src/main/java/com/seaofnodes/simple/type/TypeInteger.java
index c981f3d3..28e788fe 100644
--- a/chapter25/src/main/java/com/seaofnodes/simple/type/TypeInteger.java
+++ b/chapter25/src/main/java/com/seaofnodes/simple/type/TypeInteger.java
@@ -203,7 +203,7 @@ public class TypeInteger extends TypeScalar {
case 4 -> ZERO;
case 5 -> constant(bais.packed8());
case 6 -> make(bais.packed8(),bais.packed8(),(byte)(bais.packed1()-3));
- default -> throw Utils.TODO();
+ default -> throw Utils.TODO("Should not reach here: unknown integer type tag");
};
}
diff --git a/chapter25/src/main/java/com/seaofnodes/simple/type/TypeMem.java b/chapter25/src/main/java/com/seaofnodes/simple/type/TypeMem.java
index 7658e3fd..c634aab0 100644
--- a/chapter25/src/main/java/com/seaofnodes/simple/type/TypeMem.java
+++ b/chapter25/src/main/java/com/seaofnodes/simple/type/TypeMem.java
@@ -150,7 +150,7 @@ public class TypeMem extends Type {
@Override public TypeMem makeZero() { return TOP; }
@Override public boolean isHigh() { return _t.isHigh(); }
@Override boolean _isConstant() { return _one && _clz && _alias!= 1 && _t._isConstant(); }
- @Override public int log_size() { throw Utils.TODO(); }
+ @Override public int log_size() { throw Utils.TODO("Should not reach here: memory has no scalar storage size"); }
@Override boolean _isFinal() { return _t._isFinal(); }
@Override TypeMem _makeStorage() { return make(_alias,_t._makeStorage(),_one,_clz,_final,_escFs,_escAs); }
diff --git a/chapter25/src/main/java/com/seaofnodes/simple/type/TypePtr.java b/chapter25/src/main/java/com/seaofnodes/simple/type/TypePtr.java
index 7b27ff2b..38941ed1 100644
--- a/chapter25/src/main/java/com/seaofnodes/simple/type/TypePtr.java
+++ b/chapter25/src/main/java/com/seaofnodes/simple/type/TypePtr.java
@@ -26,7 +26,7 @@ public class TypePtr extends TypeNil {
public static void gather(ArrayList<Type> ts) { ts.add(PTR); ts.add(NPTR); }
- TypeNil makeFrom(byte nil) { throw Utils.TODO(); }
+ TypeNil makeFrom(byte nil) { throw Utils.TODO("Should not reach here: plain pointer nil state is canonical"); }
@Override public TypeNil xmeet(Type t) {
TypePtr that = (TypePtr) t;
diff --git a/chapter25/src/main/java/com/seaofnodes/simple/type/TypeStruct.java b/chapter25/src/main/java/com/seaofnodes/simple/type/TypeStruct.java
index 2949b015..e2011b38 100644
--- a/chapter25/src/main/java/com/seaofnodes/simple/type/TypeStruct.java
+++ b/chapter25/src/main/java/com/seaofnodes/simple/type/TypeStruct.java
@@ -469,7 +469,7 @@ public class TypeStruct extends Type {
// log_size for a struct is not defined, unless its exactly some power of
// 2. *Total size* is well-defined, and is available in the offsets.
- @Override public int log_size() { throw Utils.TODO(); }
+ @Override public int log_size() { throw Utils.TODO("Should not reach here: structs have no scalar log size"); }
@Override public int size() { return offset(_fields.length); }
@Override public int alignment() {
int align = 0;
diff --git a/chapter25/src/main/java/com/seaofnodes/simple/type/TypeTuple.java b/chapter25/src/main/java/com/seaofnodes/simple/type/TypeTuple.java
index 86f8aef1..075698dc 100644
--- a/chapter25/src/main/java/com/seaofnodes/simple/type/TypeTuple.java
+++ b/chapter25/src/main/java/com/seaofnodes/simple/type/TypeTuple.java
@@ -94,9 +94,9 @@ public class TypeTuple extends Type {
return false;
return true;
}
- @Override boolean _isFinal() { throw Utils.TODO(); }
+ @Override boolean _isFinal() { throw Utils.TODO("Should not reach here: tuples are not stored object values"); }
- @Override TypeMemPtr _makeRO() { throw Utils.TODO(); }
+ @Override TypeMemPtr _makeRO() { throw Utils.TODO("Should not reach here: tuples cannot be made read-only"); }
@Override Type _upgradeType(HashMap<String,Type> TYPES) {
Type[] ts = new Type[_types.length];
@@ -105,7 +105,7 @@ public class TypeTuple extends Type {
return make(ts);
}
- @Override public int log_size() { throw Utils.TODO(); }
+ @Override public int log_size() { throw Utils.TODO("Should not reach here: tuples have no scalar storage size"); }
@Override public int alignment() {
assert isConstant();
int align = 0;
diff --git a/chapter25/src/test/java/com/seaofnodes/simple/Eval2.java b/chapter25/src/test/java/com/seaofnodes/simple/Eval2.java
index e88e9caa..f8d8fe18 100644
--- a/chapter25/src/test/java/com/seaofnodes/simple/Eval2.java
+++ b/chapter25/src/test/java/com/seaofnodes/simple/Eval2.java
@@ -280,7 +280,6 @@ public abstract class Eval2 {
case BoolNode.LT lt -> lt.mode()==1
? (x(lt.in(1)) < x(lt.in(2)) ? 1L : 0L)
: (d(lt.in(1)) < d(lt.in(2)) ? 1L : 0L);
- case CheckCastNode cast -> val(cast.in(1));
case GuardNode guard -> val(guard.in(1));
case ConstantNode con -> con(con._con);
case DivNode div -> div.mode()==1