mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-25 07:27:52 +01:00
write the function type definitions to the text format
This commit is contained in:
parent
748b7e5b89
commit
6468df956f
@ -57,6 +57,10 @@ public class TextModuleWriter extends ModuleWriter {
|
|||||||
|
|
||||||
private final ArrayList<String> methodParamNames = new ArrayList<>();
|
private final ArrayList<String> methodParamNames = new ArrayList<>();
|
||||||
|
|
||||||
|
private StringBuilder typeOutput = new StringBuilder();
|
||||||
|
|
||||||
|
private ArrayList<String> types = new ArrayList<>();
|
||||||
|
|
||||||
private StringBuilder methodOutput = new StringBuilder();
|
private StringBuilder methodOutput = new StringBuilder();
|
||||||
|
|
||||||
private int inset;
|
private int inset;
|
||||||
@ -98,6 +102,11 @@ public class TextModuleWriter extends ModuleWriter {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
|
for( int i = 0; i < types.size(); i++ ) {
|
||||||
|
newline( output );
|
||||||
|
output.append( "(type $t" ).append( Integer.toString( i ) ).append( " (func" ).append( types.get( i ) ).append( "))" );
|
||||||
|
}
|
||||||
|
|
||||||
output.append( methodOutput );
|
output.append( methodOutput );
|
||||||
|
|
||||||
if( callIndirect ) {
|
if( callIndirect ) {
|
||||||
@ -230,6 +239,7 @@ public class TextModuleWriter extends ModuleWriter {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void writeMethodStart( FunctionName name, String sourceFile ) throws IOException {
|
protected void writeMethodStart( FunctionName name, String sourceFile ) throws IOException {
|
||||||
|
typeOutput.setLength( 0 );
|
||||||
newline( methodOutput );
|
newline( methodOutput );
|
||||||
methodOutput.append( "(func $" );
|
methodOutput.append( "(func $" );
|
||||||
methodOutput.append( normalizeName( name ) );
|
methodOutput.append( normalizeName( name ) );
|
||||||
@ -261,7 +271,12 @@ public class TextModuleWriter extends ModuleWriter {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void writeMethodParam( String kind, AnyType valueType, @Nullable String name ) throws IOException {
|
protected void writeMethodParam( String kind, AnyType valueType, @Nullable String name ) throws IOException {
|
||||||
methodOutput.append( " (" ).append( kind );
|
if( kind != "local" ) {
|
||||||
|
typeOutput.append( '(' ).append( kind ).append( ' ' );
|
||||||
|
writeTypeName( typeOutput, valueType );
|
||||||
|
typeOutput.append( ')' );
|
||||||
|
}
|
||||||
|
methodOutput.append( '(' ).append( kind );
|
||||||
if( debugNames ) {
|
if( debugNames ) {
|
||||||
if( name != null ) {
|
if( name != null ) {
|
||||||
methodOutput.append( " $" ).append( name );
|
methodOutput.append( " $" ).append( name );
|
||||||
@ -280,6 +295,12 @@ public class TextModuleWriter extends ModuleWriter {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void writeMethodParamFinish( ) throws IOException {
|
protected void writeMethodParamFinish( ) throws IOException {
|
||||||
|
String typeStr = typeOutput.toString();
|
||||||
|
int idx = types.indexOf( typeStr );
|
||||||
|
if( idx < 0 ) {
|
||||||
|
idx = types.size();
|
||||||
|
types.add( typeStr );
|
||||||
|
}
|
||||||
if( isImport ) {
|
if( isImport ) {
|
||||||
isImport = false;
|
isImport = false;
|
||||||
methodOutput.append( "))" );
|
methodOutput.append( "))" );
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
(module
|
(module
|
||||||
(export "abc" (func $de/inetsoftware/jwebassembly/samples/FunctionParameters.singleInt))
|
(export "abc" (func $de/inetsoftware/jwebassembly/samples/FunctionParameters.singleInt))
|
||||||
(func $de/inetsoftware/jwebassembly/samples/FunctionParameters.singleInt (param i32) (local i32)
|
(type $t0 (func(param i32)))
|
||||||
|
(func $de/inetsoftware/jwebassembly/samples/FunctionParameters.singleInt(param i32)(local i32)
|
||||||
local.get 0
|
local.get 0
|
||||||
i32.const 1
|
i32.const 1
|
||||||
i32.add
|
i32.add
|
||||||
|
Loading…
x
Reference in New Issue
Block a user