From 827f9ea3afe06d52f813c711212e396c3016f007 Mon Sep 17 00:00:00 2001 From: Pranav Gaddamadugu Date: Mon, 2 Oct 2023 10:28:29 -0400 Subject: [PATCH] Remove struct output from compiler --- compiler/compiler/src/compiler.rs | 4 ++-- leo/cli/commands/build.rs | 20 +++++++------------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/compiler/compiler/src/compiler.rs b/compiler/compiler/src/compiler.rs index 5a7b5419a2..58267fcb90 100644 --- a/compiler/compiler/src/compiler.rs +++ b/compiler/compiler/src/compiler.rs @@ -248,14 +248,14 @@ impl<'a> Compiler<'a> { } /// Returns a compiled Leo program. - pub fn compile(&mut self) -> Result<(SymbolTable, String)> { + pub fn compile(&mut self) -> Result { // Parse the program. self.parse_program()?; // Run the intermediate compiler stages. let (symbol_table, struct_graph, call_graph) = self.compiler_stages()?; // Run code generation. let bytecode = self.code_generation_pass(&symbol_table, &struct_graph, &call_graph)?; - Ok((symbol_table, bytecode)) + Ok(bytecode) } /// Writes the AST to a JSON file. diff --git a/leo/cli/commands/build.rs b/leo/cli/commands/build.rs index 7ed2071b15..5bb6a61082 100644 --- a/leo/cli/commands/build.rs +++ b/leo/cli/commands/build.rs @@ -16,7 +16,6 @@ use super::*; -use leo_ast::Struct; use leo_compiler::{Compiler, CompilerOptions, OutputOptions}; use leo_package::{ build::BuildDirectory, @@ -24,14 +23,12 @@ use leo_package::{ outputs::OutputsDirectory, source::SourceDirectory, }; -use leo_span::Symbol; use snarkvm::{ package::Package, prelude::{ProgramID, Testnet3}, }; -use indexmap::IndexMap; use std::{ io::Write, path::{Path, PathBuf}, @@ -110,12 +107,9 @@ impl Command for Build { // Check the source files. SourceDirectory::check_files(&source_files)?; - // Store all struct declarations made in the source files. - let mut structs = IndexMap::new(); - // Compile all .leo files into .aleo files. for file_path in source_files.into_iter() { - structs.extend(compile_leo_file( + compile_leo_file( file_path, &package_path, program_id, @@ -124,7 +118,7 @@ impl Command for Build { &handler, self.options.clone(), false, - )?); + )?; } if !ImportsDirectory::is_empty(&package_path)? { @@ -136,7 +130,7 @@ impl Command for Build { // Compile all .leo files into .aleo files. for file_path in import_files.into_iter() { - structs.extend(compile_leo_file( + compile_leo_file( file_path, &package_path, program_id, @@ -145,7 +139,7 @@ impl Command for Build { &handler, self.options.clone(), true, - )?); + )?; } } @@ -185,7 +179,7 @@ fn compile_leo_file( handler: &Handler, options: BuildOptions, is_import: bool, -) -> Result> { +) -> Result<()> { // Construct the Leo file name with extension `foo.leo`. let file_name = file_path.file_name().and_then(|name| name.to_str()).ok_or_else(PackageError::failed_to_get_file_name)?; @@ -215,7 +209,7 @@ fn compile_leo_file( ); // Compile the Leo program into Aleo instructions. - let (symbol_table, instructions) = compiler.compile()?; + let instructions = compiler.compile()?; // Write the instructions. std::fs::File::create(&aleo_file_path) @@ -224,5 +218,5 @@ fn compile_leo_file( .map_err(CliError::failed_to_load_instructions)?; tracing::info!("✅ Compiled '{}' into Aleo instructions", file_name); - Ok(symbol_table.structs) + Ok(()) }