Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CIRCUIT.H
- // Circuit getElemfromAll(const int& i);
- // int getCountElem(const int& i);
- // void setCountElement(const int& cont,const int& i);
- // string readFromFile(const string &circ_def/*,const int& skipped,const bool& isInst*/);
- // vector<Circuit> AllCircuits;
- //void setNewCircuit(const Circuit& circ);
- // void doTheComposit(const string& name_file);
- CIRCUIT.CPP
- /*void Circuit::setNewCircuit(const Circuit& circ){
- AllCircuits.push_back(circ);
- }
- Circuit Circuit::getElemfromAll(const int& i){
- return AllCircuits[i];
- }*/
- /*void Circuit::doTheComposit(const string& name_file){
- Circuit c1;
- string line_str;
- int line=0;
- int line_prec=0;
- int complete_count[7];
- for(int i=0; i<7; ++i){
- complete_count[i]=0;
- }
- do{
- Circuit c2;
- for(int i=0; i<7; ++i){
- c2.setCountElement(complete_count[i],i);
- }
- line_str=c2.readFromFile(name_file,line,false);
- //this read from file does not include the Instance,if u encounter "instance" the function returns the line where he started
- line=stoi(line_str);
- if(line==line_prec){
- for(int i=0; i<7; ++i){
- c1.setCountElement(complete_count[i],i);
- }
- line_str=c1.readFromFile(name_file,line,true);
- if(line_str!="ok"){
- Circuit tmp_circ;
- tmp_circ.setNewCircuit(c1);
- for (int i = 0; i < c1.AllCircuits.size(); ++i) {
- tmp_circ.setNewCircuit(c1.getElemfromAll(i));
- }
- c1=tmp_circ;
- }
- line=stoi(line_str);
- }else{
- c1.setNewCircuit(c2);
- }
- for(int i=0; i<7; ++i){
- complete_count[i]=complete_count[i]+c2.getCountElem(i);
- }
- line_prec=line;
- }while(line_str!="ok");//quando arrivi alla fine del file si ritorna "ok"
- //Il circuito c1 sara quello di cui effettuare la simulazione
- }*/
- /*int Circuit::getCountElem(const int& i){
- return _count_vect[i];
- }
- void Circuit::setCountElement(const int& cont,const int& i){
- _count_vect[i]=cont;
- }*/
- string Circuit::readFromFile(const string &circ_def/*,const int& skipped,const bool& isInst*/) {
- ifstream c_def;
- c_def.open(circ_def);
- // int cont=skipped;
- // COntrollo della validità del file
- if(!c_def.is_open()){
- return "Error occurred! Cannot open the File.";
- }
- else if(c_def.eof()){
- return "Error occurred! The file is empty.";
- }
- // Lettura e caricamento dei parametri
- else if(c_def.good()){
- string line;
- /*size_t i = 0;
- while ( i++ < skipped){
- c_def.ignore(INT_MAX,'\n');
- }*/
- while(getline(c_def, line)) {
- bool isread=false;
- istringstream iss(line);
- string label, space, val;
- // cont++;
- do{
- iss >> label;
- /*if(label=="endmodule"){
- if(getline(c_def, line).eof()){
- }else{
- cont++;
- c_def.close();
- stringstream ss;
- ss << cont;
- return ss.str();
- }
- }else*/ if(label=="module"){ // Setta il nome del circuito
- iss>>label;
- _name=label;
- }
- else if(label=="clk"){
- _isSeq=true;
- }
- else if(label == "input") {
- // Separa gli input con la virgola e aggiungili al vector per futuro controllo
- while(getline(iss,val,',')) {
- val.erase(remove(val.begin(), val.end(), ' '), val.end());
- if(val.find('[')!=string::npos){
- string name = val.substr(0, val.find('['));
- string index_str = val.substr(val.find('[')+1, val.find(']')-val.find('[')-1);
- int index = stoi(index_str);
- for(int i=0; i<index; ++i){
- _inputs.push_back(name+"["+to_string(i)+"]");
- }
- }
- else{
- _inputs.push_back(val);
- }
- }
- }
- else if(label=="output"){
- // Separa gli output con la virgola e aggiungili al vector per futuro controllo
- while(getline(iss, val, ',')) {
- val.erase(remove(val.begin(), val.end(), ' '), val.end());
- if(val.find('[')!=string::npos){
- string name = val.substr(val.find('['));
- string index_str = val.substr(val.find('['), val.find(']')-val.find('['));
- int index = stoi(index_str);
- for(int i=0; i<index; ++i){
- _outputs.push_back(name+"["+to_string(i)+"]");
- }
- }
- else{
- _outputs.push_back(val);
- }
- }
- }
- else if(label.find("FF")!=string::npos){
- _FFs.push_back(label);
- string expr = line.substr(line.find(label), string::npos);
- // Fai il parsing diretto dell'espressione con FF
- parseExpr(expr);
- isread=true;
- }
- else if(label=="assign") {
- string expr= line.substr(line.find(label)+label.size()+1);
- // Fai il parsing diretto dell'espressione dell'output
- parseExpr(expr);
- isread=true;
- }
- else{
- iss.ignore();
- }
- }while (label!="endmodule" && !isread && iss);
- }
- }
- c_def.close();
- return "ok";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement