diff --git a/compiler/src/compiler.rs b/compiler/src/compiler.rs index d48fd71c28..482776d6f4 100644 --- a/compiler/src/compiler.rs +++ b/compiler/src/compiler.rs @@ -26,7 +26,7 @@ use crate::{ }; use indexmap::IndexMap; pub use leo_asg::{new_context, AsgContext as Context, AsgContext}; -use leo_asg::{Asg, AsgPass, FormattedError, Program}; +use leo_asg::{Asg, AsgPass, FormattedError, Program as AsgProgram}; use leo_ast::{Input, LeoError, MainInput, Program as AstProgram}; use leo_input::LeoInputParser; use leo_package::inputs::InputPairs; @@ -67,7 +67,7 @@ pub struct Compiler<'a, F: PrimeField, G: GroupType> { program: AstProgram, program_input: Input, context: AsgContext<'a>, - asg: Option>, + asg: Option>, file_contents: RefCell>>>, options: CompilerOptions, _engine: PhantomData, @@ -284,12 +284,19 @@ impl<'a, F: PrimeField, G: GroupType> Compiler<'a, F, G> { Ok(()) } + /// + /// Run compiler optimization passes on the program in asg format. + /// fn do_asg_passes(&mut self) -> Result<(), FormattedError> { assert!(self.asg.is_some()); + + // Do constant folding. if self.options.constant_folding_enabled { let asg = self.asg.take().unwrap(); self.asg = Some(leo_asg_passes::ConstantFolding::do_pass(asg)?); } + + // Do dead code elimination. if self.options.dead_code_elimination_enabled { let asg = self.asg.take().unwrap(); self.asg = Some(leo_asg_passes::DeadCodeElimination::do_pass(asg)?); diff --git a/compiler/src/option.rs b/compiler/src/option.rs index 62d093c15c..8e87d4654c 100644 --- a/compiler/src/option.rs +++ b/compiler/src/option.rs @@ -14,6 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . +/// +/// Toggles compiler optimizations on the program. +/// #[derive(Clone)] pub struct CompilerOptions { pub constant_folding_enabled: bool, @@ -21,6 +24,9 @@ pub struct CompilerOptions { } impl Default for CompilerOptions { + /// + /// All compiler optimizations are enabled by default. + /// fn default() -> Self { CompilerOptions { constant_folding_enabled: true,