summaryrefslogtreecommitdiff
path: root/chapter32/src/test/java/com/seaofnodes/simple/AssemblyDumpTest.java
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2026-11-15 16:11:39 -0800
committerCliff Click <cliffc@acm.org>2026-11-15 16:11:39 -0800
commit9fe7c6f9697b5bbf3041261fdc60040e75cc674f (patch)
treed92a8ff20ed984938d90ad8917b4d67fba9fb745 /chapter32/src/test/java/com/seaofnodes/simple/AssemblyDumpTest.java
parentf0a6c6757a795b8e186de0076836a87acef59fa7 (diff)
downloadSimple-ch32.tar.gz
Simple-ch32.zip
Split off chapter 31ch32
Ch 32 will be focused on compiler performance issues.
Diffstat (limited to 'chapter32/src/test/java/com/seaofnodes/simple/AssemblyDumpTest.java')
-rw-r--r--chapter32/src/test/java/com/seaofnodes/simple/AssemblyDumpTest.java61
1 files changed, 61 insertions, 0 deletions
diff --git a/chapter32/src/test/java/com/seaofnodes/simple/AssemblyDumpTest.java b/chapter32/src/test/java/com/seaofnodes/simple/AssemblyDumpTest.java
new file mode 100644
index 00000000..0e4c230a
--- /dev/null
+++ b/chapter32/src/test/java/com/seaofnodes/simple/AssemblyDumpTest.java
@@ -0,0 +1,61 @@
+package com.seaofnodes.simple;
+
+import com.seaofnodes.simple.codegen.CodeGen;
+import com.seaofnodes.simple.type.*;
+import com.seaofnodes.simple.util.BAOS;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.HexFormat;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+public class AssemblyDumpTest {
+ @Test public void libraryUnitsAndGlyphs() throws Exception {
+ Path root=Path.of("build/objs/assembly-dump");
+ Files.createDirectories(root);
+ Path build=Files.createTempDirectory(root,"sys-");
+ CodeGen code=new CodeGen("src/main/smp",build.toString(),null,"sys",null,123,true,TypeInteger.BOT)
+ .driver(CodeGen.Phase.Serialize,TestC.CPU_PORT,TestC.CALL_CONVENTION)
+ .driver(CodeGen.Phase.Encoding,TestC.CPU_PORT,TestC.CALL_CONVENTION);
+ var entry=code._encoding;
+ String before=code.asm();
+ assertSame("Dumping another unit must not change the active encoding",entry,code._encoding);
+ for( var unit : code._compunits.values() )
+ if( unit._src!=null ) {
+ String heading="=== Compilation unit: "+unit._cname+" ===";
+ assertEquals("Exactly one heading for "+unit._cname,2,before.split(heading,-1).length);
+ }
+ int start=before.indexOf("=== Compilation unit: sys.draw.Canvas ===");
+ assertTrue(start>=0);
+ int end=before.indexOf("=== Compilation unit:",start+1);
+ String canvas=before.substring(start,end<0 ? before.length() : end);
+ assertTrue(canvas.contains("Constant Pool"));
+ assertTrue(canvas.contains("sys.draw.Canvas._glyphs: []u16"));
+ TypeMemPtr ptr=(TypeMemPtr)code._compunits.get("sys/draw/Canvas")._clz.field("_glyphs")._t;
+ TypeConAry glyphs=(TypeConAry)ptr._obj.field("[]")._t;
+ assertEquals(96,glyphs.len());
+ BAOS bytes=new BAOS();
+ glyphs.write(bytes);
+ assertTrue("The complete font follows its u32 length header",
+ canvas.contains("60000000"+HexFormat.of().formatHex(bytes.toByteArray())));
+ code.exportELF(false,false);
+ com.seaofnodes.simple.codegen.PrintRegTestSupport.checkDataAliases(
+ build.resolve("sys/draw/Canvas.o"),196,"sys.draw.Canvas._glyphs");
+ assertSame(entry,code._encoding);
+ assertEquals("Export must not truncate the dump to its entry unit",before,code.asm());
+ Files.writeString(build.resolve("sys.asm"),before);
+ }
+
+ @Test public void combinedEncodingAndEarlierPhase() {
+ for( String cpu : new String[]{"x86_64_v2","arm","riscv"} ) {
+ CodeGen code=new CodeGen("val a=new u16[~]{5,6,7}; return a[arg&1];")
+ .driver(CodeGen.Phase.RegAlloc,cpu,"SystemV");
+ assertFalse(code.asm().contains("Constant Pool"));
+ code.driver(cpu,"SystemV",true,false);
+ String dump=code.asm();
+ assertFalse(dump.contains("=== Compilation unit:"));
+ assertTrue(dump.contains("Constant Pool"));
+ assertTrue(dump.contains("03000000050006000700"));
+ }
+ }
+}