SConscript revision 10623
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. 434484Sbinkertn@umich.edu# 444484Sbinkertn@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 pseudo_inst.hh 594484Sbinkertn@umich.edu registers.hh 604484Sbinkertn@umich.edu remote_gdb.hh 614484Sbinkertn@umich.edu stacktrace.hh 624484Sbinkertn@umich.edu tlb.hh 634484Sbinkertn@umich.edu types.hh 644484Sbinkertn@umich.edu utility.hh 654484Sbinkertn@umich.edu vtophys.hh 664484Sbinkertn@umich.edu ''') 674484Sbinkertn@umich.edu 684484Sbinkertn@umich.edu# Set up this directory to support switching headers 694484Sbinkertn@umich.edumake_switching_dir('arch', isa_switch_hdrs, env) 704484Sbinkertn@umich.edu 714484Sbinkertn@umich.edu################################################################# 724484Sbinkertn@umich.edu# 734484Sbinkertn@umich.edu# Include architecture-specific files. 744484Sbinkertn@umich.edu# 754484Sbinkertn@umich.edu################################################################# 764484Sbinkertn@umich.edu 774484Sbinkertn@umich.edu# 784484Sbinkertn@umich.edu# Build a SCons scanner for ISA files 794484Sbinkertn@umich.edu# 804484Sbinkertn@umich.eduimport SCons.Scanner 814484Sbinkertn@umich.edu 824484Sbinkertn@umich.eduisa_scanner = SCons.Scanner.Classic("ISAScan", 834484Sbinkertn@umich.edu [".isa", ".ISA"], 844484Sbinkertn@umich.edu "SRCDIR", 854484Sbinkertn@umich.edu r'^\s*##include\s+"([\w/.-]*)"') 864484Sbinkertn@umich.edu 874484Sbinkertn@umich.eduenv.Append(SCANNERS = isa_scanner) 884484Sbinkertn@umich.edu 894484Sbinkertn@umich.edu# 906121Snate@binkert.org# Now create a Builder object that uses isa_parser.py to generate C++ 916121Snate@binkert.org# output from the ISA description (*.isa) files. 926121Snate@binkert.org# 935765Snate@binkert.org 945765Snate@binkert.orgisa_parser = File('isa_parser.py') 955765Snate@binkert.org 965397Ssaidi@eecs.umich.edu# The emitter patches up the sources & targets to include the 975274Ssaidi@eecs.umich.edu# autogenerated files as targets and isa parser itself as a source. 984494Ssaidi@eecs.umich.edudef isa_desc_emitter(target, source, env): 994504Ssaidi@eecs.umich.edu # List the isa parser as a source. 1004494Ssaidi@eecs.umich.edu source += [ 1014494Ssaidi@eecs.umich.edu isa_parser, 1024496Ssaidi@eecs.umich.edu Value("ExecContext"), 1034504Ssaidi@eecs.umich.edu ] 1044504Ssaidi@eecs.umich.edu 1054500Sbinkertn@umich.edu # Specify different targets depending on if we're running the ISA 1064500Sbinkertn@umich.edu # parser for its dependency information, or for the generated files. 1074496Ssaidi@eecs.umich.edu # (As an optimization, the ISA parser detects the useless second run 1084496Ssaidi@eecs.umich.edu # and skips doing any work, if the first run was performed, since it 1094487Sstever@eecs.umich.edu # always generates all its files). The way we track this in SCons is the 1104487Sstever@eecs.umich.edu # <arch>_isa_outputs value in the environment (env). If it's unset, we 1114484Sbinkertn@umich.edu # don't know what the dependencies are so we ask for generated/inc.d to 1124484Sbinkertn@umich.edu # be generated so they can be acquired. If we know what they are, then 1134484Sbinkertn@umich.edu # it's because we've already processed inc.d and then claim that our 1144484Sbinkertn@umich.edu # outputs (targets) will be thus. 1154484Sbinkertn@umich.edu isa = env['TARGET_ISA'] 1164484Sbinkertn@umich.edu key = '%s_isa_outputs' % isa 1175601Snate@binkert.org if key in env: 1185601Snate@binkert.org targets = [ os.path.join('generated', f) for f in env[key] ] 1195601Snate@binkert.org else: 1205601Snate@binkert.org targets = [ os.path.join('generated','inc.d') ] 1214484Sbinkertn@umich.edu 1226121Snate@binkert.org def prefix(s): 1236121Snate@binkert.org return os.path.join(target[0].dir.up().abspath, s) 1246121Snate@binkert.org 1254494Ssaidi@eecs.umich.edu return [ prefix(t) for t in targets ], source 126 127ARCH_DIR = Dir('.') 128 129# import ply here because SCons screws with sys.path when performing actions. 130import ply 131 132def isa_desc_action_func(target, source, env): 133 # Add the current directory to the system path so we can import files 134 sys.path[0:0] = [ ARCH_DIR.srcnode().abspath ] 135 import isa_parser 136 137 # Skip over the ISA description itself and the parser to the CPU models. 138 models = [ s.get_contents() for s in source[2:] ] 139 parser = isa_parser.ISAParser(target[0].dir.abspath) 140 parser.parse_isa_desc(source[0].abspath) 141isa_desc_action = MakeAction(isa_desc_action_func, Transform("ISA DESC", 1)) 142 143# Also include the CheckerCPU as one of the models if it is being 144# enabled via command line. 145isa_desc_builder = Builder(action=isa_desc_action, emitter=isa_desc_emitter) 146 147env.Append(BUILDERS = { 'ISADesc' : isa_desc_builder }) 148 149# The ISA is generated twice: the first time to find out what it generates, 150# and the second time to make scons happy by telling the ISADesc builder 151# what it will make before it builds it. 152def scan_isa_deps(target, source, env): 153 # Process dependency file generated by the ISA parser -- 154 # add the listed files to the dependency tree of the build. 155 source = source[0] 156 archbase = source.dir.up().path 157 158 try: 159 depfile = open(source.abspath, 'r') 160 except: 161 print "scan_isa_deps: Can't open ISA deps file '%s' in %s" % \ 162 (source.path,os.getcwd()) 163 raise 164 165 # Scan through the lines 166 targets = {} 167 for line in depfile: 168 # Read the dependency line with the format 169 # <target file>: [ <dependent file>* ] 170 m = re.match(r'^\s*([^:]+\.([^\.:]+))\s*:\s*(.*)', line) 171 assert(m) 172 targ, extn = m.group(1,2) 173 deps = m.group(3).split() 174 175 files = [ targ ] + deps 176 for f in files: 177 targets[f] = True 178 # Eliminate unnecessary re-generation if we already generated it 179 env.Precious(os.path.join(archbase, 'generated', f)) 180 181 files = [ os.path.join(archbase, 'generated', f) for f in files ] 182 183 if extn == 'cc': 184 Source(os.path.join(archbase,'generated', targ)) 185 depfile.close() 186 env[env['TARGET_ISA'] + '_isa_outputs'] = targets.keys() 187 188 isa = env.ISADesc(os.path.join(archbase,'isa','main.isa')) 189 for t in targets: 190 env.Depends('#all-isas', isa) 191 192env.Append(BUILDERS = {'ScanISA' : 193 Builder(action=MakeAction(scan_isa_deps, 194 Transform("NEW DEPS", 1)))}) 195 196DebugFlag('IntRegs') 197DebugFlag('FloatRegs') 198DebugFlag('CCRegs') 199DebugFlag('MiscRegs') 200CompoundFlag('Registers', [ 'IntRegs', 'FloatRegs', 'CCRegs', 'MiscRegs' ]) 201