SConscript (6108:66014cd0dc61) SConscript (6143:010490fd482a)
1# -*- mode:python -*-
2
3# Copyright (c) 2004-2005 The Regents of The University of Michigan
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions are
8# met: redistributions of source code must retain the above copyright

--- 15 unchanged lines hidden (view full) ---

24# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28#
29# Authors: Nathan Binkert
30
31import array
1# -*- mode:python -*-
2
3# Copyright (c) 2004-2005 The Regents of The University of Michigan
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions are
8# met: redistributions of source code must retain the above copyright

--- 15 unchanged lines hidden (view full) ---

24# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28#
29# Authors: Nathan Binkert
30
31import array
32import bisect
32import imp
33import marshal
34import os
35import re
36import sys
37import zlib
38
39from os.path import basename, dirname, exists, isdir, isfile, join as joinpath

--- 5 unchanged lines hidden (view full) ---

45
46Import('*')
47
48# Children need to see the environment
49Export('env')
50
51build_env = dict([(opt, env[opt]) for opt in export_vars])
52
33import imp
34import marshal
35import os
36import re
37import sys
38import zlib
39
40from os.path import basename, dirname, exists, isdir, isfile, join as joinpath

--- 5 unchanged lines hidden (view full) ---

46
47Import('*')
48
49# Children need to see the environment
50Export('env')
51
52build_env = dict([(opt, env[opt]) for opt in export_vars])
53
53def sort_list(_list):
54 """return a sorted copy of '_list'"""
55 if isinstance(_list, list):
56 _list = _list[:]
57 else:
58 _list = list(_list)
59 _list.sort()
60 return _list
54########################################################################
55# Code for adding source files of various types
56#
57class SourceMeta(type):
58 def __init__(cls, name, bases, dict):
59 super(SourceMeta, cls).__init__(name, bases, dict)
60 cls.all = []
61
62 def get(cls, **kwargs):
63 for src in cls.all:
64 for attr,value in kwargs.iteritems():
65 if getattr(src, attr) != value:
66 break
67 else:
68 yield src
61
69
62class PySourceFile(object):
70class SourceFile(object):
71 __metaclass__ = SourceMeta
72 def __init__(self, source):
73 tnode = source
74 if not isinstance(source, SCons.Node.FS.File):
75 tnode = File(source)
76
77 self.tnode = tnode
78 self.snode = tnode.srcnode()
79 self.filename = str(tnode)
80 self.dirname = dirname(self.filename)
81 self.basename = basename(self.filename)
82 index = self.basename.rfind('.')
83 if index <= 0:
84 # dot files aren't extensions
85 self.extname = self.basename, None
86 else:
87 self.extname = self.basename[:index], self.basename[index+1:]
88
89 for base in type(self).__mro__:
90 if issubclass(base, SourceFile):
91 bisect.insort_right(base.all, self)
92
93 def __lt__(self, other): return self.filename < other.filename
94 def __le__(self, other): return self.filename <= other.filename
95 def __gt__(self, other): return self.filename > other.filename
96 def __ge__(self, other): return self.filename >= other.filename
97 def __eq__(self, other): return self.filename == other.filename
98 def __ne__(self, other): return self.filename != other.filename
99
100class Source(SourceFile):
101 '''Add a c/c++ source file to the build'''
102 def __init__(self, source, Werror=True, swig=False, bin_only=False,
103 skip_lib=False):
104 super(Source, self).__init__(source)
105
106 self.Werror = Werror
107 self.swig = swig
108 self.bin_only = bin_only
109 self.skip_lib = bin_only or skip_lib
110
111class PySource(SourceFile):
112 '''Add a python source file to the named package'''
63 invalid_sym_char = re.compile('[^A-z0-9_]')
113 invalid_sym_char = re.compile('[^A-z0-9_]')
64 def __init__(self, package, tnode):
65 snode = tnode.srcnode()
66 filename = str(tnode)
67 pyname = basename(filename)
68 assert pyname.endswith('.py')
69 name = pyname[:-3]
114 modules = {}
115 tnodes = {}
116 symnames = {}
117
118 def __init__(self, package, source):
119 super(PySource, self).__init__(source)
120
121 modname,ext = self.extname
122 assert ext == 'py'
123
70 if package:
71 path = package.split('.')
72 else:
73 path = []
74
75 modpath = path[:]
124 if package:
125 path = package.split('.')
126 else:
127 path = []
128
129 modpath = path[:]
76 if name != '__init__':
77 modpath += [name]
130 if modname != '__init__':
131 modpath += [ modname ]
78 modpath = '.'.join(modpath)
79
132 modpath = '.'.join(modpath)
133
80 arcpath = path + [ pyname ]
81 arcname = joinpath(*arcpath)
82
83 debugname = snode.abspath
134 arcpath = path + [ self.basename ]
135 debugname = self.snode.abspath
84 if not exists(debugname):
136 if not exists(debugname):
85 debugname = tnode.abspath
137 debugname = self.tnode.abspath
86
138
87 self.tnode = tnode
88 self.snode = snode
89 self.pyname = pyname
90 self.package = package
139 self.package = package
140 self.modname = modname
91 self.modpath = modpath
141 self.modpath = modpath
92 self.arcname = arcname
142 self.arcname = joinpath(*arcpath)
93 self.debugname = debugname
143 self.debugname = debugname
94 self.compiled = File(filename + 'c')
95 self.assembly = File(filename + '.s')
96 self.symname = "PyEMB_" + self.invalid_sym_char.sub('_', modpath)
97
144 self.compiled = File(self.filename + 'c')
145 self.assembly = File(self.filename + '.s')
146 self.symname = "PyEMB_" + PySource.invalid_sym_char.sub('_', modpath)
98
147
99########################################################################
100# Code for adding source files of various types
101#
102cc_lib_sources = []
103def Source(source):
104 '''Add a source file to the libm5 build'''
105 if not isinstance(source, SCons.Node.FS.File):
106 source = File(source)
148 PySource.modules[modpath] = self
149 PySource.tnodes[self.tnode] = self
150 PySource.symnames[self.symname] = self
107
151
108 cc_lib_sources.append(source)
152class SimObject(PySource):
153 '''Add a SimObject python file as a python source object and add
154 it to a list of sim object modules'''
109
155
110cc_bin_sources = []
111def BinSource(source):
112 '''Add a source file to the m5 binary build'''
113 if not isinstance(source, SCons.Node.FS.File):
114 source = File(source)
156 fixed = False
157 modnames = []
115
158
116 cc_bin_sources.append(source)
159 def __init__(self, source):
160 super(SimObject, self).__init__('m5.objects', source)
161 if self.fixed:
162 raise AttributeError, "Too late to call SimObject now."
117
163
118py_sources = []
119def PySource(package, source):
120 '''Add a python source file to the named package'''
121 if not isinstance(source, SCons.Node.FS.File):
122 source = File(source)
164 bisect.insort_right(SimObject.modnames, self.modname)
123
165
124 source = PySourceFile(package, source)
125 py_sources.append(source)
166class SwigSource(SourceFile):
167 '''Add a swig file to build'''
126
168
127sim_objects_fixed = False
128sim_object_modfiles = set()
129def SimObject(source):
130 '''Add a SimObject python file as a python source object and add
131 it to a list of sim object modules'''
169 def __init__(self, package, source):
170 super(SwigSource, self).__init__(source)
132
171
133 if sim_objects_fixed:
134 raise AttributeError, "Too late to call SimObject now."
172 modname,ext = self.extname
173 assert ext == 'i'
135
174
136 if not isinstance(source, SCons.Node.FS.File):
137 source = File(source)
175 self.module = modname
176 cc_file = joinpath(self.dirname, modname + '_wrap.cc')
177 py_file = joinpath(self.dirname, modname + '.py')
138
178
139 PySource('m5.objects', source)
140 modfile = basename(str(source))
141 assert modfile.endswith('.py')
142 modname = modfile[:-3]
143 sim_object_modfiles.add(modname)
179 self.cc_source = Source(cc_file, swig=True)
180 self.py_source = PySource(package, py_file)
144
181
145swig_sources = []
146def SwigSource(package, source):
147 '''Add a swig file to build'''
148 if not isinstance(source, SCons.Node.FS.File):
149 source = File(source)
150 val = source,package
151 swig_sources.append(val)
152
153unit_tests = []
154def UnitTest(target, sources):
155 if not isinstance(sources, (list, tuple)):
156 sources = [ sources ]
182unit_tests = []
183def UnitTest(target, sources):
184 if not isinstance(sources, (list, tuple)):
185 sources = [ sources ]
157
158 srcs = []
159 for source in sources:
160 if not isinstance(source, SCons.Node.FS.File):
161 source = File(source)
162 srcs.append(source)
163
164 unit_tests.append((target, srcs))
165
186
187 sources = [ Source(src, skip_lib=True) for src in sources ]
188 unit_tests.append((target, sources))
189
166# Children should have access
167Export('Source')
190# Children should have access
191Export('Source')
168Export('BinSource')
169Export('PySource')
170Export('SimObject')
171Export('SwigSource')
172Export('UnitTest')
173
174########################################################################
175#
176# Trace Flags

--- 94 unchanged lines hidden (view full) ---

271 return self
272
273 if fullname == 'm5.objects':
274 return self
275
276 if fullname.startswith('m5.internal'):
277 return None
278
192Export('PySource')
193Export('SimObject')
194Export('SwigSource')
195Export('UnitTest')
196
197########################################################################
198#
199# Trace Flags

--- 94 unchanged lines hidden (view full) ---

294 return self
295
296 if fullname == 'm5.objects':
297 return self
298
299 if fullname.startswith('m5.internal'):
300 return None
301
279 if fullname in self.modules and exists(self.modules[fullname]):
302 source = self.modules.get(fullname, None)
303 if source is not None and exists(source.snode.abspath):
280 return self
281
282 return None
283
284 def load_module(self, fullname):
285 mod = imp.new_module(fullname)
286 sys.modules[fullname] = mod
287 self.installed.add(fullname)
288
289 mod.__loader__ = self
290 if fullname == 'm5.objects':
291 mod.__path__ = fullname.split('.')
292 return mod
293
294 if fullname == 'defines':
295 mod.__dict__['buildEnv'] = build_env
296 return mod
297
304 return self
305
306 return None
307
308 def load_module(self, fullname):
309 mod = imp.new_module(fullname)
310 sys.modules[fullname] = mod
311 self.installed.add(fullname)
312
313 mod.__loader__ = self
314 if fullname == 'm5.objects':
315 mod.__path__ = fullname.split('.')
316 return mod
317
318 if fullname == 'defines':
319 mod.__dict__['buildEnv'] = build_env
320 return mod
321
298 srcfile = self.modules[fullname]
299 if basename(srcfile) == '__init__.py':
300 mod.__path__ = fullname.split('.')
301 mod.__file__ = srcfile
322 source = self.modules[fullname]
323 if source.modname == '__init__':
324 mod.__path__ = source.modpath
325 mod.__file__ = source.snode.abspath
302
326
303 exec file(srcfile, 'r') in mod.__dict__
327 exec file(source.snode.abspath, 'r') in mod.__dict__
304
305 return mod
306
328
329 return mod
330
307py_modules = {}
308for source in py_sources:
309 py_modules[source.modpath] = source.snode.abspath
310
311# install the python importer so we can grab stuff from the source
312# tree itself. We can't have SimObjects added after this point or
313# else we won't know about them for the rest of the stuff.
331# install the python importer so we can grab stuff from the source
332# tree itself. We can't have SimObjects added after this point or
333# else we won't know about them for the rest of the stuff.
314sim_objects_fixed = True
315importer = DictImporter(py_modules)
334SimObject.fixed = True
335importer = DictImporter(PySource.modules)
316sys.meta_path[0:0] = [ importer ]
317
318import m5
319
320# import all sim objects so we can populate the all_objects list
321# make sure that we're working with a list, then let's sort it
336sys.meta_path[0:0] = [ importer ]
337
338import m5
339
340# import all sim objects so we can populate the all_objects list
341# make sure that we're working with a list, then let's sort it
322sim_objects = list(sim_object_modfiles)
323sim_objects.sort()
324for simobj in sim_objects:
325 exec('from m5.objects import %s' % simobj)
342for modname in SimObject.modnames:
343 exec('from m5.objects import %s' % modname)
326
327# we need to unload all of the currently imported modules so that they
328# will be re-imported the next time the sconscript is run
329importer.unload()
330sys.meta_path.remove(importer)
331
332sim_objects = m5.SimObject.allClasses
333all_enums = m5.params.allEnums
334
335all_params = {}
344
345# we need to unload all of the currently imported modules so that they
346# will be re-imported the next time the sconscript is run
347importer.unload()
348sys.meta_path.remove(importer)
349
350sim_objects = m5.SimObject.allClasses
351all_enums = m5.params.allEnums
352
353all_params = {}
336for name,obj in sim_objects.iteritems():
354for name,obj in sorted(sim_objects.iteritems()):
337 for param in obj._params.local.values():
338 if not hasattr(param, 'swig_decl'):
339 continue
340 pname = param.ptype_str
341 if pname not in all_params:
342 all_params[pname] = param
343
344########################################################################
345#
346# calculate extra dependencies
347#
348module_depends = ["m5", "m5.SimObject", "m5.params"]
355 for param in obj._params.local.values():
356 if not hasattr(param, 'swig_decl'):
357 continue
358 pname = param.ptype_str
359 if pname not in all_params:
360 all_params[pname] = param
361
362########################################################################
363#
364# calculate extra dependencies
365#
366module_depends = ["m5", "m5.SimObject", "m5.params"]
349depends = [ File(py_modules[dep]) for dep in module_depends ]
367depends = [ PySource.modules[dep].tnode for dep in module_depends ]
350
351########################################################################
352#
353# Commands for the basic automatically generated python files
354#
355
356# Generate Python file containing a dict specifying the current
357# build_env flags.

