diff options
author | Sven Gothel <[email protected]> | 2014-06-19 06:12:10 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2014-06-19 06:12:10 +0200 |
commit | 6cb643671578aa912d16dd17e773d92f4667118b (patch) | |
tree | f343ad298c8a17a81738c0e5d50f31379549425f /src/java/com/jogamp/gluegen/cgram | |
parent | 0b0f6f4d17f1ace3d3856428194126b4e3f06df0 (diff) |
GlueGen: Add support for compound-array in structs (accessors) ; Allow using C-Enum values for array length
- Parser (HeaderParser.g): Support using C-Enum values for array length specification
- Will throw an exception if enum identifier is unknown or exceeds int-size
- Add StructEmitter supports for compound-arrays
- Add Debug stderr verbose info:
- Struct Emitter prefix 'SE.' - to analyze emitting struct fields (offset+size and accessors)
- Struct Layout prefix 'SL.' - to analyze memory layout (based on MachineDescription.StaticConfig.X86_64_UNIX)
Tested via test1.[ch] BaseClass ..
Diffstat (limited to 'src/java/com/jogamp/gluegen/cgram')
-rw-r--r-- | src/java/com/jogamp/gluegen/cgram/types/StructLayout.java | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/src/java/com/jogamp/gluegen/cgram/types/StructLayout.java b/src/java/com/jogamp/gluegen/cgram/types/StructLayout.java index 11501e1..f105f1f 100644 --- a/src/java/com/jogamp/gluegen/cgram/types/StructLayout.java +++ b/src/java/com/jogamp/gluegen/cgram/types/StructLayout.java @@ -40,6 +40,9 @@ package com.jogamp.gluegen.cgram.types; +import com.jogamp.common.os.MachineDescription; +import com.jogamp.gluegen.GlueGen; + /** Encapsulates algorithm for laying out data structures. Note that this ends up embedding code in various places via SizeThunks. If the 32-bit and 64-bit ports on a given platform differ @@ -48,7 +51,7 @@ package com.jogamp.gluegen.cgram.types; SizeThunks maintained in various places. */ public class StructLayout { - private int baseOffset; + private final int baseOffset; protected StructLayout(int baseOffset) { this.baseOffset = baseOffset; @@ -60,12 +63,21 @@ public class StructLayout { * - 2) add the aligned size of the new data type * - 3) add trailing padding (largest element size) */ - int n = t.getNumFields(); + final int n = t.getNumFields(); SizeThunk curOffset = SizeThunk.constant(baseOffset); SizeThunk maxSize = SizeThunk.constant(0); + + final MachineDescription dbgMD; + if( GlueGen.debug() ) { + dbgMD = MachineDescription.StaticConfig.X86_64_UNIX.md; + System.err.printf("SL.__: o %03d, s %03d, t %s{%d}%n", curOffset.computeSize(dbgMD), 0, t, t.getNumFields()); + } else { + dbgMD = null; + } + for (int i = 0; i < n; i++) { - Field f = t.getField(i); - Type ft = f.getType(); + final Field f = t.getField(i); + final Type ft = f.getType(); if (ft.isInt() || ft.isFloat() || ft.isDouble() || ft.isPointer()) { final SizeThunk sz = ft.getSize(); curOffset = SizeThunk.align(curOffset, sz); @@ -75,6 +87,9 @@ public class StructLayout { } else { curOffset = SizeThunk.add(curOffset, sz); } + if( GlueGen.debug() ) { + System.err.printf("SL.%02d: o %03d, s %03d, t %s: %s%n", (i+1), f.getOffset(dbgMD), ft.getSize(dbgMD), ft, f); + } } else if (ft.isCompound()) { final CompoundType ct = ft.asCompound(); if(!ct.isLayouted()) { @@ -88,8 +103,11 @@ public class StructLayout { } else { curOffset = SizeThunk.add(curOffset, sz); } + if( GlueGen.debug() ) { + System.err.printf("SL.%02d: o %03d, s %03d, t %s{%d}: %s%n", (i+1), f.getOffset(dbgMD), ft.getSize(dbgMD), ft, ct.getNumFields(), f); + } } else if (ft.isArray()) { - ArrayType arrayType = ft.asArray(); + final ArrayType arrayType = ft.asArray(); if(!arrayType.isLayouted()) { CompoundType compoundElementType = arrayType.getBaseElementType().asCompound(); if (compoundElementType != null) { @@ -104,6 +122,9 @@ public class StructLayout { curOffset = SizeThunk.align(curOffset, sz); f.setOffset(curOffset); curOffset = SizeThunk.add(curOffset, sz); + if( GlueGen.debug() ) { + System.err.printf("SL.%02d: o %03d, s %03d, t %s: %s%n", (i+1), f.getOffset(dbgMD), ft.getSize(dbgMD), ft, f); + } } else { // FIXME String name = t.getName(); @@ -123,6 +144,9 @@ public class StructLayout { curOffset = SizeThunk.align(curOffset, curOffset); t.setSize(curOffset); } + if( GlueGen.debug() ) { + System.err.printf("SL.XX: o %03d, s %03d, t %s{%d}%n%n", curOffset.computeSize(dbgMD), t.getSize(dbgMD), t, t.getNumFields()); + } t.setLayouted(); } |