SConscript revision 12016:893091853afd
16167SN/A# -*- mode:python -*- 26167SN/A 36167SN/A# Copyright (c) 2006 The Regents of The University of Michigan 410036SAli.Saidi@ARM.com# All rights reserved. 58835SAli.Saidi@ARM.com# 610036SAli.Saidi@ARM.com# Redistribution and use in source and binary forms, with or without 77892SN/A# modification, are permitted provided that the following conditions are 87892SN/A# met: redistributions of source code must retain the above copyright 97892SN/A# notice, this list of conditions and the following disclaimer; 106167SN/A# redistributions in binary form must reproduce the above copyright 116167SN/A# notice, this list of conditions and the following disclaimer in the 126167SN/A# documentation and/or other materials provided with the distribution; 1310526Snilay@cs.wisc.edu# neither the name of the copyright holders nor the names of its 148835SAli.Saidi@ARM.com# contributors may be used to endorse or promote products derived from 159864Snilay@cs.wisc.edu# this software without specific prior written permission. 169864Snilay@cs.wisc.edu# 1710036SAli.Saidi@ARM.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1811312Santhony.gutierrez@amd.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 198835SAli.Saidi@ARM.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 208835SAli.Saidi@ARM.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2110315Snilay@cs.wisc.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 228835SAli.Saidi@ARM.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2310063Snilay@cs.wisc.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 247077SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 259864Snilay@cs.wisc.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2610526Snilay@cs.wisc.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2710736Snilay@cs.wisc.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2811219Snilay@cs.wisc.edu# 298721SN/A# Authors: Steve Reinhardt 308835SAli.Saidi@ARM.com 318835SAli.Saidi@ARM.comimport sys 3211440SCurtis.Dunham@arm.comimport os 3311440SCurtis.Dunham@arm.comimport re 347935SN/A 357935SN/AImport('*') 367935SN/A 377935SN/A################################################################# 387935SN/A# 397935SN/A# ISA "switch header" generation. 407935SN/A# 418983Snate@binkert.org# Auto-generate arch headers that include the right ISA-specific 426167SN/A# header based on the setting of THE_ISA preprocessor variable. 439864Snilay@cs.wisc.edu# 449864Snilay@cs.wisc.edu################################################################# 459864Snilay@cs.wisc.edu 4610315Snilay@cs.wisc.eduenv.SwitchingHeaders( 4710036SAli.Saidi@ARM.com Split(''' 4810315Snilay@cs.wisc.edu decoder.hh 499864Snilay@cs.wisc.edu interrupts.hh 509864Snilay@cs.wisc.edu isa.hh 516167SN/A isa_traits.hh 526167SN/A kernel_stats.hh 539864Snilay@cs.wisc.edu locked_mem.hh 5410063Snilay@cs.wisc.edu microcode_rom.hh 556167SN/A mmapped_ipr.hh 569864Snilay@cs.wisc.edu mt.hh 576167SN/A process.hh 586167SN/A pseudo_inst.hh 598835SAli.Saidi@ARM.com registers.hh 606167SN/A remote_gdb.hh 616167SN/A stacktrace.hh 6210036SAli.Saidi@ARM.com tlb.hh 636167SN/A types.hh 646167SN/A utility.hh 658835SAli.Saidi@ARM.com vtophys.hh 669469Snilay@cs.wisc.edu '''), 676167SN/A env.subst('${TARGET_ISA}')) 686167SN/A 696167SN/Aif env['BUILD_GPU']: 706167SN/A env.SwitchingHeaders( 716167SN/A Split(''' 726167SN/A gpu_decoder.hh 738835SAli.Saidi@ARM.com gpu_isa.hh 746167SN/A gpu_types.hh 759864Snilay@cs.wisc.edu '''), 7610315Snilay@cs.wisc.edu env.subst('${TARGET_GPU_ISA}')) 779469Snilay@cs.wisc.edu 786167SN/A################################################################# 796167SN/A# 806167SN/A# Include architecture-specific files. 819469Snilay@cs.wisc.edu# 829469Snilay@cs.wisc.edu################################################################# 836167SN/A 849864Snilay@cs.wisc.edu# 859864Snilay@cs.wisc.edu# Build a SCons scanner for ISA files 869864Snilay@cs.wisc.edu# 879864Snilay@cs.wisc.eduimport SCons.Scanner 8810036SAli.Saidi@ARM.com 899864Snilay@cs.wisc.eduisa_scanner = SCons.Scanner.Classic("ISAScan", 909864Snilay@cs.wisc.edu [".isa", ".ISA"], 919864Snilay@cs.wisc.edu "SRCDIR", 929864Snilay@cs.wisc.edu r'^\s*##include\s+"([\w/.-]*)"') 9310315Snilay@cs.wisc.edu 9410036SAli.Saidi@ARM.comenv.Append(SCANNERS = isa_scanner) 9510315Snilay@cs.wisc.edu 969864Snilay@cs.wisc.edu# 979864Snilay@cs.wisc.edu# Now create a Builder object that uses isa_parser.py to generate C++ 986167SN/A# output from the ISA description (*.isa) files. 996167SN/A# 1008835SAli.Saidi@ARM.com 10110036SAli.Saidi@ARM.comisa_parser = File('isa_parser.py') 1026167SN/A 1038835SAli.Saidi@ARM.com# The emitter patches up the sources & targets to include the 1048835SAli.Saidi@ARM.com# autogenerated files as targets and isa parser itself as a source. 1058835SAli.Saidi@ARM.comdef isa_desc_emitter(target, source, env): 1068835SAli.Saidi@ARM.com # List the isa parser as a source. 1079864Snilay@cs.wisc.edu source += [ 10810036SAli.Saidi@ARM.com isa_parser, 1099864Snilay@cs.wisc.edu Value("ExecContext"), 1108835SAli.Saidi@ARM.com ] 1119469Snilay@cs.wisc.edu 1128835SAli.Saidi@ARM.com # Specify different targets depending on if we're running the ISA 1138835SAli.Saidi@ARM.com # parser for its dependency information, or for the generated files. 1148835SAli.Saidi@ARM.com # (As an optimization, the ISA parser detects the useless second run 1159864Snilay@cs.wisc.edu # and skips doing any work, if the first run was performed, since it 11610036SAli.Saidi@ARM.com # always generates all its files). The way we track this in SCons is the 1178835SAli.Saidi@ARM.com # <arch>_isa_outputs value in the environment (env). If it's unset, we 1188835SAli.Saidi@ARM.com # don't know what the dependencies are so we ask for generated/inc.d to 1199213Snilay@cs.wisc.edu # be generated so they can be acquired. If we know what they are, then 1208835SAli.Saidi@ARM.com # it's because we've already processed inc.d and then claim that our 1219469Snilay@cs.wisc.edu # outputs (targets) will be thus. 1229469Snilay@cs.wisc.edu isa = env['TARGET_ISA'] 1239469Snilay@cs.wisc.edu key = '%s_isa_outputs' % isa 1249469Snilay@cs.wisc.edu if key in env: 1259469Snilay@cs.wisc.edu targets = [ os.path.join('generated', f) for f in env[key] ] 1269469Snilay@cs.wisc.edu else: 12710036SAli.Saidi@ARM.com targets = [ os.path.join('generated','inc.d') ] 1286167SN/A 1296167SN/A def prefix(s): 1306167SN/A return os.path.join(target[0].dir.up().abspath, s) 1318835SAli.Saidi@ARM.com 13210036SAli.Saidi@ARM.com return [ prefix(t) for t in targets ], source 1336167SN/A 1348835SAli.Saidi@ARM.comARCH_DIR = Dir('.') 1358835SAli.Saidi@ARM.com 1368835SAli.Saidi@ARM.com# import ply here because SCons screws with sys.path when performing actions. 1378835SAli.Saidi@ARM.comimport ply 1389864Snilay@cs.wisc.edu 13910036SAli.Saidi@ARM.comdef isa_desc_action_func(target, source, env): 1409864Snilay@cs.wisc.edu # Add the current directory to the system path so we can import files 1418835SAli.Saidi@ARM.com sys.path[0:0] = [ ARCH_DIR.srcnode().abspath ] 1429469Snilay@cs.wisc.edu import isa_parser 1436167SN/A 1446167SN/A # Skip over the ISA description itself and the parser to the CPU models. 1456167SN/A models = [ s.get_contents() for s in source[2:] ] 14610036SAli.Saidi@ARM.com parser = isa_parser.ISAParser(target[0].dir.abspath) 1476167SN/A parser.parse_isa_desc(source[0].abspath) 1486167SN/Aisa_desc_action = MakeAction(isa_desc_action_func, Transform("ISA DESC", 1)) 1496167SN/A 1506167SN/A# Also include the CheckerCPU as one of the models if it is being 1516167SN/A# enabled via command line. 15210645Snilay@cs.wisc.eduisa_desc_builder = Builder(action=isa_desc_action, emitter=isa_desc_emitter) 1536167SN/A 1546167SN/Aenv.Append(BUILDERS = { 'ISADesc' : isa_desc_builder }) 1556167SN/A 1566167SN/A# The ISA is generated twice: the first time to find out what it generates, 15710036SAli.Saidi@ARM.com# and the second time to make scons happy by telling the ISADesc builder 15811268Satgutier@umich.edu# what it will make before it builds it. 1596167SN/Adef scan_isa_deps(target, source, env): 1606167SN/A # Process dependency file generated by the ISA parser -- 16110645Snilay@cs.wisc.edu # add the listed files to the dependency tree of the build. 1626167SN/A source = source[0] 1636167SN/A archbase = source.dir.up().path 1646167SN/A 1656167SN/A try: 1666167SN/A depfile = open(source.abspath, 'r') 1676167SN/A except: 1686167SN/A print "scan_isa_deps: Can't open ISA deps file '%s' in %s" % \ 16910451Snilay@cs.wisc.edu (source.path,os.getcwd()) 1706167SN/A raise 17110315Snilay@cs.wisc.edu 17210315Snilay@cs.wisc.edu # Scan through the lines 17310315Snilay@cs.wisc.edu targets = {} 17410315Snilay@cs.wisc.edu for line in depfile: 17510315Snilay@cs.wisc.edu # Read the dependency line with the format 17610315Snilay@cs.wisc.edu # <target file>: [ <dependent file>* ] 17710315Snilay@cs.wisc.edu m = re.match(r'^\s*([^:]+\.([^\.:]+))\s*:\s*(.*)', line) 17810315Snilay@cs.wisc.edu assert(m) 17910526Snilay@cs.wisc.edu targ, extn = m.group(1,2) 18010526Snilay@cs.wisc.edu deps = m.group(3).split() 18110526Snilay@cs.wisc.edu 18210526Snilay@cs.wisc.edu files = [ targ ] + deps 18310526Snilay@cs.wisc.edu for f in files: 18410526Snilay@cs.wisc.edu targets[f] = True 18510526Snilay@cs.wisc.edu # Eliminate unnecessary re-generation if we already generated it 18610526Snilay@cs.wisc.edu env.Precious(os.path.join(archbase, 'generated', f)) 18710526Snilay@cs.wisc.edu 18810526Snilay@cs.wisc.edu files = [ os.path.join(archbase, 'generated', f) for f in files ] 18910526Snilay@cs.wisc.edu 19010526Snilay@cs.wisc.edu if extn == 'cc': 19110526Snilay@cs.wisc.edu Source(os.path.join(archbase,'generated', targ)) 19210526Snilay@cs.wisc.edu depfile.close() 19310526Snilay@cs.wisc.edu env[env['TARGET_ISA'] + '_isa_outputs'] = targets.keys() 19410526Snilay@cs.wisc.edu 19510526Snilay@cs.wisc.edu isa = env.ISADesc(os.path.join(archbase,'isa','main.isa')) 19610526Snilay@cs.wisc.edu for t in targets: 19710526Snilay@cs.wisc.edu env.Depends('#all-isas', isa) 19810526Snilay@cs.wisc.edu 19910526Snilay@cs.wisc.eduenv.Append(BUILDERS = {'ScanISA' : 20010526Snilay@cs.wisc.edu Builder(action=MakeAction(scan_isa_deps, 20110526Snilay@cs.wisc.edu Transform("NEW DEPS", 1)))}) 20210526Snilay@cs.wisc.edu 20310526Snilay@cs.wisc.eduDebugFlag('IntRegs') 20410526Snilay@cs.wisc.eduDebugFlag('FloatRegs') 20510526Snilay@cs.wisc.eduDebugFlag('CCRegs') 20610736Snilay@cs.wisc.eduDebugFlag('MiscRegs') 20710526Snilay@cs.wisc.eduCompoundFlag('Registers', [ 'IntRegs', 'FloatRegs', 'CCRegs', 'MiscRegs' ]) 20810526Snilay@cs.wisc.edu