forked from ferrandi/PandA-bambu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Parameter.cpp
1842 lines (1765 loc) · 61.3 KB
/
Parameter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
*
* _/_/_/ _/_/ _/ _/ _/_/_/ _/_/
* _/ _/ _/ _/ _/_/ _/ _/ _/ _/ _/
* _/_/_/ _/_/_/_/ _/ _/_/ _/ _/ _/_/_/_/
* _/ _/ _/ _/ _/ _/ _/ _/ _/
* _/ _/ _/ _/ _/ _/_/_/ _/ _/
*
* ***********************************************
* PandA Project
* URL: http://panda.dei.polimi.it
* Politecnico di Milano - DEIB
* System Architectures Group
* ***********************************************
* Copyright (C) 2004-2023 Politecnico di Milano
*
* This file is part of the PandA framework.
*
* The PandA framework is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/**
* @file Parameter.cpp
* @brief
*
* @author Christian Pilato <[email protected]>
* @author Marco Lattuada <[email protected]>
*
*/
/// Autoheader include
#include "config_HAVE_ARM_COMPILER.hpp"
#include "config_HAVE_FROM_ARCH_BUILT.hpp"
#include "config_HAVE_FROM_CSV_BUILT.hpp"
#include "config_HAVE_FROM_C_BUILT.hpp"
#include "config_HAVE_FROM_IPXACT_BUILT.hpp"
#include "config_HAVE_FROM_PSPLIB_BUILT.hpp"
#include "config_HAVE_FROM_SDF3_BUILT.hpp"
#include "config_HAVE_I386_CLANG10_COMPILER.hpp"
#include "config_HAVE_I386_CLANG11_COMPILER.hpp"
#include "config_HAVE_I386_CLANG12_COMPILER.hpp"
#include "config_HAVE_I386_CLANG13_COMPILER.hpp"
#include "config_HAVE_I386_CLANG4_COMPILER.hpp"
#include "config_HAVE_I386_CLANG5_COMPILER.hpp"
#include "config_HAVE_I386_CLANG6_COMPILER.hpp"
#include "config_HAVE_I386_CLANG7_COMPILER.hpp"
#include "config_HAVE_I386_CLANG8_COMPILER.hpp"
#include "config_HAVE_I386_CLANG9_COMPILER.hpp"
#include "config_HAVE_I386_CLANGVVD_COMPILER.hpp"
#include "config_HAVE_I386_GCC45_COMPILER.hpp"
#include "config_HAVE_I386_GCC46_COMPILER.hpp"
#include "config_HAVE_I386_GCC47_COMPILER.hpp"
#include "config_HAVE_I386_GCC48_COMPILER.hpp"
#include "config_HAVE_I386_GCC49_COMPILER.hpp"
#include "config_HAVE_I386_GCC5_COMPILER.hpp"
#include "config_HAVE_I386_GCC6_COMPILER.hpp"
#include "config_HAVE_I386_GCC7_COMPILER.hpp"
#include "config_HAVE_I386_GCC8_COMPILER.hpp"
#include "config_HAVE_IPXACT_BUILT.hpp"
#include "config_HAVE_PERFORMANCE_METRICS_XML.hpp"
#include "config_HAVE_REGRESSORS_BUILT.hpp"
#include "config_HAVE_SOURCE_CODE_STATISTICS_XML.hpp"
#include "config_HAVE_SPARC_COMPILER.hpp"
#include "config_HAVE_TO_DATAFILE_BUILT.hpp"
#include "config_HAVE_WEIGHT_MODELS_XML.hpp"
#include "config_PACKAGE_BUGREPORT.hpp"
#include "config_PACKAGE_STRING.hpp"
/// Header include
#include "Parameter.hpp"
#if HAVE_FROM_C_BUILT
/// wrapper/compiler
#include "compiler_wrapper.hpp"
#endif
/// Boost include
#include <boost/lexical_cast.hpp>
/// Constants include
#if HAVE_REGRESSORS_BUILT
#include "aggregated_features_xml.hpp"
#include "skip_rows_xml.hpp"
#endif
#if HAVE_FROM_ARCH_BUILT
#include "architecture_xml.hpp"
#endif
#include "constant_strings.hpp"
#include "constants.hpp"
#if HAVE_HLS_BUILT
#include "constraints_xml.hpp"
#endif
#include "experimental_setup_xml.hpp"
#if HAVE_TO_DATAFILE_BUILT
#include "latex_table_xml.hpp"
#endif
#if HAVE_PERFORMANCE_METRICS_XML
#include "metrics_xml.hpp"
#endif
#if HAVE_SOURCE_CODE_STATISTICS_XML
#include "source_code_statistics_xml.hpp"
#endif
#if(HAVE_WEIGHT_MODELS_XML && HAVE_EXPERIMENTAL) || HAVE_PERFORMANCE_METRICS_XML
#include "probability_distribution_xml.hpp"
#endif
#if HAVE_TECHNOLOGY_BUILT
#include "technology_xml.hpp"
#endif
#if HAVE_WEIGHT_MODELS_XML && HAVE_EXPERIMENTAL
#include "weights_xml.hpp"
#endif
#if HAVE_FROM_SDF3_BUILT
#include "sdf3_xml.hpp"
#endif
#if HAVE_CODE_ESTIMATION_BUILT
/// design_flows/codesign/estimation include
#include "actor_graph_estimator.hpp"
#endif
#if HAVE_FROM_C_BUILT
#include "token_interface.hpp"
#endif
/// STD include
#include <cstdlib>
#include <iosfwd>
/// Utility include
#include "dbgPrintHelper.hpp"
#include "fileIO.hpp"
#include "refcount.hpp"
#include "string_manipulation.hpp"
#include "xml_helper.hpp"
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/path.hpp>
/// XML include
#include "polixml.hpp"
#include "xml_dom_parser.hpp"
#if HAVE_FROM_IPXACT_BUILT
#include "ip_xact_xml.hpp"
/// Constants include
#include "design_analysis_xml.hpp"
#endif
#include "fileIO.hpp"
const std::string branch_name = {
#include "branch_name.hpp"
};
const std::string revision_hash = {
#include "revision_hash.hpp"
};
#define OPTION_NAME(r, data, elem) option_name[BOOST_PP_CAT(OPT_, elem)] = #elem;
Parameter::Parameter(const std::string& _program_name, int _argc, char** const _argv, int _debug_level)
: argc(_argc), argv(_argv), debug_level(_debug_level)
{
setOption(OPT_program_name, _program_name);
BOOST_PP_SEQ_FOR_EACH(OPTION_NAME, BOOST_PP_EMPTY, BAMBU_OPTIONS)
BOOST_PP_SEQ_FOR_EACH(OPTION_NAME, BOOST_PP_EMPTY, EUCALIPTUS_OPTIONS)
BOOST_PP_SEQ_FOR_EACH(OPTION_NAME, BOOST_PP_EMPTY, FRAMEWORK_OPTIONS)
BOOST_PP_SEQ_FOR_EACH(OPTION_NAME, BOOST_PP_EMPTY, COMPILER_OPTIONS)
BOOST_PP_SEQ_FOR_EACH(OPTION_NAME, BOOST_PP_EMPTY, GECCO_OPTIONS)
BOOST_PP_SEQ_FOR_EACH(OPTION_NAME, BOOST_PP_EMPTY, KOALA_OPTIONS)
BOOST_PP_SEQ_FOR_EACH(OPTION_NAME, BOOST_PP_EMPTY, SPIDER_OPTIONS)
BOOST_PP_SEQ_FOR_EACH(OPTION_NAME, BOOST_PP_EMPTY, SYNTHESIS_OPTIONS)
BOOST_PP_SEQ_FOR_EACH(OPTION_NAME, BOOST_PP_EMPTY, TREE_PANDA_COMPILER_OPTIONS)
BOOST_PP_SEQ_FOR_EACH(OPTION_NAME, BOOST_PP_EMPTY, ZEBU_OPTIONS)
// This part has been added since boost macro does not expand correctly
std::map<enum enum_option, std::string>::iterator it, it_end = option_name.end();
for(it = option_name.begin(); it != it_end; it++)
{
it->second = "OPT_" + it->second.substr(19);
it->second = it->second.substr(0, it->second.find(')'));
}
SetCommonDefaults();
}
Parameter::Parameter(const Parameter& other)
: argc(other.argc),
argv(other.argv),
Options(other.Options),
enum_options(other.enum_options),
option_name(other.option_name),
debug_classes(other.debug_classes),
debug_level(other.debug_level)
{
}
void Parameter::CheckParameters()
{
const auto temporary_directory = getOption<std::string>(OPT_output_temporary_directory);
if(boost::filesystem::exists(temporary_directory))
{
boost::filesystem::remove_all(temporary_directory);
}
boost::filesystem::create_directory(temporary_directory);
/// Output directory is not removed since it can be the current one
const auto output_directory = getOption<std::string>(OPT_output_directory);
if(!boost::filesystem::exists(output_directory))
{
boost::filesystem::create_directory(output_directory);
}
if(!boost::filesystem::exists(output_directory))
{
THROW_ERROR("not able to create directory " + output_directory);
}
if(getOption<bool>(OPT_print_dot))
{
const auto dot_directory = getOption<std::string>(OPT_dot_directory);
if(boost::filesystem::exists(dot_directory))
{
boost::filesystem::remove_all(dot_directory);
}
boost::filesystem::create_directory(dot_directory);
if(!boost::filesystem::exists(dot_directory))
{
THROW_ERROR("not able to create directory " + dot_directory);
}
}
#if HAVE_FROM_C_BUILT
if(isOption(OPT_gcc_m32_mx32))
{
const auto mopt = getOption<std::string>(OPT_gcc_m32_mx32);
if(mopt == "-m32" &&
CompilerWrapper::hasCompilerGCCM32(getOption<CompilerWrapper_CompilerTarget>(OPT_default_compiler)))
{
setOption(OPT_gcc_m32_mx32, "-m32 -mno-sse2");
}
else if((mopt == "-m32" && !CompilerWrapper::hasCompilerCLANGM32(
getOption<CompilerWrapper_CompilerTarget>(OPT_default_compiler))) ||
(mopt == "-mx32" &&
!CompilerWrapper::hasCompilerMX32(getOption<CompilerWrapper_CompilerTarget>(OPT_default_compiler))) ||
(mopt == "-m64" &&
!CompilerWrapper::hasCompilerM64(getOption<CompilerWrapper_CompilerTarget>(OPT_default_compiler))))
{
THROW_ERROR("Option " + mopt + " not supported by " +
CompilerWrapper::getCompilerSuffix(OPT_default_compiler) + " compiler.");
}
}
#endif
}
Parameter::~Parameter() = default;
void Parameter::load_xml_configuration_file_rec(const xml_element* node)
{
// Recurse through child nodes:
const xml_node::node_list list = node->get_children();
for(const auto& iter : list)
{
const auto* EnodeC = GetPointer<const xml_element>(iter);
if(!EnodeC)
{
continue;
}
/// general options
if(CE_XVM(value, EnodeC))
{
Options[GET_NODE_NAME(EnodeC)] = GET_STRING_VALUE(EnodeC);
}
if(EnodeC->get_children().size())
{
load_xml_configuration_file_rec(EnodeC);
}
}
}
void Parameter::load_xml_configuration_file(const std::string& filename)
{
try
{
XMLDomParser parser(filename);
parser.Exec();
if(parser)
{
// Walk the tree:
const xml_element* node = parser.get_document()->get_root_node(); // deleted by DomParser.
// Recurse through child nodes:
const xml_node::node_list list = node->get_children();
for(const auto& iter : list)
{
const auto* EnodeC = GetPointer<const xml_element>(iter);
if(!EnodeC)
{
continue;
}
/// general options
if(CE_XVM(value, EnodeC))
{
Options[GET_NODE_NAME(EnodeC)] = GET_STRING_VALUE(EnodeC);
}
if(EnodeC->get_children().size())
{
load_xml_configuration_file_rec(EnodeC);
}
}
}
}
catch(const char* msg)
{
std::cerr << msg << std::endl;
}
catch(const std::string& msg)
{
std::cerr << msg << std::endl;
}
catch(const std::exception& ex)
{
std::cout << "Exception caught: " << ex.what() << std::endl;
}
catch(...)
{
std::cerr << "unknown exception" << std::endl;
}
}
void Parameter::write_xml_configuration_file(const std::string& filename)
{
xml_document document;
xml_element* parameters = document.create_root_node("parameters");
for(auto Op = Options.begin(); Op != Options.end(); ++Op)
{
xml_element* node = parameters->add_child_element(Op->first);
WRITE_XNVM2("value", Op->second, node);
}
document.write_to_file_formatted(filename);
}
void Parameter::SetCommonDefaults()
{
setOption(STR_OPT_benchmark_fake_parameters, "<none>");
std::string current_dir = GetCurrentPath();
std::string temporary_directory = current_dir + "/" + std::string(STR_CST_temporary_directory);
setOption(OPT_dot_directory, current_dir + "/dot/");
setOption(OPT_output_temporary_directory, temporary_directory + "/");
setOption(OPT_print_dot, false);
setOption(OPT_no_clean, false);
if(revision_hash == "")
{
setOption(OPT_revision, "unknown-trunk");
}
else
{
setOption(OPT_revision, revision_hash + (branch_name != "" ? "-" + branch_name : ""));
}
setOption(OPT_seed, 0);
setOption(OPT_max_transformations, std::numeric_limits<size_t>::max());
setOption(OPT_find_max_transformations, false);
}
void Parameter::print(std::ostream& os) const
{
os << "List of parameters: " << std::endl;
for(const auto& Option : Options)
{
os << Option.first << ": " << Option.second << std::endl;
}
std::map<enum enum_option, std::string>::const_iterator option, option_end = enum_options.end();
for(option = enum_options.begin(); option != option_end; ++option)
{
os << option_name.find(option->first)->second << ": " << option->second << std::endl;
}
os << " === " << std::endl;
}
int Parameter::get_class_debug_level(const std::string& class_name, int _debug_level) const
{
auto temp = class_name;
temp.erase(std::remove(temp.begin(), temp.end(), '_'), temp.end());
if(debug_classes.find(boost::to_upper_copy(temp)) != debug_classes.end() or
debug_classes.find(STR_CST_debug_all) != debug_classes.end())
{
return DEBUG_LEVEL_INFINITE;
}
else if(_debug_level < 0)
{
return getOption<int>(OPT_debug_level);
}
else
{
return _debug_level;
}
}
int Parameter::GetFunctionDebugLevel(const std::string& class_name, const std::string& function_name) const
{
auto canonic_class_name = class_name;
canonic_class_name.erase(std::remove(canonic_class_name.begin(), canonic_class_name.end(), '_'),
canonic_class_name.end());
auto canonic_function_name = function_name;
canonic_function_name.erase(std::remove(canonic_function_name.begin(), canonic_function_name.end(), '_'),
canonic_function_name.end());
const auto canonic_full_function_name = canonic_class_name + std::string("::") + canonic_function_name;
if(debug_classes.find(boost::to_upper_copy(canonic_full_function_name)) != debug_classes.end())
{
return DEBUG_LEVEL_INFINITE;
}
else
{
return get_class_debug_level(class_name);
}
}
void Parameter::add_debug_class(const std::string& class_name)
{
auto temp = class_name;
temp.erase(std::remove(temp.begin(), temp.end(), '_'), temp.end());
debug_classes.insert(boost::to_upper_copy(temp));
}
void Parameter::PrintFullHeader(std::ostream& os) const
{
PrintProgramName(os);
os << " Politecnico di Milano - DEIB" << std::endl;
os << " System Architectures Group" << std::endl;
os << "********************************************************************************" << std::endl;
os << " Copyright (C) 2004-2023 Politecnico di Milano" << std::endl;
std::string version = PrintVersion();
if(version.size() < 80)
{
os << std::string(40 - (version.size() / 2), ' ') << version << std::endl;
}
else
{
os << version << std::endl;
}
os << std::endl;
}
std::string Parameter::PrintVersion() const
{
return std::string("Version: ") + PACKAGE_STRING + " - Revision " + getOption<std::string>(OPT_revision);
}
void Parameter::PrintUsage(std::ostream& os) const
{
PrintFullHeader(os);
PrintHelp(os);
}
bool Parameter::ManageDefaultOptions(int next_option, char* optarg_param, bool& exit_success)
{
exit_success = false;
switch(next_option)
{
case INPUT_OPT_NO_CLEAN:
setOption(OPT_no_clean, true);
break;
case 'h': // print help message and exit
PrintUsage(std::cout);
exit_success = true;
break;
case 'V':
PrintFullHeader(std::cout);
exit_success = true;
break;
#if !RELEASE
case OPT_READ_PARAMETERS_XML:
{
setOption(OPT_read_parameter_xml, optarg_param);
load_xml_configuration_file(getOption<std::string>(OPT_read_parameter_xml));
break;
}
case OPT_WRITE_PARAMETERS_XML:
{
setOption(OPT_write_parameter_xml, optarg_param);
break;
}
#endif
case 'v':
{
setOption(OPT_output_level, optarg_param);
break;
}
case OPT_BENCHMARK_NAME:
{
setOption(OPT_benchmark_name, optarg_param);
break;
}
case OPT_BENCHMARK_FAKE_PARAMETERS:
{
setOption(STR_OPT_benchmark_fake_parameters, optarg_param);
break;
}
case INPUT_OPT_MAX_TRANSFORMATIONS:
{
setOption(OPT_max_transformations, optarg_param);
break;
}
case INPUT_OPT_FIND_MAX_TRANSFORMATIONS:
{
setOption(OPT_find_max_transformations, true);
break;
}
case INPUT_OPT_CONFIGURATION_NAME:
{
setOption(OPT_configuration_name, optarg_param);
break;
}
case 'd':
{
#if HAVE_FROM_C_BUILT
if(std::string(optarg_param) == "umpversion")
{
CompilerWrapper_CompilerTarget preferred_compiler;
preferred_compiler = getOption<CompilerWrapper_CompilerTarget>(OPT_default_compiler);
PRINT_OUT_MEX(OUTPUT_LEVEL_NONE, 0,
CompilerWrapper::getCompilerVersion(static_cast<int>(preferred_compiler)));
exit_success = true;
break;
}
#endif
if(std::string(optarg_param) == "N")
{
std::string gcc_extra_options = "-dN";
if(isOption(OPT_gcc_extra_options))
{
gcc_extra_options = getOption<std::string>(OPT_gcc_extra_options) + " " + gcc_extra_options;
}
setOption(OPT_gcc_extra_options, gcc_extra_options);
break;
}
#ifndef NDEBUG
else
{
debug_level = boost::lexical_cast<int>(optarg_param);
setOption(OPT_debug_level, optarg_param);
break;
}
#endif
return true;
}
#ifndef NDEBUG
case OPT_DEBUG_CLASSES:
{
std::vector<std::string> Splitted = SplitString(optarg_param, ",");
for(const auto& i : Splitted)
{
add_debug_class(i);
}
setOption(OPT_no_clean, true);
break;
}
#endif
case INPUT_OPT_ERROR_ON_WARNING:
{
error_on_warning = true;
break;
}
case INPUT_OPT_PRINT_DOT:
{
setOption(OPT_print_dot, true);
break;
}
case INPUT_OPT_SEED:
{
setOption(OPT_seed, optarg_param);
break;
}
case OPT_OUTPUT_TEMPORARY_DIRECTORY:
{
/// If the path is not absolute, make it into absolute
std::string path(optarg_param);
std::string temporary_directory_pattern;
temporary_directory_pattern = GetPath(path) + "/" + std::string(STR_CST_temporary_directory);
// The %s are required by the mkdtemp function
boost::filesystem::path temp_path = temporary_directory_pattern + "-%%%%-%%%%-%%%%-%%%%";
boost::filesystem::path temp_path_obtained = boost::filesystem::unique_path(temp_path);
boost::filesystem::create_directories(temp_path_obtained.string());
path = temp_path_obtained.string();
path = path + "/";
setOption(OPT_output_temporary_directory, path);
break;
}
case INPUT_OPT_PANDA_PARAMETER:
{
std::string param_pair(optarg_param);
std::vector<std::string> splitted = SplitString(param_pair, "=");
if(splitted.size() != 2)
{
THROW_ERROR("panda-parameter should be in the form <parameter>=<value>: " + param_pair);
}
panda_parameters[splitted[0]] = splitted[1];
break;
}
default:
{
/// next_option is not a Tool parameter
return true;
}
}
return false;
}
#if HAVE_FROM_C_BUILT
bool Parameter::ManageGccOptions(int next_option, char* optarg_param)
{
switch(next_option)
{
case 'c':
{
setOption(OPT_gcc_c, true);
break;
}
case 'D':
{
std::string defines;
if(isOption(OPT_gcc_defines))
{
defines = getOption<std::string>(OPT_gcc_defines) + STR_CST_string_separator;
}
if(std::string(optarg_param).find('=') != std::string::npos)
{
bool has_parenthesis = std::string(optarg_param).find('(') != std::string::npos &&
std::string(optarg_param).find(')') != std::string::npos;
std::string temp_var = std::string(optarg_param);
boost::replace_first(temp_var, "=", "=\'");
if(has_parenthesis)
{
defines += "\'" + temp_var + "\'" + "\'";
}
else
{
defines += temp_var + "\'";
}
}
else
{
defines += std::string(optarg_param);
}
setOption(OPT_gcc_defines, defines);
break;
}
case 'f':
{
if(std::string(optarg_param).find("openmp-simd") != std::string::npos)
{
if(std::string(optarg_param).find('=') != std::string::npos)
{
setOption(OPT_gcc_openmp_simd,
std::string(optarg_param).substr(std::string(optarg_param).find('=') + 1));
}
else
{
setOption(OPT_gcc_openmp_simd, 4);
}
break;
}
else if(std::string(optarg_param).find("openmp") != std::string::npos)
{
setOption(OPT_parse_pragma, true);
break;
}
else
{
std::string optimizations;
if(isOption(OPT_gcc_optimizations))
{
optimizations = getOption<std::string>(OPT_gcc_optimizations) + STR_CST_string_separator;
}
THROW_ASSERT(optarg_param != nullptr && optarg_param[0] != 0, "-f alone not allowed");
setOption(OPT_gcc_optimizations, optimizations + optarg_param);
break;
}
}
case 'g':
{
///-g not managed at all
break;
}
case 'm':
{
if(optarg_param)
{
const std::string opt_level = std::string(optarg_param);
if(opt_level == "32")
{
setOption(OPT_gcc_m32_mx32, "-m32");
}
else if(opt_level == "x32")
{
setOption(OPT_gcc_m32_mx32, "-mx32");
}
else if(opt_level == "64")
{
setOption(OPT_gcc_m32_mx32, "-m64");
}
}
break;
}
case 'W':
{
std::string gcc_warnings;
if(isOption(OPT_gcc_warnings))
{
gcc_warnings = getOption<std::string>(OPT_gcc_warnings) + STR_CST_string_separator;
}
setOption(OPT_gcc_warnings, gcc_warnings + optarg_param);
break;
}
case 'E':
{
setOption(OPT_gcc_E, true);
break;
}
case 'I':
{
std::string includes = "-I " + GetPath(std::string(optarg));
if(isOption(OPT_gcc_includes))
{
includes = getOption<std::string>(OPT_gcc_includes) + " " + includes;
}
setOption(OPT_gcc_includes, includes);
break;
}
case 'l':
{
std::string libraries;
if(isOption(OPT_gcc_libraries))
{
libraries = getOption<std::string>(OPT_gcc_libraries) + STR_CST_string_separator;
}
setOption(OPT_gcc_libraries, libraries + optarg_param);
break;
}
case 'L':
{
std::string library_directories;
if(isOption(OPT_gcc_library_directories))
{
library_directories = getOption<std::string>(OPT_gcc_library_directories) + STR_CST_string_separator;
}
setOption(OPT_gcc_library_directories, library_directories + GetPath(optarg_param));
break;
}
case 'O':
{
if(optarg_param)
{
const std::string opt_level = std::string(optarg_param);
if(opt_level == "0")
{
setOption(OPT_compiler_opt_level, CompilerWrapper_OptimizationSet::O0);
}
else if(opt_level == "1")
{
setOption(OPT_compiler_opt_level, CompilerWrapper_OptimizationSet::O1);
}
else if(opt_level == "2")
{
setOption(OPT_compiler_opt_level, CompilerWrapper_OptimizationSet::O2);
}
else if(opt_level == "3")
{
setOption(OPT_compiler_opt_level, CompilerWrapper_OptimizationSet::O3);
}
else if(opt_level == "4")
{
setOption(OPT_compiler_opt_level, CompilerWrapper_OptimizationSet::O4);
}
else if(opt_level == "5")
{
setOption(OPT_compiler_opt_level, CompilerWrapper_OptimizationSet::O5);
}
else if(opt_level == "g")
{
setOption(OPT_compiler_opt_level, CompilerWrapper_OptimizationSet::Og);
}
else if(opt_level == "s")
{
setOption(OPT_compiler_opt_level, CompilerWrapper_OptimizationSet::Os);
}
else if(opt_level == "fast")
{
setOption(OPT_compiler_opt_level, CompilerWrapper_OptimizationSet::Ofast);
}
else if(opt_level == "z")
{
setOption(OPT_compiler_opt_level, CompilerWrapper_OptimizationSet::Oz);
}
else
{
THROW_ERROR("Unknown optimization level: " + opt_level);
}
}
else
{
setOption(OPT_compiler_opt_level, CompilerWrapper_OptimizationSet::O1);
}
break;
}
case 'U':
{
std::string undefines;
if(isOption(OPT_gcc_undefines))
{
undefines = getOption<std::string>(OPT_gcc_undefines) + STR_CST_string_separator;
}
if(std::string(optarg_param).find('=') != std::string::npos)
{
bool has_parenthesis = std::string(optarg_param).find('(') != std::string::npos &&
std::string(optarg_param).find(')') != std::string::npos;
std::string temp_var = std::string(optarg_param);
boost::replace_first(temp_var, "=", "=\'");
if(has_parenthesis)
{
undefines += "\'" + temp_var + "\'" + "\'";
}
else
{
undefines += temp_var + "\'";
}
}
else
{
setOption(OPT_gcc_undefines, undefines + optarg_param);
}
break;
}
case INPUT_OPT_CUSTOM_OPTIONS:
{
setOption(OPT_gcc_extra_options, optarg);
break;
}
#if !RELEASE
case INPUT_OPT_COMPUTE_SIZEOF:
{
setOption(OPT_compute_size_of, true);
break;
}
#endif
case INPUT_OPT_COMPILER:
{
#if HAVE_ARM_COMPILER
if(std::string(optarg_param) == "ARM")
{
setOption(OPT_default_compiler, static_cast<int>(CompilerWrapper_CompilerTarget::CT_ARM_GCC));
break;
}
#endif
#if HAVE_SPARC_COMPILER
if(std::string(optarg_param) == "SPARC")
{
setOption(OPT_default_compiler, static_cast<int>(CompilerWrapper_CompilerTarget::CT_SPARC_GCC));
break;
}
#endif
#if HAVE_I386_GCC45_COMPILER
if(std::string(optarg_param) == "I386_GCC45")
{
setOption(OPT_default_compiler, static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_GCC45));
break;
}
#endif
#if HAVE_I386_GCC46_COMPILER
if(std::string(optarg_param) == "I386_GCC46")
{
setOption(OPT_default_compiler, static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_GCC46));
break;
}
#endif
#if HAVE_I386_GCC47_COMPILER
if(std::string(optarg_param) == "I386_GCC47")
{
setOption(OPT_default_compiler, static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_GCC47));
break;
}
#endif
#if HAVE_I386_GCC48_COMPILER
if(std::string(optarg_param) == "I386_GCC48")
{
setOption(OPT_default_compiler, static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_GCC48));
break;
}
#endif
#if HAVE_I386_GCC49_COMPILER
if(std::string(optarg_param) == "I386_GCC49")
{
setOption(OPT_default_compiler, static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_GCC49));
break;
}
#endif
#if HAVE_I386_GCC5_COMPILER
if(std::string(optarg_param) == "I386_GCC5")
{
setOption(OPT_default_compiler, static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_GCC5));
break;
}
#endif
#if HAVE_I386_GCC6_COMPILER
if(std::string(optarg_param) == "I386_GCC6")
{
setOption(OPT_default_compiler, static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_GCC6));
break;
}
#endif
#if HAVE_I386_GCC7_COMPILER
if(std::string(optarg_param) == "I386_GCC7")
{
setOption(OPT_default_compiler, static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_GCC7));
break;
}
#endif
#if HAVE_I386_GCC8_COMPILER
if(std::string(optarg_param) == "I386_GCC8")
{
setOption(OPT_default_compiler, static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_GCC8));
break;
}
#endif
#if HAVE_I386_CLANG4_COMPILER
if(std::string(optarg_param) == "I386_CLANG4")
{
setOption(OPT_default_compiler, static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_CLANG4));
break;
}
#endif
#if HAVE_I386_CLANG5_COMPILER
if(std::string(optarg_param) == "I386_CLANG5")
{
setOption(OPT_default_compiler, static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_CLANG5));
break;
}
#endif
#if HAVE_I386_CLANG6_COMPILER
if(std::string(optarg_param) == "I386_CLANG6")
{
setOption(OPT_default_compiler, static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_CLANG6));
break;
}
#endif
#if HAVE_I386_CLANG7_COMPILER
if(std::string(optarg_param) == "I386_CLANG7")
{
setOption(OPT_default_compiler, static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_CLANG7));
break;
}
#endif
#if HAVE_I386_CLANG8_COMPILER
if(std::string(optarg_param) == "I386_CLANG8")
{
setOption(OPT_default_compiler, static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_CLANG8));
break;
}
#endif
#if HAVE_I386_CLANG9_COMPILER
if(std::string(optarg_param) == "I386_CLANG9")
{
setOption(OPT_default_compiler, static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_CLANG9));
break;
}
#endif
#if HAVE_I386_CLANG10_COMPILER
if(std::string(optarg_param) == "I386_CLANG10")
{
setOption(OPT_default_compiler, static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_CLANG10));
break;
}
#endif
#if HAVE_I386_CLANG11_COMPILER
if(std::string(optarg_param) == "I386_CLANG11")
{
setOption(OPT_default_compiler, static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_CLANG11));
break;
}
#endif
#if HAVE_I386_CLANG12_COMPILER
if(std::string(optarg_param) == "I386_CLANG12")
{
setOption(OPT_default_compiler, static_cast<int>(CompilerWrapper_CompilerTarget::CT_I386_CLANG12));
break;
}
#endif
#if HAVE_I386_CLANG13_COMPILER