-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtpypp.py
More file actions
executable file
·34 lines (28 loc) · 860 Bytes
/
tpypp.py
File metadata and controls
executable file
·34 lines (28 loc) · 860 Bytes
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
#!/usr/bin/python
import preprocessor
import sys
helpstring = \
'''usage: tpypp inputfile [outputfile]
tiny python preprocessor
(c) 2012 Isaac Evans
flags: --v for verbose mode
if output filename is not specified, it is input filename + '.p'
example macros:
#define TEMP r6
#define SWAP(A, B) mov TEMP, A\\n mov B, A\\n mov TEMP, B\\n
#include "../tests.asm"
#ifdef TEMP
SWAP(TEMP, r2)
.#else
SWAP(r5, r2)
#endif'''
pass_verbose = False
if not 2 <= len(sys.argv) <= 4:
print helpstring
sys.exit(-1)
if len(sys.argv) == 3 and sys.argv[1] == sys.argv[2]:
print 'input file cannot be same as output file'
sys.exit(-1)
if (len(sys.argv) == 3 and sys.argv[2] == '--v') or (len(sys.argv) == 4 and sys.argv[3] == '--v'):
pass_verbose = True
preprocessor.preprocessFile(sys.argv[1], None if len(sys.argv) != 3 else sys.argv[2], pass_verbose)