Skip to content

Commit

Permalink
pass sourcefile for a source map. #6
Browse files Browse the repository at this point in the history
  • Loading branch information
Horcrux7 committed Mar 28, 2019
1 parent 97b7b9d commit 7d8424a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
14 changes: 11 additions & 3 deletions src/de/inetsoftware/jwebassembly/binary/BinaryModuleWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<TypeEntry> functionTypes = new ArrayList<>();
Expand Down Expand Up @@ -90,7 +92,8 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
*/
public BinaryModuleWriter( OutputStream output, HashMap<String, String> 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 ) );
}

/**
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 );
}
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/de/inetsoftware/jwebassembly/binary/Function.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class Function extends SectionEntry {

WasmOutputStream functionsStream;

String sourceFile;

/**
* {@inheritDoc}
*/
Expand All @@ -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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down
4 changes: 3 additions & 1 deletion src/de/inetsoftware/jwebassembly/module/ModuleWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down

0 comments on commit 7d8424a

Please sign in to comment.