SConscript revision 10196:be0e1724eb39
14680Sgblack@eecs.umich.edu# -*- mode:python -*-
25442Sgblack@eecs.umich.edu
34680Sgblack@eecs.umich.edu# Copyright (c) 2006 The Regents of The University of Michigan
44680Sgblack@eecs.umich.edu# All rights reserved.
54680Sgblack@eecs.umich.edu#
64680Sgblack@eecs.umich.edu# Redistribution and use in source and binary forms, with or without
74680Sgblack@eecs.umich.edu# modification, are permitted provided that the following conditions are
84680Sgblack@eecs.umich.edu# met: redistributions of source code must retain the above copyright
94680Sgblack@eecs.umich.edu# notice, this list of conditions and the following disclaimer;
104680Sgblack@eecs.umich.edu# redistributions in binary form must reproduce the above copyright
114680Sgblack@eecs.umich.edu# notice, this list of conditions and the following disclaimer in the
124680Sgblack@eecs.umich.edu# documentation and/or other materials provided with the distribution;
134680Sgblack@eecs.umich.edu# neither the name of the copyright holders nor the names of its
144680Sgblack@eecs.umich.edu# contributors may be used to endorse or promote products derived from
154680Sgblack@eecs.umich.edu# this software without specific prior written permission.
164680Sgblack@eecs.umich.edu#
174680Sgblack@eecs.umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
184680Sgblack@eecs.umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
194680Sgblack@eecs.umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
204680Sgblack@eecs.umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
214680Sgblack@eecs.umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
224680Sgblack@eecs.umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
234680Sgblack@eecs.umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
244680Sgblack@eecs.umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
254680Sgblack@eecs.umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
264680Sgblack@eecs.umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
274680Sgblack@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
284680Sgblack@eecs.umich.edu#
294680Sgblack@eecs.umich.edu# Authors: Steve Reinhardt
304680Sgblack@eecs.umich.edu
314680Sgblack@eecs.umich.eduimport sys
324680Sgblack@eecs.umich.eduimport os
334680Sgblack@eecs.umich.eduimport re
344680Sgblack@eecs.umich.edu
356215Snate@binkert.orgImport('*')
364680Sgblack@eecs.umich.edu
375543Ssaidi@eecs.umich.edu#################################################################
384680Sgblack@eecs.umich.edu#
394680Sgblack@eecs.umich.edu# ISA "switch header" generation.
404680Sgblack@eecs.umich.edu#
414680Sgblack@eecs.umich.edu# Auto-generate arch headers that include the right ISA-specific
424680Sgblack@eecs.umich.edu# header based on the setting of THE_ISA preprocessor variable.
434680Sgblack@eecs.umich.edu#
444680Sgblack@eecs.umich.edu#################################################################
454680Sgblack@eecs.umich.edu
464680Sgblack@eecs.umich.edu# List of headers to generate
474680Sgblack@eecs.umich.eduisa_switch_hdrs = Split('''
484680Sgblack@eecs.umich.edu        decoder.hh
494680Sgblack@eecs.umich.edu        interrupts.hh
504680Sgblack@eecs.umich.edu        isa.hh
514680Sgblack@eecs.umich.edu        isa_traits.hh
524680Sgblack@eecs.umich.edu        kernel_stats.hh
534680Sgblack@eecs.umich.edu        locked_mem.hh
544680Sgblack@eecs.umich.edu        microcode_rom.hh
554680Sgblack@eecs.umich.edu        mmapped_ipr.hh
564680Sgblack@eecs.umich.edu        mt.hh
574680Sgblack@eecs.umich.edu        process.hh
584680Sgblack@eecs.umich.edu        registers.hh
594680Sgblack@eecs.umich.edu        remote_gdb.hh
604680Sgblack@eecs.umich.edu        stacktrace.hh
614680Sgblack@eecs.umich.edu        tlb.hh
624680Sgblack@eecs.umich.edu        types.hh
634680Sgblack@eecs.umich.edu        utility.hh
644680Sgblack@eecs.umich.edu        vtophys.hh
654680Sgblack@eecs.umich.edu        ''')
664680Sgblack@eecs.umich.edu
674680Sgblack@eecs.umich.edu# Set up this directory to support switching headers
684680Sgblack@eecs.umich.edumake_switching_dir('arch', isa_switch_hdrs, env)
694680Sgblack@eecs.umich.edu
704680Sgblack@eecs.umich.edu#################################################################
714680Sgblack@eecs.umich.edu#
724680Sgblack@eecs.umich.edu# Include architecture-specific files.
734680Sgblack@eecs.umich.edu#
744680Sgblack@eecs.umich.edu#################################################################
754680Sgblack@eecs.umich.edu
764680Sgblack@eecs.umich.edu#
774680Sgblack@eecs.umich.edu# Build a SCons scanner for ISA files
784680Sgblack@eecs.umich.edu#
794680Sgblack@eecs.umich.eduimport SCons.Scanner
804680Sgblack@eecs.umich.edu
814680Sgblack@eecs.umich.eduisa_scanner = SCons.Scanner.Classic("ISAScan",
824680Sgblack@eecs.umich.edu                                    [".isa", ".ISA"],
834680Sgblack@eecs.umich.edu                                    "SRCDIR",
844680Sgblack@eecs.umich.edu                                    r'^\s*##include\s+"([\w/.-]*)"')
854680Sgblack@eecs.umich.edu
864680Sgblack@eecs.umich.eduenv.Append(SCANNERS = isa_scanner)
874680Sgblack@eecs.umich.edu
884680Sgblack@eecs.umich.edu#
894680Sgblack@eecs.umich.edu# Now create a Builder object that uses isa_parser.py to generate C++
904680Sgblack@eecs.umich.edu# output from the ISA description (*.isa) files.
914680Sgblack@eecs.umich.edu#
924680Sgblack@eecs.umich.edu
934680Sgblack@eecs.umich.eduisa_parser = File('isa_parser.py')
944680Sgblack@eecs.umich.edu
954680Sgblack@eecs.umich.edu# The emitter patches up the sources & targets to include the
964680Sgblack@eecs.umich.edu# autogenerated files as targets and isa parser itself as a source.
974680Sgblack@eecs.umich.edudef isa_desc_emitter(target, source, env):
984680Sgblack@eecs.umich.edu    cpu_models = list(env['CPU_MODELS'])
994680Sgblack@eecs.umich.edu    cpu_models.append('CheckerCPU')
1004680Sgblack@eecs.umich.edu
1014680Sgblack@eecs.umich.edu    # List the isa parser as a source.
1024680Sgblack@eecs.umich.edu    source += [ isa_parser ]
1034680Sgblack@eecs.umich.edu    # Add in the CPU models.
1044680Sgblack@eecs.umich.edu    source += [ Value(m) for m in cpu_models ]
1054680Sgblack@eecs.umich.edu
1064680Sgblack@eecs.umich.edu    # Specify different targets depending on if we're running the ISA
1074680Sgblack@eecs.umich.edu    # parser for its dependency information, or for the generated files.
1084680Sgblack@eecs.umich.edu    # (As an optimization, the ISA parser detects the useless second run
1094680Sgblack@eecs.umich.edu    # and skips doing any work, if the first run was performed, since it
1104680Sgblack@eecs.umich.edu    # always generates all its files). The way we track this in SCons is the
1114680Sgblack@eecs.umich.edu    # <arch>_isa_outputs value in the environment (env). If it's unset, we
1124680Sgblack@eecs.umich.edu    # don't know what the dependencies are so we ask for generated/inc.d to
1134680Sgblack@eecs.umich.edu    # be generated so they can be acquired. If we know what they are, then
1144680Sgblack@eecs.umich.edu    # it's because we've already processed inc.d and then claim that our
1154680Sgblack@eecs.umich.edu    # outputs (targets) will be thus.
1164680Sgblack@eecs.umich.edu    isa = env['TARGET_ISA']
1174680Sgblack@eecs.umich.edu    key = '%s_isa_outputs' % isa
1184680Sgblack@eecs.umich.edu    if key in env:
1194680Sgblack@eecs.umich.edu        targets = [ os.path.join('generated', f) for f in env[key] ]
1204680Sgblack@eecs.umich.edu    else:
1214680Sgblack@eecs.umich.edu        targets = [ os.path.join('generated','inc.d') ]
1224680Sgblack@eecs.umich.edu
1234680Sgblack@eecs.umich.edu    def prefix(s):
1244680Sgblack@eecs.umich.edu        return os.path.join(target[0].dir.up().abspath, s)
1254680Sgblack@eecs.umich.edu
1264680Sgblack@eecs.umich.edu    return [ prefix(t) for t in targets ], source
1274680Sgblack@eecs.umich.edu
1284680Sgblack@eecs.umich.eduARCH_DIR = Dir('.')
1294680Sgblack@eecs.umich.edu
1304680Sgblack@eecs.umich.edu# import ply here because SCons screws with sys.path when performing actions.
1314680Sgblack@eecs.umich.eduimport ply
1324680Sgblack@eecs.umich.edu
1334680Sgblack@eecs.umich.edudef isa_desc_action_func(target, source, env):
1344680Sgblack@eecs.umich.edu    # Add the current directory to the system path so we can import files
1354680Sgblack@eecs.umich.edu    sys.path[0:0] = [ ARCH_DIR.srcnode().abspath ]
1364680Sgblack@eecs.umich.edu    import isa_parser
1374680Sgblack@eecs.umich.edu
1384680Sgblack@eecs.umich.edu    # Skip over the ISA description itself and the parser to the CPU models.
1394680Sgblack@eecs.umich.edu    models = [ s.get_contents() for s in source[2:] ]
1404680Sgblack@eecs.umich.edu    cpu_models = [CpuModel.dict[cpu] for cpu in models]
1414680Sgblack@eecs.umich.edu    parser = isa_parser.ISAParser(target[0].dir.abspath, cpu_models)
1424680Sgblack@eecs.umich.edu    parser.parse_isa_desc(source[0].abspath)
1434680Sgblack@eecs.umich.eduisa_desc_action = MakeAction(isa_desc_action_func, Transform("ISA DESC", 1))
1444680Sgblack@eecs.umich.edu
1454680Sgblack@eecs.umich.edu# Also include the CheckerCPU as one of the models if it is being
1464680Sgblack@eecs.umich.edu# enabled via command line.
1474680Sgblack@eecs.umich.eduisa_desc_builder = Builder(action=isa_desc_action, emitter=isa_desc_emitter)
1484680Sgblack@eecs.umich.edu
1494680Sgblack@eecs.umich.eduenv.Append(BUILDERS = { 'ISADesc' : isa_desc_builder })
1504680Sgblack@eecs.umich.edu
1514680Sgblack@eecs.umich.edu# The ISA is generated twice: the first time to find out what it generates,
1524680Sgblack@eecs.umich.edu# and the second time to make scons happy by telling the ISADesc builder
1534680Sgblack@eecs.umich.edu# what it will make before it builds it.
1544680Sgblack@eecs.umich.edudef scan_isa_deps(target, source, env):
1554680Sgblack@eecs.umich.edu    # Process dependency file generated by the ISA parser --
1564680Sgblack@eecs.umich.edu    # add the listed files to the dependency tree of the build.
1574680Sgblack@eecs.umich.edu    source = source[0]
1584680Sgblack@eecs.umich.edu    archbase = source.dir.up().path
1594680Sgblack@eecs.umich.edu
1604680Sgblack@eecs.umich.edu    try:
1614680Sgblack@eecs.umich.edu        depfile = open(source.abspath, 'r')
1624680Sgblack@eecs.umich.edu    except:
1634680Sgblack@eecs.umich.edu        print "scan_isa_deps: Can't open ISA deps file '%s' in %s" % \
1644680Sgblack@eecs.umich.edu              (source.path,os.getcwd())
1654680Sgblack@eecs.umich.edu        raise
1664680Sgblack@eecs.umich.edu
1674680Sgblack@eecs.umich.edu    # Scan through the lines
1684680Sgblack@eecs.umich.edu    targets = {}
1694680Sgblack@eecs.umich.edu    for line in depfile:
1704680Sgblack@eecs.umich.edu        # Read the dependency line with the format
1714680Sgblack@eecs.umich.edu        # <target file>: [ <dependent file>* ]
1724680Sgblack@eecs.umich.edu        m = re.match(r'^\s*([^:]+\.([^\.:]+))\s*:\s*(.*)', line)
1734680Sgblack@eecs.umich.edu        assert(m)
1744680Sgblack@eecs.umich.edu        targ, extn = m.group(1,2)
1754680Sgblack@eecs.umich.edu        deps = m.group(3).split()
1764680Sgblack@eecs.umich.edu
1774680Sgblack@eecs.umich.edu        files = [ targ ] + deps
1784680Sgblack@eecs.umich.edu        for f in files:
1794680Sgblack@eecs.umich.edu            targets[f] = True
1804680Sgblack@eecs.umich.edu            # Eliminate unnecessary re-generation if we already generated it
1814680Sgblack@eecs.umich.edu            env.Precious(os.path.join(archbase, 'generated', f))
1824680Sgblack@eecs.umich.edu
1834680Sgblack@eecs.umich.edu        files = [ os.path.join(archbase, 'generated', f) for f in files ]
1844680Sgblack@eecs.umich.edu
1854680Sgblack@eecs.umich.edu        if extn == 'cc':
1864680Sgblack@eecs.umich.edu            Source(os.path.join(archbase,'generated', targ))
1874680Sgblack@eecs.umich.edu    depfile.close()
1884680Sgblack@eecs.umich.edu    env[env['TARGET_ISA'] + '_isa_outputs'] = targets.keys()
1894680Sgblack@eecs.umich.edu
1904680Sgblack@eecs.umich.edu    isa = env.ISADesc(os.path.join(archbase,'isa','main.isa'))
1914680Sgblack@eecs.umich.edu    for t in targets:
1924680Sgblack@eecs.umich.edu        env.Depends('#all-isas', isa)
1934680Sgblack@eecs.umich.edu
1944680Sgblack@eecs.umich.eduenv.Append(BUILDERS = {'ScanISA' :
1954680Sgblack@eecs.umich.edu                        Builder(action=MakeAction(scan_isa_deps,
1965136Sgblack@eecs.umich.edu                                                  Transform("NEW DEPS", 1)))})
1974681Sgblack@eecs.umich.edu
1984681Sgblack@eecs.umich.eduDebugFlag('IntRegs')
1994681Sgblack@eecs.umich.eduDebugFlag('FloatRegs')
2004681Sgblack@eecs.umich.eduDebugFlag('CCRegs')
2014681Sgblack@eecs.umich.eduDebugFlag('MiscRegs')
2024681Sgblack@eecs.umich.eduCompoundFlag('Registers', [ 'IntRegs', 'FloatRegs', 'CCRegs', 'MiscRegs' ])
2034680Sgblack@eecs.umich.edu