From 3db126e018388facfab368ecb2c8f8bc566afe1a Mon Sep 17 00:00:00 2001 From: XmiliaH <45106915+XmiliaH@users.noreply.github.com> Date: Mon, 24 Mar 2025 00:09:33 +0100 Subject: First run as elf binary (#178) --- .../test/java/com/seaofnodes/simple/Compile.java | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 chapter21/src/test/java/com/seaofnodes/simple/Compile.java (limited to 'chapter21/src/test/java/com/seaofnodes') diff --git a/chapter21/src/test/java/com/seaofnodes/simple/Compile.java b/chapter21/src/test/java/com/seaofnodes/simple/Compile.java new file mode 100644 index 00000000..5286029a --- /dev/null +++ b/chapter21/src/test/java/com/seaofnodes/simple/Compile.java @@ -0,0 +1,27 @@ +package com.seaofnodes.simple; + +import com.seaofnodes.simple.codegen.CodeGen; +import org.junit.Ignore; +import org.junit.Test; + +import java.io.IOException; + +import static com.seaofnodes.simple.Main.PORTS; + +public class Compile { + + @Test + @Ignore + public void testCompile() throws IOException, InterruptedException { + boolean USE_WSL = System.getProperty("os.name").startsWith("Windows"); + CodeGen code = new CodeGen("return 13;"); + code.parse().opto().typeCheck().instSelect(PORTS,"x86_64_v2", "SystemV").GCM().localSched().regAlloc().encode(); + code.exportELF("test.o"); + Process p = Runtime.getRuntime().exec(USE_WSL ? new String[]{"wsl.exe", "gcc", "-o", "test", "test.o"}:new String[]{"gcc", "-o", "test", "test.o"}); + assert p.waitFor() == 0; + p = Runtime.getRuntime().exec(USE_WSL ? new String[]{"wsl.exe", "./test"}:new String[]{"./test"}); + System.out.println(p.waitFor()); + assert p.waitFor() == 13; + } + +} -- cgit v1.2.3