SConscript revision 2155
1# -*- mode:python -*-
2
3# Copyright (c) 2006 The Regents of The University of Michigan
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions are
8# met: redistributions of source code must retain the above copyright
9# notice, this list of conditions and the following disclaimer;
10# redistributions in binary form must reproduce the above copyright
11# notice, this list of conditions and the following disclaimer in the
12# documentation and/or other materials provided with the distribution;
13# neither the name of the copyright holders nor the names of its
14# contributors may be used to endorse or promote products derived from
15# this software without specific prior written permission.
16#
17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29import os.path
30
31# Import build environment variable from SConstruct.
32Import('env')
33
34# Right now there are no source files immediately in this directory
35sources = []
36
37#################################################################
38#
39# ISA "switch header" generation.
40#
41# Auto-generate arch headers that include the right ISA-specific
42# header based on the setting of THE_ISA preprocessor variable.
43#
44#################################################################
45
46# List of headers to generate
47isa_switch_hdrs = Split('''
48	isa_traits.hh
49        ''')
50
51# Generate the header.  target[0] is the full path of the output
52# header to generate.  'source' is a dummy variable, since we get the
53# list of ISAs from env['ALL_ISA_LIST'].
54def gen_switch_hdr(target, source, env):
55    fname = str(target[0])
56    basename = os.path.basename(fname)
57    f = open(fname, 'w')
58    f.write('#include "arch/isa_specific.hh"\n')
59    cond = '#if'
60    for isa in env['ALL_ISA_LIST']:
61        f.write('%s THE_ISA == %s_ISA\n#include "arch/%s/%s"\n'
62                % (cond, isa.upper(), isa, basename))
63        cond = '#elif'
64    f.write('#else\n#error "THE_ISA not set"\n#endif\n')
65    f.close()
66    return 0
67
68# String to print when generating header
69def gen_switch_hdr_string(target, source, env):
70    return "Generating ISA switch header " + str(target[0])
71
72# Build SCons Action object. 'varlist' specifies env vars that this
73# action depdnds on; when env['ALL_ISA_LIST'] changes these actions
74# should get re-executed.
75switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string,
76                           varlist=['ALL_ISA_LIST'])
77
78# Instantiate actions for each header
79for hdr in isa_switch_hdrs:
80    env.Command(hdr, [], switch_hdr_action)
81
82#################################################################
83#
84# Include architecture-specific files.
85#
86#################################################################
87
88#
89# Build a SCons scanner for ISA files
90#
91import SCons.Scanner
92
93def ISAScan():
94   return SCons.Scanner.Classic("ISAScan",
95                                "$ISASUFFIXES",
96                                "SRCDIR",
97                                '^[ \t]*##[ \t]*include[ \t]*"([^>"]+)"')
98
99def ISAPath(env, dir, target=None, source=None, a=None):
100   return (Dir(env['SRCDIR']), Dir('.'))   
101
102iscan = Scanner(function = ISAScan().scan, skeys = [".isa", ".ISA"],
103                path_function = ISAPath)
104env.Append(SCANNERS = iscan)
105
106#
107# Now create a Builder object that uses isa_parser.py to generate C++
108# output from the ISA description (*.isa) files.
109#
110
111# Convert to File node to fix path
112isa_parser = File('isa_parser.py')
113cpu_models_file = File('#m5/cpu/cpu_models.py')
114
115# This sucks in the defintions of the CpuModel objects.
116execfile(cpu_models_file.srcnode().abspath)
117
118# Several files are generated from the ISA description.
119# We always get the basic decoder and header file.
120isa_desc_gen_files = Split('decoder.cc decoder.hh')
121# We also get an execute file for each selected CPU model.
122isa_desc_gen_files += [CpuModel.dict[cpu].filename
123                       for cpu in env['CPU_MODELS']]
124
125# The emitter patches up the sources & targets to include the
126# autogenerated files as targets and isa parser itself as a source.
127def isa_desc_emitter(target, source, env):
128    return (isa_desc_gen_files, [isa_parser, cpu_models_file] + source)
129
130# Pieces are in place, so create the builder.
131isa_desc_builder = Builder(action='$SOURCES $TARGET.dir $CPU_MODELS',
132                           source_scanner = iscan,
133                           emitter = isa_desc_emitter)
134
135env.Append(BUILDERS = { 'ISADesc' : isa_desc_builder })
136
137#
138# Now include other ISA-specific sources from the ISA subdirectories.
139#
140
141isa = env['TARGET_ISA'] # someday this may be a list of ISAs
142
143# Let the target architecture define what additional sources it needs
144sources += SConscript(os.path.join(isa, 'SConscript'),
145                      exports = 'env', duplicate = False)
146
147Return('sources')
148