SConscript revision 12222
12139SN/A# -*- mode:python -*- 22139SN/A 312109SRekai.GonzalezAlberquilla@arm.com# Copyright (c) 2016 ARM Limited 412109SRekai.GonzalezAlberquilla@arm.com# All rights reserved. 512109SRekai.GonzalezAlberquilla@arm.com# 612109SRekai.GonzalezAlberquilla@arm.com# The license below extends only to copyright in the software and shall 712109SRekai.GonzalezAlberquilla@arm.com# not be construed as granting a license to any other intellectual 812109SRekai.GonzalezAlberquilla@arm.com# property including but not limited to intellectual property relating 912109SRekai.GonzalezAlberquilla@arm.com# to a hardware implementation of the functionality of the software 1012109SRekai.GonzalezAlberquilla@arm.com# licensed hereunder. You may use the software subject to the license 1112109SRekai.GonzalezAlberquilla@arm.com# terms below provided that you ensure that this notice is replicated 1212109SRekai.GonzalezAlberquilla@arm.com# unmodified and in its entirety in all distributions of the software, 1312109SRekai.GonzalezAlberquilla@arm.com# modified or unmodified, in source code or in binary form. 1412109SRekai.GonzalezAlberquilla@arm.com# 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. 282139SN/A# 292139SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 302139SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 312139SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 322139SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 332139SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 342139SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 352139SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 362139SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 372139SN/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. 402665Ssaidi@eecs.umich.edu# 412665Ssaidi@eecs.umich.edu# Authors: Steve Reinhardt 422139SN/A 434202Sbinkertn@umich.eduimport sys 448961Sgblack@eecs.umich.eduimport os 4510196SCurtis.Dunham@arm.comimport re 462139SN/A 474202Sbinkertn@umich.eduImport('*') 482152SN/A 492152SN/A################################################################# 502139SN/A# 512139SN/A# ISA "switch header" generation. 522139SN/A# 532139SN/A# Auto-generate arch headers that include the right ISA-specific 542139SN/A# header based on the setting of THE_ISA preprocessor variable. 552152SN/A# 562152SN/A################################################################# 572139SN/A 5812015Sgabeblack@google.comenv.SwitchingHeaders( 5912015Sgabeblack@google.com Split(''' 609020Sgblack@eecs.umich.edu decoder.hh 614781Snate@binkert.org interrupts.hh 627799Sgblack@eecs.umich.edu isa.hh 634781Snate@binkert.org isa_traits.hh 644781Snate@binkert.org kernel_stats.hh 653170Sstever@eecs.umich.edu locked_mem.hh 665664Sgblack@eecs.umich.edu microcode_rom.hh 678105Sgblack@eecs.umich.edu mmapped_ipr.hh 686179Sksewell@umich.edu mt.hh 694781Snate@binkert.org process.hh 7010553Salexandru.dutu@amd.com pseudo_inst.hh 716329Sgblack@eecs.umich.edu registers.hh 724781Snate@binkert.org remote_gdb.hh 734781Snate@binkert.org stacktrace.hh 744781Snate@binkert.org tlb.hh 754781Snate@binkert.org types.hh 764781Snate@binkert.org utility.hh 774781Snate@binkert.org vtophys.hh 7812015Sgabeblack@google.com '''), 7912015Sgabeblack@google.com env.subst('${TARGET_ISA}')) 802152SN/A 8111308Santhony.gutierrez@amd.comif env['BUILD_GPU']: 8212016Sgabeblack@google.com env.SwitchingHeaders( 8312016Sgabeblack@google.com Split(''' 8411308Santhony.gutierrez@amd.com gpu_decoder.hh 8511696Santhony.gutierrez@amd.com gpu_isa.hh 8611308Santhony.gutierrez@amd.com gpu_types.hh 8712016Sgabeblack@google.com '''), 8812016Sgabeblack@google.com env.subst('${TARGET_GPU_ISA}')) 8911308Santhony.gutierrez@amd.com 902152SN/A################################################################# 912152SN/A# 922152SN/A# Include architecture-specific files. 932152SN/A# 942152SN/A################################################################# 952152SN/A 962152SN/A# 972152SN/A# Build a SCons scanner for ISA files 982152SN/A# 992152SN/Aimport SCons.Scanner 10012222Sgabeblack@google.comimport SCons.Tool 1012152SN/A 10212222Sgabeblack@google.comscanner = SCons.Scanner.Classic("ISAScan", 10312222Sgabeblack@google.com [".isa", ".ISA"], 10412222Sgabeblack@google.com "SRCDIR", 10512222Sgabeblack@google.com r'^\s*##include\s+"([\w/.-]*)"') 1062152SN/A 10712222Sgabeblack@google.comenv.Append(SCANNERS=scanner) 10812222Sgabeblack@google.com 10912222Sgabeblack@google.com# Tell scons that when it sees a cc.inc file, it should scan it for includes. 11012222Sgabeblack@google.comSCons.Tool.SourceFileScanner.add_scanner('.cc.inc', SCons.Tool.CScanner) 1112152SN/A 1122152SN/A# 1132152SN/A# Now create a Builder object that uses isa_parser.py to generate C++ 1142152SN/A# output from the ISA description (*.isa) files. 1152152SN/A# 1162152SN/A 11712222Sgabeblack@google.comparser_py = File('isa_parser.py') 11812222Sgabeblack@google.commicro_asm_py = File('micro_asm.py') 1196993Snate@binkert.org 1206998Snate@binkert.org# import ply here because SCons screws with sys.path when performing actions. 1216998Snate@binkert.orgimport ply 1226998Snate@binkert.org 12312222Sgabeblack@google.comdef run_parser(target, source, env): 12412222Sgabeblack@google.com # Add the current directory to the system path so we can import files. 12512222Sgabeblack@google.com sys.path[0:0] = [ parser_py.dir.abspath ] 1266993Snate@binkert.org import isa_parser 1276993Snate@binkert.org 12810319SAndreas.Sandberg@ARM.com parser = isa_parser.ISAParser(target[0].dir.abspath) 1296993Snate@binkert.org parser.parse_isa_desc(source[0].abspath) 1302152SN/A 13112222Sgabeblack@google.comdesc_action = MakeAction(run_parser, Transform("ISA DESC", 1)) 1322152SN/A 13312222Sgabeblack@google.comIsaDescBuilder = Builder(action=desc_action) 1345944Sgblack@eecs.umich.edu 13510196SCurtis.Dunham@arm.com 13612222Sgabeblack@google.com# ISAs should use this function to set up an IsaDescBuilder and not try to 13712222Sgabeblack@google.com# set one up manually. 13812222Sgabeblack@google.comdef ISADesc(desc, decoder_splits=1, exec_splits=1): 13912222Sgabeblack@google.com '''Set up a builder for an ISA description. 14010196SCurtis.Dunham@arm.com 14112222Sgabeblack@google.com The decoder_splits and exec_splits parameters let us determine what 14212222Sgabeblack@google.com files the isa parser is actually going to generate. This needs to match 14312222Sgabeblack@google.com what files are actually generated, and there's no specific check for that 14412222Sgabeblack@google.com right now. 14510196SCurtis.Dunham@arm.com 14612222Sgabeblack@google.com If the parser itself is responsible for generating a list of its products 14712222Sgabeblack@google.com and their dependencies, then using that output to set up the right 14812222Sgabeblack@google.com dependencies. This is what we used to do. The problem is that scons 14912222Sgabeblack@google.com fundamentally doesn't support using a build product to affect its graph 15012222Sgabeblack@google.com of possible products, dependencies, builders, etc. There are a couple ways 15112222Sgabeblack@google.com to work around that limitation. 15210196SCurtis.Dunham@arm.com 15312222Sgabeblack@google.com One option is to compute dependencies while the build phase of scons is 15412222Sgabeblack@google.com running. That method can be quite complicated and cumbersome, because we 15512222Sgabeblack@google.com have to make sure our modifications are made before scons tries to 15612222Sgabeblack@google.com consume them. There's also no guarantee that this mechanism will work since 15712222Sgabeblack@google.com it subverts scons expectations and changes things behind its back. This 15812222Sgabeblack@google.com was implemented previously and constrained the builds parallelism 15912222Sgabeblack@google.com significantly. 16010196SCurtis.Dunham@arm.com 16112222Sgabeblack@google.com Another option would be to recursively call scons to have it update the 16212222Sgabeblack@google.com list of products/dependencies during the setup phase of this invocation of 16312222Sgabeblack@google.com scons. The problem with that is that it would be very difficult to make 16412222Sgabeblack@google.com the sub-invocation of scons observe the options passed to the primary one 16512222Sgabeblack@google.com in all possible cases, or to even determine conclusively what the name of 16612222Sgabeblack@google.com the scons executable is in the first place. 16710196SCurtis.Dunham@arm.com 16812222Sgabeblack@google.com Possible future changes to the isa parser might make it easier to 16912222Sgabeblack@google.com determine what files it would generate, perhaps because there was a more 17012222Sgabeblack@google.com direct correspondence between input files and output files. Or, if the 17112222Sgabeblack@google.com parser could run quickly and determine what its output files would be 17212222Sgabeblack@google.com without having do actually generate those files, then it could be run 17312222Sgabeblack@google.com unconditionally without slowing down all builds or touching the output 17412222Sgabeblack@google.com files unnecessarily. 17512222Sgabeblack@google.com ''' 17612222Sgabeblack@google.com generated_dir = File(desc).dir.up().Dir('generated') 17712222Sgabeblack@google.com def gen_file(name): 17812222Sgabeblack@google.com return generated_dir.File(name) 17910196SCurtis.Dunham@arm.com 18012222Sgabeblack@google.com gen = [] 18112222Sgabeblack@google.com def add_gen(name): 18212222Sgabeblack@google.com gen.append(gen_file(name)) 18312222Sgabeblack@google.com 18412222Sgabeblack@google.com # Tell scons about the various files the ISA parser will generate. 18512222Sgabeblack@google.com add_gen('decoder-g.cc.inc') 18612222Sgabeblack@google.com add_gen('decoder-ns.cc.inc') 18712222Sgabeblack@google.com add_gen('decode-method.cc.inc') 18812222Sgabeblack@google.com 18912222Sgabeblack@google.com add_gen('decoder.hh') 19012222Sgabeblack@google.com add_gen('decoder-g.hh.inc') 19112222Sgabeblack@google.com add_gen('decoder-ns.hh.inc') 19212222Sgabeblack@google.com 19312222Sgabeblack@google.com add_gen('exec-g.cc.inc') 19412222Sgabeblack@google.com add_gen('exec-ns.cc.inc') 19512222Sgabeblack@google.com 19612222Sgabeblack@google.com add_gen('max_inst_regs.hh') 19712222Sgabeblack@google.com 19812222Sgabeblack@google.com 19912222Sgabeblack@google.com # These generated files are also top level sources. 20012222Sgabeblack@google.com def source_gen(name): 20112222Sgabeblack@google.com add_gen(name) 20212222Sgabeblack@google.com Source(gen_file(name)) 20312222Sgabeblack@google.com 20412222Sgabeblack@google.com source_gen('decoder.cc') 20512222Sgabeblack@google.com 20612222Sgabeblack@google.com if decoder_splits == 1: 20712222Sgabeblack@google.com source_gen('inst-constrs.cc') 20812222Sgabeblack@google.com else: 20912222Sgabeblack@google.com for i in range(1, decoder_splits + 1): 21012222Sgabeblack@google.com source_gen('inst-constrs-%d.cc' % i) 21112222Sgabeblack@google.com 21212222Sgabeblack@google.com if exec_splits == 1: 21312222Sgabeblack@google.com source_gen('generic_cpu_exec.cc') 21412222Sgabeblack@google.com else: 21512222Sgabeblack@google.com for i in range(1, exec_splits + 1): 21612222Sgabeblack@google.com source_gen('generic_cpu_exec_%d.cc' % i) 21712222Sgabeblack@google.com 21812222Sgabeblack@google.com # Actually create the builder. 21912222Sgabeblack@google.com sources = [desc, parser_py, micro_asm_py] 22012222Sgabeblack@google.com IsaDescBuilder(target=gen, source=sources, env=env) 22112222Sgabeblack@google.com return gen 22212222Sgabeblack@google.com 22312222Sgabeblack@google.comExport('ISADesc') 22410196SCurtis.Dunham@arm.com 2258335Snate@binkert.orgDebugFlag('IntRegs') 2268335Snate@binkert.orgDebugFlag('FloatRegs') 22712109SRekai.GonzalezAlberquilla@arm.comDebugFlag('VecRegs') 2289920Syasuko.eckert@amd.comDebugFlag('CCRegs') 2298335Snate@binkert.orgDebugFlag('MiscRegs') 23010935Snilay@cs.wisc.eduCompoundFlag('Registers', [ 'IntRegs', 'FloatRegs', 'CCRegs', 'MiscRegs' ]) 231