2004-07-03 06:16:38 +02:00
|
|
|
# -*- mode:python -*-
|
|
|
|
|
2005-06-05 11:16:00 +02:00
|
|
|
# Copyright (c) 2004-2005 The Regents of The University of Michigan
|
2004-07-03 06:16:38 +02:00
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions are
|
|
|
|
# met: redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer;
|
|
|
|
# redistributions in binary form must reproduce the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution;
|
|
|
|
# neither the name of the copyright holders nor the names of its
|
|
|
|
# contributors may be used to endorse or promote products derived from
|
|
|
|
# this software without specific prior written permission.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2006-06-01 01:26:56 +02:00
|
|
|
#
|
2007-07-24 06:51:38 +02:00
|
|
|
# Authors: Nathan Binkert
|
2004-07-03 06:16:38 +02:00
|
|
|
|
libm5: Create a libm5 static library for embedding m5.
This should allow m5 to be more easily embedded into other simulators.
The m5 binary adds a simple main function which then calls into the m5
libarary to start the simulation. In order to make this work
correctly, it was necessary embed python code directly into the
library instead of the zipfile hack. This is because you can't just
append the zipfile to the end of a library the way you can a binary.
As a result, Python files that are part of the m5 simulator are now
compile, marshalled, compressed, and then inserted into the library's
data section with a certain symbol name. Additionally, a new Importer
was needed to allow python to get at the embedded python code.
Small additional changes include:
- Get rid of the PYTHONHOME stuff since I don't think anyone ever used
it, and it just confuses things. Easy enough to add back if I'm wrong.
- Create a few new functions that are key to initializing and running
the simulator: initSignals, initM5Python, m5Main.
The original code for creating libm5 was inspired by a patch Michael
Adler, though the code here was done by me.
2008-08-04 03:19:54 +02:00
|
|
|
import array
|
2009-05-05 01:58:24 +02:00
|
|
|
import bisect
|
2007-07-24 06:51:38 +02:00
|
|
|
import imp
|
libm5: Create a libm5 static library for embedding m5.
This should allow m5 to be more easily embedded into other simulators.
The m5 binary adds a simple main function which then calls into the m5
libarary to start the simulation. In order to make this work
correctly, it was necessary embed python code directly into the
library instead of the zipfile hack. This is because you can't just
append the zipfile to the end of a library the way you can a binary.
As a result, Python files that are part of the m5 simulator are now
compile, marshalled, compressed, and then inserted into the library's
data section with a certain symbol name. Additionally, a new Importer
was needed to allow python to get at the embedded python code.
Small additional changes include:
- Get rid of the PYTHONHOME stuff since I don't think anyone ever used
it, and it just confuses things. Easy enough to add back if I'm wrong.
- Create a few new functions that are key to initializing and running
the simulator: initSignals, initM5Python, m5Main.
The original code for creating libm5 was inspired by a patch Michael
Adler, though the code here was done by me.
2008-08-04 03:19:54 +02:00
|
|
|
import marshal
|
2004-07-03 06:16:38 +02:00
|
|
|
import os
|
libm5: Create a libm5 static library for embedding m5.
This should allow m5 to be more easily embedded into other simulators.
The m5 binary adds a simple main function which then calls into the m5
libarary to start the simulation. In order to make this work
correctly, it was necessary embed python code directly into the
library instead of the zipfile hack. This is because you can't just
append the zipfile to the end of a library the way you can a binary.
As a result, Python files that are part of the m5 simulator are now
compile, marshalled, compressed, and then inserted into the library's
data section with a certain symbol name. Additionally, a new Importer
was needed to allow python to get at the embedded python code.
Small additional changes include:
- Get rid of the PYTHONHOME stuff since I don't think anyone ever used
it, and it just confuses things. Easy enough to add back if I'm wrong.
- Create a few new functions that are key to initializing and running
the simulator: initSignals, initM5Python, m5Main.
The original code for creating libm5 was inspired by a patch Michael
Adler, though the code here was done by me.
2008-08-04 03:19:54 +02:00
|
|
|
import re
|
2004-07-03 06:16:38 +02:00
|
|
|
import sys
|
libm5: Create a libm5 static library for embedding m5.
This should allow m5 to be more easily embedded into other simulators.
The m5 binary adds a simple main function which then calls into the m5
libarary to start the simulation. In order to make this work
correctly, it was necessary embed python code directly into the
library instead of the zipfile hack. This is because you can't just
append the zipfile to the end of a library the way you can a binary.
As a result, Python files that are part of the m5 simulator are now
compile, marshalled, compressed, and then inserted into the library's
data section with a certain symbol name. Additionally, a new Importer
was needed to allow python to get at the embedded python code.
Small additional changes include:
- Get rid of the PYTHONHOME stuff since I don't think anyone ever used
it, and it just confuses things. Easy enough to add back if I'm wrong.
- Create a few new functions that are key to initializing and running
the simulator: initSignals, initM5Python, m5Main.
The original code for creating libm5 was inspired by a patch Michael
Adler, though the code here was done by me.
2008-08-04 03:19:54 +02:00
|
|
|
import zlib
|
2007-03-11 08:00:54 +01:00
|
|
|
|
2008-11-10 20:51:18 +01:00
|
|
|
from os.path import basename, dirname, exists, isdir, isfile, join as joinpath
|
2004-07-03 06:16:38 +02:00
|
|
|
|
2007-04-12 18:07:59 +02:00
|
|
|
import SCons
|
|
|
|
|
2011-06-03 02:36:18 +02:00
|
|
|
# This file defines how to build a particular configuration of gem5
|
2004-07-03 06:16:38 +02:00
|
|
|
# based on variable settings in the 'env' build environment.
|
|
|
|
|
2007-03-11 08:00:54 +01:00
|
|
|
Import('*')
|
2004-07-03 06:16:38 +02:00
|
|
|
|
2007-04-13 06:20:04 +02:00
|
|
|
# Children need to see the environment
|
|
|
|
Export('env')
|
|
|
|
|
2009-09-23 00:24:16 +02:00
|
|
|
build_env = [(opt, env[opt]) for opt in export_vars]
|
2008-07-31 17:01:38 +02:00
|
|
|
|
2011-11-10 06:48:28 +01:00
|
|
|
from m5.util import code_formatter, compareVersions
|
2010-09-09 23:15:42 +02:00
|
|
|
|
2009-05-05 01:58:24 +02:00
|
|
|
########################################################################
|
|
|
|
# Code for adding source files of various types
|
|
|
|
#
|
2011-04-15 19:44:44 +02:00
|
|
|
# When specifying a source file of some type, a set of guards can be
|
|
|
|
# specified for that file. When get() is used to find the files, if
|
|
|
|
# get specifies a set of filters, only files that match those filters
|
|
|
|
# will be accepted (unspecified filters on files are assumed to be
|
|
|
|
# false). Current filters are:
|
2011-06-03 02:36:18 +02:00
|
|
|
# main -- specifies the gem5 main() function
|
|
|
|
# skip_lib -- do not put this file into the gem5 library
|
2014-10-16 11:49:32 +02:00
|
|
|
# skip_no_python -- do not put this file into a no_python library
|
|
|
|
# as it embeds compiled Python
|
2011-04-15 19:44:44 +02:00
|
|
|
# <unittest> -- unit tests use filters based on the unit test name
|
|
|
|
#
|
|
|
|
# A parent can now be specified for a source file and default filter
|
|
|
|
# values will be retrieved recursively from parents (children override
|
|
|
|
# parents).
|
|
|
|
#
|
2009-05-05 01:58:24 +02:00
|
|
|
class SourceMeta(type):
|
2011-04-15 19:44:44 +02:00
|
|
|
'''Meta class for source files that keeps track of all files of a
|
|
|
|
particular type and has a get function for finding all functions
|
|
|
|
of a certain type that match a set of guards'''
|
2009-05-05 01:58:24 +02:00
|
|
|
def __init__(cls, name, bases, dict):
|
|
|
|
super(SourceMeta, cls).__init__(name, bases, dict)
|
|
|
|
cls.all = []
|
2016-01-19 20:28:22 +01:00
|
|
|
|
2011-04-15 19:44:44 +02:00
|
|
|
def get(cls, **guards):
|
|
|
|
'''Find all files that match the specified guards. If a source
|
|
|
|
file does not specify a flag, the default is False'''
|
2009-05-05 01:58:24 +02:00
|
|
|
for src in cls.all:
|
2011-04-15 19:44:44 +02:00
|
|
|
for flag,value in guards.iteritems():
|
|
|
|
# if the flag is found and has a different value, skip
|
|
|
|
# this file
|
|
|
|
if src.all_guards.get(flag, False) != value:
|
2009-05-05 01:58:24 +02:00
|
|
|
break
|
|
|
|
else:
|
|
|
|
yield src
|
|
|
|
|
|
|
|
class SourceFile(object):
|
2011-04-15 19:44:44 +02:00
|
|
|
'''Base object that encapsulates the notion of a source file.
|
|
|
|
This includes, the source node, target node, various manipulations
|
|
|
|
of those. A source file also specifies a set of guards which
|
|
|
|
describing which builds the source file applies to. A parent can
|
|
|
|
also be specified to get default guards from'''
|
2009-05-05 01:58:24 +02:00
|
|
|
__metaclass__ = SourceMeta
|
2011-04-15 19:44:44 +02:00
|
|
|
def __init__(self, source, parent=None, **guards):
|
|
|
|
self.guards = guards
|
|
|
|
self.parent = parent
|
|
|
|
|
2009-05-05 01:58:24 +02:00
|
|
|
tnode = source
|
|
|
|
if not isinstance(source, SCons.Node.FS.File):
|
|
|
|
tnode = File(source)
|
2007-07-24 06:51:38 +02:00
|
|
|
|
2009-05-05 01:58:24 +02:00
|
|
|
self.tnode = tnode
|
|
|
|
self.snode = tnode.srcnode()
|
|
|
|
|
|
|
|
for base in type(self).__mro__:
|
|
|
|
if issubclass(base, SourceFile):
|
2010-04-16 01:25:14 +02:00
|
|
|
base.all.append(self)
|
2009-05-05 01:58:24 +02:00
|
|
|
|
2011-04-15 19:44:44 +02:00
|
|
|
@property
|
|
|
|
def filename(self):
|
|
|
|
return str(self.tnode)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def dirname(self):
|
|
|
|
return dirname(self.filename)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def basename(self):
|
|
|
|
return basename(self.filename)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def extname(self):
|
|
|
|
index = self.basename.rfind('.')
|
|
|
|
if index <= 0:
|
|
|
|
# dot files aren't extensions
|
|
|
|
return self.basename, None
|
|
|
|
|
|
|
|
return self.basename[:index], self.basename[index+1:]
|
|
|
|
|
|
|
|
@property
|
|
|
|
def all_guards(self):
|
|
|
|
'''find all guards for this object getting default values
|
|
|
|
recursively from its parents'''
|
|
|
|
guards = {}
|
|
|
|
if self.parent:
|
|
|
|
guards.update(self.parent.guards)
|
|
|
|
guards.update(self.guards)
|
|
|
|
return guards
|
|
|
|
|
2009-05-05 01:58:24 +02:00
|
|
|
def __lt__(self, other): return self.filename < other.filename
|
|
|
|
def __le__(self, other): return self.filename <= other.filename
|
|
|
|
def __gt__(self, other): return self.filename > other.filename
|
|
|
|
def __ge__(self, other): return self.filename >= other.filename
|
|
|
|
def __eq__(self, other): return self.filename == other.filename
|
|
|
|
def __ne__(self, other): return self.filename != other.filename
|
2013-11-15 19:21:15 +01:00
|
|
|
|
arch: teach ISA parser how to split code across files
This patch encompasses several interrelated and interdependent changes
to the ISA generation step. The end goal is to reduce the size of the
generated compilation units for instruction execution and decoding so
that batch compilation can proceed with all CPUs active without
exhausting physical memory.
The ISA parser (src/arch/isa_parser.py) has been improved so that it can
accept 'split [output_type];' directives at the top level of the grammar
and 'split(output_type)' python calls within 'exec {{ ... }}' blocks.
This has the effect of "splitting" the files into smaller compilation
units. I use air-quotes around "splitting" because the files themselves
are not split, but preprocessing directives are inserted to have the same
effect.
Architecturally, the ISA parser has had some changes in how it works.
In general, it emits code sooner. It doesn't generate per-CPU files,
and instead defers to the C preprocessor to create the duplicate copies
for each CPU type. Likewise there are more files emitted and the C
preprocessor does more substitution that used to be done by the ISA parser.
Finally, the build system (SCons) needs to be able to cope with a
dynamic list of source files coming out of the ISA parser. The changes
to the SCons{cript,truct} files support this. In broad strokes, the
targets requested on the command line are hidden from SCons until all
the build dependencies are determined, otherwise it would try, realize
it can't reach the goal, and terminate in failure. Since build steps
(i.e. running the ISA parser) must be taken to determine the file list,
several new build stages have been inserted at the very start of the
build. First, the build dependencies from the ISA parser will be emitted
to arch/$ISA/generated/inc.d, which is then read by a new SCons builder
to finalize the dependencies. (Once inc.d exists, the ISA parser will not
need to be run to complete this step.) Once the dependencies are known,
the 'Environments' are made by the makeEnv() function. This function used
to be called before the build began but now happens during the build.
It is easy to see that this step is quite slow; this is a known issue
and it's important to realize that it was already slow, but there was
no obvious cause to attribute it to since nothing was displayed to the
terminal. Since new steps that used to be performed serially are now in a
potentially-parallel build phase, the pathname handling in the SCons scripts
has been tightened up to deal with chdir() race conditions. In general,
pathnames are computed earlier and more likely to be stored, passed around,
and processed as absolute paths rather than relative paths. In the end,
some of these issues had to be fixed by inserting serializing dependencies
in the build.
Minor note:
For the null ISA, we just provide a dummy inc.d so SCons is never
compelled to try to generate it. While it seems slightly wrong to have
anything in src/arch/*/generated (i.e. a non-generated 'generated' file),
it's by far the simplest solution.
2014-05-10 00:58:47 +02:00
|
|
|
@staticmethod
|
|
|
|
def done():
|
|
|
|
def disabled(cls, name, *ignored):
|
|
|
|
raise RuntimeError("Additional SourceFile '%s'" % name,\
|
|
|
|
"declared, but targets deps are already fixed.")
|
|
|
|
SourceFile.__init__ = disabled
|
|
|
|
|
|
|
|
|
2009-05-05 01:58:24 +02:00
|
|
|
class Source(SourceFile):
|
|
|
|
'''Add a c/c++ source file to the build'''
|
2012-04-13 17:13:04 +02:00
|
|
|
def __init__(self, source, Werror=True, swig=False, **guards):
|
2011-04-15 19:44:44 +02:00
|
|
|
'''specify the source file, and any guards'''
|
|
|
|
super(Source, self).__init__(source, **guards)
|
2009-05-05 01:58:24 +02:00
|
|
|
|
2012-04-13 17:13:04 +02:00
|
|
|
self.Werror = Werror
|
2009-05-05 01:58:24 +02:00
|
|
|
self.swig = swig
|
|
|
|
|
|
|
|
class PySource(SourceFile):
|
|
|
|
'''Add a python source file to the named package'''
|
libm5: Create a libm5 static library for embedding m5.
This should allow m5 to be more easily embedded into other simulators.
The m5 binary adds a simple main function which then calls into the m5
libarary to start the simulation. In order to make this work
correctly, it was necessary embed python code directly into the
library instead of the zipfile hack. This is because you can't just
append the zipfile to the end of a library the way you can a binary.
As a result, Python files that are part of the m5 simulator are now
compile, marshalled, compressed, and then inserted into the library's
data section with a certain symbol name. Additionally, a new Importer
was needed to allow python to get at the embedded python code.
Small additional changes include:
- Get rid of the PYTHONHOME stuff since I don't think anyone ever used
it, and it just confuses things. Easy enough to add back if I'm wrong.
- Create a few new functions that are key to initializing and running
the simulator: initSignals, initM5Python, m5Main.
The original code for creating libm5 was inspired by a patch Michael
Adler, though the code here was done by me.
2008-08-04 03:19:54 +02:00
|
|
|
invalid_sym_char = re.compile('[^A-z0-9_]')
|
2009-05-05 01:58:24 +02:00
|
|
|
modules = {}
|
|
|
|
tnodes = {}
|
|
|
|
symnames = {}
|
2013-11-15 19:21:15 +01:00
|
|
|
|
2011-04-15 19:44:44 +02:00
|
|
|
def __init__(self, package, source, **guards):
|
|
|
|
'''specify the python package, the source file, and any guards'''
|
|
|
|
super(PySource, self).__init__(source, **guards)
|
2009-05-05 01:58:24 +02:00
|
|
|
|
|
|
|
modname,ext = self.extname
|
|
|
|
assert ext == 'py'
|
|
|
|
|
libm5: Create a libm5 static library for embedding m5.
This should allow m5 to be more easily embedded into other simulators.
The m5 binary adds a simple main function which then calls into the m5
libarary to start the simulation. In order to make this work
correctly, it was necessary embed python code directly into the
library instead of the zipfile hack. This is because you can't just
append the zipfile to the end of a library the way you can a binary.
As a result, Python files that are part of the m5 simulator are now
compile, marshalled, compressed, and then inserted into the library's
data section with a certain symbol name. Additionally, a new Importer
was needed to allow python to get at the embedded python code.
Small additional changes include:
- Get rid of the PYTHONHOME stuff since I don't think anyone ever used
it, and it just confuses things. Easy enough to add back if I'm wrong.
- Create a few new functions that are key to initializing and running
the simulator: initSignals, initM5Python, m5Main.
The original code for creating libm5 was inspired by a patch Michael
Adler, though the code here was done by me.
2008-08-04 03:19:54 +02:00
|
|
|
if package:
|
|
|
|
path = package.split('.')
|
|
|
|
else:
|
|
|
|
path = []
|
2008-10-09 13:58:23 +02:00
|
|
|
|
|
|
|
modpath = path[:]
|
2009-05-05 01:58:24 +02:00
|
|
|
if modname != '__init__':
|
|
|
|
modpath += [ modname ]
|
2007-07-24 06:51:38 +02:00
|
|
|
modpath = '.'.join(modpath)
|
|
|
|
|
2009-05-05 01:58:24 +02:00
|
|
|
arcpath = path + [ self.basename ]
|
2009-11-09 02:35:49 +01:00
|
|
|
abspath = self.snode.abspath
|
|
|
|
if not exists(abspath):
|
|
|
|
abspath = self.tnode.abspath
|
2008-10-09 13:58:23 +02:00
|
|
|
|
2007-07-24 06:51:38 +02:00
|
|
|
self.package = package
|
2009-05-05 01:58:24 +02:00
|
|
|
self.modname = modname
|
2007-07-24 06:51:38 +02:00
|
|
|
self.modpath = modpath
|
2009-05-05 01:58:24 +02:00
|
|
|
self.arcname = joinpath(*arcpath)
|
2009-11-09 02:35:49 +01:00
|
|
|
self.abspath = abspath
|
2009-05-05 01:58:24 +02:00
|
|
|
self.compiled = File(self.filename + 'c')
|
2010-09-09 23:15:42 +02:00
|
|
|
self.cpp = File(self.filename + '.cc')
|
|
|
|
self.symname = PySource.invalid_sym_char.sub('_', modpath)
|
2007-07-24 06:51:38 +02:00
|
|
|
|
2009-05-05 01:58:24 +02:00
|
|
|
PySource.modules[modpath] = self
|
|
|
|
PySource.tnodes[self.tnode] = self
|
|
|
|
PySource.symnames[self.symname] = self
|
libm5: Create a libm5 static library for embedding m5.
This should allow m5 to be more easily embedded into other simulators.
The m5 binary adds a simple main function which then calls into the m5
libarary to start the simulation. In order to make this work
correctly, it was necessary embed python code directly into the
library instead of the zipfile hack. This is because you can't just
append the zipfile to the end of a library the way you can a binary.
As a result, Python files that are part of the m5 simulator are now
compile, marshalled, compressed, and then inserted into the library's
data section with a certain symbol name. Additionally, a new Importer
was needed to allow python to get at the embedded python code.
Small additional changes include:
- Get rid of the PYTHONHOME stuff since I don't think anyone ever used
it, and it just confuses things. Easy enough to add back if I'm wrong.
- Create a few new functions that are key to initializing and running
the simulator: initSignals, initM5Python, m5Main.
The original code for creating libm5 was inspired by a patch Michael
Adler, though the code here was done by me.
2008-08-04 03:19:54 +02:00
|
|
|
|
2009-05-05 01:58:24 +02:00
|
|
|
class SimObject(PySource):
|
|
|
|
'''Add a SimObject python file as a python source object and add
|
|
|
|
it to a list of sim object modules'''
|
libm5: Create a libm5 static library for embedding m5.
This should allow m5 to be more easily embedded into other simulators.
The m5 binary adds a simple main function which then calls into the m5
libarary to start the simulation. In order to make this work
correctly, it was necessary embed python code directly into the
library instead of the zipfile hack. This is because you can't just
append the zipfile to the end of a library the way you can a binary.
As a result, Python files that are part of the m5 simulator are now
compile, marshalled, compressed, and then inserted into the library's
data section with a certain symbol name. Additionally, a new Importer
was needed to allow python to get at the embedded python code.
Small additional changes include:
- Get rid of the PYTHONHOME stuff since I don't think anyone ever used
it, and it just confuses things. Easy enough to add back if I'm wrong.
- Create a few new functions that are key to initializing and running
the simulator: initSignals, initM5Python, m5Main.
The original code for creating libm5 was inspired by a patch Michael
Adler, though the code here was done by me.
2008-08-04 03:19:54 +02:00
|
|
|
|
2009-05-05 01:58:24 +02:00
|
|
|
fixed = False
|
|
|
|
modnames = []
|
2004-07-03 06:16:38 +02:00
|
|
|
|
2011-04-15 19:44:44 +02:00
|
|
|
def __init__(self, source, **guards):
|
|
|
|
'''Specify the source file and any guards (automatically in
|
|
|
|
the m5.objects package)'''
|
|
|
|
super(SimObject, self).__init__('m5.objects', source, **guards)
|
2009-05-05 01:58:24 +02:00
|
|
|
if self.fixed:
|
|
|
|
raise AttributeError, "Too late to call SimObject now."
|
2006-02-21 05:26:39 +01:00
|
|
|
|
2009-05-05 01:58:24 +02:00
|
|
|
bisect.insort_right(SimObject.modnames, self.modname)
|
2007-07-24 06:51:38 +02:00
|
|
|
|
2009-05-05 01:58:24 +02:00
|
|
|
class SwigSource(SourceFile):
|
|
|
|
'''Add a swig file to build'''
|
2007-04-13 06:20:04 +02:00
|
|
|
|
2011-04-15 19:44:44 +02:00
|
|
|
def __init__(self, package, source, **guards):
|
|
|
|
'''Specify the python package, the source file, and any guards'''
|
2014-10-16 11:49:32 +02:00
|
|
|
super(SwigSource, self).__init__(source, skip_no_python=True, **guards)
|
2007-07-24 06:51:38 +02:00
|
|
|
|
2009-05-05 01:58:24 +02:00
|
|
|
modname,ext = self.extname
|
|
|
|
assert ext == 'i'
|
2007-07-24 06:51:38 +02:00
|
|
|
|
2016-06-28 09:50:00 +02:00
|
|
|
self.package = package
|
2009-05-05 01:58:24 +02:00
|
|
|
self.module = modname
|
|
|
|
cc_file = joinpath(self.dirname, modname + '_wrap.cc')
|
|
|
|
py_file = joinpath(self.dirname, modname + '.py')
|
2007-07-24 06:51:38 +02:00
|
|
|
|
2014-10-16 11:49:32 +02:00
|
|
|
self.cc_source = Source(cc_file, swig=True, parent=self, **guards)
|
|
|
|
self.py_source = PySource(package, py_file, parent=self, **guards)
|
2007-04-13 06:20:04 +02:00
|
|
|
|
2013-01-07 19:05:37 +01:00
|
|
|
class ProtoBuf(SourceFile):
|
|
|
|
'''Add a Protocol Buffer to build'''
|
|
|
|
|
|
|
|
def __init__(self, source, **guards):
|
|
|
|
'''Specify the source file, and any guards'''
|
|
|
|
super(ProtoBuf, self).__init__(source, **guards)
|
|
|
|
|
|
|
|
# Get the file name and the extension
|
|
|
|
modname,ext = self.extname
|
|
|
|
assert ext == 'proto'
|
|
|
|
|
|
|
|
# Currently, we stick to generating the C++ headers, so we
|
|
|
|
# only need to track the source and header.
|
2013-10-17 17:20:45 +02:00
|
|
|
self.cc_file = File(modname + '.pb.cc')
|
|
|
|
self.hh_file = File(modname + '.pb.h')
|
2013-01-07 19:05:37 +01:00
|
|
|
|
2011-04-15 19:45:11 +02:00
|
|
|
class UnitTest(object):
|
|
|
|
'''Create a UnitTest'''
|
|
|
|
|
|
|
|
all = []
|
2012-05-11 01:04:28 +02:00
|
|
|
def __init__(self, target, *sources, **kwargs):
|
2011-04-15 19:45:11 +02:00
|
|
|
'''Specify the target name and any sources. Sources that are
|
|
|
|
not SourceFiles are evalued with Source(). All files are
|
|
|
|
guarded with a guard of the same name as the UnitTest
|
|
|
|
target.'''
|
|
|
|
|
|
|
|
srcs = []
|
|
|
|
for src in sources:
|
|
|
|
if not isinstance(src, SourceFile):
|
|
|
|
src = Source(src, skip_lib=True)
|
|
|
|
src.guards[target] = True
|
|
|
|
srcs.append(src)
|
|
|
|
|
|
|
|
self.sources = srcs
|
|
|
|
self.target = target
|
2012-05-11 01:04:28 +02:00
|
|
|
self.main = kwargs.get('main', False)
|
2011-04-15 19:45:11 +02:00
|
|
|
UnitTest.all.append(self)
|
2008-10-02 20:27:01 +02:00
|
|
|
|
2007-04-13 06:20:04 +02:00
|
|
|
# Children should have access
|
2007-07-24 06:51:38 +02:00
|
|
|
Export('Source')
|
2007-04-13 06:20:04 +02:00
|
|
|
Export('PySource')
|
|
|
|
Export('SimObject')
|
|
|
|
Export('SwigSource')
|
2013-01-07 19:05:37 +01:00
|
|
|
Export('ProtoBuf')
|
2008-10-02 20:27:01 +02:00
|
|
|
Export('UnitTest')
|
2007-04-13 06:20:04 +02:00
|
|
|
|
2007-10-31 06:21:54 +01:00
|
|
|
########################################################################
|
|
|
|
#
|
2011-04-15 19:44:32 +02:00
|
|
|
# Debug Flags
|
2007-10-31 06:21:54 +01:00
|
|
|
#
|
2011-04-15 19:44:32 +02:00
|
|
|
debug_flags = {}
|
|
|
|
def DebugFlag(name, desc=None):
|
|
|
|
if name in debug_flags:
|
2007-10-31 06:21:54 +01:00
|
|
|
raise AttributeError, "Flag %s already specified" % name
|
2011-04-15 19:44:32 +02:00
|
|
|
debug_flags[name] = (name, (), desc)
|
2007-10-31 06:21:54 +01:00
|
|
|
|
2009-01-19 18:59:13 +01:00
|
|
|
def CompoundFlag(name, flags, desc=None):
|
2011-04-15 19:44:32 +02:00
|
|
|
if name in debug_flags:
|
2007-10-31 06:21:54 +01:00
|
|
|
raise AttributeError, "Flag %s already specified" % name
|
|
|
|
|
|
|
|
compound = tuple(flags)
|
2011-04-15 19:44:32 +02:00
|
|
|
debug_flags[name] = (name, compound, desc)
|
2007-10-31 06:21:54 +01:00
|
|
|
|
2011-04-15 19:44:32 +02:00
|
|
|
Export('DebugFlag')
|
2007-10-31 06:21:54 +01:00
|
|
|
Export('CompoundFlag')
|
|
|
|
|
2007-04-13 06:20:04 +02:00
|
|
|
########################################################################
|
|
|
|
#
|
|
|
|
# Set some compiler variables
|
|
|
|
#
|
|
|
|
|
2006-06-10 05:01:31 +02:00
|
|
|
# Include file paths are rooted in this directory. SCons will
|
|
|
|
# automatically expand '.' to refer to both the source directory and
|
|
|
|
# the corresponding build directory to pick up generated include
|
|
|
|
# files.
|
|
|
|
env.Append(CPPPATH=Dir('.'))
|
|
|
|
|
2008-11-10 20:51:18 +01:00
|
|
|
for extra_dir in extras_dir_list:
|
|
|
|
env.Append(CPPPATH=Dir(extra_dir))
|
|
|
|
|
2009-01-13 23:17:50 +01:00
|
|
|
# Workaround for bug in SCons version > 0.97d20071212
|
2011-06-03 02:36:18 +02:00
|
|
|
# Scons bug id: 2006 gem5 Bug id: 308
|
2009-01-13 23:17:50 +01:00
|
|
|
for root, dirs, files in os.walk(base_dir, topdown=True):
|
|
|
|
Dir(root[len(base_dir) + 1:])
|
|
|
|
|
2007-04-13 06:20:04 +02:00
|
|
|
########################################################################
|
2007-07-24 06:51:38 +02:00
|
|
|
#
|
2008-02-11 17:04:01 +01:00
|
|
|
# Walk the tree and execute all SConscripts in subdirectories
|
2007-04-13 06:20:04 +02:00
|
|
|
#
|
2007-07-24 06:51:38 +02:00
|
|
|
|
2008-11-10 20:51:18 +01:00
|
|
|
here = Dir('.').srcnode().abspath
|
|
|
|
for root, dirs, files in os.walk(base_dir, topdown=True):
|
|
|
|
if root == here:
|
|
|
|
# we don't want to recurse back into this SConscript
|
|
|
|
continue
|
|
|
|
|
|
|
|
if 'SConscript' in files:
|
|
|
|
build_dir = joinpath(env['BUILDDIR'], root[len(base_dir) + 1:])
|
2010-11-07 01:48:58 +01:00
|
|
|
SConscript(joinpath(root, 'SConscript'), variant_dir=build_dir)
|
2008-02-06 02:40:08 +01:00
|
|
|
|
2008-11-10 20:51:18 +01:00
|
|
|
for extra_dir in extras_dir_list:
|
|
|
|
prefix_len = len(dirname(extra_dir)) + 1
|
2013-10-17 17:20:45 +02:00
|
|
|
|
|
|
|
# Also add the corresponding build directory to pick up generated
|
|
|
|
# include files.
|
|
|
|
env.Append(CPPPATH=Dir(joinpath(env['BUILDDIR'], extra_dir[prefix_len:])))
|
|
|
|
|
2008-11-10 20:51:18 +01:00
|
|
|
for root, dirs, files in os.walk(extra_dir, topdown=True):
|
2011-04-20 20:14:51 +02:00
|
|
|
# if build lives in the extras directory, don't walk down it
|
|
|
|
if 'build' in dirs:
|
|
|
|
dirs.remove('build')
|
|
|
|
|
2008-02-06 02:40:08 +01:00
|
|
|
if 'SConscript' in files:
|
2008-11-10 20:51:18 +01:00
|
|
|
build_dir = joinpath(env['BUILDDIR'], root[prefix_len:])
|
2010-11-07 01:48:58 +01:00
|
|
|
SConscript(joinpath(root, 'SConscript'), variant_dir=build_dir)
|
2007-07-26 03:21:11 +02:00
|
|
|
|
2009-04-21 17:17:36 +02:00
|
|
|
for opt in export_vars:
|
2005-08-30 19:18:54 +02:00
|
|
|
env.ConfigFile(opt)
|
2004-09-16 21:11:38 +02:00
|
|
|
|
2009-09-23 17:34:21 +02:00
|
|
|
def makeTheISA(source, target, env):
|
|
|
|
isas = [ src.get_contents() for src in source ]
|
2010-09-09 23:15:41 +02:00
|
|
|
target_isa = env['TARGET_ISA']
|
2009-09-23 17:34:21 +02:00
|
|
|
def define(isa):
|
|
|
|
return isa.upper() + '_ISA'
|
2016-01-19 20:28:22 +01:00
|
|
|
|
2009-09-23 17:34:21 +02:00
|
|
|
def namespace(isa):
|
2016-01-19 20:28:22 +01:00
|
|
|
return isa[0].upper() + isa[1:].lower() + 'ISA'
|
2009-09-23 17:34:21 +02:00
|
|
|
|
|
|
|
|
2010-09-09 23:15:41 +02:00
|
|
|
code = code_formatter()
|
|
|
|
code('''\
|
|
|
|
#ifndef __CONFIG_THE_ISA_HH__
|
|
|
|
#define __CONFIG_THE_ISA_HH__
|
|
|
|
|
|
|
|
''')
|
|
|
|
|
2014-10-16 11:49:44 +02:00
|
|
|
# create defines for the preprocessing and compile-time determination
|
2009-09-23 17:34:21 +02:00
|
|
|
for i,isa in enumerate(isas):
|
2010-09-09 23:15:41 +02:00
|
|
|
code('#define $0 $1', define(isa), i + 1)
|
2014-10-16 11:49:44 +02:00
|
|
|
code()
|
|
|
|
|
|
|
|
# create an enum for any run-time determination of the ISA, we
|
|
|
|
# reuse the same name as the namespaces
|
|
|
|
code('enum class Arch {')
|
|
|
|
for i,isa in enumerate(isas):
|
|
|
|
if i + 1 == len(isas):
|
|
|
|
code(' $0 = $1', namespace(isa), define(isa))
|
|
|
|
else:
|
|
|
|
code(' $0 = $1,', namespace(isa), define(isa))
|
|
|
|
code('};')
|
2010-09-09 23:15:41 +02:00
|
|
|
|
|
|
|
code('''
|
|
|
|
|
|
|
|
#define THE_ISA ${{define(target_isa)}}
|
|
|
|
#define TheISA ${{namespace(target_isa)}}
|
2012-06-05 07:23:10 +02:00
|
|
|
#define THE_ISA_STR "${{target_isa}}"
|
2010-09-09 23:15:41 +02:00
|
|
|
|
|
|
|
#endif // __CONFIG_THE_ISA_HH__''')
|
|
|
|
|
|
|
|
code.write(str(target[0]))
|
2009-09-23 17:34:21 +02:00
|
|
|
|
2010-11-15 21:04:04 +01:00
|
|
|
env.Command('config/the_isa.hh', map(Value, all_isa_list),
|
2011-01-08 06:50:13 +01:00
|
|
|
MakeAction(makeTheISA, Transform("CFG ISA", 0)))
|
2009-09-23 17:34:21 +02:00
|
|
|
|
2016-01-19 20:28:22 +01:00
|
|
|
def makeTheGPUISA(source, target, env):
|
|
|
|
isas = [ src.get_contents() for src in source ]
|
|
|
|
target_gpu_isa = env['TARGET_GPU_ISA']
|
|
|
|
def define(isa):
|
|
|
|
return isa.upper() + '_ISA'
|
|
|
|
|
|
|
|
def namespace(isa):
|
|
|
|
return isa[0].upper() + isa[1:].lower() + 'ISA'
|
|
|
|
|
|
|
|
|
|
|
|
code = code_formatter()
|
|
|
|
code('''\
|
|
|
|
#ifndef __CONFIG_THE_GPU_ISA_HH__
|
|
|
|
#define __CONFIG_THE_GPU_ISA_HH__
|
|
|
|
|
|
|
|
''')
|
|
|
|
|
|
|
|
# create defines for the preprocessing and compile-time determination
|
|
|
|
for i,isa in enumerate(isas):
|
|
|
|
code('#define $0 $1', define(isa), i + 1)
|
|
|
|
code()
|
|
|
|
|
|
|
|
# create an enum for any run-time determination of the ISA, we
|
|
|
|
# reuse the same name as the namespaces
|
|
|
|
code('enum class GPUArch {')
|
|
|
|
for i,isa in enumerate(isas):
|
|
|
|
if i + 1 == len(isas):
|
|
|
|
code(' $0 = $1', namespace(isa), define(isa))
|
|
|
|
else:
|
|
|
|
code(' $0 = $1,', namespace(isa), define(isa))
|
|
|
|
code('};')
|
|
|
|
|
|
|
|
code('''
|
|
|
|
|
|
|
|
#define THE_GPU_ISA ${{define(target_gpu_isa)}}
|
|
|
|
#define TheGpuISA ${{namespace(target_gpu_isa)}}
|
|
|
|
#define THE_GPU_ISA_STR "${{target_gpu_isa}}"
|
|
|
|
|
|
|
|
#endif // __CONFIG_THE_GPU_ISA_HH__''')
|
|
|
|
|
|
|
|
code.write(str(target[0]))
|
|
|
|
|
|
|
|
env.Command('config/the_gpu_isa.hh', map(Value, all_gpu_isa_list),
|
|
|
|
MakeAction(makeTheGPUISA, Transform("CFG ISA", 0)))
|
|
|
|
|
2007-04-13 06:20:04 +02:00
|
|
|
########################################################################
|
|
|
|
#
|
2007-07-24 06:51:38 +02:00
|
|
|
# Prevent any SimObjects from being added after this point, they
|
|
|
|
# should all have been added in the SConscripts above
|
2007-04-13 06:20:04 +02:00
|
|
|
#
|
2009-09-23 00:24:16 +02:00
|
|
|
SimObject.fixed = True
|
|
|
|
|
2008-07-31 17:01:38 +02:00
|
|
|
class DictImporter(object):
|
|
|
|
'''This importer takes a dictionary of arbitrary module names that
|
|
|
|
map to arbitrary filenames.'''
|
|
|
|
def __init__(self, modules):
|
|
|
|
self.modules = modules
|
|
|
|
self.installed = set()
|
2007-04-13 06:20:04 +02:00
|
|
|
|
2008-07-31 17:01:38 +02:00
|
|
|
def __del__(self):
|
|
|
|
self.unload()
|
2007-04-13 06:20:04 +02:00
|
|
|
|
2008-07-31 17:01:38 +02:00
|
|
|
def unload(self):
|
|
|
|
import sys
|
|
|
|
for module in self.installed:
|
|
|
|
del sys.modules[module]
|
|
|
|
self.installed = set()
|
|
|
|
|
|
|
|
def find_module(self, fullname, path):
|
2009-09-23 00:24:16 +02:00
|
|
|
if fullname == 'm5.defines':
|
2008-07-31 17:01:38 +02:00
|
|
|
return self
|
|
|
|
|
|
|
|
if fullname == 'm5.objects':
|
|
|
|
return self
|
|
|
|
|
2017-01-27 13:40:01 +01:00
|
|
|
if fullname.startswith('_m5'):
|
2008-07-31 17:01:38 +02:00
|
|
|
return None
|
|
|
|
|
2009-05-05 01:58:24 +02:00
|
|
|
source = self.modules.get(fullname, None)
|
2009-09-23 00:24:16 +02:00
|
|
|
if source is not None and fullname.startswith('m5.objects'):
|
2008-07-31 17:01:38 +02:00
|
|
|
return self
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
def load_module(self, fullname):
|
|
|
|
mod = imp.new_module(fullname)
|
|
|
|
sys.modules[fullname] = mod
|
|
|
|
self.installed.add(fullname)
|
|
|
|
|
|
|
|
mod.__loader__ = self
|
|
|
|
if fullname == 'm5.objects':
|
|
|
|
mod.__path__ = fullname.split('.')
|
|
|
|
return mod
|
|
|
|
|
2009-09-23 00:24:16 +02:00
|
|
|
if fullname == 'm5.defines':
|
|
|
|
mod.__dict__['buildEnv'] = m5.util.SmartDict(build_env)
|
2008-07-31 17:01:38 +02:00
|
|
|
return mod
|
|
|
|
|
2009-05-05 01:58:24 +02:00
|
|
|
source = self.modules[fullname]
|
|
|
|
if source.modname == '__init__':
|
|
|
|
mod.__path__ = source.modpath
|
2009-11-09 02:35:49 +01:00
|
|
|
mod.__file__ = source.abspath
|
2008-07-31 17:01:38 +02:00
|
|
|
|
2009-11-09 02:35:49 +01:00
|
|
|
exec file(source.abspath, 'r') in mod.__dict__
|
2008-07-31 17:01:38 +02:00
|
|
|
|
|
|
|
return mod
|
|
|
|
|
2009-09-23 00:24:16 +02:00
|
|
|
import m5.SimObject
|
|
|
|
import m5.params
|
2010-09-09 23:15:41 +02:00
|
|
|
from m5.util import code_formatter
|
2009-09-23 00:24:16 +02:00
|
|
|
|
|
|
|
m5.SimObject.clear()
|
|
|
|
m5.params.clear()
|
|
|
|
|
2008-07-31 17:01:38 +02:00
|
|
|
# install the python importer so we can grab stuff from the source
|
|
|
|
# tree itself. We can't have SimObjects added after this point or
|
|
|
|
# else we won't know about them for the rest of the stuff.
|
2009-05-05 01:58:24 +02:00
|
|
|
importer = DictImporter(PySource.modules)
|
2008-07-31 17:01:38 +02:00
|
|
|
sys.meta_path[0:0] = [ importer ]
|
|
|
|
|
|
|
|
# import all sim objects so we can populate the all_objects list
|
|
|
|
# make sure that we're working with a list, then let's sort it
|
2009-05-05 01:58:24 +02:00
|
|
|
for modname in SimObject.modnames:
|
|
|
|
exec('from m5.objects import %s' % modname)
|
2008-07-31 17:01:38 +02:00
|
|
|
|
|
|
|
# we need to unload all of the currently imported modules so that they
|
|
|
|
# will be re-imported the next time the sconscript is run
|
|
|
|
importer.unload()
|
|
|
|
sys.meta_path.remove(importer)
|
|
|
|
|
|
|
|
sim_objects = m5.SimObject.allClasses
|
|
|
|
all_enums = m5.params.allEnums
|
|
|
|
|
2012-11-02 17:32:01 +01:00
|
|
|
if m5.SimObject.noCxxHeader:
|
|
|
|
print >> sys.stderr, \
|
|
|
|
"warning: At least one SimObject lacks a header specification. " \
|
|
|
|
"This can cause unexpected results in the generated SWIG " \
|
|
|
|
"wrappers."
|
|
|
|
|
2011-10-20 22:08:49 +02:00
|
|
|
# Find param types that need to be explicitly wrapped with swig.
|
|
|
|
# These will be recognized because the ParamDesc will have a
|
|
|
|
# swig_decl() method. Most param types are based on types that don't
|
|
|
|
# need this, either because they're based on native types (like Int)
|
|
|
|
# or because they're SimObjects (which get swigged independently).
|
|
|
|
# For now the only things handled here are VectorParam types.
|
|
|
|
params_to_swig = {}
|
2009-05-05 01:58:24 +02:00
|
|
|
for name,obj in sorted(sim_objects.iteritems()):
|
2008-07-31 17:01:38 +02:00
|
|
|
for param in obj._params.local.values():
|
2009-09-23 00:24:16 +02:00
|
|
|
# load the ptype attribute now because it depends on the
|
|
|
|
# current version of SimObject.allClasses, but when scons
|
|
|
|
# actually uses the value, all versions of
|
|
|
|
# SimObject.allClasses will have been loaded
|
|
|
|
param.ptype
|
|
|
|
|
2008-07-31 17:01:38 +02:00
|
|
|
if not hasattr(param, 'swig_decl'):
|
|
|
|
continue
|
|
|
|
pname = param.ptype_str
|
2011-10-20 22:08:49 +02:00
|
|
|
if pname not in params_to_swig:
|
|
|
|
params_to_swig[pname] = param
|
2007-07-24 06:51:38 +02:00
|
|
|
|
|
|
|
########################################################################
|
|
|
|
#
|
|
|
|
# calculate extra dependencies
|
|
|
|
#
|
|
|
|
module_depends = ["m5", "m5.SimObject", "m5.params"]
|
2010-09-09 23:26:29 +02:00
|
|
|
depends = [ PySource.modules[dep].snode for dep in module_depends ]
|
2014-12-02 12:08:22 +01:00
|
|
|
depends.sort(key = lambda x: x.name)
|
2007-04-13 06:20:04 +02:00
|
|
|
|
2007-07-24 06:51:38 +02:00
|
|
|
########################################################################
|
|
|
|
#
|
|
|
|
# Commands for the basic automatically generated python files
|
|
|
|
#
|
|
|
|
|
2008-07-31 17:01:38 +02:00
|
|
|
# Generate Python file containing a dict specifying the current
|
2009-09-23 00:24:16 +02:00
|
|
|
# buildEnv flags.
|
2008-07-31 17:01:38 +02:00
|
|
|
def makeDefinesPyFile(target, source, env):
|
2011-03-11 20:27:36 +01:00
|
|
|
build_env = source[0].get_contents()
|
2009-09-23 00:24:16 +02:00
|
|
|
|
2010-09-09 23:15:41 +02:00
|
|
|
code = code_formatter()
|
2009-09-23 00:24:16 +02:00
|
|
|
code("""
|
2017-01-27 13:40:01 +01:00
|
|
|
import _m5.core
|
2009-09-23 00:24:16 +02:00
|
|
|
import m5.util
|
|
|
|
|
|
|
|
buildEnv = m5.util.SmartDict($build_env)
|
|
|
|
|
2017-01-27 13:40:01 +01:00
|
|
|
compileDate = _m5.core.compileDate
|
2009-09-26 21:51:37 +02:00
|
|
|
_globals = globals()
|
2017-01-27 13:40:01 +01:00
|
|
|
for key,val in _m5.core.__dict__.iteritems():
|
2009-09-26 21:51:37 +02:00
|
|
|
if key.startswith('flag_'):
|
|
|
|
flag = key[5:]
|
|
|
|
_globals[flag] = val
|
|
|
|
del _globals
|
2009-09-23 00:24:16 +02:00
|
|
|
""")
|
2010-09-09 23:15:41 +02:00
|
|
|
code.write(target[0].abspath)
|
2008-07-31 17:01:38 +02:00
|
|
|
|
2011-03-11 20:27:36 +01:00
|
|
|
defines_info = Value(build_env)
|
2009-01-19 18:59:13 +01:00
|
|
|
# Generate a file with all of the compile options in it
|
2010-11-15 21:04:04 +01:00
|
|
|
env.Command('python/m5/defines.py', defines_info,
|
2011-01-08 06:50:13 +01:00
|
|
|
MakeAction(makeDefinesPyFile, Transform("DEFINES", 0)))
|
2009-01-19 18:59:13 +01:00
|
|
|
PySource('m5', 'python/m5/defines.py')
|
|
|
|
|
2008-07-31 17:01:38 +02:00
|
|
|
# Generate python file containing info about the M5 source code
|
|
|
|
def makeInfoPyFile(target, source, env):
|
2010-09-09 23:15:41 +02:00
|
|
|
code = code_formatter()
|
2008-07-31 17:01:38 +02:00
|
|
|
for src in source:
|
|
|
|
data = ''.join(file(src.srcnode().abspath, 'r').xreadlines())
|
2010-09-09 23:15:41 +02:00
|
|
|
code('$src = ${{repr(data)}}')
|
|
|
|
code.write(str(target[0]))
|
2008-07-31 17:01:38 +02:00
|
|
|
|
2009-01-19 18:59:13 +01:00
|
|
|
# Generate a file that wraps the basic top level files
|
|
|
|
env.Command('python/m5/info.py',
|
2011-06-03 02:36:07 +02:00
|
|
|
[ '#/COPYING', '#/LICENSE', '#/README', ],
|
2011-01-08 06:50:13 +01:00
|
|
|
MakeAction(makeInfoPyFile, Transform("INFO")))
|
2009-01-19 18:59:13 +01:00
|
|
|
PySource('m5', 'python/m5/info.py')
|
|
|
|
|
2007-07-24 06:51:38 +02:00
|
|
|
########################################################################
|
|
|
|
#
|
|
|
|
# Create all of the SimObject param headers and enum headers
|
|
|
|
#
|
|
|
|
|
2011-10-20 22:08:49 +02:00
|
|
|
def createSimObjectParamStruct(target, source, env):
|
2008-07-31 17:01:38 +02:00
|
|
|
assert len(target) == 1 and len(source) == 1
|
|
|
|
|
|
|
|
name = str(source[0].get_contents())
|
|
|
|
obj = sim_objects[name]
|
|
|
|
|
2010-09-09 23:15:41 +02:00
|
|
|
code = code_formatter()
|
2011-10-20 22:08:49 +02:00
|
|
|
obj.cxx_param_decl(code)
|
2010-09-09 23:15:41 +02:00
|
|
|
code.write(target[0].abspath)
|
2008-07-31 17:01:38 +02:00
|
|
|
|
2014-10-16 11:49:37 +02:00
|
|
|
def createSimObjectCxxConfig(is_header):
|
|
|
|
def body(target, source, env):
|
|
|
|
assert len(target) == 1 and len(source) == 1
|
|
|
|
|
|
|
|
name = str(source[0].get_contents())
|
|
|
|
obj = sim_objects[name]
|
|
|
|
|
|
|
|
code = code_formatter()
|
|
|
|
obj.cxx_config_param_file(code, is_header)
|
|
|
|
code.write(target[0].abspath)
|
|
|
|
return body
|
|
|
|
|
2011-10-20 22:08:49 +02:00
|
|
|
def createParamSwigWrapper(target, source, env):
|
2008-07-31 17:01:38 +02:00
|
|
|
assert len(target) == 1 and len(source) == 1
|
|
|
|
|
|
|
|
name = str(source[0].get_contents())
|
2011-10-20 22:08:49 +02:00
|
|
|
param = params_to_swig[name]
|
2008-07-31 17:01:38 +02:00
|
|
|
|
2010-09-09 23:15:41 +02:00
|
|
|
code = code_formatter()
|
|
|
|
param.swig_decl(code)
|
|
|
|
code.write(target[0].abspath)
|
2008-07-31 17:01:38 +02:00
|
|
|
|
|
|
|
def createEnumStrings(target, source, env):
|
|
|
|
assert len(target) == 1 and len(source) == 1
|
|
|
|
|
|
|
|
name = str(source[0].get_contents())
|
|
|
|
obj = all_enums[name]
|
|
|
|
|
2010-09-09 23:15:41 +02:00
|
|
|
code = code_formatter()
|
|
|
|
obj.cxx_def(code)
|
|
|
|
code.write(target[0].abspath)
|
2008-07-31 17:01:38 +02:00
|
|
|
|
2011-10-20 22:08:49 +02:00
|
|
|
def createEnumDecls(target, source, env):
|
2008-07-31 17:01:38 +02:00
|
|
|
assert len(target) == 1 and len(source) == 1
|
|
|
|
|
|
|
|
name = str(source[0].get_contents())
|
|
|
|
obj = all_enums[name]
|
|
|
|
|
2010-09-09 23:15:41 +02:00
|
|
|
code = code_formatter()
|
|
|
|
obj.cxx_decl(code)
|
|
|
|
code.write(target[0].abspath)
|
2008-07-31 17:01:38 +02:00
|
|
|
|
2011-10-20 22:08:49 +02:00
|
|
|
def createEnumSwigWrapper(target, source, env):
|
2010-09-09 23:26:29 +02:00
|
|
|
assert len(target) == 1 and len(source) == 1
|
|
|
|
|
|
|
|
name = str(source[0].get_contents())
|
|
|
|
obj = all_enums[name]
|
|
|
|
|
|
|
|
code = code_formatter()
|
2011-10-20 22:08:49 +02:00
|
|
|
obj.swig_decl(code)
|
|
|
|
code.write(target[0].abspath)
|
2010-09-09 23:26:29 +02:00
|
|
|
|
2011-10-20 22:08:49 +02:00
|
|
|
def createSimObjectSwigWrapper(target, source, env):
|
|
|
|
name = source[0].get_contents()
|
|
|
|
obj = sim_objects[name]
|
2010-09-09 23:26:29 +02:00
|
|
|
|
2011-10-20 22:08:49 +02:00
|
|
|
code = code_formatter()
|
|
|
|
obj.swig_decl(code)
|
2010-09-09 23:26:29 +02:00
|
|
|
code.write(target[0].abspath)
|
|
|
|
|
2014-10-16 11:49:33 +02:00
|
|
|
# dummy target for generated code
|
|
|
|
# we start out with all the Source files so they get copied to build/*/ also.
|
|
|
|
SWIG = env.Dummy('swig', [s.tnode for s in Source.get()])
|
|
|
|
|
2011-10-20 22:08:49 +02:00
|
|
|
# Generate all of the SimObject param C++ struct header files
|
2007-07-24 06:51:38 +02:00
|
|
|
params_hh_files = []
|
2009-05-05 01:58:24 +02:00
|
|
|
for name,simobj in sorted(sim_objects.iteritems()):
|
|
|
|
py_source = PySource.modules[simobj.__module__]
|
|
|
|
extra_deps = [ py_source.tnode ]
|
2007-07-24 06:51:38 +02:00
|
|
|
|
|
|
|
hh_file = File('params/%s.hh' % name)
|
|
|
|
params_hh_files.append(hh_file)
|
2010-11-15 21:04:04 +01:00
|
|
|
env.Command(hh_file, Value(name),
|
2011-10-20 22:08:49 +02:00
|
|
|
MakeAction(createSimObjectParamStruct, Transform("SO PARAM")))
|
2007-07-24 06:51:38 +02:00
|
|
|
env.Depends(hh_file, depends + extra_deps)
|
2014-10-16 11:49:33 +02:00
|
|
|
env.Depends(SWIG, hh_file)
|
2007-07-24 06:51:38 +02:00
|
|
|
|
2014-10-16 11:49:37 +02:00
|
|
|
# C++ parameter description files
|
|
|
|
if GetOption('with_cxx_config'):
|
|
|
|
for name,simobj in sorted(sim_objects.iteritems()):
|
|
|
|
py_source = PySource.modules[simobj.__module__]
|
|
|
|
extra_deps = [ py_source.tnode ]
|
|
|
|
|
|
|
|
cxx_config_hh_file = File('cxx_config/%s.hh' % name)
|
|
|
|
cxx_config_cc_file = File('cxx_config/%s.cc' % name)
|
|
|
|
env.Command(cxx_config_hh_file, Value(name),
|
|
|
|
MakeAction(createSimObjectCxxConfig(True),
|
|
|
|
Transform("CXXCPRHH")))
|
|
|
|
env.Command(cxx_config_cc_file, Value(name),
|
|
|
|
MakeAction(createSimObjectCxxConfig(False),
|
|
|
|
Transform("CXXCPRCC")))
|
|
|
|
env.Depends(cxx_config_hh_file, depends + extra_deps +
|
|
|
|
[File('params/%s.hh' % name), File('sim/cxx_config.hh')])
|
|
|
|
env.Depends(cxx_config_cc_file, depends + extra_deps +
|
|
|
|
[cxx_config_hh_file])
|
|
|
|
Source(cxx_config_cc_file)
|
|
|
|
|
|
|
|
cxx_config_init_cc_file = File('cxx_config/init.cc')
|
|
|
|
|
|
|
|
def createCxxConfigInitCC(target, source, env):
|
|
|
|
assert len(target) == 1 and len(source) == 1
|
|
|
|
|
|
|
|
code = code_formatter()
|
|
|
|
|
|
|
|
for name,simobj in sorted(sim_objects.iteritems()):
|
|
|
|
if not hasattr(simobj, 'abstract') or not simobj.abstract:
|
|
|
|
code('#include "cxx_config/${name}.hh"')
|
|
|
|
code()
|
|
|
|
code('void cxxConfigInit()')
|
|
|
|
code('{')
|
|
|
|
code.indent()
|
|
|
|
for name,simobj in sorted(sim_objects.iteritems()):
|
|
|
|
not_abstract = not hasattr(simobj, 'abstract') or \
|
|
|
|
not simobj.abstract
|
|
|
|
if not_abstract and 'type' in simobj.__dict__:
|
|
|
|
code('cxx_config_directory["${name}"] = '
|
|
|
|
'${name}CxxConfigParams::makeDirectoryEntry();')
|
|
|
|
code.dedent()
|
|
|
|
code('}')
|
|
|
|
code.write(target[0].abspath)
|
|
|
|
|
|
|
|
py_source = PySource.modules[simobj.__module__]
|
|
|
|
extra_deps = [ py_source.tnode ]
|
|
|
|
env.Command(cxx_config_init_cc_file, Value(name),
|
|
|
|
MakeAction(createCxxConfigInitCC, Transform("CXXCINIT")))
|
|
|
|
cxx_param_hh_files = ["cxx_config/%s.hh" % simobj
|
2014-12-02 12:08:22 +01:00
|
|
|
for name,simobj in sorted(sim_objects.iteritems())
|
2014-10-16 11:49:37 +02:00
|
|
|
if not hasattr(simobj, 'abstract') or not simobj.abstract]
|
|
|
|
Depends(cxx_config_init_cc_file, cxx_param_hh_files +
|
|
|
|
[File('sim/cxx_config.hh')])
|
|
|
|
Source(cxx_config_init_cc_file)
|
|
|
|
|
2011-10-20 22:08:49 +02:00
|
|
|
# Generate any needed param SWIG wrapper files
|
2008-06-14 21:10:50 +02:00
|
|
|
params_i_files = []
|
2014-12-02 12:08:22 +01:00
|
|
|
for name,param in sorted(params_to_swig.iteritems()):
|
2017-01-27 13:40:01 +01:00
|
|
|
i_file = File('python/_m5/%s.i' % (param.swig_module_name()))
|
2008-06-14 21:10:50 +02:00
|
|
|
params_i_files.append(i_file)
|
2010-11-15 21:04:04 +01:00
|
|
|
env.Command(i_file, Value(name),
|
2011-10-20 22:08:49 +02:00
|
|
|
MakeAction(createParamSwigWrapper, Transform("SW PARAM")))
|
2007-07-24 06:51:38 +02:00
|
|
|
env.Depends(i_file, depends)
|
2014-10-16 11:49:33 +02:00
|
|
|
env.Depends(SWIG, i_file)
|
2017-01-27 13:40:01 +01:00
|
|
|
SwigSource('_m5', i_file)
|
2007-07-24 06:51:38 +02:00
|
|
|
|
|
|
|
# Generate all enum header files
|
2009-05-05 01:58:24 +02:00
|
|
|
for name,enum in sorted(all_enums.iteritems()):
|
|
|
|
py_source = PySource.modules[enum.__module__]
|
|
|
|
extra_deps = [ py_source.tnode ]
|
2007-07-24 06:51:38 +02:00
|
|
|
|
|
|
|
cc_file = File('enums/%s.cc' % name)
|
2010-11-15 21:04:04 +01:00
|
|
|
env.Command(cc_file, Value(name),
|
2011-01-08 06:50:13 +01:00
|
|
|
MakeAction(createEnumStrings, Transform("ENUM STR")))
|
2007-07-24 06:51:38 +02:00
|
|
|
env.Depends(cc_file, depends + extra_deps)
|
2014-10-16 11:49:33 +02:00
|
|
|
env.Depends(SWIG, cc_file)
|
2007-07-24 06:51:38 +02:00
|
|
|
Source(cc_file)
|
|
|
|
|
|
|
|
hh_file = File('enums/%s.hh' % name)
|
2010-11-15 21:04:04 +01:00
|
|
|
env.Command(hh_file, Value(name),
|
2011-10-20 22:08:49 +02:00
|
|
|
MakeAction(createEnumDecls, Transform("ENUMDECL")))
|
2007-07-24 06:51:38 +02:00
|
|
|
env.Depends(hh_file, depends + extra_deps)
|
2014-10-16 11:49:33 +02:00
|
|
|
env.Depends(SWIG, hh_file)
|
2007-07-24 06:51:38 +02:00
|
|
|
|
2017-01-27 13:40:01 +01:00
|
|
|
i_file = File('python/_m5/enum_%s.i' % name)
|
2010-11-15 21:04:04 +01:00
|
|
|
env.Command(i_file, Value(name),
|
2011-10-20 22:08:49 +02:00
|
|
|
MakeAction(createEnumSwigWrapper, Transform("ENUMSWIG")))
|
2010-09-09 23:26:29 +02:00
|
|
|
env.Depends(i_file, depends + extra_deps)
|
2014-10-16 11:49:33 +02:00
|
|
|
env.Depends(SWIG, i_file)
|
2017-01-27 13:40:01 +01:00
|
|
|
SwigSource('_m5', i_file)
|
2008-07-31 17:01:38 +02:00
|
|
|
|
2011-10-20 22:08:49 +02:00
|
|
|
# Generate SimObject SWIG wrapper files
|
2014-12-02 12:08:22 +01:00
|
|
|
for name,simobj in sorted(sim_objects.iteritems()):
|
2012-09-25 18:49:40 +02:00
|
|
|
py_source = PySource.modules[simobj.__module__]
|
|
|
|
extra_deps = [ py_source.tnode ]
|
2017-01-27 13:40:01 +01:00
|
|
|
i_file = File('python/_m5/param_%s.i' % name)
|
2011-10-20 22:08:49 +02:00
|
|
|
env.Command(i_file, Value(name),
|
|
|
|
MakeAction(createSimObjectSwigWrapper, Transform("SO SWIG")))
|
2012-09-25 18:49:40 +02:00
|
|
|
env.Depends(i_file, depends + extra_deps)
|
2017-01-27 13:40:01 +01:00
|
|
|
SwigSource('_m5', i_file)
|
2007-07-24 06:51:38 +02:00
|
|
|
|
2010-09-09 23:15:42 +02:00
|
|
|
# Generate the main swig init file
|
2016-06-28 09:50:00 +02:00
|
|
|
def makeEmbeddedSwigInit(package):
|
|
|
|
def body(target, source, env):
|
|
|
|
assert len(target) == 1 and len(source) == 1
|
2010-09-09 23:15:42 +02:00
|
|
|
|
2016-06-28 09:50:00 +02:00
|
|
|
code = code_formatter()
|
|
|
|
module = source[0].get_contents()
|
|
|
|
# Provide the full context so that the swig-generated call to
|
|
|
|
# Py_InitModule ends up placing the embedded module in the
|
|
|
|
# right package.
|
|
|
|
context = str(package) + "._" + str(module)
|
|
|
|
code('''\
|
|
|
|
#include "sim/init.hh"
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
void init_${module}();
|
|
|
|
}
|
|
|
|
|
|
|
|
EmbeddedSwig embed_swig_${module}(init_${module}, "${context}");
|
|
|
|
''')
|
|
|
|
code.write(str(target[0]))
|
|
|
|
return body
|
2016-01-19 20:28:22 +01:00
|
|
|
|
2007-07-24 06:51:38 +02:00
|
|
|
# Build all swig modules
|
2009-05-05 01:58:24 +02:00
|
|
|
for swig in SwigSource.all:
|
|
|
|
env.Command([swig.cc_source.tnode, swig.py_source.tnode], swig.tnode,
|
2010-11-15 21:04:04 +01:00
|
|
|
MakeAction('$SWIG $SWIGFLAGS -outdir ${TARGETS[1].dir} '
|
2011-01-08 06:50:13 +01:00
|
|
|
'-o ${TARGETS[0]} $SOURCES', Transform("SWIG")))
|
2011-04-15 19:45:11 +02:00
|
|
|
cc_file = str(swig.tnode)
|
2011-10-20 22:08:49 +02:00
|
|
|
init_file = '%s/%s_init.cc' % (dirname(cc_file), basename(cc_file))
|
2010-11-15 21:04:04 +01:00
|
|
|
env.Command(init_file, Value(swig.module),
|
2016-06-28 09:50:00 +02:00
|
|
|
MakeAction(makeEmbeddedSwigInit(swig.package),
|
|
|
|
Transform("EMBED SW")))
|
2014-10-16 11:49:33 +02:00
|
|
|
env.Depends(SWIG, init_file)
|
2011-04-15 19:45:11 +02:00
|
|
|
Source(init_file, **swig.guards)
|
2007-04-13 06:20:04 +02:00
|
|
|
|
2013-01-07 19:05:37 +01:00
|
|
|
# Build all protocol buffers if we have got protoc and protobuf available
|
|
|
|
if env['HAVE_PROTOBUF']:
|
|
|
|
for proto in ProtoBuf.all:
|
|
|
|
# Use both the source and header as the target, and the .proto
|
|
|
|
# file as the source. When executing the protoc compiler, also
|
|
|
|
# specify the proto_path to avoid having the generated files
|
|
|
|
# include the path.
|
|
|
|
env.Command([proto.cc_file, proto.hh_file], proto.tnode,
|
|
|
|
MakeAction('$PROTOC --cpp_out ${TARGET.dir} '
|
|
|
|
'--proto_path ${SOURCE.dir} $SOURCE',
|
|
|
|
Transform("PROTOC")))
|
|
|
|
|
2014-10-16 11:49:33 +02:00
|
|
|
env.Depends(SWIG, [proto.cc_file, proto.hh_file])
|
2013-01-07 19:05:37 +01:00
|
|
|
# Add the C++ source file
|
|
|
|
Source(proto.cc_file, **proto.guards)
|
|
|
|
elif ProtoBuf.all:
|
|
|
|
print 'Got protobuf to build, but lacks support!'
|
|
|
|
Exit(1)
|
|
|
|
|
2011-04-15 19:44:32 +02:00
|
|
|
#
|
|
|
|
# Handle debug flags
|
|
|
|
#
|
|
|
|
def makeDebugFlagCC(target, source, env):
|
|
|
|
assert(len(target) == 1 and len(source) == 1)
|
2008-07-31 17:01:38 +02:00
|
|
|
|
2010-09-09 23:15:41 +02:00
|
|
|
code = code_formatter()
|
2008-07-31 17:01:38 +02:00
|
|
|
|
2014-08-13 00:35:28 +02:00
|
|
|
# delay definition of CompoundFlags until after all the definition
|
|
|
|
# of all constituent SimpleFlags
|
|
|
|
comp_code = code_formatter()
|
|
|
|
|
2008-07-31 17:01:38 +02:00
|
|
|
# file header
|
2010-09-09 23:15:41 +02:00
|
|
|
code('''
|
2008-07-31 17:01:38 +02:00
|
|
|
/*
|
2014-08-13 00:35:28 +02:00
|
|
|
* DO NOT EDIT THIS FILE! Automatically generated by SCons.
|
2008-07-31 17:01:38 +02:00
|
|
|
*/
|
|
|
|
|
2011-04-15 19:44:32 +02:00
|
|
|
#include "base/debug.hh"
|
2008-07-31 17:01:38 +02:00
|
|
|
|
2014-08-13 00:35:28 +02:00
|
|
|
namespace Debug {
|
2008-07-31 17:01:38 +02:00
|
|
|
|
2014-08-13 00:35:28 +02:00
|
|
|
''')
|
|
|
|
|
|
|
|
for name, flag in sorted(source[0].read().iteritems()):
|
|
|
|
n, compound, desc = flag
|
|
|
|
assert n == name
|
2011-04-15 19:44:32 +02:00
|
|
|
|
2014-08-13 00:35:28 +02:00
|
|
|
if not compound:
|
|
|
|
code('SimpleFlag $name("$name", "$desc");')
|
|
|
|
else:
|
|
|
|
comp_code('CompoundFlag $name("$name", "$desc",')
|
|
|
|
comp_code.indent()
|
|
|
|
last = len(compound) - 1
|
|
|
|
for i,flag in enumerate(compound):
|
|
|
|
if i != last:
|
2015-02-11 16:23:23 +01:00
|
|
|
comp_code('&$flag,')
|
2014-08-13 00:35:28 +02:00
|
|
|
else:
|
2015-02-11 16:23:23 +01:00
|
|
|
comp_code('&$flag);')
|
2014-08-13 00:35:28 +02:00
|
|
|
comp_code.dedent()
|
|
|
|
|
|
|
|
code.append(comp_code)
|
2011-04-15 19:44:32 +02:00
|
|
|
code()
|
|
|
|
code('} // namespace Debug')
|
2008-07-31 17:01:38 +02:00
|
|
|
|
2010-09-09 23:15:41 +02:00
|
|
|
code.write(str(target[0]))
|
2008-07-31 17:01:38 +02:00
|
|
|
|
2011-04-15 19:44:32 +02:00
|
|
|
def makeDebugFlagHH(target, source, env):
|
|
|
|
assert(len(target) == 1 and len(source) == 1)
|
|
|
|
|
|
|
|
val = eval(source[0].get_contents())
|
|
|
|
name, compound, desc = val
|
2008-07-31 17:01:38 +02:00
|
|
|
|
2010-09-09 23:15:41 +02:00
|
|
|
code = code_formatter()
|
2008-07-31 17:01:38 +02:00
|
|
|
|
|
|
|
# file header boilerplate
|
2010-09-09 23:15:41 +02:00
|
|
|
code('''\
|
2008-07-31 17:01:38 +02:00
|
|
|
/*
|
2014-08-13 00:35:28 +02:00
|
|
|
* DO NOT EDIT THIS FILE! Automatically generated by SCons.
|
2008-07-31 17:01:38 +02:00
|
|
|
*/
|
|
|
|
|
2011-04-15 19:44:32 +02:00
|
|
|
#ifndef __DEBUG_${name}_HH__
|
|
|
|
#define __DEBUG_${name}_HH__
|
2008-07-31 17:01:38 +02:00
|
|
|
|
2011-04-15 19:44:32 +02:00
|
|
|
namespace Debug {
|
|
|
|
''')
|
2008-07-31 17:01:38 +02:00
|
|
|
|
2011-04-15 19:44:32 +02:00
|
|
|
if compound:
|
|
|
|
code('class CompoundFlag;')
|
|
|
|
code('class SimpleFlag;')
|
2008-07-31 17:01:38 +02:00
|
|
|
|
2011-04-15 19:44:32 +02:00
|
|
|
if compound:
|
|
|
|
code('extern CompoundFlag $name;')
|
|
|
|
for flag in compound:
|
|
|
|
code('extern SimpleFlag $flag;')
|
|
|
|
else:
|
|
|
|
code('extern SimpleFlag $name;')
|
2008-07-31 17:01:38 +02:00
|
|
|
|
2010-09-09 23:15:41 +02:00
|
|
|
code('''
|
2011-04-15 19:44:32 +02:00
|
|
|
}
|
2008-07-31 17:01:38 +02:00
|
|
|
|
2011-04-15 19:44:32 +02:00
|
|
|
#endif // __DEBUG_${name}_HH__
|
2010-09-09 23:15:41 +02:00
|
|
|
''')
|
2008-07-31 17:01:38 +02:00
|
|
|
|
2010-09-09 23:15:41 +02:00
|
|
|
code.write(str(target[0]))
|
2008-07-31 17:01:38 +02:00
|
|
|
|
2011-04-15 19:44:32 +02:00
|
|
|
for name,flag in sorted(debug_flags.iteritems()):
|
|
|
|
n, compound, desc = flag
|
|
|
|
assert n == name
|
2007-10-31 06:21:54 +01:00
|
|
|
|
2014-10-16 11:49:33 +02:00
|
|
|
hh_file = 'debug/%s.hh' % name
|
|
|
|
env.Command(hh_file, Value(flag),
|
2011-04-15 19:44:32 +02:00
|
|
|
MakeAction(makeDebugFlagHH, Transform("TRACING", 0)))
|
2014-08-13 00:35:28 +02:00
|
|
|
env.Depends(SWIG, hh_file)
|
|
|
|
|
|
|
|
env.Command('debug/flags.cc', Value(debug_flags),
|
|
|
|
MakeAction(makeDebugFlagCC, Transform("TRACING", 0)))
|
|
|
|
env.Depends(SWIG, 'debug/flags.cc')
|
|
|
|
Source('debug/flags.cc')
|
2007-10-31 06:21:54 +01:00
|
|
|
|
2015-09-02 22:23:30 +02:00
|
|
|
# version tags
|
2016-02-08 20:39:45 +01:00
|
|
|
tags = \
|
2015-09-02 22:23:30 +02:00
|
|
|
env.Command('sim/tags.cc', None,
|
|
|
|
MakeAction('util/cpt_upgrader.py --get-cc-file > $TARGET',
|
|
|
|
Transform("VER TAGS")))
|
2016-02-08 20:39:45 +01:00
|
|
|
env.AlwaysBuild(tags)
|
2015-09-02 22:23:30 +02:00
|
|
|
|
2010-09-09 23:15:42 +02:00
|
|
|
# Embed python files. All .py files that have been indicated by a
|
libm5: Create a libm5 static library for embedding m5.
This should allow m5 to be more easily embedded into other simulators.
The m5 binary adds a simple main function which then calls into the m5
libarary to start the simulation. In order to make this work
correctly, it was necessary embed python code directly into the
library instead of the zipfile hack. This is because you can't just
append the zipfile to the end of a library the way you can a binary.
As a result, Python files that are part of the m5 simulator are now
compile, marshalled, compressed, and then inserted into the library's
data section with a certain symbol name. Additionally, a new Importer
was needed to allow python to get at the embedded python code.
Small additional changes include:
- Get rid of the PYTHONHOME stuff since I don't think anyone ever used
it, and it just confuses things. Easy enough to add back if I'm wrong.
- Create a few new functions that are key to initializing and running
the simulator: initSignals, initM5Python, m5Main.
The original code for creating libm5 was inspired by a patch Michael
Adler, though the code here was done by me.
2008-08-04 03:19:54 +02:00
|
|
|
# PySource() call in a SConscript need to be embedded into the M5
|
|
|
|
# library. To do that, we compile the file to byte code, marshal the
|
2010-09-09 23:15:42 +02:00
|
|
|
# byte code, compress it, and then generate a c++ file that
|
|
|
|
# inserts the result into an array.
|
|
|
|
def embedPyFile(target, source, env):
|
|
|
|
def c_str(string):
|
|
|
|
if string is None:
|
|
|
|
return "0"
|
|
|
|
return '"%s"' % string
|
|
|
|
|
libm5: Create a libm5 static library for embedding m5.
This should allow m5 to be more easily embedded into other simulators.
The m5 binary adds a simple main function which then calls into the m5
libarary to start the simulation. In order to make this work
correctly, it was necessary embed python code directly into the
library instead of the zipfile hack. This is because you can't just
append the zipfile to the end of a library the way you can a binary.
As a result, Python files that are part of the m5 simulator are now
compile, marshalled, compressed, and then inserted into the library's
data section with a certain symbol name. Additionally, a new Importer
was needed to allow python to get at the embedded python code.
Small additional changes include:
- Get rid of the PYTHONHOME stuff since I don't think anyone ever used
it, and it just confuses things. Easy enough to add back if I'm wrong.
- Create a few new functions that are key to initializing and running
the simulator: initSignals, initM5Python, m5Main.
The original code for creating libm5 was inspired by a patch Michael
Adler, though the code here was done by me.
2008-08-04 03:19:54 +02:00
|
|
|
'''Action function to compile a .py into a code object, marshal
|
|
|
|
it, compress it, and stick it into an asm file so the code appears
|
|
|
|
as just bytes with a label in the data section'''
|
|
|
|
|
|
|
|
src = file(str(source[0]), 'r').read()
|
|
|
|
|
2009-05-05 01:58:24 +02:00
|
|
|
pysource = PySource.tnodes[source[0]]
|
2009-11-09 02:35:49 +01:00
|
|
|
compiled = compile(src, pysource.abspath, 'exec')
|
libm5: Create a libm5 static library for embedding m5.
This should allow m5 to be more easily embedded into other simulators.
The m5 binary adds a simple main function which then calls into the m5
libarary to start the simulation. In order to make this work
correctly, it was necessary embed python code directly into the
library instead of the zipfile hack. This is because you can't just
append the zipfile to the end of a library the way you can a binary.
As a result, Python files that are part of the m5 simulator are now
compile, marshalled, compressed, and then inserted into the library's
data section with a certain symbol name. Additionally, a new Importer
was needed to allow python to get at the embedded python code.
Small additional changes include:
- Get rid of the PYTHONHOME stuff since I don't think anyone ever used
it, and it just confuses things. Easy enough to add back if I'm wrong.
- Create a few new functions that are key to initializing and running
the simulator: initSignals, initM5Python, m5Main.
The original code for creating libm5 was inspired by a patch Michael
Adler, though the code here was done by me.
2008-08-04 03:19:54 +02:00
|
|
|
marshalled = marshal.dumps(compiled)
|
|
|
|
compressed = zlib.compress(marshalled)
|
|
|
|
data = compressed
|
2010-09-09 23:15:42 +02:00
|
|
|
sym = pysource.symname
|
libm5: Create a libm5 static library for embedding m5.
This should allow m5 to be more easily embedded into other simulators.
The m5 binary adds a simple main function which then calls into the m5
libarary to start the simulation. In order to make this work
correctly, it was necessary embed python code directly into the
library instead of the zipfile hack. This is because you can't just
append the zipfile to the end of a library the way you can a binary.
As a result, Python files that are part of the m5 simulator are now
compile, marshalled, compressed, and then inserted into the library's
data section with a certain symbol name. Additionally, a new Importer
was needed to allow python to get at the embedded python code.
Small additional changes include:
- Get rid of the PYTHONHOME stuff since I don't think anyone ever used
it, and it just confuses things. Easy enough to add back if I'm wrong.
- Create a few new functions that are key to initializing and running
the simulator: initSignals, initM5Python, m5Main.
The original code for creating libm5 was inspired by a patch Michael
Adler, though the code here was done by me.
2008-08-04 03:19:54 +02:00
|
|
|
|
2010-09-09 23:15:41 +02:00
|
|
|
code = code_formatter()
|
|
|
|
code('''\
|
2010-09-09 23:15:42 +02:00
|
|
|
#include "sim/init.hh"
|
|
|
|
|
|
|
|
namespace {
|
2010-09-09 23:15:41 +02:00
|
|
|
|
clang/gcc: Fix compilation issues with clang 3.0 and gcc 4.6
This patch addresses a number of minor issues that cause problems when
compiling with clang >= 3.0 and gcc >= 4.6. Most importantly, it
avoids using the deprecated ext/hash_map and instead uses
unordered_map (and similarly so for the hash_set). To make use of the
new STL containers, g++ and clang has to be invoked with "-std=c++0x",
and this is now added for all gcc versions >= 4.6, and for clang >=
3.0. For gcc >= 4.3 and <= 4.5 and clang <= 3.0 we use the tr1
unordered_map to avoid the deprecation warning.
The addition of c++0x in turn causes a few problems, as the
compiler is more stringent and adds a number of new warnings. Below,
the most important issues are enumerated:
1) the use of namespaces is more strict, e.g. for isnan, and all
headers opening the entire namespace std are now fixed.
2) another other issue caused by the more stringent compiler is the
narrowing of the embedded python, which used to be a char array,
and is now unsigned char since there were values larger than 128.
3) a particularly odd issue that arose with the new c++0x behaviour is
found in range.hh, where the operator< causes gcc to complain about
the template type parsing (the "<" is interpreted as the beginning
of a template argument), and the problem seems to be related to the
begin/end members introduced for the range-type iteration, which is
a new feature in c++11.
As a minor update, this patch also fixes the build flags for the clang
debug target that used to be shared with gcc and incorrectly use
"-ggdb".
2012-04-14 11:43:31 +02:00
|
|
|
const uint8_t data_${sym}[] = {
|
2010-09-09 23:15:42 +02:00
|
|
|
''')
|
|
|
|
code.indent()
|
|
|
|
step = 16
|
libm5: Create a libm5 static library for embedding m5.
This should allow m5 to be more easily embedded into other simulators.
The m5 binary adds a simple main function which then calls into the m5
libarary to start the simulation. In order to make this work
correctly, it was necessary embed python code directly into the
library instead of the zipfile hack. This is because you can't just
append the zipfile to the end of a library the way you can a binary.
As a result, Python files that are part of the m5 simulator are now
compile, marshalled, compressed, and then inserted into the library's
data section with a certain symbol name. Additionally, a new Importer
was needed to allow python to get at the embedded python code.
Small additional changes include:
- Get rid of the PYTHONHOME stuff since I don't think anyone ever used
it, and it just confuses things. Easy enough to add back if I'm wrong.
- Create a few new functions that are key to initializing and running
the simulator: initSignals, initM5Python, m5Main.
The original code for creating libm5 was inspired by a patch Michael
Adler, though the code here was done by me.
2008-08-04 03:19:54 +02:00
|
|
|
for i in xrange(0, len(data), step):
|
|
|
|
x = array.array('B', data[i:i+step])
|
2010-09-09 23:15:42 +02:00
|
|
|
code(''.join('%d,' % d for d in x))
|
|
|
|
code.dedent()
|
2016-01-19 20:28:22 +01:00
|
|
|
|
2010-09-09 23:15:42 +02:00
|
|
|
code('''};
|
libm5: Create a libm5 static library for embedding m5.
This should allow m5 to be more easily embedded into other simulators.
The m5 binary adds a simple main function which then calls into the m5
libarary to start the simulation. In order to make this work
correctly, it was necessary embed python code directly into the
library instead of the zipfile hack. This is because you can't just
append the zipfile to the end of a library the way you can a binary.
As a result, Python files that are part of the m5 simulator are now
compile, marshalled, compressed, and then inserted into the library's
data section with a certain symbol name. Additionally, a new Importer
was needed to allow python to get at the embedded python code.
Small additional changes include:
- Get rid of the PYTHONHOME stuff since I don't think anyone ever used
it, and it just confuses things. Easy enough to add back if I'm wrong.
- Create a few new functions that are key to initializing and running
the simulator: initSignals, initM5Python, m5Main.
The original code for creating libm5 was inspired by a patch Michael
Adler, though the code here was done by me.
2008-08-04 03:19:54 +02:00
|
|
|
|
2010-09-09 23:15:42 +02:00
|
|
|
EmbeddedPython embedded_${sym}(
|
|
|
|
${{c_str(pysource.arcname)}},
|
|
|
|
${{c_str(pysource.abspath)}},
|
|
|
|
${{c_str(pysource.modpath)}},
|
|
|
|
data_${sym},
|
|
|
|
${{len(data)}},
|
|
|
|
${{len(marshalled)}});
|
libm5: Create a libm5 static library for embedding m5.
This should allow m5 to be more easily embedded into other simulators.
The m5 binary adds a simple main function which then calls into the m5
libarary to start the simulation. In order to make this work
correctly, it was necessary embed python code directly into the
library instead of the zipfile hack. This is because you can't just
append the zipfile to the end of a library the way you can a binary.
As a result, Python files that are part of the m5 simulator are now
compile, marshalled, compressed, and then inserted into the library's
data section with a certain symbol name. Additionally, a new Importer
was needed to allow python to get at the embedded python code.
Small additional changes include:
- Get rid of the PYTHONHOME stuff since I don't think anyone ever used
it, and it just confuses things. Easy enough to add back if I'm wrong.
- Create a few new functions that are key to initializing and running
the simulator: initSignals, initM5Python, m5Main.
The original code for creating libm5 was inspired by a patch Michael
Adler, though the code here was done by me.
2008-08-04 03:19:54 +02:00
|
|
|
|
2011-01-03 23:35:43 +01:00
|
|
|
} // anonymous namespace
|
2010-09-09 23:15:41 +02:00
|
|
|
''')
|
|
|
|
code.write(str(target[0]))
|
2009-05-05 01:58:24 +02:00
|
|
|
|
2010-09-09 23:15:42 +02:00
|
|
|
for source in PySource.all:
|
2014-10-16 11:49:32 +02:00
|
|
|
env.Command(source.cpp, source.tnode,
|
2011-01-08 06:50:13 +01:00
|
|
|
MakeAction(embedPyFile, Transform("EMBED PY")))
|
2014-10-16 11:49:33 +02:00
|
|
|
env.Depends(SWIG, source.cpp)
|
2014-10-16 11:49:32 +02:00
|
|
|
Source(source.cpp, skip_no_python=True)
|
2007-04-13 06:20:04 +02:00
|
|
|
|
|
|
|
########################################################################
|
|
|
|
#
|
|
|
|
# Define binaries. Each different build type (debug, opt, etc.) gets
|
|
|
|
# a slightly different build environment.
|
|
|
|
#
|
|
|
|
|
|
|
|
# List of constructed environments to pass back to SConstruct
|
2009-05-05 01:58:24 +02:00
|
|
|
date_source = Source('base/date.cc', skip_lib=True)
|
2004-07-03 06:16:38 +02:00
|
|
|
|
arch: teach ISA parser how to split code across files
This patch encompasses several interrelated and interdependent changes
to the ISA generation step. The end goal is to reduce the size of the
generated compilation units for instruction execution and decoding so
that batch compilation can proceed with all CPUs active without
exhausting physical memory.
The ISA parser (src/arch/isa_parser.py) has been improved so that it can
accept 'split [output_type];' directives at the top level of the grammar
and 'split(output_type)' python calls within 'exec {{ ... }}' blocks.
This has the effect of "splitting" the files into smaller compilation
units. I use air-quotes around "splitting" because the files themselves
are not split, but preprocessing directives are inserted to have the same
effect.
Architecturally, the ISA parser has had some changes in how it works.
In general, it emits code sooner. It doesn't generate per-CPU files,
and instead defers to the C preprocessor to create the duplicate copies
for each CPU type. Likewise there are more files emitted and the C
preprocessor does more substitution that used to be done by the ISA parser.
Finally, the build system (SCons) needs to be able to cope with a
dynamic list of source files coming out of the ISA parser. The changes
to the SCons{cript,truct} files support this. In broad strokes, the
targets requested on the command line are hidden from SCons until all
the build dependencies are determined, otherwise it would try, realize
it can't reach the goal, and terminate in failure. Since build steps
(i.e. running the ISA parser) must be taken to determine the file list,
several new build stages have been inserted at the very start of the
build. First, the build dependencies from the ISA parser will be emitted
to arch/$ISA/generated/inc.d, which is then read by a new SCons builder
to finalize the dependencies. (Once inc.d exists, the ISA parser will not
need to be run to complete this step.) Once the dependencies are known,
the 'Environments' are made by the makeEnv() function. This function used
to be called before the build began but now happens during the build.
It is easy to see that this step is quite slow; this is a known issue
and it's important to realize that it was already slow, but there was
no obvious cause to attribute it to since nothing was displayed to the
terminal. Since new steps that used to be performed serially are now in a
potentially-parallel build phase, the pathname handling in the SCons scripts
has been tightened up to deal with chdir() race conditions. In general,
pathnames are computed earlier and more likely to be stored, passed around,
and processed as absolute paths rather than relative paths. In the end,
some of these issues had to be fixed by inserting serializing dependencies
in the build.
Minor note:
For the null ISA, we just provide a dummy inc.d so SCons is never
compelled to try to generate it. While it seems slightly wrong to have
anything in src/arch/*/generated (i.e. a non-generated 'generated' file),
it's by far the simplest solution.
2014-05-10 00:58:47 +02:00
|
|
|
# Capture this directory for the closure makeEnv, otherwise when it is
|
|
|
|
# called, it won't know what directory it should use.
|
|
|
|
variant_dir = Dir('.').path
|
|
|
|
def variant(*path):
|
|
|
|
return os.path.join(variant_dir, *path)
|
|
|
|
def variantd(*path):
|
|
|
|
return variant(*path)+'/'
|
|
|
|
|
2006-05-30 19:11:34 +02:00
|
|
|
# Function to create a new build environment as clone of current
|
|
|
|
# environment 'env' with modified object suffix and optional stripped
|
|
|
|
# binary. Additional keyword arguments are appended to corresponding
|
|
|
|
# build environment vars.
|
arch: teach ISA parser how to split code across files
This patch encompasses several interrelated and interdependent changes
to the ISA generation step. The end goal is to reduce the size of the
generated compilation units for instruction execution and decoding so
that batch compilation can proceed with all CPUs active without
exhausting physical memory.
The ISA parser (src/arch/isa_parser.py) has been improved so that it can
accept 'split [output_type];' directives at the top level of the grammar
and 'split(output_type)' python calls within 'exec {{ ... }}' blocks.
This has the effect of "splitting" the files into smaller compilation
units. I use air-quotes around "splitting" because the files themselves
are not split, but preprocessing directives are inserted to have the same
effect.
Architecturally, the ISA parser has had some changes in how it works.
In general, it emits code sooner. It doesn't generate per-CPU files,
and instead defers to the C preprocessor to create the duplicate copies
for each CPU type. Likewise there are more files emitted and the C
preprocessor does more substitution that used to be done by the ISA parser.
Finally, the build system (SCons) needs to be able to cope with a
dynamic list of source files coming out of the ISA parser. The changes
to the SCons{cript,truct} files support this. In broad strokes, the
targets requested on the command line are hidden from SCons until all
the build dependencies are determined, otherwise it would try, realize
it can't reach the goal, and terminate in failure. Since build steps
(i.e. running the ISA parser) must be taken to determine the file list,
several new build stages have been inserted at the very start of the
build. First, the build dependencies from the ISA parser will be emitted
to arch/$ISA/generated/inc.d, which is then read by a new SCons builder
to finalize the dependencies. (Once inc.d exists, the ISA parser will not
need to be run to complete this step.) Once the dependencies are known,
the 'Environments' are made by the makeEnv() function. This function used
to be called before the build began but now happens during the build.
It is easy to see that this step is quite slow; this is a known issue
and it's important to realize that it was already slow, but there was
no obvious cause to attribute it to since nothing was displayed to the
terminal. Since new steps that used to be performed serially are now in a
potentially-parallel build phase, the pathname handling in the SCons scripts
has been tightened up to deal with chdir() race conditions. In general,
pathnames are computed earlier and more likely to be stored, passed around,
and processed as absolute paths rather than relative paths. In the end,
some of these issues had to be fixed by inserting serializing dependencies
in the build.
Minor note:
For the null ISA, we just provide a dummy inc.d so SCons is never
compelled to try to generate it. While it seems slightly wrong to have
anything in src/arch/*/generated (i.e. a non-generated 'generated' file),
it's by far the simplest solution.
2014-05-10 00:58:47 +02:00
|
|
|
def makeEnv(env, label, objsfx, strip = False, **kwargs):
|
2008-10-09 13:58:23 +02:00
|
|
|
# SCons doesn't know to append a library suffix when there is a '.' in the
|
|
|
|
# name. Use '_' instead.
|
arch: teach ISA parser how to split code across files
This patch encompasses several interrelated and interdependent changes
to the ISA generation step. The end goal is to reduce the size of the
generated compilation units for instruction execution and decoding so
that batch compilation can proceed with all CPUs active without
exhausting physical memory.
The ISA parser (src/arch/isa_parser.py) has been improved so that it can
accept 'split [output_type];' directives at the top level of the grammar
and 'split(output_type)' python calls within 'exec {{ ... }}' blocks.
This has the effect of "splitting" the files into smaller compilation
units. I use air-quotes around "splitting" because the files themselves
are not split, but preprocessing directives are inserted to have the same
effect.
Architecturally, the ISA parser has had some changes in how it works.
In general, it emits code sooner. It doesn't generate per-CPU files,
and instead defers to the C preprocessor to create the duplicate copies
for each CPU type. Likewise there are more files emitted and the C
preprocessor does more substitution that used to be done by the ISA parser.
Finally, the build system (SCons) needs to be able to cope with a
dynamic list of source files coming out of the ISA parser. The changes
to the SCons{cript,truct} files support this. In broad strokes, the
targets requested on the command line are hidden from SCons until all
the build dependencies are determined, otherwise it would try, realize
it can't reach the goal, and terminate in failure. Since build steps
(i.e. running the ISA parser) must be taken to determine the file list,
several new build stages have been inserted at the very start of the
build. First, the build dependencies from the ISA parser will be emitted
to arch/$ISA/generated/inc.d, which is then read by a new SCons builder
to finalize the dependencies. (Once inc.d exists, the ISA parser will not
need to be run to complete this step.) Once the dependencies are known,
the 'Environments' are made by the makeEnv() function. This function used
to be called before the build began but now happens during the build.
It is easy to see that this step is quite slow; this is a known issue
and it's important to realize that it was already slow, but there was
no obvious cause to attribute it to since nothing was displayed to the
terminal. Since new steps that used to be performed serially are now in a
potentially-parallel build phase, the pathname handling in the SCons scripts
has been tightened up to deal with chdir() race conditions. In general,
pathnames are computed earlier and more likely to be stored, passed around,
and processed as absolute paths rather than relative paths. In the end,
some of these issues had to be fixed by inserting serializing dependencies
in the build.
Minor note:
For the null ISA, we just provide a dummy inc.d so SCons is never
compelled to try to generate it. While it seems slightly wrong to have
anything in src/arch/*/generated (i.e. a non-generated 'generated' file),
it's by far the simplest solution.
2014-05-10 00:58:47 +02:00
|
|
|
libname = variant('gem5_' + label)
|
|
|
|
exename = variant('gem5.' + label)
|
|
|
|
secondary_exename = variant('m5.' + label)
|
2008-10-09 13:58:23 +02:00
|
|
|
|
2009-02-10 05:10:14 +01:00
|
|
|
new_env = env.Clone(OBJSUFFIX=objsfx, SHOBJSUFFIX=objsfx + 's')
|
2008-10-09 13:58:23 +02:00
|
|
|
new_env.Label = label
|
|
|
|
new_env.Append(**kwargs)
|
libm5: Create a libm5 static library for embedding m5.
This should allow m5 to be more easily embedded into other simulators.
The m5 binary adds a simple main function which then calls into the m5
libarary to start the simulation. In order to make this work
correctly, it was necessary embed python code directly into the
library instead of the zipfile hack. This is because you can't just
append the zipfile to the end of a library the way you can a binary.
As a result, Python files that are part of the m5 simulator are now
compile, marshalled, compressed, and then inserted into the library's
data section with a certain symbol name. Additionally, a new Importer
was needed to allow python to get at the embedded python code.
Small additional changes include:
- Get rid of the PYTHONHOME stuff since I don't think anyone ever used
it, and it just confuses things. Easy enough to add back if I'm wrong.
- Create a few new functions that are key to initializing and running
the simulator: initSignals, initM5Python, m5Main.
The original code for creating libm5 was inspired by a patch Michael
Adler, though the code here was done by me.
2008-08-04 03:19:54 +02:00
|
|
|
|
2009-02-10 05:10:14 +01:00
|
|
|
swig_env = new_env.Clone()
|
2013-02-19 11:56:07 +01:00
|
|
|
|
|
|
|
# Both gcc and clang have issues with unused labels and values in
|
|
|
|
# the SWIG generated code
|
|
|
|
swig_env.Append(CCFLAGS=['-Wno-unused-label', '-Wno-unused-value'])
|
|
|
|
|
2008-09-26 17:18:54 +02:00
|
|
|
if env['GCC']:
|
2013-02-19 11:56:07 +01:00
|
|
|
# Depending on the SWIG version, we also need to supress
|
2013-03-27 18:03:02 +01:00
|
|
|
# warnings about uninitialized variables and missing field
|
|
|
|
# initializers.
|
|
|
|
swig_env.Append(CCFLAGS=['-Wno-uninitialized',
|
2014-06-10 23:44:39 +02:00
|
|
|
'-Wno-missing-field-initializers',
|
2015-07-03 16:14:15 +02:00
|
|
|
'-Wno-unused-but-set-variable',
|
2016-01-11 11:52:20 +01:00
|
|
|
'-Wno-maybe-uninitialized',
|
|
|
|
'-Wno-type-limits'])
|
2014-10-16 11:49:36 +02:00
|
|
|
|
2016-11-28 18:44:54 +01:00
|
|
|
|
|
|
|
# The address sanitizer is available for gcc >= 4.8
|
|
|
|
if GetOption('with_asan'):
|
|
|
|
if GetOption('with_ubsan') and \
|
|
|
|
compareVersions(env['GCC_VERSION'], '4.9') >= 0:
|
|
|
|
new_env.Append(CCFLAGS=['-fsanitize=address,undefined',
|
|
|
|
'-fno-omit-frame-pointer'])
|
|
|
|
new_env.Append(LINKFLAGS='-fsanitize=address,undefined')
|
|
|
|
else:
|
|
|
|
new_env.Append(CCFLAGS=['-fsanitize=address',
|
|
|
|
'-fno-omit-frame-pointer'])
|
|
|
|
new_env.Append(LINKFLAGS='-fsanitize=address')
|
2014-10-16 11:49:36 +02:00
|
|
|
# Only gcc >= 4.9 supports UBSan, so check both the version
|
|
|
|
# and the command-line option before adding the compiler and
|
|
|
|
# linker flags.
|
2016-11-28 18:44:54 +01:00
|
|
|
elif GetOption('with_ubsan') and \
|
2014-10-16 11:49:36 +02:00
|
|
|
compareVersions(env['GCC_VERSION'], '4.9') >= 0:
|
|
|
|
new_env.Append(CCFLAGS='-fsanitize=undefined')
|
|
|
|
new_env.Append(LINKFLAGS='-fsanitize=undefined')
|
|
|
|
|
2016-02-17 09:56:20 +01:00
|
|
|
|
2012-01-31 18:05:52 +01:00
|
|
|
if env['CLANG']:
|
2016-01-11 11:52:20 +01:00
|
|
|
swig_env.Append(CCFLAGS=['-Wno-sometimes-uninitialized',
|
|
|
|
'-Wno-deprecated-register',
|
|
|
|
'-Wno-tautological-compare'])
|
2014-08-13 12:57:28 +02:00
|
|
|
|
2016-02-17 09:56:20 +01:00
|
|
|
# We require clang >= 3.1, so there is no need to check any
|
|
|
|
# versions here.
|
2014-10-16 11:49:36 +02:00
|
|
|
if GetOption('with_ubsan'):
|
2016-11-28 18:44:54 +01:00
|
|
|
if GetOption('with_asan'):
|
|
|
|
new_env.Append(CCFLAGS=['-fsanitize=address,undefined',
|
|
|
|
'-fno-omit-frame-pointer'])
|
|
|
|
new_env.Append(LINKFLAGS='-fsanitize=address,undefined')
|
|
|
|
else:
|
|
|
|
new_env.Append(CCFLAGS='-fsanitize=undefined')
|
|
|
|
new_env.Append(LINKFLAGS='-fsanitize=undefined')
|
2014-10-16 11:49:36 +02:00
|
|
|
|
2016-11-28 18:44:54 +01:00
|
|
|
elif GetOption('with_asan'):
|
2016-05-30 08:10:48 +02:00
|
|
|
new_env.Append(CCFLAGS=['-fsanitize=address',
|
|
|
|
'-fno-omit-frame-pointer'])
|
2016-02-17 09:56:20 +01:00
|
|
|
new_env.Append(LINKFLAGS='-fsanitize=address')
|
|
|
|
|
2012-04-13 17:13:04 +02:00
|
|
|
werror_env = new_env.Clone()
|
2015-02-11 16:23:24 +01:00
|
|
|
# Treat warnings as errors but white list some warnings that we
|
|
|
|
# want to allow (e.g., deprecation warnings).
|
|
|
|
werror_env.Append(CCFLAGS=['-Werror',
|
|
|
|
'-Wno-error=deprecated-declarations',
|
|
|
|
'-Wno-error=deprecated',
|
|
|
|
])
|
2012-04-13 17:13:04 +02:00
|
|
|
|
2009-05-05 01:58:24 +02:00
|
|
|
def make_obj(source, static, extra_deps = None):
|
|
|
|
'''This function adds the specified source to the correct
|
|
|
|
build environment, and returns the corresponding SCons Object
|
|
|
|
nodes'''
|
|
|
|
|
|
|
|
if source.swig:
|
|
|
|
env = swig_env
|
2012-04-13 17:13:04 +02:00
|
|
|
elif source.Werror:
|
|
|
|
env = werror_env
|
2009-05-05 01:58:24 +02:00
|
|
|
else:
|
|
|
|
env = new_env
|
|
|
|
|
|
|
|
if static:
|
|
|
|
obj = env.StaticObject(source.tnode)
|
|
|
|
else:
|
|
|
|
obj = env.SharedObject(source.tnode)
|
|
|
|
|
|
|
|
if extra_deps:
|
|
|
|
env.Depends(obj, extra_deps)
|
|
|
|
|
|
|
|
return obj
|
|
|
|
|
2014-10-16 11:49:32 +02:00
|
|
|
lib_guards = {'main': False, 'skip_lib': False}
|
|
|
|
|
|
|
|
# Without Python, leave out all SWIG and Python content from the
|
|
|
|
# library builds. The option doesn't affect gem5 built as a program
|
|
|
|
if GetOption('without_python'):
|
|
|
|
lib_guards['skip_no_python'] = False
|
|
|
|
|
|
|
|
static_objs = [ make_obj(s, True) for s in Source.get(**lib_guards) ]
|
|
|
|
shared_objs = [ make_obj(s, False) for s in Source.get(**lib_guards) ]
|
2009-05-05 01:58:24 +02:00
|
|
|
|
|
|
|
static_date = make_obj(date_source, static=True, extra_deps=static_objs)
|
|
|
|
static_objs.append(static_date)
|
2014-10-16 11:49:32 +02:00
|
|
|
|
2009-05-05 01:58:24 +02:00
|
|
|
shared_date = make_obj(date_source, static=False, extra_deps=shared_objs)
|
2009-06-13 06:19:16 +02:00
|
|
|
shared_objs.append(shared_date)
|
2008-09-22 17:25:58 +02:00
|
|
|
|
libm5: Create a libm5 static library for embedding m5.
This should allow m5 to be more easily embedded into other simulators.
The m5 binary adds a simple main function which then calls into the m5
libarary to start the simulation. In order to make this work
correctly, it was necessary embed python code directly into the
library instead of the zipfile hack. This is because you can't just
append the zipfile to the end of a library the way you can a binary.
As a result, Python files that are part of the m5 simulator are now
compile, marshalled, compressed, and then inserted into the library's
data section with a certain symbol name. Additionally, a new Importer
was needed to allow python to get at the embedded python code.
Small additional changes include:
- Get rid of the PYTHONHOME stuff since I don't think anyone ever used
it, and it just confuses things. Easy enough to add back if I'm wrong.
- Create a few new functions that are key to initializing and running
the simulator: initSignals, initM5Python, m5Main.
The original code for creating libm5 was inspired by a patch Michael
Adler, though the code here was done by me.
2008-08-04 03:19:54 +02:00
|
|
|
# First make a library of everything but main() so other programs can
|
|
|
|
# link against m5.
|
2009-01-19 18:03:41 +01:00
|
|
|
static_lib = new_env.StaticLibrary(libname, static_objs)
|
|
|
|
shared_lib = new_env.SharedLibrary(libname, shared_objs)
|
libm5: Create a libm5 static library for embedding m5.
This should allow m5 to be more easily embedded into other simulators.
The m5 binary adds a simple main function which then calls into the m5
libarary to start the simulation. In order to make this work
correctly, it was necessary embed python code directly into the
library instead of the zipfile hack. This is because you can't just
append the zipfile to the end of a library the way you can a binary.
As a result, Python files that are part of the m5 simulator are now
compile, marshalled, compressed, and then inserted into the library's
data section with a certain symbol name. Additionally, a new Importer
was needed to allow python to get at the embedded python code.
Small additional changes include:
- Get rid of the PYTHONHOME stuff since I don't think anyone ever used
it, and it just confuses things. Easy enough to add back if I'm wrong.
- Create a few new functions that are key to initializing and running
the simulator: initSignals, initM5Python, m5Main.
The original code for creating libm5 was inspired by a patch Michael
Adler, though the code here was done by me.
2008-08-04 03:19:54 +02:00
|
|
|
|
2008-10-09 13:58:23 +02:00
|
|
|
# Now link a stub with main() and the static library.
|
2011-04-15 19:44:44 +02:00
|
|
|
main_objs = [ make_obj(s, True) for s in Source.get(main=True) ]
|
|
|
|
|
2011-04-15 19:45:11 +02:00
|
|
|
for test in UnitTest.all:
|
|
|
|
flags = { test.target : True }
|
|
|
|
test_sources = Source.get(**flags)
|
|
|
|
test_objs = [ make_obj(s, static=True) for s in test_sources ]
|
2012-05-11 01:04:28 +02:00
|
|
|
if test.main:
|
|
|
|
test_objs += main_objs
|
arch: teach ISA parser how to split code across files
This patch encompasses several interrelated and interdependent changes
to the ISA generation step. The end goal is to reduce the size of the
generated compilation units for instruction execution and decoding so
that batch compilation can proceed with all CPUs active without
exhausting physical memory.
The ISA parser (src/arch/isa_parser.py) has been improved so that it can
accept 'split [output_type];' directives at the top level of the grammar
and 'split(output_type)' python calls within 'exec {{ ... }}' blocks.
This has the effect of "splitting" the files into smaller compilation
units. I use air-quotes around "splitting" because the files themselves
are not split, but preprocessing directives are inserted to have the same
effect.
Architecturally, the ISA parser has had some changes in how it works.
In general, it emits code sooner. It doesn't generate per-CPU files,
and instead defers to the C preprocessor to create the duplicate copies
for each CPU type. Likewise there are more files emitted and the C
preprocessor does more substitution that used to be done by the ISA parser.
Finally, the build system (SCons) needs to be able to cope with a
dynamic list of source files coming out of the ISA parser. The changes
to the SCons{cript,truct} files support this. In broad strokes, the
targets requested on the command line are hidden from SCons until all
the build dependencies are determined, otherwise it would try, realize
it can't reach the goal, and terminate in failure. Since build steps
(i.e. running the ISA parser) must be taken to determine the file list,
several new build stages have been inserted at the very start of the
build. First, the build dependencies from the ISA parser will be emitted
to arch/$ISA/generated/inc.d, which is then read by a new SCons builder
to finalize the dependencies. (Once inc.d exists, the ISA parser will not
need to be run to complete this step.) Once the dependencies are known,
the 'Environments' are made by the makeEnv() function. This function used
to be called before the build began but now happens during the build.
It is easy to see that this step is quite slow; this is a known issue
and it's important to realize that it was already slow, but there was
no obvious cause to attribute it to since nothing was displayed to the
terminal. Since new steps that used to be performed serially are now in a
potentially-parallel build phase, the pathname handling in the SCons scripts
has been tightened up to deal with chdir() race conditions. In general,
pathnames are computed earlier and more likely to be stored, passed around,
and processed as absolute paths rather than relative paths. In the end,
some of these issues had to be fixed by inserting serializing dependencies
in the build.
Minor note:
For the null ISA, we just provide a dummy inc.d so SCons is never
compelled to try to generate it. While it seems slightly wrong to have
anything in src/arch/*/generated (i.e. a non-generated 'generated' file),
it's by far the simplest solution.
2014-05-10 00:58:47 +02:00
|
|
|
path = variant('unittest/%s.%s' % (test.target, label))
|
|
|
|
new_env.Program(path, test_objs + static_objs)
|
2011-04-15 19:45:11 +02:00
|
|
|
|
2009-05-05 01:58:24 +02:00
|
|
|
progname = exename
|
|
|
|
if strip:
|
|
|
|
progname += '.unstripped'
|
|
|
|
|
2011-04-15 19:44:44 +02:00
|
|
|
targets = new_env.Program(progname, main_objs + static_objs)
|
2009-05-05 01:58:24 +02:00
|
|
|
|
2006-05-30 19:11:34 +02:00
|
|
|
if strip:
|
2007-02-01 00:32:27 +01:00
|
|
|
if sys.platform == 'sunos5':
|
2007-06-20 17:12:10 +02:00
|
|
|
cmd = 'cp $SOURCE $TARGET; strip $TARGET'
|
2007-02-01 00:32:27 +01:00
|
|
|
else:
|
2007-06-20 17:12:10 +02:00
|
|
|
cmd = 'strip $SOURCE -o $TARGET'
|
2010-11-15 21:04:04 +01:00
|
|
|
targets = new_env.Command(exename, progname,
|
2011-01-08 06:50:13 +01:00
|
|
|
MakeAction(cmd, Transform("STRIP")))
|
2011-06-03 02:36:18 +02:00
|
|
|
|
|
|
|
new_env.Command(secondary_exename, exename,
|
|
|
|
MakeAction('ln $SOURCE $TARGET', Transform("HARDLINK")))
|
|
|
|
|
2008-10-09 13:58:23 +02:00
|
|
|
new_env.M5Binary = targets[0]
|
arch: teach ISA parser how to split code across files
This patch encompasses several interrelated and interdependent changes
to the ISA generation step. The end goal is to reduce the size of the
generated compilation units for instruction execution and decoding so
that batch compilation can proceed with all CPUs active without
exhausting physical memory.
The ISA parser (src/arch/isa_parser.py) has been improved so that it can
accept 'split [output_type];' directives at the top level of the grammar
and 'split(output_type)' python calls within 'exec {{ ... }}' blocks.
This has the effect of "splitting" the files into smaller compilation
units. I use air-quotes around "splitting" because the files themselves
are not split, but preprocessing directives are inserted to have the same
effect.
Architecturally, the ISA parser has had some changes in how it works.
In general, it emits code sooner. It doesn't generate per-CPU files,
and instead defers to the C preprocessor to create the duplicate copies
for each CPU type. Likewise there are more files emitted and the C
preprocessor does more substitution that used to be done by the ISA parser.
Finally, the build system (SCons) needs to be able to cope with a
dynamic list of source files coming out of the ISA parser. The changes
to the SCons{cript,truct} files support this. In broad strokes, the
targets requested on the command line are hidden from SCons until all
the build dependencies are determined, otherwise it would try, realize
it can't reach the goal, and terminate in failure. Since build steps
(i.e. running the ISA parser) must be taken to determine the file list,
several new build stages have been inserted at the very start of the
build. First, the build dependencies from the ISA parser will be emitted
to arch/$ISA/generated/inc.d, which is then read by a new SCons builder
to finalize the dependencies. (Once inc.d exists, the ISA parser will not
need to be run to complete this step.) Once the dependencies are known,
the 'Environments' are made by the makeEnv() function. This function used
to be called before the build began but now happens during the build.
It is easy to see that this step is quite slow; this is a known issue
and it's important to realize that it was already slow, but there was
no obvious cause to attribute it to since nothing was displayed to the
terminal. Since new steps that used to be performed serially are now in a
potentially-parallel build phase, the pathname handling in the SCons scripts
has been tightened up to deal with chdir() race conditions. In general,
pathnames are computed earlier and more likely to be stored, passed around,
and processed as absolute paths rather than relative paths. In the end,
some of these issues had to be fixed by inserting serializing dependencies
in the build.
Minor note:
For the null ISA, we just provide a dummy inc.d so SCons is never
compelled to try to generate it. While it seems slightly wrong to have
anything in src/arch/*/generated (i.e. a non-generated 'generated' file),
it's by far the simplest solution.
2014-05-10 00:58:47 +02:00
|
|
|
return new_env
|
2006-05-30 19:11:34 +02:00
|
|
|
|
2012-09-14 18:13:20 +02:00
|
|
|
# Start out with the compiler flags common to all compilers,
|
|
|
|
# i.e. they all use -g for opt and -g -pg for prof
|
2012-09-14 18:13:21 +02:00
|
|
|
ccflags = {'debug' : [], 'opt' : ['-g'], 'fast' : [], 'prof' : ['-g', '-pg'],
|
|
|
|
'perf' : ['-g']}
|
2012-09-14 18:13:20 +02:00
|
|
|
|
2012-09-14 18:13:21 +02:00
|
|
|
# Start out with the linker flags common to all linkers, i.e. -pg for
|
|
|
|
# prof, and -lprofiler for perf. The -lprofile flag is surrounded by
|
|
|
|
# no-as-needed and as-needed as the binutils linker is too clever and
|
|
|
|
# simply doesn't link to the library otherwise.
|
|
|
|
ldflags = {'debug' : [], 'opt' : [], 'fast' : [], 'prof' : ['-pg'],
|
|
|
|
'perf' : ['-Wl,--no-as-needed', '-lprofiler', '-Wl,--as-needed']}
|
2012-09-14 18:13:20 +02:00
|
|
|
|
gcc: Enable Link-Time Optimization for gcc >= 4.6
This patch adds Link-Time Optimization when building the fast target
using gcc >= 4.6, and adds a scons flag to disable it (-no-lto). No
check is performed to guarantee that the linker supports LTO and use
of the linker plugin, so the user has to ensure that binutils GNU ld
>= 2.21 or the gold linker is available. Typically, if gcc >= 4.6 is
available, the latter should not be a problem. Currently the LTO
option is only useful for gcc >= 4.6, due to the limited support on
clang and earlier versions of gcc. The intention is to also add
support for clang once the LTO integration matures.
The same number of jobs is used for the parallel phase of LTO as the
jobs specified on the scons command line, using the -flto=n flag that
was introduced with gcc 4.6. The gold linker also supports concurrent
and incremental linking, but this is not used at this point.
The compilation and linking time is increased by almost 50% on
average, although ARM seems to be particularly demanding with an
increase of almost 100%. Also beware when using this as gcc uses a
tremendous amount of memory and temp space in the process. You have
been warned.
After some careful consideration, and plenty discussions, the flag is
only added to the fast target, and the warning that was issued in an
earlier version of this patch is now removed. Similarly, the flag used
to enable LTO, now the default is to use it, and the flag has been
modified to disable LTO. The rationale behind this decision is that
opt is used for development, whereas fast is only used for long runs,
e.g. regressions or more elaborate experiments where the additional
compile and link time is amortized by a much larger run time.
When it comes to the return on investment, the regression seems to be
roughly 15% faster with LTO. For a bit more detail, I ran twolf on
ARM.fast, with three repeated runs, and they all finish within 42
minutes (+- 25 seconds) without LTO and 31 minutes (+- 25 seconds)
with LTO, i.e. LTO gives an impressive >25% speed-up for this case.
Without LTO (ARM.fast twolf)
real 42m37.632s
user 42m34.448s
sys 0m0.390s
real 41m51.793s
user 41m50.384s
sys 0m0.131s
real 41m45.491s
user 41m39.791s
sys 0m0.139s
With LTO (ARM.fast twolf)
real 30m33.588s
user 30m5.701s
sys 0m0.141s
real 31m27.791s
user 31m24.674s
sys 0m0.111s
real 31m25.500s
user 31m16.731s
sys 0m0.106s
2012-09-14 18:13:22 +02:00
|
|
|
# For Link Time Optimization, the optimisation flags used to compile
|
|
|
|
# individual files are decoupled from those used at link time
|
|
|
|
# (i.e. you can compile with -O3 and perform LTO with -O0), so we need
|
|
|
|
# to also update the linker flags based on the target.
|
clang/gcc: Fix compilation issues with clang 3.0 and gcc 4.6
This patch addresses a number of minor issues that cause problems when
compiling with clang >= 3.0 and gcc >= 4.6. Most importantly, it
avoids using the deprecated ext/hash_map and instead uses
unordered_map (and similarly so for the hash_set). To make use of the
new STL containers, g++ and clang has to be invoked with "-std=c++0x",
and this is now added for all gcc versions >= 4.6, and for clang >=
3.0. For gcc >= 4.3 and <= 4.5 and clang <= 3.0 we use the tr1
unordered_map to avoid the deprecation warning.
The addition of c++0x in turn causes a few problems, as the
compiler is more stringent and adds a number of new warnings. Below,
the most important issues are enumerated:
1) the use of namespaces is more strict, e.g. for isnan, and all
headers opening the entire namespace std are now fixed.
2) another other issue caused by the more stringent compiler is the
narrowing of the embedded python, which used to be a char array,
and is now unsigned char since there were values larger than 128.
3) a particularly odd issue that arose with the new c++0x behaviour is
found in range.hh, where the operator< causes gcc to complain about
the template type parsing (the "<" is interpreted as the beginning
of a template argument), and the problem seems to be related to the
begin/end members introduced for the range-type iteration, which is
a new feature in c++11.
As a minor update, this patch also fixes the build flags for the clang
debug target that used to be shared with gcc and incorrectly use
"-ggdb".
2012-04-14 11:43:31 +02:00
|
|
|
if env['GCC']:
|
2007-01-27 00:48:51 +01:00
|
|
|
if sys.platform == 'sunos5':
|
2012-09-14 18:13:20 +02:00
|
|
|
ccflags['debug'] += ['-gstabs+']
|
2007-01-27 00:48:51 +01:00
|
|
|
else:
|
2012-09-14 18:13:20 +02:00
|
|
|
ccflags['debug'] += ['-ggdb3']
|
|
|
|
ldflags['debug'] += ['-O0']
|
gcc: Enable Link-Time Optimization for gcc >= 4.6
This patch adds Link-Time Optimization when building the fast target
using gcc >= 4.6, and adds a scons flag to disable it (-no-lto). No
check is performed to guarantee that the linker supports LTO and use
of the linker plugin, so the user has to ensure that binutils GNU ld
>= 2.21 or the gold linker is available. Typically, if gcc >= 4.6 is
available, the latter should not be a problem. Currently the LTO
option is only useful for gcc >= 4.6, due to the limited support on
clang and earlier versions of gcc. The intention is to also add
support for clang once the LTO integration matures.
The same number of jobs is used for the parallel phase of LTO as the
jobs specified on the scons command line, using the -flto=n flag that
was introduced with gcc 4.6. The gold linker also supports concurrent
and incremental linking, but this is not used at this point.
The compilation and linking time is increased by almost 50% on
average, although ARM seems to be particularly demanding with an
increase of almost 100%. Also beware when using this as gcc uses a
tremendous amount of memory and temp space in the process. You have
been warned.
After some careful consideration, and plenty discussions, the flag is
only added to the fast target, and the warning that was issued in an
earlier version of this patch is now removed. Similarly, the flag used
to enable LTO, now the default is to use it, and the flag has been
modified to disable LTO. The rationale behind this decision is that
opt is used for development, whereas fast is only used for long runs,
e.g. regressions or more elaborate experiments where the additional
compile and link time is amortized by a much larger run time.
When it comes to the return on investment, the regression seems to be
roughly 15% faster with LTO. For a bit more detail, I ran twolf on
ARM.fast, with three repeated runs, and they all finish within 42
minutes (+- 25 seconds) without LTO and 31 minutes (+- 25 seconds)
with LTO, i.e. LTO gives an impressive >25% speed-up for this case.
Without LTO (ARM.fast twolf)
real 42m37.632s
user 42m34.448s
sys 0m0.390s
real 41m51.793s
user 41m50.384s
sys 0m0.131s
real 41m45.491s
user 41m39.791s
sys 0m0.139s
With LTO (ARM.fast twolf)
real 30m33.588s
user 30m5.701s
sys 0m0.141s
real 31m27.791s
user 31m24.674s
sys 0m0.111s
real 31m25.500s
user 31m16.731s
sys 0m0.106s
2012-09-14 18:13:22 +02:00
|
|
|
# opt, fast, prof and perf all share the same cc flags, also add
|
|
|
|
# the optimization to the ldflags as LTO defers the optimization
|
|
|
|
# to link time
|
2012-09-14 18:13:21 +02:00
|
|
|
for target in ['opt', 'fast', 'prof', 'perf']:
|
2012-09-14 18:13:20 +02:00
|
|
|
ccflags[target] += ['-O3']
|
gcc: Enable Link-Time Optimization for gcc >= 4.6
This patch adds Link-Time Optimization when building the fast target
using gcc >= 4.6, and adds a scons flag to disable it (-no-lto). No
check is performed to guarantee that the linker supports LTO and use
of the linker plugin, so the user has to ensure that binutils GNU ld
>= 2.21 or the gold linker is available. Typically, if gcc >= 4.6 is
available, the latter should not be a problem. Currently the LTO
option is only useful for gcc >= 4.6, due to the limited support on
clang and earlier versions of gcc. The intention is to also add
support for clang once the LTO integration matures.
The same number of jobs is used for the parallel phase of LTO as the
jobs specified on the scons command line, using the -flto=n flag that
was introduced with gcc 4.6. The gold linker also supports concurrent
and incremental linking, but this is not used at this point.
The compilation and linking time is increased by almost 50% on
average, although ARM seems to be particularly demanding with an
increase of almost 100%. Also beware when using this as gcc uses a
tremendous amount of memory and temp space in the process. You have
been warned.
After some careful consideration, and plenty discussions, the flag is
only added to the fast target, and the warning that was issued in an
earlier version of this patch is now removed. Similarly, the flag used
to enable LTO, now the default is to use it, and the flag has been
modified to disable LTO. The rationale behind this decision is that
opt is used for development, whereas fast is only used for long runs,
e.g. regressions or more elaborate experiments where the additional
compile and link time is amortized by a much larger run time.
When it comes to the return on investment, the regression seems to be
roughly 15% faster with LTO. For a bit more detail, I ran twolf on
ARM.fast, with three repeated runs, and they all finish within 42
minutes (+- 25 seconds) without LTO and 31 minutes (+- 25 seconds)
with LTO, i.e. LTO gives an impressive >25% speed-up for this case.
Without LTO (ARM.fast twolf)
real 42m37.632s
user 42m34.448s
sys 0m0.390s
real 41m51.793s
user 41m50.384s
sys 0m0.131s
real 41m45.491s
user 41m39.791s
sys 0m0.139s
With LTO (ARM.fast twolf)
real 30m33.588s
user 30m5.701s
sys 0m0.141s
real 31m27.791s
user 31m24.674s
sys 0m0.111s
real 31m25.500s
user 31m16.731s
sys 0m0.106s
2012-09-14 18:13:22 +02:00
|
|
|
ldflags[target] += ['-O3']
|
|
|
|
|
|
|
|
ccflags['fast'] += env['LTO_CCFLAGS']
|
|
|
|
ldflags['fast'] += env['LTO_LDFLAGS']
|
clang/gcc: Fix compilation issues with clang 3.0 and gcc 4.6
This patch addresses a number of minor issues that cause problems when
compiling with clang >= 3.0 and gcc >= 4.6. Most importantly, it
avoids using the deprecated ext/hash_map and instead uses
unordered_map (and similarly so for the hash_set). To make use of the
new STL containers, g++ and clang has to be invoked with "-std=c++0x",
and this is now added for all gcc versions >= 4.6, and for clang >=
3.0. For gcc >= 4.3 and <= 4.5 and clang <= 3.0 we use the tr1
unordered_map to avoid the deprecation warning.
The addition of c++0x in turn causes a few problems, as the
compiler is more stringent and adds a number of new warnings. Below,
the most important issues are enumerated:
1) the use of namespaces is more strict, e.g. for isnan, and all
headers opening the entire namespace std are now fixed.
2) another other issue caused by the more stringent compiler is the
narrowing of the embedded python, which used to be a char array,
and is now unsigned char since there were values larger than 128.
3) a particularly odd issue that arose with the new c++0x behaviour is
found in range.hh, where the operator< causes gcc to complain about
the template type parsing (the "<" is interpreted as the beginning
of a template argument), and the problem seems to be related to the
begin/end members introduced for the range-type iteration, which is
a new feature in c++11.
As a minor update, this patch also fixes the build flags for the clang
debug target that used to be shared with gcc and incorrectly use
"-ggdb".
2012-04-14 11:43:31 +02:00
|
|
|
elif env['CLANG']:
|
2012-09-14 18:13:20 +02:00
|
|
|
ccflags['debug'] += ['-g', '-O0']
|
2012-09-14 18:13:21 +02:00
|
|
|
# opt, fast, prof and perf all share the same cc flags
|
|
|
|
for target in ['opt', 'fast', 'prof', 'perf']:
|
|
|
|
ccflags[target] += ['-O3']
|
2006-11-08 21:05:54 +01:00
|
|
|
else:
|
2007-01-27 00:48:51 +01:00
|
|
|
print 'Unknown compiler, please fix compiler options'
|
2007-07-24 06:51:38 +02:00
|
|
|
Exit(1)
|
2006-11-08 21:05:54 +01:00
|
|
|
|
2012-03-07 04:07:41 +01:00
|
|
|
|
|
|
|
# To speed things up, we only instantiate the build environments we
|
|
|
|
# need. We try to identify the needed environment for each target; if
|
|
|
|
# we can't, we fall back on instantiating all the environments just to
|
|
|
|
# be safe.
|
2012-09-14 18:13:21 +02:00
|
|
|
target_types = ['debug', 'opt', 'fast', 'prof', 'perf']
|
|
|
|
obj2target = {'do': 'debug', 'o': 'opt', 'fo': 'fast', 'po': 'prof',
|
|
|
|
'gpo' : 'perf'}
|
2012-03-07 04:07:41 +01:00
|
|
|
|
|
|
|
def identifyTarget(t):
|
|
|
|
ext = t.split('.')[-1]
|
|
|
|
if ext in target_types:
|
|
|
|
return ext
|
|
|
|
if obj2target.has_key(ext):
|
|
|
|
return obj2target[ext]
|
|
|
|
match = re.search(r'/tests/([^/]+)/', t)
|
|
|
|
if match and match.group(1) in target_types:
|
|
|
|
return match.group(1)
|
|
|
|
return 'all'
|
|
|
|
|
|
|
|
needed_envs = [identifyTarget(target) for target in BUILD_TARGETS]
|
|
|
|
if 'all' in needed_envs:
|
|
|
|
needed_envs += target_types
|
|
|
|
|
arch: teach ISA parser how to split code across files
This patch encompasses several interrelated and interdependent changes
to the ISA generation step. The end goal is to reduce the size of the
generated compilation units for instruction execution and decoding so
that batch compilation can proceed with all CPUs active without
exhausting physical memory.
The ISA parser (src/arch/isa_parser.py) has been improved so that it can
accept 'split [output_type];' directives at the top level of the grammar
and 'split(output_type)' python calls within 'exec {{ ... }}' blocks.
This has the effect of "splitting" the files into smaller compilation
units. I use air-quotes around "splitting" because the files themselves
are not split, but preprocessing directives are inserted to have the same
effect.
Architecturally, the ISA parser has had some changes in how it works.
In general, it emits code sooner. It doesn't generate per-CPU files,
and instead defers to the C preprocessor to create the duplicate copies
for each CPU type. Likewise there are more files emitted and the C
preprocessor does more substitution that used to be done by the ISA parser.
Finally, the build system (SCons) needs to be able to cope with a
dynamic list of source files coming out of the ISA parser. The changes
to the SCons{cript,truct} files support this. In broad strokes, the
targets requested on the command line are hidden from SCons until all
the build dependencies are determined, otherwise it would try, realize
it can't reach the goal, and terminate in failure. Since build steps
(i.e. running the ISA parser) must be taken to determine the file list,
several new build stages have been inserted at the very start of the
build. First, the build dependencies from the ISA parser will be emitted
to arch/$ISA/generated/inc.d, which is then read by a new SCons builder
to finalize the dependencies. (Once inc.d exists, the ISA parser will not
need to be run to complete this step.) Once the dependencies are known,
the 'Environments' are made by the makeEnv() function. This function used
to be called before the build began but now happens during the build.
It is easy to see that this step is quite slow; this is a known issue
and it's important to realize that it was already slow, but there was
no obvious cause to attribute it to since nothing was displayed to the
terminal. Since new steps that used to be performed serially are now in a
potentially-parallel build phase, the pathname handling in the SCons scripts
has been tightened up to deal with chdir() race conditions. In general,
pathnames are computed earlier and more likely to be stored, passed around,
and processed as absolute paths rather than relative paths. In the end,
some of these issues had to be fixed by inserting serializing dependencies
in the build.
Minor note:
For the null ISA, we just provide a dummy inc.d so SCons is never
compelled to try to generate it. While it seems slightly wrong to have
anything in src/arch/*/generated (i.e. a non-generated 'generated' file),
it's by far the simplest solution.
2014-05-10 00:58:47 +02:00
|
|
|
def makeEnvirons(target, source, env):
|
|
|
|
# cause any later Source() calls to be fatal, as a diagnostic.
|
|
|
|
Source.done()
|
|
|
|
|
|
|
|
envList = []
|
|
|
|
|
|
|
|
# Debug binary
|
|
|
|
if 'debug' in needed_envs:
|
|
|
|
envList.append(
|
|
|
|
makeEnv(env, 'debug', '.do',
|
|
|
|
CCFLAGS = Split(ccflags['debug']),
|
|
|
|
CPPDEFINES = ['DEBUG', 'TRACING_ON=1'],
|
|
|
|
LINKFLAGS = Split(ldflags['debug'])))
|
|
|
|
|
|
|
|
# Optimized binary
|
|
|
|
if 'opt' in needed_envs:
|
|
|
|
envList.append(
|
|
|
|
makeEnv(env, 'opt', '.o',
|
|
|
|
CCFLAGS = Split(ccflags['opt']),
|
|
|
|
CPPDEFINES = ['TRACING_ON=1'],
|
|
|
|
LINKFLAGS = Split(ldflags['opt'])))
|
|
|
|
|
|
|
|
# "Fast" binary
|
|
|
|
if 'fast' in needed_envs:
|
|
|
|
envList.append(
|
|
|
|
makeEnv(env, 'fast', '.fo', strip = True,
|
|
|
|
CCFLAGS = Split(ccflags['fast']),
|
|
|
|
CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'],
|
|
|
|
LINKFLAGS = Split(ldflags['fast'])))
|
|
|
|
|
|
|
|
# Profiled binary using gprof
|
|
|
|
if 'prof' in needed_envs:
|
|
|
|
envList.append(
|
|
|
|
makeEnv(env, 'prof', '.po',
|
|
|
|
CCFLAGS = Split(ccflags['prof']),
|
|
|
|
CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'],
|
|
|
|
LINKFLAGS = Split(ldflags['prof'])))
|
|
|
|
|
|
|
|
# Profiled binary using google-pprof
|
|
|
|
if 'perf' in needed_envs:
|
|
|
|
envList.append(
|
|
|
|
makeEnv(env, 'perf', '.gpo',
|
|
|
|
CCFLAGS = Split(ccflags['perf']),
|
|
|
|
CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'],
|
|
|
|
LINKFLAGS = Split(ldflags['perf'])))
|
|
|
|
|
|
|
|
# Set up the regression tests for each build.
|
|
|
|
for e in envList:
|
2016-03-14 01:47:33 +01:00
|
|
|
SConscript(os.path.join(env.root.abspath, 'tests', 'SConscript'),
|
arch: teach ISA parser how to split code across files
This patch encompasses several interrelated and interdependent changes
to the ISA generation step. The end goal is to reduce the size of the
generated compilation units for instruction execution and decoding so
that batch compilation can proceed with all CPUs active without
exhausting physical memory.
The ISA parser (src/arch/isa_parser.py) has been improved so that it can
accept 'split [output_type];' directives at the top level of the grammar
and 'split(output_type)' python calls within 'exec {{ ... }}' blocks.
This has the effect of "splitting" the files into smaller compilation
units. I use air-quotes around "splitting" because the files themselves
are not split, but preprocessing directives are inserted to have the same
effect.
Architecturally, the ISA parser has had some changes in how it works.
In general, it emits code sooner. It doesn't generate per-CPU files,
and instead defers to the C preprocessor to create the duplicate copies
for each CPU type. Likewise there are more files emitted and the C
preprocessor does more substitution that used to be done by the ISA parser.
Finally, the build system (SCons) needs to be able to cope with a
dynamic list of source files coming out of the ISA parser. The changes
to the SCons{cript,truct} files support this. In broad strokes, the
targets requested on the command line are hidden from SCons until all
the build dependencies are determined, otherwise it would try, realize
it can't reach the goal, and terminate in failure. Since build steps
(i.e. running the ISA parser) must be taken to determine the file list,
several new build stages have been inserted at the very start of the
build. First, the build dependencies from the ISA parser will be emitted
to arch/$ISA/generated/inc.d, which is then read by a new SCons builder
to finalize the dependencies. (Once inc.d exists, the ISA parser will not
need to be run to complete this step.) Once the dependencies are known,
the 'Environments' are made by the makeEnv() function. This function used
to be called before the build began but now happens during the build.
It is easy to see that this step is quite slow; this is a known issue
and it's important to realize that it was already slow, but there was
no obvious cause to attribute it to since nothing was displayed to the
terminal. Since new steps that used to be performed serially are now in a
potentially-parallel build phase, the pathname handling in the SCons scripts
has been tightened up to deal with chdir() race conditions. In general,
pathnames are computed earlier and more likely to be stored, passed around,
and processed as absolute paths rather than relative paths. In the end,
some of these issues had to be fixed by inserting serializing dependencies
in the build.
Minor note:
For the null ISA, we just provide a dummy inc.d so SCons is never
compelled to try to generate it. While it seems slightly wrong to have
anything in src/arch/*/generated (i.e. a non-generated 'generated' file),
it's by far the simplest solution.
2014-05-10 00:58:47 +02:00
|
|
|
variant_dir = variantd('tests', e.Label),
|
|
|
|
exports = { 'env' : e }, duplicate = False)
|
|
|
|
|
|
|
|
# The MakeEnvirons Builder defers the full dependency collection until
|
|
|
|
# after processing the ISA definition (due to dynamically generated
|
|
|
|
# source files). Add this dependency to all targets so they will wait
|
|
|
|
# until the environments are completely set up. Otherwise, a second
|
|
|
|
# process (e.g. -j2 or higher) will try to compile the requested target,
|
|
|
|
# not know how, and fail.
|
|
|
|
env.Append(BUILDERS = {'MakeEnvirons' :
|
|
|
|
Builder(action=MakeAction(makeEnvirons,
|
|
|
|
Transform("ENVIRONS", 1)))})
|
|
|
|
|
|
|
|
isa_target = env['PHONY_BASE'] + '-deps'
|
|
|
|
environs = env['PHONY_BASE'] + '-environs'
|
|
|
|
env.Depends('#all-deps', isa_target)
|
|
|
|
env.Depends('#all-environs', environs)
|
|
|
|
env.ScanISA(isa_target, File('arch/%s/generated/inc.d' % env['TARGET_ISA']))
|
|
|
|
envSetup = env.MakeEnvirons(environs, isa_target)
|
|
|
|
|
|
|
|
# make sure no -deps targets occur before all ISAs are complete
|
|
|
|
env.Depends(isa_target, '#all-isas')
|
|
|
|
# likewise for -environs targets and all the -deps targets
|
|
|
|
env.Depends(environs, '#all-deps')
|