SConscript revision 13610
12139SN/A# -*- mode:python -*- 22139SN/A 32139SN/A# Copyright (c) 2016-2017 ARM Limited 42139SN/A# All rights reserved. 52139SN/A# 62139SN/A# The license below extends only to copyright in the software and shall 72139SN/A# not be construed as granting a license to any other intellectual 82139SN/A# property including but not limited to intellectual property relating 92139SN/A# to a hardware implementation of the functionality of the software 102139SN/A# licensed hereunder. You may use the software subject to the license 112139SN/A# terms below provided that you ensure that this notice is replicated 122139SN/A# unmodified and in its entirety in all distributions of the software, 132139SN/A# modified or unmodified, in source code or in binary form. 142139SN/A# 152139SN/A# Copyright (c) 2006 The Regents of The University of Michigan 162139SN/A# All rights reserved. 172139SN/A# 182139SN/A# Redistribution and use in source and binary forms, with or without 192139SN/A# modification, are permitted provided that the following conditions are 202139SN/A# met: redistributions of source code must retain the above copyright 212139SN/A# notice, this list of conditions and the following disclaimer; 222139SN/A# redistributions in binary form must reproduce the above copyright 232139SN/A# notice, this list of conditions and the following disclaimer in the 242139SN/A# documentation and/or other materials provided with the distribution; 252139SN/A# neither the name of the copyright holders nor the names of its 262139SN/A# contributors may be used to endorse or promote products derived from 272139SN/A# this software without specific prior written permission. 282665Ssaidi@eecs.umich.edu# 292665Ssaidi@eecs.umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 302139SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 314202Sbinkertn@umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 328961Sgblack@eecs.umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 3310196SCurtis.Dunham@arm.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 342139SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 354202Sbinkertn@umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 362152SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 372152SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 382139SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 392139SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 402139SN/A# 412139SN/A# Authors: Steve Reinhardt 422139SN/A 432152SN/Aimport sys 442152SN/Aimport os 452139SN/Aimport re 462139SN/A 472139SN/Afrom gem5_scons import Transform 489020Sgblack@eecs.umich.edu 494781Snate@binkert.orgImport('*') 507799Sgblack@eecs.umich.edu 514781Snate@binkert.org################################################################# 524781Snate@binkert.org# 533170Sstever@eecs.umich.edu# ISA "switch header" generation. 545664Sgblack@eecs.umich.edu# 558105Sgblack@eecs.umich.edu# Auto-generate arch headers that include the right ISA-specific 566179Sksewell@umich.edu# header based on the setting of THE_ISA preprocessor variable. 574781Snate@binkert.org# 586329Sgblack@eecs.umich.edu################################################################# 594781Snate@binkert.org 604781Snate@binkert.orgenv.SwitchingHeaders( 614781Snate@binkert.org Split(''' 624781Snate@binkert.org decoder.hh 634781Snate@binkert.org interrupts.hh 644781Snate@binkert.org isa.hh 652139SN/A isa_traits.hh 662139SN/A kernel_stats.hh 673546Sgblack@eecs.umich.edu locked_mem.hh 684202Sbinkertn@umich.edu microcode_rom.hh 692152SN/A mmapped_ipr.hh 702152SN/A mt.hh 712152SN/A process.hh 722152SN/A pseudo_inst.hh 732152SN/A registers.hh 742152SN/A remote_gdb.hh 752152SN/A stacktrace.hh 762152SN/A types.hh 772152SN/A utility.hh 782152SN/A vtophys.hh 792152SN/A '''), 802152SN/A env.subst('${TARGET_ISA}')) 812504SN/A 822504SN/Aif env['BUILD_GPU']: 832504SN/A env.SwitchingHeaders( 842504SN/A Split(''' 852152SN/A gpu_decoder.hh 862504SN/A gpu_isa.hh 872152SN/A gpu_types.hh 882152SN/A '''), 892152SN/A env.subst('${TARGET_GPU_ISA}')) 902152SN/A 912152SN/A################################################################# 922152SN/A# 938584Sgblack@eecs.umich.edu# Include architecture-specific files. 948584Sgblack@eecs.umich.edu# 956993Snate@binkert.org################################################################# 966993Snate@binkert.org 976993Snate@binkert.org# 988584Sgblack@eecs.umich.edu# Build a SCons scanner for ISA files 9910319SAndreas.Sandberg@ARM.com# 10010319SAndreas.Sandberg@ARM.comimport SCons.Scanner 10110319SAndreas.Sandberg@ARM.comimport SCons.Tool 10210319SAndreas.Sandberg@ARM.com 1038584Sgblack@eecs.umich.eduscanner = SCons.Scanner.Classic("ISAScan", 10410196SCurtis.Dunham@arm.com [".isa", ".ISA"], 10510196SCurtis.Dunham@arm.com "SRCDIR", 10610196SCurtis.Dunham@arm.com r'^\s*##include\s+"([\w/.-]*)"') 10710196SCurtis.Dunham@arm.com 10810196SCurtis.Dunham@arm.comenv.Append(SCANNERS=scanner) 10910196SCurtis.Dunham@arm.com 11010196SCurtis.Dunham@arm.com# Tell scons that when it sees a cc.inc file, it should scan it for includes. 11110196SCurtis.Dunham@arm.comSCons.Tool.SourceFileScanner.add_scanner('.cc.inc', SCons.Tool.CScanner) 11210196SCurtis.Dunham@arm.com 11310196SCurtis.Dunham@arm.com# 11410196SCurtis.Dunham@arm.com# Now create a Builder object that uses isa_parser.py to generate C++ 11510196SCurtis.Dunham@arm.com# output from the ISA description (*.isa) files. 11610196SCurtis.Dunham@arm.com# 11710196SCurtis.Dunham@arm.com 11810196SCurtis.Dunham@arm.comparser_py = File('isa_parser.py') 11910196SCurtis.Dunham@arm.commicro_asm_py = File('micro_asm.py') 12010196SCurtis.Dunham@arm.com 12110196SCurtis.Dunham@arm.com# import ply here because SCons screws with sys.path when performing actions. 12210196SCurtis.Dunham@arm.comimport ply 12310196SCurtis.Dunham@arm.com 12410196SCurtis.Dunham@arm.comdef run_parser(target, source, env): 1256993Snate@binkert.org # Add the current directory to the system path so we can import files. 1266993Snate@binkert.org sys.path[0:0] = [ parser_py.dir.abspath ] 1276993Snate@binkert.org import isa_parser 1286998Snate@binkert.org 1296998Snate@binkert.org parser = isa_parser.ISAParser(target[0].dir.abspath) 1306998Snate@binkert.org parser.parse_isa_desc(source[0].abspath) 1317756SAli.Saidi@ARM.com 1326993Snate@binkert.orgdesc_action = MakeAction(run_parser, Transform("ISA DESC", 1)) 1336993Snate@binkert.org 1346993Snate@binkert.orgIsaDescBuilder = Builder(action=desc_action) 1356993Snate@binkert.org 1368585Sgblack@eecs.umich.edu 1378584Sgblack@eecs.umich.edu# ISAs should use this function to set up an IsaDescBuilder and not try to 13810319SAndreas.Sandberg@ARM.com# set one up manually. 1396993Snate@binkert.orgdef ISADesc(desc, decoder_splits=1, exec_splits=1): 1407816Ssteve.reinhardt@amd.com '''Set up a builder for an ISA description. 1412152SN/A 1422766Sktlim@umich.edu The decoder_splits and exec_splits parameters let us determine what 1432766Sktlim@umich.edu files the isa parser is actually going to generate. This needs to match 1446993Snate@binkert.org what files are actually generated, and there's no specific check for that 1452152SN/A right now. 1462152SN/A 1475944Sgblack@eecs.umich.edu If the parser itself is responsible for generating a list of its products 14810196SCurtis.Dunham@arm.com and their dependencies, then using that output to set up the right 14910196SCurtis.Dunham@arm.com dependencies. This is what we used to do. The problem is that scons 15010196SCurtis.Dunham@arm.com fundamentally doesn't support using a build product to affect its graph 15110196SCurtis.Dunham@arm.com of possible products, dependencies, builders, etc. There are a couple ways 15210196SCurtis.Dunham@arm.com to work around that limitation. 15310196SCurtis.Dunham@arm.com 15410196SCurtis.Dunham@arm.com One option is to compute dependencies while the build phase of scons is 15510196SCurtis.Dunham@arm.com running. That method can be quite complicated and cumbersome, because we 15610196SCurtis.Dunham@arm.com have to make sure our modifications are made before scons tries to 15710196SCurtis.Dunham@arm.com consume them. There's also no guarantee that this mechanism will work since 15810196SCurtis.Dunham@arm.com it subverts scons expectations and changes things behind its back. This 15910196SCurtis.Dunham@arm.com was implemented previously and constrained the builds parallelism 16010196SCurtis.Dunham@arm.com significantly. 16110196SCurtis.Dunham@arm.com 16210196SCurtis.Dunham@arm.com Another option would be to recursively call scons to have it update the 16310196SCurtis.Dunham@arm.com list of products/dependencies during the setup phase of this invocation of 16410196SCurtis.Dunham@arm.com scons. The problem with that is that it would be very difficult to make 16510196SCurtis.Dunham@arm.com the sub-invocation of scons observe the options passed to the primary one 16610196SCurtis.Dunham@arm.com in all possible cases, or to even determine conclusively what the name of 16710196SCurtis.Dunham@arm.com the scons executable is in the first place. 16810196SCurtis.Dunham@arm.com 16910196SCurtis.Dunham@arm.com Possible future changes to the isa parser might make it easier to 17010196SCurtis.Dunham@arm.com determine what files it would generate, perhaps because there was a more 17110196SCurtis.Dunham@arm.com direct correspondence between input files and output files. Or, if the 17210196SCurtis.Dunham@arm.com parser could run quickly and determine what its output files would be 17310196SCurtis.Dunham@arm.com without having do actually generate those files, then it could be run 17410196SCurtis.Dunham@arm.com unconditionally without slowing down all builds or touching the output 17510196SCurtis.Dunham@arm.com files unnecessarily. 17610196SCurtis.Dunham@arm.com ''' 17710196SCurtis.Dunham@arm.com generated_dir = File(desc).dir.up().Dir('generated') 17810196SCurtis.Dunham@arm.com def gen_file(name): 17910196SCurtis.Dunham@arm.com return generated_dir.File(name) 18010196SCurtis.Dunham@arm.com 18110196SCurtis.Dunham@arm.com gen = [] 18210196SCurtis.Dunham@arm.com def add_gen(name): 18310196SCurtis.Dunham@arm.com gen.append(gen_file(name)) 18410196SCurtis.Dunham@arm.com 18510196SCurtis.Dunham@arm.com # Tell scons about the various files the ISA parser will generate. 18610196SCurtis.Dunham@arm.com add_gen('decoder-g.cc.inc') 18710196SCurtis.Dunham@arm.com add_gen('decoder-ns.cc.inc') 18810196SCurtis.Dunham@arm.com add_gen('decode-method.cc.inc') 18910196SCurtis.Dunham@arm.com 19010196SCurtis.Dunham@arm.com add_gen('decoder.hh') 19110196SCurtis.Dunham@arm.com add_gen('decoder-g.hh.inc') 19210196SCurtis.Dunham@arm.com add_gen('decoder-ns.hh.inc') 19310196SCurtis.Dunham@arm.com 19410196SCurtis.Dunham@arm.com add_gen('exec-g.cc.inc') 1958335Snate@binkert.org add_gen('exec-ns.cc.inc') 1968335Snate@binkert.org 1979920Syasuko.eckert@amd.com add_gen('max_inst_regs.hh') 1988335Snate@binkert.org 1999920Syasuko.eckert@amd.com 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('VecPredRegs') 230DebugFlag('CCRegs') 231DebugFlag('MiscRegs') 232CompoundFlag('Registers', [ 'IntRegs', 'FloatRegs', 'VecRegs', 'VecPredRegs', 233 'CCRegs', 'MiscRegs' ]) 234