From 29ec5ace047439b51552e3d7bbd81d397146292c Mon Sep 17 00:00:00 2001 From: Volker Berlin Date: Tue, 1 May 2018 11:46:42 +0200 Subject: [PATCH] Improve error messages in BranchManager --- .../jwebassembly/module/BranchManger.java | 14 ++++++++++---- .../jwebassembly/module/ModuleWriter.java | 6 +++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/de/inetsoftware/jwebassembly/module/BranchManger.java b/src/de/inetsoftware/jwebassembly/module/BranchManger.java index 7e3e104..aa11ad2 100644 --- a/src/de/inetsoftware/jwebassembly/module/BranchManger.java +++ b/src/de/inetsoftware/jwebassembly/module/BranchManger.java @@ -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; } } diff --git a/src/de/inetsoftware/jwebassembly/module/ModuleWriter.java b/src/de/inetsoftware/jwebassembly/module/ModuleWriter.java index 264cc7d..636c821 100644 --- a/src/de/inetsoftware/jwebassembly/module/ModuleWriter.java +++ b/src/de/inetsoftware/jwebassembly/module/ModuleWriter.java @@ -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; } }