Ciro Santilli has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/15136
Change subject: scons: allow embedding arbitrary blobs into the gem5
executable
......................................................................
scons: allow embedding arbitrary blobs into the gem5 executable
The initial motivation for this is to embed the GDB XML target
description files into the executable.
Change-Id: I721e8dd37119d8e6eb376d7e9050b1094282bacc
---
M src/SConscript
1 file changed, 63 insertions(+), 8 deletions(-)
diff --git a/src/SConscript b/src/SConscript
index 361479d..d4ecf36 100755
--- a/src/SConscript
+++ b/src/SConscript
@@ -1,5 +1,16 @@
# -*- mode:python -*-
+# Copyright (c) 2018 ARM Limited
+#
+# The license below extends only to copyright in the software and shall
+# not be construed as granting a license to any other intellectual
+# property including but not limited to intellectual property relating
+# to a hardware implementation of the functionality of the software
+# licensed hereunder. You may use the software subject to the license
+# terms below provided that you ensure that this notice is replicated
+# unmodified and in its entirety in all distributions of the software,
+# modified or unmodified, in source code or in binary form.
+#
# Copyright (c) 2004-2005 The Regents of The University of Michigan
# All rights reserved.
#
@@ -212,6 +223,55 @@
def __eq__(self, other): return self.filename == other.filename
def __ne__(self, other): return self.filename != other.filename
+def blobToCpp(code, data, symbol, header=None):
+ '''
+ Convert given bytes from data into a C++ uint8_t byte array
+ named symbol, and append it to the given code.
+
+ Optionally the file, which might be required to define
+ the class to which the symbol belongs.
+ '''
+ if header is not None:
+ code('''\
+#include "{header}"
+
+'''.format(header=header))
+ code('''\
+#include <cstdint>
+
+const size_t {symbol}_len = {length};
+const uint8_t {symbol}[] = {{
+'''.format(symbol=symbol, length=len(data)))
+ code.indent()
+ step = 16
+ for i in xrange(0, len(data), step):
+ x = array.array('B', data[i:i+step])
+ code(''.join('%d,' % d for d in x))
+ code.dedent()
+ code('};')
+
+def Blob(blob_path, header, symbol):
+ '''
+ Embed an arbitrary blob into the gem5 executable,
+ and make it accessible to C++ as a byte array.
+ '''
+ blob_path = os.path.abspath(blob_path)
+ blob_out_dir = os.path.join(env['BUILDDIR'], 'blobs')
+ cpp_path = joinpath(blob_out_dir,
+ os.path.relpath(blob_path, Dir('#').abspath)) + '.cc'
+ def embedBlob(target, source, env):
+ data = file(str(source[0]), 'r').read()
+ code = code_formatter()
+ blobToCpp(code, data, header, symbol)
+ cpp_path= str(target[0])
+ cpp_dir = os.path.split(cpp_path)[0]
+ if not os.path.exists(cpp_dir):
+ os.makedirs(cpp_dir)
+ code.write(cpp_path)
+ env.Command(cpp_path, blob_path,
+ MakeAction(embedBlob, Transform("EMBED BLOB")))
+ Source(cpp_path)
+
class Source(SourceFile):
ungrouped_tag = 'No link group'
source_groups = set()
@@ -440,6 +500,7 @@
# Children should have access
+Export('Blob')
Export('Source')
Export('PySource')
Export('SimObject')
@@ -1069,16 +1130,10 @@
namespace {
-const uint8_t data_${sym}[] = {
''')
- code.indent()
- step = 16
- for i in xrange(0, len(data), step):
- x = array.array('B', data[i:i+step])
- code(''.join('%d,' % d for d in x))
- code.dedent()
+ blobToCpp(code, data, 'data_' + sym)
+ code('''\
- code('''};
EmbeddedPython embedded_${sym}(
${{c_str(pysource.arcname)}},
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/15136
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: I721e8dd37119d8e6eb376d7e9050b1094282bacc
Gerrit-Change-Number: 15136
Gerrit-PatchSet: 1
Gerrit-Owner: Ciro Santilli <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev