mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-15 02:44:47 +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 ) {
|
||||
CodeInputStream byteCode = null;
|
||||
try {
|
||||
reset( code.getLocalVariableTable(), method );
|
||||
reset( code.getLocalVariableTable(), method, null );
|
||||
branchManager.reset( code );
|
||||
|
||||
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");
|
||||
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.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
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
|
||||
* variable table of the Java 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;
|
||||
|
||||
int maxLocals;
|
||||
@ -157,9 +160,9 @@ class LocaleVariableManager {
|
||||
}
|
||||
|
||||
// add missing slots from signature
|
||||
if( (maxLocals > 0 || variableTable == null) && size == 0 && method != null ) {
|
||||
ValueTypeParser parser = new ValueTypeParser( method.getType(), types );
|
||||
if( !method.isStatic() ) {
|
||||
if( (maxLocals > 0 || variableTable == null) && size == 0 && (method != null || signature != null )) {
|
||||
Iterator<AnyType> parser = signature == null ? new ValueTypeParser( method.getType(), types ) : signature;
|
||||
if( method != null && !method.isStatic() ) {
|
||||
resetAddVar( ValueType.anyref, size );
|
||||
}
|
||||
while( true ) {
|
||||
|
@ -480,7 +480,7 @@ public class ModuleGenerator {
|
||||
if( signature == null ) {
|
||||
signature = method.getType();
|
||||
}
|
||||
watParser.parse( watCode, method, code == null ? -1 : code.getFirstLineNr() );
|
||||
watParser.parse( watCode, method, null, code == null ? -1 : code.getFirstLineNr() );
|
||||
return watParser;
|
||||
} else if( code != null ) { // abstract methods and interface methods does not have code
|
||||
javaCodeBuilder.buildCode( code, method );
|
||||
|
@ -17,6 +17,7 @@ package de.inetsoftware.jwebassembly.module;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
@ -247,11 +248,13 @@ public abstract class WasmCodeBuilder {
|
||||
* @param variableTable
|
||||
* variable table of the Java 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();
|
||||
localVariables.reset( variableTable, method );
|
||||
localVariables.reset( variableTable, method, signature );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -87,7 +87,7 @@ class WatCodeSyntheticFunctionName extends ArraySyntheticFunctionName {
|
||||
*/
|
||||
@Override
|
||||
protected WasmCodeBuilder getCodeBuilder( WatParser watParser ) {
|
||||
watParser.parse( getCode(), null, -1 );
|
||||
watParser.parse( getCode(), null, getSignature( null ), -1 );
|
||||
return watParser;
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
package de.inetsoftware.jwebassembly.watparser;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnegative;
|
||||
@ -50,14 +51,16 @@ public class WatParser extends WasmCodeBuilder {
|
||||
*
|
||||
* @param wat
|
||||
* the text format content of a function
|
||||
* @param lineNumber
|
||||
* the line number for an error message
|
||||
* @param method
|
||||
* 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 {
|
||||
reset( null, method );
|
||||
reset( null, method, signature );
|
||||
|
||||
List<String> tokens = splitTokens( wat );
|
||||
for( int i = 0; i < tokens.size(); i++ ) {
|
||||
|
@ -40,7 +40,7 @@ public class WatParserTest {
|
||||
WatParser parser = new WatParser();
|
||||
WasmCodeBuilder codeBuilder = parser;
|
||||
codeBuilder.init( options, null );
|
||||
parser.parse( wat, null, 100 );
|
||||
parser.parse( wat, null, null, 100 );
|
||||
StringBuilder builder = new StringBuilder();
|
||||
ModuleWriter writer = new TextModuleWriter( new WasmTarget( builder ), options );
|
||||
writer.writeMethodStart( new FunctionName( "A.a()V" ), null );
|
||||
|
Loading…
x
Reference in New Issue
Block a user