201c201
< # Trace Flags
---
> # Debug Flags
203,205c203,205
< trace_flags = {}
< def TraceFlag(name, desc=None):
< if name in trace_flags:
---
> debug_flags = {}
> def DebugFlag(name, desc=None):
> if name in debug_flags:
207c207,208
< trace_flags[name] = (name, (), desc)
---
> debug_flags[name] = (name, (), desc)
> TraceFlag = DebugFlag
210c211
< if name in trace_flags:
---
> if name in debug_flags:
214c215
< trace_flags[name] = (name, compound, desc)
---
> debug_flags[name] = (name, compound, desc)
215a217
> Export('DebugFlag')
625,640c627,631
< 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)
642,643c633,635
< flagsList.sort()
< return flagsList
---
> val = eval(source[0].get_contents())
> name, compound, desc = val
> compound = list(sorted(compound))
645,648d636
<
< # Generate traceflags.py
< def traceFlagsPy(target, source, env):
< assert(len(target) == 1)
651,701d638
< 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()
<
708,732c645
< #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"
735,744c648,649
< # 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"')
745a651,652
> code('namespace Debug {')
> code()
747,750c654,657
< 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",')
752,754c659,664
< 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);')
756,757d665
< code('};')
< code()
759,769c667,668
< # 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')
773,774c672,673
< def traceFlagsHH(target, source, env):
< assert(len(target) == 1)
---
> def makeDebugFlagHH(target, source, env):
> assert(len(target) == 1 and len(source) == 1)
776c675,677
< allFlags = getFlags(source)
---
> val = eval(source[0].get_contents())
> name, compound, desc = val
>
784c685
< * Automatically generated from traceflags.py
---
> * Automatically generated by SCons
787,788c688,689
< #ifndef __BASE_TRACE_FLAGS_HH__
< #define __BASE_TRACE_FLAGS_HH__
---
> #ifndef __DEBUG_${name}_HH__
> #define __DEBUG_${name}_HH__
790c691,692
< namespace Trace {
---
> namespace Debug {
> ''')
792c694,696
< enum Flags {''')
---
> if compound:
> code('class CompoundFlag;')
> code('class SimpleFlag;')
794,800c698,703
< # 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;')
802,807d704
< numBaseFlags = idx
< code('NumFlags = $idx,')
< code.dedent()
< code()
<
< # put a comment in here to separate base from compound flags
809,811c706
< // 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.''')
---
> }
813,839c708
< 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__
844,847c713,715
< 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
849,853c717,721
< 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)