SConscript revision 13579
1955SN/A# -*- mode:python -*- 2955SN/A 313576Sciro.santilli@arm.com# Copyright (c) 2018 ARM Limited 413576Sciro.santilli@arm.com# 513576Sciro.santilli@arm.com# The license below extends only to copyright in the software and shall 613576Sciro.santilli@arm.com# not be construed as granting a license to any other intellectual 713576Sciro.santilli@arm.com# property including but not limited to intellectual property relating 813576Sciro.santilli@arm.com# to a hardware implementation of the functionality of the software 913576Sciro.santilli@arm.com# licensed hereunder. You may use the software subject to the license 1013576Sciro.santilli@arm.com# terms below provided that you ensure that this notice is replicated 1113576Sciro.santilli@arm.com# unmodified and in its entirety in all distributions of the software, 1213576Sciro.santilli@arm.com# modified or unmodified, in source code or in binary form. 1313576Sciro.santilli@arm.com# 141762SN/A# Copyright (c) 2004-2005 The Regents of The University of Michigan 15955SN/A# All rights reserved. 16955SN/A# 17955SN/A# Redistribution and use in source and binary forms, with or without 18955SN/A# modification, are permitted provided that the following conditions are 19955SN/A# met: redistributions of source code must retain the above copyright 20955SN/A# notice, this list of conditions and the following disclaimer; 21955SN/A# redistributions in binary form must reproduce the above copyright 22955SN/A# notice, this list of conditions and the following disclaimer in the 23955SN/A# documentation and/or other materials provided with the distribution; 24955SN/A# neither the name of the copyright holders nor the names of its 25955SN/A# contributors may be used to endorse or promote products derived from 26955SN/A# this software without specific prior written permission. 27955SN/A# 28955SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 29955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 30955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 31955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 32955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 33955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 34955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 35955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 36955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 37955SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 38955SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 392665Ssaidi@eecs.umich.edu# 404762Snate@binkert.org# Authors: Nathan Binkert 41955SN/A 4212563Sgabeblack@google.comfrom __future__ import print_function 4312563Sgabeblack@google.com 445522Snate@binkert.orgimport array 456143Snate@binkert.orgimport bisect 4612371Sgabeblack@google.comimport functools 474762Snate@binkert.orgimport imp 485522Snate@binkert.orgimport marshal 49955SN/Aimport os 505522Snate@binkert.orgimport re 5111974Sgabeblack@google.comimport subprocess 52955SN/Aimport sys 535522Snate@binkert.orgimport zlib 544202Sbinkertn@umich.edu 555742Snate@binkert.orgfrom os.path import basename, dirname, exists, isdir, isfile, join as joinpath 56955SN/A 574381Sbinkertn@umich.eduimport SCons 584381Sbinkertn@umich.edu 5912246Sgabeblack@google.comfrom gem5_scons import Transform 6012246Sgabeblack@google.com 618334Snate@binkert.org# This file defines how to build a particular configuration of gem5 62955SN/A# based on variable settings in the 'env' build environment. 63955SN/A 644202Sbinkertn@umich.eduImport('*') 65955SN/A 664382Sbinkertn@umich.edu# Children need to see the environment 674382Sbinkertn@umich.eduExport('env') 684382Sbinkertn@umich.edu 696654Snate@binkert.orgbuild_env = [(opt, env[opt]) for opt in export_vars] 705517Snate@binkert.org 718614Sgblack@eecs.umich.edufrom m5.util import code_formatter, compareVersions 727674Snate@binkert.org 736143Snate@binkert.org######################################################################## 746143Snate@binkert.org# Code for adding source files of various types 756143Snate@binkert.org# 7612302Sgabeblack@google.com# When specifying a source file of some type, a set of tags can be 7712302Sgabeblack@google.com# specified for that file. 7812302Sgabeblack@google.com 7912371Sgabeblack@google.comclass SourceFilter(object): 8012371Sgabeblack@google.com def __init__(self, predicate): 8112371Sgabeblack@google.com self.predicate = predicate 8212371Sgabeblack@google.com 8312371Sgabeblack@google.com def __or__(self, other): 8412371Sgabeblack@google.com return SourceFilter(lambda tags: self.predicate(tags) or 8512371Sgabeblack@google.com other.predicate(tags)) 8612371Sgabeblack@google.com 8712371Sgabeblack@google.com def __and__(self, other): 8812371Sgabeblack@google.com return SourceFilter(lambda tags: self.predicate(tags) and 8912371Sgabeblack@google.com other.predicate(tags)) 9012371Sgabeblack@google.com 9112371Sgabeblack@google.comdef with_tags_that(predicate): 9212371Sgabeblack@google.com '''Return a list of sources with tags that satisfy a predicate.''' 9312371Sgabeblack@google.com return SourceFilter(predicate) 9412371Sgabeblack@google.com 9512371Sgabeblack@google.comdef with_any_tags(*tags): 9612371Sgabeblack@google.com '''Return a list of sources with any of the supplied tags.''' 9712371Sgabeblack@google.com return SourceFilter(lambda stags: len(set(tags) & stags) > 0) 9812371Sgabeblack@google.com 9912371Sgabeblack@google.comdef with_all_tags(*tags): 10012371Sgabeblack@google.com '''Return a list of sources with all of the supplied tags.''' 10112371Sgabeblack@google.com return SourceFilter(lambda stags: set(tags) <= stags) 10212371Sgabeblack@google.com 10312371Sgabeblack@google.comdef with_tag(tag): 10412371Sgabeblack@google.com '''Return a list of sources with the supplied tag.''' 10512371Sgabeblack@google.com return SourceFilter(lambda stags: tag in stags) 10612371Sgabeblack@google.com 10712371Sgabeblack@google.comdef without_tags(*tags): 10812371Sgabeblack@google.com '''Return a list of sources without any of the supplied tags.''' 10912371Sgabeblack@google.com return SourceFilter(lambda stags: len(set(tags) & stags) == 0) 11012371Sgabeblack@google.com 11112371Sgabeblack@google.comdef without_tag(tag): 11212371Sgabeblack@google.com '''Return a list of sources with the supplied tag.''' 11312371Sgabeblack@google.com return SourceFilter(lambda stags: tag not in stags) 11412371Sgabeblack@google.com 11512371Sgabeblack@google.comsource_filter_factories = { 11612371Sgabeblack@google.com 'with_tags_that': with_tags_that, 11712371Sgabeblack@google.com 'with_any_tags': with_any_tags, 11812371Sgabeblack@google.com 'with_all_tags': with_all_tags, 11912371Sgabeblack@google.com 'with_tag': with_tag, 12012371Sgabeblack@google.com 'without_tags': without_tags, 12112371Sgabeblack@google.com 'without_tag': without_tag, 12212371Sgabeblack@google.com} 12312371Sgabeblack@google.com 12412371Sgabeblack@google.comExport(source_filter_factories) 12512371Sgabeblack@google.com 12612302Sgabeblack@google.comclass SourceList(list): 12712371Sgabeblack@google.com def apply_filter(self, f): 12812302Sgabeblack@google.com def match(source): 12912371Sgabeblack@google.com return f.predicate(source.tags) 13012302Sgabeblack@google.com return SourceList(filter(match, self)) 13112302Sgabeblack@google.com 13212371Sgabeblack@google.com def __getattr__(self, name): 13312371Sgabeblack@google.com func = source_filter_factories.get(name, None) 13412371Sgabeblack@google.com if not func: 13512371Sgabeblack@google.com raise AttributeError 13612302Sgabeblack@google.com 13712371Sgabeblack@google.com @functools.wraps(func) 13812371Sgabeblack@google.com def wrapper(*args, **kwargs): 13912371Sgabeblack@google.com return self.apply_filter(func(*args, **kwargs)) 14012371Sgabeblack@google.com return wrapper 14111983Sgabeblack@google.com 1426143Snate@binkert.orgclass SourceMeta(type): 1438233Snate@binkert.org '''Meta class for source files that keeps track of all files of a 14412302Sgabeblack@google.com particular type.''' 1456143Snate@binkert.org def __init__(cls, name, bases, dict): 1466143Snate@binkert.org super(SourceMeta, cls).__init__(name, bases, dict) 14712302Sgabeblack@google.com cls.all = SourceList() 1484762Snate@binkert.org 1496143Snate@binkert.orgclass SourceFile(object): 1508233Snate@binkert.org '''Base object that encapsulates the notion of a source file. 1518233Snate@binkert.org This includes, the source node, target node, various manipulations 15212302Sgabeblack@google.com of those. A source file also specifies a set of tags which 15312302Sgabeblack@google.com describing arbitrary properties of the source file.''' 1546143Snate@binkert.org __metaclass__ = SourceMeta 15512362Sgabeblack@google.com 15612362Sgabeblack@google.com static_objs = {} 15712362Sgabeblack@google.com shared_objs = {} 15812362Sgabeblack@google.com 15912302Sgabeblack@google.com def __init__(self, source, tags=None, add_tags=None): 16012302Sgabeblack@google.com if tags is None: 16112302Sgabeblack@google.com tags='gem5 lib' 16212302Sgabeblack@google.com if isinstance(tags, basestring): 16312302Sgabeblack@google.com tags = set([tags]) 16412363Sgabeblack@google.com if not isinstance(tags, set): 16512363Sgabeblack@google.com tags = set(tags) 16612363Sgabeblack@google.com self.tags = tags 16712363Sgabeblack@google.com 16812302Sgabeblack@google.com if add_tags: 16912363Sgabeblack@google.com if isinstance(add_tags, basestring): 17012363Sgabeblack@google.com add_tags = set([add_tags]) 17112363Sgabeblack@google.com if not isinstance(add_tags, set): 17212363Sgabeblack@google.com add_tags = set(add_tags) 17312363Sgabeblack@google.com self.tags |= add_tags 1748233Snate@binkert.org 1756143Snate@binkert.org tnode = source 1766143Snate@binkert.org if not isinstance(source, SCons.Node.FS.File): 1776143Snate@binkert.org tnode = File(source) 1786143Snate@binkert.org 1796143Snate@binkert.org self.tnode = tnode 1806143Snate@binkert.org self.snode = tnode.srcnode() 1816143Snate@binkert.org 1826143Snate@binkert.org for base in type(self).__mro__: 1836143Snate@binkert.org if issubclass(base, SourceFile): 1847065Snate@binkert.org base.all.append(self) 1856143Snate@binkert.org 18612362Sgabeblack@google.com def static(self, env): 18712362Sgabeblack@google.com key = (self.tnode, env['OBJSUFFIX']) 18812362Sgabeblack@google.com if not key in self.static_objs: 18912362Sgabeblack@google.com self.static_objs[key] = env.StaticObject(self.tnode) 19012362Sgabeblack@google.com return self.static_objs[key] 19112362Sgabeblack@google.com 19212362Sgabeblack@google.com def shared(self, env): 19312362Sgabeblack@google.com key = (self.tnode, env['OBJSUFFIX']) 19412362Sgabeblack@google.com if not key in self.shared_objs: 19512362Sgabeblack@google.com self.shared_objs[key] = env.SharedObject(self.tnode) 19612362Sgabeblack@google.com return self.shared_objs[key] 19712362Sgabeblack@google.com 1988233Snate@binkert.org @property 1998233Snate@binkert.org def filename(self): 2008233Snate@binkert.org return str(self.tnode) 2018233Snate@binkert.org 2028233Snate@binkert.org @property 2038233Snate@binkert.org def dirname(self): 2048233Snate@binkert.org return dirname(self.filename) 2058233Snate@binkert.org 2068233Snate@binkert.org @property 2078233Snate@binkert.org def basename(self): 2088233Snate@binkert.org return basename(self.filename) 2098233Snate@binkert.org 2108233Snate@binkert.org @property 2118233Snate@binkert.org def extname(self): 2128233Snate@binkert.org index = self.basename.rfind('.') 2138233Snate@binkert.org if index <= 0: 2148233Snate@binkert.org # dot files aren't extensions 2158233Snate@binkert.org return self.basename, None 2168233Snate@binkert.org 2178233Snate@binkert.org return self.basename[:index], self.basename[index+1:] 2188233Snate@binkert.org 2196143Snate@binkert.org def __lt__(self, other): return self.filename < other.filename 2206143Snate@binkert.org def __le__(self, other): return self.filename <= other.filename 2216143Snate@binkert.org def __gt__(self, other): return self.filename > other.filename 2226143Snate@binkert.org def __ge__(self, other): return self.filename >= other.filename 2236143Snate@binkert.org def __eq__(self, other): return self.filename == other.filename 2246143Snate@binkert.org def __ne__(self, other): return self.filename != other.filename 2259982Satgutier@umich.edu 22613576Sciro.santilli@arm.comdef blobToCpp(data, symbol, cpp_code, hpp_code=None, namespace=None): 22713576Sciro.santilli@arm.com ''' 22813576Sciro.santilli@arm.com Convert bytes data into C++ .cpp and .hh uint8_t byte array 22913576Sciro.santilli@arm.com code containing that binary data. 23013576Sciro.santilli@arm.com 23113576Sciro.santilli@arm.com :param data: binary data to be converted to C++ 23213576Sciro.santilli@arm.com :param symbol: name of the symbol 23313576Sciro.santilli@arm.com :param cpp_code: append the generated cpp_code to this object 23413576Sciro.santilli@arm.com :param hpp_code: append the generated hpp_code to this object 23513576Sciro.santilli@arm.com If None, ignore it. Otherwise, also include it 23613576Sciro.santilli@arm.com in the .cpp file. 23713576Sciro.santilli@arm.com :param namespace: namespace to put the symbol into. If None, 23813576Sciro.santilli@arm.com don't put the symbols into any namespace. 23913576Sciro.santilli@arm.com ''' 24013576Sciro.santilli@arm.com symbol_len_declaration = 'const std::size_t {}_len'.format(symbol) 24113576Sciro.santilli@arm.com symbol_declaration = 'const std::uint8_t {}[]'.format(symbol) 24213576Sciro.santilli@arm.com if hpp_code is not None: 24313576Sciro.santilli@arm.com cpp_code('''\ 24413576Sciro.santilli@arm.com#include "blobs/{}.hh" 24513576Sciro.santilli@arm.com'''.format(symbol)) 24613576Sciro.santilli@arm.com hpp_code('''\ 24713576Sciro.santilli@arm.com#include <cstddef> 24813576Sciro.santilli@arm.com#include <cstdint> 24913576Sciro.santilli@arm.com''') 25013576Sciro.santilli@arm.com if namespace is not None: 25113576Sciro.santilli@arm.com hpp_code('namespace {} {{'.format(namespace)) 25213576Sciro.santilli@arm.com hpp_code('extern ' + symbol_len_declaration + ';') 25313576Sciro.santilli@arm.com hpp_code('extern ' + symbol_declaration + ';') 25413576Sciro.santilli@arm.com if namespace is not None: 25513576Sciro.santilli@arm.com hpp_code('}') 25613576Sciro.santilli@arm.com if namespace is not None: 25713576Sciro.santilli@arm.com cpp_code('namespace {} {{'.format(namespace)) 25813576Sciro.santilli@arm.com cpp_code(symbol_len_declaration + ' = {};'.format(len(data))) 25913576Sciro.santilli@arm.com cpp_code(symbol_declaration + ' = {') 26013576Sciro.santilli@arm.com cpp_code.indent() 26113576Sciro.santilli@arm.com step = 16 26213576Sciro.santilli@arm.com for i in xrange(0, len(data), step): 26313576Sciro.santilli@arm.com x = array.array('B', data[i:i+step]) 26413576Sciro.santilli@arm.com cpp_code(''.join('%d,' % d for d in x)) 26513576Sciro.santilli@arm.com cpp_code.dedent() 26613576Sciro.santilli@arm.com cpp_code('};') 26713576Sciro.santilli@arm.com if namespace is not None: 26813576Sciro.santilli@arm.com cpp_code('}') 26913576Sciro.santilli@arm.com 27013576Sciro.santilli@arm.comdef Blob(blob_path, symbol): 27113576Sciro.santilli@arm.com ''' 27213576Sciro.santilli@arm.com Embed an arbitrary blob into the gem5 executable, 27313576Sciro.santilli@arm.com and make it accessible to C++ as a byte array. 27413576Sciro.santilli@arm.com ''' 27513576Sciro.santilli@arm.com blob_path = os.path.abspath(blob_path) 27613576Sciro.santilli@arm.com blob_out_dir = os.path.join(env['BUILDDIR'], 'blobs') 27713576Sciro.santilli@arm.com path_noext = joinpath(blob_out_dir, symbol) 27813576Sciro.santilli@arm.com cpp_path = path_noext + '.cc' 27913576Sciro.santilli@arm.com hpp_path = path_noext + '.hh' 28013576Sciro.santilli@arm.com def embedBlob(target, source, env): 28113576Sciro.santilli@arm.com data = file(str(source[0]), 'r').read() 28213576Sciro.santilli@arm.com cpp_code = code_formatter() 28313576Sciro.santilli@arm.com hpp_code = code_formatter() 28413576Sciro.santilli@arm.com blobToCpp(data, symbol, cpp_code, hpp_code, namespace='Blobs') 28513576Sciro.santilli@arm.com cpp_path = str(target[0]) 28613576Sciro.santilli@arm.com hpp_path = str(target[1]) 28713576Sciro.santilli@arm.com cpp_dir = os.path.split(cpp_path)[0] 28813576Sciro.santilli@arm.com if not os.path.exists(cpp_dir): 28913576Sciro.santilli@arm.com os.makedirs(cpp_dir) 29013576Sciro.santilli@arm.com cpp_code.write(cpp_path) 29113576Sciro.santilli@arm.com hpp_code.write(hpp_path) 29213576Sciro.santilli@arm.com env.Command([cpp_path, hpp_path], blob_path, 29313576Sciro.santilli@arm.com MakeAction(embedBlob, Transform("EMBED BLOB"))) 29413576Sciro.santilli@arm.com Source(cpp_path) 29513576Sciro.santilli@arm.com 29613577Sciro.santilli@arm.comdef GdbXml(xml_id, symbol): 29713577Sciro.santilli@arm.com Blob(joinpath(gdb_xml_dir, xml_id), symbol) 29813577Sciro.santilli@arm.com 2996143Snate@binkert.orgclass Source(SourceFile): 30012302Sgabeblack@google.com ungrouped_tag = 'No link group' 30112302Sgabeblack@google.com source_groups = set() 30212302Sgabeblack@google.com 30312302Sgabeblack@google.com _current_group_tag = ungrouped_tag 30412302Sgabeblack@google.com 30512302Sgabeblack@google.com @staticmethod 30612302Sgabeblack@google.com def link_group_tag(group): 30712302Sgabeblack@google.com return 'link group: %s' % group 30811983Sgabeblack@google.com 30911983Sgabeblack@google.com @classmethod 31011983Sgabeblack@google.com def set_group(cls, group): 31112302Sgabeblack@google.com new_tag = Source.link_group_tag(group) 31212302Sgabeblack@google.com Source._current_group_tag = new_tag 31312302Sgabeblack@google.com Source.source_groups.add(group) 31412302Sgabeblack@google.com 31512302Sgabeblack@google.com def _add_link_group_tag(self): 31612302Sgabeblack@google.com self.tags.add(Source._current_group_tag) 31711983Sgabeblack@google.com 3186143Snate@binkert.org '''Add a c/c++ source file to the build''' 31912305Sgabeblack@google.com def __init__(self, source, tags=None, add_tags=None): 32012302Sgabeblack@google.com '''specify the source file, and any tags''' 32112302Sgabeblack@google.com super(Source, self).__init__(source, tags, add_tags) 32212302Sgabeblack@google.com self._add_link_group_tag() 3236143Snate@binkert.org 3246143Snate@binkert.orgclass PySource(SourceFile): 3256143Snate@binkert.org '''Add a python source file to the named package''' 3265522Snate@binkert.org invalid_sym_char = re.compile('[^A-z0-9_]') 3276143Snate@binkert.org modules = {} 3286143Snate@binkert.org tnodes = {} 3296143Snate@binkert.org symnames = {} 3309982Satgutier@umich.edu 33112302Sgabeblack@google.com def __init__(self, package, source, tags=None, add_tags=None): 33212302Sgabeblack@google.com '''specify the python package, the source file, and any tags''' 33312302Sgabeblack@google.com super(PySource, self).__init__(source, tags, add_tags) 3346143Snate@binkert.org 3356143Snate@binkert.org modname,ext = self.extname 3366143Snate@binkert.org assert ext == 'py' 3376143Snate@binkert.org 3385522Snate@binkert.org if package: 3395522Snate@binkert.org path = package.split('.') 3405522Snate@binkert.org else: 3415522Snate@binkert.org path = [] 3425604Snate@binkert.org 3435604Snate@binkert.org modpath = path[:] 3446143Snate@binkert.org if modname != '__init__': 3456143Snate@binkert.org modpath += [ modname ] 3464762Snate@binkert.org modpath = '.'.join(modpath) 3474762Snate@binkert.org 3486143Snate@binkert.org arcpath = path + [ self.basename ] 3496727Ssteve.reinhardt@amd.com abspath = self.snode.abspath 3506727Ssteve.reinhardt@amd.com if not exists(abspath): 3516727Ssteve.reinhardt@amd.com abspath = self.tnode.abspath 3524762Snate@binkert.org 3536143Snate@binkert.org self.package = package 3546143Snate@binkert.org self.modname = modname 3556143Snate@binkert.org self.modpath = modpath 3566143Snate@binkert.org self.arcname = joinpath(*arcpath) 3576727Ssteve.reinhardt@amd.com self.abspath = abspath 3586143Snate@binkert.org self.compiled = File(self.filename + 'c') 3597674Snate@binkert.org self.cpp = File(self.filename + '.cc') 3607674Snate@binkert.org self.symname = PySource.invalid_sym_char.sub('_', modpath) 3615604Snate@binkert.org 3626143Snate@binkert.org PySource.modules[modpath] = self 3636143Snate@binkert.org PySource.tnodes[self.tnode] = self 3646143Snate@binkert.org PySource.symnames[self.symname] = self 3654762Snate@binkert.org 3666143Snate@binkert.orgclass SimObject(PySource): 3674762Snate@binkert.org '''Add a SimObject python file as a python source object and add 3684762Snate@binkert.org it to a list of sim object modules''' 3694762Snate@binkert.org 3706143Snate@binkert.org fixed = False 3716143Snate@binkert.org modnames = [] 3724762Snate@binkert.org 37312302Sgabeblack@google.com def __init__(self, source, tags=None, add_tags=None): 37412302Sgabeblack@google.com '''Specify the source file and any tags (automatically in 3758233Snate@binkert.org the m5.objects package)''' 37612302Sgabeblack@google.com super(SimObject, self).__init__('m5.objects', source, tags, add_tags) 3776143Snate@binkert.org if self.fixed: 3786143Snate@binkert.org raise AttributeError, "Too late to call SimObject now." 3794762Snate@binkert.org 3806143Snate@binkert.org bisect.insort_right(SimObject.modnames, self.modname) 3814762Snate@binkert.org 3829396Sandreas.hansson@arm.comclass ProtoBuf(SourceFile): 3839396Sandreas.hansson@arm.com '''Add a Protocol Buffer to build''' 3849396Sandreas.hansson@arm.com 38512302Sgabeblack@google.com def __init__(self, source, tags=None, add_tags=None): 38612302Sgabeblack@google.com '''Specify the source file, and any tags''' 38712302Sgabeblack@google.com super(ProtoBuf, self).__init__(source, tags, add_tags) 3889396Sandreas.hansson@arm.com 3899396Sandreas.hansson@arm.com # Get the file name and the extension 3909396Sandreas.hansson@arm.com modname,ext = self.extname 3919396Sandreas.hansson@arm.com assert ext == 'proto' 3929396Sandreas.hansson@arm.com 3939396Sandreas.hansson@arm.com # Currently, we stick to generating the C++ headers, so we 3949396Sandreas.hansson@arm.com # only need to track the source and header. 3959930Sandreas.hansson@arm.com self.cc_file = File(modname + '.pb.cc') 3969930Sandreas.hansson@arm.com self.hh_file = File(modname + '.pb.h') 3979396Sandreas.hansson@arm.com 3986143Snate@binkert.org 39912797Sgabeblack@google.comexectuable_classes = [] 40012797Sgabeblack@google.comclass ExecutableMeta(type): 40112797Sgabeblack@google.com '''Meta class for Executables.''' 4028235Snate@binkert.org all = [] 40312797Sgabeblack@google.com 40412797Sgabeblack@google.com def __init__(cls, name, bases, d): 40512797Sgabeblack@google.com if not d.pop('abstract', False): 40612797Sgabeblack@google.com ExecutableMeta.all.append(cls) 40712797Sgabeblack@google.com super(ExecutableMeta, cls).__init__(name, bases, d) 40812797Sgabeblack@google.com 40912797Sgabeblack@google.com cls.all = [] 41012797Sgabeblack@google.com 41112797Sgabeblack@google.comclass Executable(object): 41212797Sgabeblack@google.com '''Base class for creating an executable from sources.''' 41312797Sgabeblack@google.com __metaclass__ = ExecutableMeta 41412797Sgabeblack@google.com 41512797Sgabeblack@google.com abstract = True 41612797Sgabeblack@google.com 41712797Sgabeblack@google.com def __init__(self, target, *srcs_and_filts): 41812757Sgabeblack@google.com '''Specify the target name and any sources. Sources that are 41912757Sgabeblack@google.com not SourceFiles are evalued with Source().''' 42012797Sgabeblack@google.com super(Executable, self).__init__() 42112797Sgabeblack@google.com self.all.append(self) 42212797Sgabeblack@google.com self.target = target 42312757Sgabeblack@google.com 42412757Sgabeblack@google.com isFilter = lambda arg: isinstance(arg, SourceFilter) 42512757Sgabeblack@google.com self.filters = filter(isFilter, srcs_and_filts) 42612757Sgabeblack@google.com sources = filter(lambda a: not isFilter(a), srcs_and_filts) 4278235Snate@binkert.org 42812302Sgabeblack@google.com srcs = SourceList() 4298235Snate@binkert.org for src in sources: 4308235Snate@binkert.org if not isinstance(src, SourceFile): 43112757Sgabeblack@google.com src = Source(src, tags=[]) 4328235Snate@binkert.org srcs.append(src) 4338235Snate@binkert.org 4348235Snate@binkert.org self.sources = srcs 43512757Sgabeblack@google.com self.dir = Dir('.') 43612313Sgabeblack@google.com 43712797Sgabeblack@google.com def path(self, env): 43812797Sgabeblack@google.com return self.dir.File(self.target + '.' + env['EXE_SUFFIX']) 43912797Sgabeblack@google.com 44012797Sgabeblack@google.com def srcs_to_objs(self, env, sources): 44112797Sgabeblack@google.com return list([ s.static(env) for s in sources ]) 44212797Sgabeblack@google.com 44312797Sgabeblack@google.com @classmethod 44412797Sgabeblack@google.com def declare_all(cls, env): 44512797Sgabeblack@google.com return list([ instance.declare(env) for instance in cls.all ]) 44612797Sgabeblack@google.com 44712797Sgabeblack@google.com def declare(self, env, objs=None): 44812797Sgabeblack@google.com if objs is None: 44912797Sgabeblack@google.com objs = self.srcs_to_objs(env, self.sources) 45012797Sgabeblack@google.com 45112797Sgabeblack@google.com if env['STRIP_EXES']: 45212797Sgabeblack@google.com stripped = self.path(env) 45312797Sgabeblack@google.com unstripped = env.File(str(stripped) + '.unstripped') 45412797Sgabeblack@google.com if sys.platform == 'sunos5': 45512797Sgabeblack@google.com cmd = 'cp $SOURCE $TARGET; strip $TARGET' 45612797Sgabeblack@google.com else: 45712797Sgabeblack@google.com cmd = 'strip $SOURCE -o $TARGET' 45812797Sgabeblack@google.com env.Program(unstripped, objs) 45912797Sgabeblack@google.com return env.Command(stripped, unstripped, 46012797Sgabeblack@google.com MakeAction(cmd, Transform("STRIP"))) 46112797Sgabeblack@google.com else: 46212797Sgabeblack@google.com return env.Program(self.path(env), objs) 46312797Sgabeblack@google.com 46412797Sgabeblack@google.comclass UnitTest(Executable): 46512797Sgabeblack@google.com '''Create a UnitTest''' 46612797Sgabeblack@google.com def __init__(self, target, *srcs_and_filts, **kwargs): 46712797Sgabeblack@google.com super(UnitTest, self).__init__(target, *srcs_and_filts) 46812797Sgabeblack@google.com 46912797Sgabeblack@google.com self.main = kwargs.get('main', False) 47012797Sgabeblack@google.com 47112797Sgabeblack@google.com def declare(self, env): 47212797Sgabeblack@google.com sources = list(self.sources) 47312797Sgabeblack@google.com for f in self.filters: 47412797Sgabeblack@google.com sources = Source.all.apply_filter(f) 47512797Sgabeblack@google.com objs = self.srcs_to_objs(env, sources) + env['STATIC_OBJS'] 47612797Sgabeblack@google.com if self.main: 47712797Sgabeblack@google.com objs += env['MAIN_OBJS'] 47812797Sgabeblack@google.com return super(UnitTest, self).declare(env, objs) 47912797Sgabeblack@google.com 48012797Sgabeblack@google.comclass GTest(Executable): 48112313Sgabeblack@google.com '''Create a unit test based on the google test framework.''' 48212313Sgabeblack@google.com all = [] 48312797Sgabeblack@google.com def __init__(self, *srcs_and_filts, **kwargs): 48412797Sgabeblack@google.com super(GTest, self).__init__(*srcs_and_filts) 48512797Sgabeblack@google.com 48612371Sgabeblack@google.com self.skip_lib = kwargs.pop('skip_lib', False) 4875584Snate@binkert.org 48812797Sgabeblack@google.com @classmethod 48912797Sgabeblack@google.com def declare_all(cls, env): 49012797Sgabeblack@google.com env = env.Clone() 49112797Sgabeblack@google.com env.Append(LIBS=env['GTEST_LIBS']) 49212797Sgabeblack@google.com env.Append(CPPFLAGS=env['GTEST_CPPFLAGS']) 49312797Sgabeblack@google.com env['GTEST_LIB_SOURCES'] = Source.all.with_tag('gtest lib') 49412797Sgabeblack@google.com env['GTEST_OUT_DIR'] = \ 49512797Sgabeblack@google.com Dir(env['BUILDDIR']).Dir('unittests.' + env['EXE_SUFFIX']) 49612797Sgabeblack@google.com return super(GTest, cls).declare_all(env) 49712797Sgabeblack@google.com 49812797Sgabeblack@google.com def declare(self, env): 49912797Sgabeblack@google.com sources = list(self.sources) 50012797Sgabeblack@google.com if not self.skip_lib: 50112797Sgabeblack@google.com sources += env['GTEST_LIB_SOURCES'] 50212797Sgabeblack@google.com for f in self.filters: 50312797Sgabeblack@google.com sources += Source.all.apply_filter(f) 50412797Sgabeblack@google.com objs = self.srcs_to_objs(env, sources) 50512797Sgabeblack@google.com 50612797Sgabeblack@google.com binary = super(GTest, self).declare(env, objs) 50712797Sgabeblack@google.com 50812797Sgabeblack@google.com out_dir = env['GTEST_OUT_DIR'] 50912797Sgabeblack@google.com xml_file = out_dir.Dir(str(self.dir)).File(self.target + '.xml') 51012797Sgabeblack@google.com AlwaysBuild(env.Command(xml_file, binary, 51112797Sgabeblack@google.com "${SOURCES[0]} --gtest_output=xml:${TARGETS[0]}")) 51212797Sgabeblack@google.com 51312797Sgabeblack@google.com return binary 51412797Sgabeblack@google.com 51512797Sgabeblack@google.comclass Gem5(Executable): 51612797Sgabeblack@google.com '''Create a gem5 executable.''' 51712797Sgabeblack@google.com 51812797Sgabeblack@google.com def __init__(self, target): 51912797Sgabeblack@google.com super(Gem5, self).__init__(target) 52012797Sgabeblack@google.com 52112797Sgabeblack@google.com def declare(self, env): 52212797Sgabeblack@google.com objs = env['MAIN_OBJS'] + env['STATIC_OBJS'] 52312797Sgabeblack@google.com return super(Gem5, self).declare(env, objs) 52412797Sgabeblack@google.com 52512797Sgabeblack@google.com 5264382Sbinkertn@umich.edu# Children should have access 52713576Sciro.santilli@arm.comExport('Blob') 52813577Sciro.santilli@arm.comExport('GdbXml') 5294202Sbinkertn@umich.eduExport('Source') 5304382Sbinkertn@umich.eduExport('PySource') 5314382Sbinkertn@umich.eduExport('SimObject') 5329396Sandreas.hansson@arm.comExport('ProtoBuf') 53312797Sgabeblack@google.comExport('Executable') 5345584Snate@binkert.orgExport('UnitTest') 53512313Sgabeblack@google.comExport('GTest') 5364382Sbinkertn@umich.edu 5374382Sbinkertn@umich.edu######################################################################## 5384382Sbinkertn@umich.edu# 5398232Snate@binkert.org# Debug Flags 5405192Ssaidi@eecs.umich.edu# 5418232Snate@binkert.orgdebug_flags = {} 5428232Snate@binkert.orgdef DebugFlag(name, desc=None): 5438232Snate@binkert.org if name in debug_flags: 5445192Ssaidi@eecs.umich.edu raise AttributeError, "Flag %s already specified" % name 5458232Snate@binkert.org debug_flags[name] = (name, (), desc) 5465192Ssaidi@eecs.umich.edu 5475799Snate@binkert.orgdef CompoundFlag(name, flags, desc=None): 5488232Snate@binkert.org if name in debug_flags: 5495192Ssaidi@eecs.umich.edu raise AttributeError, "Flag %s already specified" % name 5505192Ssaidi@eecs.umich.edu 5515192Ssaidi@eecs.umich.edu compound = tuple(flags) 5528232Snate@binkert.org debug_flags[name] = (name, compound, desc) 5535192Ssaidi@eecs.umich.edu 5548232Snate@binkert.orgExport('DebugFlag') 5555192Ssaidi@eecs.umich.eduExport('CompoundFlag') 5565192Ssaidi@eecs.umich.edu 5575192Ssaidi@eecs.umich.edu######################################################################## 5585192Ssaidi@eecs.umich.edu# 5594382Sbinkertn@umich.edu# Set some compiler variables 5604382Sbinkertn@umich.edu# 5614382Sbinkertn@umich.edu 5622667Sstever@eecs.umich.edu# Include file paths are rooted in this directory. SCons will 5632667Sstever@eecs.umich.edu# automatically expand '.' to refer to both the source directory and 5642667Sstever@eecs.umich.edu# the corresponding build directory to pick up generated include 5652667Sstever@eecs.umich.edu# files. 5662667Sstever@eecs.umich.eduenv.Append(CPPPATH=Dir('.')) 5672667Sstever@eecs.umich.edu 5685742Snate@binkert.orgfor extra_dir in extras_dir_list: 5695742Snate@binkert.org env.Append(CPPPATH=Dir(extra_dir)) 5705742Snate@binkert.org 5715793Snate@binkert.org# Workaround for bug in SCons version > 0.97d20071212 5728334Snate@binkert.org# Scons bug id: 2006 gem5 Bug id: 308 5735793Snate@binkert.orgfor root, dirs, files in os.walk(base_dir, topdown=True): 5745793Snate@binkert.org Dir(root[len(base_dir) + 1:]) 5755793Snate@binkert.org 5764382Sbinkertn@umich.edu######################################################################## 5774762Snate@binkert.org# 5785344Sstever@gmail.com# Walk the tree and execute all SConscripts in subdirectories 5794382Sbinkertn@umich.edu# 5805341Sstever@gmail.com 5815742Snate@binkert.orghere = Dir('.').srcnode().abspath 5825742Snate@binkert.orgfor root, dirs, files in os.walk(base_dir, topdown=True): 5835742Snate@binkert.org if root == here: 5845742Snate@binkert.org # we don't want to recurse back into this SConscript 5855742Snate@binkert.org continue 5864762Snate@binkert.org 5875742Snate@binkert.org if 'SConscript' in files: 5885742Snate@binkert.org build_dir = joinpath(env['BUILDDIR'], root[len(base_dir) + 1:]) 58911984Sgabeblack@google.com Source.set_group(build_dir) 5907722Sgblack@eecs.umich.edu SConscript(joinpath(root, 'SConscript'), variant_dir=build_dir) 5915742Snate@binkert.org 5925742Snate@binkert.orgfor extra_dir in extras_dir_list: 5935742Snate@binkert.org prefix_len = len(dirname(extra_dir)) + 1 5949930Sandreas.hansson@arm.com 5959930Sandreas.hansson@arm.com # Also add the corresponding build directory to pick up generated 5969930Sandreas.hansson@arm.com # include files. 5979930Sandreas.hansson@arm.com env.Append(CPPPATH=Dir(joinpath(env['BUILDDIR'], extra_dir[prefix_len:]))) 5989930Sandreas.hansson@arm.com 5995742Snate@binkert.org for root, dirs, files in os.walk(extra_dir, topdown=True): 6008242Sbradley.danofsky@amd.com # if build lives in the extras directory, don't walk down it 6018242Sbradley.danofsky@amd.com if 'build' in dirs: 6028242Sbradley.danofsky@amd.com dirs.remove('build') 6038242Sbradley.danofsky@amd.com 6045341Sstever@gmail.com if 'SConscript' in files: 6055742Snate@binkert.org build_dir = joinpath(env['BUILDDIR'], root[prefix_len:]) 6067722Sgblack@eecs.umich.edu SConscript(joinpath(root, 'SConscript'), variant_dir=build_dir) 6074773Snate@binkert.org 6086108Snate@binkert.orgfor opt in export_vars: 6091858SN/A env.ConfigFile(opt) 6101085SN/A 6116658Snate@binkert.orgdef makeTheISA(source, target, env): 6126658Snate@binkert.org isas = [ src.get_contents() for src in source ] 6137673Snate@binkert.org target_isa = env['TARGET_ISA'] 6146658Snate@binkert.org def define(isa): 6156658Snate@binkert.org return isa.upper() + '_ISA' 61611308Santhony.gutierrez@amd.com 6176658Snate@binkert.org def namespace(isa): 61811308Santhony.gutierrez@amd.com return isa[0].upper() + isa[1:].lower() + 'ISA' 6196658Snate@binkert.org 6206658Snate@binkert.org 6217673Snate@binkert.org code = code_formatter() 6227673Snate@binkert.org code('''\ 6237673Snate@binkert.org#ifndef __CONFIG_THE_ISA_HH__ 6247673Snate@binkert.org#define __CONFIG_THE_ISA_HH__ 6257673Snate@binkert.org 6267673Snate@binkert.org''') 6277673Snate@binkert.org 62810467Sandreas.hansson@arm.com # create defines for the preprocessing and compile-time determination 6296658Snate@binkert.org for i,isa in enumerate(isas): 6307673Snate@binkert.org code('#define $0 $1', define(isa), i + 1) 63110467Sandreas.hansson@arm.com code() 63210467Sandreas.hansson@arm.com 63310467Sandreas.hansson@arm.com # create an enum for any run-time determination of the ISA, we 63410467Sandreas.hansson@arm.com # reuse the same name as the namespaces 63510467Sandreas.hansson@arm.com code('enum class Arch {') 63610467Sandreas.hansson@arm.com for i,isa in enumerate(isas): 63710467Sandreas.hansson@arm.com if i + 1 == len(isas): 63810467Sandreas.hansson@arm.com code(' $0 = $1', namespace(isa), define(isa)) 63910467Sandreas.hansson@arm.com else: 64010467Sandreas.hansson@arm.com code(' $0 = $1,', namespace(isa), define(isa)) 64110467Sandreas.hansson@arm.com code('};') 6427673Snate@binkert.org 6437673Snate@binkert.org code(''' 6447673Snate@binkert.org 6457673Snate@binkert.org#define THE_ISA ${{define(target_isa)}} 6467673Snate@binkert.org#define TheISA ${{namespace(target_isa)}} 6479048SAli.Saidi@ARM.com#define THE_ISA_STR "${{target_isa}}" 6487673Snate@binkert.org 6497673Snate@binkert.org#endif // __CONFIG_THE_ISA_HH__''') 6507673Snate@binkert.org 6517673Snate@binkert.org code.write(str(target[0])) 6526658Snate@binkert.org 6537756SAli.Saidi@ARM.comenv.Command('config/the_isa.hh', map(Value, all_isa_list), 6547816Ssteve.reinhardt@amd.com MakeAction(makeTheISA, Transform("CFG ISA", 0))) 6556658Snate@binkert.org 65611308Santhony.gutierrez@amd.comdef makeTheGPUISA(source, target, env): 65711308Santhony.gutierrez@amd.com isas = [ src.get_contents() for src in source ] 65811308Santhony.gutierrez@amd.com target_gpu_isa = env['TARGET_GPU_ISA'] 65911308Santhony.gutierrez@amd.com def define(isa): 66011308Santhony.gutierrez@amd.com return isa.upper() + '_ISA' 66111308Santhony.gutierrez@amd.com 66211308Santhony.gutierrez@amd.com def namespace(isa): 66311308Santhony.gutierrez@amd.com return isa[0].upper() + isa[1:].lower() + 'ISA' 66411308Santhony.gutierrez@amd.com 66511308Santhony.gutierrez@amd.com 66611308Santhony.gutierrez@amd.com code = code_formatter() 66711308Santhony.gutierrez@amd.com code('''\ 66811308Santhony.gutierrez@amd.com#ifndef __CONFIG_THE_GPU_ISA_HH__ 66911308Santhony.gutierrez@amd.com#define __CONFIG_THE_GPU_ISA_HH__ 67011308Santhony.gutierrez@amd.com 67111308Santhony.gutierrez@amd.com''') 67211308Santhony.gutierrez@amd.com 67311308Santhony.gutierrez@amd.com # create defines for the preprocessing and compile-time determination 67411308Santhony.gutierrez@amd.com for i,isa in enumerate(isas): 67511308Santhony.gutierrez@amd.com code('#define $0 $1', define(isa), i + 1) 67611308Santhony.gutierrez@amd.com code() 67711308Santhony.gutierrez@amd.com 67811308Santhony.gutierrez@amd.com # create an enum for any run-time determination of the ISA, we 67911308Santhony.gutierrez@amd.com # reuse the same name as the namespaces 68011308Santhony.gutierrez@amd.com code('enum class GPUArch {') 68111308Santhony.gutierrez@amd.com for i,isa in enumerate(isas): 68211308Santhony.gutierrez@amd.com if i + 1 == len(isas): 68311308Santhony.gutierrez@amd.com code(' $0 = $1', namespace(isa), define(isa)) 68411308Santhony.gutierrez@amd.com else: 68511308Santhony.gutierrez@amd.com code(' $0 = $1,', namespace(isa), define(isa)) 68611308Santhony.gutierrez@amd.com code('};') 68711308Santhony.gutierrez@amd.com 68811308Santhony.gutierrez@amd.com code(''' 68911308Santhony.gutierrez@amd.com 69011308Santhony.gutierrez@amd.com#define THE_GPU_ISA ${{define(target_gpu_isa)}} 69111308Santhony.gutierrez@amd.com#define TheGpuISA ${{namespace(target_gpu_isa)}} 69211308Santhony.gutierrez@amd.com#define THE_GPU_ISA_STR "${{target_gpu_isa}}" 69311308Santhony.gutierrez@amd.com 69411308Santhony.gutierrez@amd.com#endif // __CONFIG_THE_GPU_ISA_HH__''') 69511308Santhony.gutierrez@amd.com 69611308Santhony.gutierrez@amd.com code.write(str(target[0])) 69711308Santhony.gutierrez@amd.com 69811308Santhony.gutierrez@amd.comenv.Command('config/the_gpu_isa.hh', map(Value, all_gpu_isa_list), 69911308Santhony.gutierrez@amd.com MakeAction(makeTheGPUISA, Transform("CFG ISA", 0))) 70011308Santhony.gutierrez@amd.com 7014382Sbinkertn@umich.edu######################################################################## 7024382Sbinkertn@umich.edu# 7034762Snate@binkert.org# Prevent any SimObjects from being added after this point, they 7044762Snate@binkert.org# should all have been added in the SConscripts above 7054762Snate@binkert.org# 7066654Snate@binkert.orgSimObject.fixed = True 7076654Snate@binkert.org 7085517Snate@binkert.orgclass DictImporter(object): 7095517Snate@binkert.org '''This importer takes a dictionary of arbitrary module names that 7105517Snate@binkert.org map to arbitrary filenames.''' 7115517Snate@binkert.org def __init__(self, modules): 7125517Snate@binkert.org self.modules = modules 7135517Snate@binkert.org self.installed = set() 7145517Snate@binkert.org 7155517Snate@binkert.org def __del__(self): 7165517Snate@binkert.org self.unload() 7175517Snate@binkert.org 7185517Snate@binkert.org def unload(self): 7195517Snate@binkert.org import sys 7205517Snate@binkert.org for module in self.installed: 7215517Snate@binkert.org del sys.modules[module] 7225517Snate@binkert.org self.installed = set() 7235517Snate@binkert.org 7245517Snate@binkert.org def find_module(self, fullname, path): 7256654Snate@binkert.org if fullname == 'm5.defines': 7265517Snate@binkert.org return self 7275517Snate@binkert.org 7285517Snate@binkert.org if fullname == 'm5.objects': 7295517Snate@binkert.org return self 7305517Snate@binkert.org 73111802Sandreas.sandberg@arm.com if fullname.startswith('_m5'): 7325517Snate@binkert.org return None 7335517Snate@binkert.org 7346143Snate@binkert.org source = self.modules.get(fullname, None) 7356654Snate@binkert.org if source is not None and fullname.startswith('m5.objects'): 7365517Snate@binkert.org return self 7375517Snate@binkert.org 7385517Snate@binkert.org return None 7395517Snate@binkert.org 7405517Snate@binkert.org def load_module(self, fullname): 7415517Snate@binkert.org mod = imp.new_module(fullname) 7425517Snate@binkert.org sys.modules[fullname] = mod 7435517Snate@binkert.org self.installed.add(fullname) 7445517Snate@binkert.org 7455517Snate@binkert.org mod.__loader__ = self 7465517Snate@binkert.org if fullname == 'm5.objects': 7475517Snate@binkert.org mod.__path__ = fullname.split('.') 7485517Snate@binkert.org return mod 7495517Snate@binkert.org 7506654Snate@binkert.org if fullname == 'm5.defines': 7516654Snate@binkert.org mod.__dict__['buildEnv'] = m5.util.SmartDict(build_env) 7525517Snate@binkert.org return mod 7535517Snate@binkert.org 7546143Snate@binkert.org source = self.modules[fullname] 7556143Snate@binkert.org if source.modname == '__init__': 7566143Snate@binkert.org mod.__path__ = source.modpath 7576727Ssteve.reinhardt@amd.com mod.__file__ = source.abspath 7585517Snate@binkert.org 7596727Ssteve.reinhardt@amd.com exec file(source.abspath, 'r') in mod.__dict__ 7605517Snate@binkert.org 7615517Snate@binkert.org return mod 7625517Snate@binkert.org 7636654Snate@binkert.orgimport m5.SimObject 7646654Snate@binkert.orgimport m5.params 7657673Snate@binkert.orgfrom m5.util import code_formatter 7666654Snate@binkert.org 7676654Snate@binkert.orgm5.SimObject.clear() 7686654Snate@binkert.orgm5.params.clear() 7696654Snate@binkert.org 7705517Snate@binkert.org# install the python importer so we can grab stuff from the source 7715517Snate@binkert.org# tree itself. We can't have SimObjects added after this point or 7725517Snate@binkert.org# else we won't know about them for the rest of the stuff. 7736143Snate@binkert.orgimporter = DictImporter(PySource.modules) 7745517Snate@binkert.orgsys.meta_path[0:0] = [ importer ] 7754762Snate@binkert.org 7765517Snate@binkert.org# import all sim objects so we can populate the all_objects list 7775517Snate@binkert.org# make sure that we're working with a list, then let's sort it 7786143Snate@binkert.orgfor modname in SimObject.modnames: 7796143Snate@binkert.org exec('from m5.objects import %s' % modname) 7805517Snate@binkert.org 7815517Snate@binkert.org# we need to unload all of the currently imported modules so that they 7825517Snate@binkert.org# will be re-imported the next time the sconscript is run 7835517Snate@binkert.orgimporter.unload() 7845517Snate@binkert.orgsys.meta_path.remove(importer) 7855517Snate@binkert.org 7865517Snate@binkert.orgsim_objects = m5.SimObject.allClasses 7875517Snate@binkert.orgall_enums = m5.params.allEnums 7885517Snate@binkert.org 7896143Snate@binkert.orgfor name,obj in sorted(sim_objects.iteritems()): 7905517Snate@binkert.org for param in obj._params.local.values(): 7916654Snate@binkert.org # load the ptype attribute now because it depends on the 7926654Snate@binkert.org # current version of SimObject.allClasses, but when scons 7936654Snate@binkert.org # actually uses the value, all versions of 7946654Snate@binkert.org # SimObject.allClasses will have been loaded 7956654Snate@binkert.org param.ptype 7966654Snate@binkert.org 7974762Snate@binkert.org######################################################################## 7984762Snate@binkert.org# 7994762Snate@binkert.org# calculate extra dependencies 8004762Snate@binkert.org# 8014762Snate@binkert.orgmodule_depends = ["m5", "m5.SimObject", "m5.params"] 8027675Snate@binkert.orgdepends = [ PySource.modules[dep].snode for dep in module_depends ] 80310584Sandreas.hansson@arm.comdepends.sort(key = lambda x: x.name) 8044762Snate@binkert.org 8054762Snate@binkert.org######################################################################## 8064762Snate@binkert.org# 8074762Snate@binkert.org# Commands for the basic automatically generated python files 8084382Sbinkertn@umich.edu# 8094382Sbinkertn@umich.edu 8105517Snate@binkert.org# Generate Python file containing a dict specifying the current 8116654Snate@binkert.org# buildEnv flags. 8125517Snate@binkert.orgdef makeDefinesPyFile(target, source, env): 8138126Sgblack@eecs.umich.edu build_env = source[0].get_contents() 8146654Snate@binkert.org 8157673Snate@binkert.org code = code_formatter() 8166654Snate@binkert.org code(""" 81711802Sandreas.sandberg@arm.comimport _m5.core 8186654Snate@binkert.orgimport m5.util 8196654Snate@binkert.org 8206654Snate@binkert.orgbuildEnv = m5.util.SmartDict($build_env) 8216654Snate@binkert.org 82211802Sandreas.sandberg@arm.comcompileDate = _m5.core.compileDate 8236669Snate@binkert.org_globals = globals() 82411802Sandreas.sandberg@arm.comfor key,val in _m5.core.__dict__.iteritems(): 8256669Snate@binkert.org if key.startswith('flag_'): 8266669Snate@binkert.org flag = key[5:] 8276669Snate@binkert.org _globals[flag] = val 8286669Snate@binkert.orgdel _globals 8296654Snate@binkert.org""") 8307673Snate@binkert.org code.write(target[0].abspath) 8315517Snate@binkert.org 8328126Sgblack@eecs.umich.edudefines_info = Value(build_env) 8335798Snate@binkert.org# Generate a file with all of the compile options in it 8347756SAli.Saidi@ARM.comenv.Command('python/m5/defines.py', defines_info, 8357816Ssteve.reinhardt@amd.com MakeAction(makeDefinesPyFile, Transform("DEFINES", 0))) 8365798Snate@binkert.orgPySource('m5', 'python/m5/defines.py') 8375798Snate@binkert.org 8385517Snate@binkert.org# Generate python file containing info about the M5 source code 8395517Snate@binkert.orgdef makeInfoPyFile(target, source, env): 8407673Snate@binkert.org code = code_formatter() 8415517Snate@binkert.org for src in source: 8425517Snate@binkert.org data = ''.join(file(src.srcnode().abspath, 'r').xreadlines()) 8437673Snate@binkert.org code('$src = ${{repr(data)}}') 8447673Snate@binkert.org code.write(str(target[0])) 8455517Snate@binkert.org 8465798Snate@binkert.org# Generate a file that wraps the basic top level files 8475798Snate@binkert.orgenv.Command('python/m5/info.py', 8488333Snate@binkert.org [ '#/COPYING', '#/LICENSE', '#/README', ], 8497816Ssteve.reinhardt@amd.com MakeAction(makeInfoPyFile, Transform("INFO"))) 8505798Snate@binkert.orgPySource('m5', 'python/m5/info.py') 8515798Snate@binkert.org 8524762Snate@binkert.org######################################################################## 8534762Snate@binkert.org# 8544762Snate@binkert.org# Create all of the SimObject param headers and enum headers 8554762Snate@binkert.org# 8564762Snate@binkert.org 8578596Ssteve.reinhardt@amd.comdef createSimObjectParamStruct(target, source, env): 8585517Snate@binkert.org assert len(target) == 1 and len(source) == 1 8595517Snate@binkert.org 86011997Sgabeblack@google.com name = source[0].get_text_contents() 8615517Snate@binkert.org obj = sim_objects[name] 8625517Snate@binkert.org 8637673Snate@binkert.org code = code_formatter() 8648596Ssteve.reinhardt@amd.com obj.cxx_param_decl(code) 8657673Snate@binkert.org code.write(target[0].abspath) 8665517Snate@binkert.org 86710458Sandreas.hansson@arm.comdef createSimObjectCxxConfig(is_header): 86810458Sandreas.hansson@arm.com def body(target, source, env): 86910458Sandreas.hansson@arm.com assert len(target) == 1 and len(source) == 1 87010458Sandreas.hansson@arm.com 87110458Sandreas.hansson@arm.com name = str(source[0].get_contents()) 87210458Sandreas.hansson@arm.com obj = sim_objects[name] 87310458Sandreas.hansson@arm.com 87410458Sandreas.hansson@arm.com code = code_formatter() 87510458Sandreas.hansson@arm.com obj.cxx_config_param_file(code, is_header) 87610458Sandreas.hansson@arm.com code.write(target[0].abspath) 87710458Sandreas.hansson@arm.com return body 87810458Sandreas.hansson@arm.com 8795517Snate@binkert.orgdef createEnumStrings(target, source, env): 88011996Sgabeblack@google.com assert len(target) == 1 and len(source) == 2 8815517Snate@binkert.org 88211997Sgabeblack@google.com name = source[0].get_text_contents() 88311996Sgabeblack@google.com use_python = source[1].read() 8845517Snate@binkert.org obj = all_enums[name] 8855517Snate@binkert.org 8867673Snate@binkert.org code = code_formatter() 8877673Snate@binkert.org obj.cxx_def(code) 88811996Sgabeblack@google.com if use_python: 88911988Sandreas.sandberg@arm.com obj.pybind_def(code) 8907673Snate@binkert.org code.write(target[0].abspath) 8915517Snate@binkert.org 8928596Ssteve.reinhardt@amd.comdef createEnumDecls(target, source, env): 8935517Snate@binkert.org assert len(target) == 1 and len(source) == 1 8945517Snate@binkert.org 89511997Sgabeblack@google.com name = source[0].get_text_contents() 8965517Snate@binkert.org obj = all_enums[name] 8975517Snate@binkert.org 8987673Snate@binkert.org code = code_formatter() 8997673Snate@binkert.org obj.cxx_decl(code) 9007673Snate@binkert.org code.write(target[0].abspath) 9015517Snate@binkert.org 90211988Sandreas.sandberg@arm.comdef createSimObjectPyBindWrapper(target, source, env): 90311997Sgabeblack@google.com name = source[0].get_text_contents() 9048596Ssteve.reinhardt@amd.com obj = sim_objects[name] 9058596Ssteve.reinhardt@amd.com 9068596Ssteve.reinhardt@amd.com code = code_formatter() 90711988Sandreas.sandberg@arm.com obj.pybind_decl(code) 9088596Ssteve.reinhardt@amd.com code.write(target[0].abspath) 9098596Ssteve.reinhardt@amd.com 9108596Ssteve.reinhardt@amd.com# Generate all of the SimObject param C++ struct header files 9114762Snate@binkert.orgparams_hh_files = [] 9126143Snate@binkert.orgfor name,simobj in sorted(sim_objects.iteritems()): 9136143Snate@binkert.org py_source = PySource.modules[simobj.__module__] 9146143Snate@binkert.org extra_deps = [ py_source.tnode ] 9154762Snate@binkert.org 9164762Snate@binkert.org hh_file = File('params/%s.hh' % name) 9174762Snate@binkert.org params_hh_files.append(hh_file) 9187756SAli.Saidi@ARM.com env.Command(hh_file, Value(name), 9198596Ssteve.reinhardt@amd.com MakeAction(createSimObjectParamStruct, Transform("SO PARAM"))) 9204762Snate@binkert.org env.Depends(hh_file, depends + extra_deps) 9214762Snate@binkert.org 92210458Sandreas.hansson@arm.com# C++ parameter description files 92310458Sandreas.hansson@arm.comif GetOption('with_cxx_config'): 92410458Sandreas.hansson@arm.com for name,simobj in sorted(sim_objects.iteritems()): 92510458Sandreas.hansson@arm.com py_source = PySource.modules[simobj.__module__] 92610458Sandreas.hansson@arm.com extra_deps = [ py_source.tnode ] 92710458Sandreas.hansson@arm.com 92810458Sandreas.hansson@arm.com cxx_config_hh_file = File('cxx_config/%s.hh' % name) 92910458Sandreas.hansson@arm.com cxx_config_cc_file = File('cxx_config/%s.cc' % name) 93010458Sandreas.hansson@arm.com env.Command(cxx_config_hh_file, Value(name), 93110458Sandreas.hansson@arm.com MakeAction(createSimObjectCxxConfig(True), 93210458Sandreas.hansson@arm.com Transform("CXXCPRHH"))) 93310458Sandreas.hansson@arm.com env.Command(cxx_config_cc_file, Value(name), 93410458Sandreas.hansson@arm.com MakeAction(createSimObjectCxxConfig(False), 93510458Sandreas.hansson@arm.com Transform("CXXCPRCC"))) 93610458Sandreas.hansson@arm.com env.Depends(cxx_config_hh_file, depends + extra_deps + 93710458Sandreas.hansson@arm.com [File('params/%s.hh' % name), File('sim/cxx_config.hh')]) 93810458Sandreas.hansson@arm.com env.Depends(cxx_config_cc_file, depends + extra_deps + 93910458Sandreas.hansson@arm.com [cxx_config_hh_file]) 94010458Sandreas.hansson@arm.com Source(cxx_config_cc_file) 94110458Sandreas.hansson@arm.com 94210458Sandreas.hansson@arm.com cxx_config_init_cc_file = File('cxx_config/init.cc') 94310458Sandreas.hansson@arm.com 94410458Sandreas.hansson@arm.com def createCxxConfigInitCC(target, source, env): 94510458Sandreas.hansson@arm.com assert len(target) == 1 and len(source) == 1 94610458Sandreas.hansson@arm.com 94710458Sandreas.hansson@arm.com code = code_formatter() 94810458Sandreas.hansson@arm.com 94910458Sandreas.hansson@arm.com for name,simobj in sorted(sim_objects.iteritems()): 95010458Sandreas.hansson@arm.com if not hasattr(simobj, 'abstract') or not simobj.abstract: 95110458Sandreas.hansson@arm.com code('#include "cxx_config/${name}.hh"') 95210458Sandreas.hansson@arm.com code() 95310458Sandreas.hansson@arm.com code('void cxxConfigInit()') 95410458Sandreas.hansson@arm.com code('{') 95510458Sandreas.hansson@arm.com code.indent() 95610458Sandreas.hansson@arm.com for name,simobj in sorted(sim_objects.iteritems()): 95710458Sandreas.hansson@arm.com not_abstract = not hasattr(simobj, 'abstract') or \ 95810458Sandreas.hansson@arm.com not simobj.abstract 95910458Sandreas.hansson@arm.com if not_abstract and 'type' in simobj.__dict__: 96010458Sandreas.hansson@arm.com code('cxx_config_directory["${name}"] = ' 96110458Sandreas.hansson@arm.com '${name}CxxConfigParams::makeDirectoryEntry();') 96210458Sandreas.hansson@arm.com code.dedent() 96310458Sandreas.hansson@arm.com code('}') 96410458Sandreas.hansson@arm.com code.write(target[0].abspath) 96510458Sandreas.hansson@arm.com 96610458Sandreas.hansson@arm.com py_source = PySource.modules[simobj.__module__] 96710458Sandreas.hansson@arm.com extra_deps = [ py_source.tnode ] 96810458Sandreas.hansson@arm.com env.Command(cxx_config_init_cc_file, Value(name), 96910458Sandreas.hansson@arm.com MakeAction(createCxxConfigInitCC, Transform("CXXCINIT"))) 97010458Sandreas.hansson@arm.com cxx_param_hh_files = ["cxx_config/%s.hh" % simobj 97110584Sandreas.hansson@arm.com for name,simobj in sorted(sim_objects.iteritems()) 97210458Sandreas.hansson@arm.com if not hasattr(simobj, 'abstract') or not simobj.abstract] 97310458Sandreas.hansson@arm.com Depends(cxx_config_init_cc_file, cxx_param_hh_files + 97410458Sandreas.hansson@arm.com [File('sim/cxx_config.hh')]) 97510458Sandreas.hansson@arm.com Source(cxx_config_init_cc_file) 97610458Sandreas.hansson@arm.com 9774762Snate@binkert.org# Generate all enum header files 9786143Snate@binkert.orgfor name,enum in sorted(all_enums.iteritems()): 9796143Snate@binkert.org py_source = PySource.modules[enum.__module__] 9806143Snate@binkert.org extra_deps = [ py_source.tnode ] 9814762Snate@binkert.org 9824762Snate@binkert.org cc_file = File('enums/%s.cc' % name) 98311996Sgabeblack@google.com env.Command(cc_file, [Value(name), Value(env['USE_PYTHON'])], 9847816Ssteve.reinhardt@amd.com MakeAction(createEnumStrings, Transform("ENUM STR"))) 9854762Snate@binkert.org env.Depends(cc_file, depends + extra_deps) 9864762Snate@binkert.org Source(cc_file) 9874762Snate@binkert.org 9884762Snate@binkert.org hh_file = File('enums/%s.hh' % name) 9897756SAli.Saidi@ARM.com env.Command(hh_file, Value(name), 9908596Ssteve.reinhardt@amd.com MakeAction(createEnumDecls, Transform("ENUMDECL"))) 9914762Snate@binkert.org env.Depends(hh_file, depends + extra_deps) 9924762Snate@binkert.org 99311988Sandreas.sandberg@arm.com# Generate SimObject Python bindings wrapper files 99411988Sandreas.sandberg@arm.comif env['USE_PYTHON']: 99511988Sandreas.sandberg@arm.com for name,simobj in sorted(sim_objects.iteritems()): 99611988Sandreas.sandberg@arm.com py_source = PySource.modules[simobj.__module__] 99711988Sandreas.sandberg@arm.com extra_deps = [ py_source.tnode ] 99811988Sandreas.sandberg@arm.com cc_file = File('python/_m5/param_%s.cc' % name) 99911988Sandreas.sandberg@arm.com env.Command(cc_file, Value(name), 100011988Sandreas.sandberg@arm.com MakeAction(createSimObjectPyBindWrapper, 100111988Sandreas.sandberg@arm.com Transform("SO PyBind"))) 100211988Sandreas.sandberg@arm.com env.Depends(cc_file, depends + extra_deps) 100311988Sandreas.sandberg@arm.com Source(cc_file) 10044382Sbinkertn@umich.edu 10059396Sandreas.hansson@arm.com# Build all protocol buffers if we have got protoc and protobuf available 10069396Sandreas.hansson@arm.comif env['HAVE_PROTOBUF']: 10079396Sandreas.hansson@arm.com for proto in ProtoBuf.all: 10089396Sandreas.hansson@arm.com # Use both the source and header as the target, and the .proto 10099396Sandreas.hansson@arm.com # file as the source. When executing the protoc compiler, also 10109396Sandreas.hansson@arm.com # specify the proto_path to avoid having the generated files 10119396Sandreas.hansson@arm.com # include the path. 10129396Sandreas.hansson@arm.com env.Command([proto.cc_file, proto.hh_file], proto.tnode, 10139396Sandreas.hansson@arm.com MakeAction('$PROTOC --cpp_out ${TARGET.dir} ' 10149396Sandreas.hansson@arm.com '--proto_path ${SOURCE.dir} $SOURCE', 10159396Sandreas.hansson@arm.com Transform("PROTOC"))) 10169396Sandreas.hansson@arm.com 10179396Sandreas.hansson@arm.com # Add the C++ source file 101812302Sgabeblack@google.com Source(proto.cc_file, tags=proto.tags) 10199396Sandreas.hansson@arm.comelif ProtoBuf.all: 102012563Sgabeblack@google.com print('Got protobuf to build, but lacks support!') 10219396Sandreas.hansson@arm.com Exit(1) 10229396Sandreas.hansson@arm.com 10238232Snate@binkert.org# 10248232Snate@binkert.org# Handle debug flags 10258232Snate@binkert.org# 10268232Snate@binkert.orgdef makeDebugFlagCC(target, source, env): 10278232Snate@binkert.org assert(len(target) == 1 and len(source) == 1) 10286229Snate@binkert.org 102910455SCurtis.Dunham@arm.com code = code_formatter() 10306229Snate@binkert.org 103110455SCurtis.Dunham@arm.com # delay definition of CompoundFlags until after all the definition 103210455SCurtis.Dunham@arm.com # of all constituent SimpleFlags 103310455SCurtis.Dunham@arm.com comp_code = code_formatter() 10345517Snate@binkert.org 10355517Snate@binkert.org # file header 10367673Snate@binkert.org code(''' 10375517Snate@binkert.org/* 103810455SCurtis.Dunham@arm.com * DO NOT EDIT THIS FILE! Automatically generated by SCons. 10395517Snate@binkert.org */ 10405517Snate@binkert.org 10418232Snate@binkert.org#include "base/debug.hh" 104210455SCurtis.Dunham@arm.com 104310455SCurtis.Dunham@arm.comnamespace Debug { 104410455SCurtis.Dunham@arm.com 10457673Snate@binkert.org''') 10467673Snate@binkert.org 104710455SCurtis.Dunham@arm.com for name, flag in sorted(source[0].read().iteritems()): 104810455SCurtis.Dunham@arm.com n, compound, desc = flag 104910455SCurtis.Dunham@arm.com assert n == name 10505517Snate@binkert.org 105110455SCurtis.Dunham@arm.com if not compound: 105210455SCurtis.Dunham@arm.com code('SimpleFlag $name("$name", "$desc");') 105310455SCurtis.Dunham@arm.com else: 105410455SCurtis.Dunham@arm.com comp_code('CompoundFlag $name("$name", "$desc",') 105510455SCurtis.Dunham@arm.com comp_code.indent() 105610455SCurtis.Dunham@arm.com last = len(compound) - 1 105710455SCurtis.Dunham@arm.com for i,flag in enumerate(compound): 105810455SCurtis.Dunham@arm.com if i != last: 105910685Sandreas.hansson@arm.com comp_code('&$flag,') 106010455SCurtis.Dunham@arm.com else: 106110685Sandreas.hansson@arm.com comp_code('&$flag);') 106210455SCurtis.Dunham@arm.com comp_code.dedent() 10635517Snate@binkert.org 106410455SCurtis.Dunham@arm.com code.append(comp_code) 10658232Snate@binkert.org code() 10668232Snate@binkert.org code('} // namespace Debug') 10675517Snate@binkert.org 10687673Snate@binkert.org code.write(str(target[0])) 10695517Snate@binkert.org 10708232Snate@binkert.orgdef makeDebugFlagHH(target, source, env): 10718232Snate@binkert.org assert(len(target) == 1 and len(source) == 1) 10725517Snate@binkert.org 10738232Snate@binkert.org val = eval(source[0].get_contents()) 10748232Snate@binkert.org name, compound, desc = val 10758232Snate@binkert.org 10767673Snate@binkert.org code = code_formatter() 10775517Snate@binkert.org 10785517Snate@binkert.org # file header boilerplate 10797673Snate@binkert.org code('''\ 10805517Snate@binkert.org/* 108110455SCurtis.Dunham@arm.com * DO NOT EDIT THIS FILE! Automatically generated by SCons. 10825517Snate@binkert.org */ 10835517Snate@binkert.org 10848232Snate@binkert.org#ifndef __DEBUG_${name}_HH__ 10858232Snate@binkert.org#define __DEBUG_${name}_HH__ 10865517Snate@binkert.org 10878232Snate@binkert.orgnamespace Debug { 10888232Snate@binkert.org''') 10895517Snate@binkert.org 10908232Snate@binkert.org if compound: 10918232Snate@binkert.org code('class CompoundFlag;') 10928232Snate@binkert.org code('class SimpleFlag;') 10935517Snate@binkert.org 10948232Snate@binkert.org if compound: 10958232Snate@binkert.org code('extern CompoundFlag $name;') 10968232Snate@binkert.org for flag in compound: 10978232Snate@binkert.org code('extern SimpleFlag $flag;') 10988232Snate@binkert.org else: 10998232Snate@binkert.org code('extern SimpleFlag $name;') 11005517Snate@binkert.org 11018232Snate@binkert.org code(''' 11028232Snate@binkert.org} 11035517Snate@binkert.org 11048232Snate@binkert.org#endif // __DEBUG_${name}_HH__ 11057673Snate@binkert.org''') 11065517Snate@binkert.org 11077673Snate@binkert.org code.write(str(target[0])) 11085517Snate@binkert.org 11098232Snate@binkert.orgfor name,flag in sorted(debug_flags.iteritems()): 11108232Snate@binkert.org n, compound, desc = flag 11118232Snate@binkert.org assert n == name 11125192Ssaidi@eecs.umich.edu 111310454SCurtis.Dunham@arm.com hh_file = 'debug/%s.hh' % name 111410454SCurtis.Dunham@arm.com env.Command(hh_file, Value(flag), 11158232Snate@binkert.org MakeAction(makeDebugFlagHH, Transform("TRACING", 0))) 111610455SCurtis.Dunham@arm.com 111710455SCurtis.Dunham@arm.comenv.Command('debug/flags.cc', Value(debug_flags), 111810455SCurtis.Dunham@arm.com MakeAction(makeDebugFlagCC, Transform("TRACING", 0))) 111910455SCurtis.Dunham@arm.comSource('debug/flags.cc') 11205192Ssaidi@eecs.umich.edu 112111077SCurtis.Dunham@arm.com# version tags 112211330SCurtis.Dunham@arm.comtags = \ 112311077SCurtis.Dunham@arm.comenv.Command('sim/tags.cc', None, 112411077SCurtis.Dunham@arm.com MakeAction('util/cpt_upgrader.py --get-cc-file > $TARGET', 112511077SCurtis.Dunham@arm.com Transform("VER TAGS"))) 112611330SCurtis.Dunham@arm.comenv.AlwaysBuild(tags) 112711077SCurtis.Dunham@arm.com 11287674Snate@binkert.org# Embed python files. All .py files that have been indicated by a 11295522Snate@binkert.org# PySource() call in a SConscript need to be embedded into the M5 11305522Snate@binkert.org# library. To do that, we compile the file to byte code, marshal the 11317674Snate@binkert.org# byte code, compress it, and then generate a c++ file that 11327674Snate@binkert.org# inserts the result into an array. 11337674Snate@binkert.orgdef embedPyFile(target, source, env): 11347674Snate@binkert.org def c_str(string): 11357674Snate@binkert.org if string is None: 11367674Snate@binkert.org return "0" 11377674Snate@binkert.org return '"%s"' % string 11387674Snate@binkert.org 11395522Snate@binkert.org '''Action function to compile a .py into a code object, marshal 11405522Snate@binkert.org it, compress it, and stick it into an asm file so the code appears 11415522Snate@binkert.org as just bytes with a label in the data section''' 11425517Snate@binkert.org 11435522Snate@binkert.org src = file(str(source[0]), 'r').read() 11445517Snate@binkert.org 11456143Snate@binkert.org pysource = PySource.tnodes[source[0]] 11466727Ssteve.reinhardt@amd.com compiled = compile(src, pysource.abspath, 'exec') 11475522Snate@binkert.org marshalled = marshal.dumps(compiled) 11485522Snate@binkert.org compressed = zlib.compress(marshalled) 11495522Snate@binkert.org data = compressed 11507674Snate@binkert.org sym = pysource.symname 11515517Snate@binkert.org 11527673Snate@binkert.org code = code_formatter() 11537673Snate@binkert.org code('''\ 11547674Snate@binkert.org#include "sim/init.hh" 11557673Snate@binkert.org 11567674Snate@binkert.orgnamespace { 11577674Snate@binkert.org 11587674Snate@binkert.org''') 115913576Sciro.santilli@arm.com blobToCpp(data, 'data_' + sym, code) 116013576Sciro.santilli@arm.com code('''\ 116111308Santhony.gutierrez@amd.com 11627673Snate@binkert.org 11637674Snate@binkert.orgEmbeddedPython embedded_${sym}( 11647674Snate@binkert.org ${{c_str(pysource.arcname)}}, 11657674Snate@binkert.org ${{c_str(pysource.abspath)}}, 11667674Snate@binkert.org ${{c_str(pysource.modpath)}}, 11677674Snate@binkert.org data_${sym}, 11687674Snate@binkert.org ${{len(data)}}, 11697674Snate@binkert.org ${{len(marshalled)}}); 11707674Snate@binkert.org 11717811Ssteve.reinhardt@amd.com} // anonymous namespace 11727674Snate@binkert.org''') 11737673Snate@binkert.org code.write(str(target[0])) 11745522Snate@binkert.org 11756143Snate@binkert.orgfor source in PySource.all: 117610453SAndrew.Bardsley@arm.com env.Command(source.cpp, source.tnode, 11777816Ssteve.reinhardt@amd.com MakeAction(embedPyFile, Transform("EMBED PY"))) 117812302Sgabeblack@google.com Source(source.cpp, tags=source.tags, add_tags='python') 11794382Sbinkertn@umich.edu 11804382Sbinkertn@umich.edu######################################################################## 11814382Sbinkertn@umich.edu# 11824382Sbinkertn@umich.edu# Define binaries. Each different build type (debug, opt, etc.) gets 11834382Sbinkertn@umich.edu# a slightly different build environment. 11844382Sbinkertn@umich.edu# 11854382Sbinkertn@umich.edu 11864382Sbinkertn@umich.edu# List of constructed environments to pass back to SConstruct 118712302Sgabeblack@google.comdate_source = Source('base/date.cc', tags=[]) 11884382Sbinkertn@umich.edu 118912797Sgabeblack@google.comgem5_binary = Gem5('gem5') 119012797Sgabeblack@google.com 11912655Sstever@eecs.umich.edu# Function to create a new build environment as clone of current 11922655Sstever@eecs.umich.edu# environment 'env' with modified object suffix and optional stripped 11932655Sstever@eecs.umich.edu# binary. Additional keyword arguments are appended to corresponding 11942655Sstever@eecs.umich.edu# build environment vars. 119512063Sgabeblack@google.comdef makeEnv(env, label, objsfx, strip=False, disable_partial=False, **kwargs): 11965601Snate@binkert.org # SCons doesn't know to append a library suffix when there is a '.' in the 11975601Snate@binkert.org # name. Use '_' instead. 119812222Sgabeblack@google.com libname = 'gem5_' + label 119912222Sgabeblack@google.com secondary_exename = 'm5.' + label 12005522Snate@binkert.org 12015863Snate@binkert.org new_env = env.Clone(OBJSUFFIX=objsfx, SHOBJSUFFIX=objsfx + 's') 12025601Snate@binkert.org new_env.Label = label 12035601Snate@binkert.org new_env.Append(**kwargs) 12045601Snate@binkert.org 120512302Sgabeblack@google.com lib_sources = Source.all.with_tag('gem5 lib') 120610453SAndrew.Bardsley@arm.com 120711988Sandreas.sandberg@arm.com # Without Python, leave out all Python content from the library 120811988Sandreas.sandberg@arm.com # builds. The option doesn't affect gem5 built as a program 120910453SAndrew.Bardsley@arm.com if GetOption('without_python'): 121012302Sgabeblack@google.com lib_sources = lib_sources.without_tag('python') 121110453SAndrew.Bardsley@arm.com 121211983Sgabeblack@google.com static_objs = [] 121311983Sgabeblack@google.com shared_objs = [] 121412302Sgabeblack@google.com 121512302Sgabeblack@google.com for s in lib_sources.with_tag(Source.ungrouped_tag): 121612362Sgabeblack@google.com static_objs.append(s.static(new_env)) 121712362Sgabeblack@google.com shared_objs.append(s.shared(new_env)) 121811983Sgabeblack@google.com 121912302Sgabeblack@google.com for group in Source.source_groups: 122012302Sgabeblack@google.com srcs = lib_sources.with_tag(Source.link_group_tag(group)) 122111983Sgabeblack@google.com if not srcs: 122211983Sgabeblack@google.com continue 122311983Sgabeblack@google.com 122412362Sgabeblack@google.com group_static = [ s.static(new_env) for s in srcs ] 122512362Sgabeblack@google.com group_shared = [ s.shared(new_env) for s in srcs ] 122612310Sgabeblack@google.com 122712063Sgabeblack@google.com # If partial linking is disabled, add these sources to the build 122812063Sgabeblack@google.com # directly, and short circuit this loop. 122912063Sgabeblack@google.com if disable_partial: 123012310Sgabeblack@google.com static_objs.extend(group_static) 123112310Sgabeblack@google.com shared_objs.extend(group_shared) 123212063Sgabeblack@google.com continue 123312063Sgabeblack@google.com 123411983Sgabeblack@google.com # Set up the static partially linked objects. 123511983Sgabeblack@google.com file_name = new_env.subst("${OBJPREFIX}lib${OBJSUFFIX}.partial") 123611983Sgabeblack@google.com target = File(joinpath(group, file_name)) 123712310Sgabeblack@google.com partial = env.PartialStatic(target=target, source=group_static) 123812310Sgabeblack@google.com static_objs.extend(partial) 123911983Sgabeblack@google.com 124011983Sgabeblack@google.com # Set up the shared partially linked objects. 124111983Sgabeblack@google.com file_name = new_env.subst("${SHOBJPREFIX}lib${SHOBJSUFFIX}.partial") 124211983Sgabeblack@google.com target = File(joinpath(group, file_name)) 124312310Sgabeblack@google.com partial = env.PartialShared(target=target, source=group_shared) 124412310Sgabeblack@google.com shared_objs.extend(partial) 12456143Snate@binkert.org 124612362Sgabeblack@google.com static_date = date_source.static(new_env) 124712306Sgabeblack@google.com new_env.Depends(static_date, static_objs) 124812310Sgabeblack@google.com static_objs.extend(static_date) 124910453SAndrew.Bardsley@arm.com 125012362Sgabeblack@google.com shared_date = date_source.shared(new_env) 125112306Sgabeblack@google.com new_env.Depends(shared_date, shared_objs) 125212310Sgabeblack@google.com shared_objs.extend(shared_date) 12535554Snate@binkert.org 125412797Sgabeblack@google.com main_objs = [ s.static(new_env) for s in Source.all.with_tag('main') ] 125512797Sgabeblack@google.com 12565522Snate@binkert.org # First make a library of everything but main() so other programs can 12575522Snate@binkert.org # link against m5. 12585797Snate@binkert.org static_lib = new_env.StaticLibrary(libname, static_objs) 12595797Snate@binkert.org shared_lib = new_env.SharedLibrary(libname, shared_objs) 12605522Snate@binkert.org 126112797Sgabeblack@google.com # Keep track of the object files generated so far so Executables can 126212797Sgabeblack@google.com # include them. 126312797Sgabeblack@google.com new_env['STATIC_OBJS'] = static_objs 126412797Sgabeblack@google.com new_env['SHARED_OBJS'] = shared_objs 126512797Sgabeblack@google.com new_env['MAIN_OBJS'] = main_objs 12668233Snate@binkert.org 126712797Sgabeblack@google.com new_env['STATIC_LIB'] = static_lib 126812797Sgabeblack@google.com new_env['SHARED_LIB'] = shared_lib 12698235Snate@binkert.org 127012797Sgabeblack@google.com # Record some settings for building Executables. 127112797Sgabeblack@google.com new_env['EXE_SUFFIX'] = label 127212797Sgabeblack@google.com new_env['STRIP_EXES'] = strip 127312370Sgabeblack@google.com 127412797Sgabeblack@google.com for cls in ExecutableMeta.all: 127512797Sgabeblack@google.com cls.declare_all(new_env) 127612313Sgabeblack@google.com 127712797Sgabeblack@google.com new_env.M5Binary = File(gem5_binary.path(new_env)) 12786143Snate@binkert.org 127912797Sgabeblack@google.com new_env.Command(secondary_exename, new_env.M5Binary, 12808334Snate@binkert.org MakeAction('ln $SOURCE $TARGET', Transform("HARDLINK"))) 12818334Snate@binkert.org 128211993Sgabeblack@google.com # Set up regression tests. 128311993Sgabeblack@google.com SConscript(os.path.join(env.root.abspath, 'tests', 'SConscript'), 128412223Sgabeblack@google.com variant_dir=Dir('tests').Dir(new_env.Label), 128511993Sgabeblack@google.com exports={ 'env' : new_env }, duplicate=False) 12862655Sstever@eecs.umich.edu 12879225Sandreas.hansson@arm.com# Start out with the compiler flags common to all compilers, 12889225Sandreas.hansson@arm.com# i.e. they all use -g for opt and -g -pg for prof 12899226Sandreas.hansson@arm.comccflags = {'debug' : [], 'opt' : ['-g'], 'fast' : [], 'prof' : ['-g', '-pg'], 12909226Sandreas.hansson@arm.com 'perf' : ['-g']} 12919225Sandreas.hansson@arm.com 12929226Sandreas.hansson@arm.com# Start out with the linker flags common to all linkers, i.e. -pg for 12939226Sandreas.hansson@arm.com# prof, and -lprofiler for perf. The -lprofile flag is surrounded by 12949226Sandreas.hansson@arm.com# no-as-needed and as-needed as the binutils linker is too clever and 12959226Sandreas.hansson@arm.com# simply doesn't link to the library otherwise. 12969226Sandreas.hansson@arm.comldflags = {'debug' : [], 'opt' : [], 'fast' : [], 'prof' : ['-pg'], 12979226Sandreas.hansson@arm.com 'perf' : ['-Wl,--no-as-needed', '-lprofiler', '-Wl,--as-needed']} 12989225Sandreas.hansson@arm.com 12999227Sandreas.hansson@arm.com# For Link Time Optimization, the optimisation flags used to compile 13009227Sandreas.hansson@arm.com# individual files are decoupled from those used at link time 13019227Sandreas.hansson@arm.com# (i.e. you can compile with -O3 and perform LTO with -O0), so we need 13029227Sandreas.hansson@arm.com# to also update the linker flags based on the target. 13038946Sandreas.hansson@arm.comif env['GCC']: 13043918Ssaidi@eecs.umich.edu if sys.platform == 'sunos5': 13059225Sandreas.hansson@arm.com ccflags['debug'] += ['-gstabs+'] 13063918Ssaidi@eecs.umich.edu else: 13079225Sandreas.hansson@arm.com ccflags['debug'] += ['-ggdb3'] 13089225Sandreas.hansson@arm.com ldflags['debug'] += ['-O0'] 13099227Sandreas.hansson@arm.com # opt, fast, prof and perf all share the same cc flags, also add 13109227Sandreas.hansson@arm.com # the optimization to the ldflags as LTO defers the optimization 13119227Sandreas.hansson@arm.com # to link time 13129226Sandreas.hansson@arm.com for target in ['opt', 'fast', 'prof', 'perf']: 13139225Sandreas.hansson@arm.com ccflags[target] += ['-O3'] 13149227Sandreas.hansson@arm.com ldflags[target] += ['-O3'] 13159227Sandreas.hansson@arm.com 13169227Sandreas.hansson@arm.com ccflags['fast'] += env['LTO_CCFLAGS'] 13179227Sandreas.hansson@arm.com ldflags['fast'] += env['LTO_LDFLAGS'] 13188946Sandreas.hansson@arm.comelif env['CLANG']: 13199225Sandreas.hansson@arm.com ccflags['debug'] += ['-g', '-O0'] 13209226Sandreas.hansson@arm.com # opt, fast, prof and perf all share the same cc flags 13219226Sandreas.hansson@arm.com for target in ['opt', 'fast', 'prof', 'perf']: 13229226Sandreas.hansson@arm.com ccflags[target] += ['-O3'] 13233515Ssaidi@eecs.umich.eduelse: 132412563Sgabeblack@google.com print('Unknown compiler, please fix compiler options') 13254762Snate@binkert.org Exit(1) 13263515Ssaidi@eecs.umich.edu 13278881Smarc.orr@gmail.com 13288881Smarc.orr@gmail.com# To speed things up, we only instantiate the build environments we 13298881Smarc.orr@gmail.com# need. We try to identify the needed environment for each target; if 13308881Smarc.orr@gmail.com# we can't, we fall back on instantiating all the environments just to 13318881Smarc.orr@gmail.com# be safe. 13329226Sandreas.hansson@arm.comtarget_types = ['debug', 'opt', 'fast', 'prof', 'perf'] 13339226Sandreas.hansson@arm.comobj2target = {'do': 'debug', 'o': 'opt', 'fo': 'fast', 'po': 'prof', 13349226Sandreas.hansson@arm.com 'gpo' : 'perf'} 13358881Smarc.orr@gmail.com 13368881Smarc.orr@gmail.comdef identifyTarget(t): 13378881Smarc.orr@gmail.com ext = t.split('.')[-1] 13388881Smarc.orr@gmail.com if ext in target_types: 13398881Smarc.orr@gmail.com return ext 13408881Smarc.orr@gmail.com if obj2target.has_key(ext): 13418881Smarc.orr@gmail.com return obj2target[ext] 13428881Smarc.orr@gmail.com match = re.search(r'/tests/([^/]+)/', t) 13438881Smarc.orr@gmail.com if match and match.group(1) in target_types: 13448881Smarc.orr@gmail.com return match.group(1) 13458881Smarc.orr@gmail.com return 'all' 13468881Smarc.orr@gmail.com 13478881Smarc.orr@gmail.comneeded_envs = [identifyTarget(target) for target in BUILD_TARGETS] 13488881Smarc.orr@gmail.comif 'all' in needed_envs: 13498881Smarc.orr@gmail.com needed_envs += target_types 13508881Smarc.orr@gmail.com 135113508Snikos.nikoleris@arm.comdisable_partial = False 135213508Snikos.nikoleris@arm.comif env['PLATFORM'] == 'darwin': 135313508Snikos.nikoleris@arm.com # Up until Apple LLVM version 10.0.0 (clang-1000.11.45.5), partial 135413508Snikos.nikoleris@arm.com # linked objects do not expose symbols that are marked with the 135513508Snikos.nikoleris@arm.com # hidden visibility and consequently building gem5 on Mac OS 135613508Snikos.nikoleris@arm.com # fails. As a workaround, we disable partial linking, however, we 135713508Snikos.nikoleris@arm.com # may want to revisit in the future. 135813508Snikos.nikoleris@arm.com disable_partial = True 135913508Snikos.nikoleris@arm.com 136012222Sgabeblack@google.com# Debug binary 136112222Sgabeblack@google.comif 'debug' in needed_envs: 136212222Sgabeblack@google.com makeEnv(env, 'debug', '.do', 136312222Sgabeblack@google.com CCFLAGS = Split(ccflags['debug']), 136412222Sgabeblack@google.com CPPDEFINES = ['DEBUG', 'TRACING_ON=1'], 136513508Snikos.nikoleris@arm.com LINKFLAGS = Split(ldflags['debug']), 136613508Snikos.nikoleris@arm.com disable_partial=disable_partial) 1367955SN/A 136812222Sgabeblack@google.com# Optimized binary 136912222Sgabeblack@google.comif 'opt' in needed_envs: 137012222Sgabeblack@google.com makeEnv(env, 'opt', '.o', 137112222Sgabeblack@google.com CCFLAGS = Split(ccflags['opt']), 137212222Sgabeblack@google.com CPPDEFINES = ['TRACING_ON=1'], 137313508Snikos.nikoleris@arm.com LINKFLAGS = Split(ldflags['opt']), 137413508Snikos.nikoleris@arm.com disable_partial=disable_partial) 1375955SN/A 137612222Sgabeblack@google.com# "Fast" binary 137712222Sgabeblack@google.comif 'fast' in needed_envs: 137813508Snikos.nikoleris@arm.com disable_partial = disable_partial and \ 137912222Sgabeblack@google.com env.get('BROKEN_INCREMENTAL_LTO', False) and \ 138012222Sgabeblack@google.com GetOption('force_lto') 138112222Sgabeblack@google.com makeEnv(env, 'fast', '.fo', strip = True, 138212222Sgabeblack@google.com CCFLAGS = Split(ccflags['fast']), 138312222Sgabeblack@google.com CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'], 138412222Sgabeblack@google.com LINKFLAGS = Split(ldflags['fast']), 138512222Sgabeblack@google.com disable_partial=disable_partial) 13861869SN/A 138712222Sgabeblack@google.com# Profiled binary using gprof 138812222Sgabeblack@google.comif 'prof' in needed_envs: 138912222Sgabeblack@google.com makeEnv(env, 'prof', '.po', 139012222Sgabeblack@google.com CCFLAGS = Split(ccflags['prof']), 139112222Sgabeblack@google.com CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'], 139213508Snikos.nikoleris@arm.com LINKFLAGS = Split(ldflags['prof']), 139313508Snikos.nikoleris@arm.com disable_partial=disable_partial) 13949226Sandreas.hansson@arm.com 139512222Sgabeblack@google.com# Profiled binary using google-pprof 139612222Sgabeblack@google.comif 'perf' in needed_envs: 139712222Sgabeblack@google.com makeEnv(env, 'perf', '.gpo', 139812222Sgabeblack@google.com CCFLAGS = Split(ccflags['perf']), 139912222Sgabeblack@google.com CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'], 140013508Snikos.nikoleris@arm.com LINKFLAGS = Split(ldflags['perf']), 140113508Snikos.nikoleris@arm.com disable_partial=disable_partial) 1402