SConscript revision 3534
12139SN/A# -*- mode:python -*- 22139SN/A 32139SN/A# Copyright (c) 2006 The Regents of The University of Michigan 42139SN/A# All rights reserved. 52139SN/A# 62139SN/A# Redistribution and use in source and binary forms, with or without 72139SN/A# modification, are permitted provided that the following conditions are 82139SN/A# met: redistributions of source code must retain the above copyright 92139SN/A# notice, this list of conditions and the following disclaimer; 102139SN/A# redistributions in binary form must reproduce the above copyright 112139SN/A# notice, this list of conditions and the following disclaimer in the 122139SN/A# documentation and/or other materials provided with the distribution; 132139SN/A# neither the name of the copyright holders nor the names of its 142139SN/A# contributors may be used to endorse or promote products derived from 152139SN/A# this software without specific prior written permission. 162139SN/A# 172139SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 182139SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 192139SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 202139SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 212139SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 222139SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 232139SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 242139SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 252139SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 262139SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 272139SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 282665Ssaidi@eecs.umich.edu# 292665Ssaidi@eecs.umich.edu# Authors: Steve Reinhardt 302139SN/A 314202Sbinkertn@umich.eduimport os.path, sys 322139SN/A 334202Sbinkertn@umich.edu# Import build environment variable from SConstruct. 342152SN/AImport('env') 352152SN/A 362139SN/A# Right now there are no source files immediately in this directory 372139SN/Asources = [] 382139SN/A 392139SN/A################################################################# 402139SN/A# 412152SN/A# ISA "switch header" generation. 422152SN/A# 432139SN/A# Auto-generate arch headers that include the right ISA-specific 442139SN/A# header based on the setting of THE_ISA preprocessor variable. 452139SN/A# 462984Sgblack@eecs.umich.edu################################################################# 472439SN/A 483520Sgblack@eecs.umich.edu# List of headers to generate 492139SN/Aisa_switch_hdrs = Split(''' 503565Sgblack@eecs.umich.edu arguments.hh 513170Sstever@eecs.umich.edu faults.hh 523806Ssaidi@eecs.umich.edu interrupts.hh 532439SN/A isa_traits.hh 544182Sgblack@eecs.umich.edu locked_mem.hh 552460SN/A process.hh 563536Sgblack@eecs.umich.edu regfile.hh 572439SN/A stacktrace.hh 582972Sgblack@eecs.umich.edu syscallreturn.hh 592171SN/A tlb.hh 602439SN/A types.hh 612439SN/A utility.hh 622170SN/A vtophys.hh 632139SN/A ''') 642139SN/A 653546Sgblack@eecs.umich.edu# Generate the header. target[0] is the full path of the output 664202Sbinkertn@umich.edu# header to generate. 'source' is a dummy variable, since we get the 672152SN/A# list of ISAs from env['ALL_ISA_LIST']. 682152SN/Adef gen_switch_hdr(target, source, env): 692152SN/A fname = str(target[0]) 702152SN/A basename = os.path.basename(fname) 712152SN/A f = open(fname, 'w') 722152SN/A f.write('#include "arch/isa_specific.hh"\n') 732152SN/A cond = '#if' 742152SN/A for isa in env['ALL_ISA_LIST']: 752152SN/A f.write('%s THE_ISA == %s_ISA\n#include "arch/%s/%s"\n' 762152SN/A % (cond, isa.upper(), isa, basename)) 772152SN/A cond = '#elif' 782152SN/A f.write('#else\n#error "THE_ISA not set"\n#endif\n') 792504SN/A f.close() 802504SN/A return 0 812504SN/A 822504SN/A# String to print when generating header 832152SN/Adef gen_switch_hdr_string(target, source, env): 842504SN/A return "Generating ISA switch header " + str(target[0]) 852152SN/A 862152SN/A# Build SCons Action object. 'varlist' specifies env vars that this 872152SN/A# action depends on; when env['ALL_ISA_LIST'] changes these actions 882152SN/A# should get re-executed. 892152SN/Aswitch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string, 902152SN/A varlist=['ALL_ISA_LIST']) 912152SN/A 922152SN/A# Instantiate actions for each header 932632Sstever@eecs.umich.edufor hdr in isa_switch_hdrs: 942155SN/A env.Command(hdr, [], switch_hdr_action) 952155SN/A 962155SN/A################################################################# 972155SN/A# 982155SN/A# Include architecture-specific files. 992155SN/A# 1004202Sbinkertn@umich.edu################################################################# 1012155SN/A 1022155SN/A# 1032155SN/A# Build a SCons scanner for ISA files 1042152SN/A# 1052766Sktlim@umich.eduimport SCons.Scanner 1062766Sktlim@umich.edu 1072766Sktlim@umich.eduisa_scanner = SCons.Scanner.Classic("ISAScan", 1082766Sktlim@umich.edu [".isa", ".ISA"], 1092766Sktlim@umich.edu "SRCDIR", 1102152SN/A r'^\s*##include\s+"([\w/.-]*)"') 1112152SN/A 1122152SN/Aenv.Append(SCANNERS = isa_scanner) 1132155SN/A 1142152SN/A# 1152152SN/A# Now create a Builder object that uses isa_parser.py to generate C++ 1162718Sstever@eecs.umich.edu# output from the ISA description (*.isa) files. 1172921Sktlim@umich.edu# 1182921Sktlim@umich.edu 1192921Sktlim@umich.edu# Convert to File node to fix path 1202921Sktlim@umich.eduisa_parser = File('isa_parser.py') 1212921Sktlim@umich.educpu_models_file = File('../cpu/cpu_models.py') 1222921Sktlim@umich.edu 1232921Sktlim@umich.edu# This sucks in the defintions of the CpuModel objects. 1242921Sktlim@umich.eduexecfile(cpu_models_file.srcnode().abspath) 1252921Sktlim@umich.edu 1262152SN/A# Several files are generated from the ISA description. 1272152SN/A# We always get the basic decoder and header file. 128isa_desc_gen_files = Split('decoder.cc decoder.hh') 129# We also get an execute file for each selected CPU model. 130isa_desc_gen_files += [CpuModel.dict[cpu].filename 131 for cpu in env['CPU_MODELS']] 132 133# Also include the CheckerCPU as one of the models if it is being 134# enabled via command line. 135if env['USE_CHECKER']: 136 isa_desc_gen_files += [CpuModel.dict['CheckerCPU'].filename] 137 138# The emitter patches up the sources & targets to include the 139# autogenerated files as targets and isa parser itself as a source. 140def isa_desc_emitter(target, source, env): 141 return (isa_desc_gen_files, [isa_parser, cpu_models_file] + source) 142 143# Pieces are in place, so create the builder. 144python = sys.executable # use same Python binary used to run scons 145 146# Also include the CheckerCPU as one of the models if it is being 147# enabled via command line. 148if env['USE_CHECKER']: 149 isa_desc_builder = Builder(action=python + ' $SOURCES $TARGET.dir $CPU_MODELS CheckerCPU', 150 emitter = isa_desc_emitter) 151else: 152 isa_desc_builder = Builder(action=python + ' $SOURCES $TARGET.dir $CPU_MODELS', 153 emitter = isa_desc_emitter) 154 155env.Append(BUILDERS = { 'ISADesc' : isa_desc_builder }) 156 157# 158# Now include other ISA-specific sources from the ISA subdirectories. 159# 160 161isa = env['TARGET_ISA'] # someday this may be a list of ISAs 162 163# Let the target architecture define what additional sources it needs 164sources += SConscript(os.path.join(isa, 'SConscript'), exports = 'env') 165 166Return('sources') 167