Skip to content

Commit

Permalink
wasm gc: implement flags for classes
Browse files Browse the repository at this point in the history
  • Loading branch information
konsoletyper committed Sep 12, 2024
1 parent bfd2c84 commit 845523f
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
import org.teavm.model.analysis.ClassMetadataRequirements;
import org.teavm.model.classes.TagRegistry;
import org.teavm.model.util.ReflectionUtil;
import org.teavm.runtime.RuntimeClass;

public class WasmGCClassGenerator implements WasmGCClassInfoProvider, WasmGCInitializerContributor {
private static final MethodDescriptor CLINIT_METHOD_DESC = new MethodDescriptor("<clinit>", ValueType.VOID);
Expand Down Expand Up @@ -504,6 +505,7 @@ private void initRegularClass(WasmGCClassInfo classInfo, WasmGCVirtualTable virt
target.add(setClassField(classInfo, classNameOffset, new WasmGetGlobal(namePtr)));
}
if (cls != null) {
target.add(setClassField(classInfo, classFlagsOffset, new WasmInt32Constant(getFlags(cls))));
if (metadataReq.simpleName() && cls.getSimpleName() != null) {
var namePtr = strings.getStringConstant(cls.getSimpleName()).global;
target.add(setClassField(classInfo, classSimpleNameOffset, new WasmGetGlobal(namePtr)));
Expand Down Expand Up @@ -547,6 +549,29 @@ private void initRegularClass(WasmGCClassInfo classInfo, WasmGCVirtualTable virt
};
}

private int getFlags(ClassReader cls) {
var flags = 0;
if (cls.hasModifier(ElementModifier.ABSTRACT)) {
flags |= WasmGCClassFlags.ABSTRACT;
}
if (cls.hasModifier(ElementModifier.INTERFACE)) {
flags |= WasmGCClassFlags.INTERFACE;
}
if (cls.hasModifier(ElementModifier.FINAL)) {
flags |= WasmGCClassFlags.FINAL;
}
if (cls.hasModifier(ElementModifier.ANNOTATION)) {
flags |= WasmGCClassFlags.ANNOTATION;
}
if (cls.hasModifier(ElementModifier.SYNTHETIC)) {
flags |= WasmGCClassFlags.SYNTHETIC;
}
if (cls.hasModifier(ElementModifier.ENUM)) {
flags |= WasmGCClassFlags.ENUM;
}
return flags;
}

private WasmFunction generateCloneFunction(WasmGCClassInfo classInfo, String className) {
var function = new WasmFunction(functionTypes.of(standardClasses.objectClass().getType(),
standardClasses.objectClass().getType()));
Expand Down

0 comments on commit 845523f

Please sign in to comment.