SConscript revision 2874
112837Sgabeblack@google.com# -*- mode:python -*-
212837Sgabeblack@google.com
312837Sgabeblack@google.com# Copyright (c) 2006 The Regents of The University of Michigan
412837Sgabeblack@google.com# All rights reserved.
512837Sgabeblack@google.com#
612837Sgabeblack@google.com# Redistribution and use in source and binary forms, with or without
712837Sgabeblack@google.com# modification, are permitted provided that the following conditions are
812837Sgabeblack@google.com# met: redistributions of source code must retain the above copyright
912837Sgabeblack@google.com# notice, this list of conditions and the following disclaimer;
1012837Sgabeblack@google.com# redistributions in binary form must reproduce the above copyright
1112837Sgabeblack@google.com# notice, this list of conditions and the following disclaimer in the
1212837Sgabeblack@google.com# documentation and/or other materials provided with the distribution;
1312837Sgabeblack@google.com# neither the name of the copyright holders nor the names of its
1412837Sgabeblack@google.com# contributors may be used to endorse or promote products derived from
1512837Sgabeblack@google.com# this software without specific prior written permission.
1612837Sgabeblack@google.com#
1712837Sgabeblack@google.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1812837Sgabeblack@google.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1912837Sgabeblack@google.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2012837Sgabeblack@google.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2112837Sgabeblack@google.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2212837Sgabeblack@google.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2312837Sgabeblack@google.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2412837Sgabeblack@google.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2512837Sgabeblack@google.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2612837Sgabeblack@google.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2712837Sgabeblack@google.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2812837Sgabeblack@google.com#
2912837Sgabeblack@google.com# Authors: Steve Reinhardt
3012837Sgabeblack@google.com
3112837Sgabeblack@google.comimport os.path, sys
3212837Sgabeblack@google.com
3312860Sgabeblack@google.com# Import build environment variable from SConstruct.
3412860Sgabeblack@google.comImport('env')
3512860Sgabeblack@google.com
3612837Sgabeblack@google.com# Right now there are no source files immediately in this directory
3712837Sgabeblack@google.comsources = []
3812837Sgabeblack@google.com
3912837Sgabeblack@google.com#################################################################
4012837Sgabeblack@google.com#
4112837Sgabeblack@google.com# ISA "switch header" generation.
4212837Sgabeblack@google.com#
4312837Sgabeblack@google.com# Auto-generate arch headers that include the right ISA-specific
4412837Sgabeblack@google.com# header based on the setting of THE_ISA preprocessor variable.
4512860Sgabeblack@google.com#
4612860Sgabeblack@google.com#################################################################
4712860Sgabeblack@google.com
4812860Sgabeblack@google.com# List of headers to generate
4912860Sgabeblack@google.comisa_switch_hdrs = Split('''
5012860Sgabeblack@google.com	arguments.hh
5112860Sgabeblack@google.com	constants.hh
5212860Sgabeblack@google.com	faults.hh
5312860Sgabeblack@google.com	isa_traits.hh
5412860Sgabeblack@google.com	process.hh
5512860Sgabeblack@google.com	regfile.hh
5612860Sgabeblack@google.com	stacktrace.hh
5712860Sgabeblack@google.com	tlb.hh
5812860Sgabeblack@google.com	types.hh
5912860Sgabeblack@google.com	utility.hh
6012860Sgabeblack@google.com	vtophys.hh
6112860Sgabeblack@google.com        ''')
6212860Sgabeblack@google.com
6312860Sgabeblack@google.com# Generate the header.  target[0] is the full path of the output
6412860Sgabeblack@google.com# header to generate.  'source' is a dummy variable, since we get the
6512860Sgabeblack@google.com# list of ISAs from env['ALL_ISA_LIST'].
6612860Sgabeblack@google.comdef gen_switch_hdr(target, source, env):
6712860Sgabeblack@google.com    fname = str(target[0])
6812860Sgabeblack@google.com    basename = os.path.basename(fname)
6912860Sgabeblack@google.com    f = open(fname, 'w')
7012860Sgabeblack@google.com    f.write('#include "arch/isa_specific.hh"\n')
7112860Sgabeblack@google.com    cond = '#if'
7212860Sgabeblack@google.com    for isa in env['ALL_ISA_LIST']:
7312860Sgabeblack@google.com        f.write('%s THE_ISA == %s_ISA\n#include "arch/%s/%s"\n'
7412860Sgabeblack@google.com                % (cond, isa.upper(), isa, basename))
7512860Sgabeblack@google.com        cond = '#elif'
7612860Sgabeblack@google.com    f.write('#else\n#error "THE_ISA not set"\n#endif\n')
7712860Sgabeblack@google.com    f.close()
7812860Sgabeblack@google.com    return 0
7912860Sgabeblack@google.com
8012860Sgabeblack@google.com# String to print when generating header
8112860Sgabeblack@google.comdef gen_switch_hdr_string(target, source, env):
8212860Sgabeblack@google.com    return "Generating ISA switch header " + str(target[0])
8312860Sgabeblack@google.com
8412860Sgabeblack@google.com# Build SCons Action object. 'varlist' specifies env vars that this
8512860Sgabeblack@google.com# action depends on; when env['ALL_ISA_LIST'] changes these actions
8612860Sgabeblack@google.com# should get re-executed.
8712860Sgabeblack@google.comswitch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string,
8812860Sgabeblack@google.com                           varlist=['ALL_ISA_LIST'])
8912860Sgabeblack@google.com
9012860Sgabeblack@google.com# Instantiate actions for each header
9112860Sgabeblack@google.comfor hdr in isa_switch_hdrs:
9212860Sgabeblack@google.com    env.Command(hdr, [], switch_hdr_action)
9312860Sgabeblack@google.com
9412837Sgabeblack@google.com#################################################################
9512837Sgabeblack@google.com#
9612837Sgabeblack@google.com# Include architecture-specific files.
97#
98#################################################################
99
100#
101# Build a SCons scanner for ISA files
102#
103import SCons.Scanner
104
105isa_scanner = SCons.Scanner.Classic("ISAScan",
106                                    [".isa", ".ISA"],
107                                    "SRCDIR",
108                                    r'^\s*##include\s+"([\w/.-]*)"')
109
110env.Append(SCANNERS = isa_scanner)
111
112#
113# Now create a Builder object that uses isa_parser.py to generate C++
114# output from the ISA description (*.isa) files.
115#
116
117# Convert to File node to fix path
118isa_parser = File('isa_parser.py')
119cpu_models_file = File('../cpu/cpu_models.py')
120
121# This sucks in the defintions of the CpuModel objects.
122execfile(cpu_models_file.srcnode().abspath)
123
124# Several files are generated from the ISA description.
125# We always get the basic decoder and header file.
126isa_desc_gen_files = Split('decoder.cc decoder.hh')
127# We also get an execute file for each selected CPU model.
128isa_desc_gen_files += [CpuModel.dict[cpu].filename
129                       for cpu in env['CPU_MODELS']]
130
131# Also include the CheckerCPU as one of the models if it is being
132# enabled via command line.
133if env['USE_CHECKER']:
134    isa_desc_gen_files += [CpuModel.dict['CheckerCPU'].filename]
135
136# The emitter patches up the sources & targets to include the
137# autogenerated files as targets and isa parser itself as a source.
138def isa_desc_emitter(target, source, env):
139    return (isa_desc_gen_files, [isa_parser, cpu_models_file] + source)
140
141# Pieces are in place, so create the builder.
142python = sys.executable  # use same Python binary used to run scons
143isa_desc_builder = Builder(action=python + ' $SOURCES $TARGET.dir $CPU_MODELS',
144                           emitter = isa_desc_emitter)
145
146env.Append(BUILDERS = { 'ISADesc' : isa_desc_builder })
147
148#
149# Now include other ISA-specific sources from the ISA subdirectories.
150#
151
152isa = env['TARGET_ISA'] # someday this may be a list of ISAs
153
154# Let the target architecture define what additional sources it needs
155sources += SConscript(os.path.join(isa, 'SConscript'), exports = 'env')
156
157Return('sources')
158