SConscript revision 2817
12155SN/A# -*- mode:python -*- 22155SN/A 32155SN/A# Copyright (c) 2006 The Regents of The University of Michigan 42155SN/A# All rights reserved. 52155SN/A# 62155SN/A# Redistribution and use in source and binary forms, with or without 72155SN/A# modification, are permitted provided that the following conditions are 82155SN/A# met: redistributions of source code must retain the above copyright 92155SN/A# notice, this list of conditions and the following disclaimer; 102155SN/A# redistributions in binary form must reproduce the above copyright 112155SN/A# notice, this list of conditions and the following disclaimer in the 122155SN/A# documentation and/or other materials provided with the distribution; 132155SN/A# neither the name of the copyright holders nor the names of its 142155SN/A# contributors may be used to endorse or promote products derived from 152155SN/A# this software without specific prior written permission. 162155SN/A# 172155SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 182155SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 192155SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 202155SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 212155SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 222155SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 232155SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 242155SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 252155SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 262155SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 272155SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 282665Ssaidi@eecs.umich.edu# 292665Ssaidi@eecs.umich.edu# Authors: Steve Reinhardt 302155SN/A 314202Sbinkertn@umich.eduimport os.path, sys 322155SN/A 332178SN/A# Import build environment variable from SConstruct. 342178SN/AImport('env') 352178SN/A 362178SN/A# Right now there are no source files immediately in this directory 372178SN/Asources = [] 382178SN/A 392178SN/A################################################################# 402178SN/A# 412178SN/A# ISA "switch header" generation. 422178SN/A# 432178SN/A# Auto-generate arch headers that include the right ISA-specific 442178SN/A# header based on the setting of THE_ISA preprocessor variable. 452155SN/A# 462178SN/A################################################################# 472155SN/A 482155SN/A# List of headers to generate 492178SN/Aisa_switch_hdrs = Split(''' 502155SN/A arguments.hh 512155SN/A constants.hh 522623SN/A faults.hh 533918Ssaidi@eecs.umich.edu isa_traits.hh 542623SN/A process.hh 552623SN/A regfile.hh 563918Ssaidi@eecs.umich.edu stacktrace.hh 572155SN/A tlb.hh 582155SN/A types.hh 592292SN/A utility.hh 603918Ssaidi@eecs.umich.edu vtophys.hh 612292SN/A ''') 622292SN/A 632292SN/A# Generate the header. target[0] is the full path of the output 643918Ssaidi@eecs.umich.edu# header to generate. 'source' is a dummy variable, since we get the 652292SN/A# list of ISAs from env['ALL_ISA_LIST']. 662292SN/Adef gen_switch_hdr(target, source, env): 672766Sktlim@umich.edu fname = str(target[0]) 682766Sktlim@umich.edu basename = os.path.basename(fname) 692766Sktlim@umich.edu f = open(fname, 'w') 702921Sktlim@umich.edu f.write('#include "arch/isa_specific.hh"\n') 712921Sktlim@umich.edu cond = '#if' 722766Sktlim@umich.edu for isa in env['ALL_ISA_LIST']: 732766Sktlim@umich.edu f.write('%s THE_ISA == %s_ISA\n#include "arch/%s/%s"\n' 742766Sktlim@umich.edu % (cond, isa.upper(), isa, basename)) 754762Snate@binkert.org cond = '#elif' 762155SN/A f.write('#else\n#error "THE_ISA not set"\n#endif\n') 772155SN/A f.close() 782155SN/A return 0 792155SN/A 802155SN/A# String to print when generating header 812155SN/Adef gen_switch_hdr_string(target, source, env): 822766Sktlim@umich.edu return "Generating ISA switch header " + str(target[0]) 832155SN/A 842623SN/A# Build SCons Action object. 'varlist' specifies env vars that this 852155SN/A# action depends on; when env['ALL_ISA_LIST'] changes these actions 862155SN/A# should get re-executed. 872155SN/Aswitch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string, 882155SN/A varlist=['ALL_ISA_LIST']) 892178SN/A 902178SN/A# Instantiate actions for each header 912178SN/Afor hdr in isa_switch_hdrs: 922766Sktlim@umich.edu env.Command(hdr, [], switch_hdr_action) 932178SN/A 942178SN/A################################################################# 952178SN/A# 962178SN/A# Include architecture-specific files. 972766Sktlim@umich.edu# 982766Sktlim@umich.edu################################################################# 992766Sktlim@umich.edu 1002788Sktlim@umich.edu# 1012178SN/A# Build a SCons scanner for ISA files 1022733Sktlim@umich.edu# 1032733Sktlim@umich.eduimport SCons.Scanner 1042817Sksewell@umich.edu 1052733Sktlim@umich.eduisa_scanner = SCons.Scanner.Classic("ISAScan", 1064486Sbinkertn@umich.edu [".isa", ".ISA"], 1074486Sbinkertn@umich.edu "SRCDIR", 1084776Sgblack@eecs.umich.edu r'^\s*##include\s+"([\w/.-]*)"') 1094776Sgblack@eecs.umich.edu 1104486Sbinkertn@umich.eduenv.Append(SCANNERS = isa_scanner) 1114202Sbinkertn@umich.edu 1124202Sbinkertn@umich.edu# 1134202Sbinkertn@umich.edu# Now create a Builder object that uses isa_parser.py to generate C++ 1144202Sbinkertn@umich.edu# output from the ISA description (*.isa) files. 1154202Sbinkertn@umich.edu# 1164776Sgblack@eecs.umich.edu 1174202Sbinkertn@umich.edu# Convert to File node to fix path 1184202Sbinkertn@umich.eduisa_parser = File('isa_parser.py') 1194202Sbinkertn@umich.educpu_models_file = File('../cpu/cpu_models.py') 1204202Sbinkertn@umich.edu 1214202Sbinkertn@umich.edu# This sucks in the defintions of the CpuModel objects. 1222155SN/Aexecfile(cpu_models_file.srcnode().abspath) 1234202Sbinkertn@umich.edu 1244486Sbinkertn@umich.edu# Several files are generated from the ISA description. 1254486Sbinkertn@umich.edu# We always get the basic decoder and header file. 1264202Sbinkertn@umich.eduisa_desc_gen_files = Split('decoder.cc decoder.hh') 1274202Sbinkertn@umich.edu# We also get an execute file for each selected CPU model. 1282821Sktlim@umich.eduisa_desc_gen_files += [CpuModel.dict[cpu].filename 1294776Sgblack@eecs.umich.edu for cpu in env['CPU_MODELS']] 1304776Sgblack@eecs.umich.edu 1314776Sgblack@eecs.umich.edu# Also include the CheckerCPU as one of the models if it is being 1324776Sgblack@eecs.umich.edu# enabled via command line. 1334776Sgblack@eecs.umich.eduif env['USE_CHECKER']: 1344776Sgblack@eecs.umich.edu isa_desc_gen_files += [CpuModel.dict['CheckerCPU'].filename] 1354776Sgblack@eecs.umich.edu 1364776Sgblack@eecs.umich.edu# The emitter patches up the sources & targets to include the 1372766Sktlim@umich.edu# autogenerated files as targets and isa parser itself as a source. 1384202Sbinkertn@umich.edudef isa_desc_emitter(target, source, env): 1392733Sktlim@umich.edu return (isa_desc_gen_files, [isa_parser, cpu_models_file] + source) 1402733Sktlim@umich.edu 1412733Sktlim@umich.edu# Pieces are in place, so create the builder. 1422733Sktlim@umich.edupython = sys.executable # use same Python binary used to run scons 1432733Sktlim@umich.eduisa_desc_builder = Builder(action=python + ' $SOURCES $TARGET.dir $CPU_MODELS', 1442874Sktlim@umich.edu emitter = isa_desc_emitter) 1452874Sktlim@umich.edu 1462874Sktlim@umich.eduenv.Append(BUILDERS = { 'ISADesc' : isa_desc_builder }) 1474202Sbinkertn@umich.edu 1482733Sktlim@umich.edu# 149# Now include other ISA-specific sources from the ISA subdirectories. 150# 151 152isa = env['TARGET_ISA'] # someday this may be a list of ISAs 153 154# Let the target architecture define what additional sources it needs 155sources += SConscript(os.path.join(isa, 'SConscript'), exports = 'env') 156 157Return('sources') 158