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 )
132 Con_Printf( "%s:%i: ", PRVM_GetString( prog, prog->xfunction->s_file ), prog->statement_linenums[ opnum ] );
134 if (prvm_statementprofiling.integer)
135 Con_Printf("%7.0f ", prog->statement_profile[s - prog->statements]);
137 if ( (unsigned)s->op < sizeof(prvm_opnames)/sizeof(prvm_opnames[0]))
139 Con_Printf("%s ", prvm_opnames[s->op]);
140 i = strlen(prvm_opnames[s->op]);
141 // don't count a preceding color tag when padding the name
142 if (prvm_opnames[s->op][0] == STRING_COLOR_TAG)
147 if (s->operand[0] >= 0) Con_Printf( "%s", PRVM_GlobalString(prog, s->operand[0], valuebuf, sizeof(valuebuf)));
148 if (s->operand[1] >= 0) Con_Printf(", %s", PRVM_GlobalString(prog, s->operand[1], valuebuf, sizeof(valuebuf)));
149 if (s->operand[2] >= 0) Con_Printf(", %s", PRVM_GlobalString(prog, s->operand[2], valuebuf, sizeof(valuebuf)));
150 if (s->jumpabsolute >= 0) Con_Printf(", statement %i", s->jumpabsolute);
154 void PRVM_PrintFunctionStatements (prvm_prog_t *prog, const char *name)
156 int i, firststatement, endstatement;
158 func = PRVM_ED_FindFunction (prog, name);
161 Con_Printf("%s progs: no function named %s\n", prog->name, name);
164 firststatement = func->first_statement;
165 if (firststatement < 0)
167 Con_Printf("%s progs: function %s is builtin #%i\n", prog->name, name, -firststatement);
171 // find the end statement
172 endstatement = prog->numstatements;
173 for (i = 0;i < prog->numfunctions;i++)
174 if (endstatement > prog->functions[i].first_statement && firststatement < prog->functions[i].first_statement)
175 endstatement = prog->functions[i].first_statement;
177 // now print the range of statements
178 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);
179 prog->xfunction = func;
180 for (i = firststatement;i < endstatement;i++)
182 PRVM_PrintStatement(prog, prog->statements + i);
183 prog->statement_profile[i] = 0;
193 void PRVM_PrintFunction_f (void)
198 Con_Printf("usage: prvm_printfunction <program name> <function name>\n");
202 if (!(prog = PRVM_FriendlyProgFromString(Cmd_Argv(1))))
205 PRVM_PrintFunctionStatements(prog, Cmd_Argv(2));
213 void PRVM_StackTrace (prvm_prog_t *prog)
218 prog->stack[prog->depth].s = prog->xstatement;
219 prog->stack[prog->depth].f = prog->xfunction;
220 for (i = prog->depth;i > 0;i--)
222 f = prog->stack[i].f;
225 Con_Print("<NULL FUNCTION>\n");
228 if (prog->statement_linenums)
229 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);
231 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);
236 void PRVM_ShortStackTrace(prvm_prog_t *prog, char *buf, size_t bufsize)
244 dpsnprintf(buf, bufsize, "(%s) ", prog->name);
248 strlcpy(buf, "<NO PROG>", bufsize);
252 prog->stack[prog->depth].s = prog->xstatement;
253 prog->stack[prog->depth].f = prog->xfunction;
254 for (i = prog->depth;i > 0;i--)
256 f = prog->stack[i].f;
260 ? 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)
269 static void PRVM_CallProfile (prvm_prog_t *prog)
271 mfunction_t *f, *best;
275 double newprofiletime;
277 Con_Printf( "%s Call Profile:\n", prog->name );
284 for (i=0 ; i<prog->numfunctions ; i++)
286 f = &prog->functions[i];
287 if (max < f->totaltime)
295 sum += best->totaltime;
296 Con_Printf("%9.4f %s\n", best->totaltime, PRVM_GetString(prog, best->s_name));
301 newprofiletime = Sys_DirtyTime();
302 Con_Printf("Total time since last profile reset: %9.4f\n", newprofiletime - prog->profiletime);
303 Con_Printf(" - used by QC code of this VM: %9.4f\n", sum);
305 prog->profiletime = newprofiletime;
308 void PRVM_Profile (prvm_prog_t *prog, int maxfunctions, double mintime, int sortby)
310 mfunction_t *f, *best;
314 if(!prvm_timeprofiling.integer)
315 mintime *= 10000000; // count each statement as about 0.1µs
317 if(prvm_timeprofiling.integer)
318 Con_Printf( "%s Profile:\n[CallCount] [Time] [BuiltinTm] [Statement] [BuiltinCt] [TimeTotal] [StmtTotal] [BltnTotal] [self]\n", prog->name );
319 // 12345678901 12345678901 12345678901 12345678901 12345678901 12345678901 12345678901 123.45%
321 Con_Printf( "%s Profile:\n[CallCount] [Statement] [BuiltinCt] [StmtTotal] [BltnTotal] [self]\n", prog->name );
322 // 12345678901 12345678901 12345678901 12345678901 12345678901 123.45%
329 for (i=0 ; i<prog->numfunctions ; i++)
331 f = &prog->functions[i];
332 if(prvm_timeprofiling.integer)
336 if(f->first_statement < 0)
338 if (max < f->tprofile)
346 if (max < f->tprofile_total)
348 max = f->tprofile_total;
355 if (max < f->tprofile + f->tbprofile)
357 max = f->tprofile + f->tbprofile;
366 if (max < f->profile_total + f->builtinsprofile_total + f->callcount)
368 max = f->profile_total + f->builtinsprofile_total + f->callcount;
374 if (max < f->profile + f->builtinsprofile + f->callcount)
376 max = f->profile + f->builtinsprofile + f->callcount;
384 if (num < maxfunctions && max > mintime)
386 if(prvm_timeprofiling.integer)
388 if (best->first_statement < 0)
389 Con_Printf("%11.0f %11.6f ------------- builtin ------------- %11.6f ----------- builtin ----------- %s\n", best->callcount, best->tprofile, best->tprofile, PRVM_GetString(prog, best->s_name));
390 // %11.6f 12345678901 12345678901 12345678901 %11.6f 12345678901 12345678901 123.45%
392 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));
396 if (best->first_statement < 0)
397 Con_Printf("%11.0f ----------------------- builtin ----------------------- %s\n", best->callcount, PRVM_GetString(prog, best->s_name));
398 // 12345678901 12345678901 12345678901 12345678901 123.45%
400 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));
407 best->builtinsprofile = 0;
408 best->profile_total = 0;
409 best->tprofile_total = 0;
410 best->builtinsprofile_total = 0;
422 void PRVM_CallProfile_f (void)
427 Con_Print("prvm_callprofile <program name>\n");
431 if (!(prog = PRVM_FriendlyProgFromString(Cmd_Argv(1))))
434 PRVM_CallProfile(prog);
443 void PRVM_Profile_f (void)
450 howmany = atoi(Cmd_Argv(2));
451 else if (Cmd_Argc() != 2)
453 Con_Print("prvm_profile <program name>\n");
457 if (!(prog = PRVM_FriendlyProgFromString(Cmd_Argv(1))))
460 PRVM_Profile(prog, howmany, 0, 0);
463 void PRVM_ChildProfile_f (void)
470 howmany = atoi(Cmd_Argv(2));
471 else if (Cmd_Argc() != 2)
473 Con_Print("prvm_childprofile <program name>\n");
477 if (!(prog = PRVM_FriendlyProgFromString(Cmd_Argv(1))))
480 PRVM_Profile(prog, howmany, 0, 1);
483 void PRVM_PrintState(prvm_prog_t *prog, int stack_index)
486 mfunction_t *func = prog->xfunction;
487 int st = prog->xstatement;
488 if (stack_index > 0 && stack_index <= prog->depth)
490 func = prog->stack[prog->depth - stack_index].f;
491 st = prog->stack[prog->depth - stack_index].s;
493 if (prog->statestring)
495 Con_Printf("Caller-provided information: %s\n", prog->statestring);
499 for (i = -7; i <= 0;i++)
500 if (st + i >= func->first_statement)
501 PRVM_PrintStatement(prog, prog->statements + st + i);
503 PRVM_StackTrace(prog);
506 extern cvar_t prvm_errordump;
507 void PRVM_Crash(prvm_prog_t *prog)
515 PRVM_serverfunction(SV_Shutdown) = 0; // don't call SV_Shutdown on crash
517 if( prog->depth > 0 )
519 Con_Printf("QuakeC crash report for %s:\n", prog->name);
520 PRVM_PrintState(prog, 0);
523 if(prvm_errordump.integer)
526 Host_Savegame_to(prog, va(vabuf, sizeof(vabuf), "crash-%s.dmp", prog->name));
529 // dump the stack so host_error can shutdown functions
531 prog->localstack_used = 0;
533 // delete all tempstrings (FIXME: is this safe in VM->engine->VM recursion?)
534 prog->tempstringsbuf.cursize = 0;
536 // reset the prog pointer
541 ============================================================================
544 The interpretation main loop
545 ============================================================================
552 Returns the new program statement counter
555 static int PRVM_EnterFunction (prvm_prog_t *prog, mfunction_t *f)
560 prog->error_cmd("PRVM_EnterFunction: NULL function in %s", prog->name);
562 prog->stack[prog->depth].s = prog->xstatement;
563 prog->stack[prog->depth].f = prog->xfunction;
564 prog->stack[prog->depth].profile_acc = -f->profile;
565 prog->stack[prog->depth].tprofile_acc = -f->tprofile + -f->tbprofile;
566 prog->stack[prog->depth].builtinsprofile_acc = -f->builtinsprofile;
568 if (prog->depth >=PRVM_MAX_STACK_DEPTH)
569 prog->error_cmd("stack overflow");
571 // save off any locals that the new function steps on
573 if (prog->localstack_used + c > PRVM_LOCALSTACK_SIZE)
574 prog->error_cmd("PRVM_ExecuteProgram: locals stack overflow in %s", prog->name);
576 for (i=0 ; i < c ; i++)
577 prog->localstack[prog->localstack_used+i] = prog->globals.ip[f->parm_start + i];
578 prog->localstack_used += c;
582 for (i=0 ; i<f->numparms ; i++)
584 for (j=0 ; j<f->parm_size[i] ; j++)
586 prog->globals.ip[o] = prog->globals.ip[OFS_PARM0+i*3+j];
593 return f->first_statement - 1; // offset the s++
601 static int PRVM_LeaveFunction (prvm_prog_t *prog)
606 if (prog->depth <= 0)
607 prog->error_cmd("prog stack underflow in %s", prog->name);
609 if (!prog->xfunction)
610 prog->error_cmd("PR_LeaveFunction: NULL function in %s", prog->name);
611 // restore locals from the stack
612 c = prog->xfunction->locals;
613 prog->localstack_used -= c;
614 if (prog->localstack_used < 0)
615 prog->error_cmd("PRVM_ExecuteProgram: locals stack underflow in %s", prog->name);
617 for (i=0 ; i < c ; i++)
618 prog->globals.ip[prog->xfunction->parm_start + i] = prog->localstack[prog->localstack_used+i];
624 prog->xfunction = prog->stack[prog->depth].f;
625 prog->stack[prog->depth].profile_acc += f->profile;
626 prog->stack[prog->depth].tprofile_acc += f->tprofile + f->tbprofile;
627 prog->stack[prog->depth].builtinsprofile_acc += f->builtinsprofile;
630 prog->stack[prog->depth-1].profile_acc += prog->stack[prog->depth].profile_acc;
631 prog->stack[prog->depth-1].tprofile_acc += prog->stack[prog->depth].tprofile_acc;
632 prog->stack[prog->depth-1].builtinsprofile_acc += prog->stack[prog->depth].builtinsprofile_acc;
636 // if f is already on the call stack...
637 // we cannot add this profile data to it now
638 // or we would add it more than once
639 // so, let's only add to the function's profile if it is the outermost call
640 f->profile_total += prog->stack[prog->depth].profile_acc;
641 f->tprofile_total += prog->stack[prog->depth].tprofile_acc;
642 f->builtinsprofile_total += prog->stack[prog->depth].builtinsprofile_acc;
645 return prog->stack[prog->depth].s;
648 void PRVM_Init_Exec(prvm_prog_t *prog)
652 prog->localstack_used = 0;
653 // reset the string table
657 #define OPA ((prvm_eval_t *)&prog->globals.fp[st->operand[0]])
658 #define OPB ((prvm_eval_t *)&prog->globals.fp[st->operand[1]])
659 #define OPC ((prvm_eval_t *)&prog->globals.fp[st->operand[2]])
660 extern cvar_t prvm_traceqc;
661 extern cvar_t prvm_statementprofiling;
662 extern qboolean prvm_runawaycheck;
670 void MVM_ExecuteProgram (prvm_prog_t *prog, func_t fnum, const char *errormessage)
672 mstatement_t *st, *startst;
673 mfunction_t *f, *newf;
676 int jumpcount, cachedpr_trace, exitdepth;
677 int restorevm_tempstringsbuf_cursize;
680 prvm_vec_t tempfloat;
681 // these may become out of date when a builtin is called, and are updated accordingly
682 prvm_vec_t *cached_edictsfields = prog->edictsfields;
683 unsigned int cached_entityfields = prog->entityfields;
684 unsigned int cached_entityfields_3 = prog->entityfields - 3;
685 unsigned int cached_entityfieldsarea = prog->entityfieldsarea;
686 unsigned int cached_entityfieldsarea_entityfields = prog->entityfieldsarea - prog->entityfields;
687 unsigned int cached_entityfieldsarea_3 = prog->entityfieldsarea - 3;
688 unsigned int cached_entityfieldsarea_entityfields_3 = prog->entityfieldsarea - prog->entityfields - 3;
689 unsigned int cached_max_edicts = prog->max_edicts;
690 // these do not change
691 mstatement_t *cached_statements = prog->statements;
692 qboolean cached_allowworldwrites = prog->allowworldwrites;
693 unsigned int cached_flag = prog->flag;
695 calltime = Sys_DirtyTime();
697 if (!fnum || fnum >= (unsigned int)prog->numfunctions)
699 if (PRVM_allglobaledict(self))
700 PRVM_ED_Print(prog, PRVM_PROG_TO_EDICT(PRVM_allglobaledict(self)), NULL);
701 prog->error_cmd("MVM_ExecuteProgram: %s", errormessage);
704 f = &prog->functions[fnum];
706 // after executing this function, delete all tempstrings it created
707 restorevm_tempstringsbuf_cursize = prog->tempstringsbuf.cursize;
709 prog->trace = prvm_traceqc.integer;
711 // we know we're done when pr_depth drops to this
712 exitdepth = prog->depth;
714 // make a stack frame
715 st = &prog->statements[PRVM_EnterFunction(prog, f)];
716 // save the starting statement pointer for profiling
717 // (when the function exits or jumps, the (st - startst) integer value is
718 // added to the function's profile counter)
721 // instead of counting instructions, we count jumps
723 // add one to the callcount of this function because otherwise engine-called functions aren't counted
724 prog->xfunction->callcount++;
727 cachedpr_trace = prog->trace;
728 if (prvm_statementprofiling.integer || prog->trace || prog->watch_global >= 0 || prog->watch_edict >= 0 || prog->break_statement >= 0)
730 #define PRVMSLOWINTERPRETER 1
731 if (prvm_timeprofiling.integer)
733 #define PRVMTIMEPROFILING 1
734 #include "prvm_execprogram.h"
735 #undef PRVMTIMEPROFILING
739 #include "prvm_execprogram.h"
741 #undef PRVMSLOWINTERPRETER
745 if (prvm_timeprofiling.integer)
747 #define PRVMTIMEPROFILING 1
748 #include "prvm_execprogram.h"
749 #undef PRVMTIMEPROFILING
753 #include "prvm_execprogram.h"
758 if (developer_insane.integer && prog->tempstringsbuf.cursize > restorevm_tempstringsbuf_cursize)
759 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);
760 // delete tempstrings created by this function
761 prog->tempstringsbuf.cursize = restorevm_tempstringsbuf_cursize;
763 tm = Sys_DirtyTime() - calltime;if (tm < 0 || tm >= 1800) tm = 0;
766 if (prog == SVVM_prog)
767 SV_FlushBroadcastMessages();
775 void CLVM_ExecuteProgram (prvm_prog_t *prog, func_t fnum, const char *errormessage)
777 mstatement_t *st, *startst;
778 mfunction_t *f, *newf;
781 int jumpcount, cachedpr_trace, exitdepth;
782 int restorevm_tempstringsbuf_cursize;
785 prvm_vec_t tempfloat;
786 // these may become out of date when a builtin is called, and are updated accordingly
787 prvm_vec_t *cached_edictsfields = prog->edictsfields;
788 unsigned int cached_entityfields = prog->entityfields;
789 unsigned int cached_entityfields_3 = prog->entityfields - 3;
790 unsigned int cached_entityfieldsarea = prog->entityfieldsarea;
791 unsigned int cached_entityfieldsarea_entityfields = prog->entityfieldsarea - prog->entityfields;
792 unsigned int cached_entityfieldsarea_3 = prog->entityfieldsarea - 3;
793 unsigned int cached_entityfieldsarea_entityfields_3 = prog->entityfieldsarea - prog->entityfields - 3;
794 unsigned int cached_max_edicts = prog->max_edicts;
795 // these do not change
796 mstatement_t *cached_statements = prog->statements;
797 qboolean cached_allowworldwrites = prog->allowworldwrites;
798 unsigned int cached_flag = prog->flag;
800 calltime = Sys_DirtyTime();
802 if (!fnum || fnum >= (unsigned int)prog->numfunctions)
804 if (PRVM_allglobaledict(self))
805 PRVM_ED_Print(prog, PRVM_PROG_TO_EDICT(PRVM_allglobaledict(self)), NULL);
806 prog->error_cmd("CLVM_ExecuteProgram: %s", errormessage);
809 f = &prog->functions[fnum];
811 // after executing this function, delete all tempstrings it created
812 restorevm_tempstringsbuf_cursize = prog->tempstringsbuf.cursize;
814 prog->trace = prvm_traceqc.integer;
816 // we know we're done when pr_depth drops to this
817 exitdepth = prog->depth;
819 // make a stack frame
820 st = &prog->statements[PRVM_EnterFunction(prog, f)];
821 // save the starting statement pointer for profiling
822 // (when the function exits or jumps, the (st - startst) integer value is
823 // added to the function's profile counter)
826 // instead of counting instructions, we count jumps
828 // add one to the callcount of this function because otherwise engine-called functions aren't counted
829 prog->xfunction->callcount++;
832 cachedpr_trace = prog->trace;
833 if (prvm_statementprofiling.integer || prog->trace || prog->watch_global >= 0 || prog->watch_edict >= 0 || prog->break_statement >= 0)
835 #define PRVMSLOWINTERPRETER 1
836 if (prvm_timeprofiling.integer)
838 #define PRVMTIMEPROFILING 1
839 #include "prvm_execprogram.h"
840 #undef PRVMTIMEPROFILING
844 #include "prvm_execprogram.h"
846 #undef PRVMSLOWINTERPRETER
850 if (prvm_timeprofiling.integer)
852 #define PRVMTIMEPROFILING 1
853 #include "prvm_execprogram.h"
854 #undef PRVMTIMEPROFILING
858 #include "prvm_execprogram.h"
863 if (developer_insane.integer && prog->tempstringsbuf.cursize > restorevm_tempstringsbuf_cursize)
864 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);
865 // delete tempstrings created by this function
866 prog->tempstringsbuf.cursize = restorevm_tempstringsbuf_cursize;
868 tm = Sys_DirtyTime() - calltime;if (tm < 0 || tm >= 1800) tm = 0;
871 if (prog == SVVM_prog)
872 SV_FlushBroadcastMessages();
882 void SVVM_ExecuteProgram (prvm_prog_t *prog, func_t fnum, const char *errormessage)
884 void PRVM_ExecuteProgram (prvm_prog_t *prog, func_t fnum, const char *errormessage)
887 mstatement_t *st, *startst;
888 mfunction_t *f, *newf;
891 int jumpcount, cachedpr_trace, exitdepth;
892 int restorevm_tempstringsbuf_cursize;
895 prvm_vec_t tempfloat;
896 // these may become out of date when a builtin is called, and are updated accordingly
897 prvm_vec_t *cached_edictsfields = prog->edictsfields;
898 unsigned int cached_entityfields = prog->entityfields;
899 unsigned int cached_entityfields_3 = prog->entityfields - 3;
900 unsigned int cached_entityfieldsarea = prog->entityfieldsarea;
901 unsigned int cached_entityfieldsarea_entityfields = prog->entityfieldsarea - prog->entityfields;
902 unsigned int cached_entityfieldsarea_3 = prog->entityfieldsarea - 3;
903 unsigned int cached_entityfieldsarea_entityfields_3 = prog->entityfieldsarea - prog->entityfields - 3;
904 unsigned int cached_max_edicts = prog->max_edicts;
905 // these do not change
906 mstatement_t *cached_statements = prog->statements;
907 qboolean cached_allowworldwrites = prog->allowworldwrites;
908 unsigned int cached_flag = prog->flag;
910 calltime = Sys_DirtyTime();
912 if (!fnum || fnum >= (unsigned int)prog->numfunctions)
914 if (PRVM_allglobaledict(self))
915 PRVM_ED_Print(prog, PRVM_PROG_TO_EDICT(PRVM_allglobaledict(self)), NULL);
916 prog->error_cmd("SVVM_ExecuteProgram: %s", errormessage);
919 f = &prog->functions[fnum];
921 // after executing this function, delete all tempstrings it created
922 restorevm_tempstringsbuf_cursize = prog->tempstringsbuf.cursize;
924 prog->trace = prvm_traceqc.integer;
926 // we know we're done when pr_depth drops to this
927 exitdepth = prog->depth;
929 // make a stack frame
930 st = &prog->statements[PRVM_EnterFunction(prog, f)];
931 // save the starting statement pointer for profiling
932 // (when the function exits or jumps, the (st - startst) integer value is
933 // added to the function's profile counter)
936 // instead of counting instructions, we count jumps
938 // add one to the callcount of this function because otherwise engine-called functions aren't counted
939 prog->xfunction->callcount++;
942 cachedpr_trace = prog->trace;
943 if (prvm_statementprofiling.integer || prog->trace || prog->watch_global >= 0 || prog->watch_edict >= 0 || prog->break_statement >= 0)
945 #define PRVMSLOWINTERPRETER 1
946 if (prvm_timeprofiling.integer)
948 #define PRVMTIMEPROFILING 1
949 #include "prvm_execprogram.h"
950 #undef PRVMTIMEPROFILING
954 #include "prvm_execprogram.h"
956 #undef PRVMSLOWINTERPRETER
960 if (prvm_timeprofiling.integer)
962 #define PRVMTIMEPROFILING 1
963 #include "prvm_execprogram.h"
964 #undef PRVMTIMEPROFILING
968 #include "prvm_execprogram.h"
973 if (developer_insane.integer && prog->tempstringsbuf.cursize > restorevm_tempstringsbuf_cursize)
974 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);
975 // delete tempstrings created by this function
976 prog->tempstringsbuf.cursize = restorevm_tempstringsbuf_cursize;
978 tm = Sys_DirtyTime() - calltime;if (tm < 0 || tm >= 1800) tm = 0;
981 if (prog == SVVM_prog)
982 SV_FlushBroadcastMessages();