static yajl_gen_status generate_key(yajl_gen g, Var v, void *ctx) { struct generate_context *gctx = (struct generate_context *)ctx; switch (v.type) { case TYPE_OBJ: case TYPE_INT: case TYPE_FLOAT: case TYPE_ERR: { const char *tmp = value_to_literal(v); if (MODE_EMBEDDED_TYPES == gctx->mode) tmp = append_type(tmp, v.type); return yajl_gen_string(g, (const unsigned char *)tmp, strlen(tmp)); } case TYPE_STR: { const char *tmp = v.v.str; size_t len = strlen(tmp); if (MODE_EMBEDDED_TYPES == gctx->mode) if (TYPE_NONE != valid_type(&tmp, &len)) tmp = append_type(tmp, v.type); return yajl_gen_string(g, (const unsigned char *)tmp, strlen(tmp)); } default: panic("Unsupported type in generate_key()"); } return yajl_gen_keys_must_be_strings; }
static yajl_gen_status generate(yajl_gen g, Var v, void *ctx) { struct generate_context *gctx = (struct generate_context *)ctx; switch (v.type) { case TYPE_INT: return yajl_gen_integer(g, v.v.num); case TYPE_FLOAT: return yajl_gen_double(g, *v.v.fnum); case TYPE_OBJ: case TYPE_ERR: { const char *tmp = value_to_literal(v); if (MODE_EMBEDDED_TYPES == gctx->mode) tmp = append_type(tmp, v.type); return yajl_gen_string(g, (const unsigned char *)tmp, strlen(tmp)); } case TYPE_STR: { const char *tmp = v.v.str; size_t len = strlen(tmp); if (MODE_EMBEDDED_TYPES == gctx->mode) if (TYPE_NONE != valid_type(&tmp, &len)) tmp = append_type(tmp, v.type); return yajl_gen_string(g, (const unsigned char *)tmp, strlen(tmp)); } case TYPE_MAP: { struct do_map_closure dmc; dmc.g = g; dmc.gctx = gctx; dmc.status = yajl_gen_status_ok; yajl_gen_map_open(g); if (mapforeach(v, do_map, &dmc)) return dmc.status; yajl_gen_map_close(g); return yajl_gen_status_ok; } case TYPE_LIST: { int i; yajl_gen_status status; yajl_gen_array_open(g); for (i = 1; i <= v.v.list[0].v.num; i++) { status = generate(g, v.v.list[i], ctx); if (yajl_gen_status_ok != status) return status; } yajl_gen_array_close(g); return yajl_gen_status_ok; } default: panic("Unsupported type in generate()"); } return -1; }
static char * ngx_http_static_file_filter_conf(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_static_file_filter_loc_conf_t *sffcf; ngx_uint_t n; ngx_str_t *value; ngx_str_t *type; ngx_uint_t i; sffcf = conf; n = cf->args->nelts; value = cf->args->elts; if (sffcf->types == NULL) { sffcf->types = ngx_array_create(cf->pool, n, sizeof(ngx_str_t)); if (sffcf->types == NULL) { return NGX_CONF_ERROR; } } for (i = 0; i < n; ++i) { append_type(sffcf->types, &value[i]); } return NGX_CONF_OK; }
static void * ngx_http_static_file_filter_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) { ngx_http_static_file_filter_loc_conf_t *prev = parent; ngx_http_static_file_filter_loc_conf_t *conf = child; ngx_uint_t i; ngx_str_t *value; if (conf->types == NULL) { conf->types = prev->types; } else if (prev->types != NULL) { value = prev->types->elts; for (i = 0; i < prev->types->nelts; ++i) { append_type(conf->types, &value[i]); } } return NGX_CONF_OK; }
VOID Fini(INT32 code, VOID *v) { trace_enter(); #define append_type(type) \ if (need_comma) \ ofile << "," ; \ ofile << (type); \ need_comma = true for(unsigned int fid = 1; fid <= fn_nb(); fid++) { if (nb_call[fid] < NB_CALLS_TO_CONCLUDE) continue; ofile << fn_img(fid) << ":" << fn_imgaddr(fid) << ":" << fn_name(fid) << ":"; bool need_comma = false; unsigned int param_val_size = 1 + nb_param_int[fid] + nb_param_int_stack[fid]; for (unsigned int pid = 0; pid < param_val_size; pid++) { if (((float) nb_out[fid][pid]) > 0.75 * ((float) nb_call[fid])) { debug("Found 'out parameter' candidate : [%s@%lX] %s %u (%u <=> %u)\n", fn_img(fid).c_str(), fn_imgaddr(fid), fn_name(fid).c_str(), pid, nb_out[fid][pid], nb_call[fid]); } if (pid == 0 && has_return[fid] == 0) { append_type("VOID"); } else if (pid == 0 && has_return[fid] == 2) { append_type("FLOAT"); } else if (pid < 1 + nb_param_int[fid] && param_is_not_addr[fid][pid]) { append_type("INT"); } else if (param_val[fid][pid]->size() == 0) { append_type("UNDEF"); } else { int param_addr = 0; for (list<UINT64>::iterator it = param_val[fid][pid]->begin(); it != param_val[fid][pid]->end(); it++) { if (is_addr(*it)) { param_addr++; } } float coef = ((float) param_addr) / ((float) param_val[fid][pid]->size()); append_type(coef > THRESHOLD ? "ADDR" : "INT"); ofile << "(" << coef << ")"; } } for (unsigned int pid = 0; pid < nb_param_float[fid] + nb_param_float_stack[fid]; pid++) { append_type("FLOAT"); } ofile << endl; } ofile.close(); trace_leave(); }
int expand_macro(struct prog_info *pi, struct macro *macro, char *rest_line) { int ok = True, macro_arg_count = 0, off, a, b = 0, c, i = 0, j = 0; char *line = NULL; char *temp; char *macro_args[MAX_MACRO_ARGS]; char tmp[7]; char buff[LINEBUFFER_LENGTH]; char arg = False; char *nmn; //string buffer for 'n'ew 'm'acro 'n'ame struct macro_line *old_macro_line; struct macro_call *macro_call; struct macro_label *macro_label; if(rest_line) { //we reserve some extra space for extended macro parameters line = malloc(strlen(rest_line) + 20); if(!line) { print_msg(pi, MSGTYPE_OUT_OF_MEM, NULL); return(False); } /* exchange amca word 'src' with YH:YL and 'dst' with ZH:ZL */ for(c = 0, a = strlen(rest_line); c < a; c++) { switch (tolower(rest_line[c])) { case 's': if(IS_SEPARATOR(rest_line[c-1]) && (rest_line[c+1] == 'r') && (rest_line[c+2] == 'c') && IS_SEPARATOR(rest_line[c+3])) { strcpy(&line[b],"YH:YL"); b += 5; c += 2; } else { line[b++] = rest_line[c]; } break; case 'd': if(IS_SEPARATOR(rest_line[c-1]) && (rest_line[c+1] == 's') && (rest_line[c+2] == 't') && IS_SEPARATOR(rest_line[c+3])) { strcpy(&line[b],"ZH:ZL"); b += 5; c += 2; } else { line[b++] = rest_line[c]; } break; // case ';': // break; default: line[b++] = rest_line[c]; } } strcpy(&line[b],"\n"); /* set CR/LF at the end of the line */ /* here we split up the macro arguments into "macro_args" * Extended macro code interpreter added by TW 2002 */ temp = line; /* test for advanced parameters */ if( temp[0] == '[' ) { // there must be "[" " then "]", else it is garbage if(!strchr(temp, ']')) { print_msg(pi, MSGTYPE_ERROR, "found no closing ']'"); return(False); } // Okay now we are within the advanced code interpreter temp++; // = &temp[1]; // skip the first bracket nmn = malloc(LINEBUFFER_LENGTH); if(!nmn) { print_msg(pi, MSGTYPE_OUT_OF_MEM, NULL); return(False); } strcpy(nmn,macro->name); // create a new macro name buffer c = 1; // byte counter arg = True; // loop flag while(arg) { while(IS_HOR_SPACE(temp[0])) { //skip leading spaces temp++; // = &temp[1]; } off = 0; // pointer offset do { switch(temp[off]) { //test current character code case ':': temp[off] = '\0'; if(off > 0) { c++; macro_args[macro_arg_count++] = temp; } else { print_msg(pi, MSGTYPE_ERROR, "missing register before ':'",nmn); return(False); } break; case ']': arg = False; case ',': a = off; do temp[a--] = '\0'; while( IS_HOR_SPACE(temp[a]) ); if(off > 0) { macro_args[macro_arg_count++] = temp; append_type(pi, nmn, c, temp); c = 1; } else { append_type(pi, nmn, 0, temp); c = 1; } break; default: off++; } } while(temp[off] != '\0'); if(arg) temp = &temp[off+1]; else break; } macro = get_macro(pi,nmn); if(macro == NULL) { print_msg(pi, MSGTYPE_ERROR, "Macro %s is not defined !",nmn); return(False); } free(nmn); } /* or else, we handle the macro as normal macro */ else { line = malloc(strlen(rest_line) + 1); if(!line) { print_msg(pi, MSGTYPE_OUT_OF_MEM, NULL); return(False); } strcpy(line, rest_line); temp = line; while(temp) { macro_args[macro_arg_count++] = temp; temp = get_next_token(temp, TERM_COMMA); } } } if(pi->pass == PASS_1) { macro_call = calloc(1, sizeof(struct macro_call)); if(!macro_call) { print_msg(pi, MSGTYPE_OUT_OF_MEM, NULL); return(False); } if(pi->last_macro_call) pi->last_macro_call->next = macro_call; else pi->first_macro_call = macro_call; pi->last_macro_call = macro_call; macro_call->line_number = pi->fi->line_number; macro_call->include_file = pi->fi->include_file; macro_call->macro = macro; macro_call->prev_on_stack = pi->macro_call; if(macro_call->prev_on_stack) { macro_call->nest_level = macro_call->prev_on_stack->nest_level + 1; macro_call->prev_line_index = macro_call->prev_on_stack->line_index; } } else { for(macro_call = pi->first_macro_call; macro_call; macro_call = macro_call->next) { if((macro_call->include_file->num == pi->fi->include_file->num) && (macro_call->line_number == pi->fi->line_number)) { if(pi->macro_call) { /* Find correct macro_call when using recursion and nesting */ if(macro_call->prev_on_stack == pi->macro_call) if((macro_call->nest_level == (pi->macro_call->nest_level + 1)) && (macro_call->prev_line_index == pi->macro_call->line_index)) break; } else break; } } if(pi->list_line && pi->list_on) { fprintf(pi->list_file, "C:%06x + %s\n", pi->cseg_addr, pi->list_line); pi->list_line = NULL; } } macro_call->line_index = 0; pi->macro_call = macro_call; old_macro_line = pi->macro_line; //printf("\nconvert macro: '%s'\n",macro->name); for(pi->macro_line = macro->first_macro_line; pi->macro_line && ok; pi->macro_line = pi->macro_line->next) { macro_call->line_index++; if(GET_ARG(pi->args, ARG_LISTMAC)) pi->list_line = buff; else pi->list_line = NULL; /* here we change jumps/calls within macro that corresponds to macro labels. Only in case there is an entry in macro_label list */ strcpy(buff,"\0"); macro_label = get_macro_label(pi->macro_line->line,macro); if(macro_label) { /* test if the right macro label has been found */ temp = strstr(pi->macro_line->line,macro_label->label); c = strlen(macro_label->label); if(temp[c] == ':') { /* it is a label definition */ macro_label->running_number++; strncpy(buff, macro_label->label, c - 1); buff[c - 1] = 0; i = strlen(buff) + 2; /* we set the process indeafter label */ /* add running number to it */ strcpy(&buff[c-1],itoa(macro_label->running_number, tmp, 10)); strcat(buff, ":\0"); } else if(IS_HOR_SPACE(temp[c]) || IS_END_OR_COMMENT(temp[c])) { /* it is a jump to a macro defined label */ strcpy(buff,pi->macro_line->line); temp = strstr(buff, macro_label->label); i = temp - buff + strlen(macro_label->label); strncpy(temp, macro_label->label, c - 1); strcpy(&temp[c-1], itoa(macro_label->running_number, tmp, 10)); } } else { i = 0; } /* here we check every character of current line */ for(j = i; pi->macro_line->line[i] != '\0'; i++) { /* check for register place holders */ if(pi->macro_line->line[i] == '@') { i++; if(!isdigit(pi->macro_line->line[i])) print_msg(pi, MSGTYPE_ERROR, "@ must be followed by a number"); else if((pi->macro_line->line[i] - '0') >= macro_arg_count) print_msg(pi, MSGTYPE_ERROR, "Missing macro argument (for @%c)", pi->macro_line->line[i]); else { /* and replace them with given registers */ strcat(&buff[j], macro_args[pi->macro_line->line[i] - '0']); j += strlen(macro_args[pi->macro_line->line[i] - '0']); } } else if (pi->macro_line->line[i] == ';') { strncat(buff, "\n", 1); break; } else { strncat(buff, &pi->macro_line->line[i], 1); } } ok = parse_line(pi, buff); if(ok) { if((pi->pass == PASS_2) && pi->list_line && pi->list_on) fprintf(pi->list_file, " %s\n", pi->list_line); if(pi->error_count >= pi->max_errors) { print_msg(pi, MSGTYPE_MESSAGE, "Maximum error count reached. Exiting..."); ok = False; break; } } } pi->macro_line = old_macro_line; pi->macro_call = macro_call->prev_on_stack; if(rest_line) free(line); return(ok); }