diff --git a/site_scons/gem5_scons/util.py b/site_scons/gem5_scons/util.py index b62cc0164e..6049fedab2 100644 --- a/site_scons/gem5_scons/util.py +++ b/site_scons/gem5_scons/util.py @@ -38,6 +38,8 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +import array +import functools import itertools import re import sys @@ -109,3 +111,17 @@ def compareVersions(v1, v2): if n1 > n2: return 1 return 0 + +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]) + strs = map(lambda i: f'{i},', x) + code(functools.reduce(lambda x, y: x + y, strs)) + code.dedent() + code('};') diff --git a/src/SConscript b/src/SConscript index c819ad78a2..28404aa6c0 100644 --- a/src/SConscript +++ b/src/SConscript @@ -37,10 +37,8 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -import array import bisect import distutils.spawn -import functools import importlib import importlib.abc import importlib.machinery @@ -55,6 +53,7 @@ import SCons from gem5_scons import Transform, warning, error, ToValue, FromValue from gem5_scons.sources import * +from gem5_scons.util import bytesToCppArray Export(SourceFilter.factories) @@ -70,20 +69,6 @@ build_env = [(opt, env[opt]) for opt in export_vars] from m5.util import code_formatter -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]) - strs = map(lambda i: f'{i},', x) - code(functools.reduce(lambda x, y: x + y, strs)) - code.dedent() - code('};') - def build_blob(target, source, env): ''' Embed an arbitrary blob into the gem5 executable,