Commit c95db660 authored by Ronny Wichers Schreur's avatar Ronny Wichers Schreur 🏘
Browse files

Use CompAlloc for memory allocation in backend.c

parent 55c2611a
......@@ -2647,17 +2647,10 @@ BEInit (int argc)
{
Assert (!gBEState.be_initialised);
CheckBEEnumTypes ();
CurrentPhase = "Back End";
CurrentModule = "<unknown module>";
CurrentExt = "";
gBEState.be_argv = ConvertAlloc ((argc+1) * sizeof (char *));
gBEState.be_argv [argc] = NULL;
gBEState.be_argc = argc;
gBEState.be_argi = 0;
InitStorage ();
/* +++ remove symbol table from backend */
ScanInitIdentStringTable ();
......@@ -2685,6 +2678,13 @@ BEInit (int argc)
InitCoding ();
InitInstructions ();
CheckBEEnumTypes ();
gBEState.be_argv = ConvertAlloc ((argc+1) * sizeof (char *));
gBEState.be_argv [argc] = NULL;
gBEState.be_argc = argc;
gBEState.be_argi = 0;
gBEState.be_modules = NULL;
gBEState.be_allSymbols = NULL;
gBEState.be_dontCareSymbol = NULL;
......
......@@ -33,117 +33,3 @@ AssertionFailed (char *conditionString, char *file, int line)
Debugger ();
#endif
} /* AssertionFailed */
/*
Memory management
=================
*/
static enum {kMemoryInitClear, kMemoryInitSet} gMemoryInit = kMemoryInitSet;
# define kConvertBufferSize (32 * 1024)
typedef struct convert_buffer ConvertBufferS, *ConvertBufferP;
struct convert_buffer
{
ConvertBufferP cb_next;
char cb_memory [kConvertBufferSize];
};
static void
InvalidateMemory (void *memory, size_t size)
{
char value, *p;
int i;
switch (gMemoryInit)
{
case kMemoryInitClear:
value = 0;
break;
case kMemoryInitSet:
value = ~0;
break;
default:
Assert (False);
break;
}
p = memory;
for (i = 0; i < size; i++)
*p++ = value;
} /* InvalidateMemory */
static ConvertBufferP gFirstBuffer = NULL, gCurrentBuffer = NULL;
static char *gMemory;
static long gBytesLeft = 0;
static void
AllocConvertBuffer (void)
{
ConvertBufferP newBuffer;
newBuffer = (ConvertBufferP) malloc (sizeof (ConvertBufferS));
if (newBuffer == NULL)
FatalCompError ("backendsupport.c", "AllocConvertBuffer", "out of memory");
if (gFirstBuffer == NULL)
gCurrentBuffer = gFirstBuffer = newBuffer;
else
gCurrentBuffer = gCurrentBuffer->cb_next = newBuffer;
gCurrentBuffer->cb_next = NULL;
gBytesLeft = kConvertBufferSize;
gMemory = gCurrentBuffer->cb_memory;
InvalidateMemory (gMemory, kConvertBufferSize);
if (gFirstBuffer == NULL)
gFirstBuffer = gCurrentBuffer;
} /* AllocConvertBuffer */
void
FreeConvertBuffers (void)
{
ConvertBufferP buffer;
buffer = gFirstBuffer;
while (buffer != NULL)
{
ConvertBufferP nextBuffer;
nextBuffer = buffer->cb_next;
InvalidateMemory (buffer, sizeof (ConvertBufferS));
free (buffer);
buffer = nextBuffer;
}
gFirstBuffer = NULL;
gCurrentBuffer = NULL;
gBytesLeft = NULL;
} /* FreeConvertBuffers */
void *
ConvertAlloc (SizeT size)
{
void *memory;
size = (size+3) & ~3;
if (size > gBytesLeft)
AllocConvertBuffer ();
Assert (size <= gBytesLeft);
memory = gMemory;
gBytesLeft -= size;
gMemory += size;
return ((void *) memory);
} /* ConvertAlloc */
......@@ -16,7 +16,7 @@ extern void AssertionFailed (char *conditionString, char *file, int line);
Memory management
=================
*/
extern void FreeConvertBuffers (void);
extern void *ConvertAlloc (SizeT size);
# define FreeConvertBuffers()
# define ConvertAlloc(size) CompAlloc (size)
# define ConvertAllocType(t) ((t*) ConvertAlloc (SizeOf (t)))
# define ArraySize(array) ((unsigned) (sizeof (array) / sizeof (array[0])))
\ No newline at end of file
# define ArraySize(array) ((unsigned) (sizeof (array) / sizeof (array[0])))
\ No newline at end of file
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