SConscript revision 10196
1955SN/A# -*- mode:python -*- 2955SN/A 312230Sgiacomo.travaglini@arm.com# Copyright (c) 2006 The Regents of The University of Michigan 49812Sandreas.hansson@arm.com# All rights reserved. 59812Sandreas.hansson@arm.com# 69812Sandreas.hansson@arm.com# Redistribution and use in source and binary forms, with or without 79812Sandreas.hansson@arm.com# modification, are permitted provided that the following conditions are 89812Sandreas.hansson@arm.com# met: redistributions of source code must retain the above copyright 99812Sandreas.hansson@arm.com# notice, this list of conditions and the following disclaimer; 109812Sandreas.hansson@arm.com# redistributions in binary form must reproduce the above copyright 119812Sandreas.hansson@arm.com# notice, this list of conditions and the following disclaimer in the 129812Sandreas.hansson@arm.com# documentation and/or other materials provided with the distribution; 139812Sandreas.hansson@arm.com# neither the name of the copyright holders nor the names of its 149812Sandreas.hansson@arm.com# contributors may be used to endorse or promote products derived from 157816Ssteve.reinhardt@amd.com# this software without specific prior written permission. 165871Snate@binkert.org# 171762SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26955SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27955SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28955SN/A# 29955SN/A# Authors: Steve Reinhardt 30955SN/A 31955SN/Aimport sys 32955SN/Aimport os 33955SN/Aimport re 34955SN/A 35955SN/AImport('*') 36955SN/A 37955SN/A################################################################# 38955SN/A# 39955SN/A# ISA "switch header" generation. 40955SN/A# 41955SN/A# Auto-generate arch headers that include the right ISA-specific 422665Ssaidi@eecs.umich.edu# header based on the setting of THE_ISA preprocessor variable. 432665Ssaidi@eecs.umich.edu# 445863Snate@binkert.org################################################################# 45955SN/A 46955SN/A# List of headers to generate 47955SN/Aisa_switch_hdrs = Split(''' 48955SN/A decoder.hh 49955SN/A interrupts.hh 508878Ssteve.reinhardt@amd.com isa.hh 512632Sstever@eecs.umich.edu isa_traits.hh 528878Ssteve.reinhardt@amd.com kernel_stats.hh 532632Sstever@eecs.umich.edu locked_mem.hh 54955SN/A microcode_rom.hh 558878Ssteve.reinhardt@amd.com mmapped_ipr.hh 562632Sstever@eecs.umich.edu mt.hh 572761Sstever@eecs.umich.edu process.hh 582632Sstever@eecs.umich.edu registers.hh 592632Sstever@eecs.umich.edu remote_gdb.hh 602632Sstever@eecs.umich.edu stacktrace.hh 612761Sstever@eecs.umich.edu tlb.hh 622761Sstever@eecs.umich.edu types.hh 632761Sstever@eecs.umich.edu utility.hh 648878Ssteve.reinhardt@amd.com vtophys.hh 658878Ssteve.reinhardt@amd.com ''') 662761Sstever@eecs.umich.edu 672761Sstever@eecs.umich.edu# Set up this directory to support switching headers 682761Sstever@eecs.umich.edumake_switching_dir('arch', isa_switch_hdrs, env) 692761Sstever@eecs.umich.edu 702761Sstever@eecs.umich.edu################################################################# 718878Ssteve.reinhardt@amd.com# 728878Ssteve.reinhardt@amd.com# Include architecture-specific files. 732632Sstever@eecs.umich.edu# 742632Sstever@eecs.umich.edu################################################################# 758878Ssteve.reinhardt@amd.com 768878Ssteve.reinhardt@amd.com# 772632Sstever@eecs.umich.edu# Build a SCons scanner for ISA files 78955SN/A# 79955SN/Aimport SCons.Scanner 80955SN/A 816654Snate@binkert.orgisa_scanner = SCons.Scanner.Classic("ISAScan", 8210196SCurtis.Dunham@arm.com [".isa", ".ISA"], 83955SN/A "SRCDIR", 845396Ssaidi@eecs.umich.edu r'^\s*##include\s+"([\w/.-]*)"') 8511401Sandreas.sandberg@arm.com 865863Snate@binkert.orgenv.Append(SCANNERS = isa_scanner) 875863Snate@binkert.org 884202Sbinkertn@umich.edu# 895863Snate@binkert.org# Now create a Builder object that uses isa_parser.py to generate C++ 905863Snate@binkert.org# output from the ISA description (*.isa) files. 915863Snate@binkert.org# 925863Snate@binkert.org 93955SN/Aisa_parser = File('isa_parser.py') 946654Snate@binkert.org 955273Sstever@gmail.com# The emitter patches up the sources & targets to include the 965871Snate@binkert.org# autogenerated files as targets and isa parser itself as a source. 975273Sstever@gmail.comdef isa_desc_emitter(target, source, env): 986654Snate@binkert.org cpu_models = list(env['CPU_MODELS']) 995396Ssaidi@eecs.umich.edu cpu_models.append('CheckerCPU') 1008120Sgblack@eecs.umich.edu 1018120Sgblack@eecs.umich.edu # List the isa parser as a source. 1028120Sgblack@eecs.umich.edu source += [ isa_parser ] 1038120Sgblack@eecs.umich.edu # Add in the CPU models. 1048120Sgblack@eecs.umich.edu source += [ Value(m) for m in cpu_models ] 1058120Sgblack@eecs.umich.edu 1068120Sgblack@eecs.umich.edu # Specify different targets depending on if we're running the ISA 1078120Sgblack@eecs.umich.edu # parser for its dependency information, or for the generated files. 1088879Ssteve.reinhardt@amd.com # (As an optimization, the ISA parser detects the useless second run 1098879Ssteve.reinhardt@amd.com # and skips doing any work, if the first run was performed, since it 1108879Ssteve.reinhardt@amd.com # always generates all its files). The way we track this in SCons is the 1118879Ssteve.reinhardt@amd.com # <arch>_isa_outputs value in the environment (env). If it's unset, we 1128879Ssteve.reinhardt@amd.com # don't know what the dependencies are so we ask for generated/inc.d to 1138879Ssteve.reinhardt@amd.com # be generated so they can be acquired. If we know what they are, then 1148879Ssteve.reinhardt@amd.com # it's because we've already processed inc.d and then claim that our 1158879Ssteve.reinhardt@amd.com # outputs (targets) will be thus. 1168879Ssteve.reinhardt@amd.com isa = env['TARGET_ISA'] 1178879Ssteve.reinhardt@amd.com key = '%s_isa_outputs' % isa 1188879Ssteve.reinhardt@amd.com if key in env: 1198879Ssteve.reinhardt@amd.com targets = [ os.path.join('generated', f) for f in env[key] ] 1208879Ssteve.reinhardt@amd.com else: 1218120Sgblack@eecs.umich.edu targets = [ os.path.join('generated','inc.d') ] 1228120Sgblack@eecs.umich.edu 1238120Sgblack@eecs.umich.edu def prefix(s): 1248120Sgblack@eecs.umich.edu return os.path.join(target[0].dir.up().abspath, s) 1258120Sgblack@eecs.umich.edu 1268120Sgblack@eecs.umich.edu return [ prefix(t) for t in targets ], source 1278120Sgblack@eecs.umich.edu 1288120Sgblack@eecs.umich.eduARCH_DIR = Dir('.') 1298120Sgblack@eecs.umich.edu 1308120Sgblack@eecs.umich.edu# import ply here because SCons screws with sys.path when performing actions. 1318120Sgblack@eecs.umich.eduimport ply 1328120Sgblack@eecs.umich.edu 1338120Sgblack@eecs.umich.edudef isa_desc_action_func(target, source, env): 1348120Sgblack@eecs.umich.edu # Add the current directory to the system path so we can import files 1358879Ssteve.reinhardt@amd.com sys.path[0:0] = [ ARCH_DIR.srcnode().abspath ] 1368879Ssteve.reinhardt@amd.com import isa_parser 1378879Ssteve.reinhardt@amd.com 1388879Ssteve.reinhardt@amd.com # Skip over the ISA description itself and the parser to the CPU models. 13910458Sandreas.hansson@arm.com models = [ s.get_contents() for s in source[2:] ] 14010458Sandreas.hansson@arm.com cpu_models = [CpuModel.dict[cpu] for cpu in models] 14110458Sandreas.hansson@arm.com parser = isa_parser.ISAParser(target[0].dir.abspath, cpu_models) 1428879Ssteve.reinhardt@amd.com parser.parse_isa_desc(source[0].abspath) 1438879Ssteve.reinhardt@amd.comisa_desc_action = MakeAction(isa_desc_action_func, Transform("ISA DESC", 1)) 1448879Ssteve.reinhardt@amd.com 1458879Ssteve.reinhardt@amd.com# Also include the CheckerCPU as one of the models if it is being 1469227Sandreas.hansson@arm.com# enabled via command line. 1479227Sandreas.hansson@arm.comisa_desc_builder = Builder(action=isa_desc_action, emitter=isa_desc_emitter) 14812063Sgabeblack@google.com 14912063Sgabeblack@google.comenv.Append(BUILDERS = { 'ISADesc' : isa_desc_builder }) 15012063Sgabeblack@google.com 1518879Ssteve.reinhardt@amd.com# The ISA is generated twice: the first time to find out what it generates, 1528879Ssteve.reinhardt@amd.com# and the second time to make scons happy by telling the ISADesc builder 1538879Ssteve.reinhardt@amd.com# what it will make before it builds it. 1548879Ssteve.reinhardt@amd.comdef scan_isa_deps(target, source, env): 15510453SAndrew.Bardsley@arm.com # Process dependency file generated by the ISA parser -- 15610453SAndrew.Bardsley@arm.com # add the listed files to the dependency tree of the build. 15710453SAndrew.Bardsley@arm.com source = source[0] 15810456SCurtis.Dunham@arm.com archbase = source.dir.up().path 15910456SCurtis.Dunham@arm.com 16010456SCurtis.Dunham@arm.com try: 16110457Sandreas.hansson@arm.com depfile = open(source.abspath, 'r') 16210457Sandreas.hansson@arm.com except: 16311342Sandreas.hansson@arm.com print "scan_isa_deps: Can't open ISA deps file '%s' in %s" % \ 16411342Sandreas.hansson@arm.com (source.path,os.getcwd()) 1658120Sgblack@eecs.umich.edu raise 16612063Sgabeblack@google.com 16712063Sgabeblack@google.com # Scan through the lines 16812063Sgabeblack@google.com targets = {} 16912063Sgabeblack@google.com for line in depfile: 1705871Snate@binkert.org # Read the dependency line with the format 1715871Snate@binkert.org # <target file>: [ <dependent file>* ] 1726121Snate@binkert.org m = re.match(r'^\s*([^:]+\.([^\.:]+))\s*:\s*(.*)', line) 1735871Snate@binkert.org assert(m) 1745871Snate@binkert.org targ, extn = m.group(1,2) 1759926Sstan.czerniawski@arm.com deps = m.group(3).split() 17612243Sgabeblack@google.com 1771533SN/A files = [ targ ] + deps 17812246Sgabeblack@google.com for f in files: 17912246Sgabeblack@google.com targets[f] = True 18012246Sgabeblack@google.com # Eliminate unnecessary re-generation if we already generated it 18112246Sgabeblack@google.com env.Precious(os.path.join(archbase, 'generated', f)) 1829239Sandreas.hansson@arm.com 1839239Sandreas.hansson@arm.com files = [ os.path.join(archbase, 'generated', f) for f in files ] 1849239Sandreas.hansson@arm.com 1859239Sandreas.hansson@arm.com if extn == 'cc': 1869239Sandreas.hansson@arm.com Source(os.path.join(archbase,'generated', targ)) 1879239Sandreas.hansson@arm.com depfile.close() 1889239Sandreas.hansson@arm.com env[env['TARGET_ISA'] + '_isa_outputs'] = targets.keys() 189955SN/A 190955SN/A isa = env.ISADesc(os.path.join(archbase,'isa','main.isa')) 1912632Sstever@eecs.umich.edu for t in targets: 1922632Sstever@eecs.umich.edu env.Depends('#all-isas', isa) 193955SN/A 194955SN/Aenv.Append(BUILDERS = {'ScanISA' : 195955SN/A Builder(action=MakeAction(scan_isa_deps, 196955SN/A Transform("NEW DEPS", 1)))}) 1978878Ssteve.reinhardt@amd.com 198955SN/ADebugFlag('IntRegs') 1992632Sstever@eecs.umich.eduDebugFlag('FloatRegs') 2002632Sstever@eecs.umich.eduDebugFlag('CCRegs') 2012632Sstever@eecs.umich.eduDebugFlag('MiscRegs') 2022632Sstever@eecs.umich.eduCompoundFlag('Registers', [ 'IntRegs', 'FloatRegs', 'CCRegs', 'MiscRegs' ]) 2032632Sstever@eecs.umich.edu