__init__.py revision 2728
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 302667Sstever@eecs.umich.eduimport sys, os, time, atexit, optparse 312655Sstever@eecs.umich.edu 322667Sstever@eecs.umich.edu# import the SWIG-wrapped main C++ functions 332667Sstever@eecs.umich.eduimport main 342667Sstever@eecs.umich.edu# import a few SWIG-wrapped items (those that are likely to be used 352667Sstever@eecs.umich.edu# directly by user scripts) completely into this module for 362667Sstever@eecs.umich.edu# convenience 372667Sstever@eecs.umich.edufrom main import simulate, SimLoopExitEvent 382655Sstever@eecs.umich.edu 392667Sstever@eecs.umich.edu# import the m5 compile options 402667Sstever@eecs.umich.eduimport defines 411530SN/A 421530SN/A# define this here so we can use it right away if necessary 431530SN/Adef panic(string): 441530SN/A print >>sys.stderr, 'panic:', string 451530SN/A sys.exit(1) 461530SN/A 472667Sstever@eecs.umich.edu# Prepend given directory to system module search path. We may not 482667Sstever@eecs.umich.edu# need this anymore if we can structure our config library more like a 492667Sstever@eecs.umich.edu# Python package. 501692SN/Adef AddToPath(path): 511869SN/A # if it's a relative path and we know what directory the current 521869SN/A # python script is in, make the path relative to that directory. 531869SN/A if not os.path.isabs(path) and sys.path[0]: 541869SN/A path = os.path.join(sys.path[0], path) 551692SN/A path = os.path.realpath(path) 561869SN/A # sys.path[0] should always refer to the current script's directory, 571869SN/A # so place the new dir right after that. 581869SN/A sys.path.insert(1, path) 591581SN/A 602667Sstever@eecs.umich.edu 612667Sstever@eecs.umich.edu# Callback to set trace flags. Not necessarily the best way to do 622667Sstever@eecs.umich.edu# things in the long run (particularly if we change how these global 632667Sstever@eecs.umich.edu# options are handled). 642667Sstever@eecs.umich.edudef setTraceFlags(option, opt_str, value, parser): 652667Sstever@eecs.umich.edu objects.Trace.flags = value 662667Sstever@eecs.umich.edu 672728Sktlim@umich.edudef setTraceStart(option, opt_str, value, parser): 682728Sktlim@umich.edu objects.Trace.start = value 692728Sktlim@umich.edu 702728Sktlim@umich.edudef clearPCSymbol(option, opt_str, value, parser): 712728Sktlim@umich.edu objects.ExecutionTrace.pc_symbol = False 722728Sktlim@umich.edu 732728Sktlim@umich.edudef clearPrintCycle(option, opt_str, value, parser): 742728Sktlim@umich.edu objects.ExecutionTrace.print_cycle = False 752728Sktlim@umich.edu 762728Sktlim@umich.edudef statsTextFile(option, opt_str, value, parser): 772728Sktlim@umich.edu objects.Statistics.text_file = value 782728Sktlim@umich.edu 792667Sstever@eecs.umich.edu# Standard optparse options. Need to be explicitly included by the 802667Sstever@eecs.umich.edu# user script when it calls optparse.OptionParser(). 812667Sstever@eecs.umich.edustandardOptions = [ 822667Sstever@eecs.umich.edu optparse.make_option("--traceflags", type="string", action="callback", 832728Sktlim@umich.edu callback=setTraceFlags), 842728Sktlim@umich.edu optparse.make_option("--tracestart", type="int", action="callback", 852728Sktlim@umich.edu callback=setTraceStart), 862728Sktlim@umich.edu optparse.make_option("--nopcsymbol", action="callback", 872728Sktlim@umich.edu callback=clearPCSymbol, 882728Sktlim@umich.edu help="Turn off printing PC symbols in trace output"), 892728Sktlim@umich.edu optparse.make_option("--noprintcycle", action="callback", 902728Sktlim@umich.edu callback=clearPrintCycle, 912728Sktlim@umich.edu help="Turn off printing cycles in trace output"), 922728Sktlim@umich.edu optparse.make_option("--statsfile", type="string", action="callback", 932728Sktlim@umich.edu callback=statsTextFile, metavar="FILE", 942728Sktlim@umich.edu help="Sets the output file for the statistics") 952667Sstever@eecs.umich.edu ] 961530SN/A 971530SN/A# make a SmartDict out of the build options for our local use 981530SN/Aimport smartdict 991530SN/Abuild_env = smartdict.SmartDict() 1002667Sstever@eecs.umich.edubuild_env.update(defines.m5_build_env) 1011530SN/A 1021530SN/A# make a SmartDict out of the OS environment too 1031530SN/Aenv = smartdict.SmartDict() 1041530SN/Aenv.update(os.environ) 1051530SN/A 1062667Sstever@eecs.umich.edu# The final hook to generate .ini files. Called from the user script 1072667Sstever@eecs.umich.edu# once the config is built. 1082667Sstever@eecs.umich.edudef instantiate(root): 1092667Sstever@eecs.umich.edu config.ticks_per_sec = float(root.clock.frequency) 1102667Sstever@eecs.umich.edu # ugly temporary hack to get output to config.ini 1112667Sstever@eecs.umich.edu sys.stdout = file('config.ini', 'w') 1122667Sstever@eecs.umich.edu root.print_ini() 1132667Sstever@eecs.umich.edu sys.stdout.close() # close config.ini 1142667Sstever@eecs.umich.edu sys.stdout = sys.__stdout__ # restore to original 1152667Sstever@eecs.umich.edu main.initialize() # load config.ini into C++ and process it 1162667Sstever@eecs.umich.edu noDot = True # temporary until we fix dot 1172667Sstever@eecs.umich.edu if not noDot: 1182667Sstever@eecs.umich.edu dot = pydot.Dot() 1192667Sstever@eecs.umich.edu instance.outputDot(dot) 1202667Sstever@eecs.umich.edu dot.orientation = "portrait" 1212667Sstever@eecs.umich.edu dot.size = "8.5,11" 1222667Sstever@eecs.umich.edu dot.ranksep="equally" 1232667Sstever@eecs.umich.edu dot.rank="samerank" 1242667Sstever@eecs.umich.edu dot.write("config.dot") 1252667Sstever@eecs.umich.edu dot.write_ps("config.ps") 1261527SN/A 1272667Sstever@eecs.umich.edu# Export curTick to user script. 1282667Sstever@eecs.umich.edudef curTick(): 1292667Sstever@eecs.umich.edu return main.cvar.curTick 1301511SN/A 1312667Sstever@eecs.umich.edu# register our C++ exit callback function with Python 1322667Sstever@eecs.umich.eduatexit.register(main.doExitCleanup) 1332655Sstever@eecs.umich.edu 1342667Sstever@eecs.umich.edu# This import allows user scripts to reference 'm5.objects.Foo' after 1352667Sstever@eecs.umich.edu# just doing an 'import m5' (without an 'import m5.objects'). May not 1362667Sstever@eecs.umich.edu# matter since most scripts will probably 'from m5.objects import *'. 1372667Sstever@eecs.umich.eduimport objects 138