SConscript revision 2152
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')
3310196SCurtis.Dunham@arm.com
342139SN/A# Right now there are no source files immediately in this directory
354202Sbinkertn@umich.edusources = []
362152SN/A
372152SN/A#################################################################
382139SN/A#
392139SN/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.
432152SN/A#
442152SN/A#################################################################
452139SN/A
462139SN/A# List of headers to generate
472139SN/Aisa_switch_hdrs = Split('''
489020Sgblack@eecs.umich.edu	isa_traits.hh
494781Snate@binkert.org        ''')
507799Sgblack@eecs.umich.edu
514781Snate@binkert.org# Generate the header.  target[0] is the full path of the output
524781Snate@binkert.org# header to generate.  'source' is a dummy variable, since we get the
533170Sstever@eecs.umich.edu# list of ISAs from env['ALL_ISA_LIST'].
545664Sgblack@eecs.umich.edudef gen_switch_hdr(target, source, env):
558105Sgblack@eecs.umich.edu    fname = str(target[0])
566179Sksewell@umich.edu    basename = os.path.basename(fname)
574781Snate@binkert.org    f = open(fname, 'w')
5810553Salexandru.dutu@amd.com    f.write('#include "arch/isa_specific.hh"\n')
596329Sgblack@eecs.umich.edu    cond = '#if'
604781Snate@binkert.org    for isa in env['ALL_ISA_LIST']:
614781Snate@binkert.org        f.write('%s THE_ISA == %s_ISA\n#include "arch/%s/%s"\n'
624781Snate@binkert.org                % (cond, isa.upper(), isa, basename))
634781Snate@binkert.org        cond = '#elif'
644781Snate@binkert.org    f.write('#else\n#error "THE_ISA not set"\n#endif\n')
654781Snate@binkert.org    f.close()
662139SN/A    return 0
672139SN/A
683546Sgblack@eecs.umich.edu# String to print when generating header
694202Sbinkertn@umich.edudef gen_switch_hdr_string(target, source, env):
702152SN/A    return "Generating ISA switch header " + str(target[0])
7111308Santhony.gutierrez@amd.com
7211308Santhony.gutierrez@amd.com# Build SCons Action object. 'varlist' specifies env vars that this
7311308Santhony.gutierrez@amd.com# action depdnds on; when env['ALL_ISA_LIST'] changes these actions
7411308Santhony.gutierrez@amd.com# should get re-executed.
7511308Santhony.gutierrez@amd.comswitch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string,
7611308Santhony.gutierrez@amd.com                           varlist=['ALL_ISA_LIST'])
7711308Santhony.gutierrez@amd.com
7811308Santhony.gutierrez@amd.com# Instantiate actions for each header
792152SN/Afor hdr in isa_switch_hdrs:
802152SN/A    env.Command(hdr, [], switch_hdr_action)
812152SN/A
822152SN/A#################################################################
832152SN/A#
842152SN/A# Include architecture-specific files.
852152SN/A#
862152SN/A#################################################################
872152SN/A
882152SN/A#
892152SN/A# Build a SCons scanner for ISA files
902504SN/A#
912504SN/Aimport SCons.Scanner
922504SN/A
932504SN/Adef ISAScan():
942152SN/A   return SCons.Scanner.Classic("ISAScan",
952504SN/A                                "$ISASUFFIXES",
962152SN/A                                "SRCDIR",
972152SN/A                                '^[ \t]*##[ \t]*include[ \t]*"([^>"]+)"')
982152SN/A
992152SN/Adef ISAPath(env, dir, target=None, source=None, a=None):
1002152SN/A   return (Dir(env['SRCDIR']), Dir('.'))   
1012152SN/A
1028584Sgblack@eecs.umich.eduiscan = Scanner(function = ISAScan().scan, skeys = [".isa", ".ISA"],
1038584Sgblack@eecs.umich.edu                path_function = ISAPath)
1046993Snate@binkert.orgenv.Append(SCANNERS = iscan)
1056993Snate@binkert.org
1066993Snate@binkert.org#
1078584Sgblack@eecs.umich.edu# Now create a Builder object that uses isa_parser.py to generate C++
10810319SAndreas.Sandberg@ARM.com# output from the ISA description (*.isa) files.
10910319SAndreas.Sandberg@ARM.com#
11010319SAndreas.Sandberg@ARM.com
11110319SAndreas.Sandberg@ARM.com# several files are generated from the ISA description
1128584Sgblack@eecs.umich.eduisa_desc_gen_files = Split('''
11310196SCurtis.Dunham@arm.com	decoder.cc
11410196SCurtis.Dunham@arm.com        alpha_o3_exec.cc
11510196SCurtis.Dunham@arm.com	fast_cpu_exec.cc
11610196SCurtis.Dunham@arm.com        simple_cpu_exec.cc
11710196SCurtis.Dunham@arm.com        full_cpu_exec.cc
11810196SCurtis.Dunham@arm.com	decoder.hh
11910196SCurtis.Dunham@arm.com        ''')
12010196SCurtis.Dunham@arm.com
12110196SCurtis.Dunham@arm.com# Convert to File node to fix path
12210196SCurtis.Dunham@arm.comisa_parser = File('isa_parser.py')
12310196SCurtis.Dunham@arm.com
12410196SCurtis.Dunham@arm.com# The emitter patches up the sources & targets to include the
12510196SCurtis.Dunham@arm.com# autogenerated files as targets and isa parser itself as a source.
12610196SCurtis.Dunham@arm.comdef isa_desc_emitter(target, source, env):
12710196SCurtis.Dunham@arm.com    return (isa_desc_gen_files, [isa_parser] + source)
12810196SCurtis.Dunham@arm.com
12910196SCurtis.Dunham@arm.com# Pieces are in place, so create the builder.
13010196SCurtis.Dunham@arm.comisa_desc_builder = Builder(action='${SOURCES[0]} ${SOURCES[1]} $TARGET.dir',
13110196SCurtis.Dunham@arm.com                           source_scanner = iscan,
13210196SCurtis.Dunham@arm.com                           emitter = isa_desc_emitter)
13310196SCurtis.Dunham@arm.com
1346993Snate@binkert.orgenv.Append(BUILDERS = { 'ISADesc' : isa_desc_builder })
1356993Snate@binkert.org
1366993Snate@binkert.org#
1376998Snate@binkert.org# Now include other ISA-specific sources from the ISA subdirectories.
1386998Snate@binkert.org#
1396998Snate@binkert.org
1407756SAli.Saidi@ARM.comisa = env['TARGET_ISA'] # someday this may be a list of ISAs
1416993Snate@binkert.org
1426993Snate@binkert.org# Let the target architecture define what additional sources it needs
1436993Snate@binkert.orgsources += SConscript(os.path.join(isa, 'SConscript'),
1446993Snate@binkert.org                      exports = 'env', duplicate = False)
1458585Sgblack@eecs.umich.edu
1468584Sgblack@eecs.umich.eduReturn('sources')
14710319SAndreas.Sandberg@ARM.com