mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2024-11-24 04:41:25 +00:00
More assembler code
This commit is contained in:
parent
7aee8ac2ef
commit
20f203495d
3 changed files with 47 additions and 10 deletions
48
asm.c
48
asm.c
|
@ -78,22 +78,58 @@ void asm_clear() {
|
||||||
mem_d(assembly_constants_data);
|
mem_d(assembly_constants_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Parses a type, could be global or not depending on the
|
||||||
|
* assembly state: global scope with assignments are constants.
|
||||||
|
* globals with no assignments are globals. Function body types
|
||||||
|
* are locals.
|
||||||
|
*/
|
||||||
|
static inline bool asm_parse_type(const char *skip, size_t line, asm_state *state) {
|
||||||
|
if (strstr(skip, "FLOAT:") == &skip[0]) { return true; }
|
||||||
|
if (strstr(skip, "VECTOR:") == &skip[0]) { return true; }
|
||||||
|
if (strstr(skip, "ENTITY:") == &skip[0]) { return true; }
|
||||||
|
if (strstr(skip, "FIELD:") == &skip[0]) { return true; }
|
||||||
|
if (strstr(skip, "STRING:") == &skip[0]) { return true; }
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Parses a function: trivial case, handles occurances of duplicated
|
||||||
|
* names among other things. Ensures valid name as well, and even
|
||||||
|
* internal engine function selection.
|
||||||
|
*/
|
||||||
|
static inline bool asm_parse_func(const char *skip, size_t line, asm_state *state) {
|
||||||
|
if (*state == ASM_FUNCTION && (strstr(skip, "FUNCTION:") == &skip[0]))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (strstr(skip, "FUNCTION:") == &skip[0]) {
|
||||||
|
*state = ASM_FUNCTION; /* update state */
|
||||||
|
/* TODO */
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void asm_parse(FILE *fp) {
|
void asm_parse(FILE *fp) {
|
||||||
char *data = NULL;
|
char *data = NULL;
|
||||||
|
char *skip = NULL;
|
||||||
long line = 1; /* current line */
|
long line = 1; /* current line */
|
||||||
size_t size = 0; /* size of line */
|
size_t size = 0; /* size of line */
|
||||||
asm_state state = ASM_NULL;
|
asm_state state = ASM_NULL;
|
||||||
|
|
||||||
while ((data = asm_getline(&size, fp)) != NULL) {
|
#define asm_end(x) do { mem_d(data); line++; printf(x); } while (0); continue
|
||||||
data = util_strsws(data); /* skip whitespace */
|
|
||||||
|
while ((data = asm_getline (&size, fp)) != NULL) {
|
||||||
|
data = util_strsws(data,&skip); /* skip whitespace */
|
||||||
data = util_strrnl(data); /* delete newline */
|
data = util_strrnl(data); /* delete newline */
|
||||||
|
|
||||||
|
/* parse type */
|
||||||
|
if(asm_parse_type(skip, line, &state)){ asm_end(""); }
|
||||||
|
/* parse func */
|
||||||
|
if(asm_parse_func(skip, line, &state)){ asm_end(""); }
|
||||||
|
|
||||||
/* TODO: everything */
|
/* TODO: everything */
|
||||||
(void)state;
|
(void)state;
|
||||||
goto end;
|
|
||||||
end:
|
|
||||||
mem_d(data);
|
|
||||||
line ++;
|
|
||||||
}
|
}
|
||||||
asm_clear();
|
asm_clear();
|
||||||
}
|
}
|
||||||
|
|
2
gmqcc.h
2
gmqcc.h
|
@ -197,7 +197,7 @@ void util_meminfo ();
|
||||||
char *util_strdup (const char *);
|
char *util_strdup (const char *);
|
||||||
char *util_strrq (char *);
|
char *util_strrq (char *);
|
||||||
char *util_strrnl (char *);
|
char *util_strrnl (char *);
|
||||||
char *util_strsws (char *);
|
char *util_strsws (char *, char **);
|
||||||
void util_debug (const char *, const char *, ...);
|
void util_debug (const char *, const char *, ...);
|
||||||
int util_getline (char **, size_t *, FILE *);
|
int util_getline (char **, size_t *, FILE *);
|
||||||
void util_endianswap (void *, int, int);
|
void util_endianswap (void *, int, int);
|
||||||
|
|
3
util.c
3
util.c
|
@ -137,13 +137,14 @@ char *util_strrnl(char *src) {
|
||||||
* skipping past it, and stroing the skip distance, so
|
* skipping past it, and stroing the skip distance, so
|
||||||
* the string can later be freed (if it was allocated)
|
* the string can later be freed (if it was allocated)
|
||||||
*/
|
*/
|
||||||
char *util_strsws(char *skip) {
|
char *util_strsws(char *skip, char **move) {
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
if (!skip)
|
if (!skip)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
while (*skip == ' ' || *skip == '\t')
|
while (*skip == ' ' || *skip == '\t')
|
||||||
skip++,size++;
|
skip++,size++;
|
||||||
|
*move = skip;
|
||||||
return skip-size;
|
return skip-size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue