forked from edf-hpc/verrou
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerateInstrumentOp_impl.py
executable file
·56 lines (47 loc) · 1.98 KB
/
generateInstrumentOp_impl.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
#!/usr/bin/python3
import sys
includePatternHard="""
#define bcName(OP) "vr_verrou_ROUNDING"#OP, vr_verrou_ROUNDING##OP
#define bcNameWithCC(OP) "vr_verrou_ROUNDING"#OP, vr_verrou_ROUNDING##OP
#include "vr_instrumentOp_impl.h"
#undef bcName
#undef bcNameWithCC
"""
includePatternSoft="""
#define bcName(OP) "vr_verrou_ROUNDING_soft"#OP, vr_verrou_ROUNDING_soft##OP
#define bcNameWithCC(OP) "vr_verrou_ROUNDING_soft"#OP, vr_verrou_ROUNDING_soft##OP
#include "vr_instrumentOp_impl.h"
#undef bcName
#undef bcNameWithCC
"""
def generate(fileName,roundingList):
handler=open(fileName,"w")
handler.write("// Generated by %s\n"%( str(sys.argv)[1:-1] ))
for rounding in roundingList:
roundingMode=rounding[0]
checkStr="if(vr.roundingMode==VR_"+roundingMode
for checkRounding in rounding[1:]:
checkStr+= " || vr.roundingMode==VR_" +checkRounding
checkStr+="){"
includeMacroHard=includePatternHard.replace("ROUNDING",roundingMode)
includeMacroSoft=includePatternSoft.replace("ROUNDING",roundingMode)
includeMacro="""
\tif(vr.instrument_soft_used){""" + includeMacroSoft+"\t}else{"+includeMacroHard+"\t}\n"
strWrite=checkStr + includeMacro+ "}\n"
if roundingMode=="NEAREST":
strWrite=checkStr + includePatternHard.replace("ROUNDING",roundingMode)+"}\n"
# print(strWrite)
handler.write(strWrite)
if __name__=="__main__":
roundingList=[["NEAREST","NATIVE"],
["RANDOM"], ["AVERAGE"],
["RANDOM_DET"],["AVERAGE_DET"],
["RANDOM_COMDET"],["AVERAGE_COMDET"],
["RANDOM_SCOMDET"],["AVERAGE_SCOMDET"],
["SR_MONOTONIC"],["SR_SMONOTONIC"],
["UPWARD"],["DOWNWARD"],["ZERO"],
["AWAY_ZERO"],["FARTHEST"],
["PRANDOM"], ["PRANDOM_DET"], ["PRANDOM_COMDET"]
]
fileName="vr_instrumentOp_impl_generated.h"
generate(fileName,roundingList)