add option WASM_USE_EH to ignore exception support because currently not supported

This commit is contained in:
Volker Berlin 2020-01-12 12:42:31 +01:00
parent 4377db747d
commit 54d2deef4f
6 changed files with 33 additions and 8 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2017 - 2018 Volker Berlin (i-net software) * Copyright 2017 - 2020 Volker Berlin (i-net software)
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -93,6 +93,11 @@ public class JWebAssembly {
*/ */
public static final String WASM_USE_GC = "wasm.use_gc"; public static final String WASM_USE_GC = "wasm.use_gc";
/**
* If the exception handling feature of WASM should be use or an unreachable instruction. If true use the exception instructions of WASM.
*/
public static final String WASM_USE_EH = "wasm.use_eh";
/** /**
* The logger instance * The logger instance
*/ */

View File

@ -1248,8 +1248,12 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
codeStream.writeOpCode( CATCH ); codeStream.writeOpCode( CATCH );
break; break;
case THROW: case THROW:
codeStream.writeOpCode( THROW ); if( options.useEH() ) {
codeStream.writeVaruint32( 0 ); // event/exception ever 0 because currently there is only one with signature anyref codeStream.writeOpCode( THROW );
codeStream.writeVaruint32( 0 ); // event/exception ever 0 because currently there is only one with signature anyref
} else {
codeStream.writeOpCode( UNREACHABLE );
}
break; break;
case RETHROW: case RETHROW:
codeStream.writeOpCode( RETHROW ); codeStream.writeOpCode( RETHROW );

View File

@ -514,7 +514,9 @@ public class ModuleGenerator {
case CATCH: case CATCH:
case THROW: case THROW:
case RETHROW: case RETHROW:
writer.writeException(); if( writer.options.useEH() ) {
writer.writeException();
}
break; break;
default: default:
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2017 - 2019 Volker Berlin (i-net software) * Copyright 2017 - 2020 Volker Berlin (i-net software)
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -762,7 +762,7 @@ public class TextModuleWriter extends ModuleWriter {
insetAfter++; insetAfter++;
break; break;
case THROW: case THROW:
name = "throw 0"; // currently there is only one event/exception with anyref name = options.useEH() ? "throw 0" : "unreachable"; // currently there is only one event/exception with anyref
break; break;
case RETHROW: case RETHROW:
name = "rethrow"; name = "rethrow";

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2017 - 2019 Volker Berlin (i-net software) * Copyright 2017 - 2020 Volker Berlin (i-net software)
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -33,6 +33,8 @@ public class WasmOptions {
private final boolean useGC; private final boolean useGC;
private final boolean useEH;
@Nonnull @Nonnull
private final String sourceMapBase; private final String sourceMapBase;
@ -50,6 +52,7 @@ public class WasmOptions {
public WasmOptions( HashMap<String, String> properties ) { public WasmOptions( HashMap<String, String> properties ) {
debugNames = Boolean.parseBoolean( properties.get( JWebAssembly.DEBUG_NAMES ) ); debugNames = Boolean.parseBoolean( properties.get( JWebAssembly.DEBUG_NAMES ) );
useGC = Boolean.parseBoolean( properties.getOrDefault( JWebAssembly.WASM_USE_GC, "false" ) ); useGC = Boolean.parseBoolean( properties.getOrDefault( JWebAssembly.WASM_USE_GC, "false" ) );
useEH = Boolean.parseBoolean( properties.getOrDefault( JWebAssembly.WASM_USE_EH, "false" ) );
String base = properties.getOrDefault( JWebAssembly.SOURCE_MAP_BASE, "" ); String base = properties.getOrDefault( JWebAssembly.SOURCE_MAP_BASE, "" );
if( !base.isEmpty() && !base.endsWith( "/" ) ) { if( !base.isEmpty() && !base.endsWith( "/" ) ) {
base += "/"; base += "/";
@ -75,6 +78,15 @@ public class WasmOptions {
return useGC; return useGC;
} }
/**
* If the exception handling feature of WASM should be use or an unreachable instruction.
*
* @return true, use the EH instructions of WASM; false, generate an unreachable instruction
*/
public boolean useEH() {
return useEH;
}
/** /**
* Get the relative path between the final wasm file location and the source files location. * Get the relative path between the final wasm file location and the source files location.
* If not empty it should end with a slash like "../../src/main/java/". * If not empty it should end with a slash like "../../src/main/java/".

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2018 - 2019 Volker Berlin (i-net software) * Copyright 2018 - 2020 Volker Berlin (i-net software)
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -23,6 +23,7 @@ import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runners.Parameterized.Parameters; import org.junit.runners.Parameterized.Parameters;
import de.inetsoftware.jwebassembly.JWebAssembly;
import de.inetsoftware.jwebassembly.ScriptEngine; import de.inetsoftware.jwebassembly.ScriptEngine;
import de.inetsoftware.jwebassembly.WasmRule; import de.inetsoftware.jwebassembly.WasmRule;
import de.inetsoftware.jwebassembly.api.annotation.Export; import de.inetsoftware.jwebassembly.api.annotation.Export;
@ -47,6 +48,7 @@ public class Exceptions extends AbstractBaseTest {
addParam( list, script, "complex" ); addParam( list, script, "complex" );
} }
rule.setTestParameters( list ); rule.setTestParameters( list );
rule.setProperty( JWebAssembly.WASM_USE_EH, "true" );
return list; return list;
} }