From f733203dfbd034a6b1aa3eb2cd616437c982c435 Mon Sep 17 00:00:00 2001
From: Sven Gothel
Date: Sun, 17 Jul 2011 16:34:39 +0200
Subject: 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, ..
---
.../com/jogamp/gluegen/CMethodBindingEmitter.java | 1 +
src/java/com/jogamp/gluegen/DebugEmitter.java | 1 +
src/java/com/jogamp/gluegen/GlueEmitter.java | 2 +
src/java/com/jogamp/gluegen/GlueGen.java | 5 ++
src/java/com/jogamp/gluegen/JavaEmitter.java | 2 +
src/java/com/jogamp/gluegen/StructLayout.java | 53 +++++++------
src/java/com/jogamp/gluegen/cgram/GnuCParser.g | 4 +
src/java/com/jogamp/gluegen/cgram/GnuCTreeParser.g | 4 +
src/java/com/jogamp/gluegen/cgram/HeaderParser.g | 12 ++-
src/java/com/jogamp/gluegen/cgram/StdCParser.g | 4 +
src/java/com/jogamp/gluegen/cgram/types/Field.java | 2 +
.../gluegen/cgram/types/MachineDescription.java | 82 --------------------
.../cgram/types/MachineDescription32Bit.java | 46 -----------
.../cgram/types/MachineDescription64Bit.java | 46 -----------
.../com/jogamp/gluegen/cgram/types/SizeThunk.java | 20 +++++
src/java/com/jogamp/gluegen/cgram/types/Type.java | 2 +
src/java/com/jogamp/gluegen/package.html | 90 +++++++++++++++++-----
17 files changed, 153 insertions(+), 223 deletions(-)
delete mode 100644 src/java/com/jogamp/gluegen/cgram/types/MachineDescription.java
delete mode 100644 src/java/com/jogamp/gluegen/cgram/types/MachineDescription32Bit.java
delete mode 100644 src/java/com/jogamp/gluegen/cgram/types/MachineDescription64Bit.java
(limited to 'src/java/com/jogamp/gluegen')
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 {
+ /**
+ * See alignment in {@link com.jogamp.common.os.MachineDescription}.
+ *
+ * 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)}.
+ */
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:
- type | java bits | native-x32 bits | native-x64 bits | type | signed | origin |
-
---|
void | 0 | 0 | 0 | void | void | ANSI-C |
- char | 8 | 8 | 8 | integer | signed or unsigned | ANSI-C |
- short | 16 | 16 | 16 | integer | signed or unsigned | ANSI-C |
- int | 32 | 32 | 32 | integer | signed or unsigned | ANSI-C |
- long | 64 | 32 | 321 | integer | signed or unsigned | Windows |
- long | 64 | 32 | 64 | integer | signed or unsigned | Unix |
- float | 32 | 32 | 32 | float | signed | ANSI-C |
- double | 64 | 64 | 64 | double | signed | ANSI-C |
- __int32 | 32 | 32 | 32 | integer | signed or unsigned | windows |
- int32_t | 32 | 32 | 32 | integer | signed | stdint.h |
- wchar_t | 32 | 32 | 32 | integer | signed | stddef.h |
- uint32_t | 32 | 32 | 32 | integer | unsigned | stdint.h |
- __int64 | 64 | 64 | 64 | integer | signed or unsigned | windows |
- int64_t | 64 | 64 | 64 | integer | signed | stdint.h |
- uint64_t | 64 | 64 | 64 | integer | unsigned | stdint.h |
- ptrdiff_t | 64 | 32 | 64 | integer | signed | stddef.h |
- intptr_t | 64 | 32 | 64 | integer | signed | stdint.h |
- size_t | 64 | 32 | 64 | integer | unsigned | stddef.h |
- uintptr_t | 64 | 32 | 64 | integer | unsigned | stdint.h |
+ type | java bits | native bits | type | signed | origin |
+ | | x32 | x64 | | | |
+ void | 0 | 0 | 0 | void | void | ANSI-C |
+ char | 8 | 8 | 8 | integer | any | ANSI-C |
+ short | 16 | 16 | 16 | integer | any | ANSI-C |
+ int | 32 | 32 | 32 | integer | any | ANSI-C |
+ long | 64 | 32 | 321 | integer | any | ANSI-C - Windows |
+ long | 64 | 32 | 64 | integer | any | ANSI-C - Unix |
+ float | 32 | 32 | 32 | float | signed | ANSI-C |
+ double | 64 | 64 | 64 | double | signed | ANSI-C |
+ __int32 | 32 | 32 | 32 | integer | any | windows |
+ __int64 | 64 | 64 | 64 | integer | any | windows |
+ int8_t | 8 | 8 | 8 | integer | signed | stdint.h |
+ uint8_t | 8 | 8 | 8 | integer | unsigned | stdint.h |
+ int16_t | 16 | 16 | 16 | integer | signed | stdint.h |
+ uint16_t | 16 | 16 | 16 | integer | unsigned | stdint.h |
+ int32_t | 32 | 32 | 32 | integer | signed | stdint.h |
+ uint32_t | 32 | 32 | 32 | integer | unsigned | stdint.h |
+ int64_t | 64 | 64 | 64 | integer | signed | stdint.h |
+ uint64_t | 64 | 64 | 64 | integer | unsigned | stdint.h |
+ intptr_t | 64 | 32 | 64 | integer | signed | stdint.h |
+ uintptr_t | 64 | 32 | 64 | integer | unsigned | stdint.h |
+ ptrdiff_t | 64 | 32 | 64 | integer | signed | stddef.h |
+ size_t | 64 | 32 | 64 | integer | unsigned | stddef.h |
+ wchar_t | 32 | 32 | 32 | integer | signed | stddef.h |
Warning: Try to avoid unspecified bit sized types, especially long, since it differs on Unix and Windows!
Note 1: Type long will result in broken code on Windows, since we don't differentiate the OS and it's bit size is ambiguous.
-
+
+
GlueGen Internal Alignment for Compound Data
+ In general, depending on CPU and it's configuration (OS), alignment is set up
+ for each type (char, short, int, long, ..),
+ where structures are aligned naturally, i.e. their inner components are aligned.
+ See:
+
+
+ Type Size & Alignment for x86, x86_64, armv7l-32bit-eabi and Window(mingw/mingw64)
+ Runtime query is implemented as follows:
+
+ 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_) ;
+
+
+ type | 32 bits | 64 bits |
+ | size | alignment | size | alignment |
+ char | 1 | 1 | 1 | 1 |
+ short | 2 | 2 | 2 | 2 |
+ int | 4 | 4 | 4 | 4 |
+ float | 4 | 4 | 4 | 4 |
+ long | 4 | 4 | 8†,4∗ | 8†,4∗ |
+ pointer | 4 | 4 | 8 | 8 |
+ long long | 8 | 4†,8∗+ | 8 | 8 |
+ double | 8 | 4†,8∗+ | 8 | 8 |
+ long double | 12†∗,8+ | 4†∗,8+ | 16 | 16 |
+
+ † Linux, Darwin
+ +armv7l-32bit-eabi (linux)
+ ∗ Windows
+
+
GlueGen Platform Header Files
GlueGen provides convenient platform headers,
which can be included in your C header files for native compilation and GlueGen code generation.
--
cgit v1.2.3