def dump(self): def label_marker(i): if i[1].offset in self.labels: return ">" else: return " " return "\n".join("%s %10s\t%s" % ((label_marker(i), ) + i) for i in utils.iteritems(self.table))
def dump(self): def label_marker(i): if i[1].offset in self.labels: return '>' else: return ' ' return '\n'.join('%s %10s\t%s' % ((label_marker(i), ) + i) for i in utils.iteritems(self.table))
def inspect_types(self, file=None): ''' Produce a dump of the Python source of this function annotated with the corresponding Numba IR and type information. The dump is written to *file*, or *sys.stdout* if *file* is *None*. ''' if file is None: file = sys.stdout for _, defn in utils.iteritems(self.definitions): defn.inspect_types(file=file)
def inspect_types(self, file=None, signature=None, pretty=False, style="default", **kwargs): """Print/return Numba intermediate representation (IR)-annotated code. Parameters ---------- file : file-like object, optional File to which to print. Defaults to sys.stdout if None. Must be None if ``pretty=True``. signature : tuple of numba types, optional Print/return the intermediate representation for only the given signature. If None, the IR is printed for all available signatures. pretty : bool, optional If True, an Annotate object will be returned that can render the IR with color highlighting in Jupyter and IPython. ``file`` must be None if ``pretty`` is True. Additionally, the ``pygments`` library must be installed for ``pretty=True``. style : str, optional Choose a style for rendering. Ignored if ``pretty`` is ``False``. This is directly consumed by ``pygments`` formatters. To see a list of available styles, import ``pygments`` and run ``list(pygments.styles.get_all_styles())``. Returns ------- annotated : Annotate object, optional Only returned if ``pretty=True``, otherwise this function is only used for its printing side effect. If ``pretty=True``, an Annotate object is returned that can render itself in Jupyter and IPython. """ overloads = self.overloads if signature is not None: overloads = {signature: self.overloads[signature]} if not pretty: if file is None: file = sys.stdout for ver, res in utils.iteritems(overloads): print("%s %s" % (self.py_func.__name__, ver), file=file) print("-" * 80, file=file) print(res.type_annotation, file=file) print("=" * 80, file=file) else: if file is not None: raise ValueError("`file` must be None if `pretty=True`") from numba.core.annotations.pretty_annotate import Annotate return Annotate(self, signature=signature, style=style)
def __init__(self, context, library, fndesc, func_ir, metadata=None): self.library = library self.fndesc = fndesc self.blocks = utils.SortedMap(utils.iteritems(func_ir.blocks)) self.func_ir = func_ir self.call_conv = context.call_conv self.generator_info = func_ir.generator_info self.metadata = metadata # Initialize LLVM self.module = self.library.create_ir_module(self.fndesc.unique_name) # Python execution environment (will be available to the compiled # function). self.env = Environment.from_fndesc(self.fndesc) # Internal states self.blkmap = {} self.pending_phis = {} self.varmap = {} self.firstblk = min(self.blocks.keys()) self.loc = -1 # Specializes the target context as seen inside the Lowerer # This adds: # - environment: the python execution environment self.context = context.subtarget(environment=self.env, fndesc=self.fndesc) # Debuginfo dibuildercls = (self.context.DIBuilder if self.context.enable_debuginfo else debuginfo.DummyDIBuilder) self.debuginfo = dibuildercls(module=self.module, filepath=func_ir.loc.filename) # Subclass initialization self.init()