/
githubmirror
/
node
Обзор
Документация
Войти
/
githubmirror
/
node
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
deps/v8/tools/include-file-as-bytes.py
58 строк
2 KB
Michaël Zasso
deps: update V8 to 14.2.231.9
23 окт 2025, 08:36
Не верифицирован
23 окт 2025, 08:36
c2843b7
Код
Авторство
О чём код?
#!/usr/bin/env python3 # Copyright 2025 the V8 project authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. """This program takes a file and produces another file that contains its binary bytes stored as uint32_ts. The first argument is the source path, the second argument is the destination path, the third is the name of the produced static. This program could be extended in the future to make uint8_t/etc arrays. This is based on ICU4C's make_data_cpp.py, but it doesn't require the file to have any special headers. """ import mmap import os import struct import sys HEADER = """#include <cstdint> #include <cstddef> extern "C" uint32_t {0}[] = {{""" FOOTER = """ }}; extern "C" size_t {0}_len = {1}; """ def writeFile(src_path, dst_path, name): assert os.path.exists(src_path) with open(dst_path, 'w') as dst: dst.write(HEADER.format(name)) with open(src_path, 'rb') as src: # We wish to read unsigned ints s = struct.Struct('@I') assert s.size == 4 mm = mmap.mmap(src.fileno(), 0, access=mmap.ACCESS_READ) assert len(mm) % s.size == 0 # We want to have 16 values per line for offset in range(0, len(mm), s.size): u32 = s.unpack_from(mm, offset)[0] if offset % 16 == 0: dst.write("\n ") dst.write(" 0x{:08x},".format(u32)) dst.write(FOOTER.format(name, int(len(mm) / s.size))) mm.close() if __name__ == '__main__': writeFile(sys.argv[1], sys.argv[2], sys.argv[3])