A goto to the next address is like a NOP operation

This commit is contained in:
Volker Berlin 2020-01-05 20:32:26 +01:00
parent 3823ddafc2
commit b1f775a33b

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2018 - 2019 Volker Berlin (i-net software) Copyright 2018 - 2020 Volker Berlin (i-net software)
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -651,18 +651,25 @@ class BranchManger {
* the not consumed operations in the parent branch * the not consumed operations in the parent branch
*/ */
private void calculateGoto ( BranchNode parent, ParsedBlock gotoBlock, List<ParsedBlock> parsedOperations ) { private void calculateGoto ( BranchNode parent, ParsedBlock gotoBlock, List<ParsedBlock> parsedOperations ) {
int start = gotoBlock.endPosition; int jump = gotoBlock.endPosition; // jump position of the GOTO
int end = gotoBlock.startPosition; int start = gotoBlock.startPosition;
if( end > start ) { if( start > jump ) {
// back jump to a previous position like in loops
int deep = 0; int deep = 0;
while( parent != null ) { while( parent != null ) {
if( parent.startOp == WasmBlockOperator.LOOP && parent.startPos == start ) { if( parent.startOp == WasmBlockOperator.LOOP && parent.startPos == jump ) {
parent.add( new BranchNode( end, end, WasmBlockOperator.BR, null, deep ) ); // continue to the start of the loop parent.add( new BranchNode( start, start, WasmBlockOperator.BR, null, deep ) ); // continue to the start of the loop
return; return;
} }
parent = parent.parent; parent = parent.parent;
deep++; deep++;
} }
} else {
if( gotoBlock.nextPosition == jump ) {
//A GOTO to the next position is like a NOP and can be ignored.
//Occur in java.lang.Integer.getChars(int, int, char[]) of Java 8
return;
}
} }
throw new WasmException( "GOTO code without target loop/block", null, null, gotoBlock.lineNumber ); throw new WasmException( "GOTO code without target loop/block", null, null, gotoBlock.lineNumber );
} }