1
0
mirror of https://github.com/myhdl/myhdl.git synced 2024-12-14 07:44:38 +08:00

refactored bin

This commit is contained in:
jand 2003-06-24 20:22:37 +00:00
parent 46fa578ad0
commit 2824f3b2b9
5 changed files with 61 additions and 2 deletions

View File

@ -36,6 +36,7 @@ from copy import deepcopy as copy
import _simulator
from _simulator import _siglist, _futureEvents, now
from myhdl import intbv
from bin import bin
_schedule = _futureEvents.append
@ -66,7 +67,7 @@ class Signal(object):
__slots__ = ('_next', '_val', '_type',
'_eventWaiters', '_posedgeWaiters', '_negedgeWaiters',
'_codeName',
'_codeName', '_tracing',
)
def __new__(cls, val, delay=0):
@ -91,6 +92,7 @@ class Signal(object):
self._posedgeWaiters = _WaiterList()
self._negedgeWaiters = _WaiterList()
self._codeName = ""
self._tracing = 0
def _update(self):
if self._val != self._next:
@ -103,6 +105,8 @@ class Signal(object):
waiters.extend(self._negedgeWaiters[:])
del self._negedgeWaiters[:]
self._val = self._next
if self._tracing:
print >> _simulator.tracefile, "b%s" % bin(self._val, 8)
return waiters
else:
return []

View File

@ -53,7 +53,8 @@ from Signal import posedge, negedge, Signal
from _simulator import now
from delay import delay
from Cosimulation import Cosimulation
from util import downrange, bin, Error, StopSimulation
from util import downrange, Error, StopSimulation
from bin import bin
from misc import instances, processes
from always_comb import always_comb
from trace_sigs import trace_sigs

View File

@ -32,6 +32,8 @@ _siglist = []
_futureEvents = []
_time = 0
_cosim = 0
_tracing = 0
_tracefile = None
def now():
""" Return the current simulation time """

49
myhdl/bin.py Normal file
View File

@ -0,0 +1,49 @@
# This file is part of the myhdl library, a Python package for using
# Python as a Hardware Description Language.
#
# Copyright (C) 2003 Jan Decaluwe
#
# The myhdl library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of the
# License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
""" module with the bin function.
"""
__author__ = "Jan Decaluwe <jan@jandecaluwe.com>"
__revision__ = "$Revision$"
__date__ = "$Date$"
def _int2bitstring(num):
if num == 0:
return '0'
if abs(num) == 1:
return '1'
return _int2bitstring(num // 2) + _int2bitstring(num % 2)
def bin(num, width=0):
"""Return a binary string representation.
num -- number to convert
Optional parameter:
width -- specifies the desired string (sign bit padding)
"""
num = long(num)
s = _int2bitstring(num)
pad = '0'
if num < 0:
pad = '1'
return (width - len(s)) * pad + s

View File

@ -36,6 +36,7 @@ import time
from util import _isGenSeq
from myhdl import Signal, __version__
import _simulator
_tracing = 0
@ -63,6 +64,8 @@ def trace_sigs(dut, *args, **kwargs):
_writeVcdHeader(vcdfile)
_writeVcdSigs(vcdfile, h.instances)
_tracing = 0
_simulator._tracing = 1
_simulator._tracefile = vcdfile
return h.m