SConscript revision 5793
1955SN/A# -*- mode:python -*- 2955SN/A 313576Sciro.santilli@arm.com# Copyright (c) 2004-2005 The Regents of The University of Michigan 413576Sciro.santilli@arm.com# All rights reserved. 513576Sciro.santilli@arm.com# 613576Sciro.santilli@arm.com# Redistribution and use in source and binary forms, with or without 713576Sciro.santilli@arm.com# modification, are permitted provided that the following conditions are 813576Sciro.santilli@arm.com# met: redistributions of source code must retain the above copyright 913576Sciro.santilli@arm.com# notice, this list of conditions and the following disclaimer; 1013576Sciro.santilli@arm.com# redistributions in binary form must reproduce the above copyright 1113576Sciro.santilli@arm.com# notice, this list of conditions and the following disclaimer in the 1213576Sciro.santilli@arm.com# documentation and/or other materials provided with the distribution; 1313576Sciro.santilli@arm.com# neither the name of the copyright holders nor the names of its 141762SN/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. 28955SN/A# 29955SN/A# Authors: Nathan Binkert 30955SN/A 31955SN/Aimport array 32955SN/Aimport imp 33955SN/Aimport marshal 34955SN/Aimport os 35955SN/Aimport re 36955SN/Aimport sys 37955SN/Aimport zlib 38955SN/A 392665Ssaidi@eecs.umich.edufrom os.path import basename, dirname, exists, isdir, isfile, join as joinpath 404762Snate@binkert.org 41955SN/Aimport SCons 4212563Sgabeblack@google.com 4312563Sgabeblack@google.com# This file defines how to build a particular configuration of M5 445522Snate@binkert.org# based on variable settings in the 'env' build environment. 456143Snate@binkert.org 4612371Sgabeblack@google.comImport('*') 474762Snate@binkert.org 485522Snate@binkert.org# Children need to see the environment 49955SN/AExport('env') 505522Snate@binkert.org 5111974Sgabeblack@google.combuild_env = dict([(opt, env[opt]) for opt in env.ExportOptions]) 52955SN/A 535522Snate@binkert.orgdef sort_list(_list): 544202Sbinkertn@umich.edu """return a sorted copy of '_list'""" 555742Snate@binkert.org if isinstance(_list, list): 56955SN/A _list = _list[:] 574381Sbinkertn@umich.edu else: 584381Sbinkertn@umich.edu _list = list(_list) 5912246Sgabeblack@google.com _list.sort() 6012246Sgabeblack@google.com return _list 618334Snate@binkert.org 62955SN/Aclass PySourceFile(object): 63955SN/A invalid_sym_char = re.compile('[^A-z0-9_]') 644202Sbinkertn@umich.edu def __init__(self, package, tnode): 65955SN/A snode = tnode.srcnode() 664382Sbinkertn@umich.edu filename = str(tnode) 674382Sbinkertn@umich.edu pyname = basename(filename) 684382Sbinkertn@umich.edu assert pyname.endswith('.py') 696654Snate@binkert.org name = pyname[:-3] 705517Snate@binkert.org if package: 718614Sgblack@eecs.umich.edu path = package.split('.') 727674Snate@binkert.org else: 736143Snate@binkert.org path = [] 746143Snate@binkert.org 756143Snate@binkert.org modpath = path[:] 7612302Sgabeblack@google.com if name != '__init__': 7712302Sgabeblack@google.com modpath += [name] 7812302Sgabeblack@google.com modpath = '.'.join(modpath) 7912371Sgabeblack@google.com 8012371Sgabeblack@google.com arcpath = path + [ pyname ] 8112371Sgabeblack@google.com arcname = joinpath(*arcpath) 8212371Sgabeblack@google.com 8312371Sgabeblack@google.com debugname = snode.abspath 8412371Sgabeblack@google.com if not exists(debugname): 8512371Sgabeblack@google.com debugname = tnode.abspath 8612371Sgabeblack@google.com 8712371Sgabeblack@google.com self.tnode = tnode 8812371Sgabeblack@google.com self.snode = snode 8912371Sgabeblack@google.com self.pyname = pyname 9012371Sgabeblack@google.com self.package = package 9112371Sgabeblack@google.com self.modpath = modpath 9212371Sgabeblack@google.com self.arcname = arcname 9312371Sgabeblack@google.com self.debugname = debugname 9412371Sgabeblack@google.com self.compiled = File(filename + 'c') 9512371Sgabeblack@google.com self.assembly = File(filename + '.s') 9612371Sgabeblack@google.com self.symname = "PyEMB_" + self.invalid_sym_char.sub('_', modpath) 9712371Sgabeblack@google.com 9812371Sgabeblack@google.com 9912371Sgabeblack@google.com######################################################################## 10012371Sgabeblack@google.com# Code for adding source files of various types 10112371Sgabeblack@google.com# 10212371Sgabeblack@google.comcc_lib_sources = [] 10312371Sgabeblack@google.comdef Source(source): 10412371Sgabeblack@google.com '''Add a source file to the libm5 build''' 10512371Sgabeblack@google.com if not isinstance(source, SCons.Node.FS.File): 10612371Sgabeblack@google.com source = File(source) 10712371Sgabeblack@google.com 10812371Sgabeblack@google.com cc_lib_sources.append(source) 10912371Sgabeblack@google.com 11012371Sgabeblack@google.comcc_bin_sources = [] 11112371Sgabeblack@google.comdef BinSource(source): 11212371Sgabeblack@google.com '''Add a source file to the m5 binary build''' 11312371Sgabeblack@google.com if not isinstance(source, SCons.Node.FS.File): 11412371Sgabeblack@google.com source = File(source) 11512371Sgabeblack@google.com 11612371Sgabeblack@google.com cc_bin_sources.append(source) 11712371Sgabeblack@google.com 11812371Sgabeblack@google.compy_sources = [] 11912371Sgabeblack@google.comdef PySource(package, source): 12012371Sgabeblack@google.com '''Add a python source file to the named package''' 12112371Sgabeblack@google.com if not isinstance(source, SCons.Node.FS.File): 12212371Sgabeblack@google.com source = File(source) 12312371Sgabeblack@google.com 12412371Sgabeblack@google.com source = PySourceFile(package, source) 12512371Sgabeblack@google.com py_sources.append(source) 12612302Sgabeblack@google.com 12712371Sgabeblack@google.comsim_objects_fixed = False 12812302Sgabeblack@google.comsim_object_modfiles = set() 12912371Sgabeblack@google.comdef SimObject(source): 13012302Sgabeblack@google.com '''Add a SimObject python file as a python source object and add 13112302Sgabeblack@google.com it to a list of sim object modules''' 13212371Sgabeblack@google.com 13312371Sgabeblack@google.com if sim_objects_fixed: 13412371Sgabeblack@google.com raise AttributeError, "Too late to call SimObject now." 13512371Sgabeblack@google.com 13612302Sgabeblack@google.com if not isinstance(source, SCons.Node.FS.File): 13712371Sgabeblack@google.com source = File(source) 13812371Sgabeblack@google.com 13912371Sgabeblack@google.com PySource('m5.objects', source) 14012371Sgabeblack@google.com modfile = basename(str(source)) 14111983Sgabeblack@google.com assert modfile.endswith('.py') 1426143Snate@binkert.org modname = modfile[:-3] 1438233Snate@binkert.org sim_object_modfiles.add(modname) 14412302Sgabeblack@google.com 1456143Snate@binkert.orgswig_sources = [] 1466143Snate@binkert.orgdef SwigSource(package, source): 14712302Sgabeblack@google.com '''Add a swig file to build''' 1484762Snate@binkert.org if not isinstance(source, SCons.Node.FS.File): 1496143Snate@binkert.org source = File(source) 1508233Snate@binkert.org val = source,package 1518233Snate@binkert.org swig_sources.append(val) 15212302Sgabeblack@google.com 15312302Sgabeblack@google.comunit_tests = [] 1546143Snate@binkert.orgdef UnitTest(target, sources): 15512362Sgabeblack@google.com if not isinstance(sources, (list, tuple)): 15612362Sgabeblack@google.com sources = [ sources ] 15712362Sgabeblack@google.com 15812362Sgabeblack@google.com srcs = [] 15912302Sgabeblack@google.com for source in sources: 16012302Sgabeblack@google.com if not isinstance(source, SCons.Node.FS.File): 16112302Sgabeblack@google.com source = File(source) 16212302Sgabeblack@google.com srcs.append(source) 16312302Sgabeblack@google.com 16412363Sgabeblack@google.com unit_tests.append((target, srcs)) 16512363Sgabeblack@google.com 16612363Sgabeblack@google.com# Children should have access 16712363Sgabeblack@google.comExport('Source') 16812302Sgabeblack@google.comExport('BinSource') 16912363Sgabeblack@google.comExport('PySource') 17012363Sgabeblack@google.comExport('SimObject') 17112363Sgabeblack@google.comExport('SwigSource') 17212363Sgabeblack@google.comExport('UnitTest') 17312363Sgabeblack@google.com 1748233Snate@binkert.org######################################################################## 1756143Snate@binkert.org# 1766143Snate@binkert.org# Trace Flags 1776143Snate@binkert.org# 1786143Snate@binkert.orgall_flags = {} 1796143Snate@binkert.orgtrace_flags = [] 1806143Snate@binkert.orgdef TraceFlag(name, desc=''): 1816143Snate@binkert.org if name in all_flags: 1826143Snate@binkert.org raise AttributeError, "Flag %s already specified" % name 1836143Snate@binkert.org flag = (name, (), desc) 1847065Snate@binkert.org trace_flags.append(flag) 1856143Snate@binkert.org all_flags[name] = () 18612362Sgabeblack@google.com 18712362Sgabeblack@google.comdef CompoundFlag(name, flags, desc=''): 18812362Sgabeblack@google.com if name in all_flags: 18912362Sgabeblack@google.com raise AttributeError, "Flag %s already specified" % name 19012362Sgabeblack@google.com 19112362Sgabeblack@google.com compound = tuple(flags) 19212362Sgabeblack@google.com for flag in compound: 19312362Sgabeblack@google.com if flag not in all_flags: 19412362Sgabeblack@google.com raise AttributeError, "Trace flag %s not found" % flag 19512362Sgabeblack@google.com if all_flags[flag]: 19612362Sgabeblack@google.com raise AttributeError, \ 19712362Sgabeblack@google.com "Compound flag can't point to another compound flag" 1988233Snate@binkert.org 1998233Snate@binkert.org flag = (name, compound, desc) 2008233Snate@binkert.org trace_flags.append(flag) 2018233Snate@binkert.org all_flags[name] = compound 2028233Snate@binkert.org 2038233Snate@binkert.orgExport('TraceFlag') 2048233Snate@binkert.orgExport('CompoundFlag') 2058233Snate@binkert.org 2068233Snate@binkert.org######################################################################## 2078233Snate@binkert.org# 2088233Snate@binkert.org# Set some compiler variables 2098233Snate@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 2148233Snate@binkert.org# files. 2158233Snate@binkert.orgenv.Append(CPPPATH=Dir('.')) 2168233Snate@binkert.org 2178233Snate@binkert.orgfor extra_dir in extras_dir_list: 2188233Snate@binkert.org env.Append(CPPPATH=Dir(extra_dir)) 2196143Snate@binkert.org 2206143Snate@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())]) 2226143Snate@binkert.org 2236143Snate@binkert.org# Workaround for bug in SCons version > 0.97d20071212 2246143Snate@binkert.org# Scons bug id: 2006 M5 Bug id: 308 2259982Satgutier@umich.edufor root, dirs, files in os.walk(base_dir, topdown=True): 22613576Sciro.santilli@arm.com Dir(root[len(base_dir) + 1:]) 22713576Sciro.santilli@arm.com 22813576Sciro.santilli@arm.com######################################################################## 22913576Sciro.santilli@arm.com# 23013576Sciro.santilli@arm.com# Walk the tree and execute all SConscripts in subdirectories 23113576Sciro.santilli@arm.com# 23213576Sciro.santilli@arm.com 23313576Sciro.santilli@arm.comhere = Dir('.').srcnode().abspath 23413576Sciro.santilli@arm.comfor root, dirs, files in os.walk(base_dir, topdown=True): 23513576Sciro.santilli@arm.com if root == here: 23613576Sciro.santilli@arm.com # we don't want to recurse back into this SConscript 23713576Sciro.santilli@arm.com continue 23813576Sciro.santilli@arm.com 23913576Sciro.santilli@arm.com if 'SConscript' in files: 24013576Sciro.santilli@arm.com build_dir = joinpath(env['BUILDDIR'], root[len(base_dir) + 1:]) 24113576Sciro.santilli@arm.com SConscript(joinpath(root, 'SConscript'), build_dir=build_dir) 24213576Sciro.santilli@arm.com 24313576Sciro.santilli@arm.comfor extra_dir in extras_dir_list: 24413576Sciro.santilli@arm.com prefix_len = len(dirname(extra_dir)) + 1 24513576Sciro.santilli@arm.com for root, dirs, files in os.walk(extra_dir, topdown=True): 24613576Sciro.santilli@arm.com if 'SConscript' in files: 24713576Sciro.santilli@arm.com build_dir = joinpath(env['BUILDDIR'], root[prefix_len:]) 24813576Sciro.santilli@arm.com SConscript(joinpath(root, 'SConscript'), build_dir=build_dir) 24913576Sciro.santilli@arm.com 25013576Sciro.santilli@arm.comfor opt in env.ExportOptions: 25113576Sciro.santilli@arm.com env.ConfigFile(opt) 25213576Sciro.santilli@arm.com 25313576Sciro.santilli@arm.com######################################################################## 25413576Sciro.santilli@arm.com# 25513576Sciro.santilli@arm.com# Prevent any SimObjects from being added after this point, they 25613576Sciro.santilli@arm.com# should all have been added in the SConscripts above 25713576Sciro.santilli@arm.com# 25813576Sciro.santilli@arm.comclass DictImporter(object): 25913576Sciro.santilli@arm.com '''This importer takes a dictionary of arbitrary module names that 26013576Sciro.santilli@arm.com map to arbitrary filenames.''' 26113576Sciro.santilli@arm.com def __init__(self, modules): 26213576Sciro.santilli@arm.com self.modules = modules 26313576Sciro.santilli@arm.com self.installed = set() 26413576Sciro.santilli@arm.com 26513576Sciro.santilli@arm.com def __del__(self): 26613576Sciro.santilli@arm.com self.unload() 26713576Sciro.santilli@arm.com 26813576Sciro.santilli@arm.com def unload(self): 26913576Sciro.santilli@arm.com import sys 27013576Sciro.santilli@arm.com for module in self.installed: 27113576Sciro.santilli@arm.com del sys.modules[module] 27213576Sciro.santilli@arm.com self.installed = set() 27313576Sciro.santilli@arm.com 27413576Sciro.santilli@arm.com def find_module(self, fullname, path): 27513576Sciro.santilli@arm.com if fullname == '__scons': 27613576Sciro.santilli@arm.com return self 27713576Sciro.santilli@arm.com 27813576Sciro.santilli@arm.com if fullname == 'm5.objects': 27913576Sciro.santilli@arm.com return self 28013576Sciro.santilli@arm.com 28113576Sciro.santilli@arm.com if fullname.startswith('m5.internal'): 28213576Sciro.santilli@arm.com return None 28313576Sciro.santilli@arm.com 28413576Sciro.santilli@arm.com if fullname in self.modules and exists(self.modules[fullname]): 28513576Sciro.santilli@arm.com return self 28613576Sciro.santilli@arm.com 28713576Sciro.santilli@arm.com return None 28813576Sciro.santilli@arm.com 28913576Sciro.santilli@arm.com def load_module(self, fullname): 29013576Sciro.santilli@arm.com mod = imp.new_module(fullname) 29113576Sciro.santilli@arm.com sys.modules[fullname] = mod 29213576Sciro.santilli@arm.com self.installed.add(fullname) 29313576Sciro.santilli@arm.com 29413576Sciro.santilli@arm.com mod.__loader__ = self 29513576Sciro.santilli@arm.com if fullname == 'm5.objects': 2966143Snate@binkert.org mod.__path__ = fullname.split('.') 29712302Sgabeblack@google.com return mod 29812302Sgabeblack@google.com 29912302Sgabeblack@google.com if fullname == '__scons': 30012302Sgabeblack@google.com mod.__dict__['m5_build_env'] = build_env 30112302Sgabeblack@google.com return mod 30212302Sgabeblack@google.com 30312302Sgabeblack@google.com srcfile = self.modules[fullname] 30412302Sgabeblack@google.com if basename(srcfile) == '__init__.py': 30511983Sgabeblack@google.com mod.__path__ = fullname.split('.') 30611983Sgabeblack@google.com mod.__file__ = srcfile 30711983Sgabeblack@google.com 30812302Sgabeblack@google.com exec file(srcfile, 'r') in mod.__dict__ 30912302Sgabeblack@google.com 31012302Sgabeblack@google.com return mod 31112302Sgabeblack@google.com 31212302Sgabeblack@google.compy_modules = {} 31312302Sgabeblack@google.comfor source in py_sources: 31411983Sgabeblack@google.com py_modules[source.modpath] = source.snode.abspath 3156143Snate@binkert.org 31612305Sgabeblack@google.com# install the python importer so we can grab stuff from the source 31712302Sgabeblack@google.com# tree itself. We can't have SimObjects added after this point or 31812302Sgabeblack@google.com# else we won't know about them for the rest of the stuff. 31912302Sgabeblack@google.comsim_objects_fixed = True 3206143Snate@binkert.orgimporter = DictImporter(py_modules) 3216143Snate@binkert.orgsys.meta_path[0:0] = [ importer ] 3226143Snate@binkert.org 3235522Snate@binkert.orgimport m5 3246143Snate@binkert.org 3256143Snate@binkert.org# import all sim objects so we can populate the all_objects list 3266143Snate@binkert.org# make sure that we're working with a list, then let's sort it 3279982Satgutier@umich.edusim_objects = list(sim_object_modfiles) 32812302Sgabeblack@google.comsim_objects.sort() 32912302Sgabeblack@google.comfor simobj in sim_objects: 33012302Sgabeblack@google.com exec('from m5.objects import %s' % simobj) 3316143Snate@binkert.org 3326143Snate@binkert.org# we need to unload all of the currently imported modules so that they 3336143Snate@binkert.org# will be re-imported the next time the sconscript is run 3346143Snate@binkert.orgimporter.unload() 3355522Snate@binkert.orgsys.meta_path.remove(importer) 3365522Snate@binkert.org 3375522Snate@binkert.orgsim_objects = m5.SimObject.allClasses 3385522Snate@binkert.orgall_enums = m5.params.allEnums 3395604Snate@binkert.org 3405604Snate@binkert.orgall_params = {} 3416143Snate@binkert.orgfor name,obj in sim_objects.iteritems(): 3426143Snate@binkert.org for param in obj._params.local.values(): 3434762Snate@binkert.org if not hasattr(param, 'swig_decl'): 3444762Snate@binkert.org continue 3456143Snate@binkert.org pname = param.ptype_str 3466727Ssteve.reinhardt@amd.com if pname not in all_params: 3476727Ssteve.reinhardt@amd.com all_params[pname] = param 3486727Ssteve.reinhardt@amd.com 3494762Snate@binkert.org######################################################################## 3506143Snate@binkert.org# 3516143Snate@binkert.org# calculate extra dependencies 3526143Snate@binkert.org# 3536143Snate@binkert.orgmodule_depends = ["m5", "m5.SimObject", "m5.params"] 3546727Ssteve.reinhardt@amd.comdepends = [ File(py_modules[dep]) for dep in module_depends ] 3556143Snate@binkert.org 3567674Snate@binkert.org######################################################################## 3577674Snate@binkert.org# 3585604Snate@binkert.org# Commands for the basic automatically generated python files 3596143Snate@binkert.org# 3606143Snate@binkert.org 3616143Snate@binkert.org# Generate Python file containing a dict specifying the current 3624762Snate@binkert.org# build_env flags. 3636143Snate@binkert.orgdef makeDefinesPyFile(target, source, env): 3644762Snate@binkert.org f = file(str(target[0]), 'w') 3654762Snate@binkert.org print >>f, "m5_build_env = ", source[0] 3664762Snate@binkert.org f.close() 3676143Snate@binkert.org 3686143Snate@binkert.org# Generate python file containing info about the M5 source code 3694762Snate@binkert.orgdef makeInfoPyFile(target, source, env): 37012302Sgabeblack@google.com f = file(str(target[0]), 'w') 37112302Sgabeblack@google.com for src in source: 3728233Snate@binkert.org data = ''.join(file(src.srcnode().abspath, 'r').xreadlines()) 37312302Sgabeblack@google.com print >>f, "%s = %s" % (src, repr(data)) 3746143Snate@binkert.org f.close() 3756143Snate@binkert.org 3764762Snate@binkert.org# Generate the __init__.py file for m5.objects 3776143Snate@binkert.orgdef makeObjectsInitFile(target, source, env): 3784762Snate@binkert.org f = file(str(target[0]), 'w') 3799396Sandreas.hansson@arm.com print >>f, 'from params import *' 3809396Sandreas.hansson@arm.com print >>f, 'from m5.SimObject import *' 3819396Sandreas.hansson@arm.com for module in source: 38212302Sgabeblack@google.com print >>f, 'from %s import *' % module.get_contents() 38312302Sgabeblack@google.com f.close() 38412302Sgabeblack@google.com 3859396Sandreas.hansson@arm.com# Generate a file with all of the compile options in it 3869396Sandreas.hansson@arm.comenv.Command('python/m5/defines.py', Value(build_env), makeDefinesPyFile) 3879396Sandreas.hansson@arm.comPySource('m5', 'python/m5/defines.py') 3889396Sandreas.hansson@arm.com 3899396Sandreas.hansson@arm.com# Generate a file that wraps the basic top level files 3909396Sandreas.hansson@arm.comenv.Command('python/m5/info.py', 3919396Sandreas.hansson@arm.com [ '#/AUTHORS', '#/LICENSE', '#/README', '#/RELEASE_NOTES' ], 3929930Sandreas.hansson@arm.com makeInfoPyFile) 3939930Sandreas.hansson@arm.comPySource('m5', 'python/m5/info.py') 3949396Sandreas.hansson@arm.com 3956143Snate@binkert.org# Generate an __init__.py file for the objects package 39612797Sgabeblack@google.comenv.Command('python/m5/objects/__init__.py', 39712797Sgabeblack@google.com [ Value(o) for o in sort_list(sim_object_modfiles) ], 39812797Sgabeblack@google.com makeObjectsInitFile) 3998235Snate@binkert.orgPySource('m5.objects', 'python/m5/objects/__init__.py') 40012797Sgabeblack@google.com 40112797Sgabeblack@google.com######################################################################## 40212797Sgabeblack@google.com# 40312797Sgabeblack@google.com# Create all of the SimObject param headers and enum headers 40412797Sgabeblack@google.com# 40512797Sgabeblack@google.com 40612797Sgabeblack@google.comdef createSimObjectParam(target, source, env): 40712797Sgabeblack@google.com assert len(target) == 1 and len(source) == 1 40812797Sgabeblack@google.com 40912797Sgabeblack@google.com hh_file = file(target[0].abspath, 'w') 41012797Sgabeblack@google.com name = str(source[0].get_contents()) 41112797Sgabeblack@google.com obj = sim_objects[name] 41212797Sgabeblack@google.com 41312797Sgabeblack@google.com print >>hh_file, obj.cxx_decl() 41412797Sgabeblack@google.com 41512757Sgabeblack@google.comdef createSwigParam(target, source, env): 41612757Sgabeblack@google.com assert len(target) == 1 and len(source) == 1 41712797Sgabeblack@google.com 41812797Sgabeblack@google.com i_file = file(target[0].abspath, 'w') 41912797Sgabeblack@google.com name = str(source[0].get_contents()) 42012757Sgabeblack@google.com param = all_params[name] 42112757Sgabeblack@google.com 42212757Sgabeblack@google.com for line in param.swig_decl(): 42312757Sgabeblack@google.com print >>i_file, line 4248235Snate@binkert.org 42512302Sgabeblack@google.comdef createEnumStrings(target, source, env): 4268235Snate@binkert.org assert len(target) == 1 and len(source) == 1 4278235Snate@binkert.org 42812757Sgabeblack@google.com cc_file = file(target[0].abspath, 'w') 4298235Snate@binkert.org name = str(source[0].get_contents()) 4308235Snate@binkert.org obj = all_enums[name] 4318235Snate@binkert.org 43212757Sgabeblack@google.com print >>cc_file, obj.cxx_def() 43312313Sgabeblack@google.com cc_file.close() 43412797Sgabeblack@google.com 43512797Sgabeblack@google.comdef createEnumParam(target, source, env): 43612797Sgabeblack@google.com assert len(target) == 1 and len(source) == 1 43712797Sgabeblack@google.com 43812797Sgabeblack@google.com hh_file = file(target[0].abspath, 'w') 43912797Sgabeblack@google.com name = str(source[0].get_contents()) 44012797Sgabeblack@google.com obj = all_enums[name] 44112797Sgabeblack@google.com 44212797Sgabeblack@google.com print >>hh_file, obj.cxx_decl() 44312797Sgabeblack@google.com 44412797Sgabeblack@google.com# Generate all of the SimObject param struct header files 44512797Sgabeblack@google.comparams_hh_files = [] 44612797Sgabeblack@google.comfor name,simobj in sim_objects.iteritems(): 44712797Sgabeblack@google.com extra_deps = [ File(py_modules[simobj.__module__]) ] 44812797Sgabeblack@google.com 44912797Sgabeblack@google.com hh_file = File('params/%s.hh' % name) 45012797Sgabeblack@google.com params_hh_files.append(hh_file) 45112797Sgabeblack@google.com env.Command(hh_file, Value(name), createSimObjectParam) 45212797Sgabeblack@google.com env.Depends(hh_file, depends + extra_deps) 45312797Sgabeblack@google.com 45412797Sgabeblack@google.com# Generate any parameter header files needed 45512797Sgabeblack@google.comparams_i_files = [] 45612797Sgabeblack@google.comfor name,param in all_params.iteritems(): 45712797Sgabeblack@google.com if isinstance(param, m5.params.VectorParamDesc): 45812797Sgabeblack@google.com ext = 'vptype' 45912797Sgabeblack@google.com else: 46012797Sgabeblack@google.com ext = 'ptype' 46112797Sgabeblack@google.com 46212797Sgabeblack@google.com i_file = File('params/%s_%s.i' % (name, ext)) 46312797Sgabeblack@google.com params_i_files.append(i_file) 46412797Sgabeblack@google.com env.Command(i_file, Value(name), createSwigParam) 46512797Sgabeblack@google.com env.Depends(i_file, depends) 46612797Sgabeblack@google.com 46712797Sgabeblack@google.com# Generate all enum header files 46812797Sgabeblack@google.comfor name,enum in all_enums.iteritems(): 46912797Sgabeblack@google.com extra_deps = [ File(py_modules[enum.__module__]) ] 47012797Sgabeblack@google.com 47112797Sgabeblack@google.com cc_file = File('enums/%s.cc' % name) 47212797Sgabeblack@google.com env.Command(cc_file, Value(name), createEnumStrings) 47312797Sgabeblack@google.com env.Depends(cc_file, depends + extra_deps) 47412797Sgabeblack@google.com Source(cc_file) 47512797Sgabeblack@google.com 47612797Sgabeblack@google.com hh_file = File('enums/%s.hh' % name) 47712797Sgabeblack@google.com env.Command(hh_file, Value(name), createEnumParam) 47812313Sgabeblack@google.com env.Depends(hh_file, depends + extra_deps) 47912313Sgabeblack@google.com 48012797Sgabeblack@google.com# Build the big monolithic swigged params module (wraps all SimObject 48112797Sgabeblack@google.com# param structs and enum structs) 48212797Sgabeblack@google.comdef buildParams(target, source, env): 48312371Sgabeblack@google.com names = [ s.get_contents() for s in source ] 4845584Snate@binkert.org objs = [ sim_objects[name] for name in names ] 48512797Sgabeblack@google.com out = file(target[0].abspath, 'w') 48612797Sgabeblack@google.com 48712797Sgabeblack@google.com ordered_objs = [] 48812797Sgabeblack@google.com obj_seen = set() 48912797Sgabeblack@google.com def order_obj(obj): 49012797Sgabeblack@google.com name = str(obj) 49112797Sgabeblack@google.com if name in obj_seen: 49212797Sgabeblack@google.com return 49312797Sgabeblack@google.com 49412797Sgabeblack@google.com obj_seen.add(name) 49512797Sgabeblack@google.com if str(obj) != 'SimObject': 49612797Sgabeblack@google.com order_obj(obj.__bases__[0]) 49712797Sgabeblack@google.com 49812797Sgabeblack@google.com ordered_objs.append(obj) 49912797Sgabeblack@google.com 50012797Sgabeblack@google.com for obj in objs: 50112797Sgabeblack@google.com order_obj(obj) 50212797Sgabeblack@google.com 50312797Sgabeblack@google.com enums = set() 50412797Sgabeblack@google.com predecls = [] 50512797Sgabeblack@google.com pd_seen = set() 50612797Sgabeblack@google.com 50712797Sgabeblack@google.com def add_pds(*pds): 50812797Sgabeblack@google.com for pd in pds: 50912797Sgabeblack@google.com if pd not in pd_seen: 51012797Sgabeblack@google.com predecls.append(pd) 51112797Sgabeblack@google.com pd_seen.add(pd) 51212797Sgabeblack@google.com 51312797Sgabeblack@google.com for obj in ordered_objs: 51412797Sgabeblack@google.com params = obj._params.local.values() 51512797Sgabeblack@google.com for param in params: 51612797Sgabeblack@google.com ptype = param.ptype 51712797Sgabeblack@google.com if issubclass(ptype, m5.params.Enum): 51812797Sgabeblack@google.com if ptype not in enums: 51912797Sgabeblack@google.com enums.add(ptype) 52012797Sgabeblack@google.com pds = param.swig_predecls() 52112797Sgabeblack@google.com if isinstance(pds, (list, tuple)): 52212797Sgabeblack@google.com add_pds(*pds) 5234382Sbinkertn@umich.edu else: 52413576Sciro.santilli@arm.com add_pds(pds) 5254202Sbinkertn@umich.edu 5264382Sbinkertn@umich.edu print >>out, '%module params' 5274382Sbinkertn@umich.edu 5289396Sandreas.hansson@arm.com print >>out, '%{' 52912797Sgabeblack@google.com for obj in ordered_objs: 5305584Snate@binkert.org print >>out, '#include "params/%s.hh"' % obj 53112313Sgabeblack@google.com print >>out, '%}' 5324382Sbinkertn@umich.edu 5334382Sbinkertn@umich.edu for pd in predecls: 5344382Sbinkertn@umich.edu print >>out, pd 5358232Snate@binkert.org 5365192Ssaidi@eecs.umich.edu enums = list(enums) 5378232Snate@binkert.org enums.sort() 5388232Snate@binkert.org for enum in enums: 5398232Snate@binkert.org print >>out, '%%include "enums/%s.hh"' % enum.__name__ 5405192Ssaidi@eecs.umich.edu print >>out 5418232Snate@binkert.org 5425192Ssaidi@eecs.umich.edu for obj in ordered_objs: 5435799Snate@binkert.org if obj.swig_objdecls: 5448232Snate@binkert.org for decl in obj.swig_objdecls: 5455192Ssaidi@eecs.umich.edu print >>out, decl 5465192Ssaidi@eecs.umich.edu continue 5475192Ssaidi@eecs.umich.edu 5488232Snate@binkert.org class_path = obj.cxx_class.split('::') 5495192Ssaidi@eecs.umich.edu classname = class_path[-1] 5508232Snate@binkert.org namespaces = class_path[:-1] 5515192Ssaidi@eecs.umich.edu namespaces.reverse() 5525192Ssaidi@eecs.umich.edu 5535192Ssaidi@eecs.umich.edu code = '' 5545192Ssaidi@eecs.umich.edu 5554382Sbinkertn@umich.edu if namespaces: 5564382Sbinkertn@umich.edu code += '// avoid name conflicts\n' 5574382Sbinkertn@umich.edu sep_string = '_COLONS_' 5582667Sstever@eecs.umich.edu flat_name = sep_string.join(class_path) 5592667Sstever@eecs.umich.edu code += '%%rename(%s) %s;\n' % (flat_name, classname) 5602667Sstever@eecs.umich.edu 5612667Sstever@eecs.umich.edu code += '// stop swig from creating/wrapping default ctor/dtor\n' 5622667Sstever@eecs.umich.edu code += '%%nodefault %s;\n' % classname 5632667Sstever@eecs.umich.edu code += 'class %s ' % classname 5645742Snate@binkert.org if obj._base: 5655742Snate@binkert.org code += ': public %s' % obj._base.cxx_class 5665742Snate@binkert.org code += ' {};\n' 5675793Snate@binkert.org 5688334Snate@binkert.org for ns in namespaces: 5695793Snate@binkert.org new_code = 'namespace %s {\n' % ns 5705793Snate@binkert.org new_code += code 5715793Snate@binkert.org new_code += '}\n' 5724382Sbinkertn@umich.edu code = new_code 5734762Snate@binkert.org 5745344Sstever@gmail.com print >>out, code 5754382Sbinkertn@umich.edu 5765341Sstever@gmail.com print >>out, '%%include "src/sim/sim_object_params.hh"' % obj 5775742Snate@binkert.org for obj in ordered_objs: 5785742Snate@binkert.org print >>out, '%%include "params/%s.hh"' % obj 5795742Snate@binkert.org 5805742Snate@binkert.orgparams_file = File('params/params.i') 5815742Snate@binkert.orgnames = sort_list(sim_objects.keys()) 5824762Snate@binkert.orgenv.Command(params_file, [ Value(v) for v in names ], buildParams) 5835742Snate@binkert.orgenv.Depends(params_file, params_hh_files + params_i_files + depends) 5845742Snate@binkert.orgSwigSource('m5.objects', params_file) 58511984Sgabeblack@google.com 5867722Sgblack@eecs.umich.edu# Build all swig modules 5875742Snate@binkert.orgswig_modules = [] 5885742Snate@binkert.orgcc_swig_sources = [] 5895742Snate@binkert.orgfor source,package in swig_sources: 5909930Sandreas.hansson@arm.com filename = str(source) 5919930Sandreas.hansson@arm.com assert filename.endswith('.i') 5929930Sandreas.hansson@arm.com 5939930Sandreas.hansson@arm.com base = '.'.join(filename.split('.')[:-1]) 5949930Sandreas.hansson@arm.com module = basename(base) 5955742Snate@binkert.org cc_file = base + '_wrap.cc' 5968242Sbradley.danofsky@amd.com py_file = base + '.py' 5978242Sbradley.danofsky@amd.com 5988242Sbradley.danofsky@amd.com env.Command([cc_file, py_file], source, 5998242Sbradley.danofsky@amd.com '$SWIG $SWIGFLAGS -outdir ${TARGETS[1].dir} ' 6005341Sstever@gmail.com '-o ${TARGETS[0]} $SOURCES') 6015742Snate@binkert.org env.Depends(py_file, source) 6027722Sgblack@eecs.umich.edu env.Depends(cc_file, source) 6034773Snate@binkert.org 6046108Snate@binkert.org swig_modules.append(Value(module)) 6051858SN/A cc_swig_sources.append(File(cc_file)) 6061085SN/A PySource(package, py_file) 6076658Snate@binkert.org 6086658Snate@binkert.org# Generate the main swig init file 6097673Snate@binkert.orgdef makeSwigInit(target, source, env): 6106658Snate@binkert.org f = file(str(target[0]), 'w') 6116658Snate@binkert.org print >>f, 'extern "C" {' 61211308Santhony.gutierrez@amd.com for module in source: 6136658Snate@binkert.org print >>f, ' void init_%s();' % module.get_contents() 61411308Santhony.gutierrez@amd.com print >>f, '}' 6156658Snate@binkert.org print >>f, 'void initSwig() {' 6166658Snate@binkert.org for module in source: 6177673Snate@binkert.org print >>f, ' init_%s();' % module.get_contents() 6187673Snate@binkert.org print >>f, '}' 6197673Snate@binkert.org f.close() 6207673Snate@binkert.org 6217673Snate@binkert.orgenv.Command('python/swig/init.cc', swig_modules, makeSwigInit) 6227673Snate@binkert.orgSource('python/swig/init.cc') 6237673Snate@binkert.org 62410467Sandreas.hansson@arm.com# Generate traceflags.py 6256658Snate@binkert.orgdef traceFlagsPy(target, source, env): 6267673Snate@binkert.org assert(len(target) == 1) 62710467Sandreas.hansson@arm.com 62810467Sandreas.hansson@arm.com f = file(str(target[0]), 'w') 62910467Sandreas.hansson@arm.com 63010467Sandreas.hansson@arm.com allFlags = [] 63110467Sandreas.hansson@arm.com for s in source: 63210467Sandreas.hansson@arm.com val = eval(s.get_contents()) 63310467Sandreas.hansson@arm.com allFlags.append(val) 63410467Sandreas.hansson@arm.com 63510467Sandreas.hansson@arm.com print >>f, 'baseFlags = [' 63610467Sandreas.hansson@arm.com for flag, compound, desc in allFlags: 63710467Sandreas.hansson@arm.com if not compound: 6387673Snate@binkert.org print >>f, " '%s'," % flag 6397673Snate@binkert.org print >>f, " ]" 6407673Snate@binkert.org print >>f 6417673Snate@binkert.org 6427673Snate@binkert.org print >>f, 'compoundFlags = [' 6439048SAli.Saidi@ARM.com print >>f, " 'All'," 6447673Snate@binkert.org for flag, compound, desc in allFlags: 6457673Snate@binkert.org if compound: 6467673Snate@binkert.org print >>f, " '%s'," % flag 6477673Snate@binkert.org print >>f, " ]" 6486658Snate@binkert.org print >>f 6497756SAli.Saidi@ARM.com 6507816Ssteve.reinhardt@amd.com print >>f, "allFlags = frozenset(baseFlags + compoundFlags)" 6516658Snate@binkert.org print >>f 65211308Santhony.gutierrez@amd.com 65311308Santhony.gutierrez@amd.com print >>f, 'compoundFlagMap = {' 65411308Santhony.gutierrez@amd.com all = tuple([flag for flag,compound,desc in allFlags if not compound]) 65511308Santhony.gutierrez@amd.com print >>f, " 'All' : %s," % (all, ) 65611308Santhony.gutierrez@amd.com for flag, compound, desc in allFlags: 65711308Santhony.gutierrez@amd.com if compound: 65811308Santhony.gutierrez@amd.com print >>f, " '%s' : %s," % (flag, compound) 65911308Santhony.gutierrez@amd.com print >>f, " }" 66011308Santhony.gutierrez@amd.com print >>f 66111308Santhony.gutierrez@amd.com 66211308Santhony.gutierrez@amd.com print >>f, 'flagDescriptions = {' 66311308Santhony.gutierrez@amd.com print >>f, " 'All' : 'All flags'," 66411308Santhony.gutierrez@amd.com for flag, compound, desc in allFlags: 66511308Santhony.gutierrez@amd.com print >>f, " '%s' : '%s'," % (flag, desc) 66611308Santhony.gutierrez@amd.com print >>f, " }" 66711308Santhony.gutierrez@amd.com 66811308Santhony.gutierrez@amd.com f.close() 66911308Santhony.gutierrez@amd.com 67011308Santhony.gutierrez@amd.comdef traceFlagsCC(target, source, env): 67111308Santhony.gutierrez@amd.com assert(len(target) == 1) 67211308Santhony.gutierrez@amd.com 67311308Santhony.gutierrez@amd.com f = file(str(target[0]), 'w') 67411308Santhony.gutierrez@amd.com 67511308Santhony.gutierrez@amd.com allFlags = [] 67611308Santhony.gutierrez@amd.com for s in source: 67711308Santhony.gutierrez@amd.com val = eval(s.get_contents()) 67811308Santhony.gutierrez@amd.com allFlags.append(val) 67911308Santhony.gutierrez@amd.com 68011308Santhony.gutierrez@amd.com # file header 68111308Santhony.gutierrez@amd.com print >>f, ''' 68211308Santhony.gutierrez@amd.com/* 68311308Santhony.gutierrez@amd.com * DO NOT EDIT THIS FILE! Automatically generated 68411308Santhony.gutierrez@amd.com */ 68511308Santhony.gutierrez@amd.com 68611308Santhony.gutierrez@amd.com#include "base/traceflags.hh" 68711308Santhony.gutierrez@amd.com 68811308Santhony.gutierrez@amd.comusing namespace Trace; 68911308Santhony.gutierrez@amd.com 69011308Santhony.gutierrez@amd.comconst char *Trace::flagStrings[] = 69111308Santhony.gutierrez@amd.com{''' 69211308Santhony.gutierrez@amd.com 69311308Santhony.gutierrez@amd.com # The string array is used by SimpleEnumParam to map the strings 69411308Santhony.gutierrez@amd.com # provided by the user to enum values. 69511308Santhony.gutierrez@amd.com for flag, compound, desc in allFlags: 69611308Santhony.gutierrez@amd.com if not compound: 6974382Sbinkertn@umich.edu print >>f, ' "%s",' % flag 6984382Sbinkertn@umich.edu 6994762Snate@binkert.org print >>f, ' "All",' 7004762Snate@binkert.org for flag, compound, desc in allFlags: 7014762Snate@binkert.org if compound: 7026654Snate@binkert.org print >>f, ' "%s",' % flag 7036654Snate@binkert.org 7045517Snate@binkert.org print >>f, '};' 7055517Snate@binkert.org print >>f 7065517Snate@binkert.org print >>f, 'const int Trace::numFlagStrings = %d;' % (len(allFlags) + 1) 7075517Snate@binkert.org print >>f 7085517Snate@binkert.org 7095517Snate@binkert.org # 7105517Snate@binkert.org # Now define the individual compound flag arrays. There is an array 7115517Snate@binkert.org # for each compound flag listing the component base flags. 7125517Snate@binkert.org # 7135517Snate@binkert.org all = tuple([flag for flag,compound,desc in allFlags if not compound]) 7145517Snate@binkert.org print >>f, 'static const Flags AllMap[] = {' 7155517Snate@binkert.org for flag, compound, desc in allFlags: 7165517Snate@binkert.org if not compound: 7175517Snate@binkert.org print >>f, " %s," % flag 7185517Snate@binkert.org print >>f, '};' 7195517Snate@binkert.org print >>f 7205517Snate@binkert.org 7216654Snate@binkert.org for flag, compound, desc in allFlags: 7225517Snate@binkert.org if not compound: 7235517Snate@binkert.org continue 7245517Snate@binkert.org print >>f, 'static const Flags %sMap[] = {' % flag 7255517Snate@binkert.org for flag in compound: 7265517Snate@binkert.org print >>f, " %s," % flag 72711802Sandreas.sandberg@arm.com print >>f, " (Flags)-1" 7285517Snate@binkert.org print >>f, '};' 7295517Snate@binkert.org print >>f 7306143Snate@binkert.org 7316654Snate@binkert.org # 7325517Snate@binkert.org # Finally the compoundFlags[] array maps the compound flags 7335517Snate@binkert.org # to their individual arrays/ 7345517Snate@binkert.org # 7355517Snate@binkert.org print >>f, 'const Flags *Trace::compoundFlags[] =' 7365517Snate@binkert.org print >>f, '{' 7375517Snate@binkert.org print >>f, ' AllMap,' 7385517Snate@binkert.org for flag, compound, desc in allFlags: 7395517Snate@binkert.org if compound: 7405517Snate@binkert.org print >>f, ' %sMap,' % flag 7415517Snate@binkert.org # file trailer 7425517Snate@binkert.org print >>f, '};' 7435517Snate@binkert.org 7445517Snate@binkert.org f.close() 7455517Snate@binkert.org 7466654Snate@binkert.orgdef traceFlagsHH(target, source, env): 7476654Snate@binkert.org assert(len(target) == 1) 7485517Snate@binkert.org 7495517Snate@binkert.org f = file(str(target[0]), 'w') 7506143Snate@binkert.org 7516143Snate@binkert.org allFlags = [] 7526143Snate@binkert.org for s in source: 7536727Ssteve.reinhardt@amd.com val = eval(s.get_contents()) 7545517Snate@binkert.org allFlags.append(val) 7556727Ssteve.reinhardt@amd.com 7565517Snate@binkert.org # file header boilerplate 7575517Snate@binkert.org print >>f, ''' 7585517Snate@binkert.org/* 7596654Snate@binkert.org * DO NOT EDIT THIS FILE! 7606654Snate@binkert.org * 7617673Snate@binkert.org * Automatically generated from traceflags.py 7626654Snate@binkert.org */ 7636654Snate@binkert.org 7646654Snate@binkert.org#ifndef __BASE_TRACE_FLAGS_HH__ 7656654Snate@binkert.org#define __BASE_TRACE_FLAGS_HH__ 7665517Snate@binkert.org 7675517Snate@binkert.orgnamespace Trace { 7685517Snate@binkert.org 7696143Snate@binkert.orgenum Flags {''' 7705517Snate@binkert.org 7714762Snate@binkert.org # Generate the enum. Base flags come first, then compound flags. 7725517Snate@binkert.org idx = 0 7735517Snate@binkert.org for flag, compound, desc in allFlags: 7746143Snate@binkert.org if not compound: 7756143Snate@binkert.org print >>f, ' %s = %d,' % (flag, idx) 7765517Snate@binkert.org idx += 1 7775517Snate@binkert.org 7785517Snate@binkert.org numBaseFlags = idx 7795517Snate@binkert.org print >>f, ' NumFlags = %d,' % idx 7805517Snate@binkert.org 7815517Snate@binkert.org # put a comment in here to separate base from compound flags 7825517Snate@binkert.org print >>f, ''' 7835517Snate@binkert.org// The remaining enum values are *not* valid indices for Trace::flags. 7845517Snate@binkert.org// They are "compound" flags, which correspond to sets of base 7856143Snate@binkert.org// flags, and are used by changeFlag.''' 7865517Snate@binkert.org 7876654Snate@binkert.org print >>f, ' All = %d,' % idx 7886654Snate@binkert.org idx += 1 7896654Snate@binkert.org for flag, compound, desc in allFlags: 7906654Snate@binkert.org if compound: 7916654Snate@binkert.org print >>f, ' %s = %d,' % (flag, idx) 7926654Snate@binkert.org idx += 1 7934762Snate@binkert.org 7944762Snate@binkert.org numCompoundFlags = idx - numBaseFlags 7954762Snate@binkert.org print >>f, ' NumCompoundFlags = %d' % numCompoundFlags 7964762Snate@binkert.org 7974762Snate@binkert.org # trailer boilerplate 7987675Snate@binkert.org print >>f, '''\ 79910584Sandreas.hansson@arm.com}; // enum Flags 8004762Snate@binkert.org 8014762Snate@binkert.org// Array of strings for SimpleEnumParam 8024762Snate@binkert.orgextern const char *flagStrings[]; 8034762Snate@binkert.orgextern const int numFlagStrings; 8044382Sbinkertn@umich.edu 8054382Sbinkertn@umich.edu// Array of arraay pointers: for each compound flag, gives the list of 8065517Snate@binkert.org// base flags to set. Inidividual flag arrays are terminated by -1. 8076654Snate@binkert.orgextern const Flags *compoundFlags[]; 8085517Snate@binkert.org 8098126Sgblack@eecs.umich.edu/* namespace Trace */ } 8106654Snate@binkert.org 8117673Snate@binkert.org#endif // __BASE_TRACE_FLAGS_HH__ 8126654Snate@binkert.org''' 81311802Sandreas.sandberg@arm.com 8146654Snate@binkert.org f.close() 8156654Snate@binkert.org 8166654Snate@binkert.orgflags = [ Value(f) for f in trace_flags ] 8176654Snate@binkert.orgenv.Command('base/traceflags.py', flags, traceFlagsPy) 81811802Sandreas.sandberg@arm.comPySource('m5', 'base/traceflags.py') 8196669Snate@binkert.org 82011802Sandreas.sandberg@arm.comenv.Command('base/traceflags.hh', flags, traceFlagsHH) 8216669Snate@binkert.orgenv.Command('base/traceflags.cc', flags, traceFlagsCC) 8226669Snate@binkert.orgSource('base/traceflags.cc') 8236669Snate@binkert.org 8246669Snate@binkert.org# Generate program_info.cc 8256654Snate@binkert.orgdef programInfo(target, source, env): 8267673Snate@binkert.org def gen_file(target, rev, node, date): 8275517Snate@binkert.org pi_stats = file(target, 'w') 8288126Sgblack@eecs.umich.edu print >>pi_stats, 'const char *hgRev = "%s:%s";' % (rev, node) 8295798Snate@binkert.org print >>pi_stats, 'const char *hgDate = "%s";' % date 8307756SAli.Saidi@ARM.com pi_stats.close() 8317816Ssteve.reinhardt@amd.com 8325798Snate@binkert.org target = str(target[0]) 8335798Snate@binkert.org scons_dir = str(source[0].get_contents()) 8345517Snate@binkert.org try: 8355517Snate@binkert.org import mercurial.demandimport, mercurial.hg, mercurial.ui 8367673Snate@binkert.org import mercurial.util, mercurial.node 8375517Snate@binkert.org if not exists(scons_dir) or not isdir(scons_dir) or \ 8385517Snate@binkert.org not exists(joinpath(scons_dir, ".hg")): 8397673Snate@binkert.org raise ValueError 8407673Snate@binkert.org repo = mercurial.hg.repository(mercurial.ui.ui(), scons_dir) 8415517Snate@binkert.org rev = mercurial.node.nullrev + repo.changelog.count() 8425798Snate@binkert.org changenode = repo.changelog.node(rev) 8435798Snate@binkert.org changes = repo.changelog.read(changenode) 8448333Snate@binkert.org date = mercurial.util.datestr(changes[2]) 8457816Ssteve.reinhardt@amd.com 8465798Snate@binkert.org gen_file(target, rev, mercurial.node.hex(changenode), date) 8475798Snate@binkert.org 8484762Snate@binkert.org mercurial.demandimport.disable() 8494762Snate@binkert.org except ImportError: 8504762Snate@binkert.org gen_file(target, "Unknown", "Unknown", "Unknown") 8514762Snate@binkert.org 8524762Snate@binkert.org except: 8538596Ssteve.reinhardt@amd.com print "in except" 8545517Snate@binkert.org gen_file(target, "Unknown", "Unknown", "Unknown") 8555517Snate@binkert.org mercurial.demandimport.disable() 85611997Sgabeblack@google.com 8575517Snate@binkert.orgenv.Command('base/program_info.cc', 8585517Snate@binkert.org Value(str(SCons.Node.FS.default_fs.SConstruct_dir)), 8597673Snate@binkert.org programInfo) 8608596Ssteve.reinhardt@amd.com 8617673Snate@binkert.org# embed python files. All .py files that have been indicated by a 8625517Snate@binkert.org# PySource() call in a SConscript need to be embedded into the M5 86310458Sandreas.hansson@arm.com# library. To do that, we compile the file to byte code, marshal the 86410458Sandreas.hansson@arm.com# byte code, compress it, and then generate an assembly file that 86510458Sandreas.hansson@arm.com# inserts the result into the data section with symbols indicating the 86610458Sandreas.hansson@arm.com# beginning, and end (and with the size at the end) 86710458Sandreas.hansson@arm.compy_sources_tnodes = {} 86810458Sandreas.hansson@arm.comfor pysource in py_sources: 86910458Sandreas.hansson@arm.com py_sources_tnodes[pysource.tnode] = pysource 87010458Sandreas.hansson@arm.com 87110458Sandreas.hansson@arm.comdef objectifyPyFile(target, source, env): 87210458Sandreas.hansson@arm.com '''Action function to compile a .py into a code object, marshal 87310458Sandreas.hansson@arm.com it, compress it, and stick it into an asm file so the code appears 87410458Sandreas.hansson@arm.com as just bytes with a label in the data section''' 8755517Snate@binkert.org 87611996Sgabeblack@google.com src = file(str(source[0]), 'r').read() 8775517Snate@binkert.org dst = file(str(target[0]), 'w') 87811997Sgabeblack@google.com 87911996Sgabeblack@google.com pysource = py_sources_tnodes[source[0]] 8805517Snate@binkert.org compiled = compile(src, pysource.debugname, 'exec') 8815517Snate@binkert.org marshalled = marshal.dumps(compiled) 8827673Snate@binkert.org compressed = zlib.compress(marshalled) 8837673Snate@binkert.org data = compressed 88411996Sgabeblack@google.com 88511988Sandreas.sandberg@arm.com # Some C/C++ compilers prepend an underscore to global symbol 8867673Snate@binkert.org # names, so if they're going to do that, we need to prepend that 8875517Snate@binkert.org # leading underscore to globals in the assembly file. 8888596Ssteve.reinhardt@amd.com if env['LEADING_UNDERSCORE']: 8895517Snate@binkert.org sym = '_' + pysource.symname 8905517Snate@binkert.org else: 89111997Sgabeblack@google.com sym = pysource.symname 8925517Snate@binkert.org 8935517Snate@binkert.org step = 16 8947673Snate@binkert.org print >>dst, ".data" 8957673Snate@binkert.org print >>dst, ".globl %s_beg" % sym 8967673Snate@binkert.org print >>dst, ".globl %s_end" % sym 8975517Snate@binkert.org print >>dst, "%s_beg:" % sym 89811988Sandreas.sandberg@arm.com for i in xrange(0, len(data), step): 89911997Sgabeblack@google.com x = array.array('B', data[i:i+step]) 9008596Ssteve.reinhardt@amd.com print >>dst, ".byte", ','.join([str(d) for d in x]) 9018596Ssteve.reinhardt@amd.com print >>dst, "%s_end:" % sym 9028596Ssteve.reinhardt@amd.com print >>dst, ".long %d" % len(marshalled) 90311988Sandreas.sandberg@arm.com 9048596Ssteve.reinhardt@amd.comfor source in py_sources: 9058596Ssteve.reinhardt@amd.com env.Command(source.assembly, source.tnode, objectifyPyFile) 9068596Ssteve.reinhardt@amd.com Source(source.assembly) 9074762Snate@binkert.org 9086143Snate@binkert.org# Generate init_python.cc which creates a bunch of EmbeddedPyModule 9096143Snate@binkert.org# structs that describe the embedded python code. One such struct 9106143Snate@binkert.org# contains information about the importer that python uses to get at 9114762Snate@binkert.org# the embedded files, and then there's a list of all of the rest that 9124762Snate@binkert.org# the importer uses to load the rest on demand. 9134762Snate@binkert.orgpy_sources_symbols = {} 9147756SAli.Saidi@ARM.comfor pysource in py_sources: 9158596Ssteve.reinhardt@amd.com py_sources_symbols[pysource.symname] = pysource 9164762Snate@binkert.orgdef pythonInit(target, source, env): 9174762Snate@binkert.org dst = file(str(target[0]), 'w') 91810458Sandreas.hansson@arm.com 91910458Sandreas.hansson@arm.com def dump_mod(sym, endchar=','): 92010458Sandreas.hansson@arm.com pysource = py_sources_symbols[sym] 92110458Sandreas.hansson@arm.com print >>dst, ' { "%s",' % pysource.arcname 92210458Sandreas.hansson@arm.com print >>dst, ' "%s",' % pysource.modpath 92310458Sandreas.hansson@arm.com print >>dst, ' %s_beg, %s_end,' % (sym, sym) 92410458Sandreas.hansson@arm.com print >>dst, ' %s_end - %s_beg,' % (sym, sym) 92510458Sandreas.hansson@arm.com print >>dst, ' *(int *)%s_end }%s' % (sym, endchar) 92610458Sandreas.hansson@arm.com 92710458Sandreas.hansson@arm.com print >>dst, '#include "sim/init.hh"' 92810458Sandreas.hansson@arm.com 92910458Sandreas.hansson@arm.com for sym in source: 93010458Sandreas.hansson@arm.com sym = sym.get_contents() 93110458Sandreas.hansson@arm.com print >>dst, "extern const char %s_beg[], %s_end[];" % (sym, sym) 93210458Sandreas.hansson@arm.com 93310458Sandreas.hansson@arm.com print >>dst, "const EmbeddedPyModule embeddedPyImporter = " 93410458Sandreas.hansson@arm.com dump_mod("PyEMB_importer", endchar=';'); 93510458Sandreas.hansson@arm.com print >>dst 93610458Sandreas.hansson@arm.com 93710458Sandreas.hansson@arm.com print >>dst, "const EmbeddedPyModule embeddedPyModules[] = {" 93810458Sandreas.hansson@arm.com for i,sym in enumerate(source): 93910458Sandreas.hansson@arm.com sym = sym.get_contents() 94010458Sandreas.hansson@arm.com if sym == "PyEMB_importer": 94110458Sandreas.hansson@arm.com # Skip the importer since we've already exported it 94210458Sandreas.hansson@arm.com continue 94310458Sandreas.hansson@arm.com dump_mod(sym) 94410458Sandreas.hansson@arm.com print >>dst, " { 0, 0, 0, 0, 0, 0 }" 94510458Sandreas.hansson@arm.com print >>dst, "};" 94610458Sandreas.hansson@arm.com 94710458Sandreas.hansson@arm.comsymbols = [Value(s.symname) for s in py_sources] 94810458Sandreas.hansson@arm.comenv.Command('sim/init_python.cc', symbols, pythonInit) 94910458Sandreas.hansson@arm.comSource('sim/init_python.cc') 95010458Sandreas.hansson@arm.com 95110458Sandreas.hansson@arm.com######################################################################## 95210458Sandreas.hansson@arm.com# 95310458Sandreas.hansson@arm.com# Define binaries. Each different build type (debug, opt, etc.) gets 95410458Sandreas.hansson@arm.com# a slightly different build environment. 95510458Sandreas.hansson@arm.com# 95610458Sandreas.hansson@arm.com 95710458Sandreas.hansson@arm.com# List of constructed environments to pass back to SConstruct 95810458Sandreas.hansson@arm.comenvList = [] 95910458Sandreas.hansson@arm.com 96010458Sandreas.hansson@arm.com# This function adds the specified sources to the given build 96110458Sandreas.hansson@arm.com# environment, and returns a list of all the corresponding SCons 96210458Sandreas.hansson@arm.com# Object nodes (including an extra one for date.cc). We explicitly 96310458Sandreas.hansson@arm.com# add the Object nodes so we can set up special dependencies for 96410458Sandreas.hansson@arm.com# date.cc. 96510458Sandreas.hansson@arm.comdef make_objs(sources, env, static): 96610458Sandreas.hansson@arm.com if static: 96710584Sandreas.hansson@arm.com XObject = env.StaticObject 96810458Sandreas.hansson@arm.com else: 96910458Sandreas.hansson@arm.com XObject = env.SharedObject 97010458Sandreas.hansson@arm.com 97110458Sandreas.hansson@arm.com objs = [ XObject(s) for s in sources ] 97210458Sandreas.hansson@arm.com 9734762Snate@binkert.org # make date.cc depend on all other objects so it always gets 9746143Snate@binkert.org # recompiled whenever anything else does 9756143Snate@binkert.org date_obj = XObject('base/date.cc') 9766143Snate@binkert.org 9774762Snate@binkert.org # Make the generation of program_info.cc dependend on all 9784762Snate@binkert.org # the other cc files and the compiling of program_info.cc 97911996Sgabeblack@google.com # dependent on all the objects but program_info.o 9807816Ssteve.reinhardt@amd.com pinfo_obj = XObject('base/program_info.cc') 9814762Snate@binkert.org env.Depends('base/program_info.cc', sources) 9824762Snate@binkert.org env.Depends(date_obj, objs) 9834762Snate@binkert.org env.Depends(pinfo_obj, objs) 9844762Snate@binkert.org objs.extend([date_obj, pinfo_obj]) 9857756SAli.Saidi@ARM.com return objs 9868596Ssteve.reinhardt@amd.com 9874762Snate@binkert.org# Function to create a new build environment as clone of current 9884762Snate@binkert.org# environment 'env' with modified object suffix and optional stripped 98911988Sandreas.sandberg@arm.com# binary. Additional keyword arguments are appended to corresponding 99011988Sandreas.sandberg@arm.com# build environment vars. 99111988Sandreas.sandberg@arm.comdef makeEnv(label, objsfx, strip = False, **kwargs): 99211988Sandreas.sandberg@arm.com # SCons doesn't know to append a library suffix when there is a '.' in the 99311988Sandreas.sandberg@arm.com # name. Use '_' instead. 99411988Sandreas.sandberg@arm.com libname = 'm5_' + label 99511988Sandreas.sandberg@arm.com exename = 'm5.' + label 99611988Sandreas.sandberg@arm.com 99711988Sandreas.sandberg@arm.com new_env = env.Copy(OBJSUFFIX=objsfx, SHOBJSUFFIX=objsfx + 's') 99811988Sandreas.sandberg@arm.com new_env.Label = label 99911988Sandreas.sandberg@arm.com new_env.Append(**kwargs) 10004382Sbinkertn@umich.edu 10019396Sandreas.hansson@arm.com swig_env = new_env.Copy() 10029396Sandreas.hansson@arm.com if env['GCC']: 10039396Sandreas.hansson@arm.com swig_env.Append(CCFLAGS='-Wno-uninitialized') 10049396Sandreas.hansson@arm.com swig_env.Append(CCFLAGS='-Wno-sign-compare') 10059396Sandreas.hansson@arm.com swig_env.Append(CCFLAGS='-Wno-parentheses') 10069396Sandreas.hansson@arm.com 10079396Sandreas.hansson@arm.com static_objs = make_objs(cc_lib_sources, new_env, static=True) 10089396Sandreas.hansson@arm.com shared_objs = make_objs(cc_lib_sources, new_env, static=False) 10099396Sandreas.hansson@arm.com static_objs += [ swig_env.StaticObject(s) for s in cc_swig_sources ] 10109396Sandreas.hansson@arm.com shared_objs += [ swig_env.SharedObject(s) for s in cc_swig_sources ] 10119396Sandreas.hansson@arm.com 10129396Sandreas.hansson@arm.com # First make a library of everything but main() so other programs can 10139396Sandreas.hansson@arm.com # link against m5. 101412302Sgabeblack@google.com static_lib = new_env.StaticLibrary(libname, static_objs + static_objs) 10159396Sandreas.hansson@arm.com shared_lib = new_env.SharedLibrary(libname, shared_objs + shared_objs) 101612563Sgabeblack@google.com 10179396Sandreas.hansson@arm.com for target, sources in unit_tests: 10189396Sandreas.hansson@arm.com objs = [ new_env.StaticObject(s) for s in sources ] 10198232Snate@binkert.org new_env.Program("unittest/%s.%s" % (target, label), objs + static_lib) 10208232Snate@binkert.org 10218232Snate@binkert.org # Now link a stub with main() and the static library. 10228232Snate@binkert.org objects = [new_env.Object(s) for s in cc_bin_sources] + static_lib 10238232Snate@binkert.org if strip: 10246229Snate@binkert.org unstripped_exe = exename + '.unstripped' 102510455SCurtis.Dunham@arm.com new_env.Program(unstripped_exe, objects) 10266229Snate@binkert.org if sys.platform == 'sunos5': 102710455SCurtis.Dunham@arm.com cmd = 'cp $SOURCE $TARGET; strip $TARGET' 102810455SCurtis.Dunham@arm.com else: 102910455SCurtis.Dunham@arm.com cmd = 'strip $SOURCE -o $TARGET' 10305517Snate@binkert.org targets = new_env.Command(exename, unstripped_exe, cmd) 10315517Snate@binkert.org else: 10327673Snate@binkert.org targets = new_env.Program(exename, objects) 10335517Snate@binkert.org 103410455SCurtis.Dunham@arm.com new_env.M5Binary = targets[0] 10355517Snate@binkert.org envList.append(new_env) 10365517Snate@binkert.org 10378232Snate@binkert.org# Debug binary 103810455SCurtis.Dunham@arm.comccflags = {} 103910455SCurtis.Dunham@arm.comif env['GCC']: 104010455SCurtis.Dunham@arm.com if sys.platform == 'sunos5': 10417673Snate@binkert.org ccflags['debug'] = '-gstabs+' 10427673Snate@binkert.org else: 104310455SCurtis.Dunham@arm.com ccflags['debug'] = '-ggdb3' 104410455SCurtis.Dunham@arm.com ccflags['opt'] = '-g -O3' 104510455SCurtis.Dunham@arm.com ccflags['fast'] = '-O3' 10465517Snate@binkert.org ccflags['prof'] = '-O3 -g -pg' 104710455SCurtis.Dunham@arm.comelif env['SUNCC']: 104810455SCurtis.Dunham@arm.com ccflags['debug'] = '-g0' 104910455SCurtis.Dunham@arm.com ccflags['opt'] = '-g -O' 105010455SCurtis.Dunham@arm.com ccflags['fast'] = '-fast' 105110455SCurtis.Dunham@arm.com ccflags['prof'] = '-fast -g -pg' 105210455SCurtis.Dunham@arm.comelif env['ICC']: 105310455SCurtis.Dunham@arm.com ccflags['debug'] = '-g -O0' 105410455SCurtis.Dunham@arm.com ccflags['opt'] = '-g -O' 105510685Sandreas.hansson@arm.com ccflags['fast'] = '-fast' 105610455SCurtis.Dunham@arm.com ccflags['prof'] = '-fast -g -pg' 105710685Sandreas.hansson@arm.comelse: 105810455SCurtis.Dunham@arm.com print 'Unknown compiler, please fix compiler options' 10595517Snate@binkert.org Exit(1) 106010455SCurtis.Dunham@arm.com 10618232Snate@binkert.orgmakeEnv('debug', '.do', 10628232Snate@binkert.org CCFLAGS = Split(ccflags['debug']), 10635517Snate@binkert.org CPPDEFINES = ['DEBUG', 'TRACING_ON=1']) 10647673Snate@binkert.org 10655517Snate@binkert.org# Optimized binary 10668232Snate@binkert.orgmakeEnv('opt', '.o', 10678232Snate@binkert.org CCFLAGS = Split(ccflags['opt']), 10685517Snate@binkert.org CPPDEFINES = ['TRACING_ON=1']) 10698232Snate@binkert.org 10708232Snate@binkert.org# "Fast" binary 10718232Snate@binkert.orgmakeEnv('fast', '.fo', strip = True, 10727673Snate@binkert.org CCFLAGS = Split(ccflags['fast']), 10735517Snate@binkert.org CPPDEFINES = ['NDEBUG', 'TRACING_ON=0']) 10745517Snate@binkert.org 10757673Snate@binkert.org# Profiled binary 10765517Snate@binkert.orgmakeEnv('prof', '.po', 107710455SCurtis.Dunham@arm.com CCFLAGS = Split(ccflags['prof']), 10785517Snate@binkert.org CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'], 10795517Snate@binkert.org LINKFLAGS = '-pg') 10808232Snate@binkert.org 10818232Snate@binkert.orgReturn('envList') 10825517Snate@binkert.org