forked from vojone/IFJ21
-
Notifications
You must be signed in to change notification settings - Fork 0
/
perftest_generator.py
134 lines (104 loc) · 3.41 KB
/
perftest_generator.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
#Generator of huge amount of functions and its declarations to make
#performance tests of compiler (especially symbol table)
import array as arr
import random
print("require \"ifj\"")
print("")
number_of_func_declarations = 10000
number_of_only_def_functions = 100
max_num_of_returns = 100
max_num_of_params = 200
max_num_of_locals = 200
data_types = ["integer", "nil", "string", "number"]
fname = "a"
#Function declaration generator
functions = []
for i in range(0, number_of_func_declarations):
function = []
print("global", fname, ": function(", end="")
function.append(fname)
num_of_params = random.randint(0, max_num_of_params)
function_p = []
#Parameter generator
for u in range(0, num_of_params):
if u != 0:
print(", ", end="")
cur_type = random.choice(data_types)
print(cur_type, end="")
function_p.append(cur_type)
print(")", end="")
function.append(function_p)
#Generator of return values
num_of_ret = random.randint(0, max_num_of_returns)
function_r = []
for u in range(0, num_of_ret):
if u != 0:
print(", ", end="")
else:
print(" : ", end="")
cur_type = random.choice(data_types)
print(cur_type, end="")
function_r.append(cur_type)
function.append(function_r)
#Local variables generator
num_of_locals = random.randint(0, max_num_of_locals)
function_l = []
l_index = 0
for u in range(0, num_of_locals):
cur_loc = []
cur_name = "locvar" + str(l_index)
cur_type = random.choice(data_types)
cur_loc.append(cur_name)
cur_loc.append(cur_type)
l_index += 1
function_l.append(cur_loc)
function.append(function_l)
#Generating new func name
new_fname = ""
char_cnt = 1
for c in fname:
if ord(c) < ord("z"):
c = chr(ord(c) + 1)
new_fname += c
else:
new_fname += c
if char_cnt == len(fname):
new_fname = fname + "a"
char_cnt += 1
fname = new_fname
#Saving function with its paramters and returns for print definition and fcall
functions.append(function)
print("")
print("\n\n")
#Generator of function definitions
for func in functions:
if random.randint(0,1) == 1 and number_of_only_def_functions > 0:
print("function f" + str(number_of_only_def_functions) + "() \nend \n")
print("")
number_of_only_def_functions -= 1
print("function " + func[0] + "(", end="")
param_ind = 0
for param in func[1]:
if param_ind != 0:
print(", ", end="")
print("p" + str(param_ind) + " : ", end="")
print(param, end="")
param_ind += 1
print(")", end="")
return_ind = 0
for return_val in func[2]:
if return_ind != 0:
print(", ", end="")
else:
print(" : ", end="")
print(return_val, end="")
return_ind += 1
print("")
for local in func[3]:
print("local " + local[0] + " : " + local[1])
print("end")
print()
#Define the rest of only defined functions
while number_of_only_def_functions > 0:
print("function f" + str(number_of_only_def_functions) + "() \nend \n")
number_of_only_def_functions -= 1