DPC++ Runtime
Runtime libraries for oneAPI DPC++
ze_api_generator.py
Go to the documentation of this file.
1 import re
2 import sys
3 
4 def camel_to_snake(src):
5  return re.sub(r'(?<!^)(?=[A-Z])', '_', src).lower()
6 
7 def snake_to_camel(src):
8  temp = src.split('_')
9  return ''.join(x.title() for x in temp)
10 
11 
12 def extract_ze_apis(header):
13  """
14  Emit file with contents of
15  _ZE_API(api_name, api_domain, cb, param_type)
16  """
17  api = open("ze_api.def", "w")
18 
19  matches = re.finditer(r'typedef struct _ze_([_a-z]+)_callbacks_t\n\{\n([a-zA-Z_;\s\n]+)\n\} ze_([_a-z]+)_callbacks_t;', header)
20 
21  for match in matches:
22  api_domain = snake_to_camel(match.group(1))
23  for l in match.group(2).splitlines():
24  parts = l.split()
25  api_match = re.match(r'ze_pfn([a-zA-Z]+)Cb_t', parts[0])
26  api_name_tail = api_match.group(1)
27  api_name = 'ze' + api_name_tail
28 
29  param_type = 'ze_' + camel_to_snake(api_name_tail) + '_params_t'
30 
31  cb = 'pfn' + api_name_tail.replace(api_domain, '') + 'Cb'
32 
33  api.write("_ZE_API({}, {}, {}, {})\n".format(api_name, api_domain, cb, param_type))
34 
35  api.close()
36 
37 if __name__ == "__main__":
38  with open(sys.argv[1], 'r') as f:
39  header = f.read()
40  extract_ze_apis(header)
ze_api_generator.camel_to_snake
def camel_to_snake(src)
Definition: ze_api_generator.py:4
ze_api_generator.extract_ze_apis
def extract_ze_apis(header)
Definition: ze_api_generator.py:12
ze_api_generator.snake_to_camel
def snake_to_camel(src)
Definition: ze_api_generator.py:7