SConscript revision 2439
1955SN/A# -*- mode:python -*-
2955SN/A
313576Sciro.santilli@arm.com# Copyright (c) 2006 The Regents of The University of Michigan
413576Sciro.santilli@arm.com# All rights reserved.
513576Sciro.santilli@arm.com#
613576Sciro.santilli@arm.com# Redistribution and use in source and binary forms, with or without
713576Sciro.santilli@arm.com# modification, are permitted provided that the following conditions are
813576Sciro.santilli@arm.com# met: redistributions of source code must retain the above copyright
913576Sciro.santilli@arm.com# notice, this list of conditions and the following disclaimer;
1013576Sciro.santilli@arm.com# redistributions in binary form must reproduce the above copyright
1113576Sciro.santilli@arm.com# notice, this list of conditions and the following disclaimer in the
1213576Sciro.santilli@arm.com# documentation and/or other materials provided with the distribution;
1313576Sciro.santilli@arm.com# neither the name of the copyright holders nor the names of its
141762SN/A# contributors may be used to endorse or promote products derived from
15955SN/A# this software without specific prior written permission.
16955SN/A#
17955SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26955SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27955SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28955SN/A
29955SN/Aimport os.path
30955SN/A
31955SN/A# Import build environment variable from SConstruct.
32955SN/AImport('env')
33955SN/A
34955SN/A# Right now there are no source files immediately in this directory
35955SN/Asources = []
36955SN/A
37955SN/A#################################################################
38955SN/A#
392665Ssaidi@eecs.umich.edu# ISA "switch header" generation.
404762Snate@binkert.org#
41955SN/A# Auto-generate arch headers that include the right ISA-specific
4212563Sgabeblack@google.com# header based on the setting of THE_ISA preprocessor variable.
4312563Sgabeblack@google.com#
445522Snate@binkert.org#################################################################
456143Snate@binkert.org
4612371Sgabeblack@google.com# List of headers to generate
474762Snate@binkert.orgisa_switch_hdrs = Split('''
485522Snate@binkert.org	arguments.hh
49955SN/A	constants.hh
505522Snate@binkert.org	faults.hh
5111974Sgabeblack@google.com	isa_traits.hh
52955SN/A	process.hh
535522Snate@binkert.org	registerfile.hh
544202Sbinkertn@umich.edu	stacktrace.hh
555742Snate@binkert.org	tlb.hh
56955SN/A	types.hh
574381Sbinkertn@umich.edu	utility.hh
584381Sbinkertn@umich.edu	vtophys.hh
5912246Sgabeblack@google.com        ''')
6012246Sgabeblack@google.com
618334Snate@binkert.org# Generate the header.  target[0] is the full path of the output
62955SN/A# header to generate.  'source' is a dummy variable, since we get the
63955SN/A# list of ISAs from env['ALL_ISA_LIST'].
644202Sbinkertn@umich.edudef gen_switch_hdr(target, source, env):
65955SN/A    fname = str(target[0])
664382Sbinkertn@umich.edu    basename = os.path.basename(fname)
674382Sbinkertn@umich.edu    f = open(fname, 'w')
684382Sbinkertn@umich.edu    f.write('#include "arch/isa_specific.hh"\n')
696654Snate@binkert.org    cond = '#if'
705517Snate@binkert.org    for isa in env['ALL_ISA_LIST']:
718614Sgblack@eecs.umich.edu        f.write('%s THE_ISA == %s_ISA\n#include "arch/%s/%s"\n'
727674Snate@binkert.org                % (cond, isa.upper(), isa, basename))
736143Snate@binkert.org        cond = '#elif'
746143Snate@binkert.org    f.write('#else\n#error "THE_ISA not set"\n#endif\n')
756143Snate@binkert.org    f.close()
7612302Sgabeblack@google.com    return 0
7712302Sgabeblack@google.com
7812302Sgabeblack@google.com# String to print when generating header
7912371Sgabeblack@google.comdef gen_switch_hdr_string(target, source, env):
8012371Sgabeblack@google.com    return "Generating ISA switch header " + str(target[0])
8112371Sgabeblack@google.com
8212371Sgabeblack@google.com# Build SCons Action object. 'varlist' specifies env vars that this
8312371Sgabeblack@google.com# action depends on; when env['ALL_ISA_LIST'] changes these actions
8412371Sgabeblack@google.com# should get re-executed.
8512371Sgabeblack@google.comswitch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string,
8612371Sgabeblack@google.com                           varlist=['ALL_ISA_LIST'])
8712371Sgabeblack@google.com
8812371Sgabeblack@google.com# Instantiate actions for each header
8912371Sgabeblack@google.comfor hdr in isa_switch_hdrs:
9012371Sgabeblack@google.com    env.Command(hdr, [], switch_hdr_action)
9112371Sgabeblack@google.com
9212371Sgabeblack@google.com#################################################################
9312371Sgabeblack@google.com#
9412371Sgabeblack@google.com# Include architecture-specific files.
9512371Sgabeblack@google.com#
9612371Sgabeblack@google.com#################################################################
9712371Sgabeblack@google.com
9812371Sgabeblack@google.com#
9912371Sgabeblack@google.com# Build a SCons scanner for ISA files
10012371Sgabeblack@google.com#
10112371Sgabeblack@google.comimport SCons.Scanner
10212371Sgabeblack@google.com
10312371Sgabeblack@google.comdef ISAScan():
10412371Sgabeblack@google.com   return SCons.Scanner.Classic("ISAScan",
10512371Sgabeblack@google.com                                "$ISASUFFIXES",
10612371Sgabeblack@google.com                                "SRCDIR",
10712371Sgabeblack@google.com                                '^[ \t]*##[ \t]*include[ \t]*"([^>"]+)"')
10812371Sgabeblack@google.com
10912371Sgabeblack@google.comdef ISAPath(env, dir, target=None, source=None, a=None):
11012371Sgabeblack@google.com   return (Dir(env['SRCDIR']), Dir('.'))   
11112371Sgabeblack@google.com
11212371Sgabeblack@google.comiscan = Scanner(function = ISAScan().scan, skeys = [".isa", ".ISA"],
11312371Sgabeblack@google.com                path_function = ISAPath)
11412371Sgabeblack@google.comenv.Append(SCANNERS = iscan)
11512371Sgabeblack@google.com
11612371Sgabeblack@google.com#
11712371Sgabeblack@google.com# Now create a Builder object that uses isa_parser.py to generate C++
11812371Sgabeblack@google.com# output from the ISA description (*.isa) files.
11912371Sgabeblack@google.com#
12012371Sgabeblack@google.com
12112371Sgabeblack@google.com# Convert to File node to fix path
12212371Sgabeblack@google.comisa_parser = File('isa_parser.py')
12312371Sgabeblack@google.comcpu_models_file = File('#m5/cpu/cpu_models.py')
12412371Sgabeblack@google.com
12512371Sgabeblack@google.com# This sucks in the defintions of the CpuModel objects.
12612302Sgabeblack@google.comexecfile(cpu_models_file.srcnode().abspath)
12712371Sgabeblack@google.com
12812302Sgabeblack@google.com# Several files are generated from the ISA description.
12912371Sgabeblack@google.com# We always get the basic decoder and header file.
13012302Sgabeblack@google.comisa_desc_gen_files = Split('decoder.cc decoder.hh')
13112302Sgabeblack@google.com# We also get an execute file for each selected CPU model.
13212371Sgabeblack@google.comisa_desc_gen_files += [CpuModel.dict[cpu].filename
13312371Sgabeblack@google.com                       for cpu in env['CPU_MODELS']]
13412371Sgabeblack@google.com
13512371Sgabeblack@google.com# The emitter patches up the sources & targets to include the
13612302Sgabeblack@google.com# autogenerated files as targets and isa parser itself as a source.
13712371Sgabeblack@google.comdef isa_desc_emitter(target, source, env):
13812371Sgabeblack@google.com    return (isa_desc_gen_files, [isa_parser, cpu_models_file] + source)
13912371Sgabeblack@google.com
14012371Sgabeblack@google.com# Pieces are in place, so create the builder.
14111983Sgabeblack@google.comisa_desc_builder = Builder(action='$SOURCES $TARGET.dir $CPU_MODELS',
1426143Snate@binkert.org                           source_scanner = iscan,
1438233Snate@binkert.org                           emitter = isa_desc_emitter)
14412302Sgabeblack@google.com
1456143Snate@binkert.orgenv.Append(BUILDERS = { 'ISADesc' : isa_desc_builder })
1466143Snate@binkert.org
14712302Sgabeblack@google.com#
1484762Snate@binkert.org# Now include other ISA-specific sources from the ISA subdirectories.
1496143Snate@binkert.org#
1508233Snate@binkert.org
1518233Snate@binkert.orgisa = env['TARGET_ISA'] # someday this may be a list of ISAs
15212302Sgabeblack@google.com
15312302Sgabeblack@google.com# Let the target architecture define what additional sources it needs
1546143Snate@binkert.orgsources += SConscript(os.path.join(isa, 'SConscript'),
15512362Sgabeblack@google.com                      exports = 'env', duplicate = False)
15612362Sgabeblack@google.com
15712362Sgabeblack@google.comReturn('sources')
15812362Sgabeblack@google.com