diff --git a/annotations/processor/src/test/java/run/endive/annotations/processor/WasmModuleProcessorTest.java b/annotations/processor/src/test/java/run/endive/annotations/processor/WasmModuleProcessorTest.java index e6063a81..7b644abf 100644 --- a/annotations/processor/src/test/java/run/endive/annotations/processor/WasmModuleProcessorTest.java +++ b/annotations/processor/src/test/java/run/endive/annotations/processor/WasmModuleProcessorTest.java @@ -9,11 +9,14 @@ class WasmModuleProcessorTest { + private static Compilation compile(String source) { + return javac().withProcessors(new WasmModuleProcessor()) + .compile(JavaFileObjects.forResource(source)); + } + @Test void resolvesWasmModuleFromClassPathNotJustClassOutput() { - Compilation compilation = - javac().withProcessors(new WasmModuleProcessor()) - .compile(JavaFileObjects.forResource("IterFactModule.java")); + Compilation compilation = compile("IterFactModule.java"); assertThat(compilation).succeededWithoutWarnings(); @@ -22,9 +25,7 @@ void resolvesWasmModuleFromClassPathNotJustClassOutput() { @Test void reportsMissingWasmModule() { - Compilation compilation = - javac().withProcessors(new WasmModuleProcessor()) - .compile(JavaFileObjects.forResource("MissingModule.java")); + Compilation compilation = compile("MissingModule.java"); assertThat(compilation).failed(); @@ -32,4 +33,23 @@ void reportsMissingWasmModule() { .hadErrorContaining("Failed to load wasmFile") .inFile(JavaFileObjects.forResource("MissingModule.java")); } + + @Test + void skipsTagExportAndStillGeneratesFunctionExport() { + Compilation compilation = compile("TagExportModule.java"); + + assertThat(compilation).succeededWithoutWarnings(); + + assertThat(compilation).generatedSourceFile("endive.testing.TagExportModule_ModuleExports"); + } + + @Test + void generatesTagImportBindingAlongsideFunctionImport() { + Compilation compilation = compile("TagImportModule.java"); + + assertThat(compilation).succeededWithoutWarnings(); + + assertThat(compilation).generatedSourceFile("endive.testing.TagImportModule_Host"); + assertThat(compilation).generatedSourceFile("endive.testing.TagImportModule_ModuleImports"); + } } diff --git a/annotations/processor/src/test/resources/TagExportModule.java b/annotations/processor/src/test/resources/TagExportModule.java new file mode 100644 index 00000000..647199b2 --- /dev/null +++ b/annotations/processor/src/test/resources/TagExportModule.java @@ -0,0 +1,6 @@ +package endive.testing; + +import run.endive.annotations.WasmModuleInterface; + +@WasmModuleInterface("tag-export.wasm") +public class TagExportModule {} diff --git a/annotations/processor/src/test/resources/TagImportModule.java b/annotations/processor/src/test/resources/TagImportModule.java new file mode 100644 index 00000000..45653c0c --- /dev/null +++ b/annotations/processor/src/test/resources/TagImportModule.java @@ -0,0 +1,6 @@ +package endive.testing; + +import run.endive.annotations.WasmModuleInterface; + +@WasmModuleInterface("tag-import.wasm") +public class TagImportModule {} diff --git a/annotations/processor/src/test/resources/tag-export.wasm b/annotations/processor/src/test/resources/tag-export.wasm new file mode 100644 index 00000000..00f457f1 Binary files /dev/null and b/annotations/processor/src/test/resources/tag-export.wasm differ diff --git a/annotations/processor/src/test/resources/tag-import.wasm b/annotations/processor/src/test/resources/tag-import.wasm new file mode 100644 index 00000000..bdf5df05 Binary files /dev/null and b/annotations/processor/src/test/resources/tag-import.wasm differ diff --git a/codegen/src/main/java/run/endive/codegen/ModuleInterfaceCodegen.java b/codegen/src/main/java/run/endive/codegen/ModuleInterfaceCodegen.java index 0b6adb31..028f9ae0 100644 --- a/codegen/src/main/java/run/endive/codegen/ModuleInterfaceCodegen.java +++ b/codegen/src/main/java/run/endive/codegen/ModuleInterfaceCodegen.java @@ -153,6 +153,8 @@ public Map generate() { case FUNCTION: exportFieldType = parseType("ExportFunction"); break; + case TAG: + continue; } exportsClass.addField( exportFieldType, @@ -479,6 +481,18 @@ exportApplyHandle, new IntegerLiteralExpr("0")), "addTable", NodeList.nodeList(importObj.apply("ImportTable")))); continue; + } else if (importedFun.importType() == ExternalType.TAG) { + cu.addImport("run.endive.runtime.TagInstance"); + importMethod.setType("TagInstance"); + importMethod.removeBody(); + + importsCu.addImport("run.endive.runtime.ImportTag"); + toImportValuesBody.addStatement( + new MethodCallExpr( + new NameExpr("imports"), + "addTag", + NodeList.nodeList(importObj.apply("ImportTag")))); + continue; } // we now know it's a function assert (importedFun.importType() == ExternalType.FUNCTION);