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 --- 10 unchanged lines hidden (view full) --- 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 |
27import sys, os, time |
28 |
29import __main__ 30 31briefCopyright = ''' 32Copyright (c) 2001-2006 33The Regents of The University of Michigan 34All Rights Reserved 35''' 36 37fullCopyright = ''' 38Copyright (c) 2001-2006 39The Regents of The University of Michigan 40All Rights Reserved 41 42Permission is granted to use, copy, create derivative works and 43redistribute this software and such derivative works for any purpose, 44so long as the copyright notice above, this grant of permission, and 45the disclaimer below appear in all copies made; and so long as the 46name of The University of Michigan is not used in any advertising or 47publicity pertaining to the use or distribution of this software 48without specific, written prior authorization. 49 50THIS SOFTWARE IS PROVIDED AS IS, WITHOUT REPRESENTATION FROM THE 51UNIVERSITY OF MICHIGAN AS TO ITS FITNESS FOR ANY PURPOSE, AND WITHOUT 52WARRANTY BY THE UNIVERSITY OF MICHIGAN OF ANY KIND, EITHER EXPRESS OR 53IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF 54MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE REGENTS OF 55THE UNIVERSITY OF MICHIGAN SHALL NOT BE LIABLE FOR ANY DAMAGES, 56INCLUDING DIRECT, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL 57DAMAGES, WITH RESPECT TO ANY CLAIM ARISING OUT OF OR IN CONNECTION 58WITH THE USE OF THE SOFTWARE, EVEN IF IT HAS BEEN OR IS HEREAFTER 59ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 60''' 61 62def sayHello(f): 63 print >> f, "M5 Simulator System" 64 print >> f, briefCopyright 65 print >> f, "M5 compiled on", __main__.compileDate 66 hostname = os.environ.get('HOSTNAME') 67 if not hostname: 68 hostname = os.environ.get('HOST') 69 if hostname: 70 print >> f, "M5 executing on", hostname 71 print >> f, "M5 simulation started", time.ctime() 72 73sayHello(sys.stderr) 74 |
75# define this here so we can use it right away if necessary 76def panic(string): 77 print >>sys.stderr, 'panic:', string 78 sys.exit(1) 79 80def m5execfile(f, global_dict): 81 # copy current sys.path 82 oldpath = sys.path[:] --- 30 unchanged lines hidden (view full) --- 113env.update(os.environ) 114 115# import the main m5 config code 116from config import * 117 118# import the built-in object definitions 119from objects import * 120 |
121 122args_left = sys.argv[1:] 123configfile_found = False 124 125while args_left: 126 arg = args_left.pop(0) 127 if arg.startswith('--'): 128 # if arg starts with '--', parse as a special python option 129 # of the format --<python var>=<string value> 130 try: 131 (var, val) = arg.split('=', 1) 132 except ValueError: 133 panic("Could not parse configuration argument '%s'\n" 134 "Expecting --<variable>=<value>\n" % arg); 135 eval("%s = %s" % (var, repr(val))) 136 elif arg.startswith('-'): 137 # if the arg starts with '-', it should be a simulator option 138 # with a format similar to getopt. 139 optchar = arg[1] 140 if len(arg) > 2: 141 args_left.insert(0, arg[2:]) 142 if optchar == 'd': 143 outdir = args_left.pop(0) 144 elif optchar == 'h': 145 showBriefHelp(sys.stderr) 146 sys.exit(1) 147 elif optchar == 'E': 148 env_str = args_left.pop(0) 149 split_result = env_str.split('=', 1) 150 var = split_result[0] 151 if len(split_result == 2): 152 val = split_result[1] 153 else: 154 val = True 155 env[var] = val 156 elif optchar == 'I': 157 AddToPath(args_left.pop(0)) 158 elif optchar == 'P': 159 eval(args_left.pop(0)) 160 else: 161 showBriefHelp(sys.stderr) 162 panic("invalid argument '%s'\n" % arg_str) 163 else: 164 # In any other case, treat the option as a configuration file 165 # name and load it. 166 if not arg.endswith('.py'): 167 panic("Config file '%s' must end in '.py'\n" % arg) 168 configfile_found = True 169 m5execfile(arg, globals()) 170 171 172if not configfile_found: 173 panic("no configuration file specified!") 174 175if globals().has_key('root') and isinstance(root, Root): 176 sys.stdout = file('config.ini', 'w') 177 instantiate(root) 178else: 179 print 'Instantiation skipped: no root object found.' 180 |