Skip to content

Commit dc500b2

Browse files
committed
Enhanced linalg kernels factory.
Added -libFile switch and enhanced non-lib files extraction in LibraryExtractor Added very simple VectorAdd demo program
1 parent ac85895 commit dc500b2

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

jnaerator-runtime/src/main/java/com/ochafik/lang/jnaerator/runtime/LibraryExtractor.java

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ This file is part of JNAerator (http://jnaerator.googlecode.com/).
3636
import java.lang.reflect.Method;
3737
import java.lang.reflect.Proxy;
3838
import java.util.Arrays;
39+
import java.util.HashSet;
40+
import java.util.Set;
3941

4042
/**
4143
* @see http://landonf.bikemonkey.org/static/soylatte/
@@ -84,16 +86,28 @@ public static String getLibraryPath(String libraryName, boolean extractAllLibrar
8486
//ClassLoader cl = LibraryExtractor.class.getClassLoader();
8587
String prefix = "(?i)" + (Platform.isWindows() || Platform.isWindowsCE() ? "" : "lib") + libraryName + "[^A-Za-z_].*";
8688
String libsuffix = "(?i).*\\.(so|dll|dylib|jnilib)";
87-
String othersuffix = "(?i).*\\.(pdb)";
89+
//String othersuffix = "(?i).*\\.(pdb)";
8890

8991
URL sourceURL = null;
9092
List<URL> otherURLs = new ArrayList<URL>();
9193

9294

9395
String arch = getCurrentOSAndArchString();
9496
//System.out.println("libURL = " + libURL);
95-
List<URL> list = URLUtils.listFiles(URLUtils.getResource(cl, "libraries/" + arch), null);
96-
if (list.isEmpty()) {
97+
List<URL> list = URLUtils.listFiles(URLUtils.getResource(cl, "libraries/" + arch), null),
98+
noArchList = URLUtils.listFiles(URLUtils.getResource(cl, "libraries/noarch"), null);
99+
100+
Set<String> names = new HashSet<String>();
101+
for (URL url : list) {
102+
String name = getFileName(url);
103+
names.add(name);
104+
}
105+
for (URL url : noArchList) {
106+
String name = getFileName(url);
107+
if (names.add(name))
108+
list.add(url);
109+
}
110+
/*if (list.isEmpty()) {
97111
for (URL u : URLUtils.listFiles(URLUtils.getResource(cl, "libraries"), null)) {
98112
String f = u.getFile();
99113
int i = f.lastIndexOf('/');
@@ -105,17 +119,17 @@ public static String getLibraryPath(String libraryName, boolean extractAllLibrar
105119
}
106120
}
107121
108-
}
122+
}*/
109123
for (File f : new File(".").listFiles())
110124
if (f.isFile())
111125
list.add(f.toURI().toURL());
112126

113127
for (URL url : list) {
114-
String fileName = new File(url.toString()).getName();
115-
boolean pref = fileName.matches(prefix), suff = fileName.matches(libsuffix);
128+
String name = getFileName(url);
129+
boolean pref = name.matches(prefix), suff = name.matches(libsuffix);
116130
if (pref && suff)
117131
sourceURL = url;
118-
else if (suff || fileName.matches(othersuffix))
132+
else //if (suff || fileName.matches(othersuffix))
119133
otherURLs.add(url);
120134
}
121135
List<File> files = new ArrayList<File>();
@@ -250,4 +264,8 @@ public static final Object getLibrary(String name, String path, final Class libr
250264
return shouldTraceCalls(name) ?
251265
LibraryExtractor.getTracingLibrary(original, libraryClass) : original;
252266
}
267+
268+
private static String getFileName(URL url) {
269+
return new File(url.getFile()).getName();
270+
}
253271
}

jnaerator/src/main/java/com/ochafik/lang/jnaerator/JNAerator.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,9 @@ List<String> parsed(ParsedArg a) throws Exception {
352352
break;
353353
case Runtime:
354354
config.runtime = a.getEnumParam(0, JNAeratorConfig.Runtime.class);
355+
break;
356+
case LibFile:
357+
config.addLibraryFile(a.getFileParam(0), arch);
355358
break;
356359
case File:
357360
return parsedFile(a);
@@ -462,7 +465,9 @@ List<String> parsed(ParsedArg a) throws Exception {
462465
case IncludeArgs:
463466
return parsedArgsInclude(a);
464467
case Arch:
465-
arch = a.getStringParam(0);
468+
arch = a.getStringParam(0).trim();
469+
if (arch.length() == 0)
470+
arch = null;
466471
break;
467472

468473
}

jnaerator/src/main/java/com/ochafik/lang/jnaerator/JNAeratorCommandLineArgs.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ public enum OptionDef {
160160
NoJAR( "(?i)-noJar", "Do not create an output JAR"),
161161
// EnableCPlusPlus( "-cppInstanceMethods", "Enable experimental C++ instance methods wrapping"),
162162
NoLibBundle( "(?i)-noLibBundle", "Do not bundle libraries in output JAR"),
163-
MaxConstructedFields(
163+
LibFile( "-libFile", "Bundle the provided file with the JNAerated JAR so that it is extracted with the library when it is first used.", new ArgDef(Type.ExistingFile, "resourceFile")),
164+
MaxConstructedFields(
164165
"-maxConstrFields", "Maximum number of fields allowed for structure fields constructors. If a struct has more fields, it will only get a default constructor.", new ArgDef(Type.Int, "fieldCount")),
165166
CPlusPlusGen( "-genCPlusPlus", "[Experimental, Not working at all] Generate C++ classes.");
166167

0 commit comments

Comments
 (0)