-
Notifications
You must be signed in to change notification settings - Fork 327
/
Copy pathcircuit_builder.rs
73 lines (56 loc) · 2.19 KB
/
circuit_builder.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use crate::file_writer::BBFiles;
use handlebars::Handlebars;
use serde_json::json;
pub trait CircuitBuilder {
fn create_circuit_builder_hpp(&mut self, name: &str);
fn create_circuit_builder_cpp(&mut self, name: &str, all_cols_without_inverses: &[String]);
fn create_full_row_hpp(&mut self, name: &str, all_cols: &[String]);
}
impl CircuitBuilder for BBFiles {
fn create_circuit_builder_hpp(&mut self, name: &str) {
let mut handlebars = Handlebars::new();
let data = &json!({
"name": name,
});
handlebars
.register_template_string(
"circuit_builder.hpp",
std::str::from_utf8(include_bytes!("../templates/circuit_builder.hpp.hbs"))
.unwrap(),
)
.unwrap();
let circuit_hpp = handlebars.render("circuit_builder.hpp", data).unwrap();
self.write_file(None, "circuit_builder.hpp", &circuit_hpp);
}
fn create_circuit_builder_cpp(&mut self, name: &str, all_cols_without_inverses: &[String]) {
let mut handlebars = Handlebars::new();
let data = &json!({
"name": name,
"all_cols_without_inverses": all_cols_without_inverses,
});
handlebars
.register_template_string(
"circuit_builder.cpp",
std::str::from_utf8(include_bytes!("../templates/circuit_builder.cpp.hbs"))
.unwrap(),
)
.unwrap();
let circuit_cpp = handlebars.render("circuit_builder.cpp", data).unwrap();
self.write_file(None, "circuit_builder.cpp", &circuit_cpp);
}
fn create_full_row_hpp(&mut self, name: &str, all_cols: &[String]) {
let mut handlebars = Handlebars::new();
let data = &json!({
"name": name,
"all_cols": all_cols,
});
handlebars
.register_template_string(
"full_row.hpp",
std::str::from_utf8(include_bytes!("../templates/full_row.hpp.hbs")).unwrap(),
)
.unwrap();
let hpp = handlebars.render("full_row.hpp", data).unwrap();
self.write_file(None, "full_row.hpp", &hpp);
}
}