ModelImport¶
- class hugr.model.load.ModelImport(module: Module)[source]¶
Bases:
objectHelper to import a Hugr.
Methods
add_module_metadataAdd a model Node to the Hugr and record its in- and out-links.
enter_symbolexit_symbolimport_blockImport an entire CFG region from the model into the Hugr.
Import an entire DFG region from the model into the Hugr.
Import a model Node within a DFG region.
Import a model Node at the Hugr Module level.
import_signatureImport the type from a model Term.
Import a TypeArg from a model Term.
Import a TypeParam from a model Term.
import_type_rowimport_valueAdd links to the Hugr according to the recorded data.
link_static_portslookup_varRecord a bunch of links entering the given Hugr Node with the given names.
Record a bunch of links exiting the given Hugr Node with the given names.
Record the symbol introduced by a root module node, if any.
Resolve a symbol version from the model import context.
Attributes
local_varscurrent_symbollink_prefixlinked_portsstatic_edgesmodulesymbolsfn_nodesfn_callshugr- add_node(node: Node, operation: Op, parent: Node, num_outs: int | None = None) Node[source]¶
Add a model Node to the Hugr and record its in- and out-links.
- import_cfg_region(region: Region, signature: FunctionType, parent: Node)[source]¶
Import an entire CFG region from the model into the Hugr.
- import_dfg_region(region: Region, parent: Node)[source]¶
Import an entire DFG region from the model into the Hugr.
- import_node_in_dfg(node: Node, parent: Node) Node[source]¶
Import a model Node within a DFG region.
Returns the Hugr Node corresponding to the model Node. The correspondence is almost 1-1, but a LoadConst model Node requires two Hugr Nodes (Const and LoadConst); in this case the LoadConst is returned.
- import_node_in_module(node: Node, link_prefix: int) Node | None[source]¶
Import a model Node at the Hugr Module level.
- import_type_param(term: Term, bound: TypeBound = TypeBound.Linear) TypeParam[source]¶
Import a TypeParam from a model Term.
- record_in_links(node: Node, links: Iterable[str])[source]¶
Record a bunch of links entering the given Hugr Node with the given names.
- record_out_links(node: Node, links: Iterable[str])[source]¶
Record a bunch of links exiting the given Hugr Node with the given names.
- record_root_symbol(node: Node) None[source]¶
Record the symbol introduced by a root module node, if any.
- symbol_version(name: str, version: Version | None) Version | None[source]¶
Resolve a symbol version from the model import context.
If a version is explicitly provided, it is returned as is. Otherwise, an exact unversioned model binding is preferred, then the latest explicit version declared for the symbol in the model is returned. If neither exists, None is returned.