Skip to content

Commit

Permalink
[WASM] Separates the responsibilities for producing outputs and synth…
Browse files Browse the repository at this point in the history
…esizing .wat code.

Formerly `WasmOutputGenerator` would sinthezise the top level .wat code and produce all the files in a wasm transpilation. This cl renames `WasmOutputGenerator` into `WasmOutputGenerationStage` whose responsibility is only to produce the output files and control how the output is produced; and introduces `WasmConstructsGenerator` whose responsibility is to produce .wat constructs for AST and runtime needs.

`WasmOutputGenerationStage` is also responsible for the use and lifetime of the SourceBuilder objects.

PiperOrigin-RevId: 583516872
  • Loading branch information
rluble authored and copybara-github committed Nov 18, 2023
1 parent 89bbe4a commit 2ccb84b
Show file tree
Hide file tree
Showing 5 changed files with 289 additions and 233 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import com.google.j2cl.transpiler.ast.Method;
import com.google.j2cl.transpiler.ast.TypeDescriptors;
import com.google.j2cl.transpiler.ast.WasmEntryPointBridgesCreator;
import com.google.j2cl.transpiler.backend.wasm.WasmOutputsGenerator;
import com.google.j2cl.transpiler.backend.wasm.WasmGeneratorStage;
import com.google.j2cl.transpiler.frontend.common.PackageInfoCache;
import com.google.j2cl.transpiler.frontend.jdt.JdtEnvironment;
import com.google.j2cl.transpiler.frontend.jdt.JdtParser;
Expand Down Expand Up @@ -110,7 +110,7 @@ protected void run(Problems problems) {
.flatMap(t -> t.getDeclaredMethodDescriptors().stream())
.collect(toImmutableList()));

var generator = new WasmOutputsGenerator(out, /* libraryInfoOutputPath= */ null, problems);
var generator = new WasmGeneratorStage(out, /* libraryInfoOutputPath= */ null, problems);

generator.generateMethods(exportedMethods);
problems.abortIfHasErrors();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.google.j2cl.transpiler.ast.Library;
import com.google.j2cl.transpiler.backend.closure.OutputGeneratorStage;
import com.google.j2cl.transpiler.backend.kotlin.KotlinGeneratorStage;
import com.google.j2cl.transpiler.backend.wasm.WasmOutputsGenerator;
import com.google.j2cl.transpiler.backend.wasm.WasmGeneratorStage;
import com.google.j2cl.transpiler.passes.AddAbstractMethodStubs;
import com.google.j2cl.transpiler.passes.AddBridgeMethods;
import com.google.j2cl.transpiler.passes.AddDisambiguatingSuperMethodForwardingStubs;
Expand Down Expand Up @@ -344,7 +344,7 @@ public ImmutableList<Supplier<NormalizationPass>> getPassFactories(BackendOption
WASM {
@Override
public void generateOutputs(BackendOptions options, Library library, Problems problems) {
new WasmOutputsGenerator(options.getOutput(), options.getLibraryInfoOutput(), problems)
new WasmGeneratorStage(options.getOutput(), options.getLibraryInfoOutput(), problems)
.generateMonolithicOutput(library);
}

Expand Down Expand Up @@ -482,7 +482,7 @@ public boolean isWasm() {
WASM_MODULAR {
@Override
public void generateOutputs(BackendOptions options, Library library, Problems problems) {
new WasmOutputsGenerator(options.getOutput(), options.getLibraryInfoOutput(), problems)
new WasmGeneratorStage(options.getOutput(), options.getLibraryInfoOutput(), problems)
.generateModularOutput(library);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@
final class ExpressionTranspiler {

public static void renderWithUnusedResult(
Expression expression, SourceBuilder sourceBuilder, WasmGenerationEnvironment environment) {
Expression expression,
final SourceBuilder sourceBuilder,
final WasmGenerationEnvironment environment) {
if (returnsVoid(expression)) {
render(expression, sourceBuilder, environment);
} else {
Expand Down
Loading

0 comments on commit 2ccb84b

Please sign in to comment.