mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
wasm gc: always emit java.lang.Class, fix issue with recursive types
This commit is contained in:
parent
0cda737dca
commit
ba08fb395c
|
@ -30,6 +30,7 @@ public class WasmGCDependencies {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void contribute() {
|
public void contribute() {
|
||||||
|
analyzer.linkClass("java.lang.Class");
|
||||||
contributeWasmRuntime();
|
contributeWasmRuntime();
|
||||||
contributeMathUtils();
|
contributeMathUtils();
|
||||||
contributeExceptionUtils();
|
contributeExceptionUtils();
|
||||||
|
|
|
@ -296,31 +296,37 @@ public class WasmGCClassGenerator implements WasmGCClassInfoProvider, WasmGCInit
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getClassTagOffset() {
|
public int getClassTagOffset() {
|
||||||
|
standardClasses.classClass().getStructure().init();
|
||||||
return classTagOffset;
|
return classTagOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getClassArrayItemOffset() {
|
public int getClassArrayItemOffset() {
|
||||||
|
standardClasses.classClass().getStructure().init();
|
||||||
return classArrayItemOffset;
|
return classArrayItemOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getClassSupertypeFunctionOffset() {
|
public int getClassSupertypeFunctionOffset() {
|
||||||
|
standardClasses.classClass().getStructure().init();
|
||||||
return classSupertypeFunctionOffset;
|
return classSupertypeFunctionOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getClassNameOffset() {
|
public int getClassNameOffset() {
|
||||||
|
standardClasses.classClass().getStructure().init();
|
||||||
return classNameOffset;
|
return classNameOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getNewArrayFunctionOffset() {
|
public int getNewArrayFunctionOffset() {
|
||||||
|
standardClasses.classClass().getStructure().init();
|
||||||
return classNewArrayOffset;
|
return classNewArrayOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getVirtualMethodsOffset() {
|
public int getVirtualMethodsOffset() {
|
||||||
|
standardClasses.classClass().getStructure().init();
|
||||||
return virtualTableFieldOffset;
|
return virtualTableFieldOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -387,6 +393,7 @@ public class WasmGCClassGenerator implements WasmGCClassInfoProvider, WasmGCInit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
classInfo.initializer = target -> {
|
classInfo.initializer = target -> {
|
||||||
|
standardClasses.classClass().getStructure().init();
|
||||||
var ranges = tagRegistry.getRanges(name);
|
var ranges = tagRegistry.getRanges(name);
|
||||||
int tag = ranges.stream().mapToInt(range -> range.lower).min().orElse(0);
|
int tag = ranges.stream().mapToInt(range -> range.lower).min().orElse(0);
|
||||||
target.add(setClassField(classInfo, classTagOffset, new WasmInt32Constant(tag)));
|
target.add(setClassField(classInfo, classTagOffset, new WasmInt32Constant(tag)));
|
||||||
|
@ -770,6 +777,7 @@ public class WasmGCClassGenerator implements WasmGCClassInfoProvider, WasmGCInit
|
||||||
function.add(nameVar);
|
function.add(nameVar);
|
||||||
function.add(kindVar);
|
function.add(kindVar);
|
||||||
|
|
||||||
|
standardClasses.classClass().getStructure().getFields().size();
|
||||||
var flagsExpr = new WasmIntBinary(
|
var flagsExpr = new WasmIntBinary(
|
||||||
WasmIntType.INT32,
|
WasmIntType.INT32,
|
||||||
WasmIntBinaryOperation.SHL,
|
WasmIntBinaryOperation.SHL,
|
||||||
|
@ -824,6 +832,7 @@ public class WasmGCClassGenerator implements WasmGCClassInfoProvider, WasmGCInit
|
||||||
var itemVar = new WasmLocal(standardClasses.classClass().getType(), "item");
|
var itemVar = new WasmLocal(standardClasses.classClass().getType(), "item");
|
||||||
function.add(targetVar);
|
function.add(targetVar);
|
||||||
function.add(itemVar);
|
function.add(itemVar);
|
||||||
|
standardClasses.classClass().getStructure().init();
|
||||||
|
|
||||||
function.getBody().add(new WasmStructSet(
|
function.getBody().add(new WasmStructSet(
|
||||||
standardClasses.classClass().getStructure(),
|
standardClasses.classClass().getStructure(),
|
||||||
|
|
|
@ -18,7 +18,6 @@ package org.teavm.backend.wasm.model;
|
||||||
public abstract class WasmCompositeType extends WasmEntity {
|
public abstract class WasmCompositeType extends WasmEntity {
|
||||||
private String name;
|
private String name;
|
||||||
private WasmType.CompositeReference reference;
|
private WasmType.CompositeReference reference;
|
||||||
int indexInRecursiveType = -1;
|
|
||||||
int recursiveTypeCount = -1;
|
int recursiveTypeCount = -1;
|
||||||
|
|
||||||
WasmCompositeType(String name) {
|
WasmCompositeType(String name) {
|
||||||
|
@ -36,10 +35,6 @@ public abstract class WasmCompositeType extends WasmEntity {
|
||||||
return reference;
|
return reference;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getIndexInRecursiveType() {
|
|
||||||
return indexInRecursiveType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getRecursiveTypeCount() {
|
public int getRecursiveTypeCount() {
|
||||||
return recursiveTypeCount;
|
return recursiveTypeCount;
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,12 +107,7 @@ public class WasmModule {
|
||||||
var sccsByIndex = new int[types.size()][];
|
var sccsByIndex = new int[types.size()][];
|
||||||
for (var scc : sccs) {
|
for (var scc : sccs) {
|
||||||
sccsByIndex[scc[0]] = scc;
|
sccsByIndex[scc[0]] = scc;
|
||||||
var firstType = types.get(scc[0]);
|
|
||||||
firstType.recursiveTypeCount = scc.length;
|
|
||||||
for (var i = 0; i < scc.length; i++) {
|
for (var i = 0; i < scc.length; i++) {
|
||||||
var index = scc[i];
|
|
||||||
var type = types.get(index);
|
|
||||||
type.indexInRecursiveType = i;
|
|
||||||
sccStartNode[scc[i]] = sccStartNode[scc[0]];
|
sccStartNode[scc[i]] = sccStartNode[scc[0]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -162,9 +157,11 @@ public class WasmModule {
|
||||||
visit(outgoing);
|
visit(outgoing);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
var indexOfFirst = sorted.size();
|
||||||
for (var index : scc) {
|
for (var index : scc) {
|
||||||
visitScc(index, typeIndex);
|
visitScc(index, typeIndex);
|
||||||
}
|
}
|
||||||
|
sorted.get(indexOfFirst).recursiveTypeCount = scc.length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user