summaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp/gluegen/StructLayout.java
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-07-17 16:34:39 +0200
committerSven Gothel <[email protected]>2011-07-17 16:34:39 +0200
commitf733203dfbd034a6b1aa3eb2cd616437c982c435 (patch)
tree4ace71d4b129870b02f962b714c9dce9f83bc294 /src/java/com/jogamp/gluegen/StructLayout.java
parentad3dc39ccfddb007c3e91acf454f804573969419 (diff)
GlueGen proper size / alignment of primitive and compound types usage [1/2] - Preparation.
Currently GlueGen fails for type long (size) and some alignments (see package.html). - The size and alignment values shall be queried at runtime. - Compound alignment needs to follow the described natural alignment (also @runtime). - - Build - add Linux Arm7 (EABI) - junit test - added compound/struct tests, pointing out the shortcomings of current impl. - package.html - Added alignment documentation - remove intptr.cfg - add GluGen types int8_t, int16_t, uint8_t, uint16_t - move MachineDescription* into runtime - Platform - has runtime MachineDescription - moved size, .. to MachineDescription - use enums for OSType, CPUArch and CPUType defined by os.name/os.arch, triggering exception if os/arch is not supported. This avoids Java String comparison and conscious os/arch detection. - MachineDescription: - compile time instances MachineDescription32Bits, MachineDescription64Bits - runtime queried instance MachineDescriptionRuntime - correct size, alignment, page size, ..
Diffstat (limited to 'src/java/com/jogamp/gluegen/StructLayout.java')
-rw-r--r--src/java/com/jogamp/gluegen/StructLayout.java53
1 files changed, 29 insertions, 24 deletions
diff --git a/src/java/com/jogamp/gluegen/StructLayout.java b/src/java/com/jogamp/gluegen/StructLayout.java
index ea8768f..392e1b1 100644
--- a/src/java/com/jogamp/gluegen/StructLayout.java
+++ b/src/java/com/jogamp/gluegen/StructLayout.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2010 JogAmp Community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -39,6 +40,7 @@
package com.jogamp.gluegen;
+import com.jogamp.common.os.Platform;
import com.jogamp.gluegen.cgram.types.*;
/** Encapsulates algorithm for laying out data structures. Note that
@@ -119,36 +121,39 @@ public class StructLayout {
+ /**
+ * <P>See alignment in {@link com.jogamp.common.os.MachineDescription}.</p>
+ *
+ * <P>The code is currently used at compile time {@link JavaEmitter#layoutStruct(CompoundType t)} once,
+ * and code for structs is emitted for generic 32bit and 64bit only {@link JavaEmitter#emitStruct(CompoundType structType, String alternateName)}.</p>
+ */
public static StructLayout createForCurrentPlatform() {
- // Note: this code is replicated in (from?) Platform.java
- String os = System.getProperty("os.name").toLowerCase();
- String cpu = System.getProperty("os.arch").toLowerCase();
- if ((os.startsWith("windows") && cpu.equals("x86"))) {
- // It appears that Windows uses a packing alignment of 4 bytes in 32-bit mode
+ final Platform.OSType osType = Platform.getOSType();
+ final Platform.CPUArch cpuArch = Platform.getCPUArch();
+
+ if( ( Platform.OSType.WINDOWS == osType && Platform.CPUArch.X86_32 == cpuArch ) || // It appears that Windows uses a packing alignment of 4 bytes in 32-bit mode
+ ( Platform.CPUArch.ARM_32 == cpuArch )
+ ) {
return new StructLayout(0, 4);
- } else if ((os.startsWith("windows") && cpu.equals("amd64")) ||
- (os.startsWith("linux") && cpu.equals("i386")) ||
- (os.startsWith("linux") && cpu.equals("x86")) ||
- (os.startsWith("linux") && cpu.equals("amd64")) ||
- (os.startsWith("linux") && cpu.equals("x86_64")) ||
- (os.startsWith("linux") && cpu.equals("ia64")) ||
- (os.startsWith("sunos") && cpu.equals("sparc")) ||
- (os.startsWith("sunos") && cpu.equals("sparcv9")) ||
- (os.startsWith("sunos") && cpu.equals("x86")) ||
- (os.startsWith("sunos") && cpu.equals("amd64")) ||
- (os.startsWith("mac os") && cpu.equals("ppc")) ||
- (os.startsWith("mac os") && cpu.equals("i386")) ||
- (os.startsWith("mac os") && cpu.equals("x86_64")) ||
- (os.startsWith("freebsd") && cpu.equals("i386")) ||
- (os.startsWith("freebsd") && cpu.equals("amd64")) ||
- (os.startsWith("hp-ux") && cpu.equals("pa_risc2.0"))
+ } else if ((Platform.OSType.WINDOWS == osType && Platform.CPUArch.X86_64 == cpuArch) ||
+ (Platform.OSType.LINUX == osType && Platform.CPUArch.X86_32 == cpuArch) ||
+ (Platform.OSType.LINUX == osType && Platform.CPUArch.X86_64 == cpuArch) ||
+ (Platform.OSType.LINUX == osType && Platform.CPUArch.IA64 == cpuArch) ||
+ (Platform.OSType.SUNOS == osType && Platform.CPUArch.SPARC_32 == cpuArch) ||
+ (Platform.OSType.SUNOS == osType && Platform.CPUArch.SPARCV9_64 == cpuArch) ||
+ (Platform.OSType.SUNOS == osType && Platform.CPUArch.X86_32 == cpuArch) ||
+ (Platform.OSType.SUNOS == osType && Platform.CPUArch.X86_64 == cpuArch) ||
+ (Platform.OSType.MACOS == osType && Platform.CPUArch.PPC == cpuArch) ||
+ (Platform.OSType.MACOS == osType && Platform.CPUArch.X86_32 == cpuArch) ||
+ (Platform.OSType.MACOS == osType && Platform.CPUArch.X86_64 == cpuArch) ||
+ (Platform.OSType.FREEBSD == osType && Platform.CPUArch.X86_32 == cpuArch) ||
+ (Platform.OSType.FREEBSD == osType && Platform.CPUArch.X86_64 == cpuArch) ||
+ (Platform.OSType.HPUX == osType && Platform.CPUArch.PA_RISC2_0 == cpuArch)
) {
- // FIXME: make struct alignment configurable? May need to change
- // packing rules on a per-type basis?
return new StructLayout(0, 8);
} else {
// FIXME: add more ports
- throw new RuntimeException("Please port StructLayout to your OS (" + os + ") and CPU (" + cpu + ")");
+ throw new RuntimeException("Please port StructLayout to your OS (" + osType + ") and CPU (" + cpuArch + ")");
}
}
}