SConscript revision 8887
112855Sgabeblack@google.com# -*- mode:python -*- 212855Sgabeblack@google.com 312855Sgabeblack@google.com# Copyright (c) 2006 The Regents of The University of Michigan 412855Sgabeblack@google.com# All rights reserved. 512855Sgabeblack@google.com# 612855Sgabeblack@google.com# Redistribution and use in source and binary forms, with or without 712855Sgabeblack@google.com# modification, are permitted provided that the following conditions are 812855Sgabeblack@google.com# met: redistributions of source code must retain the above copyright 912855Sgabeblack@google.com# notice, this list of conditions and the following disclaimer; 1012855Sgabeblack@google.com# redistributions in binary form must reproduce the above copyright 1112855Sgabeblack@google.com# notice, this list of conditions and the following disclaimer in the 1212855Sgabeblack@google.com# documentation and/or other materials provided with the distribution; 1312855Sgabeblack@google.com# neither the name of the copyright holders nor the names of its 1412855Sgabeblack@google.com# contributors may be used to endorse or promote products derived from 1512855Sgabeblack@google.com# this software without specific prior written permission. 1612855Sgabeblack@google.com# 1712855Sgabeblack@google.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1812855Sgabeblack@google.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1912855Sgabeblack@google.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2012855Sgabeblack@google.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2112855Sgabeblack@google.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2212855Sgabeblack@google.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2312855Sgabeblack@google.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2412855Sgabeblack@google.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2512855Sgabeblack@google.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2612855Sgabeblack@google.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2712855Sgabeblack@google.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2812855Sgabeblack@google.com# 2912855Sgabeblack@google.com# Authors: Steve Reinhardt 3012855Sgabeblack@google.com 3112855Sgabeblack@google.comimport sys 3212855Sgabeblack@google.com 3312855Sgabeblack@google.comImport('*') 3412855Sgabeblack@google.com 3512855Sgabeblack@google.com################################################################# 3612855Sgabeblack@google.com# 3712855Sgabeblack@google.com# ISA "switch header" generation. 3812855Sgabeblack@google.com# 3912855Sgabeblack@google.com# Auto-generate arch headers that include the right ISA-specific 4012855Sgabeblack@google.com# header based on the setting of THE_ISA preprocessor variable. 4112855Sgabeblack@google.com# 4212855Sgabeblack@google.com################################################################# 4312855Sgabeblack@google.com 4412855Sgabeblack@google.com# List of headers to generate 4512855Sgabeblack@google.comisa_switch_hdrs = Split(''' 4612855Sgabeblack@google.com interrupts.hh 4712855Sgabeblack@google.com isa.hh 4812855Sgabeblack@google.com isa_traits.hh 4912855Sgabeblack@google.com kernel_stats.hh 5012855Sgabeblack@google.com locked_mem.hh 5112855Sgabeblack@google.com microcode_rom.hh 5212855Sgabeblack@google.com mmapped_ipr.hh 5312855Sgabeblack@google.com mt.hh 5412855Sgabeblack@google.com process.hh 5512855Sgabeblack@google.com predecoder.hh 5612855Sgabeblack@google.com registers.hh 5712855Sgabeblack@google.com remote_gdb.hh 5812855Sgabeblack@google.com stacktrace.hh 5912855Sgabeblack@google.com tlb.hh 6012855Sgabeblack@google.com types.hh 6112855Sgabeblack@google.com utility.hh 6212855Sgabeblack@google.com vtophys.hh 6312855Sgabeblack@google.com ''') 6412855Sgabeblack@google.com 6512855Sgabeblack@google.com# Set up this directory to support switching headers 6612855Sgabeblack@google.commake_switching_dir('arch', isa_switch_hdrs, env) 6712855Sgabeblack@google.com 6812855Sgabeblack@google.com################################################################# 6912855Sgabeblack@google.com# 7012855Sgabeblack@google.com# Include architecture-specific files. 7112855Sgabeblack@google.com# 7212855Sgabeblack@google.com################################################################# 7312855Sgabeblack@google.com 7412855Sgabeblack@google.com# 7512855Sgabeblack@google.com# Build a SCons scanner for ISA files 7612855Sgabeblack@google.com# 7712855Sgabeblack@google.comimport SCons.Scanner 7812855Sgabeblack@google.com 7912855Sgabeblack@google.comisa_scanner = SCons.Scanner.Classic("ISAScan", 8012855Sgabeblack@google.com [".isa", ".ISA"], 8112855Sgabeblack@google.com "SRCDIR", 8212855Sgabeblack@google.com r'^\s*##include\s+"([\w/.-]*)"') 8312855Sgabeblack@google.com 8412855Sgabeblack@google.comenv.Append(SCANNERS = isa_scanner) 8512855Sgabeblack@google.com 8612855Sgabeblack@google.com# 8712855Sgabeblack@google.com# Now create a Builder object that uses isa_parser.py to generate C++ 8812855Sgabeblack@google.com# output from the ISA description (*.isa) files. 8912855Sgabeblack@google.com# 9012855Sgabeblack@google.com 9112855Sgabeblack@google.comisa_parser = File('isa_parser.py') 9212855Sgabeblack@google.com 9312855Sgabeblack@google.com# The emitter patches up the sources & targets to include the 9412855Sgabeblack@google.com# autogenerated files as targets and isa parser itself as a source. 9512855Sgabeblack@google.comdef isa_desc_emitter(target, source, env): 9612855Sgabeblack@google.com cpu_models = list(env['CPU_MODELS']) 9712855Sgabeblack@google.com cpu_models.append('CheckerCPU') 9812855Sgabeblack@google.com 9912855Sgabeblack@google.com # Several files are generated from the ISA description. 10012855Sgabeblack@google.com # We always get the basic decoder and header file. 10112855Sgabeblack@google.com target = [ 'decoder.cc', 'decoder.hh', 'max_inst_regs.hh' ] 10212855Sgabeblack@google.com # We also get an execute file for each selected CPU model. 10312855Sgabeblack@google.com target += [CpuModel.dict[cpu].filename for cpu in cpu_models] 10412855Sgabeblack@google.com 10512855Sgabeblack@google.com # List the isa parser as a source. 10612855Sgabeblack@google.com source += [ isa_parser ] 10712855Sgabeblack@google.com # Add in the CPU models. 10812855Sgabeblack@google.com source += [ Value(m) for m in cpu_models ] 10912855Sgabeblack@google.com 11012855Sgabeblack@google.com return target, source 11112855Sgabeblack@google.com 11212855Sgabeblack@google.comARCH_DIR = Dir('.') 11312855Sgabeblack@google.com 11412855Sgabeblack@google.com# import ply here because SCons screws with sys.path when performing actions. 11512855Sgabeblack@google.comimport ply 11612855Sgabeblack@google.com 11712855Sgabeblack@google.comdef isa_desc_action_func(target, source, env): 11812855Sgabeblack@google.com # Add the current directory to the system path so we can import files 11912855Sgabeblack@google.com sys.path[0:0] = [ ARCH_DIR.srcnode().abspath ] 12012855Sgabeblack@google.com import isa_parser 12112855Sgabeblack@google.com 12212855Sgabeblack@google.com # Skip over the ISA description itself and the parser to the CPU models. 12312855Sgabeblack@google.com models = [ s.get_contents() for s in source[2:] ] 12412855Sgabeblack@google.com cpu_models = [CpuModel.dict[cpu] for cpu in models] 12512855Sgabeblack@google.com parser = isa_parser.ISAParser(target[0].dir.abspath, cpu_models) 12612855Sgabeblack@google.com parser.parse_isa_desc(source[0].abspath) 12712855Sgabeblack@google.comisa_desc_action = MakeAction(isa_desc_action_func, Transform("ISA DESC", 1)) 12812855Sgabeblack@google.com 12912855Sgabeblack@google.com# Also include the CheckerCPU as one of the models if it is being 13012855Sgabeblack@google.com# enabled via command line. 13112855Sgabeblack@google.comisa_desc_builder = Builder(action=isa_desc_action, emitter=isa_desc_emitter) 13212855Sgabeblack@google.com 13312855Sgabeblack@google.comenv.Append(BUILDERS = { 'ISADesc' : isa_desc_builder }) 13412855Sgabeblack@google.com 13512855Sgabeblack@google.comDebugFlag('IntRegs') 13612855Sgabeblack@google.comDebugFlag('FloatRegs') 13712855Sgabeblack@google.comDebugFlag('MiscRegs') 13812855Sgabeblack@google.comCompoundFlag('Registers', [ 'IntRegs', 'FloatRegs', 'MiscRegs' ]) 13912855Sgabeblack@google.com