SConscript revision 12016
1955SN/A# -*- mode:python -*- 2955SN/A 31762SN/A# Copyright (c) 2006 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: Steve Reinhardt 30955SN/A 315522Snate@binkert.orgimport sys 326143Snate@binkert.orgimport os 3312371Sgabeblack@google.comimport re 344762Snate@binkert.org 355522Snate@binkert.orgImport('*') 36955SN/A 375522Snate@binkert.org################################################################# 3811974Sgabeblack@google.com# 39955SN/A# ISA "switch header" generation. 405522Snate@binkert.org# 414202Sbinkertn@umich.edu# Auto-generate arch headers that include the right ISA-specific 425742Snate@binkert.org# header based on the setting of THE_ISA preprocessor variable. 43955SN/A# 444381Sbinkertn@umich.edu################################################################# 454381Sbinkertn@umich.edu 4612246Sgabeblack@google.comenv.SwitchingHeaders( 4712246Sgabeblack@google.com Split(''' 488334Snate@binkert.org decoder.hh 49955SN/A interrupts.hh 50955SN/A isa.hh 514202Sbinkertn@umich.edu isa_traits.hh 52955SN/A kernel_stats.hh 534382Sbinkertn@umich.edu locked_mem.hh 544382Sbinkertn@umich.edu microcode_rom.hh 554382Sbinkertn@umich.edu mmapped_ipr.hh 566654Snate@binkert.org mt.hh 575517Snate@binkert.org process.hh 588614Sgblack@eecs.umich.edu pseudo_inst.hh 597674Snate@binkert.org registers.hh 606143Snate@binkert.org remote_gdb.hh 616143Snate@binkert.org stacktrace.hh 626143Snate@binkert.org tlb.hh 6312302Sgabeblack@google.com types.hh 6412302Sgabeblack@google.com utility.hh 6512302Sgabeblack@google.com vtophys.hh 6612371Sgabeblack@google.com '''), 6712371Sgabeblack@google.com env.subst('${TARGET_ISA}')) 6812371Sgabeblack@google.com 6912371Sgabeblack@google.comif env['BUILD_GPU']: 7012371Sgabeblack@google.com env.SwitchingHeaders( 7112371Sgabeblack@google.com Split(''' 7212371Sgabeblack@google.com gpu_decoder.hh 7312371Sgabeblack@google.com gpu_isa.hh 7412371Sgabeblack@google.com gpu_types.hh 7512371Sgabeblack@google.com '''), 7612371Sgabeblack@google.com env.subst('${TARGET_GPU_ISA}')) 7712371Sgabeblack@google.com 7812371Sgabeblack@google.com################################################################# 7912371Sgabeblack@google.com# 8012371Sgabeblack@google.com# Include architecture-specific files. 8112371Sgabeblack@google.com# 8212371Sgabeblack@google.com################################################################# 8312371Sgabeblack@google.com 8412371Sgabeblack@google.com# 8512371Sgabeblack@google.com# Build a SCons scanner for ISA files 8612371Sgabeblack@google.com# 8712371Sgabeblack@google.comimport SCons.Scanner 8812371Sgabeblack@google.com 8912371Sgabeblack@google.comisa_scanner = SCons.Scanner.Classic("ISAScan", 9012371Sgabeblack@google.com [".isa", ".ISA"], 9112371Sgabeblack@google.com "SRCDIR", 9212371Sgabeblack@google.com r'^\s*##include\s+"([\w/.-]*)"') 9312371Sgabeblack@google.com 9412371Sgabeblack@google.comenv.Append(SCANNERS = isa_scanner) 9512371Sgabeblack@google.com 9612371Sgabeblack@google.com# 9712371Sgabeblack@google.com# Now create a Builder object that uses isa_parser.py to generate C++ 9812371Sgabeblack@google.com# output from the ISA description (*.isa) files. 9912371Sgabeblack@google.com# 10012371Sgabeblack@google.com 10112371Sgabeblack@google.comisa_parser = File('isa_parser.py') 10212371Sgabeblack@google.com 10312371Sgabeblack@google.com# The emitter patches up the sources & targets to include the 10412371Sgabeblack@google.com# autogenerated files as targets and isa parser itself as a source. 10512371Sgabeblack@google.comdef isa_desc_emitter(target, source, env): 10612371Sgabeblack@google.com # List the isa parser as a source. 10712371Sgabeblack@google.com source += [ 10812371Sgabeblack@google.com isa_parser, 10912371Sgabeblack@google.com Value("ExecContext"), 11012371Sgabeblack@google.com ] 11112371Sgabeblack@google.com 11212371Sgabeblack@google.com # Specify different targets depending on if we're running the ISA 11312302Sgabeblack@google.com # parser for its dependency information, or for the generated files. 11412371Sgabeblack@google.com # (As an optimization, the ISA parser detects the useless second run 11512302Sgabeblack@google.com # and skips doing any work, if the first run was performed, since it 11612371Sgabeblack@google.com # always generates all its files). The way we track this in SCons is the 11712302Sgabeblack@google.com # <arch>_isa_outputs value in the environment (env). If it's unset, we 11812302Sgabeblack@google.com # don't know what the dependencies are so we ask for generated/inc.d to 11912371Sgabeblack@google.com # be generated so they can be acquired. If we know what they are, then 12012371Sgabeblack@google.com # it's because we've already processed inc.d and then claim that our 12112371Sgabeblack@google.com # outputs (targets) will be thus. 12212371Sgabeblack@google.com isa = env['TARGET_ISA'] 12312302Sgabeblack@google.com key = '%s_isa_outputs' % isa 12412371Sgabeblack@google.com if key in env: 12512371Sgabeblack@google.com targets = [ os.path.join('generated', f) for f in env[key] ] 12612371Sgabeblack@google.com else: 12712371Sgabeblack@google.com targets = [ os.path.join('generated','inc.d') ] 12811983Sgabeblack@google.com 1296143Snate@binkert.org def prefix(s): 1308233Snate@binkert.org return os.path.join(target[0].dir.up().abspath, s) 13112302Sgabeblack@google.com 1326143Snate@binkert.org return [ prefix(t) for t in targets ], source 1336143Snate@binkert.org 13412302Sgabeblack@google.comARCH_DIR = Dir('.') 1354762Snate@binkert.org 1366143Snate@binkert.org# import ply here because SCons screws with sys.path when performing actions. 1378233Snate@binkert.orgimport ply 1388233Snate@binkert.org 13912302Sgabeblack@google.comdef isa_desc_action_func(target, source, env): 14012302Sgabeblack@google.com # Add the current directory to the system path so we can import files 1416143Snate@binkert.org sys.path[0:0] = [ ARCH_DIR.srcnode().abspath ] 14212362Sgabeblack@google.com import isa_parser 14312362Sgabeblack@google.com 14412362Sgabeblack@google.com # Skip over the ISA description itself and the parser to the CPU models. 14512362Sgabeblack@google.com models = [ s.get_contents() for s in source[2:] ] 14612302Sgabeblack@google.com parser = isa_parser.ISAParser(target[0].dir.abspath) 14712302Sgabeblack@google.com parser.parse_isa_desc(source[0].abspath) 14812302Sgabeblack@google.comisa_desc_action = MakeAction(isa_desc_action_func, Transform("ISA DESC", 1)) 14912302Sgabeblack@google.com 15012302Sgabeblack@google.com# Also include the CheckerCPU as one of the models if it is being 15112363Sgabeblack@google.com# enabled via command line. 15212363Sgabeblack@google.comisa_desc_builder = Builder(action=isa_desc_action, emitter=isa_desc_emitter) 15312363Sgabeblack@google.com 15412363Sgabeblack@google.comenv.Append(BUILDERS = { 'ISADesc' : isa_desc_builder }) 15512302Sgabeblack@google.com 15612363Sgabeblack@google.com# The ISA is generated twice: the first time to find out what it generates, 15712363Sgabeblack@google.com# and the second time to make scons happy by telling the ISADesc builder 15812363Sgabeblack@google.com# what it will make before it builds it. 15912363Sgabeblack@google.comdef scan_isa_deps(target, source, env): 16012363Sgabeblack@google.com # Process dependency file generated by the ISA parser -- 1618233Snate@binkert.org # add the listed files to the dependency tree of the build. 1626143Snate@binkert.org source = source[0] 1636143Snate@binkert.org archbase = source.dir.up().path 1646143Snate@binkert.org 1656143Snate@binkert.org try: 1666143Snate@binkert.org depfile = open(source.abspath, 'r') 1676143Snate@binkert.org except: 1686143Snate@binkert.org print "scan_isa_deps: Can't open ISA deps file '%s' in %s" % \ 1696143Snate@binkert.org (source.path,os.getcwd()) 1706143Snate@binkert.org raise 1717065Snate@binkert.org 1726143Snate@binkert.org # Scan through the lines 17312362Sgabeblack@google.com targets = {} 17412362Sgabeblack@google.com for line in depfile: 17512362Sgabeblack@google.com # Read the dependency line with the format 17612362Sgabeblack@google.com # <target file>: [ <dependent file>* ] 17712362Sgabeblack@google.com m = re.match(r'^\s*([^:]+\.([^\.:]+))\s*:\s*(.*)', line) 17812362Sgabeblack@google.com assert(m) 17912362Sgabeblack@google.com targ, extn = m.group(1,2) 18012362Sgabeblack@google.com deps = m.group(3).split() 18112362Sgabeblack@google.com 18212362Sgabeblack@google.com files = [ targ ] + deps 18312362Sgabeblack@google.com for f in files: 18412362Sgabeblack@google.com targets[f] = True 1858233Snate@binkert.org # Eliminate unnecessary re-generation if we already generated it 1868233Snate@binkert.org env.Precious(os.path.join(archbase, 'generated', f)) 1878233Snate@binkert.org 1888233Snate@binkert.org files = [ os.path.join(archbase, 'generated', f) for f in files ] 1898233Snate@binkert.org 1908233Snate@binkert.org if extn == 'cc': 1918233Snate@binkert.org Source(os.path.join(archbase,'generated', targ)) 1928233Snate@binkert.org depfile.close() 1938233Snate@binkert.org env[env['TARGET_ISA'] + '_isa_outputs'] = targets.keys() 1948233Snate@binkert.org 1958233Snate@binkert.org isa = env.ISADesc(os.path.join(archbase,'isa','main.isa')) 1968233Snate@binkert.org for t in targets: 1978233Snate@binkert.org env.Depends('#all-isas', isa) 1988233Snate@binkert.org 1998233Snate@binkert.orgenv.Append(BUILDERS = {'ScanISA' : 2008233Snate@binkert.org Builder(action=MakeAction(scan_isa_deps, 2018233Snate@binkert.org Transform("NEW DEPS", 1)))}) 2028233Snate@binkert.org 2038233Snate@binkert.orgDebugFlag('IntRegs') 2048233Snate@binkert.orgDebugFlag('FloatRegs') 2058233Snate@binkert.orgDebugFlag('CCRegs') 2066143Snate@binkert.orgDebugFlag('MiscRegs') 2076143Snate@binkert.orgCompoundFlag('Registers', [ 'IntRegs', 'FloatRegs', 'CCRegs', 'MiscRegs' ]) 2086143Snate@binkert.org