1
0
mirror of https://github.com/myhdl/myhdl.git synced 2025-01-24 21:52:56 +08:00

error handling

This commit is contained in:
jand 2003-11-18 16:38:22 +00:00
parent a392318dc1
commit ba75740cf5
10 changed files with 62 additions and 80 deletions

View File

@ -28,13 +28,10 @@ import os
import exceptions import exceptions
from myhdl._intbv import intbv from myhdl._intbv import intbv
from myhdl import _simulator from myhdl import _simulator, CosimulationError
from myhdl._Error import Error
_MAXLINE = 4096 _MAXLINE = 4096
class CosimulationError(Error):
pass
class _error: class _error:
pass pass
_error.MultipleCosim = "Only a single cosimulator allowed" _error.MultipleCosim = "Only a single cosimulator allowed"

View File

@ -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

View File

@ -28,22 +28,22 @@ import sys
import os import os
from warnings import warn from warnings import warn
from types import GeneratorType from types import GeneratorType
from sets import Set
from myhdl import delay, Signal, Cosimulation, join from myhdl import delay, Signal, Cosimulation, join, StopSimulation, SuspendSimulation
from myhdl import _simulator from myhdl import _simulator, SimulationError
from myhdl._simulator import _siglist, _futureEvents from myhdl._simulator import _siglist, _futureEvents
from myhdl._Waiter import _Waiter, _WaiterList from myhdl._Waiter import _Waiter, _WaiterList
from myhdl._util import StopSimulation, SuspendSimulation, _flatten, _printExcInfo from myhdl._util import _flatten, _printExcInfo
from myhdl._Error import Error
schedule = _futureEvents.append schedule = _futureEvents.append
class MultipleCosimError(Error): class _error:
"""Only a single cosimulator argument allowed""" pass
class ArgTypeError(Error): _error.ArgType = "Inappriopriate argument type"
"""Inappriopriate argument type""" _error.MultipleCosim = "Only a single cosimulator argument allowed"
_error.DuplicatedArg = "Duplicated argument"
class Simulation(object): class Simulation(object):
@ -203,16 +203,20 @@ class Simulation(object):
def _checkArgs(arglist): def _checkArgs(arglist):
waiters = [] waiters = []
ids = Set()
cosim = None cosim = None
for arg in arglist: for arg in arglist:
if type(arg) is GeneratorType: if type(arg) is GeneratorType:
waiters.append(_Waiter(arg)) waiters.append(_Waiter(arg))
elif type(arg) is Cosimulation: elif type(arg) is Cosimulation:
if cosim is not None: if cosim is not None:
raise MultipleCosimError raise SimulationError(_error.MultipleCosim)
cosim = arg cosim = arg
waiters.append(_Waiter(cosim._waiter())) waiters.append(_Waiter(cosim._waiter()))
else: 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 return waiters, cosim

View File

@ -23,7 +23,6 @@ __author__ = "Jan Decaluwe <jan@jandecaluwe.com>"
__revision__ = "$Revision$" __revision__ = "$Revision$"
__date__ = "$Date$" __date__ = "$Date$"
from __future__ import generators
from myhdl._join import join from myhdl._join import join
from myhdl._simulator import _siglist, _futureEvents from myhdl._simulator import _siglist, _futureEvents

View File

@ -49,6 +49,15 @@ __date__ = "$Date$"
__version__ = "0.3" __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): class Error(Exception):
def __init__(self, kind, msg="", info=""): def __init__(self, kind, msg="", info=""):
self.kind = kind self.kind = kind
@ -62,9 +71,16 @@ class Error(Exception):
class AlwaysCombError(Error): class AlwaysCombError(Error):
pass pass
class CosimulationError(Error):
pass
class ExtractHierarchyError(Error):
pass
class SimulationError(Error):
pass
class ToVerilogError(Error): class ToVerilogError(Error):
pass pass
class TraceSignalsError(Error):
pass
from _bin import bin from _bin import bin
from _concat import concat from _concat import concat
@ -73,7 +89,7 @@ from _join import join
from _Signal import posedge, negedge, Signal from _Signal import posedge, negedge, Signal
from _simulator import now from _simulator import now
from _delay import delay from _delay import delay
from _util import downrange, StopSimulation from _util import downrange
from _Cosimulation import Cosimulation from _Cosimulation import Cosimulation
from _Simulation import Simulation from _Simulation import Simulation
from _misc import instances, processes from _misc import instances, processes

View File

@ -35,15 +35,12 @@ from compiler import ast
import linecache import linecache
from sets import Set from sets import Set
from myhdl import Signal from myhdl import Signal, ExtractHierarchyError
from myhdl._util import _isGenSeq, _isGenFunc from myhdl._util import _isGenSeq, _isGenFunc
from myhdl._Error import Error
_profileFunc = None _profileFunc = None
class ExtractHierarchyError(Error):
pass
class _error: class _error:
pass pass
_error.NoInstances = "No instances found" _error.NoInstances = "No instances found"

View File

@ -23,7 +23,6 @@ __author__ = "Jan Decaluwe <jan@jandecaluwe.com>"
__revision__ = "$Revision$" __revision__ = "$Revision$"
__date__ = "$Date$" __date__ = "$Date$"
from __future__ import generators
class join(object): class join(object):

View File

@ -35,13 +35,11 @@ from sets import Set
from myhdl import _simulator, Signal, __version__ from myhdl import _simulator, Signal, __version__
from myhdl._util import _isGenSeq, _isGenFunc from myhdl._util import _isGenSeq, _isGenFunc
from myhdl._extractHierarchy import _findInstanceName, _HierExtr from myhdl._extractHierarchy import _findInstanceName, _HierExtr
from myhdl._Error import Error from myhdl import TraceSignalsError
_tracing = 0 _tracing = 0
_profileFunc = None _profileFunc = None
class TraceSignalsError(Error):
pass
class _error: class _error:
pass pass
_error.TopLevelName = "result of traceSignals call should be assigned to a top level name" _error.TopLevelName = "result of traceSignals call should be assigned to a top level name"

View File

@ -29,8 +29,9 @@ import random
from random import randrange from random import randrange
random.seed(1) # random, but deterministic 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 import Signal, posedge, negedge, intbv
from myhdl._Simulation import _error
from myhdl._simulator import _siglist from myhdl._simulator import _siglist
@ -39,6 +40,28 @@ QUIET=1
class Shared: class Shared:
pass 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): class YieldNone(TestCase):
""" Basic test of yield None behavior """ """ Basic test of yield None behavior """

View File

@ -117,7 +117,8 @@ class TestTraceSigs(TestCase):
self.fail() self.fail()
def testReturnVal(self): def testReturnVal(self):
from myhdl._extractHierarchy import ExtractHierarchyError, _error from myhdl import ExtractHierarchyError
from myhdl._extractHierarchy import _error
try: try:
dut = traceSignals(dummy) dut = traceSignals(dummy)
except ExtractHierarchyError, e: except ExtractHierarchyError, e: