mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 15:22:04 +00:00
more cleanup
This commit is contained in:
parent
0f9adc182d
commit
06bddd3ee6
29 changed files with 453 additions and 249 deletions
|
@ -1,4 +1,4 @@
|
|||
AUTOMAKE_OPTIONS= foreign
|
||||
|
||||
EXTRA_DIST= class.h cmdlib.h expr.h function.h method.h qfcc.h struct.h \
|
||||
switch.h type.h
|
||||
EXTRA_DIST= class.h cmdlib.h cpp.h def.h expr.h function.h idstuff.h \
|
||||
immediate.h method.h options.h qfcc.h struct.h switch.h type.h
|
||||
|
|
|
@ -58,7 +58,7 @@ struct type_s;
|
|||
void class_init (void);
|
||||
class_t *get_class (const char *name, int create);
|
||||
void class_add_methods (class_t *class, struct methodlist_s *methods);
|
||||
void class_add_protocol_methods (class_t *class, expr_t *protocols);
|
||||
void class_add_protocol_methods (class_t *class, struct expr_s *protocols);
|
||||
void class_add_protocol (class_t *class, struct protocol_s *protocol);
|
||||
void class_add_ivars (class_t *class, struct type_s *ivars);
|
||||
void class_check_ivars (class_t *class, struct type_s *ivars);
|
||||
|
@ -66,7 +66,7 @@ void class_begin (class_t *class);
|
|||
void class_finish (class_t *class);
|
||||
struct struct_field_s *class_find_ivar (class_t *class, int protected,
|
||||
const char *name);
|
||||
expr_t *class_ivar_expr (class_t *class, const char *name);
|
||||
struct expr_s *class_ivar_expr (class_t *class, const char *name);
|
||||
struct method_s *class_find_method (class_t *class, struct method_s *method);
|
||||
struct method_s *class_message_response (class_t *class, struct expr_s *sel);
|
||||
struct def_s *class_def (class_t *class);
|
||||
|
@ -87,7 +87,8 @@ typedef struct protocollist_s {
|
|||
|
||||
protocol_t *get_protocol (const char *name, int create);
|
||||
void protocol_add_methods (protocol_t *protocol, struct methodlist_s *methods);
|
||||
void protocol_add_protocol_methods (protocol_t *protocol, expr_t *protocols);
|
||||
void protocol_add_protocol_methods (protocol_t *protocol,
|
||||
struct expr_s *protocols);
|
||||
struct def_s *protocol_def (protocol_t *protocol);
|
||||
protocollist_t *new_protocollist (void);
|
||||
void add_protocol (protocollist_t *protocollist, protocol_t *protocol);
|
||||
|
|
41
tools/qfcc/include/cpp.h
Normal file
41
tools/qfcc/include/cpp.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
#FILENAME#
|
||||
|
||||
#DESCRIPTION#
|
||||
|
||||
Copyright (C) 2001 #AUTHOR#
|
||||
|
||||
Author: #AUTHOR#
|
||||
Date: #DATE#
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to:
|
||||
|
||||
Free Software Foundation, Inc.
|
||||
59 Temple Place - Suite 330
|
||||
Boston, MA 02111-1307, USA
|
||||
|
||||
$Id$
|
||||
*/
|
||||
|
||||
#ifndef __cpp_h
|
||||
#define __cpp_h
|
||||
|
||||
void parse_cpp_name ();
|
||||
void add_cpp_def (const char *arg);
|
||||
FILE * preprocess_file (const char *filename);
|
||||
extern const char *cpp_name;
|
||||
extern struct dstring_s *tempname;
|
||||
|
||||
#endif//__cpp_h
|
70
tools/qfcc/include/def.h
Normal file
70
tools/qfcc/include/def.h
Normal file
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
def.h
|
||||
|
||||
#DESCRIPTION#
|
||||
|
||||
Copyright (C) 2001 #AUTHOR#
|
||||
|
||||
Author: #AUTHOR#
|
||||
Date: #DATE#
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to:
|
||||
|
||||
Free Software Foundation, Inc.
|
||||
59 Temple Place - Suite 330
|
||||
Boston, MA 02111-1307, USA
|
||||
|
||||
$Id$
|
||||
*/
|
||||
|
||||
#ifndef __def_h
|
||||
#define __def_h
|
||||
|
||||
#include "QF/pr_comp.h"
|
||||
#include "QF/pr_debug.h"
|
||||
|
||||
typedef struct def_s {
|
||||
struct type_s *type;
|
||||
const char *name;
|
||||
int locals;
|
||||
int *alloc;
|
||||
int ofs;
|
||||
int initialized; // for uninit var detection
|
||||
int constant; // 1 when a declaration included "= immediate"
|
||||
struct statref_s *refs; // for relocations
|
||||
|
||||
unsigned freed:1; // already freed from the scope
|
||||
unsigned removed:1; // already removed from the symbol table
|
||||
unsigned used:1; // unused local detection
|
||||
unsigned absolute:1; // don't relocate (for temps for shorts)
|
||||
unsigned managed:1; // managed temp
|
||||
string_t file; // source file
|
||||
int line; // source line
|
||||
|
||||
int users; // ref counted temps
|
||||
struct expr_s *expr; // temp expr using this def
|
||||
|
||||
struct def_s *def_next; // for writing out the global defs list
|
||||
struct def_s *next; // general purpose linking
|
||||
struct def_s *scope_next; // to facilitate hash table removal
|
||||
struct def_s *scope; // function the var was defined in, or NULL
|
||||
struct def_s *parent; // vector/quaternion member
|
||||
} def_t;
|
||||
|
||||
extern def_t def_ret, def_parms[MAX_PARMS];
|
||||
extern def_t def_void;
|
||||
extern def_t def_function;
|
||||
|
||||
#endif//__def_h
|
|
@ -71,14 +71,14 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
struct expr_s *expr;
|
||||
def_t *def;
|
||||
type_t *type;
|
||||
struct def_s *def;
|
||||
struct type_s *type;
|
||||
int users;
|
||||
} ex_temp_t;
|
||||
|
||||
typedef struct {
|
||||
int val;
|
||||
type_t *type;
|
||||
struct type_s *type;
|
||||
int abs;
|
||||
} ex_pointer_t;
|
||||
|
||||
|
@ -94,11 +94,11 @@ typedef struct expr_s {
|
|||
ex_block_t block;
|
||||
struct {
|
||||
int op;
|
||||
type_t *type;
|
||||
struct type_s *type;
|
||||
struct expr_s *e1;
|
||||
struct expr_s *e2;
|
||||
} expr;
|
||||
def_t *def;
|
||||
struct def_s *def;
|
||||
ex_temp_t temp;
|
||||
|
||||
const char *string_val;
|
||||
|
@ -121,7 +121,7 @@ extern expr_type expr_types[];
|
|||
|
||||
extern expr_t *local_expr;
|
||||
|
||||
type_t *get_type (expr_t *e);
|
||||
struct type_s *get_type (expr_t *e);
|
||||
etype_t extract_type (expr_t *e);
|
||||
|
||||
expr_t *new_expr (void);
|
||||
|
@ -130,10 +130,10 @@ expr_t *new_label_expr (void);
|
|||
expr_t *new_block_expr (void);
|
||||
expr_t *new_binary_expr (int op, expr_t *e1, expr_t *e2);
|
||||
expr_t *new_unary_expr (int op, expr_t *e1);
|
||||
expr_t *new_temp_def_expr (type_t *type);
|
||||
expr_t *new_temp_def_expr (struct type_s *type);
|
||||
expr_t *new_bind_expr (expr_t *e1, expr_t *e2);
|
||||
expr_t *new_name_expr (const char *name);
|
||||
expr_t *new_def_expr (def_t *def);
|
||||
expr_t *new_def_expr (struct def_s *def);
|
||||
expr_t *new_self_expr (void);
|
||||
expr_t *new_this_expr (void);
|
||||
|
||||
|
@ -151,17 +151,18 @@ expr_t *binary_expr (int op, expr_t *e1, expr_t *e2);
|
|||
expr_t *asx_expr (int op, expr_t *e1, expr_t *e2);
|
||||
expr_t *unary_expr (int op, expr_t *e);
|
||||
expr_t *function_expr (expr_t *e1, expr_t *e2);
|
||||
expr_t *return_expr (function_t *f, expr_t *e);
|
||||
struct function_s;
|
||||
expr_t *return_expr (struct function_s *f, expr_t *e);
|
||||
expr_t *conditional_expr (expr_t *cond, expr_t *e1, expr_t *e2);
|
||||
expr_t *incop_expr (int op, expr_t *e, int postop);
|
||||
expr_t *array_expr (expr_t *array, expr_t *index);
|
||||
expr_t *address_expr (expr_t *e1, expr_t *e2, type_t *t);
|
||||
expr_t *address_expr (expr_t *e1, expr_t *e2, struct type_s *t);
|
||||
expr_t *assign_expr (expr_t *e1, expr_t *e2);
|
||||
expr_t *cast_expr (type_t *t, expr_t *e);
|
||||
expr_t *cast_expr (struct type_s *t, expr_t *e);
|
||||
|
||||
void init_elements (def_t *def, expr_t *eles);
|
||||
void init_elements (struct def_s *def, expr_t *eles);
|
||||
|
||||
def_t *emit_statement (int line, opcode_t *op, def_t *var_a, def_t *var_b, def_t *var_c);
|
||||
struct def_s *emit_statement (int line, opcode_t *op, struct def_s *var_a, struct def_s *var_b, struct def_s *var_c);
|
||||
void emit_expr (expr_t *e);
|
||||
|
||||
expr_t *error (expr_t *e, const char *fmt, ...) __attribute__((format(printf, 2,3)));
|
||||
|
@ -174,7 +175,7 @@ extern int lineno_base;
|
|||
struct keywordarg_s;
|
||||
expr_t *selector_expr (struct keywordarg_s *selector);
|
||||
expr_t *protocol_expr (const char *protocol);
|
||||
expr_t *encode_expr (type_t *type);
|
||||
expr_t *encode_expr (struct type_s *type);
|
||||
expr_t *message_expr (expr_t *receiver, struct keywordarg_s *message);
|
||||
|
||||
#endif//__expr_h
|
||||
|
|
|
@ -32,24 +32,42 @@
|
|||
#ifndef __function_h
|
||||
#define __function_h
|
||||
|
||||
#include "QF/pr_comp.h"
|
||||
|
||||
typedef struct function_s {
|
||||
struct function_s *next;
|
||||
dfunction_t *dfunc;
|
||||
pr_auxfunction_t *aux; // debug info;
|
||||
int builtin; // if non 0, call an internal function
|
||||
int code; // first statement
|
||||
const char *file; // source file with definition
|
||||
int file_line;
|
||||
struct def_s *def;
|
||||
int parm_ofs[MAX_PARMS]; // allways contiguous, right?
|
||||
} function_t;
|
||||
|
||||
extern function_t *pr_functions;
|
||||
extern function_t *current_func;
|
||||
|
||||
typedef struct param_s {
|
||||
// the first two fields match the first two fiels of keywordarg_t in
|
||||
// method.h
|
||||
struct param_s *next;
|
||||
const char *selector;
|
||||
type_t *type;
|
||||
struct type_s *type;
|
||||
const char *name;
|
||||
} param_t;
|
||||
|
||||
struct expr_s;
|
||||
|
||||
param_t *new_param (const char *selector, type_t *type, const char *name);
|
||||
param_t *new_param (const char *selector, struct type_s *type,
|
||||
const char *name);
|
||||
param_t *_reverse_params (param_t *params, param_t *next);
|
||||
param_t *reverse_params (param_t *params);
|
||||
type_t *parse_params (type_t *type, param_t *params);
|
||||
void build_scope (function_t *f, def_t *func, param_t *params);
|
||||
struct type_s *parse_params (struct type_s *type, param_t *params);
|
||||
void build_scope (function_t *f, struct def_s *func, param_t *params);
|
||||
function_t *new_function (void);
|
||||
void build_builtin_function (def_t *def, struct expr_s *bi_val);
|
||||
void build_builtin_function (struct def_s *def, struct expr_s *bi_val);
|
||||
void build_function (function_t *f);
|
||||
void finish_function (function_t *f);
|
||||
void emit_function (function_t *f, expr_t *e);
|
||||
|
|
44
tools/qfcc/include/idstuff.h
Normal file
44
tools/qfcc/include/idstuff.h
Normal file
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
idstuff.h
|
||||
|
||||
#DESCRIPTION#
|
||||
|
||||
Copyright (C) 2001 #AUTHOR#
|
||||
|
||||
Author: #AUTHOR#
|
||||
Date: #DATE#
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to:
|
||||
|
||||
Free Software Foundation, Inc.
|
||||
59 Temple Place - Suite 330
|
||||
Boston, MA 02111-1307, USA
|
||||
|
||||
$Id$
|
||||
*/
|
||||
|
||||
#ifndef __idstuff_h
|
||||
#define __idstuff_h
|
||||
|
||||
struct def_s;
|
||||
|
||||
//XXX eww :/
|
||||
void PrecacheSound (struct def_s *e, int ch);
|
||||
void PrecacheModel (struct def_s *e, int ch);
|
||||
void PrecacheFile (struct def_s *e, int ch);
|
||||
void WriteFiles (const char *sourcedir);
|
||||
int WriteProgdefs (char *filename);
|
||||
|
||||
#endif//__idstuff_h
|
41
tools/qfcc/include/immediate.h
Normal file
41
tools/qfcc/include/immediate.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
immediate.h
|
||||
|
||||
#DESCRIPTION#
|
||||
|
||||
Copyright (C) 2001 #AUTHOR#
|
||||
|
||||
Author: #AUTHOR#
|
||||
Date: #DATE#
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to:
|
||||
|
||||
Free Software Foundation, Inc.
|
||||
59 Temple Place - Suite 330
|
||||
Boston, MA 02111-1307, USA
|
||||
|
||||
$Id$
|
||||
*/
|
||||
|
||||
#ifndef __immediate_h
|
||||
#define __immediate_h
|
||||
|
||||
struct expr_s;
|
||||
struct def_s *ReuseConstant (struct expr_s *expr, struct def_s *def);
|
||||
|
||||
int CopyString (const char *str);
|
||||
int ReuseString (const char *str);
|
||||
|
||||
#endif//__immediate_h
|
|
@ -39,8 +39,8 @@ typedef struct method_s {
|
|||
int instance;
|
||||
param_t *selector;
|
||||
param_t *params;
|
||||
type_t *type;
|
||||
def_t *def;
|
||||
struct type_s *type;
|
||||
struct def_s *def;
|
||||
char *name;
|
||||
char *types;
|
||||
} method_t;
|
||||
|
@ -62,9 +62,10 @@ struct class_s;
|
|||
struct expr_s;
|
||||
struct dstring_s;
|
||||
|
||||
method_t *new_method (type_t *ret_type, param_t *selector, param_t *opt_parms);
|
||||
method_t *new_method (struct type_s *ret_type, param_t *selector,
|
||||
param_t *opt_parms);
|
||||
void add_method (methodlist_t *methodlist, method_t *method);
|
||||
def_t *method_def (struct class_s *class, method_t *method);
|
||||
struct def_s *method_def (struct class_s *class, method_t *method);
|
||||
|
||||
methodlist_t *new_methodlist (void);
|
||||
void copy_methods (methodlist_t *dst, methodlist_t *src);
|
||||
|
|
71
tools/qfcc/include/options.h
Normal file
71
tools/qfcc/include/options.h
Normal file
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
#FILENAME#
|
||||
|
||||
#DESCRIPTION#
|
||||
|
||||
Copyright (C) 2001 #AUTHOR#
|
||||
|
||||
Author: #AUTHOR#
|
||||
Date: #DATE#
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to:
|
||||
|
||||
Free Software Foundation, Inc.
|
||||
59 Temple Place - Suite 330
|
||||
Boston, MA 02111-1307, USA
|
||||
|
||||
$Id$
|
||||
*/
|
||||
|
||||
#ifndef __options_h
|
||||
#define __options_h
|
||||
|
||||
#include "QF/qtypes.h"
|
||||
|
||||
typedef struct {
|
||||
qboolean cow; // Turn constants into variables if written to
|
||||
qboolean debug; // Generate debug info for the engine
|
||||
int progsversion; // Progs version to generate code for
|
||||
} code_options_t;
|
||||
|
||||
typedef struct {
|
||||
qboolean promote; // Promote warnings to errors
|
||||
qboolean cow; // Warn on copy-on-write detection
|
||||
qboolean undefined_function; // Warn on undefined function use
|
||||
qboolean uninited_variable; // Warn on use of uninitialized vars
|
||||
qboolean vararg_integer; // Warn on passing an integer to vararg func
|
||||
qboolean integer_divide; // Warn on integer constant division
|
||||
} warn_options_t;
|
||||
|
||||
typedef struct {
|
||||
code_options_t code; // Code generation options
|
||||
warn_options_t warnings; // Warning options
|
||||
|
||||
int verbosity; // 0=silent, goes up to 2 currently
|
||||
qboolean save_temps; // save temporary files
|
||||
qboolean files_dat; // generate files.dat
|
||||
qboolean traditional; // behave more like qcc
|
||||
int strip_path; // number of leading path elements to strip
|
||||
// from source file names
|
||||
} options_t;
|
||||
|
||||
extern options_t options;
|
||||
int DecodeArgs (int argc, char **argv);
|
||||
extern const char *progs_src;
|
||||
|
||||
extern const char *this_program;
|
||||
extern const char *sourcedir;
|
||||
|
||||
#endif//__options_h
|
|
@ -1,20 +1,30 @@
|
|||
/* Copyright (C) 1996-1997 Id Software, Inc.
|
||||
/*
|
||||
qfcc.h
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
#DESCRIPTION#
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
Copyright (C) 2001 #AUTHOR#
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
Author: #AUTHOR#
|
||||
Date: #DATE#
|
||||
|
||||
See file, 'COPYING', for details.
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to:
|
||||
|
||||
Free Software Foundation, Inc.
|
||||
59 Temple Place - Suite 330
|
||||
Boston, MA 02111-1307, USA
|
||||
|
||||
$Id$
|
||||
*/
|
||||
|
@ -25,22 +35,7 @@
|
|||
#include "QF/pr_comp.h"
|
||||
#include "QF/pr_debug.h"
|
||||
|
||||
// offsets are allways multiplied by 4 before using
|
||||
typedef int gofs_t; // offset in global data block
|
||||
typedef struct function_s function_t;
|
||||
|
||||
typedef struct type_s {
|
||||
etype_t type;
|
||||
struct type_s *next;
|
||||
// function/pointer/struct types are more complex
|
||||
struct type_s *aux_type; // return type or field type
|
||||
int num_parms; // -1 = variable args
|
||||
struct type_s *parm_types[MAX_PARMS]; // only [num_parms] allocated
|
||||
struct hashtab_s *struct_fields;
|
||||
struct struct_field_s *struct_head;
|
||||
struct struct_field_s **struct_tail;
|
||||
struct class_s *class; // for ev_class
|
||||
} type_t;
|
||||
#include "def.h"
|
||||
|
||||
typedef struct statref_s {
|
||||
struct statref_s *next;
|
||||
|
@ -48,65 +43,18 @@ typedef struct statref_s {
|
|||
int field; // a, b, c (0, 1, 2)
|
||||
} statref_t;
|
||||
|
||||
typedef struct def_s {
|
||||
type_t *type;
|
||||
const char *name;
|
||||
int locals;
|
||||
int *alloc;
|
||||
gofs_t ofs;
|
||||
int initialized; // for uninit var detection
|
||||
int constant; // 1 when a declaration included "= immediate"
|
||||
statref_t *refs; // for relocations
|
||||
|
||||
unsigned freed:1; // already freed from the scope
|
||||
unsigned removed:1; // already removed from the symbol table
|
||||
unsigned used:1; // unused local detection
|
||||
unsigned absolute:1; // don't relocate (for temps for shorts)
|
||||
unsigned managed:1; // managed temp
|
||||
string_t file; // source file
|
||||
int line; // source line
|
||||
|
||||
int users; // ref counted temps
|
||||
struct expr_s *expr; // temp expr using this def
|
||||
|
||||
struct def_s *def_next; // for writing out the global defs list
|
||||
struct def_s *next; // general purpose linking
|
||||
struct def_s *scope_next; // to facilitate hash table removal
|
||||
struct def_s *scope; // function the var was defined in, or NULL
|
||||
struct def_s *parent; // vector/quaternion member
|
||||
} def_t;
|
||||
|
||||
//============================================================================
|
||||
|
||||
// pr_loc.h -- program local defs
|
||||
|
||||
#define MAX_ERRORS 10
|
||||
|
||||
#define MAX_REGS 65536
|
||||
|
||||
//=============================================================================
|
||||
|
||||
struct function_s {
|
||||
struct function_s *next;
|
||||
dfunction_t *dfunc;
|
||||
pr_auxfunction_t *aux; // debug info;
|
||||
int builtin; // if non 0, call an internal function
|
||||
int code; // first statement
|
||||
const char *file; // source file with definition
|
||||
int file_line;
|
||||
struct def_s *def;
|
||||
int parm_ofs[MAX_PARMS]; // allways contiguous, right?
|
||||
};
|
||||
|
||||
extern function_t *pr_functions;
|
||||
extern function_t *current_func;
|
||||
|
||||
//
|
||||
// output generated by prog parsing
|
||||
//
|
||||
typedef struct {
|
||||
int current_memory;
|
||||
type_t *types;
|
||||
struct type_s *types;
|
||||
|
||||
def_t def_head; // unused head of linked list
|
||||
def_t *def_tail; // add new defs after this and move it
|
||||
|
@ -139,42 +87,35 @@ void PR_Opcode_Init_Tables (void);
|
|||
|
||||
//============================================================================
|
||||
|
||||
extern def_t *pr_global_defs[MAX_REGS]; // to find def for a global
|
||||
|
||||
struct expr_s;
|
||||
def_t *PR_ReuseConstant (struct expr_s *expr, def_t *def);
|
||||
|
||||
extern char destfile[];
|
||||
extern int pr_source_line;
|
||||
|
||||
extern def_t *pr_scope;
|
||||
extern int pr_error_count;
|
||||
|
||||
def_t *PR_GetArray (type_t *etype, const char *name, int size, def_t *scope,
|
||||
int *allocate);
|
||||
def_t *PR_GetArray (struct type_s *etype, const char *name, int size,
|
||||
def_t *scope, int *allocate);
|
||||
|
||||
def_t *PR_GetDef (type_t *type, const char *name, def_t *scope,
|
||||
def_t *PR_GetDef (struct type_s *type, const char *name, def_t *scope,
|
||||
int *allocate);
|
||||
def_t *PR_NewDef (type_t *type, const char *name, def_t *scope);
|
||||
int PR_NewLocation (type_t *type);
|
||||
def_t *PR_NewDef (struct type_s *type, const char *name, def_t *scope);
|
||||
int PR_NewLocation (struct type_s *type);
|
||||
void PR_FreeLocation (def_t *def);
|
||||
def_t *PR_GetTempDef (type_t *type, def_t *scope);
|
||||
def_t *PR_GetTempDef (struct type_s *type, def_t *scope);
|
||||
void PR_FreeTempDefs ();
|
||||
void PR_ResetTempDefs ();
|
||||
void PR_FlushScope (def_t *scope, int force_used);
|
||||
void PR_DefInitialized (def_t *d);
|
||||
|
||||
#define G_FLOAT(o) (pr_globals[o])
|
||||
#define G_INT(o) (*(int *)&pr_globals[o])
|
||||
#define G_VECTOR(o) (&pr_globals[o])
|
||||
#define G_STRING(o) (strings + *(string_t *)&pr_globals[o])
|
||||
#define G_FUNCTION(o) (*(func_t *)&pr_globals[o])
|
||||
#define G_STRUCT(t,o) (*(t *)&pr_globals[o])
|
||||
#define G_FLOAT(o) (pr_globals[o])
|
||||
#define G_INT(o) (*(int *)&pr_globals[o])
|
||||
#define G_VECTOR(o) (&pr_globals[o])
|
||||
#define G_STRING(o) (strings + *(string_t *)&pr_globals[o])
|
||||
#define G_FUNCTION(o) (*(func_t *)&pr_globals[o])
|
||||
#define G_STRUCT(t,o) (*(t *)&pr_globals[o])
|
||||
|
||||
extern string_t s_file; // filename for function definition
|
||||
|
||||
extern def_t def_ret, def_parms[MAX_PARMS];
|
||||
|
||||
//=============================================================================
|
||||
|
||||
#define MAX_STRINGS 500000
|
||||
|
@ -183,11 +124,6 @@ extern def_t def_ret, def_parms[MAX_PARMS];
|
|||
#define MAX_STATEMENTS 131072
|
||||
#define MAX_FUNCTIONS 8192
|
||||
|
||||
#define MAX_SOUNDS 1024
|
||||
#define MAX_MODELS 1024
|
||||
#define MAX_FILES 1024
|
||||
#define MAX_DATA_PATH 64
|
||||
|
||||
extern char strings[MAX_STRINGS];
|
||||
extern int strofs;
|
||||
|
||||
|
@ -214,56 +150,6 @@ pr_auxfunction_t *new_auxfunction (void);
|
|||
pr_lineno_t *new_lineno (void);
|
||||
ddef_t *new_local (void);
|
||||
|
||||
int CopyString (const char *str);
|
||||
int ReuseString (const char *str);
|
||||
const char *strip_path (const char *filename);
|
||||
|
||||
typedef struct {
|
||||
qboolean cow; // Turn constants into variables if written to
|
||||
qboolean debug; // Generate debug info for the engine
|
||||
int progsversion; // Progs version to generate code for
|
||||
} code_options_t;
|
||||
|
||||
typedef struct {
|
||||
qboolean promote; // Promote warnings to errors
|
||||
qboolean cow; // Warn on copy-on-write detection
|
||||
qboolean undefined_function; // Warn on undefined function use
|
||||
qboolean uninited_variable; // Warn on use of uninitialized vars
|
||||
qboolean vararg_integer; // Warn on passing an integer to vararg func
|
||||
qboolean integer_divide; // Warn on integer constant division
|
||||
} warn_options_t;
|
||||
|
||||
typedef struct {
|
||||
code_options_t code; // Code generation options
|
||||
warn_options_t warnings; // Warning options
|
||||
|
||||
int verbosity; // 0=silent, goes up to 2 currently
|
||||
qboolean save_temps; // save temporary files
|
||||
qboolean files_dat; // generate files.dat
|
||||
qboolean traditional; // behave more like qcc
|
||||
int strip_path; // number of leading path elements to strip
|
||||
// from source file names
|
||||
} options_t;
|
||||
|
||||
extern options_t options;
|
||||
int DecodeArgs (int argc, char **argv);
|
||||
|
||||
extern const char *this_program;
|
||||
extern const char *sourcedir;
|
||||
|
||||
void parse_cpp_name ();
|
||||
void add_cpp_def (const char *arg);
|
||||
FILE * preprocess_file (const char *filename);
|
||||
extern const char *cpp_name;
|
||||
extern struct dstring_s *tempname;
|
||||
|
||||
extern const char *progs_src;
|
||||
|
||||
//XXX eww :/
|
||||
void PrecacheSound (def_t *e, int ch);
|
||||
void PrecacheModel (def_t *e, int ch);
|
||||
void PrecacheFile (def_t *e, int ch);
|
||||
void WriteFiles (const char *sourcedir);
|
||||
int WriteProgdefs (char *filename);
|
||||
|
||||
#endif//__qfcc_h
|
||||
|
|
|
@ -32,6 +32,21 @@
|
|||
#ifndef __type_h
|
||||
#define __type_h
|
||||
|
||||
#include "QF/pr_comp.h"
|
||||
|
||||
typedef struct type_s {
|
||||
etype_t type;
|
||||
struct type_s *next;
|
||||
// function/pointer/struct types are more complex
|
||||
struct type_s *aux_type; // return type or field type
|
||||
int num_parms; // -1 = variable args
|
||||
struct type_s *parm_types[MAX_PARMS]; // only [num_parms] allocated
|
||||
struct hashtab_s *struct_fields;
|
||||
struct struct_field_s *struct_head;
|
||||
struct struct_field_s **struct_tail;
|
||||
struct class_s *class; // for ev_class
|
||||
} type_t;
|
||||
|
||||
extern type_t type_void;
|
||||
extern type_t type_string;
|
||||
extern type_t type_float;
|
||||
|
@ -57,9 +72,6 @@ extern type_t *type_category;
|
|||
extern type_t *type_ivar;
|
||||
extern type_t *type_module;
|
||||
|
||||
extern def_t def_void;
|
||||
extern def_t def_function;
|
||||
|
||||
struct dstring_s;
|
||||
|
||||
type_t *find_type (type_t *new);
|
||||
|
|
|
@ -38,8 +38,8 @@ YFLAGS = -d
|
|||
bin_PROGRAMS= qfcc
|
||||
|
||||
qfcc_SOURCES= \
|
||||
class.c cmdlib.c cpp.c debug.c emit.c expr.c function.c method.c \
|
||||
opcodes.c options.c pr_def.c pr_imm.c precache.c qc-lex.l qc-parse.y \
|
||||
class.c cmdlib.c cpp.c debug.c emit.c expr.c function.c immediate.c \
|
||||
method.c opcodes.c options.c pr_def.c precache.c qc-lex.l qc-parse.y \
|
||||
qfcc.c struct.c switch.c type.c
|
||||
|
||||
qfcc_LDADD= $(QFCC_LIBS)
|
||||
|
|
|
@ -48,9 +48,10 @@ static const char rcsid[] =
|
|||
|
||||
#include "qfcc.h"
|
||||
|
||||
#include "expr.h"
|
||||
#include "class.h"
|
||||
#include "def.h"
|
||||
#include "expr.h"
|
||||
#include "immediate.h"
|
||||
#include "method.h"
|
||||
#include "struct.h"
|
||||
#include "type.h"
|
||||
|
|
|
@ -54,7 +54,8 @@ static const char rcsid[] =
|
|||
|
||||
#include "QF/dstring.h"
|
||||
|
||||
#include "qfcc.h"
|
||||
#include "cpp.h"
|
||||
#include "options.h"
|
||||
|
||||
typedef struct cpp_arg_s {
|
||||
struct cpp_arg_s *next;
|
||||
|
|
|
@ -46,6 +46,8 @@ static const char rcsid[] =
|
|||
|
||||
#include "qfcc.h"
|
||||
#include "expr.h"
|
||||
#include "immediate.h"
|
||||
#include "options.h"
|
||||
#include "type.h"
|
||||
#include "qc-parse.h"
|
||||
|
||||
|
@ -322,7 +324,7 @@ emit_sub_expr (expr_t *e, def_t *dest)
|
|||
zero.type = expr_types[extract_type (e->e.expr.e1)];
|
||||
|
||||
operator = "-";
|
||||
def_a = PR_ReuseConstant (&zero, 0);
|
||||
def_a = ReuseConstant (&zero, 0);
|
||||
def_b = emit_sub_expr (e->e.expr.e1, 0);
|
||||
if (!dest) {
|
||||
dest = PR_GetTempDef (e->e.expr.type, pr_scope);
|
||||
|
@ -415,7 +417,7 @@ emit_sub_expr (expr_t *e, def_t *dest)
|
|||
case ex_quaternion:
|
||||
case ex_integer:
|
||||
case ex_uinteger:
|
||||
d = PR_ReuseConstant (e, 0);
|
||||
d = ReuseConstant (e, 0);
|
||||
break;
|
||||
case ex_short:
|
||||
d = PR_NewDef (&type_short, 0, pr_scope);
|
||||
|
|
|
@ -48,9 +48,12 @@ static const char rcsid[] =
|
|||
|
||||
#include "qfcc.h"
|
||||
#include "expr.h"
|
||||
#include "function.h"
|
||||
#include "class.h"
|
||||
#include "function.h"
|
||||
#include "idstuff.h"
|
||||
#include "immediate.h"
|
||||
#include "method.h"
|
||||
#include "options.h"
|
||||
#include "struct.h"
|
||||
#include "type.h"
|
||||
#include "qc-parse.h"
|
||||
|
@ -1530,7 +1533,7 @@ function_expr (expr_t *e1, expr_t *e2)
|
|||
// FIXME eww, I hate this, but it's needed :(
|
||||
// FIXME make a qc hook? :)
|
||||
def_t *func = e1->e.def;
|
||||
def_t *e = PR_ReuseConstant (e2, 0);
|
||||
def_t *e = ReuseConstant (e2, 0);
|
||||
|
||||
if (strncmp (func->name, "precache_sound", 14) == 0)
|
||||
PrecacheSound (e, func->name[4]);
|
||||
|
|
|
@ -47,6 +47,7 @@ static const char rcsid[] =
|
|||
|
||||
#include "expr.h"
|
||||
#include "function.h"
|
||||
#include "immediate.h"
|
||||
#include "type.h"
|
||||
|
||||
param_t *
|
||||
|
|
|
@ -36,6 +36,7 @@ static const char rcsid[] =
|
|||
|
||||
#include "qfcc.h"
|
||||
#include "expr.h"
|
||||
#include "immediate.h"
|
||||
#include "type.h"
|
||||
|
||||
static hashtab_t *string_imm_defs;
|
||||
|
@ -47,6 +48,7 @@ static hashtab_t *func_imm_defs;
|
|||
static hashtab_t *pointer_imm_defs;
|
||||
static hashtab_t *quaternion_imm_defs;
|
||||
static hashtab_t *integer_imm_defs;
|
||||
static hashtab_t *strings_tab;
|
||||
|
||||
static const char *
|
||||
string_imm_get_key (void *_def, void *unused)
|
||||
|
@ -100,8 +102,43 @@ int_imm_get_key (void *_def, void *_str)
|
|||
return rep;
|
||||
}
|
||||
|
||||
static const char *
|
||||
stings_get_key (void *_str, void *unsued)
|
||||
{
|
||||
return (char *) _str;
|
||||
}
|
||||
|
||||
int
|
||||
CopyString (const char *str)
|
||||
{
|
||||
int old;
|
||||
|
||||
if (!strings_tab) {
|
||||
strings_tab = Hash_NewTable (16381, stings_get_key, 0, 0);
|
||||
Hash_Add (strings_tab, strings);
|
||||
}
|
||||
old = strofs;
|
||||
strcpy (strings + strofs, str);
|
||||
strofs += strlen (str) + 1;
|
||||
Hash_Add (strings_tab, strings + old);
|
||||
return old;
|
||||
}
|
||||
|
||||
int
|
||||
ReuseString (const char *str)
|
||||
{
|
||||
char *s;
|
||||
|
||||
if (!strings_tab)
|
||||
return CopyString (str);
|
||||
s = Hash_Find (strings_tab, str);
|
||||
if (s)
|
||||
return s - strings;
|
||||
return CopyString (str);
|
||||
}
|
||||
|
||||
def_t *
|
||||
PR_ReuseConstant (expr_t *expr, def_t *def)
|
||||
ReuseConstant (expr_t *expr, def_t *def)
|
||||
{
|
||||
def_t *cn;
|
||||
static dstring_t*rep = 0;
|
||||
|
@ -228,7 +265,6 @@ PR_ReuseConstant (expr_t *expr, def_t *def)
|
|||
} else {
|
||||
cn = PR_NewDef (type, ".imm", 0);
|
||||
cn->ofs = PR_NewLocation (type);
|
||||
pr_global_defs[cn->ofs] = cn;
|
||||
if (type == &type_vector || type == &type_quaternion) {
|
||||
int i;
|
||||
|
|
@ -50,6 +50,7 @@ static const char rcsid[] =
|
|||
|
||||
#include "expr.h"
|
||||
#include "class.h"
|
||||
#include "immediate.h"
|
||||
#include "method.h"
|
||||
#include "struct.h"
|
||||
#include "type.h"
|
||||
|
|
|
@ -33,6 +33,8 @@ static const char rcsid[] =
|
|||
#include <QF/hash.h>
|
||||
|
||||
#include "qfcc.h"
|
||||
#include "options.h"
|
||||
#include "type.h"
|
||||
|
||||
hashtab_t *opcode_type_table_ab;
|
||||
hashtab_t *opcode_type_table_abc;
|
||||
|
|
|
@ -45,9 +45,11 @@ static const char rcsid[] =
|
|||
|
||||
#include <getopt.h>
|
||||
|
||||
#include "QF/pr_comp.h"
|
||||
#include "QF/va.h"
|
||||
|
||||
#include "qfcc.h"
|
||||
#include "cpp.h"
|
||||
#include "options.h"
|
||||
|
||||
const char *this_program;
|
||||
|
||||
|
|
|
@ -44,7 +44,6 @@ typedef struct locref_s {
|
|||
int ofs;
|
||||
} locref_t;
|
||||
|
||||
def_t *pr_global_defs[MAX_REGS]; // to find def for a global variable
|
||||
static def_t *free_temps[4]; // indexted by type size
|
||||
static def_t temp_scope;
|
||||
static locref_t *free_locs[4]; // indexted by type size
|
||||
|
@ -103,7 +102,6 @@ PR_GetArray (type_t *etype, const char *name, int size, def_t *scope,
|
|||
def->ofs = *allocate;
|
||||
def->initialized = def->constant = 1;
|
||||
*allocate += type_size (type) * size + 1;
|
||||
pr_global_defs[def->ofs] = def;
|
||||
G_INT (def->ofs) = def->ofs + 1;
|
||||
return def;
|
||||
}
|
||||
|
@ -130,7 +128,6 @@ PR_GetDef (type_t *type, const char *name, def_t *scope, int *allocate)
|
|||
|
||||
// FIXME: need to sort out location re-use
|
||||
def->ofs = *allocate;
|
||||
pr_global_defs[*allocate] = def;
|
||||
|
||||
/*
|
||||
make automatic defs for the vectors elements .origin can be accessed
|
||||
|
|
|
@ -35,6 +35,13 @@ static const char rcsid[] =
|
|||
#include "cmdlib.h"
|
||||
#include "qfcc.h"
|
||||
#include "expr.h"
|
||||
#include "options.h"
|
||||
#include "type.h"
|
||||
|
||||
#define MAX_SOUNDS 1024
|
||||
#define MAX_MODELS 1024
|
||||
#define MAX_FILES 1024
|
||||
#define MAX_DATA_PATH 64
|
||||
|
||||
static char precache_sounds[MAX_SOUNDS][MAX_DATA_PATH];
|
||||
static int precache_sounds_block[MAX_SOUNDS];
|
||||
|
|
|
@ -48,6 +48,8 @@ static const char rcsid[] =
|
|||
#include "qfcc.h"
|
||||
#include "expr.h"
|
||||
#include "class.h"
|
||||
#include "immediate.h"
|
||||
#include "options.h"
|
||||
#include "struct.h"
|
||||
#include "type.h"
|
||||
#include "qc-parse.h"
|
||||
|
|
|
@ -48,7 +48,9 @@ static const char rcsid[] =
|
|||
#include "qfcc.h"
|
||||
#include "expr.h"
|
||||
#include "function.h"
|
||||
#include "immediate.h"
|
||||
#include "method.h"
|
||||
#include "options.h"
|
||||
#include "class.h"
|
||||
#include "struct.h"
|
||||
#include "switch.h"
|
||||
|
@ -94,7 +96,7 @@ void free_local_inits (hashtab_t *def_list);
|
|||
char *string_val;
|
||||
float vector_val[3];
|
||||
float quaternion_val[4];
|
||||
function_t *function;
|
||||
struct function_s *function;
|
||||
struct switch_block_s *switch_block;
|
||||
struct param_s *param;
|
||||
struct method_s *method;
|
||||
|
@ -374,7 +376,7 @@ var_initializer
|
|||
PR_DefInitialized (current_def);
|
||||
} else {
|
||||
if ($2->type >= ex_string) {
|
||||
current_def = PR_ReuseConstant ($2, current_def);
|
||||
current_def = ReuseConstant ($2, current_def);
|
||||
} else {
|
||||
error ($2, "non-constant expression used for initializer");
|
||||
}
|
||||
|
|
|
@ -61,10 +61,16 @@ static const char rcsid[] =
|
|||
#include <QF/sys.h>
|
||||
#include <QF/va.h>
|
||||
|
||||
#include "cmdlib.h"
|
||||
#include "qfcc.h"
|
||||
#include "expr.h"
|
||||
#include "class.h"
|
||||
#include "cmdlib.h"
|
||||
#include "cpp.h"
|
||||
#include "def.h"
|
||||
#include "expr.h"
|
||||
#include "function.h"
|
||||
#include "idstuff.h"
|
||||
#include "immediate.h"
|
||||
#include "options.h"
|
||||
#include "type.h"
|
||||
|
||||
options_t options;
|
||||
|
@ -103,48 +109,6 @@ ddef_t fields[MAX_FIELDS];
|
|||
int numfielddefs;
|
||||
|
||||
|
||||
/*
|
||||
CopyString
|
||||
|
||||
Return an offset from the string heap
|
||||
*/
|
||||
static hashtab_t *strings_tab;
|
||||
|
||||
static const char *
|
||||
stings_get_key (void *_str, void *unsued)
|
||||
{
|
||||
return (char *) _str;
|
||||
}
|
||||
|
||||
int
|
||||
CopyString (const char *str)
|
||||
{
|
||||
int old;
|
||||
|
||||
if (!strings_tab) {
|
||||
strings_tab = Hash_NewTable (16381, stings_get_key, 0, 0);
|
||||
Hash_Add (strings_tab, strings);
|
||||
}
|
||||
old = strofs;
|
||||
strcpy (strings + strofs, str);
|
||||
strofs += strlen (str) + 1;
|
||||
Hash_Add (strings_tab, strings + old);
|
||||
return old;
|
||||
}
|
||||
|
||||
int
|
||||
ReuseString (const char *str)
|
||||
{
|
||||
char *s;
|
||||
|
||||
if (!strings_tab)
|
||||
return CopyString (str);
|
||||
s = Hash_Find (strings_tab, str);
|
||||
if (s)
|
||||
return s - strings;
|
||||
return CopyString (str);
|
||||
}
|
||||
|
||||
void
|
||||
InitData (void)
|
||||
{
|
||||
|
@ -340,14 +304,9 @@ WriteData (int crc)
|
|||
void
|
||||
PR_BeginCompilation (void)
|
||||
{
|
||||
int i;
|
||||
|
||||
numpr_globals = RESERVED_OFS;
|
||||
pr.def_tail = &pr.def_head;
|
||||
|
||||
for (i = 0; i < RESERVED_OFS; i++)
|
||||
pr_global_defs[i] = &def_void;
|
||||
|
||||
pr_error_count = 0;
|
||||
}
|
||||
|
||||
|
@ -412,8 +371,8 @@ qboolean PR_FinishCompilation (void)
|
|||
if (options.code.debug) {
|
||||
e.type = ex_string;
|
||||
e.e.string_val = debugfile;
|
||||
PR_ReuseConstant (&e, PR_GetDef (&type_string, ".debug_file", 0,
|
||||
&numpr_globals));
|
||||
ReuseConstant (&e, PR_GetDef (&type_string, ".debug_file", 0,
|
||||
&numpr_globals));
|
||||
}
|
||||
|
||||
for (def = pr.def_head.def_next; def; def = def->def_next) {
|
||||
|
|
|
@ -49,6 +49,7 @@ static const char rcsid[] =
|
|||
|
||||
#include "qfcc.h"
|
||||
#include "expr.h"
|
||||
#include "immediate.h"
|
||||
#include "struct.h"
|
||||
#include "type.h"
|
||||
|
||||
|
|
|
@ -46,6 +46,7 @@ static const char rcsid[] =
|
|||
|
||||
#include "qfcc.h"
|
||||
#include "expr.h"
|
||||
#include "options.h"
|
||||
#include "type.h"
|
||||
#include "switch.h"
|
||||
#include "qc-parse.h"
|
||||
|
|
Loading…
Reference in a new issue