Skip to content

Commit 3513c57

Browse files
committed
port attributes
1 parent 3377070 commit 3513c57

File tree

11 files changed

+30
-9
lines changed

11 files changed

+30
-9
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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ impl BundleElim {
6969
width,
7070
live,
7171
info,
72+
attrs,
7273
} = comp.get(pidx).clone();
7374

7475
let Liveness { idxs, lens, range } = live;
@@ -152,6 +153,7 @@ impl BundleElim {
152153
owner,
153154
info, // duplicate the info
154155
width,
156+
attrs: attrs.clone(),
155157
});
156158

157159
// Fill in the live idxs with a new dummy index

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,7 @@ impl MonoSig {
800800
width,
801801
live,
802802
info,
803+
attrs,
803804
} = underlying.get(port);
804805

805806
let inv = match owner {
@@ -820,6 +821,7 @@ impl MonoSig {
820821
width: *width, // placeholder
821822
live: live.clone(), // placeholder
822823
info: info.get(),
824+
attrs: attrs.clone(),
823825
});
824826

825827
// Overwrite the value in the port map if any. This is okay because this

crates/ir/src/from_ast/astconv.rs

Lines changed: 2 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(
@@ -473,6 +474,7 @@ impl<'prog> BuildCtx<'prog> {
473474
owner,
474475
live,
475476
info,
477+
attrs,
476478
};
477479

478480
// Defines helper variable here due to lifetime issues

crates/ir/src/structure.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use super::{
33
InstIdx, InvIdx, ParamIdx, PortIdx, Subst, TimeIdx, TimeSub,
44
};
55
use fil_ast::Op;
6+
use fil_utils::PortAttrs;
67
use itertools::Itertools;
78
use std::fmt;
89

@@ -142,6 +143,7 @@ pub struct Port {
142143
pub width: ExprIdx,
143144
pub live: Liveness,
144145
pub info: InfoIdx,
146+
pub attrs: PortAttrs,
145147
}
146148
impl Port {
147149
/// Check if this is an invoke defined port

crates/utils/src/attr/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ mod types;
66
pub use attributes::Attributes;
77
pub use ctx::AttrCtx;
88
pub use store::AttrStore;
9-
pub use types::comp_attrs::{
10-
Attrs as CompAttrs, Bool as CompBool, Num as CompNum,
9+
pub use types::{
10+
comp_attrs::{Attrs as CompAttrs, Bool as CompBool, Num as CompNum},
11+
port_attrs::{Attrs as PortAttrs, Bool as PortBool, Num as PortNum},
1112
};

crates/utils/src/attr/types.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,9 @@ attr_set! {
1313
numeric {
1414
};
1515
}
16+
17+
attr_set! {
18+
port_attrs;
19+
flag {};
20+
numeric {};
21+
}

crates/utils/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ mod math;
88
mod position;
99
mod reporter;
1010

11-
pub use attr::{AttrCtx, AttrStore, Attributes, CompAttrs, CompBool, CompNum};
11+
pub use attr::{
12+
AttrCtx, AttrStore, Attributes, CompAttrs, CompBool, CompNum, PortAttrs,
13+
PortBool, PortNum,
14+
};
1215
pub use errors::{Error, FilamentResult};
1316
pub use gsym::GSym;
1417
pub use id::Id;

0 commit comments

Comments
 (0)