From 2818d720c264f043f342efd13707e1d43f883268 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sat, 14 Jul 2001 02:34:16 +0000 Subject: [PATCH] move the full info opcocde table from qfcc to gamecode (There can be only one!:) and use the table in PR_PrintStatement. This means that qfcc now links against libQFgamecode as well as libQFutil --- include/QF/pr_comp.h | 14 +++ libs/gamecode/Makefile.am | 2 +- libs/gamecode/pr_edict.c | 1 + libs/gamecode/pr_exec.c | 102 ++-------------------- libs/gamecode/pr_opcode.c | 159 ++++++++++++++++++++++++++++++++++ tools/qfcc/configure.in | 6 ++ tools/qfcc/include/qfcc.h | 14 +-- tools/qfcc/source/Makefile.am | 2 +- tools/qfcc/source/pr_opcode.c | 120 +------------------------ tools/qfcc/source/qfcc.c | 2 +- 10 files changed, 193 insertions(+), 229 deletions(-) create mode 100644 libs/gamecode/pr_opcode.c diff --git a/include/QF/pr_comp.h b/include/QF/pr_comp.h index f2530a0cc..91603b0c3 100644 --- a/include/QF/pr_comp.h +++ b/include/QF/pr_comp.h @@ -138,6 +138,20 @@ typedef enum { OP_GT_S, } pr_opcode_e; +typedef struct +{ + const char *name; + const char *opname; + pr_opcode_e opcode; + int priority; + qboolean right_associative; + etype_t type_a, type_b, type_c; + int min_version; +} opcode_t; + +extern opcode_t pr_opcodes[]; +opcode_t *PR_Opcode (short opcode); +void PR_Opcode_Init (void); typedef struct statement_s { diff --git a/libs/gamecode/Makefile.am b/libs/gamecode/Makefile.am index 67074fb42..22395ce42 100644 --- a/libs/gamecode/Makefile.am +++ b/libs/gamecode/Makefile.am @@ -3,6 +3,6 @@ INCLUDES= -I$(top_srcdir)/include lib_LTLIBRARIES = libQFgamecode.la libQFgamecode_la_LDFLAGS = -version-info 1:0:0 -libQFgamecode_la_SOURCES = pr_edict.c pr_exec.c pr_strings.c +libQFgamecode_la_SOURCES = pr_edict.c pr_exec.c pr_opcode.c pr_strings.c LIBLIST = libQFgamecode.la @LIBRARY_SEARCH_PATH@ diff --git a/libs/gamecode/pr_edict.c b/libs/gamecode/pr_edict.c index 25b34debd..f0c862933 100644 --- a/libs/gamecode/pr_edict.c +++ b/libs/gamecode/pr_edict.c @@ -1285,6 +1285,7 @@ PR_Init_Cvars (void) void PR_Init (void) { + PR_Opcode_Init (); } edict_t * diff --git a/libs/gamecode/pr_exec.c b/libs/gamecode/pr_exec.c index c706b090e..f520b8fa1 100644 --- a/libs/gamecode/pr_exec.c +++ b/libs/gamecode/pr_exec.c @@ -46,100 +46,6 @@ #include "compat.h" -char *pr_opnames[] = { - "DONE", - - "MUL_F", - "MUL_V", - "MUL_FV", - "MUL_VF", - - "DIV", - - "ADD_F", - "ADD_V", - - "SUB_F", - "SUB_V", - - "EQ_F", - "EQ_V", - "EQ_S", - "EQ_E", - "EQ_FNC", - - "NE_F", - "NE_V", - "NE_S", - "NE_E", - "NE_FNC", - - "LE", - "GE", - "LT", - "GT", - - "INDIRECT", - "INDIRECT", - "INDIRECT", - "INDIRECT", - "INDIRECT", - "INDIRECT", - - "ADDRESS", - - "STORE_F", - "STORE_V", - "STORE_S", - "STORE_ENT", - "STORE_FLD", - "STORE_FNC", - - "STOREP_F", - "STOREP_V", - "STOREP_S", - "STOREP_ENT", - "STOREP_FLD", - "STOREP_FNC", - - "RETURN", - - "NOT_F", - "NOT_V", - "NOT_S", - "NOT_ENT", - "NOT_FNC", - - "IF", - "IFNOT", - - "CALL0", - "CALL1", - "CALL2", - "CALL3", - "CALL4", - "CALL5", - "CALL6", - "CALL7", - "CALL8", - - "STATE", - - "GOTO", - - "AND", - "OR", - - "BITAND", - "BITOR", - - "ADD_S", - "LE_S", - "GE_S", - "LT_S", - "GT_S", -}; - //============================================================================= /* @@ -150,11 +56,13 @@ PR_PrintStatement (progs_t * pr, dstatement_t *s) { int i; int addr = s - pr->pr_statements; + opcode_t *op; Con_Printf ("%-7d ", addr); - if ((unsigned int) s->op < sizeof (pr_opnames) / sizeof (pr_opnames[0])) { - Con_Printf ("%s ", pr_opnames[s->op]); - i = strlen (pr_opnames[s->op]); + op = PR_Opcode (s->op); + if (op) { + Con_Printf ("%s ", op->opname); + i = strlen (op->opname); for (; i < 10; i++) Con_Printf (" "); } diff --git a/libs/gamecode/pr_opcode.c b/libs/gamecode/pr_opcode.c new file mode 100644 index 000000000..bfae34be3 --- /dev/null +++ b/libs/gamecode/pr_opcode.c @@ -0,0 +1,159 @@ +/* Copyright (C) 1996-1997 Id Software, Inc. + + 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 the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + See file, 'COPYING', for details. +*/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "QF/hash.h" +#include "QF/pr_comp.h" + +hashtab_t *opcode_table; + +opcode_t pr_opcodes[] = { + {"", "done", OP_DONE, -1, false, ev_entity, ev_field, ev_void, PROG_ID_VERSION}, + + {"*", "mul.f", OP_MUL_F, 2, false, ev_float, ev_float, ev_float, PROG_ID_VERSION}, + {"*", "mul.v", OP_MUL_V, 2, false, ev_vector, ev_vector, ev_float, PROG_ID_VERSION}, + {"*", "mul.fv", OP_MUL_FV, 2, false, ev_float, ev_vector, ev_vector, PROG_ID_VERSION}, + {"*", "mul.vf", OP_MUL_VF, 2, false, ev_vector, ev_float, ev_vector, PROG_ID_VERSION}, + + {"/", "div.f", OP_DIV_F, 2, false, ev_float, ev_float, ev_float, PROG_ID_VERSION}, + + {"+", "add.f", OP_ADD_F, 3, false, ev_float, ev_float, ev_float, PROG_ID_VERSION}, + {"+", "add.v", OP_ADD_V, 3, false, ev_vector, ev_vector, ev_vector, PROG_ID_VERSION}, + {"+", "add.s", OP_ADD_S, 3, false, ev_string, ev_string, ev_string, PROG_VERSION}, + + {"-", "sub.f", OP_SUB_F, 3, false, ev_float, ev_float, ev_float, PROG_ID_VERSION}, + {"-", "sub.v", OP_SUB_V, 3, false, ev_vector, ev_vector, ev_vector, PROG_ID_VERSION}, + + {"==", "eq.f", OP_EQ_F, 4, false, ev_float, ev_float, ev_float, PROG_ID_VERSION}, + {"==", "eq.v", OP_EQ_V, 4, false, ev_vector, ev_vector, ev_float, PROG_ID_VERSION}, + {"==", "eq.s", OP_EQ_S, 4, false, ev_string, ev_string, ev_float, PROG_ID_VERSION}, + {"==", "eq.e", OP_EQ_E, 4, false, ev_entity, ev_entity, ev_float, PROG_ID_VERSION}, + {"==", "eq.fnc", OP_EQ_FNC, 4, false, ev_func, ev_func, ev_float, PROG_ID_VERSION}, + + {"!=", "ne.f", OP_NE_F, 4, false, ev_float, ev_float, ev_float, PROG_ID_VERSION}, + {"!=", "ne.v", OP_NE_V, 4, false, ev_vector, ev_vector, ev_float, PROG_ID_VERSION}, + {"!=", "ne.s", OP_NE_S, 4, false, ev_string, ev_string, ev_float, PROG_ID_VERSION}, + {"!=", "ne.e", OP_NE_E, 4, false, ev_entity, ev_entity, ev_float, PROG_ID_VERSION}, + {"!=", "ne.fnc", OP_NE_FNC, 4, false, ev_func, ev_func, ev_float, PROG_ID_VERSION}, + + {"<=", "le", OP_LE, 4, false, ev_float, ev_float, ev_float, PROG_ID_VERSION}, + {">=", "ge", OP_GE, 4, false, ev_float, ev_float, ev_float, PROG_ID_VERSION}, + {"<=", "le.s", OP_LE_S, 4, false, ev_string, ev_string, ev_float, PROG_VERSION}, + {">=", "ge.s", OP_GE_S, 4, false, ev_string, ev_string, ev_float, PROG_VERSION}, + {"<", "lt", OP_LT, 4, false, ev_float, ev_float, ev_float, PROG_ID_VERSION}, + {">", "gt", OP_GT, 4, false, ev_float, ev_float, ev_float, PROG_ID_VERSION}, + {"<", "lt.s", OP_LT_S, 4, false, ev_string, ev_string, ev_float, PROG_VERSION}, + {">", "gt.s", OP_GT_S, 4, false, ev_string, ev_string, ev_float, PROG_VERSION}, + + {".", "load.f", OP_LOAD_F, 1, false, ev_entity, ev_field, ev_float, PROG_ID_VERSION}, + {".", "load.v", OP_LOAD_V, 1, false, ev_entity, ev_field, ev_vector, PROG_ID_VERSION}, + {".", "load.s", OP_LOAD_S, 1, false, ev_entity, ev_field, ev_string, PROG_ID_VERSION}, + {".", "load.ent", OP_LOAD_ENT, 1, false, ev_entity, ev_field, ev_entity, PROG_ID_VERSION}, + {".", "load.fld", OP_LOAD_FLD, 1, false, ev_entity, ev_field, ev_field, PROG_ID_VERSION}, + {".", "load.fnc", OP_LOAD_FNC, 1, false, ev_entity, ev_field, ev_func, PROG_ID_VERSION}, + + {".", "address", OP_ADDRESS, 1, false, ev_entity, ev_field, ev_pointer, PROG_ID_VERSION}, + + {"=", "store.f", OP_STORE_F, 5, true, ev_float, ev_float, ev_float, PROG_ID_VERSION}, + {"=", "store.v", OP_STORE_V, 5, true, ev_vector, ev_vector, ev_vector, PROG_ID_VERSION}, + {"=", "store.s", OP_STORE_S, 5, true, ev_string, ev_string, ev_string, PROG_ID_VERSION}, + {"=", "store.ent", OP_STORE_ENT, 5, true, ev_entity, ev_entity, ev_entity, PROG_ID_VERSION}, + {"=", "store.fld", OP_STORE_FLD, 5, true, ev_field, ev_field, ev_field, PROG_ID_VERSION}, + {"=", "store.fnc", OP_STORE_FNC, 5, true, ev_func, ev_func, ev_func, PROG_ID_VERSION}, + + {"=", "storep.f", OP_STOREP_F, 5, true, ev_pointer, ev_float, ev_float, PROG_ID_VERSION}, + {"=", "storep.v", OP_STOREP_V, 5, true, ev_pointer, ev_vector, ev_vector, PROG_ID_VERSION}, + {"=", "storep.s", OP_STOREP_S, 5, true, ev_pointer, ev_string, ev_string, PROG_ID_VERSION}, + {"=", "storep.ent", OP_STOREP_ENT, 5, true, ev_pointer, ev_entity, ev_entity, PROG_ID_VERSION}, + {"=", "storep.fld", OP_STOREP_FLD, 5, true, ev_pointer, ev_field, ev_field, PROG_ID_VERSION}, + {"=", "storep.fnc", OP_STOREP_FNC, 5, true, ev_pointer, ev_func, ev_func, PROG_ID_VERSION}, + + {"", "return", OP_RETURN, -1, false, ev_void, ev_void, ev_void, PROG_ID_VERSION}, + + {"!", "not.f", OP_NOT_F, -1, false, ev_float, ev_void, ev_float, PROG_ID_VERSION}, + {"!", "not.v", OP_NOT_V, -1, false, ev_vector, ev_void, ev_float, PROG_ID_VERSION}, + {"!", "not.s", OP_NOT_S, -1, false, ev_string, ev_void, ev_float, PROG_ID_VERSION}, + {"!", "not.ent", OP_NOT_ENT, -1, false, ev_entity, ev_void, ev_float, PROG_ID_VERSION}, + {"!", "not.fnc", OP_NOT_FNC, -1, false, ev_func, ev_void, ev_float, PROG_ID_VERSION}, + + {"", "if", OP_IF, -1, false, ev_float, ev_float, ev_void, PROG_ID_VERSION}, + {"", "ifnot", OP_IFNOT, -1, false, ev_float, ev_float, ev_void, PROG_ID_VERSION}, + +// calls returns REG_RETURN + {"", "call0", OP_CALL0, -1, false, ev_func, ev_void, ev_void, PROG_ID_VERSION}, + {"", "call1", OP_CALL1, -1, false, ev_func, ev_void, ev_void, PROG_ID_VERSION}, + {"", "call2", OP_CALL2, -1, false, ev_func, ev_void, ev_void, PROG_ID_VERSION}, + {"", "call3", OP_CALL3, -1, false, ev_func, ev_void, ev_void, PROG_ID_VERSION}, + {"", "call4", OP_CALL4, -1, false, ev_func, ev_void, ev_void, PROG_ID_VERSION}, + {"", "call5", OP_CALL5, -1, false, ev_func, ev_void, ev_void, PROG_ID_VERSION}, + {"", "call6", OP_CALL6, -1, false, ev_func, ev_void, ev_void, PROG_ID_VERSION}, + {"", "call7", OP_CALL7, -1, false, ev_func, ev_void, ev_void, PROG_ID_VERSION}, + {"", "call8", OP_CALL8, -1, false, ev_func, ev_void, ev_void, PROG_ID_VERSION}, + + {"", "state", OP_STATE, -1, false, ev_float, ev_float, ev_void, PROG_ID_VERSION}, + + {"", "goto", OP_GOTO, -1, false, ev_float, ev_void, ev_void, PROG_ID_VERSION}, + + {"&&", "and", OP_AND, 6, false, ev_float, ev_float, ev_float, PROG_ID_VERSION}, + {"||", "or", OP_OR, 6, false, ev_float, ev_float, ev_float, PROG_ID_VERSION}, + + {"&", "bitand", OP_BITAND, 2, false, ev_float, ev_float, ev_float, PROG_ID_VERSION}, + {"|", "bitor", OP_BITOR, 2, false, ev_float, ev_float, ev_float, PROG_ID_VERSION}, + {0}, +}; + +static const char * +get_key (void *_op, void *unused) +{ + opcode_t *op = (opcode_t *)_op; + static char rep[4]; + char *r = rep; + + *r++ = (op->opcode & 0x7f) + 2; + *r++ = ((op->opcode >> 7) & 0x7f) + 2; + *r++ = ((op->opcode >> 14) & 0x3) + 2; + *r = 0; + return rep; +} + +opcode_t * +PR_Opcode (short opcode) +{ + opcode_t op; + char rep[100]; + + op.opcode = opcode; + strcpy (rep, get_key (&op, 0)); + return Hash_Find (opcode_table, rep); +} + +void +PR_Opcode_Init (void) +{ + opcode_t *op; + + opcode_table = Hash_NewTable (1021, get_key, 0, 0); + + for (op = pr_opcodes; op->name; op++) { + Hash_Add (opcode_table, op); + } +} diff --git a/tools/qfcc/configure.in b/tools/qfcc/configure.in index b54b294fb..7ec47fcee 100644 --- a/tools/qfcc/configure.in +++ b/tools/qfcc/configure.in @@ -80,6 +80,12 @@ if test "x$HAVE_QF" != xno; then [] ) fi +if test "x$HAVE_QF" != xno; then + AC_CHECK_LIB(QFgamecode, PR_Opcode, + :, HAVE_QF=no, + [-lQFutil] + ) +fi AC_ARG_ENABLE(new-parser, [ --disable-new-parser disable the new parser.]) diff --git a/tools/qfcc/include/qfcc.h b/tools/qfcc/include/qfcc.h index 46538ab30..d2ec12ecf 100644 --- a/tools/qfcc/include/qfcc.h +++ b/tools/qfcc/include/qfcc.h @@ -376,17 +376,6 @@ typedef struct extern pr_info_t pr; -typedef struct -{ - const char *name; - const char *opname; - pr_opcode_e opcode; - int priority; - qboolean right_associative; - etype_t type_a, type_b, type_c; - int min_version; -} opcode_t; - extern opcode_t *op_done; extern opcode_t *op_return; extern opcode_t *op_if; @@ -399,8 +388,7 @@ void PR_AddStatementRef (def_t *def, dstatement_t *st, int field); def_t *PR_Statement (opcode_t *op, def_t *var_a, def_t *var_b); opcode_t *PR_Opcode_Find (const char *name, int priority, def_t *var_a, def_t *var_b, def_t *var_c); -opcode_t *PR_Opcode (short opcode); -void PR_Opcode_Init (void); +void PR_Opcode_Init_Tables (void); //============================================================================ diff --git a/tools/qfcc/source/Makefile.am b/tools/qfcc/source/Makefile.am index 470a9f8fb..7ad8048c0 100644 --- a/tools/qfcc/source/Makefile.am +++ b/tools/qfcc/source/Makefile.am @@ -38,4 +38,4 @@ qfcc_SOURCES= cmdlib.c debug.c pr_comp.c pr_def.c pr_imm.c pr_lex.c pr_opcode.c else qfcc_SOURCES= cmdlib.c debug.c pr_comp.c pr_def.c pr_imm.c pr_lex.c pr_opcode.c qfcc.c endif -qfcc_LDADD= -lQFutil +qfcc_LDADD= -lQFgamecode -lQFutil diff --git a/tools/qfcc/source/pr_opcode.c b/tools/qfcc/source/pr_opcode.c index 29a9f92c1..01087e8f6 100644 --- a/tools/qfcc/source/pr_opcode.c +++ b/tools/qfcc/source/pr_opcode.c @@ -25,7 +25,6 @@ #include "qfcc.h" -hashtab_t *opcode_table; hashtab_t *opcode_priority_table; hashtab_t *opcode_priority_type_table_ab; hashtab_t *opcode_priority_type_table_abc; @@ -37,100 +36,6 @@ opcode_t *op_ifnot; opcode_t *op_state; opcode_t *op_goto; -opcode_t pr_opcodes[] = { - {"", "done", OP_DONE, -1, false, ev_entity, ev_field, ev_void, PROG_ID_VERSION}, - - {"*", "mul.f", OP_MUL_F, 2, false, ev_float, ev_float, ev_float, PROG_ID_VERSION}, - {"*", "mul.v", OP_MUL_V, 2, false, ev_vector, ev_vector, ev_float, PROG_ID_VERSION}, - {"*", "mul.fv", OP_MUL_FV, 2, false, ev_float, ev_vector, ev_vector, PROG_ID_VERSION}, - {"*", "mul.vf", OP_MUL_VF, 2, false, ev_vector, ev_float, ev_vector, PROG_ID_VERSION}, - - {"/", "div.f", OP_DIV_F, 2, false, ev_float, ev_float, ev_float, PROG_ID_VERSION}, - - {"+", "add.f", OP_ADD_F, 3, false, ev_float, ev_float, ev_float, PROG_ID_VERSION}, - {"+", "add.v", OP_ADD_V, 3, false, ev_vector, ev_vector, ev_vector, PROG_ID_VERSION}, - {"+", "add.s", OP_ADD_S, 3, false, ev_string, ev_string, ev_string, PROG_VERSION}, - - {"-", "sub.f", OP_SUB_F, 3, false, ev_float, ev_float, ev_float, PROG_ID_VERSION}, - {"-", "sub.v", OP_SUB_V, 3, false, ev_vector, ev_vector, ev_vector, PROG_ID_VERSION}, - - {"==", "eq.f", OP_EQ_F, 4, false, ev_float, ev_float, ev_float, PROG_ID_VERSION}, - {"==", "eq.v", OP_EQ_V, 4, false, ev_vector, ev_vector, ev_float, PROG_ID_VERSION}, - {"==", "eq.s", OP_EQ_S, 4, false, ev_string, ev_string, ev_float, PROG_ID_VERSION}, - {"==", "eq.e", OP_EQ_E, 4, false, ev_entity, ev_entity, ev_float, PROG_ID_VERSION}, - {"==", "eq.fnc", OP_EQ_FNC, 4, false, ev_func, ev_func, ev_float, PROG_ID_VERSION}, - - {"!=", "ne.f", OP_NE_F, 4, false, ev_float, ev_float, ev_float, PROG_ID_VERSION}, - {"!=", "ne.v", OP_NE_V, 4, false, ev_vector, ev_vector, ev_float, PROG_ID_VERSION}, - {"!=", "ne.s", OP_NE_S, 4, false, ev_string, ev_string, ev_float, PROG_ID_VERSION}, - {"!=", "ne.e", OP_NE_E, 4, false, ev_entity, ev_entity, ev_float, PROG_ID_VERSION}, - {"!=", "ne.fnc", OP_NE_FNC, 4, false, ev_func, ev_func, ev_float, PROG_ID_VERSION}, - - {"<=", "le", OP_LE, 4, false, ev_float, ev_float, ev_float, PROG_ID_VERSION}, - {">=", "ge", OP_GE, 4, false, ev_float, ev_float, ev_float, PROG_ID_VERSION}, - {"<=", "le.s", OP_LE_S, 4, false, ev_string, ev_string, ev_float, PROG_VERSION}, - {">=", "ge.s", OP_GE_S, 4, false, ev_string, ev_string, ev_float, PROG_VERSION}, - {"<", "lt", OP_LT, 4, false, ev_float, ev_float, ev_float, PROG_ID_VERSION}, - {">", "gt", OP_GT, 4, false, ev_float, ev_float, ev_float, PROG_ID_VERSION}, - {"<", "lt.s", OP_LT_S, 4, false, ev_string, ev_string, ev_float, PROG_VERSION}, - {">", "gt.s", OP_GT_S, 4, false, ev_string, ev_string, ev_float, PROG_VERSION}, - - {".", "load.f", OP_LOAD_F, 1, false, ev_entity, ev_field, ev_float, PROG_ID_VERSION}, - {".", "load.v", OP_LOAD_V, 1, false, ev_entity, ev_field, ev_vector, PROG_ID_VERSION}, - {".", "load.s", OP_LOAD_S, 1, false, ev_entity, ev_field, ev_string, PROG_ID_VERSION}, - {".", "load.ent", OP_LOAD_ENT, 1, false, ev_entity, ev_field, ev_entity, PROG_ID_VERSION}, - {".", "load.fld", OP_LOAD_FLD, 1, false, ev_entity, ev_field, ev_field, PROG_ID_VERSION}, - {".", "load.fnc", OP_LOAD_FNC, 1, false, ev_entity, ev_field, ev_func, PROG_ID_VERSION}, - - {".", "address", OP_ADDRESS, 1, false, ev_entity, ev_field, ev_pointer, PROG_ID_VERSION}, - - {"=", "store.f", OP_STORE_F, 5, true, ev_float, ev_float, ev_float, PROG_ID_VERSION}, - {"=", "store.v", OP_STORE_V, 5, true, ev_vector, ev_vector, ev_vector, PROG_ID_VERSION}, - {"=", "store.s", OP_STORE_S, 5, true, ev_string, ev_string, ev_string, PROG_ID_VERSION}, - {"=", "store.ent", OP_STORE_ENT, 5, true, ev_entity, ev_entity, ev_entity, PROG_ID_VERSION}, - {"=", "store.fld", OP_STORE_FLD, 5, true, ev_field, ev_field, ev_field, PROG_ID_VERSION}, - {"=", "store.fnc", OP_STORE_FNC, 5, true, ev_func, ev_func, ev_func, PROG_ID_VERSION}, - - {"=", "storep.f", OP_STOREP_F, 5, true, ev_pointer, ev_float, ev_float, PROG_ID_VERSION}, - {"=", "storep.v", OP_STOREP_V, 5, true, ev_pointer, ev_vector, ev_vector, PROG_ID_VERSION}, - {"=", "storep.s", OP_STOREP_S, 5, true, ev_pointer, ev_string, ev_string, PROG_ID_VERSION}, - {"=", "storep.ent", OP_STOREP_ENT, 5, true, ev_pointer, ev_entity, ev_entity, PROG_ID_VERSION}, - {"=", "storep.fld", OP_STOREP_FLD, 5, true, ev_pointer, ev_field, ev_field, PROG_ID_VERSION}, - {"=", "storep.fnc", OP_STOREP_FNC, 5, true, ev_pointer, ev_func, ev_func, PROG_ID_VERSION}, - - {"", "return", OP_RETURN, -1, false, ev_void, ev_void, ev_void, PROG_ID_VERSION}, - - {"!", "not.f", OP_NOT_F, -1, false, ev_float, ev_void, ev_float, PROG_ID_VERSION}, - {"!", "not.v", OP_NOT_V, -1, false, ev_vector, ev_void, ev_float, PROG_ID_VERSION}, - {"!", "not.s", OP_NOT_S, -1, false, ev_string, ev_void, ev_float, PROG_ID_VERSION}, - {"!", "not.ent", OP_NOT_ENT, -1, false, ev_entity, ev_void, ev_float, PROG_ID_VERSION}, - {"!", "not.fnc", OP_NOT_FNC, -1, false, ev_func, ev_void, ev_float, PROG_ID_VERSION}, - - {"", "if", OP_IF, -1, false, ev_float, ev_float, ev_void, PROG_ID_VERSION}, - {"", "ifnot", OP_IFNOT, -1, false, ev_float, ev_float, ev_void, PROG_ID_VERSION}, - -// calls returns REG_RETURN - {"", "call0", OP_CALL0, -1, false, ev_func, ev_void, ev_void, PROG_ID_VERSION}, - {"", "call1", OP_CALL1, -1, false, ev_func, ev_void, ev_void, PROG_ID_VERSION}, - {"", "call2", OP_CALL2, -1, false, ev_func, ev_void, ev_void, PROG_ID_VERSION}, - {"", "call3", OP_CALL3, -1, false, ev_func, ev_void, ev_void, PROG_ID_VERSION}, - {"", "call4", OP_CALL4, -1, false, ev_func, ev_void, ev_void, PROG_ID_VERSION}, - {"", "call5", OP_CALL5, -1, false, ev_func, ev_void, ev_void, PROG_ID_VERSION}, - {"", "call6", OP_CALL6, -1, false, ev_func, ev_void, ev_void, PROG_ID_VERSION}, - {"", "call7", OP_CALL7, -1, false, ev_func, ev_void, ev_void, PROG_ID_VERSION}, - {"", "call8", OP_CALL8, -1, false, ev_func, ev_void, ev_void, PROG_ID_VERSION}, - - {"", "state", OP_STATE, -1, false, ev_float, ev_float, ev_void, PROG_ID_VERSION}, - - {"", "goto", OP_GOTO, -1, false, ev_float, ev_void, ev_void, PROG_ID_VERSION}, - - {"&&", "and", OP_AND, 6, false, ev_float, ev_float, ev_float, PROG_ID_VERSION}, - {"||", "or", OP_OR, 6, false, ev_float, ev_float, ev_float, PROG_ID_VERSION}, - - {"&", "bitand", OP_BITAND, 2, false, ev_float, ev_float, ev_float, PROG_ID_VERSION}, - {"|", "bitor", OP_BITOR, 2, false, ev_float, ev_float, ev_float, PROG_ID_VERSION}, -}; - static type_t *types[] = { &type_void, &type_string, @@ -226,10 +131,6 @@ get_key (void *_op, void *_tab) *r++ = op->type_b + 2; *r++ = op->type_c + 2; *r = 0; - } else if (tab == &opcode_table) { - *r++ = (op->opcode & 0xff) + 2; - *r++ = ((op->opcode >> 8) & 0xff) + 2; - *r = 0; } else { abort (); } @@ -262,34 +163,21 @@ PR_Opcode_Find (const char *name, int priority, def_t *var_a, def_t *var_b, def_ } } -opcode_t * -PR_Opcode (short opcode) -{ - opcode_t op; - char rep[100]; - - op.opcode = opcode; - strcpy (rep, get_key (&op, &opcode_table)); - return Hash_Find (opcode_table, rep); -} - void -PR_Opcode_Init (void) +PR_Opcode_Init_Tables (void) { - int i; + opcode_t *op; - opcode_table = Hash_NewTable (1021, get_key, 0, &opcode_table); + PR_Opcode_Init (); opcode_priority_table = Hash_NewTable (1021, get_key, 0, &opcode_priority_table); opcode_priority_type_table_ab = Hash_NewTable (1021, get_key, 0, &opcode_priority_type_table_ab); opcode_priority_type_table_abc = Hash_NewTable (1021, get_key, 0, &opcode_priority_type_table_abc); - for (i = 0; i < sizeof (pr_opcodes) / sizeof (pr_opcodes[0]); i++) { - opcode_t *op = &pr_opcodes[i]; + for (op = pr_opcodes; op->name; op++) { if (op->min_version > options.version) continue; - Hash_Add (opcode_table, op); Hash_Add (opcode_priority_table, op); Hash_Add (opcode_priority_type_table_ab, op); Hash_Add (opcode_priority_type_table_abc, op); diff --git a/tools/qfcc/source/qfcc.c b/tools/qfcc/source/qfcc.c index ac9a1d063..2dcc4b0ad 100644 --- a/tools/qfcc/source/qfcc.c +++ b/tools/qfcc/source/qfcc.c @@ -963,7 +963,7 @@ Options: \n\ printf ("Source directory: %s\n", sourcedir); } - PR_Opcode_Init (); + PR_Opcode_Init_Tables (); InitData ();