mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-15 02:44:47 +01:00
Move method getValueType() into class ValueType.
This commit is contained in:
parent
2c6fb9aae0
commit
c269bae443
@ -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
|
||||
|
@ -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 );
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user