def test_indexOps(self): c, interf = IndexOps() _, arch = list(c.synthesize("indexOps", interf, DummyPlatform())) s = VhdlSerializer.Architecture(arch, VhdlSerializer.getBaseContext()) self.assertNotIn("sig_", s)
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)
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()) ])
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()) ])
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())
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))
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
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)))
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"
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
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)
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)
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
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)
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)))
def __repr__(self): from hwt.serializer.vhdl.serializer import VhdlSerializer, onlyPrintDefaultValues return VhdlSerializer.Assignment(self, onlyPrintDefaultValues)
def assertStrEq(self, first, second, msg=None): ctx = VhdlSerializer.getBaseContext() first = VhdlSerializer.asHdl(first, ctx).replace(" ", "") unittest.TestCase.assertEqual(self, first, second, msg=msg)
def __repr__(self): from hwt.serializer.vhdl.serializer import VhdlSerializer return VhdlSerializer.MapExpr(self)
# 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 # );
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)
def __repr__(self): from hwt.serializer.vhdl.serializer import VhdlSerializer return VhdlSerializer.Entity(self, VhdlSerializer.getBaseNameScope())
def __repr__(self): from hwt.serializer.vhdl.serializer import VhdlSerializer, onlyPrintDefaultValues return VhdlSerializer.SwitchContainer(self, onlyPrintDefaultValues)
def __repr__(self): from hwt.serializer.vhdl.serializer import VhdlSerializer return VhdlSerializer.formater( VhdlSerializer.HWProcess(self, VhdlSerializer.getBaseNameScope()))
def __repr__(self): from hwt.serializer.vhdl.serializer import VhdlSerializer return VhdlSerializer.formater( VhdlSerializer.Architecture(self, VhdlSerializer.getBaseNameScope()))
def __repr__(self): from hwt.serializer.vhdl.serializer import VhdlSerializer, onlyPrintDefaultValues return VhdlSerializer.SignalItem(self, onlyPrintDefaultValues)