mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-25 15:37:52 +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
|
// calculate the block number for ever switch case depending its position order
|
||||||
Arrays.sort( cases, ( a, b ) -> Integer.compare( a.position, b.position ) );
|
Arrays.sort( cases, ( a, b ) -> Integer.compare( a.position, b.position ) );
|
||||||
int blockCount = 0;
|
int blockCount = -1;
|
||||||
int lastPosition = -1;
|
int lastPosition = -1;
|
||||||
BranchNode brTableNode = null;
|
BranchNode brTableNode = null;
|
||||||
BranchNode blockNode = null;
|
BranchNode blockNode = null;
|
||||||
for( int i = 0; i < cases.length; i++ ) {
|
for( int i = 0; i < cases.length; i++ ) {
|
||||||
switchCase = cases[i];
|
switchCase = cases[i];
|
||||||
switchCase.block = blockCount;
|
|
||||||
int currentPosition = switchCase.position;
|
int currentPosition = switchCase.position;
|
||||||
if( lastPosition != currentPosition ) {
|
if( lastPosition != currentPosition ) {
|
||||||
if( isTable && blockNode == null ) {
|
if( isTable && blockNode == null ) {
|
||||||
@ -303,6 +302,7 @@ class BranchManger {
|
|||||||
}
|
}
|
||||||
blockNode = node;
|
blockNode = node;
|
||||||
}
|
}
|
||||||
|
switchCase.block = blockCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle the GOTO (breaks) at the end of the CASE blocks.
|
// handle the GOTO (breaks) at the end of the CASE blocks.
|
||||||
|
@ -140,13 +140,18 @@ public class ControlFlowOperators extends AbstractBaseTest {
|
|||||||
|
|
||||||
@Export
|
@Export
|
||||||
static int switchDirect() {
|
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 ) {
|
private static int tableSwitch( int a ) {
|
||||||
int b;
|
int b;
|
||||||
switch(a){
|
switch(a){
|
||||||
|
case 8:
|
||||||
|
case 9:
|
||||||
|
b = 2;
|
||||||
|
break;
|
||||||
case 10:
|
case 10:
|
||||||
|
case 11:
|
||||||
b = 1;
|
b = 1;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user