7 memuse_list_t *heapusage = NULL;
8 memuse_list_t *stackusage = NULL;
9 funcenum_t *firstenum = NULL;
10 funcenum_t *lastenum = NULL;
11 pstruct_t *firststruct = NULL;
12 pstruct_t *laststruct = NULL;
14 structarg_t *pstructs_getarg(pstruct_t *pstruct, const char *member)
18 for (i=0; i<pstruct->argcount; i++)
20 if (strcmp(pstruct->args[i]->name, member) == 0)
22 return pstruct->args[i];
29 pstruct_t *pstructs_add(const char *name)
31 pstruct_t *p = (pstruct_t *)malloc(sizeof(pstruct_t));
33 memset(p, 0, sizeof(pstruct_t));
34 strcpy(p->name, name);
57 free(p->args[p->argcount]);
68 pstruct_t *pstructs_find(const char *name)
70 pstruct_t *p = firststruct;
74 if (strcmp(p->name, name) == 0)
84 structarg_t *pstructs_addarg(pstruct_t *pstruct, const structarg_t *arg)
89 for (i=0; i<pstruct->argcount; i++)
91 if (strcmp(pstruct->args[i]->name, arg->name) == 0)
93 /* Don't allow dup names */
98 newarg = (structarg_t *)malloc(sizeof(structarg_t));
100 memcpy(newarg, arg, sizeof(structarg_t));
102 if (pstruct->argcount == 0)
104 pstruct->args = (structarg_t **)malloc(sizeof(structarg_t *) * 1);
106 pstruct->args = (structarg_t **)realloc(
108 sizeof(structarg_t *) * (pstruct->argcount + 1));
111 newarg->offs = pstruct->argcount * sizeof(cell);
112 newarg->index = pstruct->argcount;
113 pstruct->args[pstruct->argcount++] = newarg;
118 void funcenums_free()
120 funcenum_t *e, *next;
125 functag_t *tag, *nexttag;
142 funcenum_t *funcenums_find_byval(int value)
144 funcenum_t *e = firstenum;
148 if (e->value == value)
158 funcenum_t *funcenums_add(const char *name)
160 funcenum_t *e = (funcenum_t *)malloc(sizeof(funcenum_t));
162 memset(e, 0, sizeof(funcenum_t));
164 if (firstenum == NULL)
173 strcpy(e->name, name);
174 e->value = pc_addfunctag((char *)name);
179 functag_t *functags_add(funcenum_t *en, functag_t *src)
181 functag_t *t = (functag_t *)malloc(sizeof(functag_t));
183 memcpy(t, src, sizeof(functag_t));
187 if (en->first == NULL)
200 * Creates a new mem usage tracker entry
202 void _push_memlist(memuse_list_t **head)
204 memuse_list_t *newlist = (memuse_list_t *)malloc(sizeof(memuse_list_t));
207 newlist->list_id = (*head)->list_id + 1;
209 newlist->list_id = 0;
211 newlist->prev = *head;
212 newlist->head = NULL;
217 * Pops a heap list but does not free it.
219 memuse_list_t *_pop_save_memlist(memuse_list_t **head)
221 memuse_list_t *oldlist = *head;
222 *head = (*head)->prev;
227 * Marks a memory usage on a memory list
229 int _mark_memlist(memuse_list_t *head, int type, int size)
232 if (type==MEMUSE_STATIC && size==0)
237 if (use && (type==MEMUSE_STATIC)
238 && (use->type == type))
242 use=(memuse_t *)malloc(sizeof(memuse_t));
245 use->prev=head->head;
251 void _reset_memlist(memuse_list_t **head)
253 memuse_list_t *curlist = *head;
254 memuse_list_t *tmplist;
256 memuse_t *curuse = curlist->head;
259 tmpuse = curuse->prev;
263 tmplist = curlist->prev;
272 * Wrapper for pushing the heap list
276 _push_memlist(&heapusage);
280 * Wrapper for popping and saving the heap list
282 memuse_list_t *popsaveheaplist()
284 return _pop_save_memlist(&heapusage);
288 * Wrapper for marking the heap
290 int markheap(int type, int size)
292 return _mark_memlist(heapusage, type, size);
296 * Wrapper for pushing the stack list
300 _push_memlist(&stackusage);
304 * Wrapper for marking the stack
306 int markstack(int type, int size)
308 return _mark_memlist(stackusage, type, size);
312 * Generates code to free all heap allocations on a tracker
314 void _heap_freeusage(memuse_list_t *heap, int dofree)
316 memuse_t *cur=heap->head;
320 if (cur->type == MEMUSE_STATIC)
322 modheap((-1)*cur->size*sizeof(cell));
341 void _stack_genusage(memuse_list_t *stack, int dofree)
343 memuse_t *cur = stack->head;
347 if (cur->type == MEMUSE_DYNAMIC)
352 modstk(cur->size * sizeof(cell));
370 * Pops a heap list and frees it.
374 memuse_list_t *oldlist;
375 assert(heapusage!=NULL);
377 _heap_freeusage(heapusage, 1);
378 assert(heapusage->head==NULL);
380 oldlist=heapusage->prev;
385 void genstackfree(int stop_id)
387 memuse_list_t *curlist = stackusage;
388 while (curlist && curlist->list_id > stop_id)
390 _stack_genusage(curlist, 0);
391 curlist = curlist->prev;
395 void genheapfree(int stop_id)
397 memuse_list_t *curlist = heapusage;
398 while (curlist && curlist->list_id > stop_id)
400 _heap_freeusage(curlist, 0);
401 curlist = curlist->prev;
405 void popstacklist(int codegen)
407 memuse_list_t *oldlist;
408 assert(stackusage != NULL);
412 _stack_genusage(stackusage, 1);
413 assert(stackusage->head==NULL);
416 oldlist = stackusage->prev;
418 stackusage = oldlist;
421 void resetstacklist()
423 _reset_memlist(&stackusage);
428 _reset_memlist(&heapusage);