diff --git a/assembly/src/library/mod.rs b/assembly/src/library/mod.rs index 7e2d35789..135a0008e 100644 --- a/assembly/src/library/mod.rs +++ b/assembly/src/library/mod.rs @@ -10,7 +10,7 @@ use vm_core::{ debuginfo::Span, mast::{MastForest, MastNodeId}, utils::{ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable}, - Kernel, + AdviceMap, Kernel, }; use crate::ast::{Ident, ProcedureName, QualifiedProcedureName}; @@ -88,6 +88,15 @@ impl Library { Ok(Self { digest, exports, mast_forest }) } + + pub fn with_advice_map(self, advice_map: AdviceMap) -> Self { + let mut mast_forest = (*self.mast_forest).clone(); + mast_forest.advice_map_mut().extend(advice_map); + Self { + mast_forest: Arc::new(mast_forest), + ..self + } + } } // ------------------------------------------------------------------------------------------------ diff --git a/core/src/advice/map.rs b/core/src/advice/map.rs index 1e0384eb4..52b15801e 100644 --- a/core/src/advice/map.rs +++ b/core/src/advice/map.rs @@ -59,6 +59,12 @@ impl From>> for AdviceMap { } } +impl FromIterator<(RpoDigest, Vec)> for AdviceMap { + fn from_iter)>>(iter: T) -> Self { + Self(iter.into_iter().collect()) + } +} + impl IntoIterator for AdviceMap { type Item = (RpoDigest, Vec); type IntoIter = IntoIter>; diff --git a/core/src/program.rs b/core/src/program.rs index ebff4c7b0..5d51226e2 100644 --- a/core/src/program.rs +++ b/core/src/program.rs @@ -8,6 +8,7 @@ use super::Kernel; use crate::{ mast::{MastForest, MastNode, MastNodeId}, utils::ToElements, + AdviceMap, }; // PROGRAM @@ -53,6 +54,15 @@ impl Program { Self { mast_forest, entrypoint, kernel } } + + pub fn with_advice_map(self, advice_map: AdviceMap) -> Self { + let mut mast_forest = (*self.mast_forest).clone(); + mast_forest.advice_map_mut().extend(advice_map); + Self { + mast_forest: Arc::new(mast_forest), + ..self + } + } } // ------------------------------------------------------------------------------------------------