aboutsummaryrefslogtreecommitdiff
path: root/p9kcc.py
diff options
context:
space:
mode:
Diffstat (limited to 'p9kcc.py')
-rw-r--r--p9kcc.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/p9kcc.py b/p9kcc.py
index b7266f1..bd42b84 100644
--- a/p9kcc.py
+++ b/p9kcc.py
@@ -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)