static void spoil_mon_info() { int i; vec_ptr v = vec_alloc(NULL); doc_ptr doc = doc_alloc(80); spoiler_hack = TRUE; for (i = 1; i < max_r_idx; i++) { monster_race *r_ptr = &r_info[i]; if (!r_ptr->name) continue; if (r_ptr->id == MON_MONKEY_CLONE) continue; if (r_ptr->id == MON_KAGE) continue; vec_add(v, r_ptr); } vec_sort(v, (vec_cmp_f)_compare_r_level_desc); for (i = 0; i < vec_length(v); i++) { monster_race *r_ptr = vec_get(v, i); doc_printf(doc, "<topic:%s><color:r>=====================================================================</color>\n", r_name + r_ptr->name); mon_display_doc(r_ptr, doc); doc_newline(doc); } vec_free(v); doc_display(doc, "Monster Spoilers", 0); doc_free(doc); spoiler_hack = FALSE; }
tree c_finish_oacc_wait (location_t loc, tree parms, tree clauses) { const int nparms = list_length (parms); tree stmt, t; vec<tree, va_gc> *args; vec_alloc (args, nparms + 2); stmt = builtin_decl_explicit (BUILT_IN_GOACC_WAIT); if (find_omp_clause (clauses, OMP_CLAUSE_ASYNC)) t = OMP_CLAUSE_ASYNC_EXPR (clauses); else t = build_int_cst (integer_type_node, GOMP_ASYNC_SYNC); args->quick_push (t); args->quick_push (build_int_cst (integer_type_node, nparms)); for (t = parms; t; t = TREE_CHAIN (t)) { if (TREE_CODE (OMP_CLAUSE_WAIT_EXPR (t)) == INTEGER_CST) args->quick_push (build_int_cst (integer_type_node, TREE_INT_CST_LOW (OMP_CLAUSE_WAIT_EXPR (t)))); else args->quick_push (OMP_CLAUSE_WAIT_EXPR (t)); } stmt = build_call_expr_loc_vec (loc, stmt, args); add_stmt (stmt); vec_free (args); return stmt; }
static void spoil_spells_by_class(void) { int i, realm_idx; doc_ptr doc = doc_alloc(80); vec_ptr vec = vec_alloc(NULL); for (i = 0; i < MAX_CLASS; i++) vec_add_int(vec, i); vec_sort(vec, (vec_cmp_f)_cmp_class_name); for (i = 0; i < vec_length(vec); i++) { int class_idx = vec_get_int(vec, i); class_t *class_ptr = get_class_aux(class_idx, 0); bool class_heading = FALSE; if (class_idx == CLASS_RAGE_MAGE) continue; /* broken */ for (realm_idx = REALM_LIFE; realm_idx <= MAX_REALM; realm_idx++) { if (_check_realm(class_idx, realm_idx)) { doc_ptr cols[2]; cols[0] = doc_alloc(40); cols[1] = doc_alloc(40); _spoil_spell_book(cols[0], class_idx, realm_idx, 0); _spoil_spell_book(cols[1], class_idx, realm_idx, 1); if (class_idx != CLASS_RED_MAGE || realm_idx == REALM_ARCANE) { _spoil_spell_book(cols[0], class_idx, realm_idx, 2); _spoil_spell_book(cols[1], class_idx, realm_idx, 3); } if (!class_heading) { doc_printf(doc, "<topic:%s><color:r>%s</color>\n", class_ptr->name, class_ptr->name); doc_printf(doc, "%s\n\n", class_ptr->desc); class_heading = TRUE; } doc_printf(doc, "<color:B>%s</color>\n", realm_names[realm_idx]); doc_insert_cols(doc, cols, 2, 0); doc_free(cols[0]); doc_free(cols[1]); } } } doc_display(doc, "Spells by Class", 0); doc_free(doc); vec_free(vec); }
doc_ptr doc_alloc(int width) { doc_ptr res = malloc(sizeof(doc_t)); doc_style_t style = {0}; res->cursor.x = 0; res->cursor.y = 0; res->selection = doc_region_invalid(); res->width = width; res->pages = vec_alloc(free); res->styles = str_map_alloc(free); res->bookmarks = vec_alloc(_doc_bookmark_free); res->links = int_map_alloc(_doc_link_free); res->style_stack = vec_alloc(free); res->name = string_alloc(); res->html_header = string_alloc(); /* Default Styles */ _add_doc_style_f(res, "normal", _normal_style); _add_doc_style_f(res, "note", _note_style); _add_doc_style_f(res, "title", _title_style); _add_doc_style_f(res, "heading", _heading_style); _add_doc_style_f(res, "keyword", _keyword_style); _add_doc_style_f(res, "keypress", _keypress_style); _add_doc_style_f(res, "link", _link_style); _add_doc_style_f(res, "screenshot", _screenshot_style); _add_doc_style_f(res, "table", _table_style); _add_doc_style_f(res, "selection", _selection_style); _add_doc_style_f(res, "indent", _indent_style); _add_doc_style_f(res, "wide", _wide_style); /* bottom of the style stack is *always* "normal" and can never be popped */ _normal_style(&style); doc_push_style(res, &style); return res; }
vec_ptr doc_get_links(doc_ptr doc) { vec_ptr links = vec_alloc(NULL); int_map_iter_ptr iter; for (iter = int_map_iter_alloc(doc->links); int_map_iter_is_valid(iter); int_map_iter_next(iter) ) { doc_link_ptr link = int_map_iter_current(iter); vec_add(links, link); } int_map_iter_free(iter); vec_sort(links, (vec_cmp_f)_compare_links); return links; }
static void _spoil_spells_by_realm_aux2(int realm_idx, int class1_idx) { int i, row, col, class_idx, choice; vec_ptr vec = vec_alloc(NULL); for (class_idx = 0; class_idx < MAX_CLASS; class_idx++) { if (_check_realm(class_idx, realm_idx)) vec_add_int(vec, class_idx); } vec_sort(vec, (vec_cmp_f)_cmp_class_name); while (1) { Term_clear(); c_prt(TERM_L_BLUE, format("%s", realm_names[realm_idx]), 2, 0); c_prt(TERM_L_BLUE, format("First Class: %s", get_class_aux(class1_idx, 0)->name), 3, 0); /* Classes */ row = 4; col = 2; c_prt(TERM_RED, "Second Class", row++, col - 2); for (i = 0; i < vec_length(vec); i++) { int class_idx = vec_get_int(vec, i); class_t *class_ptr = get_class_aux(class_idx, 0); prt(format("(%c) %s", 'a' + i, class_ptr->name), row++, col); } i = inkey(); if (i == ESCAPE) break; choice = i - 'a'; if (0 <= choice && choice < vec_length(vec)) { class_idx = vec_get_int(vec, choice); _spoil_spells_by_realm_aux3(realm_idx, class1_idx, class_idx); } } vec_free(vec); }
static clib_error_t * setup_signal_handlers (unix_main_t * um) { uword i; struct sigaction sa; /* give a big enough buffer for msg, most likely it can avoid vec_resize */ vec_alloc (syslog_msg, 2048); for (i = 1; i < 32; i++) { clib_memset (&sa, 0, sizeof (sa)); sa.sa_sigaction = (void *) unix_signal_handler; sa.sa_flags = SA_SIGINFO; switch (i) { /* these signals take the default action */ case SIGKILL: case SIGSTOP: case SIGUSR1: case SIGUSR2: continue; /* ignore SIGPIPE, SIGCHLD */ case SIGPIPE: case SIGCHLD: sa.sa_sigaction = (void *) SIG_IGN; break; /* catch and handle all other signals */ default: break; } if (sigaction (i, &sa, 0) < 0) return clib_error_return_unix (0, "sigaction %U", format_signal, i); } return 0; }
void init_ssanames (struct function *fn, int size) { if (size < 50) size = 50; vec_alloc (SSANAMES (fn), size); /* Version 0 is special, so reserve the first slot in the table. Though currently unused, we may use version 0 in alias analysis as part of the heuristics used to group aliases when the alias sets are too large. We use vec::quick_push here because we know that SSA_NAMES has at least 50 elements reserved in it. */ SSANAMES (fn)->quick_push (NULL_TREE); FREE_SSANAMES (fn) = NULL; fn->gimple_df->ssa_renaming_needed = 0; fn->gimple_df->rename_vops = 0; }
static tree vxworks_emutls_var_init (tree var, tree decl, tree tmpl_addr) { vec<constructor_elt, va_gc> *v; vec_alloc (v, 3); tree type = TREE_TYPE (var); tree field = TYPE_FIELDS (type); constructor_elt elt = {field, fold_convert (TREE_TYPE (field), tmpl_addr)}; v->quick_push (elt); field = DECL_CHAIN (field); elt.index = field; elt.value = build_int_cst (TREE_TYPE (field), 0); v->quick_push (elt); field = DECL_CHAIN (field); elt.index = field; elt.value = fold_convert (TREE_TYPE (field), DECL_SIZE_UNIT (decl)); v->quick_push (elt); return build_constructor (type, v); }
vec_ptr string_split(string_ptr str, char sep) { vec_ptr v = vec_alloc((vec_free_f)string_free); const char *pos = str->buf; int done = 0; while (!done && *pos) { const char *next = strchr(pos, sep); string_ptr s; if (!next && *pos) { next = strchr(pos, '\0'); assert(next); done = 1; } s = string_copy_sn(pos, next - pos); vec_add(v, s); pos = next + 1; } return v; }
/* For several overloaded builtins the argument lists do not match exactly the signature of a low-level builtin. This function adjusts the argument list ARGLIST for the overloaded builtin OB_FCODE to the signature of the low-level builtin given by DECL. */ static void s390_adjust_builtin_arglist (unsigned int ob_fcode, tree decl, vec<tree, va_gc> **arglist) { tree arg_chain; int src_arg_index, dest_arg_index; vec<tree, va_gc> *folded_args = NULL; /* We at most add one more operand to the list. */ vec_alloc (folded_args, (*arglist)->allocated () + 1); for (arg_chain = TYPE_ARG_TYPES (TREE_TYPE (decl)), src_arg_index = 0, dest_arg_index = 0; !VOID_TYPE_P (TREE_VALUE (arg_chain)); arg_chain = TREE_CHAIN (arg_chain), dest_arg_index++) { bool arg_assigned_p = false; switch (ob_fcode) { /* For all these the low level builtin needs an additional flags parameter. */ case S390_OVERLOADED_BUILTIN_s390_vec_find_any_eq_idx: case S390_OVERLOADED_BUILTIN_s390_vec_find_any_ne_idx: case S390_OVERLOADED_BUILTIN_s390_vec_find_any_eq_or_0_idx: case S390_OVERLOADED_BUILTIN_s390_vec_find_any_ne_or_0_idx: case S390_OVERLOADED_BUILTIN_s390_vec_find_any_eq: case S390_OVERLOADED_BUILTIN_s390_vec_find_any_ne: case S390_OVERLOADED_BUILTIN_s390_vec_find_any_eq_idx_cc: case S390_OVERLOADED_BUILTIN_s390_vec_find_any_ne_idx_cc: case S390_OVERLOADED_BUILTIN_s390_vec_find_any_eq_or_0_idx_cc: case S390_OVERLOADED_BUILTIN_s390_vec_find_any_ne_or_0_idx_cc: case S390_OVERLOADED_BUILTIN_s390_vec_find_any_eq_cc: case S390_OVERLOADED_BUILTIN_s390_vec_find_any_ne_cc: if (dest_arg_index == 2) { folded_args->quick_push (build_int_cst (integer_type_node, s390_get_vstring_flags (ob_fcode))); arg_assigned_p = true; } break; case S390_OVERLOADED_BUILTIN_s390_vec_cmprg_idx: case S390_OVERLOADED_BUILTIN_s390_vec_cmpnrg_idx: case S390_OVERLOADED_BUILTIN_s390_vec_cmprg_or_0_idx: case S390_OVERLOADED_BUILTIN_s390_vec_cmpnrg_or_0_idx: case S390_OVERLOADED_BUILTIN_s390_vec_cmprg: case S390_OVERLOADED_BUILTIN_s390_vec_cmpnrg: case S390_OVERLOADED_BUILTIN_s390_vec_cmprg_idx_cc: case S390_OVERLOADED_BUILTIN_s390_vec_cmpnrg_idx_cc: case S390_OVERLOADED_BUILTIN_s390_vec_cmprg_or_0_idx_cc: case S390_OVERLOADED_BUILTIN_s390_vec_cmpnrg_or_0_idx_cc: case S390_OVERLOADED_BUILTIN_s390_vec_cmprg_cc: case S390_OVERLOADED_BUILTIN_s390_vec_cmpnrg_cc: if (dest_arg_index == 3) { folded_args->quick_push (build_int_cst (integer_type_node, s390_get_vstring_flags (ob_fcode))); arg_assigned_p = true; } break; case S390_OVERLOADED_BUILTIN_s390_vec_sel: case S390_OVERLOADED_BUILTIN_s390_vec_insert: case S390_OVERLOADED_BUILTIN_s390_vec_load_len: /* Swap the first to arguments. It is better to do it here instead of the header file to avoid operand checking throwing error messages for a weird operand index. */ if (dest_arg_index < 2) { folded_args->quick_push (fully_fold_convert (TREE_VALUE (arg_chain), (**arglist)[1 - dest_arg_index])); src_arg_index++; arg_assigned_p = true; } break; case S390_OVERLOADED_BUILTIN_s390_vec_store_len: if (dest_arg_index == 1 || dest_arg_index == 2) { folded_args->quick_push (fully_fold_convert (TREE_VALUE (arg_chain), (**arglist)[3 - dest_arg_index])); src_arg_index++; arg_assigned_p = true; } break; case S390_OVERLOADED_BUILTIN_s390_vec_load_bndry: { int code; if (dest_arg_index == 1) { switch (tree_to_uhwi ((**arglist)[src_arg_index])) { case 64: code = 0; break; case 128: code = 1; break; case 256: code = 2; break; case 512: code = 3; break; case 1024: code = 4; break; case 2048: code = 5; break; case 4096: code = 6; break; default: error ("valid values for builtin %qF argument %d are 64, " "128, 256, 512, 1024, 2048, and 4096", decl, src_arg_index + 1); return; } folded_args->quick_push (build_int_cst (integer_type_node, code)); src_arg_index++; arg_assigned_p = true; } } break; case S390_OVERLOADED_BUILTIN_s390_vec_rl_mask: /* Duplicate the first src arg. */ if (dest_arg_index == 0) { folded_args->quick_push (fully_fold_convert (TREE_VALUE (arg_chain), (**arglist)[src_arg_index])); arg_assigned_p = true; } break; default: break; } if (!arg_assigned_p) { folded_args->quick_push (fully_fold_convert (TREE_VALUE (arg_chain), (**arglist)[src_arg_index])); src_arg_index++; } } *arglist = folded_args; }
/*Command line entry point of the program*/ int main (int argc, char* argv[]){ /*getopt() variables */ int opt; char* optarg_dup = NULL; /*Command line options*/ uchar cflg=0,gflg=0,kflg=0,lflg=0,mflg=0,oflg=0, sflg=0; uchar pflg=0,tflg=0,vflg=0,xflg=0,zflg=0; InputParams* inputParams = NULL; /*Working variables */ int i,m; int nbPriors; int nbNodes; int nbClass; int nbLabeled; int nbUnlabeled; int nbSimParams; int actualWlen; int start_cpu,stop_cpu; real tmp; uchar* absorbing = NULL; char* labels = NULL; char* featLabels = NULL; char* targets = NULL; char* preds = NULL; int** classes = NULL; real** N = NULL; real* gram = NULL; real** latF = NULL; real** latB = NULL; real** kernel = NULL; SparseMatrix* spmat = NULL; SparseMatrix* dataset = NULL; DataStat* graphStat = NULL; DataStat* featuresStat = NULL; DWInfo* dwInfo = NULL; OptiLen* optiLen = NULL; PerfMeasures* unlabeledPerf = NULL; LSVMDataInfo* dataInfo = NULL; /*Print the program banner*/ printBanner(); /*Scan the command line*/ inputParams = malloc(sizeof(InputParams)); init_InputParams(inputParams); while ((opt = getopt(argc,argv,"c:g:l:xms:k:o:p:rt:v:z:h")) != EOF){ switch(opt){ case 'c': cflg++; inputParams->nbFolds = atoi(optarg); break; case 'g': gflg++; inputParams->graphFname = (char*)malloc(FNAME_LEN*sizeof(char)); strncpy(inputParams->graphFname,optarg,FNAME_LEN); break; case 'k': kflg++; inputParams->gramFname = (char*)malloc(FNAME_LEN*sizeof(char)); strncpy(inputParams->gramFname,optarg,FNAME_LEN); break; case 's': sflg++; optarg_dup = (char*)__strdup(optarg); nbSimParams = getNbTokens(optarg,","); inputParams->simParams = vec_alloc(nbSimParams+1); tokenizeReals(optarg_dup,",",inputParams->simParams); break; case 'l': lflg++; inputParams->wlen = atoi(optarg); break; case 'm': mflg++; break; case 'o': oflg++; inputParams->outFname = (char*)malloc(FNAME_LEN*sizeof(char)); strncpy(inputParams->outFname,optarg,FNAME_LEN); inputParams->outPRED = (char*)malloc(FNAME_LEN*sizeof(char)); inputParams->outLEN = (char*)malloc(FNAME_LEN*sizeof(char)); addExtension(inputParams->outFname,"pred",inputParams->outPRED); addExtension(inputParams->outFname,"len",inputParams->outLEN); break; case 'p': pflg++; optarg_dup = (char*)__strdup(optarg); nbPriors = getNbTokens(optarg,"#"); inputParams->priors = vec_alloc(nbPriors+1); tokenizeReals(optarg_dup,"#",inputParams->priors); break; case 't': tflg++; inputParams->tarFname = (char*)malloc(FNAME_LEN*sizeof(char)); strncpy(inputParams->tarFname,optarg,FNAME_LEN); break; case 'v': vflg++; inputParams->verbose = atoi(optarg); break; case 'x': xflg++; inputParams->crossWalks = 1; break; case 'z': zflg++; inputParams->cvSeed = atoi(optarg); break; case 'h': printHelp(); exit(EXIT_FAILURE); break; } } /*Check mandatory arguments*/ if(!gflg || !lflg || (!oflg && !mflg)){ fprintf(stderr,"Mandatory argument(s) missing\n"); printHelp(); exit(EXIT_FAILURE); } if( (kflg && !sflg) || (!kflg && sflg)){ fprintf(stderr, "Error with 'k' and 's' parameters\n"); printHelp(); exit(EXIT_FAILURE); } /*Check that the walk length is greater than 2*/ if(inputParams->wlen < 2){ fprintf(stderr,"The walkLen must be >= 2\n"); exit(EXIT_FAILURE); } /*Check that there are the right number of similarity parameters*/ if (kflg && sflg){ if(inputParams->simParams){ switch((int)inputParams->simParams[1]){ case 1 : if((int)inputParams->simParams[0] != 1){ fprintf(stderr,"The similarity type 1 must have no parameters\n"); exit(EXIT_FAILURE); } break; case 2 : if((int)inputParams->simParams[0] != 2){ fprintf(stderr,"The similarity type 2 must have exactly 1 parameter\n"); exit(EXIT_FAILURE); } break; case 3 : if((int)inputParams->simParams[0] != 4){ fprintf(stderr,"The similarity type 3 must have exactly 3 parameters\n"); exit(EXIT_FAILURE); } break; case 4 : if((int)inputParams->simParams[0] != 2){ fprintf(stderr,"The similarity type 4 must have exactly 1 parameter\n"); exit(EXIT_FAILURE); } break; default : fprintf(stderr,"Unrecognized similarity type\n"); exit(EXIT_FAILURE); } } } /*Get the number of nodes in the graph*/ nbNodes = readNbNodes(inputParams->graphFname); /*Get the number of distinct classes*/ nbClass = readNbClass(inputParams->graphFname); /*Get info from the LIBSVM data*/ if (kflg){ dataInfo = malloc(sizeof(LSVMDataInfo)); getLSVMDataInfo(inputParams->gramFname,dataInfo); dataset = spmat_alloc(dataInfo->nbLines,dataInfo->nbFeatures,0); init_SparseMat(dataset); featuresStat = DataStat_alloc(dataInfo->nbClass); featLabels = char_vec_alloc(nbNodes); } /*Check if the number of nodes does not exceed the limitation*/ if(nbNodes > MAX_NODES){ fprintf(stderr,"This version is limited to maximum %i nodes\n",MAX_NODES); exit(EXIT_FAILURE); } /*Check that the number of classes is lower than 128*/ if(nbClass > 127){ fprintf(stderr,"The number of classes must be <= 127\n"); exit(EXIT_FAILURE); } /*Check that the number of folds is between 2 and nbNodes*/ if(cflg){ if(inputParams->nbFolds == 1 || inputParams->nbFolds > nbNodes){ fprintf(stderr,"The number of folds must be > 1 and <= number of nodes\n"); exit(EXIT_FAILURE); } } /*Allocate data structure*/ latF = mat_alloc(inputParams->wlen+1,nbNodes); latB = mat_alloc(inputParams->wlen+1,nbNodes); kernel = mat_alloc(nbNodes, nbNodes); classes = (int**)malloc(sizeof(int*)*(nbClass+1)); labels = char_vec_alloc(nbNodes); absorbing = uchar_vec_alloc(nbNodes); if(kflg) gram = vec_alloc((nbNodes*(nbNodes+1))/2); dwInfo = malloc(sizeof(DWInfo)); dwInfo->mass_abs = vec_alloc(nbClass); spmat = spmat_alloc(nbNodes,nbNodes,1); graphStat = DataStat_alloc(nbClass+1); optiLen = malloc(sizeof(OptiLen)); /*Initialize the sparse transition matrix and the dataset if required*/ init_SparseMat(spmat); /*Read the adjacency matrix*/ readMat(inputParams->graphFname,spmat,labels,graphStat,inputParams->verbose); isSymmetric(spmat); /*Get the indices of the nodes in each class */ getClasses(labels,nbNodes,classes,nbClass); /*Get the number of labeled nodes*/ nbUnlabeled = classes[0][0]; nbLabeled = nbNodes - nbUnlabeled; /*If provided, check that the priors match the number of classes*/ if(pflg){ if(nbClass != nbPriors){ printf("The number of priors does not match with the number of classes\n"); exit(EXIT_FAILURE); } /*Check that the priors sum up to 1*/ else{ tmp=0.0; for(i=1;i<=inputParams->priors[0];i++){ tmp += inputParams->priors[i]; } if(ABS(tmp-1.0) > PROB_EPS){ textcolor(BRIGHT,RED,BLACK); printf("WARNING: The class priors do not sum up to 1\n"); textcolor(RESET,WHITE,BLACK); } } } /*If no priors provided, use empirical priors */ else{ inputParams->priors = vec_alloc(nbClass+1); inputParams->priors[0] = (real)nbClass; tmp = 0.0; for(i=1;i<=inputParams->priors[0];i++) tmp += graphStat->classCount[i]; for(i=1;i<=inputParams->priors[0];i++) inputParams->priors[i] = (real)graphStat->classCount[i]/tmp; } /*If provided read the LIBSVM feature matrix*/ if(kflg){ m = readLSVMData(inputParams->gramFname,dataInfo,dataset,featLabels,featuresStat,inputParams->verbose); if (dataInfo->nbLines != nbNodes){ fprintf(stderr,"Number of line on the LIBSVM (%i) file doesn't match the number of nodes (%i)\n", dataInfo->nbLines, nbNodes); exit(EXIT_FAILURE); } /* Multiply a kernel matrix based on the dataset*/ /* TO DO : define a parameters to lower the importance of the features*/ buildKernel2(spmat, dataset, 0.1, inputParams); /*Multiply adjacency matrix*/ } /*Print statistics about the graph, classes, and run-mode*/ if (inputParams->verbose > 0) printInputInfo(spmat,graphStat,nbClass,inputParams); /*Minimum Covering Length mode*/ if (mflg){ computeMCL(spmat,absorbing,labels,classes,nbClass,latF,latB,inputParams); /*Exit after displaying the statistics*/ exit(EXIT_SUCCESS); } /*Start the CPU chronometer*/ start_cpu = clock(); /*If required tune the maximum walk length by cross-validation*/ if(cflg){ crossValidateLength(spmat,absorbing,labels,classes,nbClass,NULL,latF,latB,inputParams,optiLen); actualWlen = optiLen->len; } /*Otherwise use the prescribed length*/ else actualWlen = inputParams->wlen; /************************ALGORITHM STARTS HERE****************************/ if(inputParams->verbose >= 1){ textcolor(BRIGHT,RED,BLACK); printf("Performing discriminative walks up to length %i on full data\n",actualWlen); textcolor(RESET,WHITE,BLACK); } /*Allocate data structure*/ N = mat_alloc(nbUnlabeled,nbClass); preds = char_vec_alloc(nbUnlabeled); init_mat(N,nbUnlabeled,nbClass); /*Launch the D-walks*/ dwalk(spmat,absorbing,classes,nbClass,N,latF,latB,actualWlen,inputParams->crossWalks,dwInfo,inputParams->verbose); /************************ALGORITHM STOPS HERE****************************/ /*Stop the CPU chronometer*/ stop_cpu = clock(); /*Compute the predictions as the argmax on classes for each unlabeled node*/ computePredictions(N,preds,inputParams->priors,nbUnlabeled,nbClass); /*Write the model predictions*/ writePredictions_unlabeled(inputParams->outPRED,preds,N,nbClass,classes[0]); /*Write the class betweeness */ /*If a target file is provided compare predictions and targets*/ if(tflg){ unlabeledPerf = PerfMeasures_alloc(nbClass+1); computeUnlabeledPerf(preds,classes[0],nbUnlabeled,nbClass,inputParams,unlabeledPerf,inputParams->verbose); free_PerfMeasures(unlabeledPerf,nbClass+1); } /*Print informations*/ if (inputParams->verbose >= 1){ for(i=0;i<nbClass;i++) printf("Exploration rate in class %2i : %1.2f %%\n",i+1,100*dwInfo->mass_abs[i]); printf("CPU Time (sec) : %1.4f\n",((double)(stop_cpu - start_cpu)/CLOCKS_PER_SEC)); printLineDelim(); } /*Optionally release memory here*/ #ifdef FREE_MEMORY_AT_END free_classes(classes,nbClass+1); free_InputParams(inputParams); free_DataStat(graphStat); free_DWInfo(dwInfo); free(absorbing); free(labels); free_mat(N,nbUnlabeled); free_mat(latF,inputParams->wlen+1); free_mat(latB,inputParams->wlen+1); free_SparseMatrix(spmat); free(optiLen); free(preds); if(kflg) free(gram); #endif /*Exit successfully :-)*/ exit(EXIT_SUCCESS); }
tree ubsan_create_data (const char *name, const location_t *ploc, const struct ubsan_mismatch_data *mismatch, ...) { va_list args; tree ret, t; tree fields[5]; vec<tree, va_gc> *saved_args = NULL; size_t i = 0; location_t loc = UNKNOWN_LOCATION; /* Firstly, create a pointer to type descriptor type. */ tree td_type = ubsan_type_descriptor_type (); TYPE_READONLY (td_type) = 1; td_type = build_pointer_type (td_type); /* Create the structure type. */ ret = make_node (RECORD_TYPE); if (ploc != NULL) { loc = LOCATION_LOCUS (*ploc); fields[i] = build_decl (UNKNOWN_LOCATION, FIELD_DECL, NULL_TREE, ubsan_source_location_type ()); DECL_CONTEXT (fields[i]) = ret; i++; } va_start (args, mismatch); for (t = va_arg (args, tree); t != NULL_TREE; i++, t = va_arg (args, tree)) { gcc_checking_assert (i < 3); /* Save the tree arguments for later use. */ vec_safe_push (saved_args, t); fields[i] = build_decl (UNKNOWN_LOCATION, FIELD_DECL, NULL_TREE, td_type); DECL_CONTEXT (fields[i]) = ret; if (i) DECL_CHAIN (fields[i - 1]) = fields[i]; } va_end (args); if (mismatch != NULL) { /* We have to add two more decls. */ fields[i] = build_decl (UNKNOWN_LOCATION, FIELD_DECL, NULL_TREE, pointer_sized_int_node); DECL_CONTEXT (fields[i]) = ret; DECL_CHAIN (fields[i - 1]) = fields[i]; i++; fields[i] = build_decl (UNKNOWN_LOCATION, FIELD_DECL, NULL_TREE, unsigned_char_type_node); DECL_CONTEXT (fields[i]) = ret; DECL_CHAIN (fields[i - 1]) = fields[i]; i++; } TYPE_FIELDS (ret) = fields[0]; TYPE_NAME (ret) = get_identifier (name); layout_type (ret); /* Now, fill in the type. */ char tmp_name[32]; static unsigned int ubsan_var_id_num; ASM_GENERATE_INTERNAL_LABEL (tmp_name, "Lubsan_data", ubsan_var_id_num++); tree var = build_decl (UNKNOWN_LOCATION, VAR_DECL, get_identifier (tmp_name), ret); TREE_STATIC (var) = 1; TREE_PUBLIC (var) = 0; DECL_ARTIFICIAL (var) = 1; DECL_IGNORED_P (var) = 1; DECL_EXTERNAL (var) = 0; vec<constructor_elt, va_gc> *v; vec_alloc (v, i); tree ctor = build_constructor (ret, v); /* If desirable, set the __ubsan_source_location element. */ if (ploc != NULL) CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, ubsan_source_location (loc)); size_t nelts = vec_safe_length (saved_args); for (i = 0; i < nelts; i++) { t = (*saved_args)[i]; CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, t); } if (mismatch != NULL) { /* Append the pointer data. */ CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, mismatch->align); CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, mismatch->ckind); } TREE_CONSTANT (ctor) = 1; TREE_STATIC (ctor) = 1; DECL_INITIAL (var) = ctor; varpool_finalize_decl (var); return var; }
static tree handle_latent_entropy_attribute(tree *node, tree name, tree args __unused, int flags __unused, bool *no_add_attrs) { tree type; #if BUILDING_GCC_VERSION <= 4007 VEC(constructor_elt, gc) *vals; #else vec<constructor_elt, va_gc> *vals; #endif switch (TREE_CODE(*node)) { default: *no_add_attrs = true; error("%qE attribute only applies to functions and variables", name); break; case VAR_DECL: if (DECL_INITIAL(*node)) { *no_add_attrs = true; error("variable %qD with %qE attribute must not be initialized", *node, name); break; } if (!TREE_STATIC(*node)) { *no_add_attrs = true; error("variable %qD with %qE attribute must not be local", *node, name); break; } type = TREE_TYPE(*node); switch (TREE_CODE(type)) { default: *no_add_attrs = true; error("variable %qD with %qE attribute must be an integer or a fixed length integer array type or a fixed sized structure with integer fields", *node, name); break; case RECORD_TYPE: { tree fld, lst = TYPE_FIELDS(type); unsigned int nelt = 0; for (fld = lst; fld; nelt++, fld = TREE_CHAIN(fld)) { tree fieldtype; fieldtype = TREE_TYPE(fld); if (TREE_CODE(fieldtype) == INTEGER_TYPE) continue; *no_add_attrs = true; error("structure variable %qD with %qE attribute has a non-integer field %qE", *node, name, fld); break; } if (fld) break; #if BUILDING_GCC_VERSION <= 4007 vals = VEC_alloc(constructor_elt, gc, nelt); #else vec_alloc(vals, nelt); #endif for (fld = lst; fld; fld = TREE_CHAIN(fld)) { tree random_const, fld_t = TREE_TYPE(fld); random_const = tree_get_random_const(fld_t); CONSTRUCTOR_APPEND_ELT(vals, fld, random_const); } /* Initialize the fields with random constants */ DECL_INITIAL(*node) = build_constructor(type, vals); break; } /* Initialize the variable with a random constant */ case INTEGER_TYPE: DECL_INITIAL(*node) = tree_get_random_const(type); break; case ARRAY_TYPE: { tree elt_type, array_size, elt_size; unsigned int i, nelt; HOST_WIDE_INT array_size_int, elt_size_int; elt_type = TREE_TYPE(type); elt_size = TYPE_SIZE_UNIT(TREE_TYPE(type)); array_size = TYPE_SIZE_UNIT(type); if (TREE_CODE(elt_type) != INTEGER_TYPE || !array_size || TREE_CODE(array_size) != INTEGER_CST) { *no_add_attrs = true; error("array variable %qD with %qE attribute must be a fixed length integer array type", *node, name); break; } array_size_int = TREE_INT_CST_LOW(array_size); elt_size_int = TREE_INT_CST_LOW(elt_size); nelt = array_size_int / elt_size_int; #if BUILDING_GCC_VERSION <= 4007 vals = VEC_alloc(constructor_elt, gc, nelt); #else vec_alloc(vals, nelt); #endif for (i = 0; i < nelt; i++) { tree cst = size_int(i); tree rand_cst = tree_get_random_const(elt_type); CONSTRUCTOR_APPEND_ELT(vals, cst, rand_cst); } /* * Initialize the elements of the array with random * constants */ DECL_INITIAL(*node) = build_constructor(type, vals); break; } } break; case FUNCTION_DECL: break; } return NULL_TREE; }
static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs) { tree type; unsigned long long mask; #if BUILDING_GCC_VERSION <= 4007 VEC(constructor_elt, gc) *vals; #else vec<constructor_elt, va_gc> *vals; #endif switch (TREE_CODE(*node)) { default: *no_add_attrs = true; error("%qE attribute only applies to functions and variables", name); break; case VAR_DECL: if (DECL_INITIAL(*node)) { *no_add_attrs = true; error("variable %qD with %qE attribute must not be initialized", *node, name); break; } if (!TREE_STATIC(*node)) { *no_add_attrs = true; error("variable %qD with %qE attribute must not be local", *node, name); break; } type = TREE_TYPE(*node); switch (TREE_CODE(type)) { default: *no_add_attrs = true; error("variable %qD with %qE attribute must be an integer or a fixed length integer array type or a fixed sized structure with integer fields", *node, name); break; case RECORD_TYPE: { tree field; unsigned int nelt = 0; for (field = TYPE_FIELDS(type); field; nelt++, field = TREE_CHAIN(field)) { tree fieldtype; fieldtype = TREE_TYPE(field); if (TREE_CODE(fieldtype) != INTEGER_TYPE) { *no_add_attrs = true; error("structure variable %qD with %qE attribute has a non-integer field %qE", *node, name, field); break; } } if (field) break; #if BUILDING_GCC_VERSION <= 4007 vals = VEC_alloc(constructor_elt, gc, nelt); #else vec_alloc(vals, nelt); #endif for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) { tree fieldtype; fieldtype = TREE_TYPE(field); mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(fieldtype)) - 1); mask = 2 * (mask - 1) + 1; if (TYPE_UNSIGNED(fieldtype)) CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cstu(fieldtype, mask & get_random_const())); else CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cst(fieldtype, mask & get_random_const())); } DECL_INITIAL(*node) = build_constructor(type, vals); //debug_tree(DECL_INITIAL(*node)); break; } case INTEGER_TYPE: mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(type)) - 1); mask = 2 * (mask - 1) + 1; if (TYPE_UNSIGNED(type)) DECL_INITIAL(*node) = build_int_cstu(type, mask & get_random_const()); else DECL_INITIAL(*node) = build_int_cst(type, mask & get_random_const()); break; case ARRAY_TYPE: { tree elt_type, array_size, elt_size; unsigned int i, nelt; elt_type = TREE_TYPE(type); elt_size = TYPE_SIZE_UNIT(TREE_TYPE(type)); array_size = TYPE_SIZE_UNIT(type); if (TREE_CODE(elt_type) != INTEGER_TYPE || !array_size || TREE_CODE(array_size) != INTEGER_CST) { *no_add_attrs = true; error("array variable %qD with %qE attribute must be a fixed length integer array type", *node, name); break; } nelt = TREE_INT_CST_LOW(array_size) / TREE_INT_CST_LOW(elt_size); #if BUILDING_GCC_VERSION <= 4007 vals = VEC_alloc(constructor_elt, gc, nelt); #else vec_alloc(vals, nelt); #endif mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(elt_type)) - 1); mask = 2 * (mask - 1) + 1; for (i = 0; i < nelt; i++) if (TYPE_UNSIGNED(elt_type)) CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cstu(elt_type, mask & get_random_const())); else CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cst(elt_type, mask & get_random_const())); DECL_INITIAL(*node) = build_constructor(type, vals); //debug_tree(DECL_INITIAL(*node)); break; } } break; case FUNCTION_DECL: break; } return NULL_TREE; }
static void _spoil_table_aux(doc_ptr doc, cptr title, _obj_p pred, int options) { int i; vec_ptr entries = vec_alloc(free); int ct_std = 0, ct_rnd = 0, ct_ego = 0; int score_std = 0, score_rnd = 0, score_ego = 0; int max_score_std = 0, max_score_rnd = 0, max_score_ego = 0; if ((options & _SPOIL_ARTS) && !random_artifacts) { for (i = 1; i < max_a_idx; ++i) { object_type forge = {0}; _art_info_ptr entry; if (!p_ptr->wizard && (a_info[i].gen_flags & OFG_QUESTITEM)) continue; if (!create_named_art_aux(i, &forge)) continue; if ((options & _SPOIL_EGOS) && !a_info[i].found) continue; /* Hack */ if (pred && !pred(&forge)) continue; obj_identify_fully(&forge); entry = malloc(sizeof(_art_info_t)); entry->id = i; if (p_ptr->prace == RACE_ANDROID) { entry->score = android_obj_exp(&forge); if (!entry->score) entry->score = obj_value_real(&forge); } else entry->score = obj_value_real(&forge); object_desc(entry->name, &forge, OD_COLOR_CODED); entry->k_idx = forge.k_idx; vec_add(entries, entry); if (a_info[entry->id].found) { ct_std++; score_std += entry->score; if (entry->score > max_score_std) max_score_std = entry->score; } } } if (options & _SPOIL_RAND_ARTS) { vec_ptr v = stats_rand_arts(); for (i = 0; i < vec_length(v); i++) { object_type *o_ptr = vec_get(v, i); _art_info_ptr entry; if (pred && !pred(o_ptr)) continue; entry = malloc(sizeof(_art_info_t)); entry->id = ART_RANDOM; if (p_ptr->prace == RACE_ANDROID) { entry->score = android_obj_exp(o_ptr); if (!entry->score) entry->score = obj_value_real(o_ptr); } else entry->score = obj_value_real(o_ptr); object_desc(entry->name, o_ptr, OD_COLOR_CODED); entry->k_idx = o_ptr->k_idx; vec_add(entries, entry); ct_rnd++; score_rnd += entry->score; if (entry->score > max_score_rnd) max_score_rnd = entry->score; } } if (options & _SPOIL_EGOS) { vec_ptr v = stats_egos(); for (i = 0; i < vec_length(v); i++) { object_type *o_ptr = vec_get(v, i); _art_info_ptr entry; if (pred && !pred(o_ptr)) continue; entry = malloc(sizeof(_art_info_t)); entry->id = ART_EGO; if (p_ptr->prace == RACE_ANDROID) { entry->score = android_obj_exp(o_ptr); if (!entry->score) entry->score = obj_value_real(o_ptr); } else entry->score = obj_value_real(o_ptr); object_desc(entry->name, o_ptr, OD_COLOR_CODED); entry->k_idx = o_ptr->k_idx; vec_add(entries, entry); ct_ego++; score_ego += entry->score; if (entry->score > max_score_ego) max_score_ego = entry->score; } } if (vec_length(entries)) { vec_sort(entries, (vec_cmp_f)_art_score_cmp); doc_printf(doc, "<topic:%s><style:heading>%s</style>\n\n", title, title); doc_insert(doc, "<style:wide> <color:G> Score Lvl Rty Cts Object Description</color>\n"); for (i = 0; i < vec_length(entries); i++) { _art_info_ptr entry = vec_get(entries, i); if (entry->id == ART_RANDOM) { doc_printf(doc, "<color:v>%3d) %7d</color> %3d ", i+1, entry->score, k_info[entry->k_idx].counts.found); doc_printf(doc, "<indent><style:indent>%s</style></indent>\n", entry->name); } else if (entry->id == ART_EGO) { doc_printf(doc, "<color:B>%3d) %7d</color> %3d ", i+1, entry->score, k_info[entry->k_idx].counts.found); doc_printf(doc, "<indent><style:indent>%s</style></indent>\n", entry->name); } else { artifact_type *a_ptr = &a_info[entry->id]; doc_printf(doc, "<color:%c>%3d) %7d</color> %3d %3d ", (a_ptr->found) ? 'y' : 'w', i+1, entry->score, a_ptr->level, a_ptr->rarity); if (a_ptr->gen_flags & OFG_INSTA_ART) doc_insert(doc, " "); else doc_printf(doc, "%3d ", k_info[entry->k_idx].counts.found); doc_printf(doc, "<indent><style:indent>%s <color:D>#%d</color></style></indent>\n", entry->name, entry->id); } } if (ct_std || ct_rnd || ct_ego) { doc_printf(doc, "\n<color:G>%20.20s Ct Average Best</color>\n", ""); if (ct_std) { doc_printf(doc, "<color:B>%20.20s</color> %4d %7d %7d\n", "Stand Arts", ct_std, score_std/ct_std, max_score_std); } if (ct_rnd) { doc_printf(doc, "<color:B>%20.20s</color> %4d %7d %7d\n", "Rand Arts", ct_rnd, score_rnd/ct_rnd, max_score_rnd); } if (ct_ego) { doc_printf(doc, "<color:B>%20.20s</color> %4d %7d %7d\n", "Egos", ct_ego, score_ego/ct_ego, max_score_ego); } } doc_insert(doc, "</style>\n\n"); } vec_free(entries); }