SConscript revision 12605
12155SN/A# -*- mode:python -*-
22155SN/A
32155SN/A# Copyright (c) 2016 ARM Limited
42155SN/A# All rights reserved.
52155SN/A#
62155SN/A# The license below extends only to copyright in the software and shall
72155SN/A# not be construed as granting a license to any other intellectual
82155SN/A# property including but not limited to intellectual property relating
92155SN/A# to a hardware implementation of the functionality of the software
102155SN/A# licensed hereunder.  You may use the software subject to the license
112155SN/A# terms below provided that you ensure that this notice is replicated
122155SN/A# unmodified and in its entirety in all distributions of the software,
132155SN/A# modified or unmodified, in source code or in binary form.
142155SN/A#
152155SN/A# Copyright (c) 2006 The Regents of The University of Michigan
162155SN/A# All rights reserved.
172155SN/A#
182155SN/A# Redistribution and use in source and binary forms, with or without
192155SN/A# modification, are permitted provided that the following conditions are
202155SN/A# met: redistributions of source code must retain the above copyright
212155SN/A# notice, this list of conditions and the following disclaimer;
222155SN/A# redistributions in binary form must reproduce the above copyright
232155SN/A# notice, this list of conditions and the following disclaimer in the
242155SN/A# documentation and/or other materials provided with the distribution;
252155SN/A# neither the name of the copyright holders nor the names of its
262155SN/A# contributors may be used to endorse or promote products derived from
272155SN/A# this software without specific prior written permission.
282665Ssaidi@eecs.umich.edu#
292665Ssaidi@eecs.umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
302155SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
314202Sbinkertn@umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
322155SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
332178SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
342178SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
352178SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
362178SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
372178SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
382178SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
392178SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
402178SN/A#
412178SN/A# Authors: Steve Reinhardt
422178SN/A
432178SN/Aimport sys
442178SN/Aimport os
452155SN/Aimport re
462178SN/A
472155SN/Afrom gem5_scons import Transform
482155SN/A
492178SN/AImport('*')
502155SN/A
515865Sksewell@umich.edu#################################################################
525865Sksewell@umich.edu#
533918Ssaidi@eecs.umich.edu# ISA "switch header" generation.
545865Sksewell@umich.edu#
552623SN/A# Auto-generate arch headers that include the right ISA-specific
563918Ssaidi@eecs.umich.edu# header based on the setting of THE_ISA preprocessor variable.
575865Sksewell@umich.edu#
585865Sksewell@umich.edu#################################################################
592155SN/A
602155SN/Aenv.SwitchingHeaders(
612292SN/A    Split('''
623918Ssaidi@eecs.umich.edu        decoder.hh
632292SN/A        interrupts.hh
642292SN/A        isa.hh
652292SN/A        isa_traits.hh
663918Ssaidi@eecs.umich.edu        kernel_stats.hh
672292SN/A        locked_mem.hh
682292SN/A        microcode_rom.hh
692766Sktlim@umich.edu        mmapped_ipr.hh
702766Sktlim@umich.edu        mt.hh
712766Sktlim@umich.edu        process.hh
722921Sktlim@umich.edu        pseudo_inst.hh
732921Sktlim@umich.edu        registers.hh
742766Sktlim@umich.edu        remote_gdb.hh
752766Sktlim@umich.edu        stacktrace.hh
765529Snate@binkert.org        types.hh
772766Sktlim@umich.edu        utility.hh
784762Snate@binkert.org        vtophys.hh
792155SN/A        '''),
802155SN/A    env.subst('${TARGET_ISA}'))
812155SN/A
822155SN/Aif env['BUILD_GPU']:
832155SN/A    env.SwitchingHeaders(
842155SN/A        Split('''
852766Sktlim@umich.edu            gpu_decoder.hh
862155SN/A            gpu_isa.hh
875865Sksewell@umich.edu            gpu_types.hh
882155SN/A            '''),
892155SN/A        env.subst('${TARGET_GPU_ISA}'))
902155SN/A
912155SN/A#################################################################
922178SN/A#
932178SN/A# Include architecture-specific files.
942178SN/A#
952766Sktlim@umich.edu#################################################################
962178SN/A
972178SN/A#
982178SN/A# Build a SCons scanner for ISA files
992178SN/A#
1002766Sktlim@umich.eduimport SCons.Scanner
1012766Sktlim@umich.eduimport SCons.Tool
1022766Sktlim@umich.edu
1032788Sktlim@umich.eduscanner = SCons.Scanner.Classic("ISAScan",
1042178SN/A                                [".isa", ".ISA"],
1052733Sktlim@umich.edu                                 "SRCDIR",
1062733Sktlim@umich.edu                                r'^\s*##include\s+"([\w/.-]*)"')
1072817Sksewell@umich.edu
1082733Sktlim@umich.eduenv.Append(SCANNERS=scanner)
1094486Sbinkertn@umich.edu
1104486Sbinkertn@umich.edu# Tell scons that when it sees a cc.inc file, it should scan it for includes.
1114776Sgblack@eecs.umich.eduSCons.Tool.SourceFileScanner.add_scanner('.cc.inc', SCons.Tool.CScanner)
1124776Sgblack@eecs.umich.edu
1134486Sbinkertn@umich.edu#
1144202Sbinkertn@umich.edu# Now create a Builder object that uses isa_parser.py to generate C++
1154202Sbinkertn@umich.edu# output from the ISA description (*.isa) files.
1164202Sbinkertn@umich.edu#
1174202Sbinkertn@umich.edu
1184202Sbinkertn@umich.eduparser_py = File('isa_parser.py')
1194776Sgblack@eecs.umich.edumicro_asm_py = File('micro_asm.py')
1204202Sbinkertn@umich.edu
1214202Sbinkertn@umich.edu# import ply here because SCons screws with sys.path when performing actions.
1224202Sbinkertn@umich.eduimport ply
1234202Sbinkertn@umich.edu
1245217Ssaidi@eecs.umich.edudef run_parser(target, source, env):
1254202Sbinkertn@umich.edu    # Add the current directory to the system path so we can import files.
1262155SN/A    sys.path[0:0] = [ parser_py.dir.abspath ]
1274202Sbinkertn@umich.edu    import isa_parser
1284486Sbinkertn@umich.edu
1294486Sbinkertn@umich.edu    parser = isa_parser.ISAParser(target[0].dir.abspath)
1304202Sbinkertn@umich.edu    parser.parse_isa_desc(source[0].abspath)
1314202Sbinkertn@umich.edu
1322821Sktlim@umich.edudesc_action = MakeAction(run_parser, Transform("ISA DESC", 1))
1334776Sgblack@eecs.umich.edu
1344776Sgblack@eecs.umich.eduIsaDescBuilder = Builder(action=desc_action)
1354776Sgblack@eecs.umich.edu
1364776Sgblack@eecs.umich.edu
1374776Sgblack@eecs.umich.edu# ISAs should use this function to set up an IsaDescBuilder and not try to
1384776Sgblack@eecs.umich.edu# set one up manually.
1394776Sgblack@eecs.umich.edudef ISADesc(desc, decoder_splits=1, exec_splits=1):
1404776Sgblack@eecs.umich.edu    '''Set up a builder for an ISA description.
1412766Sktlim@umich.edu
1424202Sbinkertn@umich.edu    The decoder_splits and exec_splits parameters let us determine what
1435192Ssaidi@eecs.umich.edu    files the isa parser is actually going to generate. This needs to match
1442733Sktlim@umich.edu    what files are actually generated, and there's no specific check for that
1452733Sktlim@umich.edu    right now.
1462733Sktlim@umich.edu
1472733Sktlim@umich.edu    If the parser itself is responsible for generating a list of its products
1482733Sktlim@umich.edu    and their dependencies, then using that output to set up the right
1492874Sktlim@umich.edu    dependencies. This is what we used to do. The problem is that scons
1502874Sktlim@umich.edu    fundamentally doesn't support using a build product to affect its graph
1512874Sktlim@umich.edu    of possible products, dependencies, builders, etc. There are a couple ways
1524202Sbinkertn@umich.edu    to work around that limitation.
1532733Sktlim@umich.edu
1545192Ssaidi@eecs.umich.edu    One option is to compute dependencies while the build phase of scons is
1555192Ssaidi@eecs.umich.edu    running. That method can be quite complicated and cumbersome, because we
1565192Ssaidi@eecs.umich.edu    have to make sure our modifications are made before scons tries to
1575217Ssaidi@eecs.umich.edu    consume them. There's also no guarantee that this mechanism will work since
1585192Ssaidi@eecs.umich.edu    it subverts scons expectations and changes things behind its back. This
1595192Ssaidi@eecs.umich.edu    was implemented previously and constrained the builds parallelism
1605192Ssaidi@eecs.umich.edu    significantly.
1615192Ssaidi@eecs.umich.edu
1625192Ssaidi@eecs.umich.edu    Another option would be to recursively call scons to have it update the
1635192Ssaidi@eecs.umich.edu    list of products/dependencies during the setup phase of this invocation of
1645192Ssaidi@eecs.umich.edu    scons. The problem with that is that it would be very difficult to make
1655192Ssaidi@eecs.umich.edu    the sub-invocation of scons observe the options passed to the primary one
1665192Ssaidi@eecs.umich.edu    in all possible cases, or to even determine conclusively what the name of
1675192Ssaidi@eecs.umich.edu    the scons executable is in the first place.
1685192Ssaidi@eecs.umich.edu
1695192Ssaidi@eecs.umich.edu    Possible future changes to the isa parser might make it easier to
1705192Ssaidi@eecs.umich.edu    determine what files it would generate, perhaps because there was a more
1715784Sgblack@eecs.umich.edu    direct correspondence between input files and output files. Or, if the
1725784Sgblack@eecs.umich.edu    parser could run quickly and determine what its output files would be
1735192Ssaidi@eecs.umich.edu    without having do actually generate those files, then it could be run
1745192Ssaidi@eecs.umich.edu    unconditionally without slowing down all builds or touching the output
1755192Ssaidi@eecs.umich.edu    files unnecessarily.
1765192Ssaidi@eecs.umich.edu    '''
1775192Ssaidi@eecs.umich.edu    generated_dir = File(desc).dir.up().Dir('generated')
1785192Ssaidi@eecs.umich.edu    def gen_file(name):
1795784Sgblack@eecs.umich.edu        return generated_dir.File(name)
180
181    gen = []
182    def add_gen(name):
183        gen.append(gen_file(name))
184
185    # Tell scons about the various files the ISA parser will generate.
186    add_gen('decoder-g.cc.inc')
187    add_gen('decoder-ns.cc.inc')
188    add_gen('decode-method.cc.inc')
189
190    add_gen('decoder.hh')
191    add_gen('decoder-g.hh.inc')
192    add_gen('decoder-ns.hh.inc')
193
194    add_gen('exec-g.cc.inc')
195    add_gen('exec-ns.cc.inc')
196
197    add_gen('max_inst_regs.hh')
198
199
200    # These generated files are also top level sources.
201    def source_gen(name):
202        add_gen(name)
203        Source(gen_file(name))
204
205    source_gen('decoder.cc')
206
207    if decoder_splits == 1:
208        source_gen('inst-constrs.cc')
209    else:
210        for i in range(1, decoder_splits + 1):
211            source_gen('inst-constrs-%d.cc' % i)
212
213    if exec_splits == 1:
214        source_gen('generic_cpu_exec.cc')
215    else:
216        for i in range(1, exec_splits + 1):
217            source_gen('generic_cpu_exec_%d.cc' % i)
218
219    # Actually create the builder.
220    sources = [desc, parser_py, micro_asm_py]
221    IsaDescBuilder(target=gen, source=sources, env=env)
222    return gen
223
224Export('ISADesc')
225
226DebugFlag('IntRegs')
227DebugFlag('FloatRegs')
228DebugFlag('VecRegs')
229DebugFlag('CCRegs')
230DebugFlag('MiscRegs')
231CompoundFlag('Registers', [ 'IntRegs', 'FloatRegs', 'CCRegs', 'MiscRegs' ])
232