SConscript (8126:5138d1e453f1) SConscript (8232:b28d06a175be)
1# -*- mode:python -*-
2
3# Copyright (c) 2004-2005 The Regents of The University of Michigan
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions are
8# met: redistributions of source code must retain the above copyright

--- 184 unchanged lines hidden (view full) ---

193Export('Source')
194Export('PySource')
195Export('SimObject')
196Export('SwigSource')
197Export('UnitTest')
198
199########################################################################
200#
1# -*- mode:python -*-
2
3# Copyright (c) 2004-2005 The Regents of The University of Michigan
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions are
8# met: redistributions of source code must retain the above copyright

--- 184 unchanged lines hidden (view full) ---

193Export('Source')
194Export('PySource')
195Export('SimObject')
196Export('SwigSource')
197Export('UnitTest')
198
199########################################################################
200#
201# Trace Flags
201# Debug Flags
202#
202#
203trace_flags = {}
204def TraceFlag(name, desc=None):
205 if name in trace_flags:
203debug_flags = {}
204def DebugFlag(name, desc=None):
205 if name in debug_flags:
206 raise AttributeError, "Flag %s already specified" % name
206 raise AttributeError, "Flag %s already specified" % name
207 trace_flags[name] = (name, (), desc)
207 debug_flags[name] = (name, (), desc)
208TraceFlag = DebugFlag
208
209def CompoundFlag(name, flags, desc=None):
209
210def CompoundFlag(name, flags, desc=None):
210 if name in trace_flags:
211 if name in debug_flags:
211 raise AttributeError, "Flag %s already specified" % name
212
213 compound = tuple(flags)
212 raise AttributeError, "Flag %s already specified" % name
213
214 compound = tuple(flags)
214 trace_flags[name] = (name, compound, desc)
215 debug_flags[name] = (name, compound, desc)
215
216
217Export('DebugFlag')
216Export('TraceFlag')
217Export('CompoundFlag')
218
219########################################################################
220#
221# Set some compiler variables
222#
223

--- 393 unchanged lines hidden (view full) ---

617 env.Command([swig.cc_source.tnode, swig.py_source.tnode], swig.tnode,
618 MakeAction('$SWIG $SWIGFLAGS -outdir ${TARGETS[1].dir} '
619 '-o ${TARGETS[0]} $SOURCES', Transform("SWIG")))
620 init_file = 'python/swig/init_%s.cc' % swig.module
621 env.Command(init_file, Value(swig.module),
622 MakeAction(makeEmbeddedSwigInit, Transform("EMBED SW")))
623 Source(init_file)
624
218Export('TraceFlag')
219Export('CompoundFlag')
220
221########################################################################
222#
223# Set some compiler variables
224#
225

--- 393 unchanged lines hidden (view full) ---

