From dc4b259b6651bdc0cec0895bc74e26e504870c8e Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 21 Jul 2011 11:06:52 +0200 Subject: GlueGen proper size / alignment of primitive and compound types usage [2/2] - Fin MachineDesction == MD MD.StaticConfig: - enum for all supported static configs (ID -> MD) - verified at runtime: test runtime queried-MD versus static-MD, hard fail if not compatible (size/alignment) SizeThunk primitive sizes: - Add notion of fixed native size (eg. int64_t) and otherwise (eg. long) java struct 'wrappers' code generation: - single class using size/offset arrays of all MachineDescription configurations - at runtime the array idx is queried in static block - type aligment for not fixed-native-size types (SizeThunk, undef long/int) via StructAccessor junit test: - add float test - fix native code - add java (create, write) -> native (verify) test works (tested) on: linux 32/64 and windows 32/64 --- src/java/com/jogamp/common/nio/StructAccessor.java | 65 +++- .../com/jogamp/common/os/MachineDescription.java | 294 ++++++++-------- src/java/com/jogamp/common/os/Platform.java | 40 ++- src/java/com/jogamp/gluegen/DebugEmitter.java | 3 - src/java/com/jogamp/gluegen/GlueEmitter.java | 20 -- src/java/com/jogamp/gluegen/GlueGen.java | 5 - src/java/com/jogamp/gluegen/JavaEmitter.java | 378 ++++++++++----------- .../jogamp/gluegen/runtime/types/SizeThunk.java | 35 +- .../common/os/MachineDescriptionRuntime.java | 94 +++-- .../gluegen/test/junit/generation/BaseClass.java | 108 ++++-- .../gluegen/test/junit/generation/test1-common.cfg | 1 + .../jogamp/gluegen/test/junit/generation/test1.c | 89 ++++- .../jogamp/gluegen/test/junit/generation/test1.h | 23 +- 13 files changed, 684 insertions(+), 471 deletions(-) (limited to 'src') diff --git a/src/java/com/jogamp/common/nio/StructAccessor.java b/src/java/com/jogamp/common/nio/StructAccessor.java index 5c0e70a..41da290 100644 --- a/src/java/com/jogamp/common/nio/StructAccessor.java +++ b/src/java/com/jogamp/common/nio/StructAccessor.java @@ -113,6 +113,37 @@ public class StructAccessor { bb.putInt(byteOffset, v); } + /** Retrieves the int at the specified byteOffset. */ + public final int getIntAt(int byteOffset, int nativeSizeInBytes) { + switch(nativeSizeInBytes) { + case 2: + return (int) bb.getShort(byteOffset) & 0x0000FFFF ; + case 4: + return bb.getInt(byteOffset); + case 8: + return (int) ( bb.getLong(byteOffset) & 0x00000000FFFFFFFFL ) ; + default: + throw new InternalError("invalid nativeSizeInBytes "+nativeSizeInBytes); + } + } + + /** Puts a int at the specified byteOffset. */ + public final void setIntAt(int byteOffset, int v, int nativeSizeInBytes) { + switch(nativeSizeInBytes) { + case 2: + bb.putShort(byteOffset, (short) ( v & 0x0000FFFF ) ); + break; + case 4: + bb.putInt(byteOffset, v); + break; + case 8: + bb.putLong(byteOffset, (long)v & 0x00000000FFFFFFFFL ); + break; + default: + throw new InternalError("invalid nativeSizeInBytes "+nativeSizeInBytes); + } + } + /** Retrieves the float at the specified byteOffset. */ public final float getFloatAt(int byteOffset) { return bb.getFloat(byteOffset); @@ -133,20 +164,42 @@ public class StructAccessor { bb.putDouble(byteOffset, v); } - /** - * Retrieves the long at the specified byteOffset. - */ + /** Retrieves the long at the specified byteOffset. */ public final long getLongAt(int byteOffset) { return bb.getLong(byteOffset); } - /** - * Puts a long at the specified byteOffset. - */ + /** Puts a long at the specified byteOffset. */ public final void setLongAt(int byteOffset, long v) { bb.putLong(byteOffset, v); } + /** Retrieves the long at the specified byteOffset. */ + public final long getLongAt(int byteOffset, int nativeSizeInBytes) { + switch(nativeSizeInBytes) { + case 4: + return (long) bb.getInt(byteOffset) & 0x00000000FFFFFFFFL; + case 8: + return bb.getLong(byteOffset); + default: + throw new InternalError("invalid nativeSizeInBytes "+nativeSizeInBytes); + } + } + + /** Puts a long at the specified byteOffset. */ + public final void setLongAt(int byteOffset, long v, int nativeSizeInBytes) { + switch(nativeSizeInBytes) { + case 4: + bb.putInt(byteOffset, (int) ( v & 0x00000000FFFFFFFFL ) ); + break; + case 8: + bb.putLong(byteOffset, v); + break; + default: + throw new InternalError("invalid nativeSizeInBytes "+nativeSizeInBytes); + } + } + public final void setBytesAt(int byteOffset, byte[] v) { for (int i = 0; i < v.length; i++) { bb.put(byteOffset++, v[i]); diff --git a/src/java/com/jogamp/common/os/MachineDescription.java b/src/java/com/jogamp/common/os/MachineDescription.java index 7534917..43f2975 100644 --- a/src/java/com/jogamp/common/os/MachineDescription.java +++ b/src/java/com/jogamp/common/os/MachineDescription.java @@ -40,77 +40,93 @@ package com.jogamp.common.os; -import java.nio.ByteBuffer; -import java.nio.IntBuffer; -import java.nio.ShortBuffer; - -import com.jogamp.common.nio.Buffers; - /** * For alignment and size see {@link com.jogamp.gluegen} */ public class MachineDescription { - /* arch os int, long, float, doubl, ldoubl, ptr, page */ - final static int[] size_armeabi = { 4, 4, 4, 8, 8, 4, 4096 }; - final static int[] size_x86_32_unix = { 4, 4, 4, 8, 12, 4, 4096 }; - final static int[] size_x86_32_windows = { 4, 4, 4, 8, 12, 4, 4096 }; - final static int[] size_x86_64_unix = { 4, 8, 4, 8, 16, 8, 4096 }; - final static int[] size_x86_64_windows = { 4, 4, 4, 8, 16, 8, 4096 }; + public enum ID { + /** {@link Platform.CPUType#ARM} EABI Little Endian */ + ARMle_EABI(Platform.CPUType.ARM), + /** {@link Platform.CPUType#X86_32} Little Endian Unix */ + X86_32_UNIX(Platform.CPUType.X86_32), + /** {@link Platform.CPUType#X86_64} Little Endian Unix */ + X86_64_UNIX(Platform.CPUType.X86_64), + /** {@link Platform.CPUType#X86_32} Little Endian Windows */ + X86_32_WINDOWS(Platform.CPUType.X86_32), + /** {@link Platform.CPUType#X86_64} Little Endian Windows */ + X86_64_WINDOWS(Platform.CPUType.X86_64); + + public final Platform.CPUType cpu; + + ID(Platform.CPUType cpu){ + this.cpu = cpu; + } + } + + /* arch os int, long, float, doubl, ldoubl, ptr, page */ + private final static int[] size_armeabi = { 4, 4, 4, 8, 8, 4, 4096 }; + private final static int[] size_x86_32_unix = { 4, 4, 4, 8, 12, 4, 4096 }; + private final static int[] size_x86_32_windows = { 4, 4, 4, 8, 12, 4, 4096 }; + private final static int[] size_x86_64_unix = { 4, 8, 4, 8, 16, 8, 4096 }; + private final static int[] size_x86_64_windows = { 4, 4, 4, 8, 16, 8, 4096 }; - /* arch os i8, i16, i32, i64, int, long, float, doubl, ldoubl, ptr */ - final static int[] align_armeabi = { 1, 2, 4, 8, 4, 4, 4, 8, 8, 4 }; - final static int[] align_x86_32_unix = { 1, 2, 4, 4, 4, 4, 4, 4, 4, 4 }; - final static int[] align_x86_32_windows = { 1, 2, 4, 8, 4, 4, 4, 8, 4, 4 }; - final static int[] align_x86_64_unix = { 1, 2, 4, 8, 4, 8, 4, 8, 16, 8 }; - final static int[] align_x86_64_windows = { 1, 2, 4, 8, 4, 4, 4, 8, 16, 8 }; + /* arch os i8, i16, i32, i64, int, long, float, doubl, ldoubl, ptr */ + private final static int[] align_armeabi = { 1, 2, 4, 8, 4, 4, 4, 8, 8, 4 }; + private final static int[] align_x86_32_unix = { 1, 2, 4, 4, 4, 4, 4, 4, 4, 4 }; + private final static int[] align_x86_32_windows = { 1, 2, 4, 8, 4, 4, 4, 8, 4, 4 }; + private final static int[] align_x86_64_unix = { 1, 2, 4, 8, 4, 8, 4, 8, 16, 8 }; + private final static int[] align_x86_64_windows = { 1, 2, 4, 8, 4, 4, 4, 8, 16, 8 }; - public enum Config { - ARM_EABI(size_armeabi, align_armeabi), - X86_32_UNIX(size_x86_32_unix, align_x86_32_unix), - X86_64_UNIX(size_x86_64_unix, align_x86_64_unix), - X86_32_WINDOWS(size_x86_32_windows, align_x86_32_windows), - X86_64_WINDOWS(size_x86_64_windows, align_x86_64_windows); + public enum StaticConfig { + /** {@link MachineDescription.ID#ARMle_EABI } */ + ARMle_EABI(ID.ARMle_EABI, true, size_armeabi, align_armeabi), + /** {@link MachineDescription.ID#X86_32_UNIX } */ + X86_32_UNIX(ID.X86_32_UNIX, true, size_x86_32_unix, align_x86_32_unix), + /** {@link MachineDescription.ID#X86_64_UNIX } */ + X86_64_UNIX(ID.X86_64_UNIX, true, size_x86_64_unix, align_x86_64_unix), + /** {@link MachineDescription.ID#X86_32_WINDOWS } */ + X86_32_WINDOWS(ID.X86_32_WINDOWS, true, size_x86_32_windows, align_x86_32_windows), + /** {@link MachineDescription.ID#X86_64_WINDOWS } */ + X86_64_WINDOWS(ID.X86_64_WINDOWS, true, size_x86_64_windows, align_x86_64_windows); - public final int intSizeInBytes; - public final int longSizeInBytes; - public final int floatSizeInBytes; - public final int doubleSizeInBytes; - public final int ldoubleSizeInBytes; - public final int pointerSizeInBytes; - public final int pageSizeInBytes; + public final ID id; + public final MachineDescription md; - public final int int8AlignmentInBytes; - public final int int16AlignmentInBytes; - public final int int32AlignmentInBytes; - public final int int64AlignmentInBytes; - public final int intAlignmentInBytes; - public final int longAlignmentInBytes; - public final int floatAlignmentInBytes; - public final int doubleAlignmentInBytes; - public final int ldoubleAlignmentInBytes; - public final int pointerAlignmentInBytes; + StaticConfig(ID id, boolean littleEndian, int[] sizes, int[] alignments) { + this.id = id; + int i=0, j=0; + this.md = new MachineDescription(false, littleEndian, + sizes[i++], + sizes[i++], + sizes[i++], + sizes[i++], + sizes[i++], + sizes[i++], + sizes[i++], + alignments[j++], + alignments[j++], + alignments[j++], + alignments[j++], + alignments[j++], + alignments[j++], + alignments[j++], + alignments[j++], + alignments[j++], + alignments[j++]); + } - Config(int[] sizes, int[] alignments) { - int i=0; - intSizeInBytes = sizes[i++]; - longSizeInBytes = sizes[i++];; - floatSizeInBytes = sizes[i++];; - doubleSizeInBytes = sizes[i++];; - ldoubleSizeInBytes = sizes[i++];; - pointerSizeInBytes = sizes[i++];; - pageSizeInBytes = sizes[i++];; - - i=0; - int8AlignmentInBytes = alignments[i++]; - int16AlignmentInBytes = alignments[i++]; - int32AlignmentInBytes = alignments[i++]; - int64AlignmentInBytes = alignments[i++]; - intAlignmentInBytes = alignments[i++]; - longAlignmentInBytes = alignments[i++]; - floatAlignmentInBytes = alignments[i++]; - doubleAlignmentInBytes = alignments[i++]; - ldoubleAlignmentInBytes = alignments[i++]; - pointerAlignmentInBytes = alignments[i++]; + public StringBuilder toString(StringBuilder sb) { + if(null==sb) { + sb = new StringBuilder(); + } + sb.append("MachineDescriptionStatic: ").append(this.name()).append("(").append(this.ordinal()).append("): "); + md.toString(sb); + return sb; + } + + @Override + public String toString() { + return toString(null).toString(); } } @@ -144,72 +160,6 @@ public class MachineDescription { final private int ldoubleAlignmentInBytes; final private int pointerAlignmentInBytes; - public static boolean queryIsLittleEndian() { - ByteBuffer tst_b = Buffers.newDirectByteBuffer(Buffers.SIZEOF_INT); // 32bit in native order - IntBuffer tst_i = tst_b.asIntBuffer(); - ShortBuffer tst_s = tst_b.asShortBuffer(); - tst_i.put(0, 0x0A0B0C0D); - return 0x0C0D == tst_s.get(0); - } - - public static MachineDescription createStaticArmEABI() { - return new MachineDescription(false, queryIsLittleEndian(), Config.ARM_EABI); - } - public static MachineDescription createStaticUnix32() { - return new MachineDescription(false, queryIsLittleEndian(), Config.X86_32_UNIX); - } - public static MachineDescription createStaticUnix64() { - return new MachineDescription(false, queryIsLittleEndian(), Config.X86_64_UNIX); - } - public static MachineDescription createStaticWindows32() { - return new MachineDescription(false, queryIsLittleEndian(), Config.X86_32_WINDOWS); - } - public static MachineDescription createStaticWindows64() { - return new MachineDescription(false, queryIsLittleEndian(), Config.X86_64_WINDOWS); - } - public static MachineDescription createStatic(boolean is32BitByCPUArch) { - if(is32BitByCPUArch) { - if(Platform.getCPUFamily() == Platform.CPUFamily.ARM) { - return createStaticArmEABI(); - } else if(Platform.getOSType() == Platform.OSType.WINDOWS) { - return createStaticWindows32(); - } - return createStaticUnix32(); - } else { - if(Platform.getOSType() == Platform.OSType.WINDOWS) { - return createStaticWindows64(); - } - return createStaticUnix64(); - } - } - - public MachineDescription(boolean runtimeValidated, - boolean littleEndian, - Config config) { - this.runtimeValidated = runtimeValidated; - this.littleEndian = littleEndian; - - this.intSizeInBytes = config.intSizeInBytes; - this.longSizeInBytes = config.longSizeInBytes; - this.floatSizeInBytes = config.floatSizeInBytes; - this.doubleSizeInBytes = config.doubleSizeInBytes; - this.ldoubleSizeInBytes = config.ldoubleSizeInBytes; - this.pointerSizeInBytes = config.pointerSizeInBytes; - this.pageSizeInBytes = config.pageSizeInBytes; - this.is32Bit = 4 == config.pointerSizeInBytes; - - this.int8AlignmentInBytes = config.int8AlignmentInBytes; - this.int16AlignmentInBytes = config.int16AlignmentInBytes; - this.int32AlignmentInBytes = config.int32AlignmentInBytes; - this.int64AlignmentInBytes = config.int64AlignmentInBytes; - this.intAlignmentInBytes = config.intAlignmentInBytes; - this.longAlignmentInBytes = config.longAlignmentInBytes; - this.floatAlignmentInBytes = config.floatAlignmentInBytes; - this.doubleAlignmentInBytes = config.doubleAlignmentInBytes; - this.ldoubleAlignmentInBytes = config.ldoubleAlignmentInBytes; - this.pointerAlignmentInBytes = config.pointerAlignmentInBytes; - } - public MachineDescription(boolean runtimeValidated, boolean littleEndian, @@ -319,29 +269,75 @@ public class MachineDescription { public int pageAlignedSize(int size) { return pageCount(size) * pageSizeInBytes; } + + /** + * Checks whether two size objects are equal. Two instances + * of MachineDescription are considered equal if all components + * match but {@link #runtimeValidated}, {@link #isRuntimeValidated()}. + * @return true if the two MachineDescription are equal; + * otherwise false. + */ + public final boolean equals(Object obj) { + if (this == obj) { return true; } + if ( !(obj instanceof MachineDescription) ) { return false; } + final MachineDescription md = (MachineDescription) obj; + + return pageSizeInBytes == md.pageSizeInBytes && + compatible(md); + } + + /** + * Checks whether two size objects are equal. Two instances + * of MachineDescription are considered equal if all components + * match but {@link #isRuntimeValidated()} and {@link #pageSizeInBytes()}. + * @return true if the two MachineDescription are equal; + * otherwise false. + */ + public final boolean compatible(MachineDescription md) { + return littleEndian == md.littleEndian && + + intSizeInBytes == md.intSizeInBytes && + longSizeInBytes == md.longSizeInBytes && + floatSizeInBytes == md.floatSizeInBytes && + doubleSizeInBytes == md.doubleSizeInBytes && + ldoubleSizeInBytes == md.ldoubleSizeInBytes && + pointerSizeInBytes == md.pointerSizeInBytes && + is32Bit == md.is32Bit && + + int8AlignmentInBytes == md.int8AlignmentInBytes && + int16AlignmentInBytes == md.int16AlignmentInBytes && + int32AlignmentInBytes == md.int32AlignmentInBytes && + int64AlignmentInBytes == md.int64AlignmentInBytes && + intAlignmentInBytes == md.intAlignmentInBytes && + longAlignmentInBytes == md.longAlignmentInBytes && + floatAlignmentInBytes == md.floatAlignmentInBytes && + doubleAlignmentInBytes == md.doubleAlignmentInBytes && + ldoubleAlignmentInBytes == md.ldoubleAlignmentInBytes && + pointerAlignmentInBytes == md.pointerAlignmentInBytes ; + } - public StringBuilder toString(StringBuilder sb) { - if(null==sb) { - sb = new StringBuilder(); - } - sb.append("MachineDescription: runtimeValidated ").append(isRuntimeValidated()).append(", littleEndian ").append(isLittleEndian()).append(", 32Bit ").append(is32Bit()).append(", primitive size / alignment:").append(Platform.getNewline()); - sb.append(" int8 ").append(int8SizeInBytes) .append(" / ").append(int8AlignmentInBytes); - sb.append(", int16 ").append(int16SizeInBytes) .append(" / ").append(int16AlignmentInBytes).append(Platform.getNewline()); - sb.append(" int ").append(intSizeInBytes) .append(" / ").append(intAlignmentInBytes); - sb.append(", long ").append(longSizeInBytes) .append(" / ").append(longAlignmentInBytes).append(Platform.getNewline()); - sb.append(" int32 ").append(int32SizeInBytes) .append(" / ").append(int32AlignmentInBytes); - sb.append(", int64 ").append(int64SizeInBytes) .append(" / ").append(int64AlignmentInBytes).append(Platform.getNewline()); - sb.append(" float ").append(floatSizeInBytes) .append(" / ").append(floatAlignmentInBytes); - sb.append(", double ").append(doubleSizeInBytes) .append(" / ").append(doubleAlignmentInBytes); - sb.append(", ldouble ").append(ldoubleSizeInBytes).append(" / ").append(ldoubleAlignmentInBytes).append(Platform.getNewline()); - sb.append(" pointer ").append(pointerSizeInBytes).append(" / ").append(pointerAlignmentInBytes); - sb.append(", page ").append(pageSizeInBytes); - return sb; + public StringBuilder toString(StringBuilder sb) { + if(null==sb) { + sb = new StringBuilder(); } + sb.append("MachineDescription: runtimeValidated ").append(isRuntimeValidated()).append(", littleEndian ").append(isLittleEndian()).append(", 32Bit ").append(is32Bit()).append(", primitive size / alignment:").append(Platform.getNewline()); + sb.append(" int8 ").append(int8SizeInBytes) .append(" / ").append(int8AlignmentInBytes); + sb.append(", int16 ").append(int16SizeInBytes) .append(" / ").append(int16AlignmentInBytes).append(Platform.getNewline()); + sb.append(" int ").append(intSizeInBytes) .append(" / ").append(intAlignmentInBytes); + sb.append(", long ").append(longSizeInBytes) .append(" / ").append(longAlignmentInBytes).append(Platform.getNewline()); + sb.append(" int32 ").append(int32SizeInBytes) .append(" / ").append(int32AlignmentInBytes); + sb.append(", int64 ").append(int64SizeInBytes) .append(" / ").append(int64AlignmentInBytes).append(Platform.getNewline()); + sb.append(" float ").append(floatSizeInBytes) .append(" / ").append(floatAlignmentInBytes); + sb.append(", double ").append(doubleSizeInBytes) .append(" / ").append(doubleAlignmentInBytes); + sb.append(", ldouble ").append(ldoubleSizeInBytes).append(" / ").append(ldoubleAlignmentInBytes).append(Platform.getNewline()); + sb.append(" pointer ").append(pointerSizeInBytes).append(" / ").append(pointerAlignmentInBytes); + sb.append(", page ").append(pageSizeInBytes); + return sb; + } - @Override - public String toString() { - return toString(null).toString(); - } + @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 85567a8..4db5b09 100644 --- a/src/java/com/jogamp/common/os/Platform.java +++ b/src/java/com/jogamp/common/os/Platform.java @@ -28,9 +28,14 @@ package com.jogamp.common.os; +import java.nio.ByteBuffer; +import java.nio.IntBuffer; +import java.nio.ShortBuffer; import java.security.AccessController; import java.security.PrivilegedAction; +import com.jogamp.common.nio.Buffers; + import jogamp.common.os.MachineDescriptionRuntime; /** @@ -41,6 +46,7 @@ import jogamp.common.os.MachineDescriptionRuntime; public class Platform { public static final boolean JAVA_SE; + public static final boolean LITTLE_ENDIAN; public static final String OS; public static final String OS_lower; public static final String OS_VERSION; @@ -139,6 +145,8 @@ public class Platform { JAVA_SE = initIsJavaSE(); + LITTLE_ENDIAN = queryIsLittleEndianImpl(); + if( ARCH_lower.equals("x86") || ARCH_lower.equals("i386") || ARCH_lower.equals("i486") || @@ -171,13 +179,34 @@ public class Platform { } OS_TYPE = getOSTypeImpl(); - machineDescription = MachineDescriptionRuntime.getMachineDescription(getIs32BitByCPUArchImpl()); + MachineDescription md = MachineDescriptionRuntime.getRuntime(); + if(null == md) { + MachineDescription.StaticConfig smd = MachineDescriptionRuntime.getStatic(); + md = smd.md; + System.err.println("Warning: Using static MachineDescription: "+smd); + } else { + MachineDescription.StaticConfig smd = MachineDescriptionRuntime.getStatic(); + if(!md.compatible(smd.md)) { + throw new RuntimeException("Incompatible MachineDescriptions:"+Platform.NEWLINE+ + " Static "+smd+Platform.NEWLINE+ + " Runtime "+md); + } + } + machineDescription = md; is32Bit = machineDescription.is32Bit(); } private Platform() {} - private static boolean getIs32BitByCPUArchImpl() throws RuntimeException { + private static boolean queryIsLittleEndianImpl() { + ByteBuffer tst_b = Buffers.newDirectByteBuffer(Buffers.SIZEOF_INT); // 32bit in native order + IntBuffer tst_i = tst_b.asIntBuffer(); + ShortBuffer tst_s = tst_b.asShortBuffer(); + tst_i.put(0, 0x0A0B0C0D); + return 0x0C0D == tst_s.get(0); + } + + public static boolean isCPUArch32Bit() throws RuntimeException { switch( CPU_ARCH ) { case X86_32: case ARM: @@ -256,6 +285,13 @@ public class Platform { return JAVA_SE; } + /** + * Returns true if this machine is little endian, otherwise false. + */ + public static boolean isLittleEndian() { + return LITTLE_ENDIAN; + } + /** * Returns the OS name. */ diff --git a/src/java/com/jogamp/gluegen/DebugEmitter.java b/src/java/com/jogamp/gluegen/DebugEmitter.java index 6afc55c..ce6ae69 100644 --- a/src/java/com/jogamp/gluegen/DebugEmitter.java +++ b/src/java/com/jogamp/gluegen/DebugEmitter.java @@ -52,9 +52,6 @@ public class DebugEmitter implements GlueEmitter { public void readConfigurationFile(String filename) {} - public void setMachineDescription(MachineDescription md32, - MachineDescription md64) {} - public void beginEmission(GlueEmitterControls controls) { System.out.println("----- BEGIN EMISSION OF GLUE CODE -----"); } diff --git a/src/java/com/jogamp/gluegen/GlueEmitter.java b/src/java/com/jogamp/gluegen/GlueEmitter.java index ac1065b..99bf31d 100644 --- a/src/java/com/jogamp/gluegen/GlueEmitter.java +++ b/src/java/com/jogamp/gluegen/GlueEmitter.java @@ -54,26 +54,6 @@ public interface GlueEmitter { public void readConfigurationFile(String filename) throws Exception; - /** Sets the description of the underlying hardware. "md32" - specifies the description of a 32-bit version of the underlying - CPU architecture. "md64" specifies the description of a 64-bit - version of the underlying CPU architecture. At least one must be - specified. When both are specified, the bulk of the glue code is - generated using the 32-bit machine description, but structs are - laid out twice and the base class delegates between the 32-bit - and 64-bit implementation at run time. This allows Java code - which can access both 32-bit and 64-bit versions of the data - structures to be included in the same jar file.

- - It is up to the end user to provide the appropriate opaque - definitions to ensure that types of varying size (longs and - pointers in particular) are exposed to Java in such a way that - changing the machine description does not cause different shared - glue code to be generated for the 32- and 64-bit ports. - */ - public void setMachineDescription(MachineDescription md32, - MachineDescription md64); - /** * Begin the emission of glue code. This might include opening files, * emitting class headers, etc. diff --git a/src/java/com/jogamp/gluegen/GlueGen.java b/src/java/com/jogamp/gluegen/GlueGen.java index c0e87ee..744d526 100644 --- a/src/java/com/jogamp/gluegen/GlueGen.java +++ b/src/java/com/jogamp/gluegen/GlueGen.java @@ -188,11 +188,6 @@ public class GlueGen implements GlueEmitterControls { } } - // Provide MachineDescriptions to emitter - final MachineDescription md32 = MachineDescription.createStaticUnix32(); - final MachineDescription md64 = MachineDescription.createStaticUnix64(); - emit.setMachineDescription(md32, md64); - // Repackage the enum and #define statements from the parser into a common format // so that SymbolFilters can operate upon both identically constants = new ArrayList(); diff --git a/src/java/com/jogamp/gluegen/JavaEmitter.java b/src/java/com/jogamp/gluegen/JavaEmitter.java index dfa7594..c68fae8 100644 --- a/src/java/com/jogamp/gluegen/JavaEmitter.java +++ b/src/java/com/jogamp/gluegen/JavaEmitter.java @@ -60,6 +60,8 @@ import com.jogamp.gluegen.runtime.types.Type; import java.nio.Buffer; import java.util.logging.Logger; +import jogamp.common.os.MachineDescriptionRuntime; + import static java.util.logging.Level.*; import static com.jogamp.gluegen.JavaEmitter.MethodAccess.*; @@ -97,9 +99,9 @@ public class JavaEmitter implements GlueEmitter { private PrintWriter javaWriter; // Emits either interface or, in AllStatic mode, everything private PrintWriter javaImplWriter; // Only used in non-AllStatic modes for impl class private PrintWriter cWriter; - private MachineDescription machDesc32; - private MachineDescription machDesc64; - + private final MachineDescription machDescJava = MachineDescription.StaticConfig.X86_64_UNIX.md; + private final MachineDescription.StaticConfig[] machDescTargetConfigs = MachineDescription.StaticConfig.values(); + protected final static Logger LOG = Logger.getLogger(JavaEmitter.class.getPackage().getName()); public void readConfigurationFile(String filename) throws Exception { @@ -107,16 +109,6 @@ public class JavaEmitter implements GlueEmitter { cfg.read(filename); } - public void setMachineDescription(MachineDescription md32, MachineDescription md64) { - - if ((md32 == null) && (md64 == null)) { - throw new RuntimeException("Must specify at least one MachineDescription"); - } - - machDesc32 = md32; - machDesc64 = md64; - } - class ConstantRenamer implements SymbolFilter { private List constants; @@ -615,7 +607,7 @@ public class JavaEmitter implements GlueEmitter { cfg.allStatic(), (binding.needsNIOWrappingOrUnwrapping() || hasPrologueOrEpilogue), !cfg.nioDirectOnly(binding.getName()), - machDesc64); + machDescJava); prepCEmitter(binding, cEmitter); allEmitters.add(cEmitter); } @@ -663,7 +655,7 @@ public class JavaEmitter implements GlueEmitter { try { // Get Java binding for the function - MethodBinding mb = bindFunction(sym, null, null, machDesc64); + MethodBinding mb = bindFunction(sym, null, null, machDescJava); // JavaTypes representing C pointers in the initial // MethodBinding have not been lowered yet to concrete types @@ -771,19 +763,6 @@ public class JavaEmitter implements GlueEmitter { } public void emitStruct(CompoundType structType, String alternateName) throws Exception { - // Emit abstract base class delegating to 32-bit or 64-bit implementations - emitStructImpl(structType, alternateName, machDesc32, machDesc64, true, false); - // Emit concrete implementing class for each variant - emitStructImpl(structType, alternateName, machDesc32, machDesc64, false, true); - emitStructImpl(structType, alternateName, machDesc32, machDesc64, false, false); - } - - public void emitStructImpl(CompoundType structType, - String alternateName, - MachineDescription md32, - MachineDescription md64, - boolean doBaseClass, - boolean do32Bit) throws Exception { String name = structType.getName(); if (name == null && alternateName != null) { name = alternateName; @@ -805,50 +784,31 @@ public class JavaEmitter implements GlueEmitter { } String containingTypeName = containingType.getName(); - if ((md32 == null) || (md64 == null)) { - throw new RuntimeException("Must supply both 32- and 64-bit MachineDescriptions to emitStructImpl"); - } - String suffix = ""; - - // The "external" MachineDescription is the one used to determine - // the sizes of the primitive types seen in the public API. For - // example, if a C long is an element of a struct, it is the size + // machDescJava global MachineDescription is the one used to determine + // the sizes of the primitive types seen in the public API in Java. + // For example, if a C long is an element of a struct, it is the size // of a Java int on a 32-bit machine but the size of a Java long // on a 64-bit machine. To support both of these sizes with the // same API, the abstract base class must take and return a Java // long from the setter and getter for this field. However the // implementation on a 32-bit platform must downcast this to an - // int and set only an int's worth of data in the struct. The - // "internal" MachineDescription is the one used to determine how + // int and set only an int's worth of data in the struct. + // + // The machDescTarget MachineDescription is the one used to determine how // much data to set in or get from the struct and exactly from // where it comes. // - // Note that the 64-bit MachineDescription is always used as the - // external MachineDescription. - - MachineDescription extMachDesc = md64; - MachineDescription intMachDesc = null; - - if (!doBaseClass) { - if (do32Bit) { - intMachDesc = md32; - suffix = "32"; - } else { - intMachDesc = md64; - suffix = "64"; - } - } + // Note that machDescJava MachineDescription is always 64bit unix, + // which complies w/ Java types. boolean needsNativeCode = false; // Native code for calls through function pointers gets emitted // into the abstract base class; Java code which accesses fields // gets emitted into the concrete classes - if (doBaseClass) { - for (int i = 0; i < structType.getNumFields(); i++) { - if (structType.getField(i).getType().isFunctionPointer()) { - needsNativeCode = true; - break; - } + for (int i = 0; i < structType.getNumFields(); i++) { + if (structType.getField(i).getType().isFunctionPointer()) { + needsNativeCode = true; + break; } } @@ -859,7 +819,7 @@ public class JavaEmitter implements GlueEmitter { writer = openFile( cfg.javaOutputDir() + File.separator + CodeGenUtils.packageAsPath(structClassPkg) + - File.separator + containingTypeName + suffix + ".java"); + File.separator + containingTypeName + ".java"); CodeGenUtils.emitAutogeneratedWarning(writer, this); if (needsNativeCode) { String nRoot = cfg.nativeOutputDir(); @@ -883,6 +843,7 @@ public class JavaEmitter implements GlueEmitter { writer.println("import " + cfg.gluegenRuntimePackage() + ".*;"); writer.println("import " + DynamicLookupHelper.class.getPackage().getName() + ".*;"); writer.println("import " + Buffers.class.getPackage().getName() + ".*;"); + writer.println("import " + MachineDescriptionRuntime.class.getName() + ";"); writer.println(); List imports = cfg.imports(); for (String str : imports) { @@ -895,10 +856,7 @@ public class JavaEmitter implements GlueEmitter { for (String doc : javadoc) { writer.println(doc); } - writer.print((doBaseClass ? "public " : "") + (doBaseClass ? "abstract " : "") + "class " + containingTypeName + suffix + " "); - if (!doBaseClass) { - writer.print("extends " + containingTypeName + " "); - } + writer.print("public class " + containingTypeName + " "); boolean firstIteration = true; List userSpecifiedInterfaces = cfg.implementedInterfaces(containingTypeName); for (String userInterface : userSpecifiedInterfaces) { @@ -911,67 +869,95 @@ public class JavaEmitter implements GlueEmitter { } writer.println("{"); writer.println(); - if (doBaseClass) { - writer.println(" StructAccessor accessor;"); - writer.println(); - } + writer.println(" StructAccessor accessor;"); + writer.println(); + writer.println(" private static final int mdIdx = MachineDescriptionRuntime.getStatic().ordinal();"); + writer.println(); + // generate all offset and size arrays + generateOffsetAndSizeArrays(writer, containingTypeName, structType, null); /* w/o offset */ + for (int i = 0; i < structType.getNumFields(); i++) { + final Field field = structType.getField(i); + final Type fieldType = field.getType(); + + if (!cfg.shouldIgnoreInInterface(name + " " + field.getName())) { + final String renamed = cfg.getJavaSymbolRename(field.getName()); + final String fieldName = renamed==null ? field.getName() : renamed; + if (fieldType.isFunctionPointer()) { + // no offset/size for function pointer .. + } else if (fieldType.isCompound()) { + // FIXME: will need to support this at least in order to + // handle the union in jawt_Win32DrawingSurfaceInfo (fabricate + // a name?) + if (fieldType.getName() == null) { + throw new RuntimeException("Anonymous structs as fields not supported yet (field \"" + + field + "\" in type \"" + name + "\")"); + } + + generateOffsetAndSizeArrays(writer, fieldName, fieldType, field); + } else if (fieldType.isArray()) { + Type baseElementType = field.getType().asArray().getBaseElementType(); + + if(!baseElementType.isPrimitive()) + break; + + generateOffsetAndSizeArrays(writer, fieldName, null, field); /* w/o size */ + } else { + JavaType externalJavaType = null; + try { + externalJavaType = typeToJavaType(fieldType, false, machDescJava); + } catch (Exception e) { + System.err.println("Error occurred while creating accessor for field \"" + + field.getName() + "\" in type \"" + name + "\""); + throw(e); + } + if (externalJavaType.isPrimitive()) { + // Primitive type + generateOffsetAndSizeArrays(writer, fieldName, null, field); /* w/o size */ + } else { + // FIXME + LOG.log(WARNING, "Complicated fields (field \"{0}\" of type \"{1}\") not implemented yet", new Object[]{field, name}); + // throw new RuntimeException("Complicated fields (field \"" + field + "\" of type \"" + t + + // "\") not implemented yet"); + } + } + } + } + writer.println(); writer.println(" public static int size() {"); - if (doBaseClass) { - writer.println(" if (Platform.is32Bit()) {"); - writer.println(" return " + containingTypeName + "32" + ".size();"); - writer.println(" } else {"); - writer.println(" return " + containingTypeName + "64" + ".size();"); - writer.println(" }"); - } else { - writer.println(" return " + structType.getSize(intMachDesc) + ";"); - } + writer.println(" return "+containingTypeName+"_size[mdIdx];"); writer.println(" }"); writer.println(); - if (doBaseClass) { - writer.println(" public static " + containingTypeName + " create() {"); - writer.println(" return create(Buffers.newDirectByteBuffer(size()));"); - writer.println(" }"); - writer.println(); - writer.println(" public static " + containingTypeName + " create(java.nio.ByteBuffer buf) {"); - writer.println(" if (Platform.is32Bit()) {"); - writer.println(" return new " + containingTypeName + "32(buf);"); - writer.println(" } else {"); - writer.println(" return new " + containingTypeName + "64(buf);"); - writer.println(" }"); - writer.println(" }"); - writer.println(); - writer.println(" " + containingTypeName + "(java.nio.ByteBuffer buf) {"); - writer.println(" accessor = new StructAccessor(buf);"); - writer.println(" }"); - writer.println(); - writer.println(" public java.nio.ByteBuffer getBuffer() {"); - writer.println(" return accessor.getBuffer();"); - writer.println(" }"); - } else { - writer.println(" " + containingTypeName + suffix + "(java.nio.ByteBuffer buf) {"); - writer.println(" super(buf);"); - writer.println(" }"); - writer.println(); - } - for (int i = 0; i < structType.getNumFields(); i++) { + writer.println(" public static " + containingTypeName + " create() {"); + writer.println(" return create(Buffers.newDirectByteBuffer(size()));"); + writer.println(" }"); + writer.println(); + writer.println(" public static " + containingTypeName + " create(java.nio.ByteBuffer buf) {"); + writer.println(" return new " + containingTypeName + "(buf);"); + writer.println(" }"); + writer.println(); + writer.println(" " + containingTypeName + "(java.nio.ByteBuffer buf) {"); + writer.println(" accessor = new StructAccessor(buf);"); + writer.println(" }"); + writer.println(); + writer.println(" public java.nio.ByteBuffer getBuffer() {"); + writer.println(" return accessor.getBuffer();"); + writer.println(" }"); - Field field = structType.getField(i); - Type fieldType = field.getType(); + for (int i = 0; i < structType.getNumFields(); i++) { + final Field field = structType.getField(i); + final Type fieldType = field.getType(); if (!cfg.shouldIgnoreInInterface(name + " " + field.getName())) { - - String renamed = cfg.getJavaSymbolRename(field.getName()); - String fieldName = renamed==null ? field.getName() : renamed; + final String renamed = cfg.getJavaSymbolRename(field.getName()); + final String fieldName = renamed==null ? field.getName() : renamed; if (fieldType.isFunctionPointer()) { - - if (doBaseClass) { try { // Emit method call and associated native code FunctionType funcType = fieldType.asPointer().getTargetType().asFunction(); FunctionSymbol funcSym = new FunctionSymbol(fieldName, funcType); - MethodBinding binding = bindFunction(funcSym, containingType, containingCType, machDesc64); + MethodBinding binding = bindFunction(funcSym, containingType, containingCType, machDescJava); binding.findThisPointer(); // FIXME: need to provide option to disable this on per-function basis writer.println(); @@ -1024,14 +1010,13 @@ public class JavaEmitter implements GlueEmitter { false, true, false, // FIXME: should unify this with the general emission code - machDesc64); + machDescJava); prepCEmitter(binding, cEmitter); cEmitter.emit(); } catch (Exception e) { System.err.println("While processing field " + field + " of type " + name + ":"); throw(e); } - } } else if (fieldType.isCompound()) { // FIXME: will need to support this at least in order to // handle the union in jawt_Win32DrawingSurfaceInfo (fabricate @@ -1042,15 +1027,11 @@ public class JavaEmitter implements GlueEmitter { } writer.println(); - generateGetterSignature(writer, doBaseClass, fieldType.getName(), capitalizeString(fieldName)); - if (doBaseClass) { - writer.println(";"); - } else { - writer.println(" {"); - writer.println(" return " + fieldType.getName() + ".create(accessor.slice(" + - field.getOffset(intMachDesc) + ", " + fieldType.getSize(intMachDesc) + "));"); - writer.println(" }"); - } + generateGetterSignature(writer, false, fieldType.getName(), capitalizeString(fieldName)); + writer.println(" {"); + writer.println(" return " + fieldType.getName() + ".create( accessor.slice( " + + fieldName+"_offset[mdIdx], "+fieldName+"_size[mdIdx] ) );"); + writer.println(" }"); } else if (fieldType.isArray()) { @@ -1059,110 +1040,70 @@ public class JavaEmitter implements GlueEmitter { if(!baseElementType.isPrimitive()) break; - String paramType = typeToJavaType(baseElementType, false, extMachDesc).getName(); + String paramType = typeToJavaType(baseElementType, false, machDescJava).getName(); String capitalized = capitalizeString(fieldName); - final int byteOffset = doBaseClass ? -1 : (int) field.getOffset(intMachDesc); - // Setter writer.println(); - generateSetterSignature(writer, doBaseClass, containingTypeName, capitalized, paramType+"[]"); - if (doBaseClass) { - writer.println(";"); - } else { - writer.println(" {"); - writer.print (" accessor.set" + capitalizeString(paramType) + "sAt(" + byteOffset + ", "); - writer.println("val);"); - writer.println(" return this;"); - writer.println(" }"); - } + generateSetterSignature(writer, false, containingTypeName, capitalized, paramType+"[]"); + writer.println(" {"); + writer.print (" accessor.set" + capitalizeString(paramType) + "sAt(" + fieldName+"_offset[mdIdx], val);"); + writer.println(" return this;"); + writer.println(" }"); writer.println(); // Getter - generateGetterSignature(writer, doBaseClass, paramType+"[]", capitalized); - if (doBaseClass) { - writer.println(";"); - } else { - writer.println(" {"); - writer.print (" return "); - writer.println("accessor.get" + capitalizeString(paramType) + "sAt(" + byteOffset + ", new " +paramType+"["+fieldType.asArray().getLength()+"]);"); - writer.println(" }"); - } - + generateGetterSignature(writer, false, paramType+"[]", capitalized); + writer.println(" {"); + writer.print (" return accessor.get" + capitalizeString(paramType) + "sAt(" + fieldName+"_offset[mdIdx], new " +paramType+"["+fieldType.asArray().getLength()+"]);"); + writer.println(" }"); } else { - JavaType internalJavaType = null; - JavaType externalJavaType = null; - + JavaType javaType = null; + try { - externalJavaType = typeToJavaType(fieldType, false, extMachDesc); - if (!doBaseClass) { - internalJavaType = typeToJavaType(fieldType, false, intMachDesc); - } + javaType = typeToJavaType(fieldType, false, machDescJava); } catch (Exception e) { System.err.println("Error occurred while creating accessor for field \"" + field.getName() + "\" in type \"" + name + "\""); throw(e); } - if (externalJavaType.isPrimitive()) { + if (javaType.isPrimitive()) { // Primitive type - String externalJavaTypeName = null; - String internalJavaTypeName = null; - externalJavaTypeName = externalJavaType.getName(); - if (!doBaseClass) { - internalJavaTypeName = internalJavaType.getName(); - } + final boolean fieldTypeNativeSizeFixed = fieldType.getSize().hasFixedNativeSize() || isOpaque(fieldType) ; + String javaTypeName = javaType.getName(); if (isOpaque(fieldType)) { - externalJavaTypeName = compatiblePrimitiveJavaTypeName(fieldType, externalJavaType, extMachDesc); - if (!doBaseClass) { - internalJavaTypeName = compatiblePrimitiveJavaTypeName(fieldType, internalJavaType, intMachDesc); - } - } - String capitalized = null; - if (!doBaseClass) { - capitalized = capitalizeString(internalJavaTypeName); + javaTypeName = compatiblePrimitiveJavaTypeName(fieldType, javaType, machDescJava); } - final int byteOffset = doBaseClass ? -1 : (int) field.getOffset(intMachDesc); + String capJavaTypeName = capitalizeString(javaTypeName); + writer.println(); - String capitalizedFieldName = capitalizeString(fieldName); + String capFieldName = capitalizeString(fieldName); // Setter - generateSetterSignature(writer, doBaseClass, containingTypeName, capitalizedFieldName, externalJavaTypeName); - if (doBaseClass) { - writer.println(";"); + generateSetterSignature(writer, false, containingTypeName, capFieldName, javaTypeName); + writer.println(" {"); + if( fieldTypeNativeSizeFixed ) { + writer.println(" accessor.set" + capJavaTypeName + "At(" + fieldName+"_offset[mdIdx], val);"); } else { - writer.println(" {"); - writer.print (" accessor.set" + capitalized + "At(" + byteOffset + ", "); - if (!externalJavaTypeName.equals(internalJavaTypeName)) { - writer.print("(" + internalJavaTypeName + ") "); - } - writer.println("val);"); - writer.println(" return this;"); - writer.println(" }"); + writer.println(" accessor.set" + capJavaTypeName + "At(" + fieldName+"_offset[mdIdx], val, MachineDescriptionRuntime.getStatic().md."+javaTypeName+"SizeInBytes());"); } + writer.println(" return this;"); + writer.println(" }"); writer.println(); + // Getter - generateGetterSignature(writer, doBaseClass, externalJavaTypeName, capitalizedFieldName); - if (doBaseClass) { - writer.println(";"); + generateGetterSignature(writer, false, javaTypeName, capFieldName); + writer.println(" {"); + writer.print (" return "); + if( fieldTypeNativeSizeFixed ) { + writer.println("accessor.get" + capJavaTypeName + "At(" + fieldName+"_offset[mdIdx]);"); } else { - writer.println(" {"); - writer.print (" return "); - if (!externalJavaTypeName.equals(internalJavaTypeName)) { - writer.print("(" + externalJavaTypeName + ") "); - } - writer.println("accessor.get" + capitalized + "At(" + byteOffset + ");"); - writer.println(" }"); - } - } else { - // FIXME - LOG.log(WARNING, "Complicated fields (field \"{0}\" of type \"{1}\") not implemented yet", new Object[]{field, name}); - // throw new RuntimeException("Complicated fields (field \"" + field + "\" of type \"" + t + - // "\") not implemented yet"); + writer.println("accessor.get" + capJavaTypeName + "At(" + fieldName+"_offset[mdIdx], MachineDescriptionRuntime.getStatic().md."+javaTypeName+"SizeInBytes());"); + } + writer.println(" }"); } } } } - if (doBaseClass) { - emitCustomJavaCode(writer, containingTypeName); - } + emitCustomJavaCode(writer, containingTypeName); writer.println("}"); writer.flush(); writer.close(); @@ -1201,14 +1142,39 @@ public class JavaEmitter implements GlueEmitter { // Internals only below this point // - private void generateGetterSignature(PrintWriter writer, boolean baseClass, String returnTypeName, String capitalizedFieldName) { - writer.print(" public " + (baseClass ? "abstract " : "") + returnTypeName + " get" + capitalizedFieldName + "()"); - } + private void generateGetterSignature(PrintWriter writer, boolean abstractMethod, String returnTypeName, String capitalizedFieldName) { + writer.print(" public " + (abstractMethod ? "abstract " : "") + returnTypeName + " get" + capitalizedFieldName + "()"); + } - private void generateSetterSignature(PrintWriter writer, boolean baseClass, String returnTypeName, String capitalizedFieldName, String paramTypeName) { - writer.print(" public " + (baseClass ? "abstract " : "") + returnTypeName + " set" + capitalizedFieldName + "(" + paramTypeName + " val)"); - } + private void generateSetterSignature(PrintWriter writer, boolean abstractMethod, String returnTypeName, String capitalizedFieldName, String paramTypeName) { + writer.print(" public " + (abstractMethod ? "abstract " : "") + returnTypeName + " set" + capitalizedFieldName + "(" + paramTypeName + " val)"); + } + private void generateOffsetAndSizeArrays(PrintWriter writer, String fieldName, Type fieldType, Field field) { + if(null != field) { + writer.print(" private static final int[] "+fieldName+"_offset = new int[] { "); + for( int i=0; i < machDescTargetConfigs.length; i++ ) { + if(0 #include +#define DEBUG 1 + MYAPI foo MYAPIENTRY nopTest() { return 42; } @@ -279,6 +281,40 @@ MYAPI void MYAPIENTRY destroySurface(TK_Surface * surface) { free(surface); } +static void dumpTK_ComplicatedSuperSet(TK_ComplicatedSuperSet * s) { + fprintf(stderr, "TK_ComplicatedSuperSet [\n"); + fprintf(stderr, " cs.b1 0x%X\n", s->bits1); + + fprintf(stderr, " cs.sub1.b1 0x%X\n", s->sub1.bits1); + fprintf(stderr, " cs.sub1.id 0x%X\n", s->sub1.id); + fprintf(stderr, " cs.sub1.b2 0x%X\n", s->sub1.bits2); + fprintf(stderr, " cs.sub1.long0 0x%lX\n", s->sub1.long0); + fprintf(stderr, " cs.sub1.b3 0x%X\n", s->sub1.bits3); + fprintf(stderr, " cs.sub1.real0 %G %A\n", s->sub1.real0, s->sub1.real0); + fprintf(stderr, " cs.sub1.b4 0x%X\n", s->sub1.bits4); + fprintf(stderr, " cs.sub1.real1 %G %A\n", (double)s->sub1.real1, (double)s->sub1.real1); + fprintf(stderr, " cs.sub1.b5 0x%X\n", s->sub1.bits5); + fprintf(stderr, " cs.sub1.longX 0x%lX\n", (int64_t)s->sub1.longX); + fprintf(stderr, " cs.sub1.b6 0x%X\n", s->sub1.bits6); + + fprintf(stderr, " cs.b2 0x%X\n", s->bits2); + + fprintf(stderr, " cs.sub2.b1 0x%X\n", s->sub2.bits1); + fprintf(stderr, " cs.sub2.id 0x%X\n", s->sub2.id); + fprintf(stderr, " cs.sub2.b2 0x%X\n", s->sub2.bits2); + fprintf(stderr, " cs.sub2.long0 0x%lX\n", s->sub2.long0); + fprintf(stderr, " cs.sub2.b3 0x%X\n", s->sub2.bits3); + fprintf(stderr, " cs.sub2.real0 %G %A\n", s->sub2.real0, s->sub2.real0); + fprintf(stderr, " cs.sub2.b4 0x%X\n", s->sub2.bits4); + fprintf(stderr, " cs.sub2.real1 %G %A\n", (double)s->sub2.real1, (double)s->sub2.real1); + fprintf(stderr, " cs.sub2.b5 0x%X\n", s->sub2.bits5); + fprintf(stderr, " cs.sub2.longX 0x%lX\n", (int64_t)s->sub2.longX); + fprintf(stderr, " cs.sub2.b6 0x%X\n", s->sub2.bits6); + + fprintf(stderr, " cs.b3 0x%X\n", s->bits3); + fprintf(stderr, "]\n\n"); +} + MYAPI TK_ComplicatedSuperSet * MYAPIENTRY createComplicatedSuperSet() { TK_ComplicatedSuperSet * s = calloc(1, sizeof(TK_ComplicatedSuperSet)); @@ -288,16 +324,24 @@ MYAPI TK_ComplicatedSuperSet * MYAPIENTRY createComplicatedSuperSet() { s->sub1.bits2 = 0xA2U; s->sub1.long0 = 0x123456789abcdef0UL; s->sub1.bits3 = 0xA3U; - s->sub1.real0 = 3.1415926535897932384626433832795L; + s->sub1.real0 = 3.1415926535897932384626433832795; s->sub1.bits4 = 0xA4U; + s->sub1.real1 = 256.12345f; + s->sub1.bits5 = 0xA5U; + s->sub1.longX = (long) 0xdeadbeefU; + s->sub1.bits6 = 0xA6U; s->bits2 = 0xB0U; s->sub2.bits1 = 0xB1U; s->sub2.id = 0x12345678U; s->sub2.bits2 = 0xB2U; s->sub2.long0 = 0x123456789abcdef0UL; s->sub2.bits3 = 0xB3U; - s->sub2.real0 = 3.1415926535897932384626433832795L; + s->sub2.real0 = 3.1415926535897932384626433832795; s->sub2.bits4 = 0xB4U; + s->sub2.real1 = 256.12345f; + s->sub2.bits5 = 0xB5U; + s->sub2.longX = (long) 0xdeadbeefU; + s->sub2.bits6 = 0xB6U; s->bits3 = 0xC0U; fprintf(stderr, "TK_ComplicatedSubSet: sizeof(): %ld\n", (long) sizeof(TK_ComplicatedSubSet)); @@ -308,6 +352,10 @@ MYAPI TK_ComplicatedSuperSet * MYAPIENTRY createComplicatedSuperSet() { fprintf(stderr, "TK_ComplicatedSubSet: bits3-s offset: %ld\n", (long) ((void *)(&s->sub1.bits3) - (void *)(&s->sub1)) ); fprintf(stderr, "TK_ComplicatedSubSet: real0-s offset: %ld\n", (long) ((void *)(&s->sub1.real0) - (void *)(&s->sub1)) ); fprintf(stderr, "TK_ComplicatedSubSet: bits4-s offset: %ld\n", (long) ((void *)(&s->sub1.bits4) - (void *)(&s->sub1)) ); + fprintf(stderr, "TK_ComplicatedSubSet: real1-s offset: %ld\n", (long) ((void *)(&s->sub1.real1) - (void *)(&s->sub1)) ); + fprintf(stderr, "TK_ComplicatedSubSet: bits5-s offset: %ld\n", (long) ((void *)(&s->sub1.bits5) - (void *)(&s->sub1)) ); + fprintf(stderr, "TK_ComplicatedSubSet: longX-s offset: %ld\n", (long) ((void *)(&s->sub1.longX) - (void *)(&s->sub1)) ); + fprintf(stderr, "TK_ComplicatedSubSet: bits6-s offset: %ld\n", (long) ((void *)(&s->sub1.bits6) - (void *)(&s->sub1)) ); fprintf(stderr, "TK_ComplicatedSuperSet: sizeof(): %ld\n", (long) sizeof(TK_ComplicatedSuperSet)); fprintf(stderr, "TK_ComplicatedSuperSet: bits1-s offset: %ld\n", (long) ((void *)(&s->bits1) - (void *)(s)) ); @@ -316,9 +364,46 @@ MYAPI TK_ComplicatedSuperSet * MYAPIENTRY createComplicatedSuperSet() { fprintf(stderr, "TK_ComplicatedSuperSet: sub2-s offset: %ld\n", (long) ((void *)(&s->sub2) - (void *)(s)) ); fprintf(stderr, "TK_ComplicatedSuperSet: bits3-s offset: %ld\n", (long) ((void *)(&s->bits3) - (void *)(s)) ); + #ifdef DEBUG + fprintf(stderr, "createComplicatedSuperSet:\n"); + dumpTK_ComplicatedSuperSet(s); + #endif return s; } +MYAPI Bool MYAPIENTRY hasInitValues(TK_ComplicatedSuperSet * s) { + Bool b = s->bits1 == 0xA0U && + s->sub1.bits1 == 0xA1U && + s->sub1.id == 0x12345678U && + s->sub1.bits2 == 0xA2U && + s->sub1.long0 == 0x123456789abcdef0UL && + s->sub1.bits3 == 0xA3U && + s->sub1.real0 == 3.1415926535897932384626433832795 && + s->sub1.bits4 == 0xA4U && + s->sub1.real1 == 256.12345f && + s->sub1.bits5 == 0xA5U && + s->sub1.longX == (long) 0xdeadbeefU && + s->sub1.bits6 == 0xA6U && + s->bits2 == 0xB0U && + s->sub2.bits1 == 0xB1U && + s->sub2.id == 0x12345678U && + s->sub2.bits2 == 0xB2U && + s->sub2.long0 == 0x123456789abcdef0UL && + s->sub2.bits3 == 0xB3U && + s->sub2.real0 == 3.1415926535897932384626433832795 && + s->sub2.bits4 == 0xB4U && + s->sub2.real1 == 256.12345f && + s->sub2.bits5 == 0xB5U && + s->sub2.longX == (long) 0xdeadbeefU && + s->sub2.bits6 == 0xB6U && + s->bits3 == 0xC0U ; + #ifdef DEBUG + fprintf(stderr, "hasInitValues res %d:\n", b); + dumpTK_ComplicatedSuperSet(s); + #endif + return b; +} + MYAPI void MYAPIENTRY destroyComplicatedSuperSet(TK_ComplicatedSuperSet * s) { free(s); } diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/test1.h b/src/junit/com/jogamp/gluegen/test/junit/generation/test1.h index 041a8d2..3e20307 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/generation/test1.h +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test1.h @@ -26,6 +26,7 @@ #include #include +typedef int Bool; typedef uint64_t foo; /** Returns 42 */ @@ -150,16 +151,23 @@ typedef struct tk_Surface { } TK_Surface; typedef struct { - int8_t bits1; // +1 + uint8_t bits1; // +1 // +3 (p64) int32_t id; // +4 - int8_t bits2; // +1 + uint8_t bits2; // +1 // +7 (p64) int64_t long0; // +8 - int8_t bits3; // +1 + uint8_t bits3; // +1 // +7 (p64) double real0; // +8 - int8_t bits4; // +1 + uint8_t bits4; // +1 + // +3 (p64) + float real1; // +4 + uint8_t bits5; // +1 + // +7 (p64) / +3 (windows andx 32bit) + long longX; // +8 / +4 (windows andx 32bit) + uint8_t bits6; // +1 + // +7 (p64) (for next struct ..) // 24 net @@ -168,13 +176,13 @@ typedef struct { } TK_ComplicatedSubSet; typedef struct { - int8_t bits1; // + 1 + uint8_t bits1; // + 1 // + 7 (p64) TK_ComplicatedSubSet sub1; // +48 (64bit) - int8_t bits2; // + 1 + uint8_t bits2; // + 1 // + 7 (p64) TK_ComplicatedSubSet sub2; // +48 (64bit) - int8_t bits3; // + 1 + uint8_t bits3; // + 1 // + 7 (p64) // 51 net @@ -186,4 +194,5 @@ MYAPI TK_Surface * MYAPIENTRY createSurface(); MYAPI void MYAPIENTRY destroySurface(TK_Surface * surface); MYAPI TK_ComplicatedSuperSet * MYAPIENTRY createComplicatedSuperSet(); +MYAPI Bool MYAPIENTRY hasInitValues(TK_ComplicatedSuperSet * s); MYAPI void MYAPIENTRY destroyComplicatedSuperSet(TK_ComplicatedSuperSet * s); -- cgit v1.2.3