SConscript revision 5798
1955SN/A# -*- mode:python -*- 2955SN/A 31762SN/A# Copyright (c) 2004-2005 The Regents of The University of Michigan 4955SN/A# All rights reserved. 5955SN/A# 6955SN/A# Redistribution and use in source and binary forms, with or without 7955SN/A# modification, are permitted provided that the following conditions are 8955SN/A# met: redistributions of source code must retain the above copyright 9955SN/A# notice, this list of conditions and the following disclaimer; 10955SN/A# redistributions in binary form must reproduce the above copyright 11955SN/A# notice, this list of conditions and the following disclaimer in the 12955SN/A# documentation and/or other materials provided with the distribution; 13955SN/A# neither the name of the copyright holders nor the names of its 14955SN/A# contributors may be used to endorse or promote products derived from 15955SN/A# this software without specific prior written permission. 16955SN/A# 17955SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26955SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27955SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 282665Ssaidi@eecs.umich.edu# 294762Snate@binkert.org# Authors: Nathan Binkert 30955SN/A 315522Snate@binkert.orgimport array 326143Snate@binkert.orgimport imp 334762Snate@binkert.orgimport marshal 345522Snate@binkert.orgimport os 35955SN/Aimport re 365522Snate@binkert.orgimport sys 37955SN/Aimport zlib 385522Snate@binkert.org 394202Sbinkertn@umich.edufrom os.path import basename, dirname, exists, isdir, isfile, join as joinpath 405742Snate@binkert.org 41955SN/Aimport SCons 424381Sbinkertn@umich.edu 434381Sbinkertn@umich.edu# This file defines how to build a particular configuration of M5 448334Snate@binkert.org# based on variable settings in the 'env' build environment. 45955SN/A 46955SN/AImport('*') 474202Sbinkertn@umich.edu 48955SN/A# Children need to see the environment 494382Sbinkertn@umich.eduExport('env') 504382Sbinkertn@umich.edu 514382Sbinkertn@umich.edubuild_env = dict([(opt, env[opt]) for opt in env.ExportOptions]) 526654Snate@binkert.org 535517Snate@binkert.orgdef sort_list(_list): 548614Sgblack@eecs.umich.edu """return a sorted copy of '_list'""" 557674Snate@binkert.org if isinstance(_list, list): 566143Snate@binkert.org _list = _list[:] 576143Snate@binkert.org else: 586143Snate@binkert.org _list = list(_list) 598233Snate@binkert.org _list.sort() 608233Snate@binkert.org return _list 618233Snate@binkert.org 628233Snate@binkert.orgclass PySourceFile(object): 638233Snate@binkert.org invalid_sym_char = re.compile('[^A-z0-9_]') 648334Snate@binkert.org def __init__(self, package, tnode): 658334Snate@binkert.org snode = tnode.srcnode() 668233Snate@binkert.org filename = str(tnode) 678233Snate@binkert.org pyname = basename(filename) 688233Snate@binkert.org assert pyname.endswith('.py') 698233Snate@binkert.org name = pyname[:-3] 708233Snate@binkert.org if package: 718233Snate@binkert.org path = package.split('.') 726143Snate@binkert.org else: 738233Snate@binkert.org path = [] 748233Snate@binkert.org 758233Snate@binkert.org modpath = path[:] 766143Snate@binkert.org if name != '__init__': 776143Snate@binkert.org modpath += [name] 786143Snate@binkert.org modpath = '.'.join(modpath) 796143Snate@binkert.org 808233Snate@binkert.org arcpath = path + [ pyname ] 818233Snate@binkert.org arcname = joinpath(*arcpath) 828233Snate@binkert.org 836143Snate@binkert.org debugname = snode.abspath 848233Snate@binkert.org if not exists(debugname): 858233Snate@binkert.org debugname = tnode.abspath 868233Snate@binkert.org 878233Snate@binkert.org self.tnode = tnode 886143Snate@binkert.org self.snode = snode 896143Snate@binkert.org self.pyname = pyname 906143Snate@binkert.org self.package = package 914762Snate@binkert.org self.modpath = modpath 926143Snate@binkert.org self.arcname = arcname 938233Snate@binkert.org self.debugname = debugname 948233Snate@binkert.org self.compiled = File(filename + 'c') 958233Snate@binkert.org self.assembly = File(filename + '.s') 968233Snate@binkert.org self.symname = "PyEMB_" + self.invalid_sym_char.sub('_', modpath) 978233Snate@binkert.org 986143Snate@binkert.org 998233Snate@binkert.org######################################################################## 1008233Snate@binkert.org# Code for adding source files of various types 1018233Snate@binkert.org# 1028233Snate@binkert.orgcc_lib_sources = [] 1036143Snate@binkert.orgdef Source(source): 1046143Snate@binkert.org '''Add a source file to the libm5 build''' 1056143Snate@binkert.org if not isinstance(source, SCons.Node.FS.File): 1066143Snate@binkert.org source = File(source) 1076143Snate@binkert.org 1086143Snate@binkert.org cc_lib_sources.append(source) 1096143Snate@binkert.org 1106143Snate@binkert.orgcc_bin_sources = [] 1116143Snate@binkert.orgdef BinSource(source): 1127065Snate@binkert.org '''Add a source file to the m5 binary build''' 1136143Snate@binkert.org if not isinstance(source, SCons.Node.FS.File): 1148233Snate@binkert.org source = File(source) 1158233Snate@binkert.org 1168233Snate@binkert.org cc_bin_sources.append(source) 1178233Snate@binkert.org 1188233Snate@binkert.orgpy_sources = [] 1198233Snate@binkert.orgdef PySource(package, source): 1208233Snate@binkert.org '''Add a python source file to the named package''' 1218233Snate@binkert.org if not isinstance(source, SCons.Node.FS.File): 1228233Snate@binkert.org source = File(source) 1238233Snate@binkert.org 1248233Snate@binkert.org source = PySourceFile(package, source) 1258233Snate@binkert.org py_sources.append(source) 1268233Snate@binkert.org 1278233Snate@binkert.orgsim_objects_fixed = False 1288233Snate@binkert.orgsim_object_modfiles = set() 1298233Snate@binkert.orgdef SimObject(source): 1308233Snate@binkert.org '''Add a SimObject python file as a python source object and add 1318233Snate@binkert.org it to a list of sim object modules''' 1328233Snate@binkert.org 1338233Snate@binkert.org if sim_objects_fixed: 1348233Snate@binkert.org raise AttributeError, "Too late to call SimObject now." 1358233Snate@binkert.org 1368233Snate@binkert.org if not isinstance(source, SCons.Node.FS.File): 1378233Snate@binkert.org source = File(source) 1388233Snate@binkert.org 1398233Snate@binkert.org PySource('m5.objects', source) 1408233Snate@binkert.org modfile = basename(str(source)) 1418233Snate@binkert.org assert modfile.endswith('.py') 1428233Snate@binkert.org modname = modfile[:-3] 1438233Snate@binkert.org sim_object_modfiles.add(modname) 1448233Snate@binkert.org 1456143Snate@binkert.orgswig_sources = [] 1466143Snate@binkert.orgdef SwigSource(package, source): 1476143Snate@binkert.org '''Add a swig file to build''' 1486143Snate@binkert.org if not isinstance(source, SCons.Node.FS.File): 1496143Snate@binkert.org source = File(source) 1506143Snate@binkert.org val = source,package 1516143Snate@binkert.org swig_sources.append(val) 1526143Snate@binkert.org 1536143Snate@binkert.orgunit_tests = [] 1548945Ssteve.reinhardt@amd.comdef UnitTest(target, sources): 1558233Snate@binkert.org if not isinstance(sources, (list, tuple)): 1568233Snate@binkert.org sources = [ sources ] 1576143Snate@binkert.org 1588945Ssteve.reinhardt@amd.com srcs = [] 1596143Snate@binkert.org for source in sources: 1606143Snate@binkert.org if not isinstance(source, SCons.Node.FS.File): 1616143Snate@binkert.org source = File(source) 1626143Snate@binkert.org srcs.append(source) 1635522Snate@binkert.org 1646143Snate@binkert.org unit_tests.append((target, srcs)) 1656143Snate@binkert.org 1666143Snate@binkert.org# Children should have access 1676143Snate@binkert.orgExport('Source') 1688233Snate@binkert.orgExport('BinSource') 1698233Snate@binkert.orgExport('PySource') 1708233Snate@binkert.orgExport('SimObject') 1716143Snate@binkert.orgExport('SwigSource') 1726143Snate@binkert.orgExport('UnitTest') 1736143Snate@binkert.org 1746143Snate@binkert.org######################################################################## 1755522Snate@binkert.org# 1765522Snate@binkert.org# Trace Flags 1775522Snate@binkert.org# 1785522Snate@binkert.orgall_flags = {} 1795604Snate@binkert.orgtrace_flags = [] 1805604Snate@binkert.orgdef TraceFlag(name, desc=''): 1816143Snate@binkert.org if name in all_flags: 1826143Snate@binkert.org raise AttributeError, "Flag %s already specified" % name 1834762Snate@binkert.org flag = (name, (), desc) 1844762Snate@binkert.org trace_flags.append(flag) 1856143Snate@binkert.org all_flags[name] = () 1866727Ssteve.reinhardt@amd.com 1876727Ssteve.reinhardt@amd.comdef CompoundFlag(name, flags, desc=''): 1886727Ssteve.reinhardt@amd.com if name in all_flags: 1894762Snate@binkert.org raise AttributeError, "Flag %s already specified" % name 1906143Snate@binkert.org 1916143Snate@binkert.org compound = tuple(flags) 1926143Snate@binkert.org for flag in compound: 1936143Snate@binkert.org if flag not in all_flags: 1946727Ssteve.reinhardt@amd.com raise AttributeError, "Trace flag %s not found" % flag 1956143Snate@binkert.org if all_flags[flag]: 1967674Snate@binkert.org raise AttributeError, \ 1977674Snate@binkert.org "Compound flag can't point to another compound flag" 1985604Snate@binkert.org 1996143Snate@binkert.org flag = (name, compound, desc) 2006143Snate@binkert.org trace_flags.append(flag) 2016143Snate@binkert.org all_flags[name] = compound 2024762Snate@binkert.org 2036143Snate@binkert.orgExport('TraceFlag') 2044762Snate@binkert.orgExport('CompoundFlag') 2054762Snate@binkert.org 2064762Snate@binkert.org######################################################################## 2076143Snate@binkert.org# 2086143Snate@binkert.org# Set some compiler variables 2094762Snate@binkert.org# 2108233Snate@binkert.org 2118233Snate@binkert.org# Include file paths are rooted in this directory. SCons will 2128233Snate@binkert.org# automatically expand '.' to refer to both the source directory and 2138233Snate@binkert.org# the corresponding build directory to pick up generated include 2146143Snate@binkert.org# files. 2156143Snate@binkert.orgenv.Append(CPPPATH=Dir('.')) 2164762Snate@binkert.org 2176143Snate@binkert.orgfor extra_dir in extras_dir_list: 2184762Snate@binkert.org env.Append(CPPPATH=Dir(extra_dir)) 2196143Snate@binkert.org 2204762Snate@binkert.org# Add a flag defining what THE_ISA should be for all compilation 2216143Snate@binkert.orgenv.Append(CPPDEFINES=[('THE_ISA','%s_ISA' % env['TARGET_ISA'].upper())]) 2228233Snate@binkert.org 2238233Snate@binkert.org# Workaround for bug in SCons version > 0.97d20071212 2248233Snate@binkert.org# Scons bug id: 2006 M5 Bug id: 308 2256143Snate@binkert.orgfor root, dirs, files in os.walk(base_dir, topdown=True): 2266143Snate@binkert.org Dir(root[len(base_dir) + 1:]) 2276143Snate@binkert.org 2286143Snate@binkert.org######################################################################## 2296143Snate@binkert.org# 2306143Snate@binkert.org# Walk the tree and execute all SConscripts in subdirectories 2316143Snate@binkert.org# 2326143Snate@binkert.org 2338233Snate@binkert.orghere = Dir('.').srcnode().abspath 2348233Snate@binkert.orgfor root, dirs, files in os.walk(base_dir, topdown=True): 235955SN/A if root == here: 2368235Snate@binkert.org # we don't want to recurse back into this SConscript 2378235Snate@binkert.org continue 2386143Snate@binkert.org 2398235Snate@binkert.org if 'SConscript' in files: 2409003SAli.Saidi@ARM.com build_dir = joinpath(env['BUILDDIR'], root[len(base_dir) + 1:]) 2418235Snate@binkert.org SConscript(joinpath(root, 'SConscript'), build_dir=build_dir) 2428235Snate@binkert.org 2438235Snate@binkert.orgfor extra_dir in extras_dir_list: 2448235Snate@binkert.org prefix_len = len(dirname(extra_dir)) + 1 2458235Snate@binkert.org for root, dirs, files in os.walk(extra_dir, topdown=True): 2468235Snate@binkert.org if 'SConscript' in files: 2478235Snate@binkert.org build_dir = joinpath(env['BUILDDIR'], root[prefix_len:]) 2488235Snate@binkert.org SConscript(joinpath(root, 'SConscript'), build_dir=build_dir) 2498235Snate@binkert.org 2508235Snate@binkert.orgfor opt in env.ExportOptions: 2518235Snate@binkert.org env.ConfigFile(opt) 2528235Snate@binkert.org 2538235Snate@binkert.org######################################################################## 2548235Snate@binkert.org# 2559003SAli.Saidi@ARM.com# Prevent any SimObjects from being added after this point, they 2568235Snate@binkert.org# should all have been added in the SConscripts above 2575584Snate@binkert.org# 2584382Sbinkertn@umich.educlass DictImporter(object): 2594202Sbinkertn@umich.edu '''This importer takes a dictionary of arbitrary module names that 2604382Sbinkertn@umich.edu map to arbitrary filenames.''' 2614382Sbinkertn@umich.edu def __init__(self, modules): 2624382Sbinkertn@umich.edu self.modules = modules 2635584Snate@binkert.org self.installed = set() 2644382Sbinkertn@umich.edu 2654382Sbinkertn@umich.edu def __del__(self): 2664382Sbinkertn@umich.edu self.unload() 2678232Snate@binkert.org 2685192Ssaidi@eecs.umich.edu def unload(self): 2698232Snate@binkert.org import sys 2708232Snate@binkert.org for module in self.installed: 2718232Snate@binkert.org del sys.modules[module] 2725192Ssaidi@eecs.umich.edu self.installed = set() 2738232Snate@binkert.org 2745192Ssaidi@eecs.umich.edu def find_module(self, fullname, path): 2755799Snate@binkert.org if fullname == 'defines': 2768232Snate@binkert.org return self 2775192Ssaidi@eecs.umich.edu 2785192Ssaidi@eecs.umich.edu if fullname == 'm5.objects': 2795192Ssaidi@eecs.umich.edu return self 2808232Snate@binkert.org 2815192Ssaidi@eecs.umich.edu if fullname.startswith('m5.internal'): 2828232Snate@binkert.org return None 2835192Ssaidi@eecs.umich.edu 2845192Ssaidi@eecs.umich.edu if fullname in self.modules and exists(self.modules[fullname]): 2855192Ssaidi@eecs.umich.edu return self 2865192Ssaidi@eecs.umich.edu 2874382Sbinkertn@umich.edu return None 2884382Sbinkertn@umich.edu 2894382Sbinkertn@umich.edu def load_module(self, fullname): 2902667Sstever@eecs.umich.edu mod = imp.new_module(fullname) 2912667Sstever@eecs.umich.edu sys.modules[fullname] = mod 2922667Sstever@eecs.umich.edu self.installed.add(fullname) 2932667Sstever@eecs.umich.edu 2942667Sstever@eecs.umich.edu mod.__loader__ = self 2952667Sstever@eecs.umich.edu if fullname == 'm5.objects': 2965742Snate@binkert.org mod.__path__ = fullname.split('.') 2975742Snate@binkert.org return mod 2985742Snate@binkert.org 2995793Snate@binkert.org if fullname == 'defines': 3008334Snate@binkert.org mod.__dict__['buildEnv'] = build_env 3015793Snate@binkert.org return mod 3025793Snate@binkert.org 3035793Snate@binkert.org srcfile = self.modules[fullname] 3044382Sbinkertn@umich.edu if basename(srcfile) == '__init__.py': 3054762Snate@binkert.org mod.__path__ = fullname.split('.') 3065344Sstever@gmail.com mod.__file__ = srcfile 3074382Sbinkertn@umich.edu 3085341Sstever@gmail.com exec file(srcfile, 'r') in mod.__dict__ 3095742Snate@binkert.org 3105742Snate@binkert.org return mod 3115742Snate@binkert.org 3125742Snate@binkert.orgpy_modules = {} 3135742Snate@binkert.orgfor source in py_sources: 3144762Snate@binkert.org py_modules[source.modpath] = source.snode.abspath 3155742Snate@binkert.org 3165742Snate@binkert.org# install the python importer so we can grab stuff from the source 3177722Sgblack@eecs.umich.edu# tree itself. We can't have SimObjects added after this point or 3185742Snate@binkert.org# else we won't know about them for the rest of the stuff. 3195742Snate@binkert.orgsim_objects_fixed = True 3205742Snate@binkert.orgimporter = DictImporter(py_modules) 3215742Snate@binkert.orgsys.meta_path[0:0] = [ importer ] 3228242Sbradley.danofsky@amd.com 3238242Sbradley.danofsky@amd.comimport m5 3248242Sbradley.danofsky@amd.com 3258242Sbradley.danofsky@amd.com# import all sim objects so we can populate the all_objects list 3265341Sstever@gmail.com# make sure that we're working with a list, then let's sort it 3275742Snate@binkert.orgsim_objects = list(sim_object_modfiles) 3287722Sgblack@eecs.umich.edusim_objects.sort() 3294773Snate@binkert.orgfor simobj in sim_objects: 3306108Snate@binkert.org exec('from m5.objects import %s' % simobj) 3311858SN/A 3321085SN/A# we need to unload all of the currently imported modules so that they 3336658Snate@binkert.org# will be re-imported the next time the sconscript is run 3346658Snate@binkert.orgimporter.unload() 3357673Snate@binkert.orgsys.meta_path.remove(importer) 3366658Snate@binkert.org 3376658Snate@binkert.orgsim_objects = m5.SimObject.allClasses 3386658Snate@binkert.orgall_enums = m5.params.allEnums 3396658Snate@binkert.org 3406658Snate@binkert.orgall_params = {} 3416658Snate@binkert.orgfor name,obj in sim_objects.iteritems(): 3426658Snate@binkert.org for param in obj._params.local.values(): 3437673Snate@binkert.org if not hasattr(param, 'swig_decl'): 3447673Snate@binkert.org continue 3457673Snate@binkert.org pname = param.ptype_str 3467673Snate@binkert.org if pname not in all_params: 3477673Snate@binkert.org all_params[pname] = param 3487673Snate@binkert.org 3497673Snate@binkert.org######################################################################## 3506658Snate@binkert.org# 3517673Snate@binkert.org# calculate extra dependencies 3527673Snate@binkert.org# 3537673Snate@binkert.orgmodule_depends = ["m5", "m5.SimObject", "m5.params"] 3547673Snate@binkert.orgdepends = [ File(py_modules[dep]) for dep in module_depends ] 3557673Snate@binkert.org 3567673Snate@binkert.org######################################################################## 3579048SAli.Saidi@ARM.com# 3587673Snate@binkert.org# Commands for the basic automatically generated python files 3597673Snate@binkert.org# 3607673Snate@binkert.org 3617673Snate@binkert.orgscons_dir = str(SCons.Node.FS.default_fs.SConstruct_dir) 3626658Snate@binkert.org 3637756SAli.Saidi@ARM.comhg_info = ("Unknown", "Unknown", "Unknown") 3647816Ssteve.reinhardt@amd.comhg_demandimport = False 3656658Snate@binkert.orgtry: 3664382Sbinkertn@umich.edu if not exists(scons_dir) or not isdir(scons_dir) or \ 3674382Sbinkertn@umich.edu not exists(joinpath(scons_dir, ".hg")): 3684762Snate@binkert.org raise ValueError(".hg directory not found") 3694762Snate@binkert.org 3704762Snate@binkert.org import mercurial.demandimport, mercurial.hg, mercurial.ui 3716654Snate@binkert.org import mercurial.util, mercurial.node 3726654Snate@binkert.org hg_demandimport = True 3735517Snate@binkert.org 3745517Snate@binkert.org repo = mercurial.hg.repository(mercurial.ui.ui(), scons_dir) 3755517Snate@binkert.org rev = mercurial.node.nullrev + repo.changelog.count() 3765517Snate@binkert.org changenode = repo.changelog.node(rev) 3775517Snate@binkert.org changes = repo.changelog.read(changenode) 3785517Snate@binkert.org id = mercurial.node.hex(changenode) 3795517Snate@binkert.org date = mercurial.util.datestr(changes[2]) 3805517Snate@binkert.org 3815517Snate@binkert.org hg_info = (rev, id, date) 3825517Snate@binkert.orgexcept ImportError, e: 3835517Snate@binkert.org print "Mercurial not found" 3845517Snate@binkert.orgexcept ValueError, e: 3855517Snate@binkert.org print e 3865517Snate@binkert.orgexcept Exception, e: 3875517Snate@binkert.org print "Other mercurial exception: %s" % e 3885517Snate@binkert.org 3895517Snate@binkert.orgif hg_demandimport: 3906654Snate@binkert.org mercurial.demandimport.disable() 3915517Snate@binkert.org 3925517Snate@binkert.org# Generate Python file containing a dict specifying the current 3935517Snate@binkert.org# build_env flags. 3945517Snate@binkert.orgdef makeDefinesPyFile(target, source, env): 3955517Snate@binkert.org f = file(str(target[0]), 'w') 3965517Snate@binkert.org build_env, hg_info = [ x.get_contents() for x in source ] 3975517Snate@binkert.org print >>f, "buildEnv = %s" % build_env 3985517Snate@binkert.org print >>f, "hgRev, hgId, hgDate = %s" % hg_info 3996143Snate@binkert.org f.close() 4006654Snate@binkert.org 4015517Snate@binkert.orgdefines_info = [ Value(build_env), Value(hg_info) ] 4025517Snate@binkert.org# Generate a file with all of the compile options in it 4035517Snate@binkert.orgenv.Command('python/m5/defines.py', defines_info, makeDefinesPyFile) 4045517Snate@binkert.orgPySource('m5', 'python/m5/defines.py') 4055517Snate@binkert.org 4065517Snate@binkert.org# Generate python file containing info about the M5 source code 4075517Snate@binkert.orgdef makeInfoPyFile(target, source, env): 4085517Snate@binkert.org f = file(str(target[0]), 'w') 4095517Snate@binkert.org for src in source: 4105517Snate@binkert.org data = ''.join(file(src.srcnode().abspath, 'r').xreadlines()) 4115517Snate@binkert.org print >>f, "%s = %s" % (src, repr(data)) 4125517Snate@binkert.org f.close() 4135517Snate@binkert.org 4145517Snate@binkert.org# Generate a file that wraps the basic top level files 4156654Snate@binkert.orgenv.Command('python/m5/info.py', 4166654Snate@binkert.org [ '#/AUTHORS', '#/LICENSE', '#/README', '#/RELEASE_NOTES' ], 4175517Snate@binkert.org makeInfoPyFile) 4185517Snate@binkert.orgPySource('m5', 'python/m5/info.py') 4196143Snate@binkert.org 4206143Snate@binkert.org# Generate the __init__.py file for m5.objects 4216143Snate@binkert.orgdef makeObjectsInitFile(target, source, env): 4226727Ssteve.reinhardt@amd.com f = file(str(target[0]), 'w') 4235517Snate@binkert.org print >>f, 'from params import *' 4246727Ssteve.reinhardt@amd.com print >>f, 'from m5.SimObject import *' 4255517Snate@binkert.org for module in source: 4265517Snate@binkert.org print >>f, 'from %s import *' % module.get_contents() 4275517Snate@binkert.org f.close() 4286654Snate@binkert.org 4296654Snate@binkert.org# Generate an __init__.py file for the objects package 4307673Snate@binkert.orgenv.Command('python/m5/objects/__init__.py', 4316654Snate@binkert.org [ Value(o) for o in sort_list(sim_object_modfiles) ], 4326654Snate@binkert.org makeObjectsInitFile) 4336654Snate@binkert.orgPySource('m5.objects', 'python/m5/objects/__init__.py') 4346654Snate@binkert.org 4355517Snate@binkert.org######################################################################## 4365517Snate@binkert.org# 4375517Snate@binkert.org# Create all of the SimObject param headers and enum headers 4386143Snate@binkert.org# 4395517Snate@binkert.org 4404762Snate@binkert.orgdef createSimObjectParam(target, source, env): 4415517Snate@binkert.org assert len(target) == 1 and len(source) == 1 4425517Snate@binkert.org 4436143Snate@binkert.org hh_file = file(target[0].abspath, 'w') 4446143Snate@binkert.org name = str(source[0].get_contents()) 4455517Snate@binkert.org obj = sim_objects[name] 4465517Snate@binkert.org 4475517Snate@binkert.org print >>hh_file, obj.cxx_decl() 4485517Snate@binkert.org 4495517Snate@binkert.orgdef createSwigParam(target, source, env): 4505517Snate@binkert.org assert len(target) == 1 and len(source) == 1 4515517Snate@binkert.org 4525517Snate@binkert.org i_file = file(target[0].abspath, 'w') 4535517Snate@binkert.org name = str(source[0].get_contents()) 4548596Ssteve.reinhardt@amd.com param = all_params[name] 4558596Ssteve.reinhardt@amd.com 4568596Ssteve.reinhardt@amd.com for line in param.swig_decl(): 4578596Ssteve.reinhardt@amd.com print >>i_file, line 4588596Ssteve.reinhardt@amd.com 4598596Ssteve.reinhardt@amd.comdef createEnumStrings(target, source, env): 4608596Ssteve.reinhardt@amd.com assert len(target) == 1 and len(source) == 1 4616143Snate@binkert.org 4625517Snate@binkert.org cc_file = file(target[0].abspath, 'w') 4636654Snate@binkert.org name = str(source[0].get_contents()) 4646654Snate@binkert.org obj = all_enums[name] 4656654Snate@binkert.org 4666654Snate@binkert.org print >>cc_file, obj.cxx_def() 4676654Snate@binkert.org cc_file.close() 4686654Snate@binkert.org 4695517Snate@binkert.orgdef createEnumParam(target, source, env): 4705517Snate@binkert.org assert len(target) == 1 and len(source) == 1 4715517Snate@binkert.org 4728596Ssteve.reinhardt@amd.com hh_file = file(target[0].abspath, 'w') 4738596Ssteve.reinhardt@amd.com name = str(source[0].get_contents()) 4744762Snate@binkert.org obj = all_enums[name] 4754762Snate@binkert.org 4764762Snate@binkert.org print >>hh_file, obj.cxx_decl() 4774762Snate@binkert.org 4784762Snate@binkert.org# Generate all of the SimObject param struct header files 4794762Snate@binkert.orgparams_hh_files = [] 4807675Snate@binkert.orgfor name,simobj in sim_objects.iteritems(): 4814762Snate@binkert.org extra_deps = [ File(py_modules[simobj.__module__]) ] 4824762Snate@binkert.org 4834762Snate@binkert.org hh_file = File('params/%s.hh' % name) 4844762Snate@binkert.org params_hh_files.append(hh_file) 4854382Sbinkertn@umich.edu env.Command(hh_file, Value(name), createSimObjectParam) 4864382Sbinkertn@umich.edu env.Depends(hh_file, depends + extra_deps) 4875517Snate@binkert.org 4886654Snate@binkert.org# Generate any parameter header files needed 4895517Snate@binkert.orgparams_i_files = [] 4908126Sgblack@eecs.umich.edufor name,param in all_params.iteritems(): 4916654Snate@binkert.org if isinstance(param, m5.params.VectorParamDesc): 4927673Snate@binkert.org ext = 'vptype' 4936654Snate@binkert.org else: 4946654Snate@binkert.org ext = 'ptype' 4956654Snate@binkert.org 4966654Snate@binkert.org i_file = File('params/%s_%s.i' % (name, ext)) 4976654Snate@binkert.org params_i_files.append(i_file) 4986654Snate@binkert.org env.Command(i_file, Value(name), createSwigParam) 4996654Snate@binkert.org env.Depends(i_file, depends) 5006669Snate@binkert.org 5016669Snate@binkert.org# Generate all enum header files 5026669Snate@binkert.orgfor name,enum in all_enums.iteritems(): 5036669Snate@binkert.org extra_deps = [ File(py_modules[enum.__module__]) ] 5046669Snate@binkert.org 5056669Snate@binkert.org cc_file = File('enums/%s.cc' % name) 5066654Snate@binkert.org env.Command(cc_file, Value(name), createEnumStrings) 5077673Snate@binkert.org env.Depends(cc_file, depends + extra_deps) 5085517Snate@binkert.org Source(cc_file) 5098126Sgblack@eecs.umich.edu 5105798Snate@binkert.org hh_file = File('enums/%s.hh' % name) 5117756SAli.Saidi@ARM.com env.Command(hh_file, Value(name), createEnumParam) 5127816Ssteve.reinhardt@amd.com env.Depends(hh_file, depends + extra_deps) 5135798Snate@binkert.org 5145798Snate@binkert.org# Build the big monolithic swigged params module (wraps all SimObject 5155517Snate@binkert.org# param structs and enum structs) 5165517Snate@binkert.orgdef buildParams(target, source, env): 5177673Snate@binkert.org names = [ s.get_contents() for s in source ] 5185517Snate@binkert.org objs = [ sim_objects[name] for name in names ] 5195517Snate@binkert.org out = file(target[0].abspath, 'w') 5207673Snate@binkert.org 5217673Snate@binkert.org ordered_objs = [] 5225517Snate@binkert.org obj_seen = set() 5235798Snate@binkert.org def order_obj(obj): 5245798Snate@binkert.org name = str(obj) 5258333Snate@binkert.org if name in obj_seen: 5267816Ssteve.reinhardt@amd.com return 5275798Snate@binkert.org 5285798Snate@binkert.org obj_seen.add(name) 5294762Snate@binkert.org if str(obj) != 'SimObject': 5304762Snate@binkert.org order_obj(obj.__bases__[0]) 5314762Snate@binkert.org 5324762Snate@binkert.org ordered_objs.append(obj) 5334762Snate@binkert.org 5348596Ssteve.reinhardt@amd.com for obj in objs: 5355517Snate@binkert.org order_obj(obj) 5365517Snate@binkert.org 5375517Snate@binkert.org enums = set() 5385517Snate@binkert.org predecls = [] 5395517Snate@binkert.org pd_seen = set() 5407673Snate@binkert.org 5418596Ssteve.reinhardt@amd.com def add_pds(*pds): 5427673Snate@binkert.org for pd in pds: 5435517Snate@binkert.org if pd not in pd_seen: 5448596Ssteve.reinhardt@amd.com predecls.append(pd) 5455517Snate@binkert.org pd_seen.add(pd) 5465517Snate@binkert.org 5475517Snate@binkert.org for obj in ordered_objs: 5488596Ssteve.reinhardt@amd.com params = obj._params.local.values() 5495517Snate@binkert.org for param in params: 5507673Snate@binkert.org ptype = param.ptype 5517673Snate@binkert.org if issubclass(ptype, m5.params.Enum): 5527673Snate@binkert.org if ptype not in enums: 5535517Snate@binkert.org enums.add(ptype) 5545517Snate@binkert.org pds = param.swig_predecls() 5555517Snate@binkert.org if isinstance(pds, (list, tuple)): 5565517Snate@binkert.org add_pds(*pds) 5575517Snate@binkert.org else: 5585517Snate@binkert.org add_pds(pds) 5595517Snate@binkert.org 5607673Snate@binkert.org print >>out, '%module params' 5617673Snate@binkert.org 5627673Snate@binkert.org print >>out, '%{' 5635517Snate@binkert.org for obj in ordered_objs: 5648596Ssteve.reinhardt@amd.com print >>out, '#include "params/%s.hh"' % obj 5655517Snate@binkert.org print >>out, '%}' 5665517Snate@binkert.org 5675517Snate@binkert.org for pd in predecls: 5685517Snate@binkert.org print >>out, pd 5695517Snate@binkert.org 5707673Snate@binkert.org enums = list(enums) 5717673Snate@binkert.org enums.sort() 5727673Snate@binkert.org for enum in enums: 5735517Snate@binkert.org print >>out, '%%include "enums/%s.hh"' % enum.__name__ 5748596Ssteve.reinhardt@amd.com print >>out 5757675Snate@binkert.org 5767675Snate@binkert.org for obj in ordered_objs: 5777675Snate@binkert.org if obj.swig_objdecls: 5787675Snate@binkert.org for decl in obj.swig_objdecls: 5797675Snate@binkert.org print >>out, decl 5807675Snate@binkert.org continue 5818596Ssteve.reinhardt@amd.com 5827675Snate@binkert.org class_path = obj.cxx_class.split('::') 5837675Snate@binkert.org classname = class_path[-1] 5848596Ssteve.reinhardt@amd.com namespaces = class_path[:-1] 5858596Ssteve.reinhardt@amd.com namespaces.reverse() 5868596Ssteve.reinhardt@amd.com 5878596Ssteve.reinhardt@amd.com code = '' 5888596Ssteve.reinhardt@amd.com 5898596Ssteve.reinhardt@amd.com if namespaces: 5908596Ssteve.reinhardt@amd.com code += '// avoid name conflicts\n' 5918596Ssteve.reinhardt@amd.com sep_string = '_COLONS_' 5928596Ssteve.reinhardt@amd.com flat_name = sep_string.join(class_path) 5934762Snate@binkert.org code += '%%rename(%s) %s;\n' % (flat_name, classname) 5946143Snate@binkert.org 5956143Snate@binkert.org code += '// stop swig from creating/wrapping default ctor/dtor\n' 5966143Snate@binkert.org code += '%%nodefault %s;\n' % classname 5974762Snate@binkert.org code += 'class %s ' % classname 5984762Snate@binkert.org if obj._base: 5994762Snate@binkert.org code += ': public %s' % obj._base.cxx_class 6007756SAli.Saidi@ARM.com code += ' {};\n' 6018596Ssteve.reinhardt@amd.com 6024762Snate@binkert.org for ns in namespaces: 6034762Snate@binkert.org new_code = 'namespace %s {\n' % ns 6048596Ssteve.reinhardt@amd.com new_code += code 6055463Snate@binkert.org new_code += '}\n' 6068596Ssteve.reinhardt@amd.com code = new_code 6078596Ssteve.reinhardt@amd.com 6085463Snate@binkert.org print >>out, code 6097756SAli.Saidi@ARM.com 6108596Ssteve.reinhardt@amd.com print >>out, '%%include "src/sim/sim_object_params.hh"' % obj 6114762Snate@binkert.org for obj in ordered_objs: 6127677Snate@binkert.org print >>out, '%%include "params/%s.hh"' % obj 6134762Snate@binkert.org 6144762Snate@binkert.orgparams_file = File('params/params.i') 6156143Snate@binkert.orgnames = sort_list(sim_objects.keys()) 6166143Snate@binkert.orgenv.Command(params_file, [ Value(v) for v in names ], buildParams) 6176143Snate@binkert.orgenv.Depends(params_file, params_hh_files + params_i_files + depends) 6184762Snate@binkert.orgSwigSource('m5.objects', params_file) 6194762Snate@binkert.org 6207756SAli.Saidi@ARM.com# Build all swig modules 6217816Ssteve.reinhardt@amd.comswig_modules = [] 6224762Snate@binkert.orgcc_swig_sources = [] 6234762Snate@binkert.orgfor source,package in swig_sources: 6244762Snate@binkert.org filename = str(source) 6254762Snate@binkert.org assert filename.endswith('.i') 6267756SAli.Saidi@ARM.com 6278596Ssteve.reinhardt@amd.com base = '.'.join(filename.split('.')[:-1]) 6284762Snate@binkert.org module = basename(base) 6294762Snate@binkert.org cc_file = base + '_wrap.cc' 6307677Snate@binkert.org py_file = base + '.py' 6317756SAli.Saidi@ARM.com 6328596Ssteve.reinhardt@amd.com env.Command([cc_file, py_file], source, 6337675Snate@binkert.org '$SWIG $SWIGFLAGS -outdir ${TARGETS[1].dir} ' 6347677Snate@binkert.org '-o ${TARGETS[0]} $SOURCES') 6355517Snate@binkert.org env.Depends(py_file, source) 6368596Ssteve.reinhardt@amd.com env.Depends(cc_file, source) 6377675Snate@binkert.org 6388596Ssteve.reinhardt@amd.com swig_modules.append(Value(module)) 6398596Ssteve.reinhardt@amd.com cc_swig_sources.append(File(cc_file)) 6408596Ssteve.reinhardt@amd.com PySource(package, py_file) 6418596Ssteve.reinhardt@amd.com 6428596Ssteve.reinhardt@amd.com# Generate the main swig init file 6434762Snate@binkert.orgdef makeSwigInit(target, source, env): 6447674Snate@binkert.org f = file(str(target[0]), 'w') 6457674Snate@binkert.org print >>f, 'extern "C" {' 6467674Snate@binkert.org for module in source: 6477674Snate@binkert.org print >>f, ' void init_%s();' % module.get_contents() 6487674Snate@binkert.org print >>f, '}' 6497674Snate@binkert.org print >>f, 'void initSwig() {' 6507674Snate@binkert.org for module in source: 6517674Snate@binkert.org print >>f, ' init_%s();' % module.get_contents() 6527674Snate@binkert.org print >>f, '}' 6537674Snate@binkert.org f.close() 6547674Snate@binkert.org 6557674Snate@binkert.orgenv.Command('python/swig/init.cc', swig_modules, makeSwigInit) 6567674Snate@binkert.orgSource('python/swig/init.cc') 6577674Snate@binkert.org 6587674Snate@binkert.org# Generate traceflags.py 6594762Snate@binkert.orgdef traceFlagsPy(target, source, env): 6606143Snate@binkert.org assert(len(target) == 1) 6616143Snate@binkert.org 6627756SAli.Saidi@ARM.com f = file(str(target[0]), 'w') 6637816Ssteve.reinhardt@amd.com 6648235Snate@binkert.org allFlags = [] 6658596Ssteve.reinhardt@amd.com for s in source: 6667756SAli.Saidi@ARM.com val = eval(s.get_contents()) 6677816Ssteve.reinhardt@amd.com allFlags.append(val) 6688235Snate@binkert.org 6694382Sbinkertn@umich.edu print >>f, 'baseFlags = [' 6708232Snate@binkert.org for flag, compound, desc in allFlags: 6718232Snate@binkert.org if not compound: 6728232Snate@binkert.org print >>f, " '%s'," % flag 6738232Snate@binkert.org print >>f, " ]" 6748232Snate@binkert.org print >>f 6756229Snate@binkert.org 6768232Snate@binkert.org print >>f, 'compoundFlags = [' 6778232Snate@binkert.org print >>f, " 'All'," 6788232Snate@binkert.org for flag, compound, desc in allFlags: 6796229Snate@binkert.org if compound: 6807673Snate@binkert.org print >>f, " '%s'," % flag 6815517Snate@binkert.org print >>f, " ]" 6825517Snate@binkert.org print >>f 6837673Snate@binkert.org 6845517Snate@binkert.org print >>f, "allFlags = frozenset(baseFlags + compoundFlags)" 6855517Snate@binkert.org print >>f 6865517Snate@binkert.org 6875517Snate@binkert.org print >>f, 'compoundFlagMap = {' 6888232Snate@binkert.org all = tuple([flag for flag,compound,desc in allFlags if not compound]) 6897673Snate@binkert.org print >>f, " 'All' : %s," % (all, ) 6907673Snate@binkert.org for flag, compound, desc in allFlags: 6918232Snate@binkert.org if compound: 6928232Snate@binkert.org print >>f, " '%s' : %s," % (flag, compound) 6938232Snate@binkert.org print >>f, " }" 6948232Snate@binkert.org print >>f 6957673Snate@binkert.org 6965517Snate@binkert.org print >>f, 'flagDescriptions = {' 6978232Snate@binkert.org print >>f, " 'All' : 'All flags'," 6988232Snate@binkert.org for flag, compound, desc in allFlags: 6998232Snate@binkert.org print >>f, " '%s' : '%s'," % (flag, desc) 7008232Snate@binkert.org print >>f, " }" 7017673Snate@binkert.org 7028232Snate@binkert.org f.close() 7038232Snate@binkert.org 7048232Snate@binkert.orgdef traceFlagsCC(target, source, env): 7058232Snate@binkert.org assert(len(target) == 1) 7068232Snate@binkert.org 7078232Snate@binkert.org f = file(str(target[0]), 'w') 7087673Snate@binkert.org 7095517Snate@binkert.org allFlags = [] 7108232Snate@binkert.org for s in source: 7118232Snate@binkert.org val = eval(s.get_contents()) 7125517Snate@binkert.org allFlags.append(val) 7137673Snate@binkert.org 7145517Snate@binkert.org # file header 7158232Snate@binkert.org print >>f, ''' 7168232Snate@binkert.org/* 7175517Snate@binkert.org * DO NOT EDIT THIS FILE! Automatically generated 7188232Snate@binkert.org */ 7198232Snate@binkert.org 7208232Snate@binkert.org#include "base/traceflags.hh" 7217673Snate@binkert.org 7225517Snate@binkert.orgusing namespace Trace; 7235517Snate@binkert.org 7247673Snate@binkert.orgconst char *Trace::flagStrings[] = 7255517Snate@binkert.org{''' 7265517Snate@binkert.org 7275517Snate@binkert.org # The string array is used by SimpleEnumParam to map the strings 7288232Snate@binkert.org # provided by the user to enum values. 7295517Snate@binkert.org for flag, compound, desc in allFlags: 7305517Snate@binkert.org if not compound: 7318232Snate@binkert.org print >>f, ' "%s",' % flag 7328232Snate@binkert.org 7335517Snate@binkert.org print >>f, ' "All",' 7348232Snate@binkert.org for flag, compound, desc in allFlags: 7358232Snate@binkert.org if compound: 7365517Snate@binkert.org print >>f, ' "%s",' % flag 7378232Snate@binkert.org 7388232Snate@binkert.org print >>f, '};' 7398232Snate@binkert.org print >>f 7405517Snate@binkert.org print >>f, 'const int Trace::numFlagStrings = %d;' % (len(allFlags) + 1) 7418232Snate@binkert.org print >>f 7428232Snate@binkert.org 7438232Snate@binkert.org # 7448232Snate@binkert.org # Now define the individual compound flag arrays. There is an array 7458232Snate@binkert.org # for each compound flag listing the component base flags. 7468232Snate@binkert.org # 7475517Snate@binkert.org all = tuple([flag for flag,compound,desc in allFlags if not compound]) 7488232Snate@binkert.org print >>f, 'static const Flags AllMap[] = {' 7498232Snate@binkert.org for flag, compound, desc in allFlags: 7505517Snate@binkert.org if not compound: 7518232Snate@binkert.org print >>f, " %s," % flag 7527673Snate@binkert.org print >>f, '};' 7535517Snate@binkert.org print >>f 7547673Snate@binkert.org 7555517Snate@binkert.org for flag, compound, desc in allFlags: 7568232Snate@binkert.org if not compound: 7578232Snate@binkert.org continue 7588232Snate@binkert.org print >>f, 'static const Flags %sMap[] = {' % flag 7595192Ssaidi@eecs.umich.edu for flag in compound: 7608232Snate@binkert.org print >>f, " %s," % flag 7618232Snate@binkert.org print >>f, " (Flags)-1" 7628232Snate@binkert.org print >>f, '};' 7638232Snate@binkert.org print >>f 7648232Snate@binkert.org 7655192Ssaidi@eecs.umich.edu # 7667674Snate@binkert.org # Finally the compoundFlags[] array maps the compound flags 7675522Snate@binkert.org # to their individual arrays/ 7685522Snate@binkert.org # 7697674Snate@binkert.org print >>f, 'const Flags *Trace::compoundFlags[] =' 7707674Snate@binkert.org print >>f, '{' 7717674Snate@binkert.org print >>f, ' AllMap,' 7727674Snate@binkert.org for flag, compound, desc in allFlags: 7737674Snate@binkert.org if compound: 7747674Snate@binkert.org print >>f, ' %sMap,' % flag 7757674Snate@binkert.org # file trailer 7767674Snate@binkert.org print >>f, '};' 7775522Snate@binkert.org 7785522Snate@binkert.org f.close() 7795522Snate@binkert.org 7805517Snate@binkert.orgdef traceFlagsHH(target, source, env): 7815522Snate@binkert.org assert(len(target) == 1) 7825517Snate@binkert.org 7836143Snate@binkert.org f = file(str(target[0]), 'w') 7846727Ssteve.reinhardt@amd.com 7855522Snate@binkert.org allFlags = [] 7865522Snate@binkert.org for s in source: 7875522Snate@binkert.org val = eval(s.get_contents()) 7887674Snate@binkert.org allFlags.append(val) 7895517Snate@binkert.org 7907673Snate@binkert.org # file header boilerplate 7917673Snate@binkert.org print >>f, ''' 7927674Snate@binkert.org/* 7937673Snate@binkert.org * DO NOT EDIT THIS FILE! 7947674Snate@binkert.org * 7957674Snate@binkert.org * Automatically generated from traceflags.py 7968946Sandreas.hansson@arm.com */ 7977674Snate@binkert.org 7987674Snate@binkert.org#ifndef __BASE_TRACE_FLAGS_HH__ 7997674Snate@binkert.org#define __BASE_TRACE_FLAGS_HH__ 8005522Snate@binkert.org 8015522Snate@binkert.orgnamespace Trace { 8027674Snate@binkert.org 8037674Snate@binkert.orgenum Flags {''' 8047674Snate@binkert.org 8057674Snate@binkert.org # Generate the enum. Base flags come first, then compound flags. 8067673Snate@binkert.org idx = 0 8077674Snate@binkert.org for flag, compound, desc in allFlags: 8087674Snate@binkert.org if not compound: 8097674Snate@binkert.org print >>f, ' %s = %d,' % (flag, idx) 8107674Snate@binkert.org idx += 1 8117674Snate@binkert.org 8127674Snate@binkert.org numBaseFlags = idx 8137674Snate@binkert.org print >>f, ' NumFlags = %d,' % idx 8147674Snate@binkert.org 8157811Ssteve.reinhardt@amd.com # put a comment in here to separate base from compound flags 8167674Snate@binkert.org print >>f, ''' 8177673Snate@binkert.org// The remaining enum values are *not* valid indices for Trace::flags. 8185522Snate@binkert.org// They are "compound" flags, which correspond to sets of base 8196143Snate@binkert.org// flags, and are used by changeFlag.''' 8207756SAli.Saidi@ARM.com 8217816Ssteve.reinhardt@amd.com print >>f, ' All = %d,' % idx 8227674Snate@binkert.org idx += 1 8234382Sbinkertn@umich.edu for flag, compound, desc in allFlags: 8244382Sbinkertn@umich.edu if compound: 8254382Sbinkertn@umich.edu print >>f, ' %s = %d,' % (flag, idx) 8264382Sbinkertn@umich.edu idx += 1 8274382Sbinkertn@umich.edu 8284382Sbinkertn@umich.edu numCompoundFlags = idx - numBaseFlags 8294382Sbinkertn@umich.edu print >>f, ' NumCompoundFlags = %d' % numCompoundFlags 8304382Sbinkertn@umich.edu 8314382Sbinkertn@umich.edu # trailer boilerplate 8324382Sbinkertn@umich.edu print >>f, '''\ 8336143Snate@binkert.org}; // enum Flags 834955SN/A 8352655Sstever@eecs.umich.edu// Array of strings for SimpleEnumParam 8362655Sstever@eecs.umich.eduextern const char *flagStrings[]; 8372655Sstever@eecs.umich.eduextern const int numFlagStrings; 8382655Sstever@eecs.umich.edu 8392655Sstever@eecs.umich.edu// Array of arraay pointers: for each compound flag, gives the list of 8405601Snate@binkert.org// base flags to set. Inidividual flag arrays are terminated by -1. 8415601Snate@binkert.orgextern const Flags *compoundFlags[]; 8428334Snate@binkert.org 8438334Snate@binkert.org/* namespace Trace */ } 8448334Snate@binkert.org 8455522Snate@binkert.org#endif // __BASE_TRACE_FLAGS_HH__ 8465863Snate@binkert.org''' 8475601Snate@binkert.org 8485601Snate@binkert.org f.close() 8495601Snate@binkert.org 8505863Snate@binkert.orgflags = [ Value(f) for f in trace_flags ] 8518945Ssteve.reinhardt@amd.comenv.Command('base/traceflags.py', flags, traceFlagsPy) 8525559Snate@binkert.orgPySource('m5', 'base/traceflags.py') 8539175Sandreas.hansson@arm.com 8549175Sandreas.hansson@arm.comenv.Command('base/traceflags.hh', flags, traceFlagsHH) 8559175Sandreas.hansson@arm.comenv.Command('base/traceflags.cc', flags, traceFlagsCC) 8568946Sandreas.hansson@arm.comSource('base/traceflags.cc') 8578614Sgblack@eecs.umich.edu 8588737Skoansin.tan@gmail.com# embed python files. All .py files that have been indicated by a 8599175Sandreas.hansson@arm.com# PySource() call in a SConscript need to be embedded into the M5 8608945Ssteve.reinhardt@amd.com# library. To do that, we compile the file to byte code, marshal the 8618945Ssteve.reinhardt@amd.com# byte code, compress it, and then generate an assembly file that 8628945Ssteve.reinhardt@amd.com# inserts the result into the data section with symbols indicating the 8638945Ssteve.reinhardt@amd.com# beginning, and end (and with the size at the end) 8646143Snate@binkert.orgpy_sources_tnodes = {} 8656143Snate@binkert.orgfor pysource in py_sources: 8666143Snate@binkert.org py_sources_tnodes[pysource.tnode] = pysource 8676143Snate@binkert.org 8686143Snate@binkert.orgdef objectifyPyFile(target, source, env): 8696143Snate@binkert.org '''Action function to compile a .py into a code object, marshal 8706143Snate@binkert.org it, compress it, and stick it into an asm file so the code appears 8718945Ssteve.reinhardt@amd.com as just bytes with a label in the data section''' 8728945Ssteve.reinhardt@amd.com 8736143Snate@binkert.org src = file(str(source[0]), 'r').read() 8746143Snate@binkert.org dst = file(str(target[0]), 'w') 8756143Snate@binkert.org 8766143Snate@binkert.org pysource = py_sources_tnodes[source[0]] 8776143Snate@binkert.org compiled = compile(src, pysource.debugname, 'exec') 8786143Snate@binkert.org marshalled = marshal.dumps(compiled) 8796143Snate@binkert.org compressed = zlib.compress(marshalled) 8806143Snate@binkert.org data = compressed 8816143Snate@binkert.org 8826143Snate@binkert.org # Some C/C++ compilers prepend an underscore to global symbol 8836143Snate@binkert.org # names, so if they're going to do that, we need to prepend that 8846143Snate@binkert.org # leading underscore to globals in the assembly file. 8856143Snate@binkert.org if env['LEADING_UNDERSCORE']: 8868594Snate@binkert.org sym = '_' + pysource.symname 8878594Snate@binkert.org else: 8888594Snate@binkert.org sym = pysource.symname 8898594Snate@binkert.org 8906143Snate@binkert.org step = 16 8916143Snate@binkert.org print >>dst, ".data" 8926143Snate@binkert.org print >>dst, ".globl %s_beg" % sym 8936143Snate@binkert.org print >>dst, ".globl %s_end" % sym 8946143Snate@binkert.org print >>dst, "%s_beg:" % sym 8956240Snate@binkert.org for i in xrange(0, len(data), step): 8965554Snate@binkert.org x = array.array('B', data[i:i+step]) 8975522Snate@binkert.org print >>dst, ".byte", ','.join([str(d) for d in x]) 8985522Snate@binkert.org print >>dst, "%s_end:" % sym 8995797Snate@binkert.org print >>dst, ".long %d" % len(marshalled) 9005797Snate@binkert.org 9015522Snate@binkert.orgfor source in py_sources: 9025601Snate@binkert.org env.Command(source.assembly, source.tnode, objectifyPyFile) 9038233Snate@binkert.org Source(source.assembly) 9048233Snate@binkert.org 9058235Snate@binkert.org# Generate init_python.cc which creates a bunch of EmbeddedPyModule 9068235Snate@binkert.org# structs that describe the embedded python code. One such struct 9078235Snate@binkert.org# contains information about the importer that python uses to get at 9088235Snate@binkert.org# the embedded files, and then there's a list of all of the rest that 9099003SAli.Saidi@ARM.com# the importer uses to load the rest on demand. 9109003SAli.Saidi@ARM.compy_sources_symbols = {} 9118235Snate@binkert.orgfor pysource in py_sources: 9128942Sgblack@eecs.umich.edu py_sources_symbols[pysource.symname] = pysource 9138235Snate@binkert.orgdef pythonInit(target, source, env): 9146143Snate@binkert.org dst = file(str(target[0]), 'w') 9152655Sstever@eecs.umich.edu 9166143Snate@binkert.org def dump_mod(sym, endchar=','): 9176143Snate@binkert.org pysource = py_sources_symbols[sym] 9188233Snate@binkert.org print >>dst, ' { "%s",' % pysource.arcname 9196143Snate@binkert.org print >>dst, ' "%s",' % pysource.modpath 9206143Snate@binkert.org print >>dst, ' %s_beg, %s_end,' % (sym, sym) 9214007Ssaidi@eecs.umich.edu print >>dst, ' %s_end - %s_beg,' % (sym, sym) 9224596Sbinkertn@umich.edu print >>dst, ' *(int *)%s_end }%s' % (sym, endchar) 9234007Ssaidi@eecs.umich.edu 9244596Sbinkertn@umich.edu print >>dst, '#include "sim/init.hh"' 9257756SAli.Saidi@ARM.com 9267816Ssteve.reinhardt@amd.com for sym in source: 9278334Snate@binkert.org sym = sym.get_contents() 9288334Snate@binkert.org print >>dst, "extern const char %s_beg[], %s_end[];" % (sym, sym) 9298334Snate@binkert.org 9308334Snate@binkert.org print >>dst, "const EmbeddedPyModule embeddedPyImporter = " 9315601Snate@binkert.org dump_mod("PyEMB_importer", endchar=';'); 9325601Snate@binkert.org print >>dst 9332655Sstever@eecs.umich.edu 9349225Sandreas.hansson@arm.com print >>dst, "const EmbeddedPyModule embeddedPyModules[] = {" 9359225Sandreas.hansson@arm.com for i,sym in enumerate(source): 9369226Sandreas.hansson@arm.com sym = sym.get_contents() 9379226Sandreas.hansson@arm.com if sym == "PyEMB_importer": 9389225Sandreas.hansson@arm.com # Skip the importer since we've already exported it 9399226Sandreas.hansson@arm.com continue 9409226Sandreas.hansson@arm.com dump_mod(sym) 9419226Sandreas.hansson@arm.com print >>dst, " { 0, 0, 0, 0, 0, 0 }" 9429226Sandreas.hansson@arm.com print >>dst, "};" 9439226Sandreas.hansson@arm.com 9449226Sandreas.hansson@arm.comsymbols = [Value(s.symname) for s in py_sources] 9459225Sandreas.hansson@arm.comenv.Command('sim/init_python.cc', symbols, pythonInit) 9468946Sandreas.hansson@arm.comSource('sim/init_python.cc') 9473918Ssaidi@eecs.umich.edu 9489225Sandreas.hansson@arm.com######################################################################## 9493918Ssaidi@eecs.umich.edu# 9509225Sandreas.hansson@arm.com# Define binaries. Each different build type (debug, opt, etc.) gets 9519225Sandreas.hansson@arm.com# a slightly different build environment. 9529226Sandreas.hansson@arm.com# 9539226Sandreas.hansson@arm.com 9549225Sandreas.hansson@arm.com# List of constructed environments to pass back to SConstruct 9553918Ssaidi@eecs.umich.eduenvList = [] 9569225Sandreas.hansson@arm.com 9579225Sandreas.hansson@arm.com# This function adds the specified sources to the given build 9589226Sandreas.hansson@arm.com# environment, and returns a list of all the corresponding SCons 9599226Sandreas.hansson@arm.com# Object nodes (including an extra one for date.cc). We explicitly 9603940Ssaidi@eecs.umich.edu# add the Object nodes so we can set up special dependencies for 9619225Sandreas.hansson@arm.com# date.cc. 9629225Sandreas.hansson@arm.comdef make_objs(sources, env, static): 9639226Sandreas.hansson@arm.com if static: 9649226Sandreas.hansson@arm.com XObject = env.StaticObject 9658946Sandreas.hansson@arm.com else: 9669225Sandreas.hansson@arm.com XObject = env.SharedObject 9679226Sandreas.hansson@arm.com 9689226Sandreas.hansson@arm.com objs = [ XObject(s) for s in sources ] 9699226Sandreas.hansson@arm.com 9703515Ssaidi@eecs.umich.edu # make date.cc depend on all other objects so it always gets 9713918Ssaidi@eecs.umich.edu # recompiled whenever anything else does 9724762Snate@binkert.org date_obj = XObject('base/date.cc') 9733515Ssaidi@eecs.umich.edu 9748881Smarc.orr@gmail.com env.Depends(date_obj, objs) 9758881Smarc.orr@gmail.com objs.append(date_obj) 9768881Smarc.orr@gmail.com return objs 9778881Smarc.orr@gmail.com 9788881Smarc.orr@gmail.com# Function to create a new build environment as clone of current 9799226Sandreas.hansson@arm.com# environment 'env' with modified object suffix and optional stripped 9809226Sandreas.hansson@arm.com# binary. Additional keyword arguments are appended to corresponding 9819226Sandreas.hansson@arm.com# build environment vars. 9828881Smarc.orr@gmail.comdef makeEnv(label, objsfx, strip = False, **kwargs): 9838881Smarc.orr@gmail.com # SCons doesn't know to append a library suffix when there is a '.' in the 9848881Smarc.orr@gmail.com # name. Use '_' instead. 9858881Smarc.orr@gmail.com libname = 'm5_' + label 9868881Smarc.orr@gmail.com exename = 'm5.' + label 9878881Smarc.orr@gmail.com 9888881Smarc.orr@gmail.com new_env = env.Copy(OBJSUFFIX=objsfx, SHOBJSUFFIX=objsfx + 's') 9898881Smarc.orr@gmail.com new_env.Label = label 9908881Smarc.orr@gmail.com new_env.Append(**kwargs) 9918881Smarc.orr@gmail.com 9928881Smarc.orr@gmail.com swig_env = new_env.Copy() 9938881Smarc.orr@gmail.com if env['GCC']: 9948881Smarc.orr@gmail.com swig_env.Append(CCFLAGS='-Wno-uninitialized') 9958881Smarc.orr@gmail.com swig_env.Append(CCFLAGS='-Wno-sign-compare') 9968881Smarc.orr@gmail.com swig_env.Append(CCFLAGS='-Wno-parentheses') 9978881Smarc.orr@gmail.com 9988881Smarc.orr@gmail.com static_objs = make_objs(cc_lib_sources, new_env, static=True) 9998881Smarc.orr@gmail.com shared_objs = make_objs(cc_lib_sources, new_env, static=False) 10008881Smarc.orr@gmail.com static_objs += [ swig_env.StaticObject(s) for s in cc_swig_sources ] 10018881Smarc.orr@gmail.com shared_objs += [ swig_env.SharedObject(s) for s in cc_swig_sources ] 10029225Sandreas.hansson@arm.com 10039225Sandreas.hansson@arm.com # First make a library of everything but main() so other programs can 1004955SN/A # link against m5. 1005955SN/A static_lib = new_env.StaticLibrary(libname, static_objs) 10068881Smarc.orr@gmail.com shared_lib = new_env.SharedLibrary(libname, shared_objs) 10078881Smarc.orr@gmail.com 10088881Smarc.orr@gmail.com for target, sources in unit_tests: 10099225Sandreas.hansson@arm.com objs = [ new_env.StaticObject(s) for s in sources ] 10109225Sandreas.hansson@arm.com new_env.Program("unittest/%s.%s" % (target, label), objs + static_lib) 1011955SN/A 1012955SN/A # Now link a stub with main() and the static library. 10138881Smarc.orr@gmail.com objects = [new_env.Object(s) for s in cc_bin_sources] + static_lib 10148881Smarc.orr@gmail.com if strip: 10158881Smarc.orr@gmail.com unstripped_exe = exename + '.unstripped' 10169225Sandreas.hansson@arm.com new_env.Program(unstripped_exe, objects) 10179225Sandreas.hansson@arm.com if sys.platform == 'sunos5': 1018955SN/A cmd = 'cp $SOURCE $TARGET; strip $TARGET' 10199226Sandreas.hansson@arm.com else: 10208881Smarc.orr@gmail.com cmd = 'strip $SOURCE -o $TARGET' 10218881Smarc.orr@gmail.com targets = new_env.Command(exename, unstripped_exe, cmd) 10228881Smarc.orr@gmail.com else: 10238881Smarc.orr@gmail.com targets = new_env.Program(exename, objects) 10249225Sandreas.hansson@arm.com 10251869SN/A new_env.M5Binary = targets[0] 10269226Sandreas.hansson@arm.com envList.append(new_env) 10279226Sandreas.hansson@arm.com 10289226Sandreas.hansson@arm.com# Debug binary 10299226Sandreas.hansson@arm.comccflags = {} 10309226Sandreas.hansson@arm.comif env['GCC']: 10319226Sandreas.hansson@arm.com if sys.platform == 'sunos5': 10329226Sandreas.hansson@arm.com ccflags['debug'] = '-gstabs+' 10331869SN/A else: 1034 ccflags['debug'] = '-ggdb3' 1035 ccflags['opt'] = '-g -O3' 1036 ccflags['fast'] = '-O3' 1037 ccflags['prof'] = '-O3 -g -pg' 1038elif env['SUNCC']: 1039 ccflags['debug'] = '-g0' 1040 ccflags['opt'] = '-g -O' 1041 ccflags['fast'] = '-fast' 1042 ccflags['prof'] = '-fast -g -pg' 1043elif env['ICC']: 1044 ccflags['debug'] = '-g -O0' 1045 ccflags['opt'] = '-g -O' 1046 ccflags['fast'] = '-fast' 1047 ccflags['prof'] = '-fast -g -pg' 1048else: 1049 print 'Unknown compiler, please fix compiler options' 1050 Exit(1) 1051 1052makeEnv('debug', '.do', 1053 CCFLAGS = Split(ccflags['debug']), 1054 CPPDEFINES = ['DEBUG', 'TRACING_ON=1']) 1055 1056# Optimized binary 1057makeEnv('opt', '.o', 1058 CCFLAGS = Split(ccflags['opt']), 1059 CPPDEFINES = ['TRACING_ON=1']) 1060 1061# "Fast" binary 1062makeEnv('fast', '.fo', strip = True, 1063 CCFLAGS = Split(ccflags['fast']), 1064 CPPDEFINES = ['NDEBUG', 'TRACING_ON=0']) 1065 1066# Profiled binary 1067makeEnv('prof', '.po', 1068 CCFLAGS = Split(ccflags['prof']), 1069 CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'], 1070 LINKFLAGS = '-pg') 1071 1072Return('envList') 1073