@@ -69,9 +69,102 @@ void printVersion(raw_ostream &ostream) {
6969 cl::PrintVersionMessage ();
7070}
7171
72- int main (int argc, char **argv) {
73- cl::SetVersionPrinter (printVersion);
74- cl::HideUnrelatedOptions (category);
72+ void generateSymEncodingsFunction (std::string funcName) {
73+ auto M = getLLVMIR ();
74+ IR2Vec_Symbolic SYM (*M);
75+ std::ofstream o;
76+ o.open (oname, std::ios_base::app);
77+ if (printTime) {
78+ clock_t start = clock ();
79+ SYM.generateSymbolicEncodingsForFunction (&o, funcName);
80+ clock_t end = clock ();
81+ double elapsed = double (end - start) / CLOCKS_PER_SEC;
82+ printf (" Time taken by on-demand generation of symbolic encodings "
83+ " is: %.6f "
84+ " seconds.\n " ,
85+ elapsed);
86+ } else {
87+ SYM.generateSymbolicEncodingsForFunction (&o, funcName);
88+ }
89+ o.close ();
90+ }
91+
92+ void generateFAEncodingsFunction (std::string funcName) {
93+ auto M = getLLVMIR ();
94+ IR2Vec_FA FA (*M);
95+ std::ofstream o, missCount, cyclicCount;
96+ o.open (oname, std::ios_base::app);
97+ missCount.open (" missCount_" + oname, std::ios_base::app);
98+ cyclicCount.open (" cyclicCount_" + oname, std::ios_base::app);
99+ if (printTime) {
100+ clock_t start = clock ();
101+ FA.generateFlowAwareEncodingsForFunction (&o, funcName, &missCount,
102+ &cyclicCount);
103+ clock_t end = clock ();
104+ double elapsed = double (end - start) / CLOCKS_PER_SEC;
105+ printf (" Time taken by on-demand generation of flow-aware encodings "
106+ " is: %.6f "
107+ " seconds.\n " ,
108+ elapsed);
109+ } else {
110+ FA.generateFlowAwareEncodingsForFunction (&o, funcName, &missCount,
111+ &cyclicCount);
112+ }
113+ o.close ();
114+ }
115+
116+ void generateFAEncodings () {
117+ auto M = getLLVMIR ();
118+ IR2Vec_FA FA (*M);
119+ std::ofstream o, missCount, cyclicCount;
120+ o.open (oname, std::ios_base::app);
121+ missCount.open (" missCount_" + oname, std::ios_base::app);
122+ cyclicCount.open (" cyclicCount_" + oname, std::ios_base::app);
123+ if (printTime) {
124+ clock_t start = clock ();
125+ FA.generateFlowAwareEncodings (&o, &missCount, &cyclicCount);
126+ clock_t end = clock ();
127+ double elapsed = double (end - start) / CLOCKS_PER_SEC;
128+ printf (" Time taken by normal generation of flow-aware encodings "
129+ " is: %.6f "
130+ " seconds.\n " ,
131+ elapsed);
132+ } else {
133+ FA.generateFlowAwareEncodings (&o, &missCount, &cyclicCount);
134+ }
135+ o.close ();
136+ }
137+
138+ void generateSYMEncodings () {
139+ auto M = getLLVMIR ();
140+ IR2Vec_Symbolic SYM (*M);
141+ std::ofstream o;
142+ o.open (oname, std::ios_base::app);
143+ if (printTime) {
144+ clock_t start = clock ();
145+ SYM.generateSymbolicEncodings (&o);
146+ clock_t end = clock ();
147+ double elapsed = double (end - start) / CLOCKS_PER_SEC;
148+ printf (" Time taken by normal generation of symbolic encodings is: "
149+ " %.6f "
150+ " seconds.\n " ,
151+ elapsed);
152+ } else {
153+ SYM.generateSymbolicEncodings (&o);
154+ }
155+ o.close ();
156+ }
157+
158+ void collectIR () {
159+ auto M = getLLVMIR ();
160+ CollectIR cir (M);
161+ std::ofstream o;
162+ o.open (oname, std::ios_base::app);
163+ cir.generateTriplets (o);
164+ o.close ();
165+ }
166+
167+ void setGlobalVars (int argc, char **argv) {
75168 cl::ParseCommandLineOptions (argc, argv);
76169
77170 fa = cl_fa;
@@ -88,111 +181,56 @@ int main(int argc, char **argv) {
88181 WT = cl_WT;
89182 debug = cl_debug;
90183 printTime = cl_printTime;
184+ }
91185
186+ void checkFailureConditions () {
92187 bool failed = false ;
93- if (!((sym ^ fa) ^ collectIR)) {
94- errs () << " Either of sym, fa or collectIR should be specified\n " ;
188+
189+ if (!(sym || fa || collectIR)) {
190+ errs () << " Either of sym, fa, or collectIR should be specified\n " ;
95191 failed = true ;
96192 }
97193
194+ if (failed)
195+ exit (1 );
196+
98197 if (sym || fa) {
99198 if (level != ' p' && level != ' f' ) {
100199 errs () << " Invalid level specified: Use either p or f\n " ;
101200 failed = true ;
102201 }
103202 } else {
104- if (! collectIR) {
105- errs () << " Either of sym, fa or collectIR should be specified \n " ;
106- failed = true ;
107- } else if (level)
203+ // assert collectIR is True. Else
204+ assert ( collectIR == true ) ;
205+
206+ if (collectIR && level) {
108207 errs () << " [WARNING] level would not be used in collectIR mode\n " ;
208+ }
109209 }
110210
111211 if (failed)
112212 exit (1 );
213+ }
214+
215+ int main (int argc, char **argv) {
216+ cl::SetVersionPrinter (printVersion);
217+ cl::HideUnrelatedOptions (category);
218+
219+ setGlobalVars (argc, argv);
220+
221+ checkFailureConditions ();
113222
114- auto M = getLLVMIR ();
115223 // newly added
116224 if (sym && !(funcName.empty ())) {
117- IR2Vec_Symbolic SYM (*M);
118- std::ofstream o;
119- o.open (oname, std::ios_base::app);
120- if (printTime) {
121- clock_t start = clock ();
122- SYM.generateSymbolicEncodingsForFunction (&o, funcName);
123- clock_t end = clock ();
124- double elapsed = double (end - start) / CLOCKS_PER_SEC;
125- printf (" Time taken by on-demand generation of symbolic encodings "
126- " is: %.6f "
127- " seconds.\n " ,
128- elapsed);
129- } else {
130- SYM.generateSymbolicEncodingsForFunction (&o, funcName);
131- }
132- o.close ();
225+ generateSymEncodingsFunction (funcName);
133226 } else if (fa && !(funcName.empty ())) {
134- IR2Vec_FA FA (*M);
135- std::ofstream o, missCount, cyclicCount;
136- o.open (oname, std::ios_base::app);
137- missCount.open (" missCount_" + oname, std::ios_base::app);
138- cyclicCount.open (" cyclicCount_" + oname, std::ios_base::app);
139- if (printTime) {
140- clock_t start = clock ();
141- FA.generateFlowAwareEncodingsForFunction (&o, funcName, &missCount,
142- &cyclicCount);
143- clock_t end = clock ();
144- double elapsed = double (end - start) / CLOCKS_PER_SEC;
145- printf (" Time taken by on-demand generation of flow-aware encodings "
146- " is: %.6f "
147- " seconds.\n " ,
148- elapsed);
149- } else {
150- FA.generateFlowAwareEncodingsForFunction (&o, funcName, &missCount,
151- &cyclicCount);
152- }
153- o.close ();
227+ generateFAEncodingsFunction (funcName);
154228 } else if (fa) {
155- IR2Vec_FA FA (*M);
156- std::ofstream o, missCount, cyclicCount;
157- o.open (oname, std::ios_base::app);
158- missCount.open (" missCount_" + oname, std::ios_base::app);
159- cyclicCount.open (" cyclicCount_" + oname, std::ios_base::app);
160- if (printTime) {
161- clock_t start = clock ();
162- FA.generateFlowAwareEncodings (&o, &missCount, &cyclicCount);
163- clock_t end = clock ();
164- double elapsed = double (end - start) / CLOCKS_PER_SEC;
165- printf (" Time taken by normal generation of flow-aware encodings "
166- " is: %.6f "
167- " seconds.\n " ,
168- elapsed);
169- } else {
170- FA.generateFlowAwareEncodings (&o, &missCount, &cyclicCount);
171- }
172- o.close ();
229+ generateFAEncodings ();
173230 } else if (sym) {
174- IR2Vec_Symbolic SYM (*M);
175- std::ofstream o;
176- o.open (oname, std::ios_base::app);
177- if (printTime) {
178- clock_t start = clock ();
179- SYM.generateSymbolicEncodings (&o);
180- clock_t end = clock ();
181- double elapsed = double (end - start) / CLOCKS_PER_SEC;
182- printf (" Time taken by normal generation of symbolic encodings is: "
183- " %.6f "
184- " seconds.\n " ,
185- elapsed);
186- } else {
187- SYM.generateSymbolicEncodings (&o);
188- }
189- o.close ();
231+ generateSYMEncodings ();
190232 } else if (collectIR) {
191- CollectIR cir (M);
192- std::ofstream o;
193- o.open (oname, std::ios_base::app);
194- cir.generateTriplets (o);
195- o.close ();
233+ collectIR ();
196234 }
197235 return 0 ;
198236}
0 commit comments