mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2024-11-23 12:22:26 +00:00
code.c, info.txt
This commit is contained in:
parent
639fc8a32b
commit
bda6fc826c
4 changed files with 130 additions and 3 deletions
29
code.c
Normal file
29
code.c
Normal file
|
@ -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.
|
||||
*/
|
12
info.txt
Normal file
12
info.txt
Normal file
|
@ -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
|
11
typedef.c
11
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;
|
||||
}
|
||||
}
|
||||
|
|
81
util.c
Normal file
81
util.c
Normal file
|
@ -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;
|
||||
}
|
Loading…
Reference in a new issue