SConscript revision 8945
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 bisect 334762Snate@binkert.orgimport imp 345522Snate@binkert.orgimport marshal 35955SN/Aimport os 365522Snate@binkert.orgimport re 37955SN/Aimport sys 385522Snate@binkert.orgimport zlib 394202Sbinkertn@umich.edu 405742Snate@binkert.orgfrom os.path import basename, dirname, exists, isdir, isfile, join as joinpath 41955SN/A 424381Sbinkertn@umich.eduimport SCons 434381Sbinkertn@umich.edu 448334Snate@binkert.org# This file defines how to build a particular configuration of gem5 45955SN/A# based on variable settings in the 'env' build environment. 46955SN/A 474202Sbinkertn@umich.eduImport('*') 48955SN/A 494382Sbinkertn@umich.edu# Children need to see the environment 504382Sbinkertn@umich.eduExport('env') 514382Sbinkertn@umich.edu 526654Snate@binkert.orgbuild_env = [(opt, env[opt]) for opt in export_vars] 535517Snate@binkert.org 548614Sgblack@eecs.umich.edufrom m5.util import code_formatter, compareVersions 557674Snate@binkert.org 566143Snate@binkert.org######################################################################## 576143Snate@binkert.org# Code for adding source files of various types 586143Snate@binkert.org# 598233Snate@binkert.org# When specifying a source file of some type, a set of guards can be 608233Snate@binkert.org# specified for that file. When get() is used to find the files, if 618233Snate@binkert.org# get specifies a set of filters, only files that match those filters 628233Snate@binkert.org# will be accepted (unspecified filters on files are assumed to be 638233Snate@binkert.org# false). Current filters are: 648334Snate@binkert.org# main -- specifies the gem5 main() function 658334Snate@binkert.org# skip_lib -- do not put this file into the gem5 library 6610453SAndrew.Bardsley@arm.com# <unittest> -- unit tests use filters based on the unit test name 6710453SAndrew.Bardsley@arm.com# 688233Snate@binkert.org# A parent can now be specified for a source file and default filter 698233Snate@binkert.org# values will be retrieved recursively from parents (children override 708233Snate@binkert.org# parents). 718233Snate@binkert.org# 728233Snate@binkert.orgclass SourceMeta(type): 738233Snate@binkert.org '''Meta class for source files that keeps track of all files of a 746143Snate@binkert.org particular type and has a get function for finding all functions 758233Snate@binkert.org of a certain type that match a set of guards''' 768233Snate@binkert.org def __init__(cls, name, bases, dict): 778233Snate@binkert.org super(SourceMeta, cls).__init__(name, bases, dict) 786143Snate@binkert.org cls.all = [] 796143Snate@binkert.org 806143Snate@binkert.org def get(cls, **guards): 8111308Santhony.gutierrez@amd.com '''Find all files that match the specified guards. If a source 828233Snate@binkert.org file does not specify a flag, the default is False''' 838233Snate@binkert.org for src in cls.all: 848233Snate@binkert.org for flag,value in guards.iteritems(): 856143Snate@binkert.org # if the flag is found and has a different value, skip 868233Snate@binkert.org # this file 878233Snate@binkert.org if src.all_guards.get(flag, False) != value: 888233Snate@binkert.org break 898233Snate@binkert.org else: 906143Snate@binkert.org yield src 916143Snate@binkert.org 926143Snate@binkert.orgclass SourceFile(object): 934762Snate@binkert.org '''Base object that encapsulates the notion of a source file. 946143Snate@binkert.org This includes, the source node, target node, various manipulations 958233Snate@binkert.org of those. A source file also specifies a set of guards which 968233Snate@binkert.org describing which builds the source file applies to. A parent can 978233Snate@binkert.org also be specified to get default guards from''' 988233Snate@binkert.org __metaclass__ = SourceMeta 998233Snate@binkert.org def __init__(self, source, parent=None, **guards): 1006143Snate@binkert.org self.guards = guards 1018233Snate@binkert.org self.parent = parent 1028233Snate@binkert.org 1038233Snate@binkert.org tnode = source 1048233Snate@binkert.org if not isinstance(source, SCons.Node.FS.File): 1056143Snate@binkert.org tnode = File(source) 1066143Snate@binkert.org 1076143Snate@binkert.org self.tnode = tnode 1086143Snate@binkert.org self.snode = tnode.srcnode() 1096143Snate@binkert.org 1106143Snate@binkert.org for base in type(self).__mro__: 1116143Snate@binkert.org if issubclass(base, SourceFile): 1126143Snate@binkert.org base.all.append(self) 1136143Snate@binkert.org 1147065Snate@binkert.org @property 1156143Snate@binkert.org def filename(self): 1168233Snate@binkert.org return str(self.tnode) 1178233Snate@binkert.org 1188233Snate@binkert.org @property 1198233Snate@binkert.org def dirname(self): 1208233Snate@binkert.org return dirname(self.filename) 1218233Snate@binkert.org 1228233Snate@binkert.org @property 1238233Snate@binkert.org def basename(self): 1248233Snate@binkert.org return basename(self.filename) 1258233Snate@binkert.org 1268233Snate@binkert.org @property 1278233Snate@binkert.org def extname(self): 1288233Snate@binkert.org index = self.basename.rfind('.') 1298233Snate@binkert.org if index <= 0: 1308233Snate@binkert.org # dot files aren't extensions 1318233Snate@binkert.org return self.basename, None 1328233Snate@binkert.org 1338233Snate@binkert.org return self.basename[:index], self.basename[index+1:] 1348233Snate@binkert.org 1358233Snate@binkert.org @property 1368233Snate@binkert.org def all_guards(self): 1378233Snate@binkert.org '''find all guards for this object getting default values 1388233Snate@binkert.org recursively from its parents''' 1398233Snate@binkert.org guards = {} 1408233Snate@binkert.org if self.parent: 1418233Snate@binkert.org guards.update(self.parent.guards) 1428233Snate@binkert.org guards.update(self.guards) 1438233Snate@binkert.org return guards 1448233Snate@binkert.org 1458233Snate@binkert.org def __lt__(self, other): return self.filename < other.filename 1468233Snate@binkert.org def __le__(self, other): return self.filename <= other.filename 1476143Snate@binkert.org def __gt__(self, other): return self.filename > other.filename 1486143Snate@binkert.org def __ge__(self, other): return self.filename >= other.filename 1496143Snate@binkert.org def __eq__(self, other): return self.filename == other.filename 1506143Snate@binkert.org def __ne__(self, other): return self.filename != other.filename 1516143Snate@binkert.org 1526143Snate@binkert.orgclass Source(SourceFile): 1539982Satgutier@umich.edu '''Add a c/c++ source file to the build''' 15410196SCurtis.Dunham@arm.com def __init__(self, source, Werror=True, swig=False, **guards): 15510196SCurtis.Dunham@arm.com '''specify the source file, and any guards''' 15610196SCurtis.Dunham@arm.com super(Source, self).__init__(source, **guards) 15710196SCurtis.Dunham@arm.com 15810196SCurtis.Dunham@arm.com self.Werror = Werror 15910196SCurtis.Dunham@arm.com self.swig = swig 16010196SCurtis.Dunham@arm.com 16110196SCurtis.Dunham@arm.comclass PySource(SourceFile): 1626143Snate@binkert.org '''Add a python source file to the named package''' 1636143Snate@binkert.org invalid_sym_char = re.compile('[^A-z0-9_]') 1648945Ssteve.reinhardt@amd.com modules = {} 1658233Snate@binkert.org tnodes = {} 1668233Snate@binkert.org symnames = {} 1676143Snate@binkert.org 1688945Ssteve.reinhardt@amd.com def __init__(self, package, source, **guards): 1696143Snate@binkert.org '''specify the python package, the source file, and any guards''' 1706143Snate@binkert.org super(PySource, self).__init__(source, **guards) 1716143Snate@binkert.org 1726143Snate@binkert.org modname,ext = self.extname 1735522Snate@binkert.org assert ext == 'py' 1746143Snate@binkert.org 1756143Snate@binkert.org if package: 1766143Snate@binkert.org path = package.split('.') 1779982Satgutier@umich.edu else: 1788233Snate@binkert.org path = [] 1798233Snate@binkert.org 1808233Snate@binkert.org modpath = path[:] 1816143Snate@binkert.org if modname != '__init__': 1826143Snate@binkert.org modpath += [ modname ] 1836143Snate@binkert.org modpath = '.'.join(modpath) 1846143Snate@binkert.org 1855522Snate@binkert.org arcpath = path + [ self.basename ] 1865522Snate@binkert.org abspath = self.snode.abspath 1875522Snate@binkert.org if not exists(abspath): 1885522Snate@binkert.org abspath = self.tnode.abspath 1895604Snate@binkert.org 1905604Snate@binkert.org self.package = package 1916143Snate@binkert.org self.modname = modname 1926143Snate@binkert.org self.modpath = modpath 1934762Snate@binkert.org self.arcname = joinpath(*arcpath) 1944762Snate@binkert.org self.abspath = abspath 1956143Snate@binkert.org self.compiled = File(self.filename + 'c') 1966727Ssteve.reinhardt@amd.com self.cpp = File(self.filename + '.cc') 1976727Ssteve.reinhardt@amd.com self.symname = PySource.invalid_sym_char.sub('_', modpath) 1986727Ssteve.reinhardt@amd.com 1994762Snate@binkert.org PySource.modules[modpath] = self 2006143Snate@binkert.org PySource.tnodes[self.tnode] = self 2016143Snate@binkert.org PySource.symnames[self.symname] = self 2026143Snate@binkert.org 2036143Snate@binkert.orgclass SimObject(PySource): 2046727Ssteve.reinhardt@amd.com '''Add a SimObject python file as a python source object and add 2056143Snate@binkert.org it to a list of sim object modules''' 2067674Snate@binkert.org 2077674Snate@binkert.org fixed = False 2085604Snate@binkert.org modnames = [] 2096143Snate@binkert.org 2106143Snate@binkert.org def __init__(self, source, **guards): 2116143Snate@binkert.org '''Specify the source file and any guards (automatically in 2124762Snate@binkert.org the m5.objects package)''' 2136143Snate@binkert.org super(SimObject, self).__init__('m5.objects', source, **guards) 2144762Snate@binkert.org if self.fixed: 2154762Snate@binkert.org raise AttributeError, "Too late to call SimObject now." 2164762Snate@binkert.org 2176143Snate@binkert.org bisect.insort_right(SimObject.modnames, self.modname) 2186143Snate@binkert.org 2194762Snate@binkert.orgclass SwigSource(SourceFile): 2208233Snate@binkert.org '''Add a swig file to build''' 2218233Snate@binkert.org 2228233Snate@binkert.org def __init__(self, package, source, **guards): 2238233Snate@binkert.org '''Specify the python package, the source file, and any guards''' 2246143Snate@binkert.org super(SwigSource, self).__init__(source, **guards) 2256143Snate@binkert.org 2264762Snate@binkert.org modname,ext = self.extname 2276143Snate@binkert.org assert ext == 'i' 2284762Snate@binkert.org 2296143Snate@binkert.org self.module = modname 2304762Snate@binkert.org cc_file = joinpath(self.dirname, modname + '_wrap.cc') 2316143Snate@binkert.org py_file = joinpath(self.dirname, modname + '.py') 2328233Snate@binkert.org 2338233Snate@binkert.org self.cc_source = Source(cc_file, swig=True, parent=self) 23410453SAndrew.Bardsley@arm.com self.py_source = PySource(package, py_file, parent=self) 2356143Snate@binkert.org 2366143Snate@binkert.orgclass UnitTest(object): 2376143Snate@binkert.org '''Create a UnitTest''' 2386143Snate@binkert.org 23911548Sandreas.hansson@arm.com all = [] 2406143Snate@binkert.org def __init__(self, target, *sources): 2416143Snate@binkert.org '''Specify the target name and any sources. Sources that are 2426143Snate@binkert.org not SourceFiles are evalued with Source(). All files are 2436143Snate@binkert.org guarded with a guard of the same name as the UnitTest 24410453SAndrew.Bardsley@arm.com target.''' 24510453SAndrew.Bardsley@arm.com 246955SN/A srcs = [] 2479396Sandreas.hansson@arm.com for src in sources: 2489396Sandreas.hansson@arm.com if not isinstance(src, SourceFile): 2499396Sandreas.hansson@arm.com src = Source(src, skip_lib=True) 2509396Sandreas.hansson@arm.com src.guards[target] = True 2519396Sandreas.hansson@arm.com srcs.append(src) 2529396Sandreas.hansson@arm.com 2539396Sandreas.hansson@arm.com self.sources = srcs 2549396Sandreas.hansson@arm.com self.target = target 2559396Sandreas.hansson@arm.com UnitTest.all.append(self) 2569396Sandreas.hansson@arm.com 2579396Sandreas.hansson@arm.com# Children should have access 2589396Sandreas.hansson@arm.comExport('Source') 2599396Sandreas.hansson@arm.comExport('PySource') 2609930Sandreas.hansson@arm.comExport('SimObject') 2619930Sandreas.hansson@arm.comExport('SwigSource') 2629396Sandreas.hansson@arm.comExport('UnitTest') 2638235Snate@binkert.org 2648235Snate@binkert.org######################################################################## 2656143Snate@binkert.org# 2668235Snate@binkert.org# Debug Flags 2679003SAli.Saidi@ARM.com# 2688235Snate@binkert.orgdebug_flags = {} 2698235Snate@binkert.orgdef DebugFlag(name, desc=None): 2708235Snate@binkert.org if name in debug_flags: 2718235Snate@binkert.org raise AttributeError, "Flag %s already specified" % name 2728235Snate@binkert.org debug_flags[name] = (name, (), desc) 2738235Snate@binkert.org 2748235Snate@binkert.orgdef CompoundFlag(name, flags, desc=None): 2758235Snate@binkert.org if name in debug_flags: 2768235Snate@binkert.org raise AttributeError, "Flag %s already specified" % name 2778235Snate@binkert.org 2788235Snate@binkert.org compound = tuple(flags) 2798235Snate@binkert.org debug_flags[name] = (name, compound, desc) 2808235Snate@binkert.org 2818235Snate@binkert.orgExport('DebugFlag') 2829003SAli.Saidi@ARM.comExport('CompoundFlag') 2838235Snate@binkert.org 2845584Snate@binkert.org######################################################################## 2854382Sbinkertn@umich.edu# 2864202Sbinkertn@umich.edu# Set some compiler variables 2874382Sbinkertn@umich.edu# 2884382Sbinkertn@umich.edu 2894382Sbinkertn@umich.edu# Include file paths are rooted in this directory. SCons will 2909396Sandreas.hansson@arm.com# automatically expand '.' to refer to both the source directory and 2915584Snate@binkert.org# the corresponding build directory to pick up generated include 2924382Sbinkertn@umich.edu# files. 2934382Sbinkertn@umich.eduenv.Append(CPPPATH=Dir('.')) 2944382Sbinkertn@umich.edu 2958232Snate@binkert.orgfor extra_dir in extras_dir_list: 2965192Ssaidi@eecs.umich.edu env.Append(CPPPATH=Dir(extra_dir)) 2978232Snate@binkert.org 2988232Snate@binkert.org# Workaround for bug in SCons version > 0.97d20071212 2998232Snate@binkert.org# Scons bug id: 2006 gem5 Bug id: 308 3005192Ssaidi@eecs.umich.edufor root, dirs, files in os.walk(base_dir, topdown=True): 3018232Snate@binkert.org Dir(root[len(base_dir) + 1:]) 3025192Ssaidi@eecs.umich.edu 3035799Snate@binkert.org######################################################################## 3048232Snate@binkert.org# 3055192Ssaidi@eecs.umich.edu# Walk the tree and execute all SConscripts in subdirectories 3065192Ssaidi@eecs.umich.edu# 3075192Ssaidi@eecs.umich.edu 3088232Snate@binkert.orghere = Dir('.').srcnode().abspath 3095192Ssaidi@eecs.umich.edufor root, dirs, files in os.walk(base_dir, topdown=True): 3108232Snate@binkert.org if root == here: 3115192Ssaidi@eecs.umich.edu # we don't want to recurse back into this SConscript 3125192Ssaidi@eecs.umich.edu continue 3135192Ssaidi@eecs.umich.edu 3145192Ssaidi@eecs.umich.edu if 'SConscript' in files: 3154382Sbinkertn@umich.edu build_dir = joinpath(env['BUILDDIR'], root[len(base_dir) + 1:]) 3164382Sbinkertn@umich.edu SConscript(joinpath(root, 'SConscript'), variant_dir=build_dir) 3174382Sbinkertn@umich.edu 3182667Sstever@eecs.umich.edufor extra_dir in extras_dir_list: 3192667Sstever@eecs.umich.edu prefix_len = len(dirname(extra_dir)) + 1 3202667Sstever@eecs.umich.edu for root, dirs, files in os.walk(extra_dir, topdown=True): 3212667Sstever@eecs.umich.edu # if build lives in the extras directory, don't walk down it 3222667Sstever@eecs.umich.edu if 'build' in dirs: 3232667Sstever@eecs.umich.edu dirs.remove('build') 3245742Snate@binkert.org 3255742Snate@binkert.org if 'SConscript' in files: 3265742Snate@binkert.org build_dir = joinpath(env['BUILDDIR'], root[prefix_len:]) 3275793Snate@binkert.org SConscript(joinpath(root, 'SConscript'), variant_dir=build_dir) 3288334Snate@binkert.org 3295793Snate@binkert.orgfor opt in export_vars: 3305793Snate@binkert.org env.ConfigFile(opt) 3315793Snate@binkert.org 3324382Sbinkertn@umich.edudef makeTheISA(source, target, env): 3334762Snate@binkert.org isas = [ src.get_contents() for src in source ] 3345344Sstever@gmail.com target_isa = env['TARGET_ISA'] 3354382Sbinkertn@umich.edu def define(isa): 3365341Sstever@gmail.com return isa.upper() + '_ISA' 3375742Snate@binkert.org 3385742Snate@binkert.org def namespace(isa): 3395742Snate@binkert.org return isa[0].upper() + isa[1:].lower() + 'ISA' 3405742Snate@binkert.org 3415742Snate@binkert.org 3424762Snate@binkert.org code = code_formatter() 3435742Snate@binkert.org code('''\ 3445742Snate@binkert.org#ifndef __CONFIG_THE_ISA_HH__ 3457722Sgblack@eecs.umich.edu#define __CONFIG_THE_ISA_HH__ 3465742Snate@binkert.org 3475742Snate@binkert.org''') 3485742Snate@binkert.org 3499930Sandreas.hansson@arm.com for i,isa in enumerate(isas): 3509930Sandreas.hansson@arm.com code('#define $0 $1', define(isa), i + 1) 3519930Sandreas.hansson@arm.com 3529930Sandreas.hansson@arm.com code(''' 3539930Sandreas.hansson@arm.com 3545742Snate@binkert.org#define THE_ISA ${{define(target_isa)}} 3558242Sbradley.danofsky@amd.com#define TheISA ${{namespace(target_isa)}} 3568242Sbradley.danofsky@amd.com 3578242Sbradley.danofsky@amd.com#endif // __CONFIG_THE_ISA_HH__''') 3588242Sbradley.danofsky@amd.com 3595341Sstever@gmail.com code.write(str(target[0])) 3605742Snate@binkert.org 3617722Sgblack@eecs.umich.eduenv.Command('config/the_isa.hh', map(Value, all_isa_list), 3624773Snate@binkert.org MakeAction(makeTheISA, Transform("CFG ISA", 0))) 3636108Snate@binkert.org 3641858SN/A######################################################################## 3651085SN/A# 3666658Snate@binkert.org# Prevent any SimObjects from being added after this point, they 3676658Snate@binkert.org# should all have been added in the SConscripts above 3687673Snate@binkert.org# 3696658Snate@binkert.orgSimObject.fixed = True 3706658Snate@binkert.org 37111308Santhony.gutierrez@amd.comclass DictImporter(object): 3726658Snate@binkert.org '''This importer takes a dictionary of arbitrary module names that 37311308Santhony.gutierrez@amd.com map to arbitrary filenames.''' 3746658Snate@binkert.org def __init__(self, modules): 3756658Snate@binkert.org self.modules = modules 3767673Snate@binkert.org self.installed = set() 3777673Snate@binkert.org 3787673Snate@binkert.org def __del__(self): 3797673Snate@binkert.org self.unload() 3807673Snate@binkert.org 3817673Snate@binkert.org def unload(self): 3827673Snate@binkert.org import sys 38310467Sandreas.hansson@arm.com for module in self.installed: 3846658Snate@binkert.org del sys.modules[module] 3857673Snate@binkert.org self.installed = set() 38610467Sandreas.hansson@arm.com 38710467Sandreas.hansson@arm.com def find_module(self, fullname, path): 38810467Sandreas.hansson@arm.com if fullname == 'm5.defines': 38910467Sandreas.hansson@arm.com return self 39010467Sandreas.hansson@arm.com 39110467Sandreas.hansson@arm.com if fullname == 'm5.objects': 39210467Sandreas.hansson@arm.com return self 39310467Sandreas.hansson@arm.com 39410467Sandreas.hansson@arm.com if fullname.startswith('m5.internal'): 39510467Sandreas.hansson@arm.com return None 39610467Sandreas.hansson@arm.com 3977673Snate@binkert.org source = self.modules.get(fullname, None) 3987673Snate@binkert.org if source is not None and fullname.startswith('m5.objects'): 3997673Snate@binkert.org return self 4007673Snate@binkert.org 4017673Snate@binkert.org return None 4029048SAli.Saidi@ARM.com 4037673Snate@binkert.org def load_module(self, fullname): 4047673Snate@binkert.org mod = imp.new_module(fullname) 4057673Snate@binkert.org sys.modules[fullname] = mod 4067673Snate@binkert.org self.installed.add(fullname) 4076658Snate@binkert.org 4087756SAli.Saidi@ARM.com mod.__loader__ = self 4097816Ssteve.reinhardt@amd.com if fullname == 'm5.objects': 4106658Snate@binkert.org mod.__path__ = fullname.split('.') 41111308Santhony.gutierrez@amd.com return mod 41211308Santhony.gutierrez@amd.com 41311308Santhony.gutierrez@amd.com if fullname == 'm5.defines': 41411308Santhony.gutierrez@amd.com mod.__dict__['buildEnv'] = m5.util.SmartDict(build_env) 41511308Santhony.gutierrez@amd.com return mod 41611308Santhony.gutierrez@amd.com 41711308Santhony.gutierrez@amd.com source = self.modules[fullname] 41811308Santhony.gutierrez@amd.com if source.modname == '__init__': 41911308Santhony.gutierrez@amd.com mod.__path__ = source.modpath 42011308Santhony.gutierrez@amd.com mod.__file__ = source.abspath 42111308Santhony.gutierrez@amd.com 42211308Santhony.gutierrez@amd.com exec file(source.abspath, 'r') in mod.__dict__ 42311308Santhony.gutierrez@amd.com 42411308Santhony.gutierrez@amd.com return mod 42511308Santhony.gutierrez@amd.com 42611308Santhony.gutierrez@amd.comimport m5.SimObject 42711308Santhony.gutierrez@amd.comimport m5.params 42811308Santhony.gutierrez@amd.comfrom m5.util import code_formatter 42911308Santhony.gutierrez@amd.com 43011308Santhony.gutierrez@amd.comm5.SimObject.clear() 43111308Santhony.gutierrez@amd.comm5.params.clear() 43211308Santhony.gutierrez@amd.com 43311308Santhony.gutierrez@amd.com# install the python importer so we can grab stuff from the source 43411308Santhony.gutierrez@amd.com# tree itself. We can't have SimObjects added after this point or 43511308Santhony.gutierrez@amd.com# else we won't know about them for the rest of the stuff. 43611308Santhony.gutierrez@amd.comimporter = DictImporter(PySource.modules) 43711308Santhony.gutierrez@amd.comsys.meta_path[0:0] = [ importer ] 43811308Santhony.gutierrez@amd.com 43911308Santhony.gutierrez@amd.com# import all sim objects so we can populate the all_objects list 44011308Santhony.gutierrez@amd.com# make sure that we're working with a list, then let's sort it 44111308Santhony.gutierrez@amd.comfor modname in SimObject.modnames: 44211308Santhony.gutierrez@amd.com exec('from m5.objects import %s' % modname) 44311308Santhony.gutierrez@amd.com 44411308Santhony.gutierrez@amd.com# we need to unload all of the currently imported modules so that they 44511308Santhony.gutierrez@amd.com# will be re-imported the next time the sconscript is run 44611308Santhony.gutierrez@amd.comimporter.unload() 44711308Santhony.gutierrez@amd.comsys.meta_path.remove(importer) 44811308Santhony.gutierrez@amd.com 44911308Santhony.gutierrez@amd.comsim_objects = m5.SimObject.allClasses 45011308Santhony.gutierrez@amd.comall_enums = m5.params.allEnums 45111308Santhony.gutierrez@amd.com 45211308Santhony.gutierrez@amd.com# Find param types that need to be explicitly wrapped with swig. 45311308Santhony.gutierrez@amd.com# These will be recognized because the ParamDesc will have a 45411308Santhony.gutierrez@amd.com# swig_decl() method. Most param types are based on types that don't 45511308Santhony.gutierrez@amd.com# need this, either because they're based on native types (like Int) 4564382Sbinkertn@umich.edu# or because they're SimObjects (which get swigged independently). 4574382Sbinkertn@umich.edu# For now the only things handled here are VectorParam types. 4584762Snate@binkert.orgparams_to_swig = {} 4594762Snate@binkert.orgfor name,obj in sorted(sim_objects.iteritems()): 4604762Snate@binkert.org for param in obj._params.local.values(): 4616654Snate@binkert.org # load the ptype attribute now because it depends on the 4626654Snate@binkert.org # current version of SimObject.allClasses, but when scons 4635517Snate@binkert.org # actually uses the value, all versions of 4645517Snate@binkert.org # SimObject.allClasses will have been loaded 4655517Snate@binkert.org param.ptype 4665517Snate@binkert.org 4675517Snate@binkert.org if not hasattr(param, 'swig_decl'): 4685517Snate@binkert.org continue 4695517Snate@binkert.org pname = param.ptype_str 4705517Snate@binkert.org if pname not in params_to_swig: 4715517Snate@binkert.org params_to_swig[pname] = param 4725517Snate@binkert.org 4735517Snate@binkert.org######################################################################## 4745517Snate@binkert.org# 4755517Snate@binkert.org# calculate extra dependencies 4765517Snate@binkert.org# 4775517Snate@binkert.orgmodule_depends = ["m5", "m5.SimObject", "m5.params"] 4785517Snate@binkert.orgdepends = [ PySource.modules[dep].snode for dep in module_depends ] 4795517Snate@binkert.org 4806654Snate@binkert.org######################################################################## 4815517Snate@binkert.org# 4825517Snate@binkert.org# Commands for the basic automatically generated python files 4835517Snate@binkert.org# 4845517Snate@binkert.org 4855517Snate@binkert.org# Generate Python file containing a dict specifying the current 4865517Snate@binkert.org# buildEnv flags. 4875517Snate@binkert.orgdef makeDefinesPyFile(target, source, env): 4885517Snate@binkert.org build_env = source[0].get_contents() 4896143Snate@binkert.org 4906654Snate@binkert.org code = code_formatter() 4915517Snate@binkert.org code(""" 4925517Snate@binkert.orgimport m5.internal 4935517Snate@binkert.orgimport m5.util 4945517Snate@binkert.org 4955517Snate@binkert.orgbuildEnv = m5.util.SmartDict($build_env) 4965517Snate@binkert.org 4975517Snate@binkert.orgcompileDate = m5.internal.core.compileDate 4985517Snate@binkert.org_globals = globals() 4995517Snate@binkert.orgfor key,val in m5.internal.core.__dict__.iteritems(): 5005517Snate@binkert.org if key.startswith('flag_'): 5015517Snate@binkert.org flag = key[5:] 5025517Snate@binkert.org _globals[flag] = val 5035517Snate@binkert.orgdel _globals 5045517Snate@binkert.org""") 5056654Snate@binkert.org code.write(target[0].abspath) 5066654Snate@binkert.org 5075517Snate@binkert.orgdefines_info = Value(build_env) 5085517Snate@binkert.org# Generate a file with all of the compile options in it 5096143Snate@binkert.orgenv.Command('python/m5/defines.py', defines_info, 5106143Snate@binkert.org MakeAction(makeDefinesPyFile, Transform("DEFINES", 0))) 5116143Snate@binkert.orgPySource('m5', 'python/m5/defines.py') 5126727Ssteve.reinhardt@amd.com 5135517Snate@binkert.org# Generate python file containing info about the M5 source code 5146727Ssteve.reinhardt@amd.comdef makeInfoPyFile(target, source, env): 5155517Snate@binkert.org code = code_formatter() 5165517Snate@binkert.org for src in source: 5175517Snate@binkert.org data = ''.join(file(src.srcnode().abspath, 'r').xreadlines()) 5186654Snate@binkert.org code('$src = ${{repr(data)}}') 5196654Snate@binkert.org code.write(str(target[0])) 5207673Snate@binkert.org 5216654Snate@binkert.org# Generate a file that wraps the basic top level files 5226654Snate@binkert.orgenv.Command('python/m5/info.py', 5236654Snate@binkert.org [ '#/COPYING', '#/LICENSE', '#/README', ], 5246654Snate@binkert.org MakeAction(makeInfoPyFile, Transform("INFO"))) 5255517Snate@binkert.orgPySource('m5', 'python/m5/info.py') 5265517Snate@binkert.org 5275517Snate@binkert.org######################################################################## 5286143Snate@binkert.org# 5295517Snate@binkert.org# Create all of the SimObject param headers and enum headers 5304762Snate@binkert.org# 5315517Snate@binkert.org 5325517Snate@binkert.orgdef createSimObjectParamStruct(target, source, env): 5336143Snate@binkert.org assert len(target) == 1 and len(source) == 1 5346143Snate@binkert.org 5355517Snate@binkert.org name = str(source[0].get_contents()) 5365517Snate@binkert.org obj = sim_objects[name] 5375517Snate@binkert.org 5385517Snate@binkert.org code = code_formatter() 5395517Snate@binkert.org obj.cxx_param_decl(code) 5405517Snate@binkert.org code.write(target[0].abspath) 5415517Snate@binkert.org 5425517Snate@binkert.orgdef createParamSwigWrapper(target, source, env): 5435517Snate@binkert.org assert len(target) == 1 and len(source) == 1 5449338SAndreas.Sandberg@arm.com 5459338SAndreas.Sandberg@arm.com name = str(source[0].get_contents()) 5469338SAndreas.Sandberg@arm.com param = params_to_swig[name] 5479338SAndreas.Sandberg@arm.com 5489338SAndreas.Sandberg@arm.com code = code_formatter() 5499338SAndreas.Sandberg@arm.com param.swig_decl(code) 5508596Ssteve.reinhardt@amd.com code.write(target[0].abspath) 5518596Ssteve.reinhardt@amd.com 5528596Ssteve.reinhardt@amd.comdef createEnumStrings(target, source, env): 5538596Ssteve.reinhardt@amd.com assert len(target) == 1 and len(source) == 1 5548596Ssteve.reinhardt@amd.com 5558596Ssteve.reinhardt@amd.com name = str(source[0].get_contents()) 5568596Ssteve.reinhardt@amd.com obj = all_enums[name] 5576143Snate@binkert.org 5585517Snate@binkert.org code = code_formatter() 5596654Snate@binkert.org obj.cxx_def(code) 5606654Snate@binkert.org code.write(target[0].abspath) 5616654Snate@binkert.org 5626654Snate@binkert.orgdef createEnumDecls(target, source, env): 5636654Snate@binkert.org assert len(target) == 1 and len(source) == 1 5646654Snate@binkert.org 5655517Snate@binkert.org name = str(source[0].get_contents()) 5665517Snate@binkert.org obj = all_enums[name] 5675517Snate@binkert.org 5688596Ssteve.reinhardt@amd.com code = code_formatter() 5698596Ssteve.reinhardt@amd.com obj.cxx_decl(code) 5704762Snate@binkert.org code.write(target[0].abspath) 5714762Snate@binkert.org 5724762Snate@binkert.orgdef createEnumSwigWrapper(target, source, env): 5734762Snate@binkert.org assert len(target) == 1 and len(source) == 1 5744762Snate@binkert.org 5754762Snate@binkert.org name = str(source[0].get_contents()) 5767675Snate@binkert.org obj = all_enums[name] 57710584Sandreas.hansson@arm.com 5784762Snate@binkert.org code = code_formatter() 5794762Snate@binkert.org obj.swig_decl(code) 5804762Snate@binkert.org code.write(target[0].abspath) 5814762Snate@binkert.org 5824382Sbinkertn@umich.edudef createSimObjectSwigWrapper(target, source, env): 5834382Sbinkertn@umich.edu name = source[0].get_contents() 5845517Snate@binkert.org obj = sim_objects[name] 5856654Snate@binkert.org 5865517Snate@binkert.org code = code_formatter() 5878126Sgblack@eecs.umich.edu obj.swig_decl(code) 5886654Snate@binkert.org code.write(target[0].abspath) 5897673Snate@binkert.org 5906654Snate@binkert.org# Generate all of the SimObject param C++ struct header files 5916654Snate@binkert.orgparams_hh_files = [] 5926654Snate@binkert.orgfor name,simobj in sorted(sim_objects.iteritems()): 5936654Snate@binkert.org py_source = PySource.modules[simobj.__module__] 5946654Snate@binkert.org extra_deps = [ py_source.tnode ] 5956654Snate@binkert.org 5966654Snate@binkert.org hh_file = File('params/%s.hh' % name) 5976669Snate@binkert.org params_hh_files.append(hh_file) 5986669Snate@binkert.org env.Command(hh_file, Value(name), 5996669Snate@binkert.org MakeAction(createSimObjectParamStruct, Transform("SO PARAM"))) 6006669Snate@binkert.org env.Depends(hh_file, depends + extra_deps) 6016669Snate@binkert.org 6026669Snate@binkert.org# Generate any needed param SWIG wrapper files 6036654Snate@binkert.orgparams_i_files = [] 6047673Snate@binkert.orgfor name,param in params_to_swig.iteritems(): 6055517Snate@binkert.org i_file = File('python/m5/internal/%s.i' % (param.swig_module_name())) 6068126Sgblack@eecs.umich.edu params_i_files.append(i_file) 6075798Snate@binkert.org env.Command(i_file, Value(name), 6087756SAli.Saidi@ARM.com MakeAction(createParamSwigWrapper, Transform("SW PARAM"))) 6097816Ssteve.reinhardt@amd.com env.Depends(i_file, depends) 6105798Snate@binkert.org SwigSource('m5.internal', i_file) 6115798Snate@binkert.org 6125517Snate@binkert.org# Generate all enum header files 6135517Snate@binkert.orgfor name,enum in sorted(all_enums.iteritems()): 6147673Snate@binkert.org py_source = PySource.modules[enum.__module__] 6155517Snate@binkert.org extra_deps = [ py_source.tnode ] 6165517Snate@binkert.org 6177673Snate@binkert.org cc_file = File('enums/%s.cc' % name) 6187673Snate@binkert.org env.Command(cc_file, Value(name), 6195517Snate@binkert.org MakeAction(createEnumStrings, Transform("ENUM STR"))) 6205798Snate@binkert.org env.Depends(cc_file, depends + extra_deps) 6215798Snate@binkert.org Source(cc_file) 6228333Snate@binkert.org 6237816Ssteve.reinhardt@amd.com hh_file = File('enums/%s.hh' % name) 6245798Snate@binkert.org env.Command(hh_file, Value(name), 6255798Snate@binkert.org MakeAction(createEnumDecls, Transform("ENUMDECL"))) 6264762Snate@binkert.org env.Depends(hh_file, depends + extra_deps) 6274762Snate@binkert.org 6284762Snate@binkert.org i_file = File('python/m5/internal/enum_%s.i' % name) 6294762Snate@binkert.org env.Command(i_file, Value(name), 6304762Snate@binkert.org MakeAction(createEnumSwigWrapper, Transform("ENUMSWIG"))) 6318596Ssteve.reinhardt@amd.com env.Depends(i_file, depends + extra_deps) 6325517Snate@binkert.org SwigSource('m5.internal', i_file) 6335517Snate@binkert.org 6345517Snate@binkert.org# Generate SimObject SWIG wrapper files 6355517Snate@binkert.orgfor name in sim_objects.iterkeys(): 6365517Snate@binkert.org i_file = File('python/m5/internal/param_%s.i' % name) 6377673Snate@binkert.org env.Command(i_file, Value(name), 6388596Ssteve.reinhardt@amd.com MakeAction(createSimObjectSwigWrapper, Transform("SO SWIG"))) 6397673Snate@binkert.org env.Depends(i_file, depends) 6405517Snate@binkert.org SwigSource('m5.internal', i_file) 64110458Sandreas.hansson@arm.com 64210458Sandreas.hansson@arm.com# Generate the main swig init file 64310458Sandreas.hansson@arm.comdef makeEmbeddedSwigInit(target, source, env): 64410458Sandreas.hansson@arm.com code = code_formatter() 64510458Sandreas.hansson@arm.com module = source[0].get_contents() 64610458Sandreas.hansson@arm.com code('''\ 64710458Sandreas.hansson@arm.com#include "sim/init.hh" 64810458Sandreas.hansson@arm.com 64910458Sandreas.hansson@arm.comextern "C" { 65010458Sandreas.hansson@arm.com void init_${module}(); 65110458Sandreas.hansson@arm.com} 65210458Sandreas.hansson@arm.com 6538596Ssteve.reinhardt@amd.comEmbeddedSwig embed_swig_${module}(init_${module}); 6545517Snate@binkert.org''') 6555517Snate@binkert.org code.write(str(target[0])) 6565517Snate@binkert.org 6578596Ssteve.reinhardt@amd.com# Build all swig modules 6585517Snate@binkert.orgfor swig in SwigSource.all: 6597673Snate@binkert.org env.Command([swig.cc_source.tnode, swig.py_source.tnode], swig.tnode, 6607673Snate@binkert.org MakeAction('$SWIG $SWIGFLAGS -outdir ${TARGETS[1].dir} ' 6617673Snate@binkert.org '-o ${TARGETS[0]} $SOURCES', Transform("SWIG"))) 6625517Snate@binkert.org cc_file = str(swig.tnode) 6635517Snate@binkert.org init_file = '%s/%s_init.cc' % (dirname(cc_file), basename(cc_file)) 6645517Snate@binkert.org env.Command(init_file, Value(swig.module), 6655517Snate@binkert.org MakeAction(makeEmbeddedSwigInit, Transform("EMBED SW"))) 6665517Snate@binkert.org Source(init_file, **swig.guards) 6675517Snate@binkert.org 6685517Snate@binkert.org# 6697673Snate@binkert.org# Handle debug flags 6707673Snate@binkert.org# 6717673Snate@binkert.orgdef makeDebugFlagCC(target, source, env): 6725517Snate@binkert.org assert(len(target) == 1 and len(source) == 1) 6738596Ssteve.reinhardt@amd.com 6745517Snate@binkert.org val = eval(source[0].get_contents()) 6755517Snate@binkert.org name, compound, desc = val 6765517Snate@binkert.org compound = list(sorted(compound)) 6775517Snate@binkert.org 6785517Snate@binkert.org code = code_formatter() 6797673Snate@binkert.org 6807673Snate@binkert.org # file header 6817673Snate@binkert.org code(''' 6825517Snate@binkert.org/* 6838596Ssteve.reinhardt@amd.com * DO NOT EDIT THIS FILE! Automatically generated 6847675Snate@binkert.org */ 6857675Snate@binkert.org 6867675Snate@binkert.org#include "base/debug.hh" 6877675Snate@binkert.org''') 6887675Snate@binkert.org 6897675Snate@binkert.org for flag in compound: 6908596Ssteve.reinhardt@amd.com code('#include "debug/$flag.hh"') 6917675Snate@binkert.org code() 6927675Snate@binkert.org code('namespace Debug {') 6938596Ssteve.reinhardt@amd.com code() 6948596Ssteve.reinhardt@amd.com 6958596Ssteve.reinhardt@amd.com if not compound: 6968596Ssteve.reinhardt@amd.com code('SimpleFlag $name("$name", "$desc");') 6978596Ssteve.reinhardt@amd.com else: 6988596Ssteve.reinhardt@amd.com code('CompoundFlag $name("$name", "$desc",') 6998596Ssteve.reinhardt@amd.com code.indent() 7008596Ssteve.reinhardt@amd.com last = len(compound) - 1 70110454SCurtis.Dunham@arm.com for i,flag in enumerate(compound): 70210454SCurtis.Dunham@arm.com if i != last: 70310454SCurtis.Dunham@arm.com code('$flag,') 70410454SCurtis.Dunham@arm.com else: 7058596Ssteve.reinhardt@amd.com code('$flag);') 7064762Snate@binkert.org code.dedent() 7076143Snate@binkert.org 7086143Snate@binkert.org code() 7096143Snate@binkert.org code('} // namespace Debug') 7104762Snate@binkert.org 7114762Snate@binkert.org code.write(str(target[0])) 7124762Snate@binkert.org 7137756SAli.Saidi@ARM.comdef makeDebugFlagHH(target, source, env): 7148596Ssteve.reinhardt@amd.com assert(len(target) == 1 and len(source) == 1) 7154762Snate@binkert.org 71610454SCurtis.Dunham@arm.com val = eval(source[0].get_contents()) 7174762Snate@binkert.org name, compound, desc = val 71810458Sandreas.hansson@arm.com 71910458Sandreas.hansson@arm.com code = code_formatter() 72010458Sandreas.hansson@arm.com 72110458Sandreas.hansson@arm.com # file header boilerplate 72210458Sandreas.hansson@arm.com code('''\ 72310458Sandreas.hansson@arm.com/* 72410458Sandreas.hansson@arm.com * DO NOT EDIT THIS FILE! 72510458Sandreas.hansson@arm.com * 72610458Sandreas.hansson@arm.com * Automatically generated by SCons 72710458Sandreas.hansson@arm.com */ 72810458Sandreas.hansson@arm.com 72910458Sandreas.hansson@arm.com#ifndef __DEBUG_${name}_HH__ 73010458Sandreas.hansson@arm.com#define __DEBUG_${name}_HH__ 73110458Sandreas.hansson@arm.com 73210458Sandreas.hansson@arm.comnamespace Debug { 73310458Sandreas.hansson@arm.com''') 73410458Sandreas.hansson@arm.com 73510458Sandreas.hansson@arm.com if compound: 73610458Sandreas.hansson@arm.com code('class CompoundFlag;') 73710458Sandreas.hansson@arm.com code('class SimpleFlag;') 73810458Sandreas.hansson@arm.com 73910458Sandreas.hansson@arm.com if compound: 74010458Sandreas.hansson@arm.com code('extern CompoundFlag $name;') 74110458Sandreas.hansson@arm.com for flag in compound: 74210458Sandreas.hansson@arm.com code('extern SimpleFlag $flag;') 74310458Sandreas.hansson@arm.com else: 74410458Sandreas.hansson@arm.com code('extern SimpleFlag $name;') 74510458Sandreas.hansson@arm.com 74610458Sandreas.hansson@arm.com code(''' 74710458Sandreas.hansson@arm.com} 74810458Sandreas.hansson@arm.com 74910458Sandreas.hansson@arm.com#endif // __DEBUG_${name}_HH__ 75010458Sandreas.hansson@arm.com''') 75110458Sandreas.hansson@arm.com 75210458Sandreas.hansson@arm.com code.write(str(target[0])) 75310458Sandreas.hansson@arm.com 75410458Sandreas.hansson@arm.comfor name,flag in sorted(debug_flags.iteritems()): 75510458Sandreas.hansson@arm.com n, compound, desc = flag 75610458Sandreas.hansson@arm.com assert n == name 75710458Sandreas.hansson@arm.com 75810458Sandreas.hansson@arm.com env.Command('debug/%s.hh' % name, Value(flag), 75910458Sandreas.hansson@arm.com MakeAction(makeDebugFlagHH, Transform("TRACING", 0))) 76010458Sandreas.hansson@arm.com env.Command('debug/%s.cc' % name, Value(flag), 76110458Sandreas.hansson@arm.com MakeAction(makeDebugFlagCC, Transform("TRACING", 0))) 76210458Sandreas.hansson@arm.com Source('debug/%s.cc' % name) 76310458Sandreas.hansson@arm.com 76410458Sandreas.hansson@arm.com# Embed python files. All .py files that have been indicated by a 76510458Sandreas.hansson@arm.com# PySource() call in a SConscript need to be embedded into the M5 76610458Sandreas.hansson@arm.com# library. To do that, we compile the file to byte code, marshal the 76710584Sandreas.hansson@arm.com# byte code, compress it, and then generate a c++ file that 76810458Sandreas.hansson@arm.com# inserts the result into an array. 76910458Sandreas.hansson@arm.comdef embedPyFile(target, source, env): 77010458Sandreas.hansson@arm.com def c_str(string): 77110458Sandreas.hansson@arm.com if string is None: 77210458Sandreas.hansson@arm.com return "0" 7738596Ssteve.reinhardt@amd.com return '"%s"' % string 7745463Snate@binkert.org 77510584Sandreas.hansson@arm.com '''Action function to compile a .py into a code object, marshal 7768596Ssteve.reinhardt@amd.com it, compress it, and stick it into an asm file so the code appears 7775463Snate@binkert.org as just bytes with a label in the data section''' 7787756SAli.Saidi@ARM.com 7798596Ssteve.reinhardt@amd.com src = file(str(source[0]), 'r').read() 7804762Snate@binkert.org 78110454SCurtis.Dunham@arm.com pysource = PySource.tnodes[source[0]] 7827677Snate@binkert.org compiled = compile(src, pysource.abspath, 'exec') 7834762Snate@binkert.org marshalled = marshal.dumps(compiled) 7844762Snate@binkert.org compressed = zlib.compress(marshalled) 7856143Snate@binkert.org data = compressed 7866143Snate@binkert.org sym = pysource.symname 7876143Snate@binkert.org 7884762Snate@binkert.org code = code_formatter() 7894762Snate@binkert.org code('''\ 7907756SAli.Saidi@ARM.com#include "sim/init.hh" 7917816Ssteve.reinhardt@amd.com 7924762Snate@binkert.orgnamespace { 79310454SCurtis.Dunham@arm.com 7944762Snate@binkert.orgconst char data_${sym}[] = { 7954762Snate@binkert.org''') 7964762Snate@binkert.org code.indent() 7977756SAli.Saidi@ARM.com step = 16 7988596Ssteve.reinhardt@amd.com for i in xrange(0, len(data), step): 7994762Snate@binkert.org x = array.array('B', data[i:i+step]) 80010454SCurtis.Dunham@arm.com code(''.join('%d,' % d for d in x)) 8014762Snate@binkert.org code.dedent() 8027677Snate@binkert.org 8037756SAli.Saidi@ARM.com code('''}; 8048596Ssteve.reinhardt@amd.com 8057675Snate@binkert.orgEmbeddedPython embedded_${sym}( 80610454SCurtis.Dunham@arm.com ${{c_str(pysource.arcname)}}, 8077677Snate@binkert.org ${{c_str(pysource.abspath)}}, 8085517Snate@binkert.org ${{c_str(pysource.modpath)}}, 8098596Ssteve.reinhardt@amd.com data_${sym}, 81010584Sandreas.hansson@arm.com ${{len(data)}}, 8119248SAndreas.Sandberg@arm.com ${{len(marshalled)}}); 8129248SAndreas.Sandberg@arm.com 8138596Ssteve.reinhardt@amd.com} // anonymous namespace 8148596Ssteve.reinhardt@amd.com''') 8158596Ssteve.reinhardt@amd.com code.write(str(target[0])) 8169248SAndreas.Sandberg@arm.com 8178596Ssteve.reinhardt@amd.comfor source in PySource.all: 8184762Snate@binkert.org env.Command(source.cpp, source.tnode, 8197674Snate@binkert.org MakeAction(embedPyFile, Transform("EMBED PY"))) 82011548Sandreas.hansson@arm.com Source(source.cpp) 82111548Sandreas.hansson@arm.com 82211548Sandreas.hansson@arm.com######################################################################## 8237674Snate@binkert.org# 82411548Sandreas.hansson@arm.com# Define binaries. Each different build type (debug, opt, etc.) gets 82511548Sandreas.hansson@arm.com# a slightly different build environment. 82611548Sandreas.hansson@arm.com# 82711548Sandreas.hansson@arm.com 82811548Sandreas.hansson@arm.com# List of constructed environments to pass back to SConstruct 82911548Sandreas.hansson@arm.comenvList = [] 83011548Sandreas.hansson@arm.com 83111548Sandreas.hansson@arm.comdate_source = Source('base/date.cc', skip_lib=True) 8327674Snate@binkert.org 83311548Sandreas.hansson@arm.com# Function to create a new build environment as clone of current 83411548Sandreas.hansson@arm.com# environment 'env' with modified object suffix and optional stripped 83511548Sandreas.hansson@arm.com# binary. Additional keyword arguments are appended to corresponding 83611548Sandreas.hansson@arm.com# build environment vars. 83711548Sandreas.hansson@arm.comdef makeEnv(label, objsfx, strip = False, **kwargs): 83811548Sandreas.hansson@arm.com # SCons doesn't know to append a library suffix when there is a '.' in the 83911548Sandreas.hansson@arm.com # name. Use '_' instead. 84011548Sandreas.hansson@arm.com libname = 'gem5_' + label 84111308Santhony.gutierrez@amd.com exename = 'gem5.' + label 8424762Snate@binkert.org secondary_exename = 'm5.' + label 8436143Snate@binkert.org 8446143Snate@binkert.org new_env = env.Clone(OBJSUFFIX=objsfx, SHOBJSUFFIX=objsfx + 's') 8457756SAli.Saidi@ARM.com new_env.Label = label 8467816Ssteve.reinhardt@amd.com new_env.Append(**kwargs) 8478235Snate@binkert.org 8488596Ssteve.reinhardt@amd.com swig_env = new_env.Clone() 8497756SAli.Saidi@ARM.com swig_env.Append(CCFLAGS='-Werror') 85011548Sandreas.hansson@arm.com if env['GCC']: 85111548Sandreas.hansson@arm.com swig_env.Append(CCFLAGS='-Wno-uninitialized') 85210454SCurtis.Dunham@arm.com swig_env.Append(CCFLAGS='-Wno-sign-compare') 8538235Snate@binkert.org swig_env.Append(CCFLAGS='-Wno-parentheses') 8544382Sbinkertn@umich.edu swig_env.Append(CCFLAGS='-Wno-unused-label') 8559396Sandreas.hansson@arm.com if compareVersions(env['GCC_VERSION'], '4.6.0') != -1: 8569396Sandreas.hansson@arm.com swig_env.Append(CCFLAGS='-Wno-unused-but-set-variable') 8579396Sandreas.hansson@arm.com if env['CLANG']: 8589396Sandreas.hansson@arm.com swig_env.Append(CCFLAGS=['-Wno-unused-label']) 8599396Sandreas.hansson@arm.com 8609396Sandreas.hansson@arm.com 8619396Sandreas.hansson@arm.com werror_env = new_env.Clone() 8629396Sandreas.hansson@arm.com werror_env.Append(CCFLAGS='-Werror') 8639396Sandreas.hansson@arm.com 8649396Sandreas.hansson@arm.com def make_obj(source, static, extra_deps = None): 8659396Sandreas.hansson@arm.com '''This function adds the specified source to the correct 8669396Sandreas.hansson@arm.com build environment, and returns the corresponding SCons Object 86710454SCurtis.Dunham@arm.com nodes''' 8689396Sandreas.hansson@arm.com 8699396Sandreas.hansson@arm.com if source.swig: 8709396Sandreas.hansson@arm.com env = swig_env 8719396Sandreas.hansson@arm.com elif source.Werror: 8729396Sandreas.hansson@arm.com env = werror_env 8739396Sandreas.hansson@arm.com else: 8748232Snate@binkert.org env = new_env 8758232Snate@binkert.org 8768232Snate@binkert.org if static: 8778232Snate@binkert.org obj = env.StaticObject(source.tnode) 8788232Snate@binkert.org else: 8796229Snate@binkert.org obj = env.SharedObject(source.tnode) 88010455SCurtis.Dunham@arm.com 8816229Snate@binkert.org if extra_deps: 88210455SCurtis.Dunham@arm.com env.Depends(obj, extra_deps) 88310455SCurtis.Dunham@arm.com 88410455SCurtis.Dunham@arm.com return obj 8855517Snate@binkert.org 8865517Snate@binkert.org static_objs = \ 8877673Snate@binkert.org [ make_obj(s, True) for s in Source.get(main=False, skip_lib=False) ] 8885517Snate@binkert.org shared_objs = \ 88910455SCurtis.Dunham@arm.com [ make_obj(s, False) for s in Source.get(main=False, skip_lib=False) ] 8905517Snate@binkert.org 8915517Snate@binkert.org static_date = make_obj(date_source, static=True, extra_deps=static_objs) 8928232Snate@binkert.org static_objs.append(static_date) 89310455SCurtis.Dunham@arm.com 89410455SCurtis.Dunham@arm.com shared_date = make_obj(date_source, static=False, extra_deps=shared_objs) 89510455SCurtis.Dunham@arm.com shared_objs.append(shared_date) 8967673Snate@binkert.org 8977673Snate@binkert.org # First make a library of everything but main() so other programs can 89810455SCurtis.Dunham@arm.com # link against m5. 89910455SCurtis.Dunham@arm.com static_lib = new_env.StaticLibrary(libname, static_objs) 90010455SCurtis.Dunham@arm.com shared_lib = new_env.SharedLibrary(libname, shared_objs) 9015517Snate@binkert.org 90210455SCurtis.Dunham@arm.com # Now link a stub with main() and the static library. 90310455SCurtis.Dunham@arm.com main_objs = [ make_obj(s, True) for s in Source.get(main=True) ] 90410455SCurtis.Dunham@arm.com 90510455SCurtis.Dunham@arm.com for test in UnitTest.all: 90610455SCurtis.Dunham@arm.com flags = { test.target : True } 90710455SCurtis.Dunham@arm.com test_sources = Source.get(**flags) 90810455SCurtis.Dunham@arm.com test_objs = [ make_obj(s, static=True) for s in test_sources ] 90910455SCurtis.Dunham@arm.com testname = "unittest/%s.%s" % (test.target, label) 91010685Sandreas.hansson@arm.com new_env.Program(testname, test_objs + static_objs) 91110455SCurtis.Dunham@arm.com 91210685Sandreas.hansson@arm.com progname = exename 91310455SCurtis.Dunham@arm.com if strip: 9145517Snate@binkert.org progname += '.unstripped' 91510455SCurtis.Dunham@arm.com 9168232Snate@binkert.org targets = new_env.Program(progname, main_objs + static_objs) 9178232Snate@binkert.org 9185517Snate@binkert.org if strip: 9197673Snate@binkert.org if sys.platform == 'sunos5': 9205517Snate@binkert.org cmd = 'cp $SOURCE $TARGET; strip $TARGET' 9218232Snate@binkert.org else: 9228232Snate@binkert.org cmd = 'strip $SOURCE -o $TARGET' 9235517Snate@binkert.org targets = new_env.Command(exename, progname, 9248232Snate@binkert.org MakeAction(cmd, Transform("STRIP"))) 9258232Snate@binkert.org 9268232Snate@binkert.org new_env.Command(secondary_exename, exename, 9277673Snate@binkert.org MakeAction('ln $SOURCE $TARGET', Transform("HARDLINK"))) 9285517Snate@binkert.org 9295517Snate@binkert.org new_env.M5Binary = targets[0] 9307673Snate@binkert.org envList.append(new_env) 9315517Snate@binkert.org 93210455SCurtis.Dunham@arm.com# Debug binary 9335517Snate@binkert.orgccflags = {} 9345517Snate@binkert.orgif env['GCC'] or env['CLANG']: 9358232Snate@binkert.org if sys.platform == 'sunos5': 9368232Snate@binkert.org ccflags['debug'] = '-gstabs+' 9375517Snate@binkert.org else: 9388232Snate@binkert.org ccflags['debug'] = '-ggdb3' 9398232Snate@binkert.org ccflags['opt'] = '-g -O3' 9405517Snate@binkert.org ccflags['fast'] = '-O3' 9418232Snate@binkert.org ccflags['prof'] = '-O3 -g -pg' 9428232Snate@binkert.orgelif env['SUNCC']: 9438232Snate@binkert.org ccflags['debug'] = '-g0' 9445517Snate@binkert.org ccflags['opt'] = '-g -O' 9458232Snate@binkert.org ccflags['fast'] = '-fast' 9468232Snate@binkert.org ccflags['prof'] = '-fast -g -pg' 9478232Snate@binkert.orgelif env['ICC']: 9488232Snate@binkert.org ccflags['debug'] = '-g -O0' 9498232Snate@binkert.org ccflags['opt'] = '-g -O' 9508232Snate@binkert.org ccflags['fast'] = '-fast' 9515517Snate@binkert.org ccflags['prof'] = '-fast -g -pg' 9528232Snate@binkert.orgelse: 9538232Snate@binkert.org print 'Unknown compiler, please fix compiler options' 9545517Snate@binkert.org Exit(1) 9558232Snate@binkert.org 9567673Snate@binkert.org 9575517Snate@binkert.org# To speed things up, we only instantiate the build environments we 9587673Snate@binkert.org# need. We try to identify the needed environment for each target; if 9595517Snate@binkert.org# we can't, we fall back on instantiating all the environments just to 9608232Snate@binkert.org# be safe. 9618232Snate@binkert.orgtarget_types = ['debug', 'opt', 'fast', 'prof'] 9628232Snate@binkert.orgobj2target = {'do': 'debug', 'o': 'opt', 'fo': 'fast', 'po': 'prof'} 9635192Ssaidi@eecs.umich.edu 96410454SCurtis.Dunham@arm.comdef identifyTarget(t): 96510454SCurtis.Dunham@arm.com ext = t.split('.')[-1] 9668232Snate@binkert.org if ext in target_types: 96710455SCurtis.Dunham@arm.com return ext 96810455SCurtis.Dunham@arm.com if obj2target.has_key(ext): 96910455SCurtis.Dunham@arm.com return obj2target[ext] 97010455SCurtis.Dunham@arm.com match = re.search(r'/tests/([^/]+)/', t) 97110455SCurtis.Dunham@arm.com if match and match.group(1) in target_types: 97210455SCurtis.Dunham@arm.com return match.group(1) 9735192Ssaidi@eecs.umich.edu return 'all' 97411077SCurtis.Dunham@arm.com 97511330SCurtis.Dunham@arm.comneeded_envs = [identifyTarget(target) for target in BUILD_TARGETS] 97611077SCurtis.Dunham@arm.comif 'all' in needed_envs: 97711077SCurtis.Dunham@arm.com needed_envs += target_types 97811077SCurtis.Dunham@arm.com 97911330SCurtis.Dunham@arm.com# Debug binary 98011077SCurtis.Dunham@arm.comif 'debug' in needed_envs: 9817674Snate@binkert.org makeEnv('debug', '.do', 9825522Snate@binkert.org CCFLAGS = Split(ccflags['debug']), 9835522Snate@binkert.org CPPDEFINES = ['DEBUG', 'TRACING_ON=1']) 9847674Snate@binkert.org 9857674Snate@binkert.org# Optimized binary 9867674Snate@binkert.orgif 'opt' in needed_envs: 9877674Snate@binkert.org makeEnv('opt', '.o', 9887674Snate@binkert.org CCFLAGS = Split(ccflags['opt']), 9897674Snate@binkert.org CPPDEFINES = ['TRACING_ON=1']) 9907674Snate@binkert.org 9917674Snate@binkert.org# "Fast" binary 9925522Snate@binkert.orgif 'fast' in needed_envs: 9935522Snate@binkert.org makeEnv('fast', '.fo', strip = True, 9945522Snate@binkert.org CCFLAGS = Split(ccflags['fast']), 9955517Snate@binkert.org CPPDEFINES = ['NDEBUG', 'TRACING_ON=0']) 9965522Snate@binkert.org 9975517Snate@binkert.org# Profiled binary 9986143Snate@binkert.orgif 'prof' in needed_envs: 9996727Ssteve.reinhardt@amd.com makeEnv('prof', '.po', 10005522Snate@binkert.org CCFLAGS = Split(ccflags['prof']), 10015522Snate@binkert.org CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'], 10025522Snate@binkert.org LINKFLAGS = '-pg') 10037674Snate@binkert.org 10045517Snate@binkert.orgReturn('envList') 10057673Snate@binkert.org