1 /*
2 * Cvc.hh
3 *
4 * Copyright 2014-2020 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 #ifndef CVC_H_
25 #define CVC_H_
26
27 #define CVC_VERSION "1.1.0"
28
29 extern bool gDebug_cvc;
30 extern bool gSetup_cvc;
31 extern bool gInterrupted;
32 extern bool gInteractive_cvc;
33
34 // valid voltage globals
35 extern char vv_sign;
36 extern int vv_integer, vv_fraction;
37 extern char vv_suffix[], vv_trailer[];
38
39 #include "CvcTypes.hh"
40
41 #include <stddef.h>
42 #include <stdio.h>
43 #include <stdlib.h>
44 #include <bitset>
45 #include <cassert>
46 #include <cerrno>
47 #include <climits>
48 #include <cstdio>
49 #include <cstdlib>
50 #include <deque>
51 #include <exception>
52 #include <iostream>
53 #include <fstream>
54 #include <list>
55 #include <forward_list>
56 #include <map>
57 #include <cmath>
58 #include <memory>
59 #include <stdexcept>
60 #include <unordered_map>
61 #include <unordered_set>
62 #include <vector>
63 #include <iomanip>
64 #include <set>
65 #include <regex>
66
67 #include "sys/resource.h"
68
69 using namespace std;
70
71 typedef char * text_t;
72
73 #include "utility.h"
74 #include "CvcMaps.hh"
75 #include "CCvcExceptions.hh"
76 // #include "SFHash.hh"
77
78 // basic classes
79
80 template <class T>
ResetVector(T & theVector,uintmax_t theSize)81 void ResetVector (T& theVector, uintmax_t theSize) {
82 theVector.clear();
83 theVector.reserve(theSize);
84 theVector.resize(theSize);
85 }
86
87 template <class T>
ResetVector(T & theVector,uintmax_t theSize,uintmax_t theDefault)88 void ResetVector (T& theVector, uintmax_t theSize, uintmax_t theDefault) {
89 theVector.clear();
90 theVector.reserve(theSize);
91 theVector.resize(theSize, theDefault);
92 }
93
94 template <class T>
ResetVector(T & theVector,uintmax_t theSize,modelType_t theDefault)95 void ResetVector (T& theVector, uintmax_t theSize, modelType_t theDefault) {
96 theVector.clear();
97 theVector.reserve(theSize);
98 theVector.resize(theSize, theDefault);
99 }
100
101 template <class T>
ResetPointerVector(T & theVector,size_t theSize)102 void ResetPointerVector (T& theVector, size_t theSize) {
103 theVector.clear();
104 theVector.reserve(theSize);
105 theVector.resize(theSize, NULL);
106 }
107
108 template<typename KEY_T, typename TARGET_T>
DumpStatistics(unordered_map<KEY_T,TARGET_T> & theMap,string theTitle,ostream & theOutputFile)109 void DumpStatistics(unordered_map<KEY_T, TARGET_T> & theMap, string theTitle, ostream& theOutputFile) {
110 theOutputFile << "Hash dump:" << theTitle << endl;
111 unsigned myBucketCount = theMap.bucket_count();
112 unsigned myHashSize = theMap.size();
113 theOutputFile << "Contains " << myBucketCount << " buckets, " << myHashSize << " elements" << endl;
114 unsigned myElementCount = 0;
115 unsigned myMaxBucketSize = 0;
116 vector<int> myBucket_v;
117 myBucket_v.resize(50, 0);
118 for ( unsigned bucket_it = 0; bucket_it < myBucketCount; bucket_it++ ) {
119 myElementCount = theMap.bucket_size(bucket_it);
120 if ( myElementCount > myMaxBucketSize ) myMaxBucketSize = myElementCount;
121 if ( myElementCount > 49 ) myElementCount = 49;
122 myBucket_v[myElementCount] += 1;
123 }
124 int myDepthCount = 0;
125 for ( unsigned count_it = 0; count_it <= (unsigned) min((int) myMaxBucketSize, 49); count_it++ ) {
126 theOutputFile << "Element count " << count_it << ", " << myBucket_v[count_it] << endl;
127 myDepthCount += count_it * myBucket_v[count_it] * count_it;
128 }
129 int myLastPrecision = cout.precision();
130 theOutputFile.precision(2);
131 theOutputFile << fixed << "Unused hash: " << ((float) myBucket_v[0] / myBucketCount) << ", average depth " << ((float) myDepthCount / myHashSize) << endl;
132 theOutputFile.precision(myLastPrecision);
133 // cout << "Max element count " << myMaxBucketSize << endl;
134 }
135
136 class CTextVector : public vector<text_t> {
137 public:
138 };
139
140 class CFixedText;
141
142 class CTextList : public list<text_t> {
143 public:
144 text_t BiasNet(CFixedText & theCdlText);
145 };
146
147 #define DEFAULT_LOAD_FACTOR 2.0
148
149 class CTextResistanceMap : public unordered_map<text_t, resistance_t> {
150 public:
CTextResistanceMap(float theLoadFactor=DEFAULT_LOAD_FACTOR)151 CTextResistanceMap(float theLoadFactor = DEFAULT_LOAD_FACTOR) {max_load_factor(theLoadFactor);}
152 };
153
154 class CTextNetIdMap : public unordered_map<text_t, netId_t> {
155 public:
CTextNetIdMap(float theLoadFactor=DEFAULT_LOAD_FACTOR)156 CTextNetIdMap(float theLoadFactor = DEFAULT_LOAD_FACTOR) {max_load_factor(theLoadFactor);}
157 };
158
159 class CTextDeviceIdMap : public unordered_map<text_t, deviceId_t> {
160 public:
CTextDeviceIdMap(float theLoadFactor=DEFAULT_LOAD_FACTOR)161 CTextDeviceIdMap(float theLoadFactor = DEFAULT_LOAD_FACTOR) {max_load_factor(theLoadFactor);}
162 };
163
164 class CTextInstanceIdMap : public unordered_map<text_t, instanceId_t> {
165 public:
CTextInstanceIdMap(float theLoadFactor=DEFAULT_LOAD_FACTOR)166 CTextInstanceIdMap(float theLoadFactor = DEFAULT_LOAD_FACTOR) {max_load_factor(theLoadFactor);}
167 };
168
169 class CStringTextMap : public unordered_map<string, text_t> {
170 public:
CStringTextMap(float theLoadFactor=DEFAULT_LOAD_FACTOR)171 CStringTextMap(float theLoadFactor = DEFAULT_LOAD_FACTOR) {max_load_factor(theLoadFactor);}
172 };
173
174 class CNetIdVector : public vector<netId_t> {
175 public:
176 };
177
178 class CDeviceIdVector : public vector<deviceId_t> {
179 public:
180 };
181
182 class CInstanceIdVector : public vector<instanceId_t> {
183 public:
184 };
185
186 class CNetIdSet : public unordered_set<netId_t> {
187 public:
188 };
189
190 typedef bitset<8> CStatus;
191 extern CStatus PMOS_ONLY, NMOS_ONLY, NMOS_PMOS, NO_TYPE; //, MIN_CHECK_BITS, MAX_CHECK_BITS;
192
193 class CStatusVector : public vector<CStatus> {
194 public:
195 };
196
197 #define IGNORE_WARNINGS false
198 #define PRINT_WARNINGS true
199
200 #define toupper_(theString) for (size_t i=0; i<=theString.length(); i++) { theString[i]=toupper(theString[i]); }
201
202 class CNetList {
203
204 };
205
206 class CHierList {
207
208 };
209
210 class CStringList {
211
212 };
213
214 template<typename T1, typename T2>
215 T1 min(T1 a, T2 b) {return ((a < (T1)b) ? a : (T1) b);}
216 template<typename T1, typename T2>
217 T1 max(T1 a, T2 b) {return ((a > (T1)b) ? a : (T1) b);}
218
219 enum returnCode_t {UNKNOWN_RETURN_CODE=0, OK, SKIP, FAIL};
220
221 enum stage_t {STAGE_START = 1, STAGE_LINK, STAGE_RESISTANCE, STAGE_FIRST_MINMAX, STAGE_FIRST_SIM, STAGE_SECOND_SIM, STAGE_COMPLETE};
222
223 #endif /* CVC_H_ */
224