SConscript revision 3520
14120Sgblack@eecs.umich.edu# -*- mode:python -*- 24120Sgblack@eecs.umich.edu 34120Sgblack@eecs.umich.edu# Copyright (c) 2006 The Regents of The University of Michigan 44120Sgblack@eecs.umich.edu# All rights reserved. 54120Sgblack@eecs.umich.edu# 64120Sgblack@eecs.umich.edu# Redistribution and use in source and binary forms, with or without 74120Sgblack@eecs.umich.edu# modification, are permitted provided that the following conditions are 84120Sgblack@eecs.umich.edu# met: redistributions of source code must retain the above copyright 94120Sgblack@eecs.umich.edu# notice, this list of conditions and the following disclaimer; 104120Sgblack@eecs.umich.edu# redistributions in binary form must reproduce the above copyright 114120Sgblack@eecs.umich.edu# notice, this list of conditions and the following disclaimer in the 124120Sgblack@eecs.umich.edu# documentation and/or other materials provided with the distribution; 134120Sgblack@eecs.umich.edu# neither the name of the copyright holders nor the names of its 144120Sgblack@eecs.umich.edu# contributors may be used to endorse or promote products derived from 154120Sgblack@eecs.umich.edu# this software without specific prior written permission. 164120Sgblack@eecs.umich.edu# 174120Sgblack@eecs.umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 184120Sgblack@eecs.umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 194120Sgblack@eecs.umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 204120Sgblack@eecs.umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 214120Sgblack@eecs.umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 224120Sgblack@eecs.umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 234120Sgblack@eecs.umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 244120Sgblack@eecs.umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 254120Sgblack@eecs.umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 264120Sgblack@eecs.umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 274120Sgblack@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 284120Sgblack@eecs.umich.edu# 294120Sgblack@eecs.umich.edu# Authors: Steve Reinhardt 304120Sgblack@eecs.umich.edu 314120Sgblack@eecs.umich.eduimport os.path, sys 324120Sgblack@eecs.umich.edu 334120Sgblack@eecs.umich.edu# Import build environment variable from SConstruct. 344120Sgblack@eecs.umich.eduImport('env') 354120Sgblack@eecs.umich.edu 364120Sgblack@eecs.umich.edu# Right now there are no source files immediately in this directory 374120Sgblack@eecs.umich.edusources = [] 384120Sgblack@eecs.umich.edu 394120Sgblack@eecs.umich.edu################################################################# 404120Sgblack@eecs.umich.edu# 414120Sgblack@eecs.umich.edu# ISA "switch header" generation. 424120Sgblack@eecs.umich.edu# 434120Sgblack@eecs.umich.edu# Auto-generate arch headers that include the right ISA-specific 444120Sgblack@eecs.umich.edu# header based on the setting of THE_ISA preprocessor variable. 454120Sgblack@eecs.umich.edu# 464120Sgblack@eecs.umich.edu################################################################# 474120Sgblack@eecs.umich.edu 484120Sgblack@eecs.umich.edu# List of headers to generate 494120Sgblack@eecs.umich.eduisa_switch_hdrs = Split(''' 504120Sgblack@eecs.umich.edu arguments.hh 514120Sgblack@eecs.umich.edu faults.hh 524120Sgblack@eecs.umich.edu interrupts.hh 534120Sgblack@eecs.umich.edu isa_traits.hh 544120Sgblack@eecs.umich.edu locked_mem.hh 554120Sgblack@eecs.umich.edu process.hh 564120Sgblack@eecs.umich.edu regfile.hh 574120Sgblack@eecs.umich.edu stacktrace.hh 584120Sgblack@eecs.umich.edu syscallreturn.hh 594120Sgblack@eecs.umich.edu tlb.hh 604120Sgblack@eecs.umich.edu types.hh 614120Sgblack@eecs.umich.edu utility.hh 624120Sgblack@eecs.umich.edu vtophys.hh 634120Sgblack@eecs.umich.edu ''') 644120Sgblack@eecs.umich.edu 654120Sgblack@eecs.umich.edu# Generate the header. target[0] is the full path of the output 664120Sgblack@eecs.umich.edu# header to generate. 'source' is a dummy variable, since we get the 674120Sgblack@eecs.umich.edu# list of ISAs from env['ALL_ISA_LIST']. 684120Sgblack@eecs.umich.edudef gen_switch_hdr(target, source, env): 694120Sgblack@eecs.umich.edu fname = str(target[0]) 704120Sgblack@eecs.umich.edu basename = os.path.basename(fname) 714120Sgblack@eecs.umich.edu f = open(fname, 'w') 724120Sgblack@eecs.umich.edu f.write('#include "arch/isa_specific.hh"\n') 734120Sgblack@eecs.umich.edu cond = '#if' 744120Sgblack@eecs.umich.edu for isa in env['ALL_ISA_LIST']: 754120Sgblack@eecs.umich.edu f.write('%s THE_ISA == %s_ISA\n#include "arch/%s/%s"\n' 764120Sgblack@eecs.umich.edu % (cond, isa.upper(), isa, basename)) 774120Sgblack@eecs.umich.edu cond = '#elif' 784120Sgblack@eecs.umich.edu f.write('#else\n#error "THE_ISA not set"\n#endif\n') 794120Sgblack@eecs.umich.edu f.close() 804120Sgblack@eecs.umich.edu return 0 814120Sgblack@eecs.umich.edu 824120Sgblack@eecs.umich.edu# String to print when generating header 834120Sgblack@eecs.umich.edudef gen_switch_hdr_string(target, source, env): 844120Sgblack@eecs.umich.edu return "Generating ISA switch header " + str(target[0]) 854120Sgblack@eecs.umich.edu 864202Sbinkertn@umich.edu# Build SCons Action object. 'varlist' specifies env vars that this 874202Sbinkertn@umich.edu# action depends on; when env['ALL_ISA_LIST'] changes these actions 884601Sgblack@eecs.umich.edu# should get re-executed. 894202Sbinkertn@umich.eduswitch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string, 904679Sgblack@eecs.umich.edu varlist=['ALL_ISA_LIST']) 914679Sgblack@eecs.umich.edu 924679Sgblack@eecs.umich.edu# Instantiate actions for each header 934202Sbinkertn@umich.edufor hdr in isa_switch_hdrs: 944202Sbinkertn@umich.edu env.Command(hdr, [], switch_hdr_action) 954249Sgblack@eecs.umich.edu 964240Sgblack@eecs.umich.edu################################################################# 974202Sbinkertn@umich.edu# 984202Sbinkertn@umich.edu# Include architecture-specific files. 994120Sgblack@eecs.umich.edu# 1004202Sbinkertn@umich.edu################################################################# 1014202Sbinkertn@umich.edu 1024202Sbinkertn@umich.edu# 1034202Sbinkertn@umich.edu# Build a SCons scanner for ISA files 1044202Sbinkertn@umich.edu# 1054120Sgblack@eecs.umich.eduimport SCons.Scanner 1064202Sbinkertn@umich.edu 1074202Sbinkertn@umich.eduisa_scanner = SCons.Scanner.Classic("ISAScan", 1084202Sbinkertn@umich.edu [".isa", ".ISA"], 1094120Sgblack@eecs.umich.edu "SRCDIR", 1104202Sbinkertn@umich.edu r'^\s*##include\s+"([\w/.-]*)"') 1114202Sbinkertn@umich.edu 1124202Sbinkertn@umich.eduenv.Append(SCANNERS = isa_scanner) 1134202Sbinkertn@umich.edu 1144202Sbinkertn@umich.edu# 1154202Sbinkertn@umich.edu# Now create a Builder object that uses isa_parser.py to generate C++ 116# output from the ISA description (*.isa) files. 117# 118 119# Convert to File node to fix path 120isa_parser = File('isa_parser.py') 121cpu_models_file = File('../cpu/cpu_models.py') 122 123# This sucks in the defintions of the CpuModel objects. 124execfile(cpu_models_file.srcnode().abspath) 125 126# Several files are generated from the ISA description. 127# 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