--- 29 unchanged lines hidden (view full) ---

387 print >>f, 'from params import *'
388 print >>f, 'from m5.SimObject import *'
389 for module in source:
390 print >>f, 'from %s import *' % module.get_contents()
391 f.close()
392
393# Generate an __init__.py file for the objects package
394env.Command('python/m5/objects/__init__.py',
368
369########################################################################
370#
371# Commands for the basic automatically generated python files
372#
373
374# Generate Python file containing a dict specifying the current
375# build_env flags.

--- 29 unchanged lines hidden (view full) ---

405 print >>f, 'from params import *'
406 print >>f, 'from m5.SimObject import *'
407 for module in source:
408 print >>f, 'from %s import *' % module.get_contents()
409 f.close()
410
411# Generate an __init__.py file for the objects package
412env.Command('python/m5/objects/__init__.py',
395 [ Value(o) for o in sort_list(sim_object_modfiles) ],
413 map(Value, SimObject.modnames),
396 makeObjectsInitFile)
397PySource('m5.objects', 'python/m5/objects/__init__.py')
398
399########################################################################
400#
401# Create all of the SimObject param headers and enum headers
402#
403
404def createSimObjectParam(target, source, env):
405 assert len(target) == 1 and len(source) == 1
406
407 hh_file = file(target[0].abspath, 'w')
408 name = str(source[0].get_contents())
409 obj = sim_objects[name]
410
411 print >>hh_file, obj.cxx_decl()
414 makeObjectsInitFile)
415PySource('m5.objects', 'python/m5/objects/__init__.py')
416
417########################################################################
418#
419# Create all of the SimObject param headers and enum headers
420#
421
422def createSimObjectParam(target, source, env):
423 assert len(target) == 1 and len(source) == 1
424
425 hh_file = file(target[0].abspath, 'w')
426 name = str(source[0].get_contents())
427 obj = sim_objects[name]
428
429 print >>hh_file, obj.cxx_decl()
430 hh_file.close()
412
413def createSwigParam(target, source, env):
414 assert len(target) == 1 and len(source) == 1
415
416 i_file = file(target[0].abspath, 'w')
417 name = str(source[0].get_contents())
418 param = all_params[name]
419
420 for line in param.swig_decl():
421 print >>i_file, line
431
432def createSwigParam(target, source, env):
433 assert len(target) == 1 and len(source) == 1
434
435 i_file = file(target[0].abspath, 'w')
436 name = str(source[0].get_contents())
437 param = all_params[name]
438
439 for line in param.swig_decl():
440 print >>i_file, line
441 i_file.close()
422
423def createEnumStrings(target, source, env):
424 assert len(target) == 1 and len(source) == 1
425
426 cc_file = file(target[0].abspath, 'w')
427 name = str(source[0].get_contents())
428 obj = all_enums[name]
429
430 print >>cc_file, obj.cxx_def()
431 cc_file.close()
432
433def createEnumParam(target, source, env):
434 assert len(target) == 1 and len(source) == 1
435
436 hh_file = file(target[0].abspath, 'w')
437 name = str(source[0].get_contents())
438 obj = all_enums[name]
439
440 print >>hh_file, obj.cxx_decl()
442
443def createEnumStrings(target, source, env):
444 assert len(target) == 1 and len(source) == 1
445
446 cc_file = file(target[0].abspath, 'w')
447 name = str(source[0].get_contents())
448 obj = all_enums[name]
449
450 print >>cc_file, obj.cxx_def()
451 cc_file.close()
452
453def createEnumParam(target, source, env):
454 assert len(target) == 1 and len(source) == 1
455
456 hh_file = file(target[0].abspath, 'w')
457 name = str(source[0].get_contents())
458 obj = all_enums[name]
459
460 print >>hh_file, obj.cxx_decl()
461 hh_file.close()
441
442# Generate all of the SimObject param struct header files
443params_hh_files = []
462
463# Generate all of the SimObject param struct header files
464params_hh_files = []
444for name,simobj in sim_objects.iteritems():
445 extra_deps = [ File(py_modules[simobj.__module__]) ]
465for name,simobj in sorted(sim_objects.iteritems()):
466 py_source = PySource.modules[simobj.__module__]
467 extra_deps = [ py_source.tnode ]
446
447 hh_file = File('params/%s.hh' % name)
448 params_hh_files.append(hh_file)
449 env.Command(hh_file, Value(name), createSimObjectParam)
450 env.Depends(hh_file, depends + extra_deps)
451
452# Generate any parameter header files needed
453params_i_files = []

