Skip to content

Commit cf2f59b

Browse files
authored
Was failing with when processing a wasm with an import/export TAG. Added generation for tag import. Export TAG has no generation but is skipped, enabling generation to complete. (#76)
1 parent 5d85eb1 commit cf2f59b

6 files changed

Lines changed: 52 additions & 6 deletions

File tree

annotations/processor/src/test/java/run/endive/annotations/processor/WasmModuleProcessorTest.java

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@
99

1010
class WasmModuleProcessorTest {
1111

12+
private static Compilation compile(String source) {
13+
return javac().withProcessors(new WasmModuleProcessor())
14+
.compile(JavaFileObjects.forResource(source));
15+
}
16+
1217
@Test
1318
void resolvesWasmModuleFromClassPathNotJustClassOutput() {
14-
Compilation compilation =
15-
javac().withProcessors(new WasmModuleProcessor())
16-
.compile(JavaFileObjects.forResource("IterFactModule.java"));
19+
Compilation compilation = compile("IterFactModule.java");
1720

1821
assertThat(compilation).succeededWithoutWarnings();
1922

@@ -22,14 +25,31 @@ void resolvesWasmModuleFromClassPathNotJustClassOutput() {
2225

2326
@Test
2427
void reportsMissingWasmModule() {
25-
Compilation compilation =
26-
javac().withProcessors(new WasmModuleProcessor())
27-
.compile(JavaFileObjects.forResource("MissingModule.java"));
28+
Compilation compilation = compile("MissingModule.java");
2829

2930
assertThat(compilation).failed();
3031

3132
assertThat(compilation)
3233
.hadErrorContaining("Failed to load wasmFile")
3334
.inFile(JavaFileObjects.forResource("MissingModule.java"));
3435
}
36+
37+
@Test
38+
void skipsTagExportAndStillGeneratesFunctionExport() {
39+
Compilation compilation = compile("TagExportModule.java");
40+
41+
assertThat(compilation).succeededWithoutWarnings();
42+
43+
assertThat(compilation).generatedSourceFile("endive.testing.TagExportModule_ModuleExports");
44+
}
45+
46+
@Test
47+
void generatesTagImportBindingAlongsideFunctionImport() {
48+
Compilation compilation = compile("TagImportModule.java");
49+
50+
assertThat(compilation).succeededWithoutWarnings();
51+
52+
assertThat(compilation).generatedSourceFile("endive.testing.TagImportModule_Host");
53+
assertThat(compilation).generatedSourceFile("endive.testing.TagImportModule_ModuleImports");
54+
}
3555
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package endive.testing;
2+
3+
import run.endive.annotations.WasmModuleInterface;
4+
5+
@WasmModuleInterface("tag-export.wasm")
6+
public class TagExportModule {}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package endive.testing;
2+
3+
import run.endive.annotations.WasmModuleInterface;
4+
5+
@WasmModuleInterface("tag-import.wasm")
6+
public class TagImportModule {}
53 Bytes
Binary file not shown.
67 Bytes
Binary file not shown.

codegen/src/main/java/run/endive/codegen/ModuleInterfaceCodegen.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ public Map<String, CompilationUnit> generate() {
153153
case FUNCTION:
154154
exportFieldType = parseType("ExportFunction");
155155
break;
156+
case TAG:
157+
continue;
156158
}
157159
exportsClass.addField(
158160
exportFieldType,
@@ -479,6 +481,18 @@ exportApplyHandle, new IntegerLiteralExpr("0")),
479481
"addTable",
480482
NodeList.nodeList(importObj.apply("ImportTable"))));
481483
continue;
484+
} else if (importedFun.importType() == ExternalType.TAG) {
485+
cu.addImport("run.endive.runtime.TagInstance");
486+
importMethod.setType("TagInstance");
487+
importMethod.removeBody();
488+
489+
importsCu.addImport("run.endive.runtime.ImportTag");
490+
toImportValuesBody.addStatement(
491+
new MethodCallExpr(
492+
new NameExpr("imports"),
493+
"addTag",
494+
NodeList.nodeList(importObj.apply("ImportTag"))));
495+
continue;
482496
}
483497
// we now know it's a function
484498
assert (importedFun.importType() == ExternalType.FUNCTION);

0 commit comments

Comments
 (0)