Skip to content

Commit

Permalink
passing code position for a source map. #6
Browse files Browse the repository at this point in the history
  • Loading branch information
Horcrux7 committed Mar 26, 2019
1 parent 018fa38 commit 97b7b9d
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,14 @@ protected void writeMethodParamFinish() throws IOException {
function.typeId = typeId;
}

/**
* {@inheritDoc}
*/
@Override
protected void markCodePosition( int javaCodePosition ) {
function.markCodePosition( codeStream.size(), javaCodePosition );
}

/**
* {@inheritDoc}
*/
Expand Down
14 changes: 13 additions & 1 deletion src/de/inetsoftware/jwebassembly/binary/Function.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017 - 2018 Volker Berlin (i-net software)
* Copyright 2017 - 2019 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.
Expand Down Expand Up @@ -40,4 +40,16 @@ class Function extends SectionEntry {
void writeSectionEntry( WasmOutputStream stream ) throws IOException {
stream.writeVaruint32( this.typeId );
}

/**
* Add code position marker for a source map.
*
* @param streamPosition
* the position in the function stream
* @param javaCodePosition
* the position in the Java Source file
*/
void markCodePosition( int streamPosition, int javaCodePosition ) {
// TODO Auto-generated method stub
}
}
7 changes: 7 additions & 0 deletions src/de/inetsoftware/jwebassembly/module/ModuleGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,8 @@ private void writeMethodImpl( FunctionName name, boolean isStatic, LocalVariable

List<WasmInstruction> instructions = codeBuilder.getInstructions();
optimizer.optimze( instructions );

int lastCodePosition = -1;
for( WasmInstruction instruction : instructions ) {
switch( instruction.getType() ) {
case Block:
Expand All @@ -388,6 +390,11 @@ private void writeMethodImpl( FunctionName name, boolean isStatic, LocalVariable
break;
default:
}
int codePosition = instruction.getCodePosition();
if( codePosition >= 0 && codePosition != lastCodePosition ) {
writer.markCodePosition( codePosition );
lastCodePosition = codePosition;
}
instruction.writeTo( writer );
}
writer.writeMethodFinish();
Expand Down
8 changes: 8 additions & 0 deletions src/de/inetsoftware/jwebassembly/module/ModuleWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ public void prepareFinish() {
*/
protected abstract void writeMethodParamFinish() throws IOException;

/**
* Mark the current output position with Java code position for crating of a source map.
*
* @param javaCodePosition
* the position in the Java code
*/
protected abstract void markCodePosition( int javaCodePosition );

/**
* Complete the method
*
Expand Down
8 changes: 8 additions & 0 deletions src/de/inetsoftware/jwebassembly/text/TextModuleWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,14 @@ protected void writeMethodParamFinish( ) throws IOException {
}
}

/**
* {@inheritDoc}
*/
@Override
protected void markCodePosition( int javaCodePosition ) {
// nothing
}

/**
* {@inheritDoc}
*/
Expand Down

0 comments on commit 97b7b9d

Please sign in to comment.