summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2025-04-14 10:37:53 -0700
committerCliff Click <cliffc@acm.org>2025-04-14 10:37:53 -0700
commite1351e0f4788779e9f37a77f0abb936f2869cbfc (patch)
tree201923576d914708b7e5360d76acfc3654ce7767
parentfaf6bae55523f12c32b0e21b3c39445459c50f71 (diff)
downloadSimple-e1351e0f4788779e9f37a77f0abb936f2869cbfc.tar.gz
Simple-e1351e0f4788779e9f37a77f0abb936f2869cbfc.zip
NewXXX honors declared CC
-rw-r--r--chapter21/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/NewX86.java17
-rw-r--r--chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java2
-rw-r--r--chapter21/src/test/java/com/seaofnodes/simple/TestC.java9
3 files changed, 5 insertions, 23 deletions
diff --git a/chapter21/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/NewX86.java b/chapter21/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/NewX86.java
index a87074f4..e751fa23 100644
--- a/chapter21/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/NewX86.java
+++ b/chapter21/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/NewX86.java
@@ -6,33 +6,22 @@ import com.seaofnodes.simple.node.*;
import com.seaofnodes.simple.type.TypeFunPtr;
public class NewX86 extends NewNode implements MachNode {
- public static final String OS = System.getProperty("os.name");
- public static final RegMask ARG2 = OS.startsWith("Windows")
- ? x86_64_v2.callWin64(TypeFunPtr.CALLOC,2)
- : x86_64_v2.callSys5 (TypeFunPtr.CALLOC,2);
- public static final RegMask ARG3 = OS.startsWith("Windows")
- ? x86_64_v2.callWin64(TypeFunPtr.CALLOC,3)
- : x86_64_v2.callSys5 (TypeFunPtr.CALLOC,3);
-
// A pre-zeroed chunk of memory.
NewX86( NewNode nnn ) { super(nnn); }
@Override public String op() { return "alloc"; }
// Size and pointer result in standard calling convention; null for all the
// memory aliases edges
- @Override public RegMask regmap(int i) { return i==1 ? ARG2 : null; }
+ @Override public RegMask regmap(int i) { return i==1 ? x86_64_v2.callInMask(TypeFunPtr.CALLOC,2) : null; }
@Override public RegMask outregmap(int i) { return i == 1 ? x86_64_v2.RAX_MASK : null; }
@Override public RegMask outregmap() { return null; }
- @Override public RegMask killmap() {
- return OS.startsWith("Windows")
- ? x86_64_v2. WIN64_CALLER_SAVE_MASK
- : x86_64_v2.SYSTEM5_CALLER_SAVE_MASK;
- }
+ @Override public RegMask killmap() { return x86_64_v2.x86CallerSave(); }
@Override public void encoding( Encoding enc ) {
enc.external(this,"calloc");
// This has to call the *native* ABI, regardless of how Simple is
// being compiled, because it links against the native calloc.
// ldi rcx,#1 // number of elements to calloc
+ RegMask ARG3 = x86_64_v2.callInMask(TypeFunPtr.CALLOC,3);
enc.add1(0xB8 + ARG3.firstReg()).add4(1);
// E8 cd CALL rel32;
enc.add1(0xE8);
diff --git a/chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java b/chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java
index d67bd43d..19be4569 100644
--- a/chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java
+++ b/chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java
@@ -66,7 +66,7 @@ public class Chapter21Test {
@Test
public void testAntiDeps1() throws IOException {
String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/antiDep1.smp"));
- testCPU(src,"x86_64_v2", "SystemV", 3,"return mov(mov(S));");
+ testCPU(src,"x86_64_v2", "SystemV", 7,"return mov(mov(S));");
testCPU(src,"riscv" , "SystemV",10,"return mov(mov(S));");
testCPU(src,"arm" , "SystemV",10,"return mov(mov(S));");
}
diff --git a/chapter21/src/test/java/com/seaofnodes/simple/TestC.java b/chapter21/src/test/java/com/seaofnodes/simple/TestC.java
index c6e0b196..4294606c 100644
--- a/chapter21/src/test/java/com/seaofnodes/simple/TestC.java
+++ b/chapter21/src/test/java/com/seaofnodes/simple/TestC.java
@@ -35,14 +35,7 @@ public abstract class TestC {
// Compile and export Simple
String src = Files.readString(Path.of(sfile));
-
- // On X86, compile both win64 and sys5 variants
- if( CPU_PORT.equals("x86_64_v2") ) {
- _run(src,"Win64" ,"ms_abi" ,cfile,efile,"W",expected);
- _run(src,"SystemV","sysv_abi",cfile,efile,"S",expected);
- } else {
- _run(src,CALL_CONVENTION,"",cfile,efile,"S",expected);
- }
+ _run(src,CALL_CONVENTION,"",cfile,efile,"S",expected);
}
static void _run( String src, String simple_conv, String c_conv, String cfile, String efile, String xtn, String expected ) throws IOException {