SConscript revision 2504
1955SN/A# -*- mode:python -*- 2955SN/A 310841Sandreas.sandberg@arm.com# Copyright (c) 2006 The Regents of The University of Michigan 49812Sandreas.hansson@arm.com# All rights reserved. 59812Sandreas.hansson@arm.com# 69812Sandreas.hansson@arm.com# Redistribution and use in source and binary forms, with or without 79812Sandreas.hansson@arm.com# modification, are permitted provided that the following conditions are 89812Sandreas.hansson@arm.com# met: redistributions of source code must retain the above copyright 99812Sandreas.hansson@arm.com# notice, this list of conditions and the following disclaimer; 109812Sandreas.hansson@arm.com# redistributions in binary form must reproduce the above copyright 119812Sandreas.hansson@arm.com# notice, this list of conditions and the following disclaimer in the 129812Sandreas.hansson@arm.com# documentation and/or other materials provided with the distribution; 139812Sandreas.hansson@arm.com# neither the name of the copyright holders nor the names of its 149812Sandreas.hansson@arm.com# contributors may be used to endorse or promote products derived from 157816Ssteve.reinhardt@amd.com# this software without specific prior written permission. 165871Snate@binkert.org# 171762SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26955SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27955SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28955SN/A 29955SN/Aimport os.path 30955SN/A 31955SN/A# Import build environment variable from SConstruct. 32955SN/AImport('env') 33955SN/A 34955SN/A# Right now there are no source files immediately in this directory 35955SN/Asources = [] 36955SN/A 37955SN/A################################################################# 38955SN/A# 39955SN/A# ISA "switch header" generation. 40955SN/A# 41955SN/A# Auto-generate arch headers that include the right ISA-specific 422665Ssaidi@eecs.umich.edu# header based on the setting of THE_ISA preprocessor variable. 432665Ssaidi@eecs.umich.edu# 445863Snate@binkert.org################################################################# 45955SN/A 46955SN/A# List of headers to generate 47955SN/Aisa_switch_hdrs = Split(''' 48955SN/A arguments.hh 49955SN/A constants.hh 508878Ssteve.reinhardt@amd.com faults.hh 512632Sstever@eecs.umich.edu isa_traits.hh 528878Ssteve.reinhardt@amd.com process.hh 532632Sstever@eecs.umich.edu regfile.hh 54955SN/A stacktrace.hh 558878Ssteve.reinhardt@amd.com tlb.hh 562632Sstever@eecs.umich.edu types.hh 572761Sstever@eecs.umich.edu utility.hh 582632Sstever@eecs.umich.edu vtophys.hh 592632Sstever@eecs.umich.edu ''') 602632Sstever@eecs.umich.edu 612761Sstever@eecs.umich.edu# Generate the header. target[0] is the full path of the output 622761Sstever@eecs.umich.edu# header to generate. 'source' is a dummy variable, since we get the 632761Sstever@eecs.umich.edu# list of ISAs from env['ALL_ISA_LIST']. 648878Ssteve.reinhardt@amd.comdef gen_switch_hdr(target, source, env): 658878Ssteve.reinhardt@amd.com fname = str(target[0]) 662761Sstever@eecs.umich.edu basename = os.path.basename(fname) 672761Sstever@eecs.umich.edu f = open(fname, 'w') 682761Sstever@eecs.umich.edu f.write('#include "arch/isa_specific.hh"\n') 692761Sstever@eecs.umich.edu cond = '#if' 702761Sstever@eecs.umich.edu for isa in env['ALL_ISA_LIST']: 718878Ssteve.reinhardt@amd.com f.write('%s THE_ISA == %s_ISA\n#include "arch/%s/%s"\n' 728878Ssteve.reinhardt@amd.com % (cond, isa.upper(), isa, basename)) 732632Sstever@eecs.umich.edu cond = '#elif' 742632Sstever@eecs.umich.edu f.write('#else\n#error "THE_ISA not set"\n#endif\n') 758878Ssteve.reinhardt@amd.com f.close() 768878Ssteve.reinhardt@amd.com return 0 772632Sstever@eecs.umich.edu 78955SN/A# String to print when generating header 79955SN/Adef gen_switch_hdr_string(target, source, env): 80955SN/A return "Generating ISA switch header " + str(target[0]) 815863Snate@binkert.org 825863Snate@binkert.org# Build SCons Action object. 'varlist' specifies env vars that this 835863Snate@binkert.org# action depends on; when env['ALL_ISA_LIST'] changes these actions 845863Snate@binkert.org# should get re-executed. 855863Snate@binkert.orgswitch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string, 865863Snate@binkert.org varlist=['ALL_ISA_LIST']) 875863Snate@binkert.org 885863Snate@binkert.org# Instantiate actions for each header 895863Snate@binkert.orgfor hdr in isa_switch_hdrs: 905863Snate@binkert.org env.Command(hdr, [], switch_hdr_action) 915863Snate@binkert.org 928878Ssteve.reinhardt@amd.com################################################################# 935863Snate@binkert.org# 945863Snate@binkert.org# Include architecture-specific files. 955863Snate@binkert.org# 969812Sandreas.hansson@arm.com################################################################# 979812Sandreas.hansson@arm.com 985863Snate@binkert.org# 999812Sandreas.hansson@arm.com# Build a SCons scanner for ISA files 1005863Snate@binkert.org# 1015863Snate@binkert.orgimport SCons.Scanner 1025863Snate@binkert.org 1039812Sandreas.hansson@arm.comisa_scanner = SCons.Scanner.Classic("ISAScan", 1049812Sandreas.hansson@arm.com [".isa", ".ISA"], 1055863Snate@binkert.org "SRCDIR", 1065863Snate@binkert.org r'^\s*##include\s+"([\w/.-]*)"') 1078878Ssteve.reinhardt@amd.com 1085863Snate@binkert.orgenv.Append(SCANNERS = isa_scanner) 1095863Snate@binkert.org 1105863Snate@binkert.org# 1116654Snate@binkert.org# Now create a Builder object that uses isa_parser.py to generate C++ 11210196SCurtis.Dunham@arm.com# output from the ISA description (*.isa) files. 113955SN/A# 1145396Ssaidi@eecs.umich.edu 1155863Snate@binkert.org# Convert to File node to fix path 1165863Snate@binkert.orgisa_parser = File('isa_parser.py') 1174202Sbinkertn@umich.educpu_models_file = File('#m5/cpu/cpu_models.py') 1185863Snate@binkert.org 1195863Snate@binkert.org# This sucks in the defintions of the CpuModel objects. 1205863Snate@binkert.orgexecfile(cpu_models_file.srcnode().abspath) 1215863Snate@binkert.org 122955SN/A# Several files are generated from the ISA description. 1236654Snate@binkert.org# We always get the basic decoder and header file. 1245273Sstever@gmail.comisa_desc_gen_files = Split('decoder.cc decoder.hh') 1255871Snate@binkert.org# We also get an execute file for each selected CPU model. 1265273Sstever@gmail.comisa_desc_gen_files += [CpuModel.dict[cpu].filename 1276655Snate@binkert.org for cpu in env['CPU_MODELS']] 1288878Ssteve.reinhardt@amd.com 1296655Snate@binkert.org# The emitter patches up the sources & targets to include the 1306655Snate@binkert.org# autogenerated files as targets and isa parser itself as a source. 1319219Spower.jg@gmail.comdef isa_desc_emitter(target, source, env): 1326655Snate@binkert.org return (isa_desc_gen_files, [isa_parser, cpu_models_file] + source) 1335871Snate@binkert.org 1346654Snate@binkert.org# Pieces are in place, so create the builder. 1358947Sandreas.hansson@arm.comisa_desc_builder = Builder(action='python $SOURCES $TARGET.dir $CPU_MODELS', 1365396Ssaidi@eecs.umich.edu emitter = isa_desc_emitter) 1378120Sgblack@eecs.umich.edu 1388120Sgblack@eecs.umich.eduenv.Append(BUILDERS = { 'ISADesc' : isa_desc_builder }) 1398120Sgblack@eecs.umich.edu 1408120Sgblack@eecs.umich.edu# 1418120Sgblack@eecs.umich.edu# Now include other ISA-specific sources from the ISA subdirectories. 1428120Sgblack@eecs.umich.edu# 1438120Sgblack@eecs.umich.edu 1448120Sgblack@eecs.umich.eduisa = env['TARGET_ISA'] # someday this may be a list of ISAs 1458879Ssteve.reinhardt@amd.com 1468879Ssteve.reinhardt@amd.com# Let the target architecture define what additional sources it needs 1478879Ssteve.reinhardt@amd.comsources += SConscript(os.path.join(isa, 'SConscript'), 1488879Ssteve.reinhardt@amd.com exports = 'env', duplicate = False) 1498879Ssteve.reinhardt@amd.com 1508879Ssteve.reinhardt@amd.comReturn('sources') 1518879Ssteve.reinhardt@amd.com