__init__.py revision 5802:1fb28f526602
1# Copyright (c) 2005 The Regents of The University of Michigan 2# All rights reserved. 3# 4# Redistribution and use in source and binary forms, with or without 5# modification, are permitted provided that the following conditions are 6# met: redistributions of source code must retain the above copyright 7# notice, this list of conditions and the following disclaimer; 8# redistributions in binary form must reproduce the above copyright 9# notice, this list of conditions and the following disclaimer in the 10# documentation and/or other materials provided with the distribution; 11# neither the name of the copyright holders nor the names of its 12# contributors may be used to endorse or promote products derived from 13# this software without specific prior written permission. 14# 15# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26# 27# Authors: Nathan Binkert 28# Steve Reinhardt 29 30import os 31import sys 32 33import smartdict 34 35# define a MaxTick parameter 36MaxTick = 2**63 - 1 37 38# define this here so we can use it right away if necessary 39 40# panic() should be called when something happens that should never 41# ever happen regardless of what the user does (i.e., an acutal m5 42# bug). 43def panic(string): 44 print >>sys.stderr, 'panic:', string 45 sys.exit(1) 46 47# fatal() should be called when the simulation cannot continue due to 48# some condition that is the user's fault (bad configuration, invalid 49# arguments, etc.) and not a simulator bug. 50def fatal(string): 51 print >>sys.stderr, 'fatal:', string 52 sys.exit(1) 53 54# force scalars to one-element lists for uniformity 55def makeList(objOrList): 56 if isinstance(objOrList, list): 57 return objOrList 58 return [objOrList] 59 60# Prepend given directory to system module search path. We may not 61# need this anymore if we can structure our config library more like a 62# Python package. 63def AddToPath(path): 64 # if it's a relative path and we know what directory the current 65 # python script is in, make the path relative to that directory. 66 if not os.path.isabs(path) and sys.path[0]: 67 path = os.path.join(sys.path[0], path) 68 path = os.path.realpath(path) 69 # sys.path[0] should always refer to the current script's directory, 70 # so place the new dir right after that. 71 sys.path.insert(1, path) 72 73# make a SmartDict out of the build options for our local use 74build_env = smartdict.SmartDict() 75 76# make a SmartDict out of the OS environment too 77env = smartdict.SmartDict() 78env.update(os.environ) 79 80# Since we have so many mutual imports in this package, we should: 81# 1. Put all intra-package imports at the *bottom* of the file, unless 82# they're absolutely needed before that (for top-level statements 83# or class attributes). Imports of "trivial" packages that don't 84# import other packages (e.g., 'smartdict') can be at the top. 85# 2. Never use 'from foo import *' on an intra-package import since 86# you can get the wrong result if foo is only partially imported 87# at the point you do that (i.e., because foo is in the middle of 88# importing *you*). 89try: 90 import internal 91except ImportError: 92 internal = None 93 94import defines 95build_env.update(defines.buildEnv) 96 97if internal: 98 defines.compileDate = internal.core.compileDate 99 for k,v in internal.core.__dict__.iteritems(): 100 if k.startswith('flag_'): 101 setattr(defines, k[5:], v) 102 103 from event import * 104 from simulate import * 105 from main import options, main 106 import stats 107 import core 108 109import SimObject 110import params 111import objects 112