From 88a932522d8d2e4791999786314603e446cb5262 Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Tue, 20 Jul 2021 01:57:48 -0700 Subject: [PATCH] scons: Move the bytesToCppArray helper to gem5_scons.util. Change-Id: Ib8789dd33ebbfb8e10446de5d1079654a2200d2d Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/48377 Reviewed-by: Hoa Nguyen Reviewed-by: Bobby R. Bruce Tested-by: kokoro Maintainer: Bobby R. Bruce --- site_scons/gem5_scons/util.py | 16 ++++++++++++++++ src/SConscript | 17 +---------------- 2 files changed, 17 insertions(+), 16 deletions(-) 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,