Deleted Added
sdiff udiff text old ( 7502:3ef7ff12c788 ) new ( 7673:b28bd1fa9a35 )
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

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

254 if 'SConscript' in files:
255 build_dir = joinpath(env['BUILDDIR'], root[prefix_len:])
256 SConscript(joinpath(root, 'SConscript'), build_dir=build_dir)
257
258for opt in export_vars:
259 env.ConfigFile(opt)
260
261def makeTheISA(source, target, env):
262 isas = [ src.get_contents() for src in source ]
263 target_isa = env['TARGET_ISA']
264 def define(isa):
265 return isa.upper() + '_ISA'
266
267 def namespace(isa):
268 return isa[0].upper() + isa[1:].lower() + 'ISA'
269
270
271 code = code_formatter()
272 code('''\
273#ifndef __CONFIG_THE_ISA_HH__
274#define __CONFIG_THE_ISA_HH__
275
276''')
277
278 for i,isa in enumerate(isas):
279 code('#define $0 $1', define(isa), i + 1)
280
281 code('''
282
283#define THE_ISA ${{define(target_isa)}}
284#define TheISA ${{namespace(target_isa)}}
285
286#endif // __CONFIG_THE_ISA_HH__''')
287
288 code.write(str(target[0]))
289
290env.Command('config/the_isa.hh', map(Value, all_isa_list), makeTheISA)
291
292########################################################################
293#
294# Prevent any SimObjects from being added after this point, they
295# should all have been added in the SConscripts above
296#
297SimObject.fixed = True

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

348 mod.__file__ = source.abspath
349
350 exec file(source.abspath, 'r') in mod.__dict__
351
352 return mod
353
354import m5.SimObject
355import m5.params
356from m5.util import code_formatter
357
358m5.SimObject.clear()
359m5.params.clear()
360
361# install the python importer so we can grab stuff from the source
362# tree itself. We can't have SimObjects added after this point or
363# else we won't know about them for the rest of the stuff.
364importer = DictImporter(PySource.modules)

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

404# Commands for the basic automatically generated python files
405#
406
407# Generate Python file containing a dict specifying the current
408# buildEnv flags.
409def makeDefinesPyFile(target, source, env):
410 build_env, hg_info = [ x.get_contents() for x in source ]
411
412 code = code_formatter()
413 code("""
414import m5.internal
415import m5.util
416
417buildEnv = m5.util.SmartDict($build_env)
418hgRev = '$hg_info'
419
420compileDate = m5.internal.core.compileDate
421_globals = globals()
422for key,val in m5.internal.core.__dict__.iteritems():
423 if key.startswith('flag_'):
424 flag = key[5:]
425 _globals[flag] = val
426del _globals
427""")
428 code.write(target[0].abspath)
429
430defines_info = [ Value(build_env), Value(env['HG_INFO']) ]
431# Generate a file with all of the compile options in it
432env.Command('python/m5/defines.py', defines_info, makeDefinesPyFile)
433PySource('m5', 'python/m5/defines.py')
434
435# Generate python file containing info about the M5 source code
436def makeInfoPyFile(target, source, env):
437 code = code_formatter()
438 for src in source:
439 data = ''.join(file(src.srcnode().abspath, 'r').xreadlines())
440 code('$src = ${{repr(data)}}')
441 code.write(str(target[0]))
442
443# Generate a file that wraps the basic top level files
444env.Command('python/m5/info.py',
445 [ '#/AUTHORS', '#/LICENSE', '#/README', '#/RELEASE_NOTES' ],
446 makeInfoPyFile)
447PySource('m5', 'python/m5/info.py')
448
449# Generate the __init__.py file for m5.objects
450def makeObjectsInitFile(target, source, env):
451 code = code_formatter()
452 code('''\
453from params import *
454from m5.SimObject import *
455''')
456
457 for module in source:
458 code('from $0 import *', module.get_contents())
459 code.write(str(target[0]))
460
461# Generate an __init__.py file for the objects package
462env.Command('python/m5/objects/__init__.py',
463 map(Value, SimObject.modnames),
464 makeObjectsInitFile)
465PySource('m5.objects', 'python/m5/objects/__init__.py')
466
467########################################################################
468#
469# Create all of the SimObject param headers and enum headers
470#
471
472def createSimObjectParam(target, source, env):
473 assert len(target) == 1 and len(source) == 1
474
475 name = str(source[0].get_contents())
476 obj = sim_objects[name]
477
478 code = code_formatter()
479 obj.cxx_decl(code)
480 code.write(target[0].abspath)
481
482def createSwigParam(target, source, env):
483 assert len(target) == 1 and len(source) == 1
484
485 name = str(source[0].get_contents())
486 param = all_params[name]
487
488 code = code_formatter()
489 param.swig_decl(code)
490 code.write(target[0].abspath)
491
492def createEnumStrings(target, source, env):
493 assert len(target) == 1 and len(source) == 1
494
495 name = str(source[0].get_contents())
496 obj = all_enums[name]
497
498 code = code_formatter()
499 obj.cxx_def(code)
500 code.write(target[0].abspath)
501
502def createEnumParam(target, source, env):
503 assert len(target) == 1 and len(source) == 1
504
505 name = str(source[0].get_contents())
506 obj = all_enums[name]
507
508 code = code_formatter()
509 obj.cxx_decl(code)
510 code.write(target[0].abspath)
511
512# Generate all of the SimObject param struct header files
513params_hh_files = []
514for name,simobj in sorted(sim_objects.iteritems()):
515 py_source = PySource.modules[simobj.__module__]
516 extra_deps = [ py_source.tnode ]
517
518 hh_file = File('params/%s.hh' % name)

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

542 env.Command(hh_file, Value(name), createEnumParam)
543 env.Depends(hh_file, depends + extra_deps)
544
545# Build the big monolithic swigged params module (wraps all SimObject
546# param structs and enum structs)
547def buildParams(target, source, env):
548 names = [ s.get_contents() for s in source ]
549 objs = [ sim_objects[name] for name in names ]
550
551 ordered_objs = []
552 obj_seen = set()
553 def order_obj(obj):
554 name = str(obj)
555 if name in obj_seen:
556 return
557
558 obj_seen.add(name)
559 if str(obj) != 'SimObject':
560 order_obj(obj.__bases__[0])
561
562 ordered_objs.append(obj)
563
564 for obj in objs:
565 order_obj(obj)
566
567 code = code_formatter()
568 code('%module params')
569
570 code('%{')
571 for obj in ordered_objs:
572 code('#include "params/$obj.hh"')
573 code('%}')
574
575 for obj in ordered_objs:
576 params = obj._params.local.values()
577 for param in params:
578 param.swig_predecls(code)
579
580 enums = set()
581 for obj in ordered_objs:
582 params = obj._params.local.values()
583 for param in params:
584 ptype = param.ptype
585 if issubclass(ptype, m5.params.Enum) and ptype not in enums:
586 enums.add(ptype)
587 code('%include "enums/$0.hh"', ptype.__name__)
588
589 for obj in ordered_objs:
590 obj.swig_objdecls(code)
591 code()
592
593 for obj in ordered_objs:
594 continue
595 if obj.swig_objdecls:
596 obj.swig_objdecls(code)
597 continue
598
599 class_path = obj.cxx_class.split('::')
600 classname = class_path[-1]
601 namespaces = class_path[:-1]
602
603 for ns in namespaces:
604 code('namespace $ns {')
605
606 if namespaces:
607 code('// avoid name conflicts')
608 sep_string = '_COLONS_'
609 flat_name = sep_string.join(class_path)
610 code('%rename($flat_name) $classname;')
611
612 code('// stop swig from creating/wrapping default ctor/dtor')
613 code('%nodefault $classname;')
614 if obj._base:
615 code('class $classname : public ${{obj._base.cxx_class}} {};')
616 else:
617 code('class $classname {};')
618
619 for ns in reversed(namespaces):
620 code('/* namespace $ns */ }')
621 code()
622
623 code('%include "src/sim/sim_object_params.hh"')
624 for obj in ordered_objs:
625 code('%include "params/$obj.hh"')
626
627 code.write(target[0].abspath)
628
629params_file = File('params/params.i')
630names = sorted(sim_objects.keys())
631env.Command(params_file, map(Value, names), buildParams)
632env.Depends(params_file, params_hh_files + params_i_files + depends)
633SwigSource('m5.objects', params_file)
634
635# Build all swig modules
636for swig in SwigSource.all:
637 env.Command([swig.cc_source.tnode, swig.py_source.tnode], swig.tnode,
638 '$SWIG $SWIGFLAGS -outdir ${TARGETS[1].dir} '
639 '-o ${TARGETS[0]} $SOURCES')
640 env.Depends(swig.py_source.tnode, swig.tnode)
641 env.Depends(swig.cc_source.tnode, swig.tnode)
642
643# Generate the main swig init file
644def makeSwigInit(target, source, env):
645 code = code_formatter()
646
647 code('extern "C" {')
648 code.indent()
649 for module in source:
650 code('void init_$0();', module.get_contents())
651 code.dedent()
652 code('}')
653
654 code('void initSwig() {')
655 code.indent()
656 for module in source:
657 code('init_$0();', module.get_contents())
658 code.dedent()
659 code('}')
660
661 code.write(str(target[0]))
662
663env.Command('python/swig/init.cc',
664 map(Value, sorted(s.module for s in SwigSource.all)),
665 makeSwigInit)
666Source('python/swig/init.cc')
667
668def getFlags(source_flags):
669 flagsMap = {}
670 flagsList = []

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

684
685 flagsList.sort()
686 return flagsList
687
688
689# Generate traceflags.py
690def traceFlagsPy(target, source, env):
691 assert(len(target) == 1)
692 code = code_formatter()
693
694 allFlags = getFlags(source)
695
696 code('basic = [')
697 code.indent()
698 for flag, compound, desc in allFlags:
699 if not compound:
700 code("'$flag',")
701 code(']')
702 code.dedent()
703 code()
704
705 code('compound = [')
706 code.indent()
707 code("'All',")
708 for flag, compound, desc in allFlags:
709 if compound:
710 code("'$flag',")
711 code("]")
712 code.dedent()
713 code()
714
715 code("all = frozenset(basic + compound)")
716 code()
717
718 code('compoundMap = {')
719 code.indent()
720 all = tuple([flag for flag,compound,desc in allFlags if not compound])
721 code("'All' : $all,")
722 for flag, compound, desc in allFlags:
723 if compound:
724 code("'$flag' : $compound,")
725 code('}')
726 code.dedent()
727 code()
728
729 code('descriptions = {')
730 code.indent()
731 code("'All' : 'All flags',")
732 for flag, compound, desc in allFlags:
733 code("'$flag' : '$desc',")
734 code("}")
735 code.dedent()
736
737 code.write(str(target[0]))
738
739def traceFlagsCC(target, source, env):
740 assert(len(target) == 1)
741
742 allFlags = getFlags(source)
743 code = code_formatter()
744
745 # file header
746 code('''
747/*
748 * DO NOT EDIT THIS FILE! Automatically generated
749 */
750
751#include "base/traceflags.hh"
752
753using namespace Trace;
754
755const char *Trace::flagStrings[] =
756{''')
757
758 code.indent()
759 # The string array is used by SimpleEnumParam to map the strings
760 # provided by the user to enum values.
761 for flag, compound, desc in allFlags:
762 if not compound:
763 code('"$flag",')
764
765 code('"All",')
766 for flag, compound, desc in allFlags:
767 if compound:
768 code('"$flag",')
769 code.dedent()
770
771 code('''\
772};
773
774const int Trace::numFlagStrings = ${{len(allFlags) + 1}};
775
776''')
777
778 # Now define the individual compound flag arrays. There is an array
779 # for each compound flag listing the component base flags.
780 all = tuple([flag for flag,compound,desc in allFlags if not compound])
781 code('static const Flags AllMap[] = {')
782 code.indent()
783 for flag, compound, desc in allFlags:
784 if not compound:
785 code('$flag,')
786 code.dedent()
787 code('};')
788 code()
789
790 for flag, compound, desc in allFlags:
791 if not compound:
792 continue
793 code('static const Flags ${flag}Map[] = {')
794 code.indent()
795 for flag in compound:
796 code('$flag,')
797 code('(Flags)-1')
798 code.dedent()
799 code('};')
800 code()
801
802 # Finally the compoundFlags[] array maps the compound flags
803 # to their individual arrays/
804 code('const Flags *Trace::compoundFlags[] = {')
805 code.indent()
806 code('AllMap,')
807 for flag, compound, desc in allFlags:
808 if compound:
809 code('${flag}Map,')
810 # file trailer
811 code.dedent()
812 code('};')
813
814 code.write(str(target[0]))
815
816def traceFlagsHH(target, source, env):
817 assert(len(target) == 1)
818
819 allFlags = getFlags(source)
820 code = code_formatter()
821
822 # file header boilerplate
823 code('''\
824/*
825 * DO NOT EDIT THIS FILE!
826 *
827 * Automatically generated from traceflags.py
828 */
829
830#ifndef __BASE_TRACE_FLAGS_HH__
831#define __BASE_TRACE_FLAGS_HH__
832
833namespace Trace {
834
835enum Flags {''')
836
837 # Generate the enum. Base flags come first, then compound flags.
838 idx = 0
839 code.indent()
840 for flag, compound, desc in allFlags:
841 if not compound:
842 code('$flag = $idx,')
843 idx += 1
844
845 numBaseFlags = idx
846 code('NumFlags = $idx,')
847 code.dedent()
848 code()
849
850 # put a comment in here to separate base from compound flags
851 code('''
852// The remaining enum values are *not* valid indices for Trace::flags.
853// They are "compound" flags, which correspond to sets of base
854// flags, and are used by changeFlag.''')
855
856 code.indent()
857 code('All = $idx,')
858 idx += 1
859 for flag, compound, desc in allFlags:
860 if compound:
861 code('$flag = $idx,')
862 idx += 1
863
864 numCompoundFlags = idx - numBaseFlags
865 code('NumCompoundFlags = $numCompoundFlags')
866 code.dedent()
867
868 # trailer boilerplate
869 code('''\
870}; // enum Flags
871
872// Array of strings for SimpleEnumParam
873extern const char *flagStrings[];
874extern const int numFlagStrings;
875
876// Array of arraay pointers: for each compound flag, gives the list of
877// base flags to set. Inidividual flag arrays are terminated by -1.
878extern const Flags *compoundFlags[];
879
880/* namespace Trace */ }
881
882#endif // __BASE_TRACE_FLAGS_HH__
883''')
884
885 code.write(str(target[0]))
886
887flags = map(Value, trace_flags.values())
888env.Command('base/traceflags.py', flags, traceFlagsPy)
889PySource('m5', 'base/traceflags.py')
890
891env.Command('base/traceflags.hh', flags, traceFlagsHH)
892env.Command('base/traceflags.cc', flags, traceFlagsCC)
893Source('base/traceflags.cc')

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

899# inserts the result into the data section with symbols indicating the
900# beginning, and end (and with the size at the end)
901def objectifyPyFile(target, source, env):
902 '''Action function to compile a .py into a code object, marshal
903 it, compress it, and stick it into an asm file so the code appears
904 as just bytes with a label in the data section'''
905
906 src = file(str(source[0]), 'r').read()
907
908 pysource = PySource.tnodes[source[0]]
909 compiled = compile(src, pysource.abspath, 'exec')
910 marshalled = marshal.dumps(compiled)
911 compressed = zlib.compress(marshalled)
912 data = compressed
913
914 # Some C/C++ compilers prepend an underscore to global symbol
915 # names, so if they're going to do that, we need to prepend that
916 # leading underscore to globals in the assembly file.
917 if env['LEADING_UNDERSCORE']:
918 sym = '_' + pysource.symname
919 else:
920 sym = pysource.symname
921
922 step = 16
923 code = code_formatter()
924 code('''\
925.data
926.globl ${sym}_beg
927.globl ${sym}_end
928${sym}_beg:''')
929
930 for i in xrange(0, len(data), step):
931 x = array.array('B', data[i:i+step])
932 bytes = ','.join([str(d) for d in x])
933 code('.byte $bytes')
934 code('${sym}_end:')
935 code('.long $0', len(marshalled))
936
937 code.write(str(target[0]))
938
939for source in PySource.all:
940 env.Command(source.assembly, source.tnode, objectifyPyFile)
941 Source(source.assembly)
942
943# Generate init_python.cc which creates a bunch of EmbeddedPyModule
944# structs that describe the embedded python code. One such struct
945# contains information about the importer that python uses to get at
946# the embedded files, and then there's a list of all of the rest that
947# the importer uses to load the rest on demand.
948def pythonInit(target, source, env):
949 code = code_formatter()
950
951 def dump_mod(sym, endchar=','):
952 def c_str(string):
953 if string is None:
954 return "0"
955 return '"%s"' % string
956
957 pysource = PySource.symnames[sym]
958 arcname = c_str(pysource.arcname)
959 abspath = c_str(pysource.abspath)
960 modpath = c_str(pysource.modpath)
961 code.indent()
962 code('''\
963{ $arcname,
964 $abspath,
965 $modpath,
966 ${sym}_beg, ${sym}_end,
967 ${sym}_end - ${sym}_beg,
968 *(int *)${sym}_end }$endchar
969''')
970 code.dedent()
971
972 code('#include "sim/init.hh"')
973 for sym in source:
974 sym = sym.get_contents()
975 code('extern const char ${sym}_beg[], ${sym}_end[];')
976
977 code('const EmbeddedPyModule embeddedPyImporter = ')
978 dump_mod("PyEMB_importer", endchar=';')
979 code()
980
981 code('const EmbeddedPyModule embeddedPyModules[] = {')
982 for i,sym in enumerate(source):
983 sym = sym.get_contents()
984 if sym == "PyEMB_importer":
985 # Skip the importer since we've already exported it
986 continue
987 dump_mod(sym)
988 code(' { 0, 0, 0, 0, 0, 0, 0 }')
989 code('};')
990
991 code.write(str(target[0]))
992
993env.Command('sim/init_python.cc',
994 map(Value, (s.symname for s in PySource.all)),
995 pythonInit)
996Source('sim/init_python.cc')
997
998########################################################################
999#

--- 136 unchanged lines hidden ---