SConscript (7674:8e3734851770) SConscript (7675:2221ec64132f)
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

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

394 if pname not in all_params:
395 all_params[pname] = param
396
397########################################################################
398#
399# calculate extra dependencies
400#
401module_depends = ["m5", "m5.SimObject", "m5.params"]
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

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

394 if pname not in all_params:
395 all_params[pname] = param
396
397########################################################################
398#
399# calculate extra dependencies
400#
401module_depends = ["m5", "m5.SimObject", "m5.params"]
402depends = [ PySource.modules[dep].tnode for dep in module_depends ]
402depends = [ PySource.modules[dep].snode for dep in module_depends ]
403
404########################################################################
405#
406# Commands for the basic automatically generated python files
407#
408
409# Generate Python file containing a dict specifying the current
410# buildEnv flags.

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

465
466def createSwigParam(target, source, env):
467 assert len(target) == 1 and len(source) == 1
468
469 name = str(source[0].get_contents())
470 param = all_params[name]
471
472 code = code_formatter()
403
404########################################################################
405#
406# Commands for the basic automatically generated python files
407#
408
409# Generate Python file containing a dict specifying the current
410# buildEnv flags.

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

465
466def createSwigParam(target, source, env):
467 assert len(target) == 1 and len(source) == 1
468
469 name = str(source[0].get_contents())
470 param = all_params[name]
471
472 code = code_formatter()
473 code('%module(package="m5.internal.swig") ${name}_$0', param.file_ext)
473 param.swig_decl(code)
474 code.write(target[0].abspath)
475
476def createEnumStrings(target, source, env):
477 assert len(target) == 1 and len(source) == 1
478
479 name = str(source[0].get_contents())
480 obj = all_enums[name]

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

488
489 name = str(source[0].get_contents())
490 obj = all_enums[name]
491
492 code = code_formatter()
493 obj.cxx_decl(code)
494 code.write(target[0].abspath)
495
474 param.swig_decl(code)
475 code.write(target[0].abspath)
476
477def createEnumStrings(target, source, env):
478 assert len(target) == 1 and len(source) == 1
479
480 name = str(source[0].get_contents())
481 obj = all_enums[name]

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

