From 845523f1a7bd755f271bdd0b7270534f0e51f0d6 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Thu, 12 Sep 2024 20:43:09 +0200 Subject: [PATCH] wasm gc: implement flags for classes --- .../gc/classes/WasmGCClassGenerator.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/core/src/main/java/org/teavm/backend/wasm/generate/gc/classes/WasmGCClassGenerator.java b/core/src/main/java/org/teavm/backend/wasm/generate/gc/classes/WasmGCClassGenerator.java index a1aefe176..5b52259d1 100644 --- a/core/src/main/java/org/teavm/backend/wasm/generate/gc/classes/WasmGCClassGenerator.java +++ b/core/src/main/java/org/teavm/backend/wasm/generate/gc/classes/WasmGCClassGenerator.java @@ -88,6 +88,7 @@ import org.teavm.model.analysis.ClassInitializerInfo; 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("", ValueType.VOID); @@ -504,6 +505,7 @@ public class WasmGCClassGenerator implements WasmGCClassInfoProvider, WasmGCInit 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))); @@ -547,6 +549,29 @@ public class WasmGCClassGenerator implements WasmGCClassInfoProvider, WasmGCInit }; } + 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()));