params.py (6214:1ec0ec8933ae) params.py (6654:4c84e771cca7)
1# Copyright (c) 2004-2006 The Regents of The University of Michigan
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are
6# met: redistributions of source code must retain the above copyright
7# notice, this list of conditions and the following disclaimer;
8# redistributions in binary form must reproduce the above copyright

--- 36 unchanged lines hidden (view full) ---

45#####################################################################
46
47import copy
48import datetime
49import re
50import sys
51import time
52
1# Copyright (c) 2004-2006 The Regents of The University of Michigan
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are
6# met: redistributions of source code must retain the above copyright
7# notice, this list of conditions and the following disclaimer;
8# redistributions in binary form must reproduce the above copyright

--- 36 unchanged lines hidden (view full) ---

45#####################################################################
46
47import copy
48import datetime
49import re
50import sys
51import time
52
53import convert
54import proxy
55import ticks
56from util import *
57
53import proxy
54import ticks
55from util import *
56
58import SimObject
59
60def isSimObject(*args, **kwargs):
61 return SimObject.isSimObject(*args, **kwargs)
62
63def isSimObjectSequence(*args, **kwargs):
64 return SimObject.isSimObjectSequence(*args, **kwargs)
65
66def isSimObjectClass(*args, **kwargs):
67 return SimObject.isSimObjectClass(*args, **kwargs)

--- 638 unchanged lines hidden (view full) ---

706 else:
707 raise TypeError, "Enum-derived class must define "\
708 "attribute 'map' or 'vals'"
709
710 cls.cxx_type = 'Enums::%s' % name
711
712 super(MetaEnum, cls).__init__(name, bases, init_dict)
713
57def isSimObject(*args, **kwargs):
58 return SimObject.isSimObject(*args, **kwargs)
59
60def isSimObjectSequence(*args, **kwargs):
61 return SimObject.isSimObjectSequence(*args, **kwargs)
62
63def isSimObjectClass(*args, **kwargs):
64 return SimObject.isSimObjectClass(*args, **kwargs)

--- 638 unchanged lines hidden (view full) ---

703 else:
704 raise TypeError, "Enum-derived class must define "\
705 "attribute 'map' or 'vals'"
706
707 cls.cxx_type = 'Enums::%s' % name
708
709 super(MetaEnum, cls).__init__(name, bases, init_dict)
710
714 def __str__(cls):
715 return cls.__name__
716
717 # Generate C++ class declaration for this enum type.
718 # Note that we wrap the enum in a class/struct to act as a namespace,
719 # so that the enum strings can be brief w/o worrying about collisions.
720 def cxx_decl(cls):
711 # Generate C++ class declaration for this enum type.
712 # Note that we wrap the enum in a class/struct to act as a namespace,
713 # so that the enum strings can be brief w/o worrying about collisions.
714 def cxx_decl(cls):
721 code = "#ifndef __ENUM__%s\n" % cls
722 code += '#define __ENUM__%s\n' % cls
715 name = cls.__name__
716 code = "#ifndef __ENUM__%s\n" % name
717 code += '#define __ENUM__%s\n' % name
723 code += '\n'
724 code += 'namespace Enums {\n'
718 code += '\n'
719 code += 'namespace Enums {\n'
725 code += ' enum %s {\n' % cls
720 code += ' enum %s {\n' % name
726 for val in cls.vals:
727 code += ' %s = %d,\n' % (val, cls.map[val])
721 for val in cls.vals:
722 code += ' %s = %d,\n' % (val, cls.map[val])
728 code += ' Num_%s = %d,\n' % (cls, len(cls.vals))
723 code += ' Num_%s = %d,\n' % (name, len(cls.vals))
729 code += ' };\n'
724 code += ' };\n'
730 code += ' extern const char *%sStrings[Num_%s];\n' % (cls, cls)
725 code += ' extern const char *%sStrings[Num_%s];\n' % (name, name)
731 code += '}\n'
732 code += '\n'
733 code += '#endif\n'
734 return code
735
736 def cxx_def(cls):
726 code += '}\n'
727 code += '\n'
728 code += '#endif\n'
729 return code
730
731 def cxx_def(cls):
737 code = '#include "enums/%s.hh"\n' % cls
732 name = cls.__name__
733 code = '#include "enums/%s.hh"\n' % name
738 code += 'namespace Enums {\n'
734 code += 'namespace Enums {\n'
739 code += ' const char *%sStrings[Num_%s] =\n' % (cls, cls)
735 code += ' const char *%sStrings[Num_%s] =\n' % (name, name)
740 code += ' {\n'
741 for val in cls.vals:
742 code += ' "%s",\n' % val
743 code += ' };\n'
744 code += '}\n'
745 return code
746
747# Base class for enum types.

--- 417 unchanged lines hidden (view full) ---

1165# proxy objects (via set_param_desc()) so that proxy error messages
1166# make sense.
1167class PortParamDesc(object):
1168 __metaclass__ = Singleton
1169
1170 ptype_str = 'Port'
1171 ptype = Port
1172
736 code += ' {\n'
737 for val in cls.vals:
738 code += ' "%s",\n' % val
739 code += ' };\n'
740 code += '}\n'
741 return code
742
743# Base class for enum types.

--- 417 unchanged lines hidden (view full) ---

1161# proxy objects (via set_param_desc()) so that proxy error messages
1162# make sense.
1163class PortParamDesc(object):
1164 __metaclass__ = Singleton
1165
1166 ptype_str = 'Port'
1167 ptype = Port
1168
1169baseEnums = allEnums.copy()
1170baseParams = allParams.copy()
1171
1172def clear():
1173 global allEnums, allParams
1174
1175 allEnums = baseEnums.copy()
1176 allParams = baseParams.copy()
1177
1173__all__ = ['Param', 'VectorParam',
1174 'Enum', 'Bool', 'String', 'Float',
1175 'Int', 'Unsigned', 'Int8', 'UInt8', 'Int16', 'UInt16',
1176 'Int32', 'UInt32', 'Int64', 'UInt64',
1177 'Counter', 'Addr', 'Tick', 'Percent',
1178 'TcpPort', 'UdpPort', 'EthernetAddr',
1179 'MemorySize', 'MemorySize32',
1180 'Latency', 'Frequency', 'Clock',
1181 'NetworkBandwidth', 'MemoryBandwidth',
1182 'Range', 'AddrRange', 'TickRange',
1183 'MaxAddr', 'MaxTick', 'AllMemory',
1184 'Time',
1185 'NextEthernetAddr', 'NULL',
1186 'Port', 'VectorPort']
1178__all__ = ['Param', 'VectorParam',
1179 'Enum', 'Bool', 'String', 'Float',
1180 'Int', 'Unsigned', 'Int8', 'UInt8', 'Int16', 'UInt16',
1181 'Int32', 'UInt32', 'Int64', 'UInt64',
1182 'Counter', 'Addr', 'Tick', 'Percent',
1183 'TcpPort', 'UdpPort', 'EthernetAddr',
1184 'MemorySize', 'MemorySize32',
1185 'Latency', 'Frequency', 'Clock',
1186 'NetworkBandwidth', 'MemoryBandwidth',
1187 'Range', 'AddrRange', 'TickRange',
1188 'MaxAddr', 'MaxTick', 'AllMemory',
1189 'Time',
1190 'NextEthernetAddr', 'NULL',
1191 'Port', 'VectorPort']
1192
1193import SimObject