__init__.py revision 4762
11736SN/A# Copyright (c) 2005 The Regents of The University of Michigan
21736SN/A# All rights reserved.
31736SN/A#
41736SN/A# Redistribution and use in source and binary forms, with or without
51736SN/A# modification, are permitted provided that the following conditions are
61736SN/A# met: redistributions of source code must retain the above copyright
71736SN/A# notice, this list of conditions and the following disclaimer;
81736SN/A# redistributions in binary form must reproduce the above copyright
91736SN/A# notice, this list of conditions and the following disclaimer in the
101736SN/A# documentation and/or other materials provided with the distribution;
111736SN/A# neither the name of the copyright holders nor the names of its
121736SN/A# contributors may be used to endorse or promote products derived from
131736SN/A# this software without specific prior written permission.
141736SN/A#
151736SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
161736SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
171736SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
181736SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
191736SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
201736SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
211736SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
221736SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
231736SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
241736SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
251736SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
262665Ssaidi@eecs.umich.edu#
272665Ssaidi@eecs.umich.edu# Authors: Nathan Binkert
282665Ssaidi@eecs.umich.edu#          Steve Reinhardt
291736SN/A
304123Sbinkertn@umich.eduimport os
314123Sbinkertn@umich.eduimport sys
322655Sstever@eecs.umich.edu
334762Snate@binkert.orgimport smartdict
341530SN/A
353511Shsul@eecs.umich.edu# define a MaxTick parameter
363511Shsul@eecs.umich.eduMaxTick = 2**63 - 1
373511Shsul@eecs.umich.edu
381530SN/A# define this here so we can use it right away if necessary
391530SN/Adef panic(string):
401530SN/A    print >>sys.stderr, 'panic:', string
411530SN/A    sys.exit(1)
421530SN/A
433105Sstever@eecs.umich.edu# force scalars to one-element lists for uniformity
442969Sktlim@umich.edudef makeList(objOrList):
452969Sktlim@umich.edu    if isinstance(objOrList, list):
462969Sktlim@umich.edu        return objOrList
472969Sktlim@umich.edu    return [objOrList]
482969Sktlim@umich.edu
492667Sstever@eecs.umich.edu# Prepend given directory to system module search path.  We may not
502667Sstever@eecs.umich.edu# need this anymore if we can structure our config library more like a
512667Sstever@eecs.umich.edu# Python package.
521692SN/Adef AddToPath(path):
531869SN/A    # if it's a relative path and we know what directory the current
541869SN/A    # python script is in, make the path relative to that directory.
551869SN/A    if not os.path.isabs(path) and sys.path[0]:
561869SN/A        path = os.path.join(sys.path[0], path)
571692SN/A    path = os.path.realpath(path)
581869SN/A    # sys.path[0] should always refer to the current script's directory,
591869SN/A    # so place the new dir right after that.
601869SN/A    sys.path.insert(1, path)
611581SN/A
621530SN/A# make a SmartDict out of the build options for our local use
631530SN/Abuild_env = smartdict.SmartDict()
641530SN/A
651530SN/A# make a SmartDict out of the OS environment too
661530SN/Aenv = smartdict.SmartDict()
671530SN/Aenv.update(os.environ)
681530SN/A
693101Sstever@eecs.umich.edu# Since we have so many mutual imports in this package, we should:
703101Sstever@eecs.umich.edu# 1. Put all intra-package imports at the *bottom* of the file, unless
713101Sstever@eecs.umich.edu#    they're absolutely needed before that (for top-level statements
723101Sstever@eecs.umich.edu#    or class attributes).  Imports of "trivial" packages that don't
733101Sstever@eecs.umich.edu#    import other packages (e.g., 'smartdict') can be at the top.
743101Sstever@eecs.umich.edu# 2. Never use 'from foo import *' on an intra-package import since
753101Sstever@eecs.umich.edu#    you can get the wrong result if foo is only partially imported
763101Sstever@eecs.umich.edu#    at the point you do that (i.e., because foo is in the middle of
773101Sstever@eecs.umich.edu#    importing *you*).
784762Snate@binkert.orgtry:
794762Snate@binkert.org    import internal
804762Snate@binkert.org    running_m5 = True
814762Snate@binkert.orgexcept ImportError:
824762Snate@binkert.org    running_m5 = False
834762Snate@binkert.org
844762Snate@binkert.orgif running_m5:
854762Snate@binkert.org    from event import *
864762Snate@binkert.org    from simulate import *
874762Snate@binkert.org    from main import options
884762Snate@binkert.org
894762Snate@binkert.orgif running_m5:
904762Snate@binkert.org    import defines
914762Snate@binkert.org    build_env.update(defines.m5_build_env)
924762Snate@binkert.orgelse:
934762Snate@binkert.org    import __scons
944762Snate@binkert.org    build_env.update(__scons.m5_build_env)
954762Snate@binkert.org
964762Snate@binkert.orgimport SimObject
974762Snate@binkert.orgimport params
983101Sstever@eecs.umich.eduimport objects
99