489
490 name = str(source[0].get_contents())
491 obj = all_enums[name]
492
493 code = code_formatter()
494 obj.cxx_decl(code)
495 code.write(target[0].abspath)
496
497def createEnumSwig(target, source, env):
498 assert len(target) == 1 and len(source) == 1
499
500 name = str(source[0].get_contents())
501 obj = all_enums[name]
502
503 code = code_formatter()
504 code('''\
505%module(package="m5.internal.enums") $name
506
507%{
508#include "enums/$name.hh"
509%}
510
511%include "enums/$name.hh"
512''')
513 code.write(target[0].abspath)
514
496# Generate all of the SimObject param struct header files
497params_hh_files = []
498for name,simobj in sorted(sim_objects.iteritems()):
499 py_source = PySource.modules[simobj.__module__]
500 extra_deps = [ py_source.tnode ]
501
502 hh_file = File('params/%s.hh' % name)
503 params_hh_files.append(hh_file)
504 env.Command(hh_file, Value(name), createSimObjectParam)
505 env.Depends(hh_file, depends + extra_deps)
506
507# Generate any parameter header files needed
508params_i_files = []
509for name,param in all_params.iteritems():
510 i_file = File('params/%s_%s.i' % (name, param.file_ext))
511 params_i_files.append(i_file)
512 env.Command(i_file, Value(name), createSwigParam)
513 env.Depends(i_file, depends)
515# Generate all of the SimObject param struct header files
516params_hh_files = []
517for name,simobj in sorted(sim_objects.iteritems()):
518 py_source = PySource.modules[simobj.__module__]
519 extra_deps = [ py_source.tnode ]
520
521 hh_file = File('params/%s.hh' % name)
522 params_hh_files.append(hh_file)
523 env.Command(hh_file, Value(name), createSimObjectParam)
524 env.Depends(hh_file, depends + extra_deps)
525
526# Generate any parameter header files needed
527params_i_files = []
528for name,param in all_params.iteritems():
529 i_file = File('params/%s_%s.i' % (name, param.file_ext))
530 params_i_files.append(i_file)
531 env.Command(i_file, Value(name), createSwigParam)
532 env.Depends(i_file, depends)
533 SwigSource('m5.internal.swig', i_file)
514
515# Generate all enum header files
516for name,enum in sorted(all_enums.iteritems()):
517 py_source = PySource.modules[enum.__module__]
518 extra_deps = [ py_source.tnode ]
519
520 cc_file = File('enums/%s.cc' % name)
521 env.Command(cc_file, Value(name), createEnumStrings)
522 env.Depends(cc_file, depends + extra_deps)
523 Source(cc_file)
524
525 hh_file = File('enums/%s.hh' % name)
526 env.Command(hh_file, Value(name), createEnumParam)
527 env.Depends(hh_file, depends + extra_deps)
528
534
535# Generate all enum header files
536for name,enum in sorted(all_enums.iteritems()):
537 py_source = PySource.modules[enum.__module__]
538 extra_deps = [ py_source.tnode ]
539
540 cc_file = File('enums/%s.cc' % name)
541 env.Command(cc_file, Value(name), createEnumStrings)
542 env.Depends(cc_file, depends + extra_deps)
543 Source(cc_file)
544
545 hh_file = File('enums/%s.hh' % name)
546 env.Command(hh_file, Value(name), createEnumParam)
547 env.Depends(hh_file, depends + extra_deps)
548
529# Build the big monolithic swigged params module (wraps all SimObject
530# param structs and enum structs)
531def buildParams(target, source, env):
532 names = [ s.get_contents() for s in source ]
533 objs = [ sim_objects[name] for name in names ]
549 i_file = File('enums/%s.i' % name)
550 env.Command(i_file, Value(name), createEnumSwig)
551 env.Depends(i_file, depends + extra_deps)
552 SwigSource('m5.internal.enums', i_file)
534
553
535 ordered_objs = []
536 obj_seen = set()
537 def order_obj(obj):
538 name = str(obj)
539 if name in obj_seen:
540 return
554def buildParam(target, source, env):
555 name = source[0].get_contents()
556 obj = sim_objects[name]
557 class_path = obj.cxx_class.split('::')
558 classname = class_path[-1]
559 namespaces = class_path[:-1]
560 params = obj._params.local.values()
541
561
542 obj_seen.add(name)
543 if str(obj) != 'SimObject':
544 order_obj(obj.__bases__[0])
545
546 ordered_objs.append(obj)
547
548 for obj in objs:
549 order_obj(obj)
550
551 code = code_formatter()
562 code = code_formatter()
552 code('%module params')
553
563
564 code('%module(package="m5.internal.params") $name')
565 code()
554 code('%{')
566 code('%{')
555 for obj in ordered_objs:
556 code('#include "params/$obj.hh"')
567 code('#include "params/$obj.hh"')
568 for param in params:
569 param.cxx_predecls(code)
557 code('%}')
570 code('%}')
571 code()
558
572
559 for obj in ordered_objs:
560 params = obj._params.local.values()
561 for param in params:
562 param.swig_predecls(code)
573 for param in params:
574 param.swig_predecls(code)
563
575
564 enums = set()
565 for obj in ordered_objs:
566 params = obj._params.local.values()
567 for param in params:
568 ptype = param.ptype
569 if issubclass(ptype, m5.params.Enum) and ptype not in enums:
570 enums.add(ptype)
571 code('%include "enums/$0.hh"', ptype.__name__)
572
573 for obj in ordered_objs:
574 obj.swig_objdecls(code)
575 code()
576 code()
577 if obj._base:
578 code('%import "params/${{obj._base}}.i"')
579 code()
580 obj.swig_objdecls(code)
581 code()
576
582
577 for obj in ordered_objs:
578 continue
579 if obj.swig_objdecls:
580 obj.swig_objdecls(code)
581 continue
583 code('%include "params/$obj.hh"')
582
584
583 class_path = obj.cxx_class.split('::')
584 classname = class_path[-1]
585 namespaces = class_path[:-1]
586
587 for ns in namespaces:
588 code('namespace $ns {')
589
590 if namespaces:
591 code('// avoid name conflicts')
592 sep_string = '_COLONS_'
593 flat_name = sep_string.join(class_path)
594 code('%rename($flat_name) $classname;')
595
596 code('// stop swig from creating/wrapping default ctor/dtor')
597 code('%nodefault $classname;')
598 if obj._base:
599 code('class $classname : public ${{obj._base.cxx_class}} {};')
600 else:
601 code('class $classname {};')
602
603 for ns in reversed(namespaces):
604 code('/* namespace $ns */ }')
605 code()
606
607 code('%include "src/sim/sim_object_params.hh"')
608 for obj in ordered_objs:
609 code('%include "params/$obj.hh"')
610
611 code.write(target[0].abspath)
612
585 code.write(target[0].abspath)
586
613params_file = File('params/params.i')
614names = sorted(sim_objects.keys())
615env.Command(params_file, map(Value, names), buildParams)
616env.Depends(params_file, params_hh_files + params_i_files + depends)
617SwigSource('m5.objects', params_file)
587for name in sim_objects.iterkeys():
588 params_file = File('params/%s.i' % name)
589 env.Command(params_file, Value(name), buildParam)
590 env.Depends(params_file, depends)
591 SwigSource('m5.internal.params', params_file)
618
619# Generate the main swig init file
620def makeEmbeddedSwigInit(target, source, env):
621 code = code_formatter()
622 module = source[0].get_contents()
623 code('''\
624#include "sim/init.hh"
625

--- 441 unchanged lines hidden ---
592
593# Generate the main swig init file
594def makeEmbeddedSwigInit(target, source, env):
595 code = code_formatter()
596 module = source[0].get_contents()
597 code('''\
598#include "sim/init.hh"
599

--- 441 unchanged lines hidden ---