-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathchange_defines.py
150 lines (119 loc) · 4.6 KB
/
change_defines.py
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/python
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT license.
import sys, getopt
def file_line_rep(filedata, base_string, min_val, max_val, set_val):
#print("In file_line_rep. range: ["+str(min_val)+", "+str(max_val)+"], set_val: "+str(set_val))
print("Setting "+base_string+" to "+str(set_val))
if max_val < min_val:
print("ERROR: max_val or min_val is set incorrectly")
raise
if set_val > max_val or set_val < min_val:
print("ERROR: max_val or min_val or set_val is set incorrectly")
raise
newfiledata = []
for line in filedata:
#print(line)
if line.find(base_string) != -1:
#print(line)
for i in range(min_val, max_val+1):
line = line.replace(base_string+" "+str(i), base_string+" "+str(set_val))
#print(line)
newfiledata.append(line)
#for line in newfiledata:
# print(line)
return newfiledata
# -------------------------
# Set the IFFT type
# -------------------------
def set_ifft_define(set_val):
with open("lib/user_defines.h", "r") as file :
filedata = file.readlines()
newfiledata = file_line_rep(filedata, "#define SE_IFFT_TYPE", 0, 2, set_val)
with open("lib/user_defines.h", "w") as file :
file.writelines(newfiledata)
# ----------------------
# Set the NTT type
# ----------------------
def set_ntt_define(set_val):
with open("lib/user_defines.h", "r") as file :
filedata = file.readlines()
newfiledata = file_line_rep(filedata, "#define SE_NTT_TYPE", 0, 3, set_val)
with open("lib/user_defines.h", "w") as file :
file.writelines(newfiledata)
# -----------------------------
# Set the Index Map type
# -----------------------------
def set_index_map_define(set_val):
with open("lib/user_defines.h", "r") as file :
filedata = file.readlines()
newfiledata = file_line_rep(filedata, "#define SE_INDEX_MAP_TYPE", 0, 4, set_val)
with open("lib/user_defines.h", "w") as file :
file.writelines(newfiledata)
# -----------------------------
# Set the SK type
# -----------------------------
def set_sk_define(set_val):
with open("lib/user_defines.h", "r") as file :
filedata = file.readlines()
newfiledata = file_line_rep(filedata, "#define SE_SK_TYPE", 0, 2, set_val)
with open("lib/user_defines.h", "w") as file :
file.writelines(newfiledata)
# -----------------------------
# Set the Data Load Type
# -----------------------------
def set_data_load_define(set_val):
with open("lib/user_defines.h", "r") as file :
filedata = file.readlines()
newfiledata = file_line_rep(filedata, "#define SE_DATA_LOAD_TYPE", 0, 2, set_val)
with open("lib/user_defines.h", "w") as file :
file.writelines(newfiledata)
def main(argv):
try:
opts, args = getopt.getopt(argv,"hi:n:m:s:d:",["ifft=", "ntt=", "index_map=", "sk=", "data_load="])
except getopt.GetoptError:
print("change_defines.py -i <ifft_option> -n <ntt_option> "\
"-m <index_map_option> -s <sk_option> -d <data_load_option>")
sys.exit(2)
ifft_set_val = -1
ntt_set_val = -1
index_map_set_val = -1
sk_set_val = -1
data_load_set_val = -1
for opt, arg in opts:
if opt == '-h':
print("change_defines.py -i <ifft_option> -n <ntt_option> "\
"-m <index_map_option> -s <sk_option> -d <data_load_option>")
sys.exit()
elif opt in ("-i", "--ifft"):
ifft_set_val = int(arg)
elif opt in ("-n", "--ntt"):
ntt_set_val = int(arg)
elif opt in ("-m", "--index_map"):
index_map_set_val = int(arg)
elif opt in ("-s", "--sk"):
sk_set_val = int(arg)
elif opt in ("-d", "--data_load"):
data_load_set_val = int(arg)
if ifft_set_val < 0:
print("Error: Need to choose an ifft option")
sys.exit()
elif ntt_set_val < 0:
print("Error: Need to choose an ntt option")
sys.exit()
elif index_map_set_val < 0:
print("Error: Need to choose an index_map option")
sys.exit()
elif sk_set_val < 0:
print("Error: Need to choose an sk option")
sys.exit()
elif data_load_set_val < 0:
print("Error: Need to choose a data load option")
sys.exit()
set_ifft_define(ifft_set_val)
set_ntt_define(ntt_set_val)
set_index_map_define(index_map_set_val)
set_sk_define(sk_set_val)
set_data_load_define(data_load_set_val)
if __name__ == '__main__':
main(sys.argv[1:])