__init__.py revision 2767
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 702759Sktlim@umich.edudef setTraceFile(option, opt_str, value, parser): 712759Sktlim@umich.edu objects.Trace.file = value 722728Sktlim@umich.edu 732767Sktlim@umich.edudef noPCSymbol(option, opt_str, value, parser): 742767Sktlim@umich.edu objects.ExecutionTrace.pc_symbol = False 752759Sktlim@umich.edu 762767Sktlim@umich.edudef noPrintCycle(option, opt_str, value, parser): 772767Sktlim@umich.edu objects.ExecutionTrace.print_cycle = False 782759Sktlim@umich.edu 792767Sktlim@umich.edudef noPrintOpclass(option, opt_str, value, parser): 802767Sktlim@umich.edu objects.ExecutionTrace.print_opclass = False 812759Sktlim@umich.edu 822767Sktlim@umich.edudef noPrintThread(option, opt_str, value, parser): 832767Sktlim@umich.edu objects.ExecutionTrace.print_thread = False 842759Sktlim@umich.edu 852767Sktlim@umich.edudef noPrintEA(option, opt_str, value, parser): 862767Sktlim@umich.edu objects.ExecutionTrace.print_effaddr = False 872759Sktlim@umich.edu 882767Sktlim@umich.edudef noPrintData(option, opt_str, value, parser): 892767Sktlim@umich.edu objects.ExecutionTrace.print_data = False 902759Sktlim@umich.edu 912759Sktlim@umich.edudef printFetchseq(option, opt_str, value, parser): 922767Sktlim@umich.edu objects.ExecutionTrace.print_fetchseq = True 932759Sktlim@umich.edu 942759Sktlim@umich.edudef printCpseq(option, opt_str, value, parser): 952767Sktlim@umich.edu objects.ExecutionTrace.print_cpseq = True 962759Sktlim@umich.edu 972759Sktlim@umich.edudef dumpOnExit(option, opt_str, value, parser): 982767Sktlim@umich.edu objects.Trace.dump_on_exit = True 992759Sktlim@umich.edu 1002759Sktlim@umich.edudef debugBreak(option, opt_str, value, parser): 1012759Sktlim@umich.edu objects.Debug.break_cycles = value 1022728Sktlim@umich.edu 1032728Sktlim@umich.edudef statsTextFile(option, opt_str, value, parser): 1042728Sktlim@umich.edu objects.Statistics.text_file = value 1052728Sktlim@umich.edu 1062759Sktlim@umich.edu# Extra list to help for options that are true or false 1072759Sktlim@umich.eduTrueOrFalse = ['True', 'False'] 1082759Sktlim@umich.eduTorF = "True | False" 1092759Sktlim@umich.edu 1102667Sstever@eecs.umich.edu# Standard optparse options. Need to be explicitly included by the 1112667Sstever@eecs.umich.edu# user script when it calls optparse.OptionParser(). 1122667Sstever@eecs.umich.edustandardOptions = [ 1132667Sstever@eecs.umich.edu optparse.make_option("--traceflags", type="string", action="callback", 1142728Sktlim@umich.edu callback=setTraceFlags), 1152728Sktlim@umich.edu optparse.make_option("--tracestart", type="int", action="callback", 1162728Sktlim@umich.edu callback=setTraceStart), 1172759Sktlim@umich.edu optparse.make_option("--tracefile", type="string", action="callback", 1182759Sktlim@umich.edu callback=setTraceFile), 1192767Sktlim@umich.edu optparse.make_option("--nopcsymbol", 1202767Sktlim@umich.edu action="callback", callback=noPCSymbol, 1212767Sktlim@umich.edu help="Disable PC symbols in trace output"), 1222767Sktlim@umich.edu optparse.make_option("--noprintcycle", 1232767Sktlim@umich.edu action="callback", callback=noPrintCycle, 1242767Sktlim@umich.edu help="Don't print cycle numbers in trace output"), 1252767Sktlim@umich.edu optparse.make_option("--noprintopclass", 1262767Sktlim@umich.edu action="callback", callback=noPrintOpclass, 1272767Sktlim@umich.edu help="Don't print op class type in trace output"), 1282767Sktlim@umich.edu optparse.make_option("--noprintthread", 1292767Sktlim@umich.edu action="callback", callback=noPrintThread, 1302767Sktlim@umich.edu help="Don't print thread number in trace output"), 1312767Sktlim@umich.edu optparse.make_option("--noprinteffaddr", 1322767Sktlim@umich.edu action="callback", callback=noPrintEA, 1332767Sktlim@umich.edu help="Don't print effective address in trace output"), 1342767Sktlim@umich.edu optparse.make_option("--noprintdata", 1352767Sktlim@umich.edu action="callback", callback=noPrintData, 1362767Sktlim@umich.edu help="Don't print result data in trace output"), 1372767Sktlim@umich.edu optparse.make_option("--printfetchseq", 1382759Sktlim@umich.edu action="callback", callback=printFetchseq, 1392759Sktlim@umich.edu help="Print fetch sequence numbers in trace output"), 1402767Sktlim@umich.edu optparse.make_option("--printcpseq", 1412759Sktlim@umich.edu action="callback", callback=printCpseq, 1422759Sktlim@umich.edu help="Print correct path sequence numbers in trace output"), 1432767Sktlim@umich.edu optparse.make_option("--dumponexit", 1442759Sktlim@umich.edu action="callback", callback=dumpOnExit, 1452759Sktlim@umich.edu help="Dump trace buffer on exit"), 1462759Sktlim@umich.edu optparse.make_option("--debugbreak", type="int", metavar="CYCLE", 1472759Sktlim@umich.edu action="callback", callback=debugBreak, 1482759Sktlim@umich.edu help="Cycle to create a breakpoint"), 1492728Sktlim@umich.edu optparse.make_option("--statsfile", type="string", action="callback", 1502728Sktlim@umich.edu callback=statsTextFile, metavar="FILE", 1512728Sktlim@umich.edu help="Sets the output file for the statistics") 1522667Sstever@eecs.umich.edu ] 1531530SN/A 1541530SN/A# make a SmartDict out of the build options for our local use 1551530SN/Aimport smartdict 1561530SN/Abuild_env = smartdict.SmartDict() 1572667Sstever@eecs.umich.edubuild_env.update(defines.m5_build_env) 1581530SN/A 1591530SN/A# make a SmartDict out of the OS environment too 1601530SN/Aenv = smartdict.SmartDict() 1611530SN/Aenv.update(os.environ) 1621530SN/A 1632738Sstever@eecs.umich.edu 1642738Sstever@eecs.umich.edu# Function to provide to C++ so it can look up instances based on paths 1652738Sstever@eecs.umich.edudef resolveSimObject(name): 1662738Sstever@eecs.umich.edu obj = config.instanceDict[name] 1672740Sstever@eecs.umich.edu return obj.getCCObject() 1682738Sstever@eecs.umich.edu 1692667Sstever@eecs.umich.edu# The final hook to generate .ini files. Called from the user script 1702667Sstever@eecs.umich.edu# once the config is built. 1712667Sstever@eecs.umich.edudef instantiate(root): 1722667Sstever@eecs.umich.edu config.ticks_per_sec = float(root.clock.frequency) 1732667Sstever@eecs.umich.edu # ugly temporary hack to get output to config.ini 1742667Sstever@eecs.umich.edu sys.stdout = file('config.ini', 'w') 1752667Sstever@eecs.umich.edu root.print_ini() 1762667Sstever@eecs.umich.edu sys.stdout.close() # close config.ini 1772667Sstever@eecs.umich.edu sys.stdout = sys.__stdout__ # restore to original 1782738Sstever@eecs.umich.edu main.loadIniFile(resolveSimObject) # load config.ini into C++ 1792738Sstever@eecs.umich.edu root.createCCObject() 1802738Sstever@eecs.umich.edu root.connectPorts() 1812738Sstever@eecs.umich.edu main.finalInit() 1822667Sstever@eecs.umich.edu noDot = True # temporary until we fix dot 1832667Sstever@eecs.umich.edu if not noDot: 1842667Sstever@eecs.umich.edu dot = pydot.Dot() 1852667Sstever@eecs.umich.edu instance.outputDot(dot) 1862667Sstever@eecs.umich.edu dot.orientation = "portrait" 1872667Sstever@eecs.umich.edu dot.size = "8.5,11" 1882667Sstever@eecs.umich.edu dot.ranksep="equally" 1892667Sstever@eecs.umich.edu dot.rank="samerank" 1902667Sstever@eecs.umich.edu dot.write("config.dot") 1912667Sstever@eecs.umich.edu dot.write_ps("config.ps") 1921527SN/A 1932667Sstever@eecs.umich.edu# Export curTick to user script. 1942667Sstever@eecs.umich.edudef curTick(): 1952667Sstever@eecs.umich.edu return main.cvar.curTick 1961511SN/A 1972667Sstever@eecs.umich.edu# register our C++ exit callback function with Python 1982667Sstever@eecs.umich.eduatexit.register(main.doExitCleanup) 1992655Sstever@eecs.umich.edu 2002667Sstever@eecs.umich.edu# This import allows user scripts to reference 'm5.objects.Foo' after 2012667Sstever@eecs.umich.edu# just doing an 'import m5' (without an 'import m5.objects'). May not 2022667Sstever@eecs.umich.edu# matter since most scripts will probably 'from m5.objects import *'. 2032667Sstever@eecs.umich.eduimport objects 204