• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# Copyright © 2025 Intel Corporation
3# SPDX-License-Identifier: MIT
4
5from __future__ import annotations
6import argparse
7import binascii
8
9
10def main() -> None:
11    p = argparse.ArgumentParser()
12
13    p.add_argument('--output', dest='output', action='store',
14                   help='Output file', required=True)
15    p.add_argument('--prefix', action='store',
16                   help='Prefix string to use', required=True)
17    p.add_argument('inputs', metavar='SPIRV', nargs='+')
18
19    args = p.parse_args()
20
21    for f in args.inputs:
22        with open(f, 'rb') as fin:
23            with open(args.output, 'w') as fout:
24                fout.write("#pragma one\n")
25
26                fout.write("const uint32_t {0}[] = {{".format(args.prefix))
27
28                count = 0
29                while True:
30                    dword = fin.read(4)
31                    if not dword:
32                        break
33                    if count % 8 == 0:
34                        fout.write("\n   ")
35                    fout.write('{:#x}, '.format(int.from_bytes(dword, byteorder='little', signed=False)))
36                    count += 1
37
38                fout.write("\n")
39                fout.write("};\n")
40
41
42if __name__ == '__main__':
43    main()
44