SConscript revision 3170
14484Sbinkertn@umich.edu# -*- mode:python -*- 24484Sbinkertn@umich.edu 34484Sbinkertn@umich.edu# Copyright (c) 2006 The Regents of The University of Michigan 44484Sbinkertn@umich.edu# All rights reserved. 54484Sbinkertn@umich.edu# 64484Sbinkertn@umich.edu# Redistribution and use in source and binary forms, with or without 74484Sbinkertn@umich.edu# modification, are permitted provided that the following conditions are 84484Sbinkertn@umich.edu# met: redistributions of source code must retain the above copyright 94484Sbinkertn@umich.edu# notice, this list of conditions and the following disclaimer; 104484Sbinkertn@umich.edu# redistributions in binary form must reproduce the above copyright 114484Sbinkertn@umich.edu# notice, this list of conditions and the following disclaimer in the 124484Sbinkertn@umich.edu# documentation and/or other materials provided with the distribution; 134484Sbinkertn@umich.edu# neither the name of the copyright holders nor the names of its 144484Sbinkertn@umich.edu# contributors may be used to endorse or promote products derived from 154484Sbinkertn@umich.edu# this software without specific prior written permission. 164484Sbinkertn@umich.edu# 174484Sbinkertn@umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 184484Sbinkertn@umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 194484Sbinkertn@umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 204484Sbinkertn@umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 214484Sbinkertn@umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 224484Sbinkertn@umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 234484Sbinkertn@umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 244484Sbinkertn@umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 254484Sbinkertn@umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 264484Sbinkertn@umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 274484Sbinkertn@umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 284484Sbinkertn@umich.edu# 294484Sbinkertn@umich.edu# Authors: Steve Reinhardt 304484Sbinkertn@umich.edu 314484Sbinkertn@umich.eduimport os.path, sys 324484Sbinkertn@umich.edu 334484Sbinkertn@umich.edu# Import build environment variable from SConstruct. 344484Sbinkertn@umich.eduImport('env') 354484Sbinkertn@umich.edu 364484Sbinkertn@umich.edu# Right now there are no source files immediately in this directory 374484Sbinkertn@umich.edusources = [] 384484Sbinkertn@umich.edu 394484Sbinkertn@umich.edu################################################################# 404484Sbinkertn@umich.edu# 414484Sbinkertn@umich.edu# ISA "switch header" generation. 424484Sbinkertn@umich.edu# 434484Sbinkertn@umich.edu# Auto-generate arch headers that include the right ISA-specific 444484Sbinkertn@umich.edu# header based on the setting of THE_ISA preprocessor variable. 454484Sbinkertn@umich.edu# 464484Sbinkertn@umich.edu################################################################# 474484Sbinkertn@umich.edu 484484Sbinkertn@umich.edu# List of headers to generate 494484Sbinkertn@umich.eduisa_switch_hdrs = Split(''' 504484Sbinkertn@umich.edu arguments.hh 514484Sbinkertn@umich.edu faults.hh 524484Sbinkertn@umich.edu isa_traits.hh 534484Sbinkertn@umich.edu locked_mem.hh 544484Sbinkertn@umich.edu process.hh 554484Sbinkertn@umich.edu regfile.hh 564484Sbinkertn@umich.edu stacktrace.hh 574484Sbinkertn@umich.edu syscallreturn.hh 584484Sbinkertn@umich.edu tlb.hh 594484Sbinkertn@umich.edu types.hh 604484Sbinkertn@umich.edu utility.hh 614484Sbinkertn@umich.edu vtophys.hh 624484Sbinkertn@umich.edu ''') 634484Sbinkertn@umich.edu 644484Sbinkertn@umich.edu# Generate the header. target[0] is the full path of the output 654484Sbinkertn@umich.edu# header to generate. 'source' is a dummy variable, since we get the 664484Sbinkertn@umich.edu# list of ISAs from env['ALL_ISA_LIST']. 674484Sbinkertn@umich.edudef gen_switch_hdr(target, source, env): 684484Sbinkertn@umich.edu fname = str(target[0]) 694484Sbinkertn@umich.edu basename = os.path.basename(fname) 704484Sbinkertn@umich.edu f = open(fname, 'w') 714484Sbinkertn@umich.edu f.write('#include "arch/isa_specific.hh"\n') 724484Sbinkertn@umich.edu cond = '#if' 734484Sbinkertn@umich.edu for isa in env['ALL_ISA_LIST']: 744484Sbinkertn@umich.edu f.write('%s THE_ISA == %s_ISA\n#include "arch/%s/%s"\n' 754484Sbinkertn@umich.edu % (cond, isa.upper(), isa, basename)) 764484Sbinkertn@umich.edu cond = '#elif' 774484Sbinkertn@umich.edu f.write('#else\n#error "THE_ISA not set"\n#endif\n') 784484Sbinkertn@umich.edu f.close() 794484Sbinkertn@umich.edu return 0 804484Sbinkertn@umich.edu 814484Sbinkertn@umich.edu# String to print when generating header 824484Sbinkertn@umich.edudef gen_switch_hdr_string(target, source, env): 834484Sbinkertn@umich.edu return "Generating ISA switch header " + str(target[0]) 844484Sbinkertn@umich.edu 854484Sbinkertn@umich.edu# Build SCons Action object. 'varlist' specifies env vars that this 864484Sbinkertn@umich.edu# action depends on; when env['ALL_ISA_LIST'] changes these actions 874484Sbinkertn@umich.edu# should get re-executed. 884484Sbinkertn@umich.eduswitch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string, 894484Sbinkertn@umich.edu varlist=['ALL_ISA_LIST']) 904484Sbinkertn@umich.edu 914484Sbinkertn@umich.edu# Instantiate actions for each header 924484Sbinkertn@umich.edufor hdr in isa_switch_hdrs: 934484Sbinkertn@umich.edu env.Command(hdr, [], switch_hdr_action) 944484Sbinkertn@umich.edu 954484Sbinkertn@umich.edu################################################################# 964484Sbinkertn@umich.edu# 974484Sbinkertn@umich.edu# Include architecture-specific files. 984484Sbinkertn@umich.edu# 994484Sbinkertn@umich.edu################################################################# 1004484Sbinkertn@umich.edu 1014484Sbinkertn@umich.edu# 1024484Sbinkertn@umich.edu# Build a SCons scanner for ISA files 1034484Sbinkertn@umich.edu# 1044484Sbinkertn@umich.eduimport SCons.Scanner 1054484Sbinkertn@umich.edu 1064484Sbinkertn@umich.eduisa_scanner = SCons.Scanner.Classic("ISAScan", 1074484Sbinkertn@umich.edu [".isa", ".ISA"], 1084484Sbinkertn@umich.edu "SRCDIR", 1094484Sbinkertn@umich.edu r'^\s*##include\s+"([\w/.-]*)"') 1104484Sbinkertn@umich.edu 1114484Sbinkertn@umich.eduenv.Append(SCANNERS = isa_scanner) 1124484Sbinkertn@umich.edu 1134484Sbinkertn@umich.edu# 1144484Sbinkertn@umich.edu# Now create a Builder object that uses isa_parser.py to generate C++ 1154484Sbinkertn@umich.edu# output from the ISA description (*.isa) files. 1164484Sbinkertn@umich.edu# 1174484Sbinkertn@umich.edu 1184484Sbinkertn@umich.edu# Convert to File node to fix path 1194484Sbinkertn@umich.eduisa_parser = File('isa_parser.py') 1204484Sbinkertn@umich.educpu_models_file = File('../cpu/cpu_models.py') 1214484Sbinkertn@umich.edu 1224484Sbinkertn@umich.edu# This sucks in the defintions of the CpuModel objects. 1234484Sbinkertn@umich.eduexecfile(cpu_models_file.srcnode().abspath) 1244484Sbinkertn@umich.edu 1254484Sbinkertn@umich.edu# Several files are generated from the ISA description. 1264484Sbinkertn@umich.edu# We always get the basic decoder and header file. 1274484Sbinkertn@umich.eduisa_desc_gen_files = Split('decoder.cc decoder.hh') 1284484Sbinkertn@umich.edu# We also get an execute file for each selected CPU model. 1294484Sbinkertn@umich.eduisa_desc_gen_files += [CpuModel.dict[cpu].filename 1304484Sbinkertn@umich.edu for cpu in env['CPU_MODELS']] 1314484Sbinkertn@umich.edu 1324484Sbinkertn@umich.edu# Also include the CheckerCPU as one of the models if it is being 1334484Sbinkertn@umich.edu# enabled via command line. 134if env['USE_CHECKER']: 135 isa_desc_gen_files += [CpuModel.dict['CheckerCPU'].filename] 136 137# The emitter patches up the sources & targets to include the 138# autogenerated files as targets and isa parser itself as a source. 139def isa_desc_emitter(target, source, env): 140 return (isa_desc_gen_files, [isa_parser, cpu_models_file] + source) 141 142# Pieces are in place, so create the builder. 143python = sys.executable # use same Python binary used to run scons 144 145# Also include the CheckerCPU as one of the models if it is being 146# enabled via command line. 147if env['USE_CHECKER']: 148 isa_desc_builder = Builder(action=python + ' $SOURCES $TARGET.dir $CPU_MODELS CheckerCPU', 149 emitter = isa_desc_emitter) 150else: 151 isa_desc_builder = Builder(action=python + ' $SOURCES $TARGET.dir $CPU_MODELS', 152 emitter = isa_desc_emitter) 153 154env.Append(BUILDERS = { 'ISADesc' : isa_desc_builder }) 155 156# 157# Now include other ISA-specific sources from the ISA subdirectories. 158# 159 160isa = env['TARGET_ISA'] # someday this may be a list of ISAs 161 162# Let the target architecture define what additional sources it needs 163sources += SConscript(os.path.join(isa, 'SConscript'), exports = 'env') 164 165Return('sources') 166