diff --git a/src/de/inetsoftware/jwebassembly/JWebAssembly.java b/src/de/inetsoftware/jwebassembly/JWebAssembly.java index 6612456..3f9e4fc 100644 --- a/src/de/inetsoftware/jwebassembly/JWebAssembly.java +++ b/src/de/inetsoftware/jwebassembly/JWebAssembly.java @@ -48,6 +48,8 @@ public class JWebAssembly { private final HashMap properties = new HashMap<>(); + public static final String DEBUG_NAMES = "DebugNames"; + /** * Create a instance. */ @@ -123,8 +125,8 @@ public class JWebAssembly { * if any conversion error occurs */ public void compileToText( File file ) throws WasmException { - try (TextModuleWriter writer = new TextModuleWriter( new OutputStreamWriter( new FileOutputStream( file ), StandardCharsets.UTF_8 ) )) { - compile( writer ); + try (OutputStreamWriter output = new OutputStreamWriter( new FileOutputStream( file ), StandardCharsets.UTF_8 )) { + compileToText( output ); } catch( Exception ex ) { throw WasmException.create( ex ); } @@ -139,7 +141,7 @@ public class JWebAssembly { * if any conversion error occurs */ public void compileToText( Appendable output ) throws WasmException { - try (TextModuleWriter writer = new TextModuleWriter( output )) { + try (TextModuleWriter writer = new TextModuleWriter( output, properties )) { compile( writer ); } catch( Exception ex ) { throw WasmException.create( ex ); @@ -184,7 +186,7 @@ public class JWebAssembly { * if any conversion error occurs */ public void compileToBinary( OutputStream output ) throws WasmException { - try (BinaryModuleWriter writer = new BinaryModuleWriter( output )) { + try (BinaryModuleWriter writer = new BinaryModuleWriter( output, properties )) { compile( writer ); } catch( Exception ex ) { throw WasmException.create( ex ); diff --git a/src/de/inetsoftware/jwebassembly/binary/BinaryModuleWriter.java b/src/de/inetsoftware/jwebassembly/binary/BinaryModuleWriter.java index a9a6e59..2a16d57 100644 --- a/src/de/inetsoftware/jwebassembly/binary/BinaryModuleWriter.java +++ b/src/de/inetsoftware/jwebassembly/binary/BinaryModuleWriter.java @@ -20,6 +20,7 @@ import java.io.OutputStream; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -28,6 +29,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import de.inetsoftware.classparser.ConstantRef; +import de.inetsoftware.jwebassembly.JWebAssembly; import de.inetsoftware.jwebassembly.WasmException; import de.inetsoftware.jwebassembly.module.FunctionName; import de.inetsoftware.jwebassembly.module.ModuleWriter; @@ -49,6 +51,8 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod private WasmOutputStream wasm; + private final boolean debugNames; + private WasmOutputStream codeStream = new WasmOutputStream(); private WasmOutputStream functionsStream = new WasmOutputStream(); @@ -74,11 +78,14 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod * * @param output * the target for the module data. + * @param properties + * compiler properties * @throws IOException * if any I/O error occur */ - public BinaryModuleWriter( OutputStream output ) throws IOException { + public BinaryModuleWriter( OutputStream output, HashMap properties ) throws IOException { wasm = new WasmOutputStream( output ); + debugNames = Boolean.parseBoolean( properties.get( JWebAssembly.DEBUG_NAMES ) ); } /** diff --git a/src/de/inetsoftware/jwebassembly/text/TextModuleWriter.java b/src/de/inetsoftware/jwebassembly/text/TextModuleWriter.java index f1a54d6..221e1f0 100644 --- a/src/de/inetsoftware/jwebassembly/text/TextModuleWriter.java +++ b/src/de/inetsoftware/jwebassembly/text/TextModuleWriter.java @@ -16,6 +16,7 @@ package de.inetsoftware.jwebassembly.text; import java.io.IOException; +import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -53,10 +54,12 @@ public class TextModuleWriter extends ModuleWriter { * * @param output * target for the result + * @param properties + * compiler properties * @throws IOException * if any I/O error occur */ - public TextModuleWriter( Appendable output ) throws IOException { + public TextModuleWriter( Appendable output, HashMap properties ) throws IOException { this.output = output; output.append( "(module" ); inset++;