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 <hoanguyen@ucdavis.edu> Reviewed-by: Bobby R. Bruce <bbruce@ucdavis.edu> Tested-by: kokoro <noreply+kokoro@google.com> Maintainer: Bobby R. Bruce <bbruce@ucdavis.edu>
This commit is contained in:
@@ -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('};')
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user