summaryrefslogtreecommitdiffstats
path: root/src/java/com/sun/gluegen
diff options
context:
space:
mode:
authorMichael Bien <[email protected]>2010-06-20 04:34:12 +0200
committerMichael Bien <[email protected]>2010-06-20 04:34:12 +0200
commitae37ac16a13aa62cd6e7a6ff0346403c5aa6b3e5 (patch)
tree13d7fd843bd0ea7de314c120513db94c79e01ffb /src/java/com/sun/gluegen
parent29072eee5784035d1284d3b9625450681fca25b3 (diff)
another round of ProcAddressTable refactoring.
- moved getAddressFor() from generated table to ProcAddressTable - added initEntry() to e.g. eagerly initialize one single entry (e.g. clGetExtensionFunctionAddress which must be available first) - several utility methods mostly usefull for debugging - cleanup
Diffstat (limited to 'src/java/com/sun/gluegen')
-rwxr-xr-xsrc/java/com/sun/gluegen/procaddress/ProcAddressEmitter.java76
1 files changed, 18 insertions, 58 deletions
diff --git a/src/java/com/sun/gluegen/procaddress/ProcAddressEmitter.java b/src/java/com/sun/gluegen/procaddress/ProcAddressEmitter.java
index aa71495..9094f14 100755
--- a/src/java/com/sun/gluegen/procaddress/ProcAddressEmitter.java
+++ b/src/java/com/sun/gluegen/procaddress/ProcAddressEmitter.java
@@ -209,12 +209,16 @@ public class ProcAddressEmitter extends JavaEmitter {
}
protected void generateModifiedEmitters(CMethodBindingEmitter baseCEmitter, List<FunctionEmitter> emitters) {
+
+ FunctionSymbol cSymbol = baseCEmitter.getBinding().getCSymbol();
+
// See whether we need a proc address entry for this one
- boolean callThroughProcAddress = needsProcAddressWrapper(baseCEmitter.getBinding().getCSymbol());
- boolean forceProcAddress = getProcAddressConfig().forceProcAddressGen(baseCEmitter.getBinding().getCSymbol().getName());
+ boolean callThroughProcAddress = needsProcAddressWrapper(cSymbol);
+ boolean forceProcAddress = getProcAddressConfig().forceProcAddressGen(cSymbol.getName());
+
String forcedCallingConvention = null;
if (forceProcAddress) {
- forcedCallingConvention = getProcAddressConfig().getLocalProcAddressCallingConvention(baseCEmitter.getBinding().getCSymbol().getName());
+ forcedCallingConvention = getProcAddressConfig().getLocalProcAddressCallingConvention(cSymbol.getName());
}
// Note that we don't care much about the naming of the C argument
// variables so to keep things simple we ignore the buffer object
@@ -223,11 +227,9 @@ public class ProcAddressEmitter extends JavaEmitter {
// The C-side JNI binding for this particular function will have an
// extra final argument, which is the address (the OpenGL procedure
// address) of the function it needs to call
- ProcAddressCMethodBindingEmitter res = new ProcAddressCMethodBindingEmitter(baseCEmitter,
- callThroughProcAddress,
- forceProcAddress,
- forcedCallingConvention,
- this);
+ ProcAddressCMethodBindingEmitter res = new ProcAddressCMethodBindingEmitter(
+ baseCEmitter, callThroughProcAddress, forceProcAddress, forcedCallingConvention, this);
+
MessageFormat exp = baseCEmitter.getReturnValueCapacityExpression();
if (exp != null) {
res.setReturnValueCapacityExpression(exp);
@@ -289,9 +291,7 @@ public class ProcAddressEmitter extends JavaEmitter {
if (implPackageName == null) {
implPackageName = getImplPackageName();
}
- String jImplRoot =
- getJavaOutputDir() + File.separator
- + CodeGenUtils.packageAsPath(implPackageName);
+ String jImplRoot = getJavaOutputDir() + File.separator + CodeGenUtils.packageAsPath(implPackageName);
tableWriter = openFile(jImplRoot + File.separator + tableClassName + ".java");
emittedTableEntries = new HashSet<String>();
@@ -303,24 +303,14 @@ public class ProcAddressEmitter extends JavaEmitter {
for (String imporT : getConfig().imports()) {
tableWriter.println("import " + imporT + ";");
}
+ tableWriter.println("import " + ProcAddressTable.class.getName() + ";");
tableWriter.println();
tableWriter.println("/**");
- tableWriter.println(" * This table is a cache of pointers to the dynamically-linkable C");
- tableWriter.println(" * functions this autogenerated Java binding has exposed. Some");
- tableWriter.println(" * libraries such as OpenGL, OpenAL and others define function pointer");
- tableWriter.println(" * signatures rather than statically linkable entry points for the");
- tableWriter.println(" * purposes of being able to query at run-time whether a particular");
- tableWriter.println(" * extension is available. This table acts as a cache of these");
- tableWriter.println(" * function pointers. Each function pointer is typically looked up at");
- tableWriter.println(" * run-time by a platform-dependent mechanism such as dlsym(),");
- tableWriter.println(" * wgl/glXGetProcAddress(), or alGetProcAddress(). The associated");
- tableWriter.println(" * autogenerated Java and C code accesses the fields in this table to");
- tableWriter.println(" * call the various functions. If the field containing the function");
- tableWriter.println(" * pointer is 0, the function is considered to be unavailable and can");
- tableWriter.println(" * not be called.");
+ tableWriter.println(" * This table is a cache of pointers to the dynamically-linkable C library.");
+ tableWriter.println(" * @see " + ProcAddressTable.class.getSimpleName());
tableWriter.println(" */");
- tableWriter.println("public class " + tableClassName + " extends "+ ProcAddressTable.class.getName() + " {");
+ tableWriter.println("public class " + tableClassName + " extends "+ ProcAddressTable.class.getSimpleName() + " {");
tableWriter.println();
for (String string : getProcAddressConfig().getForceProcAddressGen()) {
@@ -336,39 +326,9 @@ public class ProcAddressEmitter extends JavaEmitter {
}
protected void endProcAddressTable() throws Exception {
- PrintWriter w = tableWriter;
-
- w.println(" /**");
- w.println(" * This is a convenience method to get (by name) the native function");
- w.println(" * pointer for a given function. It lets you avoid having to");
- w.println(" * manually compute the &quot;" + PROCADDRESS_VAR_PREFIX + " + ");
- w.println(" * &lt;functionName&gt;&quot; member variable name and look it up via");
- w.println(" * reflection; it also will throw an exception if you try to get the");
- w.println(" * address of an unknown function, or one that is statically linked");
- w.println(" * and therefore does not have a function pointer in this table.");
- w.println(" *");
- w.println(" * @throws RuntimeException if the function pointer was not found in");
- w.println(" * this table, either because the function was unknown or because");
- w.println(" * it was statically linked.");
- w.println(" */");
- w.println(" public long getAddressFor(String functionName) {");
- w.println(" String addressFieldName = PROCADDRESS_VAR_PREFIX + functionName;");
- w.println(" try { ");
- w.println(" java.lang.reflect.Field addressField = getClass().getField(addressFieldName);");
- w.println(" return addressField.getLong(this);");
- w.println(" } catch (Exception e) {");
- w.println(" // The user is calling a bogus function or one which is not");
- w.println(" // runtime linked");
- w.println(" throw new RuntimeException(");
- w.println(" \"WARNING: Address query failed for \\\"\" + functionName +");
- w.println(" \"\\\"; it's either statically linked or is not a known \" +");
- w.println(" \"function\", e);");
- w.println(" } ");
- w.println(" }");
-
- w.println("} // end of class " + tableClassName);
- w.flush();
- w.close();
+ tableWriter.println("} // end of class " + tableClassName);
+ tableWriter.flush();
+ tableWriter.close();
}
protected void emitProcAddressTableEntryForString(String str) {