619 env.Command([swig.cc_source.tnode, swig.py_source.tnode], swig.tnode,
620 MakeAction('$SWIG $SWIGFLAGS -outdir ${TARGETS[1].dir} '
621 '-o ${TARGETS[0]} $SOURCES', Transform("SWIG")))
622 init_file = 'python/swig/init_%s.cc' % swig.module
623 env.Command(init_file, Value(swig.module),
624 MakeAction(makeEmbeddedSwigInit, Transform("EMBED SW")))
625 Source(init_file)
626
625def getFlags(source_flags):
626 flagsMap = {}
627 flagsList = []
628 for s in source_flags:
629 val = eval(s.get_contents())
630 name, compound, desc = val
631 flagsList.append(val)
632 flagsMap[name] = bool(compound)
633
634 for name, compound, desc in flagsList:
635 for flag in compound:
636 if flag not in flagsMap:
637 raise AttributeError, "Trace flag %s not found" % flag
638 if flagsMap[flag]:
639 raise AttributeError, \
640 "Compound flag can't point to another compound flag"
627#
628# Handle debug flags
629#
630def makeDebugFlagCC(target, source, env):
631 assert(len(target) == 1 and len(source) == 1)
641
632
642 flagsList.sort()
643 return flagsList
633 val = eval(source[0].get_contents())
634 name, compound, desc = val
635 compound = list(sorted(compound))
644
636
645
646# Generate traceflags.py
647def traceFlagsPy(target, source, env):
648 assert(len(target) == 1)
649 code = code_formatter()
650
637 code = code_formatter()
638
651 allFlags = getFlags(source)
652
653 code('basic = [')
654 code.indent()
655 for flag, compound, desc in allFlags:
656 if not compound:
657 code("'$flag',")
658 code(']')
659 code.dedent()
660 code()
661
662 code('compound = [')
663 code.indent()
664 code("'All',")
665 for flag, compound, desc in allFlags:
666 if compound:
667 code("'$flag',")
668 code("]")
669 code.dedent()
670 code()
671
672 code("all = frozenset(basic + compound)")
673 code()
674
675 code('compoundMap = {')
676 code.indent()
677 all = tuple([flag for flag,compound,desc in allFlags if not compound])
678 code("'All' : $all,")
679 for flag, compound, desc in allFlags:
680 if compound:
681 code("'$flag' : $compound,")
682 code('}')
683 code.dedent()
684 code()
685
686 code('descriptions = {')
687 code.indent()
688 code("'All' : 'All flags',")
689 for flag, compound, desc in allFlags:
690 code("'$flag' : '$desc',")
691 code("}")
692 code.dedent()
693
694 code.write(str(target[0]))
695
696def traceFlagsCC(target, source, env):
697 assert(len(target) == 1)
698
699 allFlags = getFlags(source)
700 code = code_formatter()
701
702 # file header
703 code('''
704/*
705 * DO NOT EDIT THIS FILE! Automatically generated
706 */
707
639 # file header
640 code('''
641/*
642 * DO NOT EDIT THIS FILE! Automatically generated
643 */
644
708#include "base/traceflags.hh"
709
710using namespace Trace;
711
712const char *Trace::flagStrings[] =
713{''')
714
715 code.indent()
716 # The string array is used by SimpleEnumParam to map the strings
717 # provided by the user to enum values.
718 for flag, compound, desc in allFlags:
719 if not compound:
720 code('"$flag",')
721
722 code('"All",')
723 for flag, compound, desc in allFlags:
724 if compound:
725 code('"$flag",')
726 code.dedent()
727
728 code('''\
729};
730
731const int Trace::numFlagStrings = ${{len(allFlags) + 1}};
732
645#include "base/debug.hh"
733''')
734
646''')
647
735 # Now define the individual compound flag arrays. There is an array
736 # for each compound flag listing the component base flags.
737 all = tuple([flag for flag,compound,desc in allFlags if not compound])
738 code('static const Flags AllMap[] = {')
739 code.indent()
740 for flag, compound, desc in allFlags:
741 if not compound:
742 code('$flag,')
743 code.dedent()
744 code('};')
648 for flag in compound:
649 code('#include "debug/$flag.hh"')
745 code()
650 code()
651 code('namespace Debug {')
652 code()
746
653
747 for flag, compound, desc in allFlags:
748 if not compound:
749 continue
750 code('static const Flags ${flag}Map[] = {')
654 if not compound:
655 code('SimpleFlag $name("$name", "$desc");')
656 else:
657 code('CompoundFlag $name("$name", "$desc",')
751 code.indent()
658 code.indent()
752 for flag in compound:
753 code('$flag,')
754 code('(Flags)-1')
659 last = len(compound) - 1
660 for i,flag in enumerate(compound):
661 if i != last:
662 code('$flag,')
663 else:
664 code('$flag);')
755 code.dedent()
665 code.dedent()
756 code('};')
757 code()
758
666
759 # Finally the compoundFlags[] array maps the compound flags
760 # to their individual arrays/
761 code('const Flags *Trace::compoundFlags[] = {')
762 code.indent()
763 code('AllMap,')
764 for flag, compound, desc in allFlags:
765 if compound:
766 code('${flag}Map,')
767 # file trailer
768 code.dedent()
769 code('};')
667 code()
668 code('} // namespace Debug')
770
771 code.write(str(target[0]))
772
669
670 code.write(str(target[0]))
671
773def traceFlagsHH(target, source, env):
774 assert(len(target) == 1)
672def makeDebugFlagHH(target, source, env):
673 assert(len(target) == 1 and len(source) == 1)
775
674
776 allFlags = getFlags(source)
675 val = eval(source[0].get_contents())
676 name, compound, desc = val
677
777 code = code_formatter()
778
779 # file header boilerplate
780 code('''\
781/*
782 * DO NOT EDIT THIS FILE!
783 *
678 code = code_formatter()
679
680 # file header boilerplate
681 code('''\
682/*
683 * DO NOT EDIT THIS FILE!
684 *
784 * Automatically generated from traceflags.py
685 * Automatically generated by SCons
785 */
786
686 */
687
787#ifndef __BASE_TRACE_FLAGS_HH__
788#define __BASE_TRACE_FLAGS_HH__
688#ifndef __DEBUG_${name}_HH__
689#define __DEBUG_${name}_HH__
789
690
790namespace Trace {
691namespace Debug {
692''')
791
693
792enum Flags {''')
694 if compound:
695 code('class CompoundFlag;')
696 code('class SimpleFlag;')
793
697
794 # Generate the enum. Base flags come first, then compound flags.
795 idx = 0
796 code.indent()
797 for flag, compound, desc in allFlags:
798 if not compound:
799 code('$flag = $idx,')
800 idx += 1
698 if compound:
699 code('extern CompoundFlag $name;')
700 for flag in compound:
701 code('extern SimpleFlag $flag;')
702 else:
703 code('extern SimpleFlag $name;')
801
704
802 numBaseFlags = idx
803 code('NumFlags = $idx,')
804 code.dedent()
805 code()
806
807 # put a comment in here to separate base from compound flags
808 code('''
705 code('''
809// The remaining enum values are *not* valid indices for Trace::flags.
810// They are "compound" flags, which correspond to sets of base
811// flags, and are used by changeFlag.''')
706}
812
707
813 code.indent()
814 code('All = $idx,')
815 idx += 1
816 for flag, compound, desc in allFlags:
817 if compound:
818 code('$flag = $idx,')
819 idx += 1
820
821 numCompoundFlags = idx - numBaseFlags
822 code('NumCompoundFlags = $numCompoundFlags')
823 code.dedent()
824
825 # trailer boilerplate
826 code('''\
827}; // enum Flags
828
829// Array of strings for SimpleEnumParam
830extern const char *flagStrings[];
831extern const int numFlagStrings;
832
833// Array of arraay pointers: for each compound flag, gives the list of
834// base flags to set. Inidividual flag arrays are terminated by -1.
835extern const Flags *compoundFlags[];
836
837} // namespace Trace
838
839#endif // __BASE_TRACE_FLAGS_HH__
708#endif // __DEBUG_${name}_HH__
840''')
841
842 code.write(str(target[0]))
843
709''')
710
711 code.write(str(target[0]))
712
844flags = map(Value, trace_flags.values())
845env.Command('base/traceflags.py', flags,
846 MakeAction(traceFlagsPy, Transform("TRACING", 0)))
847PySource('m5', 'base/traceflags.py')
713for name,flag in sorted(debug_flags.iteritems()):
714 n, compound, desc = flag
715 assert n == name
848
716
849env.Command('base/traceflags.hh', flags,
850 MakeAction(traceFlagsHH, Transform("TRACING", 0)))
851env.Command('base/traceflags.cc', flags,
852 MakeAction(traceFlagsCC, Transform("TRACING", 0)))
853Source('base/traceflags.cc')
717 env.Command('debug/%s.hh' % name, Value(flag),
718 MakeAction(makeDebugFlagHH, Transform("TRACING", 0)))
719 env.Command('debug/%s.cc' % name, Value(flag),
720 MakeAction(makeDebugFlagCC, Transform("TRACING", 0)))
721 Source('debug/%s.cc' % name)
854
855# Embed python files. All .py files that have been indicated by a
856# PySource() call in a SConscript need to be embedded into the M5
857# library. To do that, we compile the file to byte code, marshal the
858# byte code, compress it, and then generate a c++ file that
859# inserts the result into an array.
860def embedPyFile(target, source, env):
861 def c_str(string):

--- 190 unchanged lines hidden ---
722
723# Embed python files. All .py files that have been indicated by a
724# PySource() call in a SConscript need to be embedded into the M5
725# library. To do that, we compile the file to byte code, marshal the
726# byte code, compress it, and then generate a c++ file that
727# inserts the result into an array.
728def embedPyFile(target, source, env):
729 def c_str(string):

--- 190 unchanged lines hidden ---