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 static const char *prvm_opnames[] =
294 //=============================================================================
301 extern cvar_t prvm_coverage;
302 extern cvar_t prvm_statementprofiling;
303 extern cvar_t prvm_timeprofiling;
304 static void PRVM_PrintStatement(prvm_prog_t *prog, mstatement_t *s)
307 int opnum = (int)(s - prog->statements);
308 char valuebuf[MAX_INPUTLINE];
311 Con_Printf("s%i: ", opnum);
312 if( prog->statement_linenums )
314 if ( prog->statement_columnnums )
315 Con_Printf( "%s:%i:%i: ", PRVM_GetString( prog, prog->xfunction->s_file ), prog->statement_linenums[ opnum ], prog->statement_columnnums[ opnum ] );
317 Con_Printf( "%s:%i: ", PRVM_GetString( prog, prog->xfunction->s_file ), prog->statement_linenums[ opnum ] );
320 if (prvm_statementprofiling.integer)
321 Con_Printf("%7.0f ", prog->statement_profile[s - prog->statements]);
323 if ( (unsigned)s->op < sizeof(prvm_opnames)/sizeof(prvm_opnames[0]) && prvm_opnames[s->op])
324 opname = prvm_opnames[s->op];
326 opname = valuebuf, dpsnprintf(valuebuf, sizeof(valuebuf), "OPCODE_%u", (unsigned)s->op);
327 Con_Printf("%s ", opname);
329 // don't count a preceding color tag when padding the name
330 if (opname[0] == STRING_COLOR_TAG)
335 if (s->operand[0] >= 0) Con_Printf( "%s", PRVM_GlobalString(prog, s->operand[0], valuebuf, sizeof(valuebuf)));
336 if (s->operand[1] >= 0) Con_Printf(", %s", PRVM_GlobalString(prog, s->operand[1], valuebuf, sizeof(valuebuf)));
337 if (s->operand[2] >= 0) Con_Printf(", %s", PRVM_GlobalString(prog, s->operand[2], valuebuf, sizeof(valuebuf)));
338 if (s->jumpabsolute >= 0) Con_Printf(", statement %i", s->jumpabsolute);
342 void PRVM_PrintFunctionStatements (prvm_prog_t *prog, const char *name)
344 int i, firststatement, endstatement;
346 func = PRVM_ED_FindFunction (prog, name);
349 Con_Printf("%s progs: no function named %s\n", prog->name, name);
352 firststatement = func->first_statement;
353 if (firststatement < 0)
355 Con_Printf("%s progs: function %s is builtin #%i\n", prog->name, name, -firststatement);
359 // find the end statement
360 endstatement = prog->numstatements;
361 for (i = 0;i < prog->numfunctions;i++)
362 if (endstatement > prog->functions[i].first_statement && firststatement < prog->functions[i].first_statement)
363 endstatement = prog->functions[i].first_statement;
365 // now print the range of statements
366 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);
367 prog->xfunction = func;
368 for (i = firststatement;i < endstatement;i++)
370 PRVM_PrintStatement(prog, prog->statements + i);
371 if (!(prvm_coverage.integer & 4))
372 prog->statement_profile[i] = 0;
374 if (prvm_coverage.integer & 4)
375 Con_Printf("Collecting statement coverage, not flushing statement profile.\n");
384 void PRVM_PrintFunction_f(cmd_state_t *cmd)
387 if (Cmd_Argc(cmd) != 3)
389 Con_Printf("usage: prvm_printfunction <program name> <function name>\n");
393 if (!(prog = PRVM_FriendlyProgFromString(Cmd_Argv(cmd, 1))))
396 PRVM_PrintFunctionStatements(prog, Cmd_Argv(cmd, 2));
404 void PRVM_StackTrace (prvm_prog_t *prog)
409 prog->stack[prog->depth].s = prog->xstatement;
410 prog->stack[prog->depth].f = prog->xfunction;
411 for (i = prog->depth;i > 0;i--)
413 f = prog->stack[i].f;
416 Con_Print("<NULL FUNCTION>\n");
419 if (prog->statement_linenums)
421 if (prog->statement_columnnums)
422 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);
424 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);
427 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);
432 void PRVM_ShortStackTrace(prvm_prog_t *prog, char *buf, size_t bufsize)
440 dpsnprintf(buf, bufsize, "(%s) ", prog->name);
444 strlcpy(buf, "<NO PROG>", bufsize);
448 prog->stack[prog->depth].s = prog->xstatement;
449 prog->stack[prog->depth].f = prog->xfunction;
450 for (i = prog->depth;i > 0;i--)
452 f = prog->stack[i].f;
456 ? 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)
465 static void PRVM_CallProfile (prvm_prog_t *prog)
467 mfunction_t *f, *best;
471 double newprofiletime;
473 Con_Printf( "%s Call Profile:\n", prog->name );
480 for (i=0 ; i<prog->numfunctions ; i++)
482 f = &prog->functions[i];
483 if (max < f->totaltime)
491 sum += best->totaltime;
492 Con_Printf("%9.4f %s\n", best->totaltime, PRVM_GetString(prog, best->s_name));
497 newprofiletime = Sys_DirtyTime();
498 Con_Printf("Total time since last profile reset: %9.4f\n", newprofiletime - prog->profiletime);
499 Con_Printf(" - used by QC code of this VM: %9.4f\n", sum);
501 prog->profiletime = newprofiletime;
504 void PRVM_Profile (prvm_prog_t *prog, int maxfunctions, double mintime, int sortby)
506 mfunction_t *f, *best;
510 if(!prvm_timeprofiling.integer)
511 mintime *= 10000000; // count each statement as about 0.1µs
513 if(prvm_timeprofiling.integer)
514 Con_Printf( "%s Profile:\n[CallCount] [Time] [BuiltinTm] [Statement] [BuiltinCt] [TimeTotal] [StmtTotal] [BltnTotal] [self]\n", prog->name );
515 // 12345678901 12345678901 12345678901 12345678901 12345678901 12345678901 12345678901 123.45%
517 Con_Printf( "%s Profile:\n[CallCount] [Statement] [BuiltinCt] [StmtTotal] [BltnTotal] [self]\n", prog->name );
518 // 12345678901 12345678901 12345678901 12345678901 12345678901 123.45%
525 for (i=0 ; i<prog->numfunctions ; i++)
527 f = &prog->functions[i];
528 if(prvm_timeprofiling.integer)
532 if(f->first_statement < 0)
534 if (max < f->tprofile)
542 if (max < f->tprofile_total)
544 max = f->tprofile_total;
551 if (max < f->tprofile + f->tbprofile)
553 max = f->tprofile + f->tbprofile;
562 if (max < f->profile_total + f->builtinsprofile_total + f->callcount)
564 max = f->profile_total + f->builtinsprofile_total + f->callcount;
570 if (max < f->profile + f->builtinsprofile + f->callcount)
572 max = f->profile + f->builtinsprofile + f->callcount;
580 if (num < maxfunctions && max > mintime)
582 if(prvm_timeprofiling.integer)
584 if (best->first_statement < 0)
585 Con_Printf("%11.0f %11.6f ------------- builtin ------------- %11.6f ----------- builtin ----------- %s\n", best->callcount, best->tprofile, best->tprofile, PRVM_GetString(prog, best->s_name));
586 // %11.6f 12345678901 12345678901 12345678901 %11.6f 12345678901 12345678901 123.45%
588 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));
592 if (best->first_statement < 0)
593 Con_Printf("%11.0f ----------------------- builtin ----------------------- %s\n", best->callcount, PRVM_GetString(prog, best->s_name));
594 // 12345678901 12345678901 12345678901 12345678901 123.45%
596 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));
603 best->builtinsprofile = 0;
604 best->profile_total = 0;
605 best->tprofile_total = 0;
606 best->builtinsprofile_total = 0;
618 void PRVM_CallProfile_f(cmd_state_t *cmd)
621 if (Cmd_Argc(cmd) != 2)
623 Con_Print("prvm_callprofile <program name>\n");
627 if (!(prog = PRVM_FriendlyProgFromString(Cmd_Argv(cmd, 1))))
630 PRVM_CallProfile(prog);
639 void PRVM_Profile_f(cmd_state_t *cmd)
644 if (prvm_coverage.integer & 1)
646 Con_Printf("Collecting function coverage, cannot profile - sorry!\n");
651 if (Cmd_Argc(cmd) == 3)
652 howmany = atoi(Cmd_Argv(cmd, 2));
653 else if (Cmd_Argc(cmd) != 2)
655 Con_Print("prvm_profile <program name>\n");
659 if (!(prog = PRVM_FriendlyProgFromString(Cmd_Argv(cmd, 1))))
662 PRVM_Profile(prog, howmany, 0, 0);
665 void PRVM_ChildProfile_f(cmd_state_t *cmd)
670 if (prvm_coverage.integer & 1)
672 Con_Printf("Collecting function coverage, cannot profile - sorry!\n");
677 if (Cmd_Argc(cmd) == 3)
678 howmany = atoi(Cmd_Argv(cmd, 2));
679 else if (Cmd_Argc(cmd) != 2)
681 Con_Print("prvm_childprofile <program name>\n");
685 if (!(prog = PRVM_FriendlyProgFromString(Cmd_Argv(cmd, 1))))
688 PRVM_Profile(prog, howmany, 0, 1);
691 void PRVM_PrintState(prvm_prog_t *prog, int stack_index)
694 mfunction_t *func = prog->xfunction;
695 int st = prog->xstatement;
696 if (stack_index > 0 && stack_index <= prog->depth)
698 func = prog->stack[prog->depth - stack_index].f;
699 st = prog->stack[prog->depth - stack_index].s;
701 if (prog->statestring)
703 Con_Printf("Caller-provided information: %s\n", prog->statestring);
707 for (i = -7; i <= 0;i++)
708 if (st + i >= func->first_statement)
709 PRVM_PrintStatement(prog, prog->statements + st + i);
711 PRVM_StackTrace(prog);
714 extern cvar_t prvm_errordump;
715 void PRVM_Crash(prvm_prog_t *prog)
723 PRVM_serverfunction(SV_Shutdown) = 0; // don't call SV_Shutdown on crash
725 if( prog->depth > 0 )
727 Con_Printf("QuakeC crash report for %s:\n", prog->name);
728 PRVM_PrintState(prog, 0);
731 if(prvm_errordump.integer)
734 SV_Savegame_to(prog, va(vabuf, sizeof(vabuf), "crash-%s.dmp", prog->name));
737 // dump the stack so host_error can shutdown functions
739 prog->localstack_used = 0;
741 // delete all tempstrings (FIXME: is this safe in VM->engine->VM recursion?)
742 prog->tempstringsbuf.cursize = 0;
744 // reset the prog pointer
749 ============================================================================
752 The interpretation main loop
753 ============================================================================
760 Returns the new program statement counter
763 static int PRVM_EnterFunction (prvm_prog_t *prog, mfunction_t *f)
768 prog->error_cmd("PRVM_EnterFunction: NULL function in %s", prog->name);
770 prog->stack[prog->depth].s = prog->xstatement;
771 prog->stack[prog->depth].f = prog->xfunction;
772 prog->stack[prog->depth].profile_acc = -f->profile;
773 prog->stack[prog->depth].tprofile_acc = -f->tprofile + -f->tbprofile;
774 prog->stack[prog->depth].builtinsprofile_acc = -f->builtinsprofile;
776 if (prog->depth >=PRVM_MAX_STACK_DEPTH)
777 prog->error_cmd("stack overflow");
779 // save off any locals that the new function steps on
781 if (prog->localstack_used + c > PRVM_LOCALSTACK_SIZE)
782 prog->error_cmd("PRVM_ExecuteProgram: locals stack overflow in %s", prog->name);
784 for (i=0 ; i < c ; i++)
785 prog->localstack[prog->localstack_used+i] = prog->globals.ip[f->parm_start + i];
786 prog->localstack_used += c;
790 for (i=0 ; i<f->numparms ; i++)
792 for (j=0 ; j<f->parm_size[i] ; j++)
794 prog->globals.ip[o] = prog->globals.ip[OFS_PARM0+i*3+j];
801 return f->first_statement - 1; // offset the s++
809 static int PRVM_LeaveFunction (prvm_prog_t *prog)
814 if (prog->depth <= 0)
815 prog->error_cmd("prog stack underflow in %s", prog->name);
817 if (!prog->xfunction)
818 prog->error_cmd("PR_LeaveFunction: NULL function in %s", prog->name);
819 // restore locals from the stack
820 c = prog->xfunction->locals;
821 prog->localstack_used -= c;
822 if (prog->localstack_used < 0)
823 prog->error_cmd("PRVM_ExecuteProgram: locals stack underflow in %s", prog->name);
825 for (i=0 ; i < c ; i++)
826 prog->globals.ip[prog->xfunction->parm_start + i] = prog->localstack[prog->localstack_used+i];
832 prog->xfunction = prog->stack[prog->depth].f;
833 prog->stack[prog->depth].profile_acc += f->profile;
834 prog->stack[prog->depth].tprofile_acc += f->tprofile + f->tbprofile;
835 prog->stack[prog->depth].builtinsprofile_acc += f->builtinsprofile;
838 prog->stack[prog->depth-1].profile_acc += prog->stack[prog->depth].profile_acc;
839 prog->stack[prog->depth-1].tprofile_acc += prog->stack[prog->depth].tprofile_acc;
840 prog->stack[prog->depth-1].builtinsprofile_acc += prog->stack[prog->depth].builtinsprofile_acc;
844 // if f is already on the call stack...
845 // we cannot add this profile data to it now
846 // or we would add it more than once
847 // so, let's only add to the function's profile if it is the outermost call
848 f->profile_total += prog->stack[prog->depth].profile_acc;
849 f->tprofile_total += prog->stack[prog->depth].tprofile_acc;
850 f->builtinsprofile_total += prog->stack[prog->depth].builtinsprofile_acc;
853 return prog->stack[prog->depth].s;
856 void PRVM_Init_Exec(prvm_prog_t *prog)
860 prog->localstack_used = 0;
861 // reset the string table
870 // Note: in these two calls, prog->xfunction is assumed to be sane.
871 static const char *PRVM_WhereAmI(char *buf, size_t bufsize, prvm_prog_t *prog, mfunction_t *func, int statement)
873 if (prog->statement_linenums)
875 if (prog->statement_columnnums)
876 return va(buf, bufsize, "%s:%i:%i(%s, %i)", PRVM_GetString(prog, func->s_file), prog->statement_linenums[statement], prog->statement_columnnums[statement], PRVM_GetString(prog, func->s_name), statement - func->first_statement);
878 return va(buf, bufsize, "%s:%i(%s, %i)", PRVM_GetString(prog, func->s_file), prog->statement_linenums[statement], PRVM_GetString(prog, func->s_name), statement - func->first_statement);
881 return va(buf, bufsize, "%s(%s, %i)", PRVM_GetString(prog, func->s_file), PRVM_GetString(prog, func->s_name), statement - func->first_statement);
883 static void PRVM_FunctionCoverageEvent(prvm_prog_t *prog, mfunction_t *func)
885 ++prog->functions_covered;
886 Con_Printf("prvm_coverage: %s just called %s for the first time. Coverage: %.2f%%.\n", prog->name, PRVM_GetString(prog, func->s_name), prog->functions_covered * 100.0 / prog->numfunctions);
888 void PRVM_ExplicitCoverageEvent(prvm_prog_t *prog, mfunction_t *func, int statement)
891 ++prog->explicit_covered;
892 Con_Printf("prvm_coverage: %s just executed a coverage() statement at %s for the first time. Coverage: %.2f%%.\n", prog->name, PRVM_WhereAmI(vabuf, sizeof(vabuf), prog, func, statement), prog->explicit_covered * 100.0 / prog->numexplicitcoveragestatements);
894 static void PRVM_StatementCoverageEvent(prvm_prog_t *prog, mfunction_t *func, int statement)
897 ++prog->statements_covered;
898 Con_Printf("prvm_coverage: %s just executed a statement at %s for the first time. Coverage: %.2f%%.\n", prog->name, PRVM_WhereAmI(vabuf, sizeof(vabuf), prog, func, statement), prog->statements_covered * 100.0 / prog->numstatements);
901 #if defined (__GNUC__) || (__clang__) || (__TINYC__)
902 # ifndef CONFIG_PEDANTIC
903 # define HAVE_COMPUTED_GOTOS 1
907 #define OPA ((prvm_eval_t *)&globals[st->operand[0]])
908 #define OPB ((prvm_eval_t *)&globals[st->operand[1]])
909 #define OPC ((prvm_eval_t *)&globals[st->operand[2]])
910 extern cvar_t prvm_traceqc;
911 extern cvar_t prvm_statementprofiling;
912 extern qbool prvm_runawaycheck;
921 void MVM_ExecuteProgram (prvm_prog_t *prog, func_t fnum, const char *errormessage)
923 mstatement_t *st, *startst;
924 mfunction_t *func, *enterfunc;
927 int jumpcount, cachedpr_trace, exitdepth;
928 int restorevm_tempstringsbuf_cursize;
931 prvm_vec_t tempfloat;
932 // these may become out of date when a builtin is called, and are updated accordingly
933 prvm_vec_t *cached_edictsfields = prog->edictsfields.fp;
934 unsigned int cached_entityfields = prog->entityfields;
935 unsigned int cached_entityfields_3 = prog->entityfields - 3;
936 unsigned int cached_entityfieldsarea = prog->entityfieldsarea;
937 unsigned int cached_entityfieldsarea_entityfields = prog->entityfieldsarea - prog->entityfields;
938 unsigned int cached_entityfieldsarea_3 = prog->entityfieldsarea - 3;
939 unsigned int cached_entityfieldsarea_entityfields_3 = prog->entityfieldsarea - prog->entityfields - 3;
940 unsigned int cached_max_edicts = prog->max_edicts;
941 // these do not change
942 mstatement_t *cached_statements = prog->statements;
943 qbool cached_allowworldwrites = prog->allowworldwrites;
944 unsigned int cached_flag = prog->flag;
946 prvm_vec_t *globals = prog->globals.fp;
948 calltime = Sys_DirtyTime();
950 if (!fnum || fnum >= (unsigned int)prog->numfunctions)
952 if (PRVM_allglobaledict(self))
953 PRVM_ED_Print(prog, PRVM_PROG_TO_EDICT(PRVM_allglobaledict(self)), NULL);
954 prog->error_cmd("MVM_ExecuteProgram: %s", errormessage);
957 func = &prog->functions[fnum];
959 // after executing this function, delete all tempstrings it created
960 restorevm_tempstringsbuf_cursize = prog->tempstringsbuf.cursize;
962 prog->trace = prvm_traceqc.integer;
964 // we know we're done when pr_depth drops to this
965 exitdepth = prog->depth;
967 // make a stack frame
968 st = &prog->statements[PRVM_EnterFunction(prog, func)];
969 // save the starting statement pointer for profiling
970 // (when the function exits or jumps, the (st - startst) integer value is
971 // added to the function's profile counter)
974 // instead of counting instructions, we count jumps
976 // add one to the callcount of this function because otherwise engine-called functions aren't counted
977 if (prog->xfunction->callcount++ == 0 && (prvm_coverage.integer & 1))
978 PRVM_FunctionCoverageEvent(prog, prog->xfunction);
981 cachedpr_trace = prog->trace;
982 if (prog->trace || prog->watch_global_type != ev_void || prog->watch_field_type != ev_void || prog->break_statement >= 0)
984 #define PRVMSLOWINTERPRETER 1
985 if (prvm_timeprofiling.integer)
987 #define PRVMTIMEPROFILING 1
988 #include "prvm_execprogram.h"
989 #undef PRVMTIMEPROFILING
993 #include "prvm_execprogram.h"
995 #undef PRVMSLOWINTERPRETER
999 if (prvm_timeprofiling.integer)
1001 #define PRVMTIMEPROFILING 1
1002 #include "prvm_execprogram.h"
1003 #undef PRVMTIMEPROFILING
1007 #include "prvm_execprogram.h"
1012 if (developer_insane.integer && prog->tempstringsbuf.cursize > restorevm_tempstringsbuf_cursize)
1013 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);
1014 // delete tempstrings created by this function
1015 prog->tempstringsbuf.cursize = restorevm_tempstringsbuf_cursize;
1017 tm = Sys_DirtyTime() - calltime;if (tm < 0 || tm >= 1800) tm = 0;
1018 func->totaltime += tm;
1020 if (prog == SVVM_prog)
1021 SV_FlushBroadcastMessages();
1026 ====================
1028 ====================
1030 void CLVM_ExecuteProgram (prvm_prog_t *prog, func_t fnum, const char *errormessage)
1032 mstatement_t *st, *startst;
1033 mfunction_t *func, *enterfunc;
1036 int jumpcount, cachedpr_trace, exitdepth;
1037 int restorevm_tempstringsbuf_cursize;
1040 prvm_vec_t tempfloat;
1041 // these may become out of date when a builtin is called, and are updated accordingly
1042 prvm_vec_t *cached_edictsfields = prog->edictsfields.fp;
1043 unsigned int cached_entityfields = prog->entityfields;
1044 unsigned int cached_entityfields_3 = prog->entityfields - 3;
1045 unsigned int cached_entityfieldsarea = prog->entityfieldsarea;
1046 unsigned int cached_entityfieldsarea_entityfields = prog->entityfieldsarea - prog->entityfields;
1047 unsigned int cached_entityfieldsarea_3 = prog->entityfieldsarea - 3;
1048 unsigned int cached_entityfieldsarea_entityfields_3 = prog->entityfieldsarea - prog->entityfields - 3;
1049 unsigned int cached_max_edicts = prog->max_edicts;
1050 // these do not change
1051 mstatement_t *cached_statements = prog->statements;
1052 qbool cached_allowworldwrites = prog->allowworldwrites;
1053 unsigned int cached_flag = prog->flag;
1055 prvm_vec_t *globals = prog->globals.fp;
1057 calltime = Sys_DirtyTime();
1059 if (!fnum || fnum >= (unsigned int)prog->numfunctions)
1061 if (PRVM_allglobaledict(self))
1062 PRVM_ED_Print(prog, PRVM_PROG_TO_EDICT(PRVM_allglobaledict(self)), NULL);
1063 prog->error_cmd("CLVM_ExecuteProgram: %s", errormessage);
1066 func = &prog->functions[fnum];
1068 // after executing this function, delete all tempstrings it created
1069 restorevm_tempstringsbuf_cursize = prog->tempstringsbuf.cursize;
1071 prog->trace = prvm_traceqc.integer;
1073 // we know we're done when pr_depth drops to this
1074 exitdepth = prog->depth;
1076 // make a stack frame
1077 st = &prog->statements[PRVM_EnterFunction(prog, func)];
1078 // save the starting statement pointer for profiling
1079 // (when the function exits or jumps, the (st - startst) integer value is
1080 // added to the function's profile counter)
1083 // instead of counting instructions, we count jumps
1085 // add one to the callcount of this function because otherwise engine-called functions aren't counted
1086 if (prog->xfunction->callcount++ == 0 && (prvm_coverage.integer & 1))
1087 PRVM_FunctionCoverageEvent(prog, prog->xfunction);
1090 cachedpr_trace = prog->trace;
1091 if (prog->trace || prog->watch_global_type != ev_void || prog->watch_field_type != ev_void || prog->break_statement >= 0)
1093 #define PRVMSLOWINTERPRETER 1
1094 if (prvm_timeprofiling.integer)
1096 #define PRVMTIMEPROFILING 1
1097 #include "prvm_execprogram.h"
1098 #undef PRVMTIMEPROFILING
1102 #include "prvm_execprogram.h"
1104 #undef PRVMSLOWINTERPRETER
1108 if (prvm_timeprofiling.integer)
1110 #define PRVMTIMEPROFILING 1
1111 #include "prvm_execprogram.h"
1112 #undef PRVMTIMEPROFILING
1116 #include "prvm_execprogram.h"
1121 if (developer_insane.integer && prog->tempstringsbuf.cursize > restorevm_tempstringsbuf_cursize)
1122 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);
1123 // delete tempstrings created by this function
1124 prog->tempstringsbuf.cursize = restorevm_tempstringsbuf_cursize;
1126 tm = Sys_DirtyTime() - calltime;if (tm < 0 || tm >= 1800) tm = 0;
1127 func->totaltime += tm;
1129 if (prog == SVVM_prog)
1130 SV_FlushBroadcastMessages();
1135 ====================
1137 ====================
1140 void SVVM_ExecuteProgram (prvm_prog_t *prog, func_t fnum, const char *errormessage)
1142 void PRVM_ExecuteProgram (prvm_prog_t *prog, func_t fnum, const char *errormessage)
1145 mstatement_t *st, *startst;
1146 mfunction_t *func, *enterfunc;
1149 int jumpcount, cachedpr_trace, exitdepth;
1150 int restorevm_tempstringsbuf_cursize;
1153 prvm_vec_t tempfloat;
1154 // these may become out of date when a builtin is called, and are updated accordingly
1155 prvm_vec_t *cached_edictsfields = prog->edictsfields.fp;
1156 unsigned int cached_entityfields = prog->entityfields;
1157 unsigned int cached_entityfields_3 = prog->entityfields - 3;
1158 unsigned int cached_entityfieldsarea = prog->entityfieldsarea;
1159 unsigned int cached_entityfieldsarea_entityfields = prog->entityfieldsarea - prog->entityfields;
1160 unsigned int cached_entityfieldsarea_3 = prog->entityfieldsarea - 3;
1161 unsigned int cached_entityfieldsarea_entityfields_3 = prog->entityfieldsarea - prog->entityfields - 3;
1162 unsigned int cached_max_edicts = prog->max_edicts;
1163 // these do not change
1164 mstatement_t *cached_statements = prog->statements;
1165 qbool cached_allowworldwrites = prog->allowworldwrites;
1166 unsigned int cached_flag = prog->flag;
1168 prvm_vec_t *globals = prog->globals.fp;
1170 calltime = Sys_DirtyTime();
1172 if (!fnum || fnum >= (unsigned int)prog->numfunctions)
1174 if (PRVM_allglobaledict(self))
1175 PRVM_ED_Print(prog, PRVM_PROG_TO_EDICT(PRVM_allglobaledict(self)), NULL);
1176 prog->error_cmd("SVVM_ExecuteProgram: %s", errormessage);
1179 func = &prog->functions[fnum];
1181 // after executing this function, delete all tempstrings it created
1182 restorevm_tempstringsbuf_cursize = prog->tempstringsbuf.cursize;
1184 prog->trace = prvm_traceqc.integer;
1186 // we know we're done when pr_depth drops to this
1187 exitdepth = prog->depth;
1189 // make a stack frame
1190 st = &prog->statements[PRVM_EnterFunction(prog, func)];
1191 // save the starting statement pointer for profiling
1192 // (when the function exits or jumps, the (st - startst) integer value is
1193 // added to the function's profile counter)
1196 // instead of counting instructions, we count jumps
1198 // add one to the callcount of this function because otherwise engine-called functions aren't counted
1199 if (prog->xfunction->callcount++ == 0 && (prvm_coverage.integer & 1))
1200 PRVM_FunctionCoverageEvent(prog, prog->xfunction);
1203 cachedpr_trace = prog->trace;
1204 if (prog->trace || prog->watch_global_type != ev_void || prog->watch_field_type != ev_void || prog->break_statement >= 0)
1206 #define PRVMSLOWINTERPRETER 1
1207 if (prvm_timeprofiling.integer)
1209 #define PRVMTIMEPROFILING 1
1210 #include "prvm_execprogram.h"
1211 #undef PRVMTIMEPROFILING
1215 #include "prvm_execprogram.h"
1217 #undef PRVMSLOWINTERPRETER
1221 if (prvm_timeprofiling.integer)
1223 #define PRVMTIMEPROFILING 1
1224 #include "prvm_execprogram.h"
1225 #undef PRVMTIMEPROFILING
1229 #include "prvm_execprogram.h"
1234 if (developer_insane.integer && prog->tempstringsbuf.cursize > restorevm_tempstringsbuf_cursize)
1235 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);
1236 // delete tempstrings created by this function
1237 prog->tempstringsbuf.cursize = restorevm_tempstringsbuf_cursize;
1239 tm = Sys_DirtyTime() - calltime;if (tm < 0 || tm >= 1800) tm = 0;
1240 func->totaltime += tm;
1242 if (prog == SVVM_prog)
1243 SV_FlushBroadcastMessages();