SConscript revision 10201
14484Sbinkertn@umich.edu# -*- mode:python -*- 24484Sbinkertn@umich.edu 34484Sbinkertn@umich.edu# Copyright (c) 2006 The Regents of The University of Michigan 44484Sbinkertn@umich.edu# All rights reserved. 54484Sbinkertn@umich.edu# 64484Sbinkertn@umich.edu# Redistribution and use in source and binary forms, with or without 74484Sbinkertn@umich.edu# modification, are permitted provided that the following conditions are 84484Sbinkertn@umich.edu# met: redistributions of source code must retain the above copyright 94484Sbinkertn@umich.edu# notice, this list of conditions and the following disclaimer; 104484Sbinkertn@umich.edu# redistributions in binary form must reproduce the above copyright 114484Sbinkertn@umich.edu# notice, this list of conditions and the following disclaimer in the 124484Sbinkertn@umich.edu# documentation and/or other materials provided with the distribution; 134484Sbinkertn@umich.edu# neither the name of the copyright holders nor the names of its 144484Sbinkertn@umich.edu# contributors may be used to endorse or promote products derived from 154484Sbinkertn@umich.edu# this software without specific prior written permission. 164484Sbinkertn@umich.edu# 174484Sbinkertn@umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 184484Sbinkertn@umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 194484Sbinkertn@umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 204484Sbinkertn@umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 214484Sbinkertn@umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 224484Sbinkertn@umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 234484Sbinkertn@umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 244484Sbinkertn@umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 254484Sbinkertn@umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 264484Sbinkertn@umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 274484Sbinkertn@umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 284484Sbinkertn@umich.edu# 294484Sbinkertn@umich.edu# Authors: Steve Reinhardt 304484Sbinkertn@umich.edu 314494Ssaidi@eecs.umich.eduimport sys 324484Sbinkertn@umich.eduimport os 336121Snate@binkert.orgimport re 344484Sbinkertn@umich.edu 354484Sbinkertn@umich.eduImport('*') 364484Sbinkertn@umich.edu 374484Sbinkertn@umich.edu################################################################# 384781Snate@binkert.org# 394484Sbinkertn@umich.edu# ISA "switch header" generation. 404484Sbinkertn@umich.edu# 414484Sbinkertn@umich.edu# Auto-generate arch headers that include the right ISA-specific 424484Sbinkertn@umich.edu# header based on the setting of THE_ISA preprocessor variable. 438349Sgblack@eecs.umich.edu# 448349Sgblack@eecs.umich.edu################################################################# 454484Sbinkertn@umich.edu 464484Sbinkertn@umich.edu# List of headers to generate 474484Sbinkertn@umich.eduisa_switch_hdrs = Split(''' 484484Sbinkertn@umich.edu decoder.hh 494484Sbinkertn@umich.edu interrupts.hh 504484Sbinkertn@umich.edu isa.hh 514484Sbinkertn@umich.edu isa_traits.hh 524484Sbinkertn@umich.edu kernel_stats.hh 534484Sbinkertn@umich.edu locked_mem.hh 544484Sbinkertn@umich.edu microcode_rom.hh 554484Sbinkertn@umich.edu mmapped_ipr.hh 564484Sbinkertn@umich.edu mt.hh 574484Sbinkertn@umich.edu process.hh 584484Sbinkertn@umich.edu registers.hh 594484Sbinkertn@umich.edu remote_gdb.hh 604484Sbinkertn@umich.edu stacktrace.hh 614484Sbinkertn@umich.edu tlb.hh 624484Sbinkertn@umich.edu types.hh 634484Sbinkertn@umich.edu utility.hh 644484Sbinkertn@umich.edu vtophys.hh 654484Sbinkertn@umich.edu ''') 664484Sbinkertn@umich.edu 674484Sbinkertn@umich.edu# Set up this directory to support switching headers 684484Sbinkertn@umich.edumake_switching_dir('arch', isa_switch_hdrs, env) 694484Sbinkertn@umich.edu 704484Sbinkertn@umich.edu################################################################# 714484Sbinkertn@umich.edu# 724484Sbinkertn@umich.edu# Include architecture-specific files. 734484Sbinkertn@umich.edu# 744484Sbinkertn@umich.edu################################################################# 754484Sbinkertn@umich.edu 764484Sbinkertn@umich.edu# 774484Sbinkertn@umich.edu# Build a SCons scanner for ISA files 784484Sbinkertn@umich.edu# 794484Sbinkertn@umich.eduimport SCons.Scanner 804484Sbinkertn@umich.edu 814484Sbinkertn@umich.eduisa_scanner = SCons.Scanner.Classic("ISAScan", 824484Sbinkertn@umich.edu [".isa", ".ISA"], 834484Sbinkertn@umich.edu "SRCDIR", 844484Sbinkertn@umich.edu r'^\s*##include\s+"([\w/.-]*)"') 854484Sbinkertn@umich.edu 864484Sbinkertn@umich.eduenv.Append(SCANNERS = isa_scanner) 874484Sbinkertn@umich.edu 884484Sbinkertn@umich.edu# 894484Sbinkertn@umich.edu# Now create a Builder object that uses isa_parser.py to generate C++ 904484Sbinkertn@umich.edu# output from the ISA description (*.isa) files. 914484Sbinkertn@umich.edu# 926121Snate@binkert.org 936121Snate@binkert.orgisa_parser = File('isa_parser.py') 946121Snate@binkert.org 955765Snate@binkert.org# The emitter patches up the sources & targets to include the 965765Snate@binkert.org# autogenerated files as targets and isa parser itself as a source. 975765Snate@binkert.orgdef isa_desc_emitter(target, source, env): 985397Ssaidi@eecs.umich.edu cpu_models = list(env['CPU_MODELS']) 995274Ssaidi@eecs.umich.edu cpu_models.append('CheckerCPU') 1004494Ssaidi@eecs.umich.edu 1014504Ssaidi@eecs.umich.edu # List the isa parser as a source. 1024494Ssaidi@eecs.umich.edu source += [ isa_parser ] 1034494Ssaidi@eecs.umich.edu # Add in the CPU models. 1044496Ssaidi@eecs.umich.edu source += [ Value(m) for m in cpu_models ] 1054504Ssaidi@eecs.umich.edu 1064504Ssaidi@eecs.umich.edu # Specify different targets depending on if we're running the ISA 1074500Sbinkertn@umich.edu # parser for its dependency information, or for the generated files. 1084500Sbinkertn@umich.edu # (As an optimization, the ISA parser detects the useless second run 1094496Ssaidi@eecs.umich.edu # and skips doing any work, if the first run was performed, since it 1104496Ssaidi@eecs.umich.edu # always generates all its files). The way we track this in SCons is the 1117739Sgblack@eecs.umich.edu # <arch>_isa_outputs value in the environment (env). If it's unset, we 1124487Sstever@eecs.umich.edu # don't know what the dependencies are so we ask for generated/inc.d to 1134484Sbinkertn@umich.edu # be generated so they can be acquired. If we know what they are, then 1144484Sbinkertn@umich.edu # it's because we've already processed inc.d and then claim that our 1154484Sbinkertn@umich.edu # outputs (targets) will be thus. 1164484Sbinkertn@umich.edu isa = env['TARGET_ISA'] 1174484Sbinkertn@umich.edu key = '%s_isa_outputs' % isa 1184484Sbinkertn@umich.edu if key in env: 1195601Snate@binkert.org targets = [ os.path.join('generated', f) for f in env[key] ] 1205601Snate@binkert.org else: 1215601Snate@binkert.org targets = [ os.path.join('generated','inc.d') ] 1225601Snate@binkert.org 1234484Sbinkertn@umich.edu def prefix(s): 1246121Snate@binkert.org return os.path.join(target[0].dir.up().abspath, s) 1256121Snate@binkert.org 1266121Snate@binkert.org return [ prefix(t) for t in targets ], source 1274494Ssaidi@eecs.umich.edu 128ARCH_DIR = Dir('.') 129 130# import ply here because SCons screws with sys.path when performing actions. 131import ply 132 133def isa_desc_action_func(target, source, env): 134 # Add the current directory to the system path so we can import files 135 sys.path[0:0] = [ ARCH_DIR.srcnode().abspath ] 136 import isa_parser 137 138 # Skip over the ISA description itself and the parser to the CPU models. 139 models = [ s.get_contents() for s in source[2:] ] 140 cpu_models = [CpuModel.dict[cpu] for cpu in models] 141 parser = isa_parser.ISAParser(target[0].dir.abspath, cpu_models) 142 parser.parse_isa_desc(source[0].abspath) 143isa_desc_action = MakeAction(isa_desc_action_func, Transform("ISA DESC", 1)) 144 145# Also include the CheckerCPU as one of the models if it is being 146# enabled via command line. 147isa_desc_builder = Builder(action=isa_desc_action, emitter=isa_desc_emitter) 148 149env.Append(BUILDERS = { 'ISADesc' : isa_desc_builder }) 150 151# The ISA is generated twice: the first time to find out what it generates, 152# and the second time to make scons happy by telling the ISADesc builder 153# what it will make before it builds it. 154def scan_isa_deps(target, source, env): 155 # Process dependency file generated by the ISA parser -- 156 # add the listed files to the dependency tree of the build. 157 source = source[0] 158 archbase = source.dir.up().path 159 160 try: 161 depfile = open(source.abspath, 'r') 162 except: 163 print "scan_isa_deps: Can't open ISA deps file '%s' in %s" % \ 164 (source.path,os.getcwd()) 165 raise 166 167 # Scan through the lines 168 targets = {} 169 for line in depfile: 170 # Read the dependency line with the format 171 # <target file>: [ <dependent file>* ] 172 m = re.match(r'^\s*([^:]+\.([^\.:]+))\s*:\s*(.*)', line) 173 assert(m) 174 targ, extn = m.group(1,2) 175 deps = m.group(3).split() 176 177 files = [ targ ] + deps 178 for f in files: 179 targets[f] = True 180 # Eliminate unnecessary re-generation if we already generated it 181 env.Precious(os.path.join(archbase, 'generated', f)) 182 183 files = [ os.path.join(archbase, 'generated', f) for f in files ] 184 185 if extn == 'cc': 186 Source(os.path.join(archbase,'generated', targ)) 187 depfile.close() 188 env[env['TARGET_ISA'] + '_isa_outputs'] = targets.keys() 189 190 isa = env.ISADesc(os.path.join(archbase,'isa','main.isa')) 191 for t in targets: 192 env.Depends('#all-isas', isa) 193 194env.Append(BUILDERS = {'ScanISA' : 195 Builder(action=MakeAction(scan_isa_deps, 196 Transform("NEW DEPS", 1)))}) 197 198DebugFlag('IntRegs') 199DebugFlag('FloatRegs') 200DebugFlag('CCRegs') 201DebugFlag('MiscRegs') 202CompoundFlag('Registers', [ 'IntRegs', 'FloatRegs', 'CCRegs', 'MiscRegs' ]) 203