Deleted Added
sdiff udiff text old ( 8579:ad3704c8a503 ) new ( 8596:e6e22fa77883 )
full compact
1# Copyright (c) 2004-2006 The Regents of The University of Michigan
2# Copyright (c) 2010-2011 Advanced Micro Devices, Inc.
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions are
7# met: redistributions of source code must retain the above copyright
8# notice, this list of conditions and the following disclaimer;

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

76 return cls
77
78
79# Dummy base class to identify types that are legitimate for SimObject
80# parameters.
81class ParamValue(object):
82 __metaclass__ = MetaParamValue
83
84 @classmethod
85 def cxx_predecls(cls, code):
86 pass
87
88 @classmethod
89 def swig_predecls(cls, code):
90 pass
91
92 # default for printing to .ini file is regular string conversion.
93 # will be overridden in some cases
94 def ini_str(self):
95 return str(self)
96
97 # allows us to blithely call unproxy() on things without checking
98 # if they're really proxies or not
99 def unproxy(self, base):
100 return self
101
102# Regular parameter description.
103class ParamDesc(object):
104 file_ext = 'ptype'
105
106 def __init__(self, ptype_str, ptype, *args, **kwargs):
107 self.ptype_str = ptype_str
108 # remember ptype only if it is provided
109 if ptype != None:
110 self.ptype = ptype
111
112 if args:
113 if len(args) == 1:

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

218 # without having to provide lots of special functions on
219 # SimObjectVector directly.
220 def descendants(self):
221 for v in self:
222 for obj in v.descendants():
223 yield obj
224
225class VectorParamDesc(ParamDesc):
226 file_ext = 'vptype'
227
228 # Convert assigned value to appropriate type. If the RHS is not a
229 # list or tuple, it generates a single-element list.
230 def convert(self, value):
231 if isinstance(value, (list, tuple)):
232 # list: coerce each element into new list
233 tmp_list = [ ParamDesc.convert(self, v) for v in value ]
234 else:
235 # singleton: coerce to a single-element list
236 tmp_list = [ ParamDesc.convert(self, value) ]
237
238 if isSimObjectSequence(tmp_list):
239 return SimObjectVector(tmp_list)
240 else:
241 return VectorParamValue(tmp_list)
242
243 def swig_predecls(self, code):
244 code('%import "vptype_${{self.ptype_str}}.i"')
245
246 def swig_decl(self, code):
247 code('%{')
248 self.ptype.cxx_predecls(code)
249 code('%}')
250 code()
251 self.ptype.swig_predecls(code)
252 code()
253 code('%include "std_vector.i"')
254 code()

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

1038 for val in cls.vals:
1039 code('"$val",')
1040 code.dedent(2)
1041 code('''
1042 };
1043} // namespace Enums
1044''')
1045
1046# Base class for enum types.
1047class Enum(ParamValue):
1048 __metaclass__ = MetaEnum
1049 vals = []
1050
1051 def __init__(self, value):
1052 if value not in self.map:
1053 raise TypeError, "Enum param got bad value '%s' (not in %s)" \

--- 471 unchanged lines hidden ---