tinycc-devel
[Top][All Lists]
Advanced

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

Re: [Tinycc-devel] uint8_t, unsigned char, and char for BufferedFile (a


From: fabrice . bellard
Subject: Re: [Tinycc-devel] uint8_t, unsigned char, and char for BufferedFile (and others)
Date: Sat, 03 May 2003 12:32:47 +0200 (CEST)
User-agent: IMP/PHP IMAP webmail program 2.2.6

Hi,

My exact plan for BufferedFile is to make it more generic by adding a better 
support when a string is given as input. I really think uint8_t is the best 
type for the buffer as it is well defined on every CPU. 

The global variable 'ch' will be suppressed ASAP as it is there only 
for 'legacy' support. Most important parsing code in TCC only use 'file-
>buf_ptr' to go faster. My last patches for better string support suppressed 
most of the difficult to remove 'ch' usage.

I think some patches in BufferedFile will be done when the gcc '-E' option 
support will be added.

Fabrice.

Quoting "Peter \"Firefly\" Lund" <address@hidden>:

> The buffered file implementation in TinyCC revolves around the
> BufferedFile type.
> 
> #define IO_BUF_SIZE 8192
> 
> typedef struct BufferedFile {
>     uint8_t *buf_ptr;
>     uint8_t *buf_end;
>     int fd;
>     int line_num;    /* current line number - here to simply code */
>     int ifndef_macro;  /* #ifndef macro / #endif search */
>     int ifndef_macro_saved; /* saved ifndef_macro */
>     int *ifdef_stack_ptr; /* ifdef_stack value at the start of the file
> */
>     char inc_type;          /* type of include */
>     char inc_filename[512]; /* filename specified by the user */
>     char filename[1024];    /* current filename - here to simplify code
> */
>     unsigned char buffer[IO_BUF_SIZE + 1]; /* extra size for CH_EOB
> char
> */
> } BufferedFile;
> 
> #define CH_EOB   '\\'       /* end of buffer or '\0' char in file */
> #define CH_EOF   (-1)   /* end of file */
> 
> ...
> static int ch, tok;
> 
> 
> It contains an 8K buffer that is used most of the time.  In some cases
> buf_ptr (and buf_end) are set to other character arrays outside of
> BufferedFile.  This happens in tcc_compile_string() and
> tcc_define_symbol().
> 
> The value of CH_EOF must be distinct from all possible values for a
> character element in the buffer.  I guess that is why the value -1 and
> the
> type unsigned char (and uint8_t) are chosen.
> 
> Other combinations are possible: 128/-128 and (signed) char, for
> example.
> 
> Sometimes a buf_ptr or buffer field is passed as a parameter to
> functions
> that really want to take char *'s:
> 
>   pstrcpy(), pstrcat(), strlen()
> 
> 
> I would prefer to keep pstrcpy()/pstrcat()/strlen() as taking char
> *'s,
> change buffer, buf_ptr, and buf_end to use char's too and change CH_EOF
> to
> -128.
> 
> Even on a 9-bit machine where a signed char can hold -256 .. 255 this
> ought to work as long as we only try to read ASCII source files.
> 
> Comments?




reply via email to

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