Skip to content

Commit aa31b71

Browse files
committed
Series of minor fixes
1 parent 5b04bd2 commit aa31b71

13 files changed

Lines changed: 73 additions & 59 deletions

File tree

chapter21/src/test/java/com/seaofnodes/simple/Simple.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ static void print_compilation_times(CodeGen code) {
152152
System.out.println(String.format("TOTAL COMPILATION TIME: %.3f sec", total));
153153
}
154154

155-
static String getInput() {
155+
static String getInput() throws IOException {
156156
try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
157157
return reader.lines().collect(Collectors.joining("\n"));
158158
}

chapter22/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Let's break it down.
2929
pool*, and from there in an ELF file's RODATA section.
3030

3131

32-
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.
32+
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.
3333

3434

3535
## Nested Types and Static Fields

chapter22/src/test/java/com/seaofnodes/simple/Simple.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,10 @@ static void print_compilation_times(CodeGen code) {
143143
System.out.printf( "TOTAL COMPILATION TIME: %.3f sec%n", total);
144144
}
145145

146-
static String getInput() {
147-
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
148-
return reader.lines().collect(Collectors.joining("\n"));
146+
static String getInput() throws IOException {
147+
try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
148+
return reader.lines().collect(Collectors.joining("\n"));
149+
}
149150
}
150151

151152
public static void main(String[] args) throws Exception {
Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
// -*- mode: java; -*-
2-
// Should fold away sign extend
3-
struct Person { i8 age;};
4-
Person !p = new Person;
5-
p.age = (arg<<48)>>48;
6-
return 0;
2+
val fib = {int n ->
3+
int temp=0;
4+
int f1=1;
5+
int f2=1;
6+
int i=n;
7+
while( i>1 ){
8+
temp = f1+f2;
9+
f1=f2;
10+
f2=temp;
11+
i=i-1;
12+
}
13+
return f2;
14+
};
15+
16+
fib(10);

chapter23/src/main/java/com/seaofnodes/simple/Parser.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,13 @@ private ReturnNode parseFunctionBody( TypeFunPtr sig, Lexer loc, String... ids)
245245
last = parseStatement();
246246

247247
// Last expression is the return except for the top-level main
248-
if( ctrl()._type==Type.CONTROL && fun.sig() != _code._main )
249-
fun.addReturn(ctrl(), _scope.mem().merge(), last);
248+
if( ctrl()._type==Type.CONTROL )
249+
if( fun.sig() != _code._main )
250+
fun.addReturn(ctrl(), _scope.mem().merge(), last);
251+
else {
252+
fun.setDef(1,XCTRL); // Kill default main
253+
_code.addAll(fun._outputs);
254+
}
250255

251256
// Pop off the inProgress node on the multi-exit Region merge
252257
assert r.inProgress();

chapter23/src/main/java/com/seaofnodes/simple/codegen/GlobalCodeMotion.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ private static void _rpo_cfg(CFGNode def, Node use, BitSet visit, Ary<CFGNode> r
3636
return; // Been there, done that
3737
if( def instanceof ReturnNode && use instanceof CallEndNode )
3838
return;
39-
assert !( def instanceof CallNode && use instanceof FunNode );
39+
assert !( def instanceof CallNode && use instanceof FunNode ); // All calls unwired now
4040
visit.set(cfg._nid);
4141
for( Node useuse : cfg._outputs )
4242
_rpo_cfg(cfg,useuse,visit,rpo);

chapter23/src/test/java/com/seaofnodes/simple/Chapter22Test.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
public class Chapter22Test {
1515

16-
@Test @Ignore
16+
@Test
1717
public void testJig() throws IOException {
1818
String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/jig.smp"));
1919
//String src = Files.readString(Path.of("docs/examples/BubbleSort.smp"));

chapter23/src/test/java/com/seaofnodes/simple/Simple.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,10 @@ static void print_compilation_times(CodeGen code) {
143143
System.out.printf( "TOTAL COMPILATION TIME: %.3f sec%n", total);
144144
}
145145

146-
static String getInput() {
147-
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
148-
return reader.lines().collect(Collectors.joining("\n"));
146+
static String getInput() throws IOException {
147+
try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
148+
return reader.lines().collect(Collectors.joining("\n"));
149+
}
149150
}
150151

151152
public static void main(String[] args) throws Exception {
Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
// -*- mode: java; -*-
2-
//2298769344378917493
3-
//========= Reduced =========
4-
struct s0 {
5-
bool v1;
6-
i16 v2;
7-
int v3;
8-
i8 v4;
9-
byte v5;
10-
};
11-
while(new s0.v3)
12-
while(new s0.v5<<new s0.v4) {}
13-
if(0) {
14-
if(0) {
15-
flt !P5ZUD4=new s0.v2;
2+
val fib = {int n ->
3+
int temp=0;
4+
int f1=1;
5+
int f2=1;
6+
int i=n;
7+
while( i>1 ){
8+
temp = f1+f2;
9+
f1=f2;
10+
f2=temp;
11+
i=i-1;
1612
}
17-
while(0) {}
18-
}
19-
return new s0.v1;
13+
return f2;
14+
};
15+
16+
fib(10);

chapter24/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ We also present an Interprocedural Sparse Conditional Constant Propagation
77
algorithm.
88

99

10-
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.
10+
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.
1111

1212

1313
## Chaining Relational Tests

0 commit comments

Comments
 (0)