SConscript revision 12462:abdd0f6a2593
12207SN/A# -*- mode:python -*- 25254Sksewell@umich.edu 35254Sksewell@umich.edu# Copyright (c) 2016 ARM Limited 42207SN/A# All rights reserved. 55254Sksewell@umich.edu# 65254Sksewell@umich.edu# The license below extends only to copyright in the software and shall 75254Sksewell@umich.edu# not be construed as granting a license to any other intellectual 85254Sksewell@umich.edu# property including but not limited to intellectual property relating 95254Sksewell@umich.edu# to a hardware implementation of the functionality of the software 105254Sksewell@umich.edu# licensed hereunder. You may use the software subject to the license 115254Sksewell@umich.edu# terms below provided that you ensure that this notice is replicated 125254Sksewell@umich.edu# unmodified and in its entirety in all distributions of the software, 135254Sksewell@umich.edu# modified or unmodified, in source code or in binary form. 145254Sksewell@umich.edu# 152207SN/A# Copyright (c) 2006 The Regents of The University of Michigan 165254Sksewell@umich.edu# All rights reserved. 175254Sksewell@umich.edu# 185254Sksewell@umich.edu# Redistribution and use in source and binary forms, with or without 195254Sksewell@umich.edu# modification, are permitted provided that the following conditions are 205254Sksewell@umich.edu# met: redistributions of source code must retain the above copyright 215254Sksewell@umich.edu# notice, this list of conditions and the following disclaimer; 225254Sksewell@umich.edu# redistributions in binary form must reproduce the above copyright 235254Sksewell@umich.edu# notice, this list of conditions and the following disclaimer in the 245254Sksewell@umich.edu# documentation and/or other materials provided with the distribution; 255254Sksewell@umich.edu# neither the name of the copyright holders nor the names of its 265254Sksewell@umich.edu# contributors may be used to endorse or promote products derived from 272665Ssaidi@eecs.umich.edu# this software without specific prior written permission. 285254Sksewell@umich.edu# 295254Sksewell@umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 305254Sksewell@umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 312207SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 322207SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 3311793Sbrandon.potter@amd.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 3411793Sbrandon.potter@amd.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 352474SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 368229Snate@binkert.org# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 372454SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3812334Sgabeblack@google.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 392680Sktlim@umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 408232Snate@binkert.org# 416650Sksewell@umich.edu# Authors: Steve Reinhardt 4212431Sgabeblack@google.com 4311854Sbrandon.potter@amd.comimport sys 446650Sksewell@umich.eduimport os 456650Sksewell@umich.eduimport re 4611800Sbrandon.potter@amd.com 472474SN/Afrom gem5_scons import Transform 482207SN/A 492447SN/AImport('*') 502474SN/A 512447SN/A################################################################# 5212431Sgabeblack@google.com# 5312432Sgabeblack@google.com# ISA "switch header" generation. 5412432Sgabeblack@google.com# 552474SN/A# Auto-generate arch headers that include the right ISA-specific 5612431Sgabeblack@google.com# header based on the setting of THE_ISA preprocessor variable. 572686Sksewell@umich.edu# 582686Sksewell@umich.edu################################################################# 5911905SBrandon.Potter@amd.com 6011905SBrandon.Potter@amd.comenv.SwitchingHeaders( 6111905SBrandon.Potter@amd.com Split(''' 622474SN/A decoder.hh 632474SN/A interrupts.hh 6411905SBrandon.Potter@amd.com isa.hh 652474SN/A isa_traits.hh 662686Sksewell@umich.edu kernel_stats.hh 6711905SBrandon.Potter@amd.com locked_mem.hh 6811905SBrandon.Potter@amd.com microcode_rom.hh 6911905SBrandon.Potter@amd.com mmapped_ipr.hh 702686Sksewell@umich.edu mt.hh 716811SMatt DeVuyst process.hh 7211905SBrandon.Potter@amd.com pseudo_inst.hh 7311905SBrandon.Potter@amd.com registers.hh 7411905SBrandon.Potter@amd.com remote_gdb.hh 7511905SBrandon.Potter@amd.com stacktrace.hh 762474SN/A types.hh 772474SN/A utility.hh 782474SN/A vtophys.hh 7911851Sbrandon.potter@amd.com '''), 802474SN/A env.subst('${TARGET_ISA}')) 8111851Sbrandon.potter@amd.com 826650Sksewell@umich.eduif env['BUILD_GPU']: 8310318Sandreas.hansson@arm.com env.SwitchingHeaders( 842474SN/A Split(''' 855958Sgblack@eecs.umich.edu gpu_decoder.hh 866811SMatt DeVuyst gpu_isa.hh 876650Sksewell@umich.edu gpu_types.hh 8811851Sbrandon.potter@amd.com '''), 896650Sksewell@umich.edu env.subst('${TARGET_GPU_ISA}')) 906811SMatt DeVuyst 916811SMatt DeVuyst################################################################# 9211389Sbrandon.potter@amd.com# 9311389Sbrandon.potter@amd.com# Include architecture-specific files. 9411389Sbrandon.potter@amd.com# 956650Sksewell@umich.edu################################################################# 966650Sksewell@umich.edu 976650Sksewell@umich.edu# 986811SMatt DeVuyst# Build a SCons scanner for ISA files 996811SMatt DeVuyst# 1006811SMatt DeVuystimport SCons.Scanner 1016811SMatt DeVuystimport SCons.Tool 1026811SMatt DeVuyst 1036811SMatt DeVuystscanner = SCons.Scanner.Classic("ISAScan", 1046811SMatt DeVuyst [".isa", ".ISA"], 10510318Sandreas.hansson@arm.com "SRCDIR", 1066811SMatt DeVuyst r'^\s*##include\s+"([\w/.-]*)"') 1076811SMatt DeVuyst 1086811SMatt DeVuystenv.Append(SCANNERS=scanner) 1096811SMatt DeVuyst 1106811SMatt DeVuyst# Tell scons that when it sees a cc.inc file, it should scan it for includes. 1116811SMatt DeVuystSCons.Tool.SourceFileScanner.add_scanner('.cc.inc', SCons.Tool.CScanner) 1126811SMatt DeVuyst 1136811SMatt DeVuyst# 1146811SMatt DeVuyst# Now create a Builder object that uses isa_parser.py to generate C++ 1156811SMatt DeVuyst# output from the ISA description (*.isa) files. 1166811SMatt DeVuyst# 11711389Sbrandon.potter@amd.com 11811389Sbrandon.potter@amd.comparser_py = File('isa_parser.py') 11911389Sbrandon.potter@amd.commicro_asm_py = File('micro_asm.py') 12011389Sbrandon.potter@amd.com 1216811SMatt DeVuyst# import ply here because SCons screws with sys.path when performing actions. 1226811SMatt DeVuystimport ply 1236811SMatt DeVuyst 1246811SMatt DeVuystdef run_parser(target, source, env): 1256811SMatt DeVuyst # Add the current directory to the system path so we can import files. 1266811SMatt DeVuyst sys.path[0:0] = [ parser_py.dir.abspath ] 1276811SMatt DeVuyst import isa_parser 1286811SMatt DeVuyst 1296811SMatt DeVuyst parser = isa_parser.ISAParser(target[0].dir.abspath) 1306811SMatt DeVuyst parser.parse_isa_desc(source[0].abspath) 1316650Sksewell@umich.edu 1326650Sksewell@umich.edudesc_action = MakeAction(run_parser, Transform("ISA DESC", 1)) 1336811SMatt DeVuyst 1346811SMatt DeVuystIsaDescBuilder = Builder(action=desc_action) 1356650Sksewell@umich.edu 1366650Sksewell@umich.edu 1376650Sksewell@umich.edu# ISAs should use this function to set up an IsaDescBuilder and not try to 1386650Sksewell@umich.edu# set one up manually. 1396650Sksewell@umich.edudef ISADesc(desc, decoder_splits=1, exec_splits=1): 1406650Sksewell@umich.edu '''Set up a builder for an ISA description. 1416650Sksewell@umich.edu 1426650Sksewell@umich.edu The decoder_splits and exec_splits parameters let us determine what 1436650Sksewell@umich.edu files the isa parser is actually going to generate. This needs to match 1446650Sksewell@umich.edu what files are actually generated, and there's no specific check for that 1456811SMatt DeVuyst right now. 1466811SMatt DeVuyst 1476811SMatt DeVuyst If the parser itself is responsible for generating a list of its products 1486811SMatt DeVuyst and their dependencies, then using that output to set up the right 1496811SMatt DeVuyst dependencies. This is what we used to do. The problem is that scons 1506650Sksewell@umich.edu fundamentally doesn't support using a build product to affect its graph 1516650Sksewell@umich.edu of possible products, dependencies, builders, etc. There are a couple ways 15211905SBrandon.Potter@amd.com to work around that limitation. 1536650Sksewell@umich.edu 15411905SBrandon.Potter@amd.com One option is to compute dependencies while the build phase of scons is 15511905SBrandon.Potter@amd.com running. That method can be quite complicated and cumbersome, because we 1566650Sksewell@umich.edu have to make sure our modifications are made before scons tries to 15711905SBrandon.Potter@amd.com consume them. There's also no guarantee that this mechanism will work since 15811905SBrandon.Potter@amd.com it subverts scons expectations and changes things behind its back. This 1596650Sksewell@umich.edu was implemented previously and constrained the builds parallelism 16011905SBrandon.Potter@amd.com significantly. 16111905SBrandon.Potter@amd.com 1626811SMatt DeVuyst Another option would be to recursively call scons to have it update the 1636811SMatt DeVuyst list of products/dependencies during the setup phase of this invocation of 1646811SMatt DeVuyst scons. The problem with that is that it would be very difficult to make 1656811SMatt DeVuyst the sub-invocation of scons observe the options passed to the primary one 1666650Sksewell@umich.edu in all possible cases, or to even determine conclusively what the name of 1676650Sksewell@umich.edu the scons executable is in the first place. 1686811SMatt DeVuyst 1696650Sksewell@umich.edu Possible future changes to the isa parser might make it easier to 1706811SMatt DeVuyst determine what files it would generate, perhaps because there was a more 1716650Sksewell@umich.edu direct correspondence between input files and output files. Or, if the 17211905SBrandon.Potter@amd.com parser could run quickly and determine what its output files would be 1736650Sksewell@umich.edu without having do actually generate those files, then it could be run 1746650Sksewell@umich.edu unconditionally without slowing down all builds or touching the output 1756650Sksewell@umich.edu files unnecessarily. 1766650Sksewell@umich.edu ''' 1776650Sksewell@umich.edu generated_dir = File(desc).dir.up().Dir('generated') 1786811SMatt DeVuyst def gen_file(name): 1796811SMatt DeVuyst return generated_dir.File(name) 1808852Sandreas.hansson@arm.com 1816811SMatt DeVuyst gen = [] 1828852Sandreas.hansson@arm.com def add_gen(name): 1836811SMatt DeVuyst gen.append(gen_file(name)) 1846811SMatt DeVuyst 1856811SMatt DeVuyst # Tell scons about the various files the ISA parser will generate. 1866811SMatt DeVuyst add_gen('decoder-g.cc.inc') 1876811SMatt DeVuyst add_gen('decoder-ns.cc.inc') 1886811SMatt DeVuyst add_gen('decode-method.cc.inc') 1896811SMatt DeVuyst 1908852Sandreas.hansson@arm.com add_gen('decoder.hh') 1916811SMatt DeVuyst add_gen('decoder-g.hh.inc') 1926811SMatt DeVuyst add_gen('decoder-ns.hh.inc') 1936650Sksewell@umich.edu 1946650Sksewell@umich.edu add_gen('exec-g.cc.inc') 1956650Sksewell@umich.edu add_gen('exec-ns.cc.inc') 1966650Sksewell@umich.edu 19711905SBrandon.Potter@amd.com add_gen('max_inst_regs.hh') 1986650Sksewell@umich.edu 19911389Sbrandon.potter@amd.com 2006650Sksewell@umich.edu # These generated files are also top level sources. 2016650Sksewell@umich.edu def source_gen(name): 2026650Sksewell@umich.edu add_gen(name) 2035958Sgblack@eecs.umich.edu Source(gen_file(name)) 20411851Sbrandon.potter@amd.com 2055958Sgblack@eecs.umich.edu source_gen('decoder.cc') 2065958Sgblack@eecs.umich.edu 2076701Sgblack@eecs.umich.edu if decoder_splits == 1: 2085958Sgblack@eecs.umich.edu source_gen('inst-constrs.cc') 2095958Sgblack@eecs.umich.edu else: 2105958Sgblack@eecs.umich.edu for i in range(1, decoder_splits + 1): 21111851Sbrandon.potter@amd.com source_gen('inst-constrs-%d.cc' % i) 2125958Sgblack@eecs.umich.edu 2135958Sgblack@eecs.umich.edu if exec_splits == 1: 2145958Sgblack@eecs.umich.edu source_gen('generic_cpu_exec.cc') 2155958Sgblack@eecs.umich.edu else: 2165958Sgblack@eecs.umich.edu for i in range(1, exec_splits + 1): 2175958Sgblack@eecs.umich.edu source_gen('generic_cpu_exec_%d.cc' % i) 21811851Sbrandon.potter@amd.com 2195958Sgblack@eecs.umich.edu # Actually create the builder. 22010223Ssteve.reinhardt@amd.com sources = [desc, parser_py, micro_asm_py] 2215958Sgblack@eecs.umich.edu IsaDescBuilder(target=gen, source=sources, env=env) 2225958Sgblack@eecs.umich.edu return gen 22310223Ssteve.reinhardt@amd.com 2245958Sgblack@eecs.umich.eduExport('ISADesc') 2255958Sgblack@eecs.umich.edu 2265958Sgblack@eecs.umich.eduDebugFlag('IntRegs') 22710223Ssteve.reinhardt@amd.comDebugFlag('FloatRegs') 2285958Sgblack@eecs.umich.eduDebugFlag('VecRegs') 2295958Sgblack@eecs.umich.eduDebugFlag('CCRegs') 230DebugFlag('MiscRegs') 231CompoundFlag('Registers', [ 'IntRegs', 'FloatRegs', 'CCRegs', 'MiscRegs' ]) 232