1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
package com.seaofnodes.simple;
import com.seaofnodes.isa.eval.EvalArm64;
import com.seaofnodes.simple.codegen.RegAllocTestSupport.CheckedCodeGen;
import com.seaofnodes.simple.codegen.CodeGen;
import com.seaofnodes.simple.node.cpus.arm.arm;
import junit.framework.Assert;
import java.nio.file.Files;
import java.nio.file.Path;
import java.io.IOException;
import static org.junit.Assert.assertEquals;
// Runs 32-bit ARM code in an emulator
public class TestArm64 {
public static EvalArm64 build( String file, int arg, int spills, boolean print ) throws IOException {
return build("src/test/java/com/seaofnodes/simple/progs",file, arg, spills, print);
}
// Compile and run a simple program
public static EvalArm64 build( String dir, String file, int arg, int spills, boolean print ) throws IOException {
// Compile and export Simple
String src = Files.readString(Path.of(dir+"/"+file+".smp"));
CodeGen code = new CheckedCodeGen(src).driver("arm", "SystemV",null);
SpillStats.recordNative(code,"arm","SystemV");
if( print ) { code.print_as_hex(); System.out.print(code.asm()); }
// Allocation quality not degraded
SpillStats.checkSpills(spills,code._regAlloc._spillScaled);
// Image
byte[] image = new byte[1<<20]; // A megabyte (1024*1024 bytes)
EvalArm64 ARM = new EvalArm64(image, 1<<16);
// Code at offset 0
System.arraycopy(code._encoding.bits(), 0, image, 0, code._encoding.bits().length);
// Initial incoming int arg
ARM.regs[arm.X0] = arg;
// malloc memory starts at 64K and goes up
return ARM;
}
}
|