tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [Tinycc-devel] Preprocessor output


From: Svein Berge
Subject: RE: [Tinycc-devel] Preprocessor output
Date: Mon, 16 Oct 2006 14:07:30 +0200

> -----Original Message-----
> From: Bernhard Fischer [mailto:address@hidden 
> Sent: Monday, October 16, 2006 9:26 AM
> To: Rob Landley
> Cc: address@hidden; Svein Berge
> Subject: Re: [Tinycc-devel] Preprocessor output
> 
> On Sun, Oct 15, 2006 at 07:40:49PM -0400, Rob Landley wrote:
> >On Saturday 14 October 2006 1:36 pm, Svein Berge wrote:
> >> > -----Original Message-----
> >> > From: Bernhard Fischer [mailto:address@hidden 
> >> > Sent: Saturday, October 14, 2006 6:43 PM
> >> > To: address@hidden
> >> > Cc: address@hidden
> >> > Subject: Re: [Tinycc-devel] Preprocessor output
> >> > 
> >> > On Sat, Oct 14, 2006 at 12:24:58AM +0200, Svein Berge wrote:
> >> > >For my project (www.sourceforge.org/projects/jsext), I need 
> >> > a C compiler
> >> > >(preferrably tiny), but also a C preprocessor. I've added a 
> >> > few lines of
> >> > >code to add the -E option to tcc and a tcc_preprocess 
> >> > function to tcclib.
> >> > >The -E option makes tcc stop after preprocessing and send 
> >> > output to stdout
> >> > >(like gcc does). The tcc_preprocess function in libtcc takes 
> >> > C code as a
> >> > >char * and returns preprocessed C code as a char *.
> >> > >
> >> > >The preprocessor output contains preprocessed code, a list 
> >> > of all constant
> >> > >#defines (that is, those without parameters) and # 
> >> > linenumber "filename"
> >> > >records.
> >> > >
> >> > >Enclosed are the diff files for libtcc.h and tcc.c. I hope 
> >> > this will be
> >> > 
> >> > Sounds useful. Unfortunately your patch doesn't apply to current
> >> > cvs. Could you please send a "diff -u" against current cvs?
> >> > 
> >> > TIA,
> >> > 
> >> > >included in a future release. It may be a useful feature for 
> >> > others, too,
> >> > >adds little code and is backwards-compatible.
> >> 
> >> Right... I worked from release 0.9.23. Here are the diffs 
> against CVS (with
> >> -u).
> 
> Why don't you use a separate PARSE_FLAG instead of the tcc_preprocess
> variable?
> Also fputs(s,stdout) is superfluous. Better make that read puts(s).
> 
> Can't you get rid of these if (tcc_preprocess) changed_file(); by just
> emitting the current tokens (after macro expansion) if e.g. 
> PARSE_FLAG_CPP
> is set? I'd expect this to be smaller and perhaps cleaner, but i admit
> that i didn't try to implement it (yet).

I didn't notice this question on my first reply. Emitting expanded tokens is
just one of three things that -E does: It also prints the file name and line
number each time an #include file is entered or exited (changed_file()), so
that the application which uses tcc as preprocessor is able to report errors
with file names and line numbers. Gcc also does this. For my particular
application, I don't need line numbers, but I think they are more than nice
to have. The third thing -E does is to output #defines. Gcc does this if
only you specify -dD. I considered adding a -d option, but opted against it
to keep patch size down. I'd be only happy if anyone finds ways to clean up
or cut down on the patch size, but I've done my best to keep it clean and
small.

Svein





reply via email to

[Prev in Thread] Current Thread [Next in Thread]