aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp/gluegen/cgram
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-07-17 19:55:36 +0200
committerSven Gothel <[email protected]>2011-07-17 19:55:36 +0200
commit8fc841257cae6b49399b29dfa53e3e834d27cabb (patch)
tree5012bb4ec63378017479d51e65262974a545645e /src/java/com/jogamp/gluegen/cgram
parent2bf03e9814477b412f9533d3ba3f4c597892501e (diff)
GlueGen: Alignment Cleanup ..
- SizeThunk - rename: compute -> computeSize - add: computeAlignment - merge types: char -> int8, short -> int16 - 'int' and 'long' may differ -
Diffstat (limited to 'src/java/com/jogamp/gluegen/cgram')
-rw-r--r--src/java/com/jogamp/gluegen/cgram/HeaderParser.g12
-rw-r--r--src/java/com/jogamp/gluegen/cgram/types/Field.java2
-rwxr-xr-xsrc/java/com/jogamp/gluegen/cgram/types/SizeThunk.java141
-rw-r--r--src/java/com/jogamp/gluegen/cgram/types/Type.java2
4 files changed, 104 insertions, 53 deletions
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; }