SConscript revision 13610
113206Sgabeblack@google.com# -*- mode:python -*-
213206Sgabeblack@google.com
313206Sgabeblack@google.com# Copyright (c) 2016-2017 ARM Limited
413206Sgabeblack@google.com# All rights reserved.
513206Sgabeblack@google.com#
613206Sgabeblack@google.com# The license below extends only to copyright in the software and shall
713206Sgabeblack@google.com# not be construed as granting a license to any other intellectual
813206Sgabeblack@google.com# property including but not limited to intellectual property relating
913206Sgabeblack@google.com# to a hardware implementation of the functionality of the software
1013206Sgabeblack@google.com# licensed hereunder.  You may use the software subject to the license
1113206Sgabeblack@google.com# terms below provided that you ensure that this notice is replicated
1213206Sgabeblack@google.com# unmodified and in its entirety in all distributions of the software,
1313206Sgabeblack@google.com# modified or unmodified, in source code or in binary form.
1413206Sgabeblack@google.com#
1513206Sgabeblack@google.com# Copyright (c) 2006 The Regents of The University of Michigan
1613206Sgabeblack@google.com# All rights reserved.
1713206Sgabeblack@google.com#
1813206Sgabeblack@google.com# Redistribution and use in source and binary forms, with or without
1913206Sgabeblack@google.com# modification, are permitted provided that the following conditions are
2013206Sgabeblack@google.com# met: redistributions of source code must retain the above copyright
2113206Sgabeblack@google.com# notice, this list of conditions and the following disclaimer;
2213206Sgabeblack@google.com# redistributions in binary form must reproduce the above copyright
2313206Sgabeblack@google.com# notice, this list of conditions and the following disclaimer in the
2413206Sgabeblack@google.com# documentation and/or other materials provided with the distribution;
2513206Sgabeblack@google.com# neither the name of the copyright holders nor the names of its
2613206Sgabeblack@google.com# contributors may be used to endorse or promote products derived from
2713206Sgabeblack@google.com# this software without specific prior written permission.
2813206Sgabeblack@google.com#
2913206Sgabeblack@google.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3013206Sgabeblack@google.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3113206Sgabeblack@google.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
3213288Sgabeblack@google.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3313206Sgabeblack@google.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3413207Sgabeblack@google.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3513208Sgabeblack@google.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3613206Sgabeblack@google.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3713260Sgabeblack@google.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3813260Sgabeblack@google.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3913260Sgabeblack@google.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4013317Sgabeblack@google.com#
4113206Sgabeblack@google.com# Authors: Steve Reinhardt
4213206Sgabeblack@google.com
4313206Sgabeblack@google.comimport sys
4413206Sgabeblack@google.comimport os
4513206Sgabeblack@google.comimport re
4613206Sgabeblack@google.com
4713206Sgabeblack@google.comfrom gem5_scons import Transform
4813207Sgabeblack@google.com
4913207Sgabeblack@google.comImport('*')
5013207Sgabeblack@google.com
5113207Sgabeblack@google.com#################################################################
5213206Sgabeblack@google.com#
5313206Sgabeblack@google.com# ISA "switch header" generation.
5413206Sgabeblack@google.com#
5513206Sgabeblack@google.com# Auto-generate arch headers that include the right ISA-specific
5613206Sgabeblack@google.com# header based on the setting of THE_ISA preprocessor variable.
5713206Sgabeblack@google.com#
5813206Sgabeblack@google.com#################################################################
5913304Sgabeblack@google.com
6013304Sgabeblack@google.comenv.SwitchingHeaders(
6113304Sgabeblack@google.com    Split('''
6213304Sgabeblack@google.com        decoder.hh
6313304Sgabeblack@google.com        interrupts.hh
6413304Sgabeblack@google.com        isa.hh
6513304Sgabeblack@google.com        isa_traits.hh
6613206Sgabeblack@google.com        kernel_stats.hh
6713206Sgabeblack@google.com        locked_mem.hh
6813304Sgabeblack@google.com        microcode_rom.hh
6913304Sgabeblack@google.com        mmapped_ipr.hh
7013304Sgabeblack@google.com        mt.hh
7113317Sgabeblack@google.com        process.hh
7213317Sgabeblack@google.com        pseudo_inst.hh
7313304Sgabeblack@google.com        registers.hh
7413304Sgabeblack@google.com        remote_gdb.hh
7513304Sgabeblack@google.com        stacktrace.hh
7613304Sgabeblack@google.com        types.hh
7713304Sgabeblack@google.com        utility.hh
7813206Sgabeblack@google.com        vtophys.hh
7913206Sgabeblack@google.com        '''),
8013304Sgabeblack@google.com    env.subst('${TARGET_ISA}'))
8113304Sgabeblack@google.com
8213206Sgabeblack@google.comif env['BUILD_GPU']:
8313206Sgabeblack@google.com    env.SwitchingHeaders(
8413208Sgabeblack@google.com        Split('''
8513208Sgabeblack@google.com            gpu_decoder.hh
8613208Sgabeblack@google.com            gpu_isa.hh
8713208Sgabeblack@google.com            gpu_types.hh
8813208Sgabeblack@google.com            '''),
8913208Sgabeblack@google.com        env.subst('${TARGET_GPU_ISA}'))
9013206Sgabeblack@google.com
9113207Sgabeblack@google.com#################################################################
9213207Sgabeblack@google.com#
9313207Sgabeblack@google.com# Include architecture-specific files.
9413207Sgabeblack@google.com#
9513206Sgabeblack@google.com#################################################################
9613206Sgabeblack@google.com
9713206Sgabeblack@google.com#
9813206Sgabeblack@google.com# Build a SCons scanner for ISA files
9913206Sgabeblack@google.com#
10013206Sgabeblack@google.comimport SCons.Scanner
10113206Sgabeblack@google.comimport SCons.Tool
10213206Sgabeblack@google.com
10313206Sgabeblack@google.comscanner = SCons.Scanner.Classic("ISAScan",
10413206Sgabeblack@google.com                                [".isa", ".ISA"],
10513206Sgabeblack@google.com                                 "SRCDIR",
10613206Sgabeblack@google.com                                r'^\s*##include\s+"([\w/.-]*)"')
10713206Sgabeblack@google.com
10813206Sgabeblack@google.comenv.Append(SCANNERS=scanner)
10913206Sgabeblack@google.com
11013206Sgabeblack@google.com# Tell scons that when it sees a cc.inc file, it should scan it for includes.
11113206Sgabeblack@google.comSCons.Tool.SourceFileScanner.add_scanner('.cc.inc', SCons.Tool.CScanner)
11213206Sgabeblack@google.com
11313206Sgabeblack@google.com#
11413206Sgabeblack@google.com# Now create a Builder object that uses isa_parser.py to generate C++
11513206Sgabeblack@google.com# output from the ISA description (*.isa) files.
11613206Sgabeblack@google.com#
11713206Sgabeblack@google.com
11813206Sgabeblack@google.comparser_py = File('isa_parser.py')
11913207Sgabeblack@google.commicro_asm_py = File('micro_asm.py')
12013207Sgabeblack@google.com
12113207Sgabeblack@google.com# import ply here because SCons screws with sys.path when performing actions.
12213207Sgabeblack@google.comimport ply
12313207Sgabeblack@google.com
12413206Sgabeblack@google.comdef run_parser(target, source, env):
12513207Sgabeblack@google.com    # Add the current directory to the system path so we can import files.
12613206Sgabeblack@google.com    sys.path[0:0] = [ parser_py.dir.abspath ]
12713207Sgabeblack@google.com    import isa_parser
12813207Sgabeblack@google.com
12913207Sgabeblack@google.com    parser = isa_parser.ISAParser(target[0].dir.abspath)
13013206Sgabeblack@google.com    parser.parse_isa_desc(source[0].abspath)
13113206Sgabeblack@google.com
13213206Sgabeblack@google.comdesc_action = MakeAction(run_parser, Transform("ISA DESC", 1))
13313207Sgabeblack@google.com
13413206Sgabeblack@google.comIsaDescBuilder = Builder(action=desc_action)
13513207Sgabeblack@google.com
13613207Sgabeblack@google.com
13713207Sgabeblack@google.com# ISAs should use this function to set up an IsaDescBuilder and not try to
13813206Sgabeblack@google.com# set one up manually.
13913206Sgabeblack@google.comdef ISADesc(desc, decoder_splits=1, exec_splits=1):
14013206Sgabeblack@google.com    '''Set up a builder for an ISA description.
14113207Sgabeblack@google.com
14213206Sgabeblack@google.com    The decoder_splits and exec_splits parameters let us determine what
14313207Sgabeblack@google.com    files the isa parser is actually going to generate. This needs to match
14413207Sgabeblack@google.com    what files are actually generated, and there's no specific check for that
14513207Sgabeblack@google.com    right now.
14613207Sgabeblack@google.com
14713206Sgabeblack@google.com    If the parser itself is responsible for generating a list of its products
14813206Sgabeblack@google.com    and their dependencies, then using that output to set up the right
14913206Sgabeblack@google.com    dependencies. This is what we used to do. The problem is that scons
15013207Sgabeblack@google.com    fundamentally doesn't support using a build product to affect its graph
15113206Sgabeblack@google.com    of possible products, dependencies, builders, etc. There are a couple ways
15213207Sgabeblack@google.com    to work around that limitation.
15313207Sgabeblack@google.com
15413207Sgabeblack@google.com    One option is to compute dependencies while the build phase of scons is
15513206Sgabeblack@google.com    running. That method can be quite complicated and cumbersome, because we
15613206Sgabeblack@google.com    have to make sure our modifications are made before scons tries to
15713207Sgabeblack@google.com    consume them. There's also no guarantee that this mechanism will work since
15813207Sgabeblack@google.com    it subverts scons expectations and changes things behind its back. This
15913207Sgabeblack@google.com    was implemented previously and constrained the builds parallelism
16013207Sgabeblack@google.com    significantly.
16113207Sgabeblack@google.com
16213207Sgabeblack@google.com    Another option would be to recursively call scons to have it update the
16313207Sgabeblack@google.com    list of products/dependencies during the setup phase of this invocation of
16413207Sgabeblack@google.com    scons. The problem with that is that it would be very difficult to make
16513207Sgabeblack@google.com    the sub-invocation of scons observe the options passed to the primary one
16613207Sgabeblack@google.com    in all possible cases, or to even determine conclusively what the name of
16713207Sgabeblack@google.com    the scons executable is in the first place.
16813207Sgabeblack@google.com
16913207Sgabeblack@google.com    Possible future changes to the isa parser might make it easier to
17013207Sgabeblack@google.com    determine what files it would generate, perhaps because there was a more
17113207Sgabeblack@google.com    direct correspondence between input files and output files. Or, if the
17213207Sgabeblack@google.com    parser could run quickly and determine what its output files would be
17313207Sgabeblack@google.com    without having do actually generate those files, then it could be run
17413207Sgabeblack@google.com    unconditionally without slowing down all builds or touching the output
17513207Sgabeblack@google.com    files unnecessarily.
17613207Sgabeblack@google.com    '''
17713207Sgabeblack@google.com    generated_dir = File(desc).dir.up().Dir('generated')
17813207Sgabeblack@google.com    def gen_file(name):
17913207Sgabeblack@google.com        return generated_dir.File(name)
18013207Sgabeblack@google.com
18113207Sgabeblack@google.com    gen = []
18213207Sgabeblack@google.com    def add_gen(name):
18313207Sgabeblack@google.com        gen.append(gen_file(name))
18413207Sgabeblack@google.com
18513207Sgabeblack@google.com    # Tell scons about the various files the ISA parser will generate.
18613207Sgabeblack@google.com    add_gen('decoder-g.cc.inc')
18713207Sgabeblack@google.com    add_gen('decoder-ns.cc.inc')
18813207Sgabeblack@google.com    add_gen('decode-method.cc.inc')
18913207Sgabeblack@google.com
19013207Sgabeblack@google.com    add_gen('decoder.hh')
19113207Sgabeblack@google.com    add_gen('decoder-g.hh.inc')
19213207Sgabeblack@google.com    add_gen('decoder-ns.hh.inc')
19313207Sgabeblack@google.com
19413207Sgabeblack@google.com    add_gen('exec-g.cc.inc')
19513207Sgabeblack@google.com    add_gen('exec-ns.cc.inc')
19613207Sgabeblack@google.com
19713207Sgabeblack@google.com    add_gen('max_inst_regs.hh')
19813207Sgabeblack@google.com
19913207Sgabeblack@google.com
20013207Sgabeblack@google.com    # These generated files are also top level sources.
20113207Sgabeblack@google.com    def source_gen(name):
20213207Sgabeblack@google.com        add_gen(name)
20313207Sgabeblack@google.com        Source(gen_file(name))
20413207Sgabeblack@google.com
20513207Sgabeblack@google.com    source_gen('decoder.cc')
20613207Sgabeblack@google.com
20713207Sgabeblack@google.com    if decoder_splits == 1:
20813207Sgabeblack@google.com        source_gen('inst-constrs.cc')
20913207Sgabeblack@google.com    else:
21013207Sgabeblack@google.com        for i in range(1, decoder_splits + 1):
21113207Sgabeblack@google.com            source_gen('inst-constrs-%d.cc' % i)
21213207Sgabeblack@google.com
21313207Sgabeblack@google.com    if exec_splits == 1:
21413207Sgabeblack@google.com        source_gen('generic_cpu_exec.cc')
21513207Sgabeblack@google.com    else:
21613207Sgabeblack@google.com        for i in range(1, exec_splits + 1):
21713207Sgabeblack@google.com            source_gen('generic_cpu_exec_%d.cc' % i)
21813207Sgabeblack@google.com
21913207Sgabeblack@google.com    # Actually create the builder.
22013207Sgabeblack@google.com    sources = [desc, parser_py, micro_asm_py]
22113207Sgabeblack@google.com    IsaDescBuilder(target=gen, source=sources, env=env)
22213207Sgabeblack@google.com    return gen
22313206Sgabeblack@google.com
22413304Sgabeblack@google.comExport('ISADesc')
22513206Sgabeblack@google.com
22613206Sgabeblack@google.comDebugFlag('IntRegs')
22713206Sgabeblack@google.comDebugFlag('FloatRegs')
22813206Sgabeblack@google.comDebugFlag('VecRegs')
22913206Sgabeblack@google.comDebugFlag('VecPredRegs')
23013206Sgabeblack@google.comDebugFlag('CCRegs')
23113206Sgabeblack@google.comDebugFlag('MiscRegs')
23213206Sgabeblack@google.comCompoundFlag('Registers', [ 'IntRegs', 'FloatRegs', 'VecRegs', 'VecPredRegs',
23313206Sgabeblack@google.com                            'CCRegs', 'MiscRegs' ])
23413206Sgabeblack@google.com