aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-12-26 22:07:17 +0000
committerMichael Williamson <mike@zwobble.org>2023-12-26 22:14:11 +0000
commitd0919581da42074999cb92856073cfe46f90b566 (patch)
tree7ec95730bd8ef451685d96955526ca73080c9980 /src/main/java
parente40f80fe4ac6d4a96e02ce6fed26209242e4476a (diff)
Validate binaries in Wasm backend
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/shedlang/compiler/backends/wasm/WasmBackend.java18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/main/java/org/shedlang/compiler/backends/wasm/WasmBackend.java b/src/main/java/org/shedlang/compiler/backends/wasm/WasmBackend.java
index 7d6f38bf..41489d3e 100644
--- a/src/main/java/org/shedlang/compiler/backends/wasm/WasmBackend.java
+++ b/src/main/java/org/shedlang/compiler/backends/wasm/WasmBackend.java
@@ -18,6 +18,7 @@ import org.shedlang.compiler.shid.ShidNamespace;
import org.shedlang.compiler.sources.Sources;
import org.shedlang.compiler.typechecker.TypeInfos;
import org.shedlang.compiler.types.NamespaceName;
+import org.shedlang.compiler.util.P;
import org.shedlang.compiler.util.processes.ProcessError;
import java.io.FileOutputStream;
@@ -77,7 +78,9 @@ public class WasmBackend implements Backend {
var mainObjectPath = writeObjectFile(mainModule, targetDir.bin(bin.name()));
linkInputs.add(mainObjectPath);
- link(linkInputs, targetDir.topLevel(bin.name() + ".wasm"));
+ var targetBinPath = targetDir.topLevel(bin.name() + ".wasm");
+ link(linkInputs, targetBinPath);
+ validate(targetBinPath);
}
}
@@ -143,7 +146,10 @@ public class WasmBackend implements Backend {
return wasmModule;
}
- private static Path writeObjectFile(WasmModule module, PartialTargetPath targetPath) throws IOException {
+ private Path writeObjectFile(
+ WasmModule module,
+ PartialTargetPath targetPath
+ ) throws IOException {
var objectPath = targetPath.withExtension(".o");
Files.createDirectories(objectPath.getParent());
try (var outputStream = new FileOutputStream(objectPath.toFile())) {
@@ -151,4 +157,12 @@ public class WasmBackend implements Backend {
}
return objectPath;
}
+
+ private void validate(Path path) throws IOException, InterruptedException {
+ var command = P.vector("wasm-validate", "--enable-exceptions")
+ .plusAll(this.target.wabtFlags())
+ .plus(path.toString());
+
+ runInheritIo(command);
+ }
}