2 Copyright (C) 1996-1997 Id Software, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 char *prvm_opnames[] =
116 "OP_DIVSTORE_F", //70
129 "OP_FETCH_GBL_F", //80
166 //mostly they are various different ways of adding two vars with conversions.
196 "OP_STOREP_IF", //120
219 "OP_POINTER_ADD", //32 bit pointers
224 "OP_LOADA_ENT", //140
236 "OP_LOADP_FLD", //150
258 //-------------------------------------
259 //string manipulation.
260 "OP_ADD_SF", //(char*)c = (char*)a + (float)b
261 "OP_SUB_S", //(float)c = (char*)a - (char*)b
262 "OP_STOREP_C",//(float)c = *(char*)b = (float)a
263 "OP_LOADP_C", //(float)c = *(char*) //170
264 //-------------------------------------
286 //erm... FTEQCC doesn't make use of these... These are for DP.
288 "OP_GSTOREP_F", //190
290 "OP_GSTOREP_FLD", // integers
292 "OP_GSTOREP_FNC", // pointers
298 "OP_GLOAD_ENT", //200
303 //back to ones that we do use.
305 "OP_PUSH", //push 4octets onto the local-stack (which is ALWAYS poped on function return). Returns a pointer.
306 "OP_POP", //pop those ones that were pushed (don't over do it). Needs assembler.
314 char *PRVM_GlobalString (int ofs);
315 char *PRVM_GlobalStringNoContents (int ofs);
316 extern ddef_t *PRVM_ED_FieldAtOfs(int ofs);
319 //=============================================================================
326 extern cvar_t prvm_statementprofiling;
327 void PRVM_PrintStatement (dstatement_t *s)
330 int opnum = (int)(s - prog->statements);
332 Con_Printf("s%i: ", opnum);
333 if( prog->statement_linenums )
334 Con_Printf( "%s:%i: ", PRVM_GetString( prog->xfunction->s_file ), prog->statement_linenums[ opnum ] );
336 if (prvm_statementprofiling.integer)
337 Con_Printf("%7.0f ", prog->statement_profile[s - prog->statements]);
339 if ( (unsigned)s->op < sizeof(prvm_opnames)/sizeof(prvm_opnames[0]))
341 Con_Printf("%s ", prvm_opnames[s->op]);
342 i = strlen(prvm_opnames[s->op]);
343 // don't count a preceding color tag when padding the name
344 if (prvm_opnames[s->op][0] == STRING_COLOR_TAG)
349 if (s->op == OP_IF || s->op == OP_IFNOT)
350 Con_Printf("%s, s%i",PRVM_GlobalString((unsigned short) s->a),(signed short)s->b + opnum);
351 else if (s->op == OP_GOTO)
352 Con_Printf("s%i",(signed short)s->a + opnum);
353 else if ( (unsigned)(s->op - OP_STORE_F) < 6)
355 Con_Print(PRVM_GlobalString((unsigned short) s->a));
357 Con_Print(PRVM_GlobalStringNoContents((unsigned short) s->b));
359 else if (s->op == OP_ADDRESS || (unsigned)(s->op - OP_LOAD_F) < 6)
362 Con_Print(PRVM_GlobalString((unsigned short) s->a));
366 Con_Print(PRVM_GlobalStringNoContents((unsigned short) s->b));
371 Con_Print(PRVM_GlobalStringNoContents((unsigned short) s->c));
377 Con_Print(PRVM_GlobalString((unsigned short) s->a));
381 Con_Print(PRVM_GlobalString((unsigned short) s->b));
385 if(!s->b) // added for debugging --blub
386 Con_Print(", (nil)");
388 Con_Print(PRVM_GlobalStringNoContents((unsigned short) s->c));
394 void PRVM_PrintFunctionStatements (const char *name)
396 int i, firststatement, endstatement;
398 func = PRVM_ED_FindFunction (name);
401 Con_Printf("%s progs: no function named %s\n", PRVM_NAME, name);
404 firststatement = func->first_statement;
405 if (firststatement < 0)
407 Con_Printf("%s progs: function %s is builtin #%i\n", PRVM_NAME, name, -firststatement);
411 // find the end statement
412 endstatement = prog->progs->numstatements;
413 for (i = 0;i < prog->progs->numfunctions;i++)
414 if (endstatement > prog->functions[i].first_statement && firststatement < prog->functions[i].first_statement)
415 endstatement = prog->functions[i].first_statement;
417 // now print the range of statements
418 Con_Printf("%s progs: disassembly of function %s (statements %i-%i, locals %i-%i):\n", PRVM_NAME, name, firststatement, endstatement, func->parm_start, func->parm_start + func->locals - 1);
419 for (i = firststatement;i < endstatement;i++)
421 PRVM_PrintStatement(prog->statements + i);
422 prog->statement_profile[i] = 0;
432 void PRVM_PrintFunction_f (void)
436 Con_Printf("usage: prvm_printfunction <program name> <function name>\n");
441 if(!PRVM_SetProgFromString(Cmd_Argv(1)))
444 PRVM_PrintFunctionStatements(Cmd_Argv(2));
454 void PRVM_StackTrace (void)
459 prog->stack[prog->depth].s = prog->xstatement;
460 prog->stack[prog->depth].f = prog->xfunction;
461 for (i = prog->depth;i > 0;i--)
463 f = prog->stack[i].f;
466 Con_Print("<NULL FUNCTION>\n");
468 Con_Printf("%12s : %s : statement %i\n", PRVM_GetString(f->s_file), PRVM_GetString(f->s_name), prog->stack[i].s - f->first_statement);
472 void PRVM_ShortStackTrace(char *buf, size_t bufsize)
479 dpsnprintf(buf, bufsize, "(%s) ", prog->name);
483 strlcpy(buf, "<NO PROG>", bufsize);
487 prog->stack[prog->depth].s = prog->xstatement;
488 prog->stack[prog->depth].f = prog->xfunction;
489 for (i = prog->depth;i > 0;i--)
491 f = prog->stack[i].f;
495 ? va("%s:%s(%i) ", PRVM_GetString(f->s_file), PRVM_GetString(f->s_name), prog->stack[i].s - f->first_statement)
504 void PRVM_CallProfile (void)
506 mfunction_t *f, *best;
511 Con_Printf( "%s Call Profile:\n", PRVM_NAME );
518 for (i=0 ; i<prog->progs->numfunctions ; i++)
520 f = &prog->functions[i];
521 if (max < f->totaltime)
529 sum += best->totaltime;
530 Con_Printf("%9.4f %s\n", best->totaltime, PRVM_GetString(best->s_name));
535 Con_Printf("Total time since last profile reset: %9.4f\n", Sys_DoubleTime() - prog->starttime);
536 Con_Printf(" - used by QC code of this VM: %9.4f\n", sum);
538 prog->starttime = Sys_DoubleTime();
541 void PRVM_Profile (int maxfunctions, int mininstructions, int sortby)
543 mfunction_t *f, *best;
547 Con_Printf( "%s Profile:\n[CallCount] [Statement] [BuiltinCt] [StmtTotal] [BltnTotal] [self]\n", PRVM_NAME );
548 // 12345678901 12345678901 12345678901 12345678901 12345678901 123.45%
555 for (i=0 ; i<prog->progs->numfunctions ; i++)
557 f = &prog->functions[i];
560 if (max < f->profile_total + f->builtinsprofile_total + f->callcount)
562 max = f->profile_total + f->builtinsprofile_total + f->callcount;
568 if (max < f->profile + f->builtinsprofile + f->callcount)
570 max = f->profile + f->builtinsprofile + f->callcount;
577 if (num < maxfunctions && max >= mininstructions)
579 if (best->first_statement < 0)
580 Con_Printf("%11.0f ----------------------- builtin ----------------------- %s\n", best->callcount, PRVM_GetString(best->s_name));
581 // 12345678901 12345678901 12345678901 12345678901 123.45%
583 Con_Printf("%11.0f %11.0f %11.0f %11.0f %11.0f %6.2f%% %s\n", best->callcount, best->profile, best->builtinsprofile, best->profile_total, best->builtinsprofile_total, (best->profile + best->builtinsprofile) * 100.0 / (best->profile_total + best->builtinsprofile_total), PRVM_GetString(best->s_name));
587 best->builtinsprofile = 0;
588 best->profile_total = 0;
589 best->builtinsprofile_total = 0;
601 void PRVM_CallProfile_f (void)
605 Con_Print("prvm_callprofile <program name>\n");
610 if(!PRVM_SetProgFromString(Cmd_Argv(1)))
624 void PRVM_Profile_f (void)
630 howmany = atoi(Cmd_Argv(2));
631 else if (Cmd_Argc() != 2)
633 Con_Print("prvm_profile <program name>\n");
638 if(!PRVM_SetProgFromString(Cmd_Argv(1)))
641 PRVM_Profile(howmany, 1, 0);
646 void PRVM_ChildProfile_f (void)
652 howmany = atoi(Cmd_Argv(2));
653 else if (Cmd_Argc() != 2)
655 Con_Print("prvm_childprofile <program name>\n");
660 if(!PRVM_SetProgFromString(Cmd_Argv(1)))
663 PRVM_Profile(howmany, 1, 1);
668 void PRVM_CrashAll(void)
671 prvm_prog_t *oldprog = prog;
673 for(i = 0; i < PRVM_MAXPROGS; i++)
675 if(!PRVM_ProgLoaded(i))
684 void PRVM_PrintState(void)
687 if(prog->statestring)
689 Con_Printf("Caller-provided information: %s\n", prog->statestring);
693 for (i = -7; i <= 0;i++)
694 if (prog->xstatement + i >= prog->xfunction->first_statement)
695 PRVM_PrintStatement (prog->statements + prog->xstatement + i);
698 Con_Print("null function executing??\n");
702 extern sizebuf_t vm_tempstringsbuf;
703 extern cvar_t prvm_errordump;
704 void Host_Savegame_to (const char *name);
705 void PRVM_Crash(void)
710 prog->funcoffsets.SV_Shutdown = 0; // don't call SV_Shutdown on crash
712 if( prog->depth > 0 )
714 Con_Printf("QuakeC crash report for %s:\n", PRVM_NAME);
718 if(prvm_errordump.integer)
721 Host_Savegame_to(va("crash-%s.dmp", PRVM_NAME));
724 // dump the stack so host_error can shutdown functions
726 prog->localstack_used = 0;
728 // delete all tempstrings (FIXME: is this safe in VM->engine->VM recursion?)
729 vm_tempstringsbuf.cursize = 0;
731 // reset the prog pointer
736 ============================================================================
739 The interpretation main loop
740 ============================================================================
747 Returns the new program statement counter
750 int PRVM_EnterFunction (mfunction_t *f)
755 PRVM_ERROR ("PRVM_EnterFunction: NULL function in %s", PRVM_NAME);
757 prog->stack[prog->depth].s = prog->xstatement;
758 prog->stack[prog->depth].f = prog->xfunction;
759 prog->stack[prog->depth].profile_acc = -f->profile;
760 prog->stack[prog->depth].builtinsprofile_acc = -f->builtinsprofile;
762 if (prog->depth >=PRVM_MAX_STACK_DEPTH)
763 PRVM_ERROR ("stack overflow");
765 // save off any locals that the new function steps on
767 if (prog->localstack_used + c > PRVM_LOCALSTACK_SIZE)
768 PRVM_ERROR ("PRVM_ExecuteProgram: locals stack overflow in %s", PRVM_NAME);
770 for (i=0 ; i < c ; i++)
771 prog->localstack[prog->localstack_used+i] = ((int *)prog->globals.generic)[f->parm_start + i];
772 prog->localstack_used += c;
776 for (i=0 ; i<f->numparms ; i++)
778 for (j=0 ; j<f->parm_size[i] ; j++)
780 ((int *)prog->globals.generic)[o] = ((int *)prog->globals.generic)[OFS_PARM0+i*3+j];
787 return f->first_statement - 1; // offset the s++
795 int PRVM_LeaveFunction (void)
800 if (prog->depth <= 0)
801 PRVM_ERROR ("prog stack underflow in %s", PRVM_NAME);
803 if (!prog->xfunction)
804 PRVM_ERROR ("PR_LeaveFunction: NULL function in %s", PRVM_NAME);
805 // restore locals from the stack
806 c = prog->xfunction->locals;
807 prog->localstack_used -= c;
808 if (prog->localstack_used < 0)
809 PRVM_ERROR ("PRVM_ExecuteProgram: locals stack underflow in %s", PRVM_NAME);
811 for (i=0 ; i < c ; i++)
812 ((int *)prog->globals.generic)[prog->xfunction->parm_start + i] = prog->localstack[prog->localstack_used+i];
818 prog->xfunction = prog->stack[prog->depth].f;
819 prog->stack[prog->depth].profile_acc += f->profile;
820 prog->stack[prog->depth].builtinsprofile_acc += f->builtinsprofile;
823 prog->stack[prog->depth-1].profile_acc += prog->stack[prog->depth].profile_acc;
824 prog->stack[prog->depth-1].builtinsprofile_acc += prog->stack[prog->depth].builtinsprofile_acc;
828 // if f is already on the call stack...
829 // we cannot add this profile data to it now
830 // or we would add it more than once
831 // so, let's only add to the function's profile if it is the outermost call
832 f->profile_total += prog->stack[prog->depth].profile_acc;
833 f->builtinsprofile_total += prog->stack[prog->depth].builtinsprofile_acc;
836 return prog->stack[prog->depth].s;
839 void PRVM_Init_Exec(void)
843 prog->localstack_used = 0;
844 // reset the string table
848 void CStateOp(prvm_prog_t *prog, float vara, float varb, mfunction_t *currentFunc)
850 // This function should not be called...
851 PRVM_ERROR("CStateOp not implemented.\n");
854 void CWStateOp(prvm_prog_t *prog, float vara, float varb, mfunction_t *currentFunc)
856 // This function should not be called...
857 PRVM_ERROR("CWStateOp not implemented.\n");
860 void ThinkTimeOp(prvm_prog_t *prog, prvm_edict_t *ent, float varb)
862 ent->fields.server->nextthink = prog->globals.server->time + varb;
870 // LordHavoc: optimized
871 #define OPA ((prvm_eval_t *)&prog->globals.generic[(unsigned short) st->a])
872 #define OPB ((prvm_eval_t *)&prog->globals.generic[(unsigned short) st->b])
873 #define OPC ((prvm_eval_t *)&prog->globals.generic[(unsigned short) st->c])
874 extern cvar_t prvm_traceqc;
875 extern cvar_t prvm_statementprofiling;
876 extern sizebuf_t vm_tempstringsbuf;
877 extern qboolean prvm_runawaycheck;
878 extern qboolean prvm_boundscheck;
879 void MVM_ExecuteProgram (func_t fnum, const char *errormessage)
881 dstatement_t *st, *startst;
882 mfunction_t *f, *newf;
885 int jumpcount, cachedpr_trace, exitdepth;
886 int restorevm_tempstringsbuf_cursize;
889 calltime = Sys_DoubleTime();
891 if (!fnum || fnum >= (unsigned int)prog->progs->numfunctions)
893 if (prog->globaloffsets.self >= 0 && PRVM_GLOBALFIELDVALUE(prog->globaloffsets.self)->edict)
894 PRVM_ED_Print(PRVM_PROG_TO_EDICT(PRVM_GLOBALFIELDVALUE(prog->globaloffsets.self)->edict), NULL);
895 PRVM_ERROR ("MVM_ExecuteProgram: %s", errormessage);
898 f = &prog->functions[fnum];
900 // after executing this function, delete all tempstrings it created
901 restorevm_tempstringsbuf_cursize = vm_tempstringsbuf.cursize;
903 prog->trace = prvm_traceqc.integer;
905 // we know we're done when pr_depth drops to this
906 exitdepth = prog->depth;
908 // make a stack frame
909 st = &prog->statements[PRVM_EnterFunction (f)];
910 // save the starting statement pointer for profiling
911 // (when the function exits or jumps, the (st - startst) integer value is
912 // added to the function's profile counter)
914 // instead of counting instructions, we count jumps
916 // add one to the callcount of this function because otherwise engine-called functions aren't counted
917 prog->xfunction->callcount++;
920 cachedpr_trace = prog->trace;
921 if (prvm_runawaycheck)
923 #define PRVMRUNAWAYCHECK 1
924 if (prvm_statementprofiling.integer)
926 #define PRVMSTATEMENTPROFILING 1
927 if (prvm_boundscheck)
929 #define PRVMBOUNDSCHECK 1
933 #include "prvm_execprogram.h"
938 #include "prvm_execprogram.h"
940 #undef PRVMBOUNDSCHECK
947 #include "prvm_execprogram.h"
952 #include "prvm_execprogram.h"
955 #undef PRVMSTATEMENTPROFILING
959 if (prvm_boundscheck)
961 #define PRVMBOUNDSCHECK 1
965 #include "prvm_execprogram.h"
970 #include "prvm_execprogram.h"
972 #undef PRVMBOUNDSCHECK
979 #include "prvm_execprogram.h"
984 #include "prvm_execprogram.h"
988 #undef PRVMRUNAWAYCHECK
992 if (prvm_statementprofiling.integer)
994 #define PRVMSTATEMENTPROFILING 1
995 if (prvm_boundscheck)
997 #define PRVMBOUNDSCHECK 1
1001 #include "prvm_execprogram.h"
1006 #include "prvm_execprogram.h"
1008 #undef PRVMBOUNDSCHECK
1015 #include "prvm_execprogram.h"
1020 #include "prvm_execprogram.h"
1023 #undef PRVMSTATEMENTPROFILING
1027 if (prvm_boundscheck)
1029 #define PRVMBOUNDSCHECK 1
1033 #include "prvm_execprogram.h"
1038 #include "prvm_execprogram.h"
1040 #undef PRVMBOUNDSCHECK
1047 #include "prvm_execprogram.h"
1052 #include "prvm_execprogram.h"
1059 if (developer.integer >= 200 && vm_tempstringsbuf.cursize > restorevm_tempstringsbuf_cursize)
1060 Con_Printf("MVM_ExecuteProgram: %s used %i bytes of tempstrings\n", PRVM_GetString(prog->functions[fnum].s_name), vm_tempstringsbuf.cursize - restorevm_tempstringsbuf_cursize);
1061 // delete tempstrings created by this function
1062 vm_tempstringsbuf.cursize = restorevm_tempstringsbuf_cursize;
1064 f->totaltime += (Sys_DoubleTime() - calltime);
1066 SV_FlushBroadcastMessages();
1070 ====================
1072 ====================
1074 // LordHavoc: optimized
1075 #define OPA ((prvm_eval_t *)&prog->globals.generic[(unsigned short) st->a])
1076 #define OPB ((prvm_eval_t *)&prog->globals.generic[(unsigned short) st->b])
1077 #define OPC ((prvm_eval_t *)&prog->globals.generic[(unsigned short) st->c])
1078 extern cvar_t prvm_traceqc;
1079 extern cvar_t prvm_statementprofiling;
1080 extern sizebuf_t vm_tempstringsbuf;
1081 extern qboolean prvm_runawaycheck;
1082 extern qboolean prvm_boundscheck;
1083 void CLVM_ExecuteProgram (func_t fnum, const char *errormessage)
1085 dstatement_t *st, *startst;
1086 mfunction_t *f, *newf;
1089 int jumpcount, cachedpr_trace, exitdepth;
1090 int restorevm_tempstringsbuf_cursize;
1093 calltime = Sys_DoubleTime();
1095 if (!fnum || fnum >= (unsigned int)prog->progs->numfunctions)
1097 if (prog->globaloffsets.self >= 0 && PRVM_GLOBALFIELDVALUE(prog->globaloffsets.self)->edict)
1098 PRVM_ED_Print(PRVM_PROG_TO_EDICT(PRVM_GLOBALFIELDVALUE(prog->globaloffsets.self)->edict), NULL);
1099 PRVM_ERROR ("CLVM_ExecuteProgram: %s", errormessage);
1102 f = &prog->functions[fnum];
1104 // after executing this function, delete all tempstrings it created
1105 restorevm_tempstringsbuf_cursize = vm_tempstringsbuf.cursize;
1107 prog->trace = prvm_traceqc.integer;
1109 // we know we're done when pr_depth drops to this
1110 exitdepth = prog->depth;
1112 // make a stack frame
1113 st = &prog->statements[PRVM_EnterFunction (f)];
1114 // save the starting statement pointer for profiling
1115 // (when the function exits or jumps, the (st - startst) integer value is
1116 // added to the function's profile counter)
1118 // instead of counting instructions, we count jumps
1120 // add one to the callcount of this function because otherwise engine-called functions aren't counted
1121 prog->xfunction->callcount++;
1124 cachedpr_trace = prog->trace;
1125 if (prvm_runawaycheck)
1127 #define PRVMRUNAWAYCHECK 1
1128 if (prvm_statementprofiling.integer)
1130 #define PRVMSTATEMENTPROFILING 1
1131 if (prvm_boundscheck)
1133 #define PRVMBOUNDSCHECK 1
1137 #include "prvm_execprogram.h"
1142 #include "prvm_execprogram.h"
1144 #undef PRVMBOUNDSCHECK
1151 #include "prvm_execprogram.h"
1156 #include "prvm_execprogram.h"
1159 #undef PRVMSTATEMENTPROFILING
1163 if (prvm_boundscheck)
1165 #define PRVMBOUNDSCHECK 1
1169 #include "prvm_execprogram.h"
1174 #include "prvm_execprogram.h"
1176 #undef PRVMBOUNDSCHECK
1183 #include "prvm_execprogram.h"
1188 #include "prvm_execprogram.h"
1192 #undef PRVMRUNAWAYCHECK
1196 if (prvm_statementprofiling.integer)
1198 #define PRVMSTATEMENTPROFILING 1
1199 if (prvm_boundscheck)
1201 #define PRVMBOUNDSCHECK 1
1205 #include "prvm_execprogram.h"
1210 #include "prvm_execprogram.h"
1212 #undef PRVMBOUNDSCHECK
1219 #include "prvm_execprogram.h"
1224 #include "prvm_execprogram.h"
1227 #undef PRVMSTATEMENTPROFILING
1231 if (prvm_boundscheck)
1233 #define PRVMBOUNDSCHECK 1
1237 #include "prvm_execprogram.h"
1242 #include "prvm_execprogram.h"
1244 #undef PRVMBOUNDSCHECK
1251 #include "prvm_execprogram.h"
1256 #include "prvm_execprogram.h"
1263 if (developer.integer >= 200 && vm_tempstringsbuf.cursize > restorevm_tempstringsbuf_cursize)
1264 Con_Printf("CLVM_ExecuteProgram: %s used %i bytes of tempstrings\n", PRVM_GetString(prog->functions[fnum].s_name), vm_tempstringsbuf.cursize - restorevm_tempstringsbuf_cursize);
1265 // delete tempstrings created by this function
1266 vm_tempstringsbuf.cursize = restorevm_tempstringsbuf_cursize;
1268 f->totaltime += (Sys_DoubleTime() - calltime);
1270 SV_FlushBroadcastMessages();
1274 ====================
1276 ====================
1278 // LordHavoc: optimized
1279 #define OPA ((prvm_eval_t *)&prog->globals.generic[(unsigned short) st->a])
1280 #define OPB ((prvm_eval_t *)&prog->globals.generic[(unsigned short) st->b])
1281 #define OPC ((prvm_eval_t *)&prog->globals.generic[(unsigned short) st->c])
1282 extern cvar_t prvm_traceqc;
1283 extern cvar_t prvm_statementprofiling;
1284 extern sizebuf_t vm_tempstringsbuf;
1285 extern qboolean prvm_runawaycheck;
1286 extern qboolean prvm_boundscheck;
1287 void SVVM_ExecuteProgram (func_t fnum, const char *errormessage)
1289 dstatement_t *st, *startst;
1290 mfunction_t *f, *newf;
1293 int jumpcount, cachedpr_trace, exitdepth;
1294 int restorevm_tempstringsbuf_cursize;
1297 calltime = Sys_DoubleTime();
1299 if (!fnum || fnum >= (unsigned int)prog->progs->numfunctions)
1301 if (prog->globaloffsets.self >= 0 && PRVM_GLOBALFIELDVALUE(prog->globaloffsets.self)->edict)
1302 PRVM_ED_Print(PRVM_PROG_TO_EDICT(PRVM_GLOBALFIELDVALUE(prog->globaloffsets.self)->edict), NULL);
1303 PRVM_ERROR ("SVVM_ExecuteProgram: %s", errormessage);
1306 f = &prog->functions[fnum];
1308 // after executing this function, delete all tempstrings it created
1309 restorevm_tempstringsbuf_cursize = vm_tempstringsbuf.cursize;
1311 prog->trace = prvm_traceqc.integer;
1313 // we know we're done when pr_depth drops to this
1314 exitdepth = prog->depth;
1316 // make a stack frame
1317 st = &prog->statements[PRVM_EnterFunction (f)];
1318 // save the starting statement pointer for profiling
1319 // (when the function exits or jumps, the (st - startst) integer value is
1320 // added to the function's profile counter)
1322 // instead of counting instructions, we count jumps
1324 // add one to the callcount of this function because otherwise engine-called functions aren't counted
1325 prog->xfunction->callcount++;
1328 cachedpr_trace = prog->trace;
1329 if (prvm_runawaycheck)
1331 #define PRVMRUNAWAYCHECK 1
1332 if (prvm_statementprofiling.integer)
1334 #define PRVMSTATEMENTPROFILING 1
1335 if (prvm_boundscheck)
1337 #define PRVMBOUNDSCHECK 1
1341 #include "prvm_execprogram.h"
1346 #include "prvm_execprogram.h"
1348 #undef PRVMBOUNDSCHECK
1355 #include "prvm_execprogram.h"
1360 #include "prvm_execprogram.h"
1363 #undef PRVMSTATEMENTPROFILING
1367 if (prvm_boundscheck)
1369 #define PRVMBOUNDSCHECK 1
1373 #include "prvm_execprogram.h"
1378 #include "prvm_execprogram.h"
1380 #undef PRVMBOUNDSCHECK
1387 #include "prvm_execprogram.h"
1392 #include "prvm_execprogram.h"
1396 #undef PRVMRUNAWAYCHECK
1400 if (prvm_statementprofiling.integer)
1402 #define PRVMSTATEMENTPROFILING 1
1403 if (prvm_boundscheck)
1405 #define PRVMBOUNDSCHECK 1
1409 #include "prvm_execprogram.h"
1414 #include "prvm_execprogram.h"
1416 #undef PRVMBOUNDSCHECK
1423 #include "prvm_execprogram.h"
1428 #include "prvm_execprogram.h"
1431 #undef PRVMSTATEMENTPROFILING
1435 if (prvm_boundscheck)
1437 #define PRVMBOUNDSCHECK 1
1441 #include "prvm_execprogram.h"
1446 #include "prvm_execprogram.h"
1448 #undef PRVMBOUNDSCHECK
1455 #include "prvm_execprogram.h"
1460 #include "prvm_execprogram.h"
1467 if (developer.integer >= 200 && vm_tempstringsbuf.cursize > restorevm_tempstringsbuf_cursize)
1468 Con_Printf("SVVM_ExecuteProgram: %s used %i bytes of tempstrings\n", PRVM_GetString(prog->functions[fnum].s_name), vm_tempstringsbuf.cursize - restorevm_tempstringsbuf_cursize);
1469 // delete tempstrings created by this function
1470 vm_tempstringsbuf.cursize = restorevm_tempstringsbuf_cursize;
1472 f->totaltime += (Sys_DoubleTime() - calltime);
1474 SV_FlushBroadcastMessages();