SConscript revision 12109
112027Sjungma@eit.uni-kl.de# -*- mode:python -*-
212027Sjungma@eit.uni-kl.de
312027Sjungma@eit.uni-kl.de# Copyright (c) 2016 ARM Limited
412027Sjungma@eit.uni-kl.de# All rights reserved.
512027Sjungma@eit.uni-kl.de#
612027Sjungma@eit.uni-kl.de# The license below extends only to copyright in the software and shall
712027Sjungma@eit.uni-kl.de# not be construed as granting a license to any other intellectual
812027Sjungma@eit.uni-kl.de# property including but not limited to intellectual property relating
912027Sjungma@eit.uni-kl.de# to a hardware implementation of the functionality of the software
1012027Sjungma@eit.uni-kl.de# licensed hereunder.  You may use the software subject to the license
1112027Sjungma@eit.uni-kl.de# terms below provided that you ensure that this notice is replicated
1212027Sjungma@eit.uni-kl.de# unmodified and in its entirety in all distributions of the software,
1312027Sjungma@eit.uni-kl.de# modified or unmodified, in source code or in binary form.
1412027Sjungma@eit.uni-kl.de#
1512027Sjungma@eit.uni-kl.de# Copyright (c) 2006 The Regents of The University of Michigan
1612027Sjungma@eit.uni-kl.de# All rights reserved.
1712027Sjungma@eit.uni-kl.de#
1812027Sjungma@eit.uni-kl.de# Redistribution and use in source and binary forms, with or without
1912027Sjungma@eit.uni-kl.de# modification, are permitted provided that the following conditions are
2012027Sjungma@eit.uni-kl.de# met: redistributions of source code must retain the above copyright
2112027Sjungma@eit.uni-kl.de# notice, this list of conditions and the following disclaimer;
2212027Sjungma@eit.uni-kl.de# redistributions in binary form must reproduce the above copyright
2312027Sjungma@eit.uni-kl.de# notice, this list of conditions and the following disclaimer in the
2412027Sjungma@eit.uni-kl.de# documentation and/or other materials provided with the distribution;
2512027Sjungma@eit.uni-kl.de# neither the name of the copyright holders nor the names of its
2612027Sjungma@eit.uni-kl.de# contributors may be used to endorse or promote products derived from
2712027Sjungma@eit.uni-kl.de# this software without specific prior written permission.
2812027Sjungma@eit.uni-kl.de#
2912027Sjungma@eit.uni-kl.de# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3012027Sjungma@eit.uni-kl.de# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3112027Sjungma@eit.uni-kl.de# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
3212027Sjungma@eit.uni-kl.de# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3312027Sjungma@eit.uni-kl.de# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3412027Sjungma@eit.uni-kl.de# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3512027Sjungma@eit.uni-kl.de# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3612027Sjungma@eit.uni-kl.de# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3712027Sjungma@eit.uni-kl.de# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3812027Sjungma@eit.uni-kl.de# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3912027Sjungma@eit.uni-kl.de# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4012027Sjungma@eit.uni-kl.de#
4112027Sjungma@eit.uni-kl.de# Authors: Steve Reinhardt
4212027Sjungma@eit.uni-kl.de
4312027Sjungma@eit.uni-kl.deimport sys
4412027Sjungma@eit.uni-kl.deimport os
4512027Sjungma@eit.uni-kl.deimport re
4612027Sjungma@eit.uni-kl.de
4712027Sjungma@eit.uni-kl.deImport('*')
4812027Sjungma@eit.uni-kl.de
4912027Sjungma@eit.uni-kl.de#################################################################
5012027Sjungma@eit.uni-kl.de#
5112027Sjungma@eit.uni-kl.de# ISA "switch header" generation.
5212027Sjungma@eit.uni-kl.de#
5312027Sjungma@eit.uni-kl.de# Auto-generate arch headers that include the right ISA-specific
5412027Sjungma@eit.uni-kl.de# header based on the setting of THE_ISA preprocessor variable.
5512027Sjungma@eit.uni-kl.de#
5612027Sjungma@eit.uni-kl.de#################################################################
5712027Sjungma@eit.uni-kl.de
5812027Sjungma@eit.uni-kl.deenv.SwitchingHeaders(
5912027Sjungma@eit.uni-kl.de    Split('''
6012027Sjungma@eit.uni-kl.de        decoder.hh
6112027Sjungma@eit.uni-kl.de        interrupts.hh
6212027Sjungma@eit.uni-kl.de        isa.hh
6312027Sjungma@eit.uni-kl.de        isa_traits.hh
6412027Sjungma@eit.uni-kl.de        kernel_stats.hh
6512027Sjungma@eit.uni-kl.de        locked_mem.hh
6612027Sjungma@eit.uni-kl.de        microcode_rom.hh
6712027Sjungma@eit.uni-kl.de        mmapped_ipr.hh
6812027Sjungma@eit.uni-kl.de        mt.hh
6912027Sjungma@eit.uni-kl.de        process.hh
7012027Sjungma@eit.uni-kl.de        pseudo_inst.hh
7112027Sjungma@eit.uni-kl.de        registers.hh
7212027Sjungma@eit.uni-kl.de        remote_gdb.hh
7312027Sjungma@eit.uni-kl.de        stacktrace.hh
7412027Sjungma@eit.uni-kl.de        tlb.hh
7512027Sjungma@eit.uni-kl.de        types.hh
7612027Sjungma@eit.uni-kl.de        utility.hh
7712027Sjungma@eit.uni-kl.de        vtophys.hh
7812027Sjungma@eit.uni-kl.de        '''),
7912027Sjungma@eit.uni-kl.de    env.subst('${TARGET_ISA}'))
8012027Sjungma@eit.uni-kl.de
8112027Sjungma@eit.uni-kl.deif env['BUILD_GPU']:
8212027Sjungma@eit.uni-kl.de    env.SwitchingHeaders(
8312027Sjungma@eit.uni-kl.de        Split('''
8412027Sjungma@eit.uni-kl.de            gpu_decoder.hh
8512027Sjungma@eit.uni-kl.de            gpu_isa.hh
8612027Sjungma@eit.uni-kl.de            gpu_types.hh
8712027Sjungma@eit.uni-kl.de            '''),
8812027Sjungma@eit.uni-kl.de        env.subst('${TARGET_GPU_ISA}'))
8912027Sjungma@eit.uni-kl.de
9012027Sjungma@eit.uni-kl.de#################################################################
9112027Sjungma@eit.uni-kl.de#
9212027Sjungma@eit.uni-kl.de# Include architecture-specific files.
9312027Sjungma@eit.uni-kl.de#
9412027Sjungma@eit.uni-kl.de#################################################################
9512027Sjungma@eit.uni-kl.de
9612027Sjungma@eit.uni-kl.de#
9712027Sjungma@eit.uni-kl.de# Build a SCons scanner for ISA files
9812027Sjungma@eit.uni-kl.de#
9912027Sjungma@eit.uni-kl.deimport SCons.Scanner
10012027Sjungma@eit.uni-kl.de
10112027Sjungma@eit.uni-kl.deisa_scanner = SCons.Scanner.Classic("ISAScan",
10212027Sjungma@eit.uni-kl.de                                    [".isa", ".ISA"],
10312027Sjungma@eit.uni-kl.de                                    "SRCDIR",
10412027Sjungma@eit.uni-kl.de                                    r'^\s*##include\s+"([\w/.-]*)"')
10512027Sjungma@eit.uni-kl.de
10612027Sjungma@eit.uni-kl.deenv.Append(SCANNERS = isa_scanner)
10712027Sjungma@eit.uni-kl.de
10812027Sjungma@eit.uni-kl.de#
10912027Sjungma@eit.uni-kl.de# Now create a Builder object that uses isa_parser.py to generate C++
11012027Sjungma@eit.uni-kl.de# output from the ISA description (*.isa) files.
11112027Sjungma@eit.uni-kl.de#
11212027Sjungma@eit.uni-kl.de
11312027Sjungma@eit.uni-kl.deisa_parser = File('isa_parser.py')
11412027Sjungma@eit.uni-kl.de
11512027Sjungma@eit.uni-kl.de# The emitter patches up the sources & targets to include the
11612027Sjungma@eit.uni-kl.de# autogenerated files as targets and isa parser itself as a source.
11712027Sjungma@eit.uni-kl.dedef isa_desc_emitter(target, source, env):
11812027Sjungma@eit.uni-kl.de    # List the isa parser as a source.
11912027Sjungma@eit.uni-kl.de    source += [
12012027Sjungma@eit.uni-kl.de        isa_parser,
12112027Sjungma@eit.uni-kl.de        Value("ExecContext"),
12212027Sjungma@eit.uni-kl.de        ]
12312027Sjungma@eit.uni-kl.de
12412027Sjungma@eit.uni-kl.de    # Specify different targets depending on if we're running the ISA
12512027Sjungma@eit.uni-kl.de    # parser for its dependency information, or for the generated files.
12612027Sjungma@eit.uni-kl.de    # (As an optimization, the ISA parser detects the useless second run
12712027Sjungma@eit.uni-kl.de    # and skips doing any work, if the first run was performed, since it
12812027Sjungma@eit.uni-kl.de    # always generates all its files). The way we track this in SCons is the
12912027Sjungma@eit.uni-kl.de    # <arch>_isa_outputs value in the environment (env). If it's unset, we
13012027Sjungma@eit.uni-kl.de    # don't know what the dependencies are so we ask for generated/inc.d to
13112027Sjungma@eit.uni-kl.de    # be generated so they can be acquired. If we know what they are, then
13212027Sjungma@eit.uni-kl.de    # it's because we've already processed inc.d and then claim that our
13312027Sjungma@eit.uni-kl.de    # outputs (targets) will be thus.
13412027Sjungma@eit.uni-kl.de    isa = env['TARGET_ISA']
13512027Sjungma@eit.uni-kl.de    key = '%s_isa_outputs' % isa
13612027Sjungma@eit.uni-kl.de    if key in env:
13712027Sjungma@eit.uni-kl.de        targets = [ os.path.join('generated', f) for f in env[key] ]
13812027Sjungma@eit.uni-kl.de    else:
13912027Sjungma@eit.uni-kl.de        targets = [ os.path.join('generated','inc.d') ]
14012027Sjungma@eit.uni-kl.de
14112027Sjungma@eit.uni-kl.de    def prefix(s):
14212027Sjungma@eit.uni-kl.de        return os.path.join(target[0].dir.up().abspath, s)
14312027Sjungma@eit.uni-kl.de
14412027Sjungma@eit.uni-kl.de    return [ prefix(t) for t in targets ], source
14512027Sjungma@eit.uni-kl.de
14612027Sjungma@eit.uni-kl.deARCH_DIR = Dir('.')
14712027Sjungma@eit.uni-kl.de
14812027Sjungma@eit.uni-kl.de# import ply here because SCons screws with sys.path when performing actions.
14912027Sjungma@eit.uni-kl.deimport ply
15012027Sjungma@eit.uni-kl.de
15112027Sjungma@eit.uni-kl.dedef isa_desc_action_func(target, source, env):
15212027Sjungma@eit.uni-kl.de    # Add the current directory to the system path so we can import files
15312027Sjungma@eit.uni-kl.de    sys.path[0:0] = [ ARCH_DIR.srcnode().abspath ]
15412027Sjungma@eit.uni-kl.de    import isa_parser
15512027Sjungma@eit.uni-kl.de
15612027Sjungma@eit.uni-kl.de    # Skip over the ISA description itself and the parser to the CPU models.
15712027Sjungma@eit.uni-kl.de    models = [ s.get_contents() for s in source[2:] ]
15812027Sjungma@eit.uni-kl.de    parser = isa_parser.ISAParser(target[0].dir.abspath)
15912027Sjungma@eit.uni-kl.de    parser.parse_isa_desc(source[0].abspath)
16012027Sjungma@eit.uni-kl.deisa_desc_action = MakeAction(isa_desc_action_func, Transform("ISA DESC", 1))
16112027Sjungma@eit.uni-kl.de
16212027Sjungma@eit.uni-kl.de# Also include the CheckerCPU as one of the models if it is being
16312027Sjungma@eit.uni-kl.de# enabled via command line.
16412027Sjungma@eit.uni-kl.deisa_desc_builder = Builder(action=isa_desc_action, emitter=isa_desc_emitter)
16512027Sjungma@eit.uni-kl.de
16612027Sjungma@eit.uni-kl.deenv.Append(BUILDERS = { 'ISADesc' : isa_desc_builder })
16712027Sjungma@eit.uni-kl.de
16812027Sjungma@eit.uni-kl.de# The ISA is generated twice: the first time to find out what it generates,
16912027Sjungma@eit.uni-kl.de# and the second time to make scons happy by telling the ISADesc builder
17012027Sjungma@eit.uni-kl.de# what it will make before it builds it.
17112027Sjungma@eit.uni-kl.dedef scan_isa_deps(target, source, env):
17212027Sjungma@eit.uni-kl.de    # Process dependency file generated by the ISA parser --
17312027Sjungma@eit.uni-kl.de    # add the listed files to the dependency tree of the build.
17412027Sjungma@eit.uni-kl.de    source = source[0]
17512027Sjungma@eit.uni-kl.de    archbase = source.dir.up().path
17612027Sjungma@eit.uni-kl.de
17712027Sjungma@eit.uni-kl.de    try:
17812027Sjungma@eit.uni-kl.de        depfile = open(source.abspath, 'r')
17912027Sjungma@eit.uni-kl.de    except:
18012027Sjungma@eit.uni-kl.de        print "scan_isa_deps: Can't open ISA deps file '%s' in %s" % \
18112027Sjungma@eit.uni-kl.de              (source.path,os.getcwd())
18212027Sjungma@eit.uni-kl.de        raise
18312027Sjungma@eit.uni-kl.de
18412027Sjungma@eit.uni-kl.de    # Scan through the lines
18512027Sjungma@eit.uni-kl.de    targets = {}
18612027Sjungma@eit.uni-kl.de    for line in depfile:
18712027Sjungma@eit.uni-kl.de        # Read the dependency line with the format
18812027Sjungma@eit.uni-kl.de        # <target file>: [ <dependent file>* ]
18912027Sjungma@eit.uni-kl.de        m = re.match(r'^\s*([^:]+\.([^\.:]+))\s*:\s*(.*)', line)
19012027Sjungma@eit.uni-kl.de        assert(m)
19112027Sjungma@eit.uni-kl.de        targ, extn = m.group(1,2)
19212027Sjungma@eit.uni-kl.de        deps = m.group(3).split()
19312027Sjungma@eit.uni-kl.de
19412027Sjungma@eit.uni-kl.de        files = [ targ ] + deps
19512027Sjungma@eit.uni-kl.de        for f in files:
19612027Sjungma@eit.uni-kl.de            targets[f] = True
19712027Sjungma@eit.uni-kl.de            # Eliminate unnecessary re-generation if we already generated it
19812027Sjungma@eit.uni-kl.de            env.Precious(os.path.join(archbase, 'generated', f))
19912027Sjungma@eit.uni-kl.de
20012027Sjungma@eit.uni-kl.de        files = [ os.path.join(archbase, 'generated', f) for f in files ]
20112027Sjungma@eit.uni-kl.de
20212027Sjungma@eit.uni-kl.de        if extn == 'cc':
20312027Sjungma@eit.uni-kl.de            Source(os.path.join(archbase,'generated', targ))
20412027Sjungma@eit.uni-kl.de    depfile.close()
20512027Sjungma@eit.uni-kl.de    env[env['TARGET_ISA'] + '_isa_outputs'] = targets.keys()
20612027Sjungma@eit.uni-kl.de
20712027Sjungma@eit.uni-kl.de    isa = env.ISADesc(os.path.join(archbase,'isa','main.isa'))
20812027Sjungma@eit.uni-kl.de    for t in targets:
20912027Sjungma@eit.uni-kl.de        env.Depends('#all-isas', isa)
21012027Sjungma@eit.uni-kl.de
21112027Sjungma@eit.uni-kl.deenv.Append(BUILDERS = {'ScanISA' :
21212027Sjungma@eit.uni-kl.de                        Builder(action=MakeAction(scan_isa_deps,
21312027Sjungma@eit.uni-kl.de                                                  Transform("NEW DEPS", 1)))})
21412027Sjungma@eit.uni-kl.de
21512027Sjungma@eit.uni-kl.deDebugFlag('IntRegs')
21612027Sjungma@eit.uni-kl.deDebugFlag('FloatRegs')
21712027Sjungma@eit.uni-kl.deDebugFlag('VecRegs')
21812027Sjungma@eit.uni-kl.deDebugFlag('CCRegs')
21912027Sjungma@eit.uni-kl.deDebugFlag('MiscRegs')
22012027Sjungma@eit.uni-kl.deCompoundFlag('Registers', [ 'IntRegs', 'FloatRegs', 'CCRegs', 'MiscRegs' ])
22112027Sjungma@eit.uni-kl.de