SConscript revision 10935
113372Sgabeblack@google.com# -*- mode:python -*- 213372Sgabeblack@google.com 313372Sgabeblack@google.com# Copyright (c) 2006 The Regents of The University of Michigan 413372Sgabeblack@google.com# All rights reserved. 513372Sgabeblack@google.com# 613372Sgabeblack@google.com# Redistribution and use in source and binary forms, with or without 713372Sgabeblack@google.com# modification, are permitted provided that the following conditions are 813372Sgabeblack@google.com# met: redistributions of source code must retain the above copyright 913372Sgabeblack@google.com# notice, this list of conditions and the following disclaimer; 1013372Sgabeblack@google.com# redistributions in binary form must reproduce the above copyright 1113372Sgabeblack@google.com# notice, this list of conditions and the following disclaimer in the 1213372Sgabeblack@google.com# documentation and/or other materials provided with the distribution; 1313372Sgabeblack@google.com# neither the name of the copyright holders nor the names of its 1413372Sgabeblack@google.com# contributors may be used to endorse or promote products derived from 1513372Sgabeblack@google.com# this software without specific prior written permission. 1613372Sgabeblack@google.com# 1713372Sgabeblack@google.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1813372Sgabeblack@google.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1913372Sgabeblack@google.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2013372Sgabeblack@google.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2113372Sgabeblack@google.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2213372Sgabeblack@google.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2313372Sgabeblack@google.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2413372Sgabeblack@google.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2513372Sgabeblack@google.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2613372Sgabeblack@google.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2713372Sgabeblack@google.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2813372Sgabeblack@google.com# 2913463Sgabeblack@google.com# Authors: Steve Reinhardt 3013463Sgabeblack@google.com 3113463Sgabeblack@google.comimport sys 3213372Sgabeblack@google.comimport os 3313372Sgabeblack@google.comimport re 3413372Sgabeblack@google.com 3513463Sgabeblack@google.comImport('*') 3613463Sgabeblack@google.com 3713372Sgabeblack@google.com################################################################# 3813372Sgabeblack@google.com# 3913372Sgabeblack@google.com# ISA "switch header" generation. 4013463Sgabeblack@google.com# 4113463Sgabeblack@google.com# Auto-generate arch headers that include the right ISA-specific 4213372Sgabeblack@google.com# header based on the setting of THE_ISA preprocessor variable. 4313372Sgabeblack@google.com# 4413372Sgabeblack@google.com################################################################# 4513372Sgabeblack@google.com 4613372Sgabeblack@google.com# List of headers to generate 4713372Sgabeblack@google.comisa_switch_hdrs = Split(''' 4813372Sgabeblack@google.com decoder.hh 4913372Sgabeblack@google.com interrupts.hh 5013372Sgabeblack@google.com isa.hh 5113372Sgabeblack@google.com isa_traits.hh 5213372Sgabeblack@google.com kernel_stats.hh 5313372Sgabeblack@google.com locked_mem.hh 5413372Sgabeblack@google.com microcode_rom.hh 5513372Sgabeblack@google.com mmapped_ipr.hh 5613372Sgabeblack@google.com mt.hh 5713372Sgabeblack@google.com process.hh 5813372Sgabeblack@google.com pseudo_inst.hh 5913372Sgabeblack@google.com registers.hh 6013372Sgabeblack@google.com remote_gdb.hh 6113372Sgabeblack@google.com stacktrace.hh 6213372Sgabeblack@google.com tlb.hh 6313372Sgabeblack@google.com types.hh 6413372Sgabeblack@google.com utility.hh 6513372Sgabeblack@google.com vtophys.hh 6613372Sgabeblack@google.com ''') 6713372Sgabeblack@google.com 6813372Sgabeblack@google.com# Set up this directory to support switching headers 6913372Sgabeblack@google.commake_switching_dir('arch', isa_switch_hdrs, env) 7013372Sgabeblack@google.com 7113372Sgabeblack@google.com################################################################# 7213372Sgabeblack@google.com# 7313372Sgabeblack@google.com# Include architecture-specific files. 7413372Sgabeblack@google.com# 7513372Sgabeblack@google.com################################################################# 7613372Sgabeblack@google.com 7713372Sgabeblack@google.com# 7813372Sgabeblack@google.com# Build a SCons scanner for ISA files 7913372Sgabeblack@google.com# 8013372Sgabeblack@google.comimport SCons.Scanner 8113372Sgabeblack@google.com 8213372Sgabeblack@google.comisa_scanner = SCons.Scanner.Classic("ISAScan", 8313372Sgabeblack@google.com [".isa", ".ISA"], 8413372Sgabeblack@google.com "SRCDIR", 8513372Sgabeblack@google.com r'^\s*##include\s+"([\w/.-]*)"') 8613372Sgabeblack@google.com 87env.Append(SCANNERS = isa_scanner) 88 89# 90# Now create a Builder object that uses isa_parser.py to generate C++ 91# output from the ISA description (*.isa) files. 92# 93 94isa_parser = File('isa_parser.py') 95 96# The emitter patches up the sources & targets to include the 97# autogenerated files as targets and isa parser itself as a source. 98def isa_desc_emitter(target, source, env): 99 # List the isa parser as a source. 100 source += [ 101 isa_parser, 102 Value("ExecContext"), 103 ] 104 105 # Specify different targets depending on if we're running the ISA 106 # parser for its dependency information, or for the generated files. 107 # (As an optimization, the ISA parser detects the useless second run 108 # and skips doing any work, if the first run was performed, since it 109 # always generates all its files). The way we track this in SCons is the 110 # <arch>_isa_outputs value in the environment (env). If it's unset, we 111 # don't know what the dependencies are so we ask for generated/inc.d to 112 # be generated so they can be acquired. If we know what they are, then 113 # it's because we've already processed inc.d and then claim that our 114 # outputs (targets) will be thus. 115 isa = env['TARGET_ISA'] 116 key = '%s_isa_outputs' % isa 117 if key in env: 118 targets = [ os.path.join('generated', f) for f in env[key] ] 119 else: 120 targets = [ os.path.join('generated','inc.d') ] 121 122 def prefix(s): 123 return os.path.join(target[0].dir.up().abspath, s) 124 125 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