Gabe Black has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/48135 )
Change subject: scons: Factor out the core of blobToCpp.
......................................................................
scons: Factor out the core of blobToCpp.
blobToCpp is called in two places, one which uses all its functionality,
and one which disables most of it. Instead, factor out the small core so
that it can be called directly by the call sight which uses only that
part, and blobToCpp itself.
This change also removes the ability to leave out a namespace or header
file code formatter, since the function is not called that way any more.
That simplifies blobToCpp significantly.
Change-Id: I63139311521bb4f9287fe41ff51e4e5301a18349
---
M src/SConscript
1 file changed, 38 insertions(+), 36 deletions(-)
diff --git a/src/SConscript b/src/SConscript
index 1750ed5..175b8cf 100644
--- a/src/SConscript
+++ b/src/SConscript
@@ -273,7 +273,20 @@
self.shared_objs[key] = env.SharedObject(self.tnode)
return self.shared_objs[key]
-def blobToCpp(data, symbol, cpp_code, hpp_code=None, namespace=None):
+def bytesToCppArray(code, symbol, data):
+ '''
+ Output an array of bytes to a code formatter as a c++ array
declaration.
+ '''
+ code('const std::uint8_t ${symbol}[] = {')
+ code.indent()
+ step = 16
+ for i in range(0, len(data), step):
+ x = array.array('B', data[i:i+step])
+ code(''.join('%d,' % d for d in x))
+ code.dedent()
+ code('};')
+
+def blobToCpp(data, symbol, cpp_code, hpp_code, namespace):
'''
Convert bytes data into C++ .cpp and .hh uint8_t byte array
code containing that binary data.
@@ -282,41 +295,32 @@
:param symbol: name of the symbol
:param cpp_code: append the generated cpp_code to this object
:param hpp_code: append the generated hpp_code to this object
- If None, ignore it. Otherwise, also include it
- in the .cpp file.
- :param namespace: namespace to put the symbol into. If None,
- don't put the symbols into any namespace.
+ Also include it in the .cpp file.
+ :param namespace: namespace to put the symbol into.
'''
- symbol_len_declaration = 'const std::size_t {}_len'.format(symbol)
- symbol_declaration = 'const std::uint8_t {}[]'.format(symbol)
- if hpp_code is not None:
- cpp_code('''\
-#include "blobs/{}.hh"
-'''.format(symbol))
- hpp_code('''\
+ hpp_code('''\
#include <cstddef>
#include <cstdint>
+
+namespace ${namespace}
+{
+
+extern const std::size_t ${symbol}_len;
+extern const std::uint8_t ${symbol};
+
+}
''')
- if namespace is not None:
- hpp_code('namespace {} {{'.format(namespace))
- hpp_code('extern ' + symbol_len_declaration + ';')
- hpp_code('extern ' + symbol_declaration + ';')
- if namespace is not None:
- hpp_code('}')
- if namespace is not None:
- cpp_code('namespace {} {{'.format(namespace))
- if hpp_code is not None:
- cpp_code(symbol_len_declaration + ' = {};'.format(len(data)))
- cpp_code(symbol_declaration + ' = {')
- cpp_code.indent()
- step = 16
- for i in range(0, len(data), step):
- x = array.array('B', data[i:i+step])
- cpp_code(''.join('%d,' % d for d in x))
- cpp_code.dedent()
- cpp_code('};')
- if namespace is not None:
- cpp_code('}')
+
+ cpp_code('''\
+#include "blobs/${symbol}.hh"
+
+namespace ${namespace}
+{
+
+const std::size_t ${symbol}_len = ${{len(data)}};
+''')
+ bytesToCode(cpp_code, symbol, data)
+ cpp_code('}')
def Blob(blob_path, symbol):
'''
@@ -1259,10 +1263,8 @@
{
''')
- blobToCpp(data, 'data_' + sym, code)
- code('''\
-
-
+ bytesToCppArray(code, 'data_{}'.format(sym), data)
+ code('''
EmbeddedPython embedded_${sym}(
${{c_str(pysource.arcname)}},
${{c_str(pysource.abspath)}},
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/48135
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I63139311521bb4f9287fe41ff51e4e5301a18349
Gerrit-Change-Number: 48135
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s