mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-25 07:27:52 +01:00
convert the GOTO in a switch into "br"
This commit is contained in:
parent
b06b368574
commit
3fa6f5670e
@ -240,28 +240,40 @@ class BranchManger {
|
|||||||
}
|
}
|
||||||
lastPosition = currentPosition;
|
lastPosition = currentPosition;
|
||||||
blockCount++;
|
blockCount++;
|
||||||
BranchNode node = new BranchNode( startPosition, startPosition + currentPosition, WasmBlockOperator.BLOCK, WasmBlockOperator.END );
|
BranchNode node = new BranchNode( startPosition, currentPosition, WasmBlockOperator.BLOCK, WasmBlockOperator.END );
|
||||||
node.add( blockNode );
|
node.add( blockNode );
|
||||||
blockNode = node;
|
blockNode = node;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle the GOTO at the end of the CASE blocks.
|
// handle the GOTO (breaks) at the end of the CASE blocks.
|
||||||
int endPosition = startPosition + lastPosition;
|
blockCount = 0;
|
||||||
for( int i = 0; i < parsedOperations.size(); i++ ) {
|
BranchNode branch = blockNode;
|
||||||
ParsedBlock parsedBlock = parsedOperations.get( i );
|
while( branch.size() > 0 ) {
|
||||||
if( parsedBlock.startPosition < endPosition ) {
|
BranchNode node = branch.get( 0 );
|
||||||
if( parsedBlock.endPosition >= endPosition && parsedBlock.op == JavaBlockOperator.GOTO ) {
|
blockCount++;
|
||||||
parsedOperations.remove( i );
|
|
||||||
endPosition = parsedBlock.endPosition;
|
for( int p = 0; p < parsedOperations.size(); p++ ) {
|
||||||
|
ParsedBlock parsedBlock = parsedOperations.get( p );
|
||||||
|
if( parsedBlock.startPosition < node.endPos ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if( parsedBlock.startPosition < lastPosition ) {
|
||||||
|
if( parsedBlock.endPosition >= lastPosition && parsedBlock.op == JavaBlockOperator.GOTO ) {
|
||||||
|
parsedOperations.remove( p );
|
||||||
|
lastPosition = parsedBlock.endPosition;
|
||||||
|
branch.add( new BranchNode( parsedBlock.startPosition, parsedBlock.startPosition, WasmBlockOperator.BR, null, blockCount ) );
|
||||||
|
p--;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
branch = node;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the main block around the switch
|
// Create the main block around the switch
|
||||||
BranchNode switchNode = new BranchNode( startPosition, endPosition, WasmBlockOperator.BLOCK, WasmBlockOperator.END );
|
BranchNode switchNode = new BranchNode( startPosition, lastPosition , WasmBlockOperator.BLOCK, WasmBlockOperator.END );
|
||||||
switchNode.add( blockNode );
|
switchNode.add( blockNode );
|
||||||
parent.add( switchNode );
|
parent.add( switchNode );
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user