int offset; /* location in globals */
} globals;
VECTOR_MAKE(globals, assembly_constants);
+
+void asm_clear() {
+ size_t i = 0;
+ for (; i < assembly_constants_elements; i++)
+ mem_d(assembly_constants_data[i].name);
+ mem_d(assembly_constants_data);
+}
void asm_parse(FILE *fp) {
char *data = NULL;
printf("%li: Invalid statement, expression, or decleration\n", line);
end:
- //free(data);
mem_d(data);
line ++;
}
+ asm_clear();
}
//===================================================================
void *util_memory_a(unsigned int, unsigned int, const char *);
void util_memory_d(void *, unsigned int, const char *);
+void util_meminfo ();
+
char *util_strdup (const char *);
char *util_strrq (char *);
char *util_strrnl (char *);
} \
void *temp = mem_a(N##_allocated * sizeof(T)); \
if (!temp) { \
- free(temp); \
+ mem_d(temp); \
return -1; \
} \
memcpy(temp, N##_data, (N##_elements * sizeof(T))); \
+ mem_d(N##_data); \
N##_data = (T*)temp; \
} \
N##_data[N##_elements] = element; \
* Each paramater incerements by 3 since vector types hold
* 3 components (x,y,z).
*/
-#define OFS_NULL 0
-#define OFS_RETURN 1
-#define OFS_PARM0 (OFS_RETURN+3)
-#define OFS_PARM1 (OFS_PARM0 +3)
-#define OFS_PARM2 (OFS_PARM1 +3)
-#define OFS_PARM3 (OFS_PARM2 +3)
-#define OFS_PARM4 (OFS_PARM3 +3)
+#define OFS_NULL 0
+#define OFS_RETURN 1
+#define OFS_PARM0 (OFS_RETURN+3)
+#define OFS_PARM1 (OFS_PARM0 +3)
+#define OFS_PARM2 (OFS_PARM1 +3)
+#define OFS_PARM3 (OFS_PARM2 +3)
+#define OFS_PARM4 (OFS_PARM3 +3)
#define OFS_PARM5 (OFS_PARM4 +3)
#define OFS_PARM6 (OFS_PARM5 +3)
#define OFS_PARM7 (OFS_PARM6 +3)
asm_init ("test.qs", &fp);
asm_parse(fp);
asm_close(fp);
+ util_meminfo();
return 0;
}
}
compile_constant_debug();
lex_reset(file);
+ /* free constants */
+ {
+ size_t i;
+ for (; i < compile_constants_elements; i++) {
+ mem_d(compile_constants_data[i].name);
+ mem_d(compile_constants_data[i].string);
+ }
+ mem_d(compile_constants_data);
+ }
return 1;
}
#include <stdarg.h>
#include <errno.h>
#include "gmqcc.h"
-
+
+unsigned long long mem_ab = 0;
+unsigned long long mem_db = 0;
+unsigned long long mem_at = 0;
+unsigned long long mem_dt = 0;
+
struct memblock_t {
const char *file;
unsigned int line;
};
void *util_memory_a(unsigned int byte, unsigned int line, const char *file) {
- struct memblock_t *data = malloc(sizeof(struct memblock_t) + byte);
+ struct memblock_t *info = malloc(sizeof(struct memblock_t) + byte);
+ void *data =(void*)((uintptr_t)info+sizeof(struct memblock_t));
if (!data) return NULL;
- data->line = line;
- data->byte = byte;
- data->file = file;
+ info->line = line;
+ info->byte = byte;
+ info->file = file;
- util_debug("MEM", "allocation: %08u (bytes) at %s:%u\n", byte, file, line);
- return (void*)((uintptr_t)data+sizeof(struct memblock_t));
+ util_debug("MEM", "allocation: %08u (bytes) address 0x%08X @ %s:%u\n", byte, data, file, line);
+ mem_at++;
+ mem_ab += info->byte;
+ return data;
}
void util_memory_d(void *ptrn, unsigned int line, const char *file) {
void *data = (void*)((uintptr_t)ptrn-sizeof(struct memblock_t));
struct memblock_t *info = (struct memblock_t*)data;
- util_debug("MEM", "released: %08u (bytes) at %s:%u\n", info->byte, file, line);
+ util_debug("MEM", "released: %08u (bytes) address 0x%08X @ %s:%u\n", info->byte, data, file, line);
+ mem_db += info->byte;
+ mem_dt++;
free(data);
}
+void util_meminfo() {
+ util_debug("MEM", "Memory information:\n\
+ Total allocations: %llu\n\
+ Total deallocations: %llu\n\
+ Total allocated: %llu (bytes)\n\
+ Total deallocated: %llu (bytes)\n",
+ mem_at, mem_dt,
+ mem_ab, mem_db
+ );
+}
+
#ifndef mem_d
#define mem_d(x) util_memory_d((x), __LINE__, __FILE__)
#endif
chr = *n + *lineptr - pos;
strcpy(tmp,*lineptr);
-
if (!(*lineptr = tmp))
return -1;