Skip to content

Commit

Permalink
Submodules query.
Browse files Browse the repository at this point in the history
  • Loading branch information
maloneymr committed May 3, 2024
1 parent b4eee0b commit c9af163
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 0 additions & 2 deletions examples/hello.vir
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ public module Top {
incoming in : Word[8];
outgoing out : Word[8];

submodule foo of Foo;

reg buf : Word[8] on clk;
buf <= in;
out := buf->add(in);
Expand Down
19 changes: 19 additions & 0 deletions src/checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ pub trait QueryGroup: salsa::Database {

fn moddef_component_names(&self, moddef: Ident) -> Result<Vec<Ident>, VirdantError>;

fn moddef_submodules(&self, moddef: Ident) -> Result<Vec<hir::Submodule>, VirdantError>;

fn moddef_component_hir(&self, moddef: Ident, component: Ident) -> VirdantResult<hir::Component>;

fn moddef_component_hir_typed(&self, moddef: Ident, component: Ident) -> VirdantResult<hir::Component>;
Expand Down Expand Up @@ -172,13 +174,30 @@ fn moddef_hir_typed(db: &dyn QueryGroup, moddef: Ident) -> VirdantResult<hir::Mo
})
}

fn moddef_submodules(db: &dyn QueryGroup, moddef: Ident) -> Result<Vec<hir::Submodule>, VirdantError> {
let moddef_hir = db.moddef_hir(moddef.clone())?;
Ok(moddef_hir.submodules.iter().cloned().collect())
}

fn moddef_context(db: &dyn QueryGroup, moddef: Ident) -> Result<Context<Path, Arc<crate::types::Type>>, VirdantError> {
let mut ctx = Context::empty();
for component in db.moddef_component_names(moddef.clone())? {
let typ = crate::types::Type::from_ast(&db.moddef_component_type(moddef.clone(), component.clone())?);
ctx = ctx.extend(component.as_path(), typ);
}

for submodule in db.moddef_submodules(moddef.clone())? {
let submodule_moddef = db.moddef_hir(submodule.moddef.clone())?;
for component in &submodule_moddef.components {
if let hir::Component::Incoming(name, typ) = component {
let path = submodule.name.as_path().join(&name.as_path());
ctx = ctx.extend(path, typ.clone());
} else if let hir::Component::Outgoing(name, typ, _connect) = component {
let path = submodule.name.as_path().join(&name.as_path());
ctx = ctx.extend(path, typ.clone());
}
}
}
Ok(ctx)
}

Expand Down
1 change: 1 addition & 0 deletions src/elab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::sim::{Sim, SimBuilder};
use crate::types::Type;
use crate::context::Context;

#[derive(Clone, Debug)]
pub struct Elab {
pub moddef: Arc<hir::ModDef>,
pub submodules: HashMap<Ident, Elab>,
Expand Down

0 comments on commit c9af163

Please sign in to comment.