summaryrefslogtreecommitdiff
path: root/src/test/java/com/seaofnodes/simple/AssemblyDumpTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/com/seaofnodes/simple/AssemblyDumpTest.java')
-rw-r--r--src/test/java/com/seaofnodes/simple/AssemblyDumpTest.java28
1 files changed, 21 insertions, 7 deletions
diff --git a/src/test/java/com/seaofnodes/simple/AssemblyDumpTest.java b/src/test/java/com/seaofnodes/simple/AssemblyDumpTest.java
index 0e4c230a..5399aecf 100644
--- a/src/test/java/com/seaofnodes/simple/AssemblyDumpTest.java
+++ b/src/test/java/com/seaofnodes/simple/AssemblyDumpTest.java
@@ -13,25 +13,39 @@ 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)
+ Path fixture=Files.createTempDirectory(root,"font-");
+ Path source=Files.createDirectories(fixture.resolve("src"));
+ Path build=Files.createDirectories(fixture.resolve("obj"));
+ Files.createDirectories(source.resolve("Atlas"));
+ // Use the real font, but only two tiny modules: drawing integration is
+ // covered by DrawTest. This test needs multiple units and constant data.
+ String canvasSource=Files.readString(Path.of("src/main/smp/sys/draw/Canvas.smp"));
+ int fontStart=canvasSource.indexOf("val _glyphs =");
+ assertTrue("Font declaration",fontStart>=0);
+ int fontEnd=canvasSource.indexOf("};",fontStart);
+ assertTrue("Font initializer",fontEnd>=0);
+ Files.writeString(source.resolve("Atlas/Font.smp"),canvasSource.substring(fontStart,fontEnd+2)+
+ "\nval glyph={int i -> _glyphs[i];};\n");
+ Files.writeString(source.resolve("Atlas.smp"),"val glyph={int i -> Font.glyph(i);};\n");
+ CodeGen code=new CodeGen(source.toString(),build.toString(),null,"Atlas",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);
+ assertEquals(2,code._compunits.size());
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 ===");
+ int start=before.indexOf("=== Compilation unit: Atlas.Font ===");
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;
+ assertTrue(canvas.contains("Atlas.Font._glyphs: []u16"));
+ TypeMemPtr ptr=(TypeMemPtr)code._compunits.get("Atlas/Font")._clz.field("_glyphs")._t;
TypeConAry glyphs=(TypeConAry)ptr._obj.field("[]")._t;
assertEquals(96,glyphs.len());
BAOS bytes=new BAOS();
@@ -40,10 +54,10 @@ public class AssemblyDumpTest {
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");
+ build.resolve("Atlas/Font.o"),196,"Atlas.Font._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);
+ Files.writeString(build.resolve("Atlas.asm"),before);
}
@Test public void combinedEncodingAndEarlierPhase() {