mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-25 07:27:52 +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( LOOP );
|
||||||
codeStream.write( 0x40 ); // void; the return type of the loop. currently we does not use it
|
codeStream.write( 0x40 ); // void; the return type of the loop. currently we does not use it
|
||||||
break;
|
break;
|
||||||
|
case UNREACHABLE:
|
||||||
|
codeStream.write( UNREACHABLE );
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Error( "Unknown block: " + op );
|
throw new Error( "Unknown block: " + op );
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,8 @@ package de.inetsoftware.jwebassembly.binary;
|
|||||||
*/
|
*/
|
||||||
interface InstructionOpcodes {
|
interface InstructionOpcodes {
|
||||||
|
|
||||||
|
static final int UNREACHABLE = 0x00;
|
||||||
|
|
||||||
static final int NOP = 0x01;
|
static final int NOP = 0x01;
|
||||||
|
|
||||||
// === Control flow operators ====
|
// === 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
|
// 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
|
// Java does not need a return byte code in this case
|
||||||
// But WebAssembly need the dead code to validate
|
// But WebAssembly need the dead code to validate
|
||||||
switch( returnType ) {
|
instructions.add( new WasmBlockInstruction( WasmBlockOperator.UNREACHABLE, null, byteCode.getCodePosition() ) );
|
||||||
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() ) );
|
|
||||||
}
|
}
|
||||||
} catch( WasmException ex ) {
|
} catch( WasmException ex ) {
|
||||||
throw ex;
|
throw ex;
|
||||||
|
@ -33,4 +33,5 @@ public enum WasmBlockOperator {
|
|||||||
BR_IF,
|
BR_IF,
|
||||||
BR_TABLE,
|
BR_TABLE,
|
||||||
LOOP,
|
LOOP,
|
||||||
|
UNREACHABLE,
|
||||||
}
|
}
|
||||||
|
@ -311,6 +311,9 @@ public class TextModuleWriter extends ModuleWriter {
|
|||||||
name = "loop";
|
name = "loop";
|
||||||
insetAfter++;
|
insetAfter++;
|
||||||
break;
|
break;
|
||||||
|
case UNREACHABLE:
|
||||||
|
name = "unreachable";
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Error( "Unknown block: " + op );
|
throw new Error( "Unknown block: " + op );
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user