SConscript revision 2178
12650Ssaidi@eecs.umich.edu# -*- mode:python -*- 22650Ssaidi@eecs.umich.edu 32650Ssaidi@eecs.umich.edu# Copyright (c) 2006 The Regents of The University of Michigan 42650Ssaidi@eecs.umich.edu# All rights reserved. 52650Ssaidi@eecs.umich.edu# 62650Ssaidi@eecs.umich.edu# Redistribution and use in source and binary forms, with or without 72650Ssaidi@eecs.umich.edu# modification, are permitted provided that the following conditions are 82650Ssaidi@eecs.umich.edu# met: redistributions of source code must retain the above copyright 92650Ssaidi@eecs.umich.edu# notice, this list of conditions and the following disclaimer; 102650Ssaidi@eecs.umich.edu# redistributions in binary form must reproduce the above copyright 112650Ssaidi@eecs.umich.edu# notice, this list of conditions and the following disclaimer in the 122650Ssaidi@eecs.umich.edu# documentation and/or other materials provided with the distribution; 132650Ssaidi@eecs.umich.edu# neither the name of the copyright holders nor the names of its 142650Ssaidi@eecs.umich.edu# contributors may be used to endorse or promote products derived from 152650Ssaidi@eecs.umich.edu# this software without specific prior written permission. 162650Ssaidi@eecs.umich.edu# 172650Ssaidi@eecs.umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 182650Ssaidi@eecs.umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 192650Ssaidi@eecs.umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 202650Ssaidi@eecs.umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 212650Ssaidi@eecs.umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 222650Ssaidi@eecs.umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 232650Ssaidi@eecs.umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 242650Ssaidi@eecs.umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 252650Ssaidi@eecs.umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 262650Ssaidi@eecs.umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 272650Ssaidi@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 282650Ssaidi@eecs.umich.edu 2913912Sgabeblack@google.comimport os.path 306335Sgblack@eecs.umich.edu 314194Ssaidi@eecs.umich.edu# Import build environment variable from SConstruct. 326335Sgblack@eecs.umich.eduImport('env') 333817Ssaidi@eecs.umich.edu 343817Ssaidi@eecs.umich.edu# Right now there are no source files immediately in this directory 353817Ssaidi@eecs.umich.edusources = [] 363817Ssaidi@eecs.umich.edu 378232Snate@binkert.org################################################################# 388232Snate@binkert.org# 3911793Sbrandon.potter@amd.com# ISA "switch header" generation. 404194Ssaidi@eecs.umich.edu# 412650Ssaidi@eecs.umich.edu# Auto-generate arch headers that include the right ISA-specific 423817Ssaidi@eecs.umich.edu# header based on the setting of THE_ISA preprocessor variable. 435946Sgblack@eecs.umich.edu# 443817Ssaidi@eecs.umich.edu################################################################# 454103Ssaidi@eecs.umich.edu 464103Ssaidi@eecs.umich.edu# List of headers to generate 476335Sgblack@eecs.umich.eduisa_switch_hdrs = Split(''' 484103Ssaidi@eecs.umich.edu isa_traits.hh 495531Snate@binkert.org ''') 505531Snate@binkert.org 514103Ssaidi@eecs.umich.edu# Generate the header. target[0] is the full path of the output 524103Ssaidi@eecs.umich.edu# header to generate. 'source' is a dummy variable, since we get the 5311150Smitch.hayenga@arm.com# list of ISAs from env['ALL_ISA_LIST']. 544103Ssaidi@eecs.umich.edudef gen_switch_hdr(target, source, env): 5511150Smitch.hayenga@arm.com fname = str(target[0]) 564103Ssaidi@eecs.umich.edu basename = os.path.basename(fname) 5711150Smitch.hayenga@arm.com f = open(fname, 'w') 584103Ssaidi@eecs.umich.edu f.write('#include "arch/isa_specific.hh"\n') 5911150Smitch.hayenga@arm.com cond = '#if' 604103Ssaidi@eecs.umich.edu for isa in env['ALL_ISA_LIST']: 614103Ssaidi@eecs.umich.edu f.write('%s THE_ISA == %s_ISA\n#include "arch/%s/%s"\n' 624103Ssaidi@eecs.umich.edu % (cond, isa.upper(), isa, basename)) 634103Ssaidi@eecs.umich.edu cond = '#elif' 6411150Smitch.hayenga@arm.com f.write('#else\n#error "THE_ISA not set"\n#endif\n') 654103Ssaidi@eecs.umich.edu f.close() 6611150Smitch.hayenga@arm.com return 0 674103Ssaidi@eecs.umich.edu 684103Ssaidi@eecs.umich.edu# String to print when generating header 694103Ssaidi@eecs.umich.edudef gen_switch_hdr_string(target, source, env): 707741Sgblack@eecs.umich.edu return "Generating ISA switch header " + str(target[0]) 715946Sgblack@eecs.umich.edu 725946Sgblack@eecs.umich.edu# Build SCons Action object. 'varlist' specifies env vars that this 735946Sgblack@eecs.umich.edu# action depends on; when env['ALL_ISA_LIST'] changes these actions 745946Sgblack@eecs.umich.edu# should get re-executed. 755946Sgblack@eecs.umich.eduswitch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string, 765946Sgblack@eecs.umich.edu varlist=['ALL_ISA_LIST']) 775946Sgblack@eecs.umich.edu 785946Sgblack@eecs.umich.edu# Instantiate actions for each header 795946Sgblack@eecs.umich.edufor hdr in isa_switch_hdrs: 805946Sgblack@eecs.umich.edu env.Command(hdr, [], switch_hdr_action) 815946Sgblack@eecs.umich.edu 825946Sgblack@eecs.umich.edu################################################################# 835946Sgblack@eecs.umich.edu# 845946Sgblack@eecs.umich.edu# Include architecture-specific files. 855946Sgblack@eecs.umich.edu# 865946Sgblack@eecs.umich.edu################################################################# 875946Sgblack@eecs.umich.edu 885946Sgblack@eecs.umich.edu# 895946Sgblack@eecs.umich.edu# Build a SCons scanner for ISA files 904103Ssaidi@eecs.umich.edu# 913817Ssaidi@eecs.umich.eduimport SCons.Scanner 9213583Sgabeblack@google.com 932650Ssaidi@eecs.umich.edudef ISAScan(): 945531Snate@binkert.org return SCons.Scanner.Classic("ISAScan", 955531Snate@binkert.org "$ISASUFFIXES", 962650Ssaidi@eecs.umich.edu "SRCDIR", 972650Ssaidi@eecs.umich.edu '^[ \t]*##[ \t]*include[ \t]*"([^>"]+)"') 982982Sstever@eecs.umich.edu 993919Shsul@eecs.umich.edudef ISAPath(env, dir, target=None, source=None, a=None): 1006335Sgblack@eecs.umich.edu return (Dir(env['SRCDIR']), Dir('.')) 1014103Ssaidi@eecs.umich.edu 1023919Shsul@eecs.umich.eduiscan = Scanner(function = ISAScan().scan, skeys = [".isa", ".ISA"], 1033919Shsul@eecs.umich.edu path_function = ISAPath) 1046335Sgblack@eecs.umich.eduenv.Append(SCANNERS = iscan) 1053919Shsul@eecs.umich.edu 1066335Sgblack@eecs.umich.edu# 1072650Ssaidi@eecs.umich.edu# Now create a Builder object that uses isa_parser.py to generate C++ 1083919Shsul@eecs.umich.edu# output from the ISA description (*.isa) files. 1093919Shsul@eecs.umich.edu# 1103919Shsul@eecs.umich.edu 1116335Sgblack@eecs.umich.edu# Convert to File node to fix path 1124103Ssaidi@eecs.umich.eduisa_parser = File('isa_parser.py') 1135606Snate@binkert.orgcpu_models_file = File('#m5/cpu/cpu_models.py') 1143919Shsul@eecs.umich.edu 1154103Ssaidi@eecs.umich.edu# This sucks in the defintions of the CpuModel objects. 1164103Ssaidi@eecs.umich.eduexecfile(cpu_models_file.srcnode().abspath) 1175606Snate@binkert.org 1189180Sandreas.hansson@arm.com# Several files are generated from the ISA description. 1194103Ssaidi@eecs.umich.edu# We always get the basic decoder and header file. 12011102Spalle@lyckegaard.dkisa_desc_gen_files = Split('decoder.cc decoder.hh') 1213919Shsul@eecs.umich.edu# We also get an execute file for each selected CPU model. 1222650Ssaidi@eecs.umich.eduisa_desc_gen_files += [CpuModel.dict[cpu].filename 1233919Shsul@eecs.umich.edu for cpu in env['CPU_MODELS']] 1243919Shsul@eecs.umich.edu 1253919Shsul@eecs.umich.edu# The emitter patches up the sources & targets to include the 1266335Sgblack@eecs.umich.edu# autogenerated files as targets and isa parser itself as a source. 1273919Shsul@eecs.umich.edudef isa_desc_emitter(target, source, env): 1285606Snate@binkert.org return (isa_desc_gen_files, [isa_parser, cpu_models_file] + source) 1293919Shsul@eecs.umich.edu 1305531Snate@binkert.org# Pieces are in place, so create the builder. 1314103Ssaidi@eecs.umich.eduisa_desc_builder = Builder(action='$SOURCES $TARGET.dir $CPU_MODELS', 1324103Ssaidi@eecs.umich.edu source_scanner = iscan, 1335606Snate@binkert.org emitter = isa_desc_emitter) 1349180Sandreas.hansson@arm.com 1354103Ssaidi@eecs.umich.eduenv.Append(BUILDERS = { 'ISADesc' : isa_desc_builder }) 1363919Shsul@eecs.umich.edu 1373919Shsul@eecs.umich.edu# 1382650Ssaidi@eecs.umich.edu# Now include other ISA-specific sources from the ISA subdirectories. 1393919Shsul@eecs.umich.edu# 1406335Sgblack@eecs.umich.edu 14112620Sgabeblack@google.comisa = env['TARGET_ISA'] # someday this may be a list of ISAs 1423827Shsul@eecs.umich.edu 1433919Shsul@eecs.umich.edu# Let the target architecture define what additional sources it needs 1446335Sgblack@eecs.umich.edusources += SConscript(os.path.join(isa, 'SConscript'), 1454103Ssaidi@eecs.umich.edu exports = 'env', duplicate = False) 1463919Shsul@eecs.umich.edu 1472650Ssaidi@eecs.umich.eduReturn('sources') 1483919Shsul@eecs.umich.edu