Skip to content

Commit

Permalink
Small example showing various forms of guards
Browse files Browse the repository at this point in the history
  • Loading branch information
anshumanmohan committed Jun 11, 2024
1 parent 63c637b commit b61ad5f
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
12 changes: 12 additions & 0 deletions calyx-py/test/correctness/guards.data
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"mem": {
"data": [
0
],
"format": {
"numeric_type": "bitnum",
"is_signed": false,
"width": 32
}
}
}
5 changes: 5 additions & 0 deletions calyx-py/test/correctness/guards.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"mem": [
42
]
}
39 changes: 39 additions & 0 deletions calyx-py/test/correctness/guards.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# pylint: disable=import-error
import calyx.builder as cb


def insert_main_component(prog):
"""Insert the main component into the program.
This component will invoke the `muler`, `abs_diff`, `mux`, and `map` components.
"""

comp = prog.component("main")

mem = comp.seq_mem_d1("mem", 32, 1, 32, is_external=True)

mul = comp.mult_pipe(32)
zero = cb.const(32, 0)
one = cb.const(32, 1)

with comp.group("well-guarded_group") as wgg:
mul.left = zero @ 4 # This will never be executed
mul.left = (one <= zero) @ 5 # This will never be executed
mul.left = ~zero @ 6 # This will work
mul.right = (zero | one) @ 7 # This will work
mul.right = (zero & one) @ 8 # This will never be executed
mul.go = cb.HI
wgg.done = mul.done

put_ans_in_mem = comp.mem_store_d1(mem, 0, mul.out, "store")

comp.control += [wgg, put_ans_in_mem]


def build():
prog = cb.Builder()
insert_main_component(prog)
return prog.program


if __name__ == "__main__":
build().emit()

0 comments on commit b61ad5f

Please sign in to comment.