1#!/usr/bin/env python3 2## 3## Copyright (C) by Argonne National Laboratory 4## See COPYRIGHT in top-level directory 5## 6 7import sys, os 8 9# inline.py [infile] [outfile] [topdir] [native: 0|1] 10 11infile = sys.argv[1] 12outfile = sys.argv[2] 13top_srcdir = sys.argv[3] 14native = sys.argv[4] 15 16base = os.path.basename(outfile) 17basename = os.path.splitext(base)[0] 18 19sys.path.append(top_srcdir + '/maint/') 20import yutils 21 22yutils.copyright_c(outfile) 23OUTFILE = open(outfile, 'a') 24 25if native == "1": 26 OUTFILE.write("/* native format */\n\n") 27else: 28 OUTFILE.write("/* SPIR-V format */\n\n") 29OUTFILE.write("#include <stdlib.h>\n\n") 30OUTFILE.write("const unsigned char %s_str[] = {\n" % basename) 31 32if os.path.exists(infile): 33 bfile = open(infile, 'rb') 34 char = bfile.read(1) 35 OUTFILE.write("%s" % hex(ord(char))) 36 while 1: 37 char = bfile.read(1) 38 if not char: 39 break 40 OUTFILE.write(", %s" % hex(ord(char))) 41 bfile.close() 42 OUTFILE.write("};\n") 43 OUTFILE.write("const size_t %s_size = %d;\n" % (basename, os.stat(infile).st_size)) 44else: 45 OUTFILE.write("};\n") 46 OUTFILE.write("const size_t %s_size = 0;\n" % basename) 47 48OUTFILE.close() 49