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 const char *prvm_opnames[] =
115 //=============================================================================
122 extern cvar_t prvm_statementprofiling;
123 extern cvar_t prvm_timeprofiling;
124 static void PRVM_PrintStatement(prvm_prog_t *prog, mstatement_t *s)
127 int opnum = (int)(s - prog->statements);
128 char valuebuf[MAX_INPUTLINE];
130 Con_Printf("s%i: ", opnum);
131 if( prog->statement_linenums )
133 if ( prog->statement_columnnums )
134 Con_Printf( "%s:%i:%i: ", PRVM_GetString( prog, prog->xfunction->s_file ), prog->statement_linenums[ opnum ], prog->statement_columnnums[ opnum ] );
136 Con_Printf( "%s:%i: ", PRVM_GetString( prog, prog->xfunction->s_file ), prog->statement_linenums[ opnum ] );
139 if (prvm_statementprofiling.integer)
140 Con_Printf("%7.0f ", prog->statement_profile[s - prog->statements]);
142 if ( (unsigned)s->op < sizeof(prvm_opnames)/sizeof(prvm_opnames[0]))
144 Con_Printf("%s ", prvm_opnames[s->op]);
145 i = strlen(prvm_opnames[s->op]);
146 // don't count a preceding color tag when padding the name
147 if (prvm_opnames[s->op][0] == STRING_COLOR_TAG)
152 if (s->operand[0] >= 0) Con_Printf( "%s", PRVM_GlobalString(prog, s->operand[0], valuebuf, sizeof(valuebuf)));
153 if (s->operand[1] >= 0) Con_Printf(", %s", PRVM_GlobalString(prog, s->operand[1], valuebuf, sizeof(valuebuf)));
154 if (s->operand[2] >= 0) Con_Printf(", %s", PRVM_GlobalString(prog, s->operand[2], valuebuf, sizeof(valuebuf)));
155 if (s->jumpabsolute >= 0) Con_Printf(", statement %i", s->jumpabsolute);
159 void PRVM_PrintFunctionStatements (prvm_prog_t *prog, const char *name)
161 int i, firststatement, endstatement;
163 func = PRVM_ED_FindFunction (prog, name);
166 Con_Printf("%s progs: no function named %s\n", prog->name, name);
169 firststatement = func->first_statement;
170 if (firststatement < 0)
172 Con_Printf("%s progs: function %s is builtin #%i\n", prog->name, name, -firststatement);
176 // find the end statement
177 endstatement = prog->numstatements;
178 for (i = 0;i < prog->numfunctions;i++)
179 if (endstatement > prog->functions[i].first_statement && firststatement < prog->functions[i].first_statement)
180 endstatement = prog->functions[i].first_statement;
182 // now print the range of statements
183 Con_Printf("%s progs: disassembly of function %s (statements %i-%i, locals %i-%i):\n", prog->name, name, firststatement, endstatement, func->parm_start, func->parm_start + func->locals - 1);
184 prog->xfunction = func;
185 for (i = firststatement;i < endstatement;i++)
187 PRVM_PrintStatement(prog, prog->statements + i);
188 prog->statement_profile[i] = 0;
198 void PRVM_PrintFunction_f (void)
203 Con_Printf("usage: prvm_printfunction <program name> <function name>\n");
207 if (!(prog = PRVM_FriendlyProgFromString(Cmd_Argv(1))))
210 PRVM_PrintFunctionStatements(prog, Cmd_Argv(2));
218 void PRVM_StackTrace (prvm_prog_t *prog)
223 prog->stack[prog->depth].s = prog->xstatement;
224 prog->stack[prog->depth].f = prog->xfunction;
225 for (i = prog->depth;i > 0;i--)
227 f = prog->stack[i].f;
230 Con_Print("<NULL FUNCTION>\n");
233 if (prog->statement_linenums)
235 if (prog->statement_columnnums)
236 Con_Printf("%12s:%i:%i : %s : statement %i\n", PRVM_GetString(prog, f->s_file), prog->statement_linenums[prog->stack[i].s], prog->statement_columnnums[prog->stack[i].s], PRVM_GetString(prog, f->s_name), prog->stack[i].s - f->first_statement);
238 Con_Printf("%12s:%i : %s : statement %i\n", PRVM_GetString(prog, f->s_file), prog->statement_linenums[prog->stack[i].s], PRVM_GetString(prog, f->s_name), prog->stack[i].s - f->first_statement);
241 Con_Printf("%12s : %s : statement %i\n", PRVM_GetString(prog, f->s_file), PRVM_GetString(prog, f->s_name), prog->stack[i].s - f->first_statement);
246 void PRVM_ShortStackTrace(prvm_prog_t *prog, char *buf, size_t bufsize)
254 dpsnprintf(buf, bufsize, "(%s) ", prog->name);
258 strlcpy(buf, "<NO PROG>", bufsize);
262 prog->stack[prog->depth].s = prog->xstatement;
263 prog->stack[prog->depth].f = prog->xfunction;
264 for (i = prog->depth;i > 0;i--)
266 f = prog->stack[i].f;
270 ? va(vabuf, sizeof(vabuf), "%s:%s(%i) ", PRVM_GetString(prog, f->s_file), PRVM_GetString(prog, f->s_name), prog->stack[i].s - f->first_statement)
279 static void PRVM_CallProfile (prvm_prog_t *prog)
281 mfunction_t *f, *best;
285 double newprofiletime;
287 Con_Printf( "%s Call Profile:\n", prog->name );
294 for (i=0 ; i<prog->numfunctions ; i++)
296 f = &prog->functions[i];
297 if (max < f->totaltime)
305 sum += best->totaltime;
306 Con_Printf("%9.4f %s\n", best->totaltime, PRVM_GetString(prog, best->s_name));
311 newprofiletime = Sys_DirtyTime();
312 Con_Printf("Total time since last profile reset: %9.4f\n", newprofiletime - prog->profiletime);
313 Con_Printf(" - used by QC code of this VM: %9.4f\n", sum);
315 prog->profiletime = newprofiletime;
318 void PRVM_Profile (prvm_prog_t *prog, int maxfunctions, double mintime, int sortby)
320 mfunction_t *f, *best;
324 if(!prvm_timeprofiling.integer)
325 mintime *= 10000000; // count each statement as about 0.1µs
327 if(prvm_timeprofiling.integer)
328 Con_Printf( "%s Profile:\n[CallCount] [Time] [BuiltinTm] [Statement] [BuiltinCt] [TimeTotal] [StmtTotal] [BltnTotal] [self]\n", prog->name );
329 // 12345678901 12345678901 12345678901 12345678901 12345678901 12345678901 12345678901 123.45%
331 Con_Printf( "%s Profile:\n[CallCount] [Statement] [BuiltinCt] [StmtTotal] [BltnTotal] [self]\n", prog->name );
332 // 12345678901 12345678901 12345678901 12345678901 12345678901 123.45%
339 for (i=0 ; i<prog->numfunctions ; i++)
341 f = &prog->functions[i];
342 if(prvm_timeprofiling.integer)
346 if(f->first_statement < 0)
348 if (max < f->tprofile)
356 if (max < f->tprofile_total)
358 max = f->tprofile_total;
365 if (max < f->tprofile + f->tbprofile)
367 max = f->tprofile + f->tbprofile;
376 if (max < f->profile_total + f->builtinsprofile_total + f->callcount)
378 max = f->profile_total + f->builtinsprofile_total + f->callcount;
384 if (max < f->profile + f->builtinsprofile + f->callcount)
386 max = f->profile + f->builtinsprofile + f->callcount;
394 if (num < maxfunctions && max > mintime)
396 if(prvm_timeprofiling.integer)
398 if (best->first_statement < 0)
399 Con_Printf("%11.0f %11.6f ------------- builtin ------------- %11.6f ----------- builtin ----------- %s\n", best->callcount, best->tprofile, best->tprofile, PRVM_GetString(prog, best->s_name));
400 // %11.6f 12345678901 12345678901 12345678901 %11.6f 12345678901 12345678901 123.45%
402 Con_Printf("%11.0f %11.6f %11.6f %11.0f %11.0f %11.6f %11.0f %11.0f %6.2f%% %s\n", best->callcount, best->tprofile, best->tbprofile, best->profile, best->builtinsprofile, best->tprofile_total, best->profile_total, best->builtinsprofile_total, (best->tprofile_total > 0) ? ((best->tprofile) * 100.0 / (best->tprofile_total)) : -99.99, PRVM_GetString(prog, best->s_name));
406 if (best->first_statement < 0)
407 Con_Printf("%11.0f ----------------------- builtin ----------------------- %s\n", best->callcount, PRVM_GetString(prog, best->s_name));
408 // 12345678901 12345678901 12345678901 12345678901 123.45%
410 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(prog, best->s_name));
417 best->builtinsprofile = 0;
418 best->profile_total = 0;
419 best->tprofile_total = 0;
420 best->builtinsprofile_total = 0;
432 void PRVM_CallProfile_f (void)
437 Con_Print("prvm_callprofile <program name>\n");
441 if (!(prog = PRVM_FriendlyProgFromString(Cmd_Argv(1))))
444 PRVM_CallProfile(prog);
453 void PRVM_Profile_f (void)
460 howmany = atoi(Cmd_Argv(2));
461 else if (Cmd_Argc() != 2)
463 Con_Print("prvm_profile <program name>\n");
467 if (!(prog = PRVM_FriendlyProgFromString(Cmd_Argv(1))))
470 PRVM_Profile(prog, howmany, 0, 0);
473 void PRVM_ChildProfile_f (void)
480 howmany = atoi(Cmd_Argv(2));
481 else if (Cmd_Argc() != 2)
483 Con_Print("prvm_childprofile <program name>\n");
487 if (!(prog = PRVM_FriendlyProgFromString(Cmd_Argv(1))))
490 PRVM_Profile(prog, howmany, 0, 1);
493 void PRVM_PrintState(prvm_prog_t *prog, int stack_index)
496 mfunction_t *func = prog->xfunction;
497 int st = prog->xstatement;
498 if (stack_index > 0 && stack_index <= prog->depth)
500 func = prog->stack[prog->depth - stack_index].f;
501 st = prog->stack[prog->depth - stack_index].s;
503 if (prog->statestring)
505 Con_Printf("Caller-provided information: %s\n", prog->statestring);
509 for (i = -7; i <= 0;i++)
510 if (st + i >= func->first_statement)
511 PRVM_PrintStatement(prog, prog->statements + st + i);
513 PRVM_StackTrace(prog);
516 extern cvar_t prvm_errordump;
517 void PRVM_Crash(prvm_prog_t *prog)
525 PRVM_serverfunction(SV_Shutdown) = 0; // don't call SV_Shutdown on crash
527 if( prog->depth > 0 )
529 Con_Printf("QuakeC crash report for %s:\n", prog->name);
530 PRVM_PrintState(prog, 0);
533 if(prvm_errordump.integer)
536 Host_Savegame_to(prog, va(vabuf, sizeof(vabuf), "crash-%s.dmp", prog->name));
539 // dump the stack so host_error can shutdown functions
541 prog->localstack_used = 0;
543 // delete all tempstrings (FIXME: is this safe in VM->engine->VM recursion?)
544 prog->tempstringsbuf.cursize = 0;
546 // reset the prog pointer
551 ============================================================================
554 The interpretation main loop
555 ============================================================================
562 Returns the new program statement counter
565 static int PRVM_EnterFunction (prvm_prog_t *prog, mfunction_t *f)
570 prog->error_cmd("PRVM_EnterFunction: NULL function in %s", prog->name);
572 prog->stack[prog->depth].s = prog->xstatement;
573 prog->stack[prog->depth].f = prog->xfunction;
574 prog->stack[prog->depth].profile_acc = -f->profile;
575 prog->stack[prog->depth].tprofile_acc = -f->tprofile + -f->tbprofile;
576 prog->stack[prog->depth].builtinsprofile_acc = -f->builtinsprofile;
578 if (prog->depth >=PRVM_MAX_STACK_DEPTH)
579 prog->error_cmd("stack overflow");
581 // save off any locals that the new function steps on
583 if (prog->localstack_used + c > PRVM_LOCALSTACK_SIZE)
584 prog->error_cmd("PRVM_ExecuteProgram: locals stack overflow in %s", prog->name);
586 for (i=0 ; i < c ; i++)
587 prog->localstack[prog->localstack_used+i] = prog->globals.ip[f->parm_start + i];
588 prog->localstack_used += c;
592 for (i=0 ; i<f->numparms ; i++)
594 for (j=0 ; j<f->parm_size[i] ; j++)
596 prog->globals.ip[o] = prog->globals.ip[OFS_PARM0+i*3+j];
603 return f->first_statement - 1; // offset the s++
611 static int PRVM_LeaveFunction (prvm_prog_t *prog)
616 if (prog->depth <= 0)
617 prog->error_cmd("prog stack underflow in %s", prog->name);
619 if (!prog->xfunction)
620 prog->error_cmd("PR_LeaveFunction: NULL function in %s", prog->name);
621 // restore locals from the stack
622 c = prog->xfunction->locals;
623 prog->localstack_used -= c;
624 if (prog->localstack_used < 0)
625 prog->error_cmd("PRVM_ExecuteProgram: locals stack underflow in %s", prog->name);
627 for (i=0 ; i < c ; i++)
628 prog->globals.ip[prog->xfunction->parm_start + i] = prog->localstack[prog->localstack_used+i];
634 prog->xfunction = prog->stack[prog->depth].f;
635 prog->stack[prog->depth].profile_acc += f->profile;
636 prog->stack[prog->depth].tprofile_acc += f->tprofile + f->tbprofile;
637 prog->stack[prog->depth].builtinsprofile_acc += f->builtinsprofile;
640 prog->stack[prog->depth-1].profile_acc += prog->stack[prog->depth].profile_acc;
641 prog->stack[prog->depth-1].tprofile_acc += prog->stack[prog->depth].tprofile_acc;
642 prog->stack[prog->depth-1].builtinsprofile_acc += prog->stack[prog->depth].builtinsprofile_acc;
646 // if f is already on the call stack...
647 // we cannot add this profile data to it now
648 // or we would add it more than once
649 // so, let's only add to the function's profile if it is the outermost call
650 f->profile_total += prog->stack[prog->depth].profile_acc;
651 f->tprofile_total += prog->stack[prog->depth].tprofile_acc;
652 f->builtinsprofile_total += prog->stack[prog->depth].builtinsprofile_acc;
655 return prog->stack[prog->depth].s;
658 void PRVM_Init_Exec(prvm_prog_t *prog)
662 prog->localstack_used = 0;
663 // reset the string table
667 #define OPA ((prvm_eval_t *)&prog->globals.fp[st->operand[0]])
668 #define OPB ((prvm_eval_t *)&prog->globals.fp[st->operand[1]])
669 #define OPC ((prvm_eval_t *)&prog->globals.fp[st->operand[2]])
670 extern cvar_t prvm_traceqc;
671 extern cvar_t prvm_statementprofiling;
672 extern qboolean prvm_runawaycheck;
681 void MVM_ExecuteProgram (prvm_prog_t *prog, func_t fnum, const char *errormessage)
683 mstatement_t *st, *startst;
684 mfunction_t *f, *newf;
687 int jumpcount, cachedpr_trace, exitdepth;
688 int restorevm_tempstringsbuf_cursize;
691 prvm_vec_t tempfloat;
692 // these may become out of date when a builtin is called, and are updated accordingly
693 prvm_vec_t *cached_edictsfields = prog->edictsfields;
694 unsigned int cached_entityfields = prog->entityfields;
695 unsigned int cached_entityfields_3 = prog->entityfields - 3;
696 unsigned int cached_entityfieldsarea = prog->entityfieldsarea;
697 unsigned int cached_entityfieldsarea_entityfields = prog->entityfieldsarea - prog->entityfields;
698 unsigned int cached_entityfieldsarea_3 = prog->entityfieldsarea - 3;
699 unsigned int cached_entityfieldsarea_entityfields_3 = prog->entityfieldsarea - prog->entityfields - 3;
700 unsigned int cached_max_edicts = prog->max_edicts;
701 // these do not change
702 mstatement_t *cached_statements = prog->statements;
703 qboolean cached_allowworldwrites = prog->allowworldwrites;
704 unsigned int cached_flag = prog->flag;
706 calltime = Sys_DirtyTime();
708 if (!fnum || fnum >= (unsigned int)prog->numfunctions)
710 if (PRVM_allglobaledict(self))
711 PRVM_ED_Print(prog, PRVM_PROG_TO_EDICT(PRVM_allglobaledict(self)), NULL);
712 prog->error_cmd("MVM_ExecuteProgram: %s", errormessage);
715 f = &prog->functions[fnum];
717 // after executing this function, delete all tempstrings it created
718 restorevm_tempstringsbuf_cursize = prog->tempstringsbuf.cursize;
720 prog->trace = prvm_traceqc.integer;
722 // we know we're done when pr_depth drops to this
723 exitdepth = prog->depth;
725 // make a stack frame
726 st = &prog->statements[PRVM_EnterFunction(prog, f)];
727 // save the starting statement pointer for profiling
728 // (when the function exits or jumps, the (st - startst) integer value is
729 // added to the function's profile counter)
732 // instead of counting instructions, we count jumps
734 // add one to the callcount of this function because otherwise engine-called functions aren't counted
735 prog->xfunction->callcount++;
738 cachedpr_trace = prog->trace;
739 if (prvm_statementprofiling.integer || prog->trace || prog->watch_global >= 0 || prog->watch_edict >= 0 || prog->break_statement >= 0)
741 #define PRVMSLOWINTERPRETER 1
742 if (prvm_timeprofiling.integer)
744 #define PRVMTIMEPROFILING 1
745 #include "prvm_execprogram.h"
746 #undef PRVMTIMEPROFILING
750 #include "prvm_execprogram.h"
752 #undef PRVMSLOWINTERPRETER
756 if (prvm_timeprofiling.integer)
758 #define PRVMTIMEPROFILING 1
759 #include "prvm_execprogram.h"
760 #undef PRVMTIMEPROFILING
764 #include "prvm_execprogram.h"
769 if (developer_insane.integer && prog->tempstringsbuf.cursize > restorevm_tempstringsbuf_cursize)
770 Con_DPrintf("MVM_ExecuteProgram: %s used %i bytes of tempstrings\n", PRVM_GetString(prog, prog->functions[fnum].s_name), prog->tempstringsbuf.cursize - restorevm_tempstringsbuf_cursize);
771 // delete tempstrings created by this function
772 prog->tempstringsbuf.cursize = restorevm_tempstringsbuf_cursize;
774 tm = Sys_DirtyTime() - calltime;if (tm < 0 || tm >= 1800) tm = 0;
777 if (prog == SVVM_prog)
778 SV_FlushBroadcastMessages();
787 void CLVM_ExecuteProgram (prvm_prog_t *prog, func_t fnum, const char *errormessage)
789 mstatement_t *st, *startst;
790 mfunction_t *f, *newf;
793 int jumpcount, cachedpr_trace, exitdepth;
794 int restorevm_tempstringsbuf_cursize;
797 prvm_vec_t tempfloat;
798 // these may become out of date when a builtin is called, and are updated accordingly
799 prvm_vec_t *cached_edictsfields = prog->edictsfields;
800 unsigned int cached_entityfields = prog->entityfields;
801 unsigned int cached_entityfields_3 = prog->entityfields - 3;
802 unsigned int cached_entityfieldsarea = prog->entityfieldsarea;
803 unsigned int cached_entityfieldsarea_entityfields = prog->entityfieldsarea - prog->entityfields;
804 unsigned int cached_entityfieldsarea_3 = prog->entityfieldsarea - 3;
805 unsigned int cached_entityfieldsarea_entityfields_3 = prog->entityfieldsarea - prog->entityfields - 3;
806 unsigned int cached_max_edicts = prog->max_edicts;
807 // these do not change
808 mstatement_t *cached_statements = prog->statements;
809 qboolean cached_allowworldwrites = prog->allowworldwrites;
810 unsigned int cached_flag = prog->flag;
812 calltime = Sys_DirtyTime();
814 if (!fnum || fnum >= (unsigned int)prog->numfunctions)
816 if (PRVM_allglobaledict(self))
817 PRVM_ED_Print(prog, PRVM_PROG_TO_EDICT(PRVM_allglobaledict(self)), NULL);
818 prog->error_cmd("CLVM_ExecuteProgram: %s", errormessage);
821 f = &prog->functions[fnum];
823 // after executing this function, delete all tempstrings it created
824 restorevm_tempstringsbuf_cursize = prog->tempstringsbuf.cursize;
826 prog->trace = prvm_traceqc.integer;
828 // we know we're done when pr_depth drops to this
829 exitdepth = prog->depth;
831 // make a stack frame
832 st = &prog->statements[PRVM_EnterFunction(prog, f)];
833 // save the starting statement pointer for profiling
834 // (when the function exits or jumps, the (st - startst) integer value is
835 // added to the function's profile counter)
838 // instead of counting instructions, we count jumps
840 // add one to the callcount of this function because otherwise engine-called functions aren't counted
841 prog->xfunction->callcount++;
844 cachedpr_trace = prog->trace;
845 if (prvm_statementprofiling.integer || prog->trace || prog->watch_global >= 0 || prog->watch_edict >= 0 || prog->break_statement >= 0)
847 #define PRVMSLOWINTERPRETER 1
848 if (prvm_timeprofiling.integer)
850 #define PRVMTIMEPROFILING 1
851 #include "prvm_execprogram.h"
852 #undef PRVMTIMEPROFILING
856 #include "prvm_execprogram.h"
858 #undef PRVMSLOWINTERPRETER
862 if (prvm_timeprofiling.integer)
864 #define PRVMTIMEPROFILING 1
865 #include "prvm_execprogram.h"
866 #undef PRVMTIMEPROFILING
870 #include "prvm_execprogram.h"
875 if (developer_insane.integer && prog->tempstringsbuf.cursize > restorevm_tempstringsbuf_cursize)
876 Con_DPrintf("CLVM_ExecuteProgram: %s used %i bytes of tempstrings\n", PRVM_GetString(prog, prog->functions[fnum].s_name), prog->tempstringsbuf.cursize - restorevm_tempstringsbuf_cursize);
877 // delete tempstrings created by this function
878 prog->tempstringsbuf.cursize = restorevm_tempstringsbuf_cursize;
880 tm = Sys_DirtyTime() - calltime;if (tm < 0 || tm >= 1800) tm = 0;
883 if (prog == SVVM_prog)
884 SV_FlushBroadcastMessages();
894 void SVVM_ExecuteProgram (prvm_prog_t *prog, func_t fnum, const char *errormessage)
896 void PRVM_ExecuteProgram (prvm_prog_t *prog, func_t fnum, const char *errormessage)
899 mstatement_t *st, *startst;
900 mfunction_t *f, *newf;
903 int jumpcount, cachedpr_trace, exitdepth;
904 int restorevm_tempstringsbuf_cursize;
907 prvm_vec_t tempfloat;
908 // these may become out of date when a builtin is called, and are updated accordingly
909 prvm_vec_t *cached_edictsfields = prog->edictsfields;
910 unsigned int cached_entityfields = prog->entityfields;
911 unsigned int cached_entityfields_3 = prog->entityfields - 3;
912 unsigned int cached_entityfieldsarea = prog->entityfieldsarea;
913 unsigned int cached_entityfieldsarea_entityfields = prog->entityfieldsarea - prog->entityfields;
914 unsigned int cached_entityfieldsarea_3 = prog->entityfieldsarea - 3;
915 unsigned int cached_entityfieldsarea_entityfields_3 = prog->entityfieldsarea - prog->entityfields - 3;
916 unsigned int cached_max_edicts = prog->max_edicts;
917 // these do not change
918 mstatement_t *cached_statements = prog->statements;
919 qboolean cached_allowworldwrites = prog->allowworldwrites;
920 unsigned int cached_flag = prog->flag;
922 calltime = Sys_DirtyTime();
924 if (!fnum || fnum >= (unsigned int)prog->numfunctions)
926 if (PRVM_allglobaledict(self))
927 PRVM_ED_Print(prog, PRVM_PROG_TO_EDICT(PRVM_allglobaledict(self)), NULL);
928 prog->error_cmd("SVVM_ExecuteProgram: %s", errormessage);
931 f = &prog->functions[fnum];
933 // after executing this function, delete all tempstrings it created
934 restorevm_tempstringsbuf_cursize = prog->tempstringsbuf.cursize;
936 prog->trace = prvm_traceqc.integer;
938 // we know we're done when pr_depth drops to this
939 exitdepth = prog->depth;
941 // make a stack frame
942 st = &prog->statements[PRVM_EnterFunction(prog, f)];
943 // save the starting statement pointer for profiling
944 // (when the function exits or jumps, the (st - startst) integer value is
945 // added to the function's profile counter)
948 // instead of counting instructions, we count jumps
950 // add one to the callcount of this function because otherwise engine-called functions aren't counted
951 prog->xfunction->callcount++;
954 cachedpr_trace = prog->trace;
955 if (prvm_statementprofiling.integer || prog->trace || prog->watch_global >= 0 || prog->watch_edict >= 0 || prog->break_statement >= 0)
957 #define PRVMSLOWINTERPRETER 1
958 if (prvm_timeprofiling.integer)
960 #define PRVMTIMEPROFILING 1
961 #include "prvm_execprogram.h"
962 #undef PRVMTIMEPROFILING
966 #include "prvm_execprogram.h"
968 #undef PRVMSLOWINTERPRETER
972 if (prvm_timeprofiling.integer)
974 #define PRVMTIMEPROFILING 1
975 #include "prvm_execprogram.h"
976 #undef PRVMTIMEPROFILING
980 #include "prvm_execprogram.h"
985 if (developer_insane.integer && prog->tempstringsbuf.cursize > restorevm_tempstringsbuf_cursize)
986 Con_DPrintf("SVVM_ExecuteProgram: %s used %i bytes of tempstrings\n", PRVM_GetString(prog, prog->functions[fnum].s_name), prog->tempstringsbuf.cursize - restorevm_tempstringsbuf_cursize);
987 // delete tempstrings created by this function
988 prog->tempstringsbuf.cursize = restorevm_tempstringsbuf_cursize;
990 tm = Sys_DirtyTime() - calltime;if (tm < 0 || tm >= 1800) tm = 0;
993 if (prog == SVVM_prog)
994 SV_FlushBroadcastMessages();