mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-15 02:44:47 +01:00
Use UNREACHABLE operation after endless loop.
This commit is contained in:
parent
bab58acebe
commit
776cf133bc
@ -727,6 +727,9 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
|
||||
codeStream.write( LOOP );
|
||||
codeStream.write( 0x40 ); // void; the return type of the loop. currently we does not use it
|
||||
break;
|
||||
case UNREACHABLE:
|
||||
codeStream.write( UNREACHABLE );
|
||||
break;
|
||||
default:
|
||||
throw new Error( "Unknown block: " + op );
|
||||
}
|
||||
|
@ -25,6 +25,8 @@ package de.inetsoftware.jwebassembly.binary;
|
||||
*/
|
||||
interface InstructionOpcodes {
|
||||
|
||||
static final int UNREACHABLE = 0x00;
|
||||
|
||||
static final int NOP = 0x01;
|
||||
|
||||
// === Control flow operators ====
|
||||
|
@ -910,22 +910,7 @@ public class ModuleGenerator {
|
||||
// if a method ends with a loop without a break then code after the loop is no reachable
|
||||
// Java does not need a return byte code in this case
|
||||
// But WebAssembly need the dead code to validate
|
||||
switch( returnType ) {
|
||||
case i32:
|
||||
instructions.add( new WasmConstInstruction( 0, byteCode.getCodePosition() ) );
|
||||
break;
|
||||
case i64:
|
||||
instructions.add( new WasmConstInstruction( 0L, byteCode.getCodePosition() ) );
|
||||
break;
|
||||
case f32:
|
||||
instructions.add( new WasmConstInstruction( 0F, byteCode.getCodePosition() ) );
|
||||
break;
|
||||
case f64:
|
||||
instructions.add( new WasmConstInstruction( 0D, byteCode.getCodePosition() ) );
|
||||
break;
|
||||
default:
|
||||
}
|
||||
instructions.add( new WasmBlockInstruction( WasmBlockOperator.RETURN, null, byteCode.getCodePosition() ) );
|
||||
instructions.add( new WasmBlockInstruction( WasmBlockOperator.UNREACHABLE, null, byteCode.getCodePosition() ) );
|
||||
}
|
||||
} catch( WasmException ex ) {
|
||||
throw ex;
|
||||
|
@ -33,4 +33,5 @@ public enum WasmBlockOperator {
|
||||
BR_IF,
|
||||
BR_TABLE,
|
||||
LOOP,
|
||||
UNREACHABLE,
|
||||
}
|
||||
|
@ -311,6 +311,9 @@ public class TextModuleWriter extends ModuleWriter {
|
||||
name = "loop";
|
||||
insetAfter++;
|
||||
break;
|
||||
case UNREACHABLE:
|
||||
name = "unreachable";
|
||||
break;
|
||||
default:
|
||||
throw new Error( "Unknown block: " + op );
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user