__init__.py (2632:1bb2f91485ea) __init__.py (2655:da93a2088efa)
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
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
27import sys, os
27import sys, os, time
28
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
29# define this here so we can use it right away if necessary
30def panic(string):
31 print >>sys.stderr, 'panic:', string
32 sys.exit(1)
33
34def m5execfile(f, global_dict):
35 # copy current sys.path
36 oldpath = sys.path[:]
37 # push file's directory onto front of path
38 sys.path.insert(0, os.path.abspath(os.path.dirname(f)))
39 execfile(f, global_dict)
40 # restore original path
41 sys.path = oldpath
42
43# Prepend given directory to system module search path.
44def AddToPath(path):
45 # if it's a relative path and we know what directory the current
46 # python script is in, make the path relative to that directory.
47 if not os.path.isabs(path) and sys.path[0]:
48 path = os.path.join(sys.path[0], path)
49 path = os.path.realpath(path)
50 # sys.path[0] should always refer to the current script's directory,
51 # so place the new dir right after that.
52 sys.path.insert(1, path)
53
54# find the m5 compile options: must be specified as a dict in
55# __main__.m5_build_env.
56import __main__
57if not hasattr(__main__, 'm5_build_env'):
58 panic("__main__ must define m5_build_env")
59
60# make a SmartDict out of the build options for our local use
61import smartdict
62build_env = smartdict.SmartDict()
63build_env.update(__main__.m5_build_env)
64
65# make a SmartDict out of the OS environment too
66env = smartdict.SmartDict()
67env.update(os.environ)
68
69# import the main m5 config code
70from config import *
71
72# import the built-in object definitions
73from objects import *
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[:]
83 # push file's directory onto front of path
84 sys.path.insert(0, os.path.abspath(os.path.dirname(f)))
85 execfile(f, global_dict)
86 # restore original path
87 sys.path = oldpath
88
89# Prepend given directory to system module search path.
90def AddToPath(path):
91 # if it's a relative path and we know what directory the current
92 # python script is in, make the path relative to that directory.
93 if not os.path.isabs(path) and sys.path[0]:
94 path = os.path.join(sys.path[0], path)
95 path = os.path.realpath(path)
96 # sys.path[0] should always refer to the current script's directory,
97 # so place the new dir right after that.
98 sys.path.insert(1, path)
99
100# find the m5 compile options: must be specified as a dict in
101# __main__.m5_build_env.
102import __main__
103if not hasattr(__main__, 'm5_build_env'):
104 panic("__main__ must define m5_build_env")
105
106# make a SmartDict out of the build options for our local use
107import smartdict
108build_env = smartdict.SmartDict()
109build_env.update(__main__.m5_build_env)
110
111# make a SmartDict out of the OS environment too
112env = smartdict.SmartDict()
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