diff options
| author | Samuel Lidén Borell <samuel@kodafritt.se> | 2026-03-08 11:13:24 +0100 |
|---|---|---|
| committer | Samuel Lidén Borell <samuel@kodafritt.se> | 2026-03-08 11:13:24 +0100 |
| commit | 19d05f43d03e038e0eb5a7140eb93bcbddac85f83ca79845bc0639ef1cd758e5 (patch) | |
| tree | 97e46d76569c7bcde8b491d3eb98d7ddf0a87dd783bb7b79659b4f6be41f5365 /p9kcc.py | |
| parent | 393cbe72195d77e1b9f24b572618891a22d413356eb35714da832e2156381c2c (diff) | |
| download | p9kcc-main.tar.gz p9kcc-main.zip | |
Handle -o (output) option for -E (preprocess only)main
Diffstat (limited to 'p9kcc.py')
| -rw-r--r-- | p9kcc.py | 14 |
1 files changed, 10 insertions, 4 deletions
@@ -207,7 +207,9 @@ class Ds9kCCompiler: argv = sys.argv[1:] self.options = self.arg_parser.parse_args(argv) if not self.options.output: - if self.options.compile_to_obj: + if self.options.preprocess_only: + self.options.output = '-' + elif self.options.compile_to_obj: self.options.output = self.options.sourcefiles[-1].removesuffix(".c") + ".o" else: self.options.output = "a.out" @@ -852,13 +854,17 @@ class Ds9kCCompiler: def run(self): self.predefines() if self.options.preprocess_only: - # TODO write to output (-o) - print(format(self.all_tokens())) + preprocessed_code = format(self.all_tokens()) + if self.options.output == '-': + outfile = sys.stdout + else: + outfile = open(self.options.output, 'w') + print(preprocessed_code, file=outfile) return - # TODO it = self.all_tokens() while self.parse_decl_or_expr(None, it): pass + # TODO generate output code def yield_tokens(self, s): it = iter(s) |
