From 8ea9c74afef87cb562604bf94f803853babe2d33 Mon Sep 17 00:00:00 2001 From: Darrick Wiebe Date: Sat, 29 Mar 2025 18:22:54 -0400 Subject: Enable asm printing to be flipped to big-endian (#185) * Suppress unchecked operation warnings * Selectable asm dump endianness * Fix a crash in coalesce when v2._adj is null, so has no adjacent nodes anyway. --- chapter21/src/main/java/com/seaofnodes/simple/IterPeeps.java | 2 ++ .../src/main/java/com/seaofnodes/simple/codegen/Coalesce.java | 2 +- .../src/main/java/com/seaofnodes/simple/codegen/CodeGen.java | 2 ++ chapter21/src/main/java/com/seaofnodes/simple/node/Node.java | 3 +++ .../src/main/java/com/seaofnodes/simple/print/ASMPrinter.java | 10 ++++++++-- chapter21/src/main/java/com/seaofnodes/simple/type/Type.java | 1 + 6 files changed, 17 insertions(+), 3 deletions(-) (limited to 'chapter21') diff --git a/chapter21/src/main/java/com/seaofnodes/simple/IterPeeps.java b/chapter21/src/main/java/com/seaofnodes/simple/IterPeeps.java index 6208209f..66e8a4a8 100644 --- a/chapter21/src/main/java/com/seaofnodes/simple/IterPeeps.java +++ b/chapter21/src/main/java/com/seaofnodes/simple/IterPeeps.java @@ -49,6 +49,7 @@ public class IterPeeps { public IterPeeps( long seed ) { _work = new WorkList<>(seed); } + @SuppressWarnings("unchecked") public N add( N n ) { return (N)_work.push(n); } public void addAll( Ary ary ) { _work.addAll(ary); } @@ -126,6 +127,7 @@ public class IterPeeps { * Classic WorkList, with a fast add/remove, dup removal, random pull. * The Node's nid is used to check membership in the worklist. */ + @SuppressWarnings("unchecked") public static class WorkList { private Node[] _es; diff --git a/chapter21/src/main/java/com/seaofnodes/simple/codegen/Coalesce.java b/chapter21/src/main/java/com/seaofnodes/simple/codegen/Coalesce.java index 7496ac3b..89dde46f 100644 --- a/chapter21/src/main/java/com/seaofnodes/simple/codegen/Coalesce.java +++ b/chapter21/src/main/java/com/seaofnodes/simple/codegen/Coalesce.java @@ -58,7 +58,7 @@ abstract public class Coalesce { // Most constrained mask RegMask mask = v1._mask==v2._mask ? v1._mask : v1._mask.copy().and(v2._mask); // Check for capacity - if( (v2._adj==null ? 0 : v2._adj._len) >= mask.size() ) { + if( v2._adj!=null && v2._adj._len >= mask.size() ) { // Fails capacity, will not be trivial colorable v2._adj.setLen(v2len); continue; diff --git a/chapter21/src/main/java/com/seaofnodes/simple/codegen/CodeGen.java b/chapter21/src/main/java/com/seaofnodes/simple/codegen/CodeGen.java index 0ca822d0..43501a9b 100644 --- a/chapter21/src/main/java/com/seaofnodes/simple/codegen/CodeGen.java +++ b/chapter21/src/main/java/com/seaofnodes/simple/codegen/CodeGen.java @@ -10,6 +10,7 @@ import java.util.BitSet; import java.util.HashMap; import java.util.IdentityHashMap; +@SuppressWarnings("unchecked") public class CodeGen { // Last created CodeGen as a global; used all over to avoid passing about a // "context". @@ -330,6 +331,7 @@ public class CodeGen { } // --------------------------- + public boolean _asmLittle=true; SB asm(SB sb) { return ASMPrinter.print(sb,this); } public String asm() { return asm(new SB()).toString(); } diff --git a/chapter21/src/main/java/com/seaofnodes/simple/node/Node.java b/chapter21/src/main/java/com/seaofnodes/simple/node/Node.java index 39af5a32..29d2f669 100644 --- a/chapter21/src/main/java/com/seaofnodes/simple/node/Node.java +++ b/chapter21/src/main/java/com/seaofnodes/simple/node/Node.java @@ -226,6 +226,7 @@ public abstract class Node { } // Breaks the edge invariants, used temporarily + @SuppressWarnings("unchecked") protected N addUse(Node n) { _outputs.add(n); return (N)this; } // Remove node 'use' from 'def's (i.e. our) output list, by compressing the list in-place. @@ -274,6 +275,7 @@ public abstract class Node { // Add bogus null use to keep node alive public N keep() { return addUse(null); } // Remove bogus null. + @SuppressWarnings("unchecked") public N unkeep() { delUse(null); return (N)this; @@ -493,6 +495,7 @@ public abstract class Node { return old; } + @SuppressWarnings("unchecked") public N init() { _type = compute(); return (N)this; } /** diff --git a/chapter21/src/main/java/com/seaofnodes/simple/print/ASMPrinter.java b/chapter21/src/main/java/com/seaofnodes/simple/print/ASMPrinter.java index cafa9e56..9fcb1472 100644 --- a/chapter21/src/main/java/com/seaofnodes/simple/print/ASMPrinter.java +++ b/chapter21/src/main/java/com/seaofnodes/simple/print/ASMPrinter.java @@ -149,8 +149,14 @@ public abstract class ASMPrinter { int fatEncoding = 0; if( code._encoding != null ) { int size = code._encoding._opLen[n._nid]; - for( int i=0; i>1); i++ ) - sb.hex1(code._encoding._bits.buf()[iadr++]); + if( code._asmLittle ) + for( int i=0; i>1); // Not-printed parts of encoding diff --git a/chapter21/src/main/java/com/seaofnodes/simple/type/Type.java b/chapter21/src/main/java/com/seaofnodes/simple/type/Type.java index 847235dd..7dc091aa 100644 --- a/chapter21/src/main/java/com/seaofnodes/simple/type/Type.java +++ b/chapter21/src/main/java/com/seaofnodes/simple/type/Type.java @@ -103,6 +103,7 @@ public class Type { // checks with every type compare, only during interning. // Factory method which interns "this" + @SuppressWarnings("unchecked") public T intern() { T nnn = (T)INTERN.get(this); if( nnn==null ) -- cgit v1.2.3