diff --git a/tools/cc.py b/tools/cc.py index b0e2406..07a8576 100644 --- a/tools/cc.py +++ b/tools/cc.py @@ -1186,12 +1186,18 @@ def parse_args(): default=sys.stdin, help='input file (default: stdin)') parser.add_argument('--output', '-o', type=argparse.FileType('wb'), default=sys.stdout.buffer, help='output file') + parser.add_argument('-I', dest='include_dirs', action='append', + default=[], help='include dirs') return parser.parse_args() -def preprocess(fin): - p = subprocess.Popen(CPP, stdin=fin, stdout=subprocess.PIPE) - return p.stdout +def preprocess(fin, include_dirs): + cmd = list(CPP) + [f'-I{x}' for x in include_dirs] + 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): @@ -1202,7 +1208,7 @@ def assemble(text, fout): def main(): 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: args.output.write(assy.encode() + b'\n') else: