| 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. |
| 15 | public 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 | |
| 44 | // link with c and also inline |
| 45 | public static void run(String src, String file, TypeInteger arg, String expected, int spills) throws IOException { |
| 46 | String dir = "src/test/java/com/seaofnodes/simple/progs"; |
| 47 | String cfile = dir+"/"+file+".c"; |
| 48 | String efile = "build/objs/"+file; |
| 49 | run(src, CALL_CONVENTION, arg, "", cfile, efile, "S", expected, spills); |
| 50 | } |
| 51 | |
| 52 | public static void run(String dir, String file, String expected, int spills ) throws IOException { |
| 53 | run(dir, file,null, expected, spills, false); |
| 54 | } |
| 55 | |
| 56 | // Do not link with c file - no inline. |
| 57 | public static void runS(String file, String expected, int spills ) throws IOException { |
| 58 | run("src/test/java/com/seaofnodes/simple/progs", file, null, expected, spills, true); |
| 59 | } |
| 60 | |
| 61 | |
| 62 | // Do not link with c file - just inline with source. |
| 63 | public static void runSF(String name, String src, TypeInteger arg, String expected, int spills ) throws IOException { |
| 64 | String efile = "build/objs/"+name; |
| 65 | run(src,CALL_CONVENTION,arg, "",null,efile,"S",expected,spills); |
| 66 | } |
| 67 | |
| 68 | public static void runS(String file, TypeInteger arg, String expected, int spills ) throws IOException { |
| 69 | run("src/test/java/com/seaofnodes/simple/progs", file, arg, expected, spills, true); |
| 70 | } |
| 71 | |
| 72 | |