/** * 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); }
/** * @brief Create a new container * @param type Type of element inside container * @param data Data pointer for contained element * @param inlist Input links list if any (else it will be created empty) * @param outlist Output links list if any (else it will be created empty) * @param uniqid Unique ID to be put into name * @return Container newly created */ container_t *container_create(u_int type, void *data, list_t *inlist, list_t *outlist, u_int uniqid) { container_t *newcntnr; aspectype_t *rtype; PROFILER_IN(__FILE__, __FUNCTION__, __LINE__); rtype = aspect_type_get_by_id(type); if (!rtype) PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, "Unknown container element type", NULL); /* Make sure meta-data is initialized and contiguous with pointed data */ #if defined(DEBUG_LIBASPECT) fprintf(stderr, "Allocating sizeof(container) + (%s type->size = %u) \n", rtype->name, rtype->size); #endif XALLOC(__FILE__, __FUNCTION__, __LINE__, newcntnr, sizeof(container_t) + rtype->size, NULL); newcntnr->data = (char *) newcntnr + sizeof(container_t); newcntnr->type = type; memcpy((char *) newcntnr->data, (char *) data, rtype->size); /* Create lists if not specified */ if (inlist) newcntnr->inlinks = elist_copy(inlist); else container_linklists_create(newcntnr, CONTAINER_LINK_IN, uniqid); if (outlist) newcntnr->outlinks = elist_copy(outlist); else container_linklists_create(newcntnr, CONTAINER_LINK_OUT, uniqid); /* Make sure the container and contained data are contiguous */ PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, newcntnr); }
/** * Display an element of a hash table * @param h Hash table. * @param key Hash key of object to be printed. * @param inside Print the content of the object in case it is a pointer. * @return Success (0) or Error (-1). */ int revm_table_display_element(hash_t *h, char *key, u_char inside) { void *data; char logbuf[BUFSIZ]; revmexpr_t *newexpr; aspectype_t *type; PROFILER_IN(__FILE__, __FUNCTION__, __LINE__); data = hash_get(h, key); if (h->type == ASPECT_TYPE_UNKNOW || !inside) { snprintf(logbuf, sizeof(logbuf), " { %-40s = <"XFMT"> } \n", key, (eresi_Addr) data); revm_output(logbuf); PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, 0); } if (*key == REVM_VAR_PREFIX) strncpy(logbuf, key, sizeof(logbuf)); else snprintf (logbuf, sizeof(logbuf), "$%s", key); newexpr = revm_expr_get(logbuf); if (newexpr) { revm_output("\t"); revm_expr_print_by_name(logbuf, 0); revm_output("\n"); PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, 0); } revm_output("\t"); if (h->type == ASPECT_TYPE_EXPR) { newexpr = (revmexpr_t *) data; revm_expr_print_by_name(newexpr->label, 0); } else { type = aspect_type_get_by_id(h->type); newexpr = revm_inform_type_addr(type->name, strdup(logbuf), (eresi_Addr) data, NULL, 0, 1); if (!newexpr) PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, "Unable to reflect hash element to expression", -1); revm_expr_print_by_name(logbuf, 0); } revm_output("\n"); PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, 0); }
/** * @brief Create container lists * @param container Container holding the lists * @param linktype CONTAINER_LINK_IN or CONTAINER_LINK_OUT for input or output links list * @param uniqid Unique ID to be put into name * @return -1 on error and 0 on success */ int container_linklists_create(container_t *container, u_int linktype, u_int uniqid) { aspectype_t *type; char bufname[BUFSIZ]; char *prefix; list_t *newlist; PROFILER_IN(__FILE__, __FUNCTION__, __LINE__); /* Check for prefix (XXX: change to lookup user-configured prefixes ?) */ switch (container->type) { case ASPECT_TYPE_BLOC: prefix = "bloc"; break; case ASPECT_TYPE_FUNC: prefix = "func"; break; default: type = aspect_type_get_by_id(container->type); if (!type) PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, "Unable to find type of container", -1); prefix = type->name; } /* Now really allocate the list */ switch (linktype) { case CONTAINER_LINK_IN: snprintf(bufname, BUFSIZ, "%d_%s_"AFMT"_%s", uniqid, prefix, *(eresi_Addr *) container->data, "inputs"); newlist = elist_find(bufname); if (newlist) container->inlinks = newlist; else { XALLOC(__FILE__, __FUNCTION__, __LINE__, container->inlinks, sizeof(list_t), -1); elist_init(container->inlinks, strdup(bufname), ASPECT_TYPE_LINK); } break; case CONTAINER_LINK_OUT: snprintf(bufname, BUFSIZ, "%d_%s_"AFMT"_%s", uniqid, prefix, *(eresi_Addr *) container->data, "outputs"); newlist = elist_find(bufname); if (newlist) container->outlinks = newlist; else { XALLOC(__FILE__, __FUNCTION__, __LINE__, container->outlinks, sizeof(list_t), -1); elist_init(container->outlinks, strdup(bufname), ASPECT_TYPE_LINK); } break; default: PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, "Unknown link type", -1); } PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, 0); }