mirror of
https://github.com/ksherlock/hystricomorph.git
synced 2024-06-02 20:41:29 +00:00
-E flag runs pre-processor on input.
This commit is contained in:
parent
ee8c65b4c5
commit
1fe3f297e8
|
@ -2,6 +2,7 @@ import getopt
|
||||||
import sys
|
import sys
|
||||||
import re
|
import re
|
||||||
from functools import reduce
|
from functools import reduce
|
||||||
|
import subprocess
|
||||||
|
|
||||||
from asm import Assembler
|
from asm import Assembler
|
||||||
|
|
||||||
|
@ -9,6 +10,7 @@ flag_i = False
|
||||||
flag_l = False
|
flag_l = False
|
||||||
flag_v = False
|
flag_v = False
|
||||||
flag_o = None
|
flag_o = None
|
||||||
|
flag_E = False
|
||||||
|
|
||||||
|
|
||||||
def str_to_int(cc):
|
def str_to_int(cc):
|
||||||
|
@ -190,6 +192,17 @@ def read_file(path):
|
||||||
with open(path) as f:
|
with open(path) as f:
|
||||||
return read_data(f, path)
|
return read_data(f, path)
|
||||||
|
|
||||||
|
def read_cpp(infile):
|
||||||
|
args = ["cpp"]
|
||||||
|
if infile: args.append(infile)
|
||||||
|
|
||||||
|
x = subprocess.run(args, stdout=subprocess.PIPE, encoding='ascii')
|
||||||
|
if x.returncode:
|
||||||
|
sys.exit(s.returncode)
|
||||||
|
|
||||||
|
lines = x.stdout.split("\n")
|
||||||
|
return read_data(lines, "<cpp-stdin>")
|
||||||
|
|
||||||
|
|
||||||
def init_maps():
|
def init_maps():
|
||||||
|
|
||||||
|
@ -234,7 +247,7 @@ def main():
|
||||||
|
|
||||||
|
|
||||||
argv = sys.argv[1:]
|
argv = sys.argv[1:]
|
||||||
opts, args = getopt.getopt(argv, "ivo:le")
|
opts, args = getopt.getopt(argv, "ivo:leE")
|
||||||
|
|
||||||
# flags = {}
|
# flags = {}
|
||||||
# for k, v in opts: flags[k] = v
|
# for k, v in opts: flags[k] = v
|
||||||
|
@ -247,6 +260,7 @@ def main():
|
||||||
elif k == '-o': flag_o = v
|
elif k == '-o': flag_o = v
|
||||||
elif k == '-v': flag_v = True
|
elif k == '-v': flag_v = True
|
||||||
elif k == '-l': flag_l = True
|
elif k == '-l': flag_l = True
|
||||||
|
elif k == '-E': flag_E = True
|
||||||
else:
|
else:
|
||||||
usage()
|
usage()
|
||||||
|
|
||||||
|
@ -256,10 +270,19 @@ def main():
|
||||||
name = args[0]
|
name = args[0]
|
||||||
data = {}
|
data = {}
|
||||||
|
|
||||||
if len(args) == 1 or args[1] == "-":
|
if len(args) == 2 and args[1] == "-":
|
||||||
data = read_stdin()
|
args.pop()
|
||||||
else:
|
|
||||||
|
if flag_E:
|
||||||
|
infile = None
|
||||||
|
if len(args) == 2:
|
||||||
|
infile = args.pop()
|
||||||
|
data = read_cpp(infile)
|
||||||
|
|
||||||
|
elif len(args) == 2:
|
||||||
data = read_file(args[1])
|
data = read_file(args[1])
|
||||||
|
else:
|
||||||
|
data = read_stdin()
|
||||||
|
|
||||||
process(data, name)
|
process(data, name)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user