Move method getValueType() into class ValueType.

This commit is contained in:
Volker 2018-08-14 12:14:36 +02:00
parent 2c6fb9aae0
commit c269bae443
3 changed files with 46 additions and 43 deletions

View File

@ -221,7 +221,7 @@ public class ModuleGenerator {
kind = "result";
continue;
}
type = getValueType( signature, i );
type = ValueType.getValueType( signature, i );
if( type != null ) {
writer.writeMethodParam( kind, type );
}
@ -230,43 +230,6 @@ public class ModuleGenerator {
writer.writeMethodParamFinish();
}
/**
* Get the WebAssembly value type from a Java signature.
*
* @param signature
* the signature
* @param idx
* the index in the signature
* @return the value type or null if void
*/
static ValueType getValueType( String signature, int idx ) {
String javaType;
switch( signature.charAt( idx ) ) {
case '[': // array
javaType = "array";
break;
case 'L':
javaType = "object";
break;
case 'B': // byte
case 'C': // char
case 'S': // short
case 'I': // int
return ValueType.i32;
case 'D': // double
return ValueType.f64;
case 'F': // float
return ValueType.f32;
case 'J': // long
return ValueType.i64;
case 'V': // void
return null;
default:
javaType = signature.substring( idx, idx + 1 );
}
throw new WasmException( "Not supported Java data type in method signature: " + javaType, null, -1 );
}
/**
* Write the byte code of a method.
*
@ -693,8 +656,8 @@ public class ModuleGenerator {
//TODO case 183: // invokespecial
case 184: // invokestatic
idx = byteCode.readUnsignedShort();
ConstantRef method = (ConstantRef)constantPool.get( idx );
instr = new WasmCallInstruction( method, codePos );
ref = (ConstantRef)constantPool.get( idx );
instr = new WasmCallInstruction( ref, codePos );
break;
//TODO case 185: // invokeinterface
//TODO case 187: // new

View File

@ -1,5 +1,5 @@
/*
* Copyright 2017 Volker Berlin (i-net software)
* Copyright 2017 - 2018 Volker Berlin (i-net software)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -15,6 +15,8 @@
*/
package de.inetsoftware.jwebassembly.module;
import de.inetsoftware.jwebassembly.WasmException;
/**
* @author Volker Berlin
*/
@ -49,4 +51,42 @@ public enum ValueType {
public int getCode() {
return code;
}
/**
* Get the WebAssembly value type from a Java signature.
*
* @param javaSignature
* the signature
* @param idx
* the index in the signature
* @return the value type or null if void
*/
public static ValueType getValueType( String javaSignature, int idx ) {
String javaType;
switch( javaSignature.charAt( idx ) ) {
case '[': // array
javaType = "array";
break;
case 'L':
javaType = "object";
break;
case 'B': // byte
case 'C': // char
case 'S': // short
case 'I': // int
return ValueType.i32;
case 'D': // double
return ValueType.f64;
case 'F': // float
return ValueType.f32;
case 'J': // long
return ValueType.i64;
case 'V': // void
return null;
default:
javaType = javaSignature.substring( idx, idx + 1 );
}
throw new WasmException( "Not supported Java data type in method signature: " + javaType, null, -1 );
}
}

View File

@ -46,7 +46,7 @@ class WasmCallInstruction extends WasmInstruction {
super( javaCodePos );
this.method = method;
String signature = method.getType();
this.valueType = ModuleGenerator.getValueType( signature, signature.indexOf( ')' ) + 1 );
this.valueType = ValueType.getValueType( signature, signature.indexOf( ')' ) + 1 );
}
/**
@ -77,7 +77,7 @@ class WasmCallInstruction extends WasmInstruction {
return paramCount;
}
paramCount++;
ModuleGenerator.getValueType( signature, i );
ValueType.getValueType( signature, i );
}
throw new Error();
}