SConscript revision 12246
12929Sktlim@umich.edu# -*- mode:python -*- 22929Sktlim@umich.edu 32932Sktlim@umich.edu# Copyright (c) 2016 ARM Limited 42929Sktlim@umich.edu# All rights reserved. 52929Sktlim@umich.edu# 62929Sktlim@umich.edu# The license below extends only to copyright in the software and shall 72929Sktlim@umich.edu# not be construed as granting a license to any other intellectual 82929Sktlim@umich.edu# property including but not limited to intellectual property relating 92929Sktlim@umich.edu# to a hardware implementation of the functionality of the software 102929Sktlim@umich.edu# licensed hereunder. You may use the software subject to the license 112929Sktlim@umich.edu# terms below provided that you ensure that this notice is replicated 122929Sktlim@umich.edu# unmodified and in its entirety in all distributions of the software, 132929Sktlim@umich.edu# modified or unmodified, in source code or in binary form. 142929Sktlim@umich.edu# 152929Sktlim@umich.edu# Copyright (c) 2006 The Regents of The University of Michigan 162929Sktlim@umich.edu# All rights reserved. 172929Sktlim@umich.edu# 182929Sktlim@umich.edu# Redistribution and use in source and binary forms, with or without 192929Sktlim@umich.edu# modification, are permitted provided that the following conditions are 202929Sktlim@umich.edu# met: redistributions of source code must retain the above copyright 212929Sktlim@umich.edu# notice, this list of conditions and the following disclaimer; 222929Sktlim@umich.edu# redistributions in binary form must reproduce the above copyright 232929Sktlim@umich.edu# notice, this list of conditions and the following disclaimer in the 242929Sktlim@umich.edu# documentation and/or other materials provided with the distribution; 252929Sktlim@umich.edu# neither the name of the copyright holders nor the names of its 262929Sktlim@umich.edu# contributors may be used to endorse or promote products derived from 272929Sktlim@umich.edu# this software without specific prior written permission. 282932Sktlim@umich.edu# 292932Sktlim@umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 302932Sktlim@umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 312929Sktlim@umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 322929Sktlim@umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 332929Sktlim@umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 342929Sktlim@umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 352929Sktlim@umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 362929Sktlim@umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 372929Sktlim@umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 382929Sktlim@umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 392929Sktlim@umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 402929Sktlim@umich.edu# 412929Sktlim@umich.edu# Authors: Steve Reinhardt 422929Sktlim@umich.edu 432929Sktlim@umich.eduimport sys 442929Sktlim@umich.eduimport os 452929Sktlim@umich.eduimport re 462929Sktlim@umich.edu 472929Sktlim@umich.edufrom gem5_scons import Transform 482929Sktlim@umich.edu 492929Sktlim@umich.eduImport('*') 502929Sktlim@umich.edu 512929Sktlim@umich.edu################################################################# 522929Sktlim@umich.edu# 532929Sktlim@umich.edu# ISA "switch header" generation. 542929Sktlim@umich.edu# 552929Sktlim@umich.edu# Auto-generate arch headers that include the right ISA-specific 562929Sktlim@umich.edu# header based on the setting of THE_ISA preprocessor variable. 572929Sktlim@umich.edu# 582929Sktlim@umich.edu################################################################# 592929Sktlim@umich.edu 602929Sktlim@umich.eduenv.SwitchingHeaders( 612929Sktlim@umich.edu Split(''' 622929Sktlim@umich.edu decoder.hh 632929Sktlim@umich.edu interrupts.hh 643020Sstever@eecs.umich.edu isa.hh 653020Sstever@eecs.umich.edu isa_traits.hh 663020Sstever@eecs.umich.edu kernel_stats.hh 672929Sktlim@umich.edu locked_mem.hh 682929Sktlim@umich.edu microcode_rom.hh 693021Sstever@eecs.umich.edu mmapped_ipr.hh 702929Sktlim@umich.edu mt.hh 712929Sktlim@umich.edu process.hh 722929Sktlim@umich.edu pseudo_inst.hh 732929Sktlim@umich.edu registers.hh 742929Sktlim@umich.edu remote_gdb.hh 752929Sktlim@umich.edu stacktrace.hh 762929Sktlim@umich.edu tlb.hh 772929Sktlim@umich.edu types.hh 782929Sktlim@umich.edu utility.hh 792929Sktlim@umich.edu vtophys.hh 802929Sktlim@umich.edu '''), 812929Sktlim@umich.edu env.subst('${TARGET_ISA}')) 822929Sktlim@umich.edu 832929Sktlim@umich.eduif env['BUILD_GPU']: 842929Sktlim@umich.edu env.SwitchingHeaders( 852929Sktlim@umich.edu Split(''' 862929Sktlim@umich.edu gpu_decoder.hh 872929Sktlim@umich.edu gpu_isa.hh 882929Sktlim@umich.edu gpu_types.hh 892929Sktlim@umich.edu '''), 902929Sktlim@umich.edu env.subst('${TARGET_GPU_ISA}')) 912929Sktlim@umich.edu 922929Sktlim@umich.edu################################################################# 932929Sktlim@umich.edu# 942929Sktlim@umich.edu# Include architecture-specific files. 952929Sktlim@umich.edu# 962929Sktlim@umich.edu################################################################# 972929Sktlim@umich.edu 982929Sktlim@umich.edu# 992929Sktlim@umich.edu# Build a SCons scanner for ISA files 1002929Sktlim@umich.edu# 1012929Sktlim@umich.eduimport SCons.Scanner 1022929Sktlim@umich.eduimport SCons.Tool 1032929Sktlim@umich.edu 1042929Sktlim@umich.eduscanner = SCons.Scanner.Classic("ISAScan", 1054937Sstever@gmail.com [".isa", ".ISA"], 1064937Sstever@gmail.com "SRCDIR", 1074937Sstever@gmail.com r'^\s*##include\s+"([\w/.-]*)"') 1084937Sstever@gmail.com 1094937Sstever@gmail.comenv.Append(SCANNERS=scanner) 1104937Sstever@gmail.com 1114937Sstever@gmail.com# Tell scons that when it sees a cc.inc file, it should scan it for includes. 1124937Sstever@gmail.comSCons.Tool.SourceFileScanner.add_scanner('.cc.inc', SCons.Tool.CScanner) 1134937Sstever@gmail.com 1144937Sstever@gmail.com# 1154937Sstever@gmail.com# Now create a Builder object that uses isa_parser.py to generate C++ 1164937Sstever@gmail.com# output from the ISA description (*.isa) files. 1174937Sstever@gmail.com# 1182929Sktlim@umich.edu 1192929Sktlim@umich.eduparser_py = File('isa_parser.py') 1202929Sktlim@umich.edumicro_asm_py = File('micro_asm.py') 1212929Sktlim@umich.edu 1222929Sktlim@umich.edu# import ply here because SCons screws with sys.path when performing actions. 1232929Sktlim@umich.eduimport ply 1242929Sktlim@umich.edu 1252929Sktlim@umich.edudef run_parser(target, source, env): 1262929Sktlim@umich.edu # Add the current directory to the system path so we can import files. 1272929Sktlim@umich.edu sys.path[0:0] = [ parser_py.dir.abspath ] 1284937Sstever@gmail.com import isa_parser 1294937Sstever@gmail.com 1304937Sstever@gmail.com parser = isa_parser.ISAParser(target[0].dir.abspath) 1314937Sstever@gmail.com parser.parse_isa_desc(source[0].abspath) 1324937Sstever@gmail.com 1334937Sstever@gmail.comdesc_action = MakeAction(run_parser, Transform("ISA DESC", 1)) 1344937Sstever@gmail.com 1354937Sstever@gmail.comIsaDescBuilder = Builder(action=desc_action) 1364937Sstever@gmail.com 1374937Sstever@gmail.com 1384937Sstever@gmail.com# ISAs should use this function to set up an IsaDescBuilder and not try to 1394937Sstever@gmail.com# set one up manually. 1404937Sstever@gmail.comdef ISADesc(desc, decoder_splits=1, exec_splits=1): 1414937Sstever@gmail.com '''Set up a builder for an ISA description. 1424937Sstever@gmail.com 1432929Sktlim@umich.edu The decoder_splits and exec_splits parameters let us determine what 1442929Sktlim@umich.edu files the isa parser is actually going to generate. This needs to match 1452929Sktlim@umich.edu what files are actually generated, and there's no specific check for that 1462929Sktlim@umich.edu right now. 1472929Sktlim@umich.edu 1482929Sktlim@umich.edu If the parser itself is responsible for generating a list of its products 1492929Sktlim@umich.edu and their dependencies, then using that output to set up the right 1502929Sktlim@umich.edu dependencies. This is what we used to do. The problem is that scons 1512929Sktlim@umich.edu fundamentally doesn't support using a build product to affect its graph 1522929Sktlim@umich.edu of possible products, dependencies, builders, etc. There are a couple ways 1532929Sktlim@umich.edu to work around that limitation. 1542929Sktlim@umich.edu 1552929Sktlim@umich.edu One option is to compute dependencies while the build phase of scons is 1562929Sktlim@umich.edu running. That method can be quite complicated and cumbersome, because we 1572929Sktlim@umich.edu have to make sure our modifications are made before scons tries to 1582929Sktlim@umich.edu consume them. There's also no guarantee that this mechanism will work since 1592997Sstever@eecs.umich.edu it subverts scons expectations and changes things behind its back. This 1602997Sstever@eecs.umich.edu was implemented previously and constrained the builds parallelism 1612929Sktlim@umich.edu significantly. 1622997Sstever@eecs.umich.edu 1632997Sstever@eecs.umich.edu Another option would be to recursively call scons to have it update the 1642929Sktlim@umich.edu list of products/dependencies during the setup phase of this invocation of 1652997Sstever@eecs.umich.edu scons. The problem with that is that it would be very difficult to make 1662997Sstever@eecs.umich.edu the sub-invocation of scons observe the options passed to the primary one 1672997Sstever@eecs.umich.edu in all possible cases, or to even determine conclusively what the name of 1682929Sktlim@umich.edu the scons executable is in the first place. 1692997Sstever@eecs.umich.edu 1702997Sstever@eecs.umich.edu Possible future changes to the isa parser might make it easier to 1712997Sstever@eecs.umich.edu determine what files it would generate, perhaps because there was a more 1722997Sstever@eecs.umich.edu direct correspondence between input files and output files. Or, if the 1732997Sstever@eecs.umich.edu parser could run quickly and determine what its output files would be 1742997Sstever@eecs.umich.edu without having do actually generate those files, then it could be run 1752997Sstever@eecs.umich.edu unconditionally without slowing down all builds or touching the output 1762997Sstever@eecs.umich.edu files unnecessarily. 1772997Sstever@eecs.umich.edu ''' 1782997Sstever@eecs.umich.edu generated_dir = File(desc).dir.up().Dir('generated') 1792997Sstever@eecs.umich.edu def gen_file(name): 1802997Sstever@eecs.umich.edu return generated_dir.File(name) 1812997Sstever@eecs.umich.edu 1822997Sstever@eecs.umich.edu gen = [] 1832997Sstever@eecs.umich.edu def add_gen(name): 1842997Sstever@eecs.umich.edu gen.append(gen_file(name)) 1852997Sstever@eecs.umich.edu 1862997Sstever@eecs.umich.edu # Tell scons about the various files the ISA parser will generate. 1872997Sstever@eecs.umich.edu add_gen('decoder-g.cc.inc') 1882997Sstever@eecs.umich.edu add_gen('decoder-ns.cc.inc') 1893045Sstever@eecs.umich.edu add_gen('decode-method.cc.inc') 1902997Sstever@eecs.umich.edu 1912997Sstever@eecs.umich.edu add_gen('decoder.hh') 1922997Sstever@eecs.umich.edu add_gen('decoder-g.hh.inc') 1932953Sktlim@umich.edu add_gen('decoder-ns.hh.inc') 1942997Sstever@eecs.umich.edu 1954781Snate@binkert.org add_gen('exec-g.cc.inc') 1962997Sstever@eecs.umich.edu add_gen('exec-ns.cc.inc') 1972997Sstever@eecs.umich.edu 1982929Sktlim@umich.edu add_gen('max_inst_regs.hh') 1992997Sstever@eecs.umich.edu 2002997Sstever@eecs.umich.edu 2012997Sstever@eecs.umich.edu # These generated files are also top level sources. 2022997Sstever@eecs.umich.edu def source_gen(name): 2032929Sktlim@umich.edu add_gen(name) 2042997Sstever@eecs.umich.edu Source(gen_file(name)) 2052997Sstever@eecs.umich.edu 2062997Sstever@eecs.umich.edu source_gen('decoder.cc') 2072997Sstever@eecs.umich.edu 2082997Sstever@eecs.umich.edu if decoder_splits == 1: 2092997Sstever@eecs.umich.edu source_gen('inst-constrs.cc') 2102997Sstever@eecs.umich.edu else: 2112929Sktlim@umich.edu for i in range(1, decoder_splits + 1): 2122997Sstever@eecs.umich.edu source_gen('inst-constrs-%d.cc' % i) 2132929Sktlim@umich.edu 2142929Sktlim@umich.edu if exec_splits == 1: 2153005Sstever@eecs.umich.edu source_gen('generic_cpu_exec.cc') 2163005Sstever@eecs.umich.edu else: 2173005Sstever@eecs.umich.edu for i in range(1, exec_splits + 1): 2183005Sstever@eecs.umich.edu source_gen('generic_cpu_exec_%d.cc' % i) 2193005Sstever@eecs.umich.edu 2203005Sstever@eecs.umich.edu # Actually create the builder. 2213005Sstever@eecs.umich.edu sources = [desc, parser_py, micro_asm_py] 2223005Sstever@eecs.umich.edu IsaDescBuilder(target=gen, source=sources, env=env) 2233691Shsul@eecs.umich.edu return gen 2244781Snate@binkert.org 2254130Ssaidi@eecs.umich.eduExport('ISADesc') 2264130Ssaidi@eecs.umich.edu 2274130Ssaidi@eecs.umich.eduDebugFlag('IntRegs') 2283691Shsul@eecs.umich.eduDebugFlag('FloatRegs') 2293005Sstever@eecs.umich.eduDebugFlag('VecRegs') 2304019Sstever@eecs.umich.eduDebugFlag('CCRegs') 2313005Sstever@eecs.umich.eduDebugFlag('MiscRegs') 2322929Sktlim@umich.eduCompoundFlag('Registers', [ 'IntRegs', 'FloatRegs', 'CCRegs', 'MiscRegs' ]) 2332929Sktlim@umich.edu