diff options
author | Sven Gothel <[email protected]> | 2015-02-01 05:21:39 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2015-02-01 05:21:39 +0100 |
commit | a3f2d08801c5a54048faca52f422bcededf81b2a (patch) | |
tree | 96e83956b62ae3e25043ccc67f4cb1c2c1f232a1 /src/java/com | |
parent | 0deceee37d943faa7c34971388863a27f395d6a5 (diff) |
Bug 1125 - Make ELF Reader 'jogamp.common.os.elf' Stateless
ELF Reader 'jogamp.common.os.elf' currently uses
Platform's pre-determined OS_TYPE and CPUType.
It also uses the host platforms MachineDescription,
hence can not read ELF files from other machines.
This also forbids Platform to determine CPUType etc
w/o having a valid 'os.arch' property.
+++
ElfHeader should be split in
- ElfHeaderPart1 (CPUType independent)
- ElfHeaderPart2 (CPUType dependent)
Fix shall make the ELF Reader self containing
by only using ELF CPUType data, etc.
This requires customization of struct parsing,
where MachineDescription.Static index shall be
- defined in ElfHeaderPart1 using e_Ident's CPUType.
- used in ElfHeaderPart2 and all its struct types.
Diffstat (limited to 'src/java/com')
-rw-r--r-- | src/java/com/jogamp/common/os/AndroidVersion.java | 97 | ||||
-rw-r--r-- | src/java/com/jogamp/common/os/MachineDescription.java | 6 | ||||
-rw-r--r-- | src/java/com/jogamp/common/os/Platform.java | 197 | ||||
-rw-r--r-- | src/java/com/jogamp/common/util/VersionUtil.java | 8 | ||||
-rw-r--r-- | src/java/com/jogamp/gluegen/JavaConfiguration.java | 40 | ||||
-rw-r--r-- | src/java/com/jogamp/gluegen/JavaEmitter.java | 56 |
6 files changed, 248 insertions, 156 deletions
diff --git a/src/java/com/jogamp/common/os/AndroidVersion.java b/src/java/com/jogamp/common/os/AndroidVersion.java index f727a47..840933f 100644 --- a/src/java/com/jogamp/common/os/AndroidVersion.java +++ b/src/java/com/jogamp/common/os/AndroidVersion.java @@ -30,7 +30,6 @@ package com.jogamp.common.os; import java.lang.reflect.Field; import com.jogamp.common.os.Platform.ABIType; -import com.jogamp.common.os.Platform.CPUFamily; import com.jogamp.common.os.Platform.CPUType; import com.jogamp.common.util.IntObjectHashMap; import com.jogamp.common.util.ReflectionUtil; @@ -67,61 +66,6 @@ public class AndroidVersion { private static final String androidBuildVersion = "android.os.Build$VERSION"; private static final String androidBuildVersionCodes = "android.os.Build$VERSION_CODES"; - /** - * Returns {@link CPUType} for matching <code>cpuABI<code>, - * i.e. {@link #CPU_ABI} or {@link #CPU_ABI2}, - * or <code>null</code> for no match. - * <p> - * FIXME: Where is a comprehensive list of known 'android.os.Build.CPU_ABI' and 'android.os.Build.CPU_ABI2' strings ?<br/> - * Fount this one: <code>http://www.kandroid.org/ndk/docs/CPU-ARCH-ABIS.html</code> - * <pre> - * lib/armeabi/libfoo.so - * lib/armeabi-v7a/libfoo.so - * lib/x86/libfoo.so - * lib/mips/libfoo.so - * </pre> - * </p> - */ - private static final CPUType getCPUTypeImpl(final String cpuABI) { - if( null == cpuABI ) { - return null; - } else if( cpuABI.equals("armv8-a") || - cpuABI.equals("arm64-v8a") ) { - return CPUType.ARMv8_A; - } else if( cpuABI.equals("aarch64") || - cpuABI.startsWith("arm64") ) { - return CPUType.ARM64; - } else if( cpuABI.equals("armeabi-v7a") || - cpuABI.equals("armeabi-v7a-hard") ) { - return CPUType.ARMv7; - } else if( cpuABI.equals("armeabi") || - cpuABI.startsWith("arm") ) { // last 32bit chance .. - return CPUType.ARM; - } else if( cpuABI.equals("x86") ) { - return CPUType.X86_32; - } else if( cpuABI.equals("mips") ) { // no 32bit vs 64bit identifier ? - return CPUType.MIPS_32; - } else { - return null; - } - } - private static final ABIType getABITypeImpl(final CPUType cpuType, final String cpuABI) { - if( null == cpuType || null == cpuABI ) { - return null; - } else if( CPUFamily.ARM == cpuType.family ) { - if( CPUType.ARM64 == cpuType || - CPUType.ARMv8_A == cpuType ) { - return ABIType.EABI_AARCH64; - } else if( cpuABI.equals("armeabi-v7a-hard") ) { - return ABIType.EABI_GNU_ARMHF; - } else { - return ABIType.EABI_GNU_ARMEL; - } - } else { - return ABIType.GENERIC_ABI; - } - } - static { final ClassLoader cl = AndroidVersion.class.getClassLoader(); Class<?> abClass = null; @@ -138,7 +82,7 @@ public class AndroidVersion { abvcClass = ReflectionUtil.getClass(androidBuildVersionCodes, true, cl); abvcObject = abvcClass.newInstance(); } catch (final Exception e) { /* n/a */ } - isAvailable = null != abObject && null != abvObject && null != abvcObject; + isAvailable = null != abObject && null != abvObject; if(isAvailable) { CPU_ABI = getString(abClass, abObject, "CPU_ABI", true); CPU_ABI2 = getString(abClass, abObject, "CPU_ABI2", true); @@ -146,9 +90,36 @@ public class AndroidVersion { INCREMENTAL = getString(abvClass, abvObject, "INCREMENTAL", false); RELEASE = getString(abvClass, abvObject, "RELEASE", false); SDK_INT = getInt(abvClass, abvObject, "SDK_INT"); - final IntObjectHashMap version_codes = getVersionCodes(abvcClass, abvcObject); - final String sdk_name = (String) version_codes.get(SDK_INT); + final String sdk_name; + if( null != abvcObject ) { + final IntObjectHashMap version_codes = getVersionCodes(abvcClass, abvcObject); + sdk_name = (String) version_codes.get(SDK_INT); + } else { + sdk_name = null; + } SDK_NAME = ( null != sdk_name ) ? sdk_name : "SDK_"+SDK_INT ; + + /** + * <p> + * FIXME: Where is a comprehensive list of known 'android.os.Build.CPU_ABI' and 'android.os.Build.CPU_ABI2' strings ?<br/> + * Fount this one: <code>http://www.kandroid.org/ndk/docs/CPU-ARCH-ABIS.html</code> + * <pre> + * lib/armeabi/libfoo.so + * lib/armeabi-v7a/libfoo.so + * lib/x86/libfoo.so + * lib/mips/libfoo.so + * </pre> + * </p> + */ + CPU_TYPE = Platform.CPUType.query(CPU_ABI); + ABI_TYPE = Platform.ABIType.query(CPU_TYPE, CPU_ABI); + if( null != CPU_ABI2 && CPU_ABI2.length() > 0 ) { + CPU_TYPE2 = Platform.CPUType.query(CPU_ABI2); + ABI_TYPE2 = Platform.ABIType.query(CPU_TYPE2, CPU_ABI2); + } else { + CPU_TYPE2 = null; + ABI_TYPE2 = null; + } } else { CPU_ABI = null; CPU_ABI2 = null; @@ -157,11 +128,11 @@ public class AndroidVersion { RELEASE = null; SDK_INT = -1; SDK_NAME = null; + CPU_TYPE = null; + ABI_TYPE = null; + CPU_TYPE2 = null; + ABI_TYPE2 = null; } - CPU_TYPE = getCPUTypeImpl(CPU_ABI); - ABI_TYPE = getABITypeImpl(CPU_TYPE, CPU_ABI); - CPU_TYPE2 = getCPUTypeImpl(CPU_ABI2); - ABI_TYPE2 = getABITypeImpl(CPU_TYPE2, CPU_ABI2); } private static final IntObjectHashMap getVersionCodes(final Class<?> cls, final Object obj) { diff --git a/src/java/com/jogamp/common/os/MachineDescription.java b/src/java/com/jogamp/common/os/MachineDescription.java index 98093d0..2a4627e 100644 --- a/src/java/com/jogamp/common/os/MachineDescription.java +++ b/src/java/com/jogamp/common/os/MachineDescription.java @@ -104,7 +104,7 @@ public class MachineDescription { alignments[j++]); } - public StringBuilder toString(StringBuilder sb) { + public final StringBuilder toString(StringBuilder sb) { if(null==sb) { sb = new StringBuilder(); } @@ -112,7 +112,9 @@ public class MachineDescription { md.toString(sb); return sb; } - + public final String toShortString() { + return this.name()+"("+this.ordinal()+")"; + } @Override public String toString() { return toString(null).toString(); diff --git a/src/java/com/jogamp/common/os/Platform.java b/src/java/com/jogamp/common/os/Platform.java index 0d00a9a..6f6c99d 100644 --- a/src/java/com/jogamp/common/os/Platform.java +++ b/src/java/com/jogamp/common/os/Platform.java @@ -58,97 +58,186 @@ import jogamp.common.os.PlatformPropsImpl; public class Platform extends PlatformPropsImpl { public enum OSType { - LINUX(0), FREEBSD(1), ANDROID(2), MACOS(3), SUNOS(4), HPUX(5), WINDOWS(6), OPENKODE(7); - - public final int id; - - OSType(final int id){ - this.id = id; - } + LINUX, FREEBSD, ANDROID, MACOS, SUNOS, HPUX, WINDOWS, OPENKODE; } public enum CPUFamily { /** AMD/Intel */ - X86( 0x00000000), + X86, /** ARM */ - ARM( 0x00010000), + ARM, /** Power PC */ - PPC( 0x00020000), + PPC, /** SPARC */ - SPARC( 0x00030000), + SPARC, /** Mips */ - MIPS( 0x00040000), + MIPS, /** PA RISC */ - PA_RISC(0xFFFF0000), + PA_RISC, /** Itanium */ - IA64( 0xFFFF1000); - - public final int id; - - CPUFamily(final int id){ - this.id = id; - } + IA64; } public enum CPUType { /** X86 32bit */ - X86_32( CPUFamily.X86, 0x0001, true), + X86_32( CPUFamily.X86, true), /** X86 64bit */ - X86_64( CPUFamily.X86, 0x0002, false), + X86_64( CPUFamily.X86, false), /** ARM 32bit default */ - ARM( CPUFamily.ARM, 0x0000, true), + ARM( CPUFamily.ARM, true), /** ARM7EJ, ARM9E, ARM10E, XScale */ - ARMv5( CPUFamily.ARM, 0x0001, true), + ARMv5( CPUFamily.ARM, true), /** ARM11 */ - ARMv6( CPUFamily.ARM, 0x0002, true), + ARMv6( CPUFamily.ARM, true), /** ARM Cortex */ - ARMv7( CPUFamily.ARM, 0x0004, true), + ARMv7( CPUFamily.ARM, true), /** ARM64 default (64bit) */ - ARM64( CPUFamily.ARM, 0x0008, false), + ARM64( CPUFamily.ARM, false), /** ARM AArch64 (64bit) */ - ARMv8_A( CPUFamily.ARM, 0x0010, false), + ARMv8_A( CPUFamily.ARM, false), /** PPC 32bit default */ - PPC( CPUFamily.PPC, 0x0000, true), + PPC( CPUFamily.PPC, true), + /** PPC 64bit default */ + PPC64( CPUFamily.PPC, false), /** SPARC 32bit */ - SPARC_32( CPUFamily.SPARC, 0x0001, true), + SPARC_32( CPUFamily.SPARC, true), /** SPARC 64bit */ - SPARCV9_64(CPUFamily.SPARC, 0x0002, false), + SPARCV9_64(CPUFamily.SPARC, false), /** MIPS 32bit */ - MIPS_32( CPUFamily.MIPS, 0x0001, true), + MIPS_32( CPUFamily.MIPS, true), /** MIPS 64bit */ - MIPS_64( CPUFamily.MIPS, 0x0002, false), + MIPS_64( CPUFamily.MIPS, false), /** Itanium 64bit default */ - IA64( CPUFamily.IA64, 0x0000, false), + IA64( CPUFamily.IA64, false), /** PA_RISC2_0 64bit */ - PA_RISC2_0(CPUFamily.PA_RISC, 0x0001, false); + PA_RISC2_0(CPUFamily.PA_RISC, false); - public final int id; public final CPUFamily family; public final boolean is32Bit; - CPUType(final CPUFamily type, final int id, final boolean is32Bit){ + CPUType(final CPUFamily type, final boolean is32Bit){ this.family = type; - this.id = id; this.is32Bit = is32Bit; } - public CPUFamily getFamily() { return family; } + /** + * Returns {@code true} if the given {@link CPUType} is compatible + * w/ this one, i.e. at least {@link #family} and {@link #is32Bit} is equal. + */ + public final boolean isCompatible(final CPUType other) { + if( null == other ) { + return false; + } else if( other == this ) { + return true; + } else { + return this.family == other.family && + this.is32Bit == other.is32Bit; + } + } + + public static final CPUType query(final String cpuABILower) { + if( null == cpuABILower ) { + throw new IllegalArgumentException("Null cpuABILower arg"); + } + if( cpuABILower.equals("x86") || + cpuABILower.equals("i386") || + cpuABILower.equals("i486") || + cpuABILower.equals("i586") || + cpuABILower.equals("i686") ) { + return X86_32; + } else if( cpuABILower.equals("x86_64") || + cpuABILower.equals("amd64") ) { + return X86_64; + } else if( cpuABILower.equals("ia64") ) { + return IA64; + } else if( cpuABILower.equals("aarch64") ) { + return ARM64; + } else if( cpuABILower.startsWith("arm") ) { + if( cpuABILower.equals("armv8-a") || + cpuABILower.equals("arm-v8-a") || + cpuABILower.equals("arm-8-a") || + cpuABILower.equals("arm64-v8a") ) { + return ARMv8_A; + } else if( cpuABILower.startsWith("arm64") ) { + return ARM64; + } else if( cpuABILower.startsWith("armv7") || + cpuABILower.startsWith("arm-v7") || + cpuABILower.startsWith("arm-7") || + cpuABILower.startsWith("armeabi-v7") ) { + return ARMv7; + } else if( cpuABILower.startsWith("armv5") || + cpuABILower.startsWith("arm-v5") || + cpuABILower.startsWith("arm-5") ) { + return ARMv5; + } else if( cpuABILower.startsWith("armv6") || + cpuABILower.startsWith("arm-v6") || + cpuABILower.startsWith("arm-6") ) { + return ARMv6; + } else { + return ARM; + } + } else if( cpuABILower.equals("sparcv9") ) { + return SPARCV9_64; + } else if( cpuABILower.equals("sparc") ) { + return SPARC_32; + } else if( cpuABILower.equals("pa_risc2.0") ) { + return PA_RISC2_0; + } else if( cpuABILower.startsWith("ppc64") ) { + return PPC64; + } else if( cpuABILower.startsWith("ppc") ) { + return PPC; + } else if( cpuABILower.startsWith("mips") ) { + return MIPS_32; + } else { + throw new RuntimeException("Please port CPUType detection to your platform (CPU_ABI string '" + cpuABILower + "')"); + } + } } public enum ABIType { - GENERIC_ABI ( 0x0000 ), + GENERIC_ABI ( 0x00 ), /** ARM GNU-EABI ARMEL -mfloat-abi=softfp */ - EABI_GNU_ARMEL ( 0x0001 ), + EABI_GNU_ARMEL ( 0x01 ), /** ARM GNU-EABI ARMHF -mfloat-abi=hard */ - EABI_GNU_ARMHF ( 0x0002 ), + EABI_GNU_ARMHF ( 0x02 ), /** ARM EABI AARCH64 (64bit) */ - EABI_AARCH64 ( 0x0003 ); + EABI_AARCH64 ( 0x03 ); public final int id; ABIType(final int id){ this.id = id; } + + /** + * Returns {@code true} if the given {@link ABIType} is compatible + * w/ this one, i.e. they are equal. + */ + public final boolean isCompatible(final ABIType other) { + if( null == other ) { + return false; + } else { + return other == this; + } + } + + public static final ABIType query(final CPUType cpuType, final String cpuABILower) { + if( null == cpuType ) { + throw new IllegalArgumentException("Null cpuType"); + } else if( null == cpuABILower ) { + throw new IllegalArgumentException("Null cpuABILower"); + } else if( CPUFamily.ARM == cpuType.family ) { + if( !cpuType.is32Bit ) { + return EABI_AARCH64; + } else if( cpuABILower.equals("armeabi-v7a-hard") ) { + return EABI_GNU_ARMHF; + } else { + return EABI_GNU_ARMEL; + } + } else { + return GENERIC_ABI; + } + } } private static final String useTempJarCachePropName = "jogamp.gluegen.UseTempJarCache"; @@ -261,26 +350,6 @@ public class Platform extends PlatformPropsImpl { public static void initSingleton() { } /** - * Returns true only if having {@link java.nio.LongBuffer} and {@link java.nio.DoubleBuffer} available. - */ - public static boolean isJavaSE() { - return JAVA_SE; - } - - /** - * Returns true only if being compatible w/ language level 6, e.g. JRE 1.6. - * <p> - * Implies {@link #isJavaSE()}. - * </p> - * <p> - * <i>Note</i>: We claim Android is compatible. - * </p> - */ - public static boolean isJava6() { - return JAVA_6; - } - - /** * Returns true if this machine is little endian, otherwise false. */ public static boolean isLittleEndian() { @@ -328,7 +397,7 @@ public class Platform extends PlatformPropsImpl { * Returns the CPU family. */ public static CPUFamily getCPUFamily() { - return CPU_ARCH.getFamily(); + return CPU_ARCH.family; } /** diff --git a/src/java/com/jogamp/common/util/VersionUtil.java b/src/java/com/jogamp/common/util/VersionUtil.java index 6949d62..aef3fc2 100644 --- a/src/java/com/jogamp/common/util/VersionUtil.java +++ b/src/java/com/jogamp/common/util/VersionUtil.java @@ -58,10 +58,10 @@ public class VersionUtil { // environment sb.append("Platform: ").append(Platform.getOSType()).append(" / ").append(Platform.getOSName()).append(' ').append(Platform.getOSVersion()).append(" (").append(Platform.getOSVersionNumber()).append("), "); - sb.append(Platform.getArchName()).append(" (arch), ").append(Platform.getABIType()).append(", "); + sb.append(Platform.getArchName()).append(" (").append(Platform.getCPUType()).append(", ").append(Platform.getABIType()).append("), "); sb.append(Runtime.getRuntime().availableProcessors()).append(" cores"); sb.append(Platform.getNewline()); - if( AndroidVersion.isAvailable) { + if( Platform.OSType.ANDROID == PlatformPropsImpl.OS_TYPE ) { sb.append("Platform: Android Version: ").append(AndroidVersion.CODENAME).append(", "); sb.append(AndroidVersion.RELEASE).append(" [").append(AndroidVersion.RELEASE).append("], SDK: ").append(AndroidVersion.SDK_INT).append(", ").append(AndroidVersion.SDK_NAME); sb.append(Platform.getNewline()); @@ -73,8 +73,8 @@ public class VersionUtil { sb.append("Platform: Java Version: ").append(Platform.getJavaVersion()).append(" (").append(Platform.getJavaVersionNumber()).append("u").append(PlatformPropsImpl.JAVA_VERSION_UPDATE).append("), VM: ").append(Platform.getJavaVMName()); sb.append(", Runtime: ").append(Platform.getJavaRuntimeName()).append(Platform.getNewline()); sb.append("Platform: Java Vendor: ").append(Platform.getJavaVendor()).append(", ").append(Platform.getJavaVendorURL()); - sb.append(", JavaSE: ").append(Platform.isJavaSE()); - sb.append(", Java6: ").append(Platform.isJava6()); + sb.append(", JavaSE: ").append(PlatformPropsImpl.JAVA_SE); + sb.append(", Java6: ").append(PlatformPropsImpl.JAVA_6); sb.append(", AWT enabled: ").append(Platform.AWT_AVAILABLE); sb.append(Platform.getNewline()).append(SEPERATOR); diff --git a/src/java/com/jogamp/gluegen/JavaConfiguration.java b/src/java/com/jogamp/gluegen/JavaConfiguration.java index b64c041..3924ec2 100644 --- a/src/java/com/jogamp/gluegen/JavaConfiguration.java +++ b/src/java/com/jogamp/gluegen/JavaConfiguration.java @@ -42,6 +42,7 @@ package com.jogamp.gluegen; import com.jogamp.gluegen.JavaEmitter.EmissionStyle; import com.jogamp.gluegen.JavaEmitter.MethodAccess; + import java.io.*; import java.lang.reflect.Array; import java.util.*; @@ -53,6 +54,7 @@ import com.jogamp.gluegen.cgram.types.*; import java.util.logging.Logger; +import jogamp.common.os.MachineDescriptionRuntime; import static java.util.logging.Level.*; import static com.jogamp.gluegen.JavaEmitter.MethodAccess.*; import static com.jogamp.gluegen.JavaEmitter.EmissionStyle.*; @@ -164,6 +166,7 @@ public class JavaConfiguration { private final Map<String, String> structPackages = new HashMap<String, String>(); private final List<String> customCCode = new ArrayList<String>(); private final List<String> forcedStructs = new ArrayList<String>(); + private final Map<String, String> structMachineDescriptorIndex = new HashMap<String, String>(); private final Map<String, String> returnValueCapacities = new HashMap<String, String>(); private final Map<String, String> returnValueLengths = new HashMap<String, String>(); private final Map<String, List<String>> temporaryCVariableDeclarations = new HashMap<String, List<String>>(); @@ -547,7 +550,12 @@ public class JavaConfiguration { } /** Returns true if the glue code for the given function will be - manually implemented by the end user. */ + manually implemented by the end user. + * <p> + * If symbol references a struct field or method, see {@link #canonicalStructFieldSymbol(String, String)}, + * it describes field's array-length or element-count referenced by a pointer. + * </p> + */ public boolean manuallyImplement(final String functionName) { return manuallyImplement.contains(functionName); } @@ -637,6 +645,20 @@ public class JavaConfiguration { } /** + * Returns a MessageFormat string of the Java code defining {@code mdIdx}, + * i.e. the index of the static MachineDescriptor index for structs. + * <p> + * If undefined, code generation uses the default expression: + * <pre> + * private static final int mdIdx = MachineDescriptionRuntime.getStatic().ordinal(); + * </pre> + * </p> + */ + public String returnStructMachineDescriptorIndex(final String structName) { + return structMachineDescriptorIndex.get(structName); + } + + /** * Returns a MessageFormat string of the C expression calculating * the capacity of the java.nio.ByteBuffer being returned from a * native method, or null if no expression has been specified. @@ -1101,6 +1123,10 @@ public class JavaConfiguration { readTemporaryCVariableAssignment(tok, filename, lineNo); // Warning: make sure delimiters are reset at the top of this loop // because TemporaryCVariableAssignment changes them. + } else if (cmd.equalsIgnoreCase("StructMachineDescriptorIndex")) { + readStructMachineDescriptorIndex(tok, filename, lineNo); + // Warning: make sure delimiters are reset at the top of this loop + // because StructMachineDescriptorIndex changes them. } else if (cmd.equalsIgnoreCase("ReturnValueCapacity")) { readReturnValueCapacity(tok, filename, lineNo); // Warning: make sure delimiters are reset at the top of this loop @@ -1499,6 +1525,18 @@ public class JavaConfiguration { } } + protected void readStructMachineDescriptorIndex(final StringTokenizer tok, final String filename, final int lineNo) { + try { + final String structName = tok.nextToken(); + String restOfLine = tok.nextToken("\n\r\f"); + restOfLine = restOfLine.trim(); + structMachineDescriptorIndex.put(structName, restOfLine); + } catch (final NoSuchElementException e) { + throw new RuntimeException("Error parsing \"StructMachineDescriptorIndex\" command at line " + lineNo + + " in file \"" + filename + "\"", e); + } + } + protected void readReturnValueCapacity(final StringTokenizer tok, final String filename, final int lineNo) { try { final String functionName = tok.nextToken(); diff --git a/src/java/com/jogamp/gluegen/JavaEmitter.java b/src/java/com/jogamp/gluegen/JavaEmitter.java index 7e5ce51..48c7047 100644 --- a/src/java/com/jogamp/gluegen/JavaEmitter.java +++ b/src/java/com/jogamp/gluegen/JavaEmitter.java @@ -963,7 +963,10 @@ public class JavaEmitter implements GlueEmitter { javaWriter.println(); javaWriter.println(" StructAccessor accessor;"); javaWriter.println(); - javaWriter.println(" private static final int mdIdx = MachineDescriptionRuntime.getStatic().ordinal();"); + final String cfgMachDescrIdxCode = cfg.returnStructMachineDescriptorIndex(containingJTypeName); + final String machDescrIdxCode = null != cfgMachDescrIdxCode ? cfgMachDescrIdxCode : "private static final int mdIdx = MachineDescriptionRuntime.getStatic().ordinal();"; + javaWriter.println(" "+machDescrIdxCode); + javaWriter.println(" private final MachineDescription md;"); javaWriter.println(); // generate all offset and size arrays generateOffsetAndSizeArrays(javaWriter, " ", containingJTypeName, structCType, null, null); /* w/o offset */ @@ -1037,22 +1040,29 @@ public class JavaEmitter implements GlueEmitter { } } javaWriter.println(); - javaWriter.println(" public static int size() {"); - javaWriter.println(" return "+containingJTypeName+"_size[mdIdx];"); - javaWriter.println(" }"); - javaWriter.println(); - javaWriter.println(" public static " + containingJTypeName + " create() {"); - javaWriter.println(" return create(Buffers.newDirectByteBuffer(size()));"); - javaWriter.println(" }"); - javaWriter.println(); - javaWriter.println(" public static " + containingJTypeName + " create(java.nio.ByteBuffer buf) {"); - javaWriter.println(" return new " + containingJTypeName + "(buf);"); - javaWriter.println(" }"); - javaWriter.println(); - javaWriter.println(" " + containingJTypeName + "(java.nio.ByteBuffer buf) {"); - javaWriter.println(" accessor = new StructAccessor(buf);"); - javaWriter.println(" }"); - javaWriter.println(); + if( !cfg.manuallyImplement(JavaConfiguration.canonicalStructFieldSymbol(containingJTypeName, "size")) ) { + javaWriter.println(" public static int size() {"); + javaWriter.println(" return "+containingJTypeName+"_size[mdIdx];"); + javaWriter.println(" }"); + javaWriter.println(); + } + if( !cfg.manuallyImplement(JavaConfiguration.canonicalStructFieldSymbol(containingJTypeName, "create")) ) { + javaWriter.println(" public static " + containingJTypeName + " create() {"); + javaWriter.println(" return create(Buffers.newDirectByteBuffer(size()));"); + javaWriter.println(" }"); + javaWriter.println(); + javaWriter.println(" public static " + containingJTypeName + " create(java.nio.ByteBuffer buf) {"); + javaWriter.println(" return new " + containingJTypeName + "(buf);"); + javaWriter.println(" }"); + javaWriter.println(); + } + if( !cfg.manuallyImplement(JavaConfiguration.canonicalStructFieldSymbol(containingJTypeName, containingJTypeName)) ) { + javaWriter.println(" " + containingJTypeName + "(java.nio.ByteBuffer buf) {"); + javaWriter.println(" md = MachineDescription.StaticConfig.values()[mdIdx].md;"); + javaWriter.println(" accessor = new StructAccessor(buf);"); + javaWriter.println(" }"); + javaWriter.println(); + } javaWriter.println(" public java.nio.ByteBuffer getBuffer() {"); javaWriter.println(" return accessor.getBuffer();"); javaWriter.println(" }"); @@ -1129,7 +1139,7 @@ public class JavaEmitter implements GlueEmitter { if( fieldTypeNativeSizeFixed ) { javaWriter.println(" accessor.set" + capJavaTypeName + "At(" + fieldName+"_offset[mdIdx], val);"); } else { - javaWriter.println(" accessor.set" + capJavaTypeName + "At(" + fieldName+"_offset[mdIdx], val, MachineDescriptionRuntime.getStatic().md."+sizeDenominator+"SizeInBytes());"); + javaWriter.println(" accessor.set" + capJavaTypeName + "At(" + fieldName+"_offset[mdIdx], val, md."+sizeDenominator+"SizeInBytes());"); } javaWriter.println(" return this;"); javaWriter.println(" }"); @@ -1143,7 +1153,7 @@ public class JavaEmitter implements GlueEmitter { if( fieldTypeNativeSizeFixed ) { javaWriter.println("accessor.get" + capJavaTypeName + "At(" + fieldName+"_offset[mdIdx]);"); } else { - javaWriter.println("accessor.get" + capJavaTypeName + "At(" + fieldName+"_offset[mdIdx], MachineDescriptionRuntime.getStatic().md."+sizeDenominator+"SizeInBytes());"); + javaWriter.println("accessor.get" + capJavaTypeName + "At(" + fieldName+"_offset[mdIdx], md."+sizeDenominator+"SizeInBytes());"); } javaWriter.println(" }"); } else { @@ -1240,7 +1250,9 @@ public class JavaEmitter implements GlueEmitter { writer.print(")"); } - private void generateOffsetAndSizeArrays(final PrintWriter writer, final String prefix, final String fieldName, final Type fieldType, final Field field, final String postfix) { + private void generateOffsetAndSizeArrays(final PrintWriter writer, final String prefix, + final String fieldName, final Type fieldType, + final Field field, final String postfix) { if(null != field) { writer.print(prefix+"private static final int[] "+fieldName+"_offset = new int[] { "); for( int i=0; i < machDescTargetConfigs.length; i++ ) { @@ -1668,7 +1680,7 @@ public class JavaEmitter implements GlueEmitter { if( baseCElemNativeSizeFixed ) { javaWriter.println(" accessor.set" + baseJElemTypeNameC + "At(" + fieldName+"_offset[mdIdx], val);"); } else { - javaWriter.println(" accessor.set" + baseJElemTypeNameC + "At(" + fieldName+"_offset[mdIdx], val, MachineDescriptionRuntime.getStatic().md."+baseCElemSizeDenominator+"SizeInBytes());"); + javaWriter.println(" accessor.set" + baseJElemTypeNameC + "At(" + fieldName+"_offset[mdIdx], val, md."+baseCElemSizeDenominator+"SizeInBytes());"); } javaWriter.println(" return this;"); javaWriter.println(" }"); @@ -1831,7 +1843,7 @@ public class JavaEmitter implements GlueEmitter { if( baseCElemNativeSizeFixed ) { javaWriter.println(" return accessor.get" + baseJElemTypeNameC + "At(" + fieldName+"_offset[mdIdx]);"); } else { - javaWriter.println(" return accessor.get" + baseJElemTypeNameC + "At(" + fieldName+"_offset[mdIdx], MachineDescriptionRuntime.getStatic().md."+baseCElemSizeDenominator+"SizeInBytes());"); + javaWriter.println(" return accessor.get" + baseJElemTypeNameC + "At(" + fieldName+"_offset[mdIdx], md."+baseCElemSizeDenominator+"SizeInBytes());"); } javaWriter.println(" }"); javaWriter.println(); |