Esempio n. 1
0
    def test_indexOps(self):
        c, interf = IndexOps()
        _, arch = list(c.synthesize("indexOps", interf, DummyPlatform()))

        s = VhdlSerializer.Architecture(arch, VhdlSerializer.getBaseContext())

        self.assertNotIn("sig_", s)
Esempio n. 2
0
    def strStructureCmp(self, cont, tmpl):
        if not isinstance(cont, str):
            cont = VhdlSerializer.asHdl(cont, VhdlSerializer.getBaseContext())
        _tmpl = rmWhitespaces.sub(" ", tmpl).strip()
        _cont = rmWhitespaces.sub(" ", cont).strip()

        self.assertEqual(_tmpl, _cont)
Esempio n. 3
0
    def strStructureCmp(self, cont, tmpl):
        if not isinstance(cont, str):
            cont = VhdlSerializer.asHdl(cont, VhdlSerializer.getBaseContext())
        _tmpl = rmWhitespaces.sub(" ", tmpl).strip()
        _cont = rmWhitespaces.sub(" ", cont).strip()

        self.assertEqual(_tmpl, _cont)
Esempio n. 4
0
def netlistToVhdlStr(name, netlist, interfaces):
    for s in interfaces:
        s._interface = True

    ctx = VhdlSerializer.getBaseContext()
    return "\n".join([VhdlSerializer.asHdl(o, ctx)
                      for o in netlist.synthesize(name, interfaces, DummyPlatform())
                      ])
Esempio n. 5
0
def netlistToVhdlStr(name, netlist, interfaces):
    for s in interfaces:
        s._interface = True

    ctx = VhdlSerializer.getBaseContext()
    return "\n".join([
        VhdlSerializer.asHdl(o, ctx)
        for o in netlist.synthesize(name, interfaces, DummyPlatform())
    ])
Esempio n. 6
0
    def serializeType(self, hdlType: HdlType) -> str:
        """
        :see: doc of method on parent class
        """

        def createTmpVar(suggestedName, dtype):
            raise NotImplementedError(
                "Can not seraialize hdl type %r into"
                "ipcore format" % (hdlType))

        return VhdlSerializer.HdlType(hdlType, VhdlSerializer.getBaseContext())
Esempio n. 7
0
    def quartus_add_interface_port(self, buff: List[str], intfName: str,
                                   signal, logicName: str):
        """
        Add subinterface to Quartus interface

        :param buff: line buffer for output
        :param intfName: name of top interface
        :param signal: subinterface to create port for
        :param logicName: name of port in Quartus
        """
        d = signal._direction
        if d == INTF_DIRECTION.MASTER:
            dir_ = "Output"
        elif d == INTF_DIRECTION.SLAVE:
            dir_ = "Input"
        else:
            raise ValueError(d)

        width = signal._dtype.width
        if isinstance(width, int):
            width = str(width)
        else:
            ctx = VhdlSerializer.getBaseContext()

            def createTmpVar(suggestedName, dtype):
                raise NotImplementedError(
                    "Width value can not be converted do ipcore format (%r)",
                    width)

            ctx.createTmpVarFn = createTmpVar
            width = VivadoTclExpressionSerializer.asHdl(
                width.staticEval(), ctx)

        buff.append("add_interface_port %s %s %s %s %s" %
                    (intfName, signal._sigInside.name, logicName, dir_, width))
Esempio n. 8
0
    def _entPort2CompPort(e, p):
        port = Port()
        port.name = p.name
        port.direction = p.direction.name.lower()
        port.type = WireTypeDef()
        t = port.type
        dt = p._dtype

        def createTmpVar(suggestedName, dtype):
            pass

        t.typeName = VhdlSerializer.HdlType(dt, createTmpVar)
        try:
            t.typeName = t.typeName[:t.typeName.index('(')]
        except ValueError:
            pass

        if dt == BIT:
            port.vector = False
        elif isinstance(dt, Bits):
            port.vector = dt.constrain.staticEval().val
        t.viewNameRefs = [
            "xilinx_vhdlsynthesis", "xilinx_vhdlbehavioralsimulation"
        ]
        return port
Esempio n. 9
0
    def dump(self, dumpFile=sys.stdout):
        for proc in self.tbArch.processes:
            proc.statements.append(WaitStm(None))

        hasToBeOpened = isinstance(dumpFile, str)
        if hasToBeOpened:
            _dumpFile = open(dumpFile, 'w')
        else:
            _dumpFile = dumpFile

        sc = VhdlSerializer.getBaseNameScope()
        _dumpFile.write(
            VhdlSerializer.formater(VhdlSerializer.Entity(self.tbEnt, sc)))
        _dumpFile.write(
            VhdlSerializer.formater(
                VhdlSerializer.Architecture(self.tbArch, sc)))
