| 39 | } |
| 40 | |
| 41 | static void _run( String src, String simple_conv, String c_conv, String cfile, String efile, String xtn, String expected, int spills ) throws IOException { |
| 42 | String bin = efile+xtn; |
| 43 | String obj = bin+".o"; |
| 44 | // Compile simple, emit ELF |
| 45 | CodeGen code = new CodeGen(src).driver( CPU_PORT, simple_conv, obj); |
| 46 | com.seaofnodes.simple.codegen.RegAllocTestSupport.checkRegisters(code); |
| 47 | SpillStats.record(code,"Chapter21",CPU_PORT,simple_conv); |
| 48 | |
| 49 | // Compile the C program |
| 50 | var params = new String[] { |
| 51 | //if (USE_WSL) "wsl.exe"; |
| 52 | "gcc", |
| 53 | cfile, |
| 54 | obj, |
| 55 | "-lm", // Picks up 'sqrt' for newtonFloat tests to compare |
| 56 | "-g", |
| 57 | "-o", |
| 58 | bin, |
| 59 | "-D", |
| 60 | "CALL_CONV="+c_conv, |
| 61 | }; |
| 62 | Process gcc = new ProcessBuilder(params).redirectErrorStream(true).start(); |
| 63 | int error; |
| 64 | try { error = gcc.waitFor(); } catch( InterruptedException e ) { throw new IOException("interrupted"); } |
| 65 | String result = new String(gcc.getInputStream().readAllBytes()); |
| 66 | if( error!=0 ) { |
| 67 | System.err.println("gcc error code: "+error); |
| 68 | System.err.println(result); |
| 69 | } |
| 70 | assertEquals( 0, error ); |
| 71 | //assertTrue(result.isEmpty()); // No data in error stream |
| 72 | |
| 73 | // Execute results |
| 74 | Process smp = new ProcessBuilder(bin).redirectErrorStream(true).start(); |
| 75 | try { error = smp.waitFor(); } catch( InterruptedException e ) { throw new IOException("interrupted"); } |
| 76 | result = new String(smp.getInputStream().readAllBytes()); |
| 77 | if( error!=0 ) { |
| 78 | System.err.println("exec error code: "+error); |
| 79 | System.err.println(result); |
| 80 | } |
| 81 | assertEquals( 0, error ); |
| 82 | assertEquals(expected,result); |
| 83 | |
| 84 | // Allocation quality not degraded |
| 85 | SpillStats.checkSpills(spills,code._regAlloc._spillScaled); |
| 86 | |
| 87 | } |
| 88 | } |