Skip to content

Commit

Permalink
Modify compiler struct
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-schott committed Nov 3, 2023
1 parent e745e43 commit 4531ef1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
6 changes: 5 additions & 1 deletion compiler/compiler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ version = "=1.9.4"
[dependencies.sha2]
version = "0.10"

[dependencies.indexmap]
version = "1.9"
features = []

[dev-dependencies.leo-test-framework]
path = "../../tests/test-framework"

Expand Down Expand Up @@ -73,4 +77,4 @@ version = "3.7"

[features]
default = [ ]
ci_skip = [ "leo-ast/ci_skip" ]
ci_skip = [ "leo-ast/ci_skip" ]
11 changes: 9 additions & 2 deletions compiler/compiler/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@
//!
//! The [`Compiler`] type compiles Leo programs into R1CS circuits.
pub use leo_ast::{Ast, InputAst};
use leo_ast::{NodeBuilder, Program};
use leo_ast::{NodeBuilder, Program, Stub};
use leo_errors::{emitter::Handler, CompilerError, Result};
pub use leo_passes::SymbolTable;
use leo_passes::*;
use leo_span::{source_map::FileName, symbol::with_session_globals};
use leo_span::{source_map::FileName, symbol::with_session_globals, Symbol};

use sha2::{Digest, Sha256};
use std::{fs, path::PathBuf};

use crate::CompilerOptions;
use indexmap::IndexMap;

/// The primary entry point of the Leo compiler.
#[derive(Clone)]
Expand All @@ -52,6 +53,8 @@ pub struct Compiler<'a> {
node_builder: NodeBuilder,
/// The `Assigner` is used to construct (unique) assignment statements.
assigner: Assigner,
/// The stubs for imported programs. Produced by `Retriever` module.
import_stubs: IndexMap<Symbol, Stub>,
}

impl<'a> Compiler<'a> {
Expand All @@ -63,6 +66,7 @@ impl<'a> Compiler<'a> {
main_file_path: PathBuf,
output_directory: PathBuf,
compiler_options: Option<CompilerOptions>,
import_stubs: IndexMap<Symbol, Stub>,
) -> Self {
let node_builder = NodeBuilder::default();
let assigner = Assigner::default();
Expand All @@ -77,6 +81,7 @@ impl<'a> Compiler<'a> {
compiler_options: compiler_options.unwrap_or_default(),
node_builder,
assigner,
import_stubs,
}
}

Expand Down Expand Up @@ -285,6 +290,8 @@ impl<'a> Compiler<'a> {
pub fn compile(&mut self) -> Result<(SymbolTable, String)> {
// Parse the program.
self.parse_program()?;
// Merge stubs
self.add_import_stubs();
// Run the intermediate compiler stages.
let (symbol_table, struct_graph, call_graph) = self.compiler_stages()?;
// Run code generation.
Expand Down
11 changes: 10 additions & 1 deletion compiler/compiler/tests/utilities/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use leo_test_framework::{test::TestConfig, Test};

use snarkvm::prelude::*;

use indexmap::IndexMap;
use leo_ast::ProgramVisitor;
use snarkvm::{file::Manifest, package::Package};
use std::{
Expand Down Expand Up @@ -142,7 +143,15 @@ pub fn new_compiler(
let output_dir = PathBuf::from("/tmp/output/");
fs::create_dir_all(output_dir.clone()).unwrap();

Compiler::new(String::from("test"), String::from("aleo"), handler, main_file_path, output_dir, compiler_options)
Compiler::new(
String::from("test"),
String::from("aleo"),
handler,
main_file_path,
output_dir,
compiler_options,
IndexMap::new(),
)
}

pub fn parse_program<'a>(
Expand Down

0 comments on commit 4531ef1

Please sign in to comment.