SConscript revision 2504
11689SN/A# -*- mode:python -*-
210331Smitch.hayenga@arm.com
39916Ssteve.reinhardt@amd.com# Copyright (c) 2006 The Regents of The University of Michigan
48707Sandreas.hansson@arm.com# All rights reserved.
58707Sandreas.hansson@arm.com#
68707Sandreas.hansson@arm.com# Redistribution and use in source and binary forms, with or without
78707Sandreas.hansson@arm.com# modification, are permitted provided that the following conditions are
88707Sandreas.hansson@arm.com# met: redistributions of source code must retain the above copyright
98707Sandreas.hansson@arm.com# notice, this list of conditions and the following disclaimer;
108707Sandreas.hansson@arm.com# redistributions in binary form must reproduce the above copyright
118707Sandreas.hansson@arm.com# notice, this list of conditions and the following disclaimer in the
128707Sandreas.hansson@arm.com# documentation and/or other materials provided with the distribution;
138707Sandreas.hansson@arm.com# neither the name of the copyright holders nor the names of its
148707Sandreas.hansson@arm.com# contributors may be used to endorse or promote products derived from
152325SN/A# this software without specific prior written permission.
167897Shestness@cs.utexas.edu#
171689SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
181689SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
191689SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
201689SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
211689SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
221689SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
231689SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
241689SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
251689SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
261689SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
271689SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
281689SN/A
291689SN/Aimport os.path
301689SN/A
311689SN/A# Import build environment variable from SConstruct.
321689SN/AImport('env')
331689SN/A
341689SN/A# Right now there are no source files immediately in this directory
351689SN/Asources = []
361689SN/A
371689SN/A#################################################################
381689SN/A#
391689SN/A# ISA "switch header" generation.
401689SN/A#
412665Ssaidi@eecs.umich.edu# Auto-generate arch headers that include the right ISA-specific
422665Ssaidi@eecs.umich.edu# header based on the setting of THE_ISA preprocessor variable.
432756Sksewell@umich.edu#
447897Shestness@cs.utexas.edu#################################################################
451689SN/A
461689SN/A# List of headers to generate
478779Sgblack@eecs.umich.eduisa_switch_hdrs = Split('''
486658Snate@binkert.org	arguments.hh
498887Sgeoffrey.blake@arm.com	constants.hh
508887Sgeoffrey.blake@arm.com	faults.hh
518229Snate@binkert.org	isa_traits.hh
528229Snate@binkert.org	process.hh
538229Snate@binkert.org	regfile.hh
544762Snate@binkert.org	stacktrace.hh
558779Sgblack@eecs.umich.edu	tlb.hh
564762Snate@binkert.org	types.hh
574762Snate@binkert.org	utility.hh
588232Snate@binkert.org	vtophys.hh
599152Satgutier@umich.edu        ''')
608232Snate@binkert.org
618232Snate@binkert.org# Generate the header.  target[0] is the full path of the output
624762Snate@binkert.org# header to generate.  'source' is a dummy variable, since we get the
634762Snate@binkert.org# list of ISAs from env['ALL_ISA_LIST'].
648793Sgblack@eecs.umich.edudef gen_switch_hdr(target, source, env):
658779Sgblack@eecs.umich.edu    fname = str(target[0])
664762Snate@binkert.org    basename = os.path.basename(fname)
678460SAli.Saidi@ARM.com    f = open(fname, 'w')
684762Snate@binkert.org    f.write('#include "arch/isa_specific.hh"\n')
695702Ssaidi@eecs.umich.edu    cond = '#if'
705702Ssaidi@eecs.umich.edu    for isa in env['ALL_ISA_LIST']:
718232Snate@binkert.org        f.write('%s THE_ISA == %s_ISA\n#include "arch/%s/%s"\n'
725702Ssaidi@eecs.umich.edu                % (cond, isa.upper(), isa, basename))
735702Ssaidi@eecs.umich.edu        cond = '#elif'
748737Skoansin.tan@gmail.com    f.write('#else\n#error "THE_ISA not set"\n#endif\n')
755529Snate@binkert.org    f.close()
762669Sktlim@umich.edu    return 0
776221Snate@binkert.org
781060SN/A# String to print when generating header
795529Snate@binkert.orgdef gen_switch_hdr_string(target, source, env):
805712Shsul@eecs.umich.edu    return "Generating ISA switch header " + str(target[0])
811060SN/A
821060SN/A# Build SCons Action object. 'varlist' specifies env vars that this
831060SN/A# action depends on; when env['ALL_ISA_LIST'] changes these actions
842292SN/A# should get re-executed.
852733Sktlim@umich.eduswitch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string,
862292SN/A                           varlist=['ALL_ISA_LIST'])
872292SN/A
882292SN/A# Instantiate actions for each header
892292SN/Afor hdr in isa_switch_hdrs:
908707Sandreas.hansson@arm.com    env.Command(hdr, [], switch_hdr_action)
918707Sandreas.hansson@arm.com
928975Sandreas.hansson@arm.com#################################################################
938707Sandreas.hansson@arm.com#
948707Sandreas.hansson@arm.com# Include architecture-specific files.
958948Sandreas.hansson@arm.com#
968948Sandreas.hansson@arm.com#################################################################
978948Sandreas.hansson@arm.com
988707Sandreas.hansson@arm.com#
998707Sandreas.hansson@arm.com# Build a SCons scanner for ISA files
1008707Sandreas.hansson@arm.com#
1018707Sandreas.hansson@arm.comimport SCons.Scanner
1028707Sandreas.hansson@arm.com
1038707Sandreas.hansson@arm.comisa_scanner = SCons.Scanner.Classic("ISAScan",
1048707Sandreas.hansson@arm.com                                    [".isa", ".ISA"],
1058707Sandreas.hansson@arm.com                                    "SRCDIR",
1068707Sandreas.hansson@arm.com                                    r'^\s*##include\s+"([\w/.-]*)"')
1078707Sandreas.hansson@arm.com
1088707Sandreas.hansson@arm.comenv.Append(SCANNERS = isa_scanner)
1098707Sandreas.hansson@arm.com
1108707Sandreas.hansson@arm.com#
1118975Sandreas.hansson@arm.com# Now create a Builder object that uses isa_parser.py to generate C++
1128707Sandreas.hansson@arm.com# output from the ISA description (*.isa) files.
1138975Sandreas.hansson@arm.com#
1148707Sandreas.hansson@arm.com
1158707Sandreas.hansson@arm.com# Convert to File node to fix path
1168707Sandreas.hansson@arm.comisa_parser = File('isa_parser.py')
1178975Sandreas.hansson@arm.comcpu_models_file = File('#m5/cpu/cpu_models.py')
1188975Sandreas.hansson@arm.com
1198948Sandreas.hansson@arm.com# This sucks in the defintions of the CpuModel objects.
1208975Sandreas.hansson@arm.comexecfile(cpu_models_file.srcnode().abspath)
1218948Sandreas.hansson@arm.com
1228948Sandreas.hansson@arm.com# Several files are generated from the ISA description.
1238948Sandreas.hansson@arm.com# We always get the basic decoder and header file.
1248707Sandreas.hansson@arm.comisa_desc_gen_files = Split('decoder.cc decoder.hh')
1258707Sandreas.hansson@arm.com# We also get an execute file for each selected CPU model.
1268707Sandreas.hansson@arm.comisa_desc_gen_files += [CpuModel.dict[cpu].filename
1278707Sandreas.hansson@arm.com                       for cpu in env['CPU_MODELS']]
1288707Sandreas.hansson@arm.com
1298707Sandreas.hansson@arm.com# The emitter patches up the sources & targets to include the
1301060SN/A# autogenerated files as targets and isa parser itself as a source.
1311755SN/Adef isa_desc_emitter(target, source, env):
1325606Snate@binkert.org    return (isa_desc_gen_files, [isa_parser, cpu_models_file] + source)
1331060SN/A
1341060SN/A# Pieces are in place, so create the builder.
1351060SN/Aisa_desc_builder = Builder(action='python $SOURCES $TARGET.dir $CPU_MODELS',
1361060SN/A                           emitter = isa_desc_emitter)
1371060SN/A
1381755SN/Aenv.Append(BUILDERS = { 'ISADesc' : isa_desc_builder })
1391060SN/A
1401060SN/A#
1411060SN/A# Now include other ISA-specific sources from the ISA subdirectories.
1421060SN/A#
1431060SN/A
1441060SN/Aisa = env['TARGET_ISA'] # someday this may be a list of ISAs
1455336Shines@cs.fsu.edu
1461060SN/A# Let the target architecture define what additional sources it needs
1474873Sstever@eecs.umich.edusources += SConscript(os.path.join(isa, 'SConscript'),
1481060SN/A                      exports = 'env', duplicate = False)
1491060SN/A
1501060SN/AReturn('sources')
1515595Sgblack@eecs.umich.edu