mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-15 02:44:47 +01:00
simplify the initializing
This commit is contained in:
parent
f2547bd0d2
commit
2f2c39a07a
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019 Volker Berlin (i-net software)
|
||||
* Copyright 2019 - 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.
|
||||
@ -25,7 +25,7 @@ import de.inetsoftware.jwebassembly.wasm.VariableOperator;
|
||||
*
|
||||
* @author Volker Berlin
|
||||
*/
|
||||
class CodeOptimizer {
|
||||
public class CodeOptimizer {
|
||||
|
||||
/**
|
||||
* Optimize the code before writing.
|
||||
@ -33,7 +33,7 @@ class CodeOptimizer {
|
||||
* @param instructions
|
||||
* the list of instructions
|
||||
*/
|
||||
public void optimze( List<WasmInstruction> instructions ) {
|
||||
void optimze( List<WasmInstruction> instructions ) {
|
||||
for( int i = instructions.size()-1; i >= 0; i-- ) {
|
||||
WasmInstruction instr = instructions.get( i );
|
||||
switch( instr.getType() ) {
|
||||
|
@ -70,13 +70,13 @@ public class ModuleGenerator {
|
||||
|
||||
private String className;
|
||||
|
||||
private FunctionManager functions = new FunctionManager();
|
||||
private final FunctionManager functions;
|
||||
|
||||
private TypeManager types = new TypeManager();
|
||||
private final TypeManager types;
|
||||
|
||||
private StringManager strings = new StringManager();
|
||||
private final StringManager strings;
|
||||
|
||||
private CodeOptimizer optimizer = new CodeOptimizer();
|
||||
private final CodeOptimizer optimizer;
|
||||
|
||||
/**
|
||||
* Create a new generator.
|
||||
@ -95,10 +95,12 @@ public class ModuleGenerator {
|
||||
this.javaScript = new JavaScriptWriter( target );
|
||||
this.classFileLoader = new ClassFileLoader( new URLClassLoader( libraries.toArray( new URL[libraries.size()] ) ) );
|
||||
WasmOptions options = writer.options;
|
||||
types.init( options );
|
||||
strings.init( functions );
|
||||
javaCodeBuilder.init( types, functions, strings, options, classFileLoader );
|
||||
((WasmCodeBuilder)watParser).init( types, functions, strings, options, classFileLoader );
|
||||
functions = options.functions;
|
||||
types = options.types;
|
||||
strings = options.strings;
|
||||
optimizer = options.optimizer;
|
||||
javaCodeBuilder.init( options, classFileLoader );
|
||||
((WasmCodeBuilder)watParser).init( options, classFileLoader );
|
||||
scanLibraries( libraries );
|
||||
}
|
||||
|
||||
|
@ -27,13 +27,14 @@ import javax.annotation.Nonnull;
|
||||
|
||||
import de.inetsoftware.jwebassembly.api.annotation.WasmTextCode;
|
||||
import de.inetsoftware.jwebassembly.wasm.ValueType;
|
||||
import de.inetsoftware.jwebassembly.wasm.WasmOptions;
|
||||
|
||||
/**
|
||||
* Handle all the constant strings. The constant strings will be write into the data section.
|
||||
*
|
||||
* @author Volker Berlin
|
||||
*/
|
||||
class StringManager extends LinkedHashMap<String, Integer> {
|
||||
public class StringManager extends LinkedHashMap<String, Integer> {
|
||||
|
||||
/**
|
||||
* Signature of method stringConstant.
|
||||
@ -48,13 +49,13 @@ class StringManager extends LinkedHashMap<String, Integer> {
|
||||
private int stringMemoryOffset = -1;
|
||||
|
||||
/**
|
||||
* Initialize the string manager.
|
||||
* Create a new instance.
|
||||
*
|
||||
* @param functions
|
||||
* the function manager
|
||||
* @param options
|
||||
* compiler properties and shared managers
|
||||
*/
|
||||
void init( FunctionManager functions ) {
|
||||
this.functions = functions;
|
||||
public StringManager( WasmOptions options ) {
|
||||
this.functions = options.functions;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -52,7 +52,7 @@ public class TypeManager {
|
||||
|
||||
private boolean isFinish;
|
||||
|
||||
private WasmOptions options;
|
||||
private final WasmOptions options;
|
||||
|
||||
/**
|
||||
* Initialize the type manager.
|
||||
@ -60,7 +60,7 @@ public class TypeManager {
|
||||
* @param options
|
||||
* compiler properties
|
||||
*/
|
||||
void init( WasmOptions options ) {
|
||||
public TypeManager( WasmOptions options ) {
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
|
@ -75,20 +75,16 @@ public abstract class WasmCodeBuilder {
|
||||
/**
|
||||
* Initialize the code builder;
|
||||
*
|
||||
* @param types
|
||||
* the type manager
|
||||
* @param functions
|
||||
* the function manager
|
||||
* @param strings
|
||||
* the string manager
|
||||
* @param options
|
||||
* compiler properties
|
||||
* @param classFileLoader
|
||||
* for loading the class files
|
||||
*/
|
||||
void init( TypeManager types, FunctionManager functions, StringManager strings, WasmOptions options, ClassFileLoader classFileLoader ) {
|
||||
this.localVariables.init( types );
|
||||
this.types = types;
|
||||
this.functions = functions;
|
||||
this.strings = strings;
|
||||
void init( WasmOptions options, ClassFileLoader classFileLoader ) {
|
||||
this.localVariables.init( options.types );
|
||||
this.types = options.types;
|
||||
this.functions = options.functions;
|
||||
this.strings = options.strings;
|
||||
this.options = options;
|
||||
this.classFileLoader = classFileLoader;
|
||||
}
|
||||
|
@ -20,7 +20,11 @@ import java.util.HashMap;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import de.inetsoftware.jwebassembly.JWebAssembly;
|
||||
import de.inetsoftware.jwebassembly.module.CodeOptimizer;
|
||||
import de.inetsoftware.jwebassembly.module.FunctionManager;
|
||||
import de.inetsoftware.jwebassembly.module.FunctionName;
|
||||
import de.inetsoftware.jwebassembly.module.StringManager;
|
||||
import de.inetsoftware.jwebassembly.module.TypeManager;
|
||||
|
||||
/**
|
||||
* The option/properties for the behavior of the compiler.
|
||||
@ -29,6 +33,14 @@ import de.inetsoftware.jwebassembly.module.FunctionName;
|
||||
*/
|
||||
public class WasmOptions {
|
||||
|
||||
public final FunctionManager functions = new FunctionManager();
|
||||
|
||||
public final TypeManager types = new TypeManager( this );
|
||||
|
||||
public final StringManager strings = new StringManager( this );
|
||||
|
||||
public final CodeOptimizer optimizer = new CodeOptimizer();
|
||||
|
||||
private final boolean debugNames;
|
||||
|
||||
private final boolean useGC;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2018 - 2019 Volker Berlin (i-net software)
|
||||
* Copyright 2018 - 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.
|
||||
@ -40,7 +40,7 @@ public class WatParserTest {
|
||||
WasmOptions options = new WasmOptions( new HashMap<>() );
|
||||
WatParser parser = new WatParser();
|
||||
WasmCodeBuilder codeBuilder = parser;
|
||||
codeBuilder.init( null, null, null, options, null );
|
||||
codeBuilder.init( options, null );
|
||||
parser.parse( wat, null, 100 );
|
||||
StringBuilder builder = new StringBuilder();
|
||||
ModuleWriter writer = new TextModuleWriter( new WasmTarget( builder ), options );
|
||||
|
Loading…
x
Reference in New Issue
Block a user