-
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.
[calyx-py] Add case statement support for ComponentBuilders (#2168)
* add case statement support for ComponentBuilders * add runt tests * change case to return a par block instead of automatically adding to control of a component * Queues: use case statements in FIFO control (#2171) * Prepare fifo for case idiom * Attempt with . Failing due to empty control * Delete calyx-py/test/correctness/queues/fifo.futil * improve naming of equalities and add name functions to some classes in builder * runt tests * apply black * remove extra print * runt tests * print out signals when possible for case statement signals * Temporarily checking in fifo.futil to discuss * Remove accidental double par * Un-check-in futil file --------- Co-authored-by: Anshuman Mohan <[email protected]> Co-authored-by: Anshuman Mohan <[email protected]>
- Loading branch information
1 parent
cd0791c
commit f823565
Showing
6 changed files
with
125 additions
and
16 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
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,28 @@ | ||
import "primitives/core.futil"; | ||
import "primitives/binary_operators.futil"; | ||
component my_comp(in_1: 8) -> (out_1: 16) { | ||
cells { | ||
comp_reg = std_reg(1); | ||
in_1_eq_1 = std_eq(8); | ||
in_1_eq_2 = std_eq(8); | ||
} | ||
wires { | ||
group my_group { | ||
|
||
} | ||
in_1_eq_1.left = in_1; | ||
in_1_eq_1.right = 8'd1; | ||
in_1_eq_2.left = in_1; | ||
in_1_eq_2.right = 8'd2; | ||
} | ||
control { | ||
par { | ||
if in_1_eq_1.out { | ||
my_group; | ||
} | ||
if in_1_eq_2.out { | ||
invoke comp_reg(in=1'd1)(); | ||
} | ||
} | ||
} | ||
} |
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,28 @@ | ||
from calyx.builder import Builder, invoke | ||
|
||
#Creates a component the has a case statement. | ||
def add_case(prog): | ||
# Inputs/Outputs | ||
my_comp = prog.component("my_comp") | ||
comp_reg = my_comp.reg(1, "comp_reg") | ||
in_1 = my_comp.input("in_1", 8) | ||
out_1 = my_comp.output("out_1", 16) | ||
|
||
with my_comp.group("my_group") as my_group: | ||
# Some assignments | ||
my_comp.out_1 = 24 | ||
|
||
my_invoke = invoke(comp_reg, in_in=1) | ||
in_1_comps = my_comp.case(in_1, {1: my_group, 2: my_invoke}) | ||
my_comp.control += in_1_comps | ||
|
||
|
||
def build(): | ||
prog = Builder() | ||
add_case(prog) | ||
return prog.program | ||
|
||
|
||
if __name__ == "__main__": | ||
build().emit() | ||
|
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