-
Notifications
You must be signed in to change notification settings - Fork 0
/
regexParser.py
98 lines (79 loc) · 2.78 KB
/
regexParser.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
import re
__FLOAT_REG=r"\d+.\d+|\d+"
__SIZE_REG=r"\d+[p|n]"
__VARIABLE_NAME=r"[a-zA-Z_\d]"
def base_parser(regex, line):
matches = re.finditer(regex, line)
groups = []
for match in matches:
for groupNum in range(0, len(match.groups())):
groupNum = groupNum + 1
groups.append(match.group(groupNum))
return groups
def parse_guassian_distribution(line):
regex = r".param\s+({variable}+)\s*=\s*(GAUSS)\s*\(\s*({float})\s*,\s*({float})\s*,\s*({float})\s*\)".format(float=__FLOAT_REG, variable=__VARIABLE_NAME)
return base_parser(regex, line)
def parse_monte(line):
regex = r"(.tran\s+{size}\s+{size})\s+sweep\s+monte\s*=\s*(\d+)".format(size=__SIZE_REG)
return base_parser(regex, line)
def parse_sizing_monte(line):
regex = r"([\w\d\s]+)([L|W]\s*=)\s*(\d+[p|n]*)\s*\*\s*([a-zA-Z_\d]+)"
return base_parser(regex, line)
def parse_tran_size(line):
regex = r"(\d+)([n|p])"
return base_parser(regex, line)
def parse_include(line):
regex = r"(.include\s*)(')([\w.]*')"
return base_parser(regex, line)
def parse_aging_part(content):
regex = r"([\s\S]*\*<---BeginAging--->)([\s\S]*)?(\*<---EndAging--->[\s\S]*)"
return base_parser(regex, content)
def parse_measure(line):
regex = r".measure\s*tran\s*([a-zA-Z_\d]*)"
return base_parser(regex, line)
def parse_lis_delay(variable_names, line):
variables = '|'.join(variable_names)
regex = r"({vars})\s*=\s*(\d+.\d+|\d+)([p|n])".format(vars=variables)
return base_parser(regex, line)
def parse_jobs(line):
regex = r"(aborted)"
# return false on abort
# return true on conclude
if len(base_parser(regex, line)):
return False
else:
return True
if __name__ == "__main__":
test_str = ".param myVariable_23 = GAUSS (1 , 0.20 , 1)"
g_dist = parse_guassian_distribution(test_str)
print(g_dist)
test_str = ".tran 10p 40n sweep monte=10"
monte = parse_monte(test_str)
print(monte)
test_str = ("M1 ss ina 0 0 nmos L=32n*c W=64n*d\n")
monte_s = parse_sizing_monte(test_str)
print(monte_s)
test_str = "32n"
size = parse_tran_size(test_str)
print(size)
test_str = ".include '32nm_LP.pm'"
include = parse_include(test_str)
print(include)
test_str = ".measure tran tpd param='(tlh+thl/2)'"
measure = parse_measure(test_str)
print(measure)
test_str = "tlh= 29.7972p targ= 1.0323n trig= 1.0025n"
delay = parse_lis_delay(['tlh', 'thl', 'tpd'], test_str)
print(delay)
test_str = "hspice job aborted"
job = parse_jobs(test_str)
if job:
print("job concluded")
else:
print("job aborted")
test_str = "hspice job concluded"
job = parse_jobs(test_str)
if job:
print("job concluded")
else:
print("job aborted")