1 /*
2  * CCdlParserDriver.cc
3  *
4  * Copyright 2014-2018 D. Mitch Bailey  cvc at shuharisystem dot com
5  *
6  * This file is part of cvc.
7  *
8  * cvc is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * cvc is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with cvc.  If not, see <http://www.gnu.org/licenses/>.
20  *
21  * You can download cvc from https://github.com/d-m-bailey/cvc.git
22  */
23 
24 #include "CCdlParserDriver.hh"
25 #include "cdlParser.hh"
26 
27 
28 #include "CFixedText.hh"
29 
30 void yyset_in(FILE * in_str);
31 
32 
CCdlParserDriver()33 CCdlParserDriver::CCdlParserDriver() :
34 		trace_scanning(false), trace_parsing(false) {
35 	result = 0;
36 }
37 
~CCdlParserDriver()38 CCdlParserDriver::~CCdlParserDriver() {
39 }
40 
parse(const string & theCdlFilename,CCircuitPtrList & theCircuitPtrList,bool theCvcSOI)41 int CCdlParserDriver::parse(const string &theCdlFilename, CCircuitPtrList& theCircuitPtrList, bool theCvcSOI) {
42 	filename = theCdlFilename;
43 	ifstream myTestFile;
44 //	scan_begin();
45 	FILE * myCdlFile;
46 	if ( filename.substr(filename.length()-3, 3) == ".gz" && (myTestFile.open(filename), myTestFile.good()) ) {
47 		myTestFile.close();
48 		string myZcat = "zcat " + filename;
49 		myCdlFile = popen(myZcat.c_str(), "r");
50 	} else {
51 		myCdlFile = fopen(const_cast<const text_t>(filename.c_str()), "r");
52 	}
53 	int myParser_result;
54 	if (myCdlFile == NULL) {
55 		cout << "Could not open file " << filename << "\n";
56 		myParser_result = 1;
57 	} else {
58 		yyset_in(myCdlFile);
59 		yy::CCdlParser parser(*this, theCircuitPtrList, theCvcSOI);
60 		cout << endl;  // Clear progress output
61 		parser.set_debug_level(trace_parsing);
62 		myParser_result = parser.parse();
63 //	scan_end();
64 	}
65 	return myParser_result;
66 }
67 
error(const yy::location_type & theLocation,const string & theMessage)68 void CCdlParserDriver::error(const yy::location_type& theLocation, const string& theMessage) {
69 	cerr << theLocation << ": " << theMessage << endl;
70 }
71 
error(const string & theMessage)72 void CCdlParserDriver::error(const string& theMessage) {
73 	cerr << theMessage << endl;
74 }
75