From 6e04ade375dae630b016c0ea818466ffaabf061c Mon Sep 17 00:00:00 2001 From: Volker Berlin Date: Sat, 21 Mar 2020 11:05:51 +0100 Subject: [PATCH] abstract Methods and interfaces not counting as real WASM functions --- .../jwebassembly/text/TextModuleWriter.java | 51 +++++++++++-------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/src/de/inetsoftware/jwebassembly/text/TextModuleWriter.java b/src/de/inetsoftware/jwebassembly/text/TextModuleWriter.java index fee36a2..70cf0e5 100644 --- a/src/de/inetsoftware/jwebassembly/text/TextModuleWriter.java +++ b/src/de/inetsoftware/jwebassembly/text/TextModuleWriter.java @@ -54,35 +54,37 @@ import de.inetsoftware.jwebassembly.wasm.WasmBlockOperator; */ public class TextModuleWriter extends ModuleWriter { - private final boolean spiderMonkey = Boolean.getBoolean( "SpiderMonkey" ); + private final boolean spiderMonkey = Boolean.getBoolean( "SpiderMonkey" ); - private final WasmTarget target; + private final WasmTarget target; - private StringBuilder output = new StringBuilder(); + private final StringBuilder output = new StringBuilder(); - private final ArrayList methodParamNames = new ArrayList<>(); + private final ArrayList methodParamNames = new ArrayList<>(); - private StringBuilder typeOutput = new StringBuilder(); + private final StringBuilder typeOutput = new StringBuilder(); - private ArrayList types = new ArrayList<>(); + private final ArrayList types = new ArrayList<>(); - private StringBuilder methodOutput; + private StringBuilder methodOutput; - private StringBuilder imports = new StringBuilder(); + private final StringBuilder imports = new StringBuilder(); - private Map functions = new LinkedHashMap<>(); + private final Map functions = new LinkedHashMap<>(); - private final Set functionNames = new HashSet<>(); + private final Map abstracts = new HashMap<>(); - private int inset; + private final Set functionNames = new HashSet<>(); - private boolean isImport; + private int inset; - private HashMap globals = new HashMap<>(); + private boolean isImport; - private boolean useExceptions; + private final HashMap globals = new HashMap<>(); - private boolean callIndirect; + private boolean useExceptions; + + private boolean callIndirect; /** * Create a new instance. @@ -330,6 +332,9 @@ public class TextModuleWriter extends ModuleWriter { */ @Override protected void writeMethodParamStart( @Nonnull FunctionName name, FunctionType funcType ) throws IOException { + if( funcType == FunctionType.Abstract ) { + abstracts.put( name.signatureName, new Function() ); + } typeOutput.setLength( 0 ); methodParamNames.clear(); } @@ -382,11 +387,15 @@ public class TextModuleWriter extends ModuleWriter { } private Function getFunction( FunctionName name ) { - Function func = functions.get( name.signatureName ); + String signatureName = name.signatureName; + Function func = functions.get( signatureName ); if( func == null ) { - func = new Function(); - func.id = functions.size(); - functions.put( name.signatureName, func ); + func = abstracts.get( signatureName ); + if( func == null ) { + func = new Function(); + func.id = functions.size(); + functions.put( name.signatureName, func ); + } } return func; } @@ -690,9 +699,9 @@ public class TextModuleWriter extends ModuleWriter { newline( methodOutput ); if(spiderMonkey) - methodOutput.append( "call_indirect $t" ).append( functions.get( name.signatureName ).typeId ); // https://bugzilla.mozilla.org/show_bug.cgi?id=1556779 + methodOutput.append( "call_indirect $t" ).append( getFunction( name ).typeId ); // https://bugzilla.mozilla.org/show_bug.cgi?id=1556779 else - methodOutput.append( "call_indirect (type $t" ).append( functions.get( name.signatureName ).typeId ).append( ") ;; " + name.signatureName ); + methodOutput.append( "call_indirect (type $t" ).append( getFunction( name ).typeId ).append( ") ;; " + name.signatureName ); } /**