remove tuple
This commit is contained in:
parent
2512c08f68
commit
be90257334
3 changed files with 39 additions and 12 deletions
|
@ -13,7 +13,7 @@ use std::io::{stdin, BufReader, BufWriter, Read, Write};
|
|||
use std::path::{Path, PathBuf};
|
||||
use std::string::String;
|
||||
use zokrates_abi::Encode;
|
||||
use zokrates_core::compile::compile;
|
||||
use zokrates_core::compile::{compile, CompilationArtifacts};
|
||||
use zokrates_core::ir;
|
||||
use zokrates_core::proof_system::*;
|
||||
use zokrates_core::typed_absy::abi::Abi;
|
||||
|
@ -292,10 +292,12 @@ fn cli() -> Result<(), String> {
|
|||
|
||||
let mut reader = BufReader::new(file);
|
||||
|
||||
let (program_flattened, abi): (ir::Prog<FieldPrime>, Abi) =
|
||||
let artifacts: CompilationArtifacts<FieldPrime> =
|
||||
compile(&mut reader, Some(location), Some(fs_resolve))
|
||||
.map_err(|e| format!("Compilation failed:\n\n {}", e))?;
|
||||
|
||||
let program_flattened = artifacts.prog();
|
||||
|
||||
// number of constraints the flattened program will translate to.
|
||||
let num_constraints = program_flattened.constraint_count();
|
||||
|
||||
|
@ -312,6 +314,8 @@ fn cli() -> Result<(), String> {
|
|||
let abi_spec_file = File::create(&abi_spec_path)
|
||||
.map_err(|why| format!("couldn't create {}: {}", abi_spec_path.display(), why))?;
|
||||
|
||||
let abi = artifacts.abi();
|
||||
|
||||
let mut writer = BufWriter::new(abi_spec_file);
|
||||
|
||||
to_writer_pretty(&mut writer, &abi)
|
||||
|
@ -632,7 +636,7 @@ mod tests {
|
|||
.into_string()
|
||||
.unwrap();
|
||||
|
||||
let _: (ir::Prog<FieldPrime>, _) =
|
||||
let _: CompilationArtifacts<FieldPrime> =
|
||||
compile(&mut reader, Some(location), Some(fs_resolve)).unwrap();
|
||||
}
|
||||
}
|
||||
|
@ -659,10 +663,11 @@ mod tests {
|
|||
|
||||
let mut reader = BufReader::new(file);
|
||||
|
||||
let (program_flattened, _): (ir::Prog<FieldPrime>, _) =
|
||||
let artifacts: CompilationArtifacts<FieldPrime> =
|
||||
compile(&mut reader, Some(location), Some(fs_resolve)).unwrap();
|
||||
|
||||
let _ = program_flattened
|
||||
let _ = artifacts
|
||||
.prog()
|
||||
.execute(&vec![FieldPrime::from(0)])
|
||||
.unwrap();
|
||||
}
|
||||
|
@ -691,10 +696,11 @@ mod tests {
|
|||
|
||||
let mut reader = BufReader::new(file);
|
||||
|
||||
let (program_flattened, _): (ir::Prog<FieldPrime>, _) =
|
||||
let artifacts: CompilationArtifacts<FieldPrime> =
|
||||
compile(&mut reader, Some(location), Some(fs_resolve)).unwrap();
|
||||
|
||||
let _ = program_flattened
|
||||
let _ = artifacts
|
||||
.prog()
|
||||
.execute(&vec![FieldPrime::from(0)])
|
||||
.unwrap();
|
||||
}
|
||||
|
|
|
@ -19,6 +19,22 @@ use typed_arena::Arena;
|
|||
use zokrates_field::field::Field;
|
||||
use zokrates_pest_ast as pest;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct CompilationArtifacts<T: Field> {
|
||||
prog: ir::Prog<T>,
|
||||
abi: Abi,
|
||||
}
|
||||
|
||||
impl<T: Field> CompilationArtifacts<T> {
|
||||
pub fn prog(&self) -> &ir::Prog<T> {
|
||||
&self.prog
|
||||
}
|
||||
|
||||
pub fn abi(&self) -> &Abi {
|
||||
&self.abi
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct CompileErrors(Vec<CompileError>);
|
||||
|
||||
|
@ -131,7 +147,7 @@ pub fn compile<T: Field, R: BufRead, S: BufRead, E: Into<imports::Error>>(
|
|||
reader: &mut R,
|
||||
location: Option<String>,
|
||||
resolve_option: Option<Resolve<S, E>>,
|
||||
) -> Result<(ir::Prog<T>, Abi), CompileErrors> {
|
||||
) -> Result<CompilationArtifacts<T>, CompileErrors> {
|
||||
let arena = Arena::new();
|
||||
|
||||
let mut source = String::new();
|
||||
|
@ -168,7 +184,10 @@ pub fn compile<T: Field, R: BufRead, S: BufRead, E: Into<imports::Error>>(
|
|||
// optimize
|
||||
let optimized_ir_prog = ir_prog.optimize();
|
||||
|
||||
Ok((optimized_ir_prog, abi))
|
||||
Ok(CompilationArtifacts {
|
||||
prog: optimized_ir_prog,
|
||||
abi: abi,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn compile_program<'ast, T: Field, S: BufRead, E: Into<imports::Error>>(
|
||||
|
@ -233,7 +252,7 @@ mod test {
|
|||
"#
|
||||
.as_bytes(),
|
||||
);
|
||||
let res: Result<(ir::Prog<FieldPrime>, Abi), CompileErrors> = compile(
|
||||
let res: Result<CompilationArtifacts<FieldPrime>, CompileErrors> = compile(
|
||||
&mut r,
|
||||
Some(String::from("./path/to/file")),
|
||||
None::<Resolve<BufReader<Empty>, io::Error>>,
|
||||
|
@ -254,7 +273,7 @@ mod test {
|
|||
"#
|
||||
.as_bytes(),
|
||||
);
|
||||
let res: Result<(ir::Prog<FieldPrime>, Abi), CompileErrors> = compile(
|
||||
let res: Result<CompilationArtifacts<FieldPrime>, CompileErrors> = compile(
|
||||
&mut r,
|
||||
Some(String::from("./path/to/file")),
|
||||
None::<Resolve<BufReader<Empty>, io::Error>>,
|
||||
|
|
|
@ -77,7 +77,7 @@ pub fn test_inner(test_path: &str) {
|
|||
|
||||
let mut code_reader = BufReader::new(File::open(&t.entry_point).unwrap());
|
||||
|
||||
let (bin, _) = compile(
|
||||
let artifacts = compile(
|
||||
&mut code_reader,
|
||||
Some(
|
||||
t.entry_point
|
||||
|
@ -91,6 +91,8 @@ pub fn test_inner(test_path: &str) {
|
|||
)
|
||||
.unwrap();
|
||||
|
||||
let bin = artifacts.prog();
|
||||
|
||||
for test in t.tests.into_iter() {
|
||||
let input = &test.input.values;
|
||||
let output = bin.execute(
|
||||
|
|
Loading…
Reference in a new issue