SConscript revision 2290
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
314202Sbinkertn@umich.edu# Import build environment variable from SConstruct.
328961Sgblack@eecs.umich.eduImport('env')
332139SN/A
344202Sbinkertn@umich.edu# Right now there are no source files immediately in this directory
352152SN/Asources = []
362152SN/A
372139SN/A#################################################################
382139SN/A#
392139SN/A# ISA "switch header" generation.
402139SN/A#
412139SN/A# Auto-generate arch headers that include the right ISA-specific
422152SN/A# header based on the setting of THE_ISA preprocessor variable.
432152SN/A#
442139SN/A#################################################################
452139SN/A
462139SN/A# List of headers to generate
479020Sgblack@eecs.umich.eduisa_switch_hdrs = Split('''
484781Snate@binkert.org	isa_traits.hh
497799Sgblack@eecs.umich.edu	tlb.hh
504781Snate@binkert.org	process.hh
514781Snate@binkert.org	arguments.hh
523170Sstever@eecs.umich.edu	stacktrace.hh
535664Sgblack@eecs.umich.edu	vtophys.hh
548105Sgblack@eecs.umich.edu	faults.hh
556179Sksewell@umich.edu        ''')
564781Snate@binkert.org
576329Sgblack@eecs.umich.edu# Generate the header.  target[0] is the full path of the output
584781Snate@binkert.org# header to generate.  'source' is a dummy variable, since we get the
594781Snate@binkert.org# list of ISAs from env['ALL_ISA_LIST'].
604781Snate@binkert.orgdef gen_switch_hdr(target, source, env):
614781Snate@binkert.org    fname = str(target[0])
624781Snate@binkert.org    basename = os.path.basename(fname)
634781Snate@binkert.org    f = open(fname, 'w')
642139SN/A    f.write('#include "arch/isa_specific.hh"\n')
652139SN/A    cond = '#if'
663546Sgblack@eecs.umich.edu    for isa in env['ALL_ISA_LIST']:
674202Sbinkertn@umich.edu        f.write('%s THE_ISA == %s_ISA\n#include "arch/%s/%s"\n'
682152SN/A                % (cond, isa.upper(), isa, basename))
692152SN/A        cond = '#elif'
702152SN/A    f.write('#else\n#error "THE_ISA not set"\n#endif\n')
712152SN/A    f.close()
722152SN/A    return 0
732152SN/A
742152SN/A# String to print when generating header
752152SN/Adef gen_switch_hdr_string(target, source, env):
762152SN/A    return "Generating ISA switch header " + str(target[0])
772152SN/A
782152SN/A# Build SCons Action object. 'varlist' specifies env vars that this
792152SN/A# action depends on; when env['ALL_ISA_LIST'] changes these actions
802504SN/A# should get re-executed.
812504SN/Aswitch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string,
822504SN/A                           varlist=['ALL_ISA_LIST'])
832504SN/A
842152SN/A# Instantiate actions for each header
852504SN/Afor hdr in isa_switch_hdrs:
862152SN/A    env.Command(hdr, [], switch_hdr_action)
872152SN/A
882152SN/A#################################################################
892152SN/A#
902152SN/A# Include architecture-specific files.
912152SN/A#
928584Sgblack@eecs.umich.edu#################################################################
938584Sgblack@eecs.umich.edu
946993Snate@binkert.org#
956993Snate@binkert.org# Build a SCons scanner for ISA files
966993Snate@binkert.org#
976993Snate@binkert.orgimport SCons.Scanner
988887Sgeoffrey.blake@arm.com
996993Snate@binkert.orgdef ISAScan():
1006993Snate@binkert.org   return SCons.Scanner.Classic("ISAScan",
1016993Snate@binkert.org                                "$ISASUFFIXES",
1026993Snate@binkert.org                                "SRCDIR",
1036993Snate@binkert.org                                '^[ \t]*##[ \t]*include[ \t]*"([^>"]+)"')
1046993Snate@binkert.org
1056993Snate@binkert.orgdef ISAPath(env, dir, target=None, source=None, a=None):
1068584Sgblack@eecs.umich.edu   return (Dir(env['SRCDIR']), Dir('.'))   
1078584Sgblack@eecs.umich.edu
1088584Sgblack@eecs.umich.eduiscan = Scanner(function = ISAScan().scan, skeys = [".isa", ".ISA"],
1098584Sgblack@eecs.umich.edu                path_function = ISAPath)
1108584Sgblack@eecs.umich.eduenv.Append(SCANNERS = iscan)
1118961Sgblack@eecs.umich.edu
1126993Snate@binkert.org#
1136993Snate@binkert.org# Now create a Builder object that uses isa_parser.py to generate C++
1146993Snate@binkert.org# output from the ISA description (*.isa) files.
1156998Snate@binkert.org#
1166998Snate@binkert.org
1176998Snate@binkert.org# Convert to File node to fix path
1187756SAli.Saidi@ARM.comisa_parser = File('isa_parser.py')
1196993Snate@binkert.orgcpu_models_file = File('#m5/cpu/cpu_models.py')
1206993Snate@binkert.org
1216993Snate@binkert.org# This sucks in the defintions of the CpuModel objects.
1226993Snate@binkert.orgexecfile(cpu_models_file.srcnode().abspath)
1238585Sgblack@eecs.umich.edu
1248584Sgblack@eecs.umich.edu# Several files are generated from the ISA description.
1256993Snate@binkert.org# We always get the basic decoder and header file.
1266993Snate@binkert.orgisa_desc_gen_files = Split('decoder.cc decoder.hh')
1276993Snate@binkert.org# We also get an execute file for each selected CPU model.
1287816Ssteve.reinhardt@amd.comisa_desc_gen_files += [CpuModel.dict[cpu].filename
1292152SN/A                       for cpu in env['CPU_MODELS']]
1302766Sktlim@umich.edu
1312766Sktlim@umich.edu# The emitter patches up the sources & targets to include the
1326993Snate@binkert.org# autogenerated files as targets and isa parser itself as a source.
1332152SN/Adef isa_desc_emitter(target, source, env):
1342152SN/A    return (isa_desc_gen_files, [isa_parser, cpu_models_file] + source)
1355944Sgblack@eecs.umich.edu
1368335Snate@binkert.org# Pieces are in place, so create the builder.
1378335Snate@binkert.orgisa_desc_builder = Builder(action='$SOURCES $TARGET.dir $CPU_MODELS',
1389920Syasuko.eckert@amd.com                           source_scanner = iscan,
1398335Snate@binkert.org                           emitter = isa_desc_emitter)
1409920Syasuko.eckert@amd.com
141env.Append(BUILDERS = { 'ISADesc' : isa_desc_builder })
142
143#
144# Now include other ISA-specific sources from the ISA subdirectories.
145#
146
147isa = env['TARGET_ISA'] # someday this may be a list of ISAs
148
149# Let the target architecture define what additional sources it needs
150sources += SConscript(os.path.join(isa, 'SConscript'),
151                      exports = 'env', duplicate = False)
152
153Return('sources')
154