Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(hugr-py): CFG builder #1192

Merged
merged 6 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hugr-py/src/hugr/_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@


class Block(DfBase[ops.DataflowBlock]):
mark-koch marked this conversation as resolved.
Show resolved Hide resolved
def block_outputs(self, branching: Wire, *other_outputs: Wire) -> None:
def set_block_outputs(self, branching: Wire, *other_outputs: Wire) -> None:
self.set_outputs(branching, *other_outputs)

def single_successor_outputs(self, *outputs: Wire) -> None:
mark-koch marked this conversation as resolved.
Show resolved Hide resolved
# TODO requires constants
raise NotImplementedError

Check warning on line 16 in hugr-py/src/hugr/_cfg.py

View check run for this annotation

Codecov / codecov/patch

hugr-py/src/hugr/_cfg.py#L16

Added line #L16 was not covered by tests


@dataclass
Expand Down
10 changes: 5 additions & 5 deletions hugr-py/tests/test_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
def build_basic_cfg(cfg: Cfg) -> None:
entry = cfg.simple_entry(1, [tys.Bool])

entry.block_outputs(*entry.inputs())
entry.set_block_outputs(*entry.inputs())
cfg.branch(entry.root.out(0), cfg.exit)


Expand All @@ -20,14 +20,14 @@ def test_basic_cfg() -> None:
def test_branch() -> None:
cfg = Cfg([tys.Bool, tys.Unit, INT_T], [INT_T])
entry = cfg.simple_entry(2, [tys.Unit, INT_T])
entry.block_outputs(*entry.inputs())
entry.set_block_outputs(*entry.inputs())

middle_1 = cfg.simple_block([tys.Unit, INT_T], 1, [INT_T])
middle_1.block_outputs(*middle_1.inputs())
middle_1.set_block_outputs(*middle_1.inputs())
middle_2 = cfg.simple_block([tys.Unit, INT_T], 1, [INT_T])
u, i = middle_2.inputs()
n = middle_2.add(DivMod(i, i))
middle_2.block_outputs(u, n[0])
middle_2.set_block_outputs(u, n[0])

cfg.branch(entry.root.out(0), middle_1.root)
mark-koch marked this conversation as resolved.
Show resolved Hide resolved
cfg.branch(entry.root.out(1), middle_2.root)
Expand All @@ -46,4 +46,4 @@ def test_nested_cfg() -> None:
build_basic_cfg(cfg)
dfg.set_outputs(cfg.root)

_validate(dfg.hugr, True)
_validate(dfg.hugr)
Loading