-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Compiling external-to-ref. TBD if correct * Allow `ref` in toplevel components * update runt tests allowing ref in main and external-to-ref pass * remove some comments from external_to_ref * update for nested external-to-ref * rustfmt * remove old main-ref-cell well-formedness test * add doc comments and remove todos from external_to_ref
- Loading branch information
1 parent
4cf9f99
commit f99a966
Showing
9 changed files
with
168 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use crate::traversal::{Action, ConstructVisitor, Named, VisResult, Visitor}; | ||
use calyx_ir::{self as ir, GetAttributes, LibrarySignatures}; | ||
use calyx_utils::CalyxResult; | ||
|
||
/// Turns memory cell primitives with the `@external(1)` attribute into | ||
/// `ref` memory cells without the `@external` attribute. | ||
pub struct ExternalToRef; | ||
|
||
impl Named for ExternalToRef { | ||
fn name() -> &'static str { | ||
"external-to-ref" | ||
} | ||
|
||
fn description() -> &'static str { | ||
"Turn memory cells marked with `@external(1) into `ref` memory cells." | ||
} | ||
} | ||
|
||
impl ConstructVisitor for ExternalToRef { | ||
fn from(_ctx: &ir::Context) -> CalyxResult<Self> | ||
where | ||
Self: Sized, | ||
{ | ||
let external_to_ref = ExternalToRef; | ||
Ok(external_to_ref) | ||
} | ||
|
||
fn clear_data(&mut self) {} | ||
} | ||
|
||
impl Visitor for ExternalToRef { | ||
fn start( | ||
&mut self, | ||
comp: &mut ir::Component, | ||
_ctx: &LibrarySignatures, | ||
_comps: &[ir::Component], | ||
) -> VisResult { | ||
// Iterate over each cell in the component | ||
for cell in comp.cells.iter() { | ||
let mut cell_ref = cell.borrow_mut(); | ||
if cell_ref.get_attributes().has(ir::BoolAttr::External) { | ||
// Change the cell type to `ref` and remove the external attribute | ||
cell_ref.get_mut_attributes().remove(ir::BoolAttr::External); | ||
cell_ref.set_reference(true); | ||
} | ||
} | ||
// Continue visiting other nodes in the AST | ||
Ok(Action::Continue) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import "primitives/core.futil"; | ||
import "primitives/memories/seq.futil"; | ||
component main(@go go: 1, @clk clk: 1, @reset reset: 1) -> (@done done: 1) { | ||
cells { | ||
ref A = seq_mem_d1(32, 16, 4); | ||
B = seq_mem_d1(32, 16, 4); | ||
ref state = std_reg(32); | ||
ref my_module = module(); | ||
} | ||
wires { | ||
group wr_A { | ||
A.write_en = 1'd1; | ||
A.content_en = 1'd1; | ||
A.write_data = 32'd5; | ||
wr_A[done] = A.done; | ||
} | ||
group wr_B { | ||
B.write_en = 1'd1; | ||
B.content_en = 1'd1; | ||
B.write_data = 32'd4; | ||
wr_B[done] = B.done; | ||
} | ||
group read_A { | ||
A.content_en = 1'd1; | ||
A.write_en = 1'd0; | ||
read_A[done] = A.done; | ||
} | ||
} | ||
control { | ||
seq { | ||
par { | ||
wr_A; | ||
wr_B; | ||
} | ||
read_A; | ||
} | ||
} | ||
} | ||
component module(@go go: 1, @clk clk: 1, @reset reset: 1) -> (@done done: 1) { | ||
cells { | ||
ref C = seq_mem_d1(32, 16, 4); | ||
} | ||
wires { | ||
group wr_C { | ||
C.write_en = 1'd1; | ||
C.content_en = 1'd1; | ||
C.write_data = 32'd6; | ||
wr_C[done] = C.done; | ||
} | ||
} | ||
control {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// -p external-to-ref | ||
|
||
import "primitives/core.futil"; | ||
import "primitives/memories/seq.futil"; | ||
|
||
component main() -> () { | ||
cells { | ||
@external(1) A = seq_mem_d1(32, 16, 4); | ||
B = seq_mem_d1(32, 16, 4); | ||
@external(1) state = std_reg(32); | ||
@external(1) my_module = module(); | ||
|
||
} | ||
wires { | ||
group wr_A { | ||
A.write_en = 1'b1; | ||
A.content_en = 1'b1; | ||
A.write_data = 32'd5; | ||
wr_A[done] = A.done; | ||
} | ||
|
||
group wr_B { | ||
B.write_en = 1'b1; | ||
B.content_en=1'b1; | ||
B.write_data = 32'd4; | ||
wr_B[done] = B.done; | ||
} | ||
|
||
group read_A { | ||
A.content_en = 1'b1; | ||
A.write_en = 1'b0; | ||
read_A[done] = A.done; | ||
} | ||
} | ||
control { | ||
seq{ | ||
par{wr_A; wr_B;} | ||
read_A; | ||
} | ||
} | ||
} | ||
|
||
component module() -> () { | ||
cells { | ||
@external(1) C = seq_mem_d1(32,16,4); | ||
} | ||
wires { | ||
group wr_C { | ||
C.write_en = 1'b1; | ||
C.content_en = 1'b1; | ||
C.write_data= 32'd6; | ||
wr_C[done] = C.done; | ||
} | ||
} | ||
control {} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.