From 7d8424a2b0754e11c489e10dbd17ab833c4d0b3f Mon Sep 17 00:00:00 2001 From: Volker Berlin Date: Thu, 28 Mar 2019 18:26:25 +0100 Subject: [PATCH] pass sourcefile for a source map. #6 --- .../jwebassembly/binary/BinaryModuleWriter.java | 14 +++++++++++--- .../inetsoftware/jwebassembly/binary/Function.java | 4 ++++ .../jwebassembly/module/ModuleGenerator.java | 2 +- .../jwebassembly/module/ModuleWriter.java | 4 +++- .../jwebassembly/text/TextModuleWriter.java | 2 +- 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/de/inetsoftware/jwebassembly/binary/BinaryModuleWriter.java b/src/de/inetsoftware/jwebassembly/binary/BinaryModuleWriter.java index 94b19498..c0369427 100644 --- a/src/de/inetsoftware/jwebassembly/binary/BinaryModuleWriter.java +++ b/src/de/inetsoftware/jwebassembly/binary/BinaryModuleWriter.java @@ -58,6 +58,8 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod private final boolean debugNames; + private final boolean createSourceMap; + private WasmOutputStream codeStream = new WasmOutputStream(); private List functionTypes = new ArrayList<>(); @@ -90,7 +92,8 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod */ public BinaryModuleWriter( OutputStream output, HashMap properties ) throws IOException { wasm = new WasmOutputStream( output ); - debugNames = Boolean.parseBoolean( properties.get( JWebAssembly.DEBUG_NAMES ) ); + // for now we build the source map together with debug names + debugNames = createSourceMap = Boolean.parseBoolean( properties.get( JWebAssembly.DEBUG_NAMES ) ); } /** @@ -350,8 +353,11 @@ protected void writeExport( FunctionName name, String exportName ) throws IOExce * {@inheritDoc} */ @Override - protected void writeMethodStart( FunctionName name ) throws IOException { + protected void writeMethodStart( FunctionName name, String sourceFile ) throws IOException { function = getFunction( name ); + if( createSourceMap ) { + function.sourceFile = sourceFile; + } functionType = new FunctionTypeEntry(); codeStream.reset(); locals.clear(); @@ -399,7 +405,9 @@ protected void writeMethodParamFinish() throws IOException { */ @Override protected void markCodePosition( int javaCodePosition ) { - function.markCodePosition( codeStream.size(), javaCodePosition ); + if( createSourceMap ) { + function.markCodePosition( codeStream.size(), javaCodePosition ); + } } /** diff --git a/src/de/inetsoftware/jwebassembly/binary/Function.java b/src/de/inetsoftware/jwebassembly/binary/Function.java index 3078699e..0605f86d 100644 --- a/src/de/inetsoftware/jwebassembly/binary/Function.java +++ b/src/de/inetsoftware/jwebassembly/binary/Function.java @@ -33,6 +33,8 @@ class Function extends SectionEntry { WasmOutputStream functionsStream; + String sourceFile; + /** * {@inheritDoc} */ @@ -50,6 +52,8 @@ void writeSectionEntry( WasmOutputStream stream ) throws IOException { * the position in the Java Source file */ void markCodePosition( int streamPosition, int javaCodePosition ) { + if( sourceFile != null ) { // TODO Auto-generated method stub + } } } diff --git a/src/de/inetsoftware/jwebassembly/module/ModuleGenerator.java b/src/de/inetsoftware/jwebassembly/module/ModuleGenerator.java index ba544ee9..c0c14bf5 100644 --- a/src/de/inetsoftware/jwebassembly/module/ModuleGenerator.java +++ b/src/de/inetsoftware/jwebassembly/module/ModuleGenerator.java @@ -363,7 +363,7 @@ private void writeMethod( FunctionName name, MethodInfo method ) throws WasmExce } private void writeMethodImpl( FunctionName name, boolean isStatic, LocalVariableTable localVariableTable, WasmCodeBuilder codeBuilder ) throws WasmException, IOException { - writer.writeMethodStart( name ); + writer.writeMethodStart( name, sourceFile ); functions.writeFunction( name ); writeMethodSignature( name, isStatic, localVariableTable, codeBuilder ); diff --git a/src/de/inetsoftware/jwebassembly/module/ModuleWriter.java b/src/de/inetsoftware/jwebassembly/module/ModuleWriter.java index c229f42e..c70052ee 100644 --- a/src/de/inetsoftware/jwebassembly/module/ModuleWriter.java +++ b/src/de/inetsoftware/jwebassembly/module/ModuleWriter.java @@ -98,11 +98,13 @@ public void prepareFinish() { * Write the method header. * @param name * the function name + * @param sourceFile + * the name of the source file * * @throws IOException * if any I/O error occur */ - protected abstract void writeMethodStart( FunctionName name ) throws IOException; + protected abstract void writeMethodStart( FunctionName name, String sourceFile ) throws IOException; /** * Write a method parameter. diff --git a/src/de/inetsoftware/jwebassembly/text/TextModuleWriter.java b/src/de/inetsoftware/jwebassembly/text/TextModuleWriter.java index 456e8ff5..aba9af78 100644 --- a/src/de/inetsoftware/jwebassembly/text/TextModuleWriter.java +++ b/src/de/inetsoftware/jwebassembly/text/TextModuleWriter.java @@ -162,7 +162,7 @@ protected void writeExport( FunctionName name, String exportName ) throws IOExce * {@inheritDoc} */ @Override - protected void writeMethodStart( FunctionName name ) throws IOException { + protected void writeMethodStart( FunctionName name, String sourceFile ) throws IOException { newline( methodOutput ); methodOutput.append( "(func $" ); methodOutput.append( name.fullName );