mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-15 02:44:47 +01:00
Fix "switch" with multiple "case" values for one block.
This commit is contained in:
parent
dea54b631c
commit
9b3993450e
@ -283,13 +283,12 @@ class BranchManger {
|
||||
|
||||
// calculate the block number for ever switch case depending its position order
|
||||
Arrays.sort( cases, ( a, b ) -> Integer.compare( a.position, b.position ) );
|
||||
int blockCount = 0;
|
||||
int blockCount = -1;
|
||||
int lastPosition = -1;
|
||||
BranchNode brTableNode = null;
|
||||
BranchNode blockNode = null;
|
||||
for( int i = 0; i < cases.length; i++ ) {
|
||||
switchCase = cases[i];
|
||||
switchCase.block = blockCount;
|
||||
int currentPosition = switchCase.position;
|
||||
if( lastPosition != currentPosition ) {
|
||||
if( isTable && blockNode == null ) {
|
||||
@ -303,6 +302,7 @@ class BranchManger {
|
||||
}
|
||||
blockNode = node;
|
||||
}
|
||||
switchCase.block = blockCount;
|
||||
}
|
||||
|
||||
// handle the GOTO (breaks) at the end of the CASE blocks.
|
||||
|
@ -140,13 +140,18 @@ public class ControlFlowOperators extends AbstractBaseTest {
|
||||
|
||||
@Export
|
||||
static int switchDirect() {
|
||||
return tableSwitch(10) + (tableSwitch( 9 ) * 10) + (lookupSwitch(Integer.MAX_VALUE) * 100) + (lookupSwitch(0) * 1000);
|
||||
return tableSwitch(10) + (tableSwitch( 9 ) * 10) + + (tableSwitch( -1 ) * 100) + (lookupSwitch(Integer.MAX_VALUE) * 1000) + (lookupSwitch(0) * 10000 );
|
||||
}
|
||||
|
||||
private static int tableSwitch( int a ) {
|
||||
int b;
|
||||
switch(a){
|
||||
case 8:
|
||||
case 9:
|
||||
b = 2;
|
||||
break;
|
||||
case 10:
|
||||
case 11:
|
||||
b = 1;
|
||||
break;
|
||||
default:
|
||||
|
Loading…
x
Reference in New Issue
Block a user