More Python hacking to deal with config.py split

and resulting recursive import trickiness.

--HG--
extra : convert_revision : 1ea93861eb8d260c9f3920dda0b8106db3e03705
This commit is contained in:
Steve Reinhardt 2006-09-04 17:14:07 -07:00
parent 1233dbb998
commit c39aea440c
35 changed files with 155 additions and 102 deletions

View file

@ -29,11 +29,40 @@
import sys, types import sys, types
import m5 from util import *
from m5 import panic, cc_main
from convert import *
from multidict import multidict from multidict import multidict
# These utility functions have to come first because they're
# referenced in params.py... otherwise they won't be defined when we
# import params below, and the recursive import of this file from
# params.py will not find these names.
def isSimObject(value):
return isinstance(value, SimObject)
def isSimObjectClass(value):
return issubclass(value, SimObject)
def isSimObjectSequence(value):
if not isinstance(value, (list, tuple)) or len(value) == 0:
return False
for val in value:
if not isNullPointer(val) and not isSimObject(val):
return False
return True
def isSimObjectOrSequence(value):
return isSimObject(value) or isSimObjectSequence(value)
# Have to import params up top since Param is referenced on initial
# load (when SimObject class references Param to create a class
# variable, the 'name' param)...
from params import *
# There are a few things we need that aren't in params.__all__ since
# normal users don't need them
from params import ParamDesc, isNullPointer, SimObjVector
noDot = False noDot = False
try: try:
import pydot import pydot
@ -564,7 +593,7 @@ class SimObject(object):
for param in param_names: for param in param_names:
value = self._values.get(param, None) value = self._values.get(param, None)
if value != None: if value != None:
if isproxy(value): if proxy.isproxy(value):
try: try:
value = value.unproxy(self) value = value.unproxy(self)
except: except:
@ -679,52 +708,6 @@ class SimObject(object):
class ParamContext(SimObject): class ParamContext(SimObject):
pass pass
# Special class for NULL pointers. Note the special check in
# make_param_value() above that lets these be assigned where a
# SimObject is required.
# only one copy of a particular node
class NullSimObject(object):
__metaclass__ = Singleton
def __call__(cls):
return cls
def _instantiate(self, parent = None, path = ''):
pass
def ini_str(self):
return 'Null'
def unproxy(self, base):
return self
def set_path(self, parent, name):
pass
def __str__(self):
return 'Null'
# The only instance you'll ever need...
Null = NULL = NullSimObject()
def isSimObject(value):
return isinstance(value, SimObject)
def isNullPointer(value):
return isinstance(value, NullSimObject)
def isSimObjectSequence(value):
if not isinstance(value, (list, tuple)) or len(value) == 0:
return False
for val in value:
if not isNullPointer(val) and not isSimObject(val):
return False
return True
def isSimObjectOrSequence(value):
return isSimObject(value) or isSimObjectSequence(value)
# Function to provide to C++ so it can look up instances based on paths # Function to provide to C++ so it can look up instances based on paths
def resolveSimObject(name): def resolveSimObject(name):
obj = instanceDict[name] obj = instanceDict[name]
@ -735,3 +718,7 @@ def resolveSimObject(name):
# short to avoid polluting other namespaces. # short to avoid polluting other namespaces.
__all__ = ['SimObject', 'ParamContext'] __all__ = ['SimObject', 'ParamContext']
# see comment on imports at end of __init__.py.
import proxy
import cc_main

View file

@ -71,8 +71,6 @@ build_env.update(defines.m5_build_env)
env = smartdict.SmartDict() env = smartdict.SmartDict()
env.update(os.environ) env.update(os.environ)
from main import options, arguments, main
# The final hook to generate .ini files. Called from the user script # The final hook to generate .ini files. Called from the user script
# once the config is built. # once the config is built.
def instantiate(root): def instantiate(root):
@ -206,5 +204,7 @@ def switchCpus(cpuList):
# you can get the wrong result if foo is only partially imported # you can get the wrong result if foo is only partially imported
# at the point you do that (i.e., because foo is in the middle of # at the point you do that (i.e., because foo is in the middle of
# importing *you*). # importing *you*).
from main import options
import objects import objects
import params import params
from SimObject import resolveSimObject

