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 |
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 = {} |
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 |
470 if pname not in params_to_swig: 471 params_to_swig[pname] = param |
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 |
532def createSimObjectParamStruct(target, source, env): |
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() |
539 obj.cxx_param_decl(code) |
540 code.write(target[0].abspath) 541 |
542def createParamSwigWrapper(target, source, env): |
543 assert len(target) == 1 and len(source) == 1 544 545 name = str(source[0].get_contents()) |
546 param = params_to_swig[name] |
547 548 code = code_formatter() |
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 |
562def createEnumDecls(target, source, env): |
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 |
572def createEnumSwigWrapper(target, source, env): |
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() |
579 obj.swig_decl(code) 580 code.write(target[0].abspath) |
581 |
582def createSimObjectSwigWrapper(target, source, env): 583 name = source[0].get_contents() 584 obj = sim_objects[name] |
585 |
586 code = code_formatter() 587 obj.swig_decl(code) |
588 code.write(target[0].abspath) 589 |
590# Generate all of the SimObject param C++ struct header files |
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), |
599 MakeAction(createSimObjectParamStruct, Transform("SO PARAM"))) |
600 env.Depends(hh_file, depends + extra_deps) 601 |
602# Generate any needed param SWIG wrapper files |
603params_i_files = [] |
604for name,param in params_to_swig.iteritems(): 605 i_file = File('python/m5/internal/%s.i' % (param.swig_module_name())) |
606 params_i_files.append(i_file) 607 env.Command(i_file, Value(name), |
608 MakeAction(createParamSwigWrapper, Transform("SW PARAM"))) |
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), |
625 MakeAction(createEnumDecls, Transform("ENUMDECL"))) |
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), |
630 MakeAction(createEnumSwigWrapper, Transform("ENUMSWIG"))) |
631 env.Depends(i_file, depends + extra_deps) 632 SwigSource('m5.internal', i_file) 633 |
634# Generate SimObject SWIG wrapper files |
635for name in sim_objects.iterkeys(): |
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) |
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) |
663 init_file = '%s/%s_init.cc' % (dirname(cc_file), basename(cc_file)) |
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 --- |