Skip to content

Commit c269bae

Browse files
VolkerVolker
authored andcommitted
Move method getValueType() into class ValueType.
1 parent 2c6fb9a commit c269bae

File tree

3 files changed

+46
-43
lines changed

3 files changed

+46
-43
lines changed

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

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ private void writeMethodSignature( MethodInfo method ) throws IOException, WasmE
221221
kind = "result";
222222
continue;
223223
}
224-
type = getValueType( signature, i );
224+
type = ValueType.getValueType( signature, i );
225225
if( type != null ) {
226226
writer.writeMethodParam( kind, type );
227227
}
@@ -230,43 +230,6 @@ private void writeMethodSignature( MethodInfo method ) throws IOException, WasmE
230230
writer.writeMethodParamFinish();
231231
}
232232

233-
/**
234-
* Get the WebAssembly value type from a Java signature.
235-
*
236-
* @param signature
237-
* the signature
238-
* @param idx
239-
* the index in the signature
240-
* @return the value type or null if void
241-
*/
242-
static ValueType getValueType( String signature, int idx ) {
243-
String javaType;
244-
switch( signature.charAt( idx ) ) {
245-
case '[': // array
246-
javaType = "array";
247-
break;
248-
case 'L':
249-
javaType = "object";
250-
break;
251-
case 'B': // byte
252-
case 'C': // char
253-
case 'S': // short
254-
case 'I': // int
255-
return ValueType.i32;
256-
case 'D': // double
257-
return ValueType.f64;
258-
case 'F': // float
259-
return ValueType.f32;
260-
case 'J': // long
261-
return ValueType.i64;
262-
case 'V': // void
263-
return null;
264-
default:
265-
javaType = signature.substring( idx, idx + 1 );
266-
}
267-
throw new WasmException( "Not supported Java data type in method signature: " + javaType, null, -1 );
268-
}
269-
270233
/**
271234
* Write the byte code of a method.
272235
*
@@ -693,8 +656,8 @@ private void writeCode( CodeInputStream byteCode, ConstantPool constantPool ) t
693656
//TODO case 183: // invokespecial
694657
case 184: // invokestatic
695658
idx = byteCode.readUnsignedShort();
696-
ConstantRef method = (ConstantRef)constantPool.get( idx );
697-
instr = new WasmCallInstruction( method, codePos );
659+
ref = (ConstantRef)constantPool.get( idx );
660+
instr = new WasmCallInstruction( ref, codePos );
698661
break;
699662
//TODO case 185: // invokeinterface
700663
//TODO case 187: // new

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

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 Volker Berlin (i-net software)
2+
* Copyright 2017 - 2018 Volker Berlin (i-net software)
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,6 +15,8 @@
1515
*/
1616
package de.inetsoftware.jwebassembly.module;
1717

18+
import de.inetsoftware.jwebassembly.WasmException;
19+
1820
/**
1921
* @author Volker Berlin
2022
*/
@@ -49,4 +51,42 @@ private ValueType( int code ) {
4951
public int getCode() {
5052
return code;
5153
}
54+
55+
/**
56+
* Get the WebAssembly value type from a Java signature.
57+
*
58+
* @param javaSignature
59+
* the signature
60+
* @param idx
61+
* the index in the signature
62+
* @return the value type or null if void
63+
*/
64+
public static ValueType getValueType( String javaSignature, int idx ) {
65+
String javaType;
66+
switch( javaSignature.charAt( idx ) ) {
67+
case '[': // array
68+
javaType = "array";
69+
break;
70+
case 'L':
71+
javaType = "object";
72+
break;
73+
case 'B': // byte
74+
case 'C': // char
75+
case 'S': // short
76+
case 'I': // int
77+
return ValueType.i32;
78+
case 'D': // double
79+
return ValueType.f64;
80+
case 'F': // float
81+
return ValueType.f32;
82+
case 'J': // long
83+
return ValueType.i64;
84+
case 'V': // void
85+
return null;
86+
default:
87+
javaType = javaSignature.substring( idx, idx + 1 );
88+
}
89+
throw new WasmException( "Not supported Java data type in method signature: " + javaType, null, -1 );
90+
}
91+
5292
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class WasmCallInstruction extends WasmInstruction {
4646
super( javaCodePos );
4747
this.method = method;
4848
String signature = method.getType();
49-
this.valueType = ModuleGenerator.getValueType( signature, signature.indexOf( ')' ) + 1 );
49+
this.valueType = ValueType.getValueType( signature, signature.indexOf( ')' ) + 1 );
5050
}
5151

5252
/**
@@ -77,7 +77,7 @@ int getPopCount() {
7777
return paramCount;
7878
}
7979
paramCount++;
80-
ModuleGenerator.getValueType( signature, i );
80+
ValueType.getValueType( signature, i );
8181
}
8282
throw new Error();
8383
}

0 commit comments

Comments
 (0)