DefinitionBuilder

class hugr.build.dfg.DefinitionBuilder(hugr: Hugr[OpVar])[source]

Bases: Generic[OpVar]

Base class for builders that can define constants, and allow access

to the Module for declaring/defining functions and aliases.

As this class may be a root node, it does not extend ParentBuilder.

Methods

add_const

Add a static constant to the graph.

module_root_builder

Allows access to the Module at the root of the Hugr (outside the scope of this builder, perhaps outside the entrypoint).

Attributes

hugr

add_const(value: val.Value, parent: ToNode | None = None) Node[source]

Add a static constant to the graph.

Parameters:
  • value – The constant value to add.

  • parent – The parent node of the constant. Defaults to the entrypoint node.

Returns:

The node holding the Const operation.

Example

>>> dfg = Dfg()
>>> const_n = dfg.add_const(val.TRUE)
>>> dfg.hugr[const_n].op
Const(TRUE)
module_root_builder() Module[source]

Allows access to the Module at the root of the Hugr (outside the scope of this builder, perhaps outside the entrypoint).