SConscript revision 12305
1955SN/A# -*- mode:python -*- 2955SN/A 310841Sandreas.sandberg@arm.com# Copyright (c) 2004-2005 The Regents of The University of Michigan 49812Sandreas.hansson@arm.com# All rights reserved. 59812Sandreas.hansson@arm.com# 69812Sandreas.hansson@arm.com# Redistribution and use in source and binary forms, with or without 79812Sandreas.hansson@arm.com# modification, are permitted provided that the following conditions are 89812Sandreas.hansson@arm.com# met: redistributions of source code must retain the above copyright 99812Sandreas.hansson@arm.com# notice, this list of conditions and the following disclaimer; 109812Sandreas.hansson@arm.com# redistributions in binary form must reproduce the above copyright 119812Sandreas.hansson@arm.com# notice, this list of conditions and the following disclaimer in the 129812Sandreas.hansson@arm.com# documentation and/or other materials provided with the distribution; 139812Sandreas.hansson@arm.com# neither the name of the copyright holders nor the names of its 149812Sandreas.hansson@arm.com# contributors may be used to endorse or promote products derived from 157816Ssteve.reinhardt@amd.com# this software without specific prior written permission. 165871Snate@binkert.org# 171762SN/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 bisect 33955SN/Aimport imp 34955SN/Aimport marshal 35955SN/Aimport os 36955SN/Aimport re 37955SN/Aimport subprocess 38955SN/Aimport sys 39955SN/Aimport zlib 40955SN/A 41955SN/Afrom os.path import basename, dirname, exists, isdir, isfile, join as joinpath 422665Ssaidi@eecs.umich.edu 432665Ssaidi@eecs.umich.eduimport SCons 445863Snate@binkert.org 45955SN/Afrom gem5_scons import Transform 46955SN/A 47955SN/A# This file defines how to build a particular configuration of gem5 48955SN/A# based on variable settings in the 'env' build environment. 49955SN/A 508878Ssteve.reinhardt@amd.comImport('*') 512632Sstever@eecs.umich.edu 528878Ssteve.reinhardt@amd.com# Children need to see the environment 532632Sstever@eecs.umich.eduExport('env') 54955SN/A 558878Ssteve.reinhardt@amd.combuild_env = [(opt, env[opt]) for opt in export_vars] 562632Sstever@eecs.umich.edu 572761Sstever@eecs.umich.edufrom m5.util import code_formatter, compareVersions 582632Sstever@eecs.umich.edu 592632Sstever@eecs.umich.edu######################################################################## 602632Sstever@eecs.umich.edu# Code for adding source files of various types 612761Sstever@eecs.umich.edu# 622761Sstever@eecs.umich.edu# When specifying a source file of some type, a set of tags can be 632761Sstever@eecs.umich.edu# specified for that file. 648878Ssteve.reinhardt@amd.com 658878Ssteve.reinhardt@amd.comclass SourceList(list): 662761Sstever@eecs.umich.edu def with_tags_that(self, predicate): 672761Sstever@eecs.umich.edu '''Return a list of sources with tags that satisfy a predicate.''' 682761Sstever@eecs.umich.edu def match(source): 692761Sstever@eecs.umich.edu return predicate(source.tags) 702761Sstever@eecs.umich.edu return SourceList(filter(match, self)) 718878Ssteve.reinhardt@amd.com 728878Ssteve.reinhardt@amd.com def with_any_tags(self, *tags): 732632Sstever@eecs.umich.edu '''Return a list of sources with any of the supplied tags.''' 742632Sstever@eecs.umich.edu return self.with_tags_that(lambda stags: len(tags & stags) > 0) 758878Ssteve.reinhardt@amd.com 768878Ssteve.reinhardt@amd.com def with_all_tags(self, *tags): 772632Sstever@eecs.umich.edu '''Return a list of sources with all of the supplied tags.''' 78955SN/A return self.with_tags_that(lambda stags: tags <= stags) 79955SN/A 80955SN/A def with_tag(self, tag): 815863Snate@binkert.org '''Return a list of sources with the supplied tag.''' 825863Snate@binkert.org return self.with_tags_that(lambda stags: tag in stags) 835863Snate@binkert.org 845863Snate@binkert.org def without_tags(self, *tags): 855863Snate@binkert.org '''Return a list of sources without any of the supplied tags.''' 865863Snate@binkert.org return self.with_tags_that(lambda stags: len(tags & stags) == 0) 875863Snate@binkert.org 885863Snate@binkert.org def without_tag(self, tag): 895863Snate@binkert.org '''Return a list of sources with the supplied tag.''' 905863Snate@binkert.org return self.with_tags_that(lambda stags: tag not in stags) 915863Snate@binkert.org 928878Ssteve.reinhardt@amd.comclass SourceMeta(type): 935863Snate@binkert.org '''Meta class for source files that keeps track of all files of a 945863Snate@binkert.org particular type.''' 955863Snate@binkert.org def __init__(cls, name, bases, dict): 969812Sandreas.hansson@arm.com super(SourceMeta, cls).__init__(name, bases, dict) 979812Sandreas.hansson@arm.com cls.all = SourceList() 985863Snate@binkert.org 999812Sandreas.hansson@arm.comclass SourceFile(object): 1005863Snate@binkert.org '''Base object that encapsulates the notion of a source file. 1015863Snate@binkert.org This includes, the source node, target node, various manipulations 1025863Snate@binkert.org of those. A source file also specifies a set of tags which 1039812Sandreas.hansson@arm.com describing arbitrary properties of the source file.''' 1049812Sandreas.hansson@arm.com __metaclass__ = SourceMeta 1055863Snate@binkert.org def __init__(self, source, tags=None, add_tags=None): 1065863Snate@binkert.org if tags is None: 1078878Ssteve.reinhardt@amd.com tags='gem5 lib' 1085863Snate@binkert.org if isinstance(tags, basestring): 1095863Snate@binkert.org tags = set([tags]) 1105863Snate@binkert.org if isinstance(add_tags, basestring): 1116654Snate@binkert.org add_tags = set([add_tags]) 11210196SCurtis.Dunham@arm.com if add_tags: 113955SN/A tags = tags | add_tags 1145396Ssaidi@eecs.umich.edu self.tags = set(tags) 1155863Snate@binkert.org 1165863Snate@binkert.org tnode = source 1174202Sbinkertn@umich.edu if not isinstance(source, SCons.Node.FS.File): 1185863Snate@binkert.org tnode = File(source) 1195863Snate@binkert.org 1205863Snate@binkert.org self.tnode = tnode 1215863Snate@binkert.org self.snode = tnode.srcnode() 122955SN/A 1236654Snate@binkert.org for base in type(self).__mro__: 1245273Sstever@gmail.com if issubclass(base, SourceFile): 1255871Snate@binkert.org base.all.append(self) 1265273Sstever@gmail.com 1276655Snate@binkert.org @property 1288878Ssteve.reinhardt@amd.com def filename(self): 1296655Snate@binkert.org return str(self.tnode) 1306655Snate@binkert.org 1319219Spower.jg@gmail.com @property 1326655Snate@binkert.org def dirname(self): 1335871Snate@binkert.org return dirname(self.filename) 1346654Snate@binkert.org 1358947Sandreas.hansson@arm.com @property 1365396Ssaidi@eecs.umich.edu def basename(self): 1378120Sgblack@eecs.umich.edu return basename(self.filename) 1388120Sgblack@eecs.umich.edu 1398120Sgblack@eecs.umich.edu @property 1408120Sgblack@eecs.umich.edu def extname(self): 1418120Sgblack@eecs.umich.edu index = self.basename.rfind('.') 1428120Sgblack@eecs.umich.edu if index <= 0: 1438120Sgblack@eecs.umich.edu # dot files aren't extensions 1448120Sgblack@eecs.umich.edu return self.basename, None 1458879Ssteve.reinhardt@amd.com 1468879Ssteve.reinhardt@amd.com return self.basename[:index], self.basename[index+1:] 1478879Ssteve.reinhardt@amd.com 1488879Ssteve.reinhardt@amd.com def __lt__(self, other): return self.filename < other.filename 1498879Ssteve.reinhardt@amd.com def __le__(self, other): return self.filename <= other.filename 1508879Ssteve.reinhardt@amd.com def __gt__(self, other): return self.filename > other.filename 1518879Ssteve.reinhardt@amd.com def __ge__(self, other): return self.filename >= other.filename 1528879Ssteve.reinhardt@amd.com def __eq__(self, other): return self.filename == other.filename 1538879Ssteve.reinhardt@amd.com def __ne__(self, other): return self.filename != other.filename 1548879Ssteve.reinhardt@amd.com 1558879Ssteve.reinhardt@amd.comclass Source(SourceFile): 1568879Ssteve.reinhardt@amd.com ungrouped_tag = 'No link group' 1578879Ssteve.reinhardt@amd.com source_groups = set() 1588120Sgblack@eecs.umich.edu 1598120Sgblack@eecs.umich.edu _current_group_tag = ungrouped_tag 1608120Sgblack@eecs.umich.edu 1618120Sgblack@eecs.umich.edu @staticmethod 1628120Sgblack@eecs.umich.edu def link_group_tag(group): 1638120Sgblack@eecs.umich.edu return 'link group: %s' % group 1648120Sgblack@eecs.umich.edu 1658120Sgblack@eecs.umich.edu @classmethod 1668120Sgblack@eecs.umich.edu def set_group(cls, group): 1678120Sgblack@eecs.umich.edu new_tag = Source.link_group_tag(group) 1688120Sgblack@eecs.umich.edu Source._current_group_tag = new_tag 1698120Sgblack@eecs.umich.edu Source.source_groups.add(group) 1708120Sgblack@eecs.umich.edu 1718120Sgblack@eecs.umich.edu def _add_link_group_tag(self): 1728879Ssteve.reinhardt@amd.com self.tags.add(Source._current_group_tag) 1738879Ssteve.reinhardt@amd.com 1748879Ssteve.reinhardt@amd.com '''Add a c/c++ source file to the build''' 1758879Ssteve.reinhardt@amd.com def __init__(self, source, tags=None, add_tags=None): 17610458Sandreas.hansson@arm.com '''specify the source file, and any tags''' 17710458Sandreas.hansson@arm.com super(Source, self).__init__(source, tags, add_tags) 17810458Sandreas.hansson@arm.com self._add_link_group_tag() 1798879Ssteve.reinhardt@amd.com 1808879Ssteve.reinhardt@amd.comclass PySource(SourceFile): 1818879Ssteve.reinhardt@amd.com '''Add a python source file to the named package''' 1828879Ssteve.reinhardt@amd.com invalid_sym_char = re.compile('[^A-z0-9_]') 1839227Sandreas.hansson@arm.com modules = {} 1849227Sandreas.hansson@arm.com tnodes = {} 1858879Ssteve.reinhardt@amd.com symnames = {} 1868879Ssteve.reinhardt@amd.com 1878879Ssteve.reinhardt@amd.com def __init__(self, package, source, tags=None, add_tags=None): 1888879Ssteve.reinhardt@amd.com '''specify the python package, the source file, and any tags''' 18910453SAndrew.Bardsley@arm.com super(PySource, self).__init__(source, tags, add_tags) 19010453SAndrew.Bardsley@arm.com 19110453SAndrew.Bardsley@arm.com modname,ext = self.extname 19210456SCurtis.Dunham@arm.com assert ext == 'py' 19310456SCurtis.Dunham@arm.com 19410456SCurtis.Dunham@arm.com if package: 19510457Sandreas.hansson@arm.com path = package.split('.') 19610457Sandreas.hansson@arm.com else: 1978120Sgblack@eecs.umich.edu path = [] 1988947Sandreas.hansson@arm.com 1997816Ssteve.reinhardt@amd.com modpath = path[:] 2005871Snate@binkert.org if modname != '__init__': 2015871Snate@binkert.org modpath += [ modname ] 2026121Snate@binkert.org modpath = '.'.join(modpath) 2035871Snate@binkert.org 2045871Snate@binkert.org arcpath = path + [ self.basename ] 2059926Sstan.czerniawski@arm.com abspath = self.snode.abspath 2069926Sstan.czerniawski@arm.com if not exists(abspath): 2079119Sandreas.hansson@arm.com abspath = self.tnode.abspath 20810068Sandreas.hansson@arm.com 20910068Sandreas.hansson@arm.com self.package = package 210955SN/A self.modname = modname 2119416SAndreas.Sandberg@ARM.com self.modpath = modpath 2129416SAndreas.Sandberg@ARM.com self.arcname = joinpath(*arcpath) 2139416SAndreas.Sandberg@ARM.com self.abspath = abspath 2149416SAndreas.Sandberg@ARM.com self.compiled = File(self.filename + 'c') 2159416SAndreas.Sandberg@ARM.com self.cpp = File(self.filename + '.cc') 2169416SAndreas.Sandberg@ARM.com self.symname = PySource.invalid_sym_char.sub('_', modpath) 2179416SAndreas.Sandberg@ARM.com 2185871Snate@binkert.org PySource.modules[modpath] = self 21910584Sandreas.hansson@arm.com PySource.tnodes[self.tnode] = self 2209416SAndreas.Sandberg@ARM.com PySource.symnames[self.symname] = self 2219416SAndreas.Sandberg@ARM.com 2225871Snate@binkert.orgclass SimObject(PySource): 223955SN/A '''Add a SimObject python file as a python source object and add 22410671Sandreas.hansson@arm.com it to a list of sim object modules''' 22510671Sandreas.hansson@arm.com 22610671Sandreas.hansson@arm.com fixed = False 22710671Sandreas.hansson@arm.com modnames = [] 2288881Smarc.orr@gmail.com 2296121Snate@binkert.org def __init__(self, source, tags=None, add_tags=None): 2306121Snate@binkert.org '''Specify the source file and any tags (automatically in 2311533SN/A the m5.objects package)''' 2329239Sandreas.hansson@arm.com super(SimObject, self).__init__('m5.objects', source, tags, add_tags) 2339239Sandreas.hansson@arm.com if self.fixed: 2349239Sandreas.hansson@arm.com raise AttributeError, "Too late to call SimObject now." 2359239Sandreas.hansson@arm.com 2369239Sandreas.hansson@arm.com bisect.insort_right(SimObject.modnames, self.modname) 2379239Sandreas.hansson@arm.com 2389239Sandreas.hansson@arm.comclass ProtoBuf(SourceFile): 2399239Sandreas.hansson@arm.com '''Add a Protocol Buffer to build''' 2409239Sandreas.hansson@arm.com 2419239Sandreas.hansson@arm.com def __init__(self, source, tags=None, add_tags=None): 2429239Sandreas.hansson@arm.com '''Specify the source file, and any tags''' 2439239Sandreas.hansson@arm.com super(ProtoBuf, self).__init__(source, tags, add_tags) 2446655Snate@binkert.org 2456655Snate@binkert.org # Get the file name and the extension 2466655Snate@binkert.org modname,ext = self.extname 2476655Snate@binkert.org assert ext == 'proto' 2485871Snate@binkert.org 2495871Snate@binkert.org # Currently, we stick to generating the C++ headers, so we 2505863Snate@binkert.org # only need to track the source and header. 2515871Snate@binkert.org self.cc_file = File(modname + '.pb.cc') 2528878Ssteve.reinhardt@amd.com self.hh_file = File(modname + '.pb.h') 2535871Snate@binkert.org 2545871Snate@binkert.orgclass UnitTest(object): 2555871Snate@binkert.org '''Create a UnitTest''' 2565863Snate@binkert.org 2576121Snate@binkert.org all = [] 2585863Snate@binkert.org def __init__(self, target, *sources, **kwargs): 2595871Snate@binkert.org '''Specify the target name and any sources. Sources that are 2608336Ssteve.reinhardt@amd.com not SourceFiles are evalued with Source(). All files are 2618336Ssteve.reinhardt@amd.com tagged with the name of the UnitTest target.''' 2628336Ssteve.reinhardt@amd.com 2638336Ssteve.reinhardt@amd.com srcs = SourceList() 2644678Snate@binkert.org for src in sources: 2658336Ssteve.reinhardt@amd.com if not isinstance(src, SourceFile): 2668336Ssteve.reinhardt@amd.com src = Source(src, tags=str(target)) 2678336Ssteve.reinhardt@amd.com srcs.append(src) 2684678Snate@binkert.org 2694678Snate@binkert.org self.sources = srcs 2704678Snate@binkert.org self.target = target 2714678Snate@binkert.org self.main = kwargs.get('main', False) 2727827Snate@binkert.org UnitTest.all.append(self) 2737827Snate@binkert.org 2748336Ssteve.reinhardt@amd.com# Children should have access 2754678Snate@binkert.orgExport('Source') 2768336Ssteve.reinhardt@amd.comExport('PySource') 2778336Ssteve.reinhardt@amd.comExport('SimObject') 2788336Ssteve.reinhardt@amd.comExport('ProtoBuf') 2798336Ssteve.reinhardt@amd.comExport('UnitTest') 2808336Ssteve.reinhardt@amd.com 2818336Ssteve.reinhardt@amd.com######################################################################## 2825871Snate@binkert.org# 2835871Snate@binkert.org# Debug Flags 2848336Ssteve.reinhardt@amd.com# 2858336Ssteve.reinhardt@amd.comdebug_flags = {} 2868336Ssteve.reinhardt@amd.comdef DebugFlag(name, desc=None): 2878336Ssteve.reinhardt@amd.com if name in debug_flags: 2888336Ssteve.reinhardt@amd.com raise AttributeError, "Flag %s already specified" % name 2895871Snate@binkert.org debug_flags[name] = (name, (), desc) 2908336Ssteve.reinhardt@amd.com 2918336Ssteve.reinhardt@amd.comdef CompoundFlag(name, flags, desc=None): 2928336Ssteve.reinhardt@amd.com if name in debug_flags: 2938336Ssteve.reinhardt@amd.com raise AttributeError, "Flag %s already specified" % name 2948336Ssteve.reinhardt@amd.com 2954678Snate@binkert.org compound = tuple(flags) 2965871Snate@binkert.org debug_flags[name] = (name, compound, desc) 2974678Snate@binkert.org 2988336Ssteve.reinhardt@amd.comExport('DebugFlag') 2998336Ssteve.reinhardt@amd.comExport('CompoundFlag') 3008336Ssteve.reinhardt@amd.com 3018336Ssteve.reinhardt@amd.com######################################################################## 3028336Ssteve.reinhardt@amd.com# 3038336Ssteve.reinhardt@amd.com# Set some compiler variables 3048336Ssteve.reinhardt@amd.com# 3058336Ssteve.reinhardt@amd.com 3068336Ssteve.reinhardt@amd.com# Include file paths are rooted in this directory. SCons will 3078336Ssteve.reinhardt@amd.com# automatically expand '.' to refer to both the source directory and 3088336Ssteve.reinhardt@amd.com# the corresponding build directory to pick up generated include 3098336Ssteve.reinhardt@amd.com# files. 3108336Ssteve.reinhardt@amd.comenv.Append(CPPPATH=Dir('.')) 3118336Ssteve.reinhardt@amd.com 3128336Ssteve.reinhardt@amd.comfor extra_dir in extras_dir_list: 3138336Ssteve.reinhardt@amd.com env.Append(CPPPATH=Dir(extra_dir)) 3148336Ssteve.reinhardt@amd.com 3155871Snate@binkert.org# Workaround for bug in SCons version > 0.97d20071212 3166121Snate@binkert.org# Scons bug id: 2006 gem5 Bug id: 308 317955SN/Afor root, dirs, files in os.walk(base_dir, topdown=True): 318955SN/A Dir(root[len(base_dir) + 1:]) 3192632Sstever@eecs.umich.edu 3202632Sstever@eecs.umich.edu######################################################################## 321955SN/A# 322955SN/A# Walk the tree and execute all SConscripts in subdirectories 323955SN/A# 324955SN/A 3258878Ssteve.reinhardt@amd.comhere = Dir('.').srcnode().abspath 326955SN/Afor root, dirs, files in os.walk(base_dir, topdown=True): 3272632Sstever@eecs.umich.edu if root == here: 3282632Sstever@eecs.umich.edu # we don't want to recurse back into this SConscript 3292632Sstever@eecs.umich.edu continue 3302632Sstever@eecs.umich.edu 3312632Sstever@eecs.umich.edu if 'SConscript' in files: 3322632Sstever@eecs.umich.edu build_dir = joinpath(env['BUILDDIR'], root[len(base_dir) + 1:]) 3332632Sstever@eecs.umich.edu Source.set_group(build_dir) 3348268Ssteve.reinhardt@amd.com SConscript(joinpath(root, 'SConscript'), variant_dir=build_dir) 3358268Ssteve.reinhardt@amd.com 3368268Ssteve.reinhardt@amd.comfor extra_dir in extras_dir_list: 3378268Ssteve.reinhardt@amd.com prefix_len = len(dirname(extra_dir)) + 1 3388268Ssteve.reinhardt@amd.com 3398268Ssteve.reinhardt@amd.com # Also add the corresponding build directory to pick up generated 3408268Ssteve.reinhardt@amd.com # include files. 3412632Sstever@eecs.umich.edu env.Append(CPPPATH=Dir(joinpath(env['BUILDDIR'], extra_dir[prefix_len:]))) 3422632Sstever@eecs.umich.edu 3432632Sstever@eecs.umich.edu for root, dirs, files in os.walk(extra_dir, topdown=True): 3442632Sstever@eecs.umich.edu # if build lives in the extras directory, don't walk down it 3458268Ssteve.reinhardt@amd.com if 'build' in dirs: 3462632Sstever@eecs.umich.edu dirs.remove('build') 3478268Ssteve.reinhardt@amd.com 3488268Ssteve.reinhardt@amd.com if 'SConscript' in files: 3498268Ssteve.reinhardt@amd.com build_dir = joinpath(env['BUILDDIR'], root[prefix_len:]) 3508268Ssteve.reinhardt@amd.com SConscript(joinpath(root, 'SConscript'), variant_dir=build_dir) 3513718Sstever@eecs.umich.edu 3522634Sstever@eecs.umich.edufor opt in export_vars: 3532634Sstever@eecs.umich.edu env.ConfigFile(opt) 3545863Snate@binkert.org 3552638Sstever@eecs.umich.edudef makeTheISA(source, target, env): 3568268Ssteve.reinhardt@amd.com isas = [ src.get_contents() for src in source ] 3572632Sstever@eecs.umich.edu target_isa = env['TARGET_ISA'] 3582632Sstever@eecs.umich.edu def define(isa): 3592632Sstever@eecs.umich.edu return isa.upper() + '_ISA' 3602632Sstever@eecs.umich.edu 3612632Sstever@eecs.umich.edu def namespace(isa): 3621858SN/A return isa[0].upper() + isa[1:].lower() + 'ISA' 3633716Sstever@eecs.umich.edu 3642638Sstever@eecs.umich.edu 3652638Sstever@eecs.umich.edu code = code_formatter() 3662638Sstever@eecs.umich.edu code('''\ 3672638Sstever@eecs.umich.edu#ifndef __CONFIG_THE_ISA_HH__ 3682638Sstever@eecs.umich.edu#define __CONFIG_THE_ISA_HH__ 3692638Sstever@eecs.umich.edu 3702638Sstever@eecs.umich.edu''') 3715863Snate@binkert.org 3725863Snate@binkert.org # create defines for the preprocessing and compile-time determination 3735863Snate@binkert.org for i,isa in enumerate(isas): 374955SN/A code('#define $0 $1', define(isa), i + 1) 3755341Sstever@gmail.com code() 3765341Sstever@gmail.com 3775863Snate@binkert.org # create an enum for any run-time determination of the ISA, we 3787756SAli.Saidi@ARM.com # reuse the same name as the namespaces 3795341Sstever@gmail.com code('enum class Arch {') 3806121Snate@binkert.org for i,isa in enumerate(isas): 3814494Ssaidi@eecs.umich.edu if i + 1 == len(isas): 3826121Snate@binkert.org code(' $0 = $1', namespace(isa), define(isa)) 3831105SN/A else: 3842667Sstever@eecs.umich.edu code(' $0 = $1,', namespace(isa), define(isa)) 3852667Sstever@eecs.umich.edu code('};') 3862667Sstever@eecs.umich.edu 3872667Sstever@eecs.umich.edu code(''' 3886121Snate@binkert.org 3892667Sstever@eecs.umich.edu#define THE_ISA ${{define(target_isa)}} 3905341Sstever@gmail.com#define TheISA ${{namespace(target_isa)}} 3915863Snate@binkert.org#define THE_ISA_STR "${{target_isa}}" 3925341Sstever@gmail.com 3935341Sstever@gmail.com#endif // __CONFIG_THE_ISA_HH__''') 3945341Sstever@gmail.com 3958120Sgblack@eecs.umich.edu code.write(str(target[0])) 3965341Sstever@gmail.com 3978120Sgblack@eecs.umich.eduenv.Command('config/the_isa.hh', map(Value, all_isa_list), 3985341Sstever@gmail.com MakeAction(makeTheISA, Transform("CFG ISA", 0))) 3998120Sgblack@eecs.umich.edu 4006121Snate@binkert.orgdef makeTheGPUISA(source, target, env): 4016121Snate@binkert.org isas = [ src.get_contents() for src in source ] 4028980Ssteve.reinhardt@amd.com target_gpu_isa = env['TARGET_GPU_ISA'] 4039396Sandreas.hansson@arm.com def define(isa): 4045397Ssaidi@eecs.umich.edu return isa.upper() + '_ISA' 4055397Ssaidi@eecs.umich.edu 4067727SAli.Saidi@ARM.com def namespace(isa): 4078268Ssteve.reinhardt@amd.com return isa[0].upper() + isa[1:].lower() + 'ISA' 4086168Snate@binkert.org 4095341Sstever@gmail.com 4108120Sgblack@eecs.umich.edu code = code_formatter() 4118120Sgblack@eecs.umich.edu code('''\ 4128120Sgblack@eecs.umich.edu#ifndef __CONFIG_THE_GPU_ISA_HH__ 4136814Sgblack@eecs.umich.edu#define __CONFIG_THE_GPU_ISA_HH__ 4145863Snate@binkert.org 4158120Sgblack@eecs.umich.edu''') 4165341Sstever@gmail.com 4175863Snate@binkert.org # create defines for the preprocessing and compile-time determination 4188268Ssteve.reinhardt@amd.com for i,isa in enumerate(isas): 4196121Snate@binkert.org code('#define $0 $1', define(isa), i + 1) 4206121Snate@binkert.org code() 4218268Ssteve.reinhardt@amd.com 4225742Snate@binkert.org # create an enum for any run-time determination of the ISA, we 4235742Snate@binkert.org # reuse the same name as the namespaces 4245341Sstever@gmail.com code('enum class GPUArch {') 4255742Snate@binkert.org for i,isa in enumerate(isas): 4265742Snate@binkert.org if i + 1 == len(isas): 4275341Sstever@gmail.com code(' $0 = $1', namespace(isa), define(isa)) 4286017Snate@binkert.org else: 4296121Snate@binkert.org code(' $0 = $1,', namespace(isa), define(isa)) 4306017Snate@binkert.org code('};') 4317816Ssteve.reinhardt@amd.com 4327756SAli.Saidi@ARM.com code(''' 4337756SAli.Saidi@ARM.com 4347756SAli.Saidi@ARM.com#define THE_GPU_ISA ${{define(target_gpu_isa)}} 4357756SAli.Saidi@ARM.com#define TheGpuISA ${{namespace(target_gpu_isa)}} 4367756SAli.Saidi@ARM.com#define THE_GPU_ISA_STR "${{target_gpu_isa}}" 4377756SAli.Saidi@ARM.com 4387756SAli.Saidi@ARM.com#endif // __CONFIG_THE_GPU_ISA_HH__''') 4397756SAli.Saidi@ARM.com 4407816Ssteve.reinhardt@amd.com code.write(str(target[0])) 4417816Ssteve.reinhardt@amd.com 4427816Ssteve.reinhardt@amd.comenv.Command('config/the_gpu_isa.hh', map(Value, all_gpu_isa_list), 4437816Ssteve.reinhardt@amd.com MakeAction(makeTheGPUISA, Transform("CFG ISA", 0))) 4447816Ssteve.reinhardt@amd.com 4457816Ssteve.reinhardt@amd.com######################################################################## 4467816Ssteve.reinhardt@amd.com# 4477816Ssteve.reinhardt@amd.com# Prevent any SimObjects from being added after this point, they 4487816Ssteve.reinhardt@amd.com# should all have been added in the SConscripts above 4497816Ssteve.reinhardt@amd.com# 4507756SAli.Saidi@ARM.comSimObject.fixed = True 4517816Ssteve.reinhardt@amd.com 4527816Ssteve.reinhardt@amd.comclass DictImporter(object): 4537816Ssteve.reinhardt@amd.com '''This importer takes a dictionary of arbitrary module names that 4547816Ssteve.reinhardt@amd.com map to arbitrary filenames.''' 4557816Ssteve.reinhardt@amd.com def __init__(self, modules): 4567816Ssteve.reinhardt@amd.com self.modules = modules 4577816Ssteve.reinhardt@amd.com self.installed = set() 4587816Ssteve.reinhardt@amd.com 4597816Ssteve.reinhardt@amd.com def __del__(self): 4607816Ssteve.reinhardt@amd.com self.unload() 4617816Ssteve.reinhardt@amd.com 4627816Ssteve.reinhardt@amd.com def unload(self): 4637816Ssteve.reinhardt@amd.com import sys 4647816Ssteve.reinhardt@amd.com for module in self.installed: 4657816Ssteve.reinhardt@amd.com del sys.modules[module] 4667816Ssteve.reinhardt@amd.com self.installed = set() 4677816Ssteve.reinhardt@amd.com 4687816Ssteve.reinhardt@amd.com def find_module(self, fullname, path): 4697816Ssteve.reinhardt@amd.com if fullname == 'm5.defines': 4707816Ssteve.reinhardt@amd.com return self 4717816Ssteve.reinhardt@amd.com 4727816Ssteve.reinhardt@amd.com if fullname == 'm5.objects': 4737816Ssteve.reinhardt@amd.com return self 4747816Ssteve.reinhardt@amd.com 4757816Ssteve.reinhardt@amd.com if fullname.startswith('_m5'): 4767816Ssteve.reinhardt@amd.com return None 4777816Ssteve.reinhardt@amd.com 4787816Ssteve.reinhardt@amd.com source = self.modules.get(fullname, None) 4797816Ssteve.reinhardt@amd.com if source is not None and fullname.startswith('m5.objects'): 4807816Ssteve.reinhardt@amd.com return self 4817816Ssteve.reinhardt@amd.com 4827816Ssteve.reinhardt@amd.com return None 4837816Ssteve.reinhardt@amd.com 4847816Ssteve.reinhardt@amd.com def load_module(self, fullname): 4857816Ssteve.reinhardt@amd.com mod = imp.new_module(fullname) 4867816Ssteve.reinhardt@amd.com sys.modules[fullname] = mod 4877816Ssteve.reinhardt@amd.com self.installed.add(fullname) 4887816Ssteve.reinhardt@amd.com 4897816Ssteve.reinhardt@amd.com mod.__loader__ = self 4907816Ssteve.reinhardt@amd.com if fullname == 'm5.objects': 4917816Ssteve.reinhardt@amd.com mod.__path__ = fullname.split('.') 4927816Ssteve.reinhardt@amd.com return mod 4937816Ssteve.reinhardt@amd.com 4947816Ssteve.reinhardt@amd.com if fullname == 'm5.defines': 4957816Ssteve.reinhardt@amd.com mod.__dict__['buildEnv'] = m5.util.SmartDict(build_env) 4967816Ssteve.reinhardt@amd.com return mod 4977816Ssteve.reinhardt@amd.com 4987816Ssteve.reinhardt@amd.com source = self.modules[fullname] 4997816Ssteve.reinhardt@amd.com if source.modname == '__init__': 5007816Ssteve.reinhardt@amd.com mod.__path__ = source.modpath 5017816Ssteve.reinhardt@amd.com mod.__file__ = source.abspath 5027816Ssteve.reinhardt@amd.com 5037816Ssteve.reinhardt@amd.com exec file(source.abspath, 'r') in mod.__dict__ 5047816Ssteve.reinhardt@amd.com 5057816Ssteve.reinhardt@amd.com return mod 5067816Ssteve.reinhardt@amd.com 5077816Ssteve.reinhardt@amd.comimport m5.SimObject 5087816Ssteve.reinhardt@amd.comimport m5.params 5097816Ssteve.reinhardt@amd.comfrom m5.util import code_formatter 5107816Ssteve.reinhardt@amd.com 5117816Ssteve.reinhardt@amd.comm5.SimObject.clear() 5128947Sandreas.hansson@arm.comm5.params.clear() 5138947Sandreas.hansson@arm.com 5147756SAli.Saidi@ARM.com# install the python importer so we can grab stuff from the source 5158120Sgblack@eecs.umich.edu# tree itself. We can't have SimObjects added after this point or 5167756SAli.Saidi@ARM.com# else we won't know about them for the rest of the stuff. 5177756SAli.Saidi@ARM.comimporter = DictImporter(PySource.modules) 5187756SAli.Saidi@ARM.comsys.meta_path[0:0] = [ importer ] 5197756SAli.Saidi@ARM.com 5207816Ssteve.reinhardt@amd.com# import all sim objects so we can populate the all_objects list 5217816Ssteve.reinhardt@amd.com# make sure that we're working with a list, then let's sort it 5227816Ssteve.reinhardt@amd.comfor modname in SimObject.modnames: 5237816Ssteve.reinhardt@amd.com exec('from m5.objects import %s' % modname) 5247816Ssteve.reinhardt@amd.com 5257816Ssteve.reinhardt@amd.com# we need to unload all of the currently imported modules so that they 5267816Ssteve.reinhardt@amd.com# will be re-imported the next time the sconscript is run 5277816Ssteve.reinhardt@amd.comimporter.unload() 5287816Ssteve.reinhardt@amd.comsys.meta_path.remove(importer) 5297816Ssteve.reinhardt@amd.com 5307756SAli.Saidi@ARM.comsim_objects = m5.SimObject.allClasses 5317756SAli.Saidi@ARM.comall_enums = m5.params.allEnums 5329227Sandreas.hansson@arm.com 5339227Sandreas.hansson@arm.comfor name,obj in sorted(sim_objects.iteritems()): 5349227Sandreas.hansson@arm.com for param in obj._params.local.values(): 5359227Sandreas.hansson@arm.com # load the ptype attribute now because it depends on the 5369590Sandreas@sandberg.pp.se # current version of SimObject.allClasses, but when scons 5379590Sandreas@sandberg.pp.se # actually uses the value, all versions of 5389590Sandreas@sandberg.pp.se # SimObject.allClasses will have been loaded 5399590Sandreas@sandberg.pp.se param.ptype 5409590Sandreas@sandberg.pp.se 5419590Sandreas@sandberg.pp.se######################################################################## 5426654Snate@binkert.org# 5436654Snate@binkert.org# calculate extra dependencies 5445871Snate@binkert.org# 5456121Snate@binkert.orgmodule_depends = ["m5", "m5.SimObject", "m5.params"] 5468946Sandreas.hansson@arm.comdepends = [ PySource.modules[dep].snode for dep in module_depends ] 5479419Sandreas.hansson@arm.comdepends.sort(key = lambda x: x.name) 5483940Ssaidi@eecs.umich.edu 5493918Ssaidi@eecs.umich.edu######################################################################## 5503918Ssaidi@eecs.umich.edu# 5511858SN/A# Commands for the basic automatically generated python files 5529556Sandreas.hansson@arm.com# 5539556Sandreas.hansson@arm.com 5549556Sandreas.hansson@arm.com# Generate Python file containing a dict specifying the current 5559556Sandreas.hansson@arm.com# buildEnv flags. 5569556Sandreas.hansson@arm.comdef makeDefinesPyFile(target, source, env): 5579556Sandreas.hansson@arm.com build_env = source[0].get_contents() 5589556Sandreas.hansson@arm.com 5599556Sandreas.hansson@arm.com code = code_formatter() 5609556Sandreas.hansson@arm.com code(""" 5619556Sandreas.hansson@arm.comimport _m5.core 5629556Sandreas.hansson@arm.comimport m5.util 5639556Sandreas.hansson@arm.com 5649556Sandreas.hansson@arm.combuildEnv = m5.util.SmartDict($build_env) 5659556Sandreas.hansson@arm.com 5669556Sandreas.hansson@arm.comcompileDate = _m5.core.compileDate 5679556Sandreas.hansson@arm.com_globals = globals() 5689556Sandreas.hansson@arm.comfor key,val in _m5.core.__dict__.iteritems(): 5699556Sandreas.hansson@arm.com if key.startswith('flag_'): 5709556Sandreas.hansson@arm.com flag = key[5:] 5719556Sandreas.hansson@arm.com _globals[flag] = val 5729556Sandreas.hansson@arm.comdel _globals 5739556Sandreas.hansson@arm.com""") 5749556Sandreas.hansson@arm.com code.write(target[0].abspath) 5759556Sandreas.hansson@arm.com 5769556Sandreas.hansson@arm.comdefines_info = Value(build_env) 5779556Sandreas.hansson@arm.com# Generate a file with all of the compile options in it 5789556Sandreas.hansson@arm.comenv.Command('python/m5/defines.py', defines_info, 5799556Sandreas.hansson@arm.com MakeAction(makeDefinesPyFile, Transform("DEFINES", 0))) 5809556Sandreas.hansson@arm.comPySource('m5', 'python/m5/defines.py') 5819556Sandreas.hansson@arm.com 5829556Sandreas.hansson@arm.com# Generate python file containing info about the M5 source code 5839556Sandreas.hansson@arm.comdef makeInfoPyFile(target, source, env): 5846121Snate@binkert.org code = code_formatter() 58510238Sandreas.hansson@arm.com for src in source: 58610238Sandreas.hansson@arm.com data = ''.join(file(src.srcnode().abspath, 'r').xreadlines()) 58710238Sandreas.hansson@arm.com code('$src = ${{repr(data)}}') 58810238Sandreas.hansson@arm.com code.write(str(target[0])) 5899420Sandreas.hansson@arm.com 59010238Sandreas.hansson@arm.com# Generate a file that wraps the basic top level files 59110238Sandreas.hansson@arm.comenv.Command('python/m5/info.py', 5929420Sandreas.hansson@arm.com [ '#/COPYING', '#/LICENSE', '#/README', ], 5939420Sandreas.hansson@arm.com MakeAction(makeInfoPyFile, Transform("INFO"))) 5949420Sandreas.hansson@arm.comPySource('m5', 'python/m5/info.py') 5959420Sandreas.hansson@arm.com 5969420Sandreas.hansson@arm.com######################################################################## 59710264Sandreas.hansson@arm.com# 59810264Sandreas.hansson@arm.com# Create all of the SimObject param headers and enum headers 59910264Sandreas.hansson@arm.com# 60010264Sandreas.hansson@arm.com 60110264Sandreas.hansson@arm.comdef createSimObjectParamStruct(target, source, env): 60210264Sandreas.hansson@arm.com assert len(target) == 1 and len(source) == 1 60310264Sandreas.hansson@arm.com 60410264Sandreas.hansson@arm.com name = source[0].get_text_contents() 60510264Sandreas.hansson@arm.com obj = sim_objects[name] 60610264Sandreas.hansson@arm.com 60710264Sandreas.hansson@arm.com code = code_formatter() 60810264Sandreas.hansson@arm.com obj.cxx_param_decl(code) 60910264Sandreas.hansson@arm.com code.write(target[0].abspath) 61010264Sandreas.hansson@arm.com 61110264Sandreas.hansson@arm.comdef createSimObjectCxxConfig(is_header): 61210264Sandreas.hansson@arm.com def body(target, source, env): 61310457Sandreas.hansson@arm.com assert len(target) == 1 and len(source) == 1 61410457Sandreas.hansson@arm.com 61510457Sandreas.hansson@arm.com name = str(source[0].get_contents()) 61610457Sandreas.hansson@arm.com obj = sim_objects[name] 61710457Sandreas.hansson@arm.com 61810457Sandreas.hansson@arm.com code = code_formatter() 61910457Sandreas.hansson@arm.com obj.cxx_config_param_file(code, is_header) 62010457Sandreas.hansson@arm.com code.write(target[0].abspath) 62110457Sandreas.hansson@arm.com return body 62210238Sandreas.hansson@arm.com 62310238Sandreas.hansson@arm.comdef createEnumStrings(target, source, env): 62410238Sandreas.hansson@arm.com assert len(target) == 1 and len(source) == 2 62510238Sandreas.hansson@arm.com 62610238Sandreas.hansson@arm.com name = source[0].get_text_contents() 62710238Sandreas.hansson@arm.com use_python = source[1].read() 62810416Sandreas.hansson@arm.com obj = all_enums[name] 62910238Sandreas.hansson@arm.com 6309227Sandreas.hansson@arm.com code = code_formatter() 63110238Sandreas.hansson@arm.com obj.cxx_def(code) 63210416Sandreas.hansson@arm.com if use_python: 63310416Sandreas.hansson@arm.com obj.pybind_def(code) 6349227Sandreas.hansson@arm.com code.write(target[0].abspath) 6359590Sandreas@sandberg.pp.se 6369590Sandreas@sandberg.pp.sedef createEnumDecls(target, source, env): 6379590Sandreas@sandberg.pp.se assert len(target) == 1 and len(source) == 1 6388737Skoansin.tan@gmail.com 63910238Sandreas.hansson@arm.com name = source[0].get_text_contents() 64010238Sandreas.hansson@arm.com obj = all_enums[name] 6419420Sandreas.hansson@arm.com 6428737Skoansin.tan@gmail.com code = code_formatter() 64310106SMitch.Hayenga@arm.com obj.cxx_decl(code) 6448737Skoansin.tan@gmail.com code.write(target[0].abspath) 6458737Skoansin.tan@gmail.com 64610238Sandreas.hansson@arm.comdef createSimObjectPyBindWrapper(target, source, env): 64710238Sandreas.hansson@arm.com name = source[0].get_text_contents() 6488737Skoansin.tan@gmail.com obj = sim_objects[name] 6498737Skoansin.tan@gmail.com 6508737Skoansin.tan@gmail.com code = code_formatter() 6518737Skoansin.tan@gmail.com obj.pybind_decl(code) 6528737Skoansin.tan@gmail.com code.write(target[0].abspath) 6538737Skoansin.tan@gmail.com 6549556Sandreas.hansson@arm.com# Generate all of the SimObject param C++ struct header files 6559556Sandreas.hansson@arm.comparams_hh_files = [] 6569556Sandreas.hansson@arm.comfor name,simobj in sorted(sim_objects.iteritems()): 6579556Sandreas.hansson@arm.com py_source = PySource.modules[simobj.__module__] 6589556Sandreas.hansson@arm.com extra_deps = [ py_source.tnode ] 6599556Sandreas.hansson@arm.com 6609556Sandreas.hansson@arm.com hh_file = File('params/%s.hh' % name) 6619556Sandreas.hansson@arm.com params_hh_files.append(hh_file) 66210278SAndreas.Sandberg@ARM.com env.Command(hh_file, Value(name), 66310278SAndreas.Sandberg@ARM.com MakeAction(createSimObjectParamStruct, Transform("SO PARAM"))) 66410278SAndreas.Sandberg@ARM.com env.Depends(hh_file, depends + extra_deps) 66510278SAndreas.Sandberg@ARM.com 66610278SAndreas.Sandberg@ARM.com# C++ parameter description files 66710278SAndreas.Sandberg@ARM.comif GetOption('with_cxx_config'): 6689556Sandreas.hansson@arm.com for name,simobj in sorted(sim_objects.iteritems()): 6699590Sandreas@sandberg.pp.se py_source = PySource.modules[simobj.__module__] 6709590Sandreas@sandberg.pp.se extra_deps = [ py_source.tnode ] 6719420Sandreas.hansson@arm.com 6729846Sandreas.hansson@arm.com cxx_config_hh_file = File('cxx_config/%s.hh' % name) 6739846Sandreas.hansson@arm.com cxx_config_cc_file = File('cxx_config/%s.cc' % name) 6749846Sandreas.hansson@arm.com env.Command(cxx_config_hh_file, Value(name), 6759846Sandreas.hansson@arm.com MakeAction(createSimObjectCxxConfig(True), 6768946Sandreas.hansson@arm.com Transform("CXXCPRHH"))) 6773918Ssaidi@eecs.umich.edu env.Command(cxx_config_cc_file, Value(name), 6789068SAli.Saidi@ARM.com MakeAction(createSimObjectCxxConfig(False), 6799068SAli.Saidi@ARM.com Transform("CXXCPRCC"))) 6809068SAli.Saidi@ARM.com env.Depends(cxx_config_hh_file, depends + extra_deps + 6819068SAli.Saidi@ARM.com [File('params/%s.hh' % name), File('sim/cxx_config.hh')]) 6829068SAli.Saidi@ARM.com env.Depends(cxx_config_cc_file, depends + extra_deps + 6839068SAli.Saidi@ARM.com [cxx_config_hh_file]) 6849068SAli.Saidi@ARM.com Source(cxx_config_cc_file) 6859068SAli.Saidi@ARM.com 6869068SAli.Saidi@ARM.com cxx_config_init_cc_file = File('cxx_config/init.cc') 6879419Sandreas.hansson@arm.com 6889068SAli.Saidi@ARM.com def createCxxConfigInitCC(target, source, env): 6899068SAli.Saidi@ARM.com assert len(target) == 1 and len(source) == 1 6909068SAli.Saidi@ARM.com 6919068SAli.Saidi@ARM.com code = code_formatter() 6929068SAli.Saidi@ARM.com 6939068SAli.Saidi@ARM.com for name,simobj in sorted(sim_objects.iteritems()): 6943918Ssaidi@eecs.umich.edu if not hasattr(simobj, 'abstract') or not simobj.abstract: 6953918Ssaidi@eecs.umich.edu code('#include "cxx_config/${name}.hh"') 6966157Snate@binkert.org code() 6976157Snate@binkert.org code('void cxxConfigInit()') 6986157Snate@binkert.org code('{') 6996157Snate@binkert.org code.indent() 7005397Ssaidi@eecs.umich.edu for name,simobj in sorted(sim_objects.iteritems()): 7015397Ssaidi@eecs.umich.edu not_abstract = not hasattr(simobj, 'abstract') or \ 7026121Snate@binkert.org not simobj.abstract 7036121Snate@binkert.org if not_abstract and 'type' in simobj.__dict__: 7046121Snate@binkert.org code('cxx_config_directory["${name}"] = ' 7056121Snate@binkert.org '${name}CxxConfigParams::makeDirectoryEntry();') 7066121Snate@binkert.org code.dedent() 7076121Snate@binkert.org code('}') 7085397Ssaidi@eecs.umich.edu code.write(target[0].abspath) 7091851SN/A 7101851SN/A py_source = PySource.modules[simobj.__module__] 7117739Sgblack@eecs.umich.edu extra_deps = [ py_source.tnode ] 712955SN/A env.Command(cxx_config_init_cc_file, Value(name), 7139396Sandreas.hansson@arm.com MakeAction(createCxxConfigInitCC, Transform("CXXCINIT"))) 7149396Sandreas.hansson@arm.com cxx_param_hh_files = ["cxx_config/%s.hh" % simobj 7159396Sandreas.hansson@arm.com for name,simobj in sorted(sim_objects.iteritems()) 7169396Sandreas.hansson@arm.com if not hasattr(simobj, 'abstract') or not simobj.abstract] 7179396Sandreas.hansson@arm.com Depends(cxx_config_init_cc_file, cxx_param_hh_files + 7189396Sandreas.hansson@arm.com [File('sim/cxx_config.hh')]) 7199396Sandreas.hansson@arm.com Source(cxx_config_init_cc_file) 7209396Sandreas.hansson@arm.com 7219396Sandreas.hansson@arm.com# Generate all enum header files 7229396Sandreas.hansson@arm.comfor name,enum in sorted(all_enums.iteritems()): 7239396Sandreas.hansson@arm.com py_source = PySource.modules[enum.__module__] 7249396Sandreas.hansson@arm.com extra_deps = [ py_source.tnode ] 7259396Sandreas.hansson@arm.com 7269396Sandreas.hansson@arm.com cc_file = File('enums/%s.cc' % name) 7279396Sandreas.hansson@arm.com env.Command(cc_file, [Value(name), Value(env['USE_PYTHON'])], 7289396Sandreas.hansson@arm.com MakeAction(createEnumStrings, Transform("ENUM STR"))) 7299477Sandreas.hansson@arm.com env.Depends(cc_file, depends + extra_deps) 7309477Sandreas.hansson@arm.com Source(cc_file) 7319477Sandreas.hansson@arm.com 7329477Sandreas.hansson@arm.com hh_file = File('enums/%s.hh' % name) 7339477Sandreas.hansson@arm.com env.Command(hh_file, Value(name), 7349477Sandreas.hansson@arm.com MakeAction(createEnumDecls, Transform("ENUMDECL"))) 7359477Sandreas.hansson@arm.com env.Depends(hh_file, depends + extra_deps) 7369477Sandreas.hansson@arm.com 7379477Sandreas.hansson@arm.com# Generate SimObject Python bindings wrapper files 7389477Sandreas.hansson@arm.comif env['USE_PYTHON']: 7399477Sandreas.hansson@arm.com for name,simobj in sorted(sim_objects.iteritems()): 7409477Sandreas.hansson@arm.com py_source = PySource.modules[simobj.__module__] 7419477Sandreas.hansson@arm.com extra_deps = [ py_source.tnode ] 7429477Sandreas.hansson@arm.com cc_file = File('python/_m5/param_%s.cc' % name) 7439477Sandreas.hansson@arm.com env.Command(cc_file, Value(name), 7449477Sandreas.hansson@arm.com MakeAction(createSimObjectPyBindWrapper, 7459477Sandreas.hansson@arm.com Transform("SO PyBind"))) 7469477Sandreas.hansson@arm.com env.Depends(cc_file, depends + extra_deps) 7479477Sandreas.hansson@arm.com Source(cc_file) 7489477Sandreas.hansson@arm.com 7499477Sandreas.hansson@arm.com# Build all protocol buffers if we have got protoc and protobuf available 7509477Sandreas.hansson@arm.comif env['HAVE_PROTOBUF']: 7519396Sandreas.hansson@arm.com for proto in ProtoBuf.all: 7523053Sstever@eecs.umich.edu # Use both the source and header as the target, and the .proto 7536121Snate@binkert.org # file as the source. When executing the protoc compiler, also 7543053Sstever@eecs.umich.edu # specify the proto_path to avoid having the generated files 7553053Sstever@eecs.umich.edu # include the path. 7563053Sstever@eecs.umich.edu env.Command([proto.cc_file, proto.hh_file], proto.tnode, 7573053Sstever@eecs.umich.edu MakeAction('$PROTOC --cpp_out ${TARGET.dir} ' 7583053Sstever@eecs.umich.edu '--proto_path ${SOURCE.dir} $SOURCE', 7599072Sandreas.hansson@arm.com Transform("PROTOC"))) 7603053Sstever@eecs.umich.edu 7614742Sstever@eecs.umich.edu # Add the C++ source file 7624742Sstever@eecs.umich.edu Source(proto.cc_file, tags=proto.tags) 7633053Sstever@eecs.umich.eduelif ProtoBuf.all: 7643053Sstever@eecs.umich.edu print 'Got protobuf to build, but lacks support!' 7653053Sstever@eecs.umich.edu Exit(1) 76610181SCurtis.Dunham@arm.com 7676654Snate@binkert.org# 7683053Sstever@eecs.umich.edu# Handle debug flags 7693053Sstever@eecs.umich.edu# 7703053Sstever@eecs.umich.edudef makeDebugFlagCC(target, source, env): 7713053Sstever@eecs.umich.edu assert(len(target) == 1 and len(source) == 1) 77210425Sandreas.hansson@arm.com 77310425Sandreas.hansson@arm.com code = code_formatter() 77410425Sandreas.hansson@arm.com 77510425Sandreas.hansson@arm.com # delay definition of CompoundFlags until after all the definition 77610425Sandreas.hansson@arm.com # of all constituent SimpleFlags 77710425Sandreas.hansson@arm.com comp_code = code_formatter() 77810425Sandreas.hansson@arm.com 77910425Sandreas.hansson@arm.com # file header 78010425Sandreas.hansson@arm.com code(''' 78110425Sandreas.hansson@arm.com/* 78210425Sandreas.hansson@arm.com * DO NOT EDIT THIS FILE! Automatically generated by SCons. 7832667Sstever@eecs.umich.edu */ 7844554Sbinkertn@umich.edu 7856121Snate@binkert.org#include "base/debug.hh" 7862667Sstever@eecs.umich.edu 78710710Sandreas.hansson@arm.comnamespace Debug { 78810710Sandreas.hansson@arm.com 78910710Sandreas.hansson@arm.com''') 79010710Sandreas.hansson@arm.com 79110710Sandreas.hansson@arm.com for name, flag in sorted(source[0].read().iteritems()): 79210710Sandreas.hansson@arm.com n, compound, desc = flag 79310710Sandreas.hansson@arm.com assert n == name 79410710Sandreas.hansson@arm.com 79510710Sandreas.hansson@arm.com if not compound: 79610384SCurtis.Dunham@arm.com code('SimpleFlag $name("$name", "$desc");') 7974554Sbinkertn@umich.edu else: 7984554Sbinkertn@umich.edu comp_code('CompoundFlag $name("$name", "$desc",') 7994554Sbinkertn@umich.edu comp_code.indent() 8006121Snate@binkert.org last = len(compound) - 1 8014554Sbinkertn@umich.edu for i,flag in enumerate(compound): 8024554Sbinkertn@umich.edu if i != last: 8034554Sbinkertn@umich.edu comp_code('&$flag,') 8044781Snate@binkert.org else: 8054554Sbinkertn@umich.edu comp_code('&$flag);') 8064554Sbinkertn@umich.edu comp_code.dedent() 8072667Sstever@eecs.umich.edu 8084554Sbinkertn@umich.edu code.append(comp_code) 8094554Sbinkertn@umich.edu code() 8104554Sbinkertn@umich.edu code('} // namespace Debug') 8114554Sbinkertn@umich.edu 8122667Sstever@eecs.umich.edu code.write(str(target[0])) 8134554Sbinkertn@umich.edu 8142667Sstever@eecs.umich.edudef makeDebugFlagHH(target, source, env): 8154554Sbinkertn@umich.edu assert(len(target) == 1 and len(source) == 1) 8166121Snate@binkert.org 8172667Sstever@eecs.umich.edu val = eval(source[0].get_contents()) 8185522Snate@binkert.org name, compound, desc = val 8195522Snate@binkert.org 8205522Snate@binkert.org code = code_formatter() 8215522Snate@binkert.org 8225522Snate@binkert.org # file header boilerplate 8235522Snate@binkert.org code('''\ 8245522Snate@binkert.org/* 8255522Snate@binkert.org * DO NOT EDIT THIS FILE! Automatically generated by SCons. 8265522Snate@binkert.org */ 8275522Snate@binkert.org 8285522Snate@binkert.org#ifndef __DEBUG_${name}_HH__ 8295522Snate@binkert.org#define __DEBUG_${name}_HH__ 8305522Snate@binkert.org 8315522Snate@binkert.orgnamespace Debug { 8325522Snate@binkert.org''') 8335522Snate@binkert.org 8345522Snate@binkert.org if compound: 8355522Snate@binkert.org code('class CompoundFlag;') 8365522Snate@binkert.org code('class SimpleFlag;') 8375522Snate@binkert.org 8385522Snate@binkert.org if compound: 8395522Snate@binkert.org code('extern CompoundFlag $name;') 8405522Snate@binkert.org for flag in compound: 8415522Snate@binkert.org code('extern SimpleFlag $flag;') 8425522Snate@binkert.org else: 8435522Snate@binkert.org code('extern SimpleFlag $name;') 8449986Sandreas@sandberg.pp.se 8459986Sandreas@sandberg.pp.se code(''' 8469986Sandreas@sandberg.pp.se} 8479986Sandreas@sandberg.pp.se 8489986Sandreas@sandberg.pp.se#endif // __DEBUG_${name}_HH__ 8499986Sandreas@sandberg.pp.se''') 8509986Sandreas@sandberg.pp.se 8519986Sandreas@sandberg.pp.se code.write(str(target[0])) 8529986Sandreas@sandberg.pp.se 8539986Sandreas@sandberg.pp.sefor name,flag in sorted(debug_flags.iteritems()): 8549986Sandreas@sandberg.pp.se n, compound, desc = flag 8559986Sandreas@sandberg.pp.se assert n == name 8569986Sandreas@sandberg.pp.se 8579986Sandreas@sandberg.pp.se hh_file = 'debug/%s.hh' % name 8589986Sandreas@sandberg.pp.se env.Command(hh_file, Value(flag), 8599986Sandreas@sandberg.pp.se MakeAction(makeDebugFlagHH, Transform("TRACING", 0))) 8609986Sandreas@sandberg.pp.se 8619986Sandreas@sandberg.pp.seenv.Command('debug/flags.cc', Value(debug_flags), 8629986Sandreas@sandberg.pp.se MakeAction(makeDebugFlagCC, Transform("TRACING", 0))) 8639986Sandreas@sandberg.pp.seSource('debug/flags.cc') 8642638Sstever@eecs.umich.edu 8652638Sstever@eecs.umich.edu# version tags 8666121Snate@binkert.orgtags = \ 8673716Sstever@eecs.umich.eduenv.Command('sim/tags.cc', None, 8685522Snate@binkert.org MakeAction('util/cpt_upgrader.py --get-cc-file > $TARGET', 8699986Sandreas@sandberg.pp.se Transform("VER TAGS"))) 8709986Sandreas@sandberg.pp.seenv.AlwaysBuild(tags) 8719986Sandreas@sandberg.pp.se 8729986Sandreas@sandberg.pp.se# Embed python files. All .py files that have been indicated by a 8735522Snate@binkert.org# PySource() call in a SConscript need to be embedded into the M5 8745522Snate@binkert.org# library. To do that, we compile the file to byte code, marshal the 8755522Snate@binkert.org# byte code, compress it, and then generate a c++ file that 8765522Snate@binkert.org# inserts the result into an array. 8771858SN/Adef embedPyFile(target, source, env): 8785227Ssaidi@eecs.umich.edu def c_str(string): 8795227Ssaidi@eecs.umich.edu if string is None: 8805227Ssaidi@eecs.umich.edu return "0" 8815227Ssaidi@eecs.umich.edu return '"%s"' % string 8826654Snate@binkert.org 8836654Snate@binkert.org '''Action function to compile a .py into a code object, marshal 8847769SAli.Saidi@ARM.com it, compress it, and stick it into an asm file so the code appears 8857769SAli.Saidi@ARM.com as just bytes with a label in the data section''' 8867769SAli.Saidi@ARM.com 8877769SAli.Saidi@ARM.com src = file(str(source[0]), 'r').read() 8885227Ssaidi@eecs.umich.edu 8895227Ssaidi@eecs.umich.edu pysource = PySource.tnodes[source[0]] 8905227Ssaidi@eecs.umich.edu compiled = compile(src, pysource.abspath, 'exec') 8915204Sstever@gmail.com marshalled = marshal.dumps(compiled) 8925204Sstever@gmail.com compressed = zlib.compress(marshalled) 8935204Sstever@gmail.com data = compressed 8945204Sstever@gmail.com sym = pysource.symname 8955204Sstever@gmail.com 8965204Sstever@gmail.com code = code_formatter() 8975204Sstever@gmail.com code('''\ 8985204Sstever@gmail.com#include "sim/init.hh" 8995204Sstever@gmail.com 9005204Sstever@gmail.comnamespace { 9015204Sstever@gmail.com 9025204Sstever@gmail.comconst uint8_t data_${sym}[] = { 9035204Sstever@gmail.com''') 9045204Sstever@gmail.com code.indent() 9055204Sstever@gmail.com step = 16 9065204Sstever@gmail.com for i in xrange(0, len(data), step): 9075204Sstever@gmail.com x = array.array('B', data[i:i+step]) 9086121Snate@binkert.org code(''.join('%d,' % d for d in x)) 9095204Sstever@gmail.com code.dedent() 9107727SAli.Saidi@ARM.com 9117727SAli.Saidi@ARM.com code('''}; 9127727SAli.Saidi@ARM.com 9137727SAli.Saidi@ARM.comEmbeddedPython embedded_${sym}( 9147727SAli.Saidi@ARM.com ${{c_str(pysource.arcname)}}, 91510453SAndrew.Bardsley@arm.com ${{c_str(pysource.abspath)}}, 91610453SAndrew.Bardsley@arm.com ${{c_str(pysource.modpath)}}, 91710453SAndrew.Bardsley@arm.com data_${sym}, 91810453SAndrew.Bardsley@arm.com ${{len(data)}}, 91910453SAndrew.Bardsley@arm.com ${{len(marshalled)}}); 92010453SAndrew.Bardsley@arm.com 92110453SAndrew.Bardsley@arm.com} // anonymous namespace 92210453SAndrew.Bardsley@arm.com''') 92310453SAndrew.Bardsley@arm.com code.write(str(target[0])) 92410453SAndrew.Bardsley@arm.com 92510453SAndrew.Bardsley@arm.comfor source in PySource.all: 92610160Sandreas.hansson@arm.com env.Command(source.cpp, source.tnode, 92710453SAndrew.Bardsley@arm.com MakeAction(embedPyFile, Transform("EMBED PY"))) 92810453SAndrew.Bardsley@arm.com Source(source.cpp, tags=source.tags, add_tags='python') 92910453SAndrew.Bardsley@arm.com 93010453SAndrew.Bardsley@arm.com######################################################################## 93110453SAndrew.Bardsley@arm.com# 93210453SAndrew.Bardsley@arm.com# Define binaries. Each different build type (debug, opt, etc.) gets 93310453SAndrew.Bardsley@arm.com# a slightly different build environment. 93410453SAndrew.Bardsley@arm.com# 9359812Sandreas.hansson@arm.com 93610453SAndrew.Bardsley@arm.com# List of constructed environments to pass back to SConstruct 93710453SAndrew.Bardsley@arm.comdate_source = Source('base/date.cc', tags=[]) 93810453SAndrew.Bardsley@arm.com 93910453SAndrew.Bardsley@arm.com# Function to create a new build environment as clone of current 94010453SAndrew.Bardsley@arm.com# environment 'env' with modified object suffix and optional stripped 94110453SAndrew.Bardsley@arm.com# binary. Additional keyword arguments are appended to corresponding 94210453SAndrew.Bardsley@arm.com# build environment vars. 94310453SAndrew.Bardsley@arm.comdef makeEnv(env, label, objsfx, strip=False, disable_partial=False, **kwargs): 94410453SAndrew.Bardsley@arm.com # SCons doesn't know to append a library suffix when there is a '.' in the 94510453SAndrew.Bardsley@arm.com # name. Use '_' instead. 94610453SAndrew.Bardsley@arm.com libname = 'gem5_' + label 94710453SAndrew.Bardsley@arm.com exename = 'gem5.' + label 9487727SAli.Saidi@ARM.com secondary_exename = 'm5.' + label 94910453SAndrew.Bardsley@arm.com 95010453SAndrew.Bardsley@arm.com new_env = env.Clone(OBJSUFFIX=objsfx, SHOBJSUFFIX=objsfx + 's') 95110453SAndrew.Bardsley@arm.com new_env.Label = label 95210453SAndrew.Bardsley@arm.com new_env.Append(**kwargs) 95310453SAndrew.Bardsley@arm.com 9543118Sstever@eecs.umich.edu def make_obj(source, static, extra_deps=None): 95510453SAndrew.Bardsley@arm.com '''This function creates a scons node of the requested type, and sets 95610453SAndrew.Bardsley@arm.com up any additional dependencies.''' 95710453SAndrew.Bardsley@arm.com 95810453SAndrew.Bardsley@arm.com if static: 9593118Sstever@eecs.umich.edu obj = new_env.StaticObject(source.tnode) 9603483Ssaidi@eecs.umich.edu else: 9613494Ssaidi@eecs.umich.edu obj = new_env.SharedObject(source.tnode) 9623494Ssaidi@eecs.umich.edu 9633483Ssaidi@eecs.umich.edu if extra_deps: 9643483Ssaidi@eecs.umich.edu new_env.Depends(obj, extra_deps) 9653483Ssaidi@eecs.umich.edu 9663053Sstever@eecs.umich.edu return obj 9673053Sstever@eecs.umich.edu 9683918Ssaidi@eecs.umich.edu lib_sources = Source.all.with_tag('gem5 lib') 9693053Sstever@eecs.umich.edu 9703053Sstever@eecs.umich.edu # Without Python, leave out all Python content from the library 9713053Sstever@eecs.umich.edu # builds. The option doesn't affect gem5 built as a program 9723053Sstever@eecs.umich.edu if GetOption('without_python'): 9733053Sstever@eecs.umich.edu lib_sources = lib_sources.without_tag('python') 9749396Sandreas.hansson@arm.com 9759396Sandreas.hansson@arm.com static_objs = [] 9769396Sandreas.hansson@arm.com shared_objs = [] 9779396Sandreas.hansson@arm.com 9789396Sandreas.hansson@arm.com for s in lib_sources.with_tag(Source.ungrouped_tag): 9799396Sandreas.hansson@arm.com static_objs.append(make_obj(s, True)) 9809396Sandreas.hansson@arm.com shared_objs.append(make_obj(s, False)) 9819396Sandreas.hansson@arm.com 9829396Sandreas.hansson@arm.com partial_objs = [] 9839477Sandreas.hansson@arm.com 9849396Sandreas.hansson@arm.com for group in Source.source_groups: 9859477Sandreas.hansson@arm.com srcs = lib_sources.with_tag(Source.link_group_tag(group)) 9869477Sandreas.hansson@arm.com if not srcs: 9879477Sandreas.hansson@arm.com continue 9889477Sandreas.hansson@arm.com 9899396Sandreas.hansson@arm.com # If partial linking is disabled, add these sources to the build 9907840Snate@binkert.org # directly, and short circuit this loop. 9917865Sgblack@eecs.umich.edu if disable_partial: 9927865Sgblack@eecs.umich.edu for s in srcs: 9937865Sgblack@eecs.umich.edu static_objs.append(make_obj(s, True)) 9947865Sgblack@eecs.umich.edu shared_objs.append(make_obj(s, False)) 9957865Sgblack@eecs.umich.edu continue 9967840Snate@binkert.org 9979900Sandreas@sandberg.pp.se # Set up the static partially linked objects. 9989900Sandreas@sandberg.pp.se source_objs = [ make_obj(s, True) for s in srcs ] 9999900Sandreas@sandberg.pp.se file_name = new_env.subst("${OBJPREFIX}lib${OBJSUFFIX}.partial") 10009900Sandreas@sandberg.pp.se target = File(joinpath(group, file_name)) 100110456SCurtis.Dunham@arm.com partial = env.PartialStatic(target=target, source=source_objs) 100210456SCurtis.Dunham@arm.com static_objs.append(partial) 100310456SCurtis.Dunham@arm.com 100410456SCurtis.Dunham@arm.com # Set up the shared partially linked objects. 100510456SCurtis.Dunham@arm.com source_objs = [ make_obj(s, False) for s in srcs ] 100610456SCurtis.Dunham@arm.com file_name = new_env.subst("${SHOBJPREFIX}lib${SHOBJSUFFIX}.partial") 100710456SCurtis.Dunham@arm.com target = File(joinpath(group, file_name)) 100810456SCurtis.Dunham@arm.com partial = env.PartialShared(target=target, source=source_objs) 100910456SCurtis.Dunham@arm.com shared_objs.append(partial) 101010456SCurtis.Dunham@arm.com 10119045SAli.Saidi@ARM.com static_date = make_obj(date_source, static=True, extra_deps=static_objs) 10127840Snate@binkert.org static_objs.append(static_date) 10137840Snate@binkert.org 10147840Snate@binkert.org shared_date = make_obj(date_source, static=False, extra_deps=shared_objs) 10151858SN/A shared_objs.append(shared_date) 10161858SN/A 10171858SN/A # First make a library of everything but main() so other programs can 10181858SN/A # link against m5. 10191858SN/A static_lib = new_env.StaticLibrary(libname, static_objs) 10201858SN/A shared_lib = new_env.SharedLibrary(libname, shared_objs) 10219903Sandreas.hansson@arm.com 10229903Sandreas.hansson@arm.com # Now link a stub with main() and the static library. 10239903Sandreas.hansson@arm.com main_objs = [ make_obj(s, True) for s in Source.all.with_tag('main') ] 10249903Sandreas.hansson@arm.com 102510841Sandreas.sandberg@arm.com for test in UnitTest.all: 10269651SAndreas.Sandberg@ARM.com test_sources = Source.all.with_tag(str(test.target)) 10279903Sandreas.hansson@arm.com test_objs = [ make_obj(s, static=True) for s in test_sources ] 10289651SAndreas.Sandberg@ARM.com if test.main: 10299651SAndreas.Sandberg@ARM.com test_objs += main_objs 103010841Sandreas.sandberg@arm.com path = 'unittest/%s.%s' % (test.target, label) 103110841Sandreas.sandberg@arm.com new_env.Program(path, test_objs + static_objs) 103210841Sandreas.sandberg@arm.com 103310841Sandreas.sandberg@arm.com progname = exename 103410841Sandreas.sandberg@arm.com if strip: 103510841Sandreas.sandberg@arm.com progname += '.unstripped' 10369651SAndreas.Sandberg@ARM.com 10379651SAndreas.Sandberg@ARM.com targets = new_env.Program(progname, main_objs + static_objs) 10389651SAndreas.Sandberg@ARM.com 10399651SAndreas.Sandberg@ARM.com if strip: 10409651SAndreas.Sandberg@ARM.com if sys.platform == 'sunos5': 10419651SAndreas.Sandberg@ARM.com cmd = 'cp $SOURCE $TARGET; strip $TARGET' 10429651SAndreas.Sandberg@ARM.com else: 10439651SAndreas.Sandberg@ARM.com cmd = 'strip $SOURCE -o $TARGET' 10449651SAndreas.Sandberg@ARM.com targets = new_env.Command(exename, progname, 104510841Sandreas.sandberg@arm.com MakeAction(cmd, Transform("STRIP"))) 104610841Sandreas.sandberg@arm.com 104710841Sandreas.sandberg@arm.com new_env.Command(secondary_exename, exename, 104810841Sandreas.sandberg@arm.com MakeAction('ln $SOURCE $TARGET', Transform("HARDLINK"))) 104910841Sandreas.sandberg@arm.com 105010841Sandreas.sandberg@arm.com new_env.M5Binary = targets[0] 105110860Sandreas.sandberg@arm.com 105210841Sandreas.sandberg@arm.com # Set up regression tests. 105310841Sandreas.sandberg@arm.com SConscript(os.path.join(env.root.abspath, 'tests', 'SConscript'), 105410841Sandreas.sandberg@arm.com variant_dir=Dir('tests').Dir(new_env.Label), 105510841Sandreas.sandberg@arm.com exports={ 'env' : new_env }, duplicate=False) 105610841Sandreas.sandberg@arm.com 105710841Sandreas.sandberg@arm.com# Start out with the compiler flags common to all compilers, 105810841Sandreas.sandberg@arm.com# i.e. they all use -g for opt and -g -pg for prof 105910841Sandreas.sandberg@arm.comccflags = {'debug' : [], 'opt' : ['-g'], 'fast' : [], 'prof' : ['-g', '-pg'], 106010841Sandreas.sandberg@arm.com 'perf' : ['-g']} 106110841Sandreas.sandberg@arm.com 106210841Sandreas.sandberg@arm.com# Start out with the linker flags common to all linkers, i.e. -pg for 10639651SAndreas.Sandberg@ARM.com# prof, and -lprofiler for perf. The -lprofile flag is surrounded by 10649651SAndreas.Sandberg@ARM.com# no-as-needed and as-needed as the binutils linker is too clever and 10659986Sandreas@sandberg.pp.se# simply doesn't link to the library otherwise. 10669986Sandreas@sandberg.pp.seldflags = {'debug' : [], 'opt' : [], 'fast' : [], 'prof' : ['-pg'], 10679986Sandreas@sandberg.pp.se 'perf' : ['-Wl,--no-as-needed', '-lprofiler', '-Wl,--as-needed']} 10689986Sandreas@sandberg.pp.se 10699986Sandreas@sandberg.pp.se# For Link Time Optimization, the optimisation flags used to compile 10709986Sandreas@sandberg.pp.se# individual files are decoupled from those used at link time 10715863Snate@binkert.org# (i.e. you can compile with -O3 and perform LTO with -O0), so we need 10725863Snate@binkert.org# to also update the linker flags based on the target. 10735863Snate@binkert.orgif env['GCC']: 10745863Snate@binkert.org if sys.platform == 'sunos5': 10756121Snate@binkert.org ccflags['debug'] += ['-gstabs+'] 10761858SN/A else: 10775863Snate@binkert.org ccflags['debug'] += ['-ggdb3'] 10785863Snate@binkert.org ldflags['debug'] += ['-O0'] 10795863Snate@binkert.org # opt, fast, prof and perf all share the same cc flags, also add 10805863Snate@binkert.org # the optimization to the ldflags as LTO defers the optimization 10815863Snate@binkert.org # to link time 10822139SN/A for target in ['opt', 'fast', 'prof', 'perf']: 10834202Sbinkertn@umich.edu ccflags[target] += ['-O3'] 10844202Sbinkertn@umich.edu ldflags[target] += ['-O3'] 10852139SN/A 10866994Snate@binkert.org ccflags['fast'] += env['LTO_CCFLAGS'] 10876994Snate@binkert.org ldflags['fast'] += env['LTO_LDFLAGS'] 10886994Snate@binkert.orgelif env['CLANG']: 10896994Snate@binkert.org ccflags['debug'] += ['-g', '-O0'] 10906994Snate@binkert.org # opt, fast, prof and perf all share the same cc flags 10916994Snate@binkert.org for target in ['opt', 'fast', 'prof', 'perf']: 10926994Snate@binkert.org ccflags[target] += ['-O3'] 10936994Snate@binkert.orgelse: 109410319SAndreas.Sandberg@ARM.com print 'Unknown compiler, please fix compiler options' 10956994Snate@binkert.org Exit(1) 10966994Snate@binkert.org 10976994Snate@binkert.org 10986994Snate@binkert.org# To speed things up, we only instantiate the build environments we 10996994Snate@binkert.org# need. We try to identify the needed environment for each target; if 11006994Snate@binkert.org# we can't, we fall back on instantiating all the environments just to 11016994Snate@binkert.org# be safe. 11026994Snate@binkert.orgtarget_types = ['debug', 'opt', 'fast', 'prof', 'perf'] 11036994Snate@binkert.orgobj2target = {'do': 'debug', 'o': 'opt', 'fo': 'fast', 'po': 'prof', 11046994Snate@binkert.org 'gpo' : 'perf'} 11056994Snate@binkert.org 11062155SN/Adef identifyTarget(t): 11075863Snate@binkert.org ext = t.split('.')[-1] 11081869SN/A if ext in target_types: 11091869SN/A return ext 11105863Snate@binkert.org if obj2target.has_key(ext): 11115863Snate@binkert.org return obj2target[ext] 11124202Sbinkertn@umich.edu match = re.search(r'/tests/([^/]+)/', t) 11136108Snate@binkert.org if match and match.group(1) in target_types: 11146108Snate@binkert.org return match.group(1) 11156108Snate@binkert.org return 'all' 11166108Snate@binkert.org 11179219Spower.jg@gmail.comneeded_envs = [identifyTarget(target) for target in BUILD_TARGETS] 11189219Spower.jg@gmail.comif 'all' in needed_envs: 11199219Spower.jg@gmail.com needed_envs += target_types 11209219Spower.jg@gmail.com 11219219Spower.jg@gmail.com# Debug binary 11229219Spower.jg@gmail.comif 'debug' in needed_envs: 11239219Spower.jg@gmail.com makeEnv(env, 'debug', '.do', 11249219Spower.jg@gmail.com CCFLAGS = Split(ccflags['debug']), 11254202Sbinkertn@umich.edu CPPDEFINES = ['DEBUG', 'TRACING_ON=1'], 11265863Snate@binkert.org LINKFLAGS = Split(ldflags['debug'])) 112710135SCurtis.Dunham@arm.com 11288474Sgblack@eecs.umich.edu# Optimized binary 11295742Snate@binkert.orgif 'opt' in needed_envs: 11308268Ssteve.reinhardt@amd.com makeEnv(env, 'opt', '.o', 11318268Ssteve.reinhardt@amd.com CCFLAGS = Split(ccflags['opt']), 11328268Ssteve.reinhardt@amd.com CPPDEFINES = ['TRACING_ON=1'], 11335742Snate@binkert.org LINKFLAGS = Split(ldflags['opt'])) 11345341Sstever@gmail.com 11358474Sgblack@eecs.umich.edu# "Fast" binary 11368474Sgblack@eecs.umich.eduif 'fast' in needed_envs: 11375342Sstever@gmail.com disable_partial = \ 11384202Sbinkertn@umich.edu env.get('BROKEN_INCREMENTAL_LTO', False) and \ 11394202Sbinkertn@umich.edu GetOption('force_lto') 11404202Sbinkertn@umich.edu makeEnv(env, 'fast', '.fo', strip = True, 11415863Snate@binkert.org CCFLAGS = Split(ccflags['fast']), 11425863Snate@binkert.org CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'], 11436994Snate@binkert.org LINKFLAGS = Split(ldflags['fast']), 11446994Snate@binkert.org disable_partial=disable_partial) 114510319SAndreas.Sandberg@ARM.com 11465863Snate@binkert.org# Profiled binary using gprof 11475863Snate@binkert.orgif 'prof' in needed_envs: 11485863Snate@binkert.org makeEnv(env, 'prof', '.po', 11495863Snate@binkert.org CCFLAGS = Split(ccflags['prof']), 11505863Snate@binkert.org CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'], 11515863Snate@binkert.org LINKFLAGS = Split(ldflags['prof'])) 11525863Snate@binkert.org 11535863Snate@binkert.org# Profiled binary using google-pprof 11547840Snate@binkert.orgif 'perf' in needed_envs: 11555863Snate@binkert.org makeEnv(env, 'perf', '.gpo', 11565952Ssaidi@eecs.umich.edu CCFLAGS = Split(ccflags['perf']), 11579651SAndreas.Sandberg@ARM.com CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'], 11589219Spower.jg@gmail.com LINKFLAGS = Split(ldflags['perf'])) 11599219Spower.jg@gmail.com