Deleted Added
sdiff udiff text old ( 8594:0e77bd34385f ) new ( 8596:e6e22fa77883 )
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

--- 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 = {}
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
464 if pname not in all_params:
465 all_params[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
526def createSimObjectParam(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 obj.cxx_decl(code)
534 code.write(target[0].abspath)
535
536def createSwigParam(target, source, env):
537 assert len(target) == 1 and len(source) == 1
538
539 name = str(source[0].get_contents())
540 param = all_params[name]
541
542 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
557def createEnumParam(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
567def createEnumSwig(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()
574 code('''\
575%module(package="m5.internal") enum_$name
576
577%{
578#include "enums/$name.hh"
579%}
580
581%include "enums/$name.hh"
582''')
583 code.write(target[0].abspath)
584
585# Generate all of the SimObject param 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),
594 MakeAction(createSimObjectParam, Transform("SO PARAM")))
595 env.Depends(hh_file, depends + extra_deps)
596
597# Generate any parameter header files needed
598params_i_files = []
599for name,param in all_params.iteritems():
600 i_file = File('python/m5/internal/%s_%s.i' % (param.file_ext, name))
601 params_i_files.append(i_file)
602 env.Command(i_file, Value(name),
603 MakeAction(createSwigParam, 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),
620 MakeAction(createEnumParam, Transform("EN PARAM")))
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),
625 MakeAction(createEnumSwig, Transform("ENUMSWIG")))
626 env.Depends(i_file, depends + extra_deps)
627 SwigSource('m5.internal', i_file)
628
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
662for 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)
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)
690 init_file = '%s/init_%s.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 ---