From e5f4f7b85fbb91a293a7d89d7b85adfbaeeb51f4 Mon Sep 17 00:00:00 2001 From: Thalia Archibald Date: Fri, 21 Jun 2024 06:13:09 -0700 Subject: Format whitespace (#86) * Trim trailing whitespace * Ensure final new lines * Convert line endings from CRLF to LF * Replace tabs with spaces --- chapter02/README.md | 6 +++--- chapter02/docs/02-grammar.md | 10 +++++----- chapter02/docs/02-lattice.gv | 2 +- chapter02/pom.xml | 2 +- .../java/com/seaofnodes/simple/GraphVisualizer.java | 8 ++++---- .../src/main/java/com/seaofnodes/simple/Parser.java | 4 ++-- .../src/main/java/com/seaofnodes/simple/Utils.java | 2 +- .../main/java/com/seaofnodes/simple/node/AddNode.java | 6 +++--- .../java/com/seaofnodes/simple/node/ConstantNode.java | 8 ++++---- .../main/java/com/seaofnodes/simple/node/DivNode.java | 2 +- .../java/com/seaofnodes/simple/node/MinusNode.java | 6 +++--- .../main/java/com/seaofnodes/simple/node/MulNode.java | 2 +- .../src/main/java/com/seaofnodes/simple/node/Node.java | 18 +++++++++--------- .../java/com/seaofnodes/simple/node/ReturnNode.java | 4 ++-- .../main/java/com/seaofnodes/simple/node/SubNode.java | 2 +- .../src/main/java/com/seaofnodes/simple/type/Type.java | 4 ++-- .../java/com/seaofnodes/simple/type/TypeInteger.java | 12 ++++++------ .../test/java/com/seaofnodes/simple/Chapter02Test.java | 8 ++++---- 18 files changed, 53 insertions(+), 53 deletions(-) (limited to 'chapter02') diff --git a/chapter02/README.md b/chapter02/README.md index b5cb5dce..4b912465 100644 --- a/chapter02/README.md +++ b/chapter02/README.md @@ -7,7 +7,7 @@ multiplication, division, and unary minus. This allows us to write statements su return 1 + 2 * 3 + -5; ``` -Here is the [complete language grammar](docs/02-grammar.md) for this chapter. +Here is the [complete language grammar](docs/02-grammar.md) for this chapter. ## Extensions to Intermediate Representation @@ -96,7 +96,7 @@ structure: Our lattice elements can be one of three types: * The highest element is "top", denoted by T; assigning T means that the Node's value may or may not be a compile time constant. -* All elements in the middle are constants. +* All elements in the middle are constants. * The lowest is "bottom", denoted by ⊥; assigning ⊥ means that we know that the Node's value is **not** a compile time constant. An invariant of peephole optimizations is that the type of a Node always moves down the lattice. @@ -121,4 +121,4 @@ The following visual shows how the graph looks like pre-peephole optimization: ## Post-peephole -![Example Visual](./docs/02-post-peephole-ex1.svg) \ No newline at end of file +![Example Visual](./docs/02-post-peephole-ex1.svg) diff --git a/chapter02/docs/02-grammar.md b/chapter02/docs/02-grammar.md index 1a1e1239..ce875eda 100644 --- a/chapter02/docs/02-grammar.md +++ b/chapter02/docs/02-grammar.md @@ -14,11 +14,11 @@ statement expression : additiveExpression ; - + additiveExpression - : multiplicativeExpression (('+' | '-') multiplicativeExpression)* + : multiplicativeExpression (('+' | '-') multiplicativeExpression)* ; - + multiplicativeExpression : unaryExpression (('*' | '/') unaryExpression)* ; @@ -36,5 +36,5 @@ primaryExpression INTEGER_LITERAL : [1-9][0-9]* | [0] - ; -``` \ No newline at end of file + ; +``` diff --git a/chapter02/docs/02-lattice.gv b/chapter02/docs/02-lattice.gv index 57f14d77..4faa0e11 100644 --- a/chapter02/docs/02-lattice.gv +++ b/chapter02/docs/02-lattice.gv @@ -3,7 +3,7 @@ digraph Lattice { node [shape=circle, style=filled, fillcolor=lightblue]; Top [label="⊤"]; Bottom [label="⊥"]; - + A [label="MIN_INT"]; B [label="..." shape=none style=none]; C [label="-1"]; diff --git a/chapter02/pom.xml b/chapter02/pom.xml index 5ced95c3..acc963b0 100644 --- a/chapter02/pom.xml +++ b/chapter02/pom.xml @@ -11,4 +11,4 @@ chapter02 jar Chapter 2 - \ No newline at end of file + diff --git a/chapter02/src/main/java/com/seaofnodes/simple/GraphVisualizer.java b/chapter02/src/main/java/com/seaofnodes/simple/GraphVisualizer.java index df128674..4c625be1 100644 --- a/chapter02/src/main/java/com/seaofnodes/simple/GraphVisualizer.java +++ b/chapter02/src/main/java/com/seaofnodes/simple/GraphVisualizer.java @@ -21,7 +21,7 @@ public class GraphVisualizer { sb.append("/*\n"); sb.append(parser.src()); sb.append("\n*/\n"); - + // To keep the Scopes below the graph and pointing up into the graph we // need to group the Nodes in a subgraph cluster, and the scopes into a // different subgraph cluster. THEN we can draw edges between the @@ -35,13 +35,13 @@ public class GraphVisualizer { // Merge multiple edges hitting the same node. Makes common shared // nodes much prettier to look at. sb.append("\tconcentrate=\"true\";\n"); - + // Just the Nodes first, in a cluster no edges nodes(sb, all); // Walk the Node edges nodeEdges(sb, all); - + sb.append("}\n"); return sb.toString(); } @@ -89,7 +89,7 @@ public class GraphVisualizer { } } } - + /** * Finds all nodes in the graph. */ diff --git a/chapter02/src/main/java/com/seaofnodes/simple/Parser.java b/chapter02/src/main/java/com/seaofnodes/simple/Parser.java index f5aca5ba..155cd353 100644 --- a/chapter02/src/main/java/com/seaofnodes/simple/Parser.java +++ b/chapter02/src/main/java/com/seaofnodes/simple/Parser.java @@ -244,7 +244,7 @@ public class Parser { return TypeInteger.constant(Long.parseLong(snum)); } - // First letter of an identifier + // First letter of an identifier private boolean isIdStart(char ch) { return Character.isAlphabetic(ch) || ch == '_'; } @@ -260,7 +260,7 @@ public class Parser { return new String(_input, start, --_position - start); } - // + // private boolean isPunctuation(char ch) { return "=;[]<>()+-/*".indexOf(ch) != -1; } diff --git a/chapter02/src/main/java/com/seaofnodes/simple/Utils.java b/chapter02/src/main/java/com/seaofnodes/simple/Utils.java index 4d663c25..45f15327 100644 --- a/chapter02/src/main/java/com/seaofnodes/simple/Utils.java +++ b/chapter02/src/main/java/com/seaofnodes/simple/Utils.java @@ -36,4 +36,4 @@ public class Utils { return i; return -1; } -} \ No newline at end of file +} diff --git a/chapter02/src/main/java/com/seaofnodes/simple/node/AddNode.java b/chapter02/src/main/java/com/seaofnodes/simple/node/AddNode.java index a0376dd4..2d58cb75 100644 --- a/chapter02/src/main/java/com/seaofnodes/simple/node/AddNode.java +++ b/chapter02/src/main/java/com/seaofnodes/simple/node/AddNode.java @@ -6,7 +6,7 @@ public class AddNode extends Node { public AddNode(Node lhs, Node rhs) { super(null, lhs, rhs); } @Override public String label() { return "Add"; } - + @Override public String glabel() { return "+"; } @Override @@ -15,7 +15,7 @@ public class AddNode extends Node { in(2)._print0(sb.append("+")); return sb.append(")"); } - + @Override public Type compute() { @@ -32,5 +32,5 @@ public class AddNode extends Node { // TODO: add of 0 return null; } - + } diff --git a/chapter02/src/main/java/com/seaofnodes/simple/node/ConstantNode.java b/chapter02/src/main/java/com/seaofnodes/simple/node/ConstantNode.java index ec85bf1f..e4d7f412 100644 --- a/chapter02/src/main/java/com/seaofnodes/simple/node/ConstantNode.java +++ b/chapter02/src/main/java/com/seaofnodes/simple/node/ConstantNode.java @@ -21,10 +21,10 @@ public class ConstantNode extends Node { super(Parser.START); _con = type; } - + @Override public String label() { return "#"+_con; } - + @Override public String uniqueName() { return "Con_" + _nid; } @@ -32,11 +32,11 @@ public class ConstantNode extends Node { StringBuilder _print1(StringBuilder sb) { return _con._print(sb); } - + @Override public Type compute() { return _con; } @Override public Node idealize() { return null; } - + } diff --git a/chapter02/src/main/java/com/seaofnodes/simple/node/DivNode.java b/chapter02/src/main/java/com/seaofnodes/simple/node/DivNode.java index 4f502e5f..e3c3616a 100644 --- a/chapter02/src/main/java/com/seaofnodes/simple/node/DivNode.java +++ b/chapter02/src/main/java/com/seaofnodes/simple/node/DivNode.java @@ -16,7 +16,7 @@ public class DivNode extends Node { in(2)._print0(sb.append("/")); return sb.append(")"); } - + @Override public Type compute() { if (in(1)._type instanceof TypeInteger i0 && diff --git a/chapter02/src/main/java/com/seaofnodes/simple/node/MinusNode.java b/chapter02/src/main/java/com/seaofnodes/simple/node/MinusNode.java index 08924563..0d59ef25 100644 --- a/chapter02/src/main/java/com/seaofnodes/simple/node/MinusNode.java +++ b/chapter02/src/main/java/com/seaofnodes/simple/node/MinusNode.java @@ -7,15 +7,15 @@ public class MinusNode extends Node { public MinusNode(Node in) { super(null, in); } @Override public String label() { return "Minus"; } - + @Override public String glabel() { return "-"; } - + @Override StringBuilder _print1(StringBuilder sb) { in(1)._print0(sb.append("(-")); return sb.append(")"); } - + @Override public Type compute() { if (in(1)._type instanceof TypeInteger i0) diff --git a/chapter02/src/main/java/com/seaofnodes/simple/node/MulNode.java b/chapter02/src/main/java/com/seaofnodes/simple/node/MulNode.java index c6718d27..26c28281 100644 --- a/chapter02/src/main/java/com/seaofnodes/simple/node/MulNode.java +++ b/chapter02/src/main/java/com/seaofnodes/simple/node/MulNode.java @@ -7,7 +7,7 @@ public class MulNode extends Node { public MulNode(Node lhs, Node rhs) { super(null, lhs, rhs); } @Override public String label() { return "Mul"; } - + @Override public String glabel() { return "*"; } @Override diff --git a/chapter02/src/main/java/com/seaofnodes/simple/node/Node.java b/chapter02/src/main/java/com/seaofnodes/simple/node/Node.java index 960742e8..7e5f2701 100644 --- a/chapter02/src/main/java/com/seaofnodes/simple/node/Node.java +++ b/chapter02/src/main/java/com/seaofnodes/simple/node/Node.java @@ -74,9 +74,9 @@ public abstract class Node { // ------------------------------------------------------------------------ - + // Debugger Printing. - + // {@code toString} is what you get in the debugger. It has to print 1 // line (because this is what a debugger typically displays by default) and // has to be robust with broken graph/nodes. @@ -103,7 +103,7 @@ public abstract class Node { // Every Node implements this. abstract StringBuilder _print1(StringBuilder sb); - + /** * Gets the ith input node * @param i Offset of the input node @@ -120,13 +120,13 @@ public abstract class Node { public boolean isUnused() { return nOuts() == 0; } public boolean isCFG() { return false; } - + /** * Change a def into a Node. Keeps the edges correct, by removing * the corresponding use->def edge. This may make the original * def go dead. This function is co-recursive with {@link #kill}. - * + * * @param idx which def to set * @param new_def the new definition * @return new_def for flow coding @@ -195,7 +195,7 @@ public abstract class Node { public final Node peephole( ) { // Compute initial or improved Type Type type = _type = compute(); - + if (_disablePeephole) return this; // Peephole optimizations turned off @@ -206,15 +206,15 @@ public abstract class Node { } // Future chapter: Global Value Numbering goes here - + // Ask each node for a better replacement Node n = idealize(); if( n != null ) return n; - + return this; // No progress } - + /** * This function needs to be * Monotonic diff --git a/chapter02/src/main/java/com/seaofnodes/simple/node/ReturnNode.java b/chapter02/src/main/java/com/seaofnodes/simple/node/ReturnNode.java index a0f2e931..7fa470f8 100644 --- a/chapter02/src/main/java/com/seaofnodes/simple/node/ReturnNode.java +++ b/chapter02/src/main/java/com/seaofnodes/simple/node/ReturnNode.java @@ -19,7 +19,7 @@ public class ReturnNode extends Node { public Node ctrl() { return in(0); } public Node expr() { return in(1); } - + @Override public String label() { return "Return"; } @@ -29,7 +29,7 @@ public class ReturnNode extends Node { } @Override public boolean isCFG() { return true; } - + @Override public Type compute() { return Type.BOTTOM; diff --git a/chapter02/src/main/java/com/seaofnodes/simple/node/SubNode.java b/chapter02/src/main/java/com/seaofnodes/simple/node/SubNode.java index 6eda4f11..d2e32c61 100644 --- a/chapter02/src/main/java/com/seaofnodes/simple/node/SubNode.java +++ b/chapter02/src/main/java/com/seaofnodes/simple/node/SubNode.java @@ -16,7 +16,7 @@ public class SubNode extends Node { in(2)._print0(sb.append("-")); return sb.append(")"); } - + @Override public Type compute() { if (in(1)._type instanceof TypeInteger i0 && diff --git a/chapter02/src/main/java/com/seaofnodes/simple/type/Type.java b/chapter02/src/main/java/com/seaofnodes/simple/type/Type.java index 5bd51611..89f6c715 100644 --- a/chapter02/src/main/java/com/seaofnodes/simple/type/Type.java +++ b/chapter02/src/main/java/com/seaofnodes/simple/type/Type.java @@ -4,7 +4,7 @@ package com.seaofnodes.simple.type; /** * These types are part of a Monotone Analysis Framework, * @see see for example this set of slides. - *

+ *

* The types form a lattice; @see a symmetric complete bounded (ranked) lattice. *

* This wild lattice theory will be needed later to allow us to easily beef up @@ -15,7 +15,7 @@ package com.seaofnodes.simple.type; * actual implementation is darn near trivial and is generally really obvious * what we're doing with it. Right now, it's just simple integer math to do * simple constant folding e.g. 1+2 == 3 stuff. - */ + */ public class Type { diff --git a/chapter02/src/main/java/com/seaofnodes/simple/type/TypeInteger.java b/chapter02/src/main/java/com/seaofnodes/simple/type/TypeInteger.java index 69fb811c..13f816bf 100644 --- a/chapter02/src/main/java/com/seaofnodes/simple/type/TypeInteger.java +++ b/chapter02/src/main/java/com/seaofnodes/simple/type/TypeInteger.java @@ -6,16 +6,16 @@ package com.seaofnodes.simple.type; public class TypeInteger extends Type { public final static TypeInteger ZERO= new TypeInteger(0); - + /** * The constant value observed for this type */ private final long _con; - public TypeInteger(long con) { - super(TINT); - _con = con; - } + public TypeInteger(long con) { + super(TINT); + _con = con; + } public static TypeInteger constant(long con) { return new TypeInteger(con); } @@ -24,7 +24,7 @@ public class TypeInteger extends Type { return _print(new StringBuilder()).toString(); } - @Override + @Override public StringBuilder _print(StringBuilder sb) { return sb.append(_con); } @Override diff --git a/chapter02/src/test/java/com/seaofnodes/simple/Chapter02Test.java b/chapter02/src/test/java/com/seaofnodes/simple/Chapter02Test.java index 971b60ba..35464955 100644 --- a/chapter02/src/test/java/com/seaofnodes/simple/Chapter02Test.java +++ b/chapter02/src/test/java/com/seaofnodes/simple/Chapter02Test.java @@ -73,7 +73,7 @@ public class Chapter02Test { Parser parser = new Parser("return 1;"); ReturnNode ret = parser.parse(); StartNode start = Parser.START; - + assertEquals(start, ret.ctrl()); Node expr = ret.expr(); if( expr instanceof ConstantNode con ) { @@ -96,7 +96,7 @@ public class Chapter02Test { @Test public void testBad1() { - try { + try { new Parser("ret").parse(); fail(); } catch( RuntimeException e ) { @@ -106,7 +106,7 @@ public class Chapter02Test { @Test public void testBad2() { - try { + try { new Parser("return 0123;").parse(); fail(); } catch( RuntimeException e ) { @@ -122,7 +122,7 @@ public class Chapter02Test { @Test public void testBad4() { - try { + try { new Parser("return 100").parse(); fail(); } catch( RuntimeException e ) { -- cgit v1.2.3