2005-06-05 07:57:57 +02:00
|
|
|
# Copyright (c) 2005 The Regents of The University of Michigan
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions are
|
|
|
|
# met: redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer;
|
|
|
|
# redistributions in binary form must reproduce the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution;
|
|
|
|
# neither the name of the copyright holders nor the names of its
|
|
|
|
# contributors may be used to endorse or promote products derived from
|
|
|
|
# this software without specific prior written permission.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2006-06-01 01:26:56 +02:00
|
|
|
#
|
|
|
|
# Authors: Nathan Binkert
|
|
|
|
# Steve Reinhardt
|
2005-06-05 07:57:57 +02:00
|
|
|
|
2006-06-10 05:01:31 +02:00
|
|
|
import sys, os, time, atexit, optparse
|
2006-05-30 19:11:34 +02:00
|
|
|
|
2006-06-10 05:01:31 +02:00
|
|
|
# import the SWIG-wrapped main C++ functions
|
2006-06-17 18:08:19 +02:00
|
|
|
import cc_main
|
2006-06-10 05:01:31 +02:00
|
|
|
# import a few SWIG-wrapped items (those that are likely to be used
|
|
|
|
# directly by user scripts) completely into this module for
|
|
|
|
# convenience
|
2006-06-17 18:08:19 +02:00
|
|
|
from cc_main import simulate, SimLoopExitEvent
|
2006-05-30 19:11:34 +02:00
|
|
|
|
2006-06-10 05:01:31 +02:00
|
|
|
# import the m5 compile options
|
|
|
|
import defines
|
2005-03-14 13:46:26 +01:00
|
|
|
|
|
|
|
# define this here so we can use it right away if necessary
|
|
|
|
def panic(string):
|
|
|
|
print >>sys.stderr, 'panic:', string
|
|
|
|
sys.exit(1)
|
|
|
|
|
2006-06-10 05:01:31 +02:00
|
|
|
# Prepend given directory to system module search path. We may not
|
|
|
|
# need this anymore if we can structure our config library more like a
|
|
|
|
# Python package.
|
2005-05-29 07:14:50 +02:00
|
|
|
def AddToPath(path):
|
2005-09-05 22:31:27 +02:00
|
|
|
# if it's a relative path and we know what directory the current
|
|
|
|
# python script is in, make the path relative to that directory.
|
|
|
|
if not os.path.isabs(path) and sys.path[0]:
|
|
|
|
path = os.path.join(sys.path[0], path)
|
2005-05-29 07:14:50 +02:00
|
|
|
path = os.path.realpath(path)
|
2005-09-05 22:31:27 +02:00
|
|
|
# sys.path[0] should always refer to the current script's directory,
|
|
|
|
# so place the new dir right after that.
|
|
|
|
sys.path.insert(1, path)
|
2005-03-18 19:34:28 +01:00
|
|
|
|
2006-06-10 05:01:31 +02:00
|
|
|
|
2006-06-17 15:58:10 +02:00
|
|
|
# The m5 module's pointer to the parsed options object
|
|
|
|
options = None
|
|
|
|
|
|
|
|
|
|
|
|
# User should call this function after calling parse_args() to pass
|
|
|
|
# parsed standard option values back into the m5 module for
|
|
|
|
# processing.
|
|
|
|
def setStandardOptions(_options):
|
|
|
|
# Set module global var
|
|
|
|
global options
|
|
|
|
options = _options
|
|
|
|
# tell C++ about output directory
|
2006-06-17 18:08:19 +02:00
|
|
|
cc_main.setOutputDir(options.outdir)
|
2006-06-17 15:58:10 +02:00
|
|
|
|
2006-06-10 05:01:31 +02:00
|
|
|
# Callback to set trace flags. Not necessarily the best way to do
|
|
|
|
# things in the long run (particularly if we change how these global
|
|
|
|
# options are handled).
|
|
|
|
def setTraceFlags(option, opt_str, value, parser):
|
|
|
|
objects.Trace.flags = value
|
|
|
|
|
2006-06-14 04:39:31 +02:00
|
|
|
def setTraceStart(option, opt_str, value, parser):
|
|
|
|
objects.Trace.start = value
|
|
|
|
|
2006-06-17 03:18:19 +02:00
|
|
|
def setTraceFile(option, opt_str, value, parser):
|
|
|
|
objects.Trace.file = value
|
2006-06-14 04:39:31 +02:00
|
|
|
|
2006-06-18 04:04:48 +02:00
|
|
|
def noPCSymbol(option, opt_str, value, parser):
|
|
|
|
objects.ExecutionTrace.pc_symbol = False
|
2006-06-17 03:18:19 +02:00
|
|
|
|
2006-06-18 04:04:48 +02:00
|
|
|
def noPrintCycle(option, opt_str, value, parser):
|
|
|
|
objects.ExecutionTrace.print_cycle = False
|
2006-06-17 03:18:19 +02:00
|
|
|
|
2006-06-18 04:04:48 +02:00
|
|
|
def noPrintOpclass(option, opt_str, value, parser):
|
|
|
|
objects.ExecutionTrace.print_opclass = False
|
2006-06-17 03:18:19 +02:00
|
|
|
|
2006-06-18 04:04:48 +02:00
|
|
|
def noPrintThread(option, opt_str, value, parser):
|
|
|
|
objects.ExecutionTrace.print_thread = False
|
2006-06-17 03:18:19 +02:00
|
|
|
|
2006-06-18 04:04:48 +02:00
|
|
|
def noPrintEA(option, opt_str, value, parser):
|
|
|
|
objects.ExecutionTrace.print_effaddr = False
|
2006-06-17 03:18:19 +02:00
|
|
|
|
2006-06-18 04:04:48 +02:00
|
|
|
def noPrintData(option, opt_str, value, parser):
|
|
|
|
objects.ExecutionTrace.print_data = False
|
2006-06-17 03:18:19 +02:00
|
|
|
|
|
|
|
def printFetchseq(option, opt_str, value, parser):
|
2006-06-18 04:04:48 +02:00
|
|
|
objects.ExecutionTrace.print_fetchseq = True
|
2006-06-17 03:18:19 +02:00
|
|
|
|
|
|
|
def printCpseq(option, opt_str, value, parser):
|
2006-06-18 04:04:48 +02:00
|
|
|
objects.ExecutionTrace.print_cpseq = True
|
2006-06-17 03:18:19 +02:00
|
|
|
|
|
|
|
def dumpOnExit(option, opt_str, value, parser):
|
2006-06-18 04:04:48 +02:00
|
|
|
objects.Trace.dump_on_exit = True
|
2006-06-17 03:18:19 +02:00
|
|
|
|
|
|
|
def debugBreak(option, opt_str, value, parser):
|
|
|
|
objects.Debug.break_cycles = value
|
2006-06-14 04:39:31 +02:00
|
|
|
|
|
|
|
def statsTextFile(option, opt_str, value, parser):
|
|
|
|
objects.Statistics.text_file = value
|
|
|
|
|
2006-06-17 03:18:19 +02:00
|
|
|
# Extra list to help for options that are true or false
|
|
|
|
TrueOrFalse = ['True', 'False']
|
|
|
|
TorF = "True | False"
|
|
|
|
|
2006-06-10 05:01:31 +02:00
|
|
|
# Standard optparse options. Need to be explicitly included by the
|
|
|
|
# user script when it calls optparse.OptionParser().
|
|
|
|
standardOptions = [
|
2006-06-17 15:58:10 +02:00
|
|
|
optparse.make_option("--outdir", type="string", default="."),
|
2006-06-10 05:01:31 +02:00
|
|
|
optparse.make_option("--traceflags", type="string", action="callback",
|
2006-06-14 04:39:31 +02:00
|
|
|
callback=setTraceFlags),
|
|
|
|
optparse.make_option("--tracestart", type="int", action="callback",
|
|
|
|
callback=setTraceStart),
|
2006-06-17 03:18:19 +02:00
|
|
|
optparse.make_option("--tracefile", type="string", action="callback",
|
|
|
|
callback=setTraceFile),
|
2006-06-18 04:04:48 +02:00
|
|
|
optparse.make_option("--nopcsymbol",
|
|
|
|
action="callback", callback=noPCSymbol,
|
|
|
|
help="Disable PC symbols in trace output"),
|
|
|
|
optparse.make_option("--noprintcycle",
|
|
|
|
action="callback", callback=noPrintCycle,
|
|
|
|
help="Don't print cycle numbers in trace output"),
|
|
|
|
optparse.make_option("--noprintopclass",
|
|
|
|
action="callback", callback=noPrintOpclass,
|
|
|
|
help="Don't print op class type in trace output"),
|
|
|
|
optparse.make_option("--noprintthread",
|
|
|
|
action="callback", callback=noPrintThread,
|
|
|
|
help="Don't print thread number in trace output"),
|
|
|
|
optparse.make_option("--noprinteffaddr",
|
|
|
|
action="callback", callback=noPrintEA,
|
|
|
|
help="Don't print effective address in trace output"),
|
|
|
|
optparse.make_option("--noprintdata",
|
|
|
|
action="callback", callback=noPrintData,
|
|
|
|
help="Don't print result data in trace output"),
|
|
|
|
optparse.make_option("--printfetchseq",
|
2006-06-17 03:18:19 +02:00
|
|
|
action="callback", callback=printFetchseq,
|
|
|
|
help="Print fetch sequence numbers in trace output"),
|
2006-06-18 04:04:48 +02:00
|
|
|
optparse.make_option("--printcpseq",
|
2006-06-17 03:18:19 +02:00
|
|
|
action="callback", callback=printCpseq,
|
|
|
|
help="Print correct path sequence numbers in trace output"),
|
2006-06-18 04:04:48 +02:00
|
|
|
optparse.make_option("--dumponexit",
|
2006-06-17 03:18:19 +02:00
|
|
|
action="callback", callback=dumpOnExit,
|
|
|
|
help="Dump trace buffer on exit"),
|
|
|
|
optparse.make_option("--debugbreak", type="int", metavar="CYCLE",
|
|
|
|
action="callback", callback=debugBreak,
|
|
|
|
help="Cycle to create a breakpoint"),
|
2006-06-14 04:39:31 +02:00
|
|
|
optparse.make_option("--statsfile", type="string", action="callback",
|
|
|
|
callback=statsTextFile, metavar="FILE",
|
|
|
|
help="Sets the output file for the statistics")
|
2006-06-10 05:01:31 +02:00
|
|
|
]
|
2005-03-14 13:46:26 +01:00
|
|
|
|
|
|
|
# make a SmartDict out of the build options for our local use
|
|
|
|
import smartdict
|
|
|
|
build_env = smartdict.SmartDict()
|
2006-06-10 05:01:31 +02:00
|
|
|
build_env.update(defines.m5_build_env)
|
2005-03-14 13:46:26 +01:00
|
|
|
|
|
|
|
# make a SmartDict out of the OS environment too
|
|
|
|
env = smartdict.SmartDict()
|
|
|
|
env.update(os.environ)
|
|
|
|
|
2006-06-14 05:19:28 +02:00
|
|
|
|
|
|
|
# Function to provide to C++ so it can look up instances based on paths
|
|
|
|
def resolveSimObject(name):
|
|
|
|
obj = config.instanceDict[name]
|
2006-06-15 17:45:51 +02:00
|
|
|
return obj.getCCObject()
|
2006-06-14 05:19:28 +02:00
|
|
|
|
2006-06-10 05:01:31 +02:00
|
|
|
# The final hook to generate .ini files. Called from the user script
|
|
|
|
# once the config is built.
|
|
|
|
def instantiate(root):
|
|
|
|
config.ticks_per_sec = float(root.clock.frequency)
|
|
|
|
# ugly temporary hack to get output to config.ini
|
2006-06-17 15:58:10 +02:00
|
|
|
sys.stdout = file(os.path.join(options.outdir, 'config.ini'), 'w')
|
2006-06-10 05:01:31 +02:00
|
|
|
root.print_ini()
|
|
|
|
sys.stdout.close() # close config.ini
|
|
|
|
sys.stdout = sys.__stdout__ # restore to original
|
2006-06-17 18:08:19 +02:00
|
|
|
cc_main.loadIniFile(resolveSimObject) # load config.ini into C++
|
2006-06-14 05:19:28 +02:00
|
|
|
root.createCCObject()
|
|
|
|
root.connectPorts()
|
2006-06-17 18:08:19 +02:00
|
|
|
cc_main.finalInit()
|
2006-06-10 05:01:31 +02:00
|
|
|
noDot = True # temporary until we fix dot
|
|
|
|
if not noDot:
|
|
|
|
dot = pydot.Dot()
|
|
|
|
instance.outputDot(dot)
|
|
|
|
dot.orientation = "portrait"
|
|
|
|
dot.size = "8.5,11"
|
|
|
|
dot.ranksep="equally"
|
|
|
|
dot.rank="samerank"
|
|
|
|
dot.write("config.dot")
|
|
|
|
dot.write_ps("config.ps")
|
|
|
|
|
|
|
|
# Export curTick to user script.
|
|
|
|
def curTick():
|
2006-06-17 18:08:19 +02:00
|
|
|
return cc_main.cvar.curTick
|
2006-06-10 05:01:31 +02:00
|
|
|
|
|
|
|
# register our C++ exit callback function with Python
|
2006-06-17 18:08:19 +02:00
|
|
|
atexit.register(cc_main.doExitCleanup)
|
2006-06-10 05:01:31 +02:00
|
|
|
|
|
|
|
# This import allows user scripts to reference 'm5.objects.Foo' after
|
|
|
|
# just doing an 'import m5' (without an 'import m5.objects'). May not
|
|
|
|
# matter since most scripts will probably 'from m5.objects import *'.
|
|
|
|
import objects
|