ONE - On-device Neural Engine
Loading...
Searching...
No Matches
resolve_includes Namespace Reference

Functions

 resolve_includes (target, source)
 

Variables

 cl_files = glob.glob('src/core/CL/cl_kernels/*.cl')
 
list embed_files = [f + "embed" for f in cl_files]
 

Function Documentation

◆ resolve_includes()

resolve_includes.resolve_includes (   target,
  source 
)

Definition at line 44 of file resolve_includes.py.

44def resolve_includes(target, source):
45 # File collection
46 FileEntry = collections.namedtuple('FileEntry', 'target_name file_contents')
47
48 # Include pattern
49 pattern = re.compile("#include \"(.*)\"")
50
51 # Get file contents
52 files = []
53 for i in range(len(source)):
54 src = source[i]
55 dst = target[i]
56 f = open(src)
57 cts = f.read()
58 f.close()
59 contents = cts.splitlines()
60 entry = FileEntry(target_name=dst, file_contents=contents)
61 files.append((os.path.basename(src), entry))
62
63 # Create dictionary of tupled list
64 files_dict = dict(files)
65
66 # Check for includes (can only be files in the same folder)
67 final_files = []
68 for file in files:
69 done = False
70 tmp_file = file[1].file_contents
71 print(file[1].target_name)
72 while not done:
73 file_count = 0
74 updated_file = []
75 for line in tmp_file:
76 found = pattern.search(line)
77 if found:
78 include_file = found.group(1)
79 data = files_dict[include_file].file_contents
80 updated_file.extend(data)
81 else:
82 updated_file.append(line)
83 file_count += 1
84
85 # Check if all include are replaced.
86 if file_count == len(tmp_file):
87 done = True
88
89 # Update temp file
90 tmp_file = updated_file
91
92 # Append and prepend string literal identifiers and add expanded file to final list
93 tmp_file.insert(0, "R\"(\n")
94 tmp_file.append("\n)\"")
95 entry = FileEntry(target_name=file[1].target_name, file_contents=tmp_file)
96 final_files.append((file[0], entry))
97
98 # Write output files
99 for file in final_files:
100 with open(file[1].target_name, 'w+') as out_file:
101 out_file.write("\n".join(file[1].file_contents))
102
103
104# Generate embed files

Variable Documentation

◆ cl_files

resolve_includes.cl_files = glob.glob('src/core/CL/cl_kernels/*.cl')

Definition at line 105 of file resolve_includes.py.

◆ embed_files

list resolve_includes.embed_files = [f + "embed" for f in cl_files]

Definition at line 112 of file resolve_includes.py.