Deleted Added
sdiff udiff text old ( 8126:5138d1e453f1 ) new ( 8232:b28d06a175be )
full compact
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
202#
203trace_flags = {}
204def TraceFlag(name, desc=None):
205 if name in trace_flags:
206 raise AttributeError, "Flag %s already specified" % name
207 trace_flags[name] = (name, (), desc)
208
209def CompoundFlag(name, flags, desc=None):
210 if name in trace_flags:
211 raise AttributeError, "Flag %s already specified" % name
212
213 compound = tuple(flags)
214 trace_flags[name] = (name, compound, desc)
215
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
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"
641
642 flagsList.sort()
643 return flagsList
644
645
646# Generate traceflags.py
647def traceFlagsPy(target, source, env):
648 assert(len(target) == 1)
649 code = code_formatter()
650
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
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
733''')
734
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('};')
745 code()
746
747 for flag, compound, desc in allFlags:
748 if not compound:
749 continue
750 code('static const Flags ${flag}Map[] = {')
751 code.indent()
752 for flag in compound:
753 code('$flag,')
754 code('(Flags)-1')
755 code.dedent()
756 code('};')
757 code()
758
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('};')
770
771 code.write(str(target[0]))
772
773def traceFlagsHH(target, source, env):
774 assert(len(target) == 1)
775
776 allFlags = getFlags(source)
777 code = code_formatter()
778
779 # file header boilerplate
780 code('''\
781/*
782 * DO NOT EDIT THIS FILE!
783 *
784 * Automatically generated from traceflags.py
785 */
786
787#ifndef __BASE_TRACE_FLAGS_HH__
788#define __BASE_TRACE_FLAGS_HH__
789
790namespace Trace {
791
792enum Flags {''')
793
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
801
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('''
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.''')
812
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__
840''')
841
842 code.write(str(target[0]))
843
844flags = map(Value, trace_flags.values())
845env.Command('base/traceflags.py', flags,
846 MakeAction(traceFlagsPy, Transform("TRACING", 0)))
847PySource('m5', 'base/traceflags.py')
848
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')
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 ---