Esempio n. 10
0
    def addWidthParam(self, thisIntf, name, value):
        ctx = VhdlSerializer.getBaseContext()

        def createTmpVar(suggestedName, dtype):
            raise NotImplementedError(
                "Value of generic %s can not be converted do ipcore format (%r)",
                name, value)

        ctx.createTmpVarFn = createTmpVar

        v = VivadoTclExpressionSerializer.asHdl(value.staticEval(), ctx)
        p = self.addSimpleParam(thisIntf, "ADDR_WIDTH", v)
        if isinstance(value, RtlSignalBase):
            p.value.resolve = "user"
Esempio n. 11
0
File: port.py Progetto: Ben-401/hwt
    def _entPort2CompPort(e, p):
        port = Port()
        port.name = p.name
        port.direction = p.direction.name.lower()
        port.type = WireTypeDef()
        t = port.type
        dt = p._dtype

        t.typeName = VhdlSerializer.HdlType(dt,
                                            VhdlSerializer.getBaseContext())
        try:
            t.typeName = t.typeName[:t.typeName.index('(')]
        except ValueError:
            pass

        if dt == BIT:
            port.vector = False
        elif isinstance(dt, Bits):
            port.vector = [evalParam(dt.width) - 1, hInt(0)]
        t.viewNameRefs = [
            "xilinx_vhdlsynthesis", "xilinx_vhdlbehavioralsimulation"
        ]
        return port
Esempio n. 12
0
    def __repr__(self):
        from hwt.serializer.vhdl.serializer import VhdlSerializer, onlyPrintDefaultValues
        c = self.constrain
        if isinstance(c, int):
            constr = "width:%d" % c
        elif isinstance(c, Unconstrained):
            try:
                constr = "derivedWidth:%d" % (c.derivedWidth)
            except AttributeError:
                constr = ""
        else:
            constr = VhdlSerializer.asHdl(self.constrain, onlyPrintDefaultValues) +\
                     (", %dbits" % self.bit_length())

        return "<HdlType %s, %s>" % (self.__class__.__name__, constr)
Esempio n. 13
0
File: bits.py Progetto: mgielda/hwt
    def __repr__(self, indent=0, withAddr=None, expandStructs=False):
        """
        :param indent: number of indentation
        :param withAddr: if is not None is used as a additional
            information about on which address this type is stored
            (used only by HStruct)
        :param expandStructs: expand HStructTypes (used by HStruct and HArray)
        """
        c = self.width
        if isinstance(c, int):
            constr = "%dbits" % c
        else:
            from hwt.serializer.vhdl.serializer import VhdlSerializer
            ctx = VhdlSerializer.getBaseContext()
            constr = VhdlSerializer.asHdl(self.width, ctx)
            constr = "%s, %dbits" % (constr, self.bit_length())

        if self.signed:
            constr += ", signed"
        elif self.signed is False:
            constr += ", unsigned"

        return "%s<%s, %s>" % (getIndent(indent), self.__class__.__name__,
                               constr)
Esempio n. 14
0
    def getExprVal(self, val, do_eval=False):
        """
        :see: doc of method on parent class
        """
        ctx = VhdlSerializer.getBaseContext()

        def createTmpVar(suggestedName, dtype):
            raise NotImplementedError(
                "Width value can not be converted do ipcore format (%r)",
                val)

        ctx.createTmpVarFn = createTmpVar
        if do_eval:
            val = val.staticEval()
        val = VivadoTclExpressionSerializer.asHdl(val, ctx)
        return val
Esempio n. 15
0
    def change(self, time, sig, newVal):
        self.setTime(time)
        varInfo = self.vars[sig]
        if isinstance(sig._dtype, Enum):
            if newVal.vldMask:
                val = newVal.val
            else:
                val = "XXXX"
            frmt = "s%s %s"
        else:
            val = VhdlSerializer.BitString_binary(newVal.val, varInfo.width,
                                                  newVal.vldMask)
            val = val.replace('"', "")

            if varInfo._dtype == BIT:
                frmt = "%s%s"
            else:
                frmt = "b%s %s"

        return frmt % (val, varInfo.id)