--- 4 unchanged lines hidden (view full) ---

458 ext = 'ptype'
459
460 i_file = File('params/%s_%s.i' % (name, ext))
461 params_i_files.append(i_file)
462 env.Command(i_file, Value(name), createSwigParam)
463 env.Depends(i_file, depends)
464
465# Generate all enum header files
468
469 hh_file = File('params/%s.hh' % name)
470 params_hh_files.append(hh_file)
471 env.Command(hh_file, Value(name), createSimObjectParam)
472 env.Depends(hh_file, depends + extra_deps)
473
474# Generate any parameter header files needed
475params_i_files = []

--- 4 unchanged lines hidden (view full) ---

480 ext = 'ptype'
481
482 i_file = File('params/%s_%s.i' % (name, ext))
483 params_i_files.append(i_file)
484 env.Command(i_file, Value(name), createSwigParam)
485 env.Depends(i_file, depends)
486
487# Generate all enum header files
466for name,enum in all_enums.iteritems():
467 extra_deps = [ File(py_modules[enum.__module__]) ]
488for name,enum in sorted(all_enums.iteritems()):
489 py_source = PySource.modules[enum.__module__]
490 extra_deps = [ py_source.tnode ]
468
469 cc_file = File('enums/%s.cc' % name)
470 env.Command(cc_file, Value(name), createEnumStrings)
471 env.Depends(cc_file, depends + extra_deps)
472 Source(cc_file)
473
474 hh_file = File('enums/%s.hh' % name)
475 env.Command(hh_file, Value(name), createEnumParam)

