From a4c2442675d3419be6d2f5cf912aa3f804b3c4ab Mon Sep 17 00:00:00 2001 From: Griffin Berlstein Date: Tue, 18 Jun 2024 14:28:38 -0400 Subject: [PATCH] Add a nice little warning (#2160) --- interp/src/flatten/primitives/builder.rs | 7 ++++++ .../src/flatten/structures/environment/env.rs | 22 ++++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/interp/src/flatten/primitives/builder.rs b/interp/src/flatten/primitives/builder.rs index 2e15789aad..111f953fdb 100644 --- a/interp/src/flatten/primitives/builder.rs +++ b/interp/src/flatten/primitives/builder.rs @@ -1,3 +1,5 @@ +use ahash::HashSet; + use super::{combinational::*, stateful::*, Primitive}; use crate::{ flatten::{ @@ -17,6 +19,7 @@ pub fn build_primitive( // extras for memory initialization ctx: &Context, dump: &Option, + memories_initialized: &mut HashSet, ) -> Box { match &prim.prototype { CellPrototype::Constant { @@ -128,11 +131,15 @@ pub fn build_primitive( match mem_type { MemType::Seq => Box::new(if let Some(data) = data { + memories_initialized + .insert(ctx.lookup_string(prim.name).clone()); SeqMem::new_with_init(base_port, *width, false, dims, data) } else { SeqMemD1::new(base_port, *width, false, dims) }), MemType::Std => Box::new(if let Some(data) = data { + memories_initialized + .insert(ctx.lookup_string(prim.name).clone()); CombMem::new_with_init(base_port, *width, false, dims, data) } else { CombMem::new(base_port, *width, false, dims) diff --git a/interp/src/flatten/structures/environment/env.rs b/interp/src/flatten/structures/environment/env.rs index c3a3c8f1e5..6fdfa03284 100644 --- a/interp/src/flatten/structures/environment/env.rs +++ b/interp/src/flatten/structures/environment/env.rs @@ -25,6 +25,7 @@ use crate::{ environment::program_counter::ControlPoint, index_trait::IndexRef, }, }, + logging, serialization::data_dump::{DataDump, Dimensions}, values::Value, }; @@ -32,6 +33,7 @@ use ahash::HashMap; use ahash::HashSet; use ahash::HashSetExt; use itertools::Itertools; +use slog::warn; use std::{fmt::Debug, iter::once}; pub type PortMap = IndexedMap; @@ -250,7 +252,7 @@ impl<'a> Environment<'a> { let root_node = CellLedger::new_comp(root, &env); let root = env.cells.push(root_node); - env.layout_component(root, data_map); + env.layout_component(root, data_map, &mut HashSet::new()); // Initialize program counter // TODO griffin: Maybe refactor into a separate function @@ -280,6 +282,7 @@ impl<'a> Environment<'a> { &mut self, comp: GlobalCellIdx, data_map: Option, + memories_initialized: &mut HashSet, ) { let ComponentLedger { index_bases, @@ -339,7 +342,11 @@ impl<'a> Environment<'a> { ); } let cell_dyn = primitives::build_primitive( - info, port_base, self.ctx, &data_map, + info, + port_base, + self.ctx, + &data_map, + memories_initialized, ); let cell = self.cells.push(CellLedger::Primitive { cell_dyn }); @@ -358,7 +365,16 @@ impl<'a> Environment<'a> { ); // layout sub-component but don't include the data map - self.layout_component(cell, None); + self.layout_component(cell, None, memories_initialized); + } + } + + if let Some(data) = data_map { + for dec in data.header.memories.iter() { + if !memories_initialized.contains(&dec.name) { + // TODO griffin: maybe make this an error? + warn!(logging::root(), "Initialization was provided for memory {} but no such memory exists in the entrypoint component.", dec.name); + } } }