2001-06-20 07:02:36 +00:00
|
|
|
typedef enum {
|
2001-06-25 22:11:20 +00:00
|
|
|
ex_label,
|
2001-06-26 03:33:01 +00:00
|
|
|
ex_block,
|
2001-06-20 21:18:04 +00:00
|
|
|
ex_expr, // binary expression
|
|
|
|
ex_uexpr, // unary expression
|
2001-06-15 19:38:43 +00:00
|
|
|
ex_def,
|
2001-08-11 21:15:24 +00:00
|
|
|
ex_temp, // temporary variable
|
2001-10-17 07:45:37 +00:00
|
|
|
ex_nil, // umm, nil, null. nuff said
|
2001-12-08 08:19:48 +00:00
|
|
|
ex_name,
|
2001-07-18 06:37:14 +00:00
|
|
|
|
2001-06-15 19:38:43 +00:00
|
|
|
ex_string,
|
2001-07-18 06:37:14 +00:00
|
|
|
ex_float,
|
2001-06-15 19:38:43 +00:00
|
|
|
ex_vector,
|
2001-07-18 06:37:14 +00:00
|
|
|
ex_entity,
|
|
|
|
ex_field,
|
|
|
|
ex_func,
|
|
|
|
ex_pointer,
|
2001-06-15 19:38:43 +00:00
|
|
|
ex_quaternion,
|
2001-07-22 06:59:12 +00:00
|
|
|
ex_integer,
|
2001-11-13 08:58:54 +00:00
|
|
|
ex_uinteger,
|
2001-12-07 20:10:30 +00:00
|
|
|
ex_short,
|
2001-06-20 07:02:36 +00:00
|
|
|
} expr_type;
|
|
|
|
|
2001-06-25 22:11:20 +00:00
|
|
|
typedef struct {
|
|
|
|
statref_t *refs;
|
|
|
|
dstatement_t *statement;
|
2001-11-13 08:58:54 +00:00
|
|
|
const char *name;
|
2001-08-11 21:46:02 +00:00
|
|
|
} elabel_t;
|
2001-06-25 22:11:20 +00:00
|
|
|
|
2001-06-26 03:33:01 +00:00
|
|
|
typedef struct {
|
|
|
|
struct expr_s *head;
|
|
|
|
struct expr_s **tail;
|
2001-08-11 21:15:24 +00:00
|
|
|
struct expr_s *result;
|
2001-08-24 21:47:52 +00:00
|
|
|
int is_call;
|
2001-06-26 03:33:01 +00:00
|
|
|
} block_t;
|
|
|
|
|
2001-08-11 21:15:24 +00:00
|
|
|
typedef struct {
|
|
|
|
struct expr_s *expr;
|
|
|
|
def_t *def;
|
|
|
|
type_t *type;
|
|
|
|
int users;
|
|
|
|
} temp_t;
|
|
|
|
|
2001-06-15 19:38:43 +00:00
|
|
|
typedef struct expr_s {
|
2001-06-20 21:18:04 +00:00
|
|
|
struct expr_s *next;
|
2001-06-20 07:02:36 +00:00
|
|
|
expr_type type;
|
2001-06-26 16:23:21 +00:00
|
|
|
int line;
|
|
|
|
string_t file;
|
2001-06-28 15:20:31 +00:00
|
|
|
int paren;
|
2001-06-15 19:38:43 +00:00
|
|
|
union {
|
2001-08-11 21:46:02 +00:00
|
|
|
elabel_t label;
|
2001-06-26 03:33:01 +00:00
|
|
|
block_t block;
|
2001-06-15 19:38:43 +00:00
|
|
|
struct {
|
|
|
|
int op;
|
|
|
|
type_t *type;
|
|
|
|
struct expr_s *e1;
|
|
|
|
struct expr_s *e2;
|
|
|
|
} expr;
|
|
|
|
def_t *def;
|
2001-08-11 21:15:24 +00:00
|
|
|
temp_t temp;
|
2001-07-18 06:37:14 +00:00
|
|
|
|
2001-11-13 08:58:54 +00:00
|
|
|
const char *string_val;
|
2001-07-18 06:37:14 +00:00
|
|
|
float float_val;
|
2001-06-15 19:38:43 +00:00
|
|
|
float vector_val[3];
|
2001-07-18 06:37:14 +00:00
|
|
|
int entity_val;
|
|
|
|
int field_val;
|
|
|
|
int func_val;
|
|
|
|
int pointer_val;
|
2001-06-15 19:38:43 +00:00
|
|
|
float quaternion_val[4];
|
2001-07-23 01:31:22 +00:00
|
|
|
int integer_val;
|
2001-11-15 00:46:36 +00:00
|
|
|
unsigned int uinteger_val;
|
2001-12-07 20:10:30 +00:00
|
|
|
short short_val;
|
2001-06-15 19:38:43 +00:00
|
|
|
} e;
|
|
|
|
} expr_t;
|
|
|
|
|
2001-07-26 05:15:34 +00:00
|
|
|
extern etype_t qc_types[];
|
|
|
|
extern struct type_s *types[];
|
|
|
|
extern expr_type expr_types[];
|
|
|
|
|
2001-10-02 18:55:52 +00:00
|
|
|
type_t *get_type (expr_t *e);
|
|
|
|
etype_t extract_type (expr_t *e);
|
2001-07-26 05:15:34 +00:00
|
|
|
|
2001-06-15 19:38:43 +00:00
|
|
|
expr_t *new_expr (void);
|
2001-11-13 08:58:54 +00:00
|
|
|
const char *new_label_name (void);
|
2001-06-26 02:46:02 +00:00
|
|
|
expr_t *new_label_expr (void);
|
2001-06-26 03:33:01 +00:00
|
|
|
expr_t *new_block_expr (void);
|
2001-06-26 02:46:02 +00:00
|
|
|
expr_t *new_binary_expr (int op, expr_t *e1, expr_t *e2);
|
|
|
|
expr_t *new_unary_expr (int op, expr_t *e1);
|
2001-08-11 21:15:24 +00:00
|
|
|
expr_t *new_temp_def_expr (type_t *type);
|
2001-11-13 18:49:27 +00:00
|
|
|
expr_t *new_bind_expr (expr_t *e1, expr_t *e2);
|
2001-06-26 03:33:01 +00:00
|
|
|
|
pr_comp.h:
o add ev_uniteger to the types enum
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
progs.h:
o add uinteger accessors
pr_exec.c:
o implement ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
pr_opcode.c:
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
expr.h:
o prototype inc_users
qfcc.h:
o add externs for op_ifbe, op_ifb, op_ifae and op_ifa
emit.c:
o don't bother emiting an assignment to a temp def that's only used once
(ie, it's never read, only written to)
o support the new if* instructions
expr.c:
o support the new if* insructions
o dectect expression loops in append_expr
o support unsigned integers
o re-work temp def usage counting
pr_def.c
o debugging for temp def usage counts
pr_opcode.c:
o support the new if* instructions
qc-parse.y:
o provide defines for IFBE IFB IFAE IFA
switch.c:
o do binary searches for strings, floats and ints if there are more than
8 cases in a switch. Strings need more testing.
2001-11-09 00:58:16 +00:00
|
|
|
void inc_users (expr_t *e);
|
|
|
|
|
2001-06-26 03:33:01 +00:00
|
|
|
expr_t *append_expr (expr_t *block, expr_t *e);
|
|
|
|
|
2001-06-25 17:15:56 +00:00
|
|
|
void print_expr (expr_t *e);
|
2001-07-24 22:30:31 +00:00
|
|
|
|
2001-07-24 23:53:35 +00:00
|
|
|
void convert_int (expr_t *e);
|
|
|
|
|
2001-07-24 22:30:31 +00:00
|
|
|
expr_t *test_expr (expr_t *e, int test);
|
2001-06-20 07:02:36 +00:00
|
|
|
expr_t *binary_expr (int op, expr_t *e1, expr_t *e2);
|
2001-08-10 16:17:00 +00:00
|
|
|
expr_t *asx_expr (int op, expr_t *e1, expr_t *e2);
|
2001-06-20 07:02:36 +00:00
|
|
|
expr_t *unary_expr (int op, expr_t *e);
|
2001-06-20 21:18:04 +00:00
|
|
|
expr_t *function_expr (expr_t *e1, expr_t *e2);
|
2001-07-23 02:27:46 +00:00
|
|
|
expr_t *return_expr (function_t *f, expr_t *e);
|
2001-08-11 21:15:24 +00:00
|
|
|
expr_t *conditional_expr (expr_t *cond, expr_t *e1, expr_t *e2);
|
2001-08-20 06:22:28 +00:00
|
|
|
expr_t *incop_expr (int op, expr_t *e, int postop);
|
2001-11-15 00:46:36 +00:00
|
|
|
expr_t *array_expr (expr_t *array, expr_t *index);
|
2001-06-26 07:21:20 +00:00
|
|
|
|
2001-07-14 01:15:40 +00:00
|
|
|
def_t *emit_statement (int line, opcode_t *op, def_t *var_a, def_t *var_b, def_t *var_c);
|
2001-06-26 07:21:20 +00:00
|
|
|
void emit_expr (expr_t *e);
|
2001-06-28 21:26:40 +00:00
|
|
|
|
2001-07-03 20:53:49 +00:00
|
|
|
expr_t *error (expr_t *e, const char *fmt, ...) __attribute__((format(printf, 2,3)));
|
|
|
|
void warning (expr_t *e, const char *fmt, ...) __attribute__((format(printf, 2,3)));
|
2001-07-14 01:15:40 +00:00
|
|
|
|
2001-10-25 17:48:35 +00:00
|
|
|
const char *get_op_string (int op);
|
|
|
|
|
2001-07-14 01:15:40 +00:00
|
|
|
extern int lineno_base;
|