-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpredefExpand.py
76 lines (68 loc) · 3.48 KB
/
predefExpand.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
def predefExpand (code):
predef_file = file("predef.txt")
predef_map = {}
temp = predef_file.read()
lines = temp.split ("\n")
predef_file.close()
output = []
j=0
for line in lines:
if "#" in line:
list = []
for i in range(len(line.split("#"))-1):
list.append(line.split("#")[i+1].lstrip().rstrip())
predef_map[line.split("#")[0].upper().lstrip().rstrip()] = list
for i in range(len(code)):
if 'ADDRR' in code[i]:
if ':' in code[i]:
arg1=code[i].split(':')[1].lstrip().rstrip().split(' ')[1].split(',')[0].lstrip().rstrip()
arg2=code[i].split(':')[1].lstrip().rstrip().split(' ')[1].split(',')[1].lstrip().rstrip()
output.append(code[i].split(':')[0].lstrip().rstrip()+': MOV A,'+arg1)
output.append("ADD "+arg2)
output.append("MOV "+arg1+",A")
else:
arg1=code[i].lstrip().rstrip().split(' ')[1].split(',')[0].lstrip().rstrip()
arg2=code[i].lstrip().rstrip().split(' ')[1].split(',')[1].lstrip().rstrip()
output.append("MOV A,"+arg1)
output.append("ADD "+arg2)
output.append("MOV "+arg1+",A")
elif 'SUBRR' in code[i]:
if ':' in code[i]:
arg1=code[i].split(':')[1].lstrip().rstrip().split(' ')[1].split(',')[0].lstrip().rstrip()
arg2=code[i].split(':')[1].lstrip().rstrip().split(' ')[1].split(',')[1].lstrip().rstrip()
output.append(code[i].split(':')[0].lstrip().rstrip()+': MOV A,'+arg1)
output.append("SUB "+arg2)
output.append("MOV "+arg1+",A")
else:
arg1=code[i].lstrip().rstrip().split(' ')[1].split(',')[0].lstrip().rstrip()
arg2=code[i].lstrip().rstrip().split(' ')[1].split(',')[1].lstrip().rstrip()
output.append("MOV A,"+arg1)
output.append("SUB "+arg2)
output.append("MOV "+arg1+",A")
else:
if ":" in code[i]:
keyword = code[i].lstrip().rstrip().split(":")[1].lstrip().rstrip().split(" ")[0].lstrip().rstrip()
else:
keyword = code[i].lstrip().rstrip().split(" ")[0]
keyword = keyword.lstrip().rstrip()
if keyword in predef_map:
counter = 0
counter = len(predef_map[keyword])
if ':' in code[i]:
if "FACTORIAL" in keyword:
argument = code[i].split(':')[1].lstrip().rstrip().split(" ")[1].lstrip().rstrip()
output.append("VARIABILITY: EQU "+argument)
output.append(code[i].split(':')[0].lstrip().rstrip()+': '+predef_map[keyword][0])
else:
if "FACTORIAL" in keyword:
argument = code[i].lstrip().rstrip().split(" ")[1].lstrip().rstrip()
print argument
output.append("VARIABILITY: EQU "+argument)
output.append(predef_map[keyword][0])
for k in range(1, counter):
output.append(predef_map[keyword][k])
j+=1
else:
output.append(code[i])
j+=1
return output