Added build option to leo build

This commit is contained in:
Pranav Gaddamadugu 2021-09-20 18:12:03 -07:00
parent 3236351d72
commit 991a658950
4 changed files with 28 additions and 4 deletions

View File

@ -246,7 +246,11 @@ impl<'a, F: PrimeField, G: GroupType<F>> Compiler<'a, F, G> {
let mut ast: leo_ast::Ast = parse_ast(self.main_file_path.to_str().unwrap_or_default(), program_string)?;
if self.ast_snapshot_options.initial {
ast.to_json_file(self.output_directory.clone(), "initial_ast.json")?;
if !self.ast_snapshot_options.spans_enabled {
//TODO: Implement
} else {
ast.to_json_file(self.output_directory.clone(), "initial_ast.json")?;
}
}
// Preform import resolution.
@ -256,14 +260,22 @@ impl<'a, F: PrimeField, G: GroupType<F>> Compiler<'a, F, G> {
)?;
if self.ast_snapshot_options.imports_resolved {
ast.to_json_file(self.output_directory.clone(), "imports_resolved_ast.json")?;
if !self.ast_snapshot_options.spans_enabled {
//TODO: Implement
} else {
ast.to_json_file(self.output_directory.clone(), "imports_resolved_ast.json")?;
}
}
// Preform canonicalization of AST always.
ast = leo_ast_passes::Canonicalizer::do_pass(ast.into_repr())?;
if self.ast_snapshot_options.canonicalized {
ast.to_json_file(self.output_directory.clone(), "canonicalization_ast.json")?;
if !self.ast_snapshot_options.spans_enabled {
//TODO: Implement
} else {
ast.to_json_file(self.output_directory.clone(), "canonicalization_ast.json")?;
}
}
// Store the main program file.
@ -279,7 +291,11 @@ impl<'a, F: PrimeField, G: GroupType<F>> Compiler<'a, F, G> {
let new_ast = TypeInferencePhase::default()
.phase_ast(&self.program, &asg.clone().into_repr())
.expect("Failed to produce type inference ast.");
new_ast.to_json_file(self.output_directory.clone(), "type_inferenced_ast.json")?;
if self.ast_snapshot_options.spans_enabled {
//TODO: Implement
} else {
new_ast.to_json_file(self.output_directory.clone(), "type_inferenced_ast.json")?;
}
}
tracing::debug!("ASG generation complete");

View File

@ -37,6 +37,7 @@ impl Default for CompilerOptions {
#[derive(Clone)]
pub struct AstSnapshotOptions {
pub spans_enabled: bool,
pub initial: bool,
pub imports_resolved: bool,
pub canonicalized: bool,
@ -46,6 +47,7 @@ pub struct AstSnapshotOptions {
impl Default for AstSnapshotOptions {
fn default() -> Self {
Self {
spans_enabled: false,
initial: false,
imports_resolved: false,
canonicalized: false,

View File

@ -118,6 +118,7 @@ impl Namespace for CompileNamespace {
let parsed = parse_program(
&test.content,
Some(AstSnapshotOptions {
spans_enabled: true,
initial: true,
imports_resolved: true,
canonicalized: true,

View File

@ -43,6 +43,8 @@ pub struct BuildOptions {
pub disable_code_elimination: bool,
#[structopt(long, help = "Disable all compiler optimizations")]
pub disable_all_optimizations: bool,
#[structopt(long, help = "Enable spans in AST snapshots.")]
pub enable_spans: bool,
#[structopt(long, help = "Writes all AST snapshots for the different compiler phases.")]
pub enable_all_ast_snapshots: bool,
#[structopt(long, help = "Writes AST snapshot of the initial parse.")]
@ -61,6 +63,7 @@ impl Default for BuildOptions {
disable_constant_folding: false,
disable_code_elimination: false,
disable_all_optimizations: false,
enable_spans: false,
enable_all_ast_snapshots: false,
enable_initial_ast_snapshot: false,
enable_imports_resolved_ast_snapshot: false,
@ -90,6 +93,7 @@ impl From<BuildOptions> for AstSnapshotOptions {
fn from(options: BuildOptions) -> Self {
if options.enable_all_ast_snapshots {
AstSnapshotOptions {
spans_enabled: options.enable_spans,
initial: true,
imports_resolved: true,
canonicalized: true,
@ -97,6 +101,7 @@ impl From<BuildOptions> for AstSnapshotOptions {
}
} else {
AstSnapshotOptions {
spans_enabled: options.enable_spans,
initial: options.enable_initial_ast_snapshot,
imports_resolved: options.enable_imports_resolved_ast_snapshot,
canonicalized: options.enable_canonicalized_ast_snapshot,