MCPcopy Create free account
hub / github.com/SeaOfNodes/Simple / TestC

Class TestC

chapter23/src/test/java/com/seaofnodes/simple/TestC.java:15–122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13// Call a C driver program, which calls a Simple-generated .o, and self-checks.
14// Expects GCC from the default CLI, compiles C, compiles Simple, links and runs.
15public abstract class TestC {
16
17 public static final String OS = System.getProperty("os.name");
18 public static final String CPU = System.getProperty("os.arch");
19
20 public static final String CALL_CONVENTION = OS.startsWith("Windows") ? "Win64" : "SystemV";
21 public static final String CPU_PORT = switch( CPU ) {
22 case "amd64" -> "x86_64_v2";
23 default -> throw Utils.TODO("Map Yer CPU Port Here");
24 };
25
26 public static void run( String file, int spills ) throws IOException { run(file,"",spills); }
27
28 public static void run( String file, String expected, int spills ) throws IOException {
29 run("src/test/java/com/seaofnodes/simple/progs",file,expected,spills);
30 }
31
32 // Compile and run a simple program
33 public static void run( String dir, String file, TypeInteger arg, String expected, int spills, boolean standalone) throws IOException {
34 // Files
35 String cfile = dir+"/"+file+".c" ;
36 String sfile = dir+"/"+file+".smp";
37 String efile = "build/objs/"+file;
38
39 // Compile and export Simple
40 String src = Files.readString(Path.of(sfile));
41 run(src,CALL_CONVENTION,arg, "",standalone? null: cfile,efile,"S",expected,spills);
42 }
43 public static void run(String dir, String file, String expected, int spills ) throws IOException {
44 run(dir, file,null, expected, spills, false);
45 }
46
47 public static void runS(String file, String expected, int spills ) throws IOException {
48 run("src/test/java/com/seaofnodes/simple/progs", file, null, expected, spills, true);
49 }
50
51 public static void runS(String file, TypeInteger arg, String expected, int spills ) throws IOException {
52 run("src/test/java/com/seaofnodes/simple/progs", file, arg, expected, spills, true);
53 }
54
55
56 public static void run( String src, String simple_conv, TypeInteger arg, String c_conv, String cfile, String efile, String xtn, String expected, int spills ) throws IOException {
57 String bin = efile+xtn;
58 String obj = bin+".o";
59 String exe = OS.startsWith("Windows") ? bin+".exe" : bin;
60 // Compile simple, emit ELF
61 CodeGen code = new CodeGen(src, arg).driver( CPU_PORT, simple_conv, obj);
62
63 String result = gcc(obj, c_conv, cfile, false, exe );
64 assertEquals(expected,result);
65
66 // Allocation quality not degraded
67 int delta = spills>>3;
68 if( delta==0 ) delta = 1;
69 if( spills != -1 )
70 assertEquals("Expect spills:",spills,code._regAlloc._spillScaled,delta);
71 }
72

Callers

nothing calls this directly

Calls 1

TODOMethod · 0.95

Tested by

no test coverage detected