SConscript revision 12943
14484Sbinkertn@umich.edu# -*- mode:python -*- 24484Sbinkertn@umich.edu 34484Sbinkertn@umich.edu# Copyright (c) 2016 ARM Limited 44484Sbinkertn@umich.edu# All rights reserved. 54484Sbinkertn@umich.edu# 64484Sbinkertn@umich.edu# The license below extends only to copyright in the software and shall 74484Sbinkertn@umich.edu# not be construed as granting a license to any other intellectual 84484Sbinkertn@umich.edu# property including but not limited to intellectual property relating 94484Sbinkertn@umich.edu# to a hardware implementation of the functionality of the software 104484Sbinkertn@umich.edu# licensed hereunder. You may use the software subject to the license 114484Sbinkertn@umich.edu# terms below provided that you ensure that this notice is replicated 124484Sbinkertn@umich.edu# unmodified and in its entirety in all distributions of the software, 134484Sbinkertn@umich.edu# modified or unmodified, in source code or in binary form. 144484Sbinkertn@umich.edu# 154484Sbinkertn@umich.edu# Copyright (c) 2006 The Regents of The University of Michigan 164484Sbinkertn@umich.edu# All rights reserved. 174484Sbinkertn@umich.edu# 184484Sbinkertn@umich.edu# Redistribution and use in source and binary forms, with or without 194484Sbinkertn@umich.edu# modification, are permitted provided that the following conditions are 204484Sbinkertn@umich.edu# met: redistributions of source code must retain the above copyright 214484Sbinkertn@umich.edu# notice, this list of conditions and the following disclaimer; 224484Sbinkertn@umich.edu# redistributions in binary form must reproduce the above copyright 234484Sbinkertn@umich.edu# notice, this list of conditions and the following disclaimer in the 244484Sbinkertn@umich.edu# documentation and/or other materials provided with the distribution; 254484Sbinkertn@umich.edu# neither the name of the copyright holders nor the names of its 264484Sbinkertn@umich.edu# contributors may be used to endorse or promote products derived from 274484Sbinkertn@umich.edu# this software without specific prior written permission. 284484Sbinkertn@umich.edu# 294484Sbinkertn@umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 304484Sbinkertn@umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 314494Ssaidi@eecs.umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 324484Sbinkertn@umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 336121Snate@binkert.org# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 344484Sbinkertn@umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 354484Sbinkertn@umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 364484Sbinkertn@umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 374484Sbinkertn@umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 384781Snate@binkert.org# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 394484Sbinkertn@umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 404484Sbinkertn@umich.edu# 414484Sbinkertn@umich.edu# Authors: Steve Reinhardt 424484Sbinkertn@umich.edu 434484Sbinkertn@umich.eduimport sys 444484Sbinkertn@umich.eduimport os 454484Sbinkertn@umich.eduimport re 464484Sbinkertn@umich.edu 474484Sbinkertn@umich.edufrom gem5_scons import Transform 484484Sbinkertn@umich.edu 494484Sbinkertn@umich.eduImport('*') 504484Sbinkertn@umich.edu 514484Sbinkertn@umich.edu################################################################# 524484Sbinkertn@umich.edu# 534484Sbinkertn@umich.edu# ISA "switch header" generation. 544484Sbinkertn@umich.edu# 554484Sbinkertn@umich.edu# Auto-generate arch headers that include the right ISA-specific 564484Sbinkertn@umich.edu# header based on the setting of THE_ISA preprocessor variable. 574484Sbinkertn@umich.edu# 584484Sbinkertn@umich.edu################################################################# 594484Sbinkertn@umich.edu 604484Sbinkertn@umich.eduenv.SwitchingHeaders( 614484Sbinkertn@umich.edu Split(''' 624484Sbinkertn@umich.edu decoder.hh 634484Sbinkertn@umich.edu interrupts.hh 644484Sbinkertn@umich.edu isa.hh 654484Sbinkertn@umich.edu isa_traits.hh 664484Sbinkertn@umich.edu kernel_stats.hh 674484Sbinkertn@umich.edu locked_mem.hh 684484Sbinkertn@umich.edu microcode_rom.hh 694484Sbinkertn@umich.edu mmapped_ipr.hh 704484Sbinkertn@umich.edu mt.hh 714484Sbinkertn@umich.edu process.hh 724484Sbinkertn@umich.edu pseudo_inst.hh 734484Sbinkertn@umich.edu registers.hh 744484Sbinkertn@umich.edu remote_gdb.hh 754484Sbinkertn@umich.edu stacktrace.hh 764484Sbinkertn@umich.edu types.hh 774484Sbinkertn@umich.edu utility.hh 784484Sbinkertn@umich.edu vtophys.hh 794484Sbinkertn@umich.edu '''), 804484Sbinkertn@umich.edu env.subst('${TARGET_ISA}')) 814484Sbinkertn@umich.edu 824484Sbinkertn@umich.eduif env['BUILD_GPU']: 834484Sbinkertn@umich.edu env.SwitchingHeaders( 844484Sbinkertn@umich.edu Split(''' 854484Sbinkertn@umich.edu gpu_decoder.hh 864484Sbinkertn@umich.edu gpu_isa.hh 874484Sbinkertn@umich.edu gpu_types.hh 884484Sbinkertn@umich.edu '''), 894484Sbinkertn@umich.edu env.subst('${TARGET_GPU_ISA}')) 906121Snate@binkert.org 916121Snate@binkert.org################################################################# 926121Snate@binkert.org# 935765Snate@binkert.org# Include architecture-specific files. 945765Snate@binkert.org# 955765Snate@binkert.org################################################################# 965397Ssaidi@eecs.umich.edu 975274Ssaidi@eecs.umich.edu# 984494Ssaidi@eecs.umich.edu# Build a SCons scanner for ISA files 994504Ssaidi@eecs.umich.edu# 1004494Ssaidi@eecs.umich.eduimport SCons.Scanner 1014494Ssaidi@eecs.umich.eduimport SCons.Tool 1024496Ssaidi@eecs.umich.edu 1034504Ssaidi@eecs.umich.eduscanner = SCons.Scanner.Classic("ISAScan", 1044504Ssaidi@eecs.umich.edu [".isa", ".ISA"], 1054500Sbinkertn@umich.edu "SRCDIR", 1064500Sbinkertn@umich.edu r'^\s*##include\s+"([\w/.-]*)"') 1074496Ssaidi@eecs.umich.edu 1084496Ssaidi@eecs.umich.eduenv.Append(SCANNERS=scanner) 1097739Sgblack@eecs.umich.edu 1104487Sstever@eecs.umich.edu# Tell scons that when it sees a cc.inc file, it should scan it for includes. 1114484Sbinkertn@umich.eduSCons.Tool.SourceFileScanner.add_scanner('.cc.inc', SCons.Tool.CScanner) 1124484Sbinkertn@umich.edu 1134484Sbinkertn@umich.edu# 1144484Sbinkertn@umich.edu# Now create a Builder object that uses isa_parser.py to generate C++ 1154484Sbinkertn@umich.edu# output from the ISA description (*.isa) files. 1164484Sbinkertn@umich.edu# 1175601Snate@binkert.org 1185601Snate@binkert.orgparser_py = File('isa_parser.py') 1195601Snate@binkert.orgmicro_asm_py = File('micro_asm.py') 1205601Snate@binkert.org 1214484Sbinkertn@umich.edu# import ply here because SCons screws with sys.path when performing actions. 1226121Snate@binkert.orgimport ply 1236121Snate@binkert.org 1246121Snate@binkert.orgdef run_parser(target, source, env): 1254494Ssaidi@eecs.umich.edu # Add the current directory to the system path so we can import files. 126 sys.path[0:0] = [ parser_py.dir.abspath ] 127 import isa_parser 128 129 parser = isa_parser.ISAParser(target[0].dir.abspath) 130 parser.parse_isa_desc(source[0].abspath) 131 132desc_action = MakeAction(run_parser, Transform("ISA DESC", 1)) 133 134IsaDescBuilder = Builder(action=desc_action) 135 136 137# ISAs should use this function to set up an IsaDescBuilder and not try to 138# set one up manually. 139def ISADesc(desc, decoder_splits=1, exec_splits=1): 140 '''Set up a builder for an ISA description. 141 142 The decoder_splits and exec_splits parameters let us determine what 143 files the isa parser is actually going to generate. This needs to match 144 what files are actually generated, and there's no specific check for that 145 right now. 146 147 If the parser itself is responsible for generating a list of its products 148 and their dependencies, then using that output to set up the right 149 dependencies. This is what we used to do. The problem is that scons 150 fundamentally doesn't support using a build product to affect its graph 151 of possible products, dependencies, builders, etc. There are a couple ways 152 to work around that limitation. 153 154 One option is to compute dependencies while the build phase of scons is 155 running. That method can be quite complicated and cumbersome, because we 156 have to make sure our modifications are made before scons tries to 157 consume them. There's also no guarantee that this mechanism will work since 158 it subverts scons expectations and changes things behind its back. This 159 was implemented previously and constrained the builds parallelism 160 significantly. 161 162 Another option would be to recursively call scons to have it update the 163 list of products/dependencies during the setup phase of this invocation of 164 scons. The problem with that is that it would be very difficult to make 165 the sub-invocation of scons observe the options passed to the primary one 166 in all possible cases, or to even determine conclusively what the name of 167 the scons executable is in the first place. 168 169 Possible future changes to the isa parser might make it easier to 170 determine what files it would generate, perhaps because there was a more 171 direct correspondence between input files and output files. Or, if the 172 parser could run quickly and determine what its output files would be 173 without having do actually generate those files, then it could be run 174 unconditionally without slowing down all builds or touching the output 175 files unnecessarily. 176 ''' 177 generated_dir = File(desc).dir.up().Dir('generated') 178 def gen_file(name): 179 return generated_dir.File(name) 180 181 gen = [] 182 def add_gen(name): 183 gen.append(gen_file(name)) 184 185 # Tell scons about the various files the ISA parser will generate. 186 add_gen('decoder-g.cc.inc') 187 add_gen('decoder-ns.cc.inc') 188 add_gen('decode-method.cc.inc') 189 190 add_gen('decoder.hh') 191 add_gen('decoder-g.hh.inc') 192 add_gen('decoder-ns.hh.inc') 193 194 add_gen('exec-g.cc.inc') 195 add_gen('exec-ns.cc.inc') 196 197 add_gen('max_inst_regs.hh') 198 199 200 # These generated files are also top level sources. 201 def source_gen(name): 202 add_gen(name) 203 Source(gen_file(name)) 204 205 source_gen('decoder.cc') 206 207 if decoder_splits == 1: 208 source_gen('inst-constrs.cc') 209 else: 210 for i in range(1, decoder_splits + 1): 211 source_gen('inst-constrs-%d.cc' % i) 212 213 if exec_splits == 1: 214 source_gen('generic_cpu_exec.cc') 215 else: 216 for i in range(1, exec_splits + 1): 217 source_gen('generic_cpu_exec_%d.cc' % i) 218 219 # Actually create the builder. 220 sources = [desc, parser_py, micro_asm_py] 221 IsaDescBuilder(target=gen, source=sources, env=env) 222 return gen 223 224Export('ISADesc') 225 226DebugFlag('IntRegs') 227DebugFlag('FloatRegs') 228DebugFlag('VecRegs') 229DebugFlag('CCRegs') 230DebugFlag('MiscRegs') 231CompoundFlag('Registers', [ 'IntRegs', 'FloatRegs', 'CCRegs', 'MiscRegs' ]) 232