mirror of
https://github.com/myhdl/myhdl.git
synced 2025-01-24 21:52:56 +08:00
error handling
This commit is contained in:
parent
a392318dc1
commit
ba75740cf5
@ -28,13 +28,10 @@ import os
|
||||
import exceptions
|
||||
|
||||
from myhdl._intbv import intbv
|
||||
from myhdl import _simulator
|
||||
from myhdl._Error import Error
|
||||
from myhdl import _simulator, CosimulationError
|
||||
|
||||
_MAXLINE = 4096
|
||||
|
||||
class CosimulationError(Error):
|
||||
pass
|
||||
class _error:
|
||||
pass
|
||||
_error.MultipleCosim = "Only a single cosimulator allowed"
|
||||
|
@ -1,52 +0,0 @@
|
||||
# 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
|
||||
|
||||
""" myhdl Error object.
|
||||
|
||||
This module provides the following myhdl objects:
|
||||
Error -- myhdl Error exception
|
||||
|
||||
"""
|
||||
|
||||
__author__ = "Jan Decaluwe <jan@jandecaluwe.com>"
|
||||
__revision__ = "$Revision$"
|
||||
__date__ = "$Date$"
|
||||
|
||||
|
||||
|
||||
class Error(Exception):
|
||||
def __init__(self, arg=""):
|
||||
self.arg = arg
|
||||
def __str__(self):
|
||||
if self.__doc__ and self.arg:
|
||||
msg = self.__doc__ + ": " + str(self.arg)
|
||||
else:
|
||||
msg = self.__doc__ or self.arg
|
||||
return msg
|
||||
|
||||
class Error(Exception):
|
||||
def __init__(self, kind, msg="", info=""):
|
||||
self.kind = kind
|
||||
self.msg = msg
|
||||
self.info = info
|
||||
def __str__(self):
|
||||
s = "%s%s" % (self.info, self.kind)
|
||||
if self.msg:
|
||||
s += ": %s" % self.msg
|
||||
return s
|
@ -28,22 +28,22 @@ import sys
|
||||
import os
|
||||
from warnings import warn
|
||||
from types import GeneratorType
|
||||
from sets import Set
|
||||
|
||||
from myhdl import delay, Signal, Cosimulation, join
|
||||
from myhdl import _simulator
|
||||
from myhdl import delay, Signal, Cosimulation, join, StopSimulation, SuspendSimulation
|
||||
from myhdl import _simulator, SimulationError
|
||||
from myhdl._simulator import _siglist, _futureEvents
|
||||
from myhdl._Waiter import _Waiter, _WaiterList
|
||||
from myhdl._util import StopSimulation, SuspendSimulation, _flatten, _printExcInfo
|
||||
from myhdl._Error import Error
|
||||
from myhdl._util import _flatten, _printExcInfo
|
||||
|
||||
|
||||
schedule = _futureEvents.append
|
||||
|
||||
class MultipleCosimError(Error):
|
||||
"""Only a single cosimulator argument allowed"""
|
||||
class ArgTypeError(Error):
|
||||
"""Inappriopriate argument type"""
|
||||
|
||||
class _error:
|
||||
pass
|
||||
_error.ArgType = "Inappriopriate argument type"
|
||||
_error.MultipleCosim = "Only a single cosimulator argument allowed"
|
||||
_error.DuplicatedArg = "Duplicated argument"
|
||||
|
||||
class Simulation(object):
|
||||
|
||||
@ -203,16 +203,20 @@ class Simulation(object):
|
||||
|
||||
def _checkArgs(arglist):
|
||||
waiters = []
|
||||
ids = Set()
|
||||
cosim = None
|
||||
for arg in arglist:
|
||||
if type(arg) is GeneratorType:
|
||||
waiters.append(_Waiter(arg))
|
||||
elif type(arg) is Cosimulation:
|
||||
if cosim is not None:
|
||||
raise MultipleCosimError
|
||||
raise SimulationError(_error.MultipleCosim)
|
||||
cosim = arg
|
||||
waiters.append(_Waiter(cosim._waiter()))
|
||||
else:
|
||||
raise ArgTypeError(str(type(arg)))
|
||||
raise SimulationError(_error.ArgType, str(type(arg)))
|
||||
if id(arg) in ids:
|
||||
raise SimulationError(_error.DuplicatedArg)
|
||||
ids.add(id(arg))
|
||||
return waiters, cosim
|
||||
|
||||
|
@ -23,7 +23,6 @@ __author__ = "Jan Decaluwe <jan@jandecaluwe.com>"
|
||||
__revision__ = "$Revision$"
|
||||
__date__ = "$Date$"
|
||||
|
||||
from __future__ import generators
|
||||
|
||||
from myhdl._join import join
|
||||
from myhdl._simulator import _siglist, _futureEvents
|
||||
|
@ -49,6 +49,15 @@ __date__ = "$Date$"
|
||||
|
||||
__version__ = "0.3"
|
||||
|
||||
|
||||
class StopSimulation(Exception):
|
||||
""" Basic exception to stop a Simulation """
|
||||
pass
|
||||
|
||||
class SuspendSimulation(Exception):
|
||||
""" Basic exception to suspend a Simulation """
|
||||
pass
|
||||
|
||||
class Error(Exception):
|
||||
def __init__(self, kind, msg="", info=""):
|
||||
self.kind = kind
|
||||
@ -62,9 +71,16 @@ class Error(Exception):
|
||||
|
||||
class AlwaysCombError(Error):
|
||||
pass
|
||||
|
||||
class CosimulationError(Error):
|
||||
pass
|
||||
class ExtractHierarchyError(Error):
|
||||
pass
|
||||
class SimulationError(Error):
|
||||
pass
|
||||
class ToVerilogError(Error):
|
||||
pass
|
||||
class TraceSignalsError(Error):
|
||||
pass
|
||||
|
||||
from _bin import bin
|
||||
from _concat import concat
|
||||
@ -73,7 +89,7 @@ from _join import join
|
||||
from _Signal import posedge, negedge, Signal
|
||||
from _simulator import now
|
||||
from _delay import delay
|
||||
from _util import downrange, StopSimulation
|
||||
from _util import downrange
|
||||
from _Cosimulation import Cosimulation
|
||||
from _Simulation import Simulation
|
||||
from _misc import instances, processes
|
||||
|
@ -35,15 +35,12 @@ from compiler import ast
|
||||
import linecache
|
||||
from sets import Set
|
||||
|
||||
from myhdl import Signal
|
||||
from myhdl import Signal, ExtractHierarchyError
|
||||
from myhdl._util import _isGenSeq, _isGenFunc
|
||||
from myhdl._Error import Error
|
||||
|
||||
|
||||
_profileFunc = None
|
||||
|
||||
class ExtractHierarchyError(Error):
|
||||
pass
|
||||
class _error:
|
||||
pass
|
||||
_error.NoInstances = "No instances found"
|
||||
|
@ -23,7 +23,6 @@ __author__ = "Jan Decaluwe <jan@jandecaluwe.com>"
|
||||
__revision__ = "$Revision$"
|
||||
__date__ = "$Date$"
|
||||
|
||||
from __future__ import generators
|
||||
|
||||
class join(object):
|
||||
|
||||
|
@ -35,13 +35,11 @@ from sets import Set
|
||||
from myhdl import _simulator, Signal, __version__
|
||||
from myhdl._util import _isGenSeq, _isGenFunc
|
||||
from myhdl._extractHierarchy import _findInstanceName, _HierExtr
|
||||
from myhdl._Error import Error
|
||||
from myhdl import TraceSignalsError
|
||||
|
||||
_tracing = 0
|
||||
_profileFunc = None
|
||||
|
||||
class TraceSignalsError(Error):
|
||||
pass
|
||||
class _error:
|
||||
pass
|
||||
_error.TopLevelName = "result of traceSignals call should be assigned to a top level name"
|
||||
|
@ -29,8 +29,9 @@ import random
|
||||
from random import randrange
|
||||
random.seed(1) # random, but deterministic
|
||||
|
||||
from myhdl import Simulation, now, delay, StopSimulation, join
|
||||
from myhdl import Simulation, SimulationError, now, delay, StopSimulation, join
|
||||
from myhdl import Signal, posedge, negedge, intbv
|
||||
from myhdl._Simulation import _error
|
||||
|
||||
from myhdl._simulator import _siglist
|
||||
|
||||
@ -39,6 +40,28 @@ QUIET=1
|
||||
class Shared:
|
||||
pass
|
||||
|
||||
class SimArgs(TestCase):
|
||||
""" Simulation arguments """
|
||||
def test1(self):
|
||||
try:
|
||||
Simulation(None)
|
||||
except SimulationError, e:
|
||||
self.assertEqual(e.kind, _error.ArgType)
|
||||
except:
|
||||
self.fail()
|
||||
|
||||
def test2(self):
|
||||
def g():
|
||||
yield delay(10)
|
||||
i = g()
|
||||
try:
|
||||
Simulation(i, i)
|
||||
except SimulationError, e:
|
||||
self.assertEqual(e.kind, _error.DuplicatedArg)
|
||||
except:
|
||||
self.fail()
|
||||
|
||||
|
||||
class YieldNone(TestCase):
|
||||
""" Basic test of yield None behavior """
|
||||
|
||||
|
@ -117,7 +117,8 @@ class TestTraceSigs(TestCase):
|
||||
self.fail()
|
||||
|
||||
def testReturnVal(self):
|
||||
from myhdl._extractHierarchy import ExtractHierarchyError, _error
|
||||
from myhdl import ExtractHierarchyError
|
||||
from myhdl._extractHierarchy import _error
|
||||
try:
|
||||
dut = traceSignals(dummy)
|
||||
except ExtractHierarchyError, e:
|
||||
|
Loading…
x
Reference in New Issue
Block a user