diff options
| author | Cliff Click <cliffc@acm.org> | 2024-05-13 15:35:19 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-13 15:35:19 -0700 |
| commit | 492786481ed69edb847f5ebfa9a24a95d08aedb8 (patch) | |
| tree | 38f36a27984b1e80abac6d9cfa7aedc113d0c71b /chapter10/src/test/java | |
| parent | 555604e0c870e10720e4baeabe93a2b0ae5a60c9 (diff) | |
| download | Simple-492786481ed69edb847f5ebfa9a24a95d08aedb8.tar.gz Simple-492786481ed69edb847f5ebfa9a24a95d08aedb8.zip | |
Bugfix 78 (#81)
* Missing idepth for LoopNode
* backedge code removing a Parser keep
Stop subsuming a node parser yet needs
* Missing addDep
* LoadNode cloning peep better profit
The LoadNode cloning peep cannot clone around a Loop unless its profit on the backedge, otherwise might infinitely clone around backedge.
peep: x - (-y) is x+y
peep: -(-x) is x
* Drop alias from Field
Field is intended to be a part of a Type; as such is abstract, immutable, and true for ALL Time and all TypeStructs which have the same field. Drop the alias and struct from Field. Drop field reset.
The alias#s are decided in the Parser, and have a lifetime for the compilation unit; the Fields have infinite lifetime.
Minor bugfix idepth caching
* Remove emacs junk file
Diffstat (limited to 'chapter10/src/test/java')
3 files changed, 30 insertions, 32 deletions
diff --git a/chapter10/src/test/java/com/seaofnodes/simple/Chapter10Test.java b/chapter10/src/test/java/com/seaofnodes/simple/Chapter10Test.java index 36ad19ae..4a4ef8be 100644 --- a/chapter10/src/test/java/com/seaofnodes/simple/Chapter10Test.java +++ b/chapter10/src/test/java/com/seaofnodes/simple/Chapter10Test.java @@ -13,6 +13,24 @@ import static org.junit.Assert.fail; public class Chapter10Test { + @Test + public void testFuzzer() { + Parser parser = new Parser( +""" +struct s0 { + int v0; +} +s0 v5 = new s0; +int v6 = new s0.v0; +s0? arg=v5; +if( arg ) v5 = new s0; +else v6 = 0; +s0 v7=v5; +return 0; +"""); + StopNode stop = parser.parse(false).iterate(false); + assertEquals("return 0;", stop.toString()); + } @Test public void testStruct() { diff --git a/chapter10/src/test/java/com/seaofnodes/simple/TypeTest.java b/chapter10/src/test/java/com/seaofnodes/simple/TypeTest.java index f18fb306..f9c580cc 100644 --- a/chapter10/src/test/java/com/seaofnodes/simple/TypeTest.java +++ b/chapter10/src/test/java/com/seaofnodes/simple/TypeTest.java @@ -13,19 +13,19 @@ public class TypeTest { @Test public void testTypeAdHoc() { TypeStruct s1 = TypeStruct.make("s1", new Field[]{ - Field.make("s1", TypeInteger.BOT, "a"), - Field.make("s1", TypeInteger.BOT, "b") }); + Field.make("a", TypeInteger.BOT), + Field.make("b", TypeInteger.BOT) }); TypeStruct s2 = TypeStruct.make("s2", new Field[]{ - Field.make("s2", TypeInteger.BOT, "a"), - Field.make("s2", TypeInteger.BOT, "b") }); + Field.make("a", TypeInteger.BOT), + Field.make("b", TypeInteger.BOT) }); Assert.assertEquals(s1, s1.glb()); Assert.assertNotEquals(s1, s1.dual()); Assert.assertEquals(s1, s1.dual().glb()); - TypeMem m1 = TypeMem.make(s1.get("a")._alias); - TypeMem m2 = TypeMem.make(s1.get("b")._alias); - TypeMem m3 = TypeMem.make(s2.get("a")._alias); - TypeMem m4 = TypeMem.make(s2.get("b")._alias); + TypeMem m1 = TypeMem.make(1); + TypeMem m2 = TypeMem.make(2); + TypeMem m3 = TypeMem.make(3); + TypeMem m4 = TypeMem.make(4); Assert.assertNotEquals(m1, m2); Assert.assertNotEquals(m2, m3); diff --git a/chapter10/src/test/java/com/seaofnodes/simple/evaluator/Evaluator.java b/chapter10/src/test/java/com/seaofnodes/simple/evaluator/Evaluator.java index 15f65f39..8622eb25 100644 --- a/chapter10/src/test/java/com/seaofnodes/simple/evaluator/Evaluator.java +++ b/chapter10/src/test/java/com/seaofnodes/simple/evaluator/Evaluator.java @@ -29,30 +29,10 @@ public class Evaluator { }
}
- private static final MethodHandle get_MemOpNode_field;
-
- static {
- try {
- var MemOpNode = Class.forName("com.seaofnodes.simple.node.MemOpNode");
- var field = MemOpNode.getDeclaredField("_field");
- field.setAccessible(true);
- get_MemOpNode_field = MethodHandles.lookup().unreflectGetter(field);
- } catch (Exception e) {
- throw new ExceptionInInitializerError(e);
- }
- }
-
- private static int getFieldIndex(TypeStruct struct, Node memop) {
- Field field;
- try {
- field = (Field)get_MemOpNode_field.invoke(memop);
- } catch (Throwable e) {
- throw new RuntimeException(e);
- }
- for(int i=0;i<struct._fields.length;i++) {
- if (struct._fields[i]._alias == field._alias) return i;
- }
- throw new AssertionError("Field "+field._fname+" of struct " +field._sname + " not found in struct " + struct._name);
+ private static int getFieldIndex(TypeStruct struct, MemOpNode memop) {
+ int idx = struct.find(memop._name);
+ if( idx >= 0 ) return idx;
+ throw new AssertionError("Field "+memop._name+" not found in struct " + struct._name);
}
public enum Status {
|
