]> de.git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
code.c, info.txt
authorDale Weiler <killfieldengine@gmail.com>
Tue, 10 Apr 2012 09:09:55 +0000 (05:09 -0400)
committerDale Weiler <killfieldengine@gmail.com>
Tue, 10 Apr 2012 09:09:55 +0000 (05:09 -0400)
code.c [new file with mode: 0644]
info.txt [new file with mode: 0644]
typedef.c
util.c [new file with mode: 0644]

diff --git a/code.c b/code.c
new file mode 100644 (file)
index 0000000..ef33d31
--- /dev/null
+++ b/code.c
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2012 
+ *     Dale Weiler
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is furnished to do
+ * so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#include "gmqcc.h"
+/*
+ * This file is empty:  This is where codegen will take place:  Once the
+ * parser is completed, right now it on;y creates parse trees.  Syntax
+ * checking and other convoluted things on the parse tree need to take
+ * place much like a parser.
+ */
diff --git a/info.txt b/info.txt
new file mode 100644 (file)
index 0000000..8916a97
--- /dev/null
+++ b/info.txt
@@ -0,0 +1,12 @@
+there are 3 accessible memory zones -
+globals:
+  array of 32bit ints/floats, mixed, LE,
+entities:
+  structure is up to the engine but the fields are a linear array
+  of mixed ints/floats, there are globals referring to the offsets
+  of these in the entity struct so there are ADDRESS and STOREP and
+  LOAD instructions that use globals containing field offsets.
+strings:
+  a static array in the progs.dat, with file parsing creating
+  additional constants, and some engine fields are mapped by 
+  address as well to unique string offsets
index e84300a88a0c2c8ac801d266342431348c14ebaf..dcc4e20b377a37a498859cb151d1773621ad1d53 100644 (file)
--- a/typedef.c
+++ b/typedef.c
@@ -25,6 +25,7 @@
 #include <limits.h>
 #include "gmqcc.h"
 static typedef_node *typedef_table[1024];
+
 void typedef_init() {
        int i;
        for(i = 0; i < sizeof(typedef_table)/sizeof(*typedef_table); i++)
@@ -56,14 +57,18 @@ typedef_node *typedef_find(const char *s) {
 
 void typedef_clear() {
        int i;
-       for(i = 1024; i > 0; i--)
-               if(typedef_table[i])
+       for(i = 1024; i > 0; i--) {
+               if(typedef_table[i]) {
+                       mem_d(typedef_table[i]->name);
                        mem_d(typedef_table[i]);
+               }
+       }
 }
 
 int typedef_add(const char *from, const char *to) {
        unsigned int  hash = typedef_hash(to);
        typedef_node *find = typedef_table[hash];
+       
        if (find)
                return error(ERROR_PARSE, "typedef for %s already exists or conflicts\n", to);
        
@@ -82,7 +87,7 @@ int typedef_add(const char *from, const char *to) {
                typedef_node *find = typedef_table[typedef_hash(from)];
                if (find) {
                        typedef_table[hash]       = mem_a(sizeof(typedef_node));
-                       typedef_table[hash]->name = strdup(find->name);
+                       typedef_table[hash]->name = util_strdup(find->name);
                        return -100;
                }
        }
diff --git a/util.c b/util.c
new file mode 100644 (file)
index 0000000..5261063
--- /dev/null
+++ b/util.c
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2012 
+ *     Dale Weiler
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is furnished to do
+ * so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include "gmqcc.h"
+struct memblock_t {
+       const char  *file;
+       unsigned int line;
+       unsigned int byte;
+};
+
+void *util_memory_a(unsigned int byte, unsigned int line, const char *file) {
+       struct memblock_t *data = malloc(sizeof(struct memblock_t) + byte);
+       if (!data) return NULL;
+       data->line = line;
+       data->byte = byte;
+       data->file = file;
+       
+       printf("[MEM] allocation: %08u (bytes) at %s:%u\n", byte, file, line);
+       return (void*)((uintptr_t)data+sizeof(struct memblock_t));
+}
+
+void util_memory_d(void *ptrn, unsigned int line, const char *file) {
+       if (!ptrn) return;
+       void              *data = (void*)((uintptr_t)ptrn-sizeof(struct memblock_t));
+       struct memblock_t *info = (struct memblock_t*)data;
+       
+       printf("[MEM] released:   %08u (bytes) at %s:%u\n", info->byte, file, line);
+       free(data);
+}
+
+#ifndef mem_d
+#define mem_d(x) util_memory_d((x), __LINE__, __FILE__)
+#endif
+#ifndef mem_a
+#define mem_a(x) util_memory_a((x), __LINE__, __FILE__)
+#endif
+
+/*
+ * Some string utility functions, because strdup uses malloc, and we want
+ * to track all memory (without replacing malloc).
+ */
+char *util_strdup(const char *s) {
+       size_t  len;
+       char   *ptr;
+       
+       if (!s)
+               return NULL;
+               
+       len = strlen(s);
+       ptr = mem_a (len+1);
+       
+       if (ptr && len) {
+               memcpy(ptr, s, len);
+               ptr[len] = '\0';
+       }
+       
+       return ptr;
+}