mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-15 02:44:47 +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 de.inetsoftware.classparser.CodeInputStream;
|
||||
import de.inetsoftware.jwebassembly.WasmException;
|
||||
|
||||
/**
|
||||
* This calculate the goto offsets from Java back to block operations
|
||||
@ -51,9 +52,11 @@ class BranchManger {
|
||||
* the byte position of the start position
|
||||
* @param offset
|
||||
* the relative jump position
|
||||
* @param lineNumber
|
||||
* the current line number
|
||||
*/
|
||||
void start( BlockOperator op, int startPosition, int offset ) {
|
||||
allParsedOperations.add( new ParsedBlock( op, startPosition, offset ) );
|
||||
void start( BlockOperator op, int startPosition, int offset, int lineNumber ) {
|
||||
allParsedOperations.add( new ParsedBlock( op, startPosition, offset, lineNumber ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -77,7 +80,7 @@ class BranchManger {
|
||||
caculateIf( parent, parsedBlock, parsedOperations );
|
||||
break;
|
||||
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 ParsedBlock( BlockOperator op, int startPosition, int offset ) {
|
||||
private int lineNumber;
|
||||
|
||||
private ParsedBlock( BlockOperator op, int startPosition, int offset, int lineNumber ) {
|
||||
this.op = op;
|
||||
this.startPosition = startPosition;
|
||||
this.endPosition = startPosition + offset;
|
||||
this.lineNumber = lineNumber;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -146,7 +146,7 @@ public abstract class ModuleWriter implements Closeable {
|
||||
}
|
||||
writeMethodFinish( locals );
|
||||
}
|
||||
} catch( IOException ioex ) {
|
||||
} catch( Exception ioex ) {
|
||||
throw WasmException.create( ioex, sourceFile, -1 );
|
||||
}
|
||||
}
|
||||
@ -334,12 +334,12 @@ public abstract class ModuleWriter implements Closeable {
|
||||
case 166: // if_acmpne
|
||||
int startPosition = byteCode.getCodePosition() + 2;
|
||||
int offset = byteCode.readShort();
|
||||
branchManager.start( BlockOperator.IF, startPosition, offset - 3 );
|
||||
branchManager.start( BlockOperator.IF, startPosition, offset - 3, lineNumber );
|
||||
break;
|
||||
case 167: // goto
|
||||
startPosition = byteCode.getCodePosition() - 1;
|
||||
offset = byteCode.readShort();
|
||||
branchManager.start( BlockOperator.GOTO, startPosition, offset );
|
||||
branchManager.start( BlockOperator.GOTO, startPosition, offset, lineNumber );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user