mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
Adds checkstyle and findbugs into configuration of teavm-core
This commit is contained in:
parent
226f4c2c8a
commit
d714e880d3
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
||||||
/.directory
|
/.directory
|
||||||
/.project
|
/.project
|
||||||
/.settings
|
/.settings
|
||||||
|
.checkstyle
|
||||||
|
|
87
teavm-core/checkstyle.xml
Normal file
87
teavm-core/checkstyle.xml
Normal file
|
@ -0,0 +1,87 @@
|
||||||
|
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.2//EN"
|
||||||
|
"http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
|
||||||
|
<module name="Checker">
|
||||||
|
<module name="TreeWalker">
|
||||||
|
<module name="AnnotationUseStyle"/>
|
||||||
|
<module name="MissingOverride">
|
||||||
|
<property name="javaFiveCompatibility" value="true"/>
|
||||||
|
</module>
|
||||||
|
<module name="EmptyBlock">
|
||||||
|
<property name="option" value="text"/>
|
||||||
|
<property name="tokens" value="LITERAL_CATCH"/>
|
||||||
|
</module>
|
||||||
|
<module name="EmptyBlock">
|
||||||
|
<property name="tokens" value="LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY, LITERAL_IF,
|
||||||
|
LITERAL_FOR, LITERAL_TRY, LITERAL_WHILE, STATIC_INIT"/>
|
||||||
|
</module>
|
||||||
|
<module name="LeftCurly"/>
|
||||||
|
<module name="NeedBraces"/>
|
||||||
|
<module name="RightCurly"/>
|
||||||
|
<module name="FinalClass"/>
|
||||||
|
<module name="InterfaceIsType"/>
|
||||||
|
<module name="HideUtilityClassConstructor"/>
|
||||||
|
<module name="MutableException"/>
|
||||||
|
<module name="EmptyStatement"/>
|
||||||
|
<module name="EqualsHashCode"/>
|
||||||
|
<module name="InnerAssignment"/>
|
||||||
|
<module name="SimplifyBooleanExpression"/>
|
||||||
|
<module name="SimplifyBooleanReturn"/>
|
||||||
|
<module name="StringLiteralEquality"/>
|
||||||
|
<module name="IllegalThrows"/>
|
||||||
|
<module name="ExplicitInitialization"/>
|
||||||
|
<module name="DefaultComesLast"/>
|
||||||
|
<module name="FallThrough"/>
|
||||||
|
<module name="MultipleVariableDeclarations"/>
|
||||||
|
<module name="UnnecessaryParentheses"/>
|
||||||
|
<module name="RedundantImport"/>
|
||||||
|
<module name="UnusedImports">
|
||||||
|
<property name="processJavadoc" value="true"/>
|
||||||
|
</module>
|
||||||
|
<module name="ImportOrder">
|
||||||
|
<property name="option" value="top"/>
|
||||||
|
</module>
|
||||||
|
<module name="UpperEll"/>
|
||||||
|
<module name="ArrayTypeStyle"/>
|
||||||
|
<module name="TrailingComment"/>
|
||||||
|
<module name="RedundantModifier"/>
|
||||||
|
<module name="ClassTypeParameterName"/>
|
||||||
|
<module name="LocalFinalVariableName"/>
|
||||||
|
<module name="LocalVariableName"/>
|
||||||
|
<module name="MemberName"/>
|
||||||
|
<module name="MethodName"/>
|
||||||
|
<module name="MethodTypeParameterName"/>
|
||||||
|
<module name="PackageName"/>
|
||||||
|
<module name="ParameterName"/>
|
||||||
|
<module name="StaticVariableName"/>
|
||||||
|
<module name="TypeName"/>
|
||||||
|
<module name="LineLength">
|
||||||
|
<property name="max" value="120"/>
|
||||||
|
</module>
|
||||||
|
<module name="GenericWhitespace"/>
|
||||||
|
<module name="EmptyForInitializerPad"/>
|
||||||
|
<module name="EmptyForIteratorPad"/>
|
||||||
|
<module name="MethodParamPad"/>
|
||||||
|
<module name="NoWhitespaceAfter">
|
||||||
|
<property name="tokens" value="BNOT,DEC,DOT,INC,LNOT,UNARY_MINUS,UNARY_PLUS,TYPECAST"/>
|
||||||
|
</module>
|
||||||
|
<module name="NoWhitespaceBefore">
|
||||||
|
<property name="allowLineBreaks" value="true"/>
|
||||||
|
<property name="tokens" value="BNOT,DEC,DOT,INC,LNOT,UNARY_MINUS,UNARY_PLUS,TYPECAST"/>
|
||||||
|
</module>
|
||||||
|
<module name="OperatorWrap">
|
||||||
|
<property name="option" value="eol"/>
|
||||||
|
</module>
|
||||||
|
<module name="ParenPad"/>
|
||||||
|
<module name="TypecastParenPad"/>
|
||||||
|
<module name="WhitespaceAfter">
|
||||||
|
<property name="tokens" value="COMMA,SEMI"/>
|
||||||
|
</module>
|
||||||
|
</module>
|
||||||
|
<module name="RegexpHeader">
|
||||||
|
<property name="headerFile" value="${config_loc}/license-regexp.txt"/>
|
||||||
|
<property name="fileExtensions" value="java"/>
|
||||||
|
</module>
|
||||||
|
<module name="FileTabCharacter">
|
||||||
|
<property name="fileExtensions" value="java"/>
|
||||||
|
</module>
|
||||||
|
</module>
|
15
teavm-core/license-regexp.txt
Normal file
15
teavm-core/license-regexp.txt
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
/\*
|
||||||
|
\* Copyright 2[0-9]{3} .+
|
||||||
|
\*
|
||||||
|
\* 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.
|
||||||
|
\*/
|
|
@ -42,4 +42,41 @@
|
||||||
<version>3.3.1</version>
|
<version>3.3.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||||
|
<version>2.11</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>validate</id>
|
||||||
|
<phase>validate</phase>
|
||||||
|
<configuration>
|
||||||
|
<propertyExpansion>config_loc=${basedir}</propertyExpansion>
|
||||||
|
<configLocation>checkstyle.xml</configLocation>
|
||||||
|
<encoding>UTF-8</encoding>
|
||||||
|
<consoleOutput>true</consoleOutput>
|
||||||
|
<failsOnError>true</failsOnError>
|
||||||
|
<linkXRef>false</linkXRef>
|
||||||
|
</configuration>
|
||||||
|
<goals>
|
||||||
|
<goal>check</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<reporting>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
|
<artifactId>findbugs-maven-plugin</artifactId>
|
||||||
|
<version>2.5.2</version>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</reporting>
|
||||||
</project>
|
</project>
|
|
@ -87,12 +87,13 @@ public class DefaultNamingStrategy implements NamingStrategy {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getFullNameFor(MethodReference method) throws NamingException {
|
public String getFullNameFor(MethodReference method) throws NamingException {
|
||||||
|
MethodReference originalMethod = method;
|
||||||
if (!minifying) {
|
if (!minifying) {
|
||||||
return getNameFor(method.getClassName()) + "_" + getNameFor(method);
|
return getNameFor(method.getClassName()) + "_" + getNameFor(method);
|
||||||
}
|
}
|
||||||
method = getRealMethod(method);
|
method = getRealMethod(method);
|
||||||
if (method == null) {
|
if (method == null) {
|
||||||
throw new NamingException("Can't provide name for method as it was not found: " + method);
|
throw new NamingException("Can't provide name for method as it was not found: " + originalMethod);
|
||||||
}
|
}
|
||||||
String key = method.toString();
|
String key = method.toString();
|
||||||
String alias = privateAliases.get(key);
|
String alias = privateAliases.get(key);
|
||||||
|
|
|
@ -27,7 +27,7 @@ import org.teavm.model.ValueType;
|
||||||
*/
|
*/
|
||||||
public class SourceWriter implements Appendable {
|
public class SourceWriter implements Appendable {
|
||||||
private Appendable innerWriter;
|
private Appendable innerWriter;
|
||||||
private int indentSize = 0;
|
private int indentSize;
|
||||||
private NamingStrategy naming;
|
private NamingStrategy naming;
|
||||||
private boolean lineStart;
|
private boolean lineStart;
|
||||||
private boolean minified;
|
private boolean minified;
|
||||||
|
|
|
@ -1,3 +1,18 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2013 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.common;
|
package org.teavm.common;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -71,7 +86,7 @@ public class ConcurrentCachedMapper<T, R> implements Mapper<T, R> {
|
||||||
keyListeners.add(listener);
|
keyListeners.add(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static interface KeyListener<S> {
|
public interface KeyListener<S> {
|
||||||
void keyAdded(S key);
|
void keyAdded(S key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ public class DisjointSet {
|
||||||
private int[] rank = new int[16];
|
private int[] rank = new int[16];
|
||||||
private int[] setSize = new int[16];
|
private int[] setSize = new int[16];
|
||||||
private int maxRank;
|
private int maxRank;
|
||||||
private int size = 0;
|
private int size;
|
||||||
|
|
||||||
public int find(int node) {
|
public int find(int node) {
|
||||||
int initial = node;
|
int initial = node;
|
||||||
|
|
|
@ -27,7 +27,7 @@ import java.util.List;
|
||||||
public class GraphBuilder {
|
public class GraphBuilder {
|
||||||
private GraphImpl builtGraph;
|
private GraphImpl builtGraph;
|
||||||
private List<IntegerArray> addedEdges = new ArrayList<>();
|
private List<IntegerArray> addedEdges = new ArrayList<>();
|
||||||
private int sz = 0;
|
private int sz;
|
||||||
|
|
||||||
public GraphBuilder() {
|
public GraphBuilder() {
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,9 @@ import java.util.Comparator;
|
||||||
* @author Alexey Andreev
|
* @author Alexey Andreev
|
||||||
*/
|
*/
|
||||||
public class GraphIndexer {
|
public class GraphIndexer {
|
||||||
|
static final byte NONE = 0;
|
||||||
|
static final byte VISITING = 1;
|
||||||
|
static final byte VISITED = 2;
|
||||||
private int[] indexToNode;
|
private int[] indexToNode;
|
||||||
private int[] nodeToIndex;
|
private int[] nodeToIndex;
|
||||||
private Graph graph;
|
private Graph graph;
|
||||||
|
@ -37,9 +40,6 @@ public class GraphIndexer {
|
||||||
}
|
}
|
||||||
|
|
||||||
private int sort(Graph graph) {
|
private int sort(Graph graph) {
|
||||||
final byte NONE = 0;
|
|
||||||
final byte VISITING = 1;
|
|
||||||
final byte VISITED = 2;
|
|
||||||
LoopGraph loopGraph = new LoopGraph(graph);
|
LoopGraph loopGraph = new LoopGraph(graph);
|
||||||
int sz = graph.size();
|
int sz = graph.size();
|
||||||
int[] indexToNode = new int[sz + 1];
|
int[] indexToNode = new int[sz + 1];
|
||||||
|
@ -89,6 +89,8 @@ public class GraphIndexer {
|
||||||
case NONE:
|
case NONE:
|
||||||
stack[stackSize++] = next;
|
stack[stackSize++] = next;
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -22,7 +22,14 @@ import java.util.Arrays;
|
||||||
*
|
*
|
||||||
* @author Alexey Andreev
|
* @author Alexey Andreev
|
||||||
*/
|
*/
|
||||||
public class GraphUtils {
|
public final class GraphUtils {
|
||||||
|
static final byte NONE = 0;
|
||||||
|
static final byte VISITING = 1;
|
||||||
|
static final byte VISITED = 2;
|
||||||
|
|
||||||
|
private GraphUtils() {
|
||||||
|
}
|
||||||
|
|
||||||
public static Graph invert(Graph graph) {
|
public static Graph invert(Graph graph) {
|
||||||
int sz = graph.size();
|
int sz = graph.size();
|
||||||
GraphBuilder result = new GraphBuilder();
|
GraphBuilder result = new GraphBuilder();
|
||||||
|
@ -52,9 +59,6 @@ public class GraphUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Graph removeLoops(Graph graph) {
|
public static Graph removeLoops(Graph graph) {
|
||||||
final byte NONE = 0;
|
|
||||||
final byte VISITING = 1;
|
|
||||||
final byte VISITED = 2;
|
|
||||||
int sz = graph.size();
|
int sz = graph.size();
|
||||||
GraphBuilder result = new GraphBuilder();
|
GraphBuilder result = new GraphBuilder();
|
||||||
int[] stack = new int[sz * 2];
|
int[] stack = new int[sz * 2];
|
||||||
|
|
|
@ -1,99 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2013 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.common;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Alexey Andreev
|
|
||||||
*/
|
|
||||||
public class GraphWithIndexedEdges implements Graph {
|
|
||||||
private int[][] incoming;
|
|
||||||
private int[][] outgoing;
|
|
||||||
private int[][] edgeIndex;
|
|
||||||
|
|
||||||
public GraphWithIndexedEdges(Graph graph) {
|
|
||||||
incoming = new int[graph.size()][];
|
|
||||||
outgoing = new int[graph.size()][];
|
|
||||||
edgeIndex = new int[graph.size()][];
|
|
||||||
for (int i = 0; i < graph.size(); ++i) {
|
|
||||||
outgoing[i] = graph.outgoingEdges(i);
|
|
||||||
incoming[i] = new int[graph.incomingEdgesCount(i)];
|
|
||||||
edgeIndex[i] = new int[graph.outgoingEdgesCount(i)];
|
|
||||||
}
|
|
||||||
int[] lastIncoming = new int[graph.size()];
|
|
||||||
for (int i = 0; i < graph.size(); ++i) {
|
|
||||||
int[] localOutgoing = outgoing[i];
|
|
||||||
int[] localEdgeIndex = edgeIndex[i];
|
|
||||||
for (int j = 0; j < localOutgoing.length; ++j) {
|
|
||||||
int target = localOutgoing[j];
|
|
||||||
int index = lastIncoming[target]++;
|
|
||||||
incoming[target][index] = i;
|
|
||||||
localEdgeIndex[j] = index;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int size() {
|
|
||||||
return incoming.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int[] incomingEdges(int node) {
|
|
||||||
int[] edges = incoming[node];
|
|
||||||
return Arrays.copyOf(edges, edges.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int copyIncomingEdges(int node, int[] target) {
|
|
||||||
int[] edges = incoming[node];
|
|
||||||
System.arraycopy(edges, 0, target, 0, edges.length);
|
|
||||||
return edges.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int[] outgoingEdges(int node) {
|
|
||||||
int[] edges = outgoing[node];
|
|
||||||
return Arrays.copyOf(edges, edges.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int copyOutgoingEdges(int node, int[] target) {
|
|
||||||
int[] edges = outgoing[node];
|
|
||||||
System.arraycopy(edges, 0, target, 0, edges.length);
|
|
||||||
return edges.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int incomingEdgesCount(int node) {
|
|
||||||
return incoming[node].length;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int outgoingEdgesCount(int node) {
|
|
||||||
return outgoing[node].length;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* For given edge, identified by source node and index in source node edge array,
|
|
||||||
* returns index in target node edge array. Works in constant time.
|
|
||||||
*/
|
|
||||||
public int getEdgeIndex(int sourceNode, int sourceEdgeIndex) {
|
|
||||||
return edgeIndex[sourceNode][sourceEdgeIndex];
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -37,7 +37,7 @@ public class RangeTree {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static interface Node {
|
public interface Node {
|
||||||
Node getParent();
|
Node getParent();
|
||||||
|
|
||||||
int getStart();
|
int getStart();
|
||||||
|
|
|
@ -410,10 +410,11 @@ public class DependencyChecker implements DependencyInfo {
|
||||||
DependencyStack stack = stackMap.get(item);
|
DependencyStack stack = stackMap.get(item);
|
||||||
if (stack == null) {
|
if (stack == null) {
|
||||||
sb.append(" at unknown location\n");
|
sb.append(" at unknown location\n");
|
||||||
}
|
} else {
|
||||||
while (stack.getMethod() != null) {
|
while (stack.getMethod() != null) {
|
||||||
sb.append(" at " + stack.getMethod() + "\n");
|
sb.append(" at " + stack.getMethod() + "\n");
|
||||||
stack = stack.getCause();
|
stack = stack.getCause();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
sb.append('\n');
|
sb.append('\n');
|
||||||
}
|
}
|
||||||
|
|
|
@ -414,7 +414,7 @@ class DependencyGraphBuilder {
|
||||||
public void invoke(VariableReader receiver, VariableReader instance, MethodReference method,
|
public void invoke(VariableReader receiver, VariableReader instance, MethodReference method,
|
||||||
List<? extends VariableReader> arguments, InvocationType type) {
|
List<? extends VariableReader> arguments, InvocationType type) {
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
invokeSpecial(receiver, instance, method, arguments);
|
invokeSpecial(receiver, null, method, arguments);
|
||||||
} else {
|
} else {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case SPECIAL:
|
case SPECIAL:
|
||||||
|
|
|
@ -55,7 +55,7 @@ public class Decompiler {
|
||||||
return this.graph.size();
|
return this.graph.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
class Block {
|
static class Block {
|
||||||
public final IdentifiedStatement statement;
|
public final IdentifiedStatement statement;
|
||||||
public final List<Statement> body;
|
public final List<Statement> body;
|
||||||
public final int end;
|
public final int end;
|
||||||
|
|
|
@ -21,7 +21,10 @@ import org.teavm.javascript.ast.*;
|
||||||
*
|
*
|
||||||
* @author Alexey Andreev
|
* @author Alexey Andreev
|
||||||
*/
|
*/
|
||||||
class ExprOptimizer {
|
final class ExprOptimizer {
|
||||||
|
private ExprOptimizer() {
|
||||||
|
}
|
||||||
|
|
||||||
public static Expr invert(Expr expr) {
|
public static Expr invert(Expr expr) {
|
||||||
if (expr instanceof UnaryExpr) {
|
if (expr instanceof UnaryExpr) {
|
||||||
UnaryExpr unary = (UnaryExpr)expr;
|
UnaryExpr unary = (UnaryExpr)expr;
|
||||||
|
|
|
@ -1,94 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.javascript;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import org.teavm.model.*;
|
|
||||||
import org.teavm.model.util.InstructionTransitionExtractor;
|
|
||||||
import org.teavm.model.util.UsageExtractor;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Alexey Andreev
|
|
||||||
*/
|
|
||||||
class PhiEliminator {
|
|
||||||
public static void eliminatePhis(Program program) {
|
|
||||||
// Count how many times each variable is used
|
|
||||||
int[] variableUsageCount = new int[program.variableCount()];
|
|
||||||
int[] definitionRenamings = new int[program.variableCount()];
|
|
||||||
for (int i = 0; i < definitionRenamings.length; ++i) {
|
|
||||||
definitionRenamings[i] = i;
|
|
||||||
}
|
|
||||||
UsageExtractor usageExtractor = new UsageExtractor();
|
|
||||||
InstructionTransitionExtractor transitionExtractor = new InstructionTransitionExtractor();
|
|
||||||
int blockCount = program.basicBlockCount();
|
|
||||||
for (int i = 0; i < blockCount; ++i) {
|
|
||||||
BasicBlock block = program.basicBlockAt(i);
|
|
||||||
for (Instruction insn : block.getInstructions()) {
|
|
||||||
insn.acceptVisitor(usageExtractor);
|
|
||||||
for (Variable var : usageExtractor.getUsedVariables()) {
|
|
||||||
variableUsageCount[var.getIndex()]++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (Phi phi : block.getPhis()) {
|
|
||||||
for (Incoming incoming : phi.getIncomings()) {
|
|
||||||
variableUsageCount[incoming.getValue().getIndex()]++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Places assignments at the end of each block
|
|
||||||
for (int i = 0; i < blockCount; ++i) {
|
|
||||||
BasicBlock block = program.basicBlockAt(i);
|
|
||||||
block.getLastInstruction().acceptVisitor(transitionExtractor);
|
|
||||||
BasicBlock[] targets = transitionExtractor.getTargets();
|
|
||||||
if (targets.length == 1) {
|
|
||||||
|
|
||||||
} else {
|
|
||||||
for (BasicBlock targetBlock : transitionExtractor.getTargets()) {
|
|
||||||
List<Incoming> incomings = new ArrayList<>();
|
|
||||||
for (Incoming incoming : getIncomings(block, targetBlock)) {
|
|
||||||
if (variableUsageCount[incoming.getSource().getIndex()] <= 1) {
|
|
||||||
definitionRenamings[incoming.getValue().getIndex()] =
|
|
||||||
incoming.getPhi().getReceiver().getIndex();
|
|
||||||
} else {
|
|
||||||
incomings.add(incoming);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Removes phi functions
|
|
||||||
for (int i = 0; i < blockCount; ++i) {
|
|
||||||
BasicBlock block = program.basicBlockAt(i);
|
|
||||||
block.getPhis().clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<Incoming> getIncomings(BasicBlock block, BasicBlock targetBlock) {
|
|
||||||
List<Incoming> incomings = new ArrayList<>();
|
|
||||||
for (Phi phi : targetBlock.getPhis()) {
|
|
||||||
for (Incoming incoming : phi.getIncomings()) {
|
|
||||||
if (incoming.getSource() == block) {
|
|
||||||
incomings.add(incoming);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return incomings;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -396,7 +396,7 @@ class StatementGenerator implements InstructionVisitor {
|
||||||
Map<Integer, List<Integer>> switchMap = new HashMap<>();
|
Map<Integer, List<Integer>> switchMap = new HashMap<>();
|
||||||
for (int i = 0; i < insn.getEntries().size(); ++i) {
|
for (int i = 0; i < insn.getEntries().size(); ++i) {
|
||||||
SwitchTableEntry entry = insn.getEntries().get(i);
|
SwitchTableEntry entry = insn.getEntries().get(i);
|
||||||
List<Integer> conditions = switchMap.get(entry.getTarget());
|
List<Integer> conditions = switchMap.get(entry.getTarget().getIndex());
|
||||||
if (conditions == null) {
|
if (conditions == null) {
|
||||||
conditions = new ArrayList<>();
|
conditions = new ArrayList<>();
|
||||||
switchMap.put(entry.getTarget().getIndex(), conditions);
|
switchMap.put(entry.getTarget().getIndex(), conditions);
|
||||||
|
|
|
@ -41,7 +41,7 @@ public class DefinitionExtractor implements InstructionVisitor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(NullConstantInstruction insn) {
|
public void visit(NullConstantInstruction insn) {
|
||||||
definedVariables = new Variable[] { insn.getReceiver() };
|
definedVariables = new Variable[] {insn.getReceiver()};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -24,7 +24,10 @@ import org.teavm.model.instructions.*;
|
||||||
*
|
*
|
||||||
* @author Alexey Andreev
|
* @author Alexey Andreev
|
||||||
*/
|
*/
|
||||||
public class ProgramUtils {
|
public final class ProgramUtils {
|
||||||
|
private ProgramUtils() {
|
||||||
|
}
|
||||||
|
|
||||||
public static Graph buildControlFlowGraphWithoutTryCatch(Program program) {
|
public static Graph buildControlFlowGraphWithoutTryCatch(Program program) {
|
||||||
GraphBuilder graphBuilder = new GraphBuilder(program.basicBlockCount());
|
GraphBuilder graphBuilder = new GraphBuilder(program.basicBlockCount());
|
||||||
InstructionTransitionExtractor transitionExtractor = new InstructionTransitionExtractor();
|
InstructionTransitionExtractor transitionExtractor = new InstructionTransitionExtractor();
|
||||||
|
|
|
@ -161,9 +161,8 @@ public class RegisterAllocator {
|
||||||
if (!interfere) {
|
if (!interfere) {
|
||||||
int newClass = congruenceClasses.union(copyClass, origClass);
|
int newClass = congruenceClasses.union(copyClass, origClass);
|
||||||
block.getInstructions().set(j, new EmptyInstruction());
|
block.getInstructions().set(j, new EmptyInstruction());
|
||||||
MutableGraphNode newNode = interferenceGraph.get(origClass);
|
|
||||||
if (newClass == interferenceGraph.size()) {
|
if (newClass == interferenceGraph.size()) {
|
||||||
newNode = new MutableGraphNode(interferenceGraph.size());
|
MutableGraphNode newNode = new MutableGraphNode(interferenceGraph.size());
|
||||||
interferenceGraph.add(newNode);
|
interferenceGraph.add(newNode);
|
||||||
}
|
}
|
||||||
for (MutableGraphEdge edge : interferenceGraph.get(origClass).getEdges()
|
for (MutableGraphEdge edge : interferenceGraph.get(origClass).getEdges()
|
||||||
|
|
|
@ -117,7 +117,7 @@ public class CommonSubexpressionElimination implements MethodOptimization {
|
||||||
}
|
}
|
||||||
|
|
||||||
program.pack();
|
program.pack();
|
||||||
program = null;
|
this.program = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<List<Incoming>> findOutgoings(Program program) {
|
private List<List<Incoming>> findOutgoings(Program program) {
|
||||||
|
|
|
@ -73,7 +73,7 @@ public class UnusedVariableElimination implements MethodOptimization {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class InstructionOptimizer implements InstructionVisitor {
|
private static class InstructionOptimizer implements InstructionVisitor {
|
||||||
private boolean[] used;
|
private boolean[] used;
|
||||||
boolean eliminate;
|
boolean eliminate;
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,10 @@ import org.teavm.model.instructions.*;
|
||||||
*
|
*
|
||||||
* @author Alexey Andreev <konsoletyper@gmail.com>
|
* @author Alexey Andreev <konsoletyper@gmail.com>
|
||||||
*/
|
*/
|
||||||
public class VariableEscapeAnalyzer {
|
public final class VariableEscapeAnalyzer {
|
||||||
|
private VariableEscapeAnalyzer() {
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean[] findEscapingVariables(Program program) {
|
public static boolean[] findEscapingVariables(Program program) {
|
||||||
boolean[] escaping = new boolean[program.variableCount()];
|
boolean[] escaping = new boolean[program.variableCount()];
|
||||||
InstructionAnalyzer analyzer = new InstructionAnalyzer(escaping);
|
InstructionAnalyzer analyzer = new InstructionAnalyzer(escaping);
|
||||||
|
|
|
@ -24,7 +24,10 @@ import org.teavm.model.instructions.*;
|
||||||
*
|
*
|
||||||
* @author Alexey Andreev <konsoletyper@gmail.com>
|
* @author Alexey Andreev <konsoletyper@gmail.com>
|
||||||
*/
|
*/
|
||||||
public class VariableUsageGraphBuilder {
|
public final class VariableUsageGraphBuilder {
|
||||||
|
private VariableUsageGraphBuilder() {
|
||||||
|
}
|
||||||
|
|
||||||
public static Graph build(Program program) {
|
public static Graph build(Program program) {
|
||||||
GraphBuilder builder = new GraphBuilder(program.variableCount());
|
GraphBuilder builder = new GraphBuilder(program.variableCount());
|
||||||
InstructionAnalyzer analyzer = new InstructionAnalyzer(builder);
|
InstructionAnalyzer analyzer = new InstructionAnalyzer(builder);
|
||||||
|
|
|
@ -28,8 +28,8 @@ import org.teavm.model.ClassHolder;
|
||||||
* @author Alexey Andreev <konsoletyper@gmail.com>
|
* @author Alexey Andreev <konsoletyper@gmail.com>
|
||||||
*/
|
*/
|
||||||
public class ClasspathResourceMapper implements Mapper<String, ClassHolder> {
|
public class ClasspathResourceMapper implements Mapper<String, ClassHolder> {
|
||||||
private static String PACKAGE_PREFIX = "packagePrefix.";
|
private static final String PACKAGE_PREFIX = "packagePrefix.";
|
||||||
private static String CLASS_PREFIX = "classPrefix.";
|
private static final String CLASS_PREFIX = "classPrefix.";
|
||||||
private Mapper<String, ClassHolder> innerMapper;
|
private Mapper<String, ClassHolder> innerMapper;
|
||||||
private List<Transformation> transformations = new ArrayList<>();
|
private List<Transformation> transformations = new ArrayList<>();
|
||||||
private ClassRefsRenamer renamer;
|
private ClassRefsRenamer renamer;
|
||||||
|
|
|
@ -27,7 +27,10 @@ import org.teavm.optimization.UnreachableBasicBlockEliminator;
|
||||||
*
|
*
|
||||||
* @author Alexey Andreev
|
* @author Alexey Andreev
|
||||||
*/
|
*/
|
||||||
public class Parser {
|
public final class Parser {
|
||||||
|
private Parser() {
|
||||||
|
}
|
||||||
|
|
||||||
public static MethodHolder parseMethod(MethodNode node, String className) {
|
public static MethodHolder parseMethod(MethodNode node, String className) {
|
||||||
ValueType[] signature = MethodDescriptor.parseSignature(node.desc);
|
ValueType[] signature = MethodDescriptor.parseSignature(node.desc);
|
||||||
MethodHolder method = new MethodHolder(node.name, signature);
|
MethodHolder method = new MethodHolder(node.name, signature);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2011 Alexey Andreev.
|
* Copyright 2011 Alexey Andreev.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
|
@ -199,7 +199,7 @@ public class TeaVM implements TeaVMHost {
|
||||||
if (bytecodeLogging) {
|
if (bytecodeLogging) {
|
||||||
try {
|
try {
|
||||||
logBytecode(new PrintWriter(new OutputStreamWriter(logStream, "UTF-8")), classSet);
|
logBytecode(new PrintWriter(new OutputStreamWriter(logStream, "UTF-8")), classSet);
|
||||||
} catch (IOException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
// Just don't do anything
|
// Just don't do anything
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,6 @@ package org.teavm.html4j.test;
|
||||||
*
|
*
|
||||||
* @author Alexey Andreev
|
* @author Alexey Andreev
|
||||||
*/
|
*/
|
||||||
interface A {
|
public interface A {
|
||||||
int foo();
|
int foo();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user