SConscript revision 10810
12139SN/A# -*- mode:python -*- 22139SN/A 32139SN/A# Copyright (c) 2006 The Regents of The University of Michigan 42139SN/A# All rights reserved. 52139SN/A# 62139SN/A# Redistribution and use in source and binary forms, with or without 72139SN/A# modification, are permitted provided that the following conditions are 82139SN/A# met: redistributions of source code must retain the above copyright 92139SN/A# notice, this list of conditions and the following disclaimer; 102139SN/A# redistributions in binary form must reproduce the above copyright 112139SN/A# notice, this list of conditions and the following disclaimer in the 122139SN/A# documentation and/or other materials provided with the distribution; 132139SN/A# neither the name of the copyright holders nor the names of its 142139SN/A# contributors may be used to endorse or promote products derived from 152139SN/A# this software without specific prior written permission. 162139SN/A# 172139SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 182139SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 192139SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 202139SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 212139SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 222139SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 232139SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 242139SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 252139SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 262139SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 272139SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 282665Ssaidi@eecs.umich.edu# 292665Ssaidi@eecs.umich.edu# Authors: Steve Reinhardt 302139SN/A 314202Sbinkertn@umich.eduimport sys 322139SN/Aimport os 334202Sbinkertn@umich.eduimport re 342152SN/A 352152SN/AImport('*') 362139SN/A 372139SN/A################################################################# 382139SN/A# 392139SN/A# ISA "switch header" generation. 402139SN/A# 412152SN/A# Auto-generate arch headers that include the right ISA-specific 422152SN/A# header based on the setting of THE_ISA preprocessor variable. 432139SN/A# 442139SN/A################################################################# 452139SN/A 464781Snate@binkert.org# List of headers to generate 474781Snate@binkert.orgisa_switch_hdrs = Split(''' 487799Sgblack@eecs.umich.edu decoder.hh 494781Snate@binkert.org interrupts.hh 504781Snate@binkert.org isa.hh 513170Sstever@eecs.umich.edu isa_traits.hh 525664Sgblack@eecs.umich.edu kernel_stats.hh 538105Sgblack@eecs.umich.edu locked_mem.hh 546179Sksewell@umich.edu microcode_rom.hh 554781Snate@binkert.org mmapped_ipr.hh 564781Snate@binkert.org mt.hh 576329Sgblack@eecs.umich.edu process.hh 584781Snate@binkert.org pseudo_inst.hh 594781Snate@binkert.org registers.hh 604781Snate@binkert.org remote_gdb.hh 614781Snate@binkert.org stacktrace.hh 624781Snate@binkert.org tlb.hh 634781Snate@binkert.org types.hh 642139SN/A utility.hh 652139SN/A vtophys.hh 663546Sgblack@eecs.umich.edu ''') 674202Sbinkertn@umich.edu 682152SN/A# Set up this directory to support switching headers 692152SN/Amake_switching_dir('arch', isa_switch_hdrs, env) 702152SN/A 712152SN/A################################################################# 722152SN/A# 732152SN/A# Include architecture-specific files. 742152SN/A# 752152SN/A################################################################# 762152SN/A 772152SN/A# 782152SN/A# Build a SCons scanner for ISA files 792152SN/A# 802504SN/Aimport SCons.Scanner 812504SN/A 822504SN/Aisa_scanner = SCons.Scanner.Classic("ISAScan", 832504SN/A [".isa", ".ISA"], 842152SN/A "SRCDIR", 852504SN/A r'^\s*##include\s+"([\w/.-]*)"') 862152SN/A 872152SN/Aenv.Append(SCANNERS = isa_scanner) 882152SN/A 892152SN/A# 902152SN/A# Now create a Builder object that uses isa_parser.py to generate C++ 912152SN/A# output from the ISA description (*.isa) files. 928584Sgblack@eecs.umich.edu# 938584Sgblack@eecs.umich.edu 946993Snate@binkert.orgisa_parser = File('isa_parser.py') 956993Snate@binkert.org 966993Snate@binkert.org# The emitter patches up the sources & targets to include the 976993Snate@binkert.org# autogenerated files as targets and isa parser itself as a source. 986993Snate@binkert.orgdef isa_desc_emitter(target, source, env): 996993Snate@binkert.org # List the isa parser as a source. 1006993Snate@binkert.org source += [ 1016993Snate@binkert.org isa_parser, 1026993Snate@binkert.org Value("ExecContext"), 1036993Snate@binkert.org ] 1046993Snate@binkert.org 1056993Snate@binkert.org # Specify different targets depending on if we're running the ISA 1066993Snate@binkert.org # parser for its dependency information, or for the generated files. 1078584Sgblack@eecs.umich.edu # (As an optimization, the ISA parser detects the useless second run 1088584Sgblack@eecs.umich.edu # and skips doing any work, if the first run was performed, since it 1098584Sgblack@eecs.umich.edu # always generates all its files). The way we track this in SCons is the 1108584Sgblack@eecs.umich.edu # <arch>_isa_outputs value in the environment (env). If it's unset, we 1118584Sgblack@eecs.umich.edu # don't know what the dependencies are so we ask for generated/inc.d to 1128584Sgblack@eecs.umich.edu # be generated so they can be acquired. If we know what they are, then 1136993Snate@binkert.org # it's because we've already processed inc.d and then claim that our 1146993Snate@binkert.org # outputs (targets) will be thus. 1156993Snate@binkert.org isa = env['TARGET_ISA'] 1166998Snate@binkert.org key = '%s_isa_outputs' % isa 1176998Snate@binkert.org if key in env: 1186998Snate@binkert.org targets = [ os.path.join('generated', f) for f in env[key] ] 1197756SAli.Saidi@ARM.com else: 1206993Snate@binkert.org targets = [ os.path.join('generated','inc.d') ] 1216993Snate@binkert.org 1226993Snate@binkert.org def prefix(s): 1236993Snate@binkert.org return os.path.join(target[0].dir.up().abspath, s) 1248585Sgblack@eecs.umich.edu 1258584Sgblack@eecs.umich.edu return [ prefix(t) for t in targets ], source 1266993Snate@binkert.org 1276993Snate@binkert.orgARCH_DIR = Dir('.') 1286993Snate@binkert.org 1297816Ssteve.reinhardt@amd.com# import ply here because SCons screws with sys.path when performing actions. 1302152SN/Aimport ply 1312766Sktlim@umich.edu 1322766Sktlim@umich.edudef isa_desc_action_func(target, source, env): 1336993Snate@binkert.org # Add the current directory to the system path so we can import files 1342152SN/A sys.path[0:0] = [ ARCH_DIR.srcnode().abspath ] 1352152SN/A import isa_parser 1365944Sgblack@eecs.umich.edu 1378335Snate@binkert.org # Skip over the ISA description itself and the parser to the CPU models. 1388335Snate@binkert.org models = [ s.get_contents() for s in source[2:] ] 1398335Snate@binkert.org parser = isa_parser.ISAParser(target[0].dir.abspath) 1405944Sgblack@eecs.umich.edu 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