def __init__(self, context, fndesc, interp): self.context = context self.fndesc = fndesc self.blocks = utils.SortedMap(utils.iteritems(interp.blocks)) # Initialize LLVM self.module = Module.new("module.%s" % self.fndesc.unique_name) # Python execution environment (will be available to the compiled # function). self.env = _dynfunc.Environment( globals=self.fndesc.lookup_module().__dict__) # Setup function self.function = context.declare_function(self.module, fndesc) self.entry_block = self.function.append_basic_block('entry') self.builder = Builder.new(self.entry_block) # Internal states self.blkmap = {} self.varmap = {} self.firstblk = min(self.blocks.keys()) self.loc = -1 # Subclass initialization self.init()
def inspect_types(self, file=None, **kwargs): """ print or return annotated source with Numba intermediate IR Pass `pretty=True` to attempt color highlighting, and HTML rendering in Jupyter and IPython by returning an Annotate Object. `file` must be None if used in conjunction with `pretty=True`. """ pretty = kwargs.get('pretty', False) style = kwargs.get('style', 'default') if not pretty: if file is None: file = sys.stdout for ver, res in utils.iteritems(self.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 .pretty_annotate import Annotate return Annotate(self, style=style)
def __init__(self, context, library, fndesc, interp): self.context = context self.library = library self.fndesc = fndesc self.blocks = utils.SortedMap(utils.iteritems(interp.blocks)) self.interp = interp self.call_conv = context.call_conv # 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 = _dynfunc.Environment( globals=self.fndesc.lookup_module().__dict__) # Setup function self.function = context.declare_function(self.module, fndesc) self.entry_block = self.function.append_basic_block('entry') self.builder = Builder.new(self.entry_block) self.call_helper = self.call_conv.init_call_helper(self.builder) # Internal states self.blkmap = {} self.varmap = {} self.firstblk = min(self.blocks.keys()) self.loc = -1 # Subclass initialization self.init()
def inspect_types(self, file=None, signature=None, **kwargs): """ print or return annotated source with Numba intermediate IR Pass `pretty=True` to attempt color highlighting, and HTML rendering in Jupyter and IPython by returning an Annotate Object. `file` must be None if used in conjunction with `pretty=True`. """ pretty = kwargs.get('pretty', False) style = kwargs.get('style', 'default') 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 .pretty_annotate import Annotate return Annotate(self, signature=signature, style=style)
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): if file is None: file = sys.stdout for ver, res in utils.iteritems(self.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)
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 ver, 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 .pretty_annotate import Annotate return Annotate(self, signature=signature, style=style)
def insert_class(self, cls, attrs): clsty = types.Object(cls) for name, vtype in utils.iteritems(attrs): imp = python_attr_impl(clsty, name, vtype) self.attrs[imp.attr].append(imp)
def run(self): for blkid, blk in utils.iteritems(self.interp.blocks): self.run_block(blk)
def inspect_types(self, file=None): if file is None: file = sys.stdout for ver, defn in utils.iteritems(self.definitions): defn.inspect_types(file=file)