mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 15:22:04 +00:00
clean up qfcc.h a bit
This commit is contained in:
parent
8f2d1fa2d9
commit
c4d0c574ee
5 changed files with 50 additions and 100 deletions
|
@ -22,26 +22,9 @@
|
|||
#ifndef __qfcc_h
|
||||
#define __qfcc_h
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include "QF/pr_comp.h"
|
||||
#include "QF/pr_debug.h"
|
||||
|
||||
/* These may be underscored... */
|
||||
#if defined(HAVE__SNPRINTF)
|
||||
# undef snprintf
|
||||
# define snprintf _snprintf
|
||||
#endif
|
||||
#if defined(HAVE__VSNPRINTF)
|
||||
# undef vsnprintf
|
||||
# define vsnprintf _vsnprintf
|
||||
#endif
|
||||
|
||||
/*
|
||||
TODO:
|
||||
o "stopped at 10 errors"
|
||||
|
|
|
@ -348,33 +348,16 @@ new_expr (void)
|
|||
return e;
|
||||
}
|
||||
|
||||
static int
|
||||
num_digits (int val)
|
||||
{
|
||||
int num = 1;
|
||||
|
||||
if (val < 0) {
|
||||
num++;
|
||||
val = -val;
|
||||
}
|
||||
while (val > 9) {
|
||||
val /= 10;
|
||||
num++;
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
const char *
|
||||
new_label_name (void)
|
||||
{
|
||||
static int label = 0;
|
||||
int lnum = ++label;
|
||||
const char *fname = current_func->def->name;
|
||||
int len = 1 + strlen (fname) + 1 + num_digits (lnum) + 1;
|
||||
char *lname = malloc (len);
|
||||
char *lname;
|
||||
|
||||
lname = strdup (va ("$%s_%d", fname, lnum));
|
||||
SYS_CHECKMEM (lname);
|
||||
snprintf (lname, len, "$%s_%d", fname, lnum);
|
||||
return lname;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ static const char rcsid[] =
|
|||
|
||||
#include <QF/hash.h>
|
||||
#include <QF/sys.h>
|
||||
#include <QF/va.h>
|
||||
|
||||
#include "qfcc.h"
|
||||
#include "expr.h"
|
||||
|
@ -117,7 +118,6 @@ def_t *
|
|||
PR_GetDef (type_t *type, const char *name, def_t *scope, int *allocate)
|
||||
{
|
||||
def_t *def = check_for_name (type, name, scope, allocate);
|
||||
char element[MAX_NAME];
|
||||
int size;
|
||||
|
||||
if (def || !allocate)
|
||||
|
@ -139,18 +139,15 @@ PR_GetDef (type_t *type, const char *name, def_t *scope, int *allocate)
|
|||
if (type->type == ev_vector && name) {
|
||||
def_t *d;
|
||||
|
||||
snprintf (element, sizeof (element), "%s_x", name);
|
||||
d = PR_GetDef (&type_float, element, scope, allocate);
|
||||
d = PR_GetDef (&type_float, va ("%s_x", name), scope, allocate);
|
||||
d->used = 1;
|
||||
d->parent = def;
|
||||
|
||||
snprintf (element, sizeof (element), "%s_y", name);
|
||||
d = PR_GetDef (&type_float, element, scope, allocate);
|
||||
d = PR_GetDef (&type_float, va ("%s_y", name), scope, allocate);
|
||||
d->used = 1;
|
||||
d->parent = def;
|
||||
|
||||
snprintf (element, sizeof (element), "%s_z", name);
|
||||
d = PR_GetDef (&type_float, element, scope, allocate);
|
||||
d = PR_GetDef (&type_float, va ("%s_z", name), scope, allocate);
|
||||
d->used = 1;
|
||||
d->parent = def;
|
||||
} else {
|
||||
|
@ -163,18 +160,18 @@ PR_GetDef (type_t *type, const char *name, def_t *scope, int *allocate)
|
|||
if (type->aux_type->type == ev_vector) {
|
||||
def_t *d;
|
||||
|
||||
snprintf (element, sizeof (element), "%s_x", name);
|
||||
d = PR_GetDef (&type_floatfield, element, scope, allocate);
|
||||
d = PR_GetDef (&type_floatfield,
|
||||
va ("%s_x", name), scope, allocate);
|
||||
d->used = 1; // always `used'
|
||||
d->parent = def;
|
||||
|
||||
snprintf (element, sizeof (element), "%s_y", name);
|
||||
d = PR_GetDef (&type_floatfield, element, scope, allocate);
|
||||
d = PR_GetDef (&type_floatfield,
|
||||
va ("%s_y", name), scope, allocate);
|
||||
d->used = 1; // always `used'
|
||||
d->parent = def;
|
||||
|
||||
snprintf (element, sizeof (element), "%s_z", name);
|
||||
d = PR_GetDef (&type_floatfield, element, scope, allocate);
|
||||
d = PR_GetDef (&type_floatfield,
|
||||
va ("%s_z", name), scope, allocate);
|
||||
d->used = 1; // always `used'
|
||||
d->parent = def;
|
||||
} else if (type->aux_type->type == ev_pointer) {
|
||||
|
|
|
@ -31,6 +31,7 @@ static const char rcsid[] =
|
|||
#include <stdlib.h>
|
||||
|
||||
#include "QF/hash.h"
|
||||
#include "QF/va.h"
|
||||
|
||||
#include "qfcc.h"
|
||||
#include "type.h"
|
||||
|
@ -59,7 +60,7 @@ float_imm_get_key (void *_def, void *unused)
|
|||
def_t *def = (def_t *) _def;
|
||||
static char rep[20];
|
||||
|
||||
snprintf (rep, sizeof (rep), "\001float:%08X\001", G_INT (def->ofs));
|
||||
return va ("\001float:%08X\001", G_INT (def->ofs));
|
||||
return rep;
|
||||
}
|
||||
|
||||
|
@ -69,7 +70,7 @@ vector_imm_get_key (void *_def, void *unused)
|
|||
def_t *def = (def_t *) _def;
|
||||
static char rep[60];
|
||||
|
||||
snprintf (rep, sizeof (rep), "\001vector:%08X\001%08X\001%08X\001",
|
||||
return va ("\001vector:%08X\001%08X\001%08X\001",
|
||||
G_INT (def->ofs), G_INT (def->ofs + 1), G_INT (def->ofs + 2));
|
||||
return rep;
|
||||
}
|
||||
|
@ -80,10 +81,9 @@ quaternion_imm_get_key (void *_def, void *unused)
|
|||
def_t *def = (def_t *) _def;
|
||||
static char rep[60];
|
||||
|
||||
snprintf (rep, sizeof (rep),
|
||||
"\001quaternion:%08X\001%08X\001%08X\001%08X\001",
|
||||
G_INT (def->ofs), G_INT (def->ofs + 1),
|
||||
G_INT (def->ofs + 2), G_INT (def->ofs + 3));
|
||||
return va ("\001quaternion:%08X\001%08X\001%08X\001%08X\001",
|
||||
G_INT (def->ofs), G_INT (def->ofs + 1),
|
||||
G_INT (def->ofs + 2), G_INT (def->ofs + 3));
|
||||
return rep;
|
||||
}
|
||||
|
||||
|
@ -94,7 +94,7 @@ int_imm_get_key (void *_def, void *_str)
|
|||
static char rep[60];
|
||||
char *str = (char *) _str;
|
||||
|
||||
snprintf (rep, sizeof (rep), "\001%s:%08X\001", str, G_INT (def->ofs));
|
||||
return va ("\001%s:%08X\001", str, G_INT (def->ofs));
|
||||
return rep;
|
||||
}
|
||||
|
||||
|
@ -102,8 +102,7 @@ def_t *
|
|||
PR_ReuseConstant (expr_t *expr, def_t *def)
|
||||
{
|
||||
def_t *cn;
|
||||
char rep[60];
|
||||
const char *r = rep;
|
||||
const char *rep;
|
||||
hashtab_t *tab = 0;
|
||||
type_t *type;
|
||||
expr_t e = *expr;
|
||||
|
@ -134,32 +133,29 @@ PR_ReuseConstant (expr_t *expr, def_t *def)
|
|||
cn = 0;
|
||||
switch (e.type) {
|
||||
case ex_entity:
|
||||
snprintf (rep, sizeof (rep), "\001entity:%08X\001",
|
||||
e.e.integer_val);
|
||||
rep = va ("\001entity:%08X\001", e.e.integer_val);
|
||||
tab = entity_imm_defs;
|
||||
type = &type_entity;
|
||||
break;
|
||||
case ex_field:
|
||||
snprintf (rep, sizeof (rep), "\001field:%08X\001", e.e.integer_val);
|
||||
rep = va ("\001field:%08X\001", e.e.integer_val);
|
||||
tab = field_imm_defs;
|
||||
type = &type_field;
|
||||
break;
|
||||
case ex_func:
|
||||
snprintf (rep, sizeof (rep), "\001func:%08X\001", e.e.integer_val);
|
||||
rep = va ("\001func:%08X\001", e.e.integer_val);
|
||||
tab = func_imm_defs;
|
||||
type = &type_function;
|
||||
break;
|
||||
case ex_pointer:
|
||||
snprintf (rep, sizeof (rep), "\001pointer:%08X\001",
|
||||
e.e.pointer.val);
|
||||
rep = va ("\001pointer:%08X\001", e.e.pointer.val);
|
||||
tab = pointer_imm_defs;
|
||||
type = &type_pointer;
|
||||
break;
|
||||
case ex_integer:
|
||||
case ex_uinteger:
|
||||
if (!def || def->type != &type_float) {
|
||||
snprintf (rep, sizeof (rep), "\001integer:%08X\001",
|
||||
e.e.integer_val);
|
||||
rep = va ("\001integer:%08X\001", e.e.integer_val);
|
||||
tab = integer_imm_defs;
|
||||
if (e.type == ex_uinteger)
|
||||
type = &type_uinteger;
|
||||
|
@ -172,25 +168,24 @@ PR_ReuseConstant (expr_t *expr, def_t *def)
|
|||
else
|
||||
e.e.float_val = e.e.integer_val;
|
||||
case ex_float:
|
||||
snprintf (rep, sizeof (rep), "\001float:%08X\001", e.e.integer_val);
|
||||
rep = va ("\001float:%08X\001", e.e.integer_val);
|
||||
tab = float_imm_defs;
|
||||
type = &type_float;
|
||||
break;
|
||||
case ex_string:
|
||||
r = e.e.string_val ? e.e.string_val : "";
|
||||
rep = e.e.string_val ? e.e.string_val : "";
|
||||
tab = string_imm_defs;
|
||||
type = &type_string;
|
||||
break;
|
||||
case ex_vector:
|
||||
snprintf (rep, sizeof (rep), "\001vector:%08X\001%08X\001%08X\001",
|
||||
rep = va ("\001vector:%08X\001%08X\001%08X\001",
|
||||
*(int *) &e.e.vector_val[0],
|
||||
*(int *) &e.e.vector_val[1], *(int *) &e.e.vector_val[2]);
|
||||
tab = vector_imm_defs;
|
||||
type = &type_vector;
|
||||
break;
|
||||
case ex_quaternion:
|
||||
snprintf (rep, sizeof (rep),
|
||||
"\001quaternion:%08X\001%08X\001%08X\001%08X\001",
|
||||
rep = va ("\001quaternion:%08X\001%08X\001%08X\001%08X\001",
|
||||
*(int *) &e.e.quaternion_val[0],
|
||||
*(int *) &e.e.quaternion_val[1],
|
||||
*(int *) &e.e.quaternion_val[2],
|
||||
|
@ -201,7 +196,7 @@ PR_ReuseConstant (expr_t *expr, def_t *def)
|
|||
default:
|
||||
abort ();
|
||||
}
|
||||
cn = (def_t *) Hash_Find (tab, r);
|
||||
cn = (def_t *) Hash_Find (tab, rep);
|
||||
if (cn) {
|
||||
if (def) {
|
||||
PR_FreeLocation (def);
|
||||
|
@ -240,7 +235,7 @@ PR_ReuseConstant (expr_t *expr, def_t *def)
|
|||
cn->initialized = cn->constant = 1;
|
||||
// copy the immediate to the global area
|
||||
if (e.type == ex_string)
|
||||
e.e.integer_val = CopyString (r);
|
||||
e.e.integer_val = CopyString (rep);
|
||||
|
||||
memcpy (pr_globals + cn->ofs, &e.e, 4 * pr_type_size[type->type]);
|
||||
|
||||
|
|
|
@ -67,6 +67,7 @@ static const char rcsid[] =
|
|||
#include <QF/hash.h>
|
||||
#include <QF/qendian.h>
|
||||
#include <QF/sys.h>
|
||||
#include <QF/va.h>
|
||||
|
||||
#include "cmdlib.h"
|
||||
#include "qfcc.h"
|
||||
|
@ -167,13 +168,12 @@ WriteFiles (void)
|
|||
{
|
||||
FILE *f;
|
||||
int i;
|
||||
char filename[1024];
|
||||
dstring_t *filename = dstring_newstr ();
|
||||
|
||||
snprintf (filename, sizeof (filename), "%s%cfiles.dat", sourcedir,
|
||||
PATH_SEPARATOR);
|
||||
f = fopen (filename, "w");
|
||||
dsprintf (filename, "%s%cfiles.dat", sourcedir, PATH_SEPARATOR);
|
||||
f = fopen (filename->str, "w");
|
||||
if (!f)
|
||||
Error ("Couldn't open %s", filename);
|
||||
Error ("Couldn't open %s", filename->str);
|
||||
|
||||
fprintf (f, "%i\n", numsounds);
|
||||
for (i = 0; i < numsounds; i++)
|
||||
|
@ -188,6 +188,7 @@ WriteFiles (void)
|
|||
fprintf (f, "%i %s\n", precache_files_block[i], precache_files[i]);
|
||||
|
||||
fclose (f);
|
||||
dstring_delete (filename);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -964,10 +965,7 @@ DecodeArgs (int argc, char **argv)
|
|||
char *temp = strtok (opts, ",");
|
||||
|
||||
while (temp) {
|
||||
char temp2[1024];
|
||||
|
||||
snprintf (temp2, sizeof (temp2), "%s%s", "-D", temp);
|
||||
add_cpp_def (strdup (temp2));
|
||||
add_cpp_def (strdup (va ("%s%s", "-D", temp)));
|
||||
temp = strtok (NULL, ",");
|
||||
}
|
||||
free (opts);
|
||||
|
@ -978,10 +976,7 @@ DecodeArgs (int argc, char **argv)
|
|||
char *temp = strtok (opts, ",");
|
||||
|
||||
while (temp) {
|
||||
char temp2[1024];
|
||||
|
||||
snprintf (temp2, sizeof (temp2), "%s%s", "-I", temp);
|
||||
add_cpp_def (strdup (temp2));
|
||||
add_cpp_def (strdup (va ("%s%s", "-I", temp)));
|
||||
temp = strtok (NULL, ",");
|
||||
}
|
||||
free (opts);
|
||||
|
@ -992,10 +987,7 @@ DecodeArgs (int argc, char **argv)
|
|||
char *temp = strtok (opts, ",");
|
||||
|
||||
while (temp) {
|
||||
char temp2[1024];
|
||||
|
||||
snprintf (temp2, sizeof (temp2), "%s%s", "-U", temp);
|
||||
add_cpp_def (strdup (temp2));
|
||||
add_cpp_def (strdup (va ("%s%s", "-U", temp)));
|
||||
temp = strtok (NULL, ",");
|
||||
}
|
||||
free (opts);
|
||||
|
@ -1160,7 +1152,7 @@ int
|
|||
main (int argc, char **argv)
|
||||
{
|
||||
char *src;
|
||||
char filename[1024];
|
||||
dstring_t *filename = dstring_newstr ();
|
||||
int crc = 0;
|
||||
double start, stop;
|
||||
|
||||
|
@ -1188,10 +1180,10 @@ main (int argc, char **argv)
|
|||
init_types ();
|
||||
|
||||
if (*sourcedir)
|
||||
snprintf (filename, sizeof (filename), "%s/%s", sourcedir, progs_src);
|
||||
dsprintf (filename, "%s/%s", sourcedir, progs_src);
|
||||
else
|
||||
snprintf (filename, sizeof (filename), "%s", progs_src);
|
||||
LoadFile (filename, (void *) &src);
|
||||
dsprintf (filename, "%s", progs_src);
|
||||
LoadFile (filename->str, (void *) &src);
|
||||
|
||||
if (!(src = Parse (src)))
|
||||
Error ("No destination filename. qfcc --help for info.\n");
|
||||
|
@ -1233,16 +1225,16 @@ main (int argc, char **argv)
|
|||
//yydebug = 1;
|
||||
|
||||
if (*sourcedir)
|
||||
snprintf (filename, sizeof (filename), "%s%c%s", sourcedir,
|
||||
PATH_SEPARATOR, qfcc_com_token);
|
||||
dsprintf (filename, "%s%c%s", sourcedir, PATH_SEPARATOR,
|
||||
qfcc_com_token);
|
||||
else
|
||||
snprintf (filename, sizeof (filename), "%s", qfcc_com_token);
|
||||
dsprintf (filename, "%s", qfcc_com_token);
|
||||
if (options.verbosity >= 2)
|
||||
printf ("compiling %s\n", filename);
|
||||
printf ("compiling %s\n", filename->str);
|
||||
|
||||
yyin = preprocess_file (filename);
|
||||
yyin = preprocess_file (filename->str);
|
||||
|
||||
s_file = ReuseString (strip_path (filename));
|
||||
s_file = ReuseString (strip_path (filename->str));
|
||||
pr_source_line = 1;
|
||||
clear_frame_macros ();
|
||||
error = yyparse () || pr_error_count;
|
||||
|
|
Loading…
Reference in a new issue