mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-25 07:27:52 +01:00
Generalize the usage of SyntheticFuctionName
This commit is contained in:
parent
04b3b67927
commit
09b817117a
@ -352,11 +352,11 @@ class JavaMethodWasmCodeBuilder extends WasmCodeBuilder {
|
|||||||
break;
|
break;
|
||||||
case 114: // frem
|
case 114: // frem
|
||||||
//helper function like: (a - (int)(a / b) * (float)b)
|
//helper function like: (a - (int)(a / b) * (float)b)
|
||||||
addCallInstruction( new SyntheticFunctionName( "frem", "local.get 0 local.get 0 local.get 1 f32.div i32.trunc_sat_f32_s f32.convert_i32_s local.get 1 f32.mul f32.sub return", ValueType.f32, ValueType.f32, null, ValueType.f32 ), codePos, lineNumber );
|
addCallInstruction( new WatCodeSyntheticFunctionName( "frem", "local.get 0 local.get 0 local.get 1 f32.div i32.trunc_sat_f32_s f32.convert_i32_s local.get 1 f32.mul f32.sub return", ValueType.f32, ValueType.f32, null, ValueType.f32 ), codePos, lineNumber );
|
||||||
break;
|
break;
|
||||||
case 115: // drem
|
case 115: // drem
|
||||||
//helper function like: (a - (long)(a / b) * (double)b)
|
//helper function like: (a - (long)(a / b) * (double)b)
|
||||||
addCallInstruction( new SyntheticFunctionName( "drem", "local.get 0 local.get 0 local.get 1 f64.div i64.trunc_sat_f64_s f64.convert_i64_s local.get 1 f64.mul f64.sub return", ValueType.f64, ValueType.f64, null, ValueType.f64 ), codePos, lineNumber );
|
addCallInstruction( new WatCodeSyntheticFunctionName( "drem", "local.get 0 local.get 0 local.get 1 f64.div i64.trunc_sat_f64_s f64.convert_i64_s local.get 1 f64.mul f64.sub return", ValueType.f64, ValueType.f64, null, ValueType.f64 ), codePos, lineNumber );
|
||||||
break;
|
break;
|
||||||
case 116: // ineg
|
case 116: // ineg
|
||||||
addConstInstruction( -1, ValueType.i32, codePos, lineNumber );
|
addConstInstruction( -1, ValueType.i32, codePos, lineNumber );
|
||||||
|
@ -164,8 +164,7 @@ public class ModuleGenerator {
|
|||||||
InputStream stream = libraries.getResourceAsStream( next.className + ".class" );
|
InputStream stream = libraries.getResourceAsStream( next.className + ".class" );
|
||||||
if( stream == null ) {
|
if( stream == null ) {
|
||||||
if( next instanceof SyntheticFunctionName ) {
|
if( next instanceof SyntheticFunctionName ) {
|
||||||
watParser.parse( ((SyntheticFunctionName)next).getCode(), -1 );
|
writeMethodImpl( next, true, ((SyntheticFunctionName)next).getCodeBuilder( watParser ) );
|
||||||
writeMethodImpl( next, true, watParser );
|
|
||||||
} else {
|
} else {
|
||||||
throw new WasmException( "Missing function: " + next.signatureName, -1 );
|
throw new WasmException( "Missing function: " + next.signatureName, -1 );
|
||||||
}
|
}
|
||||||
|
@ -20,32 +20,28 @@ import java.util.Arrays;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import de.inetsoftware.jwebassembly.wasm.AnyType;
|
import de.inetsoftware.jwebassembly.wasm.AnyType;
|
||||||
|
import de.inetsoftware.jwebassembly.watparser.WatParser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Synthetic/dynamic method.
|
* Synthetic/dynamic method.
|
||||||
*
|
*
|
||||||
* @author Volker Berlin
|
* @author Volker Berlin
|
||||||
*/
|
*/
|
||||||
public class SyntheticFunctionName extends FunctionName {
|
abstract class SyntheticFunctionName extends FunctionName {
|
||||||
|
|
||||||
private final AnyType[] signature;
|
private final AnyType[] signature;
|
||||||
|
|
||||||
private final String code;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new instance.
|
* Create a new instance.
|
||||||
*
|
*
|
||||||
* @param name
|
* @param name
|
||||||
* the function name
|
* the function name
|
||||||
* @param code
|
|
||||||
* the WAT code (WASM in text form)
|
|
||||||
* @param signature
|
* @param signature
|
||||||
* the method signature, first the parameters, then null and the the return types
|
* the method signature, first the parameters, then null and the the return types
|
||||||
*/
|
*/
|
||||||
public SyntheticFunctionName( String name, String code, AnyType... signature ) {
|
public SyntheticFunctionName( String name, AnyType... signature ) {
|
||||||
super( "", name, "()V" ); //TODO better signature name
|
super( "", name, "()V" ); //TODO better signature name
|
||||||
this.signature = signature;
|
this.signature = signature;
|
||||||
this.code = code;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -57,11 +53,10 @@ public class SyntheticFunctionName extends FunctionName {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the WAT code (WASM in text form)
|
* Get the WasmCodeBuilder.
|
||||||
*
|
*
|
||||||
|
* @param watParser a helping WatParser
|
||||||
* @return the code
|
* @return the code
|
||||||
*/
|
*/
|
||||||
public String getCode() {
|
abstract WasmCodeBuilder getCodeBuilder( WatParser watParser );
|
||||||
return code;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2019 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.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
|
||||||
|
*/
|
||||||
|
package de.inetsoftware.jwebassembly.module;
|
||||||
|
|
||||||
|
import de.inetsoftware.jwebassembly.wasm.AnyType;
|
||||||
|
import de.inetsoftware.jwebassembly.watparser.WatParser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Synthetic/dynamic method based on WAT code (WASM in text form).
|
||||||
|
*
|
||||||
|
* @author Volker Berlin
|
||||||
|
*/
|
||||||
|
class WatCodeSyntheticFunctionName extends SyntheticFunctionName {
|
||||||
|
|
||||||
|
private final String code;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new instance.
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* the function name
|
||||||
|
* @param code
|
||||||
|
* the WAT code (WASM in text form)
|
||||||
|
* @param signature
|
||||||
|
* the method signature, first the parameters, then null and the the return types
|
||||||
|
*/
|
||||||
|
public WatCodeSyntheticFunctionName( String name, String code, AnyType... signature ) {
|
||||||
|
super( name, signature );
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public WasmCodeBuilder getCodeBuilder( WatParser watParser ) {
|
||||||
|
watParser.parse( code, -1 );
|
||||||
|
return watParser;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user