From ffc76d36f985817a86ff73822e0ed268226737dd Mon Sep 17 00:00:00 2001 From: lemon Date: Fri, 17 Oct 2025 18:00:52 +0200 Subject: add -E preprocessing option --- c.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'c.c') diff --git a/c.c b/c.c index 2d3b3cf..58a3147 100644 --- a/c.c +++ b/c.c @@ -4017,20 +4017,34 @@ docomp(struct comp *cm) } } -void -ccomp(const char *file) +static void +initcm(struct comp *cm, const char *file) { enum { N = 1<<12 }; static union { char m[sizeof(struct arena) + N]; struct arena *_align; } amem[2]; - struct comp cm = {0}; - const char *err = initlexer(&cm.lx, NULL, file); + const char *err = initlexer(&cm->lx, NULL, file); if (err) fatal(NULL, "Cannot open %'s: %s", file, err); - cm.fnarena = (void *)amem[0].m; - cm.fnarena->cap = N; - cm.exarena = (void *)amem[1].m; - cm.exarena->cap = N; + cm->fnarena = (void *)amem[0].m; + cm->fnarena->cap = N; + cm->exarena = (void *)amem[1].m; + cm->exarena->cap = N; +} + +void +ccomp(const char *file) +{ + struct comp cm = {0}; + initcm(&cm, file); docomp(&cm); } +void +cpp(struct wbuf *out, const char *file) +{ + struct comp cm = {0}; + initcm(&cm, file); + lexerdump(&cm.lx, out); +} + /* vim:set ts=3 sw=3 expandtab: */ -- cgit v1.2.3