SConscript revision 12222
13534Sgblack@eecs.umich.edu# -*- mode:python -*-
23534Sgblack@eecs.umich.edu
33534Sgblack@eecs.umich.edu# Copyright (c) 2016 ARM Limited
43534Sgblack@eecs.umich.edu# All rights reserved.
53534Sgblack@eecs.umich.edu#
63534Sgblack@eecs.umich.edu# The license below extends only to copyright in the software and shall
73534Sgblack@eecs.umich.edu# not be construed as granting a license to any other intellectual
83534Sgblack@eecs.umich.edu# property including but not limited to intellectual property relating
93534Sgblack@eecs.umich.edu# to a hardware implementation of the functionality of the software
103534Sgblack@eecs.umich.edu# licensed hereunder.  You may use the software subject to the license
113534Sgblack@eecs.umich.edu# terms below provided that you ensure that this notice is replicated
123534Sgblack@eecs.umich.edu# unmodified and in its entirety in all distributions of the software,
133534Sgblack@eecs.umich.edu# modified or unmodified, in source code or in binary form.
143534Sgblack@eecs.umich.edu#
153534Sgblack@eecs.umich.edu# Copyright (c) 2006 The Regents of The University of Michigan
163534Sgblack@eecs.umich.edu# All rights reserved.
173534Sgblack@eecs.umich.edu#
183534Sgblack@eecs.umich.edu# Redistribution and use in source and binary forms, with or without
193534Sgblack@eecs.umich.edu# modification, are permitted provided that the following conditions are
203534Sgblack@eecs.umich.edu# met: redistributions of source code must retain the above copyright
213534Sgblack@eecs.umich.edu# notice, this list of conditions and the following disclaimer;
223534Sgblack@eecs.umich.edu# redistributions in binary form must reproduce the above copyright
233534Sgblack@eecs.umich.edu# notice, this list of conditions and the following disclaimer in the
243534Sgblack@eecs.umich.edu# documentation and/or other materials provided with the distribution;
253534Sgblack@eecs.umich.edu# neither the name of the copyright holders nor the names of its
263534Sgblack@eecs.umich.edu# contributors may be used to endorse or promote products derived from
273534Sgblack@eecs.umich.edu# this software without specific prior written permission.
283534Sgblack@eecs.umich.edu#
293534Sgblack@eecs.umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
303534Sgblack@eecs.umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
313534Sgblack@eecs.umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
324202Sbinkertn@umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
333534Sgblack@eecs.umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
347768SAli.Saidi@ARM.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
357768SAli.Saidi@ARM.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
367768SAli.Saidi@ARM.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
378739Sgblack@eecs.umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
388739Sgblack@eecs.umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
398739Sgblack@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
408739Sgblack@eecs.umich.edu#
418739Sgblack@eecs.umich.edu# Authors: Steve Reinhardt
428739Sgblack@eecs.umich.edu
438739Sgblack@eecs.umich.eduimport sys
448739Sgblack@eecs.umich.eduimport os
458739Sgblack@eecs.umich.eduimport re
468739Sgblack@eecs.umich.edu
478739Sgblack@eecs.umich.eduImport('*')
484486Sbinkertn@umich.edu
498739Sgblack@eecs.umich.edu#################################################################
508739Sgblack@eecs.umich.edu#
518739Sgblack@eecs.umich.edu# ISA "switch header" generation.
529016Sandreas.hansson@arm.com#
538739Sgblack@eecs.umich.edu# Auto-generate arch headers that include the right ISA-specific
548739Sgblack@eecs.umich.edu# header based on the setting of THE_ISA preprocessor variable.
558739Sgblack@eecs.umich.edu#
568739Sgblack@eecs.umich.edu#################################################################
578739Sgblack@eecs.umich.edu
588739Sgblack@eecs.umich.eduenv.SwitchingHeaders(
598739Sgblack@eecs.umich.edu    Split('''
608739Sgblack@eecs.umich.edu        decoder.hh
618739Sgblack@eecs.umich.edu        interrupts.hh
628739Sgblack@eecs.umich.edu        isa.hh
638739Sgblack@eecs.umich.edu        isa_traits.hh
648739Sgblack@eecs.umich.edu        kernel_stats.hh
658739Sgblack@eecs.umich.edu        locked_mem.hh
668739Sgblack@eecs.umich.edu        microcode_rom.hh
678739Sgblack@eecs.umich.edu        mmapped_ipr.hh
688739Sgblack@eecs.umich.edu        mt.hh
698739Sgblack@eecs.umich.edu        process.hh
708739Sgblack@eecs.umich.edu        pseudo_inst.hh
718739Sgblack@eecs.umich.edu        registers.hh
728739Sgblack@eecs.umich.edu        remote_gdb.hh
738739Sgblack@eecs.umich.edu        stacktrace.hh
748739Sgblack@eecs.umich.edu        tlb.hh
758739Sgblack@eecs.umich.edu        types.hh
768739Sgblack@eecs.umich.edu        utility.hh
778739Sgblack@eecs.umich.edu        vtophys.hh
785192Ssaidi@eecs.umich.edu        '''),
798739Sgblack@eecs.umich.edu    env.subst('${TARGET_ISA}'))
808739Sgblack@eecs.umich.edu
818739Sgblack@eecs.umich.eduif env['BUILD_GPU']:
828739Sgblack@eecs.umich.edu    env.SwitchingHeaders(
838739Sgblack@eecs.umich.edu        Split('''
848739Sgblack@eecs.umich.edu            gpu_decoder.hh
858739Sgblack@eecs.umich.edu            gpu_isa.hh
868739Sgblack@eecs.umich.edu            gpu_types.hh
878739Sgblack@eecs.umich.edu            '''),
888739Sgblack@eecs.umich.edu        env.subst('${TARGET_GPU_ISA}'))
898739Sgblack@eecs.umich.edu
908739Sgblack@eecs.umich.edu#################################################################
918739Sgblack@eecs.umich.edu#
928739Sgblack@eecs.umich.edu# Include architecture-specific files.
938739Sgblack@eecs.umich.edu#
948739Sgblack@eecs.umich.edu#################################################################
958739Sgblack@eecs.umich.edu
968739Sgblack@eecs.umich.edu#
978739Sgblack@eecs.umich.edu# Build a SCons scanner for ISA files
988739Sgblack@eecs.umich.edu#
998739Sgblack@eecs.umich.eduimport SCons.Scanner
1008739Sgblack@eecs.umich.eduimport SCons.Tool
1018739Sgblack@eecs.umich.edu
1028739Sgblack@eecs.umich.eduscanner = SCons.Scanner.Classic("ISAScan",
1038739Sgblack@eecs.umich.edu                                [".isa", ".ISA"],
1045192Ssaidi@eecs.umich.edu                                 "SRCDIR",
1058739Sgblack@eecs.umich.edu                                r'^\s*##include\s+"([\w/.-]*)"')
1068739Sgblack@eecs.umich.edu
1078739Sgblack@eecs.umich.eduenv.Append(SCANNERS=scanner)
1088739Sgblack@eecs.umich.edu
1098739Sgblack@eecs.umich.edu# Tell scons that when it sees a cc.inc file, it should scan it for includes.
1108739Sgblack@eecs.umich.eduSCons.Tool.SourceFileScanner.add_scanner('.cc.inc', SCons.Tool.CScanner)
1118739Sgblack@eecs.umich.edu
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
117parser_py = File('isa_parser.py')
118micro_asm_py = File('micro_asm.py')
119
120# import ply here because SCons screws with sys.path when performing actions.
121import ply
122
123def run_parser(target, source, env):
124    # Add the current directory to the system path so we can import files.
125    sys.path[0:0] = [ parser_py.dir.abspath ]
126    import isa_parser
127
128    parser = isa_parser.ISAParser(target[0].dir.abspath)
129    parser.parse_isa_desc(source[0].abspath)
130
131desc_action = MakeAction(run_parser, Transform("ISA DESC", 1))
132
133IsaDescBuilder = Builder(action=desc_action)
134
135
136# ISAs should use this function to set up an IsaDescBuilder and not try to
137# set one up manually.
138def ISADesc(desc, decoder_splits=1, exec_splits=1):
139    '''Set up a builder for an ISA description.
140
141    The decoder_splits and exec_splits parameters let us determine what
142    files the isa parser is actually going to generate. This needs to match
143    what files are actually generated, and there's no specific check for that
144    right now.
145
146    If the parser itself is responsible for generating a list of its products
147    and their dependencies, then using that output to set up the right
148    dependencies. This is what we used to do. The problem is that scons
149    fundamentally doesn't support using a build product to affect its graph
150    of possible products, dependencies, builders, etc. There are a couple ways
151    to work around that limitation.
152
153    One option is to compute dependencies while the build phase of scons is
154    running. That method can be quite complicated and cumbersome, because we
155    have to make sure our modifications are made before scons tries to
156    consume them. There's also no guarantee that this mechanism will work since
157    it subverts scons expectations and changes things behind its back. This
158    was implemented previously and constrained the builds parallelism
159    significantly.
160
161    Another option would be to recursively call scons to have it update the
162    list of products/dependencies during the setup phase of this invocation of
163    scons. The problem with that is that it would be very difficult to make
164    the sub-invocation of scons observe the options passed to the primary one
165    in all possible cases, or to even determine conclusively what the name of
166    the scons executable is in the first place.
167
168    Possible future changes to the isa parser might make it easier to
169    determine what files it would generate, perhaps because there was a more
170    direct correspondence between input files and output files. Or, if the
171    parser could run quickly and determine what its output files would be
172    without having do actually generate those files, then it could be run
173    unconditionally without slowing down all builds or touching the output
174    files unnecessarily.
175    '''
176    generated_dir = File(desc).dir.up().Dir('generated')
177    def gen_file(name):
178        return generated_dir.File(name)
179
180    gen = []
181    def add_gen(name):
182        gen.append(gen_file(name))
183
184    # Tell scons about the various files the ISA parser will generate.
185    add_gen('decoder-g.cc.inc')
186    add_gen('decoder-ns.cc.inc')
187    add_gen('decode-method.cc.inc')
188
189    add_gen('decoder.hh')
190    add_gen('decoder-g.hh.inc')
191    add_gen('decoder-ns.hh.inc')
192
193    add_gen('exec-g.cc.inc')
194    add_gen('exec-ns.cc.inc')
195
196    add_gen('max_inst_regs.hh')
197
198
199    # These generated files are also top level sources.
200    def source_gen(name):
201        add_gen(name)
202        Source(gen_file(name))
203
204    source_gen('decoder.cc')
205
206    if decoder_splits == 1:
207        source_gen('inst-constrs.cc')
208    else:
209        for i in range(1, decoder_splits + 1):
210            source_gen('inst-constrs-%d.cc' % i)
211
212    if exec_splits == 1:
213        source_gen('generic_cpu_exec.cc')
214    else:
215        for i in range(1, exec_splits + 1):
216            source_gen('generic_cpu_exec_%d.cc' % i)
217
218    # Actually create the builder.
219    sources = [desc, parser_py, micro_asm_py]
220    IsaDescBuilder(target=gen, source=sources, env=env)
221    return gen
222
223Export('ISADesc')
224
225DebugFlag('IntRegs')
226DebugFlag('FloatRegs')
227DebugFlag('VecRegs')
228DebugFlag('CCRegs')
229DebugFlag('MiscRegs')
230CompoundFlag('Registers', [ 'IntRegs', 'FloatRegs', 'CCRegs', 'MiscRegs' ])
231