From 8dff74b26fbfafad4ea9a12d20ad57b8094b0bc9 Mon Sep 17 00:00:00 2001 From: Steve Reinhardt Date: Sun, 13 Mar 2005 00:36:06 -0500 Subject: Clean up import situation... key things are: - global tracking of legitimate param types in separate dict keeps us from having to import objects in config.py, which gets rid of nasty circular dependence - use __all__ in config.py and restrict imports from mpy_importer to reduce m5 namespace pollution python/m5/__init__.py: Try to limit namespace pollution by only importing what's needed from mpy_importer. Explicitly set up legal parameter types rather than relying on eval(). python/m5/config.py: Use empty ParamType base class to distinguish types that are legitimate SimObject params. Explicitly add these to global param_types map. Rework CheckedInt and Range classes a little bit to fit in better with the model. No need to import objects here any longer. Add __all__ list to specify subset of names that get exported on 'from m5.config import *'. --HG-- extra : convert_revision : 01c6e82e0b175fc9b3df25dd0cc80ecd842680bc --- python/m5/__init__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'python/m5/__init__.py') diff --git a/python/m5/__init__.py b/python/m5/__init__.py index 7cb3a32c6..3d54a83da 100644 --- a/python/m5/__init__.py +++ b/python/m5/__init__.py @@ -1,7 +1,11 @@ -from mpy_importer import * +from mpy_importer import AddToPath, LoadMpyFile + from config import * +config.add_param_types(config.__dict__) + from objects import * +config.add_param_types(objects.__dict__) -cpp_classes = MetaSimObject.cpp_classes +cpp_classes = config.MetaSimObject.cpp_classes cpp_classes.sort() -- cgit v1.2.3 From 1b841a871ecd717dd8705d12ff7311c6fc97fc63 Mon Sep 17 00:00:00 2001 From: Steve Reinhardt Date: Mon, 14 Mar 2005 07:46:26 -0500 Subject: - Add capability to auto-generate Param structs from .mpy SimObject descriptions. Structs are defined in simobj/param/ObjectName.hh. - Move compile-time python params (from CPPDEFINES) to separate dict from run-time params (from os.environ). The former are needed to generate proper param structs. This also helps prevent users from messing things up by setting the wrong environment vars (which could have overridden compile-time settings in the old system). - Other misc cleanup of m5 python package. SConscript: Include simobj/SConscript build/SConstruct: Fix type in comment python/SConscript: Move CPPDEFINES dict-generating code to m5scons.flatten_defines python/m5/__init__.py: - Generate a build_env SmartDict here to hold compile-time params (passed in via __main__.m5_build_env). - Move panic and env here from config.py. python/m5/config.py: Move panic, env to top level (m5/__init__.py) python/m5/objects/BaseCPU.mpy: Use build_env instead of env for compile-time params python/m5/smartdict.py: Add some comments. sim/sim_object.hh: Include auto-generated Param struct. Not used yet, just here as proof of concept. test/genini.py: Put -E arguments in build_env as well as os.environ --HG-- extra : convert_revision : cf6f4a2565b230c495b33b18612d6030988adac5 --- python/m5/__init__.py | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'python/m5/__init__.py') diff --git a/python/m5/__init__.py b/python/m5/__init__.py index 3d54a83da..16f48dba3 100644 --- a/python/m5/__init__.py +++ b/python/m5/__init__.py @@ -1,10 +1,36 @@ +import sys, os + +# the mpy import code is added to the global import meta_path as a +# side effect of this import from mpy_importer import AddToPath, LoadMpyFile +# define this here so we can use it right away if necessary +def panic(string): + print >>sys.stderr, 'panic:', string + sys.exit(1) + +# find the m5 compile options: must be specified as a dict in +# __main__.m5_build_env. +import __main__ +if not hasattr(__main__, 'm5_build_env'): + panic("__main__ must define m5_build_env") + +# make a SmartDict out of the build options for our local use +import smartdict +build_env = smartdict.SmartDict() +build_env.update(__main__.m5_build_env) + +# make a SmartDict out of the OS environment too +env = smartdict.SmartDict() +env.update(os.environ) + +# import the main m5 config code from config import * -config.add_param_types(config.__dict__) +config.add_param_types(config) +# import the built-in object definitions from objects import * -config.add_param_types(objects.__dict__) +config.add_param_types(objects) cpp_classes = config.MetaSimObject.cpp_classes cpp_classes.sort() -- cgit v1.2.3