mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-25 15:37:52 +01:00
extract method writeSwitchCode()
This commit is contained in:
parent
6c971c6525
commit
6a7744e228
@ -831,6 +831,42 @@ public abstract class ModuleWriter implements Closeable {
|
||||
break;
|
||||
case 170: // tableswitch
|
||||
case 171: // lookupswitch
|
||||
writeSwitchCode( byteCode, op == 171 );
|
||||
break;
|
||||
case 172: // ireturn
|
||||
case 173: // lreturn
|
||||
case 174: // freturn
|
||||
case 175: // dreturn
|
||||
case 177: // return void
|
||||
writeBlockCode( WasmBlockOperator.RETURN, null );
|
||||
break;
|
||||
case 184: // invokestatic
|
||||
idx = byteCode.readUnsignedShort();
|
||||
ConstantRef method = (ConstantRef)constantPool.get( idx );
|
||||
writeFunctionCall( method.getConstantClass().getName() + '.' + method.getName() + method.getType() );
|
||||
break;
|
||||
default:
|
||||
throw new WasmException( "Unimplemented Java byte code operation: " + op, sourceFile, lineNumber );
|
||||
}
|
||||
}
|
||||
} catch( WasmException ex ) {
|
||||
throw ex;
|
||||
} catch( Exception ex ) {
|
||||
throw WasmException.create( ex, sourceFile, lineNumber );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the both switch operation codes
|
||||
*
|
||||
* @param byteCode
|
||||
* the current stream with a position after the operation code
|
||||
* @param isLookupSwitch
|
||||
* true, if the operation was a loopupswitch; false, if the operation was a tableswitch
|
||||
* @throws IOException
|
||||
* if any I/O error occur
|
||||
*/
|
||||
private void writeSwitchCode( CodeInputStream byteCode, boolean isLookupSwitch ) throws IOException {
|
||||
int startPosition = byteCode.getCodePosition();
|
||||
int padding = startPosition % 4;
|
||||
if( padding > 0 ) {
|
||||
@ -839,7 +875,7 @@ public abstract class ModuleWriter implements Closeable {
|
||||
startPosition--;
|
||||
|
||||
int defaultPosition = byteCode.readInt();
|
||||
if( op == 171 ) { // lookupswitch
|
||||
if( isLookupSwitch ) { // lookupswitch
|
||||
int count = byteCode.readInt();
|
||||
int[] keys = new int[count];
|
||||
int[] positions = new int[count];
|
||||
@ -891,30 +927,17 @@ public abstract class ModuleWriter implements Closeable {
|
||||
writeNumericOperator( NumericOperator.sub, ValueType.i32 );
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 172: // ireturn
|
||||
case 173: // lreturn
|
||||
case 174: // freturn
|
||||
case 175: // dreturn
|
||||
case 177: // return void
|
||||
writeBlockCode( WasmBlockOperator.RETURN, null );
|
||||
break;
|
||||
case 184: // invokestatic
|
||||
idx = byteCode.readUnsignedShort();
|
||||
ConstantRef method = (ConstantRef)constantPool.get( idx );
|
||||
writeFunctionCall( method.getConstantClass().getName() + '.' + method.getName() + method.getType() );
|
||||
break;
|
||||
default:
|
||||
throw new WasmException( "Unimplemented Java byte code operation: " + op, sourceFile, lineNumber );
|
||||
}
|
||||
}
|
||||
} catch( WasmException ex ) {
|
||||
throw ex;
|
||||
} catch( Exception ex ) {
|
||||
throw WasmException.create( ex, sourceFile, lineNumber );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the next higher value.
|
||||
*
|
||||
* @param current
|
||||
* the current value
|
||||
* @param values
|
||||
* the unordered list of values
|
||||
* @return the next value or current value if not found.
|
||||
*/
|
||||
private static int findNext( int current, int[] values ) {
|
||||
boolean find = false;
|
||||
int next = Integer.MAX_VALUE;
|
||||
|
Loading…
x
Reference in New Issue
Block a user