示例#1
0
def form_hls_syntax_error(ctx, e, lineno=1):
    if isinstance(ctx, GearContext):
        func, fn, ln = gear_definition_location(ctx.gear.func)
        msg = (f'{str(e)}\n    - when compiling gear "{ctx.gear.name}" with'
               f' parameters {ctx.gear.params}')
    else:
        func, fn, ln = gear_definition_location(ctx.funcref.func)
        msg = (f'{str(e)}\n    - when compiling function "{ctx.funcref.func}" with'
               f' signature {ctx.signature}')

    err = HLSSyntaxError(msg, ln + lineno - 1, filename=fn)

    traceback = make_traceback((HLSSyntaxError, err, sys.exc_info()[2]))
    _, exc_value, tb = traceback.standard_exc_info

    return exc_value, tb
示例#2
0
    async def run(self):
        args, kwds = self.sim_func_args

        out_prods = [p.producer for p in self.gear.out_ports]
        single_output = len(out_prods) == 1
        if single_output:
            out_prods = out_prods[0]

        sim = reg['sim/simulator']
        err = None

        try:
            if is_async_gen(self.func):
                while (1):
                    if sim.phase != 'forward':
                        await clk()

                    async_gen = self.func(*args, **kwds)

                    async for val in async_gen:
                        if sim.phase != 'forward':
                            await clk()

                        # TODO: Yielding an interface might make sense to
                        # connect internaly instantiated module directly to the
                        # output, think about it
                        if val is not None:
                            if single_output:
                                tb = None
                                try:
                                    out_prods.put_nb(val)
                                except GearDone:
                                    raise
                                except Exception as e:
                                    func, fn, ln = gear_definition_location(self.func)

                                    err = SimulationError(
                                        f"inside '{self.gear.name}': {repr(e)}",
                                        async_gen.ag_frame.f_lineno,
                                        filename=fn)

                                    traceback = make_traceback((SimulationError, err, sys.exc_info()[2]))
                                    exc_type, exc_value, tb = traceback.standard_exc_info

                                if tb is not None:
                                    raise exc_value.with_traceback(tb)

                                await out_prods.ready()
                            else:
                                for p, v in zip(out_prods, val):
                                    if v is not None:
                                        p.put_nb(v)

                                for p, v in zip(out_prods, val):
                                    if v is not None:
                                        await p.ready()

                    if self.parent:
                        raise GearDone

                    if args:
                        if all(a.done for a in args):
                            raise GearDone
            elif inspect.isgeneratorfunction(self.func):
                while (1):
                    if sim.phase != 'forward':
                        await clk()

                    for val in self.func(*args, **kwds):
                        if sim.phase != 'forward':
                            await clk()

                        if val is not None:
                            if single_output:
                                out_prods.put_nb(val)
                                await out_prods.ready()
                            else:
                                for p, v in zip(out_prods, val):
                                    if v is not None:
                                        p.put_nb(v)

                                for p, v in zip(out_prods, val):
                                    if v is not None:
                                        await p.ready()

                    if self.parent:
                        raise GearDone

                    if args:
                        if all(a.done for a in args):
                            raise GearDone
            else:
                while (1):
                    # TODO: handle case where self.func is empty and this loop
                    # will just go on forever freezing everything. It happens
                    # if the user accidently creates empty "async def" function
                    await self.func(*args, **kwds)

                    if args:
                        if all(a.done for a in args):
                            raise GearDone

        except GearDone as e:
            for p in self.gear.in_ports:
                intf = p.consumer
                try:
                    if not intf.empty():
                        prod_intf = intf.in_queue.intf
                        prod_gear = prod_intf.consumers[0].gear
                        schedule_to_finish(prod_gear)
                except GearDone:
                    pass

            if self.parent:
                self.parent.child.remove(self)

            self._finish()
            raise e
        except Exception as e:
            e.args = (f'{str(e)}, in the module "{self.gear.name}"', )
            err = e

        if err:
            raise err