--- 95 unchanged lines hidden (view full) ---

571
572 print >>out, code
573
574 print >>out, '%%include "src/sim/sim_object_params.hh"' % obj
575 for obj in ordered_objs:
576 print >>out, '%%include "params/%s.hh"' % obj
577
578params_file = File('params/params.i')
491
492 cc_file = File('enums/%s.cc' % name)
493 env.Command(cc_file, Value(name), createEnumStrings)
494 env.Depends(cc_file, depends + extra_deps)
495 Source(cc_file)
496
497 hh_file = File('enums/%s.hh' % name)
498 env.Command(hh_file, Value(name), createEnumParam)

--- 95 unchanged lines hidden (view full) ---

594
595 print >>out, code
596
597 print >>out, '%%include "src/sim/sim_object_params.hh"' % obj
598 for obj in ordered_objs:
599 print >>out, '%%include "params/%s.hh"' % obj
600
601params_file = File('params/params.i')
579names = sort_list(sim_objects.keys())
580env.Command(params_file, [ Value(v) for v in names ], buildParams)
602names = sorted(sim_objects.keys())
603env.Command(params_file, map(Value, names), buildParams)
581env.Depends(params_file, params_hh_files + params_i_files + depends)
582SwigSource('m5.objects', params_file)
583
584# Build all swig modules
604env.Depends(params_file, params_hh_files + params_i_files + depends)
605SwigSource('m5.objects', params_file)
606
607# Build all swig modules
585swig_modules = []
586cc_swig_sources = []
587for source,package in swig_sources:
588 filename = str(source)
589 assert filename.endswith('.i')
590
591 base = '.'.join(filename.split('.')[:-1])
592 module = basename(base)
593 cc_file = base + '_wrap.cc'
594 py_file = base + '.py'
595
596 env.Command([cc_file, py_file], source,
608for swig in SwigSource.all:
609 env.Command([swig.cc_source.tnode, swig.py_source.tnode], swig.tnode,
597 '$SWIG $SWIGFLAGS -outdir ${TARGETS[1].dir} '
598 '-o ${TARGETS[0]} $SOURCES')
610 '$SWIG $SWIGFLAGS -outdir ${TARGETS[1].dir} '
611 '-o ${TARGETS[0]} $SOURCES')
599 env.Depends(py_file, source)
600 env.Depends(cc_file, source)
612 env.Depends(swig.py_source.tnode, swig.tnode)
613 env.Depends(swig.cc_source.tnode, swig.tnode)
601
614
602 swig_modules.append(Value(module))
603 cc_swig_sources.append(File(cc_file))
604 PySource(package, py_file)
605
606# Generate the main swig init file
607def makeSwigInit(target, source, env):
608 f = file(str(target[0]), 'w')
609 print >>f, 'extern "C" {'
610 for module in source:
611 print >>f, ' void init_%s();' % module.get_contents()
612 print >>f, '}'
613 print >>f, 'void initSwig() {'
614 for module in source:
615 print >>f, ' init_%s();' % module.get_contents()
616 print >>f, '}'
617 f.close()
618
615# Generate the main swig init file
616def makeSwigInit(target, source, env):
617 f = file(str(target[0]), 'w')
618 print >>f, 'extern "C" {'
619 for module in source:
620 print >>f, ' void init_%s();' % module.get_contents()
621 print >>f, '}'
622 print >>f, 'void initSwig() {'
623 for module in source:
624 print >>f, ' init_%s();' % module.get_contents()
625 print >>f, '}'
626 f.close()
627
619env.Command('python/swig/init.cc', swig_modules, makeSwigInit)
628env.Command('python/swig/init.cc',
629 map(Value, sorted(s.module for s in SwigSource.all)),
630 makeSwigInit)
620Source('python/swig/init.cc')
621
622# Generate traceflags.py
623def traceFlagsPy(target, source, env):
624 assert(len(target) == 1)
625
626 f = file(str(target[0]), 'w')
627

