SConscript revision 2623
12139SN/A# -*- mode:python -*-
22139SN/A
32139SN/A# Copyright (c) 2006 The Regents of The University of Michigan
42139SN/A# All rights reserved.
52139SN/A#
62139SN/A# Redistribution and use in source and binary forms, with or without
72139SN/A# modification, are permitted provided that the following conditions are
82139SN/A# met: redistributions of source code must retain the above copyright
92139SN/A# notice, this list of conditions and the following disclaimer;
102139SN/A# redistributions in binary form must reproduce the above copyright
112139SN/A# notice, this list of conditions and the following disclaimer in the
122139SN/A# documentation and/or other materials provided with the distribution;
132139SN/A# neither the name of the copyright holders nor the names of its
142139SN/A# contributors may be used to endorse or promote products derived from
152139SN/A# this software without specific prior written permission.
162139SN/A#
172139SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
182139SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
192139SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
202139SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
212139SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
222139SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
232139SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
242139SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
252139SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
262139SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
272139SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
282665Ssaidi@eecs.umich.edu
292665Ssaidi@eecs.umich.eduimport os.path
302139SN/A
312718Sstever@eecs.umich.edu# Import build environment variable from SConstruct.
322139SN/AImport('env')
332139SN/A
342139SN/A# Right now there are no source files immediately in this directory
352139SN/Asources = []
362152SN/A
372152SN/A#################################################################
382152SN/A#
392152SN/A# ISA "switch header" generation.
402139SN/A#
412139SN/A# Auto-generate arch headers that include the right ISA-specific
422139SN/A# header based on the setting of THE_ISA preprocessor variable.
432139SN/A#
442139SN/A#################################################################
452152SN/A
462152SN/A# List of headers to generate
472139SN/Aisa_switch_hdrs = Split('''
482139SN/A	arguments.hh
492139SN/A	constants.hh
502984Sgblack@eecs.umich.edu	faults.hh
512439SN/A	isa_traits.hh
523520Sgblack@eecs.umich.edu	process.hh
532139SN/A	regfile.hh
543565Sgblack@eecs.umich.edu	stacktrace.hh
553170Sstever@eecs.umich.edu	tlb.hh
563806Ssaidi@eecs.umich.edu	types.hh
572439SN/A	utility.hh
582460SN/A	vtophys.hh
593536Sgblack@eecs.umich.edu        ''')
602439SN/A
612972Sgblack@eecs.umich.edu# Generate the header.  target[0] is the full path of the output
622171SN/A# header to generate.  'source' is a dummy variable, since we get the
632439SN/A# list of ISAs from env['ALL_ISA_LIST'].
642439SN/Adef gen_switch_hdr(target, source, env):
652170SN/A    fname = str(target[0])
662139SN/A    basename = os.path.basename(fname)
672139SN/A    f = open(fname, 'w')
683546Sgblack@eecs.umich.edu    f.write('#include "arch/isa_specific.hh"\n')
693546Sgblack@eecs.umich.edu    cond = '#if'
702152SN/A    for isa in env['ALL_ISA_LIST']:
712152SN/A        f.write('%s THE_ISA == %s_ISA\n#include "arch/%s/%s"\n'
722152SN/A                % (cond, isa.upper(), isa, basename))
732152SN/A        cond = '#elif'
742152SN/A    f.write('#else\n#error "THE_ISA not set"\n#endif\n')
752152SN/A    f.close()
762152SN/A    return 0
772152SN/A
782152SN/A# String to print when generating header
792152SN/Adef gen_switch_hdr_string(target, source, env):
802152SN/A    return "Generating ISA switch header " + str(target[0])
812152SN/A
822504SN/A# Build SCons Action object. 'varlist' specifies env vars that this
832504SN/A# action depends on; when env['ALL_ISA_LIST'] changes these actions
842504SN/A# should get re-executed.
852504SN/Aswitch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string,
862152SN/A                           varlist=['ALL_ISA_LIST'])
872504SN/A
882152SN/A# Instantiate actions for each header
892152SN/Afor hdr in isa_switch_hdrs:
902152SN/A    env.Command(hdr, [], switch_hdr_action)
912152SN/A
922152SN/A#################################################################
932152SN/A#
942152SN/A# Include architecture-specific files.
952152SN/A#
962632Sstever@eecs.umich.edu#################################################################
972155SN/A
982155SN/A#
992155SN/A# Build a SCons scanner for ISA files
1002155SN/A#
1012155SN/Aimport SCons.Scanner
1022155SN/A
1032155SN/Aisa_scanner = SCons.Scanner.Classic("ISAScan",
1042155SN/A                                    [".isa", ".ISA"],
1052155SN/A                                    "SRCDIR",
1062155SN/A                                    r'^\s*##include\s+"([\w/.-]*)"')
1072152SN/A
1082766Sktlim@umich.eduenv.Append(SCANNERS = isa_scanner)
1092766Sktlim@umich.edu
1102766Sktlim@umich.edu#
1112766Sktlim@umich.edu# Now create a Builder object that uses isa_parser.py to generate C++
1122766Sktlim@umich.edu# output from the ISA description (*.isa) files.
1132152SN/A#
1142152SN/A
1152152SN/A# Convert to File node to fix path
1162155SN/Aisa_parser = File('isa_parser.py')
1172152SN/Acpu_models_file = File('#m5/cpu/cpu_models.py')
1182152SN/A
1192718Sstever@eecs.umich.edu# This sucks in the defintions of the CpuModel objects.
1202921Sktlim@umich.eduexecfile(cpu_models_file.srcnode().abspath)
1212921Sktlim@umich.edu
1222921Sktlim@umich.edu# Several files are generated from the ISA description.
1232921Sktlim@umich.edu# We always get the basic decoder and header file.
1242921Sktlim@umich.eduisa_desc_gen_files = Split('decoder.cc decoder.hh')
1252921Sktlim@umich.edu# We also get an execute file for each selected CPU model.
1262921Sktlim@umich.eduisa_desc_gen_files += [CpuModel.dict[cpu].filename
1272921Sktlim@umich.edu                       for cpu in env['CPU_MODELS']]
1282921Sktlim@umich.edu
1292152SN/A# The emitter patches up the sources & targets to include the
1302152SN/A# autogenerated files as targets and isa parser itself as a source.
1312152SN/Adef isa_desc_emitter(target, source, env):
1322152SN/A    return (isa_desc_gen_files, [isa_parser, cpu_models_file] + source)
1332152SN/A
1342152SN/A# Pieces are in place, so create the builder.
1352152SN/Aisa_desc_builder = Builder(action='python $SOURCES $TARGET.dir $CPU_MODELS',
1362152SN/A                           emitter = isa_desc_emitter)
1372152SN/A
1382152SN/Aenv.Append(BUILDERS = { 'ISADesc' : isa_desc_builder })
1392667Sstever@eecs.umich.edu
1402152SN/A#
1412152SN/A# Now include other ISA-specific sources from the ISA subdirectories.
142#
143
144isa = env['TARGET_ISA'] # someday this may be a list of ISAs
145
146# Let the target architecture define what additional sources it needs
147sources += SConscript(os.path.join(isa, 'SConscript'),
148                      exports = 'env', duplicate = False)
149
150Return('sources')
151