summaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp/gluegen
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2015-02-01 05:21:39 +0100
committerSven Gothel <[email protected]>2015-02-01 05:21:39 +0100
commita3f2d08801c5a54048faca52f422bcededf81b2a (patch)
tree96e83956b62ae3e25043ccc67f4cb1c2c1f232a1 /src/java/com/jogamp/gluegen
parent0deceee37d943faa7c34971388863a27f395d6a5 (diff)
Bug 1125 - Make ELF Reader 'jogamp.common.os.elf' Stateless
ELF Reader 'jogamp.common.os.elf' currently uses Platform's pre-determined OS_TYPE and CPUType. It also uses the host platforms MachineDescription, hence can not read ELF files from other machines. This also forbids Platform to determine CPUType etc w/o having a valid 'os.arch' property. +++ ElfHeader should be split in - ElfHeaderPart1 (CPUType independent) - ElfHeaderPart2 (CPUType dependent) Fix shall make the ELF Reader self containing by only using ELF CPUType data, etc. This requires customization of struct parsing, where MachineDescription.Static index shall be - defined in ElfHeaderPart1 using e_Ident's CPUType. - used in ElfHeaderPart2 and all its struct types.
Diffstat (limited to 'src/java/com/jogamp/gluegen')
-rw-r--r--src/java/com/jogamp/gluegen/JavaConfiguration.java40
-rw-r--r--src/java/com/jogamp/gluegen/JavaEmitter.java56
2 files changed, 73 insertions, 23 deletions
diff --git a/src/java/com/jogamp/gluegen/JavaConfiguration.java b/src/java/com/jogamp/gluegen/JavaConfiguration.java
index b64c041..3924ec2 100644
--- a/src/java/com/jogamp/gluegen/JavaConfiguration.java
+++ b/src/java/com/jogamp/gluegen/JavaConfiguration.java
@@ -42,6 +42,7 @@ package com.jogamp.gluegen;
import com.jogamp.gluegen.JavaEmitter.EmissionStyle;
import com.jogamp.gluegen.JavaEmitter.MethodAccess;
+
import java.io.*;
import java.lang.reflect.Array;
import java.util.*;
@@ -53,6 +54,7 @@ import com.jogamp.gluegen.cgram.types.*;
import java.util.logging.Logger;
+import jogamp.common.os.MachineDescriptionRuntime;
import static java.util.logging.Level.*;
import static com.jogamp.gluegen.JavaEmitter.MethodAccess.*;
import static com.jogamp.gluegen.JavaEmitter.EmissionStyle.*;
@@ -164,6 +166,7 @@ public class JavaConfiguration {
private final Map<String, String> structPackages = new HashMap<String, String>();
private final List<String> customCCode = new ArrayList<String>();
private final List<String> forcedStructs = new ArrayList<String>();
+ private final Map<String, String> structMachineDescriptorIndex = new HashMap<String, String>();
private final Map<String, String> returnValueCapacities = new HashMap<String, String>();
private final Map<String, String> returnValueLengths = new HashMap<String, String>();
private final Map<String, List<String>> temporaryCVariableDeclarations = new HashMap<String, List<String>>();
@@ -547,7 +550,12 @@ public class JavaConfiguration {
}
/** Returns true if the glue code for the given function will be
- manually implemented by the end user. */
+ manually implemented by the end user.
+ * <p>
+ * If symbol references a struct field or method, see {@link #canonicalStructFieldSymbol(String, String)},
+ * it describes field's array-length or element-count referenced by a pointer.
+ * </p>
+ */
public boolean manuallyImplement(final String functionName) {
return manuallyImplement.contains(functionName);
}
@@ -637,6 +645,20 @@ public class JavaConfiguration {
}
/**
+ * Returns a MessageFormat string of the Java code defining {@code mdIdx},
+ * i.e. the index of the static MachineDescriptor index for structs.
+ * <p>
+ * If undefined, code generation uses the default expression:
+ * <pre>
+ * private static final int mdIdx = MachineDescriptionRuntime.getStatic().ordinal();
+ * </pre>
+ * </p>
+ */
+ public String returnStructMachineDescriptorIndex(final String structName) {
+ return structMachineDescriptorIndex.get(structName);
+ }
+
+ /**
* Returns a MessageFormat string of the C expression calculating
* the capacity of the java.nio.ByteBuffer being returned from a
* native method, or null if no expression has been specified.
@@ -1101,6 +1123,10 @@ public class JavaConfiguration {
readTemporaryCVariableAssignment(tok, filename, lineNo);
// Warning: make sure delimiters are reset at the top of this loop
// because TemporaryCVariableAssignment changes them.
+ } else if (cmd.equalsIgnoreCase("StructMachineDescriptorIndex")) {
+ readStructMachineDescriptorIndex(tok, filename, lineNo);
+ // Warning: make sure delimiters are reset at the top of this loop
+ // because StructMachineDescriptorIndex changes them.
} else if (cmd.equalsIgnoreCase("ReturnValueCapacity")) {
readReturnValueCapacity(tok, filename, lineNo);
// Warning: make sure delimiters are reset at the top of this loop
@@ -1499,6 +1525,18 @@ public class JavaConfiguration {
}
}
+ protected void readStructMachineDescriptorIndex(final StringTokenizer tok, final String filename, final int lineNo) {
+ try {
+ final String structName = tok.nextToken();
+ String restOfLine = tok.nextToken("\n\r\f");
+ restOfLine = restOfLine.trim();
+ structMachineDescriptorIndex.put(structName, restOfLine);
+ } catch (final NoSuchElementException e) {
+ throw new RuntimeException("Error parsing \"StructMachineDescriptorIndex\" command at line " + lineNo +
+ " in file \"" + filename + "\"", e);
+ }
+ }
+
protected void readReturnValueCapacity(final StringTokenizer tok, final String filename, final int lineNo) {
try {
final String functionName = tok.nextToken();
diff --git a/src/java/com/jogamp/gluegen/JavaEmitter.java b/src/java/com/jogamp/gluegen/JavaEmitter.java
index 7e5ce51..48c7047 100644
--- a/src/java/com/jogamp/gluegen/JavaEmitter.java
+++ b/src/java/com/jogamp/gluegen/JavaEmitter.java
@@ -963,7 +963,10 @@ public class JavaEmitter implements GlueEmitter {
javaWriter.println();
javaWriter.println(" StructAccessor accessor;");
javaWriter.println();
- javaWriter.println(" private static final int mdIdx = MachineDescriptionRuntime.getStatic().ordinal();");
+ final String cfgMachDescrIdxCode = cfg.returnStructMachineDescriptorIndex(containingJTypeName);
+ final String machDescrIdxCode = null != cfgMachDescrIdxCode ? cfgMachDescrIdxCode : "private static final int mdIdx = MachineDescriptionRuntime.getStatic().ordinal();";
+ javaWriter.println(" "+machDescrIdxCode);
+ javaWriter.println(" private final MachineDescription md;");
javaWriter.println();
// generate all offset and size arrays
generateOffsetAndSizeArrays(javaWriter, " ", containingJTypeName, structCType, null, null); /* w/o offset */
@@ -1037,22 +1040,29 @@ public class JavaEmitter implements GlueEmitter {
}
}
javaWriter.println();
- javaWriter.println(" public static int size() {");
- javaWriter.println(" return "+containingJTypeName+"_size[mdIdx];");
- javaWriter.println(" }");
- javaWriter.println();
- javaWriter.println(" public static " + containingJTypeName + " create() {");
- javaWriter.println(" return create(Buffers.newDirectByteBuffer(size()));");
- javaWriter.println(" }");
- javaWriter.println();
- javaWriter.println(" public static " + containingJTypeName + " create(java.nio.ByteBuffer buf) {");
- javaWriter.println(" return new " + containingJTypeName + "(buf);");
- javaWriter.println(" }");
- javaWriter.println();
- javaWriter.println(" " + containingJTypeName + "(java.nio.ByteBuffer buf) {");
- javaWriter.println(" accessor = new StructAccessor(buf);");
- javaWriter.println(" }");
- javaWriter.println();
+ if( !cfg.manuallyImplement(JavaConfiguration.canonicalStructFieldSymbol(containingJTypeName, "size")) ) {
+ javaWriter.println(" public static int size() {");
+ javaWriter.println(" return "+containingJTypeName+"_size[mdIdx];");
+ javaWriter.println(" }");
+ javaWriter.println();
+ }
+ if( !cfg.manuallyImplement(JavaConfiguration.canonicalStructFieldSymbol(containingJTypeName, "create")) ) {
+ javaWriter.println(" public static " + containingJTypeName + " create() {");
+ javaWriter.println(" return create(Buffers.newDirectByteBuffer(size()));");
+ javaWriter.println(" }");
+ javaWriter.println();
+ javaWriter.println(" public static " + containingJTypeName + " create(java.nio.ByteBuffer buf) {");
+ javaWriter.println(" return new " + containingJTypeName + "(buf);");
+ javaWriter.println(" }");
+ javaWriter.println();
+ }
+ if( !cfg.manuallyImplement(JavaConfiguration.canonicalStructFieldSymbol(containingJTypeName, containingJTypeName)) ) {
+ javaWriter.println(" " + containingJTypeName + "(java.nio.ByteBuffer buf) {");
+ javaWriter.println(" md = MachineDescription.StaticConfig.values()[mdIdx].md;");
+ javaWriter.println(" accessor = new StructAccessor(buf);");
+ javaWriter.println(" }");
+ javaWriter.println();
+ }
javaWriter.println(" public java.nio.ByteBuffer getBuffer() {");
javaWriter.println(" return accessor.getBuffer();");
javaWriter.println(" }");
@@ -1129,7 +1139,7 @@ public class JavaEmitter implements GlueEmitter {
if( fieldTypeNativeSizeFixed ) {
javaWriter.println(" accessor.set" + capJavaTypeName + "At(" + fieldName+"_offset[mdIdx], val);");
} else {
- javaWriter.println(" accessor.set" + capJavaTypeName + "At(" + fieldName+"_offset[mdIdx], val, MachineDescriptionRuntime.getStatic().md."+sizeDenominator+"SizeInBytes());");
+ javaWriter.println(" accessor.set" + capJavaTypeName + "At(" + fieldName+"_offset[mdIdx], val, md."+sizeDenominator+"SizeInBytes());");
}
javaWriter.println(" return this;");
javaWriter.println(" }");
@@ -1143,7 +1153,7 @@ public class JavaEmitter implements GlueEmitter {
if( fieldTypeNativeSizeFixed ) {
javaWriter.println("accessor.get" + capJavaTypeName + "At(" + fieldName+"_offset[mdIdx]);");
} else {
- javaWriter.println("accessor.get" + capJavaTypeName + "At(" + fieldName+"_offset[mdIdx], MachineDescriptionRuntime.getStatic().md."+sizeDenominator+"SizeInBytes());");
+ javaWriter.println("accessor.get" + capJavaTypeName + "At(" + fieldName+"_offset[mdIdx], md."+sizeDenominator+"SizeInBytes());");
}
javaWriter.println(" }");
} else {
@@ -1240,7 +1250,9 @@ public class JavaEmitter implements GlueEmitter {
writer.print(")");
}
- private void generateOffsetAndSizeArrays(final PrintWriter writer, final String prefix, final String fieldName, final Type fieldType, final Field field, final String postfix) {
+ private void generateOffsetAndSizeArrays(final PrintWriter writer, final String prefix,
+ final String fieldName, final Type fieldType,
+ final Field field, final String postfix) {
if(null != field) {
writer.print(prefix+"private static final int[] "+fieldName+"_offset = new int[] { ");
for( int i=0; i < machDescTargetConfigs.length; i++ ) {
@@ -1668,7 +1680,7 @@ public class JavaEmitter implements GlueEmitter {
if( baseCElemNativeSizeFixed ) {
javaWriter.println(" accessor.set" + baseJElemTypeNameC + "At(" + fieldName+"_offset[mdIdx], val);");
} else {
- javaWriter.println(" accessor.set" + baseJElemTypeNameC + "At(" + fieldName+"_offset[mdIdx], val, MachineDescriptionRuntime.getStatic().md."+baseCElemSizeDenominator+"SizeInBytes());");
+ javaWriter.println(" accessor.set" + baseJElemTypeNameC + "At(" + fieldName+"_offset[mdIdx], val, md."+baseCElemSizeDenominator+"SizeInBytes());");
}
javaWriter.println(" return this;");
javaWriter.println(" }");
@@ -1831,7 +1843,7 @@ public class JavaEmitter implements GlueEmitter {
if( baseCElemNativeSizeFixed ) {
javaWriter.println(" return accessor.get" + baseJElemTypeNameC + "At(" + fieldName+"_offset[mdIdx]);");
} else {
- javaWriter.println(" return accessor.get" + baseJElemTypeNameC + "At(" + fieldName+"_offset[mdIdx], MachineDescriptionRuntime.getStatic().md."+baseCElemSizeDenominator+"SizeInBytes());");
+ javaWriter.println(" return accessor.get" + baseJElemTypeNameC + "At(" + fieldName+"_offset[mdIdx], md."+baseCElemSizeDenominator+"SizeInBytes());");
}
javaWriter.println(" }");
javaWriter.println();