--- 180 unchanged lines hidden (view full) ---

808
809/* namespace Trace */ }
810
811#endif // __BASE_TRACE_FLAGS_HH__
812'''
813
814 f.close()
815
631Source('python/swig/init.cc')
632
633# Generate traceflags.py
634def traceFlagsPy(target, source, env):
635 assert(len(target) == 1)
636
637 f = file(str(target[0]), 'w')
638

--- 180 unchanged lines hidden (view full) ---

819
820/* namespace Trace */ }
821
822#endif // __BASE_TRACE_FLAGS_HH__
823'''
824
825 f.close()
826
816flags = [ Value(f) for f in trace_flags.values() ]
827flags = map(Value, trace_flags.values())
817env.Command('base/traceflags.py', flags, traceFlagsPy)
818PySource('m5', 'base/traceflags.py')
819
820env.Command('base/traceflags.hh', flags, traceFlagsHH)
821env.Command('base/traceflags.cc', flags, traceFlagsCC)
822Source('base/traceflags.cc')
823
824# embed python files. All .py files that have been indicated by a
825# PySource() call in a SConscript need to be embedded into the M5
826# library. To do that, we compile the file to byte code, marshal the
827# byte code, compress it, and then generate an assembly file that
828# inserts the result into the data section with symbols indicating the
829# beginning, and end (and with the size at the end)
828env.Command('base/traceflags.py', flags, traceFlagsPy)
829PySource('m5', 'base/traceflags.py')
830
831env.Command('base/traceflags.hh', flags, traceFlagsHH)
832env.Command('base/traceflags.cc', flags, traceFlagsCC)
833Source('base/traceflags.cc')
834
835# embed python files. All .py files that have been indicated by a
836# PySource() call in a SConscript need to be embedded into the M5
837# library. To do that, we compile the file to byte code, marshal the
838# byte code, compress it, and then generate an assembly file that
839# inserts the result into the data section with symbols indicating the
840# beginning, and end (and with the size at the end)
830py_sources_tnodes = {}
831for pysource in py_sources:
832 py_sources_tnodes[pysource.tnode] = pysource
833
834def objectifyPyFile(target, source, env):
835 '''Action function to compile a .py into a code object, marshal
836 it, compress it, and stick it into an asm file so the code appears
837 as just bytes with a label in the data section'''
838
839 src = file(str(source[0]), 'r').read()
840 dst = file(str(target[0]), 'w')
841
841def objectifyPyFile(target, source, env):
842 '''Action function to compile a .py into a code object, marshal
843 it, compress it, and stick it into an asm file so the code appears
844 as just bytes with a label in the data section'''
845
846 src = file(str(source[0]), 'r').read()
847 dst = file(str(target[0]), 'w')
848
842 pysource = py_sources_tnodes[source[0]]
849 pysource = PySource.tnodes[source[0]]
843 compiled = compile(src, pysource.debugname, 'exec')
844 marshalled = marshal.dumps(compiled)
845 compressed = zlib.compress(marshalled)
846 data = compressed
847
848 # Some C/C++ compilers prepend an underscore to global symbol
849 # names, so if they're going to do that, we need to prepend that
850 # leading underscore to globals in the assembly file.

--- 8 unchanged lines hidden (view full) ---

859 print >>dst, ".globl %s_end" % sym
860 print >>dst, "%s_beg:" % sym
861 for i in xrange(0, len(data), step):
862 x = array.array('B', data[i:i+step])
863 print >>dst, ".byte", ','.join([str(d) for d in x])
864 print >>dst, "%s_end:" % sym
865 print >>dst, ".long %d" % len(marshalled)
866
850 compiled = compile(src, pysource.debugname, 'exec')
851 marshalled = marshal.dumps(compiled)
852 compressed = zlib.compress(marshalled)
853 data = compressed
854
855 # Some C/C++ compilers prepend an underscore to global symbol
856 # names, so if they're going to do that, we need to prepend that
857 # leading underscore to globals in the assembly file.

--- 8 unchanged lines hidden (view full) ---

