X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=prvm_exec.c;h=452f2803f1b780c3dd1ca70cd0c45b7af03c7308;hb=dc9916ff540094fee6bde0fff89717f5453a573a;hp=1be07894330e569c26fc0e40c6cb274218a7d9a1;hpb=f77d65db40fde1a5e3191628c8b1f9a47b76ba08;p=xonotic%2Fdarkplaces.git diff --git a/prvm_exec.c b/prvm_exec.c index 1be07894..452f2803 100644 --- a/prvm_exec.c +++ b/prvm_exec.c @@ -199,19 +199,19 @@ PRVM_PrintFunction_f ============ */ -void PRVM_PrintFunction_f (void) +void PRVM_PrintFunction_f(cmd_state_t *cmd) { prvm_prog_t *prog; - if (Cmd_Argc() != 3) + if (Cmd_Argc(cmd) != 3) { Con_Printf("usage: prvm_printfunction \n"); return; } - if (!(prog = PRVM_FriendlyProgFromString(Cmd_Argv(1)))) + if (!(prog = PRVM_FriendlyProgFromString(Cmd_Argv(cmd, 1)))) return; - PRVM_PrintFunctionStatements(prog, Cmd_Argv(2)); + PRVM_PrintFunctionStatements(prog, Cmd_Argv(cmd, 2)); } /* @@ -433,16 +433,16 @@ PRVM_CallProfile_f ============ */ -void PRVM_CallProfile_f (void) +void PRVM_CallProfile_f(cmd_state_t *cmd) { prvm_prog_t *prog; - if (Cmd_Argc() != 2) + if (Cmd_Argc(cmd) != 2) { Con_Print("prvm_callprofile \n"); return; } - if (!(prog = PRVM_FriendlyProgFromString(Cmd_Argv(1)))) + if (!(prog = PRVM_FriendlyProgFromString(Cmd_Argv(cmd, 1)))) return; PRVM_CallProfile(prog); @@ -454,7 +454,7 @@ PRVM_Profile_f ============ */ -void PRVM_Profile_f (void) +void PRVM_Profile_f(cmd_state_t *cmd) { prvm_prog_t *prog; int howmany; @@ -466,21 +466,21 @@ void PRVM_Profile_f (void) } howmany = 1<<30; - if (Cmd_Argc() == 3) - howmany = atoi(Cmd_Argv(2)); - else if (Cmd_Argc() != 2) + if (Cmd_Argc(cmd) == 3) + howmany = atoi(Cmd_Argv(cmd, 2)); + else if (Cmd_Argc(cmd) != 2) { Con_Print("prvm_profile \n"); return; } - if (!(prog = PRVM_FriendlyProgFromString(Cmd_Argv(1)))) + if (!(prog = PRVM_FriendlyProgFromString(Cmd_Argv(cmd, 1)))) return; PRVM_Profile(prog, howmany, 0, 0); } -void PRVM_ChildProfile_f (void) +void PRVM_ChildProfile_f(cmd_state_t *cmd) { prvm_prog_t *prog; int howmany; @@ -492,15 +492,15 @@ void PRVM_ChildProfile_f (void) } howmany = 1<<30; - if (Cmd_Argc() == 3) - howmany = atoi(Cmd_Argv(2)); - else if (Cmd_Argc() != 2) + if (Cmd_Argc(cmd) == 3) + howmany = atoi(Cmd_Argv(cmd, 2)); + else if (Cmd_Argc(cmd) != 2) { Con_Print("prvm_childprofile \n"); return; } - if (!(prog = PRVM_FriendlyProgFromString(Cmd_Argv(1)))) + if (!(prog = PRVM_FriendlyProgFromString(Cmd_Argv(cmd, 1)))) return; PRVM_Profile(prog, howmany, 0, 1); @@ -549,7 +549,7 @@ void PRVM_Crash(prvm_prog_t *prog) if(prvm_errordump.integer) { // make a savegame - Host_Savegame_to(prog, va(vabuf, sizeof(vabuf), "crash-%s.dmp", prog->name)); + SV_Savegame_to(prog, va(vabuf, sizeof(vabuf), "crash-%s.dmp", prog->name)); } // dump the stack so host_error can shutdown functions @@ -685,26 +685,46 @@ void PRVM_Init_Exec(prvm_prog_t *prog) Coverage ================== */ +// Note: in these two calls, prog->xfunction is assumed to be sane. +static const char *PRVM_WhereAmI(char *buf, size_t bufsize, prvm_prog_t *prog, mfunction_t *func, int statement) +{ + if (prog->statement_linenums) + { + if (prog->statement_columnnums) + 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); + else + 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); + } + else + return va(buf, bufsize, "%s(%s, %i)", PRVM_GetString(prog, func->s_file), PRVM_GetString(prog, func->s_name), statement - func->first_statement); +} static void PRVM_FunctionCoverageEvent(prvm_prog_t *prog, mfunction_t *func) { ++prog->functions_covered; 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); } -void PRVM_ExplicitCoverageEvent(prvm_prog_t *prog, int statement) +void PRVM_ExplicitCoverageEvent(prvm_prog_t *prog, mfunction_t *func, int statement) { + char vabuf[128]; ++prog->explicit_covered; - Con_Printf("prvm_coverage: %s just executed a coverage() statement for the first time. Coverage: %.2f%%.\n", prog->name, prog->explicit_covered * 100.0 / prog->numexplicitcoveragestatements); + 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); } -static void PRVM_StatementCoverageEvent(prvm_prog_t *prog, int statement) +static void PRVM_StatementCoverageEvent(prvm_prog_t *prog, mfunction_t *func, int statement) { + char vabuf[128]; ++prog->statements_covered; - Con_Printf("prvm_coverage: %s just executed a statement for the first time. Coverage: %.2f%%.\n", prog->name, prog->statements_covered * 100.0 / prog->numstatements); + 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); } +#if defined (__GNUC__) || (__clang__) || (__TINYC__) +# ifndef CONFIG_PEDANTIC +# define HAVE_COMPUTED_GOTOS 1 +# endif +#endif -#define OPA ((prvm_eval_t *)&prog->globals.fp[st->operand[0]]) -#define OPB ((prvm_eval_t *)&prog->globals.fp[st->operand[1]]) -#define OPC ((prvm_eval_t *)&prog->globals.fp[st->operand[2]]) +#define OPA ((prvm_eval_t *)&globals[st->operand[0]]) +#define OPB ((prvm_eval_t *)&globals[st->operand[1]]) +#define OPC ((prvm_eval_t *)&globals[st->operand[2]]) extern cvar_t prvm_traceqc; extern cvar_t prvm_statementprofiling; extern qboolean prvm_runawaycheck; @@ -719,7 +739,7 @@ MVM_ExecuteProgram void MVM_ExecuteProgram (prvm_prog_t *prog, func_t fnum, const char *errormessage) { mstatement_t *st, *startst; - mfunction_t *f, *newf; + mfunction_t *func, *enterfunc; prvm_edict_t *ed; prvm_eval_t *ptr; int jumpcount, cachedpr_trace, exitdepth; @@ -728,7 +748,7 @@ void MVM_ExecuteProgram (prvm_prog_t *prog, func_t fnum, const char *errormessag double tm, starttm; prvm_vec_t tempfloat; // these may become out of date when a builtin is called, and are updated accordingly - prvm_vec_t *cached_edictsfields = prog->edictsfields; + prvm_vec_t *cached_edictsfields = prog->edictsfields.fp; unsigned int cached_entityfields = prog->entityfields; unsigned int cached_entityfields_3 = prog->entityfields - 3; unsigned int cached_entityfieldsarea = prog->entityfieldsarea; @@ -741,6 +761,8 @@ void MVM_ExecuteProgram (prvm_prog_t *prog, func_t fnum, const char *errormessag qboolean cached_allowworldwrites = prog->allowworldwrites; unsigned int cached_flag = prog->flag; + prvm_vec_t *globals = prog->globals.fp; + calltime = Sys_DirtyTime(); if (!fnum || fnum >= (unsigned int)prog->numfunctions) @@ -750,7 +772,7 @@ void MVM_ExecuteProgram (prvm_prog_t *prog, func_t fnum, const char *errormessag prog->error_cmd("MVM_ExecuteProgram: %s", errormessage); } - f = &prog->functions[fnum]; + func = &prog->functions[fnum]; // after executing this function, delete all tempstrings it created restorevm_tempstringsbuf_cursize = prog->tempstringsbuf.cursize; @@ -761,7 +783,7 @@ void MVM_ExecuteProgram (prvm_prog_t *prog, func_t fnum, const char *errormessag exitdepth = prog->depth; // make a stack frame - st = &prog->statements[PRVM_EnterFunction(prog, f)]; + st = &prog->statements[PRVM_EnterFunction(prog, func)]; // save the starting statement pointer for profiling // (when the function exits or jumps, the (st - startst) integer value is // added to the function's profile counter) @@ -775,7 +797,7 @@ void MVM_ExecuteProgram (prvm_prog_t *prog, func_t fnum, const char *errormessag chooseexecprogram: cachedpr_trace = prog->trace; - if (prvm_statementprofiling.integer || prog->trace || prog->watch_global_type != ev_void || prog->watch_field_type != ev_void || prog->break_statement >= 0 || (prvm_coverage.integer & 4)) + if (prog->trace || prog->watch_global_type != ev_void || prog->watch_field_type != ev_void || prog->break_statement >= 0) { #define PRVMSLOWINTERPRETER 1 if (prvm_timeprofiling.integer) @@ -811,7 +833,7 @@ cleanup: prog->tempstringsbuf.cursize = restorevm_tempstringsbuf_cursize; tm = Sys_DirtyTime() - calltime;if (tm < 0 || tm >= 1800) tm = 0; - f->totaltime += tm; + func->totaltime += tm; if (prog == SVVM_prog) SV_FlushBroadcastMessages(); @@ -826,7 +848,7 @@ CLVM_ExecuteProgram void CLVM_ExecuteProgram (prvm_prog_t *prog, func_t fnum, const char *errormessage) { mstatement_t *st, *startst; - mfunction_t *f, *newf; + mfunction_t *func, *enterfunc; prvm_edict_t *ed; prvm_eval_t *ptr; int jumpcount, cachedpr_trace, exitdepth; @@ -835,7 +857,7 @@ void CLVM_ExecuteProgram (prvm_prog_t *prog, func_t fnum, const char *errormessa double tm, starttm; prvm_vec_t tempfloat; // these may become out of date when a builtin is called, and are updated accordingly - prvm_vec_t *cached_edictsfields = prog->edictsfields; + prvm_vec_t *cached_edictsfields = prog->edictsfields.fp; unsigned int cached_entityfields = prog->entityfields; unsigned int cached_entityfields_3 = prog->entityfields - 3; unsigned int cached_entityfieldsarea = prog->entityfieldsarea; @@ -848,6 +870,8 @@ void CLVM_ExecuteProgram (prvm_prog_t *prog, func_t fnum, const char *errormessa qboolean cached_allowworldwrites = prog->allowworldwrites; unsigned int cached_flag = prog->flag; + prvm_vec_t *globals = prog->globals.fp; + calltime = Sys_DirtyTime(); if (!fnum || fnum >= (unsigned int)prog->numfunctions) @@ -857,7 +881,7 @@ void CLVM_ExecuteProgram (prvm_prog_t *prog, func_t fnum, const char *errormessa prog->error_cmd("CLVM_ExecuteProgram: %s", errormessage); } - f = &prog->functions[fnum]; + func = &prog->functions[fnum]; // after executing this function, delete all tempstrings it created restorevm_tempstringsbuf_cursize = prog->tempstringsbuf.cursize; @@ -868,7 +892,7 @@ void CLVM_ExecuteProgram (prvm_prog_t *prog, func_t fnum, const char *errormessa exitdepth = prog->depth; // make a stack frame - st = &prog->statements[PRVM_EnterFunction(prog, f)]; + st = &prog->statements[PRVM_EnterFunction(prog, func)]; // save the starting statement pointer for profiling // (when the function exits or jumps, the (st - startst) integer value is // added to the function's profile counter) @@ -882,7 +906,7 @@ void CLVM_ExecuteProgram (prvm_prog_t *prog, func_t fnum, const char *errormessa chooseexecprogram: cachedpr_trace = prog->trace; - if (prvm_statementprofiling.integer || prog->trace || prog->watch_global_type != ev_void || prog->watch_field_type != ev_void || prog->break_statement >= 0 || (prvm_coverage.integer & 4)) + if (prog->trace || prog->watch_global_type != ev_void || prog->watch_field_type != ev_void || prog->break_statement >= 0) { #define PRVMSLOWINTERPRETER 1 if (prvm_timeprofiling.integer) @@ -918,7 +942,7 @@ cleanup: prog->tempstringsbuf.cursize = restorevm_tempstringsbuf_cursize; tm = Sys_DirtyTime() - calltime;if (tm < 0 || tm >= 1800) tm = 0; - f->totaltime += tm; + func->totaltime += tm; if (prog == SVVM_prog) SV_FlushBroadcastMessages(); @@ -937,7 +961,7 @@ void PRVM_ExecuteProgram (prvm_prog_t *prog, func_t fnum, const char *errormessa #endif { mstatement_t *st, *startst; - mfunction_t *f, *newf; + mfunction_t *func, *enterfunc; prvm_edict_t *ed; prvm_eval_t *ptr; int jumpcount, cachedpr_trace, exitdepth; @@ -946,7 +970,7 @@ void PRVM_ExecuteProgram (prvm_prog_t *prog, func_t fnum, const char *errormessa double tm, starttm; prvm_vec_t tempfloat; // these may become out of date when a builtin is called, and are updated accordingly - prvm_vec_t *cached_edictsfields = prog->edictsfields; + prvm_vec_t *cached_edictsfields = prog->edictsfields.fp; unsigned int cached_entityfields = prog->entityfields; unsigned int cached_entityfields_3 = prog->entityfields - 3; unsigned int cached_entityfieldsarea = prog->entityfieldsarea; @@ -959,6 +983,8 @@ void PRVM_ExecuteProgram (prvm_prog_t *prog, func_t fnum, const char *errormessa qboolean cached_allowworldwrites = prog->allowworldwrites; unsigned int cached_flag = prog->flag; + prvm_vec_t *globals = prog->globals.fp; + calltime = Sys_DirtyTime(); if (!fnum || fnum >= (unsigned int)prog->numfunctions) @@ -968,7 +994,7 @@ void PRVM_ExecuteProgram (prvm_prog_t *prog, func_t fnum, const char *errormessa prog->error_cmd("SVVM_ExecuteProgram: %s", errormessage); } - f = &prog->functions[fnum]; + func = &prog->functions[fnum]; // after executing this function, delete all tempstrings it created restorevm_tempstringsbuf_cursize = prog->tempstringsbuf.cursize; @@ -979,7 +1005,7 @@ void PRVM_ExecuteProgram (prvm_prog_t *prog, func_t fnum, const char *errormessa exitdepth = prog->depth; // make a stack frame - st = &prog->statements[PRVM_EnterFunction(prog, f)]; + st = &prog->statements[PRVM_EnterFunction(prog, func)]; // save the starting statement pointer for profiling // (when the function exits or jumps, the (st - startst) integer value is // added to the function's profile counter) @@ -993,7 +1019,7 @@ void PRVM_ExecuteProgram (prvm_prog_t *prog, func_t fnum, const char *errormessa chooseexecprogram: cachedpr_trace = prog->trace; - if (prvm_statementprofiling.integer || prog->trace || prog->watch_global_type != ev_void || prog->watch_field_type != ev_void || prog->break_statement >= 0 || (prvm_coverage.integer & 4)) + if (prog->trace || prog->watch_global_type != ev_void || prog->watch_field_type != ev_void || prog->break_statement >= 0) { #define PRVMSLOWINTERPRETER 1 if (prvm_timeprofiling.integer) @@ -1029,7 +1055,7 @@ cleanup: prog->tempstringsbuf.cursize = restorevm_tempstringsbuf_cursize; tm = Sys_DirtyTime() - calltime;if (tm < 0 || tm >= 1800) tm = 0; - f->totaltime += tm; + func->totaltime += tm; if (prog == SVVM_prog) SV_FlushBroadcastMessages();