SConscript (13508:8fe5d0294e51) SConscript (13576:88594d85f9a9)
1# -*- mode:python -*-
2
1# -*- mode:python -*-
2
3# Copyright (c) 2018 ARM Limited
4#
5# The license below extends only to copyright in the software and shall
6# not be construed as granting a license to any other intellectual
7# property including but not limited to intellectual property relating
8# to a hardware implementation of the functionality of the software
9# licensed hereunder. You may use the software subject to the license
10# terms below provided that you ensure that this notice is replicated
11# unmodified and in its entirety in all distributions of the software,
12# modified or unmodified, in source code or in binary form.
13#
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
9# notice, this list of conditions and the following disclaimer;
10# redistributions in binary form must reproduce the above copyright

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

207
208 def __lt__(self, other): return self.filename < other.filename
209 def __le__(self, other): return self.filename <= other.filename
210 def __gt__(self, other): return self.filename > other.filename
211 def __ge__(self, other): return self.filename >= other.filename
212 def __eq__(self, other): return self.filename == other.filename
213 def __ne__(self, other): return self.filename != other.filename
214
14# Copyright (c) 2004-2005 The Regents of The University of Michigan
15# All rights reserved.
16#
17# Redistribution and use in source and binary forms, with or without
18# modification, are permitted provided that the following conditions are
19# met: redistributions of source code must retain the above copyright
20# notice, this list of conditions and the following disclaimer;
21# redistributions in binary form must reproduce the above copyright

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

218
219 def __lt__(self, other): return self.filename < other.filename
220 def __le__(self, other): return self.filename <= other.filename
221 def __gt__(self, other): return self.filename > other.filename
222 def __ge__(self, other): return self.filename >= other.filename
223 def __eq__(self, other): return self.filename == other.filename
224 def __ne__(self, other): return self.filename != other.filename
225
226def blobToCpp(data, symbol, cpp_code, hpp_code=None, namespace=None):
227 '''
228 Convert bytes data into C++ .cpp and .hh uint8_t byte array
229 code containing that binary data.
230
231 :param data: binary data to be converted to C++
232 :param symbol: name of the symbol
233 :param cpp_code: append the generated cpp_code to this object
234 :param hpp_code: append the generated hpp_code to this object
235 If None, ignore it. Otherwise, also include it
236 in the .cpp file.
237 :param namespace: namespace to put the symbol into. If None,
238 don't put the symbols into any namespace.
239 '''
240 symbol_len_declaration = 'const std::size_t {}_len'.format(symbol)
241 symbol_declaration = 'const std::uint8_t {}[]'.format(symbol)
242 if hpp_code is not None:
243 cpp_code('''\
244#include "blobs/{}.hh"
245'''.format(symbol))
246 hpp_code('''\
247#include <cstddef>
248#include <cstdint>
249''')
250 if namespace is not None:
251 hpp_code('namespace {} {{'.format(namespace))
252 hpp_code('extern ' + symbol_len_declaration + ';')
253 hpp_code('extern ' + symbol_declaration + ';')
254 if namespace is not None:
255 hpp_code('}')
256 if namespace is not None:
257 cpp_code('namespace {} {{'.format(namespace))
258 cpp_code(symbol_len_declaration + ' = {};'.format(len(data)))
259 cpp_code(symbol_declaration + ' = {')
260 cpp_code.indent()
261 step = 16
262 for i in xrange(0, len(data), step):
263 x = array.array('B', data[i:i+step])
264 cpp_code(''.join('%d,' % d for d in x))
265 cpp_code.dedent()
266 cpp_code('};')
267 if namespace is not None:
268 cpp_code('}')
269
270def Blob(blob_path, symbol):
271 '''
272 Embed an arbitrary blob into the gem5 executable,
273 and make it accessible to C++ as a byte array.
274 '''
275 blob_path = os.path.abspath(blob_path)
276 blob_out_dir = os.path.join(env['BUILDDIR'], 'blobs')
277 path_noext = joinpath(blob_out_dir, symbol)
278 cpp_path = path_noext + '.cc'
279 hpp_path = path_noext + '.hh'
280 def embedBlob(target, source, env):
281 data = file(str(source[0]), 'r').read()
282 cpp_code = code_formatter()
283 hpp_code = code_formatter()
284 blobToCpp(data, symbol, cpp_code, hpp_code, namespace='Blobs')
285 cpp_path = str(target[0])
286 hpp_path = str(target[1])
287 cpp_dir = os.path.split(cpp_path)[0]
288 if not os.path.exists(cpp_dir):
289 os.makedirs(cpp_dir)
290 cpp_code.write(cpp_path)
291 hpp_code.write(hpp_path)
292 env.Command([cpp_path, hpp_path], blob_path,
293 MakeAction(embedBlob, Transform("EMBED BLOB")))
294 Source(cpp_path)
295
215class Source(SourceFile):
216 ungrouped_tag = 'No link group'
217 source_groups = set()
218
219 _current_group_tag = ungrouped_tag
220
221 @staticmethod
222 def link_group_tag(group):

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

435 super(Gem5, self).__init__(target)
436
437 def declare(self, env):
438 objs = env['MAIN_OBJS'] + env['STATIC_OBJS']
439 return super(Gem5, self).declare(env, objs)
440
441
442# Children should have access
296class Source(SourceFile):
297 ungrouped_tag = 'No link group'
298 source_groups = set()
299
300 _current_group_tag = ungrouped_tag
301
302 @staticmethod
303 def link_group_tag(group):

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

516 super(Gem5, self).__init__(target)
517
518 def declare(self, env):
519 objs = env['MAIN_OBJS'] + env['STATIC_OBJS']
520 return super(Gem5, self).declare(env, objs)
521
522
523# Children should have access
524Export('Blob')
443Export('Source')
444Export('PySource')
445Export('SimObject')
446Export('ProtoBuf')
447Export('Executable')
448Export('UnitTest')
449Export('GTest')
450

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

1064 sym = pysource.symname
1065
1066 code = code_formatter()
1067 code('''\
1068#include "sim/init.hh"
1069
1070namespace {
1071
525Export('Source')
526Export('PySource')
527Export('SimObject')
528Export('ProtoBuf')
529Export('Executable')
530Export('UnitTest')
531Export('GTest')
532

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

1146 sym = pysource.symname
1147
1148 code = code_formatter()
1149 code('''\
1150#include "sim/init.hh"
1151
1152namespace {
1153
1072const uint8_t data_${sym}[] = {
1073''')
1154''')
1074 code.indent()
1075 step = 16
1076 for i in xrange(0, len(data), step):
1077 x = array.array('B', data[i:i+step])
1078 code(''.join('%d,' % d for d in x))
1079 code.dedent()
1155 blobToCpp(data, 'data_' + sym, code)
1156 code('''\
1080
1157
1081 code('''};
1082
1083EmbeddedPython embedded_${sym}(
1084 ${{c_str(pysource.arcname)}},
1085 ${{c_str(pysource.abspath)}},
1086 ${{c_str(pysource.modpath)}},
1087 data_${sym},
1088 ${{len(data)}},
1089 ${{len(marshalled)}});

--- 232 unchanged lines hidden ---
1158
1159EmbeddedPython embedded_${sym}(
1160 ${{c_str(pysource.arcname)}},
1161 ${{c_str(pysource.abspath)}},
1162 ${{c_str(pysource.modpath)}},
1163 data_${sym},
1164 ${{len(data)}},
1165 ${{len(marshalled)}});

--- 232 unchanged lines hidden ---