866 print >>dst, ".globl %s_end" % sym
867 print >>dst, "%s_beg:" % sym
868 for i in xrange(0, len(data), step):
869 x = array.array('B', data[i:i+step])
870 print >>dst, ".byte", ','.join([str(d) for d in x])
871 print >>dst, "%s_end:" % sym
872 print >>dst, ".long %d" % len(marshalled)
873
867for source in py_sources:
874for source in PySource.all:
868 env.Command(source.assembly, source.tnode, objectifyPyFile)
869 Source(source.assembly)
870
871# Generate init_python.cc which creates a bunch of EmbeddedPyModule
872# structs that describe the embedded python code. One such struct
873# contains information about the importer that python uses to get at
874# the embedded files, and then there's a list of all of the rest that
875# the importer uses to load the rest on demand.
875 env.Command(source.assembly, source.tnode, objectifyPyFile)
876 Source(source.assembly)
877
878# Generate init_python.cc which creates a bunch of EmbeddedPyModule
879# structs that describe the embedded python code. One such struct
880# contains information about the importer that python uses to get at
881# the embedded files, and then there's a list of all of the rest that
882# the importer uses to load the rest on demand.
876py_sources_symbols = {}
877for pysource in py_sources:
878 py_sources_symbols[pysource.symname] = pysource
879def pythonInit(target, source, env):
880 dst = file(str(target[0]), 'w')
881
882 def dump_mod(sym, endchar=','):
883def pythonInit(target, source, env):
884 dst = file(str(target[0]), 'w')
885
886 def dump_mod(sym, endchar=','):
883 pysource = py_sources_symbols[sym]
887 pysource = PySource.symnames[sym]
884 print >>dst, ' { "%s",' % pysource.arcname
885 print >>dst, ' "%s",' % pysource.modpath
886 print >>dst, ' %s_beg, %s_end,' % (sym, sym)
887 print >>dst, ' %s_end - %s_beg,' % (sym, sym)
888 print >>dst, ' *(int *)%s_end }%s' % (sym, endchar)
889
890 print >>dst, '#include "sim/init.hh"'
891

--- 10 unchanged lines hidden (view full) ---

902 sym = sym.get_contents()
903 if sym == "PyEMB_importer":
904 # Skip the importer since we've already exported it
905 continue
906 dump_mod(sym)
907 print >>dst, " { 0, 0, 0, 0, 0, 0 }"
908 print >>dst, "};"
909
888 print >>dst, ' { "%s",' % pysource.arcname
889 print >>dst, ' "%s",' % pysource.modpath
890 print >>dst, ' %s_beg, %s_end,' % (sym, sym)
891 print >>dst, ' %s_end - %s_beg,' % (sym, sym)
892 print >>dst, ' *(int *)%s_end }%s' % (sym, endchar)
893
894 print >>dst, '#include "sim/init.hh"'
895

--- 10 unchanged lines hidden (view full) ---

