SConscript revision 10934:5af8f40d8f2c
14348Sgblack@eecs.umich.edu# -*- mode:python -*- 24348Sgblack@eecs.umich.edu 34348Sgblack@eecs.umich.edu# Copyright (c) 2006 The Regents of The University of Michigan 44348Sgblack@eecs.umich.edu# All rights reserved. 54348Sgblack@eecs.umich.edu# 64348Sgblack@eecs.umich.edu# Redistribution and use in source and binary forms, with or without 74348Sgblack@eecs.umich.edu# modification, are permitted provided that the following conditions are 84348Sgblack@eecs.umich.edu# met: redistributions of source code must retain the above copyright 94348Sgblack@eecs.umich.edu# notice, this list of conditions and the following disclaimer; 104348Sgblack@eecs.umich.edu# redistributions in binary form must reproduce the above copyright 114348Sgblack@eecs.umich.edu# notice, this list of conditions and the following disclaimer in the 124348Sgblack@eecs.umich.edu# documentation and/or other materials provided with the distribution; 134348Sgblack@eecs.umich.edu# neither the name of the copyright holders nor the names of its 144348Sgblack@eecs.umich.edu# contributors may be used to endorse or promote products derived from 154348Sgblack@eecs.umich.edu# this software without specific prior written permission. 164348Sgblack@eecs.umich.edu# 174348Sgblack@eecs.umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 184348Sgblack@eecs.umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 194348Sgblack@eecs.umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 204348Sgblack@eecs.umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 214348Sgblack@eecs.umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 224348Sgblack@eecs.umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 234348Sgblack@eecs.umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 244348Sgblack@eecs.umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 254348Sgblack@eecs.umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 264348Sgblack@eecs.umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 274348Sgblack@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 284348Sgblack@eecs.umich.edu# 294348Sgblack@eecs.umich.edu# Authors: Steve Reinhardt 304348Sgblack@eecs.umich.edu 314348Sgblack@eecs.umich.eduimport sys 324348Sgblack@eecs.umich.eduimport os 334348Sgblack@eecs.umich.eduimport re 344348Sgblack@eecs.umich.edu 354348Sgblack@eecs.umich.eduImport('*') 364348Sgblack@eecs.umich.edu 374348Sgblack@eecs.umich.edu################################################################# 384348Sgblack@eecs.umich.edu# 394348Sgblack@eecs.umich.edu# ISA "switch header" generation. 404348Sgblack@eecs.umich.edu# 414348Sgblack@eecs.umich.edu# Auto-generate arch headers that include the right ISA-specific 424348Sgblack@eecs.umich.edu# header based on the setting of THE_ISA preprocessor variable. 434348Sgblack@eecs.umich.edu# 444348Sgblack@eecs.umich.edu################################################################# 454348Sgblack@eecs.umich.edu 464348Sgblack@eecs.umich.edu# List of headers to generate 474348Sgblack@eecs.umich.eduisa_switch_hdrs = Split(''' 484348Sgblack@eecs.umich.edu decoder.hh 494348Sgblack@eecs.umich.edu interrupts.hh 504348Sgblack@eecs.umich.edu isa.hh 514348Sgblack@eecs.umich.edu isa_traits.hh 524348Sgblack@eecs.umich.edu kernel_stats.hh 534348Sgblack@eecs.umich.edu locked_mem.hh 544348Sgblack@eecs.umich.edu microcode_rom.hh 554348Sgblack@eecs.umich.edu mmapped_ipr.hh 564348Sgblack@eecs.umich.edu mt.hh 574348Sgblack@eecs.umich.edu process.hh 584348Sgblack@eecs.umich.edu pseudo_inst.hh 594348Sgblack@eecs.umich.edu registers.hh 604348Sgblack@eecs.umich.edu remote_gdb.hh 614348Sgblack@eecs.umich.edu stacktrace.hh 624348Sgblack@eecs.umich.edu tlb.hh 634348Sgblack@eecs.umich.edu types.hh 644348Sgblack@eecs.umich.edu utility.hh 654348Sgblack@eecs.umich.edu vtophys.hh 664348Sgblack@eecs.umich.edu ''') 674609Sgblack@eecs.umich.edu 684609Sgblack@eecs.umich.edu# Set up this directory to support switching headers 694609Sgblack@eecs.umich.edumake_switching_dir('arch', isa_switch_hdrs, env) 704542Sgblack@eecs.umich.edu 714542Sgblack@eecs.umich.edu################################################################# 724348Sgblack@eecs.umich.edu# 734609Sgblack@eecs.umich.edu# Include architecture-specific files. 744542Sgblack@eecs.umich.edu# 754542Sgblack@eecs.umich.edu################################################################# 764542Sgblack@eecs.umich.edu 774348Sgblack@eecs.umich.edu# 784609Sgblack@eecs.umich.edu# Build a SCons scanner for ISA files 794542Sgblack@eecs.umich.edu# 804542Sgblack@eecs.umich.eduimport SCons.Scanner 814542Sgblack@eecs.umich.edu 824542Sgblack@eecs.umich.eduisa_scanner = SCons.Scanner.Classic("ISAScan", 834542Sgblack@eecs.umich.edu [".isa", ".ISA"], 844348Sgblack@eecs.umich.edu "SRCDIR", 854348Sgblack@eecs.umich.edu r'^\s*##include\s+"([\w/.-]*)"') 864348Sgblack@eecs.umich.edu 874609Sgblack@eecs.umich.eduenv.Append(SCANNERS = isa_scanner) 884609Sgblack@eecs.umich.edu 895788Sgblack@eecs.umich.edu# 905788Sgblack@eecs.umich.edu# Now create a Builder object that uses isa_parser.py to generate C++ 915788Sgblack@eecs.umich.edu# output from the ISA description (*.isa) files. 925788Sgblack@eecs.umich.edu# 935788Sgblack@eecs.umich.edu 945788Sgblack@eecs.umich.eduisa_parser = File('isa_parser.py') 955788Sgblack@eecs.umich.edu 965788Sgblack@eecs.umich.edu# The emitter patches up the sources & targets to include the 975788Sgblack@eecs.umich.edu# autogenerated files as targets and isa parser itself as a source. 985788Sgblack@eecs.umich.edudef isa_desc_emitter(target, source, env): 995788Sgblack@eecs.umich.edu # List the isa parser as a source. 1004609Sgblack@eecs.umich.edu source += [ 1014609Sgblack@eecs.umich.edu isa_parser, 1024609Sgblack@eecs.umich.edu Value("ExecContext"), 1034609Sgblack@eecs.umich.edu ] 1044609Sgblack@eecs.umich.edu 1054609Sgblack@eecs.umich.edu # Specify different targets depending on if we're running the ISA 1064609Sgblack@eecs.umich.edu # parser for its dependency information, or for the generated files. 1074609Sgblack@eecs.umich.edu # (As an optimization, the ISA parser detects the useless second run 1084609Sgblack@eecs.umich.edu # and skips doing any work, if the first run was performed, since it 1094609Sgblack@eecs.umich.edu # always generates all its files). The way we track this in SCons is the 1104609Sgblack@eecs.umich.edu # <arch>_isa_outputs value in the environment (env). If it's unset, we 1114609Sgblack@eecs.umich.edu # don't know what the dependencies are so we ask for generated/inc.d to 1124609Sgblack@eecs.umich.edu # be generated so they can be acquired. If we know what they are, then 1134609Sgblack@eecs.umich.edu # it's because we've already processed inc.d and then claim that our 1144609Sgblack@eecs.umich.edu # outputs (targets) will be thus. 1154609Sgblack@eecs.umich.edu isa = env['TARGET_ISA'] 1164609Sgblack@eecs.umich.edu key = '%s_isa_outputs' % isa 1174348Sgblack@eecs.umich.edu if key in env: 1184601Sgblack@eecs.umich.edu targets = [ os.path.join('generated', f) for f in env[key] ] 1194348Sgblack@eecs.umich.edu else: 1204348Sgblack@eecs.umich.edu targets = [ os.path.join('generated','inc.d') ] 1214348Sgblack@eecs.umich.edu 1224348Sgblack@eecs.umich.edu def prefix(s): 1234348Sgblack@eecs.umich.edu return os.path.join(target[0].dir.up().abspath, s) 1244348Sgblack@eecs.umich.edu 1254348Sgblack@eecs.umich.edu return [ prefix(t) for t in targets ], source 1264746Sgblack@eecs.umich.edu 1274746Sgblack@eecs.umich.eduARCH_DIR = Dir('.') 1284348Sgblack@eecs.umich.edu 1294548Sgblack@eecs.umich.edu# import ply here because SCons screws with sys.path when performing actions. 1304548Sgblack@eecs.umich.eduimport ply 1314716Sgblack@eecs.umich.edu 1324548Sgblack@eecs.umich.edudef isa_desc_action_func(target, source, env): 1334348Sgblack@eecs.umich.edu # Add the current directory to the system path so we can import files 1344528Sgblack@eecs.umich.edu sys.path[0:0] = [ ARCH_DIR.srcnode().abspath ] 1354528Sgblack@eecs.umich.edu import isa_parser 1364568Sgblack@eecs.umich.edu 1374348Sgblack@eecs.umich.edu # Skip over the ISA description itself and the parser to the CPU models. 1384528Sgblack@eecs.umich.edu models = [ s.get_contents() for s in source[2:] ] 1394542Sgblack@eecs.umich.edu parser = isa_parser.ISAParser(target[0].dir.abspath) 1404601Sgblack@eecs.umich.edu parser.parse_isa_desc(source[0].abspath) 1414348Sgblack@eecs.umich.eduisa_desc_action = MakeAction(isa_desc_action_func, Transform("ISA DESC", 1)) 1426519Sgblack@eecs.umich.edu 1434746Sgblack@eecs.umich.edu# Also include the CheckerCPU as one of the models if it is being 1444746Sgblack@eecs.umich.edu# enabled via command line. 1454746Sgblack@eecs.umich.eduisa_desc_builder = Builder(action=isa_desc_action, emitter=isa_desc_emitter) 1464348Sgblack@eecs.umich.edu 1474348Sgblack@eecs.umich.eduenv.Append(BUILDERS = { 'ISADesc' : isa_desc_builder }) 1484528Sgblack@eecs.umich.edu 1494542Sgblack@eecs.umich.edu# The ISA is generated twice: the first time to find out what it generates, 1505788Sgblack@eecs.umich.edu# and the second time to make scons happy by telling the ISADesc builder 1514542Sgblack@eecs.umich.edu# what it will make before it builds it. 1525788Sgblack@eecs.umich.edudef scan_isa_deps(target, source, env): 1535788Sgblack@eecs.umich.edu # Process dependency file generated by the ISA parser -- 1545788Sgblack@eecs.umich.edu # add the listed files to the dependency tree of the build. 1555788Sgblack@eecs.umich.edu source = source[0] 1564575Sgblack@eecs.umich.edu archbase = source.dir.up().path 1574716Sgblack@eecs.umich.edu 1584716Sgblack@eecs.umich.edu try: 1595788Sgblack@eecs.umich.edu depfile = open(source.abspath, 'r') 1605788Sgblack@eecs.umich.edu except: 1614716Sgblack@eecs.umich.edu print "scan_isa_deps: Can't open ISA deps file '%s' in %s" % \ 1624716Sgblack@eecs.umich.edu (source.path,os.getcwd()) 1634601Sgblack@eecs.umich.edu raise 1644601Sgblack@eecs.umich.edu 1654601Sgblack@eecs.umich.edu # Scan through the lines 1664601Sgblack@eecs.umich.edu targets = {} 1674817Sgblack@eecs.umich.edu for line in depfile: 1684348Sgblack@eecs.umich.edu # Read the dependency line with the format 1694348Sgblack@eecs.umich.edu # <target file>: [ <dependent file>* ] 1705241Sgblack@eecs.umich.edu m = re.match(r'^\s*([^:]+\.([^\.:]+))\s*:\s*(.*)', line) 1715294Sgblack@eecs.umich.edu assert(m) 1725241Sgblack@eecs.umich.edu targ, extn = m.group(1,2) 1735788Sgblack@eecs.umich.edu deps = m.group(3).split() 1745788Sgblack@eecs.umich.edu 1755241Sgblack@eecs.umich.edu files = [ targ ] + deps 1765241Sgblack@eecs.umich.edu for f in files: 1775294Sgblack@eecs.umich.edu targets[f] = True 1785241Sgblack@eecs.umich.edu # Eliminate unnecessary re-generation if we already generated it 1795788Sgblack@eecs.umich.edu env.Precious(os.path.join(archbase, 'generated', f)) 1805788Sgblack@eecs.umich.edu 1815241Sgblack@eecs.umich.edu files = [ os.path.join(archbase, 'generated', f) for f in files ] 1825294Sgblack@eecs.umich.edu 1835294Sgblack@eecs.umich.edu if extn == 'cc': 1845294Sgblack@eecs.umich.edu Source(os.path.join(archbase,'generated', targ)) 1855788Sgblack@eecs.umich.edu depfile.close() 1865788Sgblack@eecs.umich.edu env[env['TARGET_ISA'] + '_isa_outputs'] = targets.keys() 1875294Sgblack@eecs.umich.edu 1885294Sgblack@eecs.umich.edu isa = env.ISADesc(os.path.join(archbase,'isa','main.isa')) 1894348Sgblack@eecs.umich.edu for t in targets: 1904548Sgblack@eecs.umich.edu env.Depends('#all-isas', isa) 1915788Sgblack@eecs.umich.edu 1925788Sgblack@eecs.umich.eduenv.Append(BUILDERS = {'ScanISA' : 1936518Sgblack@eecs.umich.edu Builder(action=MakeAction(scan_isa_deps, 1946518Sgblack@eecs.umich.edu Transform("NEW DEPS", 1)))}) 1956518Sgblack@eecs.umich.edu 1966518Sgblack@eecs.umich.eduDebugFlag('IntRegs') 1976518Sgblack@eecs.umich.eduDebugFlag('FloatRegs') 1986518Sgblack@eecs.umich.eduDebugFlag('CCRegs') 1994348Sgblack@eecs.umich.eduDebugFlag('VectorRegs') 2004348Sgblack@eecs.umich.eduDebugFlag('MiscRegs') 2014348Sgblack@eecs.umich.eduCompoundFlag('Registers', [ 'IntRegs', 'FloatRegs', 'CCRegs', 'VectorRegs', 2024528Sgblack@eecs.umich.edu 'MiscRegs' ]) 2034548Sgblack@eecs.umich.edu