Skip to content

Commit 86815a0

Browse files
committed
merge
2 parents 85a263e + 487712a commit 86815a0

File tree

8 files changed

+36
-7
lines changed

8 files changed

+36
-7
lines changed

crates/ast/src/control.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use super::{
22
Binding, Expr, Id, Implication, Loc, OrderConstraint, Range, Time,
33
};
4+
use fil_utils::PortAttrs;
45
use struct_variant::struct_variant;
56

67
#[derive(Clone)]
@@ -365,11 +366,13 @@ pub struct Bundle {
365366
pub name: Loc<Id>,
366367
/// Type of the bundle
367368
pub typ: BundleType,
369+
/// Attributes associated with the bundle
370+
pub attrs: PortAttrs,
368371
}
369372

370373
impl Bundle {
371-
pub fn new(name: Loc<Id>, typ: BundleType) -> Self {
372-
Self { name, typ }
374+
pub fn new(name: Loc<Id>, typ: BundleType, attrs: PortAttrs) -> Self {
375+
Self { name, typ, attrs }
373376
}
374377

375378
/// Resolve expressions in the Bundle

crates/ast/src/parser.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ impl FilamentParser {
719719
fn bundle_def(input: Node) -> ParseResult<ast::Bundle> {
720720
match_nodes!(
721721
input.clone().into_children();
722-
[identifier(name), expr(sizes).., bundle_typ((params, range, width))] => {
722+
[attributes(attrs), identifier(name), expr(sizes).., bundle_typ((params, range, width))] => {
723723
let sizes = sizes.collect_vec();
724724
// If no size is specified, treat this is as one dimensional bundle with size 1.
725725
let (sizes, s_len) = if sizes.is_empty() {
@@ -739,7 +739,7 @@ impl FilamentParser {
739739
params.push(Loc::unknown(ast::Id::from(format!("_{i}"))));
740740
});
741741

742-
Ok(ast::Bundle::new(name, ast::BundleType::new(params, sizes, range, width)))
742+
Ok(ast::Bundle::new(name, ast::BundleType::new(params, sizes, range, width), attrs))
743743
}
744744
)
745745
}

crates/ast/src/syntax.pest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ bundle_typ = {
175175

176176
// Bundle definition
177177
bundle_def = {
178-
identifier ~ ("[" ~ expr ~ "]")* ~ ":" ~ bundle_typ
178+
attributes ~ identifier ~ ("[" ~ expr ~ "]")* ~ ":" ~ bundle_typ
179179
}
180180

181181
// Ports

crates/filament/src/ir_passes/bundle_elim.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ impl BundleElim {
7171
info,
7272
} = comp.get(pidx).clone();
7373

74+
let attrs = comp.port_attrs.get(pidx).clone();
75+
7476
let Liveness { idxs, lens, range } = live;
7577

7678
let start = comp.get(range.start).clone();
@@ -154,6 +156,9 @@ impl BundleElim {
154156
width,
155157
});
156158

159+
// copy over the attributes
160+
comp.port_attrs.push(pidx, attrs.clone());
161+
157162
// Fill in the live idxs with a new dummy index
158163
let port = ir::Param {
159164
owner: ir::ParamOwner::bundle(pidx),

crates/filament/src/ir_passes/mono/monosig.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,7 @@ impl MonoSig {
801801
live,
802802
info,
803803
} = underlying.get(port);
804+
let attrs = underlying.port_attrs().get(port.idx());
804805

805806
let inv = match owner {
806807
ir::PortOwner::Sig { .. } | ir::PortOwner::Local => None,
@@ -822,6 +823,8 @@ impl MonoSig {
822823
info: info.get(),
823824
});
824825

826+
self.base.push_port_attrs(new_port, attrs.clone());
827+
825828
// Overwrite the value in the port map if any. This is okay because this
826829
// method can be called on local ports defined in iterative scopes.
827830
self.port_map.insert(port_map_k, new_port);

crates/filament/src/ir_passes/mono/utils/comp.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use fil_ast as ast;
22
use fil_ir::{
3-
self as ir, AddCtx, Ctx, DisplayCtx, Idx, IndexStore, InterfaceSrc, MutCtx,
3+
self as ir, AddCtx, Ctx, DenseIndexInfo, DisplayCtx, Idx, IndexStore,
4+
InterfaceSrc, MutCtx,
45
};
6+
use fil_utils as utils;
57

68
use super::{Base, IntoBase, IntoUdl, Underlying};
79

@@ -25,6 +27,9 @@ impl<'a> UnderlyingComp<'a> {
2527
pub fn ports(&self) -> &IndexStore<ir::Port> {
2628
self.0.ports()
2729
}
30+
pub fn port_attrs(&self) -> &DenseIndexInfo<ir::Port, utils::PortAttrs> {
31+
&self.0.port_attrs
32+
}
2833
pub fn src_info(&self) -> &Option<InterfaceSrc> {
2934
&self.0.src_info
3035
}
@@ -95,6 +100,14 @@ impl BaseComp {
95100
self.0.src_info = other;
96101
}
97102

103+
pub fn push_port_attrs(
104+
&mut self,
105+
key: Base<ir::Port>,
106+
val: utils::PortAttrs,
107+
) {
108+
self.0.port_attrs.push(key.get(), val);
109+
}
110+
98111
pub fn extend_cmds(
99112
&mut self,
100113
other: impl IntoIterator<Item = ir::Command>,

crates/ir/src/comp.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use super::{
44
InvIdx, Invoke, MutCtx, Param, ParamIdx, Port, PortIdx, Prop, PropIdx,
55
Time, TimeSub,
66
};
7-
use crate::{utils::Idx, ParamOwner};
7+
use crate::{utils::Idx, DenseIndexInfo, ParamOwner};
88
use fil_ast as ast;
99
use fil_derive::Ctx;
1010
use fil_utils as utils;
@@ -59,6 +59,8 @@ pub struct Component {
5959
// ============== Component signature ===============
6060
/// Attributes of the component
6161
pub attrs: utils::CompAttrs,
62+
/// Attributes of ports in the component
63+
pub port_attrs: DenseIndexInfo<Port, utils::PortAttrs>,
6264
/// The input parameters to the component
6365
/// TODO (Edmund): revert this to pub(crate) once we have an IR builder
6466
pub param_args: Box<[ParamIdx]>,

crates/ir/src/from_ast/astconv.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ impl<'prog> BuildCtx<'prog> {
440440
liveness,
441441
bitwidth,
442442
},
443+
attrs,
443444
} = pd;
444445

445446
let info = self.comp().add(ir::Info::port(
@@ -478,6 +479,8 @@ impl<'prog> BuildCtx<'prog> {
478479
// Defines helper variable here due to lifetime issues
479480
let is_sig_port = p.is_sig();
480481
let idx = self.comp().add(p);
482+
// Add the attributes to port attributes
483+
self.comp().port_attrs.push(idx, attrs);
481484
// Fixup the liveness index parameter's owner
482485
let idxs = self.comp().get(idx).live.idxs.clone();
483486
for p in idxs {

0 commit comments

Comments
 (0)