Skip to content

Commit

Permalink
Remove struct output from compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
d0cd committed Oct 18, 2023
1 parent a0ab388 commit 827f9ea
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
4 changes: 2 additions & 2 deletions compiler/compiler/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
// 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.
Expand Down
20 changes: 7 additions & 13 deletions leo/cli/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,19 @@

use super::*;

use leo_ast::Struct;
use leo_compiler::{Compiler, CompilerOptions, OutputOptions};
use leo_package::{
build::BuildDirectory,
imports::ImportsDirectory,
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},
Expand Down Expand Up @@ -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,
Expand All @@ -124,7 +118,7 @@ impl Command for Build {
&handler,
self.options.clone(),
false,
)?);
)?;
}

if !ImportsDirectory::is_empty(&package_path)? {
Expand All @@ -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,
Expand All @@ -145,7 +139,7 @@ impl Command for Build {
&handler,
self.options.clone(),
true,
)?);
)?;
}
}

Expand Down Expand Up @@ -185,7 +179,7 @@ fn compile_leo_file(
handler: &Handler,
options: BuildOptions,
is_import: bool,
) -> Result<IndexMap<Symbol, Struct>> {
) -> 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)?;
Expand Down Expand Up @@ -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)
Expand All @@ -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(())
}

0 comments on commit 827f9ea

Please sign in to comment.