SConscript revision 13610
12139SN/A# -*- mode:python -*-
22139SN/A
313610Sgiacomo.gabrielli@arm.com# Copyright (c) 2016-2017 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
4712246Sgabeblack@google.comfrom gem5_scons import Transform
4812246Sgabeblack@google.com
494202Sbinkertn@umich.eduImport('*')
502152SN/A
512152SN/A#################################################################
522139SN/A#
532139SN/A# ISA "switch header" generation.
542139SN/A#
552139SN/A# Auto-generate arch headers that include the right ISA-specific
562139SN/A# header based on the setting of THE_ISA preprocessor variable.
572152SN/A#
582152SN/A#################################################################
592139SN/A
6012015Sgabeblack@google.comenv.SwitchingHeaders(
6112015Sgabeblack@google.com    Split('''
629020Sgblack@eecs.umich.edu        decoder.hh
634781Snate@binkert.org        interrupts.hh
647799Sgblack@eecs.umich.edu        isa.hh
654781Snate@binkert.org        isa_traits.hh
664781Snate@binkert.org        kernel_stats.hh
673170Sstever@eecs.umich.edu        locked_mem.hh
685664Sgblack@eecs.umich.edu        microcode_rom.hh
698105Sgblack@eecs.umich.edu        mmapped_ipr.hh
706179Sksewell@umich.edu        mt.hh
714781Snate@binkert.org        process.hh
7210553Salexandru.dutu@amd.com        pseudo_inst.hh
736329Sgblack@eecs.umich.edu        registers.hh
744781Snate@binkert.org        remote_gdb.hh
754781Snate@binkert.org        stacktrace.hh
764781Snate@binkert.org        types.hh
774781Snate@binkert.org        utility.hh
784781Snate@binkert.org        vtophys.hh
7912015Sgabeblack@google.com        '''),
8012015Sgabeblack@google.com    env.subst('${TARGET_ISA}'))
812152SN/A
8211308Santhony.gutierrez@amd.comif env['BUILD_GPU']:
8312016Sgabeblack@google.com    env.SwitchingHeaders(
8412016Sgabeblack@google.com        Split('''
8511308Santhony.gutierrez@amd.com            gpu_decoder.hh
8611696Santhony.gutierrez@amd.com            gpu_isa.hh
8711308Santhony.gutierrez@amd.com            gpu_types.hh
8812016Sgabeblack@google.com            '''),
8912016Sgabeblack@google.com        env.subst('${TARGET_GPU_ISA}'))
9011308Santhony.gutierrez@amd.com
912152SN/A#################################################################
922152SN/A#
932152SN/A# Include architecture-specific files.
942152SN/A#
952152SN/A#################################################################
962152SN/A
972152SN/A#
982152SN/A# Build a SCons scanner for ISA files
992152SN/A#
1002152SN/Aimport SCons.Scanner
10112222Sgabeblack@google.comimport SCons.Tool
1022152SN/A
10312222Sgabeblack@google.comscanner = SCons.Scanner.Classic("ISAScan",
10412222Sgabeblack@google.com                                [".isa", ".ISA"],
10512222Sgabeblack@google.com                                 "SRCDIR",
10612222Sgabeblack@google.com                                r'^\s*##include\s+"([\w/.-]*)"')
1072152SN/A
10812222Sgabeblack@google.comenv.Append(SCANNERS=scanner)
10912222Sgabeblack@google.com
11012222Sgabeblack@google.com# Tell scons that when it sees a cc.inc file, it should scan it for includes.
11112222Sgabeblack@google.comSCons.Tool.SourceFileScanner.add_scanner('.cc.inc', SCons.Tool.CScanner)
1122152SN/A
1132152SN/A#
1142152SN/A# Now create a Builder object that uses isa_parser.py to generate C++
1152152SN/A# output from the ISA description (*.isa) files.
1162152SN/A#
1172152SN/A
11812222Sgabeblack@google.comparser_py = File('isa_parser.py')
11912222Sgabeblack@google.commicro_asm_py = File('micro_asm.py')
1206993Snate@binkert.org
1216998Snate@binkert.org# import ply here because SCons screws with sys.path when performing actions.
1226998Snate@binkert.orgimport ply
1236998Snate@binkert.org
12412222Sgabeblack@google.comdef run_parser(target, source, env):
12512222Sgabeblack@google.com    # Add the current directory to the system path so we can import files.
12612222Sgabeblack@google.com    sys.path[0:0] = [ parser_py.dir.abspath ]
1276993Snate@binkert.org    import isa_parser
1286993Snate@binkert.org
12910319SAndreas.Sandberg@ARM.com    parser = isa_parser.ISAParser(target[0].dir.abspath)
1306993Snate@binkert.org    parser.parse_isa_desc(source[0].abspath)
1312152SN/A
13212222Sgabeblack@google.comdesc_action = MakeAction(run_parser, Transform("ISA DESC", 1))
1332152SN/A
13412222Sgabeblack@google.comIsaDescBuilder = Builder(action=desc_action)
1355944Sgblack@eecs.umich.edu
13610196SCurtis.Dunham@arm.com
13712222Sgabeblack@google.com# ISAs should use this function to set up an IsaDescBuilder and not try to
13812222Sgabeblack@google.com# set one up manually.
13912222Sgabeblack@google.comdef ISADesc(desc, decoder_splits=1, exec_splits=1):
14012222Sgabeblack@google.com    '''Set up a builder for an ISA description.
14110196SCurtis.Dunham@arm.com
14212222Sgabeblack@google.com    The decoder_splits and exec_splits parameters let us determine what
14312222Sgabeblack@google.com    files the isa parser is actually going to generate. This needs to match
14412222Sgabeblack@google.com    what files are actually generated, and there's no specific check for that
14512222Sgabeblack@google.com    right now.
14610196SCurtis.Dunham@arm.com
14712222Sgabeblack@google.com    If the parser itself is responsible for generating a list of its products
14812222Sgabeblack@google.com    and their dependencies, then using that output to set up the right
14912222Sgabeblack@google.com    dependencies. This is what we used to do. The problem is that scons
15012222Sgabeblack@google.com    fundamentally doesn't support using a build product to affect its graph
15112222Sgabeblack@google.com    of possible products, dependencies, builders, etc. There are a couple ways
15212222Sgabeblack@google.com    to work around that limitation.
15310196SCurtis.Dunham@arm.com
15412222Sgabeblack@google.com    One option is to compute dependencies while the build phase of scons is
15512222Sgabeblack@google.com    running. That method can be quite complicated and cumbersome, because we
15612222Sgabeblack@google.com    have to make sure our modifications are made before scons tries to
15712222Sgabeblack@google.com    consume them. There's also no guarantee that this mechanism will work since
15812222Sgabeblack@google.com    it subverts scons expectations and changes things behind its back. This
15912222Sgabeblack@google.com    was implemented previously and constrained the builds parallelism
16012222Sgabeblack@google.com    significantly.
16110196SCurtis.Dunham@arm.com
16212222Sgabeblack@google.com    Another option would be to recursively call scons to have it update the
16312222Sgabeblack@google.com    list of products/dependencies during the setup phase of this invocation of
16412222Sgabeblack@google.com    scons. The problem with that is that it would be very difficult to make
16512222Sgabeblack@google.com    the sub-invocation of scons observe the options passed to the primary one
16612222Sgabeblack@google.com    in all possible cases, or to even determine conclusively what the name of
16712222Sgabeblack@google.com    the scons executable is in the first place.
16810196SCurtis.Dunham@arm.com
16912222Sgabeblack@google.com    Possible future changes to the isa parser might make it easier to
17012222Sgabeblack@google.com    determine what files it would generate, perhaps because there was a more
17112222Sgabeblack@google.com    direct correspondence between input files and output files. Or, if the
17212222Sgabeblack@google.com    parser could run quickly and determine what its output files would be
17312222Sgabeblack@google.com    without having do actually generate those files, then it could be run
17412222Sgabeblack@google.com    unconditionally without slowing down all builds or touching the output
17512222Sgabeblack@google.com    files unnecessarily.
17612222Sgabeblack@google.com    '''
17712222Sgabeblack@google.com    generated_dir = File(desc).dir.up().Dir('generated')
17812222Sgabeblack@google.com    def gen_file(name):
17912222Sgabeblack@google.com        return generated_dir.File(name)
18010196SCurtis.Dunham@arm.com
18112222Sgabeblack@google.com    gen = []
18212222Sgabeblack@google.com    def add_gen(name):
18312222Sgabeblack@google.com        gen.append(gen_file(name))
18412222Sgabeblack@google.com
18512222Sgabeblack@google.com    # Tell scons about the various files the ISA parser will generate.
18612222Sgabeblack@google.com    add_gen('decoder-g.cc.inc')
18712222Sgabeblack@google.com    add_gen('decoder-ns.cc.inc')
18812222Sgabeblack@google.com    add_gen('decode-method.cc.inc')
18912222Sgabeblack@google.com
19012222Sgabeblack@google.com    add_gen('decoder.hh')
19112222Sgabeblack@google.com    add_gen('decoder-g.hh.inc')
19212222Sgabeblack@google.com    add_gen('decoder-ns.hh.inc')
19312222Sgabeblack@google.com
19412222Sgabeblack@google.com    add_gen('exec-g.cc.inc')
19512222Sgabeblack@google.com    add_gen('exec-ns.cc.inc')
19612222Sgabeblack@google.com
19712222Sgabeblack@google.com    add_gen('max_inst_regs.hh')
19812222Sgabeblack@google.com
19912222Sgabeblack@google.com
20012222Sgabeblack@google.com    # These generated files are also top level sources.
20112222Sgabeblack@google.com    def source_gen(name):
20212222Sgabeblack@google.com        add_gen(name)
20312222Sgabeblack@google.com        Source(gen_file(name))
20412222Sgabeblack@google.com
20512222Sgabeblack@google.com    source_gen('decoder.cc')
20612222Sgabeblack@google.com
20712222Sgabeblack@google.com    if decoder_splits == 1:
20812222Sgabeblack@google.com        source_gen('inst-constrs.cc')
20912222Sgabeblack@google.com    else:
21012222Sgabeblack@google.com        for i in range(1, decoder_splits + 1):
21112222Sgabeblack@google.com            source_gen('inst-constrs-%d.cc' % i)
21212222Sgabeblack@google.com
21312222Sgabeblack@google.com    if exec_splits == 1:
21412222Sgabeblack@google.com        source_gen('generic_cpu_exec.cc')
21512222Sgabeblack@google.com    else:
21612222Sgabeblack@google.com        for i in range(1, exec_splits + 1):
21712222Sgabeblack@google.com            source_gen('generic_cpu_exec_%d.cc' % i)
21812222Sgabeblack@google.com
21912222Sgabeblack@google.com    # Actually create the builder.
22012222Sgabeblack@google.com    sources = [desc, parser_py, micro_asm_py]
22112222Sgabeblack@google.com    IsaDescBuilder(target=gen, source=sources, env=env)
22212222Sgabeblack@google.com    return gen
22312222Sgabeblack@google.com
22412222Sgabeblack@google.comExport('ISADesc')
22510196SCurtis.Dunham@arm.com
2268335Snate@binkert.orgDebugFlag('IntRegs')
2278335Snate@binkert.orgDebugFlag('FloatRegs')
22812109SRekai.GonzalezAlberquilla@arm.comDebugFlag('VecRegs')
22913610Sgiacomo.gabrielli@arm.comDebugFlag('VecPredRegs')
2309920Syasuko.eckert@amd.comDebugFlag('CCRegs')
2318335Snate@binkert.orgDebugFlag('MiscRegs')
23213610Sgiacomo.gabrielli@arm.comCompoundFlag('Registers', [ 'IntRegs', 'FloatRegs', 'VecRegs', 'VecPredRegs',
23313610Sgiacomo.gabrielli@arm.com                            'CCRegs', 'MiscRegs' ])
234