Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env python3
#------------------------------------------------------------------------------------
# Verilog Filelist compilation script
# A joint work commissioned on behalf of SoC Labs, under Arm Academic Access license.
#
# Contributors
#
# David Mapstone (d.a.mapstone@soton.ac.uk)
# Copyright (c) 2023, SoC Labs (www.soclabs.org)
#------------------------------------------------------------------------------------
import argparse
import os
verilog_extensions = (".v", ".sv")
filelist_header = """//-----------------------------------------------------------------------------
// AUTOGENERATED: Compiled Filelist
// A joint work commissioned on behalf of SoC Labs, under Arm Academic Access license.
//
// Contributors
//
// David Mapstone (d.a.mapstone@soton.ac.uk)
//
// Copyright � 2021-3, SoC Labs (www.soclabs.org)
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Abstract : Verilog Command File with expanded system variables
//-----------------------------------------------------------------------------
"""
def env_var_substitute(path):
# Interpret the path and remove brackets from path
sub_path = path.translate(str.maketrans('', '', '()'))
# Expand environment variables in Path
sub_path = os.path.expandvars(sub_path)
return sub_path
def read_list(filelist):
# Create Filelist List Structure
compiled_filelist = []
# Open Filelist and Read Lines
f = open(filelist, "r")
filelines = f.readlines()
f.close()
# Remove Black Lines from list
filelines = [x.rstrip("\n") for x in filelines]
filelines = [x for x in filelines if x != ""]
# Iterate over list and process
for line in filelines:
# Remove whitespace and split line into arguments
line_list = line.strip().split()
# print(line_list)
# Check Line isn't a comment
if not line_list[0].startswith("//"):
# If line is a reference to another filelist
if line_list[0] == "-f":
# Recursively call this function and append list to this compiled Filelist
print(line_list[1])
compiled_filelist += read_list(env_var_substitute(line_list[1]))
elif line_list[0] == "-y":
# Append to filelist
for file in os.listdir(env_var_substitute(line_list[1])):
if file.endswith(verilog_extensions):
compiled_filelist.append(env_var_substitute(line_list[1])+"/"+str(file))
elif line_list[0].startswith("+incdir+"):
# Append to filelist
for file in os.listdir(env_var_substitute(line_list[0].lstrip("+incdir+"))):
if file.endswith(verilog_extensions):
compiled_filelist.append(env_var_substitute(line_list[0].lstrip("+incdir+"))+"/"+str(file))
# If file list a verilog file
elif line_list[0].endswith(verilog_extensions):
# Append to filelist
compiled_filelist.append(env_var_substitute(line_list[0]))
return compiled_filelist
def filelist_compile(args):
input_filelist = args.filelist
output_filelist = args.output
print("------------------")
print("Compiling Filelist")
print("------------------")
filelist = read_list(input_filelist)
filelist = [x+"\n" for x in filelist]
filelist_str = filelist_header
for path in filelist: filelist_str += path
print("Compile Done")
print("------------------")
f_outlist = open(output_filelist, "w")
f_outlist.write(filelist_str)
f_outlist.close()
if __name__ == "__main__":
# Capture Arguments from Command Line
parser = argparse.ArgumentParser(description='Compiles Filelist to Read')
parser.add_argument("-f", "--filelist", type=str, help="Input Filelist to Read")
parser.add_argument("-o", "--output", type=str, help="Output Filelist location")
args = parser.parse_args()
filelist_compile(args)