SConscript revision 13610
1955SN/A# -*- mode:python -*- 2955SN/A 31762SN/A# Copyright (c) 2016-2017 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 6610453SAndrew.Bardsley@arm.com kernel_stats.hh 6710453SAndrew.Bardsley@arm.com 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 728233Snate@binkert.org pseudo_inst.hh 738233Snate@binkert.org registers.hh 746143Snate@binkert.org remote_gdb.hh 758233Snate@binkert.org stacktrace.hh 768233Snate@binkert.org types.hh 778233Snate@binkert.org utility.hh 786143Snate@binkert.org vtophys.hh 796143Snate@binkert.org '''), 806143Snate@binkert.org env.subst('${TARGET_ISA}')) 816143Snate@binkert.org 828233Snate@binkert.orgif env['BUILD_GPU']: 838233Snate@binkert.org env.SwitchingHeaders( 848233Snate@binkert.org Split(''' 856143Snate@binkert.org gpu_decoder.hh 868233Snate@binkert.org gpu_isa.hh 878233Snate@binkert.org gpu_types.hh 888233Snate@binkert.org '''), 898233Snate@binkert.org env.subst('${TARGET_GPU_ISA}')) 906143Snate@binkert.org 916143Snate@binkert.org################################################################# 926143Snate@binkert.org# 934762Snate@binkert.org# Include architecture-specific files. 946143Snate@binkert.org# 958233Snate@binkert.org################################################################# 968233Snate@binkert.org 978233Snate@binkert.org# 988233Snate@binkert.org# Build a SCons scanner for ISA files 998233Snate@binkert.org# 1006143Snate@binkert.orgimport SCons.Scanner 1018233Snate@binkert.orgimport SCons.Tool 1028233Snate@binkert.org 1038233Snate@binkert.orgscanner = SCons.Scanner.Classic("ISAScan", 1048233Snate@binkert.org [".isa", ".ISA"], 1056143Snate@binkert.org "SRCDIR", 1066143Snate@binkert.org r'^\s*##include\s+"([\w/.-]*)"') 1076143Snate@binkert.org 1086143Snate@binkert.orgenv.Append(SCANNERS=scanner) 1096143Snate@binkert.org 1106143Snate@binkert.org# Tell scons that when it sees a cc.inc file, it should scan it for includes. 1116143Snate@binkert.orgSCons.Tool.SourceFileScanner.add_scanner('.cc.inc', SCons.Tool.CScanner) 1126143Snate@binkert.org 1136143Snate@binkert.org# 1147065Snate@binkert.org# Now create a Builder object that uses isa_parser.py to generate C++ 1156143Snate@binkert.org# output from the ISA description (*.isa) files. 1168233Snate@binkert.org# 1178233Snate@binkert.org 1188233Snate@binkert.orgparser_py = File('isa_parser.py') 1198233Snate@binkert.orgmicro_asm_py = File('micro_asm.py') 1208233Snate@binkert.org 1218233Snate@binkert.org# import ply here because SCons screws with sys.path when performing actions. 1228233Snate@binkert.orgimport ply 1238233Snate@binkert.org 1248233Snate@binkert.orgdef run_parser(target, source, env): 1258233Snate@binkert.org # Add the current directory to the system path so we can import files. 1268233Snate@binkert.org sys.path[0:0] = [ parser_py.dir.abspath ] 1278233Snate@binkert.org import isa_parser 1288233Snate@binkert.org 1298233Snate@binkert.org parser = isa_parser.ISAParser(target[0].dir.abspath) 1308233Snate@binkert.org parser.parse_isa_desc(source[0].abspath) 1318233Snate@binkert.org 1328233Snate@binkert.orgdesc_action = MakeAction(run_parser, Transform("ISA DESC", 1)) 1338233Snate@binkert.org 1348233Snate@binkert.orgIsaDescBuilder = Builder(action=desc_action) 1358233Snate@binkert.org 1368233Snate@binkert.org 1378233Snate@binkert.org# ISAs should use this function to set up an IsaDescBuilder and not try to 1388233Snate@binkert.org# set one up manually. 1398233Snate@binkert.orgdef ISADesc(desc, decoder_splits=1, exec_splits=1): 1408233Snate@binkert.org '''Set up a builder for an ISA description. 1418233Snate@binkert.org 1428233Snate@binkert.org The decoder_splits and exec_splits parameters let us determine what 1438233Snate@binkert.org files the isa parser is actually going to generate. This needs to match 1448233Snate@binkert.org what files are actually generated, and there's no specific check for that 1458233Snate@binkert.org right now. 1468233Snate@binkert.org 1476143Snate@binkert.org If the parser itself is responsible for generating a list of its products 1486143Snate@binkert.org and their dependencies, then using that output to set up the right 1496143Snate@binkert.org dependencies. This is what we used to do. The problem is that scons 1506143Snate@binkert.org fundamentally doesn't support using a build product to affect its graph 1516143Snate@binkert.org of possible products, dependencies, builders, etc. There are a couple ways 1526143Snate@binkert.org to work around that limitation. 1539982Satgutier@umich.edu 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 1626143Snate@binkert.org Another option would be to recursively call scons to have it update the 1636143Snate@binkert.org list of products/dependencies during the setup phase of this invocation of 1648945Ssteve.reinhardt@amd.com scons. The problem with that is that it would be very difficult to make 1658233Snate@binkert.org the sub-invocation of scons observe the options passed to the primary one 1668233Snate@binkert.org in all possible cases, or to even determine conclusively what the name of 1676143Snate@binkert.org the scons executable is in the first place. 1688945Ssteve.reinhardt@amd.com 1696143Snate@binkert.org Possible future changes to the isa parser might make it easier to 1706143Snate@binkert.org determine what files it would generate, perhaps because there was a more 1716143Snate@binkert.org direct correspondence between input files and output files. Or, if the 1726143Snate@binkert.org parser could run quickly and determine what its output files would be 1735522Snate@binkert.org without having do actually generate those files, then it could be run 1746143Snate@binkert.org unconditionally without slowing down all builds or touching the output 1756143Snate@binkert.org files unnecessarily. 1766143Snate@binkert.org ''' 1779982Satgutier@umich.edu generated_dir = File(desc).dir.up().Dir('generated') 1788233Snate@binkert.org def gen_file(name): 1798233Snate@binkert.org return generated_dir.File(name) 1808233Snate@binkert.org 1816143Snate@binkert.org gen = [] 1826143Snate@binkert.org def add_gen(name): 1836143Snate@binkert.org gen.append(gen_file(name)) 1846143Snate@binkert.org 1855522Snate@binkert.org # Tell scons about the various files the ISA parser will generate. 1865522Snate@binkert.org add_gen('decoder-g.cc.inc') 1875522Snate@binkert.org add_gen('decoder-ns.cc.inc') 1885522Snate@binkert.org add_gen('decode-method.cc.inc') 1895604Snate@binkert.org 1905604Snate@binkert.org add_gen('decoder.hh') 1916143Snate@binkert.org add_gen('decoder-g.hh.inc') 1926143Snate@binkert.org add_gen('decoder-ns.hh.inc') 1934762Snate@binkert.org 1944762Snate@binkert.org add_gen('exec-g.cc.inc') 1956143Snate@binkert.org add_gen('exec-ns.cc.inc') 1966727Ssteve.reinhardt@amd.com 1976727Ssteve.reinhardt@amd.com add_gen('max_inst_regs.hh') 1986727Ssteve.reinhardt@amd.com 1994762Snate@binkert.org 2006143Snate@binkert.org # These generated files are also top level sources. 2016143Snate@binkert.org def source_gen(name): 2026143Snate@binkert.org add_gen(name) 2036143Snate@binkert.org Source(gen_file(name)) 2046727Ssteve.reinhardt@amd.com 2056143Snate@binkert.org source_gen('decoder.cc') 2067674Snate@binkert.org 2077674Snate@binkert.org if decoder_splits == 1: 2085604Snate@binkert.org source_gen('inst-constrs.cc') 2096143Snate@binkert.org else: 2106143Snate@binkert.org for i in range(1, decoder_splits + 1): 2116143Snate@binkert.org source_gen('inst-constrs-%d.cc' % i) 2124762Snate@binkert.org 2136143Snate@binkert.org if exec_splits == 1: 2144762Snate@binkert.org source_gen('generic_cpu_exec.cc') 2154762Snate@binkert.org else: 2164762Snate@binkert.org for i in range(1, exec_splits + 1): 2176143Snate@binkert.org source_gen('generic_cpu_exec_%d.cc' % i) 2186143Snate@binkert.org 2194762Snate@binkert.org # Actually create the builder. 2208233Snate@binkert.org sources = [desc, parser_py, micro_asm_py] 2218233Snate@binkert.org IsaDescBuilder(target=gen, source=sources, env=env) 2228233Snate@binkert.org return gen 2238233Snate@binkert.org 2246143Snate@binkert.orgExport('ISADesc') 2256143Snate@binkert.org 2264762Snate@binkert.orgDebugFlag('IntRegs') 2276143Snate@binkert.orgDebugFlag('FloatRegs') 2284762Snate@binkert.orgDebugFlag('VecRegs') 2296143Snate@binkert.orgDebugFlag('VecPredRegs') 2304762Snate@binkert.orgDebugFlag('CCRegs') 2316143Snate@binkert.orgDebugFlag('MiscRegs') 2328233Snate@binkert.orgCompoundFlag('Registers', [ 'IntRegs', 'FloatRegs', 'VecRegs', 'VecPredRegs', 2338233Snate@binkert.org 'CCRegs', 'MiscRegs' ]) 23410453SAndrew.Bardsley@arm.com