SConscript revision 7674:8e3734851770
1955SN/A# -*- mode:python -*- 2955SN/A 31762SN/A# Copyright (c) 2004-2005 The Regents of The University of Michigan 4955SN/A# All rights reserved. 5955SN/A# 6955SN/A# Redistribution and use in source and binary forms, with or without 7955SN/A# modification, are permitted provided that the following conditions are 8955SN/A# met: redistributions of source code must retain the above copyright 9955SN/A# notice, this list of conditions and the following disclaimer; 10955SN/A# redistributions in binary form must reproduce the above copyright 11955SN/A# notice, this list of conditions and the following disclaimer in the 12955SN/A# documentation and/or other materials provided with the distribution; 13955SN/A# neither the name of the copyright holders nor the names of its 14955SN/A# contributors may be used to endorse or promote products derived from 15955SN/A# this software without specific prior written permission. 16955SN/A# 17955SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26955SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27955SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 282665Ssaidi@eecs.umich.edu# 294762Snate@binkert.org# Authors: Nathan Binkert 30955SN/A 315522Snate@binkert.orgimport array 326143Snate@binkert.orgimport bisect 334762Snate@binkert.orgimport imp 345522Snate@binkert.orgimport marshal 35955SN/Aimport os 365522Snate@binkert.orgimport re 37955SN/Aimport sys 385522Snate@binkert.orgimport zlib 394202Sbinkertn@umich.edu 405742Snate@binkert.orgfrom os.path import basename, dirname, exists, isdir, isfile, join as joinpath 41955SN/A 424381Sbinkertn@umich.eduimport SCons 434381Sbinkertn@umich.edu 448334Snate@binkert.org# This file defines how to build a particular configuration of M5 45955SN/A# based on variable settings in the 'env' build environment. 46955SN/A 474202Sbinkertn@umich.eduImport('*') 48955SN/A 494382Sbinkertn@umich.edu# Children need to see the environment 504382Sbinkertn@umich.eduExport('env') 514382Sbinkertn@umich.edu 526654Snate@binkert.orgbuild_env = [(opt, env[opt]) for opt in export_vars] 535517Snate@binkert.org 548614Sgblack@eecs.umich.edufrom m5.util import code_formatter 557674Snate@binkert.org 566143Snate@binkert.org######################################################################## 576143Snate@binkert.org# Code for adding source files of various types 586143Snate@binkert.org# 598233Snate@binkert.orgclass SourceMeta(type): 608233Snate@binkert.org def __init__(cls, name, bases, dict): 618233Snate@binkert.org super(SourceMeta, cls).__init__(name, bases, dict) 628233Snate@binkert.org cls.all = [] 638233Snate@binkert.org 648334Snate@binkert.org def get(cls, **kwargs): 658334Snate@binkert.org for src in cls.all: 6610453SAndrew.Bardsley@arm.com for attr,value in kwargs.iteritems(): 6710453SAndrew.Bardsley@arm.com if getattr(src, attr) != value: 688233Snate@binkert.org break 698233Snate@binkert.org else: 708233Snate@binkert.org yield src 718233Snate@binkert.org 728233Snate@binkert.orgclass SourceFile(object): 738233Snate@binkert.org __metaclass__ = SourceMeta 746143Snate@binkert.org def __init__(self, source): 758233Snate@binkert.org tnode = source 768233Snate@binkert.org if not isinstance(source, SCons.Node.FS.File): 778233Snate@binkert.org tnode = File(source) 786143Snate@binkert.org 796143Snate@binkert.org self.tnode = tnode 806143Snate@binkert.org self.snode = tnode.srcnode() 816143Snate@binkert.org self.filename = str(tnode) 828233Snate@binkert.org self.dirname = dirname(self.filename) 838233Snate@binkert.org self.basename = basename(self.filename) 848233Snate@binkert.org index = self.basename.rfind('.') 856143Snate@binkert.org if index <= 0: 868233Snate@binkert.org # dot files aren't extensions 878233Snate@binkert.org self.extname = self.basename, None 888233Snate@binkert.org else: 898233Snate@binkert.org self.extname = self.basename[:index], self.basename[index+1:] 906143Snate@binkert.org 916143Snate@binkert.org for base in type(self).__mro__: 926143Snate@binkert.org if issubclass(base, SourceFile): 934762Snate@binkert.org base.all.append(self) 946143Snate@binkert.org 958233Snate@binkert.org def __lt__(self, other): return self.filename < other.filename 968233Snate@binkert.org def __le__(self, other): return self.filename <= other.filename 978233Snate@binkert.org def __gt__(self, other): return self.filename > other.filename 988233Snate@binkert.org def __ge__(self, other): return self.filename >= other.filename 998233Snate@binkert.org def __eq__(self, other): return self.filename == other.filename 1006143Snate@binkert.org def __ne__(self, other): return self.filename != other.filename 1018233Snate@binkert.org 1028233Snate@binkert.orgclass Source(SourceFile): 1038233Snate@binkert.org '''Add a c/c++ source file to the build''' 1048233Snate@binkert.org def __init__(self, source, Werror=True, swig=False, bin_only=False, 1056143Snate@binkert.org skip_lib=False): 1066143Snate@binkert.org super(Source, self).__init__(source) 1076143Snate@binkert.org 1086143Snate@binkert.org self.Werror = Werror 1096143Snate@binkert.org self.swig = swig 1106143Snate@binkert.org self.bin_only = bin_only 1116143Snate@binkert.org self.skip_lib = bin_only or skip_lib 1126143Snate@binkert.org 1136143Snate@binkert.orgclass PySource(SourceFile): 1147065Snate@binkert.org '''Add a python source file to the named package''' 1156143Snate@binkert.org invalid_sym_char = re.compile('[^A-z0-9_]') 1168233Snate@binkert.org modules = {} 1178233Snate@binkert.org tnodes = {} 1188233Snate@binkert.org symnames = {} 1198233Snate@binkert.org 1208233Snate@binkert.org def __init__(self, package, source): 1218233Snate@binkert.org super(PySource, self).__init__(source) 1228233Snate@binkert.org 1238233Snate@binkert.org modname,ext = self.extname 1248233Snate@binkert.org assert ext == 'py' 1258233Snate@binkert.org 1268233Snate@binkert.org if package: 1278233Snate@binkert.org path = package.split('.') 1288233Snate@binkert.org else: 1298233Snate@binkert.org path = [] 1308233Snate@binkert.org 1318233Snate@binkert.org modpath = path[:] 1328233Snate@binkert.org if modname != '__init__': 1338233Snate@binkert.org modpath += [ modname ] 1348233Snate@binkert.org modpath = '.'.join(modpath) 1358233Snate@binkert.org 1368233Snate@binkert.org arcpath = path + [ self.basename ] 1378233Snate@binkert.org abspath = self.snode.abspath 1388233Snate@binkert.org if not exists(abspath): 1398233Snate@binkert.org abspath = self.tnode.abspath 1408233Snate@binkert.org 1418233Snate@binkert.org self.package = package 1428233Snate@binkert.org self.modname = modname 1438233Snate@binkert.org self.modpath = modpath 1448233Snate@binkert.org self.arcname = joinpath(*arcpath) 1458233Snate@binkert.org self.abspath = abspath 1468233Snate@binkert.org self.compiled = File(self.filename + 'c') 1476143Snate@binkert.org self.cpp = File(self.filename + '.cc') 1486143Snate@binkert.org self.symname = PySource.invalid_sym_char.sub('_', modpath) 1496143Snate@binkert.org 1506143Snate@binkert.org PySource.modules[modpath] = self 1516143Snate@binkert.org PySource.tnodes[self.tnode] = self 1526143Snate@binkert.org PySource.symnames[self.symname] = self 1539982Satgutier@umich.edu 15410196SCurtis.Dunham@arm.comclass SimObject(PySource): 15510196SCurtis.Dunham@arm.com '''Add a SimObject python file as a python source object and add 15610196SCurtis.Dunham@arm.com it to a list of sim object modules''' 15710196SCurtis.Dunham@arm.com 15810196SCurtis.Dunham@arm.com fixed = False 15910196SCurtis.Dunham@arm.com modnames = [] 16010196SCurtis.Dunham@arm.com 16110196SCurtis.Dunham@arm.com def __init__(self, source): 1626143Snate@binkert.org super(SimObject, self).__init__('m5.objects', source) 1636143Snate@binkert.org if self.fixed: 1648945Ssteve.reinhardt@amd.com raise AttributeError, "Too late to call SimObject now." 1658233Snate@binkert.org 1668233Snate@binkert.org bisect.insort_right(SimObject.modnames, self.modname) 1676143Snate@binkert.org 1688945Ssteve.reinhardt@amd.comclass SwigSource(SourceFile): 1696143Snate@binkert.org '''Add a swig file to build''' 1706143Snate@binkert.org 1716143Snate@binkert.org def __init__(self, package, source): 1726143Snate@binkert.org super(SwigSource, self).__init__(source) 1735522Snate@binkert.org 1746143Snate@binkert.org modname,ext = self.extname 1756143Snate@binkert.org assert ext == 'i' 1766143Snate@binkert.org 1779982Satgutier@umich.edu self.module = modname 1788233Snate@binkert.org cc_file = joinpath(self.dirname, modname + '_wrap.cc') 1798233Snate@binkert.org py_file = joinpath(self.dirname, modname + '.py') 1808233Snate@binkert.org 1816143Snate@binkert.org self.cc_source = Source(cc_file, swig=True) 1826143Snate@binkert.org self.py_source = PySource(package, py_file) 1836143Snate@binkert.org 1846143Snate@binkert.orgunit_tests = [] 1855522Snate@binkert.orgdef UnitTest(target, sources): 1865522Snate@binkert.org if not isinstance(sources, (list, tuple)): 1875522Snate@binkert.org sources = [ sources ] 1885522Snate@binkert.org 1895604Snate@binkert.org sources = [ Source(src, skip_lib=True) for src in sources ] 1905604Snate@binkert.org unit_tests.append((target, sources)) 1916143Snate@binkert.org 1926143Snate@binkert.org# Children should have access 1934762Snate@binkert.orgExport('Source') 1944762Snate@binkert.orgExport('PySource') 1956143Snate@binkert.orgExport('SimObject') 1966727Ssteve.reinhardt@amd.comExport('SwigSource') 1976727Ssteve.reinhardt@amd.comExport('UnitTest') 1986727Ssteve.reinhardt@amd.com 1994762Snate@binkert.org######################################################################## 2006143Snate@binkert.org# 2016143Snate@binkert.org# Trace Flags 2026143Snate@binkert.org# 2036143Snate@binkert.orgtrace_flags = {} 2046727Ssteve.reinhardt@amd.comdef TraceFlag(name, desc=None): 2056143Snate@binkert.org if name in trace_flags: 2067674Snate@binkert.org raise AttributeError, "Flag %s already specified" % name 2077674Snate@binkert.org trace_flags[name] = (name, (), desc) 2085604Snate@binkert.org 2096143Snate@binkert.orgdef CompoundFlag(name, flags, desc=None): 2106143Snate@binkert.org if name in trace_flags: 2116143Snate@binkert.org raise AttributeError, "Flag %s already specified" % name 2124762Snate@binkert.org 2136143Snate@binkert.org compound = tuple(flags) 2144762Snate@binkert.org trace_flags[name] = (name, compound, desc) 2154762Snate@binkert.org 2164762Snate@binkert.orgExport('TraceFlag') 2176143Snate@binkert.orgExport('CompoundFlag') 2186143Snate@binkert.org 2194762Snate@binkert.org######################################################################## 2208233Snate@binkert.org# 2218233Snate@binkert.org# Set some compiler variables 2228233Snate@binkert.org# 2238233Snate@binkert.org 2246143Snate@binkert.org# Include file paths are rooted in this directory. SCons will 2256143Snate@binkert.org# automatically expand '.' to refer to both the source directory and 2264762Snate@binkert.org# the corresponding build directory to pick up generated include 2276143Snate@binkert.org# files. 2284762Snate@binkert.orgenv.Append(CPPPATH=Dir('.')) 2296143Snate@binkert.org 2304762Snate@binkert.orgfor extra_dir in extras_dir_list: 2316143Snate@binkert.org env.Append(CPPPATH=Dir(extra_dir)) 2328233Snate@binkert.org 2338233Snate@binkert.org# Workaround for bug in SCons version > 0.97d20071212 23410453SAndrew.Bardsley@arm.com# Scons bug id: 2006 M5 Bug id: 308 2356143Snate@binkert.orgfor root, dirs, files in os.walk(base_dir, topdown=True): 2366143Snate@binkert.org Dir(root[len(base_dir) + 1:]) 2376143Snate@binkert.org 2386143Snate@binkert.org######################################################################## 2396143Snate@binkert.org# 2406143Snate@binkert.org# Walk the tree and execute all SConscripts in subdirectories 2416143Snate@binkert.org# 2426143Snate@binkert.org 24310453SAndrew.Bardsley@arm.comhere = Dir('.').srcnode().abspath 24410453SAndrew.Bardsley@arm.comfor root, dirs, files in os.walk(base_dir, topdown=True): 245955SN/A if root == here: 2469396Sandreas.hansson@arm.com # we don't want to recurse back into this SConscript 2479396Sandreas.hansson@arm.com continue 2489396Sandreas.hansson@arm.com 2499396Sandreas.hansson@arm.com if 'SConscript' in files: 2509396Sandreas.hansson@arm.com build_dir = joinpath(env['BUILDDIR'], root[len(base_dir) + 1:]) 2519396Sandreas.hansson@arm.com SConscript(joinpath(root, 'SConscript'), build_dir=build_dir) 2529396Sandreas.hansson@arm.com 2539396Sandreas.hansson@arm.comfor extra_dir in extras_dir_list: 2549396Sandreas.hansson@arm.com prefix_len = len(dirname(extra_dir)) + 1 2559396Sandreas.hansson@arm.com for root, dirs, files in os.walk(extra_dir, topdown=True): 2569396Sandreas.hansson@arm.com if 'SConscript' in files: 2579396Sandreas.hansson@arm.com build_dir = joinpath(env['BUILDDIR'], root[prefix_len:]) 2589396Sandreas.hansson@arm.com SConscript(joinpath(root, 'SConscript'), build_dir=build_dir) 2599930Sandreas.hansson@arm.com 2609930Sandreas.hansson@arm.comfor opt in export_vars: 2619396Sandreas.hansson@arm.com env.ConfigFile(opt) 2628235Snate@binkert.org 2638235Snate@binkert.orgdef makeTheISA(source, target, env): 2646143Snate@binkert.org isas = [ src.get_contents() for src in source ] 2658235Snate@binkert.org target_isa = env['TARGET_ISA'] 2669003SAli.Saidi@ARM.com def define(isa): 2678235Snate@binkert.org return isa.upper() + '_ISA' 2688235Snate@binkert.org 2698235Snate@binkert.org def namespace(isa): 2708235Snate@binkert.org return isa[0].upper() + isa[1:].lower() + 'ISA' 2718235Snate@binkert.org 2728235Snate@binkert.org 2738235Snate@binkert.org code = code_formatter() 2748235Snate@binkert.org code('''\ 2758235Snate@binkert.org#ifndef __CONFIG_THE_ISA_HH__ 2768235Snate@binkert.org#define __CONFIG_THE_ISA_HH__ 2778235Snate@binkert.org 2788235Snate@binkert.org''') 2798235Snate@binkert.org 2808235Snate@binkert.org for i,isa in enumerate(isas): 2819003SAli.Saidi@ARM.com code('#define $0 $1', define(isa), i + 1) 2828235Snate@binkert.org 2835584Snate@binkert.org code(''' 2844382Sbinkertn@umich.edu 2854202Sbinkertn@umich.edu#define THE_ISA ${{define(target_isa)}} 2864382Sbinkertn@umich.edu#define TheISA ${{namespace(target_isa)}} 2874382Sbinkertn@umich.edu 2884382Sbinkertn@umich.edu#endif // __CONFIG_THE_ISA_HH__''') 2899396Sandreas.hansson@arm.com 2905584Snate@binkert.org code.write(str(target[0])) 2914382Sbinkertn@umich.edu 2924382Sbinkertn@umich.eduenv.Command('config/the_isa.hh', map(Value, all_isa_list), makeTheISA) 2934382Sbinkertn@umich.edu 2948232Snate@binkert.org######################################################################## 2955192Ssaidi@eecs.umich.edu# 2968232Snate@binkert.org# Prevent any SimObjects from being added after this point, they 2978232Snate@binkert.org# should all have been added in the SConscripts above 2988232Snate@binkert.org# 2995192Ssaidi@eecs.umich.eduSimObject.fixed = True 3008232Snate@binkert.org 3015192Ssaidi@eecs.umich.educlass DictImporter(object): 3025799Snate@binkert.org '''This importer takes a dictionary of arbitrary module names that 3038232Snate@binkert.org map to arbitrary filenames.''' 3045192Ssaidi@eecs.umich.edu def __init__(self, modules): 3055192Ssaidi@eecs.umich.edu self.modules = modules 3065192Ssaidi@eecs.umich.edu self.installed = set() 3078232Snate@binkert.org 3085192Ssaidi@eecs.umich.edu def __del__(self): 3098232Snate@binkert.org self.unload() 3105192Ssaidi@eecs.umich.edu 3115192Ssaidi@eecs.umich.edu def unload(self): 3125192Ssaidi@eecs.umich.edu import sys 3135192Ssaidi@eecs.umich.edu for module in self.installed: 3144382Sbinkertn@umich.edu del sys.modules[module] 3154382Sbinkertn@umich.edu self.installed = set() 3164382Sbinkertn@umich.edu 3172667Sstever@eecs.umich.edu def find_module(self, fullname, path): 3182667Sstever@eecs.umich.edu if fullname == 'm5.defines': 3192667Sstever@eecs.umich.edu return self 3202667Sstever@eecs.umich.edu 3212667Sstever@eecs.umich.edu if fullname == 'm5.objects': 3222667Sstever@eecs.umich.edu return self 3235742Snate@binkert.org 3245742Snate@binkert.org if fullname.startswith('m5.internal'): 3255742Snate@binkert.org return None 3265793Snate@binkert.org 3278334Snate@binkert.org source = self.modules.get(fullname, None) 3285793Snate@binkert.org if source is not None and fullname.startswith('m5.objects'): 3295793Snate@binkert.org return self 3305793Snate@binkert.org 3314382Sbinkertn@umich.edu return None 3324762Snate@binkert.org 3335344Sstever@gmail.com def load_module(self, fullname): 3344382Sbinkertn@umich.edu mod = imp.new_module(fullname) 3355341Sstever@gmail.com sys.modules[fullname] = mod 3365742Snate@binkert.org self.installed.add(fullname) 3375742Snate@binkert.org 3385742Snate@binkert.org mod.__loader__ = self 3395742Snate@binkert.org if fullname == 'm5.objects': 3405742Snate@binkert.org mod.__path__ = fullname.split('.') 3414762Snate@binkert.org return mod 3425742Snate@binkert.org 3435742Snate@binkert.org if fullname == 'm5.defines': 3447722Sgblack@eecs.umich.edu mod.__dict__['buildEnv'] = m5.util.SmartDict(build_env) 3455742Snate@binkert.org return mod 3465742Snate@binkert.org 3475742Snate@binkert.org source = self.modules[fullname] 3489930Sandreas.hansson@arm.com if source.modname == '__init__': 3499930Sandreas.hansson@arm.com mod.__path__ = source.modpath 3509930Sandreas.hansson@arm.com mod.__file__ = source.abspath 3519930Sandreas.hansson@arm.com 3529930Sandreas.hansson@arm.com exec file(source.abspath, 'r') in mod.__dict__ 3535742Snate@binkert.org 3548242Sbradley.danofsky@amd.com return mod 3558242Sbradley.danofsky@amd.com 3568242Sbradley.danofsky@amd.comimport m5.SimObject 3578242Sbradley.danofsky@amd.comimport m5.params 3585341Sstever@gmail.comfrom m5.util import code_formatter 3595742Snate@binkert.org 3607722Sgblack@eecs.umich.edum5.SimObject.clear() 3614773Snate@binkert.orgm5.params.clear() 3626108Snate@binkert.org 3631858SN/A# install the python importer so we can grab stuff from the source 3641085SN/A# tree itself. We can't have SimObjects added after this point or 3656658Snate@binkert.org# else we won't know about them for the rest of the stuff. 3666658Snate@binkert.orgimporter = DictImporter(PySource.modules) 3677673Snate@binkert.orgsys.meta_path[0:0] = [ importer ] 3686658Snate@binkert.org 3696658Snate@binkert.org# import all sim objects so we can populate the all_objects list 3706658Snate@binkert.org# make sure that we're working with a list, then let's sort it 3716658Snate@binkert.orgfor modname in SimObject.modnames: 3726658Snate@binkert.org exec('from m5.objects import %s' % modname) 3736658Snate@binkert.org 3746658Snate@binkert.org# we need to unload all of the currently imported modules so that they 3757673Snate@binkert.org# will be re-imported the next time the sconscript is run 3767673Snate@binkert.orgimporter.unload() 3777673Snate@binkert.orgsys.meta_path.remove(importer) 3787673Snate@binkert.org 3797673Snate@binkert.orgsim_objects = m5.SimObject.allClasses 3807673Snate@binkert.orgall_enums = m5.params.allEnums 3817673Snate@binkert.org 38210467Sandreas.hansson@arm.comall_params = {} 3836658Snate@binkert.orgfor name,obj in sorted(sim_objects.iteritems()): 3847673Snate@binkert.org for param in obj._params.local.values(): 38510467Sandreas.hansson@arm.com # load the ptype attribute now because it depends on the 38610467Sandreas.hansson@arm.com # current version of SimObject.allClasses, but when scons 38710467Sandreas.hansson@arm.com # actually uses the value, all versions of 38810467Sandreas.hansson@arm.com # SimObject.allClasses will have been loaded 38910467Sandreas.hansson@arm.com param.ptype 39010467Sandreas.hansson@arm.com 39110467Sandreas.hansson@arm.com if not hasattr(param, 'swig_decl'): 39210467Sandreas.hansson@arm.com continue 39310467Sandreas.hansson@arm.com pname = param.ptype_str 39410467Sandreas.hansson@arm.com if pname not in all_params: 39510467Sandreas.hansson@arm.com all_params[pname] = param 3967673Snate@binkert.org 3977673Snate@binkert.org######################################################################## 3987673Snate@binkert.org# 3997673Snate@binkert.org# calculate extra dependencies 4007673Snate@binkert.org# 4019048SAli.Saidi@ARM.commodule_depends = ["m5", "m5.SimObject", "m5.params"] 4027673Snate@binkert.orgdepends = [ PySource.modules[dep].tnode for dep in module_depends ] 4037673Snate@binkert.org 4047673Snate@binkert.org######################################################################## 4057673Snate@binkert.org# 4066658Snate@binkert.org# Commands for the basic automatically generated python files 4077756SAli.Saidi@ARM.com# 4087816Ssteve.reinhardt@amd.com 4096658Snate@binkert.org# Generate Python file containing a dict specifying the current 4104382Sbinkertn@umich.edu# buildEnv flags. 4114382Sbinkertn@umich.edudef makeDefinesPyFile(target, source, env): 4124762Snate@binkert.org build_env, hg_info = [ x.get_contents() for x in source ] 4134762Snate@binkert.org 4144762Snate@binkert.org code = code_formatter() 4156654Snate@binkert.org code(""" 4166654Snate@binkert.orgimport m5.internal 4175517Snate@binkert.orgimport m5.util 4185517Snate@binkert.org 4195517Snate@binkert.orgbuildEnv = m5.util.SmartDict($build_env) 4205517Snate@binkert.orghgRev = '$hg_info' 4215517Snate@binkert.org 4225517Snate@binkert.orgcompileDate = m5.internal.core.compileDate 4235517Snate@binkert.org_globals = globals() 4245517Snate@binkert.orgfor key,val in m5.internal.core.__dict__.iteritems(): 4255517Snate@binkert.org if key.startswith('flag_'): 4265517Snate@binkert.org flag = key[5:] 4275517Snate@binkert.org _globals[flag] = val 4285517Snate@binkert.orgdel _globals 4295517Snate@binkert.org""") 4305517Snate@binkert.org code.write(target[0].abspath) 4315517Snate@binkert.org 4325517Snate@binkert.orgdefines_info = [ Value(build_env), Value(env['HG_INFO']) ] 4335517Snate@binkert.org# Generate a file with all of the compile options in it 4346654Snate@binkert.orgenv.Command('python/m5/defines.py', defines_info, makeDefinesPyFile) 4355517Snate@binkert.orgPySource('m5', 'python/m5/defines.py') 4365517Snate@binkert.org 4375517Snate@binkert.org# Generate python file containing info about the M5 source code 4385517Snate@binkert.orgdef makeInfoPyFile(target, source, env): 4395517Snate@binkert.org code = code_formatter() 4405517Snate@binkert.org for src in source: 4415517Snate@binkert.org data = ''.join(file(src.srcnode().abspath, 'r').xreadlines()) 4425517Snate@binkert.org code('$src = ${{repr(data)}}') 4436143Snate@binkert.org code.write(str(target[0])) 4446654Snate@binkert.org 4455517Snate@binkert.org# Generate a file that wraps the basic top level files 4465517Snate@binkert.orgenv.Command('python/m5/info.py', 4475517Snate@binkert.org [ '#/AUTHORS', '#/LICENSE', '#/README', '#/RELEASE_NOTES' ], 4485517Snate@binkert.org makeInfoPyFile) 4495517Snate@binkert.orgPySource('m5', 'python/m5/info.py') 4505517Snate@binkert.org 4515517Snate@binkert.org######################################################################## 4525517Snate@binkert.org# 4535517Snate@binkert.org# Create all of the SimObject param headers and enum headers 4545517Snate@binkert.org# 4555517Snate@binkert.org 4565517Snate@binkert.orgdef createSimObjectParam(target, source, env): 4575517Snate@binkert.org assert len(target) == 1 and len(source) == 1 4585517Snate@binkert.org 4596654Snate@binkert.org name = str(source[0].get_contents()) 4606654Snate@binkert.org obj = sim_objects[name] 4615517Snate@binkert.org 4625517Snate@binkert.org code = code_formatter() 4636143Snate@binkert.org obj.cxx_decl(code) 4646143Snate@binkert.org code.write(target[0].abspath) 4656143Snate@binkert.org 4666727Ssteve.reinhardt@amd.comdef createSwigParam(target, source, env): 4675517Snate@binkert.org assert len(target) == 1 and len(source) == 1 4686727Ssteve.reinhardt@amd.com 4695517Snate@binkert.org name = str(source[0].get_contents()) 4705517Snate@binkert.org param = all_params[name] 4715517Snate@binkert.org 4726654Snate@binkert.org code = code_formatter() 4736654Snate@binkert.org param.swig_decl(code) 4747673Snate@binkert.org code.write(target[0].abspath) 4756654Snate@binkert.org 4766654Snate@binkert.orgdef createEnumStrings(target, source, env): 4776654Snate@binkert.org assert len(target) == 1 and len(source) == 1 4786654Snate@binkert.org 4795517Snate@binkert.org name = str(source[0].get_contents()) 4805517Snate@binkert.org obj = all_enums[name] 4815517Snate@binkert.org 4826143Snate@binkert.org code = code_formatter() 4835517Snate@binkert.org obj.cxx_def(code) 4844762Snate@binkert.org code.write(target[0].abspath) 4855517Snate@binkert.org 4865517Snate@binkert.orgdef createEnumParam(target, source, env): 4876143Snate@binkert.org assert len(target) == 1 and len(source) == 1 4886143Snate@binkert.org 4895517Snate@binkert.org name = str(source[0].get_contents()) 4905517Snate@binkert.org obj = all_enums[name] 4915517Snate@binkert.org 4925517Snate@binkert.org code = code_formatter() 4935517Snate@binkert.org obj.cxx_decl(code) 4945517Snate@binkert.org code.write(target[0].abspath) 4955517Snate@binkert.org 4965517Snate@binkert.org# Generate all of the SimObject param struct header files 4975517Snate@binkert.orgparams_hh_files = [] 4989338SAndreas.Sandberg@arm.comfor name,simobj in sorted(sim_objects.iteritems()): 4999338SAndreas.Sandberg@arm.com py_source = PySource.modules[simobj.__module__] 5009338SAndreas.Sandberg@arm.com extra_deps = [ py_source.tnode ] 5019338SAndreas.Sandberg@arm.com 5029338SAndreas.Sandberg@arm.com hh_file = File('params/%s.hh' % name) 5039338SAndreas.Sandberg@arm.com params_hh_files.append(hh_file) 5048596Ssteve.reinhardt@amd.com env.Command(hh_file, Value(name), createSimObjectParam) 5058596Ssteve.reinhardt@amd.com env.Depends(hh_file, depends + extra_deps) 5068596Ssteve.reinhardt@amd.com 5078596Ssteve.reinhardt@amd.com# Generate any parameter header files needed 5088596Ssteve.reinhardt@amd.comparams_i_files = [] 5098596Ssteve.reinhardt@amd.comfor name,param in all_params.iteritems(): 5108596Ssteve.reinhardt@amd.com i_file = File('params/%s_%s.i' % (name, param.file_ext)) 5116143Snate@binkert.org params_i_files.append(i_file) 5125517Snate@binkert.org env.Command(i_file, Value(name), createSwigParam) 5136654Snate@binkert.org env.Depends(i_file, depends) 5146654Snate@binkert.org 5156654Snate@binkert.org# Generate all enum header files 5166654Snate@binkert.orgfor name,enum in sorted(all_enums.iteritems()): 5176654Snate@binkert.org py_source = PySource.modules[enum.__module__] 5186654Snate@binkert.org extra_deps = [ py_source.tnode ] 5195517Snate@binkert.org 5205517Snate@binkert.org cc_file = File('enums/%s.cc' % name) 5215517Snate@binkert.org env.Command(cc_file, Value(name), createEnumStrings) 5228596Ssteve.reinhardt@amd.com env.Depends(cc_file, depends + extra_deps) 5238596Ssteve.reinhardt@amd.com Source(cc_file) 5244762Snate@binkert.org 5254762Snate@binkert.org hh_file = File('enums/%s.hh' % name) 5264762Snate@binkert.org env.Command(hh_file, Value(name), createEnumParam) 5274762Snate@binkert.org env.Depends(hh_file, depends + extra_deps) 5284762Snate@binkert.org 5294762Snate@binkert.org# Build the big monolithic swigged params module (wraps all SimObject 5307675Snate@binkert.org# param structs and enum structs) 53110584Sandreas.hansson@arm.comdef buildParams(target, source, env): 5324762Snate@binkert.org names = [ s.get_contents() for s in source ] 5334762Snate@binkert.org objs = [ sim_objects[name] for name in names ] 5344762Snate@binkert.org 5354762Snate@binkert.org ordered_objs = [] 5364382Sbinkertn@umich.edu obj_seen = set() 5374382Sbinkertn@umich.edu def order_obj(obj): 5385517Snate@binkert.org name = str(obj) 5396654Snate@binkert.org if name in obj_seen: 5405517Snate@binkert.org return 5418126Sgblack@eecs.umich.edu 5426654Snate@binkert.org obj_seen.add(name) 5437673Snate@binkert.org if str(obj) != 'SimObject': 5446654Snate@binkert.org order_obj(obj.__bases__[0]) 5456654Snate@binkert.org 5466654Snate@binkert.org ordered_objs.append(obj) 5476654Snate@binkert.org 5486654Snate@binkert.org for obj in objs: 5496654Snate@binkert.org order_obj(obj) 5506654Snate@binkert.org 5516669Snate@binkert.org code = code_formatter() 5526669Snate@binkert.org code('%module params') 5536669Snate@binkert.org 5546669Snate@binkert.org code('%{') 5556669Snate@binkert.org for obj in ordered_objs: 5566669Snate@binkert.org code('#include "params/$obj.hh"') 5576654Snate@binkert.org code('%}') 5587673Snate@binkert.org 5595517Snate@binkert.org for obj in ordered_objs: 5608126Sgblack@eecs.umich.edu params = obj._params.local.values() 5615798Snate@binkert.org for param in params: 5627756SAli.Saidi@ARM.com param.swig_predecls(code) 5637816Ssteve.reinhardt@amd.com 5645798Snate@binkert.org enums = set() 5655798Snate@binkert.org for obj in ordered_objs: 5665517Snate@binkert.org params = obj._params.local.values() 5675517Snate@binkert.org for param in params: 5687673Snate@binkert.org ptype = param.ptype 5695517Snate@binkert.org if issubclass(ptype, m5.params.Enum) and ptype not in enums: 5705517Snate@binkert.org enums.add(ptype) 5717673Snate@binkert.org code('%include "enums/$0.hh"', ptype.__name__) 5727673Snate@binkert.org 5735517Snate@binkert.org for obj in ordered_objs: 5745798Snate@binkert.org obj.swig_objdecls(code) 5755798Snate@binkert.org code() 5768333Snate@binkert.org 5777816Ssteve.reinhardt@amd.com for obj in ordered_objs: 5785798Snate@binkert.org continue 5795798Snate@binkert.org if obj.swig_objdecls: 5804762Snate@binkert.org obj.swig_objdecls(code) 5814762Snate@binkert.org continue 5824762Snate@binkert.org 5834762Snate@binkert.org class_path = obj.cxx_class.split('::') 5844762Snate@binkert.org classname = class_path[-1] 5858596Ssteve.reinhardt@amd.com namespaces = class_path[:-1] 5865517Snate@binkert.org 5875517Snate@binkert.org for ns in namespaces: 5885517Snate@binkert.org code('namespace $ns {') 5895517Snate@binkert.org 5905517Snate@binkert.org if namespaces: 5917673Snate@binkert.org code('// avoid name conflicts') 5928596Ssteve.reinhardt@amd.com sep_string = '_COLONS_' 5937673Snate@binkert.org flat_name = sep_string.join(class_path) 5945517Snate@binkert.org code('%rename($flat_name) $classname;') 59510458Sandreas.hansson@arm.com 59610458Sandreas.hansson@arm.com code('// stop swig from creating/wrapping default ctor/dtor') 59710458Sandreas.hansson@arm.com code('%nodefault $classname;') 59810458Sandreas.hansson@arm.com if obj._base: 59910458Sandreas.hansson@arm.com code('class $classname : public ${{obj._base.cxx_class}} {};') 60010458Sandreas.hansson@arm.com else: 60110458Sandreas.hansson@arm.com code('class $classname {};') 60210458Sandreas.hansson@arm.com 60310458Sandreas.hansson@arm.com for ns in reversed(namespaces): 60410458Sandreas.hansson@arm.com code('/* namespace $ns */ }') 60510458Sandreas.hansson@arm.com code() 60610458Sandreas.hansson@arm.com 6078596Ssteve.reinhardt@amd.com code('%include "src/sim/sim_object_params.hh"') 6085517Snate@binkert.org for obj in ordered_objs: 6095517Snate@binkert.org code('%include "params/$obj.hh"') 6105517Snate@binkert.org 6118596Ssteve.reinhardt@amd.com code.write(target[0].abspath) 6125517Snate@binkert.org 6137673Snate@binkert.orgparams_file = File('params/params.i') 6147673Snate@binkert.orgnames = sorted(sim_objects.keys()) 6157673Snate@binkert.orgenv.Command(params_file, map(Value, names), buildParams) 6165517Snate@binkert.orgenv.Depends(params_file, params_hh_files + params_i_files + depends) 6175517Snate@binkert.orgSwigSource('m5.objects', params_file) 6185517Snate@binkert.org 6195517Snate@binkert.org# Generate the main swig init file 6205517Snate@binkert.orgdef makeEmbeddedSwigInit(target, source, env): 6215517Snate@binkert.org code = code_formatter() 6225517Snate@binkert.org module = source[0].get_contents() 6237673Snate@binkert.org code('''\ 6247673Snate@binkert.org#include "sim/init.hh" 6257673Snate@binkert.org 6265517Snate@binkert.orgextern "C" { 6278596Ssteve.reinhardt@amd.com void init_${module}(); 6285517Snate@binkert.org} 6295517Snate@binkert.org 6305517Snate@binkert.orgEmbeddedSwig embed_swig_${module}(init_${module}); 6315517Snate@binkert.org''') 6325517Snate@binkert.org code.write(str(target[0])) 6337673Snate@binkert.org 6347673Snate@binkert.org# Build all swig modules 6357673Snate@binkert.orgfor swig in SwigSource.all: 6365517Snate@binkert.org env.Command([swig.cc_source.tnode, swig.py_source.tnode], swig.tnode, 6378596Ssteve.reinhardt@amd.com '$SWIG $SWIGFLAGS -outdir ${TARGETS[1].dir} ' 6387675Snate@binkert.org '-o ${TARGETS[0]} $SOURCES') 6397675Snate@binkert.org init_file = 'python/swig/init_%s.cc' % swig.module 6407675Snate@binkert.org env.Command(init_file, Value(swig.module), makeEmbeddedSwigInit) 6417675Snate@binkert.org Source(init_file) 6427675Snate@binkert.org env.Depends(swig.py_source.tnode, swig.tnode) 6437675Snate@binkert.org env.Depends(swig.cc_source.tnode, swig.tnode) 6448596Ssteve.reinhardt@amd.com 6457675Snate@binkert.orgdef getFlags(source_flags): 6467675Snate@binkert.org flagsMap = {} 6478596Ssteve.reinhardt@amd.com flagsList = [] 6488596Ssteve.reinhardt@amd.com for s in source_flags: 6498596Ssteve.reinhardt@amd.com val = eval(s.get_contents()) 6508596Ssteve.reinhardt@amd.com name, compound, desc = val 6518596Ssteve.reinhardt@amd.com flagsList.append(val) 6528596Ssteve.reinhardt@amd.com flagsMap[name] = bool(compound) 6538596Ssteve.reinhardt@amd.com 6548596Ssteve.reinhardt@amd.com for name, compound, desc in flagsList: 65510454SCurtis.Dunham@arm.com for flag in compound: 65610454SCurtis.Dunham@arm.com if flag not in flagsMap: 65710454SCurtis.Dunham@arm.com raise AttributeError, "Trace flag %s not found" % flag 65810454SCurtis.Dunham@arm.com if flagsMap[flag]: 6598596Ssteve.reinhardt@amd.com raise AttributeError, \ 6604762Snate@binkert.org "Compound flag can't point to another compound flag" 6616143Snate@binkert.org 6626143Snate@binkert.org flagsList.sort() 6636143Snate@binkert.org return flagsList 6644762Snate@binkert.org 6654762Snate@binkert.org 6664762Snate@binkert.org# Generate traceflags.py 6677756SAli.Saidi@ARM.comdef traceFlagsPy(target, source, env): 6688596Ssteve.reinhardt@amd.com assert(len(target) == 1) 6694762Snate@binkert.org code = code_formatter() 67010454SCurtis.Dunham@arm.com 6714762Snate@binkert.org allFlags = getFlags(source) 67210458Sandreas.hansson@arm.com 67310458Sandreas.hansson@arm.com code('basic = [') 67410458Sandreas.hansson@arm.com code.indent() 67510458Sandreas.hansson@arm.com for flag, compound, desc in allFlags: 67610458Sandreas.hansson@arm.com if not compound: 67710458Sandreas.hansson@arm.com code("'$flag',") 67810458Sandreas.hansson@arm.com code(']') 67910458Sandreas.hansson@arm.com code.dedent() 68010458Sandreas.hansson@arm.com code() 68110458Sandreas.hansson@arm.com 68210458Sandreas.hansson@arm.com code('compound = [') 68310458Sandreas.hansson@arm.com code.indent() 68410458Sandreas.hansson@arm.com code("'All',") 68510458Sandreas.hansson@arm.com for flag, compound, desc in allFlags: 68610458Sandreas.hansson@arm.com if compound: 68710458Sandreas.hansson@arm.com code("'$flag',") 68810458Sandreas.hansson@arm.com code("]") 68910458Sandreas.hansson@arm.com code.dedent() 69010458Sandreas.hansson@arm.com code() 69110458Sandreas.hansson@arm.com 69210458Sandreas.hansson@arm.com code("all = frozenset(basic + compound)") 69310458Sandreas.hansson@arm.com code() 69410458Sandreas.hansson@arm.com 69510458Sandreas.hansson@arm.com code('compoundMap = {') 69610458Sandreas.hansson@arm.com code.indent() 69710458Sandreas.hansson@arm.com all = tuple([flag for flag,compound,desc in allFlags if not compound]) 69810458Sandreas.hansson@arm.com code("'All' : $all,") 69910458Sandreas.hansson@arm.com for flag, compound, desc in allFlags: 70010458Sandreas.hansson@arm.com if compound: 70110458Sandreas.hansson@arm.com code("'$flag' : $compound,") 70210458Sandreas.hansson@arm.com code('}') 70310458Sandreas.hansson@arm.com code.dedent() 70410458Sandreas.hansson@arm.com code() 70510458Sandreas.hansson@arm.com 70610458Sandreas.hansson@arm.com code('descriptions = {') 70710458Sandreas.hansson@arm.com code.indent() 70810458Sandreas.hansson@arm.com code("'All' : 'All flags',") 70910458Sandreas.hansson@arm.com for flag, compound, desc in allFlags: 71010458Sandreas.hansson@arm.com code("'$flag' : '$desc',") 71110458Sandreas.hansson@arm.com code("}") 71210458Sandreas.hansson@arm.com code.dedent() 71310458Sandreas.hansson@arm.com 71410458Sandreas.hansson@arm.com code.write(str(target[0])) 71510458Sandreas.hansson@arm.com 71610458Sandreas.hansson@arm.comdef traceFlagsCC(target, source, env): 71710458Sandreas.hansson@arm.com assert(len(target) == 1) 71810458Sandreas.hansson@arm.com 71910458Sandreas.hansson@arm.com allFlags = getFlags(source) 72010458Sandreas.hansson@arm.com code = code_formatter() 72110584Sandreas.hansson@arm.com 72210458Sandreas.hansson@arm.com # file header 72310458Sandreas.hansson@arm.com code(''' 72410458Sandreas.hansson@arm.com/* 72510458Sandreas.hansson@arm.com * DO NOT EDIT THIS FILE! Automatically generated 72610458Sandreas.hansson@arm.com */ 7278596Ssteve.reinhardt@amd.com 7285463Snate@binkert.org#include "base/traceflags.hh" 72910584Sandreas.hansson@arm.com 7308596Ssteve.reinhardt@amd.comusing namespace Trace; 7315463Snate@binkert.org 7327756SAli.Saidi@ARM.comconst char *Trace::flagStrings[] = 7338596Ssteve.reinhardt@amd.com{''') 7344762Snate@binkert.org 73510454SCurtis.Dunham@arm.com code.indent() 7367677Snate@binkert.org # The string array is used by SimpleEnumParam to map the strings 7374762Snate@binkert.org # provided by the user to enum values. 7384762Snate@binkert.org for flag, compound, desc in allFlags: 7396143Snate@binkert.org if not compound: 7406143Snate@binkert.org code('"$flag",') 7416143Snate@binkert.org 7424762Snate@binkert.org code('"All",') 7434762Snate@binkert.org for flag, compound, desc in allFlags: 7447756SAli.Saidi@ARM.com if compound: 7457816Ssteve.reinhardt@amd.com code('"$flag",') 7464762Snate@binkert.org code.dedent() 74710454SCurtis.Dunham@arm.com 7484762Snate@binkert.org code('''\ 7494762Snate@binkert.org}; 7504762Snate@binkert.org 7517756SAli.Saidi@ARM.comconst int Trace::numFlagStrings = ${{len(allFlags) + 1}}; 7528596Ssteve.reinhardt@amd.com 7534762Snate@binkert.org''') 75410454SCurtis.Dunham@arm.com 7554762Snate@binkert.org # Now define the individual compound flag arrays. There is an array 7567677Snate@binkert.org # for each compound flag listing the component base flags. 7577756SAli.Saidi@ARM.com all = tuple([flag for flag,compound,desc in allFlags if not compound]) 7588596Ssteve.reinhardt@amd.com code('static const Flags AllMap[] = {') 7597675Snate@binkert.org code.indent() 76010454SCurtis.Dunham@arm.com for flag, compound, desc in allFlags: 7617677Snate@binkert.org if not compound: 7625517Snate@binkert.org code('$flag,') 7638596Ssteve.reinhardt@amd.com code.dedent() 76410584Sandreas.hansson@arm.com code('};') 7659248SAndreas.Sandberg@arm.com code() 7669248SAndreas.Sandberg@arm.com 7678596Ssteve.reinhardt@amd.com for flag, compound, desc in allFlags: 7688596Ssteve.reinhardt@amd.com if not compound: 7698596Ssteve.reinhardt@amd.com continue 7709248SAndreas.Sandberg@arm.com code('static const Flags ${flag}Map[] = {') 7718596Ssteve.reinhardt@amd.com code.indent() 7724762Snate@binkert.org for flag in compound: 7737674Snate@binkert.org code('$flag,') 7747674Snate@binkert.org code('(Flags)-1') 7757674Snate@binkert.org code.dedent() 7767674Snate@binkert.org code('};') 7777674Snate@binkert.org code() 7787674Snate@binkert.org 7797674Snate@binkert.org # Finally the compoundFlags[] array maps the compound flags 7807674Snate@binkert.org # to their individual arrays/ 7817674Snate@binkert.org code('const Flags *Trace::compoundFlags[] = {') 7827674Snate@binkert.org code.indent() 7837674Snate@binkert.org code('AllMap,') 7847674Snate@binkert.org for flag, compound, desc in allFlags: 7857674Snate@binkert.org if compound: 7867674Snate@binkert.org code('${flag}Map,') 7877674Snate@binkert.org # file trailer 7884762Snate@binkert.org code.dedent() 7896143Snate@binkert.org code('};') 7906143Snate@binkert.org 7917756SAli.Saidi@ARM.com code.write(str(target[0])) 7927816Ssteve.reinhardt@amd.com 7938235Snate@binkert.orgdef traceFlagsHH(target, source, env): 7948596Ssteve.reinhardt@amd.com assert(len(target) == 1) 7957756SAli.Saidi@ARM.com 7967816Ssteve.reinhardt@amd.com allFlags = getFlags(source) 79710454SCurtis.Dunham@arm.com code = code_formatter() 7988235Snate@binkert.org 7994382Sbinkertn@umich.edu # file header boilerplate 8009396Sandreas.hansson@arm.com code('''\ 8019396Sandreas.hansson@arm.com/* 8029396Sandreas.hansson@arm.com * DO NOT EDIT THIS FILE! 8039396Sandreas.hansson@arm.com * 8049396Sandreas.hansson@arm.com * Automatically generated from traceflags.py 8059396Sandreas.hansson@arm.com */ 8069396Sandreas.hansson@arm.com 8079396Sandreas.hansson@arm.com#ifndef __BASE_TRACE_FLAGS_HH__ 8089396Sandreas.hansson@arm.com#define __BASE_TRACE_FLAGS_HH__ 8099396Sandreas.hansson@arm.com 8109396Sandreas.hansson@arm.comnamespace Trace { 8119396Sandreas.hansson@arm.com 81210454SCurtis.Dunham@arm.comenum Flags {''') 8139396Sandreas.hansson@arm.com 8149396Sandreas.hansson@arm.com # Generate the enum. Base flags come first, then compound flags. 8159396Sandreas.hansson@arm.com idx = 0 8169396Sandreas.hansson@arm.com code.indent() 8179396Sandreas.hansson@arm.com for flag, compound, desc in allFlags: 8189396Sandreas.hansson@arm.com if not compound: 8198232Snate@binkert.org code('$flag = $idx,') 8208232Snate@binkert.org idx += 1 8218232Snate@binkert.org 8228232Snate@binkert.org numBaseFlags = idx 8238232Snate@binkert.org code('NumFlags = $idx,') 8246229Snate@binkert.org code.dedent() 82510455SCurtis.Dunham@arm.com code() 8266229Snate@binkert.org 82710455SCurtis.Dunham@arm.com # put a comment in here to separate base from compound flags 82810455SCurtis.Dunham@arm.com code(''' 82910455SCurtis.Dunham@arm.com// The remaining enum values are *not* valid indices for Trace::flags. 8305517Snate@binkert.org// They are "compound" flags, which correspond to sets of base 8315517Snate@binkert.org// flags, and are used by changeFlag.''') 8327673Snate@binkert.org 8335517Snate@binkert.org code.indent() 83410455SCurtis.Dunham@arm.com code('All = $idx,') 8355517Snate@binkert.org idx += 1 8365517Snate@binkert.org for flag, compound, desc in allFlags: 8378232Snate@binkert.org if compound: 83810455SCurtis.Dunham@arm.com code('$flag = $idx,') 83910455SCurtis.Dunham@arm.com idx += 1 84010455SCurtis.Dunham@arm.com 8417673Snate@binkert.org numCompoundFlags = idx - numBaseFlags 8427673Snate@binkert.org code('NumCompoundFlags = $numCompoundFlags') 84310455SCurtis.Dunham@arm.com code.dedent() 84410455SCurtis.Dunham@arm.com 84510455SCurtis.Dunham@arm.com # trailer boilerplate 8465517Snate@binkert.org code('''\ 84710455SCurtis.Dunham@arm.com}; // enum Flags 84810455SCurtis.Dunham@arm.com 84910455SCurtis.Dunham@arm.com// Array of strings for SimpleEnumParam 85010455SCurtis.Dunham@arm.comextern const char *flagStrings[]; 85110455SCurtis.Dunham@arm.comextern const int numFlagStrings; 85210455SCurtis.Dunham@arm.com 85310455SCurtis.Dunham@arm.com// Array of arraay pointers: for each compound flag, gives the list of 85410455SCurtis.Dunham@arm.com// base flags to set. Inidividual flag arrays are terminated by -1. 85510685Sandreas.hansson@arm.comextern const Flags *compoundFlags[]; 85610455SCurtis.Dunham@arm.com 85710685Sandreas.hansson@arm.com/* namespace Trace */ } 85810455SCurtis.Dunham@arm.com 8595517Snate@binkert.org#endif // __BASE_TRACE_FLAGS_HH__ 86010455SCurtis.Dunham@arm.com''') 8618232Snate@binkert.org 8628232Snate@binkert.org code.write(str(target[0])) 8635517Snate@binkert.org 8647673Snate@binkert.orgflags = map(Value, trace_flags.values()) 8655517Snate@binkert.orgenv.Command('base/traceflags.py', flags, traceFlagsPy) 8668232Snate@binkert.orgPySource('m5', 'base/traceflags.py') 8678232Snate@binkert.org 8685517Snate@binkert.orgenv.Command('base/traceflags.hh', flags, traceFlagsHH) 8698232Snate@binkert.orgenv.Command('base/traceflags.cc', flags, traceFlagsCC) 8708232Snate@binkert.orgSource('base/traceflags.cc') 8718232Snate@binkert.org 8727673Snate@binkert.org# Embed python files. All .py files that have been indicated by a 8735517Snate@binkert.org# PySource() call in a SConscript need to be embedded into the M5 8745517Snate@binkert.org# library. To do that, we compile the file to byte code, marshal the 8757673Snate@binkert.org# byte code, compress it, and then generate a c++ file that 8765517Snate@binkert.org# inserts the result into an array. 87710455SCurtis.Dunham@arm.comdef embedPyFile(target, source, env): 8785517Snate@binkert.org def c_str(string): 8795517Snate@binkert.org if string is None: 8808232Snate@binkert.org return "0" 8818232Snate@binkert.org return '"%s"' % string 8825517Snate@binkert.org 8838232Snate@binkert.org '''Action function to compile a .py into a code object, marshal 8848232Snate@binkert.org it, compress it, and stick it into an asm file so the code appears 8855517Snate@binkert.org as just bytes with a label in the data section''' 8868232Snate@binkert.org 8878232Snate@binkert.org src = file(str(source[0]), 'r').read() 8888232Snate@binkert.org 8895517Snate@binkert.org pysource = PySource.tnodes[source[0]] 8908232Snate@binkert.org compiled = compile(src, pysource.abspath, 'exec') 8918232Snate@binkert.org marshalled = marshal.dumps(compiled) 8928232Snate@binkert.org compressed = zlib.compress(marshalled) 8938232Snate@binkert.org data = compressed 8948232Snate@binkert.org sym = pysource.symname 8958232Snate@binkert.org 8965517Snate@binkert.org code = code_formatter() 8978232Snate@binkert.org code('''\ 8988232Snate@binkert.org#include "sim/init.hh" 8995517Snate@binkert.org 9008232Snate@binkert.orgnamespace { 9017673Snate@binkert.org 9025517Snate@binkert.orgconst char data_${sym}[] = { 9037673Snate@binkert.org''') 9045517Snate@binkert.org code.indent() 9058232Snate@binkert.org step = 16 9068232Snate@binkert.org for i in xrange(0, len(data), step): 9078232Snate@binkert.org x = array.array('B', data[i:i+step]) 9085192Ssaidi@eecs.umich.edu code(''.join('%d,' % d for d in x)) 90910454SCurtis.Dunham@arm.com code.dedent() 91010454SCurtis.Dunham@arm.com 9118232Snate@binkert.org code('''}; 91210455SCurtis.Dunham@arm.com 91310455SCurtis.Dunham@arm.comEmbeddedPython embedded_${sym}( 91410455SCurtis.Dunham@arm.com ${{c_str(pysource.arcname)}}, 91510455SCurtis.Dunham@arm.com ${{c_str(pysource.abspath)}}, 91610455SCurtis.Dunham@arm.com ${{c_str(pysource.modpath)}}, 91710455SCurtis.Dunham@arm.com data_${sym}, 9185192Ssaidi@eecs.umich.edu ${{len(data)}}, 91911077SCurtis.Dunham@arm.com ${{len(marshalled)}}); 92011077SCurtis.Dunham@arm.com 92111077SCurtis.Dunham@arm.com/* namespace */ } 92211077SCurtis.Dunham@arm.com''') 92311077SCurtis.Dunham@arm.com code.write(str(target[0])) 9247674Snate@binkert.org 9255522Snate@binkert.orgfor source in PySource.all: 9265522Snate@binkert.org env.Command(source.cpp, source.tnode, embedPyFile) 9277674Snate@binkert.org Source(source.cpp) 9287674Snate@binkert.org 9297674Snate@binkert.org######################################################################## 9307674Snate@binkert.org# 9317674Snate@binkert.org# Define binaries. Each different build type (debug, opt, etc.) gets 9327674Snate@binkert.org# a slightly different build environment. 9337674Snate@binkert.org# 9347674Snate@binkert.org 9355522Snate@binkert.org# List of constructed environments to pass back to SConstruct 9365522Snate@binkert.orgenvList = [] 9375522Snate@binkert.org 9385517Snate@binkert.orgdate_source = Source('base/date.cc', skip_lib=True) 9395522Snate@binkert.org 9405517Snate@binkert.org# Function to create a new build environment as clone of current 9416143Snate@binkert.org# environment 'env' with modified object suffix and optional stripped 9426727Ssteve.reinhardt@amd.com# binary. Additional keyword arguments are appended to corresponding 9435522Snate@binkert.org# build environment vars. 9445522Snate@binkert.orgdef makeEnv(label, objsfx, strip = False, **kwargs): 9455522Snate@binkert.org # SCons doesn't know to append a library suffix when there is a '.' in the 9467674Snate@binkert.org # name. Use '_' instead. 9475517Snate@binkert.org libname = 'm5_' + label 9487673Snate@binkert.org exename = 'm5.' + label 9497673Snate@binkert.org 9507674Snate@binkert.org new_env = env.Clone(OBJSUFFIX=objsfx, SHOBJSUFFIX=objsfx + 's') 9517673Snate@binkert.org new_env.Label = label 9527674Snate@binkert.org new_env.Append(**kwargs) 9537674Snate@binkert.org 9548946Sandreas.hansson@arm.com swig_env = new_env.Clone() 9557674Snate@binkert.org swig_env.Append(CCFLAGS='-Werror') 9567674Snate@binkert.org if env['GCC']: 9577674Snate@binkert.org swig_env.Append(CCFLAGS='-Wno-uninitialized') 9585522Snate@binkert.org swig_env.Append(CCFLAGS='-Wno-sign-compare') 9595522Snate@binkert.org swig_env.Append(CCFLAGS='-Wno-parentheses') 9607674Snate@binkert.org 9617674Snate@binkert.org werror_env = new_env.Clone() 9627674Snate@binkert.org werror_env.Append(CCFLAGS='-Werror') 9637674Snate@binkert.org 9647673Snate@binkert.org def make_obj(source, static, extra_deps = None): 9657674Snate@binkert.org '''This function adds the specified source to the correct 9667674Snate@binkert.org build environment, and returns the corresponding SCons Object 9677674Snate@binkert.org nodes''' 9687674Snate@binkert.org 9697674Snate@binkert.org if source.swig: 9707674Snate@binkert.org env = swig_env 9717674Snate@binkert.org elif source.Werror: 9727674Snate@binkert.org env = werror_env 9737811Ssteve.reinhardt@amd.com else: 9747674Snate@binkert.org env = new_env 9757673Snate@binkert.org 9765522Snate@binkert.org if static: 9776143Snate@binkert.org obj = env.StaticObject(source.tnode) 97810453SAndrew.Bardsley@arm.com else: 9797816Ssteve.reinhardt@amd.com obj = env.SharedObject(source.tnode) 98010454SCurtis.Dunham@arm.com 98110453SAndrew.Bardsley@arm.com if extra_deps: 9824382Sbinkertn@umich.edu env.Depends(obj, extra_deps) 9834382Sbinkertn@umich.edu 9844382Sbinkertn@umich.edu return obj 9854382Sbinkertn@umich.edu 9864382Sbinkertn@umich.edu static_objs = [ make_obj(s, True) for s in Source.get(skip_lib=False)] 9874382Sbinkertn@umich.edu shared_objs = [ make_obj(s, False) for s in Source.get(skip_lib=False)] 9884382Sbinkertn@umich.edu 9894382Sbinkertn@umich.edu static_date = make_obj(date_source, static=True, extra_deps=static_objs) 99010196SCurtis.Dunham@arm.com static_objs.append(static_date) 9914382Sbinkertn@umich.edu 99210196SCurtis.Dunham@arm.com shared_date = make_obj(date_source, static=False, extra_deps=shared_objs) 99310196SCurtis.Dunham@arm.com shared_objs.append(shared_date) 99410196SCurtis.Dunham@arm.com 99510196SCurtis.Dunham@arm.com # First make a library of everything but main() so other programs can 99610196SCurtis.Dunham@arm.com # link against m5. 99710196SCurtis.Dunham@arm.com static_lib = new_env.StaticLibrary(libname, static_objs) 99810196SCurtis.Dunham@arm.com shared_lib = new_env.SharedLibrary(libname, shared_objs) 999955SN/A 10002655Sstever@eecs.umich.edu for target, sources in unit_tests: 10012655Sstever@eecs.umich.edu objs = [ make_obj(s, static=True) for s in sources ] 10022655Sstever@eecs.umich.edu new_env.Program("unittest/%s.%s" % (target, label), objs + static_objs) 10032655Sstever@eecs.umich.edu 100410196SCurtis.Dunham@arm.com # Now link a stub with main() and the static library. 10055601Snate@binkert.org bin_objs = [make_obj(s, True) for s in Source.get(bin_only=True) ] 10065601Snate@binkert.org progname = exename 100710196SCurtis.Dunham@arm.com if strip: 100810196SCurtis.Dunham@arm.com progname += '.unstripped' 100910196SCurtis.Dunham@arm.com 10105522Snate@binkert.org targets = new_env.Program(progname, bin_objs + static_objs) 10115863Snate@binkert.org 10125601Snate@binkert.org if strip: 10135601Snate@binkert.org if sys.platform == 'sunos5': 10145601Snate@binkert.org cmd = 'cp $SOURCE $TARGET; strip $TARGET' 10155863Snate@binkert.org else: 10169556Sandreas.hansson@arm.com cmd = 'strip $SOURCE -o $TARGET' 10179556Sandreas.hansson@arm.com targets = new_env.Command(exename, progname, cmd) 10189556Sandreas.hansson@arm.com 10199556Sandreas.hansson@arm.com new_env.M5Binary = targets[0] 10209556Sandreas.hansson@arm.com envList.append(new_env) 10219556Sandreas.hansson@arm.com 10229556Sandreas.hansson@arm.com# Debug binary 102310878Sandreas.hansson@arm.comccflags = {} 102410878Sandreas.hansson@arm.comif env['GCC']: 10259556Sandreas.hansson@arm.com if sys.platform == 'sunos5': 10265559Snate@binkert.org ccflags['debug'] = '-gstabs+' 10279556Sandreas.hansson@arm.com else: 10289618Ssteve.reinhardt@amd.com ccflags['debug'] = '-ggdb3' 10299618Ssteve.reinhardt@amd.com ccflags['opt'] = '-g -O3' 10309618Ssteve.reinhardt@amd.com ccflags['fast'] = '-O3' 103110238Sandreas.hansson@arm.com ccflags['prof'] = '-O3 -g -pg' 103210878Sandreas.hansson@arm.comelif env['SUNCC']: 103310878Sandreas.hansson@arm.com ccflags['debug'] = '-g0' 103410457Sandreas.hansson@arm.com ccflags['opt'] = '-g -O' 103510457Sandreas.hansson@arm.com ccflags['fast'] = '-fast' 103610457Sandreas.hansson@arm.com ccflags['prof'] = '-fast -g -pg' 103710457Sandreas.hansson@arm.comelif env['ICC']: 103810457Sandreas.hansson@arm.com ccflags['debug'] = '-g -O0' 103910457Sandreas.hansson@arm.com ccflags['opt'] = '-g -O' 104010457Sandreas.hansson@arm.com ccflags['fast'] = '-fast' 104110457Sandreas.hansson@arm.com ccflags['prof'] = '-fast -g -pg' 104210457Sandreas.hansson@arm.comelse: 10438737Skoansin.tan@gmail.com print 'Unknown compiler, please fix compiler options' 104410278SAndreas.Sandberg@ARM.com Exit(1) 104510278SAndreas.Sandberg@ARM.com 104610278SAndreas.Sandberg@ARM.commakeEnv('debug', '.do', 104710278SAndreas.Sandberg@ARM.com CCFLAGS = Split(ccflags['debug']), 104810278SAndreas.Sandberg@ARM.com CPPDEFINES = ['DEBUG', 'TRACING_ON=1']) 104910278SAndreas.Sandberg@ARM.com 105010278SAndreas.Sandberg@ARM.com# Optimized binary 105110278SAndreas.Sandberg@ARM.commakeEnv('opt', '.o', 105210457Sandreas.hansson@arm.com CCFLAGS = Split(ccflags['opt']), 105310457Sandreas.hansson@arm.com CPPDEFINES = ['TRACING_ON=1']) 105410457Sandreas.hansson@arm.com 105510457Sandreas.hansson@arm.com# "Fast" binary 105610457Sandreas.hansson@arm.commakeEnv('fast', '.fo', strip = True, 105710457Sandreas.hansson@arm.com CCFLAGS = Split(ccflags['fast']), 10588945Ssteve.reinhardt@amd.com CPPDEFINES = ['NDEBUG', 'TRACING_ON=0']) 105910686SAndreas.Sandberg@ARM.com 106010686SAndreas.Sandberg@ARM.com# Profiled binary 106110686SAndreas.Sandberg@ARM.commakeEnv('prof', '.po', 106210686SAndreas.Sandberg@ARM.com CCFLAGS = Split(ccflags['prof']), 106310686SAndreas.Sandberg@ARM.com CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'], 106410686SAndreas.Sandberg@ARM.com LINKFLAGS = '-pg') 10658945Ssteve.reinhardt@amd.com 10666143Snate@binkert.orgReturn('envList') 10676143Snate@binkert.org