Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generate row deserialization #68

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions bberg/src/circuit_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ pub trait CircuitBuilder {
to_be_shifted: &[String],
all_cols_with_shifts: &[String],
);

fn create_circuit_builder_cpp(&mut self, name: &str, all_cols: &[String]);
}

fn circuit_hpp_includes(name: &str, relations: &[String], permutations: &[String]) -> String {
Expand Down Expand Up @@ -158,6 +160,8 @@ namespace bb {{

{row_with_all_included};

template <typename FF> std::ostream& operator<<(std::ostream& os, {name}FullRow<FF> const& row);

class {name}CircuitBuilder {{
public:
using Flavor = bb::{name}Flavor;
Expand Down Expand Up @@ -254,6 +258,58 @@ class {name}CircuitBuilder {{
&circuit_hpp,
);
}

fn create_circuit_builder_cpp(&mut self, name: &str, all_cols: &[String]) {
let names_list = map_with_newline(all_cols, |name: &String| format!("\"{}\",", name));
let stream_all_relations = map_with_newline(all_cols, |name: &String| {
format!("<< field_to_string(row.{}) << \",\"", name)
});
let snake_name = snake_case(name);

let circuit_cpp = format!(
"
#include \"barretenberg/vm/generated/{snake_name}_circuit_builder.hpp\"

namespace bb {{
namespace {{

template <typename FF> std::string field_to_string(const FF& ff)
{{
std::ostringstream os;
os << ff;
std::string raw = os.str();
auto first_not_zero = raw.find_first_not_of('0', 2);
std::string result = \"0x\" + (first_not_zero != std::string::npos ? raw.substr(first_not_zero) : \"0\");
return result;
}}

}} // namespace

template <typename FF> std::vector<std::string> {name}FullRow<FF>::names() {{
return {{
{names_list}
\"\"
}};
}}

template <typename FF> std::ostream& operator<<(std::ostream& os, {name}FullRow<FF> const& row) {{
return os {stream_all_relations}
\"\";
}}

// Explicit template instantiation.
template std::ostream& operator<<(std::ostream& os, AvmFullRow<bb::AvmFlavor::FF> const& row);
template std::vector<std::string> AvmFullRow<bb::AvmFlavor::FF>::names();

}} // namespace bb"
);

self.write_file(
&self.circuit,
&format!("{}_circuit_builder.cpp", snake_case(name)),
&circuit_cpp,
);
}
}

fn get_lookup_check_closure() -> String {
Expand Down
4 changes: 2 additions & 2 deletions bberg/src/flavor_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ fn flavor_includes(name: &str, relation_file_names: &[String], lookups: &[String
let relation_imports = get_relations_imports(name, relation_file_names, lookups);

format!(
"
#pragma once
"#pragma once

#include \"barretenberg/commitment_schemes/kzg/kzg.hpp\"
#include \"barretenberg/ecc/curves/bn254/g1.hpp\"
#include \"barretenberg/flavor/relation_definitions.hpp\"
Expand Down
6 changes: 5 additions & 1 deletion bberg/src/relation_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,11 @@ pub(crate) fn create_row_type(name: &str, all_rows: &[String]) -> String {
let all_annotated = map_with_newline(all_rows, row_transformation);

format!(
"template <typename FF> struct {name}Row {{ \n{}\n }}",
"template <typename FF> struct {name}Row {{
{}

[[maybe_unused]] static std::vector<std::string> names();
}}",
all_annotated,
)
}
Expand Down
2 changes: 2 additions & 0 deletions bberg/src/vm_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ pub(crate) fn analyzed_to_cpp<F: FieldElement>(
&all_cols_with_shifts,
);

bb_files.create_circuit_builder_cpp(file_name, &all_cols);

// ----------------------- Create the flavor file -----------------------
bb_files.create_flavor_hpp(
file_name,
Expand Down
2 changes: 1 addition & 1 deletion bberg_pil_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authors = ["Maddiaa"]
edition = "2021"

[[bin]]
name = "bberg_pil"
name = "bb_pil"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fine with the renaming but please announce this change in the Slack channel. I have an alias currently pointing to bberg_pil and I would continue to use an old version until it breaks. I do not think that cargo build would clean the old binary.

path = "src/main.rs"

[dependencies]
Expand Down
Loading