View file

@ -1,4 +1,5 @@
from m5.config import * from m5.params import *
from m5.proxy import *
from Device import BasicPioDevice from Device import BasicPioDevice
class AlphaConsole(BasicPioDevice): class AlphaConsole(BasicPioDevice):

View file

@ -1,4 +1,5 @@
from m5.config import * from m5.SimObject import SimObject
from m5.params import *
class AlphaTLB(SimObject): class AlphaTLB(SimObject):
type = 'AlphaTLB' type = 'AlphaTLB'
abstract = True abstract = True

View file

@ -1,4 +1,4 @@
from m5.config import * from m5.params import *
from Device import BasicPioDevice from Device import BasicPioDevice
class BadDevice(BasicPioDevice): class BadDevice(BasicPioDevice):

View file

@ -1,5 +1,7 @@
from m5.SimObject import SimObject
from m5.params import *
from m5.proxy import *
from m5 import build_env from m5 import build_env
from m5.config import *
from AlphaTLB import AlphaDTB, AlphaITB from AlphaTLB import AlphaDTB, AlphaITB
from Bus import Bus from Bus import Bus

View file

@ -1,4 +1,4 @@
from m5.config import * from m5.params import *
from MemObject import MemObject from MemObject import MemObject
class Prefetch(Enum): vals = ['none', 'tagged', 'stride', 'ghb'] class Prefetch(Enum): vals = ['none', 'tagged', 'stride', 'ghb']

View file

@ -1,4 +1,4 @@
from m5.config import * from m5.params import *
from MemObject import MemObject from MemObject import MemObject
class Bridge(MemObject): class Bridge(MemObject):

View file

@ -1,4 +1,4 @@
from m5.config import * from m5.params import *
from MemObject import MemObject from MemObject import MemObject
class Bus(MemObject): class Bus(MemObject):

View file

@ -1,4 +1,5 @@
from m5.config import * from m5.SimObject import SimObject
from m5.params import *
class Coherence(Enum): vals = ['uni', 'msi', 'mesi', 'mosi', 'moesi'] class Coherence(Enum): vals = ['uni', 'msi', 'mesi', 'mosi', 'moesi']
class CoherenceProtocol(SimObject): class CoherenceProtocol(SimObject):

View file

@ -1,4 +1,5 @@
from m5.config import * from m5.params import *
from m5.proxy import *
from MemObject import MemObject from MemObject import MemObject
class PioDevice(MemObject): class PioDevice(MemObject):

View file

@ -1,4 +1,5 @@
from m5.config import * from m5.SimObject import SimObject
from m5.params import *
class DiskImage(SimObject): class DiskImage(SimObject):
type = 'DiskImage' type = 'DiskImage'
abstract = True abstract = True

View file

@ -1,5 +1,7 @@
from m5.SimObject import SimObject
from m5.params import *
from m5.proxy import *
from m5 import build_env from m5 import build_env
from m5.config import *
from Device import DmaDevice from Device import DmaDevice
from Pci import PciDevice, PciConfigData from Pci import PciDevice, PciConfigData

View file

@ -1,4 +1,5 @@
from m5.config import * from m5.SimObject import SimObject
from m5.params import *
class FUPool(SimObject): class FUPool(SimObject):
type = 'FUPool' type = 'FUPool'

View file

