-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmac4.py
More file actions
executable file
·97 lines (71 loc) · 2.37 KB
/
mac4.py
File metadata and controls
executable file
·97 lines (71 loc) · 2.37 KB
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
#!/usr/bin/python
import sys
#This file is always supposed to be an entry point, and
#thus basically everything in it is in main
if __name__ == "__main__":
#import global variables
import globalVars
#import the core functionality
import macroExpand
#Buffer for output instructions
IBuffer = []
#Buffer for output data
DBuffer = []
#parse argument vector
if len(sys.argv) < 2:
print "no input file specified!"
quit()
if len(sys.argv) < 3:
print "no output file specified!"
quit()
#Start the queue
globalVars.FList.append(sys.argv[1])
#open the appropriate files
outFile = open(sys.argv[2], "w")
#deal with files
while globalVars.FIndex < len(globalVars.FList):
#first file breaks, everything breaks
#other files break, not the worst thing
try:
inFile = open(globalVars.FList[globalVars.FIndex], "r")
except OSError:
if FIndex > 0:
print "Serious exception: Included file not opened! " + globalVars.FList[gobalVars.FIndex] + '\n'
print "Proceeding with other files. Output may not be valid.\n"
else:
print "Fatal exception: Base file not opened!"
raise
#keep enforcing the organisation with files, but not between them.
globalVars.DataFields = False
#comments good
DBuffer.append("\n;Start of data from " + globalVars.FList[globalVars.FIndex] + "\n")
IBuffer.append("\n;Start of code from " + globalVars.FList[globalVars.FIndex] + "\n")
#use the functions we defined above
for line in inFile.readlines():
expandedLine = macroExpand.expandline(line.split())
for expLine in expandedLine:
if(globalVars.DataFields):
DBuffer.append(expLine)
else:
IBuffer.append(expLine)
#comments foamy
DBuffer.append("\n;End of data from " + globalVars.FList[globalVars.FIndex])
IBuffer.append("\n;End of code from " + globalVars.FList[globalVars.FIndex])
#housekeeping
globalVars.FIndex += 1
inFile.close()
#Add the one line of INF header that we care about
outFile.write("INF " + str(globalVars.BAddr) + '\n')
#dump the buffers
for ILine in IBuffer:
outFile.write(ILine + '\n')
outFile.write(";Start of data sections")
for DLine in DBuffer:
outFile.write(DLine + '\n')
#declare macro scratch space
if globalVars.memUsed > 0:
outFile.write("\n;memory space used by macros\n")
outFile.write("macro: .data " + str(globalVars.memUsed) + "\n\n")
#clean up after ourselves
outFile.close()
#done!