Skip to content

Commit 5a7acb5

Browse files
committed
Platform: Clean up the recently added things.
A lot of it didn't make sense.
1 parent 15c5bb7 commit 5a7acb5

File tree

4 files changed

+83
-62
lines changed

4 files changed

+83
-62
lines changed

Platform/src/main/java/co/casterlabs/commons/platform/ArchFamily.java

Lines changed: 65 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,18 @@
1818
@AllArgsConstructor
1919
public enum ArchFamily {
2020
// @formatter:off
21-
X86 ("x86", "x86|i[0-9]86|ia32|amd64|ia64|itanium64"),
22-
ARM ("arm", "arm|aarch"),
23-
PPC ("ppc", "ppc|power"),
24-
SPARC ("sparc", "sparc"),
25-
MIPS ("mips", "mips"),
26-
S390 ("s390", "s390"),
27-
RISCV ("riscv", "riscv"),
21+
X86 ("x86", false, "x86|i[0-9]86|ia32|amd64|ia64|itanium64"),
22+
ARM ("arm", false, "arm|aarch"),
23+
PPC ("ppc", true, "ppc|power"),
24+
SPARC ("sparc", true, "sparc"),
25+
MIPS ("mips", true, "mips"),
26+
S390 ("s390", true, "s390"),
27+
RISCV ("riscv", false, "riscv"),
2828
;
2929
// @formatter:on
3030

3131
private String name;
32+
public final boolean isUsuallyBigEndian;
3233
private String regex;
3334

3435
static ArchFamily get() {
@@ -53,4 +54,61 @@ public String toString() {
5354
return this.name;
5455
}
5556

57+
/**
58+
* @param wordSize The word size, usually 32 or 64.
59+
*
60+
* @return A "standard" target name.
61+
*/
62+
public String getArchTarget(int wordSize) {
63+
return getArchTarget(wordSize, this.isUsuallyBigEndian);
64+
}
65+
66+
/**
67+
* @param wordSize The word size, usually 32 or 64.
68+
* @param bigEndian Whether or not the processor is bigEndian or littleEndian.
69+
* Some CPUs don't support this so this will be silently
70+
* ignored.
71+
*
72+
* @return A "standard" target name.
73+
*/
74+
public String getArchTarget(int wordSize, boolean isBigEndian) {
75+
// https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/TargetParser/Triple.h
76+
switch (this) {
77+
case ARM:
78+
return wordSize == 64 ? //
79+
(isBigEndian ? "aarch64_be" : "aarch64") : //
80+
(isBigEndian ? "armeb" : "arm");
81+
82+
case MIPS:
83+
return wordSize == 64 ? //
84+
(isBigEndian ? "mips64" : "mips64el") : //
85+
(isBigEndian ? "mips" : "mipsel");
86+
87+
case PPC:
88+
return wordSize == 64 ? //
89+
(isBigEndian ? "ppc64" : "ppc64le") : //
90+
(isBigEndian ? "ppc" : "ppcle");
91+
92+
case RISCV:
93+
return wordSize == 64 ? "riscv64" : "riscv32";
94+
95+
case S390:
96+
return "systemz"; // TODO LLVM appears to not have a s390x variant?
97+
98+
case SPARC:
99+
return wordSize == 64 ? //
100+
("sparcv9") : //
101+
(isBigEndian ? "sparc" : "sparcel");
102+
103+
case X86:
104+
return Platform.wordSize == 64 ? "x86_64" : "x86";
105+
106+
// Don't create a `default:` entry.
107+
// We want the compiler to warn us about missed values.
108+
109+
}
110+
111+
throw new RuntimeException("Unable to figure out LLVM for arch: " + Platform.archFamily);
112+
}
113+
56114
}

Platform/src/main/java/co/casterlabs/commons/platform/OSDistribution.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,25 @@ public enum OSDistribution {
2626
// @formatter:off
2727

2828
// DOS
29-
MS_DOS (DOS, "MS-DOS", "<manually detected>"),
29+
MS_DOS (DOS, "MS-DOS", "MSDOS", "<manually detected>"),
3030

3131
// Windows
32-
WINDOWS_9X (WINDOWS, "Windows 9x", "windows (95|98|me|ce)"),
33-
WINDOWS_NT (WINDOWS, "Windows NT", "win"),
32+
WINDOWS_9X (WINDOWS, "Windows 9x", "MSDOS", "windows (95|98|me|ce)"),
33+
WINDOWS_NT (WINDOWS, "Windows NT", "Windows", "win"),
3434

3535
// Unix
36-
MACOS (UNIX, "macOS", "mac|darwin"),
37-
SOLARIS (UNIX, "Solaris", "sun|solaris"),
38-
BSD (UNIX, "BSD", "bsd"),
39-
LINUX (UNIX, "Linux", "nux"),
36+
MACOS (UNIX, "macOS", "macOS", "mac|darwin"),
37+
SOLARIS (UNIX, "Solaris", "Solaris", "sun|solaris"),
38+
BSD (UNIX, "BSD", "BSD", "bsd"),
39+
LINUX (UNIX, "Linux", "Linux", "nux"),
4040

4141
// VMS
42-
OPEN_VMS (VMS, "OpenVMS", "vms"),
42+
OPEN_VMS (VMS, "OpenVMS", "VMS", "vms"),
4343

4444
/**
4545
* This is the fallback, this is not to be considered to be a valid value.
4646
*/
47-
GENERIC (null, "Generic", ""),
47+
GENERIC (null, "Generic", "Generic", ""),
4848

4949
;
5050
// @formatter:on
@@ -56,6 +56,12 @@ public enum OSDistribution {
5656
* A friendly name for the distribution (e.g "macOS" or "Windows NT").
5757
*/
5858
public final String name;
59+
60+
/**
61+
* A "standard" target name.
62+
*/
63+
public final String target;
64+
5965
private String regex;
6066

6167
static OSDistribution get(OSFamily family) {

Platform/src/main/java/co/casterlabs/commons/platform/Platform.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@ public class Platform {
2424
/* CPU Architecture */
2525
/* ---------------- */
2626

27-
/** The CPU Architecture of the host, e.g x86 or arm. */
28-
public static final ArchFamily archFamily = ArchFamily.get();
29-
30-
/** A more familiar LLVM-like name, such as amd64 or x86_64. */
31-
public static final String archTarget = _PlatformUtil.getArchTarget();
32-
3327
/**
3428
* Whether or not the current machine's endianess is big endian.
3529
*
@@ -45,6 +39,9 @@ public class Platform {
4539
*/
4640
public static final int wordSize = _PlatformUtil.getWordSize();
4741

42+
/** The CPU Architecture of the host, e.g x86 or arm. */
43+
public static final ArchFamily archFamily = ArchFamily.get();
44+
4845
/* ---------------- */
4946
/* Operating System */
5047
/* ---------------- */

Platform/src/main/java/co/casterlabs/commons/platform/_PlatformUtil.java

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -66,44 +66,4 @@ static int getWordSize() {
6666
return -1;
6767
}
6868

69-
static String getArchTarget() {
70-
// https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/TargetParser/Triple.h
71-
switch (Platform.archFamily) {
72-
case ARM:
73-
return Platform.wordSize == 64 ? //
74-
(Platform.isBigEndian ? "arm" : "aarch64") : //
75-
(Platform.isBigEndian ? "armeb" : "arm");
76-
77-
case MIPS:
78-
return Platform.wordSize == 64 ? //
79-
(Platform.isBigEndian ? "mips64" : "mips64el") : //
80-
(Platform.isBigEndian ? "mips" : "mipsel");
81-
82-
case PPC:
83-
return Platform.wordSize == 64 ? //
84-
(Platform.isBigEndian ? "ppc64" : "ppc64le") : //
85-
(Platform.isBigEndian ? "ppc" : "ppcle");
86-
87-
case RISCV:
88-
return Platform.wordSize == 64 ? "riscv64" : "riscv32";
89-
90-
case S390:
91-
return "systemz"; // TODO LLVM appears to not have a s390x variant?
92-
93-
case SPARC:
94-
return Platform.wordSize == 64 ? //
95-
("sparcv9") : //
96-
(Platform.isBigEndian ? "sparc" : "sparcel");
97-
98-
case X86:
99-
return Platform.wordSize == 64 ? "x86_64" : "x86";
100-
101-
// Don't create a `default:` entry.
102-
// We want the compiler to warn us about missed values.
103-
104-
}
105-
106-
throw new RuntimeException("Unable to figure out LLVM for arch: " + Platform.archFamily);
107-
}
108-
10969
}

0 commit comments

Comments
 (0)