__init__.py revision 2665:a124942bacb8
15703SN/A# Copyright (c) 2005 The Regents of The University of Michigan 25703SN/A# All rights reserved. 35703SN/A# 45703SN/A# Redistribution and use in source and binary forms, with or without 55703SN/A# modification, are permitted provided that the following conditions are 65703SN/A# met: redistributions of source code must retain the above copyright 75703SN/A# notice, this list of conditions and the following disclaimer; 85703SN/A# redistributions in binary form must reproduce the above copyright 95703SN/A# notice, this list of conditions and the following disclaimer in the 105703SN/A# documentation and/or other materials provided with the distribution; 115703SN/A# neither the name of the copyright holders nor the names of its 125703SN/A# contributors may be used to endorse or promote products derived from 135703SN/A# this software without specific prior written permission. 145703SN/A# 155703SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 165703SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 175703SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 185703SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 195703SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 205703SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 215703SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 225703SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 235703SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 245703SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 255703SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 265703SN/A# 275703SN/A# Authors: Nathan Binkert 285703SN/A# Steve Reinhardt 295703SN/A 30import sys, os, time 31 32import __main__ 33 34briefCopyright = ''' 35Copyright (c) 2001-2006 36The Regents of The University of Michigan 37All Rights Reserved 38''' 39 40fullCopyright = ''' 41Copyright (c) 2001-2006 42The Regents of The University of Michigan 43All Rights Reserved 44 45Permission is granted to use, copy, create derivative works and 46redistribute this software and such derivative works for any purpose, 47so long as the copyright notice above, this grant of permission, and 48the disclaimer below appear in all copies made; and so long as the 49name of The University of Michigan is not used in any advertising or 50publicity pertaining to the use or distribution of this software 51without specific, written prior authorization. 52 53THIS SOFTWARE IS PROVIDED AS IS, WITHOUT REPRESENTATION FROM THE 54UNIVERSITY OF MICHIGAN AS TO ITS FITNESS FOR ANY PURPOSE, AND WITHOUT 55WARRANTY BY THE UNIVERSITY OF MICHIGAN OF ANY KIND, EITHER EXPRESS OR 56IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF 57MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE REGENTS OF 58THE UNIVERSITY OF MICHIGAN SHALL NOT BE LIABLE FOR ANY DAMAGES, 59INCLUDING DIRECT, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL 60DAMAGES, WITH RESPECT TO ANY CLAIM ARISING OUT OF OR IN CONNECTION 61WITH THE USE OF THE SOFTWARE, EVEN IF IT HAS BEEN OR IS HEREAFTER 62ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 63''' 64 65def sayHello(f): 66 print >> f, "M5 Simulator System" 67 print >> f, briefCopyright 68 print >> f, "M5 compiled on", __main__.compileDate 69 hostname = os.environ.get('HOSTNAME') 70 if not hostname: 71 hostname = os.environ.get('HOST') 72 if hostname: 73 print >> f, "M5 executing on", hostname 74 print >> f, "M5 simulation started", time.ctime() 75 76sayHello(sys.stderr) 77 78# define this here so we can use it right away if necessary 79def panic(string): 80 print >>sys.stderr, 'panic:', string 81 sys.exit(1) 82 83def m5execfile(f, global_dict): 84 # copy current sys.path 85 oldpath = sys.path[:] 86 # push file's directory onto front of path 87 sys.path.insert(0, os.path.abspath(os.path.dirname(f))) 88 execfile(f, global_dict) 89 # restore original path 90 sys.path = oldpath 91 92# Prepend given directory to system module search path. 93def AddToPath(path): 94 # if it's a relative path and we know what directory the current 95 # python script is in, make the path relative to that directory. 96 if not os.path.isabs(path) and sys.path[0]: 97 path = os.path.join(sys.path[0], path) 98 path = os.path.realpath(path) 99 # sys.path[0] should always refer to the current script's directory, 100 # so place the new dir right after that. 101 sys.path.insert(1, path) 102 103# find the m5 compile options: must be specified as a dict in 104# __main__.m5_build_env. 105import __main__ 106if not hasattr(__main__, 'm5_build_env'): 107 panic("__main__ must define m5_build_env") 108 109# make a SmartDict out of the build options for our local use 110import smartdict 111build_env = smartdict.SmartDict() 112build_env.update(__main__.m5_build_env) 113 114# make a SmartDict out of the OS environment too 115env = smartdict.SmartDict() 116env.update(os.environ) 117 118# import the main m5 config code 119from config import * 120 121# import the built-in object definitions 122from objects import * 123 124 125args_left = sys.argv[1:] 126configfile_found = False 127 128while args_left: 129 arg = args_left.pop(0) 130 if arg.startswith('--'): 131 # if arg starts with '--', parse as a special python option 132 # of the format --<python var>=<string value> 133 try: 134 (var, val) = arg.split('=', 1) 135 except ValueError: 136 panic("Could not parse configuration argument '%s'\n" 137 "Expecting --<variable>=<value>\n" % arg); 138 eval("%s = %s" % (var, repr(val))) 139 elif arg.startswith('-'): 140 # if the arg starts with '-', it should be a simulator option 141 # with a format similar to getopt. 142 optchar = arg[1] 143 if len(arg) > 2: 144 args_left.insert(0, arg[2:]) 145 if optchar == 'd': 146 outdir = args_left.pop(0) 147 elif optchar == 'h': 148 showBriefHelp(sys.stderr) 149 sys.exit(1) 150 elif optchar == 'E': 151 env_str = args_left.pop(0) 152 split_result = env_str.split('=', 1) 153 var = split_result[0] 154 if len(split_result == 2): 155 val = split_result[1] 156 else: 157 val = True 158 env[var] = val 159 elif optchar == 'I': 160 AddToPath(args_left.pop(0)) 161 elif optchar == 'P': 162 eval(args_left.pop(0)) 163 else: 164 showBriefHelp(sys.stderr) 165 panic("invalid argument '%s'\n" % arg_str) 166 else: 167 # In any other case, treat the option as a configuration file 168 # name and load it. 169 if not arg.endswith('.py'): 170 panic("Config file '%s' must end in '.py'\n" % arg) 171 configfile_found = True 172 m5execfile(arg, globals()) 173 174 175if not configfile_found: 176 panic("no configuration file specified!") 177 178if globals().has_key('root') and isinstance(root, Root): 179 sys.stdout = file('config.ini', 'w') 180 instantiate(root) 181else: 182 print 'Instantiation skipped: no root object found.' 183 184