-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
41 lines (30 loc) · 922 Bytes
/
run.py
File metadata and controls
41 lines (30 loc) · 922 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
35
36
37
38
39
40
41
import subprocess
import argparse
import compile
def main():
parser = argparse.ArgumentParser()
parser.add_argument("input", type=argparse.FileType("r"))
args = parser.parse_args()
src = compile.build_to_str(target = 'inc', code = args.input.read())
prep = []
cur = ''
for line in src.split('\n'):
if line.startswith('#'):
prep.append(line + '\n')
else:
cur += line + '\n'
with open('defines.h', 'w') as f:
f.writelines(prep)
last = None
iters = 0
while last != cur:
last = cur
with open('file.c', 'w') as f:
f.write('#include "defines.h"\n')
f.write(cur)
cur = subprocess.check_output(['gcc', '-E', '-P', 'file.c']).decode('utf-8')
print('\x1B[2J' + cur, end='')
iters += 1
print('// iters:', iters)
if __name__ == '__main__':
main()