SConscript revision 2632:1bb2f91485ea
1955SN/A# -*- mode:python -*-
2955SN/A
31762SN/A# Copyright (c) 2006 The Regents of The University of Michigan
4955SN/A# All rights reserved.
5955SN/A#
6955SN/A# Redistribution and use in source and binary forms, with or without
7955SN/A# modification, are permitted provided that the following conditions are
8955SN/A# met: redistributions of source code must retain the above copyright
9955SN/A# notice, this list of conditions and the following disclaimer;
10955SN/A# redistributions in binary form must reproduce the above copyright
11955SN/A# notice, this list of conditions and the following disclaimer in the
12955SN/A# documentation and/or other materials provided with the distribution;
13955SN/A# neither the name of the copyright holders nor the names of its
14955SN/A# contributors may be used to endorse or promote products derived from
15955SN/A# this software without specific prior written permission.
16955SN/A#
17955SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26955SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27955SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
282665Ssaidi@eecs.umich.edu
292665Ssaidi@eecs.umich.eduimport os.path
30955SN/A
31955SN/A# Import build environment variable from SConstruct.
32955SN/AImport('env')
33955SN/A
34955SN/A# Right now there are no source files immediately in this directory
352632Sstever@eecs.umich.edusources = []
362632Sstever@eecs.umich.edu
372632Sstever@eecs.umich.edu#################################################################
382632Sstever@eecs.umich.edu#
39955SN/A# ISA "switch header" generation.
402632Sstever@eecs.umich.edu#
412632Sstever@eecs.umich.edu# Auto-generate arch headers that include the right ISA-specific
422761Sstever@eecs.umich.edu# header based on the setting of THE_ISA preprocessor variable.
432632Sstever@eecs.umich.edu#
442632Sstever@eecs.umich.edu#################################################################
452632Sstever@eecs.umich.edu
462761Sstever@eecs.umich.edu# List of headers to generate
472761Sstever@eecs.umich.eduisa_switch_hdrs = Split('''
482761Sstever@eecs.umich.edu	arguments.hh
492632Sstever@eecs.umich.edu	constants.hh
502632Sstever@eecs.umich.edu	faults.hh
512761Sstever@eecs.umich.edu	isa_traits.hh
522761Sstever@eecs.umich.edu	process.hh
532761Sstever@eecs.umich.edu	regfile.hh
542761Sstever@eecs.umich.edu	stacktrace.hh
552761Sstever@eecs.umich.edu	tlb.hh
562632Sstever@eecs.umich.edu	types.hh
572632Sstever@eecs.umich.edu	utility.hh
582632Sstever@eecs.umich.edu	vtophys.hh
592632Sstever@eecs.umich.edu        ''')
602632Sstever@eecs.umich.edu
612632Sstever@eecs.umich.edu# Generate the header.  target[0] is the full path of the output
622632Sstever@eecs.umich.edu# header to generate.  'source' is a dummy variable, since we get the
63955SN/A# list of ISAs from env['ALL_ISA_LIST'].
64955SN/Adef gen_switch_hdr(target, source, env):
65955SN/A    fname = str(target[0])
66955SN/A    basename = os.path.basename(fname)
67955SN/A    f = open(fname, 'w')
68955SN/A    f.write('#include "arch/isa_specific.hh"\n')
69955SN/A    cond = '#if'
702656Sstever@eecs.umich.edu    for isa in env['ALL_ISA_LIST']:
712656Sstever@eecs.umich.edu        f.write('%s THE_ISA == %s_ISA\n#include "arch/%s/%s"\n'
722656Sstever@eecs.umich.edu                % (cond, isa.upper(), isa, basename))
732656Sstever@eecs.umich.edu        cond = '#elif'
742656Sstever@eecs.umich.edu    f.write('#else\n#error "THE_ISA not set"\n#endif\n')
752656Sstever@eecs.umich.edu    f.close()
762656Sstever@eecs.umich.edu    return 0
772653Sstever@eecs.umich.edu
782653Sstever@eecs.umich.edu# String to print when generating header
792653Sstever@eecs.umich.edudef gen_switch_hdr_string(target, source, env):
802653Sstever@eecs.umich.edu    return "Generating ISA switch header " + str(target[0])
812653Sstever@eecs.umich.edu
822653Sstever@eecs.umich.edu# Build SCons Action object. 'varlist' specifies env vars that this
832653Sstever@eecs.umich.edu# action depends on; when env['ALL_ISA_LIST'] changes these actions
842653Sstever@eecs.umich.edu# should get re-executed.
852653Sstever@eecs.umich.eduswitch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string,
862653Sstever@eecs.umich.edu                           varlist=['ALL_ISA_LIST'])
872653Sstever@eecs.umich.edu
881852SN/A# Instantiate actions for each header
89955SN/Afor hdr in isa_switch_hdrs:
90955SN/A    env.Command(hdr, [], switch_hdr_action)
91955SN/A
922632Sstever@eecs.umich.edu#################################################################
932632Sstever@eecs.umich.edu#
94955SN/A# Include architecture-specific files.
951533SN/A#
962632Sstever@eecs.umich.edu#################################################################
971533SN/A
98955SN/A#
99955SN/A# Build a SCons scanner for ISA files
1002632Sstever@eecs.umich.edu#
1012632Sstever@eecs.umich.eduimport SCons.Scanner
102955SN/A
103955SN/Aisa_scanner = SCons.Scanner.Classic("ISAScan",
104955SN/A                                    [".isa", ".ISA"],
105955SN/A                                    "SRCDIR",
1062632Sstever@eecs.umich.edu                                    r'^\s*##include\s+"([\w/.-]*)"')
107955SN/A
1082632Sstever@eecs.umich.eduenv.Append(SCANNERS = isa_scanner)
109955SN/A
110955SN/A#
1112632Sstever@eecs.umich.edu# Now create a Builder object that uses isa_parser.py to generate C++
1122632Sstever@eecs.umich.edu# output from the ISA description (*.isa) files.
1132632Sstever@eecs.umich.edu#
1142632Sstever@eecs.umich.edu
1152632Sstever@eecs.umich.edu# Convert to File node to fix path
1162632Sstever@eecs.umich.eduisa_parser = File('isa_parser.py')
1172632Sstever@eecs.umich.educpu_models_file = File('../cpu/cpu_models.py')
1182632Sstever@eecs.umich.edu
1192632Sstever@eecs.umich.edu# This sucks in the defintions of the CpuModel objects.
1202632Sstever@eecs.umich.eduexecfile(cpu_models_file.srcnode().abspath)
1212632Sstever@eecs.umich.edu
1223053Sstever@eecs.umich.edu# Several files are generated from the ISA description.
1233053Sstever@eecs.umich.edu# We always get the basic decoder and header file.
1243053Sstever@eecs.umich.eduisa_desc_gen_files = Split('decoder.cc decoder.hh')
1253053Sstever@eecs.umich.edu# We also get an execute file for each selected CPU model.
1263053Sstever@eecs.umich.eduisa_desc_gen_files += [CpuModel.dict[cpu].filename
1273053Sstever@eecs.umich.edu                       for cpu in env['CPU_MODELS']]
1283053Sstever@eecs.umich.edu
1293053Sstever@eecs.umich.edu# The emitter patches up the sources & targets to include the
1303053Sstever@eecs.umich.edu# autogenerated files as targets and isa parser itself as a source.
1313053Sstever@eecs.umich.edudef isa_desc_emitter(target, source, env):
1323053Sstever@eecs.umich.edu    return (isa_desc_gen_files, [isa_parser, cpu_models_file] + source)
1333053Sstever@eecs.umich.edu
1343053Sstever@eecs.umich.edu# Pieces are in place, so create the builder.
1353053Sstever@eecs.umich.eduisa_desc_builder = Builder(action='python $SOURCES $TARGET.dir $CPU_MODELS',
1363053Sstever@eecs.umich.edu                           emitter = isa_desc_emitter)
1373053Sstever@eecs.umich.edu
1382632Sstever@eecs.umich.eduenv.Append(BUILDERS = { 'ISADesc' : isa_desc_builder })
1392632Sstever@eecs.umich.edu
1402632Sstever@eecs.umich.edu#
1412632Sstever@eecs.umich.edu# Now include other ISA-specific sources from the ISA subdirectories.
1422632Sstever@eecs.umich.edu#
1432632Sstever@eecs.umich.edu
1442634Sstever@eecs.umich.eduisa = env['TARGET_ISA'] # someday this may be a list of ISAs
1452634Sstever@eecs.umich.edu
1462632Sstever@eecs.umich.edu# Let the target architecture define what additional sources it needs
1472638Sstever@eecs.umich.edusources += SConscript(os.path.join(isa, 'SConscript'),
1482632Sstever@eecs.umich.edu                      exports = 'env', duplicate = False)
1492632Sstever@eecs.umich.edu
1502632Sstever@eecs.umich.eduReturn('sources')
1512632Sstever@eecs.umich.edu