SConscript revision 9016
112838Sgabeblack@google.com# -*- mode:python -*-
212838Sgabeblack@google.com
312838Sgabeblack@google.com# Copyright (c) 2006 The Regents of The University of Michigan
412838Sgabeblack@google.com# All rights reserved.
512838Sgabeblack@google.com#
612838Sgabeblack@google.com# Redistribution and use in source and binary forms, with or without
712838Sgabeblack@google.com# modification, are permitted provided that the following conditions are
812838Sgabeblack@google.com# met: redistributions of source code must retain the above copyright
912838Sgabeblack@google.com# notice, this list of conditions and the following disclaimer;
1012838Sgabeblack@google.com# redistributions in binary form must reproduce the above copyright
1112838Sgabeblack@google.com# notice, this list of conditions and the following disclaimer in the
1212838Sgabeblack@google.com# documentation and/or other materials provided with the distribution;
1312838Sgabeblack@google.com# neither the name of the copyright holders nor the names of its
1412838Sgabeblack@google.com# contributors may be used to endorse or promote products derived from
1512838Sgabeblack@google.com# this software without specific prior written permission.
1612838Sgabeblack@google.com#
1712838Sgabeblack@google.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1812838Sgabeblack@google.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1912838Sgabeblack@google.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2012838Sgabeblack@google.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2112838Sgabeblack@google.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2212838Sgabeblack@google.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2312838Sgabeblack@google.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2412838Sgabeblack@google.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2512838Sgabeblack@google.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2612838Sgabeblack@google.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2712838Sgabeblack@google.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2812838Sgabeblack@google.com#
2912838Sgabeblack@google.com# Authors: Steve Reinhardt
3012838Sgabeblack@google.com
3112838Sgabeblack@google.comimport sys
3212838Sgabeblack@google.comimport os
3312838Sgabeblack@google.com
3412838Sgabeblack@google.comImport('*')
3512838Sgabeblack@google.com
3612852Sgabeblack@google.com#################################################################
3712852Sgabeblack@google.com#
3812852Sgabeblack@google.com# ISA "switch header" generation.
3912852Sgabeblack@google.com#
4012852Sgabeblack@google.com# Auto-generate arch headers that include the right ISA-specific
4112952Sgabeblack@google.com# header based on the setting of THE_ISA preprocessor variable.
4212952Sgabeblack@google.com#
4312952Sgabeblack@google.com#################################################################
4412952Sgabeblack@google.com
4512952Sgabeblack@google.com# List of headers to generate
4612952Sgabeblack@google.comisa_switch_hdrs = Split('''
4712952Sgabeblack@google.com        interrupts.hh
4812952Sgabeblack@google.com        isa.hh
4912952Sgabeblack@google.com        isa_traits.hh
5012952Sgabeblack@google.com        kernel_stats.hh
5112952Sgabeblack@google.com        locked_mem.hh
5212952Sgabeblack@google.com        microcode_rom.hh
5312952Sgabeblack@google.com        mmapped_ipr.hh
5412952Sgabeblack@google.com        mt.hh
5512952Sgabeblack@google.com        process.hh
5612952Sgabeblack@google.com        predecoder.hh
5712952Sgabeblack@google.com        registers.hh
5812952Sgabeblack@google.com        remote_gdb.hh
5912952Sgabeblack@google.com        stacktrace.hh
6012952Sgabeblack@google.com        tlb.hh
6112952Sgabeblack@google.com        types.hh
6212952Sgabeblack@google.com        utility.hh
6312952Sgabeblack@google.com        vtophys.hh
6412952Sgabeblack@google.com        ''')
6512952Sgabeblack@google.com
6612952Sgabeblack@google.com# Set up this directory to support switching headers
6712952Sgabeblack@google.commake_switching_dir('arch', isa_switch_hdrs, env)
6812952Sgabeblack@google.com
6912952Sgabeblack@google.com#################################################################
7012952Sgabeblack@google.com#
7112952Sgabeblack@google.com# Include architecture-specific files.
7212952Sgabeblack@google.com#
7312952Sgabeblack@google.com#################################################################
7412952Sgabeblack@google.com
7512852Sgabeblack@google.com#
7612852Sgabeblack@google.com# Build a SCons scanner for ISA files
7712838Sgabeblack@google.com#
7812838Sgabeblack@google.comimport SCons.Scanner
7912838Sgabeblack@google.com
8012838Sgabeblack@google.comisa_scanner = SCons.Scanner.Classic("ISAScan",
8112838Sgabeblack@google.com                                    [".isa", ".ISA"],
8212838Sgabeblack@google.com                                    "SRCDIR",
8312838Sgabeblack@google.com                                    r'^\s*##include\s+"([\w/.-]*)"')
8412838Sgabeblack@google.com
8512838Sgabeblack@google.comenv.Append(SCANNERS = isa_scanner)
8612838Sgabeblack@google.com
8712838Sgabeblack@google.com#
8812838Sgabeblack@google.com# Now create a Builder object that uses isa_parser.py to generate C++
8912838Sgabeblack@google.com# output from the ISA description (*.isa) files.
9012838Sgabeblack@google.com#
9112838Sgabeblack@google.com
9212838Sgabeblack@google.comisa_parser = File('isa_parser.py')
9312838Sgabeblack@google.com
9412838Sgabeblack@google.com# The emitter patches up the sources & targets to include the
9512838Sgabeblack@google.com# autogenerated files as targets and isa parser itself as a source.
9612838Sgabeblack@google.comdef isa_desc_emitter(target, source, env):
9712838Sgabeblack@google.com    cpu_models = list(env['CPU_MODELS'])
9812838Sgabeblack@google.com    cpu_models.append('CheckerCPU')
9912838Sgabeblack@google.com
10012838Sgabeblack@google.com    # Several files are generated from the ISA description.
10112838Sgabeblack@google.com    # We always get the basic decoder and header file.
10212838Sgabeblack@google.com    target = [ 'decoder.cc', 'decoder.hh', 'max_inst_regs.hh' ]
10312898Sgabeblack@google.com    # We also get an execute file for each selected CPU model.
10412898Sgabeblack@google.com    target += [CpuModel.dict[cpu].filename for cpu in cpu_models]
10512898Sgabeblack@google.com
10612898Sgabeblack@google.com    # List the isa parser as a source.
10712898Sgabeblack@google.com    source += [ isa_parser ]
10812898Sgabeblack@google.com    # Add in the CPU models.
10912898Sgabeblack@google.com    source += [ Value(m) for m in cpu_models ]
11012838Sgabeblack@google.com
11112838Sgabeblack@google.com    return [os.path.join("generated", t) for t in target], source
11212838Sgabeblack@google.com
11312838Sgabeblack@google.comARCH_DIR = Dir('.')
11412939Sgabeblack@google.com
11512939Sgabeblack@google.com# import ply here because SCons screws with sys.path when performing actions.
11612939Sgabeblack@google.comimport ply
11712939Sgabeblack@google.com
11812939Sgabeblack@google.comdef isa_desc_action_func(target, source, env):
11912939Sgabeblack@google.com    # Add the current directory to the system path so we can import files
12012939Sgabeblack@google.com    sys.path[0:0] = [ ARCH_DIR.srcnode().abspath ]
12112939Sgabeblack@google.com    import isa_parser
12212939Sgabeblack@google.com
12312939Sgabeblack@google.com    # Skip over the ISA description itself and the parser to the CPU models.
12412939Sgabeblack@google.com    models = [ s.get_contents() for s in source[2:] ]
12512939Sgabeblack@google.com    cpu_models = [CpuModel.dict[cpu] for cpu in models]
12612939Sgabeblack@google.com    parser = isa_parser.ISAParser(target[0].dir.abspath, cpu_models)
12712939Sgabeblack@google.com    parser.parse_isa_desc(source[0].abspath)
12812939Sgabeblack@google.comisa_desc_action = MakeAction(isa_desc_action_func, Transform("ISA DESC", 1))
12912939Sgabeblack@google.com
13012939Sgabeblack@google.com# Also include the CheckerCPU as one of the models if it is being
13112939Sgabeblack@google.com# enabled via command line.
13212939Sgabeblack@google.comisa_desc_builder = Builder(action=isa_desc_action, emitter=isa_desc_emitter)
13312939Sgabeblack@google.com
13412939Sgabeblack@google.comenv.Append(BUILDERS = { 'ISADesc' : isa_desc_builder })
13512939Sgabeblack@google.com
13612939Sgabeblack@google.comDebugFlag('IntRegs')
13712939Sgabeblack@google.comDebugFlag('FloatRegs')
13812939Sgabeblack@google.comDebugFlag('MiscRegs')
13912939Sgabeblack@google.comCompoundFlag('Registers', [ 'IntRegs', 'FloatRegs', 'MiscRegs' ])
14012939Sgabeblack@google.com