Advertisement
Guest User

ForMerge

a guest
Jul 17th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.12 KB | None | 0 0
  1. CIRCUIT.H
  2. // Circuit getElemfromAll(const int& i);
  3. // int getCountElem(const int& i);
  4. // void setCountElement(const int& cont,const int& i);
  5. // string readFromFile(const string &circ_def/*,const int& skipped,const bool& isInst*/);
  6. // vector<Circuit> AllCircuits;
  7. //void setNewCircuit(const Circuit& circ);
  8. // void doTheComposit(const string& name_file);
  9. CIRCUIT.CPP
  10. /*void Circuit::setNewCircuit(const Circuit& circ){
  11. AllCircuits.push_back(circ);
  12. }
  13. Circuit Circuit::getElemfromAll(const int& i){
  14. return AllCircuits[i];
  15. }*/
  16. /*void Circuit::doTheComposit(const string& name_file){
  17. Circuit c1;
  18. string line_str;
  19. int line=0;
  20. int line_prec=0;
  21. int complete_count[7];
  22. for(int i=0; i<7; ++i){
  23. complete_count[i]=0;
  24. }
  25. do{
  26. Circuit c2;
  27. for(int i=0; i<7; ++i){
  28. c2.setCountElement(complete_count[i],i);
  29. }
  30. line_str=c2.readFromFile(name_file,line,false);
  31. //this read from file does not include the Instance,if u encounter "instance" the function returns the line where he started
  32. line=stoi(line_str);
  33. if(line==line_prec){
  34. for(int i=0; i<7; ++i){
  35. c1.setCountElement(complete_count[i],i);
  36. }
  37. line_str=c1.readFromFile(name_file,line,true);
  38. if(line_str!="ok"){
  39. Circuit tmp_circ;
  40. tmp_circ.setNewCircuit(c1);
  41. for (int i = 0; i < c1.AllCircuits.size(); ++i) {
  42. tmp_circ.setNewCircuit(c1.getElemfromAll(i));
  43. }
  44. c1=tmp_circ;
  45. }
  46. line=stoi(line_str);
  47. }else{
  48. c1.setNewCircuit(c2);
  49. }
  50. for(int i=0; i<7; ++i){
  51. complete_count[i]=complete_count[i]+c2.getCountElem(i);
  52. }
  53. line_prec=line;
  54. }while(line_str!="ok");//quando arrivi alla fine del file si ritorna "ok"
  55. //Il circuito c1 sara quello di cui effettuare la simulazione
  56. }*/
  57. /*int Circuit::getCountElem(const int& i){
  58. return _count_vect[i];
  59. }
  60. void Circuit::setCountElement(const int& cont,const int& i){
  61. _count_vect[i]=cont;
  62. }*/
  63. string Circuit::readFromFile(const string &circ_def/*,const int& skipped,const bool& isInst*/) {
  64. ifstream c_def;
  65. c_def.open(circ_def);
  66. // int cont=skipped;
  67. // COntrollo della validità del file
  68. if(!c_def.is_open()){
  69. return "Error occurred! Cannot open the File.";
  70. }
  71. else if(c_def.eof()){
  72. return "Error occurred! The file is empty.";
  73. }
  74.  
  75. // Lettura e caricamento dei parametri
  76. else if(c_def.good()){
  77. string line;
  78. /*size_t i = 0;
  79. while ( i++ < skipped){
  80. c_def.ignore(INT_MAX,'\n');
  81. }*/
  82. while(getline(c_def, line)) {
  83. bool isread=false;
  84. istringstream iss(line);
  85. string label, space, val;
  86. // cont++;
  87. do{
  88. iss >> label;
  89. /*if(label=="endmodule"){
  90. if(getline(c_def, line).eof()){
  91.  
  92. }else{
  93. cont++;
  94. c_def.close();
  95. stringstream ss;
  96. ss << cont;
  97. return ss.str();
  98. }
  99. }else*/ if(label=="module"){ // Setta il nome del circuito
  100. iss>>label;
  101. _name=label;
  102. }
  103. else if(label=="clk"){
  104. _isSeq=true;
  105. }
  106. else if(label == "input") {
  107. // Separa gli input con la virgola e aggiungili al vector per futuro controllo
  108. while(getline(iss,val,',')) {
  109. val.erase(remove(val.begin(), val.end(), ' '), val.end());
  110. if(val.find('[')!=string::npos){
  111. string name = val.substr(0, val.find('['));
  112. string index_str = val.substr(val.find('[')+1, val.find(']')-val.find('[')-1);
  113. int index = stoi(index_str);
  114. for(int i=0; i<index; ++i){
  115. _inputs.push_back(name+"["+to_string(i)+"]");
  116. }
  117. }
  118. else{
  119. _inputs.push_back(val);
  120. }
  121. }
  122. }
  123. else if(label=="output"){
  124.  
  125. // Separa gli output con la virgola e aggiungili al vector per futuro controllo
  126. while(getline(iss, val, ',')) {
  127. val.erase(remove(val.begin(), val.end(), ' '), val.end());
  128. if(val.find('[')!=string::npos){
  129. string name = val.substr(val.find('['));
  130. string index_str = val.substr(val.find('['), val.find(']')-val.find('['));
  131. int index = stoi(index_str);
  132. for(int i=0; i<index; ++i){
  133. _outputs.push_back(name+"["+to_string(i)+"]");
  134. }
  135. }
  136. else{
  137. _outputs.push_back(val);
  138. }
  139. }
  140. }
  141. else if(label.find("FF")!=string::npos){
  142. _FFs.push_back(label);
  143. string expr = line.substr(line.find(label), string::npos);
  144.  
  145. // Fai il parsing diretto dell'espressione con FF
  146. parseExpr(expr);
  147. isread=true;
  148. }
  149. else if(label=="assign") {
  150. string expr= line.substr(line.find(label)+label.size()+1);
  151.  
  152. // Fai il parsing diretto dell'espressione dell'output
  153. parseExpr(expr);
  154. isread=true;
  155. }
  156. else{
  157. iss.ignore();
  158. }
  159. }while (label!="endmodule" && !isread && iss);
  160. }
  161. }
  162. c_def.close();
  163. return "ok";
  164. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement