SConscript (8594:0e77bd34385f) SConscript (8596:e6e22fa77883)
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

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

444# we need to unload all of the currently imported modules so that they
445# will be re-imported the next time the sconscript is run
446importer.unload()
447sys.meta_path.remove(importer)
448
449sim_objects = m5.SimObject.allClasses
450all_enums = m5.params.allEnums
451
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

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

444# we need to unload all of the currently imported modules so that they
445# will be re-imported the next time the sconscript is run
446importer.unload()
447sys.meta_path.remove(importer)
448
449sim_objects = m5.SimObject.allClasses
450all_enums = m5.params.allEnums
451
452all_params = {}
452# Find param types that need to be explicitly wrapped with swig.
453# These will be recognized because the ParamDesc will have a
454# swig_decl() method. Most param types are based on types that don't
455# need this, either because they're based on native types (like Int)
456# or because they're SimObjects (which get swigged independently).
457# For now the only things handled here are VectorParam types.
458params_to_swig = {}
453for name,obj in sorted(sim_objects.iteritems()):
454 for param in obj._params.local.values():
455 # load the ptype attribute now because it depends on the
456 # current version of SimObject.allClasses, but when scons
457 # actually uses the value, all versions of
458 # SimObject.allClasses will have been loaded
459 param.ptype
460
461 if not hasattr(param, 'swig_decl'):
462 continue
463 pname = param.ptype_str
459for name,obj in sorted(sim_objects.iteritems()):
460 for param in obj._params.local.values():
461 # load the ptype attribute now because it depends on the
462 # current version of SimObject.allClasses, but when scons
463 # actually uses the value, all versions of
464 # SimObject.allClasses will have been loaded
465 param.ptype
466
467 if not hasattr(param, 'swig_decl'):
468 continue
469 pname = param.ptype_str
464 if pname not in all_params:
465 all_params[pname] = param
470 if pname not in params_to_swig:
471 params_to_swig[pname] = param
466
467########################################################################
468#
469# calculate extra dependencies
470#
471module_depends = ["m5", "m5.SimObject", "m5.params"]
472depends = [ PySource.modules[dep].snode for dep in module_depends ]
473

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

518 MakeAction(makeInfoPyFile, Transform("INFO")))
519PySource('m5', 'python/m5/info.py')
520
521########################################################################
522#
523# Create all of the SimObject param headers and enum headers
524#
525
472
473########################################################################
474#
475# calculate extra dependencies
476#
477module_depends = ["m5", "m5.SimObject", "m5.params"]
478depends = [ PySource.modules[dep].snode for dep in module_depends ]
479

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

524 MakeAction(makeInfoPyFile, Transform("INFO")))
525PySource('m5', 'python/m5/info.py')
526
527########################################################################
528#
529# Create all of the SimObject param headers and enum headers
530#
531
526def createSimObjectParam(target, source, env):
532def createSimObjectParamStruct(target, source, env):
527 assert len(target) == 1 and len(source) == 1
528
529 name = str(source[0].get_contents())
530 obj = sim_objects[name]
531
532 code = code_formatter()
533 assert len(target) == 1 and len(source) == 1
534
535 name = str(source[0].get_contents())
536 obj = sim_objects[name]
537
538 code = code_formatter()
533 obj.cxx_decl(code)
539 obj.cxx_param_decl(code)
534 code.write(target[0].abspath)
535
540 code.write(target[0].abspath)
541
536def createSwigParam(target, source, env):
542def createParamSwigWrapper(target, source, env):
537 assert len(target) == 1 and len(source) == 1
538
539 name = str(source[0].get_contents())
543 assert len(target) == 1 and len(source) == 1
544
545 name = str(source[0].get_contents())
540 param = all_params[name]
546 param = params_to_swig[name]
541
542 code = code_formatter()
547
548 code = code_formatter()
543 code('%module(package="m5.internal") $0_${name}', param.file_ext)
544 param.swig_decl(code)
545 code.write(target[0].abspath)
546
547def createEnumStrings(target, source, env):
548 assert len(target) == 1 and len(source) == 1
549
550 name = str(source[0].get_contents())
551 obj = all_enums[name]
552
553 code = code_formatter()
554 obj.cxx_def(code)
555 code.write(target[0].abspath)
556
549 param.swig_decl(code)
550 code.write(target[0].abspath)
551
552def createEnumStrings(target, source, env):
553 assert len(target) == 1 and len(source) == 1
554
555 name = str(source[0].get_contents())
556 obj = all_enums[name]
557
558 code = code_formatter()
559 obj.cxx_def(code)
560 code.write(target[0].abspath)
561
557def createEnumParam(target, source, env):
562def createEnumDecls(target, source, env):
558 assert len(target) == 1 and len(source) == 1
559
560 name = str(source[0].get_contents())
561 obj = all_enums[name]
562
563 code = code_formatter()
564 obj.cxx_decl(code)
565 code.write(target[0].abspath)
566
563 assert len(target) == 1 and len(source) == 1
564
565 name = str(source[0].get_contents())
566 obj = all_enums[name]
567
568 code = code_formatter()
569 obj.cxx_decl(code)
570 code.write(target[0].abspath)
571
567def createEnumSwig(target, source, env):
572def createEnumSwigWrapper(target, source, env):
568 assert len(target) == 1 and len(source) == 1
569
570 name = str(source[0].get_contents())
571 obj = all_enums[name]
572
573 code = code_formatter()
573 assert len(target) == 1 and len(source) == 1
574
575 name = str(source[0].get_contents())
576 obj = all_enums[name]
577
578 code = code_formatter()
574 code('''\
575%module(package="m5.internal") enum_$name
579 obj.swig_decl(code)
580 code.write(target[0].abspath)
576
581
577%{
578#include "enums/$name.hh"
579%}
582def createSimObjectSwigWrapper(target, source, env):
583 name = source[0].get_contents()
584 obj = sim_objects[name]
580
585
581%include "enums/$name.hh"
582''')
586 code = code_formatter()
587 obj.swig_decl(code)
583 code.write(target[0].abspath)
584
588 code.write(target[0].abspath)
589
585# Generate all of the SimObject param struct header files
590# Generate all of the SimObject param C++ struct header files
586params_hh_files = []
587for name,simobj in sorted(sim_objects.iteritems()):
588 py_source = PySource.modules[simobj.__module__]
589 extra_deps = [ py_source.tnode ]
590
591 hh_file = File('params/%s.hh' % name)
592 params_hh_files.append(hh_file)
593 env.Command(hh_file, Value(name),
591params_hh_files = []
592for name,simobj in sorted(sim_objects.iteritems()):
593 py_source = PySource.modules[simobj.__module__]
594 extra_deps = [ py_source.tnode ]
595
596 hh_file = File('params/%s.hh' % name)
597 params_hh_files.append(hh_file)
598 env.Command(hh_file, Value(name),
594 MakeAction(createSimObjectParam, Transform("SO PARAM")))
599 MakeAction(createSimObjectParamStruct, Transform("SO PARAM")))
595 env.Depends(hh_file, depends + extra_deps)
596
600 env.Depends(hh_file, depends + extra_deps)
601
597# Generate any parameter header files needed
602# Generate any needed param SWIG wrapper files
598params_i_files = []
603params_i_files = []
599for name,param in all_params.iteritems():
600 i_file = File('python/m5/internal/%s_%s.i' % (param.file_ext, name))
604for name,param in params_to_swig.iteritems():
605 i_file = File('python/m5/internal/%s.i' % (param.swig_module_name()))
601 params_i_files.append(i_file)
602 env.Command(i_file, Value(name),
606 params_i_files.append(i_file)
607 env.Command(i_file, Value(name),
603 MakeAction(createSwigParam, Transform("SW PARAM")))
608 MakeAction(createParamSwigWrapper, Transform("SW PARAM")))
604 env.Depends(i_file, depends)
605 SwigSource('m5.internal', i_file)
606
607# Generate all enum header files
608for name,enum in sorted(all_enums.iteritems()):
609 py_source = PySource.modules[enum.__module__]
610 extra_deps = [ py_source.tnode ]
611
612 cc_file = File('enums/%s.cc' % name)
613 env.Command(cc_file, Value(name),
614 MakeAction(createEnumStrings, Transform("ENUM STR")))
615 env.Depends(cc_file, depends + extra_deps)
616 Source(cc_file)
617
618 hh_file = File('enums/%s.hh' % name)
619 env.Command(hh_file, Value(name),
609 env.Depends(i_file, depends)
610 SwigSource('m5.internal', i_file)
611
612# Generate all enum header files
613for name,enum in sorted(all_enums.iteritems()):
614 py_source = PySource.modules[enum.__module__]
615 extra_deps = [ py_source.tnode ]
616
617 cc_file = File('enums/%s.cc' % name)
618 env.Command(cc_file, Value(name),
619 MakeAction(createEnumStrings, Transform("ENUM STR")))
620 env.Depends(cc_file, depends + extra_deps)
621 Source(cc_file)
622
623 hh_file = File('enums/%s.hh' % name)
624 env.Command(hh_file, Value(name),
620 MakeAction(createEnumParam, Transform("EN PARAM")))
625 MakeAction(createEnumDecls, Transform("ENUMDECL")))
621 env.Depends(hh_file, depends + extra_deps)
622
623 i_file = File('python/m5/internal/enum_%s.i' % name)
624 env.Command(i_file, Value(name),
626 env.Depends(hh_file, depends + extra_deps)
627
628 i_file = File('python/m5/internal/enum_%s.i' % name)
629 env.Command(i_file, Value(name),
625 MakeAction(createEnumSwig, Transform("ENUMSWIG")))
630 MakeAction(createEnumSwigWrapper, Transform("ENUMSWIG")))
626 env.Depends(i_file, depends + extra_deps)
627 SwigSource('m5.internal', i_file)
628
631 env.Depends(i_file, depends + extra_deps)
632 SwigSource('m5.internal', i_file)
633
629def buildParam(target, source, env):
630 name = source[0].get_contents()
631 obj = sim_objects[name]
632 class_path = obj.cxx_class.split('::')
633 classname = class_path[-1]
634 namespaces = class_path[:-1]
635 params = obj._params.local.values()
636
637 code = code_formatter()
638
639 code('%module(package="m5.internal") param_$name')
640 code()
641 code('%{')
642 code('#include "params/$obj.hh"')
643 for param in params:
644 param.cxx_predecls(code)
645 code('%}')
646 code()
647
648 for param in params:
649 param.swig_predecls(code)
650
651 code()
652 if obj._base:
653 code('%import "python/m5/internal/param_${{obj._base}}.i"')
654 code()
655 obj.swig_objdecls(code)
656 code()
657
658 code('%include "params/$obj.hh"')
659
660 code.write(target[0].abspath)
661
634# Generate SimObject SWIG wrapper files
662for name in sim_objects.iterkeys():
635for name in sim_objects.iterkeys():
663 params_file = File('python/m5/internal/param_%s.i' % name)
664 env.Command(params_file, Value(name),
665 MakeAction(buildParam, Transform("BLDPARAM")))
666 env.Depends(params_file, depends)
667 SwigSource('m5.internal', params_file)
636 i_file = File('python/m5/internal/param_%s.i' % name)
637 env.Command(i_file, Value(name),
638 MakeAction(createSimObjectSwigWrapper, Transform("SO SWIG")))
639 env.Depends(i_file, depends)
640 SwigSource('m5.internal', i_file)
668
669# Generate the main swig init file
670def makeEmbeddedSwigInit(target, source, env):
671 code = code_formatter()
672 module = source[0].get_contents()
673 code('''\
674#include "sim/init.hh"
675

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

682 code.write(str(target[0]))
683
684# Build all swig modules
685for swig in SwigSource.all:
686 env.Command([swig.cc_source.tnode, swig.py_source.tnode], swig.tnode,
687 MakeAction('$SWIG $SWIGFLAGS -outdir ${TARGETS[1].dir} '
688 '-o ${TARGETS[0]} $SOURCES', Transform("SWIG")))
689 cc_file = str(swig.tnode)
641
642# Generate the main swig init file
643def makeEmbeddedSwigInit(target, source, env):
644 code = code_formatter()
645 module = source[0].get_contents()
646 code('''\
647#include "sim/init.hh"
648

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

655 code.write(str(target[0]))
656
657# Build all swig modules
658for swig in SwigSource.all:
659 env.Command([swig.cc_source.tnode, swig.py_source.tnode], swig.tnode,
660 MakeAction('$SWIG $SWIGFLAGS -outdir ${TARGETS[1].dir} '
661 '-o ${TARGETS[0]} $SOURCES', Transform("SWIG")))
662 cc_file = str(swig.tnode)
690 init_file = '%s/init_%s.cc' % (dirname(cc_file), basename(cc_file))
663 init_file = '%s/%s_init.cc' % (dirname(cc_file), basename(cc_file))
691 env.Command(init_file, Value(swig.module),
692 MakeAction(makeEmbeddedSwigInit, Transform("EMBED SW")))
693 Source(init_file, **swig.guards)
694
695#
696# Handle debug flags
697#
698def makeDebugFlagCC(target, source, env):

--- 299 unchanged lines hidden ---
664 env.Command(init_file, Value(swig.module),
665 MakeAction(makeEmbeddedSwigInit, Transform("EMBED SW")))
666 Source(init_file, **swig.guards)
667
668#
669# Handle debug flags
670#
671def makeDebugFlagCC(target, source, env):

--- 299 unchanged lines hidden ---