SConscript revision 2665
112027Sjungma@eit.uni-kl.de# -*- mode:python -*- 212027Sjungma@eit.uni-kl.de 312027Sjungma@eit.uni-kl.de# Copyright (c) 2006 The Regents of The University of Michigan 412027Sjungma@eit.uni-kl.de# All rights reserved. 512027Sjungma@eit.uni-kl.de# 612027Sjungma@eit.uni-kl.de# Redistribution and use in source and binary forms, with or without 712027Sjungma@eit.uni-kl.de# modification, are permitted provided that the following conditions are 812027Sjungma@eit.uni-kl.de# met: redistributions of source code must retain the above copyright 912027Sjungma@eit.uni-kl.de# notice, this list of conditions and the following disclaimer; 1012027Sjungma@eit.uni-kl.de# redistributions in binary form must reproduce the above copyright 1112027Sjungma@eit.uni-kl.de# notice, this list of conditions and the following disclaimer in the 1212027Sjungma@eit.uni-kl.de# documentation and/or other materials provided with the distribution; 1312027Sjungma@eit.uni-kl.de# neither the name of the copyright holders nor the names of its 1412027Sjungma@eit.uni-kl.de# contributors may be used to endorse or promote products derived from 1512027Sjungma@eit.uni-kl.de# this software without specific prior written permission. 1612027Sjungma@eit.uni-kl.de# 1712027Sjungma@eit.uni-kl.de# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1812027Sjungma@eit.uni-kl.de# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1912027Sjungma@eit.uni-kl.de# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2012027Sjungma@eit.uni-kl.de# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2112027Sjungma@eit.uni-kl.de# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2212027Sjungma@eit.uni-kl.de# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2312027Sjungma@eit.uni-kl.de# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2412027Sjungma@eit.uni-kl.de# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2512027Sjungma@eit.uni-kl.de# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2612027Sjungma@eit.uni-kl.de# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2712027Sjungma@eit.uni-kl.de# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2812027Sjungma@eit.uni-kl.de# 2912027Sjungma@eit.uni-kl.de# Authors: Steve Reinhardt 3012027Sjungma@eit.uni-kl.de 3112027Sjungma@eit.uni-kl.deimport os.path 3212027Sjungma@eit.uni-kl.de 3312027Sjungma@eit.uni-kl.de# Import build environment variable from SConstruct. 3412027Sjungma@eit.uni-kl.deImport('env') 3512027Sjungma@eit.uni-kl.de 3612027Sjungma@eit.uni-kl.de# Right now there are no source files immediately in this directory 3712027Sjungma@eit.uni-kl.desources = [] 3812027Sjungma@eit.uni-kl.de 3912027Sjungma@eit.uni-kl.de################################################################# 4012027Sjungma@eit.uni-kl.de# 4112027Sjungma@eit.uni-kl.de# ISA "switch header" generation. 4212027Sjungma@eit.uni-kl.de# 4312027Sjungma@eit.uni-kl.de# Auto-generate arch headers that include the right ISA-specific 4412027Sjungma@eit.uni-kl.de# header based on the setting of THE_ISA preprocessor variable. 4512027Sjungma@eit.uni-kl.de# 4612027Sjungma@eit.uni-kl.de################################################################# 4712027Sjungma@eit.uni-kl.de 4812027Sjungma@eit.uni-kl.de# List of headers to generate 4912027Sjungma@eit.uni-kl.deisa_switch_hdrs = Split(''' 5012027Sjungma@eit.uni-kl.de arguments.hh 5112027Sjungma@eit.uni-kl.de constants.hh 5212027Sjungma@eit.uni-kl.de faults.hh 5312027Sjungma@eit.uni-kl.de isa_traits.hh 5412027Sjungma@eit.uni-kl.de process.hh 5512027Sjungma@eit.uni-kl.de regfile.hh 5612027Sjungma@eit.uni-kl.de stacktrace.hh 5712027Sjungma@eit.uni-kl.de tlb.hh 5812027Sjungma@eit.uni-kl.de types.hh 5912027Sjungma@eit.uni-kl.de utility.hh 6012027Sjungma@eit.uni-kl.de vtophys.hh 6112027Sjungma@eit.uni-kl.de ''') 6212027Sjungma@eit.uni-kl.de 6312027Sjungma@eit.uni-kl.de# Generate the header. target[0] is the full path of the output 6412027Sjungma@eit.uni-kl.de# header to generate. 'source' is a dummy variable, since we get the 6512027Sjungma@eit.uni-kl.de# list of ISAs from env['ALL_ISA_LIST']. 6612027Sjungma@eit.uni-kl.dedef gen_switch_hdr(target, source, env): 6712027Sjungma@eit.uni-kl.de fname = str(target[0]) 6812027Sjungma@eit.uni-kl.de basename = os.path.basename(fname) 6912027Sjungma@eit.uni-kl.de f = open(fname, 'w') 7012027Sjungma@eit.uni-kl.de f.write('#include "arch/isa_specific.hh"\n') 7112027Sjungma@eit.uni-kl.de cond = '#if' 7212027Sjungma@eit.uni-kl.de for isa in env['ALL_ISA_LIST']: 7312027Sjungma@eit.uni-kl.de f.write('%s THE_ISA == %s_ISA\n#include "arch/%s/%s"\n' 7412027Sjungma@eit.uni-kl.de % (cond, isa.upper(), isa, basename)) 7512027Sjungma@eit.uni-kl.de cond = '#elif' 7612027Sjungma@eit.uni-kl.de f.write('#else\n#error "THE_ISA not set"\n#endif\n') 7712027Sjungma@eit.uni-kl.de f.close() 7812027Sjungma@eit.uni-kl.de return 0 7912027Sjungma@eit.uni-kl.de 8012027Sjungma@eit.uni-kl.de# String to print when generating header 8112027Sjungma@eit.uni-kl.dedef gen_switch_hdr_string(target, source, env): 8212027Sjungma@eit.uni-kl.de return "Generating ISA switch header " + str(target[0]) 8312027Sjungma@eit.uni-kl.de 8412027Sjungma@eit.uni-kl.de# Build SCons Action object. 'varlist' specifies env vars that this 8512027Sjungma@eit.uni-kl.de# action depends on; when env['ALL_ISA_LIST'] changes these actions 8612027Sjungma@eit.uni-kl.de# should get re-executed. 8712027Sjungma@eit.uni-kl.deswitch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string, 8812027Sjungma@eit.uni-kl.de varlist=['ALL_ISA_LIST']) 8912027Sjungma@eit.uni-kl.de 9012027Sjungma@eit.uni-kl.de# Instantiate actions for each header 9112027Sjungma@eit.uni-kl.defor hdr in isa_switch_hdrs: 9212027Sjungma@eit.uni-kl.de env.Command(hdr, [], switch_hdr_action) 9312027Sjungma@eit.uni-kl.de 9412027Sjungma@eit.uni-kl.de################################################################# 9512027Sjungma@eit.uni-kl.de# 9612027Sjungma@eit.uni-kl.de# Include architecture-specific files. 9712027Sjungma@eit.uni-kl.de# 9812027Sjungma@eit.uni-kl.de################################################################# 9912027Sjungma@eit.uni-kl.de 10012027Sjungma@eit.uni-kl.de# 10112027Sjungma@eit.uni-kl.de# Build a SCons scanner for ISA files 10212027Sjungma@eit.uni-kl.de# 10312027Sjungma@eit.uni-kl.deimport SCons.Scanner 10412027Sjungma@eit.uni-kl.de 10512027Sjungma@eit.uni-kl.deisa_scanner = SCons.Scanner.Classic("ISAScan", 10612027Sjungma@eit.uni-kl.de [".isa", ".ISA"], 10712027Sjungma@eit.uni-kl.de "SRCDIR", 10812027Sjungma@eit.uni-kl.de r'^\s*##include\s+"([\w/.-]*)"') 10912027Sjungma@eit.uni-kl.de 11012027Sjungma@eit.uni-kl.deenv.Append(SCANNERS = isa_scanner) 11112027Sjungma@eit.uni-kl.de 11212027Sjungma@eit.uni-kl.de# 11312027Sjungma@eit.uni-kl.de# Now create a Builder object that uses isa_parser.py to generate C++ 11412027Sjungma@eit.uni-kl.de# output from the ISA description (*.isa) files. 11512027Sjungma@eit.uni-kl.de# 11612027Sjungma@eit.uni-kl.de 11712027Sjungma@eit.uni-kl.de# Convert to File node to fix path 11812027Sjungma@eit.uni-kl.deisa_parser = File('isa_parser.py') 11912027Sjungma@eit.uni-kl.decpu_models_file = File('../cpu/cpu_models.py') 12012027Sjungma@eit.uni-kl.de 12112027Sjungma@eit.uni-kl.de# This sucks in the defintions of the CpuModel objects. 12212027Sjungma@eit.uni-kl.deexecfile(cpu_models_file.srcnode().abspath) 12312027Sjungma@eit.uni-kl.de 12412027Sjungma@eit.uni-kl.de# Several files are generated from the ISA description. 12512027Sjungma@eit.uni-kl.de# We always get the basic decoder and header file. 12612027Sjungma@eit.uni-kl.deisa_desc_gen_files = Split('decoder.cc decoder.hh') 12712027Sjungma@eit.uni-kl.de# We also get an execute file for each selected CPU model. 12812027Sjungma@eit.uni-kl.deisa_desc_gen_files += [CpuModel.dict[cpu].filename 12912027Sjungma@eit.uni-kl.de for cpu in env['CPU_MODELS']] 13012027Sjungma@eit.uni-kl.de 13112027Sjungma@eit.uni-kl.de# The emitter patches up the sources & targets to include the 13212027Sjungma@eit.uni-kl.de# autogenerated files as targets and isa parser itself as a source. 13312027Sjungma@eit.uni-kl.dedef isa_desc_emitter(target, source, env): 13412027Sjungma@eit.uni-kl.de return (isa_desc_gen_files, [isa_parser, cpu_models_file] + source) 13512027Sjungma@eit.uni-kl.de 13612027Sjungma@eit.uni-kl.de# Pieces are in place, so create the builder. 13712027Sjungma@eit.uni-kl.deisa_desc_builder = Builder(action='python2.4 $SOURCES $TARGET.dir $CPU_MODELS', 13812027Sjungma@eit.uni-kl.de emitter = isa_desc_emitter) 13912027Sjungma@eit.uni-kl.de 14012027Sjungma@eit.uni-kl.deenv.Append(BUILDERS = { 'ISADesc' : isa_desc_builder }) 14112027Sjungma@eit.uni-kl.de 14212027Sjungma@eit.uni-kl.de# 14312027Sjungma@eit.uni-kl.de# Now include other ISA-specific sources from the ISA subdirectories. 14412027Sjungma@eit.uni-kl.de# 14512027Sjungma@eit.uni-kl.de 14612027Sjungma@eit.uni-kl.deisa = env['TARGET_ISA'] # someday this may be a list of ISAs 14712027Sjungma@eit.uni-kl.de 14812027Sjungma@eit.uni-kl.de# Let the target architecture define what additional sources it needs 14912027Sjungma@eit.uni-kl.desources += SConscript(os.path.join(isa, 'SConscript'), 15012027Sjungma@eit.uni-kl.de exports = 'env', duplicate = False) 15112027Sjungma@eit.uni-kl.de 15212027Sjungma@eit.uni-kl.deReturn('sources') 15312027Sjungma@eit.uni-kl.de