Esempio n. 16
0
    def dump(self, dumpFile=sys.stdout):
        for proc in self.tbArch.processes:
            proc.statements.append(WaitStm(None))

        hasToBeOpened = isinstance(dumpFile, str)
        if hasToBeOpened:
            _dumpFile = open(dumpFile, 'w')
        else:
            _dumpFile = dumpFile

        ctx = VhdlSerializer.getBaseContext()
        ctx.scope.setLevel(2)
        VhdlSerializer.Entity_prepare(self.tbArch.components[0], ctx)
        ctx.scope.setLevel(1)

        _dumpFile.write(VhdlSerializer.formatter(
            VhdlSerializer.Entity(self.tbEnt, ctx)))
        _dumpFile.write(VhdlSerializer.formatter(
            VhdlSerializer.Architecture(self.tbArch, ctx)))
Esempio n. 17
0
 def __repr__(self):
     from hwt.serializer.vhdl.serializer import VhdlSerializer, onlyPrintDefaultValues
     return VhdlSerializer.Assignment(self, onlyPrintDefaultValues)
Esempio n. 18
0
 def assertStrEq(self, first, second, msg=None):
     ctx = VhdlSerializer.getBaseContext()
     first = VhdlSerializer.asHdl(first, ctx).replace(" ", "")
     unittest.TestCase.assertEqual(self, first, second, msg=msg)
Esempio n. 19
0
 def __repr__(self):
     from hwt.serializer.vhdl.serializer import VhdlSerializer
     return VhdlSerializer.MapExpr(self)
Esempio n. 20
0
        # are destinations.
        self.b(self.a)  # a drives b, "()" because "=" can not be overriden
        # directions of a and b interfaces are derived automatically,
        # if signal has driver it is output


if __name__ == "__main__":  # alias python main function
    # toRtl can be imported anywhere but we prefer to import it only
    # when this script is running as main
    from hwt.synthesizer.utils import toRtl
    # there are other serializers ...
    from hwt.serializer.vhdl.serializer import VhdlSerializer
    # we create instance of our unit
    u = SimpleUnit()
    # there is more of synthesis methods. toRtl() returns formated hdl string
    print(toRtl(u, serializer=VhdlSerializer()))

# expected Output (without # ofcourse)
# --   In order to create a new unit you have to make new class derived from Unit.
# --
# --   You can use sphinx-hwt plugin for sphinx document generator
# --   to generate interactive schematic and documentation.
# --   Schematic is generated by directive bellow.
# library IEEE;
# use IEEE.std_logic_1164.all;
# use IEEE.numeric_std.all;
#
# ENTITY SimpleUnit IS
#     PORT (a : IN STD_LOGIC;
#         b : OUT STD_LOGIC
#     );
Esempio n. 21
0
 def SignalItem(si, declaration=False):
     assert (declaration == False)
     if si.hidden:
         return VhdlSerializer.asHdl(si.origin)
     else:
         return "spirit:decode(id('MODELPARAM_VALUE.%s'))" % (si.name)
Esempio n. 22
0
 def __repr__(self):
     from hwt.serializer.vhdl.serializer import VhdlSerializer
     return VhdlSerializer.Entity(self, VhdlSerializer.getBaseNameScope())
Esempio n. 23
0
 def __repr__(self):
     from hwt.serializer.vhdl.serializer import VhdlSerializer, onlyPrintDefaultValues
     return VhdlSerializer.SwitchContainer(self, onlyPrintDefaultValues)
Esempio n. 24
0
 def __repr__(self):
     from hwt.serializer.vhdl.serializer import VhdlSerializer
     return VhdlSerializer.formater(
         VhdlSerializer.HWProcess(self, VhdlSerializer.getBaseNameScope()))
Esempio n. 25
0
 def assertStrEq(self, first, second, msg=None):
     ctx = VhdlSerializer.getBaseContext()
     first = VhdlSerializer.asHdl(first, ctx).replace(" ", "")
     unittest.TestCase.assertEqual(self, first, second, msg=msg)
Esempio n. 26
0
 def __repr__(self):
     from hwt.serializer.vhdl.serializer import VhdlSerializer
     return VhdlSerializer.formater(
         VhdlSerializer.Architecture(self,
                                     VhdlSerializer.getBaseNameScope()))
Esempio n. 27
0
 def __repr__(self):
     from hwt.serializer.vhdl.serializer import VhdlSerializer, onlyPrintDefaultValues
     return VhdlSerializer.SignalItem(self, onlyPrintDefaultValues)