Commit b8af0ca5 by Neil Booth Committed by Neil Booth

cpphash.h (struct _cpp_buff, [...]): New.

	* cpphash.h (struct _cpp_buff, _cpp_get_buff, _cpp_release_buff,
	_cpp_extend_buff, _cpp_free_buff): New.
	(struct cpp_reader): New member free_buffs.
	* cppinit.c (cpp_destroy): Free buffers.
	* cpplex.c (new_buff, _cpp_release_buff, _cpp_get_buff,
	_cpp_extend_buff, _cpp_free_buff): New.
	* cpplib.h (struct cpp_options): Remove unused member.
	* cppmacro.c (collect_args): New.  Combines the old parse_arg
	and parse_args.  Use _cpp_buff for memory allocation.
	(funlike_invocation_p, replace_args): Update.

From-SVN: r45827
parent 9c383523
2001-09-26 Neil Booth <neil@daikokuya.demon.co.uk>
* cpphash.h (struct _cpp_buff, _cpp_get_buff, _cpp_release_buff,
_cpp_extend_buff, _cpp_free_buff): New.
(struct cpp_reader): New member free_buffs.
* cppinit.c (cpp_destroy): Free buffers.
* cpplex.c (new_buff, _cpp_release_buff, _cpp_get_buff,
_cpp_extend_buff, _cpp_free_buff): New.
* cpplib.h (struct cpp_options): Remove unused member.
* cppmacro.c (collect_args): New. Combines the old parse_arg
and parse_args. Use _cpp_buff for memory allocation.
(funlike_invocation_p, replace_args): Update.
Wed Sep 26 13:20:51 CEST 2001 Jan Hubicka <jh@suse.cz> Wed Sep 26 13:20:51 CEST 2001 Jan Hubicka <jh@suse.cz>
* final.c (final_scan_insn): Use delete_insn instead of delete_note. * final.c (final_scan_insn): Use delete_insn instead of delete_note.
......
...@@ -72,6 +72,21 @@ struct cpp_pool ...@@ -72,6 +72,21 @@ struct cpp_pool
unsigned int locks; unsigned int locks;
}; };
/* A generic memory buffer. */
typedef struct _cpp_buff _cpp_buff;
struct _cpp_buff
{
struct _cpp_buff *next;
char *base, *cur, *limit;
};
extern _cpp_buff *_cpp_get_buff PARAMS ((cpp_reader *, unsigned int));
extern void _cpp_release_buff PARAMS ((cpp_reader *, _cpp_buff *));
extern _cpp_buff *_cpp_extend_buff PARAMS ((cpp_reader *, _cpp_buff *,
unsigned int));
extern void _cpp_free_buff PARAMS ((_cpp_buff *));
/* List of directories to look for include files in. */ /* List of directories to look for include files in. */
struct search_path struct search_path
{ {
...@@ -254,6 +269,9 @@ struct cpp_reader ...@@ -254,6 +269,9 @@ struct cpp_reader
cpp_pool macro_pool; /* For macro definitions. Permanent. */ cpp_pool macro_pool; /* For macro definitions. Permanent. */
cpp_pool argument_pool; /* For macro arguments. Temporary. */ cpp_pool argument_pool; /* For macro arguments. Temporary. */
/* Memory buffers. */
_cpp_buff *free_buffs;
/* Context stack. */ /* Context stack. */
struct cpp_context base_context; struct cpp_context base_context;
struct cpp_context *context; struct cpp_context *context;
......
...@@ -591,6 +591,7 @@ cpp_destroy (pfile) ...@@ -591,6 +591,7 @@ cpp_destroy (pfile)
_cpp_free_pool (&pfile->ident_pool); _cpp_free_pool (&pfile->ident_pool);
_cpp_free_pool (&pfile->macro_pool); _cpp_free_pool (&pfile->macro_pool);
_cpp_free_pool (&pfile->argument_pool); _cpp_free_pool (&pfile->argument_pool);
_cpp_free_buff (pfile->free_buffs);
for (run = &pfile->base_run; run; run = runn) for (run = &pfile->base_run; run; run = runn)
{ {
......
...@@ -107,6 +107,7 @@ static tokenrun *next_tokenrun PARAMS ((tokenrun *)); ...@@ -107,6 +107,7 @@ static tokenrun *next_tokenrun PARAMS ((tokenrun *));
static cpp_chunk *new_chunk PARAMS ((unsigned int)); static cpp_chunk *new_chunk PARAMS ((unsigned int));
static int chunk_suitable PARAMS ((cpp_pool *, cpp_chunk *, unsigned int)); static int chunk_suitable PARAMS ((cpp_pool *, cpp_chunk *, unsigned int));
static unsigned int hex_digit_value PARAMS ((unsigned int)); static unsigned int hex_digit_value PARAMS ((unsigned int));
static _cpp_buff *new_buff PARAMS ((unsigned int));
/* Utility routine: /* Utility routine:
...@@ -2114,7 +2115,7 @@ cpp_interpret_charconst (pfile, token, warn_multi, traditional, pchars_seen) ...@@ -2114,7 +2115,7 @@ cpp_interpret_charconst (pfile, token, warn_multi, traditional, pchars_seen)
return result; return result;
} }
/* Memory pools. */ /* Memory buffers. */
struct dummy struct dummy
{ {
...@@ -2127,6 +2128,95 @@ struct dummy ...@@ -2127,6 +2128,95 @@ struct dummy
}; };
#define DEFAULT_ALIGNMENT (offsetof (struct dummy, u)) #define DEFAULT_ALIGNMENT (offsetof (struct dummy, u))
#define CPP_ALIGN(size, align) (((size) + ((align) - 1)) & ~((align) - 1))
/* Create a new allocation buffer. */
static _cpp_buff *
new_buff (len)
unsigned int len;
{
_cpp_buff *result;
char *base;
if (len < 4000)
len = 4000;
len = CPP_ALIGN (len, DEFAULT_ALIGNMENT);
base = xmalloc (len + sizeof (_cpp_buff));
result = (_cpp_buff *) (base + len);
result->base = base;
result->cur = base;
result->limit = base + len;
result->next = NULL;
return result;
}
/* Place a chain of unwanted allocation buffers on the free list. */
void
_cpp_release_buff (pfile, buff)
cpp_reader *pfile;
_cpp_buff *buff;
{
_cpp_buff *end = buff;
while (end->next)
end = end->next;
end->next = pfile->free_buffs;
pfile->free_buffs = buff;
}
/* Return a free buffer of size at least MIN_SIZE. */
_cpp_buff *
_cpp_get_buff (pfile, min_size)
cpp_reader *pfile;
unsigned int min_size;
{
_cpp_buff *result, **p;
for (p = &pfile->free_buffs;; p = &(*p)->next)
{
if (*p == NULL || (*p)->next == NULL)
return new_buff (min_size);
result = (*p)->next;
if ((unsigned int) (result->limit - result->base) > min_size)
break;
}
*p = result->next;
result->next = NULL;
result->cur = result->base;
return result;
}
/* Return a buffer chained on the end of BUFF. Copy to it the
uncommitted remaining bytes of BUFF, with at least MIN_EXTRA more
bytes. */
_cpp_buff *
_cpp_extend_buff (pfile, buff, min_extra)
cpp_reader *pfile;
_cpp_buff *buff;
unsigned int min_extra;
{
unsigned int size = min_extra + (buff->limit - buff->cur) * 2;
buff->next = _cpp_get_buff (pfile, size);
memcpy (buff->next->base, buff->cur, buff->limit - buff->cur);
return buff->next;
}
/* Free a chain of buffers starting at BUFF. */
void
_cpp_free_buff (buff)
_cpp_buff *buff;
{
_cpp_buff *next;
for (; buff; buff = next)
{
next = buff->next;
free (buff->base);
}
}
static int static int
chunk_suitable (pool, chunk, size) chunk_suitable (pool, chunk, size)
......
...@@ -236,9 +236,6 @@ struct cpp_options ...@@ -236,9 +236,6 @@ struct cpp_options
/* The language we're preprocessing. */ /* The language we're preprocessing. */
enum c_lang lang; enum c_lang lang;
/* Nonzero means to return spacing characters for stand-alone CPP. */
unsigned char spacing;
/* Non-0 means -v, so print the full set of include dirs. */ /* Non-0 means -v, so print the full set of include dirs. */
unsigned char verbose; unsigned char verbose;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment