#include #include #include #include #include #include using std::iostream; using namespace std; int strtoint(string num); bool num(char num); int log2(int num); void ADD(int *inputs_v,int &carry_out,int C[],int size); void COMPARE(int *inputs,int size,int C[]); void MULTIPLY(int *inputs,int size,int C[]); void ogen_menu(); void igen_menu(); int main() { char cont; do{ system("cls"); char choice; cout << "\t\tEspresso I/O Generator v1.3\n"; cout << "Dept. of Computer Science & Engineering - University of California, Riverside\n"; cout << "programmed by Korey Sewell as part of of a research project assigned under Dr. Frank Vahid"; cout << "\n\nGenerate Inputs - I\nRead from Outputs - R\nQuit - Q?\nEnter Choice: "; cin >> choice; if(toupper(int(choice)) == 'I') igen_menu(); else if (toupper(int(choice)) == 'R') ogen_menu(); else if(toupper((int)choice) == 'Q') break; cout << "\n\nContinue ESPRESSO I/O GENERATOR?\n\n"; cin >> cont; }while(cont == 'y'); cout << "Program ended.\n"; return 0; } //ogen_menu(): Analyzes ESPRESSO output file void ogen_menu() { cout << "\nThe following program will do some basic analysis on the output of" << endl; cout << "some espresso files\n\n"; //Get Input string strFiles; bool details = true; bool cla = true; cout << "Enter the names of your output files separated by a single space\n"; string tmpString; while(1) { cin >> tmpString; if(strcmp(tmpString.c_str(),";") != 0) strFiles += " " + tmpString; else break; } //cin >> strFiles; cout << "The name: " << strFiles << endl; //getline(cin,strFiles,50); //Tokenize Input char *output_file[50]; int num_files=0; char *files = new char [strFiles.length()]; strcpy(files,strFiles.c_str()); char *tok = strtok(files," "); while(tok != NULL) { output_file[num_files] = tok; num_files++; tok = strtok(NULL," "); } output_file[num_files] = NULL; //Create Output File string a_file; cout << "\nWhat name do you want to call the analysis file? \n"; //getline(cin,a_file); while(1) { cin >> tmpString; a_file += tmpString; break; } ofstream outfile(a_file.c_str(),ios::out); if(!outfile) { cout << "Error creating analysis file.\n"; } //Analyze Each File for(int i=0;i (Num Tokens - 2) Equal The # of Outputs in a ESPRESSO FILE char *line3 = new char[line.length()]; strcpy(line3,line.c_str()); char *output_names[50]; char *l3_tok = strtok(line3," "); int token_count = 0; while(l3_tok != NULL) { output_names[token_count] = l3_tok; token_count++; l3_tok = strtok(NULL," "); } output_names[token_count] = NULL; getline(infile,line); //Finally, Read Line 3 //cout << line << endl; //getline(infile,line); //Finally, Read Line 3 //cout << line << endl; //getline(infile,line); //Finally, Read Line 3 //cout << line << endl; //Tokenize Line 3 => (Num Tokens - 2) Equal The # of Outputs in a ESPRESSO FILE char *line4 = new char[line.length()]; strcpy(line4,line.c_str()); char *in_out_nums[50]; char *l4_tok = strtok(line4," "); token_count = 0; while(l4_tok != NULL) { in_out_nums[token_count] = l4_tok; token_count++; l4_tok = strtok(NULL," "); } in_out_nums[token_count] = NULL; int num_ins = strtoint(in_out_nums[5]); int num_outs = strtoint(in_out_nums[8]); //Eliminates ".olb" and extra increment from count char *output_stats[50]; int *and_gate_inputs = new int [num_outs]; //MAX inputs for each minimized AND gate int *or_gate_inputs= new int [num_outs]; //MAX inputs for each minimized OR gate int omax_and_inputs = 0; //Overall MAX and inputs. (Useful to //determine critical path) string tnum_and_gates; double max_delay = 0; for(int m=0;m " << outputNUM << " " << and_gate_inputs[outputNUM] << " incrementing\n"; } outputNUM++; } //cout << "-> " << max_AND_inputs << endl; } if(omax_and_inputs < max_AND_inputs) //Update OVERALL MAX "AND GATE" inputs omax_and_inputs = max_AND_inputs; }while(getline(infile,line)); int y,statcount; if(details) { cout << "\n----------- DETAILS -----------\n"; cout << "*** The Maximum # of Inputs Table per Output w/Gate Delay ***\n"; cout << "Name" << "\t"; cout << "AND " << "\t"; cout << "OR "<< "\t"; cout << "Gate Delay" << endl; for(y=0;y> type_inputs; if(type_inputs == 1) adder = true; if(type_inputs == 2) comparator = true; if(type_inputs == 3) multiplier = true; if(type_inputs == 4) cla = true; cout << "Enter The Size (in bits) of the Component (q-quit): "; cin >> input_size; size = input_size - 48; if(adder) espresso_file = "a_"; if(multiplier) espresso_file = "m_"; if(comparator) espresso_file = "c_"; if(cla) espresso_file = "cl_"; espresso_file += input_size; ofstream e_file(espresso_file.c_str(),ios::out); if(!e_file) cout << "File couldn't be created\n"; else cout << "Input File: " << espresso_file << " is created: \n"; cout << "Output make take awhile.\n"; int inputs; if(cla) inputs = size * 4; else inputs = size * 2; int *inputs_v = new int[inputs]; int *SUM = new int[size]; int rows = pow((double)2,(double)size+size); //Write # of Inputs e_file << ".i " << inputs << endl; //Write # of Outputs if(comparator) e_file << ".o 3" << endl; else if(multiplier) e_file << ".o " << inputs << endl; else if(adder || cla) e_file << ".o " << size+1 << endl; //Write Names of Inputs e_file << ".ilb "; int b_count=0; int g_count=0; if(cla) { int loopi = size * 2; for(int i=0;i(loopi/2)-1) { e_file << "B"; e_file << b_count++; } else { e_file << "A"; e_file << i; } e_file << " "; } for(i=0;i(loopi/2)-1) { e_file << "P"; e_file << g_count++; } else { e_file << "G"; e_file << i; } e_file << " "; } } else { for(int i=0;i(inputs/2)-1) { e_file << "B"; e_file << b_count++; } else { e_file << "A"; e_file << i; } e_file << " "; } } //Write Names of Outputs e_file << "\n.olb "; if(adder || cla) { for(int j=0;j=0;j--) { double test = pow((double)2,(double)j); if(test > row_value2) { row_table[spot] = 0; } else { row_table[spot] = 1; row_value2 -= test; } e_file << row_table[spot]; spot++; } spot = 0; for(j=size-1;j>=0;j--) { e_file << (row_table[spot] && row_table[spot+size]); spot++; } spot = 0; for(j=size-1;j>=0;j--) { e_file << (row_table[spot] || row_table[spot+size]); spot++; } e_file << " "; } else { for(int j=inputs-1;j>=0;j--) { double test = pow((double)2,(double)j); if(test > row_value2) { row_table[spot] = 0; } else { row_table[spot] = 1; row_value2 -= test; } e_file << row_table[spot]; spot++; } e_file << " "; } if(adder == 1) { ADD(row_table,carry_out,SUM,inputs); for(int m=0;m 1) { temp = temp / 2; levels++; } retvalue = levels; } else { int levels = 0; int temp = num; while(temp != 1) { temp = temp / 2; levels++; } retvalue = levels + 1; } return retvalue; } bool num(char num) { switch(num) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case '-': return true; break; default: return false; } } void COMPARE(int *inputs,int size,int C[]) { int bsum,asum,power,b_count; b_count = bsum = asum = power = 0; int *A = new int[size/2]; int *B = new int[size/2]; for(int j=0;j ((size/2)-1)) { B[b_count] = inputs[j]; b_count++; } else A[j] = inputs[j]; } for(int i=(size/2)-1;i>=0;i--) { if(A[i] == 1) asum += pow(2,power); if(B[i] == 1) bsum += pow(2,power); power++; } C[0] = (asum < bsum); C[1] = (asum > bsum); C[2] = (asum == bsum); } void MULTIPLY(int *inputs,int size,int C[]) { int bsum,asum,power,b_count; b_count = bsum = asum = power = 0; int *A = new int[size/2]; int *B = new int[size/2]; for(int j=0;j ((size/2)-1)) { B[b_count] = inputs[j]; b_count++; } else A[j] = inputs[j]; } for(int i=(size/2)-1;i>=0;i--) { if(A[i] == 1) asum += pow(2,power); if(B[i] == 1) bsum += pow(2,power); power++; } int temp = asum * bsum; int spot = 0; for(int k=size-1;k>=0;k--) { double test = pow((double)2,(double)k); if(test > temp) { C[spot] = 0; } else { C[spot] = 1; temp -= test; } spot++; } } void ADD(int *inputs,int &carry_out,int C[],int size) { int *A = new int[size/2]; int *B = new int[size/2]; int b_count=0; for(int j=0;j ((size/2)-1)) { B[b_count] = inputs[j]; b_count++; } else A[j] = inputs[j]; } int cin = 0; for(int i=(size/2)-1;i>=0;i--) { if((cin == 0) && (A[i] == 0) && (B[i] == 0)) { C[i] = 0; cin = 0; } else if((cin == 0) && (A[i] == 0) && (B[i] == 1)) { C[i] = 1; cin = 0; } else if((cin == 0) && (A[i] == 1) && (B[i] == 0)) { C[i] = 1; cin = 0; } else if((cin == 0) && (A[i] == 1) && (B[i] == 1)) { C[i] = 0; cin = 1; } else if((cin == 1) && (A[i] == 0) && (B[i] == 0)) { C[i] = 1; cin = 0; } else if((cin == 1) && (A[i] == 0) && (B[i] == 1)) { C[i] = 0; cin = 1; } else if((cin == 1) && (A[i] == 1) && (B[i] == 0)) { C[i] = 0; cin = 1; } else if((cin == 1) && (A[i] == 1) && (B[i] == 1)) { C[i] = 1; cin = 1; } } carry_out = cin; }