mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
Start refactoring dependency checker to make it partially incremental
This commit is contained in:
parent
0ff2b2a1dc
commit
e60be5d518
|
@ -259,9 +259,8 @@ class DependencyGraphBuilder {
|
|||
@Override
|
||||
public void stringConstant(VariableReader receiver, String cst) {
|
||||
useRunners.add(new TypePropagationRunner(nodes[receiver.getIndex()], "java.lang.String"));
|
||||
MethodDependency method = dependencyChecker.linkMethod(new MethodReference("java.lang.String",
|
||||
new MethodDescriptor("<init>", ValueType.arrayOf(ValueType.CHARACTER), ValueType.VOID)),
|
||||
callerStack);
|
||||
MethodDependency method = dependencyChecker.linkMethod(new MethodReference(String.class,
|
||||
"<init>", char.class, void.class), callerStack);
|
||||
method.use();
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright 2014 Alexey Andreev.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.teavm.dependency;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Alexey Andreev
|
||||
*/
|
||||
public interface DependencyGraphCreator {
|
||||
DependencyGraphCreatorProduct createDependency(DependencyChecker checker, DependencyStack stack);
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* Copyright 2014 Alexey Andreev.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.teavm.dependency;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Alexey Andreev
|
||||
*/
|
||||
public class DependencyGraphCreatorProduct {
|
||||
public DependencyNode[] variableNodes;
|
||||
public DependencyNode resultNode;
|
||||
public DependencyNode thrownNode;
|
||||
public Runnable[] deferredActions;
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* Copyright 2014 Alexey Andreev.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.teavm.dependency;
|
||||
|
||||
import org.teavm.model.MethodReference;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Alexey Andreev
|
||||
*/
|
||||
public interface DependencyGraphCreatorProvider {
|
||||
DependencyGraphCreator get(MethodReference method);
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
/*
|
||||
* Copyright 2014 Alexey Andreev.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.teavm.dependency;
|
||||
|
||||
import org.teavm.model.ClassReader;
|
||||
import org.teavm.model.ClassReaderSource;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Alexey Andreev
|
||||
*/
|
||||
class ProgrammableDependencyGraphCreator implements DependencyGraphCreator {
|
||||
int nodeCount;
|
||||
Connection[] connections;
|
||||
TypeRestrictedConnection[] typeRestrictedConnections;
|
||||
TypePropagation[] typePropagations;
|
||||
String[] initializedClasses;
|
||||
int[] variableMap;
|
||||
int resultIndex;
|
||||
|
||||
ProgrammableDependencyGraphCreator() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public DependencyGraphCreatorProduct createDependency(DependencyChecker checker, DependencyStack stack) {
|
||||
DependencyNode[] nodes = new DependencyNode[nodeCount];
|
||||
for (int i = 0; i < nodes.length; ++i) {
|
||||
nodes[i] = checker.createNode();
|
||||
}
|
||||
for (Connection conn : connections) {
|
||||
nodes[conn.from].connect(nodes[conn.to]);
|
||||
}
|
||||
for (TypeRestrictedConnection conn : typeRestrictedConnections) {
|
||||
nodes[conn.from].connect(nodes[conn.to], new DependencySupertypeFilter(checker.getClassSource(),
|
||||
checker.getClassSource().get(conn.superclass)));
|
||||
}
|
||||
for (TypePropagation propagation : typePropagations) {
|
||||
nodes[propagation.var].propagate(propagation.type);
|
||||
}
|
||||
for (String className : initializedClasses) {
|
||||
checker.initClass(className, stack);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static class Connection {
|
||||
int from;
|
||||
int to;
|
||||
}
|
||||
|
||||
static class TypeRestrictedConnection {
|
||||
int from;
|
||||
int to;
|
||||
String superclass;
|
||||
}
|
||||
|
||||
static class TypePropagation {
|
||||
int var;
|
||||
String type;
|
||||
}
|
||||
|
||||
static class DependencySupertypeFilter implements DependencyTypeFilter {
|
||||
private ClassReaderSource classSource;
|
||||
private ClassReader superClass;
|
||||
public DependencySupertypeFilter(ClassReaderSource classSource, ClassReader superClass) {
|
||||
this.classSource = classSource;
|
||||
this.superClass = superClass;
|
||||
}
|
||||
@Override public boolean match(String type) {
|
||||
if (superClass.getName().equals("java.lang.Object")) {
|
||||
return true;
|
||||
}
|
||||
return isAssignableFrom(classSource, superClass, type);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isAssignableFrom(ClassReaderSource classSource, ClassReader supertype,
|
||||
String subtypeName) {
|
||||
if (supertype.getName().equals(subtypeName)) {
|
||||
return true;
|
||||
}
|
||||
ClassReader subtype = classSource.get(subtypeName);
|
||||
if (subtype == null) {
|
||||
return false;
|
||||
}
|
||||
if (subtype.getParent() != null && isAssignableFrom(classSource, supertype, subtype.getParent())) {
|
||||
return true;
|
||||
}
|
||||
for (String iface : subtype.getInterfaces()) {
|
||||
if (isAssignableFrom(classSource, supertype, iface)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright 2014 Alexey Andreev.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.teavm.dependency;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Alexey Andreev
|
||||
*/
|
||||
public class ProgrammableDependencyGraphCreatorBuilder {
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user