mirror of
https://github.com/powdr-labs/powdr.git
synced 2026-04-20 03:03:25 -04:00
52 lines
1.4 KiB
Rust
52 lines
1.4 KiB
Rust
use ast::analyzed::{Analyzed, FunctionValueDefinition, Symbol};
|
|
use number::{read_polys_file, DegreeType, FieldElement};
|
|
use std::{fs::File, io::BufReader, path::Path};
|
|
|
|
pub trait PolySet {
|
|
const FILE_NAME: &'static str;
|
|
fn get_polys<T: FieldElement>(
|
|
pil: &Analyzed<T>,
|
|
) -> Vec<&(Symbol, Option<FunctionValueDefinition<T>>)>;
|
|
}
|
|
|
|
pub struct FixedPolySet;
|
|
impl PolySet for FixedPolySet {
|
|
const FILE_NAME: &'static str = "constants.bin";
|
|
|
|
fn get_polys<T: FieldElement>(
|
|
pil: &Analyzed<T>,
|
|
) -> Vec<&(Symbol, Option<FunctionValueDefinition<T>>)> {
|
|
pil.constant_polys_in_source_order()
|
|
}
|
|
}
|
|
|
|
pub struct WitnessPolySet;
|
|
impl PolySet for WitnessPolySet {
|
|
const FILE_NAME: &'static str = "commits.bin";
|
|
|
|
fn get_polys<T: FieldElement>(
|
|
pil: &Analyzed<T>,
|
|
) -> Vec<&(Symbol, Option<FunctionValueDefinition<T>>)> {
|
|
pil.committed_polys_in_source_order()
|
|
}
|
|
}
|
|
|
|
pub fn read_poly_set<P: PolySet, T: FieldElement>(
|
|
pil: &Analyzed<T>,
|
|
dir: &Path,
|
|
name: &str,
|
|
) -> (Vec<(String, Vec<T>)>, DegreeType) {
|
|
let column_names: Vec<String> = P::get_polys(pil)
|
|
.iter()
|
|
.flat_map(|(poly, _)| poly.array_elements())
|
|
.map(|(name, _id)| name)
|
|
.collect();
|
|
|
|
let fname = format!("{name}_{}", P::FILE_NAME);
|
|
|
|
read_polys_file(
|
|
&mut BufReader::new(File::open(dir.join(fname)).unwrap()),
|
|
&column_names,
|
|
)
|
|
}
|