Skip to content

Commit 4e4fa8a

Browse files
VolkerVolker
authored andcommitted
pass the ValueType to the return WasmBlockInstruction
1 parent b78e605 commit 4e4fa8a

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

src/de/inetsoftware/jwebassembly/module/ModuleGenerator.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -674,8 +674,27 @@ private void writeCode( CodeInputStream byteCode, ConstantPool constantPool ) t
674674
case 173: // lreturn
675675
case 174: // freturn
676676
case 175: // dreturn
677+
case 176: // areturn
677678
case 177: // return void
678-
instr = new WasmBlockInstruction( WasmBlockOperator.RETURN, null, codePos );
679+
ValueType type = null;
680+
switch ( op ) {
681+
case 172: // ireturn
682+
type = ValueType.i32;
683+
break;
684+
case 173: // lreturn
685+
type = ValueType.i64;
686+
break;
687+
case 174: // freturn
688+
type = ValueType.f32;
689+
break;
690+
case 175: // dreturn
691+
type = ValueType.f64;
692+
break;
693+
case 176: // areturn
694+
type = ValueType.anyref;
695+
break;
696+
}
697+
instr = new WasmBlockInstruction( WasmBlockOperator.RETURN, type, codePos );
679698
endWithReturn = true;
680699
break;
681700
//TODO case 178: // getstatic
@@ -688,7 +707,7 @@ private void writeCode( CodeInputStream byteCode, ConstantPool constantPool ) t
688707
idx = byteCode.readUnsignedShort();
689708
ConstantRef method = (ConstantRef)constantPool.get( idx );
690709
String signature = method.getType();
691-
ValueType type = getValueType( signature, signature.indexOf( ')' ) + 1 );
710+
type = getValueType( signature, signature.indexOf( ')' ) + 1 );
692711
if( type != null ) {
693712
stackManager.add( type, codePos );
694713
}

src/de/inetsoftware/jwebassembly/module/WasmBlockInstruction.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,14 @@ public void writeTo( @Nonnull ModuleWriter writer ) throws IOException {
6060
* {@inheritDoc}
6161
*/
6262
ValueType getPushValueType() {
63-
return op == WasmBlockOperator.IF && data != ValueType.empty ? (ValueType)data : null;
63+
switch( op ) {
64+
case IF:
65+
return data != ValueType.empty ? (ValueType)data : null;
66+
case RETURN:
67+
return (ValueType)data;
68+
default:
69+
return null;
70+
}
6471
}
6572

6673
/**

0 commit comments

Comments
 (0)