diff options
| author | Cliff Click <cliffc@acm.org> | 2026-10-04 13:30:41 -0700 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2026-10-04 13:30:41 -0700 |
| commit | a4994371c0b0fbea9d2802acc22d9cc3977a0de0 (patch) | |
| tree | 98fd05869028a931f5ec8cf503b5cdf6b6c52e87 /docs/2026_REBASE/tools | |
| parent | 9149ea7a50c564856bd09633f38d980e8230c34f (diff) | |
| download | Simple-readme.tar.gz Simple-readme.zip | |
Slides for 2026 REBASEreadme
Diffstat (limited to 'docs/2026_REBASE/tools')
| -rw-r--r-- | docs/2026_REBASE/tools/BackendDump.java | 45 | ||||
| -rw-r--r-- | docs/2026_REBASE/tools/RichLattice.java | 59 | ||||
| -rw-r--r-- | docs/2026_REBASE/tools/snapshot-library.py | 16 |
3 files changed, 120 insertions, 0 deletions
diff --git a/docs/2026_REBASE/tools/BackendDump.java b/docs/2026_REBASE/tools/BackendDump.java new file mode 100644 index 00000000..faac89a4 --- /dev/null +++ b/docs/2026_REBASE/tools/BackendDump.java @@ -0,0 +1,45 @@ +import com.seaofnodes.simple.codegen.CodeGen; +import com.seaofnodes.simple.node.*; +import java.nio.file.*; +import java.util.regex.Pattern; + +/** Run from the repo root with Chapter 21's built classes on the classpath. */ +public class BackendDump { + static String js(String s) { + return "\""+s.replace("\\","\\\\").replace("\"","\\\"") + .replace("\r", "").replace("\n","\\n")+"\""; + } + public static void main(String[] args) throws Exception { + Path deck=Path.of("docs/2026_REBASE"); + String source=Files.readString(deck.resolve("demos/backend.smp")); + CodeGen code=new CodeGen(source).parse().opto().typeCheck().loopTree() + .instSelect("x86_64_v2","SystemV"); + String selected=code.toString(); + // Every row from the whole graph, in printer order. Show concrete Java + // classes and every input slot; omit types and redundant use lists. + StringBuilder compact=new StringBuilder("id node inputs\n"); + var rows=Pattern.compile("(?m)^\\s*(\\d+) ").matcher(selected); + int count=0; + while(rows.find()) { + Node n=code.f(Integer.parseInt(rows.group(1))); + String name=n.getClass().getSimpleName(); + if(n instanceof ParmNode || n instanceof CProjNode) name+=":"+n.label(); + compact.append(String.format("%2d %-16s",n._nid,name)); + for(int i=0;i<n.nIns();i++) compact.append(' ').append(n.in(i)==null?"_":n.in(i)._nid); + compact.append('\n'); + count++; + } + code.GCM().localSched().regAlloc(); + String assembly=code.asm(); + code.encode(); + String encoded=code.asm(); + Files.writeString(deck.resolve("assets/backend-selected.txt"),selected); + Files.writeString(deck.resolve("assets/backend-registers.txt"),assembly); + Files.writeString(deck.resolve("assets/backend-encoded.txt"),encoded); + Files.writeString(deck.resolve("backend.js"), + "/* Generated by tools/BackendDump.java; Chapter 21, x86-64 System V. */\n"+ + "window.REBASE.backend = {\n source: "+js(source)+",\n selected: "+js(compact.toString())+ + ",\n assembly: "+js(assembly)+",\n encoded: "+js(encoded)+"\n};\n"); + System.out.println("Captured "+count+" selected nodes, allocated assembly, and encoded assembly."); + } +} diff --git a/docs/2026_REBASE/tools/RichLattice.java b/docs/2026_REBASE/tools/RichLattice.java new file mode 100644 index 00000000..bd2d99e9 --- /dev/null +++ b/docs/2026_REBASE/tools/RichLattice.java @@ -0,0 +1,59 @@ +import com.seaofnodes.simple.type.*; +import java.nio.file.*; +import java.util.*; + +/** Draw the ordering of Chapter 24's representative types and their duals. */ +public class RichLattice { + static String quote(String s) { + return "\""+s.replace("\\","\\\\").replace("\"","\\\"").replace("\n","\\n")+"\""; + } + static String color(Type t) { + String name=t.getClass().getSimpleName(); + if(t==Type.TOP || t==Type.BOTTOM) return "#172e35"; + return switch(name) { + case "TypeInteger" -> "#d3e7f5"; + case "TypeFloat" -> "#c7eee9"; + case "TypePtr", "TypeMemPtr" -> "#cce4d6"; + case "TypeFunPtr" -> "#dfd0ef"; + case "TypeMem" -> "#a9c9e5"; + case "TypeStruct", "Field" -> "#e0ebc8"; + case "TypeTuple" -> "#f2d7e4"; + case "TypeRPC" -> "#f4d4b5"; + default -> name.startsWith("TypeConAry") ? "#d9d5cc" : "#faedce"; + }; + } + public static void main(String[] args) throws Exception { + var types=new ArrayList<>(new LinkedHashSet<>(Arrays.asList(Type.gather()))); + int size=types.size(); + boolean[][] above=new boolean[size][size]; + for(int i=0;i<size;i++) for(int j=0;j<size;j++) + above[i][j]=i!=j && types.get(i).meet(types.get(j))==types.get(j); + int top=types.indexOf(Type.TOP), bottom=types.indexOf(Type.BOTTOM); + for(int i=0;i<size;i++) { + assert !above[i][top] && !above[bottom][i]; + assert i==top || above[top][i]; + assert i==bottom || above[i][bottom]; + } + StringBuilder dot=new StringBuilder("digraph RichLattice {\n"+ + "graph [bgcolor=\"transparent\", ranksep=0.35, nodesep=0.12, pad=0.08];\n"+ + "node [shape=box, style=\"rounded,filled\", fontname=\"Arial\", fontsize=10, margin=\"0.06,0.04\", color=\"#647674\", penwidth=0.65];\n"+ + "edge [arrowhead=none, color=\"#899895\", penwidth=0.65];\n"); + for(int i=0;i<size;i++) { + Type t=types.get(i); + String name=t==Type.TOP?"TOP":t==Type.BOTTOM?"BOTTOM":t.str(); + dot.append("n").append(i).append(" [label=").append(quote(name)) + .append(", tooltip=").append(quote(t.getClass().getSimpleName()+": "+t)) + .append(", fillcolor=").append(quote(color(t))) + .append(", fontcolor=").append(quote(t==Type.TOP || t==Type.BOTTOM?"white":"#172e35")).append("];\n"); + } + int edges=0; + for(int i=0;i<size;i++) for(int j=0;j<size;j++) if(above[i][j]) { + boolean indirect=false; + for(int k=0;k<size;k++) if(above[i][k] && above[k][j]) {indirect=true;break;} + if(!indirect) {dot.append("n").append(i).append(" -> n").append(j).append(";\n");edges++;} + } + dot.append("}\n"); + Files.writeString(Path.of("docs/2026_REBASE/assets/rich-lattice.gv"),dot); + System.out.println(size+" representative types; "+edges+" order edges (transitively reduced)."); + } +} diff --git a/docs/2026_REBASE/tools/snapshot-library.py b/docs/2026_REBASE/tools/snapshot-library.py new file mode 100644 index 00000000..dee09d2f --- /dev/null +++ b/docs/2026_REBASE/tools/snapshot-library.py @@ -0,0 +1,16 @@ +"""Bundle the current Chapter 25 stdlib and methods example for offline browsing.""" +from pathlib import Path +import json + +deck = Path(__file__).resolve().parents[1] +repo = deck.parents[1] +source = repo / "chapter25/src/main/smp" +paths = [source / "sys.smp", *sorted((source / "sys").rglob("*.smp"))] +files = {path.relative_to(source).as_posix(): path.read_text(encoding="utf-8") for path in paths} +bundle = {"origin": "chapter25/src/main/smp", "files": files, + "methods": (deck / "demos/methods.smp").read_text(encoding="utf-8")} +(deck / "stdlib.js").write_text( + "/* Generated by tools/snapshot-library.py; local source snapshot. */\n" + "window.REBASE.library = " + json.dumps(bundle, ensure_ascii=False, indent=2) + ";\n", + encoding="utf-8", newline="\n") +print(f"Bundled {len(files)} standard-library files and the methods example.") |
