params.py (8579:ad3704c8a503) | params.py (8596:e6e22fa77883) |
---|---|
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 | 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. |
|
84 @classmethod 85 def cxx_predecls(cls, code): 86 pass 87 | 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. |
|
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): | 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 | |
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): | 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 | |
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 | 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 |
|
243 def swig_predecls(self, code): | 249 def swig_predecls(self, code): |
244 code('%import "vptype_${{self.ptype_str}}.i"') | 250 code('%import "${{self.swig_module_name()}}.i"') |
245 246 def swig_decl(self, code): | 251 252 def swig_decl(self, code): |
253 code('%module(package="m5.internal") ${{self.swig_module_name()}}') |
|
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 | 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 |
|
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 --- | 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 --- |