mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-25 15:37:52 +01:00
Improve error messages in BranchManager
This commit is contained in:
parent
7ba809ac86
commit
29ec5ace04
@ -21,6 +21,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import de.inetsoftware.classparser.CodeInputStream;
|
import de.inetsoftware.classparser.CodeInputStream;
|
||||||
|
import de.inetsoftware.jwebassembly.WasmException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This calculate the goto offsets from Java back to block operations
|
* This calculate the goto offsets from Java back to block operations
|
||||||
@ -51,9 +52,11 @@ class BranchManger {
|
|||||||
* the byte position of the start position
|
* the byte position of the start position
|
||||||
* @param offset
|
* @param offset
|
||||||
* the relative jump position
|
* the relative jump position
|
||||||
|
* @param lineNumber
|
||||||
|
* the current line number
|
||||||
*/
|
*/
|
||||||
void start( BlockOperator op, int startPosition, int offset ) {
|
void start( BlockOperator op, int startPosition, int offset, int lineNumber ) {
|
||||||
allParsedOperations.add( new ParsedBlock( op, startPosition, offset ) );
|
allParsedOperations.add( new ParsedBlock( op, startPosition, offset, lineNumber ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -77,7 +80,7 @@ class BranchManger {
|
|||||||
caculateIf( parent, parsedBlock, parsedOperations );
|
caculateIf( parent, parsedBlock, parsedOperations );
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException( "Unimplemented block code operation: " + parsedBlock.op );
|
throw new WasmException( "Unimplemented block code operation: " + parsedBlock.op, null, parsedBlock.lineNumber );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -159,10 +162,13 @@ class BranchManger {
|
|||||||
|
|
||||||
private int endPosition;
|
private int endPosition;
|
||||||
|
|
||||||
private ParsedBlock( BlockOperator op, int startPosition, int offset ) {
|
private int lineNumber;
|
||||||
|
|
||||||
|
private ParsedBlock( BlockOperator op, int startPosition, int offset, int lineNumber ) {
|
||||||
this.op = op;
|
this.op = op;
|
||||||
this.startPosition = startPosition;
|
this.startPosition = startPosition;
|
||||||
this.endPosition = startPosition + offset;
|
this.endPosition = startPosition + offset;
|
||||||
|
this.lineNumber = lineNumber;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,7 +146,7 @@ public abstract class ModuleWriter implements Closeable {
|
|||||||
}
|
}
|
||||||
writeMethodFinish( locals );
|
writeMethodFinish( locals );
|
||||||
}
|
}
|
||||||
} catch( IOException ioex ) {
|
} catch( Exception ioex ) {
|
||||||
throw WasmException.create( ioex, sourceFile, -1 );
|
throw WasmException.create( ioex, sourceFile, -1 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -334,12 +334,12 @@ public abstract class ModuleWriter implements Closeable {
|
|||||||
case 166: // if_acmpne
|
case 166: // if_acmpne
|
||||||
int startPosition = byteCode.getCodePosition() + 2;
|
int startPosition = byteCode.getCodePosition() + 2;
|
||||||
int offset = byteCode.readShort();
|
int offset = byteCode.readShort();
|
||||||
branchManager.start( BlockOperator.IF, startPosition, offset - 3 );
|
branchManager.start( BlockOperator.IF, startPosition, offset - 3, lineNumber );
|
||||||
break;
|
break;
|
||||||
case 167: // goto
|
case 167: // goto
|
||||||
startPosition = byteCode.getCodePosition() - 1;
|
startPosition = byteCode.getCodePosition() - 1;
|
||||||
offset = byteCode.readShort();
|
offset = byteCode.readShort();
|
||||||
branchManager.start( BlockOperator.GOTO, startPosition, offset );
|
branchManager.start( BlockOperator.GOTO, startPosition, offset, lineNumber );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user