@ -1,4 +1,5 @@
from m5.config import * from m5.SimObject import SimObject
from m5.params import *
class OpType(Enum): class OpType(Enum):
vals = ['(null)', 'IntAlu', 'IntMult', 'IntDiv', 'FloatAdd', vals = ['(null)', 'IntAlu', 'IntMult', 'IntDiv', 'FloatAdd',

View file

@ -1,4 +1,5 @@
from m5.config import * from m5.SimObject import SimObject
from m5.params import *
from Pci import PciDevice, PciConfigData from Pci import PciDevice, PciConfigData
class IdeID(Enum): vals = ['master', 'slave'] class IdeID(Enum): vals = ['master', 'slave']

View file

@ -1,4 +1,6 @@
from m5.config import * from m5.SimObject import SimObject
from m5.params import *
from m5.proxy import *
class IntrControl(SimObject): class IntrControl(SimObject):
type = 'IntrControl' type = 'IntrControl'
cpu = Param.BaseCPU(Parent.any, "the cpu") cpu = Param.BaseCPU(Parent.any, "the cpu")

View file

@ -1,4 +1,5 @@
from m5.config import * from m5.SimObject import SimObject
from m5.SimObject import SimObject
class MemObject(SimObject): class MemObject(SimObject):
type = 'MemObject' type = 'MemObject'

View file

@ -1,4 +1,5 @@
from m5.config import * from m5.SimObject import SimObject
from m5.params import *
class MemTest(SimObject): class MemTest(SimObject):
type = 'MemTest' type = 'MemTest'
cache = Param.BaseCache("L1 cache") cache = Param.BaseCache("L1 cache")

View file

@ -1,5 +1,6 @@
from m5.params import *
from m5.proxy import *
from m5 import build_env from m5 import build_env
from m5.config import *
from BaseCPU import BaseCPU from BaseCPU import BaseCPU
from Checker import O3Checker from Checker import O3Checker

View file

@ -1,5 +1,5 @@
from m5.params import *
from m5 import build_env from m5 import build_env
from m5.config import *
from BaseCPU import BaseCPU from BaseCPU import BaseCPU
class DerivOzoneCPU(BaseCPU): class DerivOzoneCPU(BaseCPU):

View file

@ -1,4 +1,6 @@
from m5.config import * from m5.SimObject import SimObject
from m5.params import *
from m5.proxy import *
from Device import BasicPioDevice, DmaDevice, PioDevice from Device import BasicPioDevice, DmaDevice, PioDevice
class PciConfigData(SimObject): class PciConfigData(SimObject):

View file

@ -1,4 +1,5 @@
from m5.config import * from m5.params import *
from m5.proxy import *
from MemObject import * from MemObject import *
class PhysicalMemory(MemObject): class PhysicalMemory(MemObject):

View file

@ -1,4 +1,6 @@
from m5.config import * from m5.SimObject import SimObject
from m5.params import *
from m5.proxy import *
class Platform(SimObject): class Platform(SimObject):
type = 'Platform' type = 'Platform'
abstract = True abstract = True

View file

@ -1,4 +1,6 @@
from m5.config import * from m5.SimObject import SimObject
from m5.params import *
from m5.proxy import *
class Process(SimObject): class Process(SimObject):
type = 'Process' type = 'Process'
abstract = True abstract = True

View file

@ -1,4 +1,5 @@
from m5.config import * from m5.SimObject import SimObject
from m5.params import *
class Repl(SimObject): class Repl(SimObject):
type = 'Repl' type = 'Repl'
abstract = True abstract = True

View file

@ -1,4 +1,5 @@
from m5.config import * from m5.SimObject import SimObject
from m5.params import *
from Serialize import Serialize from Serialize import Serialize
from Statistics import Statistics from Statistics import Statistics
from Trace import Trace from Trace import Trace

View file

@ -1,4 +1,6 @@
from m5.config import * from m5.SimObject import SimObject
from m5.params import *
from m5.proxy import *
class ConsoleListener(SimObject): class ConsoleListener(SimObject):
type = 'ConsoleListener' type = 'ConsoleListener'
port = Param.TcpPort(3456, "listen port") port = Param.TcpPort(3456, "listen port")

View file

@ -1,4 +1,6 @@
from m5.config import * from m5.SimObject import SimObject
from m5.params import *
from m5.proxy import *
class SimpleDisk(SimObject): class SimpleDisk(SimObject):
type = 'SimpleDisk' type = 'SimpleDisk'
disk = Param.DiskImage("Disk Image") disk = Param.DiskImage("Disk Image")

View file

@ -1,5 +1,5 @@
from m5.params import *
from m5 import build_env from m5 import build_env
from m5.config import *
from BaseCPU import BaseCPU from BaseCPU import BaseCPU
class SimpleOzoneCPU(BaseCPU): class SimpleOzoneCPU(BaseCPU):

View file

@ -1,5 +1,7 @@
from m5.SimObject import SimObject
from m5.params import *
from m5.proxy import *
from m5 import build_env from m5 import build_env
from m5.config import *
class MemoryMode(Enum): vals = ['invalid', 'atomic', 'timing'] class MemoryMode(Enum): vals = ['invalid', 'atomic', 'timing']

View file

@ -1,4 +1,5 @@
from m5.config import * from m5.params import *
from m5.proxy import *
from Device import BasicPioDevice from Device import BasicPioDevice
from Platform import Platform from Platform import Platform
from AlphaConsole import AlphaConsole from AlphaConsole import AlphaConsole

View file

@ -1,5 +1,6 @@
from m5.params import *
from m5.proxy import *
from m5 import build_env from m5 import build_env
from m5.config import *
from Device import BasicPioDevice from Device import BasicPioDevice
class Uart(BasicPioDevice): class Uart(BasicPioDevice):

View file

@ -46,6 +46,7 @@
import sys, inspect, copy import sys, inspect, copy
import convert import convert
from util import *
# Dummy base class to identify types that are legitimate for SimObject # Dummy base class to identify types that are legitimate for SimObject
# parameters. # parameters.
@ -100,13 +101,14 @@ class ParamDesc(object):
def __getattr__(self, attr): def __getattr__(self, attr):
if attr == 'ptype': if attr == 'ptype':
try: try:
ptype = eval(self.ptype_str, m5.objects.__dict__) ptype = eval(self.ptype_str, objects.__dict__)
if not isinstance(ptype, type): if not isinstance(ptype, type):
panic("Param qualifier is not a type: %s" % self.ptype) raise NameError
self.ptype = ptype self.ptype = ptype
return ptype return ptype
except NameError: except NameError:
pass raise TypeError, \
"Param qualifier '%s' is not a type" % self.ptype_str
raise AttributeError, "'%s' object has no attribute '%s'" % \ raise AttributeError, "'%s' object has no attribute '%s'" % \
(type(self).__name__, attr) (type(self).__name__, attr)
@ -120,7 +122,7 @@ class ParamDesc(object):
return value return value
if isinstance(value, self.ptype): if isinstance(value, self.ptype):
return value return value
if isNullPointer(value) and issubclass(self.ptype, SimObject): if isNullPointer(value) and isSimObjectClass(self.ptype):
return value return value
return self.ptype(value) return self.ptype(value)
@ -305,7 +307,7 @@ class CheckedInt(NumericParamValue):
def __init__(self, value): def __init__(self, value):
if isinstance(value, str): if isinstance(value, str):
self.value = toInteger(value) self.value = convert.toInteger(value)
elif isinstance(value, (int, long, float)): elif isinstance(value, (int, long, float)):
self.value = long(value) self.value = long(value)
self._check() self._check()
@ -340,7 +342,7 @@ class MemorySize(CheckedInt):
if isinstance(value, MemorySize): if isinstance(value, MemorySize):
self.value = value.value self.value = value.value
else: else:
self.value = toMemorySize(value) self.value = convert.toMemorySize(value)
self._check() self._check()
class MemorySize32(CheckedInt): class MemorySize32(CheckedInt):
@ -350,7 +352,7 @@ class MemorySize32(CheckedInt):
if isinstance(value, MemorySize): if isinstance(value, MemorySize):
self.value = value.value self.value = value.value
else: else:
self.value = toMemorySize(value) self.value = convert.toMemorySize(value)
self._check() self._check()
class Addr(CheckedInt): class Addr(CheckedInt):
@ -363,7 +365,7 @@ class Addr(CheckedInt):
self.value = value.value self.value = value.value
else: else:
try: try:
self.value = toMemorySize(value) self.value = convert.toMemorySize(value)
except TypeError: except TypeError:
self.value = long(value) self.value = long(value)
self._check() self._check()
@ -430,7 +432,7 @@ class Bool(ParamValue):
cxx_type = 'bool' cxx_type = 'bool'
def __init__(self, value): def __init__(self, value):
try: try:
self.value = toBool(value) self.value = convert.toBool(value)
except TypeError: except TypeError:
self.value = bool(value) self.value = bool(value)
@ -586,10 +588,10 @@ def getLatency(value):
return 1 / value.value return 1 / value.value
elif isinstance(value, str): elif isinstance(value, str):
try: try:
return toLatency(value) return convert.toLatency(value)
except ValueError: except ValueError:
try: try:
return 1 / toFrequency(value) return 1 / convert.toFrequency(value)
except ValueError: except ValueError:
pass # fall through pass # fall through
raise ValueError, "Invalid Frequency/Latency value '%s'" % value raise ValueError, "Invalid Frequency/Latency value '%s'" % value
@ -678,7 +680,7 @@ class Clock(ParamValue):
class NetworkBandwidth(float,ParamValue): class NetworkBandwidth(float,ParamValue):
cxx_type = 'float' cxx_type = 'float'
def __new__(cls, value): def __new__(cls, value):
val = toNetworkBandwidth(value) / 8.0 val = convert.toNetworkBandwidth(value) / 8.0
return super(cls, NetworkBandwidth).__new__(cls, val) return super(cls, NetworkBandwidth).__new__(cls, val)
def __str__(self): def __str__(self):
@ -690,7 +692,7 @@ class NetworkBandwidth(float,ParamValue):
class MemoryBandwidth(float,ParamValue): class MemoryBandwidth(float,ParamValue):
cxx_type = 'float' cxx_type = 'float'
def __new__(self, value): def __new__(self, value):
val = toMemoryBandwidth(value) val = convert.toMemoryBandwidth(value)
return super(cls, MemoryBandwidth).__new__(cls, val) return super(cls, MemoryBandwidth).__new__(cls, val)
def __str__(self): def __str__(self):
@ -703,6 +705,36 @@ class MemoryBandwidth(float,ParamValue):
# "Constants"... handy aliases for various values. # "Constants"... handy aliases for various values.
# #
# Special class for NULL pointers. Note the special check in
# make_param_value() above that lets these be assigned where a
# SimObject is required.
# only one copy of a particular node
class NullSimObject(object):
__metaclass__ = Singleton
def __call__(cls):
return cls
def _instantiate(self, parent = None, path = ''):
pass
def ini_str(self):
return 'Null'
def unproxy(self, base):
return self
def set_path(self, parent, name):
pass
def __str__(self):
return 'Null'
# The only instance you'll ever need...
NULL = NullSimObject()
def isNullPointer(value):
return isinstance(value, NullSimObject)
# Some memory range specifications use this as a default upper bound. # Some memory range specifications use this as a default upper bound.
MaxAddr = Addr.max MaxAddr = Addr.max
MaxTick = Tick.max MaxTick = Tick.max
@ -821,11 +853,11 @@ __all__ = ['Param', 'VectorParam',
'NetworkBandwidth', 'MemoryBandwidth', 'NetworkBandwidth', 'MemoryBandwidth',
'Range', 'AddrRange', 'TickRange', 'Range', 'AddrRange', 'TickRange',
'MaxAddr', 'MaxTick', 'AllMemory', 'MaxAddr', 'MaxTick', 'AllMemory',
'Null', 'NULL', 'NextEthernetAddr', 'NULL',
'NextEthernetAddr',
'Port', 'VectorPort'] 'Port', 'VectorPort']
# see comment on imports at end of __init__.py. # see comment on imports at end of __init__.py.
from SimObject import SimObject, isSimObject, isSimObjectSequence, \ from SimObject import isSimObject, isSimObjectSequence, isSimObjectClass
isNullPointer
import proxy import proxy
import objects
import cc_main

View file

@ -151,8 +151,8 @@ main(int argc, char **argv)
// initialize SWIG 'cc_main' module // initialize SWIG 'cc_main' module
init_cc_main(); init_cc_main();
PyRun_SimpleString("import m5"); PyRun_SimpleString("import m5.main");
PyRun_SimpleString("m5.main()"); PyRun_SimpleString("m5.main.main()");
// clean up Python intepreter. // clean up Python intepreter.
Py_Finalize(); Py_Finalize();