SConscript revision 2139
16157Snate@binkert.org# -*- mode:python -*-
26157Snate@binkert.org
36157Snate@binkert.org# Copyright (c) 2006 The Regents of The University of Michigan
46157Snate@binkert.org# All rights reserved.
56157Snate@binkert.org#
66157Snate@binkert.org# Redistribution and use in source and binary forms, with or without
76157Snate@binkert.org# modification, are permitted provided that the following conditions are
86157Snate@binkert.org# met: redistributions of source code must retain the above copyright
96157Snate@binkert.org# notice, this list of conditions and the following disclaimer;
106157Snate@binkert.org# redistributions in binary form must reproduce the above copyright
116157Snate@binkert.org# notice, this list of conditions and the following disclaimer in the
126157Snate@binkert.org# documentation and/or other materials provided with the distribution;
136157Snate@binkert.org# neither the name of the copyright holders nor the names of its
146157Snate@binkert.org# contributors may be used to endorse or promote products derived from
156157Snate@binkert.org# this software without specific prior written permission.
166157Snate@binkert.org#
176157Snate@binkert.org# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
186157Snate@binkert.org# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
196157Snate@binkert.org# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
206157Snate@binkert.org# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
216157Snate@binkert.org# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
226157Snate@binkert.org# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
236157Snate@binkert.org# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
246157Snate@binkert.org# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
256157Snate@binkert.org# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
266157Snate@binkert.org# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
276157Snate@binkert.org# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
286157Snate@binkert.org
296157Snate@binkert.orgimport os.path
306157Snate@binkert.org
3112563Sgabeblack@google.com# Import build environment variable from SConstruct.
3212563Sgabeblack@google.comImport('env')
336157Snate@binkert.org
346157Snate@binkert.org#
356157Snate@binkert.org# ISA "switch header" generation.
366157Snate@binkert.org#
376157Snate@binkert.org# Auto-generate arch headers that include the right ISA-specific
386157Snate@binkert.org# header based on the setting of THE_ISA preprocessor variable.
396157Snate@binkert.org
4012246Sgabeblack@google.com# List of headers to generate
4112246Sgabeblack@google.comisa_switch_hdrs = Split('''
426157Snate@binkert.org	isa_traits.hh
436157Snate@binkert.org        ''')
4412892Sbrandon.potter@amd.com
4512892Sbrandon.potter@amd.com# Generate the header.  target[0] is the full path of the output
4612892Sbrandon.potter@amd.com# header to generate.  'source' is a dummy variable, since we get the
4710133Sandreas.hansson@arm.com# list of ISAs from env['ALL_ISA_LIST'].
4810133Sandreas.hansson@arm.comdef gen_switch_hdr(target, source, env):
4910133Sandreas.hansson@arm.com    fname = str(target[0])
5010133Sandreas.hansson@arm.com    basename = os.path.basename(fname)
5110133Sandreas.hansson@arm.com    f = open(fname, 'w')
5210133Sandreas.hansson@arm.com    f.write('#include "arch/isa_specific.hh"\n')
5310133Sandreas.hansson@arm.com    cond = '#if'
5410133Sandreas.hansson@arm.com    for isa in env['ALL_ISA_LIST']:
5510133Sandreas.hansson@arm.com        f.write('%s THE_ISA == %s_ISA\n#include "arch/%s/%s"\n'
5610133Sandreas.hansson@arm.com                % (cond, isa.upper(), isa, basename))
5710133Sandreas.hansson@arm.com        cond = '#elif'
5810133Sandreas.hansson@arm.com    f.write('#else\n#error "THE_ISA not set"\n#endif\n')
5910133Sandreas.hansson@arm.com    f.close()
6010133Sandreas.hansson@arm.com    return 0
6110133Sandreas.hansson@arm.com
6210133Sandreas.hansson@arm.com# String to print when generating header
6310133Sandreas.hansson@arm.comdef gen_switch_hdr_string(target, source, env):
6410133Sandreas.hansson@arm.com    return "Generating ISA switch header " + str(target[0])
6511755Sandreas.hansson@arm.com
6610133Sandreas.hansson@arm.com# Build SCons Action object. 'varlist' specifies env vars that this
6710133Sandreas.hansson@arm.com# action depdnds on; when env['ALL_ISA_LIST'] changes these actions
686157Snate@binkert.org# should get re-executed.
696157Snate@binkert.orgswitch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string,
706157Snate@binkert.org                           varlist=['ALL_ISA_LIST'])
716157Snate@binkert.org
726157Snate@binkert.org# Instantiate actions for each header
736157Snate@binkert.orgfor hdr in isa_switch_hdrs:
746157Snate@binkert.org    env.Command(hdr, [], switch_hdr_action)
756157Snate@binkert.org