906 sym = sym.get_contents()
907 if sym == "PyEMB_importer":
908 # Skip the importer since we've already exported it
909 continue
910 dump_mod(sym)
911 print >>dst, " { 0, 0, 0, 0, 0, 0 }"
912 print >>dst, "};"
913
910symbols = [Value(s.symname) for s in py_sources]
911env.Command('sim/init_python.cc', symbols, pythonInit)
914
915env.Command('sim/init_python.cc',
916 map(Value, (s.symname for s in PySource.all)),
917 pythonInit)
912Source('sim/init_python.cc')
913
914########################################################################
915#
916# Define binaries. Each different build type (debug, opt, etc.) gets
917# a slightly different build environment.
918#
919
920# List of constructed environments to pass back to SConstruct
921envList = []
922
918Source('sim/init_python.cc')
919
920########################################################################
921#
922# Define binaries. Each different build type (debug, opt, etc.) gets
923# a slightly different build environment.
924#
925
926# List of constructed environments to pass back to SConstruct
927envList = []
928
923# This function adds the specified sources to the given build
924# environment, and returns a list of all the corresponding SCons
925# Object nodes (including an extra one for date.cc). We explicitly
926# add the Object nodes so we can set up special dependencies for
927# date.cc.
928def make_objs(sources, env, static):
929 if static:
930 XObject = env.StaticObject
931 else:
932 XObject = env.SharedObject
929date_source = Source('base/date.cc', skip_lib=True)
933
930
934 objs = [ XObject(s) for s in sources ]
935
936 # make date.cc depend on all other objects so it always gets
937 # recompiled whenever anything else does
938 date_obj = XObject('base/date.cc')
939
940 env.Depends(date_obj, objs)
941 objs.append(date_obj)
942 return objs
943
944# Function to create a new build environment as clone of current
945# environment 'env' with modified object suffix and optional stripped
946# binary. Additional keyword arguments are appended to corresponding
947# build environment vars.
948def makeEnv(label, objsfx, strip = False, **kwargs):
949 # SCons doesn't know to append a library suffix when there is a '.' in the
950 # name. Use '_' instead.
951 libname = 'm5_' + label
952 exename = 'm5.' + label
953
954 new_env = env.Clone(OBJSUFFIX=objsfx, SHOBJSUFFIX=objsfx + 's')
955 new_env.Label = label
956 new_env.Append(**kwargs)
957
958 swig_env = new_env.Clone()
931# Function to create a new build environment as clone of current
932# environment 'env' with modified object suffix and optional stripped
933# binary. Additional keyword arguments are appended to corresponding
934# build environment vars.
935def makeEnv(label, objsfx, strip = False, **kwargs):
936 # SCons doesn't know to append a library suffix when there is a '.' in the
937 # name. Use '_' instead.
938 libname = 'm5_' + label
939 exename = 'm5.' + label
940
941 new_env = env.Clone(OBJSUFFIX=objsfx, SHOBJSUFFIX=objsfx + 's')
942 new_env.Label = label
943 new_env.Append(**kwargs)
944
945 swig_env = new_env.Clone()
946 swig_env.Append(CCFLAGS='-Werror')
959 if env['GCC']:
960 swig_env.Append(CCFLAGS='-Wno-uninitialized')
961 swig_env.Append(CCFLAGS='-Wno-sign-compare')
962 swig_env.Append(CCFLAGS='-Wno-parentheses')
963
947 if env['GCC']:
948 swig_env.Append(CCFLAGS='-Wno-uninitialized')
949 swig_env.Append(CCFLAGS='-Wno-sign-compare')
950 swig_env.Append(CCFLAGS='-Wno-parentheses')
951
964 static_objs = make_objs(cc_lib_sources, new_env, static=True)
965 shared_objs = make_objs(cc_lib_sources, new_env, static=False)
966 static_objs += [ swig_env.StaticObject(s) for s in cc_swig_sources ]
967 shared_objs += [ swig_env.SharedObject(s) for s in cc_swig_sources ]
952 werror_env = new_env.Clone()
953 werror_env.Append(CCFLAGS='-Werror')
968
954
955 def make_obj(source, static, extra_deps = None):
956 '''This function adds the specified source to the correct
957 build environment, and returns the corresponding SCons Object
958 nodes'''
959
960 if source.swig:
961 env = swig_env
962 elif source.Werror:
963 env = werror_env
964 else:
965 env = new_env
966
967 if static:
968 obj = env.StaticObject(source.tnode)
969 else:
970 obj = env.SharedObject(source.tnode)
971
972 if extra_deps:
973 env.Depends(obj, extra_deps)
974
975 return obj
976
977 static_objs = [ make_obj(s, True) for s in Source.get(skip_lib=False)]
978 shared_objs = [ make_obj(s, False) for s in Source.get(skip_lib=False)]
979
980 static_date = make_obj(date_source, static=True, extra_deps=static_objs)
981 static_objs.append(static_date)
982
983 shared_date = make_obj(date_source, static=False, extra_deps=shared_objs)
984 shared_objs.append(static_date)
985
969 # First make a library of everything but main() so other programs can
970 # link against m5.
971 static_lib = new_env.StaticLibrary(libname, static_objs)
972 shared_lib = new_env.SharedLibrary(libname, shared_objs)
973
974 for target, sources in unit_tests:
986 # First make a library of everything but main() so other programs can
987 # link against m5.
988 static_lib = new_env.StaticLibrary(libname, static_objs)
989 shared_lib = new_env.SharedLibrary(libname, shared_objs)
990
991 for target, sources in unit_tests:
975 objs = [ new_env.StaticObject(s) for s in sources ]
992 objs = [ make_obj(s, static=True) for s in sources ]
976 new_env.Program("unittest/%s.%s" % (target, label), objs + static_objs)
977
978 # Now link a stub with main() and the static library.
993 new_env.Program("unittest/%s.%s" % (target, label), objs + static_objs)
994
995 # Now link a stub with main() and the static library.
979 objects = [new_env.Object(s) for s in cc_bin_sources] + static_objs
996 bin_objs = [make_obj(s, True) for s in Source.get(bin_only=True) ]
997 progname = exename
980 if strip:
998 if strip:
981 unstripped_exe = exename + '.unstripped'
982 new_env.Program(unstripped_exe, objects)
999 progname += '.unstripped'
1000
1001 targets = new_env.Program(progname, bin_objs + static_objs)
1002
1003 if strip:
983 if sys.platform == 'sunos5':
984 cmd = 'cp $SOURCE $TARGET; strip $TARGET'
985 else:
986 cmd = 'strip $SOURCE -o $TARGET'
1004 if sys.platform == 'sunos5':
1005 cmd = 'cp $SOURCE $TARGET; strip $TARGET'
1006 else:
1007 cmd = 'strip $SOURCE -o $TARGET'
987 targets = new_env.Command(exename, unstripped_exe, cmd)
988 else:
989 targets = new_env.Program(exename, objects)
1008 targets = new_env.Command(exename, progname, cmd)
990
991 new_env.M5Binary = targets[0]
992 envList.append(new_env)
993
994# Debug binary
995ccflags = {}
996if env['GCC']:
997 if sys.platform == 'sunos5':

--- 41 unchanged lines hidden ---
1009
1010 new_env.M5Binary = targets[0]
1011 envList.append(new_env)
1012
1013# Debug binary
1014ccflags = {}
1015if env['GCC']:
1016 if sys.platform == 'sunos5':

--- 41 unchanged lines hidden ---