Skip to content

Commit

Permalink
Bug 1134 - Utilize AliasedSymbol where required in *Configuration; Cl…
Browse files Browse the repository at this point in the history
…arify ProcAddressEmitter criteria
  • Loading branch information
sgothel committed Mar 6, 2015
1 parent 54dcf42 commit 4183867
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 68 deletions.
9 changes: 6 additions & 3 deletions make/build-test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,8 @@ chmod 644 ${results}/* \${line.separator}
includeRefid="stub.includes.fileset.test"
emitter="com.jogamp.gluegen.JavaEmitter"
dumpCPP="false"
debug="true">
debug="true"
logLevel="WARNING">
<classpath refid="gluegen.classpath" />
</gluegen>

Expand All @@ -553,7 +554,8 @@ chmod 644 ${results}/* \${line.separator}
includeRefid="stub.includes.fileset.test"
emitter="com.jogamp.gluegen.JavaEmitter"
dumpCPP="false"
debug="false">
debug="false"
logLevel="INFO">
<classpath refid="gluegen.classpath" />
</gluegen>

Expand All @@ -564,7 +566,8 @@ chmod 644 ${results}/* \${line.separator}
includeRefid="stub.includes.fileset.test"
emitter="com.jogamp.gluegen.procaddress.ProcAddressEmitter"
dumpCPP="false"
debug="false">
debug="false"
logLevel="INFO">
<classpath refid="gluegen.classpath" />
</gluegen>
</target>
Expand Down
52 changes: 28 additions & 24 deletions src/java/com/jogamp/gluegen/JavaConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -813,27 +813,32 @@ public final boolean shouldIgnoreInInterface(final String symbol) {
public boolean shouldIgnoreInInterface(final AliasedSymbol symbol) {
return shouldIgnoreInInterface_Int(symbol);
}
private static boolean oneInSet(final Set<String> ignoreSymbols, final Set<String> symbols) {
if( null != ignoreSymbols && ignoreSymbols.size() > 0 &&
public static <K,V> V oneInMap(final Map<K, V> map, final Set<K> symbols) {
if( null != map && map.size() > 0 &&
null != symbols && symbols.size() > 0 ) {
for(final String sym : symbols) {
if( ignoreSymbols.contains( sym ) ) {
return true;
for(final K sym : symbols) {
final V v = map.get(sym);
if( null != v ) {
return v;
}
}
}
return false;
return null;
}
/** private static boolean allInSet(final Set<String> ignoreSymbols, final Set<String> symbols) {
if( null != ignoreSymbols && ignoreSymbols.size() > 0 &&
null != symbols && symbols.size() > 0 ) {
return ignoreSymbols.containsAll(symbols);
public static <K> boolean oneInSet(final Set<K> set1, final Set<K> set2) {
if( null != set1 && set1.size() > 0 &&
null != set2 && set2.size() > 0 ) {
for(final K sym : set2) {
if( set1.contains( sym ) ) {
return true;
}
}
}
return false;
} */
private static boolean onePatternMatch(final Pattern ignoreRegexp, final Set<String> symbols) {
if( null != ignoreRegexp && null != symbols && symbols.size() > 0 ) {
for(final String sym : symbols) {
}
private static boolean onePatternMatch(final Pattern ignoreRegexp, final Set<String> set) {
if( null != ignoreRegexp && null != set && set.size() > 0 ) {
for(final String sym : set) {
final Matcher matcher = ignoreRegexp.matcher(sym);
if (matcher.matches()) {
return true;
Expand Down Expand Up @@ -948,17 +953,16 @@ protected final boolean shouldIgnoreInImpl_Int(final AliasedSymbol symbol) {
/** Returns true if this function should be given a body which
throws a run-time exception with an "unimplemented" message
during glue code generation. */
public boolean isUnimplemented(final String symbol) {
// Ok, the slow case. We need to check the entire table, in case the table
// contains an regular expression that matches the symbol.
for (final Pattern regexp : unimplemented) {
final Matcher matcher = regexp.matcher(symbol);
if (matcher.matches()) {
return true;
public boolean isUnimplemented(final AliasedSymbol symbol) {
// Ok, the slow case. We need to check the entire table, in case the table
// contains an regular expression that matches the symbol.
for (final Pattern unimplRegexp : unimplemented) {
final Matcher matcher = unimplRegexp.matcher(symbol.getName());
if ( matcher.matches() || onePatternMatch(unimplRegexp, symbol.getAliasedNames()) ) {
return true;
}
}
}

return false;
return false;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/java/com/jogamp/gluegen/JavaEmitter.java
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ protected void generatePublicEmitters(final MethodBinding binding, final List<Fu
// It's possible we may not need a body even if signatureOnly is
// set to false; for example, if the routine doesn't take any
// arrays or buffers as arguments
final boolean isUnimplemented = cfg.isUnimplemented(binding.getName());
final boolean isUnimplemented = cfg.isUnimplemented(binding.getCSymbol());
final List<String> prologue = cfg.javaPrologueForMethod(binding, false, false);
final List<String> epilogue = cfg.javaEpilogueForMethod(binding, false, false);
final boolean needsBody = isUnimplemented ||
Expand Down Expand Up @@ -633,7 +633,7 @@ protected void generatePrivateEmitters(final MethodBinding binding,
cfg.javaPrologueForMethod(binding, false, false) != null ||
cfg.javaEpilogueForMethod(binding, false, false) != null ;

if ( !cfg.isUnimplemented( binding.getName() ) ) {
if ( !cfg.isUnimplemented( binding.getCSymbol() ) ) {
if( !requiresStaticInitialization ) {
requiresStaticInitialization = binding.signatureRequiresStaticInitialization();
if( requiresStaticInitialization ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ public String getName() {
emitter.getConfiguration()
);

if( needsLocalTypedef && !callThroughProcAddress ) {
throw new IllegalArgumentException("needsLocalTypedef=true, but callThroughProcAddress=false for "+methodToWrap.toString());
}

if (methodToWrap.getReturnValueCapacityExpression() != null) {
setReturnValueCapacityExpression(methodToWrap.getReturnValueCapacityExpression());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@
*/
package com.jogamp.gluegen.procaddress;

import static java.util.logging.Level.INFO;

import com.jogamp.gluegen.JavaConfiguration;
import com.jogamp.gluegen.cgram.types.AliasedSymbol;

import java.io.*;
import java.text.*;
import java.util.*;
Expand Down Expand Up @@ -269,8 +273,15 @@ public String tableClassName() {
return tableClassName;
}

public boolean skipProcAddressGen(final String name) {
return skipProcAddressGen.contains(name);
public boolean skipProcAddressGen(final AliasedSymbol symbol) {
if ( skipProcAddressGen.contains( symbol.getName() ) ||
oneInSet(skipProcAddressGen, symbol.getAliasedNames())
)
{
LOG.log(INFO, "Skip ProcAddress: {0}", symbol.getAliasedString());
return true;
}
return false;
}

public boolean isForceProcAddressGen4All() {
Expand Down Expand Up @@ -298,9 +309,25 @@ public String convertToFunctionPointerName(final String funcName) {
return procAddressNameConverter.convert(funcName);
}

public boolean forceProcAddressGen(final String funcName) {
return forceProcAddressGen4All || forceProcAddressGenSet.contains(funcName);
public boolean forceProcAddressGen(final AliasedSymbol symbol) {
if( forceProcAddressGen4All ) {
if(!forceProcAddressGen4AllOnce) {
forceProcAddressGen4AllOnce = true;
LOG.log(INFO, "Force ALL ProcAddress");
}
return true;
}

if ( forceProcAddressGenSet.contains( symbol.getName() ) ||
oneInSet(forceProcAddressGenSet, symbol.getAliasedNames())
)
{
LOG.log(INFO, "Force ProcAddress: {0}", symbol.getAliasedString());
return true;
}
return false;
}
private static boolean forceProcAddressGen4AllOnce = false;

public void addForceProcAddressGen(final String funcName) {
forceProcAddressGen.add(funcName);
Expand All @@ -311,11 +338,15 @@ public void addLocalProcAddressCallingConvention(final String funcName, final St
localProcAddressCallingConventionMap.put(funcName, callingConvention);
}

public String getLocalProcAddressCallingConvention(final String funcName) {
if (isLocalProcAddressCallingConvention4All()) {
public String getLocalProcAddressCallingConvention(final AliasedSymbol symbol) {
if ( isLocalProcAddressCallingConvention4All() ) {
return getLocalProcAddressCallingConvention4All();
}
return localProcAddressCallingConventionMap.get(funcName);
final String res = localProcAddressCallingConventionMap.get(symbol.getName());
if( null != res ) {
return res;
}
return oneInMap(localProcAddressCallingConventionMap, symbol.getAliasedNames());
}

public boolean isLocalProcAddressCallingConvention4All() {
Expand Down
75 changes: 43 additions & 32 deletions src/java/com/jogamp/gluegen/procaddress/ProcAddressEmitter.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ protected List<? extends FunctionEmitter> generateMethodBindingEmitters(final Se
}

protected boolean needsModifiedEmitters(final FunctionSymbol sym) {
if (!needsProcAddressWrapper(sym) || getConfig().isUnimplemented(getAliasedSymName(sym))) {
if ( !callThroughProcAddress(sym) || getConfig().isUnimplemented(sym) ) {
return false;
} else {
return true;
}

return true;
}

private List<? extends FunctionEmitter> generateMethodBindingEmittersImpl(final Set<MethodBinding> methodBindingSet, final FunctionSymbol sym) throws Exception {
Expand All @@ -138,15 +138,19 @@ private List<? extends FunctionEmitter> generateMethodBindingEmittersImpl(final
return defaultEmitters;
}

// Don't do anything special if this symbol doesn't require
// modifications
if (!needsModifiedEmitters(sym)) {
final boolean callThroughProcAddress = callThroughProcAddress(sym);
final boolean isUnimplemented = getConfig().isUnimplemented(sym);

// Don't do anything special if this symbol doesn't require modifications
if( !callThroughProcAddress || isUnimplemented ) {
LOG.log(Level.INFO, "genModProcAddrEmitter: SKIP, not needed: callThrough {0}, isUnimplemented {1}: {2}",
callThroughProcAddress, isUnimplemented, sym.getAliasedString());
return defaultEmitters;
}

final ArrayList<FunctionEmitter> modifiedEmitters = new ArrayList<FunctionEmitter>(defaultEmitters.size());

if (needsProcAddressWrapper(sym)) {
if ( callThroughProcAddress ) {
if (getProcAddressConfig().emitProcAddressTable()) {
// emit an entry in the GL proc address table for this method.
emitProcAddressTableEntryForString(getAliasedSymName(sym));
Expand Down Expand Up @@ -196,7 +200,7 @@ protected void fixSecurityModifiers(final JavaMethodBindingEmitter javaEmitter)

protected void generateModifiedEmitters(final JavaMethodBindingEmitter baseJavaEmitter, final List<FunctionEmitter> emitters) {
// See whether we need a proc address entry for this one
final boolean callThroughProcAddress = needsProcAddressWrapper(baseJavaEmitter.getBinding().getCSymbol());
final boolean callThroughProcAddress = callThroughProcAddress(baseJavaEmitter.getBinding().getCSymbol());

// If this emitter doesn't have a body (i.e., is a direct native
// call with no intervening argument processing), we need to force
Expand Down Expand Up @@ -245,12 +249,15 @@ protected void generateModifiedEmitters(final CMethodBindingEmitter baseCEmitter
final FunctionSymbol cSymbol = baseCEmitter.getBinding().getCSymbol();

// See whether we need a proc address entry for this one
final boolean callThroughProcAddress = needsProcAddressWrapper(cSymbol);
final boolean forceProcAddress = getProcAddressConfig().forceProcAddressGen(cSymbol.getName());
final boolean needsLocalTypedef = getProcAddressConfig().forceProcAddressGen(cSymbol) ||
!hasFunctionPointerTypedef(cSymbol);
final boolean callThroughProcAddress = needsLocalTypedef || callThroughProcAddress(cSymbol);
LOG.log(Level.INFO, "genModProcAddrEmitter: needsTypedef {0}, callThrough {1}: {2}",
needsLocalTypedef, callThroughProcAddress, cSymbol.getAliasedString());

String forcedCallingConvention = null;
if (forceProcAddress) {
forcedCallingConvention = getProcAddressConfig().getLocalProcAddressCallingConvention(cSymbol.getName());
if (needsLocalTypedef) {
forcedCallingConvention = getProcAddressConfig().getLocalProcAddressCallingConvention(cSymbol);
}
// 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
Expand All @@ -260,7 +267,7 @@ protected void generateModifiedEmitters(final CMethodBindingEmitter baseCEmitter
// extra final argument, which is the address (the OpenGL procedure
// address) of the function it needs to call
final ProcAddressCMethodBindingEmitter res = new ProcAddressCMethodBindingEmitter(
baseCEmitter, callThroughProcAddress, forceProcAddress, forcedCallingConvention, this);
baseCEmitter, callThroughProcAddress, needsLocalTypedef, forcedCallingConvention, this);

final MessageFormat exp = baseCEmitter.getReturnValueCapacityExpression();
if (exp != null) {
Expand All @@ -277,26 +284,30 @@ private String getAliasedSymName(final FunctionSymbol sym) {
return symName;
}

protected boolean needsProcAddressWrapper(final FunctionSymbol sym) {
final String symName = getAliasedSymName(sym);

final ProcAddressConfiguration config = getProcAddressConfig();

// We should only generate code to call through a function pointer
// if the symbol has an associated function pointer typedef.
final String funcPointerTypedefName = getFunctionPointerTypedefName(sym);
boolean shouldWrap = typedefDictionary.containsKey(funcPointerTypedefName);
//System.err.println(funcPointerTypedefName + " defined: " + shouldWrap);

if (config.skipProcAddressGen(symName)) {
shouldWrap = false;
}

if (config.forceProcAddressGen(symName)) {
shouldWrap = true;
protected boolean callThroughProcAddress(final FunctionSymbol sym) {
final ProcAddressConfiguration cfg = getProcAddressConfig();
boolean res = false;
int mode = 0;
if (cfg.forceProcAddressGen(sym)) {
res = true;
mode = 1;
} else {
if (cfg.skipProcAddressGen(sym)) {
res = false;
mode = 2;
} else {
res = hasFunctionPointerTypedef(sym);
mode = 3;
}
}

return shouldWrap;
LOG.log(Level.INFO, "callThroughProcAddress: {0} [m {1}]: {2}", res, mode, sym.getAliasedString());
return res;
}
protected boolean hasFunctionPointerTypedef(final FunctionSymbol sym) {
final String funcPointerTypedefName = getFunctionPointerTypedefName(sym);
final boolean res = typedefDictionary.containsKey(funcPointerTypedefName);
LOG.log(Level.INFO, "hasFunctionPointerTypedef: {0}: {1}", res, sym.getAliasedString());
return res;
}

protected void beginProcAddressTable() throws Exception {
Expand Down

0 comments on commit 4183867

Please sign in to comment.