SConscript revision 2155
1955SN/A# -*- mode:python -*-
2955SN/A
31762SN/A# Copyright (c) 2006 The Regents of The University of Michigan
4955SN/A# All rights reserved.
5955SN/A#
6955SN/A# Redistribution and use in source and binary forms, with or without
7955SN/A# modification, are permitted provided that the following conditions are
8955SN/A# met: redistributions of source code must retain the above copyright
9955SN/A# notice, this list of conditions and the following disclaimer;
10955SN/A# redistributions in binary form must reproduce the above copyright
11955SN/A# notice, this list of conditions and the following disclaimer in the
12955SN/A# documentation and/or other materials provided with the distribution;
13955SN/A# neither the name of the copyright holders nor the names of its
14955SN/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.
282665Ssaidi@eecs.umich.edu
292665Ssaidi@eecs.umich.eduimport os.path
30955SN/A
31955SN/A# Import build environment variable from SConstruct.
32955SN/AImport('env')
334202Sbinkertn@umich.edu
344202Sbinkertn@umich.edu# Right now there are no source files immediately in this directory
35955SN/Asources = []
36955SN/A
37955SN/A#################################################################
38955SN/A#
394202Sbinkertn@umich.edu# ISA "switch header" generation.
40955SN/A#
414202Sbinkertn@umich.edu# Auto-generate arch headers that include the right ISA-specific
424202Sbinkertn@umich.edu# header based on the setting of THE_ISA preprocessor variable.
434202Sbinkertn@umich.edu#
444202Sbinkertn@umich.edu#################################################################
454202Sbinkertn@umich.edu
464202Sbinkertn@umich.edu# List of headers to generate
474202Sbinkertn@umich.eduisa_switch_hdrs = Split('''
484202Sbinkertn@umich.edu	isa_traits.hh
494202Sbinkertn@umich.edu        ''')
504202Sbinkertn@umich.edu
51955SN/A# Generate the header.  target[0] is the full path of the output
524202Sbinkertn@umich.edu# header to generate.  'source' is a dummy variable, since we get the
534202Sbinkertn@umich.edu# list of ISAs from env['ALL_ISA_LIST'].
54955SN/Adef gen_switch_hdr(target, source, env):
552667Sstever@eecs.umich.edu    fname = str(target[0])
562667Sstever@eecs.umich.edu    basename = os.path.basename(fname)
572667Sstever@eecs.umich.edu    f = open(fname, 'w')
582667Sstever@eecs.umich.edu    f.write('#include "arch/isa_specific.hh"\n')
592667Sstever@eecs.umich.edu    cond = '#if'
602667Sstever@eecs.umich.edu    for isa in env['ALL_ISA_LIST']:
612037SN/A        f.write('%s THE_ISA == %s_ISA\n#include "arch/%s/%s"\n'
622037SN/A                % (cond, isa.upper(), isa, basename))
632037SN/A        cond = '#elif'
644202Sbinkertn@umich.edu    f.write('#else\n#error "THE_ISA not set"\n#endif\n')
654202Sbinkertn@umich.edu    f.close()
664202Sbinkertn@umich.edu    return 0
674202Sbinkertn@umich.edu
684202Sbinkertn@umich.edu# String to print when generating header
694202Sbinkertn@umich.edudef gen_switch_hdr_string(target, source, env):
704202Sbinkertn@umich.edu    return "Generating ISA switch header " + str(target[0])
714202Sbinkertn@umich.edu
724202Sbinkertn@umich.edu# Build SCons Action object. 'varlist' specifies env vars that this
734202Sbinkertn@umich.edu# action depdnds on; when env['ALL_ISA_LIST'] changes these actions
744202Sbinkertn@umich.edu# should get re-executed.
754202Sbinkertn@umich.eduswitch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string,
764202Sbinkertn@umich.edu                           varlist=['ALL_ISA_LIST'])
771858SN/A
781858SN/A# Instantiate actions for each header
791858SN/Afor hdr in isa_switch_hdrs:
801085SN/A    env.Command(hdr, [], switch_hdr_action)
81955SN/A
82955SN/A#################################################################
83955SN/A#
84955SN/A# Include architecture-specific files.
851108SN/A#
86955SN/A#################################################################
87955SN/A
88955SN/A#
89955SN/A# Build a SCons scanner for ISA files
90955SN/A#
91955SN/Aimport SCons.Scanner
92955SN/A
93955SN/Adef ISAScan():
94955SN/A   return SCons.Scanner.Classic("ISAScan",
95955SN/A                                "$ISASUFFIXES",
96955SN/A                                "SRCDIR",
97955SN/A                                '^[ \t]*##[ \t]*include[ \t]*"([^>"]+)"')
98955SN/A
99955SN/Adef ISAPath(env, dir, target=None, source=None, a=None):
100955SN/A   return (Dir(env['SRCDIR']), Dir('.'))   
101955SN/A
1022655Sstever@eecs.umich.eduiscan = Scanner(function = ISAScan().scan, skeys = [".isa", ".ISA"],
1032655Sstever@eecs.umich.edu                path_function = ISAPath)
1042655Sstever@eecs.umich.eduenv.Append(SCANNERS = iscan)
1052655Sstever@eecs.umich.edu
1062655Sstever@eecs.umich.edu#
1072655Sstever@eecs.umich.edu# Now create a Builder object that uses isa_parser.py to generate C++
1082655Sstever@eecs.umich.edu# output from the ISA description (*.isa) files.
1092655Sstever@eecs.umich.edu#
1102655Sstever@eecs.umich.edu
1112655Sstever@eecs.umich.edu# Convert to File node to fix path
1122655Sstever@eecs.umich.eduisa_parser = File('isa_parser.py')
1132655Sstever@eecs.umich.educpu_models_file = File('#m5/cpu/cpu_models.py')
1142655Sstever@eecs.umich.edu
1152655Sstever@eecs.umich.edu# This sucks in the defintions of the CpuModel objects.
1162655Sstever@eecs.umich.eduexecfile(cpu_models_file.srcnode().abspath)
1172655Sstever@eecs.umich.edu
1184007Ssaidi@eecs.umich.edu# Several files are generated from the ISA description.
1194007Ssaidi@eecs.umich.edu# We always get the basic decoder and header file.
1204007Ssaidi@eecs.umich.eduisa_desc_gen_files = Split('decoder.cc decoder.hh')
1214007Ssaidi@eecs.umich.edu# We also get an execute file for each selected CPU model.
1222655Sstever@eecs.umich.eduisa_desc_gen_files += [CpuModel.dict[cpu].filename
1232655Sstever@eecs.umich.edu                       for cpu in env['CPU_MODELS']]
1242655Sstever@eecs.umich.edu
1252655Sstever@eecs.umich.edu# The emitter patches up the sources & targets to include the
1262655Sstever@eecs.umich.edu# autogenerated files as targets and isa parser itself as a source.
127955SN/Adef isa_desc_emitter(target, source, env):
1283918Ssaidi@eecs.umich.edu    return (isa_desc_gen_files, [isa_parser, cpu_models_file] + source)
1293918Ssaidi@eecs.umich.edu
1303918Ssaidi@eecs.umich.edu# Pieces are in place, so create the builder.
1313918Ssaidi@eecs.umich.eduisa_desc_builder = Builder(action='$SOURCES $TARGET.dir $CPU_MODELS',
1323918Ssaidi@eecs.umich.edu                           source_scanner = iscan,
1333918Ssaidi@eecs.umich.edu                           emitter = isa_desc_emitter)
1343918Ssaidi@eecs.umich.edu
1353918Ssaidi@eecs.umich.eduenv.Append(BUILDERS = { 'ISADesc' : isa_desc_builder })
1363918Ssaidi@eecs.umich.edu
1373918Ssaidi@eecs.umich.edu#
1383918Ssaidi@eecs.umich.edu# Now include other ISA-specific sources from the ISA subdirectories.
1393918Ssaidi@eecs.umich.edu#
1403918Ssaidi@eecs.umich.edu
1413918Ssaidi@eecs.umich.eduisa = env['TARGET_ISA'] # someday this may be a list of ISAs
1423940Ssaidi@eecs.umich.edu
1433940Ssaidi@eecs.umich.edu# Let the target architecture define what additional sources it needs
1443940Ssaidi@eecs.umich.edusources += SConscript(os.path.join(isa, 'SConscript'),
1453942Ssaidi@eecs.umich.edu                      exports = 'env', duplicate = False)
1463940Ssaidi@eecs.umich.edu
1473515Ssaidi@eecs.umich.eduReturn('sources')
1483918Ssaidi@eecs.umich.edu