share the LocaleVariableManager between multiple WasmCodeBuilder

This commit is contained in:
Volker Berlin 2022-02-27 20:44:42 +01:00
parent 9680ba6445
commit 3fd3c63351
3 changed files with 32 additions and 3 deletions

View File

@ -50,6 +50,16 @@ class JavaMethodWasmCodeBuilder extends WasmCodeBuilder {
private BranchManager branchManager;
/**
* Create an instance
*
* @param codeBuilder
* other code builder for shred references
*/
JavaMethodWasmCodeBuilder( @Nonnull WasmCodeBuilder codeBuilder ) {
super( codeBuilder );
}
/**
* {@inheritDoc}
*/

View File

@ -91,8 +91,8 @@ public class ModuleGenerator {
* libraries
*/
public ModuleGenerator( @Nonnull ModuleWriter writer, WasmTarget target, @Nonnull List<URL> libraries ) {
this.javaCodeBuilder = new JavaMethodWasmCodeBuilder();
this.watParser = new WatParser();
this.javaCodeBuilder = new JavaMethodWasmCodeBuilder( watParser );
this.writer = writer;
this.javaScript = new JavaScriptWriter( target );
this.classFileLoader = new ClassFileLoader( new URLClassLoader( libraries.toArray( new URL[libraries.size()] ) ) );

View File

@ -57,9 +57,9 @@ import de.inetsoftware.jwebassembly.wasm.WasmBlockOperator;
*/
public abstract class WasmCodeBuilder {
private final LocaleVariableManager localVariables = new LocaleVariableManager();
private final LocaleVariableManager localVariables;
private final List<WasmInstruction> instructions = new ArrayList<>();
private final List<WasmInstruction> instructions;
private TypeManager types;
@ -71,6 +71,25 @@ public abstract class WasmCodeBuilder {
private ClassFileLoader classFileLoader;
/**
* Create a new instance of CodeBuilder
*/
protected WasmCodeBuilder() {
localVariables = new LocaleVariableManager();
instructions = new ArrayList<>();
}
/**
* Create a new instance with shared resources
*
* @param codeBuilder
* other instance of CodeBuilder
*/
WasmCodeBuilder( @Nonnull WasmCodeBuilder codeBuilder ) {
localVariables = codeBuilder.localVariables;
instructions = codeBuilder.instructions;
}
/**
* Initialize the code builder;
*