SConscript revision 10553
14202Sbinkertn@umich.edu# -*- mode:python -*-
24202Sbinkertn@umich.edu
34202Sbinkertn@umich.edu# Copyright (c) 2006 The Regents of The University of Michigan
44202Sbinkertn@umich.edu# All rights reserved.
54202Sbinkertn@umich.edu#
64202Sbinkertn@umich.edu# Redistribution and use in source and binary forms, with or without
74202Sbinkertn@umich.edu# modification, are permitted provided that the following conditions are
84202Sbinkertn@umich.edu# met: redistributions of source code must retain the above copyright
94202Sbinkertn@umich.edu# notice, this list of conditions and the following disclaimer;
104202Sbinkertn@umich.edu# redistributions in binary form must reproduce the above copyright
114202Sbinkertn@umich.edu# notice, this list of conditions and the following disclaimer in the
124202Sbinkertn@umich.edu# documentation and/or other materials provided with the distribution;
134202Sbinkertn@umich.edu# neither the name of the copyright holders nor the names of its
144202Sbinkertn@umich.edu# contributors may be used to endorse or promote products derived from
154202Sbinkertn@umich.edu# this software without specific prior written permission.
164202Sbinkertn@umich.edu#
174202Sbinkertn@umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
184202Sbinkertn@umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
194202Sbinkertn@umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
204202Sbinkertn@umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
214202Sbinkertn@umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
224202Sbinkertn@umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
234202Sbinkertn@umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
244202Sbinkertn@umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
254202Sbinkertn@umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
264202Sbinkertn@umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
274202Sbinkertn@umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
284202Sbinkertn@umich.edu#
294202Sbinkertn@umich.edu# Authors: Steve Reinhardt
304202Sbinkertn@umich.edu
314202Sbinkertn@umich.eduimport sys
324202Sbinkertn@umich.eduimport os
334486Sbinkertn@umich.eduimport re
344486Sbinkertn@umich.edu
356165Ssanchezd@stanford.eduImport('*')
366168Snate@binkert.org
374202Sbinkertn@umich.edu#################################################################
384202Sbinkertn@umich.edu#
394202Sbinkertn@umich.edu# ISA "switch header" generation.
408761Sgblack@eecs.umich.edu#
414202Sbinkertn@umich.edu# Auto-generate arch headers that include the right ISA-specific
424202Sbinkertn@umich.edu# header based on the setting of THE_ISA preprocessor variable.
434202Sbinkertn@umich.edu#
448853Sandreas.hansson@arm.com#################################################################
458799Sgblack@eecs.umich.edu
468799Sgblack@eecs.umich.edu# List of headers to generate
476168Snate@binkert.orgisa_switch_hdrs = Split('''
487768SAli.Saidi@ARM.com        decoder.hh
497768SAli.Saidi@ARM.com        interrupts.hh
507768SAli.Saidi@ARM.com        isa.hh
518763Sgblack@eecs.umich.edu        isa_traits.hh
527768SAli.Saidi@ARM.com        kernel_stats.hh
537768SAli.Saidi@ARM.com        locked_mem.hh
548335Snate@binkert.org        microcode_rom.hh
558335Snate@binkert.org        mmapped_ipr.hh
568335Snate@binkert.org        mt.hh
578335Snate@binkert.org        process.hh
588335Snate@binkert.org        pseudo_inst.hh
598335Snate@binkert.org        registers.hh
607780Snilay@cs.wisc.edu        remote_gdb.hh
618335Snate@binkert.org        stacktrace.hh
628335Snate@binkert.org        tlb.hh
638683Snilay@cs.wisc.edu        types.hh
648335Snate@binkert.org        utility.hh
658335Snate@binkert.org        vtophys.hh
668335Snate@binkert.org        ''')
678335Snate@binkert.org
688335Snate@binkert.org# Set up this directory to support switching headers
698335Snate@binkert.orgmake_switching_dir('arch', isa_switch_hdrs, env)
708615Snilay@cs.wisc.edu
718335Snate@binkert.org#################################################################
728687Snilay@cs.wisc.edu#
738335Snate@binkert.org# Include architecture-specific files.
747780Snilay@cs.wisc.edu#
757780Snilay@cs.wisc.edu#################################################################
768687Snilay@cs.wisc.edu
778683Snilay@cs.wisc.edu#
78# Build a SCons scanner for ISA files
79#
80import SCons.Scanner
81
82isa_scanner = SCons.Scanner.Classic("ISAScan",
83                                    [".isa", ".ISA"],
84                                    "SRCDIR",
85                                    r'^\s*##include\s+"([\w/.-]*)"')
86
87env.Append(SCANNERS = isa_scanner)
88
89#
90# Now create a Builder object that uses isa_parser.py to generate C++
91# output from the ISA description (*.isa) files.
92#
93
94isa_parser = File('isa_parser.py')
95
96# The emitter patches up the sources & targets to include the
97# autogenerated files as targets and isa parser itself as a source.
98def isa_desc_emitter(target, source, env):
99    # List the isa parser as a source.
100    source += [
101        isa_parser,
102        Value("ExecContext"),
103        ]
104
105    # Specify different targets depending on if we're running the ISA
106    # parser for its dependency information, or for the generated files.
107    # (As an optimization, the ISA parser detects the useless second run
108    # and skips doing any work, if the first run was performed, since it
109    # always generates all its files). The way we track this in SCons is the
110    # <arch>_isa_outputs value in the environment (env). If it's unset, we
111    # don't know what the dependencies are so we ask for generated/inc.d to
112    # be generated so they can be acquired. If we know what they are, then
113    # it's because we've already processed inc.d and then claim that our
114    # outputs (targets) will be thus.
115    isa = env['TARGET_ISA']
116    key = '%s_isa_outputs' % isa
117    if key in env:
118        targets = [ os.path.join('generated', f) for f in env[key] ]
119    else:
120        targets = [ os.path.join('generated','inc.d') ]
121
122    def prefix(s):
123        return os.path.join(target[0].dir.up().abspath, s)
124
125    return [ prefix(t) for t in targets ], source
126
127ARCH_DIR = Dir('.')
128
129# import ply here because SCons screws with sys.path when performing actions.
130import ply
131
132def isa_desc_action_func(target, source, env):
133    # Add the current directory to the system path so we can import files
134    sys.path[0:0] = [ ARCH_DIR.srcnode().abspath ]
135    import isa_parser
136
137    # Skip over the ISA description itself and the parser to the CPU models.
138    models = [ s.get_contents() for s in source[2:] ]
139    parser = isa_parser.ISAParser(target[0].dir.abspath)
140    parser.parse_isa_desc(source[0].abspath)
141isa_desc_action = MakeAction(isa_desc_action_func, Transform("ISA DESC", 1))
142
143# Also include the CheckerCPU as one of the models if it is being
144# enabled via command line.
145isa_desc_builder = Builder(action=isa_desc_action, emitter=isa_desc_emitter)
146
147env.Append(BUILDERS = { 'ISADesc' : isa_desc_builder })
148
149# The ISA is generated twice: the first time to find out what it generates,
150# and the second time to make scons happy by telling the ISADesc builder
151# what it will make before it builds it.
152def scan_isa_deps(target, source, env):
153    # Process dependency file generated by the ISA parser --
154    # add the listed files to the dependency tree of the build.
155    source = source[0]
156    archbase = source.dir.up().path
157
158    try:
159        depfile = open(source.abspath, 'r')
160    except:
161        print "scan_isa_deps: Can't open ISA deps file '%s' in %s" % \
162              (source.path,os.getcwd())
163        raise
164
165    # Scan through the lines
166    targets = {}
167    for line in depfile:
168        # Read the dependency line with the format
169        # <target file>: [ <dependent file>* ]
170        m = re.match(r'^\s*([^:]+\.([^\.:]+))\s*:\s*(.*)', line)
171        assert(m)
172        targ, extn = m.group(1,2)
173        deps = m.group(3).split()
174
175        files = [ targ ] + deps
176        for f in files:
177            targets[f] = True
178            # Eliminate unnecessary re-generation if we already generated it
179            env.Precious(os.path.join(archbase, 'generated', f))
180
181        files = [ os.path.join(archbase, 'generated', f) for f in files ]
182
183        if extn == 'cc':
184            Source(os.path.join(archbase,'generated', targ))
185    depfile.close()
186    env[env['TARGET_ISA'] + '_isa_outputs'] = targets.keys()
187
188    isa = env.ISADesc(os.path.join(archbase,'isa','main.isa'))
189    for t in targets:
190        env.Depends('#all-isas', isa)
191
192env.Append(BUILDERS = {'ScanISA' :
193                        Builder(action=MakeAction(scan_isa_deps,
194                                                  Transform("NEW DEPS", 1)))})
195
196DebugFlag('IntRegs')
197DebugFlag('FloatRegs')
198DebugFlag('CCRegs')
199DebugFlag('MiscRegs')
200CompoundFlag('Registers', [ 'IntRegs', 'FloatRegs', 'CCRegs', 'MiscRegs' ])
201