mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-25 07:27:52 +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";
|
kind = "result";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
type = getValueType( signature, i );
|
type = ValueType.getValueType( signature, i );
|
||||||
if( type != null ) {
|
if( type != null ) {
|
||||||
writer.writeMethodParam( kind, type );
|
writer.writeMethodParam( kind, type );
|
||||||
}
|
}
|
||||||
@ -230,43 +230,6 @@ public class ModuleGenerator {
|
|||||||
writer.writeMethodParamFinish();
|
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.
|
* Write the byte code of a method.
|
||||||
*
|
*
|
||||||
@ -693,8 +656,8 @@ public class ModuleGenerator {
|
|||||||
//TODO case 183: // invokespecial
|
//TODO case 183: // invokespecial
|
||||||
case 184: // invokestatic
|
case 184: // invokestatic
|
||||||
idx = byteCode.readUnsignedShort();
|
idx = byteCode.readUnsignedShort();
|
||||||
ConstantRef method = (ConstantRef)constantPool.get( idx );
|
ref = (ConstantRef)constantPool.get( idx );
|
||||||
instr = new WasmCallInstruction( method, codePos );
|
instr = new WasmCallInstruction( ref, codePos );
|
||||||
break;
|
break;
|
||||||
//TODO case 185: // invokeinterface
|
//TODO case 185: // invokeinterface
|
||||||
//TODO case 187: // new
|
//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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -15,6 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package de.inetsoftware.jwebassembly.module;
|
package de.inetsoftware.jwebassembly.module;
|
||||||
|
|
||||||
|
import de.inetsoftware.jwebassembly.WasmException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Volker Berlin
|
* @author Volker Berlin
|
||||||
*/
|
*/
|
||||||
@ -49,4 +51,42 @@ public enum ValueType {
|
|||||||
public int getCode() {
|
public int getCode() {
|
||||||
return code;
|
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 );
|
super( javaCodePos );
|
||||||
this.method = method;
|
this.method = method;
|
||||||
String signature = method.getType();
|
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;
|
return paramCount;
|
||||||
}
|
}
|
||||||
paramCount++;
|
paramCount++;
|
||||||
ModuleGenerator.getValueType( signature, i );
|
ValueType.getValueType( signature, i );
|
||||||
}
|
}
|
||||||
throw new Error();
|
throw new Error();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user