summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chapter21/src/test/java/com/seaofnodes/simple/Simple.java2
-rw-r--r--chapter22/README.md2
-rw-r--r--chapter22/src/test/java/com/seaofnodes/simple/Simple.java7
-rw-r--r--chapter22/src/test/java/com/seaofnodes/simple/progs/jig.smp20
-rw-r--r--chapter23/src/main/java/com/seaofnodes/simple/Parser.java9
-rw-r--r--chapter23/src/main/java/com/seaofnodes/simple/codegen/GlobalCodeMotion.java2
-rw-r--r--chapter23/src/test/java/com/seaofnodes/simple/Chapter22Test.java2
-rw-r--r--chapter23/src/test/java/com/seaofnodes/simple/Simple.java7
-rw-r--r--chapter23/src/test/java/com/seaofnodes/simple/progs/jig.smp31
-rw-r--r--chapter24/README.md2
-rw-r--r--chapter24/pom.xml4
-rw-r--r--chapter24/src/test/java/com/seaofnodes/simple/Chapter22Test.java37
-rw-r--r--chapter24/src/test/java/com/seaofnodes/simple/Simple.java7
13 files changed, 73 insertions, 59 deletions
diff --git a/chapter21/src/test/java/com/seaofnodes/simple/Simple.java b/chapter21/src/test/java/com/seaofnodes/simple/Simple.java
index b77f2433..509ec100 100644
--- a/chapter21/src/test/java/com/seaofnodes/simple/Simple.java
+++ b/chapter21/src/test/java/com/seaofnodes/simple/Simple.java
@@ -152,7 +152,7 @@ Options:
System.out.println(String.format("TOTAL COMPILATION TIME: %.3f sec", total));
}
- static String getInput() {
+ static String getInput() throws IOException {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
return reader.lines().collect(Collectors.joining("\n"));
}
diff --git a/chapter22/README.md b/chapter22/README.md
index 65625ecb..f31dcf19 100644
--- a/chapter22/README.md
+++ b/chapter22/README.md
@@ -29,7 +29,7 @@ Let's break it down.
pool*, and from there in an ELF file's RODATA section.
- You can also read [this chapter](https://github.com/SeaOfNodes/Simple/tree/linear-chapter22) in a linear Git revision history on the [linear](https://github.com/SeaOfNodes/Simple/tree/linear) branch and [compare](https://github.com/SeaOfNodes/Simple/compare/linear-chapter21...linear-chapter22) it to the previous chapter.
+You can also read [this chapter](https://github.com/SeaOfNodes/Simple/tree/linear-chapter22) in a linear Git revision history on the [linear](https://github.com/SeaOfNodes/Simple/tree/linear) branch and [compare](https://github.com/SeaOfNodes/Simple/compare/linear-chapter21...linear-chapter22) it to the previous chapter.
## Nested Types and Static Fields
diff --git a/chapter22/src/test/java/com/seaofnodes/simple/Simple.java b/chapter22/src/test/java/com/seaofnodes/simple/Simple.java
index 1465aa6d..cc044b6f 100644
--- a/chapter22/src/test/java/com/seaofnodes/simple/Simple.java
+++ b/chapter22/src/test/java/com/seaofnodes/simple/Simple.java
@@ -143,9 +143,10 @@ Options:
System.out.printf( "TOTAL COMPILATION TIME: %.3f sec%n", total);
}
- static String getInput() {
- BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
- return reader.lines().collect(Collectors.joining("\n"));
+ static String getInput() throws IOException {
+ try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
+ return reader.lines().collect(Collectors.joining("\n"));
+ }
}
public static void main(String[] args) throws Exception {
diff --git a/chapter22/src/test/java/com/seaofnodes/simple/progs/jig.smp b/chapter22/src/test/java/com/seaofnodes/simple/progs/jig.smp
index fd3e7b9c..f7a5d202 100644
--- a/chapter22/src/test/java/com/seaofnodes/simple/progs/jig.smp
+++ b/chapter22/src/test/java/com/seaofnodes/simple/progs/jig.smp
@@ -1,6 +1,16 @@
// -*- mode: java; -*-
-// Should fold away sign extend
-struct Person { i8 age;};
-Person !p = new Person;
-p.age = (arg<<48)>>48;
-return 0;
+val fib = {int n ->
+ int temp=0;
+ int f1=1;
+ int f2=1;
+ int i=n;
+ while( i>1 ){
+ temp = f1+f2;
+ f1=f2;
+ f2=temp;
+ i=i-1;
+ }
+ return f2;
+};
+
+fib(10);
diff --git a/chapter23/src/main/java/com/seaofnodes/simple/Parser.java b/chapter23/src/main/java/com/seaofnodes/simple/Parser.java
index ffd4bfe9..8a6b1967 100644
--- a/chapter23/src/main/java/com/seaofnodes/simple/Parser.java
+++ b/chapter23/src/main/java/com/seaofnodes/simple/Parser.java
@@ -245,8 +245,13 @@ public class Parser {
last = parseStatement();
// Last expression is the return except for the top-level main
- if( ctrl()._type==Type.CONTROL && fun.sig() != _code._main )
- fun.addReturn(ctrl(), _scope.mem().merge(), last);
+ if( ctrl()._type==Type.CONTROL )
+ if( fun.sig() != _code._main )
+ fun.addReturn(ctrl(), _scope.mem().merge(), last);
+ else {
+ fun.setDef(1,XCTRL); // Kill default main
+ _code.addAll(fun._outputs);
+ }
// Pop off the inProgress node on the multi-exit Region merge
assert r.inProgress();
diff --git a/chapter23/src/main/java/com/seaofnodes/simple/codegen/GlobalCodeMotion.java b/chapter23/src/main/java/com/seaofnodes/simple/codegen/GlobalCodeMotion.java
index 520a18a3..d9c7a6ad 100644
--- a/chapter23/src/main/java/com/seaofnodes/simple/codegen/GlobalCodeMotion.java
+++ b/chapter23/src/main/java/com/seaofnodes/simple/codegen/GlobalCodeMotion.java
@@ -36,7 +36,7 @@ public abstract class GlobalCodeMotion {
return; // Been there, done that
if( def instanceof ReturnNode && use instanceof CallEndNode )
return;
- assert !( def instanceof CallNode && use instanceof FunNode );
+ assert !( def instanceof CallNode && use instanceof FunNode ); // All calls unwired now
visit.set(cfg._nid);
for( Node useuse : cfg._outputs )
_rpo_cfg(cfg,useuse,visit,rpo);
diff --git a/chapter23/src/test/java/com/seaofnodes/simple/Chapter22Test.java b/chapter23/src/test/java/com/seaofnodes/simple/Chapter22Test.java
index 13322d3d..f6410b6a 100644
--- a/chapter23/src/test/java/com/seaofnodes/simple/Chapter22Test.java
+++ b/chapter23/src/test/java/com/seaofnodes/simple/Chapter22Test.java
@@ -13,7 +13,7 @@ import static org.junit.Assert.*;
public class Chapter22Test {
- @Test @Ignore
+ @Test
public void testJig() throws IOException {
String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/jig.smp"));
//String src = Files.readString(Path.of("docs/examples/BubbleSort.smp"));
diff --git a/chapter23/src/test/java/com/seaofnodes/simple/Simple.java b/chapter23/src/test/java/com/seaofnodes/simple/Simple.java
index 5eab4842..f765d939 100644
--- a/chapter23/src/test/java/com/seaofnodes/simple/Simple.java
+++ b/chapter23/src/test/java/com/seaofnodes/simple/Simple.java
@@ -143,9 +143,10 @@ Options:
System.out.printf( "TOTAL COMPILATION TIME: %.3f sec%n", total);
}
- static String getInput() {
- BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
- return reader.lines().collect(Collectors.joining("\n"));
+ static String getInput() throws IOException {
+ try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
+ return reader.lines().collect(Collectors.joining("\n"));
+ }
}
public static void main(String[] args) throws Exception {
diff --git a/chapter23/src/test/java/com/seaofnodes/simple/progs/jig.smp b/chapter23/src/test/java/com/seaofnodes/simple/progs/jig.smp
index 001e8eae..f7a5d202 100644
--- a/chapter23/src/test/java/com/seaofnodes/simple/progs/jig.smp
+++ b/chapter23/src/test/java/com/seaofnodes/simple/progs/jig.smp
@@ -1,19 +1,16 @@
// -*- mode: java; -*-
-//2298769344378917493
-//========= Reduced =========
-struct s0 {
- bool v1;
- i16 v2;
- int v3;
- i8 v4;
- byte v5;
-};
-while(new s0.v3)
- while(new s0.v5<<new s0.v4) {}
-if(0) {
- if(0) {
- flt !P5ZUD4=new s0.v2;
+val fib = {int n ->
+ int temp=0;
+ int f1=1;
+ int f2=1;
+ int i=n;
+ while( i>1 ){
+ temp = f1+f2;
+ f1=f2;
+ f2=temp;
+ i=i-1;
}
- while(0) {}
-}
-return new s0.v1;
+ return f2;
+};
+
+fib(10);
diff --git a/chapter24/README.md b/chapter24/README.md
index cd5693d4..22fda399 100644
--- a/chapter24/README.md
+++ b/chapter24/README.md
@@ -7,7 +7,7 @@ We also present an Interprocedural Sparse Conditional Constant Propagation
algorithm.
-You can also read [this chapter](https://github.com/SeaOfNodes/Simple/tree/linear-chapter23) in a linear Git revision history on the [linear](https://github.com/SeaOfNodes/Simple/tree/linear) branch and [compare](https://github.com/SeaOfNodes/Simple/compare/linear-chapter22...linear-chapter23) it to the previous chapter.
+You can also read [this chapter](https://github.com/SeaOfNodes/Simple/tree/linear-chapter24) in a linear Git revision history on the [linear](https://github.com/SeaOfNodes/Simple/tree/linear) branch and [compare](https://github.com/SeaOfNodes/Simple/compare/linear-chapter23...linear-chapter24) it to the previous chapter.
## Chaining Relational Tests
diff --git a/chapter24/pom.xml b/chapter24/pom.xml
index 6a59188f..4f0f80b1 100644
--- a/chapter24/pom.xml
+++ b/chapter24/pom.xml
@@ -8,7 +8,7 @@
<artifactId>simple</artifactId>
<version>1.0</version>
</parent>
- <artifactId>chapter23</artifactId>
+ <artifactId>chapter24</artifactId>
<packaging>jar</packaging>
- <name>Chapter 23</name>
+ <name>Chapter 24</name>
</project>
diff --git a/chapter24/src/test/java/com/seaofnodes/simple/Chapter22Test.java b/chapter24/src/test/java/com/seaofnodes/simple/Chapter22Test.java
index 9e230bcd..78b9e7a1 100644
--- a/chapter24/src/test/java/com/seaofnodes/simple/Chapter22Test.java
+++ b/chapter24/src/test/java/com/seaofnodes/simple/Chapter22Test.java
@@ -16,24 +16,23 @@ public class Chapter22Test {
@Test
public void testJig() throws IOException {
String src =
- """
- struct s0 {
- bool v1;
- i16 v2;
- int v3;
- i8 v4;
- byte v5;
- };
- while(new s0.v3)
- while(new s0.v5<<new s0.v4) {}
- if(0) {
- if(0) {
- flt !P5ZUD4=new s0.v2;
- }
- while(0) {}
- }
- return new s0.v1;
- """;
+"""
+val fib = {int n ->
+ int temp=0;
+ int f1=1;
+ int f2=1;
+ int i=n;
+ while( i>1 ){
+ temp = f1+f2;
+ f1=f2;
+ f2=temp;
+ i=i-1;
+ }
+ return f2;
+};
+
+fib(10);
+""";
testCPU(src,"x86_64_v2", "Win64" ,-1,null);
testCPU(src,"riscv" , "SystemV",-1,null);
testCPU(src,"arm" , "SystemV",-1,null);
@@ -138,7 +137,7 @@ struct Person {
val fcn = { Person?[] ps, int x ->
if( ps[x] )
ps[x].age++;
-};
+};
""";
String person = "6\n";
TestC.run(src, "person", null, person, 0);
diff --git a/chapter24/src/test/java/com/seaofnodes/simple/Simple.java b/chapter24/src/test/java/com/seaofnodes/simple/Simple.java
index 8b275389..be582a64 100644
--- a/chapter24/src/test/java/com/seaofnodes/simple/Simple.java
+++ b/chapter24/src/test/java/com/seaofnodes/simple/Simple.java
@@ -143,9 +143,10 @@ Options:
System.out.printf( "TOTAL COMPILATION TIME: %.3f sec%n", total);
}
- static String getInput() {
- BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
- return reader.lines().collect(Collectors.joining("\n"));
+ static String getInput() throws IOException {
+ try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
+ return reader.lines().collect(Collectors.joining("\n"));
+ }
}
public static void main(String[] args) throws Exception {