SConscript revision 3536
12155SN/A# -*- mode:python -*-
22155SN/A
32155SN/A# Copyright (c) 2006 The Regents of The University of Michigan
42155SN/A# All rights reserved.
52155SN/A#
62155SN/A# Redistribution and use in source and binary forms, with or without
72155SN/A# modification, are permitted provided that the following conditions are
82155SN/A# met: redistributions of source code must retain the above copyright
92155SN/A# notice, this list of conditions and the following disclaimer;
102155SN/A# redistributions in binary form must reproduce the above copyright
112155SN/A# notice, this list of conditions and the following disclaimer in the
122155SN/A# documentation and/or other materials provided with the distribution;
132155SN/A# neither the name of the copyright holders nor the names of its
142155SN/A# contributors may be used to endorse or promote products derived from
152155SN/A# this software without specific prior written permission.
162155SN/A#
172155SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
182155SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
192155SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
202155SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
212155SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
222155SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
232155SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
242155SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
252155SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
262155SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
272155SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
282665Ssaidi@eecs.umich.edu#
292665Ssaidi@eecs.umich.edu# Authors: Steve Reinhardt
302155SN/A
312155SN/Aimport os.path, sys
322155SN/A
332155SN/A# Import build environment variable from SConstruct.
342155SN/AImport('env')
352155SN/A
362155SN/A# Right now there are no source files immediately in this directory
372178SN/Asources = []
382178SN/A
392178SN/A#################################################################
402178SN/A#
412178SN/A# ISA "switch header" generation.
422178SN/A#
432178SN/A# Auto-generate arch headers that include the right ISA-specific
442178SN/A# header based on the setting of THE_ISA preprocessor variable.
452178SN/A#
462178SN/A#################################################################
472178SN/A
482178SN/A# List of headers to generate
492155SN/Aisa_switch_hdrs = Split('''
502178SN/A	arguments.hh
512155SN/A	faults.hh
522155SN/A	interrupts.hh
532178SN/A	isa_traits.hh
542155SN/A        locked_mem.hh
552155SN/A	process.hh
562623SN/A	regfile.hh
572623SN/A	remote_gdb.hh
582623SN/A	stacktrace.hh
592623SN/A	syscallreturn.hh
602623SN/A	tlb.hh
612155SN/A	types.hh
622155SN/A	utility.hh
632292SN/A	vtophys.hh
642292SN/A        ''')
652292SN/A
662292SN/A# Generate the header.  target[0] is the full path of the output
672292SN/A# header to generate.  'source' is a dummy variable, since we get the
682292SN/A# list of ISAs from env['ALL_ISA_LIST'].
692292SN/Adef gen_switch_hdr(target, source, env):
702292SN/A    fname = str(target[0])
712766Sktlim@umich.edu    basename = os.path.basename(fname)
722766Sktlim@umich.edu    f = open(fname, 'w')
732766Sktlim@umich.edu    f.write('#include "arch/isa_specific.hh"\n')
742921Sktlim@umich.edu    cond = '#if'
752921Sktlim@umich.edu    for isa in env['ALL_ISA_LIST']:
762766Sktlim@umich.edu        f.write('%s THE_ISA == %s_ISA\n#include "arch/%s/%s"\n'
772766Sktlim@umich.edu                % (cond, isa.upper(), isa, basename))
782766Sktlim@umich.edu        cond = '#elif'
792178SN/A    f.write('#else\n#error "THE_ISA not set"\n#endif\n')
802155SN/A    f.close()
812155SN/A    return 0
822155SN/A
832155SN/A# String to print when generating header
842155SN/Adef gen_switch_hdr_string(target, source, env):
852155SN/A    return "Generating ISA switch header " + str(target[0])
862766Sktlim@umich.edu
872155SN/A# Build SCons Action object. 'varlist' specifies env vars that this
882623SN/A# action depends on; when env['ALL_ISA_LIST'] changes these actions
892155SN/A# should get re-executed.
902155SN/Aswitch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string,
912155SN/A                           varlist=['ALL_ISA_LIST'])
922155SN/A
932178SN/A# Instantiate actions for each header
942178SN/Afor hdr in isa_switch_hdrs:
952178SN/A    env.Command(hdr, [], switch_hdr_action)
962766Sktlim@umich.edu
972178SN/A#################################################################
982178SN/A#
992178SN/A# Include architecture-specific files.
1002178SN/A#
1012766Sktlim@umich.edu#################################################################
1022766Sktlim@umich.edu
1032766Sktlim@umich.edu#
1042788Sktlim@umich.edu# Build a SCons scanner for ISA files
1052178SN/A#
1062733Sktlim@umich.eduimport SCons.Scanner
1072733Sktlim@umich.edu
1082817Sksewell@umich.eduisa_scanner = SCons.Scanner.Classic("ISAScan",
1092733Sktlim@umich.edu                                    [".isa", ".ISA"],
1102178SN/A                                    "SRCDIR",
1112178SN/A                                    r'^\s*##include\s+"([\w/.-]*)"')
1122178SN/A
1132178SN/Aenv.Append(SCANNERS = isa_scanner)
1142178SN/A
1152178SN/A#
1162155SN/A# Now create a Builder object that uses isa_parser.py to generate C++
1172929Sktlim@umich.edu# output from the ISA description (*.isa) files.
1182929Sktlim@umich.edu#
1192929Sktlim@umich.edu
1202155SN/A# Convert to File node to fix path
1212155SN/Aisa_parser = File('isa_parser.py')
1222623SN/Acpu_models_file = File('../cpu/cpu_models.py')
1232623SN/A
1242623SN/A# This sucks in the defintions of the CpuModel objects.
1252623SN/Aexecfile(cpu_models_file.srcnode().abspath)
1262623SN/A
1272623SN/A# Several files are generated from the ISA description.
1282623SN/A# We always get the basic decoder and header file.
1292623SN/Aisa_desc_gen_files = Split('decoder.cc decoder.hh')
1302623SN/A# We also get an execute file for each selected CPU model.
1312623SN/Aisa_desc_gen_files += [CpuModel.dict[cpu].filename
1322623SN/A                       for cpu in env['CPU_MODELS']]
1332155SN/A
1342155SN/A# Also include the CheckerCPU as one of the models if it is being
1352155SN/A# enabled via command line.
1362155SN/Aif env['USE_CHECKER']:
1372821Sktlim@umich.edu    isa_desc_gen_files += [CpuModel.dict['CheckerCPU'].filename]
1382817Sksewell@umich.edu
1392821Sktlim@umich.edu# The emitter patches up the sources & targets to include the
1402817Sksewell@umich.edu# autogenerated files as targets and isa parser itself as a source.
1412155SN/Adef isa_desc_emitter(target, source, env):
1422765Sktlim@umich.edu    return (isa_desc_gen_files, [isa_parser, cpu_models_file] + source)
1432155SN/A
1442155SN/A# Pieces are in place, so create the builder.
1452155SN/Apython = sys.executable  # use same Python binary used to run scons
1462155SN/A
1472155SN/A# Also include the CheckerCPU as one of the models if it is being
1482292SN/A# enabled via command line.
1492155SN/Aif env['USE_CHECKER']:
1502155SN/A    isa_desc_builder = Builder(action=python + ' $SOURCES $TARGET.dir $CPU_MODELS CheckerCPU',
1512155SN/A                               emitter = isa_desc_emitter)
1522292SN/Aelse:
1532292SN/A    isa_desc_builder = Builder(action=python + ' $SOURCES $TARGET.dir $CPU_MODELS',
1542155SN/A                               emitter = isa_desc_emitter)
1552155SN/A
1562155SN/Aenv.Append(BUILDERS = { 'ISADesc' : isa_desc_builder })
1572155SN/A
1582292SN/A#
1592155SN/A# Now include other ISA-specific sources from the ISA subdirectories.
1602155SN/A#
1612766Sktlim@umich.edu
1622765Sktlim@umich.eduisa = env['TARGET_ISA'] # someday this may be a list of ISAs
1632929Sktlim@umich.edu
1642155SN/A# Let the target architecture define what additional sources it needs
1652792Sktlim@umich.edusources += SConscript(os.path.join(isa, 'SConscript'), exports = 'env')
1662821Sktlim@umich.edu
1672292SN/AReturn('sources')
1682792Sktlim@umich.edu