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