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
85 # Generate the code needed as a prerequisite for declaring a C++
86 # object of this type. Typically generates one or more #include
87 # statements. Used when declaring parameters of this type.
88 @classmethod
89 def cxx_predecls(cls, code):
90 pass
91
92 # Generate the code needed as a prerequisite for including a
93 # reference to a C++ object of this type in a SWIG .i file.
94 # Typically generates one or more %import or %include statements.
95 @classmethod
96 def swig_predecls(cls, code):
97 pass
98
99 # default for printing to .ini file is regular string conversion.
100 # will be overridden in some cases
101 def ini_str(self):
102 return str(self)
103
104 # allows us to blithely call unproxy() on things without checking
105 # if they're really proxies or not
106 def unproxy(self, base):
107 return self
108
109# Regular parameter description.
110class ParamDesc(object):
104 file_ext = 'ptype'
105
111 def __init__(self, ptype_str, ptype, *args, **kwargs):
112 self.ptype_str = ptype_str
113 # remember ptype only if it is provided
114 if ptype != None:
115 self.ptype = ptype
116
117 if args:
118 if len(args) == 1:

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

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

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

1045 for val in cls.vals:
1046 code('"$val",')
1047 code.dedent(2)
1048 code('''
1049 };
1050} // namespace Enums
1051''')
1052
1053 def swig_decl(cls, code):
1054 name = cls.__name__
1055 code('''\
1056%module(package="m5.internal") enum_$name
1057
1058%{
1059#include "enums/$name.hh"
1060%}
1061
1062%include "enums/$name.hh"
1063''')
1064
1065
1066# Base class for enum types.
1067class Enum(ParamValue):
1068 __metaclass__ = MetaEnum
1069 vals = []
1070
1071 def __init__(self, value):
1072 if value not in self.map:
1073 raise TypeError, "Enum param got bad value '%s' (not in %s)" \

--- 471 unchanged lines hidden ---