Skip to content

Commit

Permalink
Add a nice little warning (#2160)
Browse files Browse the repository at this point in the history
  • Loading branch information
EclecticGriffin authored Jun 18, 2024
1 parent 70d278b commit a4c2442
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
7 changes: 7 additions & 0 deletions interp/src/flatten/primitives/builder.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use ahash::HashSet;

use super::{combinational::*, stateful::*, Primitive};
use crate::{
flatten::{
Expand All @@ -17,6 +19,7 @@ pub fn build_primitive(
// extras for memory initialization
ctx: &Context,
dump: &Option<DataDump>,
memories_initialized: &mut HashSet<String>,
) -> Box<dyn Primitive> {
match &prim.prototype {
CellPrototype::Constant {
Expand Down Expand Up @@ -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)
Expand Down
22 changes: 19 additions & 3 deletions interp/src/flatten/structures/environment/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ use crate::{
environment::program_counter::ControlPoint, index_trait::IndexRef,
},
},
logging,
serialization::data_dump::{DataDump, Dimensions},
values::Value,
};
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<GlobalPortIdx, PortValue>;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -280,6 +282,7 @@ impl<'a> Environment<'a> {
&mut self,
comp: GlobalCellIdx,
data_map: Option<DataDump>,
memories_initialized: &mut HashSet<String>,
) {
let ComponentLedger {
index_bases,
Expand Down Expand Up @@ -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 });

Expand All @@ -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);
}
}
}

Expand Down

0 comments on commit a4c2442

Please sign in to comment.