trace: reimplement the DTRACE function so it doesn't use a vector
At the same time, rename the trace flags to debug flags since they have broader usage than simply tracing. This means that --trace-flags is now --debug-flags and --trace-help is now --debug-help
This commit is contained in:
258
src/SConscript
258
src/SConscript
@@ -198,21 +198,23 @@ Export('UnitTest')
|
||||
|
||||
########################################################################
|
||||
#
|
||||
# Trace Flags
|
||||
# Debug Flags
|
||||
#
|
||||
trace_flags = {}
|
||||
def TraceFlag(name, desc=None):
|
||||
if name in trace_flags:
|
||||
debug_flags = {}
|
||||
def DebugFlag(name, desc=None):
|
||||
if name in debug_flags:
|
||||
raise AttributeError, "Flag %s already specified" % name
|
||||
trace_flags[name] = (name, (), desc)
|
||||
debug_flags[name] = (name, (), desc)
|
||||
TraceFlag = DebugFlag
|
||||
|
||||
def CompoundFlag(name, flags, desc=None):
|
||||
if name in trace_flags:
|
||||
if name in debug_flags:
|
||||
raise AttributeError, "Flag %s already specified" % name
|
||||
|
||||
compound = tuple(flags)
|
||||
trace_flags[name] = (name, compound, desc)
|
||||
debug_flags[name] = (name, compound, desc)
|
||||
|
||||
Export('DebugFlag')
|
||||
Export('TraceFlag')
|
||||
Export('CompoundFlag')
|
||||
|
||||
@@ -622,81 +624,16 @@ for swig in SwigSource.all:
|
||||
MakeAction(makeEmbeddedSwigInit, Transform("EMBED SW")))
|
||||
Source(init_file)
|
||||
|
||||
def getFlags(source_flags):
|
||||
flagsMap = {}
|
||||
flagsList = []
|
||||
for s in source_flags:
|
||||
val = eval(s.get_contents())
|
||||
name, compound, desc = val
|
||||
flagsList.append(val)
|
||||
flagsMap[name] = bool(compound)
|
||||
|
||||
for name, compound, desc in flagsList:
|
||||
for flag in compound:
|
||||
if flag not in flagsMap:
|
||||
raise AttributeError, "Trace flag %s not found" % flag
|
||||
if flagsMap[flag]:
|
||||
raise AttributeError, \
|
||||
"Compound flag can't point to another compound flag"
|
||||
#
|
||||
# Handle debug flags
|
||||
#
|
||||
def makeDebugFlagCC(target, source, env):
|
||||
assert(len(target) == 1 and len(source) == 1)
|
||||
|
||||
flagsList.sort()
|
||||
return flagsList
|
||||
val = eval(source[0].get_contents())
|
||||
name, compound, desc = val
|
||||
compound = list(sorted(compound))
|
||||
|
||||
|
||||
# Generate traceflags.py
|
||||
def traceFlagsPy(target, source, env):
|
||||
assert(len(target) == 1)
|
||||
code = code_formatter()
|
||||
|
||||
allFlags = getFlags(source)
|
||||
|
||||
code('basic = [')
|
||||
code.indent()
|
||||
for flag, compound, desc in allFlags:
|
||||
if not compound:
|
||||
code("'$flag',")
|
||||
code(']')
|
||||
code.dedent()
|
||||
code()
|
||||
|
||||
code('compound = [')
|
||||
code.indent()
|
||||
code("'All',")
|
||||
for flag, compound, desc in allFlags:
|
||||
if compound:
|
||||
code("'$flag',")
|
||||
code("]")
|
||||
code.dedent()
|
||||
code()
|
||||
|
||||
code("all = frozenset(basic + compound)")
|
||||
code()
|
||||
|
||||
code('compoundMap = {')
|
||||
code.indent()
|
||||
all = tuple([flag for flag,compound,desc in allFlags if not compound])
|
||||
code("'All' : $all,")
|
||||
for flag, compound, desc in allFlags:
|
||||
if compound:
|
||||
code("'$flag' : $compound,")
|
||||
code('}')
|
||||
code.dedent()
|
||||
code()
|
||||
|
||||
code('descriptions = {')
|
||||
code.indent()
|
||||
code("'All' : 'All flags',")
|
||||
for flag, compound, desc in allFlags:
|
||||
code("'$flag' : '$desc',")
|
||||
code("}")
|
||||
code.dedent()
|
||||
|
||||
code.write(str(target[0]))
|
||||
|
||||
def traceFlagsCC(target, source, env):
|
||||
assert(len(target) == 1)
|
||||
|
||||
allFlags = getFlags(source)
|
||||
code = code_formatter()
|
||||
|
||||
# file header
|
||||
@@ -705,75 +642,39 @@ def traceFlagsCC(target, source, env):
|
||||
* DO NOT EDIT THIS FILE! Automatically generated
|
||||
*/
|
||||
|
||||
#include "base/traceflags.hh"
|
||||
|
||||
using namespace Trace;
|
||||
|
||||
const char *Trace::flagStrings[] =
|
||||
{''')
|
||||
|
||||
code.indent()
|
||||
# The string array is used by SimpleEnumParam to map the strings
|
||||
# provided by the user to enum values.
|
||||
for flag, compound, desc in allFlags:
|
||||
if not compound:
|
||||
code('"$flag",')
|
||||
|
||||
code('"All",')
|
||||
for flag, compound, desc in allFlags:
|
||||
if compound:
|
||||
code('"$flag",')
|
||||
code.dedent()
|
||||
|
||||
code('''\
|
||||
};
|
||||
|
||||
const int Trace::numFlagStrings = ${{len(allFlags) + 1}};
|
||||
|
||||
#include "base/debug.hh"
|
||||
''')
|
||||
|
||||
# Now define the individual compound flag arrays. There is an array
|
||||
# for each compound flag listing the component base flags.
|
||||
all = tuple([flag for flag,compound,desc in allFlags if not compound])
|
||||
code('static const Flags AllMap[] = {')
|
||||
code.indent()
|
||||
for flag, compound, desc in allFlags:
|
||||
if not compound:
|
||||
code('$flag,')
|
||||
code.dedent()
|
||||
code('};')
|
||||
for flag in compound:
|
||||
code('#include "debug/$flag.hh"')
|
||||
code()
|
||||
code('namespace Debug {')
|
||||
code()
|
||||
|
||||
for flag, compound, desc in allFlags:
|
||||
if not compound:
|
||||
continue
|
||||
code('static const Flags ${flag}Map[] = {')
|
||||
if not compound:
|
||||
code('SimpleFlag $name("$name", "$desc");')
|
||||
else:
|
||||
code('CompoundFlag $name("$name", "$desc",')
|
||||
code.indent()
|
||||
for flag in compound:
|
||||
code('$flag,')
|
||||
code('(Flags)-1')
|
||||
last = len(compound) - 1
|
||||
for i,flag in enumerate(compound):
|
||||
if i != last:
|
||||
code('$flag,')
|
||||
else:
|
||||
code('$flag);')
|
||||
code.dedent()
|
||||
code('};')
|
||||
code()
|
||||
|
||||
# Finally the compoundFlags[] array maps the compound flags
|
||||
# to their individual arrays/
|
||||
code('const Flags *Trace::compoundFlags[] = {')
|
||||
code.indent()
|
||||
code('AllMap,')
|
||||
for flag, compound, desc in allFlags:
|
||||
if compound:
|
||||
code('${flag}Map,')
|
||||
# file trailer
|
||||
code.dedent()
|
||||
code('};')
|
||||
code()
|
||||
code('} // namespace Debug')
|
||||
|
||||
code.write(str(target[0]))
|
||||
|
||||
def traceFlagsHH(target, source, env):
|
||||
assert(len(target) == 1)
|
||||
def makeDebugFlagHH(target, source, env):
|
||||
assert(len(target) == 1 and len(source) == 1)
|
||||
|
||||
val = eval(source[0].get_contents())
|
||||
name, compound, desc = val
|
||||
|
||||
allFlags = getFlags(source)
|
||||
code = code_formatter()
|
||||
|
||||
# file header boilerplate
|
||||
@@ -781,76 +682,43 @@ def traceFlagsHH(target, source, env):
|
||||
/*
|
||||
* DO NOT EDIT THIS FILE!
|
||||
*
|
||||
* Automatically generated from traceflags.py
|
||||
* Automatically generated by SCons
|
||||
*/
|
||||
|
||||
#ifndef __BASE_TRACE_FLAGS_HH__
|
||||
#define __BASE_TRACE_FLAGS_HH__
|
||||
#ifndef __DEBUG_${name}_HH__
|
||||
#define __DEBUG_${name}_HH__
|
||||
|
||||
namespace Trace {
|
||||
namespace Debug {
|
||||
''')
|
||||
|
||||
enum Flags {''')
|
||||
if compound:
|
||||
code('class CompoundFlag;')
|
||||
code('class SimpleFlag;')
|
||||
|
||||
# Generate the enum. Base flags come first, then compound flags.
|
||||
idx = 0
|
||||
code.indent()
|
||||
for flag, compound, desc in allFlags:
|
||||
if not compound:
|
||||
code('$flag = $idx,')
|
||||
idx += 1
|
||||
if compound:
|
||||
code('extern CompoundFlag $name;')
|
||||
for flag in compound:
|
||||
code('extern SimpleFlag $flag;')
|
||||
else:
|
||||
code('extern SimpleFlag $name;')
|
||||
|
||||
numBaseFlags = idx
|
||||
code('NumFlags = $idx,')
|
||||
code.dedent()
|
||||
code()
|
||||
|
||||
# put a comment in here to separate base from compound flags
|
||||
code('''
|
||||
// The remaining enum values are *not* valid indices for Trace::flags.
|
||||
// They are "compound" flags, which correspond to sets of base
|
||||
// flags, and are used by changeFlag.''')
|
||||
}
|
||||
|
||||
code.indent()
|
||||
code('All = $idx,')
|
||||
idx += 1
|
||||
for flag, compound, desc in allFlags:
|
||||
if compound:
|
||||
code('$flag = $idx,')
|
||||
idx += 1
|
||||
|
||||
numCompoundFlags = idx - numBaseFlags
|
||||
code('NumCompoundFlags = $numCompoundFlags')
|
||||
code.dedent()
|
||||
|
||||
# trailer boilerplate
|
||||
code('''\
|
||||
}; // enum Flags
|
||||
|
||||
// Array of strings for SimpleEnumParam
|
||||
extern const char *flagStrings[];
|
||||
extern const int numFlagStrings;
|
||||
|
||||
// Array of arraay pointers: for each compound flag, gives the list of
|
||||
// base flags to set. Inidividual flag arrays are terminated by -1.
|
||||
extern const Flags *compoundFlags[];
|
||||
|
||||
} // namespace Trace
|
||||
|
||||
#endif // __BASE_TRACE_FLAGS_HH__
|
||||
#endif // __DEBUG_${name}_HH__
|
||||
''')
|
||||
|
||||
code.write(str(target[0]))
|
||||
|
||||
flags = map(Value, trace_flags.values())
|
||||
env.Command('base/traceflags.py', flags,
|
||||
MakeAction(traceFlagsPy, Transform("TRACING", 0)))
|
||||
PySource('m5', 'base/traceflags.py')
|
||||
for name,flag in sorted(debug_flags.iteritems()):
|
||||
n, compound, desc = flag
|
||||
assert n == name
|
||||
|
||||
env.Command('base/traceflags.hh', flags,
|
||||
MakeAction(traceFlagsHH, Transform("TRACING", 0)))
|
||||
env.Command('base/traceflags.cc', flags,
|
||||
MakeAction(traceFlagsCC, Transform("TRACING", 0)))
|
||||
Source('base/traceflags.cc')
|
||||
env.Command('debug/%s.hh' % name, Value(flag),
|
||||
MakeAction(makeDebugFlagHH, Transform("TRACING", 0)))
|
||||
env.Command('debug/%s.cc' % name, Value(flag),
|
||||
MakeAction(makeDebugFlagCC, Transform("TRACING", 0)))
|
||||
Source('debug/%s.cc' % name)
|
||||
|
||||
# Embed python files. All .py files that have been indicated by a
|
||||
# PySource() call in a SConscript need to be embedded into the M5
|
||||
|
||||
Reference in New Issue
Block a user