Skip to content

Commit

Permalink
[api] Make Module and Sections immutable with Builders
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaTP committed Aug 12, 2024
1 parent 64d65bf commit 20fb213
Show file tree
Hide file tree
Showing 16 changed files with 546 additions and 427 deletions.
110 changes: 40 additions & 70 deletions wasm/src/main/java/com/dylibso/chicory/wasm/Module.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,49 @@
public class Module {
private final HashMap<String, CustomSection> customSections;

private TypeSection typeSection = new TypeSection();
private ImportSection importSection = new ImportSection();
private FunctionSection functionSection = new FunctionSection();
private TableSection tableSection = new TableSection();
private MemorySection memorySection;
private GlobalSection globalSection = new GlobalSection();
private ExportSection exportSection = new ExportSection();
private StartSection startSection;
private ElementSection elementSection = new ElementSection();
private CodeSection codeSection = new CodeSection();
private DataSection dataSection = new DataSection();
private DataCountSection dataCountSection;

private final List<Integer> ignoredSections = new ArrayList();

public Module() {
this.customSections = new HashMap<>();
}

public void setTypeSection(TypeSection typeSection) {
private final TypeSection typeSection;
private final ImportSection importSection;
private final FunctionSection functionSection;
private final TableSection tableSection;
private final MemorySection memorySection;
private final GlobalSection globalSection;
private final ExportSection exportSection;
private final StartSection startSection;
private final ElementSection elementSection;
private final CodeSection codeSection;
private final DataSection dataSection;
private final DataCountSection dataCountSection;
private final List<Integer> ignoredSections;

Module(
TypeSection typeSection,
ImportSection importSection,
FunctionSection functionSection,
TableSection tableSection,
MemorySection memorySection,
GlobalSection globalSection,
ExportSection exportSection,
StartSection startSection,
ElementSection elementSection,
CodeSection codeSection,
DataSection dataSection,
DataCountSection dataCountSection,
HashMap<String, CustomSection> customSections,
List<Integer> ignoredSections) {
this.typeSection = requireNonNull(typeSection);
}

public void setFunctionSection(FunctionSection functionSection) {
this.importSection = requireNonNull(importSection);
this.functionSection = requireNonNull(functionSection);
}

public void setExportSection(ExportSection exportSection) {
this.tableSection = requireNonNull(tableSection);
this.memorySection = memorySection;
this.globalSection = requireNonNull(globalSection);
this.exportSection = requireNonNull(exportSection);
this.startSection = startSection;
this.elementSection = requireNonNull(elementSection);
this.codeSection = requireNonNull(codeSection);
this.dataSection = requireNonNull(dataSection);
this.dataCountSection = dataCountSection;
this.customSections = requireNonNull(customSections);
this.ignoredSections = requireNonNull(ignoredSections);
}

public TypeSection typeSection() {
Expand All @@ -85,30 +99,10 @@ public ImportSection importSection() {
return importSection;
}

public void setStartSection(StartSection startSection) {
this.startSection = startSection;
}

public void setImportSection(ImportSection importSection) {
this.importSection = requireNonNull(importSection);
}

public CodeSection codeSection() {
return codeSection;
}

public void setCodeSection(CodeSection codeSection) {
this.codeSection = requireNonNull(codeSection);
}

public void setDataSection(DataSection dataSection) {
this.dataSection = requireNonNull(dataSection);
}

public void setDataCountSection(DataCountSection dataCountSection) {
this.dataCountSection = dataCountSection;
}

public DataSection dataSection() {
return dataSection;
}
Expand All @@ -121,30 +115,14 @@ public MemorySection memorySection() {
return memorySection;
}

public void setMemorySection(MemorySection memorySection) {
this.memorySection = memorySection;
}

public GlobalSection globalSection() {
return globalSection;
}

public void setGlobalSection(GlobalSection globalSection) {
this.globalSection = requireNonNull(globalSection);
}

public TableSection tableSection() {
return tableSection;
}

public void setTableSection(TableSection tableSection) {
this.tableSection = requireNonNull(tableSection);
}

public void addCustomSection(CustomSection customSection) {
this.customSections.put(customSection.name(), customSection);
}

public List<CustomSection> customSections() {
return new ArrayList<>(customSections.values());
}
Expand All @@ -161,14 +139,6 @@ public ElementSection elementSection() {
return elementSection;
}

public void setElementSection(ElementSection elementSection) {
this.elementSection = requireNonNull(elementSection);
}

public void addIgnoredSection(int id) {
ignoredSections.add(id);
}

/**
* Creates a {@link Builder} for the specified {@link InputStream}
*
Expand Down
Loading

0 comments on commit 20fb213

Please sign in to comment.