void Builder::irgen(File* file) { // Generates code for all basic blocks using the Jogo intermediate // represenation. Also performs optimizations, if enabled by the // environment options. Machine::Ptr machine = Machine::intel64(); IrGenerator::Ptr bgen(new IrGenerator(env_, machine)); RegisterAllocator::Ptr alloc(new RegisterAllocator(env_, machine)); IrBlockPrinter::Ptr bprint(new IrBlockPrinter(env_, machine)); Stream::Ptr out = Stream::stout(); out->machine(machine); bprint->out(out); bgen->operator()(file); if (env_->dump_ir() && env_->verbose()) { bprint->operator()(file); } if (env_->optimize()) { CopyPropagator::Ptr copy(new CopyPropagator(env_, machine)); DeadCodeEliminator::Ptr elim(new DeadCodeEliminator(env_, machine)); copy->operator()(file); elim->operator()(file); } if (env_->dump_ir() && env_->verbose()) { bprint->operator()(file); } alloc->operator()(file); DeadCodeEliminator::Ptr elim(new DeadCodeEliminator(env_, machine)); elim->operator()(file); if (env_->dump_ir()) { bprint->operator()(file); } }
void pref(char prefi[78],char exp[78]) { struct stack st1; struct stack st2; struct stack st3; int cn=0; int i, apil=0; st1.top=0; st2.top=0; st3.top=0; lim(&st1); exp[0]='\0'; for(i=strlen(prefi)-1;i>=0;i--) { if( oper(prefi[i])) ins(&st2,prefi[i]); else { ins(&st1,prefi[i]); cn++; } if (cn==2) { vaciar(&st1,&st3); ins(&st3,elim(&st2,st2.pila[st2.top])); cn=0; } } //mostrarmul(&st1,&st2,&st3); copytexp(&st2,exp); copytexp(&st1,exp); copytexp(&st3,exp); }
Elimination find_elim(int size, float ** adj_mat, int ** order, int max_neighbors){ int i, j; word w, value; Map * adj_list; Elimination e; Neighborhood * partial_order; Map node_map; node_map = create_Map(size * size, ptr_compare, hash_ptr, empty(), 2); if(size == 0 || adj_mat == (float **) NULL){ return (Elimination) NULL; } if(max_neighbors <= 0){ max_neighbors = size; } adj_list = (Map *) malloc(sizeof(Map) * size); for(i = 0; i < size; i++){ adj_list[i] = create_Map(max_neighbors, compare, hash_int, empty(), 1); } for(i = 0; i < size; i++){ for(j = 0; j < size; j++){ if(adj_mat[i][j] > 0){ w.i = j; value.v = create_Node(w.i, adj_mat[i][j]); put(node_map, value, value); put(adj_list[i], w, value); } } w.i = i; } partial_order = (Neighborhood *) malloc(sizeof(Neighborhood) * size); for(i = 0; i < size; i++){ partial_order[i] = create_Neighborhood(max_neighbors); } if(order){ for(i = 0; i < size; i++){ for(j = 0; j < size; j++){ if(order[i][j] > 0){ add_edge(partial_order, i, j); } } } } e = elim(size, adj_list, partial_order, node_map); for(i = 0; i < size; i++){ destroy_Map(adj_list[i]); } free(adj_list); for(i = 0; i < size; i++){ destroy_Neighborhood(partial_order[i]); } free(partial_order); return e; }
void copytexp(struct stack * pil, char *exp) { char d, mat[2]; mat[1]='\0'; do { if(pil->top!=0) { d=elim(pil,pil->pila[pil->top]); mat[0]=d; strcat(exp,mat); strcat(exp," "); } else break; }while(pil->top!=0); }
int Gauss(double *matrix, int n, double *soln) { int pivot=0; unsigned short error=0; while ((pivot<(n-1)) && (!error)) { if(!(error = order(matrix,n,pivot))) { elim(matrix,n,pivot); pivot++; } } if (error) { return 1; } else { backsb(matrix, n, soln); } return 0; }
int main(int argc, char *argv[]) { int opt; // default values int l = 2000, m = 2000, t=1, bs=0, c=0; // biggest prime < 2^16 /* // no arguments given */ if(argc == 1) { //fprintf(stderr, "This program needs arguments....\n\n"); //print_help(1); } while((opt = getopt(argc, argv, "hl:m:t:b:c")) != -1) { switch(opt) { case 'h': print_help(0); break; case 'l': l = atoi(strdup(optarg)); break; case 'm': m = atoi(strdup(optarg)); break; case 't': t = atoi(strdup(optarg)); break; case 'b': bs = atoi(strdup(optarg)); break; case 'c': c = 1; break; } } if (c) elim_co(l,m,t,bs); else elim(l,m,t,bs); return 0; }
void place_support () { int i, j; int from_trans = 1; ROWP cp, cp2; struct matrix * rp, * nrp, * prp; #ifdef DEBUG fprintf(stderr," Start of place_support\n"); #endif for ( j = 0 ; j++ < trans_num ; ) { #ifdef DEBUG { ROWP cp; struct matrix * rp; int i, j; printf("\nMATRIX\n"); for ( rp = mat; rp != NULL ; rp = rp->next ) { for ( i = 0, j = *(cp = rp->rowp), cp++ ; i++ < place_num ; ) if ( (j>0) && (i == (int)(*cp)) ) { j--; cp++; printf(" %2d",(int)*(cp++) ); } else printf(" 0"); for ( i = 0 ; i++ < trans_num ; ) if ( (i == (int)(*cp)) ) { cp++; printf(" %2d",(int)*(cp++) ); } else printf(" 0"); printf("\n"); } } #endif { int ii, ntr=0; ROWP cp; struct matrix * rp; int * ip; for ( ii=trans_num+1, ip=poss_trans ; ii-- ; *(ip++) = FALSE ); for ( rp = mat; rp != NULL ; rp = rp->next ) { for ( i = *(cp = rp->rowp), cp++ ; i-- && *cp <= testplace ; cp += 2 ) if ( *cp == testplace ) { i = 0; ii = *(cp = rp->rowp); cp += (2 * ii + 1); while ( (ii = *cp) ) { cp += 2; ip = (poss_trans+ii); if ( !(*ip) && !(*(elim_trans+ii)) ) { #ifdef DEBUG printf("transition %d possible\n", ii ); #endif *ip = TRUE; ntr++; } } } } if ( ! ntr ) { #ifdef DEBUG fprintf(stderr," End of place_support\n"); #endif return; } } { int first, minval=0, mm, ii; int * ip, * it, * pp, * np; for ( first=TRUE, ii=from_trans, ip=(elim_trans+from_trans), it=(poss_trans+from_trans), pp=(n_pos+from_trans), np=(n_neg+from_trans); ii <= trans_num; ip++, it++, pp++, np++, ii++) if ( *it ) { while ( *ip ) { it++; ip++; pp++; np++; if ( ++ii > trans_num ) goto end_test; } mm = (*pp)*(*np) - (*pp) - (*np); if ( first ) { i = ii; minval = mm; first = FALSE; } else if ( mm < minval ) { i = ii; minval = mm; } } } end_test: elim_trans[i] = TRUE; if ( i == from_trans ) while ( elim_trans[from_trans] ) ++from_trans; #ifdef DEBUG printf("\neliminating transition #%d\n",i); #endif for ( prp = NULL, rp = mat ; rp != NULL ; rp = nrp ) { nrp = rp->next; cp2 = cp = (rp->rowp) + ( 2 * *(rp->rowp) + 1 ); while ( ((int)(*cp)<i) && ((int)(*cp)>0) ) cp += 2; if ( (int)(*cp) == i ) { /* TAKE THE ROW OUT FROM MATRIX LIST */ while ( (short)(*cp2) != (short)0 ) { if ( (short)(*(cp2+1)) > (short)0 ) --(n_pos[(int)(*cp2)]); else --(n_neg[(int)(*cp2)]); cp2 += 2; } if ( rp == mat ) mat = nrp; else prp->next = nrp; if ( (short)(*(++cp)) > (short)0 ) { rp->next = oldmp; oldmp = rp; } else { rp->next = oldmm; oldmm = rp; } } else prp = rp; } if ( oldmp != NULL && oldmm != NULL ) { while ( (rp = oldmp) != NULL ) { elim( (short)i ); oldmp = oldmp->next; destroy_mat( rp ); } } else while ( (rp = oldmp) != NULL ) { oldmp = oldmp->next; destroy_mat( rp ); } while ( (rp = oldmm) != NULL ) { oldmm = oldmm->next; destroy_mat( rp ); } } #ifdef DEBUG fprintf(stderr," End of place_support\n"); #endif }
void main() { clrscr(); char pwd[]="bigmanani"; char ans[20]; cout<<"Enter password : "******"*"; } else break; } if(strcmp(ans,pwd)) { cout<<"\nIncorrect password."; getch(); exit(0); } int op; clrscr(); fout<<"main\n"; ifstream fin("sdk.txt"); // cout<<"Enter the puzzle row-wise (Use 0's for empty spaces) :\n"; for(int i=0;i<=8;++i) for(int j=0;j<=8;++j) { fin>>space[i][j].value; if(space[i][j].value==0) { for(int k=1;k<=9;++k) space[i][j].poss[k]=1; } else { for(int k=1;k<=9;++k) { if(k!=space[i][j].value) space[i][j].poss[k]=0; else space[i][j].poss[k]=1; } } } cout<<"Puzzle accepted. Starting Evaluation.\n"; //getch(); for(int e=1;;++e) { fout<<"Starting Evaluation "<<e<<"\n"; // getch(); for(i=0;i<=8;++i) { for(j=0;j<=8;++j) { int nop=0; cell_one_pos(i,j); int the_poss_val=0; cout<<"Evaluating space "<<i<<" "<<j<<"\n"; //getch(); if(space[i][j].value!=0) // already filled { cout<<"space "<<i<<" "<<j<<" is already filled.\n";//getch(); continue; } else cout<<"space "<<i<<" "<<j<<" is empty\n";//getch(); for(int k=1;k<=9;++k) { cout<<"Trying value "<<k<<"\n"; //getch (); if(!in_col(j,k)&&!in_row(i,k)&&!in_box(i,j,k)) // check conds { nop++; cout<<k<<" is a possible value.\n"; //getch(); space[i][j].poss[k]=1; the_poss_val=k; } else if(in_col(j,k)||in_row(i,k)||in_box(i,j,k)) { space[i][j].poss[k]=0; cout<<k<<" is not a possible value\n"; // getch(); } } if(nop==1) { space[i][j].value=the_poss_val; cout<<i<<" "<<j<<" ="<<the_poss_val<<"\n";// getch(); boxes_filled++; for(int d=1;d<=9;d++) { if(d!=the_poss_val) space[i][j].poss[d]=0; } } } } elim(0,0);elim(0,3);elim(0,6); elim(3,0);elim(3,3);elim(3,6); elim(6,0);elim(6,3);elim(6,6); rem_lin_pos(1133);rem_lin_pos(4769); rem_lin_pos(1436);rem_lin_pos(7193); rem_lin_pos(1739);rem_lin_pos(7496); rem_lin_pos(4163);rem_lin_pos(7799); rem_lin_pos(4466); cout<<"\nEvaluation "<<e<<" finished. A total of "<<boxes_filled<<" spaces have now been filled.\n"; Menu : cout<<"\n1.View the puzzle solved this far.\n"; cout<<"2.Continue Evaluation.\n"; cout<<"3.View the possibilities of a space. [row col]\n"; cout<<"4.Exit Program.\n"; cout<<"6.Elimination\n"; cout<<"7.Set Value. [row col val]\n"; cout<<"Choose an Option : "; cin>>op; if(op==1) { for(i=0;i<=8;++i) { for(j=0;j<=8;++j) { //if(space[i][j].value!=0) cout<<" "<<space[i][j].value; /* else { cout<<" {"; for(int g=1;g<=9;++g) { if(space[i][j].poss[g]) cout<<g; } cout<<"}"; } */ } cout<<"\n"; } } if(op==2) { unfilled(); continue; } if(op==3) { int i,j; cin>>i>>j; cout<<"Possibilities are : "; for(int k=1;k<=9;++k) { if(space[i][j].poss[k]==1) cout<<k<<" "; } } if(op==4) exit(0); if(op==5) { cout<<"Enter BIN : "; int bin; cin>>bin; double_down(bin); }