SConscript revision 12246
1955SN/A# -*- mode:python -*- 2955SN/A 31762SN/A# Copyright (c) 2016 ARM Limited 4955SN/A# All rights reserved. 5955SN/A# 6955SN/A# The license below extends only to copyright in the software and shall 7955SN/A# not be construed as granting a license to any other intellectual 8955SN/A# property including but not limited to intellectual property relating 9955SN/A# to a hardware implementation of the functionality of the software 10955SN/A# licensed hereunder. You may use the software subject to the license 11955SN/A# terms below provided that you ensure that this notice is replicated 12955SN/A# unmodified and in its entirety in all distributions of the software, 13955SN/A# modified or unmodified, in source code or in binary form. 14955SN/A# 15955SN/A# Copyright (c) 2006 The Regents of The University of Michigan 16955SN/A# All rights reserved. 17955SN/A# 18955SN/A# Redistribution and use in source and binary forms, with or without 19955SN/A# modification, are permitted provided that the following conditions are 20955SN/A# met: redistributions of source code must retain the above copyright 21955SN/A# notice, this list of conditions and the following disclaimer; 22955SN/A# redistributions in binary form must reproduce the above copyright 23955SN/A# notice, this list of conditions and the following disclaimer in the 24955SN/A# documentation and/or other materials provided with the distribution; 25955SN/A# neither the name of the copyright holders nor the names of its 26955SN/A# contributors may be used to endorse or promote products derived from 27955SN/A# this software without specific prior written permission. 282665Ssaidi@eecs.umich.edu# 294762Snate@binkert.org# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 30955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 315522Snate@binkert.org# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 326143Snate@binkert.org# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 334762Snate@binkert.org# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 345522Snate@binkert.org# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 35955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 365522Snate@binkert.org# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 37955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 385522Snate@binkert.org# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 394202Sbinkertn@umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 405742Snate@binkert.org# 41955SN/A# Authors: Steve Reinhardt 424381Sbinkertn@umich.edu 434381Sbinkertn@umich.eduimport sys 448334Snate@binkert.orgimport os 45955SN/Aimport re 46955SN/A 474202Sbinkertn@umich.edufrom gem5_scons import Transform 48955SN/A 494382Sbinkertn@umich.eduImport('*') 504382Sbinkertn@umich.edu 514382Sbinkertn@umich.edu################################################################# 526654Snate@binkert.org# 535517Snate@binkert.org# ISA "switch header" generation. 548614Sgblack@eecs.umich.edu# 557674Snate@binkert.org# Auto-generate arch headers that include the right ISA-specific 566143Snate@binkert.org# header based on the setting of THE_ISA preprocessor variable. 576143Snate@binkert.org# 586143Snate@binkert.org################################################################# 598233Snate@binkert.org 608233Snate@binkert.orgenv.SwitchingHeaders( 618233Snate@binkert.org Split(''' 628233Snate@binkert.org decoder.hh 638233Snate@binkert.org interrupts.hh 648334Snate@binkert.org isa.hh 658334Snate@binkert.org isa_traits.hh 668233Snate@binkert.org kernel_stats.hh 678233Snate@binkert.org locked_mem.hh 688233Snate@binkert.org microcode_rom.hh 698233Snate@binkert.org mmapped_ipr.hh 708233Snate@binkert.org mt.hh 718233Snate@binkert.org process.hh 726143Snate@binkert.org pseudo_inst.hh 738233Snate@binkert.org registers.hh 748233Snate@binkert.org remote_gdb.hh 758233Snate@binkert.org stacktrace.hh 766143Snate@binkert.org tlb.hh 776143Snate@binkert.org types.hh 786143Snate@binkert.org utility.hh 796143Snate@binkert.org vtophys.hh 808233Snate@binkert.org '''), 818233Snate@binkert.org env.subst('${TARGET_ISA}')) 828233Snate@binkert.org 836143Snate@binkert.orgif env['BUILD_GPU']: 848233Snate@binkert.org env.SwitchingHeaders( 858233Snate@binkert.org Split(''' 868233Snate@binkert.org gpu_decoder.hh 878233Snate@binkert.org gpu_isa.hh 886143Snate@binkert.org gpu_types.hh 896143Snate@binkert.org '''), 906143Snate@binkert.org env.subst('${TARGET_GPU_ISA}')) 914762Snate@binkert.org 926143Snate@binkert.org################################################################# 938233Snate@binkert.org# 948233Snate@binkert.org# Include architecture-specific files. 958233Snate@binkert.org# 968233Snate@binkert.org################################################################# 978233Snate@binkert.org 986143Snate@binkert.org# 998233Snate@binkert.org# Build a SCons scanner for ISA files 1008233Snate@binkert.org# 1018233Snate@binkert.orgimport SCons.Scanner 1028233Snate@binkert.orgimport SCons.Tool 1036143Snate@binkert.org 1046143Snate@binkert.orgscanner = SCons.Scanner.Classic("ISAScan", 1056143Snate@binkert.org [".isa", ".ISA"], 1066143Snate@binkert.org "SRCDIR", 1076143Snate@binkert.org r'^\s*##include\s+"([\w/.-]*)"') 1086143Snate@binkert.org 1096143Snate@binkert.orgenv.Append(SCANNERS=scanner) 1106143Snate@binkert.org 1116143Snate@binkert.org# Tell scons that when it sees a cc.inc file, it should scan it for includes. 1127065Snate@binkert.orgSCons.Tool.SourceFileScanner.add_scanner('.cc.inc', SCons.Tool.CScanner) 1136143Snate@binkert.org 1148233Snate@binkert.org# 1158233Snate@binkert.org# Now create a Builder object that uses isa_parser.py to generate C++ 1168233Snate@binkert.org# output from the ISA description (*.isa) files. 1178233Snate@binkert.org# 1188233Snate@binkert.org 1198233Snate@binkert.orgparser_py = File('isa_parser.py') 1208233Snate@binkert.orgmicro_asm_py = File('micro_asm.py') 1218233Snate@binkert.org 1228233Snate@binkert.org# import ply here because SCons screws with sys.path when performing actions. 1238233Snate@binkert.orgimport ply 1248233Snate@binkert.org 1258233Snate@binkert.orgdef run_parser(target, source, env): 1268233Snate@binkert.org # Add the current directory to the system path so we can import files. 1278233Snate@binkert.org sys.path[0:0] = [ parser_py.dir.abspath ] 1288233Snate@binkert.org import isa_parser 1298233Snate@binkert.org 1308233Snate@binkert.org parser = isa_parser.ISAParser(target[0].dir.abspath) 1318233Snate@binkert.org parser.parse_isa_desc(source[0].abspath) 1328233Snate@binkert.org 1338233Snate@binkert.orgdesc_action = MakeAction(run_parser, Transform("ISA DESC", 1)) 1348233Snate@binkert.org 1358233Snate@binkert.orgIsaDescBuilder = Builder(action=desc_action) 1368233Snate@binkert.org 1378233Snate@binkert.org 1388233Snate@binkert.org# ISAs should use this function to set up an IsaDescBuilder and not try to 1398233Snate@binkert.org# set one up manually. 1408233Snate@binkert.orgdef ISADesc(desc, decoder_splits=1, exec_splits=1): 1418233Snate@binkert.org '''Set up a builder for an ISA description. 1428233Snate@binkert.org 1438233Snate@binkert.org The decoder_splits and exec_splits parameters let us determine what 1448233Snate@binkert.org files the isa parser is actually going to generate. This needs to match 1456143Snate@binkert.org what files are actually generated, and there's no specific check for that 1466143Snate@binkert.org right now. 1476143Snate@binkert.org 1486143Snate@binkert.org If the parser itself is responsible for generating a list of its products 1496143Snate@binkert.org and their dependencies, then using that output to set up the right 1506143Snate@binkert.org dependencies. This is what we used to do. The problem is that scons 1516143Snate@binkert.org fundamentally doesn't support using a build product to affect its graph 1526143Snate@binkert.org of possible products, dependencies, builders, etc. There are a couple ways 1536143Snate@binkert.org to work around that limitation. 1548233Snate@binkert.org 1558233Snate@binkert.org One option is to compute dependencies while the build phase of scons is 1568233Snate@binkert.org running. That method can be quite complicated and cumbersome, because we 1576143Snate@binkert.org have to make sure our modifications are made before scons tries to 1586143Snate@binkert.org consume them. There's also no guarantee that this mechanism will work since 1596143Snate@binkert.org it subverts scons expectations and changes things behind its back. This 1606143Snate@binkert.org was implemented previously and constrained the builds parallelism 1616143Snate@binkert.org significantly. 1626143Snate@binkert.org 1635522Snate@binkert.org Another option would be to recursively call scons to have it update the 1646143Snate@binkert.org list of products/dependencies during the setup phase of this invocation of 1656143Snate@binkert.org scons. The problem with that is that it would be very difficult to make 1666143Snate@binkert.org the sub-invocation of scons observe the options passed to the primary one 1676143Snate@binkert.org in all possible cases, or to even determine conclusively what the name of 1688233Snate@binkert.org the scons executable is in the first place. 1698233Snate@binkert.org 1708233Snate@binkert.org Possible future changes to the isa parser might make it easier to 1716143Snate@binkert.org determine what files it would generate, perhaps because there was a more 1726143Snate@binkert.org direct correspondence between input files and output files. Or, if the 1736143Snate@binkert.org parser could run quickly and determine what its output files would be 1746143Snate@binkert.org without having do actually generate those files, then it could be run 1755522Snate@binkert.org unconditionally without slowing down all builds or touching the output 1765522Snate@binkert.org files unnecessarily. 1775522Snate@binkert.org ''' 1785522Snate@binkert.org generated_dir = File(desc).dir.up().Dir('generated') 1795604Snate@binkert.org def gen_file(name): 1805604Snate@binkert.org return generated_dir.File(name) 1816143Snate@binkert.org 1826143Snate@binkert.org gen = [] 1834762Snate@binkert.org def add_gen(name): 1844762Snate@binkert.org gen.append(gen_file(name)) 1856143Snate@binkert.org 1866727Ssteve.reinhardt@amd.com # Tell scons about the various files the ISA parser will generate. 1876727Ssteve.reinhardt@amd.com add_gen('decoder-g.cc.inc') 1886727Ssteve.reinhardt@amd.com add_gen('decoder-ns.cc.inc') 1894762Snate@binkert.org add_gen('decode-method.cc.inc') 1906143Snate@binkert.org 1916143Snate@binkert.org add_gen('decoder.hh') 1926143Snate@binkert.org add_gen('decoder-g.hh.inc') 1936143Snate@binkert.org add_gen('decoder-ns.hh.inc') 1946727Ssteve.reinhardt@amd.com 1956143Snate@binkert.org add_gen('exec-g.cc.inc') 1967674Snate@binkert.org add_gen('exec-ns.cc.inc') 1977674Snate@binkert.org 1985604Snate@binkert.org add_gen('max_inst_regs.hh') 1996143Snate@binkert.org 2006143Snate@binkert.org 2016143Snate@binkert.org # These generated files are also top level sources. 2024762Snate@binkert.org def source_gen(name): 2036143Snate@binkert.org add_gen(name) 2044762Snate@binkert.org Source(gen_file(name)) 2054762Snate@binkert.org 2064762Snate@binkert.org source_gen('decoder.cc') 2076143Snate@binkert.org 2086143Snate@binkert.org if decoder_splits == 1: 2094762Snate@binkert.org source_gen('inst-constrs.cc') 2108233Snate@binkert.org else: 2118233Snate@binkert.org for i in range(1, decoder_splits + 1): 2128233Snate@binkert.org source_gen('inst-constrs-%d.cc' % i) 2138233Snate@binkert.org 2146143Snate@binkert.org if exec_splits == 1: 2156143Snate@binkert.org source_gen('generic_cpu_exec.cc') 2164762Snate@binkert.org else: 2176143Snate@binkert.org for i in range(1, exec_splits + 1): 2184762Snate@binkert.org source_gen('generic_cpu_exec_%d.cc' % i) 2196143Snate@binkert.org 2204762Snate@binkert.org # Actually create the builder. 2216143Snate@binkert.org sources = [desc, parser_py, micro_asm_py] 2228233Snate@binkert.org IsaDescBuilder(target=gen, source=sources, env=env) 2238233Snate@binkert.org return gen 2248233Snate@binkert.org 2256143Snate@binkert.orgExport('ISADesc') 2266143Snate@binkert.org 2276143Snate@binkert.orgDebugFlag('IntRegs') 2286143Snate@binkert.orgDebugFlag('FloatRegs') 2296143Snate@binkert.orgDebugFlag('VecRegs') 2306143Snate@binkert.orgDebugFlag('CCRegs') 2316143Snate@binkert.orgDebugFlag('MiscRegs') 2326143Snate@binkert.orgCompoundFlag('Registers', [ 'IntRegs', 'FloatRegs', 'CCRegs', 'MiscRegs' ]) 2338233Snate@binkert.org