From a3f2d08801c5a54048faca52f422bcededf81b2a Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sun, 1 Feb 2015 05:21:39 +0100 Subject: 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. --- src/java/com/jogamp/gluegen/JavaConfiguration.java | 40 +++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'src/java/com/jogamp/gluegen/JavaConfiguration.java') 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 structPackages = new HashMap(); private final List customCCode = new ArrayList(); private final List forcedStructs = new ArrayList(); + private final Map structMachineDescriptorIndex = new HashMap(); private final Map returnValueCapacities = new HashMap(); private final Map returnValueLengths = new HashMap(); private final Map> temporaryCVariableDeclarations = new HashMap>(); @@ -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. + *

+ * 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. + *

+ */ public boolean manuallyImplement(final String functionName) { return manuallyImplement.contains(functionName); } @@ -636,6 +644,20 @@ public class JavaConfiguration { return forcedStructs; } + /** + * Returns a MessageFormat string of the Java code defining {@code mdIdx}, + * i.e. the index of the static MachineDescriptor index for structs. + *

+ * If undefined, code generation uses the default expression: + *

+   *     private static final int mdIdx = MachineDescriptionRuntime.getStatic().ordinal();
+   * 
+ *

+ */ + 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 @@ -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(); -- cgit v1.2.3