cc: add -I preprocessor option

This commit is contained in:
Paul Mathieu 2021-03-13 15:44:12 -08:00
parent a3a67105eb
commit e1557ad4b6

View File

@ -1186,12 +1186,18 @@ def parse_args():
default=sys.stdin, help='input file (default: stdin)') default=sys.stdin, help='input file (default: stdin)')
parser.add_argument('--output', '-o', type=argparse.FileType('wb'), parser.add_argument('--output', '-o', type=argparse.FileType('wb'),
default=sys.stdout.buffer, help='output file') default=sys.stdout.buffer, help='output file')
parser.add_argument('-I', dest='include_dirs', action='append',
default=[], help='include dirs')
return parser.parse_args() return parser.parse_args()
def preprocess(fin): def preprocess(fin, include_dirs):
p = subprocess.Popen(CPP, stdin=fin, stdout=subprocess.PIPE) cmd = list(CPP) + [f'-I{x}' for x in include_dirs]
return p.stdout p = subprocess.Popen(cmd, stdin=fin, stdout=subprocess.PIPE)
out, _ = p.communicate()
if p.returncode != 0:
raise RuntimeError(f'preprocessor error')
return io.StringIO(out.decode())
def assemble(text, fout): def assemble(text, fout):
@ -1202,7 +1208,7 @@ def assemble(text, fout):
def main(): def main():
args = parse_args() args = parse_args()
assy = larkparse(preprocess(args.input), debug=args.debug) assy = larkparse(preprocess(args.input, args.include_dirs), debug=args.debug)
if args.assembly: if args.assembly:
args.output.write(assy.encode() + b'\n') args.output.write(assy.encode() + b'\n')
else: else: