SConscript revision 12246
1# -*- mode:python -*-
2
3# Copyright (c) 2016 ARM Limited
4# All rights reserved.
5#
6# The license below extends only to copyright in the software and shall
7# not be construed as granting a license to any other intellectual
8# property including but not limited to intellectual property relating
9# to a hardware implementation of the functionality of the software
10# licensed hereunder.  You may use the software subject to the license
11# terms below provided that you ensure that this notice is replicated
12# unmodified and in its entirety in all distributions of the software,
13# modified or unmodified, in source code or in binary form.
14#
15# Copyright (c) 2006 The Regents of The University of Michigan
16# All rights reserved.
17#
18# Redistribution and use in source and binary forms, with or without
19# modification, are permitted provided that the following conditions are
20# met: redistributions of source code must retain the above copyright
21# notice, this list of conditions and the following disclaimer;
22# redistributions in binary form must reproduce the above copyright
23# notice, this list of conditions and the following disclaimer in the
24# documentation and/or other materials provided with the distribution;
25# neither the name of the copyright holders nor the names of its
26# contributors may be used to endorse or promote products derived from
27# this software without specific prior written permission.
28#
29# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40#
41# Authors: Steve Reinhardt
42
43import sys
44import os
45import re
46
47from gem5_scons import Transform
48
49Import('*')
50
51#################################################################
52#
53# ISA "switch header" generation.
54#
55# Auto-generate arch headers that include the right ISA-specific
56# header based on the setting of THE_ISA preprocessor variable.
57#
58#################################################################
59
60env.SwitchingHeaders(
61    Split('''
62        decoder.hh
63        interrupts.hh
64        isa.hh
65        isa_traits.hh
66        kernel_stats.hh
67        locked_mem.hh
68        microcode_rom.hh
69        mmapped_ipr.hh
70        mt.hh
71        process.hh
72        pseudo_inst.hh
73        registers.hh
74        remote_gdb.hh
75        stacktrace.hh
76        tlb.hh
77        types.hh
78        utility.hh
79        vtophys.hh
80        '''),
81    env.subst('${TARGET_ISA}'))
82
83if env['BUILD_GPU']:
84    env.SwitchingHeaders(
85        Split('''
86            gpu_decoder.hh
87            gpu_isa.hh
88            gpu_types.hh
89            '''),
90        env.subst('${TARGET_GPU_ISA}'))
91
92#################################################################
93#
94# Include architecture-specific files.
95#
96#################################################################
97
98#
99# Build a SCons scanner for ISA files
100#
101import SCons.Scanner
102import SCons.Tool
103
104scanner = SCons.Scanner.Classic("ISAScan",
105                                [".isa", ".ISA"],
106                                 "SRCDIR",
107                                r'^\s*##include\s+"([\w/.-]*)"')
108
109env.Append(SCANNERS=scanner)
110
111# Tell scons that when it sees a cc.inc file, it should scan it for includes.
112SCons.Tool.SourceFileScanner.add_scanner('.cc.inc', SCons.Tool.CScanner)
113
114#
115# Now create a Builder object that uses isa_parser.py to generate C++
116# output from the ISA description (*.isa) files.
117#
118
119parser_py = File('isa_parser.py')
120micro_asm_py = File('micro_asm.py')
121
122# import ply here because SCons screws with sys.path when performing actions.
123import ply
124
125def run_parser(target, source, env):
126    # Add the current directory to the system path so we can import files.
127    sys.path[0:0] = [ parser_py.dir.abspath ]
128    import isa_parser
129
130    parser = isa_parser.ISAParser(target[0].dir.abspath)
131    parser.parse_isa_desc(source[0].abspath)
132
133desc_action = MakeAction(run_parser, Transform("ISA DESC", 1))
134
135IsaDescBuilder = Builder(action=desc_action)
136
137
138# ISAs should use this function to set up an IsaDescBuilder and not try to
139# set one up manually.
140def ISADesc(desc, decoder_splits=1, exec_splits=1):
141    '''Set up a builder for an ISA description.
142
143    The decoder_splits and exec_splits parameters let us determine what
144    files the isa parser is actually going to generate. This needs to match
145    what files are actually generated, and there's no specific check for that
146    right now.
147
148    If the parser itself is responsible for generating a list of its products
149    and their dependencies, then using that output to set up the right
150    dependencies. This is what we used to do. The problem is that scons
151    fundamentally doesn't support using a build product to affect its graph
152    of possible products, dependencies, builders, etc. There are a couple ways
153    to work around that limitation.
154
155    One option is to compute dependencies while the build phase of scons is
156    running. That method can be quite complicated and cumbersome, because we
157    have to make sure our modifications are made before scons tries to
158    consume them. There's also no guarantee that this mechanism will work since
159    it subverts scons expectations and changes things behind its back. This
160    was implemented previously and constrained the builds parallelism
161    significantly.
162
163    Another option would be to recursively call scons to have it update the
164    list of products/dependencies during the setup phase of this invocation of
165    scons. The problem with that is that it would be very difficult to make
166    the sub-invocation of scons observe the options passed to the primary one
167    in all possible cases, or to even determine conclusively what the name of
168    the scons executable is in the first place.
169
170    Possible future changes to the isa parser might make it easier to
171    determine what files it would generate, perhaps because there was a more
172    direct correspondence between input files and output files. Or, if the
173    parser could run quickly and determine what its output files would be
174    without having do actually generate those files, then it could be run
175    unconditionally without slowing down all builds or touching the output
176    files unnecessarily.
177    '''
178    generated_dir = File(desc).dir.up().Dir('generated')
179    def gen_file(name):
180        return generated_dir.File(name)
181
182    gen = []
183    def add_gen(name):
184        gen.append(gen_file(name))
185
186    # Tell scons about the various files the ISA parser will generate.
187    add_gen('decoder-g.cc.inc')
188    add_gen('decoder-ns.cc.inc')
189    add_gen('decode-method.cc.inc')
190
191    add_gen('decoder.hh')
192    add_gen('decoder-g.hh.inc')
193    add_gen('decoder-ns.hh.inc')
194
195    add_gen('exec-g.cc.inc')
196    add_gen('exec-ns.cc.inc')
197
198    add_gen('max_inst_regs.hh')
199
200
201    # These generated files are also top level sources.
202    def source_gen(name):
203        add_gen(name)
204        Source(gen_file(name))
205
206    source_gen('decoder.cc')
207
208    if decoder_splits == 1:
209        source_gen('inst-constrs.cc')
210    else:
211        for i in range(1, decoder_splits + 1):
212            source_gen('inst-constrs-%d.cc' % i)
213
214    if exec_splits == 1:
215        source_gen('generic_cpu_exec.cc')
216    else:
217        for i in range(1, exec_splits + 1):
218            source_gen('generic_cpu_exec_%d.cc' % i)
219
220    # Actually create the builder.
221    sources = [desc, parser_py, micro_asm_py]
222    IsaDescBuilder(target=gen, source=sources, env=env)
223    return gen
224
225Export('ISADesc')
226
227DebugFlag('IntRegs')
228DebugFlag('FloatRegs')
229DebugFlag('VecRegs')
230DebugFlag('CCRegs')
231DebugFlag('MiscRegs')
232CompoundFlag('Registers', [ 'IntRegs', 'FloatRegs', 'CCRegs', 'MiscRegs' ])
233