SimObject.py (9254:f1b35c618252) SimObject.py (9338:97b4a2be1e5b)
1# Copyright (c) 2012 ARM Limited
2# All rights reserved.
3#
4# The license below extends only to copyright in the software and shall
5# not be construed as granting a license to any other intellectual
6# property including but not limited to intellectual property relating
7# to a hardware implementation of the functionality of the software
8# licensed hereunder. You may use the software subject to the license

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

100#####################################################################
101
102# list of all SimObject classes
103allClasses = {}
104
105# dict to look up SimObjects based on path
106instanceDict = {}
107
1# Copyright (c) 2012 ARM Limited
2# All rights reserved.
3#
4# The license below extends only to copyright in the software and shall
5# not be construed as granting a license to any other intellectual
6# property including but not limited to intellectual property relating
7# to a hardware implementation of the functionality of the software
8# licensed hereunder. You may use the software subject to the license

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

100#####################################################################
101
102# list of all SimObject classes
103allClasses = {}
104
105# dict to look up SimObjects based on path
106instanceDict = {}
107
108# Did any of the SimObjects lack a header file?
109noCxxHeader = False
110
108def public_value(key, value):
109 return key.startswith('_') or \
110 isinstance(value, (FunctionType, MethodType, ModuleType,
111 classmethod, type))
112
113# The metaclass for SimObject. This class controls how new classes
114# that derive from SimObject are instantiated, and provides inherited
115# class behavior (just like a class controls how instances of that
116# class are instantiated, and provides inherited instance behavior).
117class MetaSimObject(type):
118 # Attributes that can be set only at initialization time
119 init_keywords = { 'abstract' : bool,
120 'cxx_class' : str,
121 'cxx_type' : str,
111def public_value(key, value):
112 return key.startswith('_') or \
113 isinstance(value, (FunctionType, MethodType, ModuleType,
114 classmethod, type))
115
116# The metaclass for SimObject. This class controls how new classes
117# that derive from SimObject are instantiated, and provides inherited
118# class behavior (just like a class controls how instances of that
119# class are instantiated, and provides inherited instance behavior).
120class MetaSimObject(type):
121 # Attributes that can be set only at initialization time
122 init_keywords = { 'abstract' : bool,
123 'cxx_class' : str,
124 'cxx_type' : str,
125 'cxx_header' : str,
122 'type' : str }
123 # Attributes that can be set any time
124 keywords = { 'check' : FunctionType }
125
126 # __new__ is called before __init__, and is where the statements
127 # in the body of the class definition get loaded into the class's
128 # __dict__. We intercept this to filter out parameter & port assignments
129 # and only allow "private" attributes to be passed to the base

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

198
199 # default keyword values
200 if 'type' in cls._value_dict:
201 if 'cxx_class' not in cls._value_dict:
202 cls._value_dict['cxx_class'] = cls._value_dict['type']
203
204 cls._value_dict['cxx_type'] = '%s *' % cls._value_dict['cxx_class']
205
126 'type' : str }
127 # Attributes that can be set any time
128 keywords = { 'check' : FunctionType }
129
130 # __new__ is called before __init__, and is where the statements
131 # in the body of the class definition get loaded into the class's
132 # __dict__. We intercept this to filter out parameter & port assignments
133 # and only allow "private" attributes to be passed to the base

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

