native interface for WALA
This commit is contained in:
parent
d32b2a29ad
commit
7c476eac3d
|
@ -39,7 +39,7 @@ import com.ibm.wala.classLoader.IMethod;
|
||||||
import com.ibm.wala.classLoader.Module;
|
import com.ibm.wala.classLoader.Module;
|
||||||
import com.ibm.wala.classLoader.SourceModule;
|
import com.ibm.wala.classLoader.SourceModule;
|
||||||
import com.ibm.wala.classLoader.SourceURLModule;
|
import com.ibm.wala.classLoader.SourceURLModule;
|
||||||
import com.ibm.wala.ipa.callgraph.AnalysisCache;
|
import com.ibm.wala.ipa.callgraph.IAnalysisCacheView;
|
||||||
import com.ibm.wala.ipa.callgraph.AnalysisScope;
|
import com.ibm.wala.ipa.callgraph.AnalysisScope;
|
||||||
import com.ibm.wala.ipa.callgraph.CallGraph;
|
import com.ibm.wala.ipa.callgraph.CallGraph;
|
||||||
import com.ibm.wala.ipa.callgraph.Entrypoint;
|
import com.ibm.wala.ipa.callgraph.Entrypoint;
|
||||||
|
@ -232,7 +232,7 @@ public class JSCallGraphBuilderUtil extends com.ibm.wala.cast.js.ipa.callgraph.J
|
||||||
Iterable<Entrypoint> roots = makeScriptRoots(cha);
|
Iterable<Entrypoint> roots = makeScriptRoots(cha);
|
||||||
JSAnalysisOptions options = makeOptions(scope, cha, roots);
|
JSAnalysisOptions options = makeOptions(scope, cha, roots);
|
||||||
options.setHandleCallApply(builderType.handleCallApply());
|
options.setHandleCallApply(builderType.handleCallApply());
|
||||||
AnalysisCache cache = makeCache(irFactory);
|
IAnalysisCacheView cache = makeCache(irFactory);
|
||||||
JSCFABuilder builder = new JSZeroOrOneXCFABuilder(cha, options, cache, null, null, ZeroXInstanceKeys.ALLOCATIONS,
|
JSCFABuilder builder = new JSZeroOrOneXCFABuilder(cha, options, cache, null, null, ZeroXInstanceKeys.ALLOCATIONS,
|
||||||
builderType.useOneCFA());
|
builderType.useOneCFA());
|
||||||
if(builderType.extractCorrelatedPairs())
|
if(builderType.extractCorrelatedPairs())
|
||||||
|
|
|
@ -21,7 +21,7 @@ import com.ibm.wala.cast.js.ipa.callgraph.JSCFABuilder;
|
||||||
import com.ibm.wala.cast.js.ipa.callgraph.JSCallGraphUtil;
|
import com.ibm.wala.cast.js.ipa.callgraph.JSCallGraphUtil;
|
||||||
import com.ibm.wala.cast.js.ipa.callgraph.JSZeroOrOneXCFABuilder;
|
import com.ibm.wala.cast.js.ipa.callgraph.JSZeroOrOneXCFABuilder;
|
||||||
import com.ibm.wala.cast.js.loader.JavaScriptLoaderFactory;
|
import com.ibm.wala.cast.js.loader.JavaScriptLoaderFactory;
|
||||||
import com.ibm.wala.ipa.callgraph.AnalysisCache;
|
import com.ibm.wala.ipa.callgraph.IAnalysisCacheView;
|
||||||
import com.ibm.wala.ipa.callgraph.AnalysisScope;
|
import com.ibm.wala.ipa.callgraph.AnalysisScope;
|
||||||
import com.ibm.wala.ipa.callgraph.CallGraph;
|
import com.ibm.wala.ipa.callgraph.CallGraph;
|
||||||
import com.ibm.wala.ipa.callgraph.Entrypoint;
|
import com.ibm.wala.ipa.callgraph.Entrypoint;
|
||||||
|
@ -50,7 +50,7 @@ public abstract class TestArgumentSensitivity extends TestJSCallGraphShape {
|
||||||
Iterable<Entrypoint> roots = JSCallGraphUtil.makeScriptRoots(cha);
|
Iterable<Entrypoint> roots = JSCallGraphUtil.makeScriptRoots(cha);
|
||||||
JSAnalysisOptions options = JSCallGraphUtil.makeOptions(scope, cha, roots);
|
JSAnalysisOptions options = JSCallGraphUtil.makeOptions(scope, cha, roots);
|
||||||
|
|
||||||
AnalysisCache cache = CAstCallGraphUtil.makeCache(new ArgumentSpecialization.ArgumentCountIRFactory(options.getSSAOptions()));
|
IAnalysisCacheView cache = CAstCallGraphUtil.makeCache(new ArgumentSpecialization.ArgumentCountIRFactory(options.getSSAOptions()));
|
||||||
|
|
||||||
JSCFABuilder builder = new JSZeroOrOneXCFABuilder(cha, options, cache, null, null, ZeroXInstanceKeys.ALLOCATIONS, false);
|
JSCFABuilder builder = new JSZeroOrOneXCFABuilder(cha, options, cache, null, null, ZeroXInstanceKeys.ALLOCATIONS, false);
|
||||||
builder.setContextSelector(new ArgumentSpecialization.ArgumentCountContextSelector(builder.getContextSelector()));
|
builder.setContextSelector(new ArgumentSpecialization.ArgumentCountContextSelector(builder.getContextSelector()));
|
||||||
|
|
|
@ -34,7 +34,7 @@ import com.ibm.wala.cfg.ControlFlowGraph;
|
||||||
import com.ibm.wala.cfg.IBasicBlock;
|
import com.ibm.wala.cfg.IBasicBlock;
|
||||||
import com.ibm.wala.classLoader.CallSiteReference;
|
import com.ibm.wala.classLoader.CallSiteReference;
|
||||||
import com.ibm.wala.classLoader.IMethod;
|
import com.ibm.wala.classLoader.IMethod;
|
||||||
import com.ibm.wala.ipa.callgraph.AnalysisCache;
|
import com.ibm.wala.ipa.callgraph.IAnalysisCacheView;
|
||||||
import com.ibm.wala.ipa.callgraph.AnalysisOptions;
|
import com.ibm.wala.ipa.callgraph.AnalysisOptions;
|
||||||
import com.ibm.wala.ipa.callgraph.CGNode;
|
import com.ibm.wala.ipa.callgraph.CGNode;
|
||||||
import com.ibm.wala.ipa.callgraph.Context;
|
import com.ibm.wala.ipa.callgraph.Context;
|
||||||
|
@ -58,7 +58,7 @@ public class ArgumentSpecialization {
|
||||||
|
|
||||||
public static class ArgumentSpecializationContextIntepreter extends AstContextInsensitiveSSAContextInterpreter {
|
public static class ArgumentSpecializationContextIntepreter extends AstContextInsensitiveSSAContextInterpreter {
|
||||||
|
|
||||||
public ArgumentSpecializationContextIntepreter(AnalysisOptions options, AnalysisCache cache) {
|
public ArgumentSpecializationContextIntepreter(AnalysisOptions options, IAnalysisCacheView cache) {
|
||||||
super(options, cache);
|
super(options, cache);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<classpath>
|
<classpath>
|
||||||
|
<classpathentry kind="src" path="harness-src/java"/>
|
||||||
|
<classpathentry kind="src" path="harness-src/c"/>
|
||||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||||
<classpathentry kind="src" path="harness-src"/>
|
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
|
||||||
<classpathentry kind="output" path="bin"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|
|
@ -11,7 +11,8 @@
|
||||||
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
|
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
|
||||||
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
|
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
|
||||||
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/>
|
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/>
|
||||||
<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.launching.macosx.MacOSXType/1.7.0 25/"/>
|
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/>
|
||||||
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value=""/>
|
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value=""/>
|
||||||
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="com.ibm.wala.cast.test"/>
|
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="com.ibm.wala.cast.test"/>
|
||||||
|
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-ea -Djava.library.path=${project_loc:/com.ibm.wala.cast.test}/bin"/>
|
||||||
</launchConfiguration>
|
</launchConfiguration>
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
|
||||||
|
include Makefile.configuration
|
||||||
|
|
||||||
|
include ../../../com.ibm.wala.cast/source/c/Makefile.configuration
|
||||||
|
|
||||||
|
include ../../../com.ibm.wala.cast/source/c/Makefile.definitions
|
||||||
|
|
||||||
|
TEST_JNI_BRIDGE_HEADER = $(C_GENERATED)com_ibm_wala_cast_test_TestNativeTranslator.h
|
||||||
|
|
||||||
|
#
|
||||||
|
# rules
|
||||||
|
#
|
||||||
|
|
||||||
|
default: $(CAST_TEST_BIN)$(LIBPREFIX)xlator_test.$(DLLEXT)
|
||||||
|
|
||||||
|
$(TEST_JNI_BRIDGE_HEADER): $(CAST_TEST_BIN)com/ibm/wala/cast/test/TestNativeTranslator.class
|
||||||
|
$(JAVA_SDK)bin/javah -classpath "$(CAST_TEST_BIN)$(JAVAH_CLASS_PATH)" -d "$(JAVAH_GENERATED)" com.ibm.wala.cast.test.TestNativeTranslator
|
||||||
|
|
||||||
|
$(C_GENERATED)/smoke.o: $(TEST_JNI_BRIDGE_HEADER) smoke.cpp
|
||||||
|
$(CC) $(ALL_FLAGS) -o $@ -c smoke.cpp
|
||||||
|
|
||||||
|
$(CAST_TEST_BIN)$(LIBPREFIX)xlator_test.$(DLLEXT): $(C_GENERATED)/smoke.o
|
||||||
|
$(CC) $(CC_LDFLAGS) -Wl,-rpath -Wl,$(DOMO_AST_BIN) $(DOMO_AST_BIN)/$(LIBPREFIX)cast.$(DLLEXT) $^ -o $@
|
||||||
|
|
||||||
|
main: $(CAST_TEST_BIN)/smoke_main
|
||||||
|
|
||||||
|
$(CAST_TEST_BIN)/smoke_main: $(TEST_JNI_BRIDGE_HEADER) smoke_main.cpp
|
||||||
|
$(CC) $(ALL_FLAGS) -Wl,-rpath -Wl,$(DOMO_AST_BIN) $(DOMO_AST_BIN)/$(LIBPREFIX)cast.$(DLLEXT) -o $@ smoke_main.cpp
|
|
@ -0,0 +1 @@
|
||||||
|
CAST_TEST_BIN = /private/tmp/WALA/com.ibm.wala.cast.test/target/classes/
|
|
@ -0,0 +1,16 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
C_DIR=`realpath $0`
|
||||||
|
CAST_TEST_DIR=`realpath $C_DIR/../../..`
|
||||||
|
|
||||||
|
pushd $CAST_TEST_DIR/harness-src/c
|
||||||
|
|
||||||
|
cat > $CAST_TEST_DIR/harness-src/c/Makefile.configuration <<EOF
|
||||||
|
CAST_TEST_BIN = $CAST_TEST_DIR/target/classes/
|
||||||
|
EOF
|
||||||
|
|
||||||
|
make
|
||||||
|
|
||||||
|
make main
|
||||||
|
|
||||||
|
popd
|
|
@ -0,0 +1,20 @@
|
||||||
|
#include "CAstWrapper.h"
|
||||||
|
#include "com_ibm_wala_cast_test_TestNativeTranslator.h"
|
||||||
|
|
||||||
|
JNIEXPORT jobject JNICALL Java_com_ibm_wala_cast_test_TestNativeTranslator_inventAst
|
||||||
|
(JNIEnv *java_env, jclass cls, jobject ast)
|
||||||
|
{
|
||||||
|
TRY(exp, java_env)
|
||||||
|
|
||||||
|
CAstWrapper CAst(java_env, exp, ast);
|
||||||
|
THROW_ANY_EXCEPTION(exp);
|
||||||
|
|
||||||
|
return
|
||||||
|
CAst.makeNode(CAst.BINARY_EXPR,
|
||||||
|
CAst.OP_ADD,
|
||||||
|
CAst.makeConstant(1),
|
||||||
|
CAst.makeConstant(2));
|
||||||
|
|
||||||
|
CATCH()
|
||||||
|
return NULL;
|
||||||
|
}
|
|
@ -0,0 +1,51 @@
|
||||||
|
#include "launch.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <strings.h>
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
char buf[ strlen(argv[1]) + 1 ];
|
||||||
|
strcpy(buf, argv[1]);
|
||||||
|
|
||||||
|
printf("%s\n", buf);
|
||||||
|
|
||||||
|
JNIEnv *java_env = launch(buf);
|
||||||
|
|
||||||
|
jclass NativeTranslatorTest =
|
||||||
|
java_env->FindClass("com/ibm/wala/cast/test/TestNativeTranslator");
|
||||||
|
|
||||||
|
jmethodID testInit =
|
||||||
|
java_env->GetMethodID(NativeTranslatorTest, "<init>", "()V");
|
||||||
|
|
||||||
|
jobject test =
|
||||||
|
java_env->NewObject(NativeTranslatorTest, testInit);
|
||||||
|
|
||||||
|
jmethodID testAst =
|
||||||
|
java_env->GetMethodID(NativeTranslatorTest, "testNativeCAst", "()V");
|
||||||
|
|
||||||
|
java_env->CallVoidMethod(test, testAst);
|
||||||
|
if (java_env->ExceptionCheck()) {
|
||||||
|
jclass Object =
|
||||||
|
java_env->FindClass("java/lang/Object");
|
||||||
|
|
||||||
|
jmethodID testInit =
|
||||||
|
java_env->GetMethodID(NativeTranslatorTest, "<init>", "()V");
|
||||||
|
|
||||||
|
jmethodID toString =
|
||||||
|
java_env->GetMethodID(Object, "toString", "()Ljava/lang/String;");
|
||||||
|
|
||||||
|
jthrowable real_ex = java_env->ExceptionOccurred();
|
||||||
|
|
||||||
|
jstring msg = (jstring) java_env->CallObjectMethod(real_ex, toString);
|
||||||
|
|
||||||
|
jboolean f = true;
|
||||||
|
const char *text = java_env->GetStringUTFChars(msg, &f);
|
||||||
|
|
||||||
|
printf("exception: %s\n", text);
|
||||||
|
|
||||||
|
java_env->ReleaseStringUTFChars(msg, text);
|
||||||
|
|
||||||
|
exit(-1);
|
||||||
|
} else {
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,162 @@
|
||||||
|
package com.ibm.wala.cast.test;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.ibm.wala.cast.ir.translator.NativeTranslatorToCAst;
|
||||||
|
import com.ibm.wala.cast.tree.CAst;
|
||||||
|
import com.ibm.wala.cast.tree.CAstAnnotation;
|
||||||
|
import com.ibm.wala.cast.tree.CAstControlFlowMap;
|
||||||
|
import com.ibm.wala.cast.tree.CAstEntity;
|
||||||
|
import com.ibm.wala.cast.tree.CAstNode;
|
||||||
|
import com.ibm.wala.cast.tree.CAstNodeTypeMap;
|
||||||
|
import com.ibm.wala.cast.tree.CAstQualifier;
|
||||||
|
import com.ibm.wala.cast.tree.CAstSourcePositionMap;
|
||||||
|
import com.ibm.wala.cast.tree.CAstSourcePositionMap.Position;
|
||||||
|
import com.ibm.wala.cast.tree.CAstType;
|
||||||
|
import com.ibm.wala.cast.tree.impl.CAstImpl;
|
||||||
|
import com.ibm.wala.cast.tree.rewrite.CAstRewriter.CopyKey;
|
||||||
|
import com.ibm.wala.cast.tree.rewrite.CAstRewriter.RewriteContext;
|
||||||
|
import com.ibm.wala.cast.tree.rewrite.CAstRewriterFactory;
|
||||||
|
import com.ibm.wala.util.io.TemporaryFile;
|
||||||
|
|
||||||
|
public class TestNativeTranslator {
|
||||||
|
|
||||||
|
static {
|
||||||
|
System.loadLibrary("xlator_test");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static native CAstNode inventAst(SmokeXlator ast);
|
||||||
|
|
||||||
|
private static class SmokeXlator extends NativeTranslatorToCAst {
|
||||||
|
|
||||||
|
private SmokeXlator(CAst Ast, URL sourceURL) throws IOException {
|
||||||
|
super(Ast, sourceURL, TemporaryFile.urlToFile("temp", sourceURL).getAbsolutePath());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <C extends RewriteContext<K>, K extends CopyKey<K>> void addRewriter(CAstRewriterFactory<C, K> factory,
|
||||||
|
boolean prepend) {
|
||||||
|
assert false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CAstEntity translateToCAst() {
|
||||||
|
return new CAstEntity() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getKind() {
|
||||||
|
return CAstEntity.FUNCTION_ENTITY;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return sourceURL.getFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSignature() {
|
||||||
|
return "()";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getArgumentNames() {
|
||||||
|
return new String[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CAstNode[] getArgumentDefaults() {
|
||||||
|
return new CAstNode[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getArgumentCount() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<CAstNode, Collection<CAstEntity>> getAllScopedEntities() {
|
||||||
|
return Collections.emptyMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterator<CAstEntity> getScopedEntities(CAstNode construct) {
|
||||||
|
return Collections.emptyIterator();
|
||||||
|
}
|
||||||
|
|
||||||
|
private CAstNode ast;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CAstNode getAST() {
|
||||||
|
if (ast == null) {
|
||||||
|
ast = inventAst(SmokeXlator.this);
|
||||||
|
}
|
||||||
|
return ast;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CAstControlFlowMap getControlFlow() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CAstSourcePositionMap getSourceMap() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Position getPosition() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CAstNodeTypeMap getNodeTypeMap() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<CAstQualifier> getQualifiers() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CAstType getType() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<CAstAnnotation> getAnnotations() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNativeCAst() throws IOException {
|
||||||
|
CAst Ast = new CAstImpl();
|
||||||
|
|
||||||
|
URL junk = TestNativeTranslator.class.getClassLoader().getResource("smoke_main");
|
||||||
|
|
||||||
|
SmokeXlator xlator = new SmokeXlator(Ast, junk);
|
||||||
|
|
||||||
|
CAstNode ast = xlator.translateToCAst().getAST();
|
||||||
|
|
||||||
|
System.err.println(ast);
|
||||||
|
|
||||||
|
assert ast.getChildCount() == 3;
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,6 +11,38 @@
|
||||||
<packaging>eclipse-plugin</packaging>
|
<packaging>eclipse-plugin</packaging>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
|
<artifactId>exec-maven-plugin</artifactId>
|
||||||
|
<version>1.6.0</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>compile</phase>
|
||||||
|
<configuration>
|
||||||
|
<executable>bash</executable>
|
||||||
|
<arguments>
|
||||||
|
<argument>${basedir}/harness-src/c/cbuild.sh</argument>
|
||||||
|
</arguments>
|
||||||
|
</configuration>
|
||||||
|
<goals>
|
||||||
|
<goal>exec</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
<execution>
|
||||||
|
<id>test-native</id>
|
||||||
|
<phase>test</phase>
|
||||||
|
<configuration>
|
||||||
|
<executable>${project.build.outputDirectory}/smoke_main</executable>
|
||||||
|
<arguments>
|
||||||
|
<argument>${project.build.outputDirectory}:${basedir}/../com.ibm.wala.cast/target/classes:${basedir}/../com.ibm.wala.core/target/classes:${basedir}/../com.ibm.wala.util/target/classes</argument>
|
||||||
|
</arguments>
|
||||||
|
</configuration>
|
||||||
|
<goals>
|
||||||
|
<goal>exec</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
@ -20,7 +52,7 @@
|
||||||
<phase>test</phase>
|
<phase>test</phase>
|
||||||
<configuration>
|
<configuration>
|
||||||
<testClassesDirectory>${project.build.outputDirectory}</testClassesDirectory>
|
<testClassesDirectory>${project.build.outputDirectory}</testClassesDirectory>
|
||||||
<argLine>-Xmx800M -ea</argLine>
|
<argLine>-Djava.library.path=${project.build.outputDirectory} -ea</argLine>
|
||||||
<redirectTestOutputToFile>true</redirectTestOutputToFile>
|
<redirectTestOutputToFile>true</redirectTestOutputToFile>
|
||||||
</configuration>
|
</configuration>
|
||||||
<goals>
|
<goals>
|
||||||
|
@ -38,5 +70,10 @@
|
||||||
<version>4.11</version>
|
<version>4.11</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
|
<artifactId>exec-maven-plugin</artifactId>
|
||||||
|
<version>1.6.0</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -11,6 +11,25 @@
|
||||||
<packaging>eclipse-plugin</packaging>
|
<packaging>eclipse-plugin</packaging>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
|
<artifactId>exec-maven-plugin</artifactId>
|
||||||
|
<version>1.6.0</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>compile</phase>
|
||||||
|
<configuration>
|
||||||
|
<executable>bash</executable>
|
||||||
|
<arguments>
|
||||||
|
<argument>${basedir}/source/c/cbuild.sh</argument>
|
||||||
|
</arguments>
|
||||||
|
</configuration>
|
||||||
|
<goals>
|
||||||
|
<goal>exec</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-dependency-plugin</artifactId>
|
<artifactId>maven-dependency-plugin</artifactId>
|
||||||
<executions>
|
<executions>
|
||||||
|
@ -35,4 +54,11 @@
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
|
<artifactId>exec-maven-plugin</artifactId>
|
||||||
|
<version>1.6.0</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -1,64 +1,7 @@
|
||||||
|
|
||||||
include Makefile.configuration
|
include Makefile.configuration
|
||||||
|
|
||||||
#
|
include Makefile.definitions
|
||||||
# in theory, these definitions should not need to be changed
|
|
||||||
#
|
|
||||||
|
|
||||||
ifeq (x$(PLATFORM),x)
|
|
||||||
PLATFORM=$(shell uname -s)
|
|
||||||
endif
|
|
||||||
|
|
||||||
C_GENERATED=$(DOMO_AST_BIN)libcast/
|
|
||||||
|
|
||||||
JAVAH_GENERATED=$(C_GENERATED)
|
|
||||||
ifeq ($(PLATFORM),windows)
|
|
||||||
CC=i686-mingw32-g++
|
|
||||||
else
|
|
||||||
CC=g++
|
|
||||||
endif
|
|
||||||
|
|
||||||
vpath %.cpp jni
|
|
||||||
|
|
||||||
JAVA_INCLUDES = -I$(JAVA_SDK)include
|
|
||||||
|
|
||||||
CAPA_INCLUDE_DIR = include/
|
|
||||||
CAPA_INCLUDES = -I$(CAPA_INCLUDE_DIR) -I$(C_GENERATED)
|
|
||||||
|
|
||||||
CAPA_JNI_BRIDGE_HEADER = $(C_GENERATED)com_ibm_wala_cast_ir_translator_NativeBridge.h
|
|
||||||
CAPA_JNI_XLATOR_HEADER = $(C_GENERATED)com_ibm_wala_cast_ir_translator_NativeTranslatorToCAst.h
|
|
||||||
CAPA_JNI_HEADERS = $(CAPA_JNI_BRIDGE_HEADER) $(CAPA_JNI_XLATOR_HEADER)
|
|
||||||
|
|
||||||
INCLUDES = $(CAPA_INCLUDES) $(JAVA_INCLUDES)
|
|
||||||
|
|
||||||
CAPA_SOURCES = $(notdir $(wildcard jni/*.cpp))
|
|
||||||
CAPA_OBJECTS = $(patsubst %.cpp,$(C_GENERATED)%.o,$(CAPA_SOURCES))
|
|
||||||
|
|
||||||
ifeq ($(PLATFORM),windows)
|
|
||||||
ALL_FLAGS = -gstabs+ $(TRACE) $(INCLUDES) -DBUILD_CAST_DLL
|
|
||||||
DLLEXT = dll
|
|
||||||
else
|
|
||||||
ifeq ($(PLATFORM),Darwin)
|
|
||||||
ALL_FLAGS = -gstabs+ $(TRACE) $(INCLUDES) -fPIC
|
|
||||||
DLLEXT = jnilib
|
|
||||||
else
|
|
||||||
ALL_FLAGS = -pthread -gstabs+ $(TRACE) $(INCLUDES) -fPIC
|
|
||||||
DLLEXT = so
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(PLATFORM),windows)
|
|
||||||
CC_LDFLAGS = -shared -Wl,--add-stdcall-alias -Wl,-export-all-symbols
|
|
||||||
LIBPREFIX =
|
|
||||||
else
|
|
||||||
ifeq ($(PLATFORM),Darwin)
|
|
||||||
CC_LDFLAGS = -dynamiclib -Wl,-flat_namespace
|
|
||||||
LIBPREFIX = lib
|
|
||||||
else
|
|
||||||
CC_LDFLAGS = -pthread -shared
|
|
||||||
LIBPREFIX = lib
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# rules
|
# rules
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
JAVA_SDK = /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/
|
||||||
|
DOMO_AST_BIN = /private/tmp/WALA/com.ibm.wala.cast/target/classes/
|
||||||
|
JAVAH_CLASS_PATH = :/private/tmp/WALA/com.ibm.wala.cast/target/classes/
|
||||||
|
TRACE =
|
||||||
|
JNI_MD_DIR = darwin
|
|
@ -0,0 +1,18 @@
|
||||||
|
#
|
||||||
|
# global configuration. adjust for your system.
|
||||||
|
#
|
||||||
|
|
||||||
|
# The root of the java SDK to use (must end in /)
|
||||||
|
JAVA_SDK = /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/
|
||||||
|
|
||||||
|
# Path .class files of the com.ibm.domo.ast Java code (must end in /)
|
||||||
|
DOMO_AST_BIN = /Users/dolby/git/WALA/com.ibm.wala.cast/bin/
|
||||||
|
|
||||||
|
# Extra stuff needed in the classpath of javah (must start with path separator)
|
||||||
|
JAVAH_CLASS_PATH =
|
||||||
|
|
||||||
|
# enable debugging flags
|
||||||
|
TRACE =
|
||||||
|
|
||||||
|
# low-level JNI path
|
||||||
|
JNI_MD_DIR = darwin
|
|
@ -0,0 +1,63 @@
|
||||||
|
#
|
||||||
|
# in theory, these definitions should not need to be changed
|
||||||
|
#
|
||||||
|
|
||||||
|
ifeq (x$(PLATFORM),x)
|
||||||
|
PLATFORM=$(shell uname -s)
|
||||||
|
endif
|
||||||
|
|
||||||
|
C_GENERATED=$(DOMO_AST_BIN)libcast/
|
||||||
|
|
||||||
|
JAVAH_GENERATED=$(C_GENERATED)
|
||||||
|
ifeq ($(PLATFORM),windows)
|
||||||
|
CC=i686-mingw32-g++
|
||||||
|
else
|
||||||
|
CC=g++
|
||||||
|
endif
|
||||||
|
|
||||||
|
vpath %.cpp jni
|
||||||
|
|
||||||
|
JAVA_INCLUDES = -I$(JAVA_SDK)include -I$(JAVA_SDK)include/$(JNI_MD_DIR) -DWALA_CLASSPATH="\"$(DOMO_AST_BIN)$(JAVAH_CLASS_PATH)\""
|
||||||
|
|
||||||
|
CAPA_INCLUDE_DIR = ../../../com.ibm.wala.cast/source/c/include/
|
||||||
|
CAPA_INCLUDES = -I$(CAPA_INCLUDE_DIR) -I$(C_GENERATED)
|
||||||
|
|
||||||
|
CAPA_JNI_BRIDGE_HEADER = $(C_GENERATED)com_ibm_wala_cast_ir_translator_NativeBridge.h
|
||||||
|
CAPA_JNI_XLATOR_HEADER = $(C_GENERATED)com_ibm_wala_cast_ir_translator_NativeTranslatorToCAst.h
|
||||||
|
CAPA_JNI_HEADERS = $(CAPA_JNI_BRIDGE_HEADER) $(CAPA_JNI_XLATOR_HEADER)
|
||||||
|
|
||||||
|
INCLUDES = $(CAPA_INCLUDES) $(JAVA_INCLUDES)
|
||||||
|
|
||||||
|
CAPA_SOURCES = $(notdir $(wildcard jni/*.cpp))
|
||||||
|
CAPA_OBJECTS = $(patsubst %.cpp,$(C_GENERATED)%.o,$(CAPA_SOURCES))
|
||||||
|
|
||||||
|
ifeq ($(PLATFORM),windows)
|
||||||
|
ALL_FLAGS = -g $(TRACE) $(INCLUDES) -DBUILD_CAST_DLL
|
||||||
|
DLLEXT = dll
|
||||||
|
else
|
||||||
|
ifeq ($(PLATFORM),Darwin)
|
||||||
|
ALL_FLAGS = -g $(TRACE) $(INCLUDES) -fPIC
|
||||||
|
DLLEXT = jnilib
|
||||||
|
else
|
||||||
|
ALL_FLAGS = -pthread -g $(TRACE) $(INCLUDES) -fPIC
|
||||||
|
DLLEXT = so
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(PLATFORM),windows)
|
||||||
|
CC_LDFLAGS = -shared -Wl,--add-stdcall-alias -Wl,-export-all-symbols
|
||||||
|
LIBPREFIX =
|
||||||
|
else
|
||||||
|
ifeq ($(PLATFORM),Darwin)
|
||||||
|
CC_LDFLAGS = -dynamiclib -Wl,-flat_namespace
|
||||||
|
LIBPREFIX = lib
|
||||||
|
else
|
||||||
|
CC_LDFLAGS = -pthread -shared
|
||||||
|
LIBPREFIX = lib
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
CC_LDFLAGS += -L$(JAVA_SDK)jre/lib/server -Wl,-rpath -Wl,$(JAVA_SDK)jre/lib/server -ljvm
|
||||||
|
|
||||||
|
ALL_FLAGS += -std=c++11
|
||||||
|
|
|
@ -1,5 +1,36 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
C_DIR=`realpath $0`
|
||||||
|
CAST_DIR=`realpath $C_DIR/../../..`
|
||||||
|
|
||||||
|
pushd $CAST_DIR/source/c
|
||||||
|
|
||||||
|
cat > /tmp/JrePath.java <<EOF
|
||||||
|
class JrePath {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println(System.getProperty("java.home"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
|
||||||
|
pushd /tmp
|
||||||
|
javac JrePath.java
|
||||||
|
JRE_DIR=`java JrePath`
|
||||||
|
JDK_DIR=`realpath $JRE_DIR/..`
|
||||||
|
popd
|
||||||
|
|
||||||
|
JNI_MD_H=`ls $JDK_DIR/include/*/jni_md.h`
|
||||||
|
JNI_MD_PATH=`dirname $JNI_MD_H`
|
||||||
|
JNI_MD_DIR=`basename $JNI_MD_PATH`
|
||||||
|
|
||||||
|
cat > $CAST_DIR/source/c/Makefile.configuration <<EOF
|
||||||
|
JAVA_SDK = $JDK_DIR/
|
||||||
|
DOMO_AST_BIN = $CAST_DIR/target/classes/
|
||||||
|
JAVAH_CLASS_PATH = :$CAST_DIR/target/classes/
|
||||||
|
TRACE =
|
||||||
|
JNI_MD_DIR = $JNI_MD_DIR
|
||||||
|
EOF
|
||||||
|
|
||||||
if (uname | grep -i "cygwin"); then
|
if (uname | grep -i "cygwin"); then
|
||||||
# This should be the default for most of cases;
|
# This should be the default for most of cases;
|
||||||
# adjust to your environment if necessary.
|
# adjust to your environment if necessary.
|
||||||
|
@ -10,3 +41,5 @@ if (uname | grep -i "cygwin"); then
|
||||||
else
|
else
|
||||||
make
|
make
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
popd
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <list>
|
#include <list>
|
||||||
#include "jni.h"
|
#include "jni.h"
|
||||||
#include "Exceptions.h"
|
#include "Exceptions.h"
|
||||||
|
#include "launch.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
@ -53,6 +54,7 @@ private:
|
||||||
jclass CAstInterface;
|
jclass CAstInterface;
|
||||||
jclass CAstPrinter;
|
jclass CAstPrinter;
|
||||||
jclass CAstSymbol;
|
jclass CAstSymbol;
|
||||||
|
jclass CAstType;
|
||||||
jclass NativeEntity;
|
jclass NativeEntity;
|
||||||
jclass NativeClassEntity;
|
jclass NativeClassEntity;
|
||||||
jclass NativeCodeEntity;
|
jclass NativeCodeEntity;
|
||||||
|
|
|
@ -45,6 +45,11 @@ extern "C" {
|
||||||
#define THROW_ANY_EXCEPTION(CPP_EXP_NAME) \
|
#define THROW_ANY_EXCEPTION(CPP_EXP_NAME) \
|
||||||
(CPP_EXP_NAME).throwAnyException(__FILE__, __LINE__)
|
(CPP_EXP_NAME).throwAnyException(__FILE__, __LINE__)
|
||||||
|
|
||||||
|
#define NULL_CHECK(cpp_exp_name, c_expr) \
|
||||||
|
if ((c_expr) == NULL) { \
|
||||||
|
(CPP_EXP_NAME).throwException(__FILE__, __LINE__, "unexpected null value"); \
|
||||||
|
}
|
||||||
|
|
||||||
#if __WIN32__
|
#if __WIN32__
|
||||||
#ifdef BUILD_CAST_DLL
|
#ifdef BUILD_CAST_DLL
|
||||||
#define DLLEXPORT __declspec(dllexport)
|
#define DLLEXPORT __declspec(dllexport)
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
#ifndef _CAST_LAUNCH_H
|
||||||
|
#define _CAST_LAUNCH_H
|
||||||
|
|
||||||
|
#include "jni.h"
|
||||||
|
|
||||||
|
JNIEnv *launch(char *);
|
||||||
|
void kill();
|
||||||
|
|
||||||
|
#endif
|
|
@ -74,11 +74,15 @@ CAstWrapper::CAstWrapper(JNIEnv *env, Exceptions &ex, jobject xlator)
|
||||||
env->FindClass("com/ibm/wala/cast/ir/translator/NativeBridge");
|
env->FindClass("com/ibm/wala/cast/ir/translator/NativeBridge");
|
||||||
this->NativeTranslatorToCAst =
|
this->NativeTranslatorToCAst =
|
||||||
env->FindClass("com/ibm/wala/cast/ir/translator/NativeTranslatorToCAst");
|
env->FindClass("com/ibm/wala/cast/ir/translator/NativeTranslatorToCAst");
|
||||||
|
THROW_ANY_EXCEPTION(java_ex);
|
||||||
|
|
||||||
jfieldID castFieldID = env->GetFieldID(NativeBridge, "Ast", "Lcom/ibm/wala/cast/tree/CAst;");
|
jfieldID castFieldID = env->GetFieldID(NativeBridge, "Ast", "Lcom/ibm/wala/cast/tree/CAst;");
|
||||||
|
THROW_ANY_EXCEPTION(java_ex);
|
||||||
this->Ast = env->GetObjectField(xlator, castFieldID);
|
this->Ast = env->GetObjectField(xlator, castFieldID);
|
||||||
|
THROW_ANY_EXCEPTION(java_ex);
|
||||||
|
|
||||||
jclass xlatorCls = env->FindClass( XlatorCls );
|
jclass xlatorCls = env->FindClass( XlatorCls );
|
||||||
|
THROW_ANY_EXCEPTION(java_ex);
|
||||||
this->_makeLocation = env->GetMethodID(xlatorCls, "makeLocation", "(IIII)Lcom/ibm/wala/cast/tree/CAstSourcePositionMap$Position;");
|
this->_makeLocation = env->GetMethodID(xlatorCls, "makeLocation", "(IIII)Lcom/ibm/wala/cast/tree/CAstSourcePositionMap$Position;");
|
||||||
THROW_ANY_EXCEPTION(java_ex);
|
THROW_ANY_EXCEPTION(java_ex);
|
||||||
|
|
||||||
|
@ -206,21 +210,21 @@ CAstWrapper::CAstWrapper(JNIEnv *env, Exceptions &ex, jobject xlator)
|
||||||
THROW_ANY_EXCEPTION(java_ex);
|
THROW_ANY_EXCEPTION(java_ex);
|
||||||
this->_getEntityName = env->GetMethodID(castEntity, "getName", "()Ljava/lang/String;");
|
this->_getEntityName = env->GetMethodID(castEntity, "getName", "()Ljava/lang/String;");
|
||||||
|
|
||||||
|
CAstType = env->FindClass("com/ibm/wala/cast/tree/CAstType");
|
||||||
CAstSymbol = env->FindClass("com/ibm/wala/cast/tree/impl/CAstSymbolImpl");
|
CAstSymbol = env->FindClass("com/ibm/wala/cast/tree/impl/CAstSymbolImpl");
|
||||||
THROW_ANY_EXCEPTION(java_ex);
|
THROW_ANY_EXCEPTION(java_ex);
|
||||||
this->castSymbolInit1 =
|
this->castSymbolInit1 =
|
||||||
env->GetMethodID(CAstSymbol, "<init>", "(Ljava/lang/String;)V");
|
env->GetMethodID(CAstSymbol, "<init>", "(Ljava/lang/String;Lcom/ibm/wala/cast/tree/CAstType;)V");
|
||||||
THROW_ANY_EXCEPTION(java_ex);
|
THROW_ANY_EXCEPTION(java_ex);
|
||||||
this->castSymbolInit2 =
|
this->castSymbolInit2 =
|
||||||
env->GetMethodID(CAstSymbol, "<init>", "(Ljava/lang/String;Z)V");
|
env->GetMethodID(CAstSymbol, "<init>", "(Ljava/lang/String;Lcom/ibm/wala/cast/tree/CAstType;Z)V");
|
||||||
THROW_ANY_EXCEPTION(java_ex);
|
THROW_ANY_EXCEPTION(java_ex);
|
||||||
this->castSymbolInit3 =
|
this->castSymbolInit3 =
|
||||||
env->GetMethodID(CAstSymbol, "<init>", "(Ljava/lang/String;ZZ)V");
|
env->GetMethodID(CAstSymbol, "<init>", "(Ljava/lang/String;Lcom/ibm/wala/cast/tree/CAstType;ZZ)V");
|
||||||
THROW_ANY_EXCEPTION(java_ex);
|
THROW_ANY_EXCEPTION(java_ex);
|
||||||
this->castSymbolInit4 =
|
this->castSymbolInit4 =
|
||||||
env->GetMethodID(CAstSymbol, "<init>", "(Ljava/lang/String;ZZLjava/lang/Object;)V");
|
env->GetMethodID(CAstSymbol, "<init>", "(Ljava/lang/String;Lcom/ibm/wala/cast/tree/CAstType;ZZLjava/lang/Object;)V");
|
||||||
THROW_ANY_EXCEPTION(java_ex);
|
THROW_ANY_EXCEPTION(java_ex);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define _CPP_CONSTANTS
|
#define _CPP_CONSTANTS
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
#include <jni.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <strings.h>
|
||||||
|
#include "Exceptions.h"
|
||||||
|
#include "CAstWrapper.h"
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
JavaVM *javaVM;
|
||||||
|
|
||||||
|
JNIEnv *launch(char *classpath) {
|
||||||
|
JavaVMOption jvmopt[2];
|
||||||
|
|
||||||
|
const char *jcp = "-Djava.class.path=";
|
||||||
|
char buf_jcp[ strlen(jcp) + strlen(classpath) + 1 ];
|
||||||
|
sprintf(buf_jcp, "%s%s", jcp, classpath);
|
||||||
|
jvmopt[0].optionString = buf_jcp;
|
||||||
|
|
||||||
|
const char *jlp = "-Djava.library.path=";
|
||||||
|
char buf_jlp[ strlen(jlp) + strlen(classpath) + 1 ];
|
||||||
|
sprintf(buf_jlp, "%s%s", jlp, classpath);
|
||||||
|
jvmopt[1].optionString = buf_jlp;
|
||||||
|
|
||||||
|
JavaVMInitArgs vmArgs;
|
||||||
|
vmArgs.version = JNI_VERSION_1_8;
|
||||||
|
vmArgs.nOptions = 2;
|
||||||
|
vmArgs.options = jvmopt;
|
||||||
|
vmArgs.ignoreUnrecognized = JNI_TRUE;
|
||||||
|
|
||||||
|
// Create the JVM
|
||||||
|
JNIEnv *jniEnv;
|
||||||
|
long flag = JNI_CreateJavaVM(&javaVM, (void**)
|
||||||
|
&jniEnv, &vmArgs);
|
||||||
|
if (flag == JNI_ERR) {
|
||||||
|
cout << "Error creating VM. Exiting...\n";
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return jniEnv;
|
||||||
|
}
|
||||||
|
|
||||||
|
void kill() {
|
||||||
|
javaVM->DestroyJavaVM();
|
||||||
|
}
|
||||||
|
|
|
@ -26,11 +26,11 @@ import com.ibm.wala.classLoader.IMethod;
|
||||||
import com.ibm.wala.classLoader.Language;
|
import com.ibm.wala.classLoader.Language;
|
||||||
import com.ibm.wala.classLoader.Module;
|
import com.ibm.wala.classLoader.Module;
|
||||||
import com.ibm.wala.classLoader.SourceFileModule;
|
import com.ibm.wala.classLoader.SourceFileModule;
|
||||||
import com.ibm.wala.ipa.callgraph.AnalysisCache;
|
|
||||||
import com.ibm.wala.ipa.callgraph.AnalysisCacheImpl;
|
import com.ibm.wala.ipa.callgraph.AnalysisCacheImpl;
|
||||||
import com.ibm.wala.ipa.callgraph.AnalysisScope;
|
import com.ibm.wala.ipa.callgraph.AnalysisScope;
|
||||||
import com.ibm.wala.ipa.callgraph.CGNode;
|
import com.ibm.wala.ipa.callgraph.CGNode;
|
||||||
import com.ibm.wala.ipa.callgraph.CallGraph;
|
import com.ibm.wala.ipa.callgraph.CallGraph;
|
||||||
|
import com.ibm.wala.ipa.callgraph.IAnalysisCacheView;
|
||||||
import com.ibm.wala.ipa.callgraph.propagation.InstanceKey;
|
import com.ibm.wala.ipa.callgraph.propagation.InstanceKey;
|
||||||
import com.ibm.wala.ipa.callgraph.propagation.PointerAnalysis;
|
import com.ibm.wala.ipa.callgraph.propagation.PointerAnalysis;
|
||||||
import com.ibm.wala.ipa.callgraph.propagation.PointerKey;
|
import com.ibm.wala.ipa.callgraph.propagation.PointerKey;
|
||||||
|
@ -91,7 +91,7 @@ public class CAstCallGraphUtil {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AnalysisCache makeCache(IRFactory<IMethod> factory) {
|
public static IAnalysisCacheView makeCache(IRFactory<IMethod> factory) {
|
||||||
return new AnalysisCacheImpl(factory);
|
return new AnalysisCacheImpl(factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,10 +14,10 @@ import java.util.Iterator;
|
||||||
|
|
||||||
import com.ibm.wala.cast.ipa.callgraph.AstSSAPropagationCallGraphBuilder.AstPointerAnalysisImpl.AstImplicitPointsToSetVisitor;
|
import com.ibm.wala.cast.ipa.callgraph.AstSSAPropagationCallGraphBuilder.AstPointerAnalysisImpl.AstImplicitPointsToSetVisitor;
|
||||||
import com.ibm.wala.cast.util.TargetLanguageSelector;
|
import com.ibm.wala.cast.util.TargetLanguageSelector;
|
||||||
import com.ibm.wala.ipa.callgraph.AnalysisCache;
|
|
||||||
import com.ibm.wala.ipa.callgraph.AnalysisOptions;
|
import com.ibm.wala.ipa.callgraph.AnalysisOptions;
|
||||||
import com.ibm.wala.ipa.callgraph.CGNode;
|
import com.ibm.wala.ipa.callgraph.CGNode;
|
||||||
import com.ibm.wala.ipa.callgraph.CallGraph;
|
import com.ibm.wala.ipa.callgraph.CallGraph;
|
||||||
|
import com.ibm.wala.ipa.callgraph.IAnalysisCacheView;
|
||||||
import com.ibm.wala.ipa.callgraph.impl.AbstractRootMethod;
|
import com.ibm.wala.ipa.callgraph.impl.AbstractRootMethod;
|
||||||
import com.ibm.wala.ipa.callgraph.impl.ExplicitCallGraph;
|
import com.ibm.wala.ipa.callgraph.impl.ExplicitCallGraph;
|
||||||
import com.ibm.wala.ipa.callgraph.propagation.InstanceKey;
|
import com.ibm.wala.ipa.callgraph.propagation.InstanceKey;
|
||||||
|
@ -47,7 +47,7 @@ public abstract class CrossLanguageSSAPropagationCallGraphBuilder extends AstSSA
|
||||||
|
|
||||||
protected abstract TargetLanguageSelector<AbstractRootMethod, CrossLanguageCallGraph> makeRootNodeSelector();
|
protected abstract TargetLanguageSelector<AbstractRootMethod, CrossLanguageCallGraph> makeRootNodeSelector();
|
||||||
|
|
||||||
protected CrossLanguageSSAPropagationCallGraphBuilder(IClassHierarchy cha, AnalysisOptions options, AnalysisCache cache,
|
protected CrossLanguageSSAPropagationCallGraphBuilder(IClassHierarchy cha, AnalysisOptions options, IAnalysisCacheView cache,
|
||||||
PointerKeyFactory pointerKeyFactory) {
|
PointerKeyFactory pointerKeyFactory) {
|
||||||
super(cha, options, cache, pointerKeyFactory);
|
super(cha, options, cache, pointerKeyFactory);
|
||||||
visitors = makeMainVisitorSelector();
|
visitors = makeMainVisitorSelector();
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
/******************************************************************************
|
||||||
|
* Copyright (c) 2002 - 2006 IBM Corporation.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* IBM Corporation - initial API and implementation
|
||||||
|
*****************************************************************************/
|
||||||
|
package com.ibm.wala.cast.ir.translator;
|
||||||
|
|
||||||
|
import com.ibm.wala.cast.tree.CAst;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* superclass for CAst parsers / translators making use of native code. performs
|
||||||
|
* initialization of the core CAst native library.
|
||||||
|
*/
|
||||||
|
public abstract class NativeBridge {
|
||||||
|
|
||||||
|
protected final CAst Ast;
|
||||||
|
|
||||||
|
protected static boolean isInitialized;
|
||||||
|
|
||||||
|
protected NativeBridge(CAst Ast) {
|
||||||
|
this.Ast = Ast;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* initialize the CAst native library
|
||||||
|
*/
|
||||||
|
protected static native void initialize();
|
||||||
|
|
||||||
|
static {
|
||||||
|
isInitialized = false;
|
||||||
|
try {
|
||||||
|
//System.loadLibrary("cast");
|
||||||
|
initialize();
|
||||||
|
isInitialized = true;
|
||||||
|
} catch (Throwable e) {
|
||||||
|
// leave isInitialized as false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,103 @@
|
||||||
|
package com.ibm.wala.cast.ir.translator;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.Reader;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
import com.ibm.wala.cast.tree.CAst;
|
||||||
|
import com.ibm.wala.cast.tree.CAstEntity;
|
||||||
|
import com.ibm.wala.cast.tree.CAstSourcePositionMap.Position;
|
||||||
|
import com.ibm.wala.cast.tree.impl.AbstractSourcePosition;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* common functionality for any {@link TranslatorToCAst} making use of native code
|
||||||
|
*/
|
||||||
|
public abstract class NativeTranslatorToCAst
|
||||||
|
extends NativeBridge
|
||||||
|
implements TranslatorToCAst
|
||||||
|
{
|
||||||
|
|
||||||
|
protected final URL sourceURL;
|
||||||
|
|
||||||
|
protected final String sourceFileName;
|
||||||
|
|
||||||
|
protected NativeTranslatorToCAst(CAst Ast, URL sourceURL, String sourceFileName) {
|
||||||
|
super(Ast);
|
||||||
|
this.sourceURL = sourceURL;
|
||||||
|
this.sourceFileName = sourceFileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getLocalFile() {
|
||||||
|
return sourceFileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getFile() {
|
||||||
|
return sourceURL.getFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Position makeLocation(final int fl, final int fc, final int ll, final int lc) {
|
||||||
|
return new AbstractSourcePosition() {
|
||||||
|
@Override
|
||||||
|
public int getFirstLine() {
|
||||||
|
return fl;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getLastLine() {
|
||||||
|
return ll;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getFirstCol() {
|
||||||
|
return fc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getLastCol() {
|
||||||
|
return lc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getFirstOffset() {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getLastOffset() {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public URL getURL() {
|
||||||
|
return sourceURL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InputStream getInputStream() throws IOException {
|
||||||
|
return new FileInputStream(sourceFileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
String urlString = sourceURL.toString();
|
||||||
|
if (urlString.lastIndexOf(File.separator) == -1)
|
||||||
|
return "[" + fl + ":" + fc + "]->[" + ll + ":" + lc + "]";
|
||||||
|
else
|
||||||
|
return urlString.substring(urlString.lastIndexOf(File.separator) + 1) + "@[" + fl + ":" + fc + "]->[" + ll + ":" + lc
|
||||||
|
+ "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Reader getReader() throws IOException {
|
||||||
|
return new InputStreamReader(getInputStream());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public abstract CAstEntity translateToCAst();
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue