SConscript revision 2171
1955SN/A# -*- mode:python -*-
2955SN/A
35871Snate@binkert.org# Copyright (c) 2006 The Regents of The University of Michigan
41762SN/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.
28955SN/A
292665Ssaidi@eecs.umich.eduimport os.path
302665Ssaidi@eecs.umich.edu
315863Snate@binkert.org# 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
372632Sstever@eecs.umich.edu#################################################################
382632Sstever@eecs.umich.edu#
392632Sstever@eecs.umich.edu# ISA "switch header" generation.
402632Sstever@eecs.umich.edu#
41955SN/A# Auto-generate arch headers that include the right ISA-specific
422632Sstever@eecs.umich.edu# header based on the setting of THE_ISA preprocessor variable.
432632Sstever@eecs.umich.edu#
442761Sstever@eecs.umich.edu#################################################################
452632Sstever@eecs.umich.edu
462632Sstever@eecs.umich.edu# List of headers to generate
472632Sstever@eecs.umich.eduisa_switch_hdrs = Split('''
482761Sstever@eecs.umich.edu	isa_traits.hh
492761Sstever@eecs.umich.edu	linux_process.hh
502761Sstever@eecs.umich.edu	tru64_process.hh
512632Sstever@eecs.umich.edu	tlb.hh
522632Sstever@eecs.umich.edu	aout_machdep.h
532761Sstever@eecs.umich.edu	ecoff_machdep.h
542761Sstever@eecs.umich.edu	arguments.hh
552761Sstever@eecs.umich.edu	stacktrace.hh
562761Sstever@eecs.umich.edu	vtophys.hh
572761Sstever@eecs.umich.edu	faults.hh
582632Sstever@eecs.umich.edu	ev5.hh
592632Sstever@eecs.umich.edu        ''')
602632Sstever@eecs.umich.edu
612632Sstever@eecs.umich.edu# Generate the header.  target[0] is the full path of the output
622632Sstever@eecs.umich.edu# header to generate.  'source' is a dummy variable, since we get the
632632Sstever@eecs.umich.edu# list of ISAs from env['ALL_ISA_LIST'].
642632Sstever@eecs.umich.edudef gen_switch_hdr(target, source, env):
65955SN/A    fname = str(target[0])
66955SN/A    basename = os.path.basename(fname)
67955SN/A    f = open(fname, 'w')
685863Snate@binkert.org    f.write('#include "arch/isa_specific.hh"\n')
695863Snate@binkert.org    cond = '#if'
705863Snate@binkert.org    for isa in env['ALL_ISA_LIST']:
715863Snate@binkert.org        f.write('%s THE_ISA == %s_ISA\n#include "arch/%s/%s"\n'
725863Snate@binkert.org                % (cond, isa.upper(), isa, basename))
735863Snate@binkert.org        cond = '#elif'
745863Snate@binkert.org    f.write('#else\n#error "THE_ISA not set"\n#endif\n')
755863Snate@binkert.org    f.close()
765863Snate@binkert.org    return 0
775863Snate@binkert.org
785863Snate@binkert.org# String to print when generating header
795863Snate@binkert.orgdef gen_switch_hdr_string(target, source, env):
805863Snate@binkert.org    return "Generating ISA switch header " + str(target[0])
815863Snate@binkert.org
825863Snate@binkert.org# Build SCons Action object. 'varlist' specifies env vars that this
835863Snate@binkert.org# action depdnds on; when env['ALL_ISA_LIST'] changes these actions
845863Snate@binkert.org# should get re-executed.
855863Snate@binkert.orgswitch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string,
865863Snate@binkert.org                           varlist=['ALL_ISA_LIST'])
875863Snate@binkert.org
885863Snate@binkert.org# Instantiate actions for each header
895863Snate@binkert.orgfor hdr in isa_switch_hdrs:
905863Snate@binkert.org    env.Command(hdr, [], switch_hdr_action)
915863Snate@binkert.org
925863Snate@binkert.org#################################################################
935863Snate@binkert.org#
945863Snate@binkert.org# Include architecture-specific files.
955863Snate@binkert.org#
965863Snate@binkert.org#################################################################
975863Snate@binkert.org
985863Snate@binkert.org#
99955SN/A# Build a SCons scanner for ISA files
1005396Ssaidi@eecs.umich.edu#
1015863Snate@binkert.orgimport SCons.Scanner
1025863Snate@binkert.org
1034202Sbinkertn@umich.edudef ISAScan():
1045863Snate@binkert.org   return SCons.Scanner.Classic("ISAScan",
1055863Snate@binkert.org                                "$ISASUFFIXES",
1065863Snate@binkert.org                                "SRCDIR",
1075863Snate@binkert.org                                '^[ \t]*##[ \t]*include[ \t]*"([^>"]+)"')
108955SN/A
1095273Sstever@gmail.comdef ISAPath(env, dir, target=None, source=None, a=None):
1105871Snate@binkert.org   return (Dir(env['SRCDIR']), Dir('.'))   
1115273Sstever@gmail.com
1125871Snate@binkert.orgiscan = Scanner(function = ISAScan().scan, skeys = [".isa", ".ISA"],
1135863Snate@binkert.org                path_function = ISAPath)
1145863Snate@binkert.orgenv.Append(SCANNERS = iscan)
1155863Snate@binkert.org
1165871Snate@binkert.org#
1175872Snate@binkert.org# Now create a Builder object that uses isa_parser.py to generate C++
1185872Snate@binkert.org# output from the ISA description (*.isa) files.
1195872Snate@binkert.org#
1205871Snate@binkert.org
1215871Snate@binkert.org# Convert to File node to fix path
1225871Snate@binkert.orgisa_parser = File('isa_parser.py')
1235871Snate@binkert.orgcpu_models_file = File('#m5/cpu/cpu_models.py')
1245871Snate@binkert.org
1255871Snate@binkert.org# This sucks in the defintions of the CpuModel objects.
1265871Snate@binkert.orgexecfile(cpu_models_file.srcnode().abspath)
1275871Snate@binkert.org
1285871Snate@binkert.org# Several files are generated from the ISA description.
1295871Snate@binkert.org# We always get the basic decoder and header file.
1305871Snate@binkert.orgisa_desc_gen_files = Split('decoder.cc decoder.hh')
1315871Snate@binkert.org# We also get an execute file for each selected CPU model.
1325871Snate@binkert.orgisa_desc_gen_files += [CpuModel.dict[cpu].filename
1335871Snate@binkert.org                       for cpu in env['CPU_MODELS']]
1345863Snate@binkert.org
1355227Ssaidi@eecs.umich.edu# The emitter patches up the sources & targets to include the
1365396Ssaidi@eecs.umich.edu# autogenerated files as targets and isa parser itself as a source.
1375396Ssaidi@eecs.umich.edudef isa_desc_emitter(target, source, env):
1385396Ssaidi@eecs.umich.edu    return (isa_desc_gen_files, [isa_parser, cpu_models_file] + source)
1395396Ssaidi@eecs.umich.edu
1405396Ssaidi@eecs.umich.edu# Pieces are in place, so create the builder.
1415396Ssaidi@eecs.umich.eduisa_desc_builder = Builder(action='$SOURCES $TARGET.dir $CPU_MODELS',
1425396Ssaidi@eecs.umich.edu                           source_scanner = iscan,
1435396Ssaidi@eecs.umich.edu                           emitter = isa_desc_emitter)
1445588Ssaidi@eecs.umich.edu
1455396Ssaidi@eecs.umich.eduenv.Append(BUILDERS = { 'ISADesc' : isa_desc_builder })
1465396Ssaidi@eecs.umich.edu
1475396Ssaidi@eecs.umich.edu#
1485396Ssaidi@eecs.umich.edu# Now include other ISA-specific sources from the ISA subdirectories.
1495396Ssaidi@eecs.umich.edu#
1505396Ssaidi@eecs.umich.edu
1515396Ssaidi@eecs.umich.eduisa = env['TARGET_ISA'] # someday this may be a list of ISAs
1525396Ssaidi@eecs.umich.edu
1535396Ssaidi@eecs.umich.edu# Let the target architecture define what additional sources it needs
1545396Ssaidi@eecs.umich.edusources += SConscript(os.path.join(isa, 'SConscript'),
1555396Ssaidi@eecs.umich.edu                      exports = 'env', duplicate = False)
1565396Ssaidi@eecs.umich.edu
1575396Ssaidi@eecs.umich.eduReturn('sources')
1585396Ssaidi@eecs.umich.edu