SConscript revision 8614
1955SN/A# -*- mode:python -*- 2955SN/A 31762SN/A# Copyright (c) 2004-2005 The Regents of The University of Michigan 4955SN/A# All rights reserved. 5955SN/A# 6955SN/A# Redistribution and use in source and binary forms, with or without 7955SN/A# modification, are permitted provided that the following conditions are 8955SN/A# met: redistributions of source code must retain the above copyright 9955SN/A# notice, this list of conditions and the following disclaimer; 10955SN/A# redistributions in binary form must reproduce the above copyright 11955SN/A# notice, this list of conditions and the following disclaimer in the 12955SN/A# documentation and/or other materials provided with the distribution; 13955SN/A# neither the name of the copyright holders nor the names of its 14955SN/A# contributors may be used to endorse or promote products derived from 15955SN/A# this software without specific prior written permission. 16955SN/A# 17955SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26955SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27955SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 282665Ssaidi@eecs.umich.edu# 294762Snate@binkert.org# Authors: Nathan Binkert 30955SN/A 3112563Sgabeblack@google.comimport array 3212563Sgabeblack@google.comimport bisect 335522Snate@binkert.orgimport imp 346143Snate@binkert.orgimport marshal 3512371Sgabeblack@google.comimport os 364762Snate@binkert.orgimport re 375522Snate@binkert.orgimport sys 38955SN/Aimport zlib 395522Snate@binkert.org 4011974Sgabeblack@google.comfrom os.path import basename, dirname, exists, isdir, isfile, join as joinpath 41955SN/A 425522Snate@binkert.orgimport SCons 434202Sbinkertn@umich.edu 445742Snate@binkert.org# This file defines how to build a particular configuration of gem5 45955SN/A# based on variable settings in the 'env' build environment. 464381Sbinkertn@umich.edu 474381Sbinkertn@umich.eduImport('*') 4812246Sgabeblack@google.com 4912246Sgabeblack@google.com# Children need to see the environment 508334Snate@binkert.orgExport('env') 51955SN/A 52955SN/Abuild_env = [(opt, env[opt]) for opt in export_vars] 534202Sbinkertn@umich.edu 54955SN/Afrom m5.util import code_formatter, compareVersions 554382Sbinkertn@umich.edu 564382Sbinkertn@umich.edu######################################################################## 574382Sbinkertn@umich.edu# Code for adding source files of various types 586654Snate@binkert.org# 595517Snate@binkert.org# When specifying a source file of some type, a set of guards can be 608614Sgblack@eecs.umich.edu# specified for that file. When get() is used to find the files, if 617674Snate@binkert.org# get specifies a set of filters, only files that match those filters 626143Snate@binkert.org# will be accepted (unspecified filters on files are assumed to be 636143Snate@binkert.org# false). Current filters are: 646143Snate@binkert.org# main -- specifies the gem5 main() function 6512302Sgabeblack@google.com# skip_lib -- do not put this file into the gem5 library 6612302Sgabeblack@google.com# <unittest> -- unit tests use filters based on the unit test name 6712302Sgabeblack@google.com# 6812371Sgabeblack@google.com# A parent can now be specified for a source file and default filter 6912371Sgabeblack@google.com# values will be retrieved recursively from parents (children override 7012371Sgabeblack@google.com# parents). 7112371Sgabeblack@google.com# 7212371Sgabeblack@google.comclass SourceMeta(type): 7312371Sgabeblack@google.com '''Meta class for source files that keeps track of all files of a 7412371Sgabeblack@google.com particular type and has a get function for finding all functions 7512371Sgabeblack@google.com of a certain type that match a set of guards''' 7612371Sgabeblack@google.com def __init__(cls, name, bases, dict): 7712371Sgabeblack@google.com super(SourceMeta, cls).__init__(name, bases, dict) 7812371Sgabeblack@google.com cls.all = [] 7912371Sgabeblack@google.com 8012371Sgabeblack@google.com def get(cls, **guards): 8112371Sgabeblack@google.com '''Find all files that match the specified guards. If a source 8212371Sgabeblack@google.com file does not specify a flag, the default is False''' 8312371Sgabeblack@google.com for src in cls.all: 8412371Sgabeblack@google.com for flag,value in guards.iteritems(): 8512371Sgabeblack@google.com # if the flag is found and has a different value, skip 8612371Sgabeblack@google.com # this file 8712371Sgabeblack@google.com if src.all_guards.get(flag, False) != value: 8812371Sgabeblack@google.com break 8912371Sgabeblack@google.com else: 9012371Sgabeblack@google.com yield src 9112371Sgabeblack@google.com 9212371Sgabeblack@google.comclass SourceFile(object): 9312371Sgabeblack@google.com '''Base object that encapsulates the notion of a source file. 9412371Sgabeblack@google.com This includes, the source node, target node, various manipulations 9512371Sgabeblack@google.com of those. A source file also specifies a set of guards which 9612371Sgabeblack@google.com describing which builds the source file applies to. A parent can 9712371Sgabeblack@google.com also be specified to get default guards from''' 9812371Sgabeblack@google.com __metaclass__ = SourceMeta 9912371Sgabeblack@google.com def __init__(self, source, parent=None, **guards): 10012371Sgabeblack@google.com self.guards = guards 10112371Sgabeblack@google.com self.parent = parent 10212371Sgabeblack@google.com 10312371Sgabeblack@google.com tnode = source 10412371Sgabeblack@google.com if not isinstance(source, SCons.Node.FS.File): 10512371Sgabeblack@google.com tnode = File(source) 10612371Sgabeblack@google.com 10712371Sgabeblack@google.com self.tnode = tnode 10812371Sgabeblack@google.com self.snode = tnode.srcnode() 10912371Sgabeblack@google.com 11012371Sgabeblack@google.com for base in type(self).__mro__: 11112371Sgabeblack@google.com if issubclass(base, SourceFile): 11212371Sgabeblack@google.com base.all.append(self) 11312371Sgabeblack@google.com 11412371Sgabeblack@google.com @property 11512302Sgabeblack@google.com def filename(self): 11612371Sgabeblack@google.com return str(self.tnode) 11712302Sgabeblack@google.com 11812371Sgabeblack@google.com @property 11912302Sgabeblack@google.com def dirname(self): 12012302Sgabeblack@google.com return dirname(self.filename) 12112371Sgabeblack@google.com 12212371Sgabeblack@google.com @property 12312371Sgabeblack@google.com def basename(self): 12412371Sgabeblack@google.com return basename(self.filename) 12512302Sgabeblack@google.com 12612371Sgabeblack@google.com @property 12712371Sgabeblack@google.com def extname(self): 12812371Sgabeblack@google.com index = self.basename.rfind('.') 12912371Sgabeblack@google.com if index <= 0: 13011983Sgabeblack@google.com # dot files aren't extensions 1316143Snate@binkert.org return self.basename, None 1328233Snate@binkert.org 13312302Sgabeblack@google.com return self.basename[:index], self.basename[index+1:] 1346143Snate@binkert.org 1356143Snate@binkert.org @property 13612302Sgabeblack@google.com def all_guards(self): 1374762Snate@binkert.org '''find all guards for this object getting default values 1386143Snate@binkert.org recursively from its parents''' 1398233Snate@binkert.org guards = {} 1408233Snate@binkert.org if self.parent: 14112302Sgabeblack@google.com guards.update(self.parent.guards) 14212302Sgabeblack@google.com guards.update(self.guards) 1436143Snate@binkert.org return guards 14412362Sgabeblack@google.com 14512362Sgabeblack@google.com def __lt__(self, other): return self.filename < other.filename 14612362Sgabeblack@google.com def __le__(self, other): return self.filename <= other.filename 14712362Sgabeblack@google.com def __gt__(self, other): return self.filename > other.filename 14812302Sgabeblack@google.com def __ge__(self, other): return self.filename >= other.filename 14912302Sgabeblack@google.com def __eq__(self, other): return self.filename == other.filename 15012302Sgabeblack@google.com def __ne__(self, other): return self.filename != other.filename 15112302Sgabeblack@google.com 15212302Sgabeblack@google.comclass Source(SourceFile): 15312363Sgabeblack@google.com '''Add a c/c++ source file to the build''' 15412363Sgabeblack@google.com def __init__(self, source, Werror=True, swig=False, **guards): 15512363Sgabeblack@google.com '''specify the source file, and any guards''' 15612363Sgabeblack@google.com super(Source, self).__init__(source, **guards) 15712302Sgabeblack@google.com 15812363Sgabeblack@google.com self.Werror = Werror 15912363Sgabeblack@google.com self.swig = swig 16012363Sgabeblack@google.com 16112363Sgabeblack@google.comclass PySource(SourceFile): 16212363Sgabeblack@google.com '''Add a python source file to the named package''' 1638233Snate@binkert.org invalid_sym_char = re.compile('[^A-z0-9_]') 1646143Snate@binkert.org modules = {} 1656143Snate@binkert.org tnodes = {} 1666143Snate@binkert.org symnames = {} 1676143Snate@binkert.org 1686143Snate@binkert.org def __init__(self, package, source, **guards): 1696143Snate@binkert.org '''specify the python package, the source file, and any guards''' 1706143Snate@binkert.org super(PySource, self).__init__(source, **guards) 1716143Snate@binkert.org 1726143Snate@binkert.org modname,ext = self.extname 1737065Snate@binkert.org assert ext == 'py' 1746143Snate@binkert.org 17512362Sgabeblack@google.com if package: 17612362Sgabeblack@google.com path = package.split('.') 17712362Sgabeblack@google.com else: 17812362Sgabeblack@google.com path = [] 17912362Sgabeblack@google.com 18012362Sgabeblack@google.com modpath = path[:] 18112362Sgabeblack@google.com if modname != '__init__': 18212362Sgabeblack@google.com modpath += [ modname ] 18312362Sgabeblack@google.com modpath = '.'.join(modpath) 18412362Sgabeblack@google.com 18512362Sgabeblack@google.com arcpath = path + [ self.basename ] 18612362Sgabeblack@google.com abspath = self.snode.abspath 1878233Snate@binkert.org if not exists(abspath): 1888233Snate@binkert.org abspath = self.tnode.abspath 1898233Snate@binkert.org 1908233Snate@binkert.org self.package = package 1918233Snate@binkert.org self.modname = modname 1928233Snate@binkert.org self.modpath = modpath 1938233Snate@binkert.org self.arcname = joinpath(*arcpath) 1948233Snate@binkert.org self.abspath = abspath 1958233Snate@binkert.org self.compiled = File(self.filename + 'c') 1968233Snate@binkert.org self.cpp = File(self.filename + '.cc') 1978233Snate@binkert.org self.symname = PySource.invalid_sym_char.sub('_', modpath) 1988233Snate@binkert.org 1998233Snate@binkert.org PySource.modules[modpath] = self 2008233Snate@binkert.org PySource.tnodes[self.tnode] = self 2018233Snate@binkert.org PySource.symnames[self.symname] = self 2028233Snate@binkert.org 2038233Snate@binkert.orgclass SimObject(PySource): 2048233Snate@binkert.org '''Add a SimObject python file as a python source object and add 2058233Snate@binkert.org it to a list of sim object modules''' 2068233Snate@binkert.org 2078233Snate@binkert.org fixed = False 2086143Snate@binkert.org modnames = [] 2096143Snate@binkert.org 2106143Snate@binkert.org def __init__(self, source, **guards): 2116143Snate@binkert.org '''Specify the source file and any guards (automatically in 2126143Snate@binkert.org the m5.objects package)''' 2136143Snate@binkert.org super(SimObject, self).__init__('m5.objects', source, **guards) 2149982Satgutier@umich.edu if self.fixed: 2156143Snate@binkert.org raise AttributeError, "Too late to call SimObject now." 21612302Sgabeblack@google.com 21712302Sgabeblack@google.com bisect.insort_right(SimObject.modnames, self.modname) 21812302Sgabeblack@google.com 21912302Sgabeblack@google.comclass SwigSource(SourceFile): 22012302Sgabeblack@google.com '''Add a swig file to build''' 22112302Sgabeblack@google.com 22212302Sgabeblack@google.com def __init__(self, package, source, **guards): 22312302Sgabeblack@google.com '''Specify the python package, the source file, and any guards''' 22411983Sgabeblack@google.com super(SwigSource, self).__init__(source, **guards) 22511983Sgabeblack@google.com 22611983Sgabeblack@google.com modname,ext = self.extname 22712302Sgabeblack@google.com assert ext == 'i' 22812302Sgabeblack@google.com 22912302Sgabeblack@google.com self.module = modname 23012302Sgabeblack@google.com cc_file = joinpath(self.dirname, modname + '_wrap.cc') 23112302Sgabeblack@google.com py_file = joinpath(self.dirname, modname + '.py') 23212302Sgabeblack@google.com 23311983Sgabeblack@google.com self.cc_source = Source(cc_file, swig=True, parent=self) 2346143Snate@binkert.org self.py_source = PySource(package, py_file, parent=self) 23512305Sgabeblack@google.com 23612302Sgabeblack@google.comclass UnitTest(object): 23712302Sgabeblack@google.com '''Create a UnitTest''' 23812302Sgabeblack@google.com 2396143Snate@binkert.org all = [] 2406143Snate@binkert.org def __init__(self, target, *sources): 2416143Snate@binkert.org '''Specify the target name and any sources. Sources that are 2425522Snate@binkert.org not SourceFiles are evalued with Source(). All files are 2436143Snate@binkert.org guarded with a guard of the same name as the UnitTest 2446143Snate@binkert.org target.''' 2456143Snate@binkert.org 2469982Satgutier@umich.edu srcs = [] 24712302Sgabeblack@google.com for src in sources: 24812302Sgabeblack@google.com if not isinstance(src, SourceFile): 24912302Sgabeblack@google.com src = Source(src, skip_lib=True) 2506143Snate@binkert.org src.guards[target] = True 2516143Snate@binkert.org srcs.append(src) 2526143Snate@binkert.org 2536143Snate@binkert.org self.sources = srcs 2545522Snate@binkert.org self.target = target 2555522Snate@binkert.org UnitTest.all.append(self) 2565522Snate@binkert.org 2575522Snate@binkert.org# Children should have access 2585604Snate@binkert.orgExport('Source') 2595604Snate@binkert.orgExport('PySource') 2606143Snate@binkert.orgExport('SimObject') 2616143Snate@binkert.orgExport('SwigSource') 2624762Snate@binkert.orgExport('UnitTest') 2634762Snate@binkert.org 2646143Snate@binkert.org######################################################################## 2656727Ssteve.reinhardt@amd.com# 2666727Ssteve.reinhardt@amd.com# Debug Flags 2676727Ssteve.reinhardt@amd.com# 2684762Snate@binkert.orgdebug_flags = {} 2696143Snate@binkert.orgdef DebugFlag(name, desc=None): 2706143Snate@binkert.org if name in debug_flags: 2716143Snate@binkert.org raise AttributeError, "Flag %s already specified" % name 2726143Snate@binkert.org debug_flags[name] = (name, (), desc) 2736727Ssteve.reinhardt@amd.com 2746143Snate@binkert.orgdef CompoundFlag(name, flags, desc=None): 2757674Snate@binkert.org if name in debug_flags: 2767674Snate@binkert.org raise AttributeError, "Flag %s already specified" % name 2775604Snate@binkert.org 2786143Snate@binkert.org compound = tuple(flags) 2796143Snate@binkert.org debug_flags[name] = (name, compound, desc) 2806143Snate@binkert.org 2814762Snate@binkert.orgExport('DebugFlag') 2826143Snate@binkert.orgExport('CompoundFlag') 2834762Snate@binkert.org 2844762Snate@binkert.org######################################################################## 2854762Snate@binkert.org# 2866143Snate@binkert.org# Set some compiler variables 2876143Snate@binkert.org# 2884762Snate@binkert.org 28912302Sgabeblack@google.com# Include file paths are rooted in this directory. SCons will 29012302Sgabeblack@google.com# automatically expand '.' to refer to both the source directory and 2918233Snate@binkert.org# the corresponding build directory to pick up generated include 29212302Sgabeblack@google.com# files. 2936143Snate@binkert.orgenv.Append(CPPPATH=Dir('.')) 2946143Snate@binkert.org 2954762Snate@binkert.orgfor extra_dir in extras_dir_list: 2966143Snate@binkert.org env.Append(CPPPATH=Dir(extra_dir)) 2974762Snate@binkert.org 2989396Sandreas.hansson@arm.com# Workaround for bug in SCons version > 0.97d20071212 2999396Sandreas.hansson@arm.com# Scons bug id: 2006 gem5 Bug id: 308 3009396Sandreas.hansson@arm.comfor root, dirs, files in os.walk(base_dir, topdown=True): 30112302Sgabeblack@google.com Dir(root[len(base_dir) + 1:]) 30212302Sgabeblack@google.com 30312302Sgabeblack@google.com######################################################################## 3049396Sandreas.hansson@arm.com# 3059396Sandreas.hansson@arm.com# Walk the tree and execute all SConscripts in subdirectories 3069396Sandreas.hansson@arm.com# 3079396Sandreas.hansson@arm.com 3089396Sandreas.hansson@arm.comhere = Dir('.').srcnode().abspath 3099396Sandreas.hansson@arm.comfor root, dirs, files in os.walk(base_dir, topdown=True): 3109396Sandreas.hansson@arm.com if root == here: 3119930Sandreas.hansson@arm.com # we don't want to recurse back into this SConscript 3129930Sandreas.hansson@arm.com continue 3139396Sandreas.hansson@arm.com 3148235Snate@binkert.org if 'SConscript' in files: 3158235Snate@binkert.org build_dir = joinpath(env['BUILDDIR'], root[len(base_dir) + 1:]) 3166143Snate@binkert.org SConscript(joinpath(root, 'SConscript'), variant_dir=build_dir) 3178235Snate@binkert.org 3189003SAli.Saidi@ARM.comfor extra_dir in extras_dir_list: 3198235Snate@binkert.org prefix_len = len(dirname(extra_dir)) + 1 3208235Snate@binkert.org for root, dirs, files in os.walk(extra_dir, topdown=True): 32112302Sgabeblack@google.com # if build lives in the extras directory, don't walk down it 3228235Snate@binkert.org if 'build' in dirs: 32312302Sgabeblack@google.com dirs.remove('build') 3248235Snate@binkert.org 3258235Snate@binkert.org if 'SConscript' in files: 32612302Sgabeblack@google.com build_dir = joinpath(env['BUILDDIR'], root[prefix_len:]) 3278235Snate@binkert.org SConscript(joinpath(root, 'SConscript'), variant_dir=build_dir) 3288235Snate@binkert.org 3298235Snate@binkert.orgfor opt in export_vars: 3308235Snate@binkert.org env.ConfigFile(opt) 3319003SAli.Saidi@ARM.com 33212313Sgabeblack@google.comdef makeTheISA(source, target, env): 33312313Sgabeblack@google.com isas = [ src.get_contents() for src in source ] 33412313Sgabeblack@google.com target_isa = env['TARGET_ISA'] 33512313Sgabeblack@google.com def define(isa): 33612313Sgabeblack@google.com return isa.upper() + '_ISA' 33712315Sgabeblack@google.com 33812371Sgabeblack@google.com def namespace(isa): 33912371Sgabeblack@google.com return isa[0].upper() + isa[1:].lower() + 'ISA' 34012371Sgabeblack@google.com 34112315Sgabeblack@google.com 34212315Sgabeblack@google.com code = code_formatter() 34312371Sgabeblack@google.com code('''\ 3445584Snate@binkert.org#ifndef __CONFIG_THE_ISA_HH__ 3454382Sbinkertn@umich.edu#define __CONFIG_THE_ISA_HH__ 3464202Sbinkertn@umich.edu 3474382Sbinkertn@umich.edu''') 3484382Sbinkertn@umich.edu 3499396Sandreas.hansson@arm.com for i,isa in enumerate(isas): 3505584Snate@binkert.org code('#define $0 $1', define(isa), i + 1) 35112313Sgabeblack@google.com 3524382Sbinkertn@umich.edu code(''' 3534382Sbinkertn@umich.edu 3544382Sbinkertn@umich.edu#define THE_ISA ${{define(target_isa)}} 3558232Snate@binkert.org#define TheISA ${{namespace(target_isa)}} 3565192Ssaidi@eecs.umich.edu 3578232Snate@binkert.org#endif // __CONFIG_THE_ISA_HH__''') 3588232Snate@binkert.org 3598232Snate@binkert.org code.write(str(target[0])) 3605192Ssaidi@eecs.umich.edu 3618232Snate@binkert.orgenv.Command('config/the_isa.hh', map(Value, all_isa_list), 3625192Ssaidi@eecs.umich.edu MakeAction(makeTheISA, Transform("CFG ISA", 0))) 3635799Snate@binkert.org 3648232Snate@binkert.org######################################################################## 3655192Ssaidi@eecs.umich.edu# 3665192Ssaidi@eecs.umich.edu# Prevent any SimObjects from being added after this point, they 3675192Ssaidi@eecs.umich.edu# should all have been added in the SConscripts above 3688232Snate@binkert.org# 3695192Ssaidi@eecs.umich.eduSimObject.fixed = True 3708232Snate@binkert.org 3715192Ssaidi@eecs.umich.educlass DictImporter(object): 3725192Ssaidi@eecs.umich.edu '''This importer takes a dictionary of arbitrary module names that 3735192Ssaidi@eecs.umich.edu map to arbitrary filenames.''' 3745192Ssaidi@eecs.umich.edu def __init__(self, modules): 3754382Sbinkertn@umich.edu self.modules = modules 3764382Sbinkertn@umich.edu self.installed = set() 3774382Sbinkertn@umich.edu 3782667Sstever@eecs.umich.edu def __del__(self): 3792667Sstever@eecs.umich.edu self.unload() 3802667Sstever@eecs.umich.edu 3812667Sstever@eecs.umich.edu def unload(self): 3822667Sstever@eecs.umich.edu import sys 3832667Sstever@eecs.umich.edu for module in self.installed: 3845742Snate@binkert.org del sys.modules[module] 3855742Snate@binkert.org self.installed = set() 3865742Snate@binkert.org 3875793Snate@binkert.org def find_module(self, fullname, path): 3888334Snate@binkert.org if fullname == 'm5.defines': 3895793Snate@binkert.org return self 3905793Snate@binkert.org 3915793Snate@binkert.org if fullname == 'm5.objects': 3924382Sbinkertn@umich.edu return self 3934762Snate@binkert.org 3945344Sstever@gmail.com if fullname.startswith('m5.internal'): 3954382Sbinkertn@umich.edu return None 3965341Sstever@gmail.com 3975742Snate@binkert.org source = self.modules.get(fullname, None) 3985742Snate@binkert.org if source is not None and fullname.startswith('m5.objects'): 3995742Snate@binkert.org return self 4005742Snate@binkert.org 4015742Snate@binkert.org return None 4024762Snate@binkert.org 4035742Snate@binkert.org def load_module(self, fullname): 4045742Snate@binkert.org mod = imp.new_module(fullname) 40511984Sgabeblack@google.com sys.modules[fullname] = mod 4067722Sgblack@eecs.umich.edu self.installed.add(fullname) 4075742Snate@binkert.org 4085742Snate@binkert.org mod.__loader__ = self 4095742Snate@binkert.org if fullname == 'm5.objects': 4109930Sandreas.hansson@arm.com mod.__path__ = fullname.split('.') 4119930Sandreas.hansson@arm.com return mod 4129930Sandreas.hansson@arm.com 4139930Sandreas.hansson@arm.com if fullname == 'm5.defines': 4149930Sandreas.hansson@arm.com mod.__dict__['buildEnv'] = m5.util.SmartDict(build_env) 4155742Snate@binkert.org return mod 4168242Sbradley.danofsky@amd.com 4178242Sbradley.danofsky@amd.com source = self.modules[fullname] 4188242Sbradley.danofsky@amd.com if source.modname == '__init__': 4198242Sbradley.danofsky@amd.com mod.__path__ = source.modpath 4205341Sstever@gmail.com mod.__file__ = source.abspath 4215742Snate@binkert.org 4227722Sgblack@eecs.umich.edu exec file(source.abspath, 'r') in mod.__dict__ 4234773Snate@binkert.org 4246108Snate@binkert.org return mod 4251858SN/A 4261085SN/Aimport m5.SimObject 4276658Snate@binkert.orgimport m5.params 4286658Snate@binkert.orgfrom m5.util import code_formatter 4297673Snate@binkert.org 4306658Snate@binkert.orgm5.SimObject.clear() 4316658Snate@binkert.orgm5.params.clear() 43211308Santhony.gutierrez@amd.com 4336658Snate@binkert.org# install the python importer so we can grab stuff from the source 43411308Santhony.gutierrez@amd.com# tree itself. We can't have SimObjects added after this point or 4356658Snate@binkert.org# else we won't know about them for the rest of the stuff. 4366658Snate@binkert.orgimporter = DictImporter(PySource.modules) 4377673Snate@binkert.orgsys.meta_path[0:0] = [ importer ] 4387673Snate@binkert.org 4397673Snate@binkert.org# import all sim objects so we can populate the all_objects list 4407673Snate@binkert.org# make sure that we're working with a list, then let's sort it 4417673Snate@binkert.orgfor modname in SimObject.modnames: 4427673Snate@binkert.org exec('from m5.objects import %s' % modname) 4437673Snate@binkert.org 44410467Sandreas.hansson@arm.com# we need to unload all of the currently imported modules so that they 4456658Snate@binkert.org# will be re-imported the next time the sconscript is run 4467673Snate@binkert.orgimporter.unload() 44710467Sandreas.hansson@arm.comsys.meta_path.remove(importer) 44810467Sandreas.hansson@arm.com 44910467Sandreas.hansson@arm.comsim_objects = m5.SimObject.allClasses 45010467Sandreas.hansson@arm.comall_enums = m5.params.allEnums 45110467Sandreas.hansson@arm.com 45210467Sandreas.hansson@arm.com# Find param types that need to be explicitly wrapped with swig. 45310467Sandreas.hansson@arm.com# These will be recognized because the ParamDesc will have a 45410467Sandreas.hansson@arm.com# swig_decl() method. Most param types are based on types that don't 45510467Sandreas.hansson@arm.com# need this, either because they're based on native types (like Int) 45610467Sandreas.hansson@arm.com# or because they're SimObjects (which get swigged independently). 45710467Sandreas.hansson@arm.com# For now the only things handled here are VectorParam types. 4587673Snate@binkert.orgparams_to_swig = {} 4597673Snate@binkert.orgfor name,obj in sorted(sim_objects.iteritems()): 4607673Snate@binkert.org for param in obj._params.local.values(): 4617673Snate@binkert.org # load the ptype attribute now because it depends on the 4627673Snate@binkert.org # current version of SimObject.allClasses, but when scons 4639048SAli.Saidi@ARM.com # actually uses the value, all versions of 4647673Snate@binkert.org # SimObject.allClasses will have been loaded 4657673Snate@binkert.org param.ptype 4667673Snate@binkert.org 4677673Snate@binkert.org if not hasattr(param, 'swig_decl'): 4686658Snate@binkert.org continue 4697756SAli.Saidi@ARM.com pname = param.ptype_str 4707816Ssteve.reinhardt@amd.com if pname not in params_to_swig: 4716658Snate@binkert.org params_to_swig[pname] = param 47211308Santhony.gutierrez@amd.com 47311308Santhony.gutierrez@amd.com######################################################################## 47411308Santhony.gutierrez@amd.com# 47511308Santhony.gutierrez@amd.com# calculate extra dependencies 47611308Santhony.gutierrez@amd.com# 47711308Santhony.gutierrez@amd.commodule_depends = ["m5", "m5.SimObject", "m5.params"] 47811308Santhony.gutierrez@amd.comdepends = [ PySource.modules[dep].snode for dep in module_depends ] 47911308Santhony.gutierrez@amd.com 48011308Santhony.gutierrez@amd.com######################################################################## 48111308Santhony.gutierrez@amd.com# 48211308Santhony.gutierrez@amd.com# Commands for the basic automatically generated python files 48311308Santhony.gutierrez@amd.com# 48411308Santhony.gutierrez@amd.com 48511308Santhony.gutierrez@amd.com# Generate Python file containing a dict specifying the current 48611308Santhony.gutierrez@amd.com# buildEnv flags. 48711308Santhony.gutierrez@amd.comdef makeDefinesPyFile(target, source, env): 48811308Santhony.gutierrez@amd.com build_env = source[0].get_contents() 48911308Santhony.gutierrez@amd.com 49011308Santhony.gutierrez@amd.com code = code_formatter() 49111308Santhony.gutierrez@amd.com code(""" 49211308Santhony.gutierrez@amd.comimport m5.internal 49311308Santhony.gutierrez@amd.comimport m5.util 49411308Santhony.gutierrez@amd.com 49511308Santhony.gutierrez@amd.combuildEnv = m5.util.SmartDict($build_env) 49611308Santhony.gutierrez@amd.com 49711308Santhony.gutierrez@amd.comcompileDate = m5.internal.core.compileDate 49811308Santhony.gutierrez@amd.com_globals = globals() 49911308Santhony.gutierrez@amd.comfor key,val in m5.internal.core.__dict__.iteritems(): 50011308Santhony.gutierrez@amd.com if key.startswith('flag_'): 50111308Santhony.gutierrez@amd.com flag = key[5:] 50211308Santhony.gutierrez@amd.com _globals[flag] = val 50311308Santhony.gutierrez@amd.comdel _globals 50411308Santhony.gutierrez@amd.com""") 50511308Santhony.gutierrez@amd.com code.write(target[0].abspath) 50611308Santhony.gutierrez@amd.com 50711308Santhony.gutierrez@amd.comdefines_info = Value(build_env) 50811308Santhony.gutierrez@amd.com# Generate a file with all of the compile options in it 50911308Santhony.gutierrez@amd.comenv.Command('python/m5/defines.py', defines_info, 51011308Santhony.gutierrez@amd.com MakeAction(makeDefinesPyFile, Transform("DEFINES", 0))) 51111308Santhony.gutierrez@amd.comPySource('m5', 'python/m5/defines.py') 51211308Santhony.gutierrez@amd.com 51311308Santhony.gutierrez@amd.com# Generate python file containing info about the M5 source code 51411308Santhony.gutierrez@amd.comdef makeInfoPyFile(target, source, env): 51511308Santhony.gutierrez@amd.com code = code_formatter() 51611308Santhony.gutierrez@amd.com for src in source: 5174382Sbinkertn@umich.edu data = ''.join(file(src.srcnode().abspath, 'r').xreadlines()) 5184382Sbinkertn@umich.edu code('$src = ${{repr(data)}}') 5194762Snate@binkert.org code.write(str(target[0])) 5204762Snate@binkert.org 5214762Snate@binkert.org# Generate a file that wraps the basic top level files 5226654Snate@binkert.orgenv.Command('python/m5/info.py', 5236654Snate@binkert.org [ '#/COPYING', '#/LICENSE', '#/README', ], 5245517Snate@binkert.org MakeAction(makeInfoPyFile, Transform("INFO"))) 5255517Snate@binkert.orgPySource('m5', 'python/m5/info.py') 5265517Snate@binkert.org 5275517Snate@binkert.org######################################################################## 5285517Snate@binkert.org# 5295517Snate@binkert.org# Create all of the SimObject param headers and enum headers 5305517Snate@binkert.org# 5315517Snate@binkert.org 5325517Snate@binkert.orgdef createSimObjectParamStruct(target, source, env): 5335517Snate@binkert.org assert len(target) == 1 and len(source) == 1 5345517Snate@binkert.org 5355517Snate@binkert.org name = str(source[0].get_contents()) 5365517Snate@binkert.org obj = sim_objects[name] 5375517Snate@binkert.org 5385517Snate@binkert.org code = code_formatter() 5395517Snate@binkert.org obj.cxx_param_decl(code) 5405517Snate@binkert.org code.write(target[0].abspath) 5416654Snate@binkert.org 5425517Snate@binkert.orgdef createParamSwigWrapper(target, source, env): 5435517Snate@binkert.org assert len(target) == 1 and len(source) == 1 5445517Snate@binkert.org 5455517Snate@binkert.org name = str(source[0].get_contents()) 5465517Snate@binkert.org param = params_to_swig[name] 54711802Sandreas.sandberg@arm.com 5485517Snate@binkert.org code = code_formatter() 5495517Snate@binkert.org param.swig_decl(code) 5506143Snate@binkert.org code.write(target[0].abspath) 5516654Snate@binkert.org 5525517Snate@binkert.orgdef createEnumStrings(target, source, env): 5535517Snate@binkert.org assert len(target) == 1 and len(source) == 1 5545517Snate@binkert.org 5555517Snate@binkert.org name = str(source[0].get_contents()) 5565517Snate@binkert.org obj = all_enums[name] 5575517Snate@binkert.org 5585517Snate@binkert.org code = code_formatter() 5595517Snate@binkert.org obj.cxx_def(code) 5605517Snate@binkert.org code.write(target[0].abspath) 5615517Snate@binkert.org 5625517Snate@binkert.orgdef createEnumDecls(target, source, env): 5635517Snate@binkert.org assert len(target) == 1 and len(source) == 1 5645517Snate@binkert.org 5655517Snate@binkert.org name = str(source[0].get_contents()) 5666654Snate@binkert.org obj = all_enums[name] 5676654Snate@binkert.org 5685517Snate@binkert.org code = code_formatter() 5695517Snate@binkert.org obj.cxx_decl(code) 5706143Snate@binkert.org code.write(target[0].abspath) 5716143Snate@binkert.org 5726143Snate@binkert.orgdef createEnumSwigWrapper(target, source, env): 5736727Ssteve.reinhardt@amd.com assert len(target) == 1 and len(source) == 1 5745517Snate@binkert.org 5756727Ssteve.reinhardt@amd.com name = str(source[0].get_contents()) 5765517Snate@binkert.org obj = all_enums[name] 5775517Snate@binkert.org 5785517Snate@binkert.org code = code_formatter() 5796654Snate@binkert.org obj.swig_decl(code) 5806654Snate@binkert.org code.write(target[0].abspath) 5817673Snate@binkert.org 5826654Snate@binkert.orgdef createSimObjectSwigWrapper(target, source, env): 5836654Snate@binkert.org name = source[0].get_contents() 5846654Snate@binkert.org obj = sim_objects[name] 5856654Snate@binkert.org 5865517Snate@binkert.org code = code_formatter() 5875517Snate@binkert.org obj.swig_decl(code) 5885517Snate@binkert.org code.write(target[0].abspath) 5896143Snate@binkert.org 5905517Snate@binkert.org# Generate all of the SimObject param C++ struct header files 5914762Snate@binkert.orgparams_hh_files = [] 5925517Snate@binkert.orgfor name,simobj in sorted(sim_objects.iteritems()): 5935517Snate@binkert.org py_source = PySource.modules[simobj.__module__] 5946143Snate@binkert.org extra_deps = [ py_source.tnode ] 5956143Snate@binkert.org 5965517Snate@binkert.org hh_file = File('params/%s.hh' % name) 5975517Snate@binkert.org params_hh_files.append(hh_file) 5985517Snate@binkert.org env.Command(hh_file, Value(name), 5995517Snate@binkert.org MakeAction(createSimObjectParamStruct, Transform("SO PARAM"))) 6005517Snate@binkert.org env.Depends(hh_file, depends + extra_deps) 6015517Snate@binkert.org 6025517Snate@binkert.org# Generate any needed param SWIG wrapper files 6035517Snate@binkert.orgparams_i_files = [] 6045517Snate@binkert.orgfor name,param in params_to_swig.iteritems(): 6056143Snate@binkert.org i_file = File('python/m5/internal/%s.i' % (param.swig_module_name())) 6065517Snate@binkert.org params_i_files.append(i_file) 6076654Snate@binkert.org env.Command(i_file, Value(name), 6086654Snate@binkert.org MakeAction(createParamSwigWrapper, Transform("SW PARAM"))) 6096654Snate@binkert.org env.Depends(i_file, depends) 6106654Snate@binkert.org SwigSource('m5.internal', i_file) 6116654Snate@binkert.org 6126654Snate@binkert.org# Generate all enum header files 6134762Snate@binkert.orgfor name,enum in sorted(all_enums.iteritems()): 6144762Snate@binkert.org py_source = PySource.modules[enum.__module__] 6154762Snate@binkert.org extra_deps = [ py_source.tnode ] 6164762Snate@binkert.org 6174762Snate@binkert.org cc_file = File('enums/%s.cc' % name) 6187675Snate@binkert.org env.Command(cc_file, Value(name), 61910584Sandreas.hansson@arm.com MakeAction(createEnumStrings, Transform("ENUM STR"))) 6204762Snate@binkert.org env.Depends(cc_file, depends + extra_deps) 6214762Snate@binkert.org Source(cc_file) 6224762Snate@binkert.org 6234762Snate@binkert.org hh_file = File('enums/%s.hh' % name) 6244382Sbinkertn@umich.edu env.Command(hh_file, Value(name), 6254382Sbinkertn@umich.edu MakeAction(createEnumDecls, Transform("ENUMDECL"))) 6265517Snate@binkert.org env.Depends(hh_file, depends + extra_deps) 6276654Snate@binkert.org 6285517Snate@binkert.org i_file = File('python/m5/internal/enum_%s.i' % name) 6298126Sgblack@eecs.umich.edu env.Command(i_file, Value(name), 6306654Snate@binkert.org MakeAction(createEnumSwigWrapper, Transform("ENUMSWIG"))) 6317673Snate@binkert.org env.Depends(i_file, depends + extra_deps) 6326654Snate@binkert.org SwigSource('m5.internal', i_file) 63311802Sandreas.sandberg@arm.com 6346654Snate@binkert.org# Generate SimObject SWIG wrapper files 6356654Snate@binkert.orgfor name in sim_objects.iterkeys(): 6366654Snate@binkert.org i_file = File('python/m5/internal/param_%s.i' % name) 6376654Snate@binkert.org env.Command(i_file, Value(name), 63811802Sandreas.sandberg@arm.com MakeAction(createSimObjectSwigWrapper, Transform("SO SWIG"))) 6396669Snate@binkert.org env.Depends(i_file, depends) 64011802Sandreas.sandberg@arm.com SwigSource('m5.internal', i_file) 6416669Snate@binkert.org 6426669Snate@binkert.org# Generate the main swig init file 6436669Snate@binkert.orgdef makeEmbeddedSwigInit(target, source, env): 6446669Snate@binkert.org code = code_formatter() 6456654Snate@binkert.org module = source[0].get_contents() 6467673Snate@binkert.org code('''\ 6475517Snate@binkert.org#include "sim/init.hh" 6488126Sgblack@eecs.umich.edu 6495798Snate@binkert.orgextern "C" { 6507756SAli.Saidi@ARM.com void init_${module}(); 6517816Ssteve.reinhardt@amd.com} 6525798Snate@binkert.org 6535798Snate@binkert.orgEmbeddedSwig embed_swig_${module}(init_${module}); 6545517Snate@binkert.org''') 6555517Snate@binkert.org code.write(str(target[0])) 6567673Snate@binkert.org 6575517Snate@binkert.org# Build all swig modules 6585517Snate@binkert.orgfor swig in SwigSource.all: 6597673Snate@binkert.org env.Command([swig.cc_source.tnode, swig.py_source.tnode], swig.tnode, 6607673Snate@binkert.org MakeAction('$SWIG $SWIGFLAGS -outdir ${TARGETS[1].dir} ' 6615517Snate@binkert.org '-o ${TARGETS[0]} $SOURCES', Transform("SWIG"))) 6625798Snate@binkert.org cc_file = str(swig.tnode) 6635798Snate@binkert.org init_file = '%s/%s_init.cc' % (dirname(cc_file), basename(cc_file)) 6648333Snate@binkert.org env.Command(init_file, Value(swig.module), 6657816Ssteve.reinhardt@amd.com MakeAction(makeEmbeddedSwigInit, Transform("EMBED SW"))) 6665798Snate@binkert.org Source(init_file, **swig.guards) 6675798Snate@binkert.org 6684762Snate@binkert.org# 6694762Snate@binkert.org# Handle debug flags 6704762Snate@binkert.org# 6714762Snate@binkert.orgdef makeDebugFlagCC(target, source, env): 6724762Snate@binkert.org assert(len(target) == 1 and len(source) == 1) 6738596Ssteve.reinhardt@amd.com 6745517Snate@binkert.org val = eval(source[0].get_contents()) 6755517Snate@binkert.org name, compound, desc = val 67611997Sgabeblack@google.com compound = list(sorted(compound)) 6775517Snate@binkert.org 6785517Snate@binkert.org code = code_formatter() 6797673Snate@binkert.org 6808596Ssteve.reinhardt@amd.com # file header 6817673Snate@binkert.org code(''' 6825517Snate@binkert.org/* 68310458Sandreas.hansson@arm.com * DO NOT EDIT THIS FILE! Automatically generated 68410458Sandreas.hansson@arm.com */ 68510458Sandreas.hansson@arm.com 68610458Sandreas.hansson@arm.com#include "base/debug.hh" 68710458Sandreas.hansson@arm.com''') 68810458Sandreas.hansson@arm.com 68910458Sandreas.hansson@arm.com for flag in compound: 69010458Sandreas.hansson@arm.com code('#include "debug/$flag.hh"') 69110458Sandreas.hansson@arm.com code() 69210458Sandreas.hansson@arm.com code('namespace Debug {') 69310458Sandreas.hansson@arm.com code() 69410458Sandreas.hansson@arm.com 6955517Snate@binkert.org if not compound: 69611996Sgabeblack@google.com code('SimpleFlag $name("$name", "$desc");') 6975517Snate@binkert.org else: 69811997Sgabeblack@google.com code('CompoundFlag $name("$name", "$desc",') 69911996Sgabeblack@google.com code.indent() 7005517Snate@binkert.org last = len(compound) - 1 7015517Snate@binkert.org for i,flag in enumerate(compound): 7027673Snate@binkert.org if i != last: 7037673Snate@binkert.org code('$flag,') 70411996Sgabeblack@google.com else: 70511988Sandreas.sandberg@arm.com code('$flag);') 7067673Snate@binkert.org code.dedent() 7075517Snate@binkert.org 7088596Ssteve.reinhardt@amd.com code() 7095517Snate@binkert.org code('} // namespace Debug') 7105517Snate@binkert.org 71111997Sgabeblack@google.com code.write(str(target[0])) 7125517Snate@binkert.org 7135517Snate@binkert.orgdef makeDebugFlagHH(target, source, env): 7147673Snate@binkert.org assert(len(target) == 1 and len(source) == 1) 7157673Snate@binkert.org 7167673Snate@binkert.org val = eval(source[0].get_contents()) 7175517Snate@binkert.org name, compound, desc = val 71811988Sandreas.sandberg@arm.com 71911997Sgabeblack@google.com code = code_formatter() 7208596Ssteve.reinhardt@amd.com 7218596Ssteve.reinhardt@amd.com # file header boilerplate 7228596Ssteve.reinhardt@amd.com code('''\ 72311988Sandreas.sandberg@arm.com/* 7248596Ssteve.reinhardt@amd.com * DO NOT EDIT THIS FILE! 7258596Ssteve.reinhardt@amd.com * 7268596Ssteve.reinhardt@amd.com * Automatically generated by SCons 7274762Snate@binkert.org */ 7286143Snate@binkert.org 7296143Snate@binkert.org#ifndef __DEBUG_${name}_HH__ 7306143Snate@binkert.org#define __DEBUG_${name}_HH__ 7314762Snate@binkert.org 7324762Snate@binkert.orgnamespace Debug { 7334762Snate@binkert.org''') 7347756SAli.Saidi@ARM.com 7358596Ssteve.reinhardt@amd.com if compound: 7364762Snate@binkert.org code('class CompoundFlag;') 7374762Snate@binkert.org code('class SimpleFlag;') 73810458Sandreas.hansson@arm.com 73910458Sandreas.hansson@arm.com if compound: 74010458Sandreas.hansson@arm.com code('extern CompoundFlag $name;') 74110458Sandreas.hansson@arm.com for flag in compound: 74210458Sandreas.hansson@arm.com code('extern SimpleFlag $flag;') 74310458Sandreas.hansson@arm.com else: 74410458Sandreas.hansson@arm.com code('extern SimpleFlag $name;') 74510458Sandreas.hansson@arm.com 74610458Sandreas.hansson@arm.com code(''' 74710458Sandreas.hansson@arm.com} 74810458Sandreas.hansson@arm.com 74910458Sandreas.hansson@arm.com#endif // __DEBUG_${name}_HH__ 75010458Sandreas.hansson@arm.com''') 75110458Sandreas.hansson@arm.com 75210458Sandreas.hansson@arm.com code.write(str(target[0])) 75310458Sandreas.hansson@arm.com 75410458Sandreas.hansson@arm.comfor name,flag in sorted(debug_flags.iteritems()): 75510458Sandreas.hansson@arm.com n, compound, desc = flag 75610458Sandreas.hansson@arm.com assert n == name 75710458Sandreas.hansson@arm.com 75810458Sandreas.hansson@arm.com env.Command('debug/%s.hh' % name, Value(flag), 75910458Sandreas.hansson@arm.com MakeAction(makeDebugFlagHH, Transform("TRACING", 0))) 76010458Sandreas.hansson@arm.com env.Command('debug/%s.cc' % name, Value(flag), 76110458Sandreas.hansson@arm.com MakeAction(makeDebugFlagCC, Transform("TRACING", 0))) 76210458Sandreas.hansson@arm.com Source('debug/%s.cc' % name) 76310458Sandreas.hansson@arm.com 76410458Sandreas.hansson@arm.com# Embed python files. All .py files that have been indicated by a 76510458Sandreas.hansson@arm.com# PySource() call in a SConscript need to be embedded into the M5 76610458Sandreas.hansson@arm.com# library. To do that, we compile the file to byte code, marshal the 76710458Sandreas.hansson@arm.com# byte code, compress it, and then generate a c++ file that 76810458Sandreas.hansson@arm.com# inserts the result into an array. 76910458Sandreas.hansson@arm.comdef embedPyFile(target, source, env): 77010458Sandreas.hansson@arm.com def c_str(string): 77110458Sandreas.hansson@arm.com if string is None: 77210458Sandreas.hansson@arm.com return "0" 77310458Sandreas.hansson@arm.com return '"%s"' % string 77410458Sandreas.hansson@arm.com 77510458Sandreas.hansson@arm.com '''Action function to compile a .py into a code object, marshal 77610458Sandreas.hansson@arm.com it, compress it, and stick it into an asm file so the code appears 77710458Sandreas.hansson@arm.com as just bytes with a label in the data section''' 77810458Sandreas.hansson@arm.com 77910458Sandreas.hansson@arm.com src = file(str(source[0]), 'r').read() 78010458Sandreas.hansson@arm.com 78110458Sandreas.hansson@arm.com pysource = PySource.tnodes[source[0]] 78210458Sandreas.hansson@arm.com compiled = compile(src, pysource.abspath, 'exec') 78310458Sandreas.hansson@arm.com marshalled = marshal.dumps(compiled) 78410458Sandreas.hansson@arm.com compressed = zlib.compress(marshalled) 78510458Sandreas.hansson@arm.com data = compressed 78610458Sandreas.hansson@arm.com sym = pysource.symname 78710584Sandreas.hansson@arm.com 78810458Sandreas.hansson@arm.com code = code_formatter() 78910458Sandreas.hansson@arm.com code('''\ 79010458Sandreas.hansson@arm.com#include "sim/init.hh" 79110458Sandreas.hansson@arm.com 79210458Sandreas.hansson@arm.comnamespace { 7934762Snate@binkert.org 7946143Snate@binkert.orgconst char data_${sym}[] = { 7956143Snate@binkert.org''') 7966143Snate@binkert.org code.indent() 7974762Snate@binkert.org step = 16 7984762Snate@binkert.org for i in xrange(0, len(data), step): 79911996Sgabeblack@google.com x = array.array('B', data[i:i+step]) 8007816Ssteve.reinhardt@amd.com code(''.join('%d,' % d for d in x)) 8014762Snate@binkert.org code.dedent() 8024762Snate@binkert.org 8034762Snate@binkert.org code('''}; 8044762Snate@binkert.org 8057756SAli.Saidi@ARM.comEmbeddedPython embedded_${sym}( 8068596Ssteve.reinhardt@amd.com ${{c_str(pysource.arcname)}}, 8074762Snate@binkert.org ${{c_str(pysource.abspath)}}, 8084762Snate@binkert.org ${{c_str(pysource.modpath)}}, 80911988Sandreas.sandberg@arm.com data_${sym}, 81011988Sandreas.sandberg@arm.com ${{len(data)}}, 81111988Sandreas.sandberg@arm.com ${{len(marshalled)}}); 81211988Sandreas.sandberg@arm.com 81311988Sandreas.sandberg@arm.com} // anonymous namespace 81411988Sandreas.sandberg@arm.com''') 81511988Sandreas.sandberg@arm.com code.write(str(target[0])) 81611988Sandreas.sandberg@arm.com 81711988Sandreas.sandberg@arm.comfor source in PySource.all: 81811988Sandreas.sandberg@arm.com env.Command(source.cpp, source.tnode, 81911988Sandreas.sandberg@arm.com MakeAction(embedPyFile, Transform("EMBED PY"))) 8204382Sbinkertn@umich.edu Source(source.cpp) 8219396Sandreas.hansson@arm.com 8229396Sandreas.hansson@arm.com######################################################################## 8239396Sandreas.hansson@arm.com# 8249396Sandreas.hansson@arm.com# Define binaries. Each different build type (debug, opt, etc.) gets 8259396Sandreas.hansson@arm.com# a slightly different build environment. 8269396Sandreas.hansson@arm.com# 8279396Sandreas.hansson@arm.com 8289396Sandreas.hansson@arm.com# List of constructed environments to pass back to SConstruct 8299396Sandreas.hansson@arm.comenvList = [] 8309396Sandreas.hansson@arm.com 8319396Sandreas.hansson@arm.comdate_source = Source('base/date.cc', skip_lib=True) 8329396Sandreas.hansson@arm.com 8339396Sandreas.hansson@arm.com# Function to create a new build environment as clone of current 83412302Sgabeblack@google.com# environment 'env' with modified object suffix and optional stripped 8359396Sandreas.hansson@arm.com# binary. Additional keyword arguments are appended to corresponding 83612563Sgabeblack@google.com# build environment vars. 8379396Sandreas.hansson@arm.comdef makeEnv(label, objsfx, strip = False, **kwargs): 8389396Sandreas.hansson@arm.com # SCons doesn't know to append a library suffix when there is a '.' in the 8398232Snate@binkert.org # name. Use '_' instead. 8408232Snate@binkert.org libname = 'gem5_' + label 8418232Snate@binkert.org exename = 'gem5.' + label 8428232Snate@binkert.org secondary_exename = 'm5.' + label 8438232Snate@binkert.org 8446229Snate@binkert.org new_env = env.Clone(OBJSUFFIX=objsfx, SHOBJSUFFIX=objsfx + 's') 84510455SCurtis.Dunham@arm.com new_env.Label = label 8466229Snate@binkert.org new_env.Append(**kwargs) 84710455SCurtis.Dunham@arm.com 84810455SCurtis.Dunham@arm.com swig_env = new_env.Clone() 84910455SCurtis.Dunham@arm.com swig_env.Append(CCFLAGS='-Werror') 8505517Snate@binkert.org if env['GCC']: 8515517Snate@binkert.org swig_env.Append(CCFLAGS='-Wno-uninitialized') 8527673Snate@binkert.org swig_env.Append(CCFLAGS='-Wno-sign-compare') 8535517Snate@binkert.org swig_env.Append(CCFLAGS='-Wno-parentheses') 85410455SCurtis.Dunham@arm.com if compareVersions(env['GCC_VERSION'], '4.6.0') != -1: 8555517Snate@binkert.org swig_env.Append(CCFLAGS='-Wno-unused-label') 8565517Snate@binkert.org swig_env.Append(CCFLAGS='-Wno-unused-but-set-variable') 8578232Snate@binkert.org 85810455SCurtis.Dunham@arm.com werror_env = new_env.Clone() 85910455SCurtis.Dunham@arm.com werror_env.Append(CCFLAGS='-Werror') 86010455SCurtis.Dunham@arm.com 8617673Snate@binkert.org def make_obj(source, static, extra_deps = None): 8627673Snate@binkert.org '''This function adds the specified source to the correct 86310455SCurtis.Dunham@arm.com build environment, and returns the corresponding SCons Object 86410455SCurtis.Dunham@arm.com nodes''' 86510455SCurtis.Dunham@arm.com 8665517Snate@binkert.org if source.swig: 86710455SCurtis.Dunham@arm.com env = swig_env 86810455SCurtis.Dunham@arm.com elif source.Werror: 86910455SCurtis.Dunham@arm.com env = werror_env 87010455SCurtis.Dunham@arm.com else: 87110455SCurtis.Dunham@arm.com env = new_env 87210455SCurtis.Dunham@arm.com 87310455SCurtis.Dunham@arm.com if static: 87410455SCurtis.Dunham@arm.com obj = env.StaticObject(source.tnode) 87510685Sandreas.hansson@arm.com else: 87610455SCurtis.Dunham@arm.com obj = env.SharedObject(source.tnode) 87710685Sandreas.hansson@arm.com 87810455SCurtis.Dunham@arm.com if extra_deps: 8795517Snate@binkert.org env.Depends(obj, extra_deps) 88010455SCurtis.Dunham@arm.com 8818232Snate@binkert.org return obj 8828232Snate@binkert.org 8835517Snate@binkert.org static_objs = \ 8847673Snate@binkert.org [ make_obj(s, True) for s in Source.get(main=False, skip_lib=False) ] 8855517Snate@binkert.org shared_objs = \ 8868232Snate@binkert.org [ make_obj(s, False) for s in Source.get(main=False, skip_lib=False) ] 8878232Snate@binkert.org 8885517Snate@binkert.org static_date = make_obj(date_source, static=True, extra_deps=static_objs) 8898232Snate@binkert.org static_objs.append(static_date) 8908232Snate@binkert.org 8918232Snate@binkert.org shared_date = make_obj(date_source, static=False, extra_deps=shared_objs) 8927673Snate@binkert.org shared_objs.append(shared_date) 8935517Snate@binkert.org 8945517Snate@binkert.org # First make a library of everything but main() so other programs can 8957673Snate@binkert.org # link against m5. 8965517Snate@binkert.org static_lib = new_env.StaticLibrary(libname, static_objs) 89710455SCurtis.Dunham@arm.com shared_lib = new_env.SharedLibrary(libname, shared_objs) 8985517Snate@binkert.org 8995517Snate@binkert.org # Now link a stub with main() and the static library. 9008232Snate@binkert.org main_objs = [ make_obj(s, True) for s in Source.get(main=True) ] 9018232Snate@binkert.org 9025517Snate@binkert.org for test in UnitTest.all: 9038232Snate@binkert.org flags = { test.target : True } 9048232Snate@binkert.org test_sources = Source.get(**flags) 9055517Snate@binkert.org test_objs = [ make_obj(s, static=True) for s in test_sources ] 9068232Snate@binkert.org testname = "unittest/%s.%s" % (test.target, label) 9078232Snate@binkert.org new_env.Program(testname, main_objs + test_objs + static_objs) 9088232Snate@binkert.org 9095517Snate@binkert.org progname = exename 9108232Snate@binkert.org if strip: 9118232Snate@binkert.org progname += '.unstripped' 9128232Snate@binkert.org 9138232Snate@binkert.org targets = new_env.Program(progname, main_objs + static_objs) 9148232Snate@binkert.org 9158232Snate@binkert.org if strip: 9165517Snate@binkert.org if sys.platform == 'sunos5': 9178232Snate@binkert.org cmd = 'cp $SOURCE $TARGET; strip $TARGET' 9188232Snate@binkert.org else: 9195517Snate@binkert.org cmd = 'strip $SOURCE -o $TARGET' 9208232Snate@binkert.org targets = new_env.Command(exename, progname, 9217673Snate@binkert.org MakeAction(cmd, Transform("STRIP"))) 9225517Snate@binkert.org 9237673Snate@binkert.org new_env.Command(secondary_exename, exename, 9245517Snate@binkert.org MakeAction('ln $SOURCE $TARGET', Transform("HARDLINK"))) 9258232Snate@binkert.org 9268232Snate@binkert.org new_env.M5Binary = targets[0] 9278232Snate@binkert.org envList.append(new_env) 9285192Ssaidi@eecs.umich.edu 92910454SCurtis.Dunham@arm.com# Debug binary 93010454SCurtis.Dunham@arm.comccflags = {} 9318232Snate@binkert.orgif env['GCC']: 93210455SCurtis.Dunham@arm.com if sys.platform == 'sunos5': 93310455SCurtis.Dunham@arm.com ccflags['debug'] = '-gstabs+' 93410455SCurtis.Dunham@arm.com else: 93510455SCurtis.Dunham@arm.com ccflags['debug'] = '-ggdb3' 9365192Ssaidi@eecs.umich.edu ccflags['opt'] = '-g -O3' 93711077SCurtis.Dunham@arm.com ccflags['fast'] = '-O3' 93811330SCurtis.Dunham@arm.com ccflags['prof'] = '-O3 -g -pg' 93911077SCurtis.Dunham@arm.comelif env['SUNCC']: 94011077SCurtis.Dunham@arm.com ccflags['debug'] = '-g0' 94111077SCurtis.Dunham@arm.com ccflags['opt'] = '-g -O' 94211330SCurtis.Dunham@arm.com ccflags['fast'] = '-fast' 94311077SCurtis.Dunham@arm.com ccflags['prof'] = '-fast -g -pg' 9447674Snate@binkert.orgelif env['ICC']: 9455522Snate@binkert.org ccflags['debug'] = '-g -O0' 9465522Snate@binkert.org ccflags['opt'] = '-g -O' 9477674Snate@binkert.org ccflags['fast'] = '-fast' 9487674Snate@binkert.org ccflags['prof'] = '-fast -g -pg' 9497674Snate@binkert.orgelse: 9507674Snate@binkert.org print 'Unknown compiler, please fix compiler options' 9517674Snate@binkert.org Exit(1) 9527674Snate@binkert.org 9537674Snate@binkert.orgmakeEnv('debug', '.do', 9547674Snate@binkert.org CCFLAGS = Split(ccflags['debug']), 9555522Snate@binkert.org CPPDEFINES = ['DEBUG', 'TRACING_ON=1']) 9565522Snate@binkert.org 9575522Snate@binkert.org# Optimized binary 9585517Snate@binkert.orgmakeEnv('opt', '.o', 9595522Snate@binkert.org CCFLAGS = Split(ccflags['opt']), 9605517Snate@binkert.org CPPDEFINES = ['TRACING_ON=1']) 9616143Snate@binkert.org 9626727Ssteve.reinhardt@amd.com# "Fast" binary 9635522Snate@binkert.orgmakeEnv('fast', '.fo', strip = True, 9645522Snate@binkert.org CCFLAGS = Split(ccflags['fast']), 9655522Snate@binkert.org CPPDEFINES = ['NDEBUG', 'TRACING_ON=0']) 9667674Snate@binkert.org 9675517Snate@binkert.org# Profiled binary 9687673Snate@binkert.orgmakeEnv('prof', '.po', 9697673Snate@binkert.org CCFLAGS = Split(ccflags['prof']), 9707674Snate@binkert.org CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'], 9717673Snate@binkert.org LINKFLAGS = '-pg') 9727674Snate@binkert.org 9737674Snate@binkert.orgReturn('envList') 9748946Sandreas.hansson@arm.com