blob: 4db47ea754126daa5a0b707bfd899d1e1327b0e6 [file] [log] [blame]
Gian Marco Iodice16824302017-09-28 15:41:37 +01001#!/usr/bin/env python
Anthony Barbier6ff3b192017-09-04 18:44:23 +01002import glob
3import collections
4import os
5
Anthony Barbier6ff3b192017-09-04 18:44:23 +01006armcv_path = "arm_compute"
Sang-Hoon Park03076262020-11-04 17:32:38 +00007src_path ="src"
Anthony Barbier6ff3b192017-09-04 18:44:23 +01008
Sang-Hoon Park03076262020-11-04 17:32:38 +00009Target = collections.namedtuple('Target', 'name prefix basepath')
10
11core_targets = [
12 Target("NEON", "NE", src_path), # NEON kernels are under src
13 Target("CL", "CL", src_path), # CL kernels are under src
14 Target("CPP", "CPP", armcv_path), # CPP kernels are under arm_compute
15 Target("GLES_COMPUTE", "GC", armcv_path) # GLES kernels are under arm_compute
16 ]
17
18# All functions are under arm_compute
19runtime_targets = [
20 Target("NEON", "NE", armcv_path),
21 Target("CL", "CL", armcv_path),
22 Target("CPP", "CPP", armcv_path),
23 Target("GLES_COMPUTE", "GC", armcv_path)
24 ]
25
26core_path = "/core/"
27runtime_path = "/runtime/"
28include_str = "#include \""
Anthony Barbier6ff3b192017-09-04 18:44:23 +010029
30def read_file(file):
31 with open(file, "r") as f:
32 lines = f.readlines()
33 return lines
34
35
36def write_file(file, lines):
37 with open(file, "w") as f:
38 for line in lines:
39 f.write(line)
40
41
42def remove_existing_includes(lines):
43 first_pos = next(i for i, line in enumerate(lines) if include_str in line)
44 return [x for x in lines if not x.startswith(include_str)], first_pos
45
46
47def add_updated_includes(lines, pos, includes):
48 lines[pos:pos] = includes
49 return lines
50
51
52def create_include_list(folder):
53 files_path = folder + "/*.h"
54 files = glob.glob(files_path)
55 updated_files = [include_str + folder + "/" + x.rsplit('/',1)[1] + "\"\n" for x in files]
56 updated_files.sort()
57 return updated_files
58
59
Sang-Hoon Park03076262020-11-04 17:32:38 +000060def include_components(target, path, header_prefix, folder, subfolders=None):
61 for t in target:
62 target_path = t.basepath + path + t.name + "/"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010063 components_file = target_path + t.prefix + header_prefix
64 if os.path.exists(components_file):
65 include_list = create_include_list(target_path + folder)
Anthony Barbier6a5627a2017-09-26 14:42:02 +010066 for s in subfolders or []:
67 include_list += create_include_list( target_path + folder + "/" + s)
68 include_list.sort()
Anthony Barbier6ff3b192017-09-04 18:44:23 +010069 lines = read_file(components_file)
70 lines, first_pos = remove_existing_includes(lines)
71 lines = add_updated_includes(lines, first_pos, include_list)
72 write_file(components_file, lines)
73
74
75if __name__ == "__main__":
76 # Include kernels
Sang-Hoon Park03076262020-11-04 17:32:38 +000077 include_components(core_targets, core_path, "Kernels.h", "kernels", ["arm32", "arm64"])
Anthony Barbier6ff3b192017-09-04 18:44:23 +010078
79 # Include functions
Sang-Hoon Park03076262020-11-04 17:32:38 +000080 include_components(runtime_targets, runtime_path, "Functions.h", "functions")