loki.visitors.ir_graph
GraphCollector classes for IR
Module Attributes
Indicate wheater the graphviz package is available. |
Functions
|
Pretty-print the given IR using |
Classes
|
Convert a given IR tree to a node and edge list via the visit mechanism. |
- HAVE_IR_GRAPH = True
Indicate wheater the graphviz package is available.
- class GraphCollector(show_comments=False, show_expressions=False, linewidth=40, symgen=<class 'str'>)
Bases:
Visitor
Convert a given IR tree to a node and edge list via the visit mechanism.
This serves as base class for backends and provides a number of helpful routines that ease implementing automatic recursion and line wrapping. It is adapted from the Stringifier in “pprint.py”. It doubles as a means to produce a human readable graph representation of the IR, which is useful for debugging purposes and first visualization.
- Parameters:
linewidth (int, optional) – The line width limit after which to break a line.
symgen (str, optional) – A function handle that accepts a
pymbolic.primitives.Expression
and produces a string representation for that.show_comments (bool, optional, default: False) – Whether to show comments in the output
show_expressions (bool, optional, default: False) – Whether to further expand expressions in the output
- property symgen
Formatter for expressions.
- join_items(items, sep=', ', separable=True)
Concatenate a list of items into
JoinableStringList
.The return value can be passed to
format_line()
orformat_node()
or converted to a string with str, using theJoinableStringList
as an argument. Upon expansion, lines will be wrapped automatically to stay within the linewidth limit.- Parameters:
- Return type:
- format_node(name, *items)
Default format for a node.
Creates a string of the form
<name[, attribute, attribute, ...]>
.
- format_line(*items, comment=None, no_wrap=False)
Format a line by concatenating all items and applying indentation while observing the allowed line width limit.
Note that the provided comment will simply be extended to the line and no line width limit will be enforced for that.
- Parameters:
- Returns:
required to observe the line width limit.
- Return type:
str the string of the current line, potentially including line breaks if
- visit_all(item, *args, **kwargs)
Convenience function to call
visit()
for all given arguments.If only a single argument is given that is iterable,
visit()
is called on all of its elements instead.
- visit_Module(o, **kwargs)
Add a
Module
, mark parent node and visit all “spec” and “subroutine” nodes.
- visit_Subroutine(o, **kwargs)
Add a
Subroutine
, mark parent node and visit all “docstring”, “spec”, “body”, “members” nodes.
- visit_Comment(o, **kwargs)
Enables turning off comments.
- visit_CommentBlock(o, **kwargs)
Enables turning off comments.
- visit_Expression(o, **kwargs)
Dispatch routine to add nodes utilizing expression tree stringifier, mark parent and stop.
- visit_tuple(o, **kwargs)
Recurse for each item in the tuple.
- visit_list(o, **kwargs)
Recurse for each item in the tuple.
- ir_graph(ir, show_comments=False, show_expressions=False, linewidth=40, symgen=<class 'str'>)
Pretty-print the given IR using
GraphCollector
.