mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-25 07:27:52 +01:00
pass the signature from synthetic functions to the wat parser.
This commit is contained in:
parent
03957b0988
commit
d3f7069cc8
@ -60,7 +60,7 @@ class JavaMethodWasmCodeBuilder extends WasmCodeBuilder {
|
|||||||
void buildCode( @Nonnull Code code, MethodInfo method ) {
|
void buildCode( @Nonnull Code code, MethodInfo method ) {
|
||||||
CodeInputStream byteCode = null;
|
CodeInputStream byteCode = null;
|
||||||
try {
|
try {
|
||||||
reset( code.getLocalVariableTable(), method );
|
reset( code.getLocalVariableTable(), method, null );
|
||||||
branchManager.reset( code );
|
branchManager.reset( code );
|
||||||
|
|
||||||
byteCode = code.getByteCode();
|
byteCode = code.getByteCode();
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2018 - 2019 Volker Berlin (i-net software)
|
Copyright 2018 - 2020 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.
|
||||||
@ -20,6 +20,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@ -74,14 +75,16 @@ class LocaleVariableManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reset the manager to an initial state
|
* Reset the manager to an initial state.
|
||||||
*
|
*
|
||||||
* @param variableTable
|
* @param variableTable
|
||||||
* variable table of the Java method.
|
* variable table of the Java method.
|
||||||
* @param method
|
* @param method
|
||||||
* the method with signature as fallback for a missing variable table
|
* the method with signature as fallback for a missing variable table. If null signature is used and the method must be static.
|
||||||
|
* @param signature
|
||||||
|
* alternative for method signature, can be null if method is set
|
||||||
*/
|
*/
|
||||||
void reset( LocalVariableTable variableTable, MethodInfo method ) {
|
void reset( LocalVariableTable variableTable, MethodInfo method, Iterator<AnyType> signature ) {
|
||||||
size = 0;
|
size = 0;
|
||||||
|
|
||||||
int maxLocals;
|
int maxLocals;
|
||||||
@ -157,9 +160,9 @@ class LocaleVariableManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// add missing slots from signature
|
// add missing slots from signature
|
||||||
if( (maxLocals > 0 || variableTable == null) && size == 0 && method != null ) {
|
if( (maxLocals > 0 || variableTable == null) && size == 0 && (method != null || signature != null )) {
|
||||||
ValueTypeParser parser = new ValueTypeParser( method.getType(), types );
|
Iterator<AnyType> parser = signature == null ? new ValueTypeParser( method.getType(), types ) : signature;
|
||||||
if( !method.isStatic() ) {
|
if( method != null && !method.isStatic() ) {
|
||||||
resetAddVar( ValueType.anyref, size );
|
resetAddVar( ValueType.anyref, size );
|
||||||
}
|
}
|
||||||
while( true ) {
|
while( true ) {
|
||||||
|
@ -480,7 +480,7 @@ public class ModuleGenerator {
|
|||||||
if( signature == null ) {
|
if( signature == null ) {
|
||||||
signature = method.getType();
|
signature = method.getType();
|
||||||
}
|
}
|
||||||
watParser.parse( watCode, method, code == null ? -1 : code.getFirstLineNr() );
|
watParser.parse( watCode, method, null, code == null ? -1 : code.getFirstLineNr() );
|
||||||
return watParser;
|
return watParser;
|
||||||
} else if( code != null ) { // abstract methods and interface methods does not have code
|
} else if( code != null ) { // abstract methods and interface methods does not have code
|
||||||
javaCodeBuilder.buildCode( code, method );
|
javaCodeBuilder.buildCode( code, method );
|
||||||
|
@ -17,6 +17,7 @@ package de.inetsoftware.jwebassembly.module;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
@ -247,11 +248,13 @@ public abstract class WasmCodeBuilder {
|
|||||||
* @param variableTable
|
* @param variableTable
|
||||||
* variable table of the Java method.
|
* variable table of the Java method.
|
||||||
* @param method
|
* @param method
|
||||||
* the method with signature as fallback for a missing variable table
|
* the method with signature as fallback for a missing variable table. If null signature is used and the method must be static.
|
||||||
|
* @param signature
|
||||||
|
* alternative for method signature, can be null if method is set
|
||||||
*/
|
*/
|
||||||
protected void reset( LocalVariableTable variableTable, MethodInfo method ) {
|
protected void reset( LocalVariableTable variableTable, MethodInfo method, Iterator<AnyType> signature ) {
|
||||||
instructions.clear();
|
instructions.clear();
|
||||||
localVariables.reset( variableTable, method );
|
localVariables.reset( variableTable, method, signature );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -87,7 +87,7 @@ class WatCodeSyntheticFunctionName extends ArraySyntheticFunctionName {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected WasmCodeBuilder getCodeBuilder( WatParser watParser ) {
|
protected WasmCodeBuilder getCodeBuilder( WatParser watParser ) {
|
||||||
watParser.parse( getCode(), null, -1 );
|
watParser.parse( getCode(), null, getSignature( null ), -1 );
|
||||||
return watParser;
|
return watParser;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
package de.inetsoftware.jwebassembly.watparser;
|
package de.inetsoftware.jwebassembly.watparser;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.annotation.Nonnegative;
|
import javax.annotation.Nonnegative;
|
||||||
@ -50,14 +51,16 @@ public class WatParser extends WasmCodeBuilder {
|
|||||||
*
|
*
|
||||||
* @param wat
|
* @param wat
|
||||||
* the text format content of a function
|
* the text format content of a function
|
||||||
* @param lineNumber
|
|
||||||
* the line number for an error message
|
|
||||||
* @param method
|
* @param method
|
||||||
* the method with signature as fallback for a missing variable table
|
* the method with signature as fallback for a missing variable table
|
||||||
|
* @param signature
|
||||||
|
* alternative for method signature, can be null if method is set
|
||||||
|
* @param lineNumber
|
||||||
|
* the line number for an error message
|
||||||
*/
|
*/
|
||||||
public void parse( String wat, MethodInfo method, int lineNumber ) {
|
public void parse( String wat, MethodInfo method, Iterator<AnyType> signature, int lineNumber ) {
|
||||||
try {
|
try {
|
||||||
reset( null, method );
|
reset( null, method, signature );
|
||||||
|
|
||||||
List<String> tokens = splitTokens( wat );
|
List<String> tokens = splitTokens( wat );
|
||||||
for( int i = 0; i < tokens.size(); i++ ) {
|
for( int i = 0; i < tokens.size(); i++ ) {
|
||||||
|
@ -40,7 +40,7 @@ public class WatParserTest {
|
|||||||
WatParser parser = new WatParser();
|
WatParser parser = new WatParser();
|
||||||
WasmCodeBuilder codeBuilder = parser;
|
WasmCodeBuilder codeBuilder = parser;
|
||||||
codeBuilder.init( options, null );
|
codeBuilder.init( options, null );
|
||||||
parser.parse( wat, null, 100 );
|
parser.parse( wat, null, null, 100 );
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
ModuleWriter writer = new TextModuleWriter( new WasmTarget( builder ), options );
|
ModuleWriter writer = new TextModuleWriter( new WasmTarget( builder ), options );
|
||||||
writer.writeMethodStart( new FunctionName( "A.a()V" ), null );
|
writer.writeMethodStart( new FunctionName( "A.a()V" ), null );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user