202
203 # default keyword values
204 if 'type' in cls._value_dict:
205 if 'cxx_class' not in cls._value_dict:
206 cls._value_dict['cxx_class'] = cls._value_dict['type']
207
208 cls._value_dict['cxx_type'] = '%s *' % cls._value_dict['cxx_class']
209
210 if 'cxx_header' not in cls._value_dict:
211 global noCxxHeader
212 noCxxHeader = True
213 print >> sys.stderr, \
214 "warning: No header file specified for SimObject: %s" % name
215
206 # Export methods are automatically inherited via C++, so we
207 # don't want the method declarations to get inherited on the
208 # python side (and thus end up getting repeated in the wrapped
209 # versions of derived classes). The code below basicallly
210 # suppresses inheritance by substituting in the base (null)
211 # versions of these methods unless a different version is
212 # explicitly supplied.
213 for method_name in ('export_methods', 'export_method_cxx_predecls',

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

402 ports = cls._ports.local
403
404 code('%module(package="m5.internal") param_$cls')
405 code()
406 code('%{')
407 code('#include "params/$cls.hh"')
408 for param in params:
409 param.cxx_predecls(code)
216 # Export methods are automatically inherited via C++, so we
217 # don't want the method declarations to get inherited on the
218 # python side (and thus end up getting repeated in the wrapped
219 # versions of derived classes). The code below basicallly
220 # suppresses inheritance by substituting in the base (null)
221 # versions of these methods unless a different version is
222 # explicitly supplied.
223 for method_name in ('export_methods', 'export_method_cxx_predecls',

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

412 ports = cls._ports.local
413
414 code('%module(package="m5.internal") param_$cls')
415 code()
416 code('%{')
417 code('#include "params/$cls.hh"')
418 for param in params:
419 param.cxx_predecls(code)
420 code('#include "${{cls.cxx_header}}"')
410 cls.export_method_cxx_predecls(code)
411 code('''\
412/**
413 * This is a workaround for bug in swig. Prior to gcc 4.6.1 the STL
414 * headers like vector, string, etc. used to automatically pull in
415 * the cstddef header but starting with gcc 4.6.1 they no longer do.
416 * This leads to swig generated a file that does not compile so we
417 * explicitly include cstddef. Additionally, including version 2.0.4,

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

563# the code in this class deals with the configuration hierarchy itself
564# (parent/child node relationships).
565class SimObject(object):
566 # Specify metaclass. Any class inheriting from SimObject will
567 # get this metaclass.
568 __metaclass__ = MetaSimObject
569 type = 'SimObject'
570 abstract = True
421 cls.export_method_cxx_predecls(code)
422 code('''\
423/**
424 * This is a workaround for bug in swig. Prior to gcc 4.6.1 the STL
425 * headers like vector, string, etc. used to automatically pull in
426 * the cstddef header but starting with gcc 4.6.1 they no longer do.
427 * This leads to swig generated a file that does not compile so we
428 * explicitly include cstddef. Additionally, including version 2.0.4,

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

574# the code in this class deals with the configuration hierarchy itself
575# (parent/child node relationships).
576class SimObject(object):
577 # Specify metaclass. Any class inheriting from SimObject will
578 # get this metaclass.
579 __metaclass__ = MetaSimObject
580 type = 'SimObject'
581 abstract = True
582 cxx_header = "sim/sim_object.hh"
571
572 @classmethod
583
584 @classmethod
573 def export_method_cxx_predecls(cls, code):
574 code('''
575#include <Python.h>
576
577#include "sim/serialize.hh"
578#include "sim/sim_object.hh"
579''')
580
581 @classmethod
582 def export_method_swig_predecls(cls, code):
583 code('''
584%include <std_string.i>
585''')
586
587 @classmethod
588 def export_methods(cls, code):
589 code('''

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

1094 if value is None:
1095 raise TypeError, "SimObject or SimObjectVector expected"
1096 return value
1097
1098baseClasses = allClasses.copy()
1099baseInstances = instanceDict.copy()
1100
1101def clear():
585 def export_method_swig_predecls(cls, code):
586 code('''
587%include <std_string.i>
588''')
589
590 @classmethod
591 def export_methods(cls, code):
592 code('''

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

1097 if value is None:
1098 raise TypeError, "SimObject or SimObjectVector expected"
1099 return value
1100
1101baseClasses = allClasses.copy()
1102baseInstances = instanceDict.copy()
1103
1104def clear():
1102 global allClasses, instanceDict
1105 global allClasses, instanceDict, noCxxHeader
1103
1104 allClasses = baseClasses.copy()
1105 instanceDict = baseInstances.copy()
1106
1107 allClasses = baseClasses.copy()
1108 instanceDict = baseInstances.copy()
1109 noCxxHeader = False
1106
1107# __all__ defines the list of symbols that get exported when
1108# 'from config import *' is invoked. Try to keep this reasonably
1109# short to avoid polluting other namespaces.
1110__all__ = [ 'SimObject' ]
1110
1111# __all__ defines the list of symbols that get exported when
1112# 'from config import *' is invoked. Try to keep this reasonably
1113# short to avoid polluting other namespaces.
1114__all__ = [ 'SimObject' ]