DefinitionBuilder#
- class hugr.build.dfg.DefinitionBuilder(hugr: Hugr[OpVar])[source]#
Bases:
Generic
[OpVar
]Base class for builders that can define functions, constants, and aliases.
As this class may be a root node, it does not extend ParentBuilder.
Methods
Add a type alias definition.
Add a static constant to the graph.
Start building a function definition in the graph.
Attributes
hugr
- add_alias_defn(name: str, ty: Type, parent: ToNode | None = None) Node [source]#
Add a type alias definition.
- 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 root 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)
- define_function(name: str, input_types: TypeRow, output_types: TypeRow | None = None, type_params: list[TypeParam] | None = None, parent: ToNode | None = None) Function [source]#
Start building a function definition in the graph.
- Parameters:
name – The name of the function.
input_types – The input types for the function.
output_types – The output types for the function. If not provided, it will be inferred after the function is built.
type_params – The type parameters for the function, if polymorphic.
parent – The parent node of the constant. Defaults to the root node.
- Returns:
The new function builder.