diff options
Diffstat (limited to 'src/java/com')
5 files changed, 110 insertions, 77 deletions
diff --git a/src/java/com/jogamp/common/os/MachineDescription.java b/src/java/com/jogamp/common/os/MachineDescription.java index a407187..99383b4 100644 --- a/src/java/com/jogamp/common/os/MachineDescription.java +++ b/src/java/com/jogamp/common/os/MachineDescription.java @@ -55,8 +55,6 @@ public class MachineDescription { final private int int32SizeInBytes = 4; final private int int64SizeInBytes = 8; - final private int charSizeInBytes; - final private int shortSizeInBytes; final private int intSizeInBytes; final private int longSizeInBytes; final private int floatSizeInBytes; @@ -69,8 +67,6 @@ public class MachineDescription { final private int int16AlignmentInBytes; final private int int32AlignmentInBytes; final private int int64AlignmentInBytes; - final private int charAlignmentInBytes; - final private int shortAlignmentInBytes; final private int intAlignmentInBytes; final private int longAlignmentInBytes; final private int floatAlignmentInBytes; @@ -81,8 +77,6 @@ public class MachineDescription { boolean littleEndian, - int charSizeInBytes, - int shortSizeInBytes, int intSizeInBytes, int longSizeInBytes, int floatSizeInBytes, @@ -94,8 +88,6 @@ public class MachineDescription { int int16AlignmentInBytes, int int32AlignmentInBytes, int int64AlignmentInBytes, - int charAlignmentInBytes, - int shortAlignmentInBytes, int intAlignmentInBytes, int longAlignmentInBytes, int floatAlignmentInBytes, @@ -105,8 +97,6 @@ public class MachineDescription { this.littleEndian = littleEndian; - this.charSizeInBytes = charSizeInBytes; - this.shortSizeInBytes = shortSizeInBytes; this.intSizeInBytes = intSizeInBytes; this.longSizeInBytes = longSizeInBytes; this.floatSizeInBytes = floatSizeInBytes; @@ -119,8 +109,6 @@ public class MachineDescription { this.int16AlignmentInBytes = int16AlignmentInBytes; this.int32AlignmentInBytes = int32AlignmentInBytes; this.int64AlignmentInBytes = int64AlignmentInBytes; - this.charAlignmentInBytes = charAlignmentInBytes; - this.shortAlignmentInBytes = shortAlignmentInBytes; this.intAlignmentInBytes = intAlignmentInBytes; this.longAlignmentInBytes = longAlignmentInBytes; this.floatAlignmentInBytes = floatAlignmentInBytes; @@ -156,8 +144,6 @@ public class MachineDescription { return !is32Bit; } - public final int charSizeInBytes() { return charSizeInBytes; } - public final int shortSizeInBytes() { return shortSizeInBytes; } public final int intSizeInBytes() { return intSizeInBytes; } public final int longSizeInBytes() { return longSizeInBytes; } public final int int8SizeInBytes() { return int8SizeInBytes; } @@ -169,8 +155,6 @@ public class MachineDescription { public final int pointerSizeInBytes() { return pointerSizeInBytes; } public final int pageSizeInBytes() { return pageSizeInBytes; } - public final int charAlignmentInBytes() { return charAlignmentInBytes; } - public final int shortAlignmentInBytes() { return shortAlignmentInBytes; } public final int intAlignmentInBytes() { return intAlignmentInBytes; } public final int longAlignmentInBytes() { return longAlignmentInBytes; } public final int int8AlignmentInBytes() { return int8AlignmentInBytes; } @@ -200,17 +184,15 @@ public class MachineDescription { 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(" char ").append(charSizeInBytes) .append(" / ").append(charAlignmentInBytes); - sb.append(", short ").append(shortSizeInBytes) .append(" / ").append(shortAlignmentInBytes); - sb.append(", int ").append(intSizeInBytes) .append(" / ").append(intAlignmentInBytes); - sb.append(", long ").append(longSizeInBytes) .append(" / ").append(longAlignmentInBytes).append(Platform.getNewline()); sb.append(" int8 ").append(int8SizeInBytes) .append(" / ").append(int8AlignmentInBytes); - sb.append(", int16 ").append(int16SizeInBytes) .append(" / ").append(int16AlignmentInBytes); - sb.append(", int32 ").append(int32SizeInBytes) .append(" / ").append(int32AlignmentInBytes); + 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(", pointer ").append(pointerSizeInBytes).append(" / ").append(pointerAlignmentInBytes); + sb.append(", double ").append(doubleSizeInBytes) .append(" / ").append(doubleAlignmentInBytes).append(Platform.getNewline()); + sb.append(" pointer ").append(pointerSizeInBytes).append(" / ").append(pointerAlignmentInBytes); sb.append(", page ").append(pageSizeInBytes); return sb; } diff --git a/src/java/com/jogamp/gluegen/cgram/HeaderParser.g b/src/java/com/jogamp/gluegen/cgram/HeaderParser.g index 79f966f..8c2ad26 100644 --- a/src/java/com/jogamp/gluegen/cgram/HeaderParser.g +++ b/src/java/com/jogamp/gluegen/cgram/HeaderParser.g @@ -334,7 +334,7 @@ options { // entry the enum should expand to e.g. int64. However, using // "long" here (which is what used to be the case) was // definitely incorrect and caused problems. - enumType = new EnumType(enumTypeName, SizeThunk.INT); + enumType = new EnumType(enumTypeName, SizeThunk.INT32); } return enumType; @@ -464,7 +464,7 @@ declSpecifiers returns [TypeBox tb] { { if (t == null && (x & (SIGNED | UNSIGNED)) != 0) { - t = new IntType("int", SizeThunk.INT, ((x & UNSIGNED) != 0), attrs2CVAttrs(x)); + t = new IntType("int", SizeThunk.INTxx, ((x & UNSIGNED) != 0), attrs2CVAttrs(x)); } tb = new TypeBox(t, ((x & TYPEDEF) != 0)); } @@ -498,9 +498,9 @@ typeSpecifier[int attributes] returns [Type t] { boolean unsigned = ((attributes & UNSIGNED) != 0); } : "void" { t = new VoidType(cvAttrs); } - | "char" { t = new IntType("char" , SizeThunk.CHAR, unsigned, cvAttrs); } - | "short" { t = new IntType("short", SizeThunk.SHORT, unsigned, cvAttrs); } - | "int" { t = new IntType("int" , SizeThunk.INT, unsigned, cvAttrs); } + | "char" { t = new IntType("char" , SizeThunk.INT8, unsigned, cvAttrs); } + | "short" { t = new IntType("short", SizeThunk.INT16, unsigned, cvAttrs); } + | "int" { t = new IntType("int" , SizeThunk.INTxx, unsigned, cvAttrs); } | "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); } @@ -593,7 +593,7 @@ specifierQualifierList returns [Type t] { )+ { if (t == null && (x & (SIGNED | UNSIGNED)) != 0) { - t = new IntType("int", SizeThunk.INT, ((x & UNSIGNED) != 0), attrs2CVAttrs(x)); + t = new IntType("int", SizeThunk.INTxx, ((x & UNSIGNED) != 0), attrs2CVAttrs(x)); } } ; diff --git a/src/java/com/jogamp/gluegen/cgram/types/Field.java b/src/java/com/jogamp/gluegen/cgram/types/Field.java index 2479e3d..891bb27 100644 --- a/src/java/com/jogamp/gluegen/cgram/types/Field.java +++ b/src/java/com/jogamp/gluegen/cgram/types/Field.java @@ -84,7 +84,7 @@ public class Field { /** Offset, in bytes, of this field in the containing data structure given the specified MachineDescription. */ - public long getOffset(MachineDescription machDesc) { return offset.compute(machDesc); } + public long getOffset(MachineDescription machDesc) { return offset.computeSize(machDesc); } /** Sets the offset of this field in the containing data structure. */ public void setOffset(SizeThunk offset) { this.offset = offset; } diff --git a/src/java/com/jogamp/gluegen/cgram/types/SizeThunk.java b/src/java/com/jogamp/gluegen/cgram/types/SizeThunk.java index 1584a13..d71445d 100755 --- a/src/java/com/jogamp/gluegen/cgram/types/SizeThunk.java +++ b/src/java/com/jogamp/gluegen/cgram/types/SizeThunk.java @@ -60,72 +60,88 @@ public abstract class SizeThunk implements Cloneable { } } - public abstract long compute(MachineDescription machDesc); + public abstract long computeSize(MachineDescription machDesc); + public abstract long computeAlignment(MachineDescription machDesc); - public static final SizeThunk CHAR = new SizeThunk() { - public long compute(MachineDescription machDesc) { - return machDesc.charSizeInBytes(); + public static final SizeThunk INT8 = new SizeThunk() { + public long computeSize(MachineDescription machDesc) { + return machDesc.int8SizeInBytes(); } - }; - - public static final SizeThunk SHORT = new SizeThunk() { - public long compute(MachineDescription machDesc) { - return machDesc.shortSizeInBytes(); + public long computeAlignment(MachineDescription machDesc) { + return machDesc.int8AlignmentInBytes(); } }; - public static final SizeThunk INT = new SizeThunk() { - public long compute(MachineDescription machDesc) { - return machDesc.intSizeInBytes(); + public static final SizeThunk INT16 = new SizeThunk() { + public long computeSize(MachineDescription machDesc) { + return machDesc.int16SizeInBytes(); } - }; - - public static final SizeThunk LONG = new SizeThunk() { - public long compute(MachineDescription machDesc) { - return machDesc.longSizeInBytes(); + public long computeAlignment(MachineDescription machDesc) { + return machDesc.int16AlignmentInBytes(); } }; - public static final SizeThunk INT8 = new SizeThunk() { - public long compute(MachineDescription machDesc) { - return machDesc.int8SizeInBytes(); + public static final SizeThunk INT32 = new SizeThunk() { + public long computeSize(MachineDescription machDesc) { + return machDesc.int32SizeInBytes(); + } + public long computeAlignment(MachineDescription machDesc) { + return machDesc.int32AlignmentInBytes(); } }; - public static final SizeThunk INT16 = new SizeThunk() { - public long compute(MachineDescription machDesc) { - return machDesc.int16SizeInBytes(); + public static final SizeThunk INTxx = new SizeThunk() { + public long computeSize(MachineDescription machDesc) { + return machDesc.intSizeInBytes(); + } + public long computeAlignment(MachineDescription machDesc) { + return machDesc.intAlignmentInBytes(); } }; - public static final SizeThunk INT32 = new SizeThunk() { - public long compute(MachineDescription machDesc) { - return machDesc.int32SizeInBytes(); + public static final SizeThunk LONG = new SizeThunk() { + public long computeSize(MachineDescription machDesc) { + return machDesc.longSizeInBytes(); + } + public long computeAlignment(MachineDescription machDesc) { + return machDesc.longAlignmentInBytes(); } }; public static final SizeThunk INT64 = new SizeThunk() { - public long compute(MachineDescription machDesc) { + public long computeSize(MachineDescription machDesc) { return machDesc.int64SizeInBytes(); } + public long computeAlignment(MachineDescription machDesc) { + return machDesc.int64AlignmentInBytes(); + } }; public static final SizeThunk FLOAT = new SizeThunk() { - public long compute(MachineDescription machDesc) { + public long computeSize(MachineDescription machDesc) { return machDesc.floatSizeInBytes(); } + public long computeAlignment(MachineDescription machDesc) { + return machDesc.floatAlignmentInBytes(); + } }; public static final SizeThunk DOUBLE = new SizeThunk() { - public long compute(MachineDescription machDesc) { + public long computeSize(MachineDescription machDesc) { return machDesc.doubleSizeInBytes(); } + public long computeAlignment(MachineDescription machDesc) { + return machDesc.doubleAlignmentInBytes(); + } }; public static final SizeThunk POINTER = new SizeThunk() { - public long compute(MachineDescription machDesc) { + public long computeSize(MachineDescription machDesc) { return machDesc.pointerSizeInBytes(); } + public long computeAlignment(MachineDescription machDesc) { + return machDesc.pointerAlignmentInBytes(); + } }; // Factory methods for performing certain limited kinds of @@ -133,8 +149,13 @@ public abstract class SizeThunk implements Cloneable { public static SizeThunk add(final SizeThunk thunk1, final SizeThunk thunk2) { return new SizeThunk() { - public long compute(MachineDescription machDesc) { - return thunk1.compute(machDesc) + thunk2.compute(machDesc); + public long computeSize(MachineDescription machDesc) { + return thunk1.computeSize(machDesc) + thunk2.computeSize(machDesc); + } + public long computeAlignment(MachineDescription machDesc) { + final long thunk1A = thunk1.computeAlignment(machDesc); + final long thunk2A = thunk2.computeAlignment(machDesc); + return ( thunk1A > thunk2A ) ? thunk1A : thunk2A ; } }; } @@ -142,8 +163,14 @@ public abstract class SizeThunk implements Cloneable { public static SizeThunk sub(final SizeThunk thunk1, final SizeThunk thunk2) { return new SizeThunk() { - public long compute(MachineDescription machDesc) { - return thunk1.compute(machDesc) - thunk2.compute(machDesc); + public long computeSize(MachineDescription machDesc) { + return thunk1.computeSize(machDesc) - thunk2.computeSize(machDesc); + } + public long computeAlignment(MachineDescription machDesc) { + // FIXME + final long thunk1A = thunk1.computeAlignment(machDesc); + final long thunk2A = thunk2.computeAlignment(machDesc); + return ( thunk1A > thunk2A ) ? thunk1A : thunk2A ; } }; } @@ -151,8 +178,13 @@ public abstract class SizeThunk implements Cloneable { public static SizeThunk mul(final SizeThunk thunk1, final SizeThunk thunk2) { return new SizeThunk() { - public long compute(MachineDescription machDesc) { - return thunk1.compute(machDesc) * thunk2.compute(machDesc); + public long computeSize(MachineDescription machDesc) { + return thunk1.computeSize(machDesc) * thunk2.computeSize(machDesc); + } + public long computeAlignment(MachineDescription machDesc) { + final long thunk1A = thunk1.computeAlignment(machDesc); + final long thunk2A = thunk2.computeAlignment(machDesc); + return ( thunk1A > thunk2A ) ? thunk1A : thunk2A ; } }; } @@ -160,8 +192,14 @@ public abstract class SizeThunk implements Cloneable { public static SizeThunk mod(final SizeThunk thunk1, final SizeThunk thunk2) { return new SizeThunk() { - public long compute(MachineDescription machDesc) { - return thunk1.compute(machDesc) % thunk2.compute(machDesc); + public long computeSize(MachineDescription machDesc) { + return thunk1.computeSize(machDesc) % thunk2.computeSize(machDesc); + } + public long computeAlignment(MachineDescription machDesc) { + // FIXME + final long thunk1A = thunk1.computeAlignment(machDesc); + final long thunk2A = thunk2.computeAlignment(machDesc); + return ( thunk1A > thunk2A ) ? thunk1A : thunk2A ; } }; } @@ -169,32 +207,45 @@ public abstract class SizeThunk implements Cloneable { public static SizeThunk roundUp(final SizeThunk thunk1, final SizeThunk thunk2) { return new SizeThunk() { - public long compute(MachineDescription machDesc) { - long sz1 = thunk1.compute(machDesc); - long sz2 = thunk2.compute(machDesc); - long rem = (sz1 % sz2); + public long computeSize(MachineDescription machDesc) { + final long sz1 = thunk1.computeSize(machDesc); + final long sz2 = thunk2.computeSize(machDesc); + final long rem = (sz1 % sz2); if (rem == 0) { return sz1; } return sz1 + (sz2 - rem); } + public long computeAlignment(MachineDescription machDesc) { + final long thunk1A = thunk1.computeAlignment(machDesc); + final long thunk2A = thunk2.computeAlignment(machDesc); + return ( thunk1A > thunk2A ) ? thunk1A : thunk2A ; + } }; } public static SizeThunk max(final SizeThunk thunk1, final SizeThunk thunk2) { return new SizeThunk() { - public long compute(MachineDescription machDesc) { - return Math.max(thunk1.compute(machDesc), thunk2.compute(machDesc)); + public long computeSize(MachineDescription machDesc) { + return Math.max(thunk1.computeSize(machDesc), thunk2.computeSize(machDesc)); + } + public long computeAlignment(MachineDescription machDesc) { + final long thunk1A = thunk1.computeAlignment(machDesc); + final long thunk2A = thunk2.computeAlignment(machDesc); + return ( thunk1A > thunk2A ) ? thunk1A : thunk2A ; } }; } public static SizeThunk constant(final int constant) { return new SizeThunk() { - public long compute(MachineDescription machDesc) { + public long computeSize(MachineDescription machDesc) { return constant; } + public long computeAlignment(MachineDescription machDesc) { + return 1; // no real alignment for constants + } }; } } diff --git a/src/java/com/jogamp/gluegen/cgram/types/Type.java b/src/java/com/jogamp/gluegen/cgram/types/Type.java index 95afc2c..27aff92 100644 --- a/src/java/com/jogamp/gluegen/cgram/types/Type.java +++ b/src/java/com/jogamp/gluegen/cgram/types/Type.java @@ -107,7 +107,7 @@ public abstract class Type implements Cloneable { if (thunk == null) { throw new RuntimeException("No size set for type \"" + getName() + "\""); } - return thunk.compute(machDesc); + return thunk.computeSize(machDesc); } /** Set the size of this type; only available for CompoundTypes. */ void setSize(SizeThunk size) { this.size = size; } |