diff options
author | Sven Gothel <[email protected]> | 2011-07-17 16:34:39 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-07-17 16:34:39 +0200 |
commit | f733203dfbd034a6b1aa3eb2cd616437c982c435 (patch) | |
tree | 4ace71d4b129870b02f962b714c9dce9f83bc294 /src/java/com/jogamp/gluegen | |
parent | ad3dc39ccfddb007c3e91acf454f804573969419 (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')
17 files changed, 153 insertions, 223 deletions
diff --git a/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java b/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java index ba2eb17..d47cded 100644 --- a/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java +++ b/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java @@ -43,6 +43,7 @@ import java.util.*; import java.io.*; import java.text.MessageFormat; +import com.jogamp.common.os.MachineDescription; import com.jogamp.gluegen.cgram.types.*; import java.util.logging.Logger; diff --git a/src/java/com/jogamp/gluegen/DebugEmitter.java b/src/java/com/jogamp/gluegen/DebugEmitter.java index 22cc0c5..fc536c8 100644 --- a/src/java/com/jogamp/gluegen/DebugEmitter.java +++ b/src/java/com/jogamp/gluegen/DebugEmitter.java @@ -41,6 +41,7 @@ package com.jogamp.gluegen; import java.util.*; +import com.jogamp.common.os.MachineDescription; import com.jogamp.gluegen.cgram.types.*; /** Debug emitter which prints the parsing results to standard output. */ diff --git a/src/java/com/jogamp/gluegen/GlueEmitter.java b/src/java/com/jogamp/gluegen/GlueEmitter.java index 5f627f9..ed06b19 100644 --- a/src/java/com/jogamp/gluegen/GlueEmitter.java +++ b/src/java/com/jogamp/gluegen/GlueEmitter.java @@ -40,6 +40,8 @@ package com.jogamp.gluegen; import java.util.*; + +import com.jogamp.common.os.MachineDescription; import com.jogamp.gluegen.cgram.types.*; /** Specifies the interface by which GlueGen requests glue code to be diff --git a/src/java/com/jogamp/gluegen/GlueGen.java b/src/java/com/jogamp/gluegen/GlueGen.java index 286aac4..c898058 100644 --- a/src/java/com/jogamp/gluegen/GlueGen.java +++ b/src/java/com/jogamp/gluegen/GlueGen.java @@ -40,9 +40,14 @@ package com.jogamp.gluegen; import com.jogamp.common.GlueGenVersion; +import com.jogamp.common.os.MachineDescription; + import java.io.*; import java.util.*; +import jogamp.common.os.MachineDescription32Bit; +import jogamp.common.os.MachineDescription64Bit; + import antlr.*; import com.jogamp.gluegen.cgram.*; import com.jogamp.gluegen.cgram.types.*; diff --git a/src/java/com/jogamp/gluegen/JavaEmitter.java b/src/java/com/jogamp/gluegen/JavaEmitter.java index 745176a..d92e589 100644 --- a/src/java/com/jogamp/gluegen/JavaEmitter.java +++ b/src/java/com/jogamp/gluegen/JavaEmitter.java @@ -42,6 +42,8 @@ package com.jogamp.gluegen; import com.jogamp.common.nio.Buffers; import com.jogamp.common.os.DynamicLookupHelper; +import com.jogamp.common.os.MachineDescription; + import java.io.*; import java.util.*; import java.text.MessageFormat; 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 + ")"); } } } diff --git a/src/java/com/jogamp/gluegen/cgram/GnuCParser.g b/src/java/com/jogamp/gluegen/cgram/GnuCParser.g index 58d3171..e8ca8c5 100644 --- a/src/java/com/jogamp/gluegen/cgram/GnuCParser.g +++ b/src/java/com/jogamp/gluegen/cgram/GnuCParser.g @@ -313,6 +313,10 @@ typeSpecifier [int specCount] returns [int retSpecCount] | "double" | "signed" | "unsigned" + | "int8_t" + | "uint8_t" + | "int16_t" + | "uint16_t" | "__int32" | "int32_t" | "wchar_t" diff --git a/src/java/com/jogamp/gluegen/cgram/GnuCTreeParser.g b/src/java/com/jogamp/gluegen/cgram/GnuCTreeParser.g index 1beeb7d..dbe2f98 100644 --- a/src/java/com/jogamp/gluegen/cgram/GnuCTreeParser.g +++ b/src/java/com/jogamp/gluegen/cgram/GnuCTreeParser.g @@ -183,6 +183,10 @@ typeSpecifier | "double" | "signed" | "unsigned" + | "int8_t" + | "uint8_t" + | "int16_t" + | "uint16_t" | "__int32" | "int32_t" | "wchar_t" diff --git a/src/java/com/jogamp/gluegen/cgram/HeaderParser.g b/src/java/com/jogamp/gluegen/cgram/HeaderParser.g index a0d2a83..79f966f 100644 --- a/src/java/com/jogamp/gluegen/cgram/HeaderParser.g +++ b/src/java/com/jogamp/gluegen/cgram/HeaderParser.g @@ -504,11 +504,15 @@ typeSpecifier[int attributes] returns [Type t] { | "long" { t = new IntType("long" , SizeThunk.LONG, unsigned, cvAttrs); } | "float" { t = new FloatType("float", SizeThunk.FLOAT, cvAttrs); } | "double" { t = new DoubleType("double", SizeThunk.DOUBLE, cvAttrs); } - | "__int32" { t = new IntType("__int32", SizeThunk.INT, unsigned, cvAttrs); } - | "int32_t" { t = new IntType("int32_t", SizeThunk.INT, false, cvAttrs); /* TS: always signed */ } - | "wchar_t" { t = new IntType("wchar_t", SizeThunk.INT, false, cvAttrs); /* TS: always signed */ } - | "uint32_t" { t = new IntType("uint32_t", SizeThunk.INT, true, cvAttrs, true); /* TS: always unsigned */ } + | "__int32" { t = new IntType("__int32", SizeThunk.INT32, unsigned, cvAttrs); } | "__int64" { t = new IntType("__int64", SizeThunk.INT64, unsigned, cvAttrs); } + | "int8_t" { t = new IntType("int8_t", SizeThunk.INT8, false, cvAttrs); /* TS: always signed */ } + | "uint8_t" { t = new IntType("uint8_t", SizeThunk.INT8, true, cvAttrs); /* TS: always unsigned */ } + | "int16_t" { t = new IntType("int16_t", SizeThunk.INT16, false, cvAttrs); /* TS: always signed */ } + | "uint16_t" { t = new IntType("uint16_t", SizeThunk.INT16, true, cvAttrs); /* TS: always unsigned */ } + | "int32_t" { t = new IntType("int32_t", SizeThunk.INT32, false, cvAttrs); /* TS: always signed */ } + | "wchar_t" { t = new IntType("wchar_t", SizeThunk.INT32, false, cvAttrs); /* TS: always signed */ } + | "uint32_t" { t = new IntType("uint32_t", SizeThunk.INT32, true, cvAttrs, true); /* TS: always unsigned */ } | "int64_t" { t = new IntType("int64_t", SizeThunk.INT64, false, cvAttrs); /* TS: always signed */ } | "uint64_t" { t = new IntType("uint64_t", SizeThunk.INT64, true, cvAttrs, true); /* TS: always unsigned */ } | "ptrdiff_t" { t = new IntType("ptrdiff_t", SizeThunk.POINTER, false, cvAttrs); /* TS: always signed */ } diff --git a/src/java/com/jogamp/gluegen/cgram/StdCParser.g b/src/java/com/jogamp/gluegen/cgram/StdCParser.g index 231e371..7b34656 100644 --- a/src/java/com/jogamp/gluegen/cgram/StdCParser.g +++ b/src/java/com/jogamp/gluegen/cgram/StdCParser.g @@ -265,6 +265,10 @@ typeSpecifier [int specCount] returns [int retSpecCount] | "double" | "signed" | "unsigned" + | "int8_t" + | "uint8_t" + | "int16_t" + | "uint16_t" | "__int32" | "int32_t" | "wchar_t" diff --git a/src/java/com/jogamp/gluegen/cgram/types/Field.java b/src/java/com/jogamp/gluegen/cgram/types/Field.java index 07d90ea..2479e3d 100644 --- a/src/java/com/jogamp/gluegen/cgram/types/Field.java +++ b/src/java/com/jogamp/gluegen/cgram/types/Field.java @@ -39,6 +39,8 @@ package com.jogamp.gluegen.cgram.types; +import com.jogamp.common.os.MachineDescription; + /** Represents a field in a struct or union. */ public class Field { diff --git a/src/java/com/jogamp/gluegen/cgram/types/MachineDescription.java b/src/java/com/jogamp/gluegen/cgram/types/MachineDescription.java deleted file mode 100644 index d2598e0..0000000 --- a/src/java/com/jogamp/gluegen/cgram/types/MachineDescription.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -package com.jogamp.gluegen.cgram.types; - -public class MachineDescription { - private int charSizeInBytes; - private int shortSizeInBytes; - private int intSizeInBytes; - private int longSizeInBytes; - private int int64SizeInBytes; - private int floatSizeInBytes; - private int doubleSizeInBytes; - private int pointerSizeInBytes; - private int structAlignmentInBytes; - - public MachineDescription(int charSizeInBytes, - int shortSizeInBytes, - int intSizeInBytes, - int longSizeInBytes, - int int64SizeInBytes, - int floatSizeInBytes, - int doubleSizeInBytes, - int pointerSizeInBytes, - int structAlignmentInBytes) { - this.charSizeInBytes = charSizeInBytes; - this.shortSizeInBytes = shortSizeInBytes; - this.intSizeInBytes = intSizeInBytes; - this.longSizeInBytes = longSizeInBytes; - this.int64SizeInBytes = int64SizeInBytes; - this.floatSizeInBytes = floatSizeInBytes; - this.doubleSizeInBytes = doubleSizeInBytes; - this.pointerSizeInBytes = pointerSizeInBytes; - this.structAlignmentInBytes = structAlignmentInBytes; - } - - public int charSizeInBytes() { return charSizeInBytes; } - public int shortSizeInBytes() { return shortSizeInBytes; } - public int intSizeInBytes() { return intSizeInBytes; } - public int longSizeInBytes() { return longSizeInBytes; } - public int int64SizeInBytes() { return int64SizeInBytes; } - public int floatSizeInBytes() { return floatSizeInBytes; } - public int doubleSizeInBytes() { return doubleSizeInBytes; } - public int pointerSizeInBytes() { return pointerSizeInBytes; } - public int structAlignmentInBytes() { return structAlignmentInBytes; } -} diff --git a/src/java/com/jogamp/gluegen/cgram/types/MachineDescription32Bit.java b/src/java/com/jogamp/gluegen/cgram/types/MachineDescription32Bit.java deleted file mode 100644 index 6bbb801..0000000 --- a/src/java/com/jogamp/gluegen/cgram/types/MachineDescription32Bit.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -package com.jogamp.gluegen.cgram.types; - -public class MachineDescription32Bit extends MachineDescription { - public MachineDescription32Bit() { - super(1, 2, 4, 4, 8, 4, 8, 4, 8); - } -} diff --git a/src/java/com/jogamp/gluegen/cgram/types/MachineDescription64Bit.java b/src/java/com/jogamp/gluegen/cgram/types/MachineDescription64Bit.java deleted file mode 100644 index 38328e4..0000000 --- a/src/java/com/jogamp/gluegen/cgram/types/MachineDescription64Bit.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -package com.jogamp.gluegen.cgram.types; - -public class MachineDescription64Bit extends MachineDescription { - public MachineDescription64Bit() { - super(1, 2, 4, 8, 8, 4, 8, 8, 16); - } -} diff --git a/src/java/com/jogamp/gluegen/cgram/types/SizeThunk.java b/src/java/com/jogamp/gluegen/cgram/types/SizeThunk.java index 40ddd57..1584a13 100755 --- a/src/java/com/jogamp/gluegen/cgram/types/SizeThunk.java +++ b/src/java/com/jogamp/gluegen/cgram/types/SizeThunk.java @@ -40,6 +40,8 @@ package com.jogamp.gluegen.cgram.types; +import com.jogamp.common.os.MachineDescription; + /** Provides a level of indirection between the definition of a type's size and the absolute value of this size. Necessary when generating glue code for two different CPU architectures (e.g., @@ -84,6 +86,24 @@ public abstract class SizeThunk implements Cloneable { } }; + public static final SizeThunk INT8 = new SizeThunk() { + public long compute(MachineDescription machDesc) { + return machDesc.int8SizeInBytes(); + } + }; + + public static final SizeThunk INT16 = new SizeThunk() { + public long compute(MachineDescription machDesc) { + return machDesc.int16SizeInBytes(); + } + }; + + public static final SizeThunk INT32 = new SizeThunk() { + public long compute(MachineDescription machDesc) { + return machDesc.int32SizeInBytes(); + } + }; + public static final SizeThunk INT64 = new SizeThunk() { public long compute(MachineDescription machDesc) { return machDesc.int64SizeInBytes(); diff --git a/src/java/com/jogamp/gluegen/cgram/types/Type.java b/src/java/com/jogamp/gluegen/cgram/types/Type.java index c58bfae..95afc2c 100644 --- a/src/java/com/jogamp/gluegen/cgram/types/Type.java +++ b/src/java/com/jogamp/gluegen/cgram/types/Type.java @@ -42,6 +42,8 @@ package com.jogamp.gluegen.cgram.types; import java.util.List; +import com.jogamp.common.os.MachineDescription; + /** Models a C type. Primitive types include int, float, and double. All types have an associated name. Structs and unions are modeled as "compound" types -- composed of fields of primitive or diff --git a/src/java/com/jogamp/gluegen/package.html b/src/java/com/jogamp/gluegen/package.html index 2862fe6..f8a2e6d 100644 --- a/src/java/com/jogamp/gluegen/package.html +++ b/src/java/com/jogamp/gluegen/package.html @@ -9,32 +9,80 @@ Gluegen has build-in types (terminal symbols) for:<br/> <br/> <table border="1"> - <tr><th>type</th> <th>java bits</th> <th>native-x32 bits</th><th>native-x64 bits</th><th>type</th> <th>signed</th> <th>origin</th</tr> - <tr><th>void</th> <th> 0</th> <th> 0</th> <th> 0</th> <th>void</th> <th>void</th> <th>ANSI-C</th></tr> - <tr><th>char</th> <th> 8</th> <th> 8</th> <th> 8</th> <th>integer</th><th>signed or unsigned</th><th>ANSI-C</th></tr> - <tr><th>short</th> <th>16</th> <th>16</th> <th>16</th> <th>integer</th><th>signed or unsigned</th><th>ANSI-C</th></tr> - <tr><th>int</th> <th>32</th> <th>32</th> <th>32</th> <th>integer</th><th>signed or unsigned</th><th>ANSI-C</th></tr> - <tr><th>long</th> <th>64</th> <th>32</th> <th>32<sup>1</sup></th> <th>integer</th><th>signed or unsigned</th><th>Windows</th></tr> - <tr><th>long</th> <th>64</th> <th>32</th> <th>64</th> <th>integer</th><th>signed or unsigned</th><th>Unix</th></tr> - <tr><th>float</th> <th>32</th> <th>32</th> <th>32</th> <th>float</th> <th>signed</th> <th>ANSI-C</th></tr> - <tr><th>double</th> <th>64</th> <th>64</th> <th>64</th> <th>double</th> <th>signed</th> <th>ANSI-C</th></tr> - <tr><th>__int32</th> <th>32</th> <th>32</th> <th>32</th> <th>integer</th><th>signed or unsigned</th><th>windows</th></tr> - <tr><th>int32_t</th> <th>32</th> <th>32</th> <th>32</th> <th>integer</th><th>signed</th> <th>stdint.h</th></tr> - <tr><th>wchar_t</th> <th>32</th> <th>32</th> <th>32</th> <th>integer</th><th>signed</th> <th>stddef.h</th></tr> - <tr><th>uint32_t</th> <th>32</th> <th>32</th> <th>32</th> <th>integer</th><th>unsigned</th> <th>stdint.h</th></tr> - <tr><th>__int64</th> <th>64</th> <th>64</th> <th>64</th> <th>integer</th><th>signed or unsigned</th><th>windows</th></tr> - <tr><th>int64_t</th> <th>64</th> <th>64</th> <th>64</th> <th>integer</th><th>signed</th> <th>stdint.h</th></tr> - <tr><th>uint64_t</th> <th>64</th> <th>64</th> <th>64</th> <th>integer</th><th>unsigned</th> <th>stdint.h</th></tr> - <tr><th>ptrdiff_t</th> <th>64</th> <th>32</th> <th>64</th> <th>integer</th><th>signed</th> <th>stddef.h</th></tr> - <tr><th>intptr_t</th> <th>64</th> <th>32</th> <th>64</th> <th>integer</th><th>signed</th> <th>stdint.h</th></tr> - <tr><th>size_t</th> <th>64</th> <th>32</th> <th>64</th> <th>integer</th><th>unsigned</th> <th>stddef.h</th></tr> - <tr><th>uintptr_t</th> <th>64</th> <th>32</th> <th>64</th> <th>integer</th><th>unsigned</th> <th>stdint.h</th></tr> + <tr><th>type</th> <th>java bits</th> <th colspan="2">native bits</th> <th>type</th> <th>signed</th> <th>origin</th></tr> + <tr><th></th> <th></th> <th>x32</th> <th>x64</th> <th></th> <th></th> <th></th></tr> + <tr><td>void</td> <td> 0</td> <td> 0</td> <td> 0</td> <td>void</td> <td>void</td> <td>ANSI-C</td></tr> + <tr><td>char</td> <td> 8</td> <td> 8</td> <td> 8</td> <td>integer</td><td>any</td> <td>ANSI-C</td></tr> + <tr><td>short</td> <td>16</td> <td>16</td> <td>16</td> <td>integer</td><td>any</td> <td>ANSI-C</td></tr> + <tr><td>int</td> <td>32</td> <td>32</td> <td>32</td> <td>integer</td><td>any</td> <td>ANSI-C</td></tr> + <tr><td>long</td> <td>64</td> <td>32</td> <td><b>32<sup>1</sup></b></td> <td>integer</td><td>any</td> <td>ANSI-C - Windows</td></tr> + <tr><td>long</td> <td>64</td> <td>32</td> <td><b>64</b></td> <td>integer</td><td>any</td> <td>ANSI-C - Unix</td></tr> + <tr><td>float</td> <td>32</td> <td>32</td> <td>32</td> <td>float</td> <td>signed</td> <td>ANSI-C</td></tr> + <tr><td>double</td> <td>64</td> <td>64</td> <td>64</td> <td>double</td> <td>signed</td> <td>ANSI-C</td></tr> + <tr><td>__int32</td> <td>32</td> <td>32</td> <td>32</td> <td>integer</td><td>any</td> <td>windows</td></tr> + <tr><td>__int64</td> <td>64</td> <td>64</td> <td>64</td> <td>integer</td><td>any</td> <td>windows</td></tr> + <tr><td>int8_t</td> <td> 8</td> <td> 8</td> <td> 8</td> <td>integer</td><td>signed</td> <td>stdint.h</td></tr> + <tr><td>uint8_t</td> <td> 8</td> <td> 8</td> <td> 8</td> <td>integer</td><td>unsigned</td> <td>stdint.h</td></tr> + <tr><td>int16_t</td> <td>16</td> <td>16</td> <td>16</td> <td>integer</td><td>signed</td> <td>stdint.h</td></tr> + <tr><td>uint16_t</td> <td>16</td> <td>16</td> <td>16</td> <td>integer</td><td>unsigned</td> <td>stdint.h</td></tr> + <tr><td>int32_t</td> <td>32</td> <td>32</td> <td>32</td> <td>integer</td><td>signed</td> <td>stdint.h</td></tr> + <tr><td>uint32_t</td> <td>32</td> <td>32</td> <td>32</td> <td>integer</td><td>unsigned</td> <td>stdint.h</td></tr> + <tr><td>int64_t</td> <td>64</td> <td>64</td> <td>64</td> <td>integer</td><td>signed</td> <td>stdint.h</td></tr> + <tr><td>uint64_t</td> <td>64</td> <td>64</td> <td>64</td> <td>integer</td><td>unsigned</td> <td>stdint.h</td></tr> + <tr><td>intptr_t</td> <td>64</td> <td>32</td> <td>64</td> <td>integer</td><td>signed</td> <td>stdint.h</td></tr> + <tr><td>uintptr_t</td> <td>64</td> <td>32</td> <td>64</td> <td>integer</td><td>unsigned</td> <td>stdint.h</td></tr> + <tr><td>ptrdiff_t</td> <td>64</td> <td>32</td> <td>64</td> <td>integer</td><td>signed</td> <td>stddef.h</td></tr> + <tr><td>size_t</td> <td>64</td> <td>32</td> <td>64</td> <td>integer</td><td>unsigned</td> <td>stddef.h</td></tr> + <tr><td>wchar_t</td> <td>32</td> <td>32</td> <td>32</td> <td>integer</td><td>signed</td> <td>stddef.h</td></tr> </table> <p> <b>Warning:</b> Try to avoid unspecified bit sized types, especially <b>long</b>, since it differs on Unix and Windows!<br/> <b>Note 1:</b> Type <b>long</b> will result in broken code on Windows, since we don't differentiate the OS and it's bit size is ambiguous. </p> - <p> + + <h4>GlueGen Internal Alignment for Compound Data</h4> + In general, depending on CPU and it's configuration (OS), alignment is set up + for each type (char, short, int, long, ..),<br> + where structures are aligned naturally, i.e. their inner components are aligned.<br> + See:<br> + <ul> + <li><a href="http://en.wikipedia.org/wiki/Data_structure_alignment">Wikipedia Data Structure Alignment</a></li> + <li><a href="http://en.wikipedia.org/wiki/Data_structure_alignment#Data_structure_padding">Wikipedia Data Structure Alignment - Padding</a></li> + <li><a href="http://www.viva64.com/en/l/0021/">Viva64 Data Alignment</a></li> + <li><a href="http://developer.apple.com/library/mac/#documentation/Darwin/Conceptual/64bitPorting/transition/transition.html#//apple_ref/doc/uid/TP40001064-CH207-SW1">Apple: Darwin 64bit Porting - Data Type Size & Alignment</a></li> + </ul> + + <h5>Type Size & Alignment for x86, x86_64, armv7l-32bit-eabi and Window(mingw/mingw64)</h5> + Runtime query is implemented as follows: + <pre> + typedef struct { + _TYPE_ s0; // ensures start address alignment + char fill; // nibble one byte + // padding to align s1 + _TYPE_ s1; // + } type_t; + + padding = sizeof(type_t) - 2 * sizeof(_TYPE_) - sizeof(char); + alignment = sizeof(type_t) - 2 * sizeof(_TYPE_) ; + </pre> + <table border="1"> + <tr><th>type</th> <th colspan="2">32 bits</th><th colspan="2">64 bits</th></tr> + <tr><th></th> <th>size</th><th>alignment</th><th>size</th><th>alignment</th></tr> + <tr><td>char</td> <td> 1</td> <td> 1</td> <td> 1</td> <td> 1</td></tr> + <tr><td>short</td> <td> 2</td> <td> 2</td> <td> 2</td> <td> 2</td></tr> + <tr><td>int</td> <td> 4</td> <td> 4</td> <td> 4</td> <td> 4</td></tr> + <tr><td>float</td> <td> 4</td> <td> 4</td> <td> 4</td> <td> 4</td></tr> + <tr><td>long</td> <td> 4</td> <td> 4</td> <td> 8<sup>†</sup>,4<sup>∗</sup></td> <td> 8<sup>†</sup>,4<sup>∗</sup></td></tr> + <tr><td>pointer</td> <td> 4</td> <td> 4</td> <td> 8</td> <td> 8</td></tr> + <tr><td>long long</td> <td> 8</td> <td>4<sup>†</sup>,8<sup>∗</sup><sup>+</sup></td> <td> 8</td> <td> 8</td></tr> + <tr><td>double</td> <td> 8</td> <td>4<sup>†</sup>,8<sup>∗</sup><sup>+</sup></td> <td> 8</td> <td> 8</td></tr> + <tr><td>long double</td><td>12<sup>†</sup><sup>∗</sup>,8<sup>+</sup></td> <td>4<sup>†</sup><sup>∗</sup>,8<sup>+</sup></td> <td> 16</td> <td>16</td></tr> + </table><br> + <sup>†</sup> Linux, Darwin<br> + <sup>+</sup>armv7l-32bit-eabi (linux)<br> + <sup>∗</sup> Windows<br> + </P> + <h4>GlueGen Platform Header Files</h4> GlueGen provides convenient platform headers,<br/> which can be included in your C header files for native compilation and GlueGen code generation.<br/> |