/** * Check input type, translate if matching */ int cmd_case() { aspectype_t *exprtype; revmexpr_t *matchme; revmexpr_t *candid; int ret; PROFILER_IN(__FILE__, __FUNCTION__, __LINE__); if (!world.curjob->recur[world.curjob->curscope].rwrt.matchexpr) PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, "Case is not in a match", -1); exprtype = aspect_type_get_by_id(ASPECT_TYPE_EXPR); if (!exprtype) PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, "Expression type not found : lacking reflection ?", -1); /* If a previous case has already matched, simply end the transformation now : We must do that here because some "post" commands can be put after a matching "case", so we only stop rewriting at the first case -following- a matching case */ if (world.curjob->recur[world.curjob->curscope].rwrt.matched) { revm_move_pc(world.curjob->curcmd->endlabel); PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, 0); } /* Check if we match */ matchme = (revmexpr_t *) world.curjob->recur[world.curjob->curscope].rwrt.matchexpr; if (!matchme->type) PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, "Invalid type for matchme expression", -1); candid = revm_expr_create(matchme->type, "$candid", strdup(world.curjob->curcmd->param[0])); ret = (!candid ? 1 : revm_expr_match(candid, matchme)); /* No match or bad match : nothing happens */ if (ret) { world.curjob->recur[world.curjob->curscope].rwrt.matched = 0; PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, 0); } /* Matched : transform and execute post side effects if any */ world.curjob->recur[world.curjob->curscope].rwrt.matched = 1; /* Sometimes the case command comes directly with appended post side-effects */ if (!world.curjob->curcmd->param[1]) PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, 0); /* The rewrite output was directly specified in the case command */ revm_case_transform(matchme, strdup(world.curjob->curcmd->param[1])); /* Additional side-effects were specified in the case command */ if (world.curjob->curcmd->param[2] && revm_case_execmd(world.curjob->curcmd->param[2]) < 0) PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, "Post-side-effects commands failed", -1); /* Jump to end of the match construct */ PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, 0); }
/** * Handler for the jmp instruction */ int cmd_jmp() { int ret; PROFILER_IN(__FILE__, __FUNCTION__, __LINE__); ret = revm_move_pc(world.curjob->curcmd->param[0]); PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, (ret)); }
/** * Default case of a match when nothing else has matched */ int cmd_default() { char *str; revmargv_t *cur; char actual[ERESI_MEANING]; PROFILER_IN(__FILE__, __FUNCTION__, __LINE__); cur = world.curjob->curcmd; /* Dont execute if we matched something */ if (world.curjob->recur[world.curjob->curscope].rwrt.matched) PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, 0); /* Create new context */ world.curjob->curscope++; snprintf(actual, sizeof(actual), "job%u_rec%u_labels", world.curjob->id, world.curjob->curscope); hash_init(&world.curjob->recur[world.curjob->curscope].labels, strdup(actual), 3, ASPECT_TYPE_UNKNOW); snprintf(actual, sizeof(actual), "job%u_rec%u_exprs", world.curjob->id, world.curjob->curscope); hash_init(&world.curjob->recur[world.curjob->curscope].exprs, strdup(actual), 7, ASPECT_TYPE_UNKNOW); /* Execute parameter commands */ str = revm_string_get(world.curjob->curcmd->param); cur = world.curjob->curcmd; if (revm_exec_str(str) < 0) { puts("FAILED EXEC_STR"); //PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, // "Display execrequest failed", -1); } world.curjob->curcmd = world.curjob->recur[world.curjob->curscope].script; if (revm_execmd() < 0) { puts("FAILED EXEC_CMD"); //PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, // "Default command execution failed", -1); } /* Restore previous context */ world.curjob->curcmd = cur; world.curjob->recur[world.curjob->curscope].script = NULL; hash_destroy(&world.curjob->recur[world.curjob->curscope].labels); hash_destroy(&world.curjob->recur[world.curjob->curscope].exprs); world.curjob->curscope--; /* Jump to end of rewrite construct */ revm_move_pc(world.curjob->curcmd->endlabel); PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, 0); }
int cmd_jg() { revmexpr_t *last; revmobj_t *res; int ret; PROFILER_IN(__FILE__, __FUNCTION__, __LINE__); last = revm_expr_get(REVM_VAR_RESULT); if (!last || !last->value) PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, "Cannot retreive last result variable", -1); res = last->value; if (res->immed_val.ent > 0) { ret = revm_move_pc(world.curjob->curcmd->param[0]); PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, (ret)); } PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, 0); }