SConscript revision 2504
110152Satgutier@umich.edu# -*- mode:python -*- 210152Satgutier@umich.edu 310152Satgutier@umich.edu# Copyright (c) 2006 The Regents of The University of Michigan 410152Satgutier@umich.edu# All rights reserved. 510152Satgutier@umich.edu# 610152Satgutier@umich.edu# Redistribution and use in source and binary forms, with or without 710152Satgutier@umich.edu# modification, are permitted provided that the following conditions are 810152Satgutier@umich.edu# met: redistributions of source code must retain the above copyright 910152Satgutier@umich.edu# notice, this list of conditions and the following disclaimer; 1010152Satgutier@umich.edu# redistributions in binary form must reproduce the above copyright 1110152Satgutier@umich.edu# notice, this list of conditions and the following disclaimer in the 1210152Satgutier@umich.edu# documentation and/or other materials provided with the distribution; 1310152Satgutier@umich.edu# neither the name of the copyright holders nor the names of its 1410152Satgutier@umich.edu# contributors may be used to endorse or promote products derived from 1510152Satgutier@umich.edu# this software without specific prior written permission. 1610152Satgutier@umich.edu# 1710152Satgutier@umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1810152Satgutier@umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1910152Satgutier@umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2010152Satgutier@umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2110152Satgutier@umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2210152Satgutier@umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2310152Satgutier@umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2410152Satgutier@umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2510152Satgutier@umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2610152Satgutier@umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2710152Satgutier@umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2810152Satgutier@umich.edu 2910152Satgutier@umich.eduimport os.path 3010152Satgutier@umich.edu 3110152Satgutier@umich.edu# Import build environment variable from SConstruct. 3210152Satgutier@umich.eduImport('env') 3310152Satgutier@umich.edu 3410152Satgutier@umich.edu# Right now there are no source files immediately in this directory 3510152Satgutier@umich.edusources = [] 3610152Satgutier@umich.edu 3710152Satgutier@umich.edu################################################################# 3810152Satgutier@umich.edu# 3910152Satgutier@umich.edu# ISA "switch header" generation. 4010152Satgutier@umich.edu# 4110152Satgutier@umich.edu# Auto-generate arch headers that include the right ISA-specific 4210152Satgutier@umich.edu# header based on the setting of THE_ISA preprocessor variable. 4310152Satgutier@umich.edu# 4410152Satgutier@umich.edu################################################################# 4510152Satgutier@umich.edu 4610152Satgutier@umich.edu# List of headers to generate 4710152Satgutier@umich.eduisa_switch_hdrs = Split(''' 4810152Satgutier@umich.edu arguments.hh 4910152Satgutier@umich.edu constants.hh 5010152Satgutier@umich.edu faults.hh 5110152Satgutier@umich.edu isa_traits.hh 5210152Satgutier@umich.edu process.hh 5310152Satgutier@umich.edu regfile.hh 5410152Satgutier@umich.edu stacktrace.hh 5510152Satgutier@umich.edu tlb.hh 5610152Satgutier@umich.edu types.hh 5710152Satgutier@umich.edu utility.hh 5810152Satgutier@umich.edu vtophys.hh 5910152Satgutier@umich.edu ''') 6010152Satgutier@umich.edu 6110152Satgutier@umich.edu# Generate the header. target[0] is the full path of the output 6210152Satgutier@umich.edu# header to generate. 'source' is a dummy variable, since we get the 6310152Satgutier@umich.edu# list of ISAs from env['ALL_ISA_LIST']. 6410152Satgutier@umich.edudef gen_switch_hdr(target, source, env): 6510152Satgutier@umich.edu fname = str(target[0]) 6610152Satgutier@umich.edu basename = os.path.basename(fname) 6710152Satgutier@umich.edu f = open(fname, 'w') 6810152Satgutier@umich.edu f.write('#include "arch/isa_specific.hh"\n') 6910152Satgutier@umich.edu cond = '#if' 7010152Satgutier@umich.edu for isa in env['ALL_ISA_LIST']: 7110152Satgutier@umich.edu f.write('%s THE_ISA == %s_ISA\n#include "arch/%s/%s"\n' 7210152Satgutier@umich.edu % (cond, isa.upper(), isa, basename)) 7310152Satgutier@umich.edu cond = '#elif' 7410152Satgutier@umich.edu f.write('#else\n#error "THE_ISA not set"\n#endif\n') 7510152Satgutier@umich.edu f.close() 7610152Satgutier@umich.edu return 0 7710152Satgutier@umich.edu 7810152Satgutier@umich.edu# String to print when generating header 7910152Satgutier@umich.edudef gen_switch_hdr_string(target, source, env): 8010152Satgutier@umich.edu return "Generating ISA switch header " + str(target[0]) 8110152Satgutier@umich.edu 8210152Satgutier@umich.edu# Build SCons Action object. 'varlist' specifies env vars that this 8310152Satgutier@umich.edu# action depends on; when env['ALL_ISA_LIST'] changes these actions 8410152Satgutier@umich.edu# should get re-executed. 8510152Satgutier@umich.eduswitch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string, 8610152Satgutier@umich.edu varlist=['ALL_ISA_LIST']) 8710152Satgutier@umich.edu 8810152Satgutier@umich.edu# Instantiate actions for each header 8910152Satgutier@umich.edufor hdr in isa_switch_hdrs: 9010152Satgutier@umich.edu env.Command(hdr, [], switch_hdr_action) 9110152Satgutier@umich.edu 9210152Satgutier@umich.edu################################################################# 9310152Satgutier@umich.edu# 9410152Satgutier@umich.edu# Include architecture-specific files. 9510152Satgutier@umich.edu# 9610152Satgutier@umich.edu################################################################# 9710152Satgutier@umich.edu 9810152Satgutier@umich.edu# 9910152Satgutier@umich.edu# Build a SCons scanner for ISA files 10010152Satgutier@umich.edu# 10110152Satgutier@umich.eduimport SCons.Scanner 10210152Satgutier@umich.edu 10310152Satgutier@umich.eduisa_scanner = SCons.Scanner.Classic("ISAScan", 10410152Satgutier@umich.edu [".isa", ".ISA"], 10510152Satgutier@umich.edu "SRCDIR", 10610152Satgutier@umich.edu r'^\s*##include\s+"([\w/.-]*)"') 10710152Satgutier@umich.edu 10810152Satgutier@umich.eduenv.Append(SCANNERS = isa_scanner) 10910152Satgutier@umich.edu 11010152Satgutier@umich.edu# 11110152Satgutier@umich.edu# Now create a Builder object that uses isa_parser.py to generate C++ 11210152Satgutier@umich.edu# output from the ISA description (*.isa) files. 11310152Satgutier@umich.edu# 11410152Satgutier@umich.edu 11510152Satgutier@umich.edu# Convert to File node to fix path 11610152Satgutier@umich.eduisa_parser = File('isa_parser.py') 11710152Satgutier@umich.educpu_models_file = File('#m5/cpu/cpu_models.py') 11810152Satgutier@umich.edu 11910152Satgutier@umich.edu# This sucks in the defintions of the CpuModel objects. 12010152Satgutier@umich.eduexecfile(cpu_models_file.srcnode().abspath) 12110152Satgutier@umich.edu 12210152Satgutier@umich.edu# Several files are generated from the ISA description. 12310152Satgutier@umich.edu# We always get the basic decoder and header file. 12410152Satgutier@umich.eduisa_desc_gen_files = Split('decoder.cc decoder.hh') 12510152Satgutier@umich.edu# We also get an execute file for each selected CPU model. 12610152Satgutier@umich.eduisa_desc_gen_files += [CpuModel.dict[cpu].filename 12710152Satgutier@umich.edu for cpu in env['CPU_MODELS']] 12810152Satgutier@umich.edu 12910152Satgutier@umich.edu# The emitter patches up the sources & targets to include the 13010152Satgutier@umich.edu# autogenerated files as targets and isa parser itself as a source. 13110152Satgutier@umich.edudef isa_desc_emitter(target, source, env): 13210152Satgutier@umich.edu return (isa_desc_gen_files, [isa_parser, cpu_models_file] + source) 13310152Satgutier@umich.edu 13410152Satgutier@umich.edu# Pieces are in place, so create the builder. 13510152Satgutier@umich.eduisa_desc_builder = Builder(action='python $SOURCES $TARGET.dir $CPU_MODELS', 13610152Satgutier@umich.edu emitter = isa_desc_emitter) 13710152Satgutier@umich.edu 13810152Satgutier@umich.eduenv.Append(BUILDERS = { 'ISADesc' : isa_desc_builder }) 13910152Satgutier@umich.edu 14010152Satgutier@umich.edu# 14110152Satgutier@umich.edu# Now include other ISA-specific sources from the ISA subdirectories. 14210152Satgutier@umich.edu# 14310152Satgutier@umich.edu 14410152Satgutier@umich.eduisa = env['TARGET_ISA'] # someday this may be a list of ISAs 14510152Satgutier@umich.edu 14610152Satgutier@umich.edu# Let the target architecture define what additional sources it needs 14710152Satgutier@umich.edusources += SConscript(os.path.join(isa, 'SConscript'), 14810152Satgutier@umich.edu exports = 'env', duplicate = False) 14910152Satgutier@umich.edu 15010152Satgutier@umich.eduReturn('sources') 15110152Satgutier@umich.edu