• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2import struct
3import sys
4import argparse
5
6parser=argparse.ArgumentParser(
7            description='''Script for converting shaders from binary to hex ''' )
8parser = argparse.ArgumentParser(prog='converter.py', usage='%(prog)s binary_file')
9parser.add_argument('binary', nargs=1, help='binary_file')
10args=parser.parse_args()
11
12print "static const uint32_t kernel[][4] = {"
13with open(sys.argv[1], 'r') as f:
14    fmt = '<LLLL'
15    step = struct.calcsize(fmt)
16    while True:
17        buf = f.read(step)
18        if not buf:
19            break
20        elif len(buf) < step:
21            buf += '\x00' * (step - len(buf))
22
23        val = struct.unpack('<LLLL', buf)
24        print "\t{{ 0x{:08x}, 0x{:08x}, 0x{:08x}, 0x{:08x} }},".format(*val)
25
26print "};"
27