Files
react/compiler/forget/src/CompilerDriver.ts
T
Jan Kassens 779947520d [playground] new HIR tab
Instead of hacking into the babel plugin passes, this now takes a new approach 
for the HIR tab: 

- The different passes are exported from the babel plugin (for simplicity) 

- The tab actually runs the compiler steps based on local config in the tab. 

- Re-purposed the CompilerFlags component to configure what passes to run. This 
is currently mostly causing different errors, but could be useful going forward 
as a direction.
2022-11-10 15:45:51 -05:00

69 lines
1.9 KiB
TypeScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import { NodePath } from "@babel/traverse";
import * as t from "@babel/types";
import * as BE from "./BackEnd";
import { CompilerContext } from "./CompilerContext";
import { CompilerOptions } from "./CompilerOptions";
import * as ME from "./MiddleEnd";
import { PassManager } from "./PassManager";
import * as Validation from "./Validation";
/**
* Compiler Driver
*
* Owns {@link CompilerContext} and source program.
*/
export interface CompilerDriver {
context: CompilerContext;
program: NodePath<t.Program>;
compile(): void;
}
export function createCompilerDriver(
options: CompilerOptions,
program: NodePath<t.Program>
): CompilerDriver {
const context = new CompilerContext(options, program);
return {
context,
program,
compile() {
const passManager = new PassManager(program, context);
// Syntax Analysis and IR Generation.
passManager.addPass(ME.ReactFuncsInfer);
passManager.addPass(ME.ParamAnalysis);
passManager.addPass(ME.BodyAnalysis);
passManager.addPass(ME.SketchyCodeCheck);
passManager.addPass(ME.RefKindInfer);
passManager.addPass(ME.DumpIR);
passManager.addPass(ME.IRCheck);
passManager.addPass(ME.DumpCFG);
// Dependency Analysis via DepGraph.
passManager.addPass(ME.DepGraphAnalysis);
// LIR Generation.
passManager.addPass(BE.LIRGen);
passManager.addPass(BE.MemoCacheAlloc);
passManager.addPass(BE.DumpLIR);
passManager.addPass(BE.SanityCheck);
// JS Generation.
passManager.addPass(BE.JSGen);
// Optionally sanity-check the transformed output
passManager.addPass(Validation.PostCodegenValidator);
passManager.runAll();
},
};
}