simplify the string count

This commit is contained in:
Volker Berlin 2020-03-11 20:03:00 +01:00
parent cc4a5e7858
commit a6f1743109
5 changed files with 5 additions and 27 deletions

View File

@ -168,7 +168,7 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
* if any I/O error occur
*/
private void writeTableSection() throws IOException {
int stringCount = getStringCount();
int stringCount = options.strings.size();
int typeCount = options.types.size();
if( !callIndirect && stringCount == 0 ) {
return;

View File

@ -1,5 +1,5 @@
/*
* Copyright 2017 - 2019 Volker Berlin (i-net software)
* Copyright 2017 - 2020 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.
@ -51,8 +51,6 @@ public abstract class ModuleWriter implements Closeable {
*/
protected final ByteArrayOutputStream dataStream = new ByteArrayOutputStream();
private int stringCount;
/**
* Create a instance with its options.
*
@ -63,25 +61,6 @@ public abstract class ModuleWriter implements Closeable {
this.options = options;
}
/**
* Set the used string counts
*
* @param count
* the count
*/
void setStringCount( int count ) {
this.stringCount = count;
}
/**
* Get the string count
*
* @return the count
*/
protected int getStringCount() {
return stringCount;
}
/**
* Finish the prepare after all classes/methods are prepare. This must be call before we can start with write the
* first method.

View File

@ -33,7 +33,7 @@ import de.inetsoftware.jwebassembly.wasm.ValueType;
*
* @author Volker Berlin
*/
class StringManager extends LinkedHashMap<String, Integer> {
public class StringManager extends LinkedHashMap<String, Integer> {
/**
* Signature of method stringConstant.
@ -106,7 +106,6 @@ class StringManager extends LinkedHashMap<String, Integer> {
void prepareFinish( ModuleWriter writer ) throws IOException {
// inform the writer of string count that it can allocate a table of type anyref for the constant strings
int size = size();
writer.setStringCount( size );
if( size == 0 ) {
// no strings, nothing to do
return;

View File

@ -39,7 +39,7 @@ public class WasmOptions {
public final TypeManager types = new TypeManager( this );
final StringManager strings = new StringManager( this );
public final StringManager strings = new StringManager( this );
final CodeOptimizer optimizer = new CodeOptimizer();

View File

@ -146,7 +146,7 @@ public class TextModuleWriter extends ModuleWriter {
}
// table for string constants
int stringCount = getStringCount();
int stringCount = options.strings.size();
if( stringCount > 0 ) {
if( !callIndirect ) {
// we need to create a placeholder table with index 0 if not exists