extract method calculateSubOperations()

This commit is contained in:
Volker Berlin 2022-04-24 17:19:10 +02:00
parent aabff4d93c
commit 2f8538dbf5

View File

@ -421,6 +421,28 @@ class BranchManager {
} }
} }
/**
* Calculate the operations which are inside the given branch node.
* @param branch
* the parent branch/block in the hierarchy.
* @param parsedOperations
* the not consumed parsed operations of the parent block.
*/
private void calculateSubOperations( BranchNode branch, List<ParsedBlock> parsedOperations ) {
int endPos = branch.endPos;
int idx = 0;
int size = parsedOperations.size();
for( ; idx < size; idx++ ) {
ParsedBlock parsedBlock = parsedOperations.get( idx );
if( parsedBlock.startPosition >= endPos ) {
break;
}
}
if( idx > 0 ) {
calculate( branch, parsedOperations.subList( 0, idx ) );
}
}
/** /**
* Add a break to the node if the block jump to the continue position of an outer loop. * Add a break to the node if the block jump to the continue position of an outer loop.
* *
@ -563,18 +585,7 @@ class BranchManager {
} }
startBlock.negateCompare(); startBlock.negateCompare();
/** calculateSubOperations( branch, parsedOperations );
* Search the index in the stack to add the END operator
*/
for( ; i < parsedOperations.size(); i++ ) {
ParsedBlock parsedBlock = parsedOperations.get( i );
if( parsedBlock.startPosition >= endPos ) {
break;
}
}
if( i > 0 ) {
calculate( branch, parsedOperations.subList( 0, i ) );
}
} }
/** /**
@ -1097,14 +1108,7 @@ class BranchManager {
loopNode.continuePos = loopBlock.nextPosition; loopNode.continuePos = loopBlock.nextPosition;
blockNode.add( loopNode ); blockNode.add( loopNode );
int idx = 0; calculateSubOperations( loopNode, parsedOperations );
for( ; idx < parsedOperations.size(); idx++ ) {
ParsedBlock parsedBlock = parsedOperations.get( idx );
if( parsedBlock.startPosition >= loopBlock.endPosition ) {
break;
}
}
calculate( loopNode, parsedOperations.subList( 0, idx ) );
// add the "br 0" as last child to receive the right order // add the "br 0" as last child to receive the right order
// loopNode.add( new BranchNode( loopBlock.endPosition, loopBlock.endPosition, WasmBlockOperator.BR, null, 0 ) ); // continue to the start of the loop // loopNode.add( new BranchNode( loopBlock.endPosition, loopBlock.endPosition, WasmBlockOperator.BR, null, 0 ) ); // continue to the start of the loop
} }
@ -1290,17 +1294,8 @@ class BranchManager {
* the not consumed operations in the parent branch * the not consumed operations in the parent branch
*/ */
private void calculateTrySubOperations( BranchNode catchNode, BranchNode node, List<ParsedBlock> parsedOperations ) { private void calculateTrySubOperations( BranchNode catchNode, BranchNode node, List<ParsedBlock> parsedOperations ) {
int idx;
do { do {
for( idx = 0; idx < parsedOperations.size(); idx++ ) { calculateSubOperations( node, parsedOperations );
ParsedBlock parsedBlock = parsedOperations.get( idx );
if( parsedBlock.startPosition >= node.endPos ) {
break;
}
}
if( idx > 0 ) {
calculate( node, parsedOperations.subList( 0, idx ) );
}
if( node == catchNode ) { if( node == catchNode ) {
break; break;
} }