SConscript revision 2178
12SN/A# -*- mode:python -*-
213954Sgiacomo.gabrielli@arm.com
39920Syasuko.eckert@amd.com# Copyright (c) 2006 The Regents of The University of Michigan
47338SAli.Saidi@ARM.com# All rights reserved.
57338SAli.Saidi@ARM.com#
67338SAli.Saidi@ARM.com# Redistribution and use in source and binary forms, with or without
77338SAli.Saidi@ARM.com# modification, are permitted provided that the following conditions are
87338SAli.Saidi@ARM.com# met: redistributions of source code must retain the above copyright
97338SAli.Saidi@ARM.com# notice, this list of conditions and the following disclaimer;
107338SAli.Saidi@ARM.com# redistributions in binary form must reproduce the above copyright
117338SAli.Saidi@ARM.com# notice, this list of conditions and the following disclaimer in the
127338SAli.Saidi@ARM.com# documentation and/or other materials provided with the distribution;
137338SAli.Saidi@ARM.com# neither the name of the copyright holders nor the names of its
147338SAli.Saidi@ARM.com# contributors may be used to endorse or promote products derived from
151762SN/A# this software without specific prior written permission.
162SN/A#
172SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
182SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
192SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
202SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
212SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
222SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
232SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
242SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
252SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
262SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
272SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
282SN/A
292SN/Aimport os.path
302SN/A
312SN/A# Import build environment variable from SConstruct.
322SN/AImport('env')
332SN/A
342SN/A# Right now there are no source files immediately in this directory
352SN/Asources = []
362SN/A
372SN/A#################################################################
382SN/A#
392SN/A# ISA "switch header" generation.
402665Ssaidi@eecs.umich.edu#
412665Ssaidi@eecs.umich.edu# Auto-generate arch headers that include the right ISA-specific
422SN/A# header based on the setting of THE_ISA preprocessor variable.
432SN/A#
4411793Sbrandon.potter@amd.com#################################################################
4511793Sbrandon.potter@amd.com
468779Sgblack@eecs.umich.edu# List of headers to generate
472439SN/Aisa_switch_hdrs = Split('''
488779Sgblack@eecs.umich.edu	isa_traits.hh
496216Snate@binkert.org        ''')
50146SN/A
51146SN/A# Generate the header.  target[0] is the full path of the output
5211793Sbrandon.potter@amd.com# header to generate.  'source' is a dummy variable, since we get the
5312334Sgabeblack@google.com# list of ISAs from env['ALL_ISA_LIST'].
54146SN/Adef gen_switch_hdr(target, source, env):
55146SN/A    fname = str(target[0])
566216Snate@binkert.org    basename = os.path.basename(fname)
576658Snate@binkert.org    f = open(fname, 'w')
581717SN/A    f.write('#include "arch/isa_specific.hh"\n')
598887Sgeoffrey.blake@arm.com    cond = '#if'
608887Sgeoffrey.blake@arm.com    for isa in env['ALL_ISA_LIST']:
61146SN/A        f.write('%s THE_ISA == %s_ISA\n#include "arch/%s/%s"\n'
6210061Sandreas@sandberg.pp.se                % (cond, isa.upper(), isa, basename))
631977SN/A        cond = '#elif'
6411147Smitch.hayenga@arm.com    f.write('#else\n#error "THE_ISA not set"\n#endif\n')
652683Sktlim@umich.edu    f.close()
661717SN/A    return 0
67146SN/A
682683Sktlim@umich.edu# String to print when generating header
698232Snate@binkert.orgdef gen_switch_hdr_string(target, source, env):
708232Snate@binkert.org    return "Generating ISA switch header " + str(target[0])
718232Snate@binkert.org
723348Sbinkertn@umich.edu# Build SCons Action object. 'varlist' specifies env vars that this
736105Ssteve.reinhardt@amd.com# action depends on; when env['ALL_ISA_LIST'] changes these actions
746216Snate@binkert.org# should get re-executed.
752036SN/Aswitch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string,
76146SN/A                           varlist=['ALL_ISA_LIST'])
778817Sgblack@eecs.umich.edu
788793Sgblack@eecs.umich.edu# Instantiate actions for each header
7956SN/Afor hdr in isa_switch_hdrs:
8056SN/A    env.Command(hdr, [], switch_hdr_action)
81695SN/A
822901Ssaidi@eecs.umich.edu#################################################################
832SN/A#
842SN/A# Include architecture-specific files.
852449SN/A#
861355SN/A#################################################################
875529Snate@binkert.org
8810061Sandreas@sandberg.pp.se#
8911147Smitch.hayenga@arm.com# Build a SCons scanner for ISA files
9010061Sandreas@sandberg.pp.se#
9111147Smitch.hayenga@arm.comimport SCons.Scanner
9211147Smitch.hayenga@arm.com
9311147Smitch.hayenga@arm.comdef ISAScan():
94224SN/A   return SCons.Scanner.Classic("ISAScan",
9511147Smitch.hayenga@arm.com                                "$ISASUFFIXES",
962SN/A                                "SRCDIR",
9711147Smitch.hayenga@arm.com                                '^[ \t]*##[ \t]*include[ \t]*"([^>"]+)"')
9811147Smitch.hayenga@arm.com
9911147Smitch.hayenga@arm.comdef ISAPath(env, dir, target=None, source=None, a=None):
10011147Smitch.hayenga@arm.com   return (Dir(env['SRCDIR']), Dir('.'))   
10111147Smitch.hayenga@arm.com
10211147Smitch.hayenga@arm.comiscan = Scanner(function = ISAScan().scan, skeys = [".isa", ".ISA"],
10311147Smitch.hayenga@arm.com                path_function = ISAPath)
10411147Smitch.hayenga@arm.comenv.Append(SCANNERS = iscan)
10511147Smitch.hayenga@arm.com
10611147Smitch.hayenga@arm.com#
10711147Smitch.hayenga@arm.com# Now create a Builder object that uses isa_parser.py to generate C++
10811147Smitch.hayenga@arm.com# output from the ISA description (*.isa) files.
1092SN/A#
1108733Sgeoffrey.blake@arm.com
11111147Smitch.hayenga@arm.com# Convert to File node to fix path
11211147Smitch.hayenga@arm.comisa_parser = File('isa_parser.py')
11311147Smitch.hayenga@arm.comcpu_models_file = File('#m5/cpu/cpu_models.py')
1148733Sgeoffrey.blake@arm.com
1158733Sgeoffrey.blake@arm.com# This sucks in the defintions of the CpuModel objects.
1168733Sgeoffrey.blake@arm.comexecfile(cpu_models_file.srcnode().abspath)
1178733Sgeoffrey.blake@arm.com
11811147Smitch.hayenga@arm.com# Several files are generated from the ISA description.
11911147Smitch.hayenga@arm.com# We always get the basic decoder and header file.
1208733Sgeoffrey.blake@arm.comisa_desc_gen_files = Split('decoder.cc decoder.hh')
1218733Sgeoffrey.blake@arm.com# We also get an execute file for each selected CPU model.
1228733Sgeoffrey.blake@arm.comisa_desc_gen_files += [CpuModel.dict[cpu].filename
12311147Smitch.hayenga@arm.com                       for cpu in env['CPU_MODELS']]
1248733Sgeoffrey.blake@arm.com
12511147Smitch.hayenga@arm.com# The emitter patches up the sources & targets to include the
12611147Smitch.hayenga@arm.com# autogenerated files as targets and isa parser itself as a source.
12711147Smitch.hayenga@arm.comdef isa_desc_emitter(target, source, env):
12811147Smitch.hayenga@arm.com    return (isa_desc_gen_files, [isa_parser, cpu_models_file] + source)
1292SN/A
13011147Smitch.hayenga@arm.com# Pieces are in place, so create the builder.
13111147Smitch.hayenga@arm.comisa_desc_builder = Builder(action='$SOURCES $TARGET.dir $CPU_MODELS',
13211147Smitch.hayenga@arm.com                           source_scanner = iscan,
1334377Sgblack@eecs.umich.edu                           emitter = isa_desc_emitter)
13411147Smitch.hayenga@arm.com
13511147Smitch.hayenga@arm.comenv.Append(BUILDERS = { 'ISADesc' : isa_desc_builder })
13611147Smitch.hayenga@arm.com
13711147Smitch.hayenga@arm.com#
13811147Smitch.hayenga@arm.com# Now include other ISA-specific sources from the ISA subdirectories.
13911147Smitch.hayenga@arm.com#
1405169Ssaidi@eecs.umich.edu
14111147Smitch.hayenga@arm.comisa = env['TARGET_ISA'] # someday this may be a list of ISAs
14211147Smitch.hayenga@arm.com
14311147Smitch.hayenga@arm.com# Let the target architecture define what additional sources it needs
14411147Smitch.hayenga@arm.comsources += SConscript(os.path.join(isa, 'SConscript'),
14511147Smitch.hayenga@arm.com                      exports = 'env', duplicate = False)
14611147Smitch.hayenga@arm.com
14711147Smitch.hayenga@arm.comReturn('sources')
14811147Smitch.hayenga@arm.com