-#ifndef __BASE_TRACE_FLAGS_HH__
-#define __BASE_TRACE_FLAGS_HH__
-
-namespace Trace {
-
-enum Flags {'''
-
- # Generate the enum. Base flags come first, then compound flags.
- idx = 0
- for flag, compound, desc in allFlags:
- if not compound:
- print >>f, ' %s = %d,' % (flag, idx)
- idx += 1
-
- numBaseFlags = idx
- print >>f, ' NumFlags = %d,' % idx
-
- # put a comment in here to separate base from compound flags
- print >>f, '''
-// 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.'''
-
- print >>f, ' All = %d,' % idx
- idx += 1
- for flag, compound, desc in allFlags:
- if compound:
- print >>f, ' %s = %d,' % (flag, idx)
- idx += 1
-
- numCompoundFlags = idx - numBaseFlags
- print >>f, ' NumCompoundFlags = %d' % numCompoundFlags
-
- # trailer boilerplate
- print >>f, '''\
-}; // 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__
-'''
-
- f.close()
-
-flags = [ Value(f) for f in trace_flags ]
-env.Command('base/traceflags.py', flags, traceFlagsPy)
-PySource('m5', 'base/traceflags.py')
-
-env.Command('base/traceflags.hh', flags, traceFlagsHH)
-env.Command('base/traceflags.cc', flags, traceFlagsCC)
-Source('base/traceflags.cc')
-
-# Generate program_info.cc
-def programInfo(target, source, env):
- def gen_file(target, rev, node, date):
- pi_stats = file(target, 'w')
- print >>pi_stats, 'const char *hgRev = "%s:%s";' % (rev, node)
- print >>pi_stats, 'const char *hgDate = "%s";' % date
- pi_stats.close()
-
- target = str(target[0])
- scons_dir = str(source[0].get_contents())
- try:
- import mercurial.demandimport, mercurial.hg, mercurial.ui
- import mercurial.util, mercurial.node
- if not exists(scons_dir) or not isdir(scons_dir) or \
- not exists(joinpath(scons_dir, ".hg")):
- raise ValueError
- repo = mercurial.hg.repository(mercurial.ui.ui(), scons_dir)
- rev = mercurial.node.nullrev + repo.changelog.count()
- changenode = repo.changelog.node(rev)
- changes = repo.changelog.read(changenode)
- date = mercurial.util.datestr(changes[2])
-
- gen_file(target, rev, mercurial.node.hex(changenode), date)
-
- mercurial.demandimport.disable()
- except ImportError:
- gen_file(target, "Unknown", "Unknown", "Unknown")
-
- except:
- print "in except"
- gen_file(target, "Unknown", "Unknown", "Unknown")
- mercurial.demandimport.disable()
-
-env.Command('base/program_info.cc',
- Value(str(SCons.Node.FS.default_fs.SConstruct_dir)),
- programInfo)
-
-# Build the zip file
-def compilePyFile(target, source, env):
- '''Action function to compile a .py into a .pyc'''
- py_compile.compile(str(source[0]), str(target[0]))
-
-def buildPyZip(target, source, env):
- '''Action function to build the zip archive. Uses the
- PyZipFile module included in the standard Python library.'''
-
- py_compiled = {}
- for s in py_sources:
- compname = str(s.compiled)
- assert compname not in py_compiled
- py_compiled[compname] = s
-
- zf = zipfile.ZipFile(str(target[0]), 'w')
- for s in source:
- zipname = str(s)
- arcname = py_compiled[zipname].arcname
- zf.write(zipname, arcname)
- zf.close()
-
-py_compiled = []
-py_zip_depends = []
-for source in py_sources:
- env.Command(source.compiled, source.source, compilePyFile)
- py_compiled.append(source.compiled)
-
- # make the zipfile depend on the archive name so that the archive
- # is rebuilt if the name changes
- py_zip_depends.append(Value(source.arcname))
-
-# Add the zip file target to the environment.
-m5zip = File('m5py.zip')
-env.Command(m5zip, py_compiled, buildPyZip)
-env.Depends(m5zip, py_zip_depends)
+#ifndef __DEBUG_${name}_HH__
+#define __DEBUG_${name}_HH__
+
+namespace Debug {
+''')
+
+ if compound:
+ code('class CompoundFlag;')
+ code('class SimpleFlag;')
+
+ if compound:
+ code('extern CompoundFlag $name;')
+ for flag in compound:
+ code('extern SimpleFlag $flag;')
+ else:
+ code('extern SimpleFlag $name;')
+
+ code('''
+}
+
+#endif // __DEBUG_${name}_HH__
+''')
+
+ code.write(str(target[0]))
+
+for name,flag in sorted(debug_flags.iteritems()):
+ n, compound, desc = flag
+ assert n == name
+
+ 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
+# library. To do that, we compile the file to byte code, marshal the
+# byte code, compress it, and then generate a c++ file that
+# inserts the result into an array.
+def embedPyFile(target, source, env):
+ def c_str(string):
+ if string is None:
+ return "0"
+ return '"%s"' % string
+
+ '''Action function to compile a .py into a code object, marshal
+ it, compress it, and stick it into an asm file so the code appears
+ as just bytes with a label in the data section'''
+
+ src = file(str(source[0]), 'r').read()
+
+ pysource = PySource.tnodes[source[0]]
+ compiled = compile(src, pysource.abspath, 'exec')
+ marshalled = marshal.dumps(compiled)
+ compressed = zlib.compress(marshalled)
+ data = compressed
+ sym = pysource.symname
+
+ code = code_formatter()
+ code('''\
+#include "sim/init.hh"
+
+namespace {
+
+const uint8_t data_${sym}[] = {
+''')
+ code.indent()
+ step = 16
+ for i in xrange(0, len(data), step):
+ x = array.array('B', data[i:i+step])
+ code(''.join('%d,' % d for d in x))
+ code.dedent()
+
+ code('''};
+
+EmbeddedPython embedded_${sym}(
+ ${{c_str(pysource.arcname)}},
+ ${{c_str(pysource.abspath)}},
+ ${{c_str(pysource.modpath)}},
+ data_${sym},
+ ${{len(data)}},
+ ${{len(marshalled)}});
+
+} // anonymous namespace
+''')
+ code.write(str(target[0]))
+
+for source in PySource.all:
+ env.Command(source.cpp, source.tnode,
+ MakeAction(embedPyFile, Transform("EMBED PY")))
+ Source(source.cpp)