diff --git a/compiler/compiler/src/compiler.rs b/compiler/compiler/src/compiler.rs index d60e207007..0bfd63b28e 100644 --- a/compiler/compiler/src/compiler.rs +++ b/compiler/compiler/src/compiler.rs @@ -196,14 +196,33 @@ impl<'a> Compiler<'a> { } /// Runs the flattening pass. - pub fn flattening_pass(&mut self, symbol_table: &SymbolTable, assigner: Assigner) -> Result<()> { - self.ast = Flattener::do_pass((std::mem::take(&mut self.ast), symbol_table, assigner))?; + pub fn flattening_pass(&mut self, symbol_table: &SymbolTable, assigner: Assigner) -> Result { + let (ast, assigner) = Flattener::do_pass((std::mem::take(&mut self.ast), symbol_table, assigner))?; + self.ast = ast; if self.output_options.flattened_ast { self.write_ast_to_json("flattened_ast.json")?; } - Ok(()) + Ok(assigner) + } + + /// Runs the function inlining pass. + pub fn function_inlining_pass( + &mut self, + symbol_table: &SymbolTable, + call_graph: &CallGraph, + assigner: Assigner, + ) -> Result { + let (ast, assigner) = + FunctionInliner::do_pass((std::mem::take(&mut self.ast), symbol_table, call_graph, assigner))?; + self.ast = ast; + + if self.output_options.inlined_ast { + self.write_ast_to_json("inlined_ast.json")?; + } + + Ok(assigner) } /// Runs the compiler stages. @@ -220,7 +239,9 @@ impl<'a> Compiler<'a> { // TODO: Make this pass optional. let assigner = self.static_single_assignment_pass(&st, assigner)?; - self.flattening_pass(&st, assigner)?; + let assigner = self.flattening_pass(&st, assigner)?; + + let _ = self.function_inlining_pass(&st, &call_graph, assigner)?; Ok((st, struct_graph, call_graph)) } diff --git a/compiler/compiler/src/options.rs b/compiler/compiler/src/options.rs index 5a68ee6194..6428ae3c72 100644 --- a/compiler/compiler/src/options.rs +++ b/compiler/compiler/src/options.rs @@ -30,4 +30,6 @@ pub struct OutputOptions { pub ssa_ast: bool, /// If enabled writes the AST after flattening. pub flattened_ast: bool, + /// If enabled writes the AST after inlining. + pub inlined_ast: bool, } diff --git a/leo/commands/build.rs b/leo/commands/build.rs index 772d040e01..539a6b0f87 100644 --- a/leo/commands/build.rs +++ b/leo/commands/build.rs @@ -58,6 +58,8 @@ pub struct BuildOptions { pub enable_ssa_ast_snapshot: bool, #[structopt(long, help = "Writes AST snapshot of the flattened AST.")] pub enable_flattened_ast_snapshot: bool, + #[structopt(long, help = "Writes AST snapshot of the inlined AST.")] + pub enable_inlined_ast_snapshot: bool, } impl From for OutputOptions { @@ -69,6 +71,7 @@ impl From for OutputOptions { unrolled_ast: options.enable_unrolled_ast_snapshot, ssa_ast: options.enable_ssa_ast_snapshot, flattened_ast: options.enable_flattened_ast_snapshot, + inlined_ast: options.enable_inlined_ast_snapshot, }; if options.enable_all_ast_snapshots { out_options.initial_input_ast = true; @@ -76,6 +79,7 @@ impl From for OutputOptions { out_options.unrolled_ast = true; out_options.ssa_ast = true; out_options.flattened_ast = true; + out_options.inlined_ast = true; } out_options