Directory: | ./ |
---|---|
File: | src/main.cpp |
Date: | 2025-03-14 12:14:21 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 77 | 85 | 90.6% |
Branches: | 163 | 191 | 85.3% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /*************************************** | ||
2 | Auteur : Pierre Aubert | ||
3 | Mail : pierre.aubert@lapp.in2p3.fr | ||
4 | Licence : CeCILL-C | ||
5 | ****************************************/ | ||
6 | |||
7 | #include "convertToString.h" | ||
8 | |||
9 | #include "OptionParser.h" | ||
10 | |||
11 | #include "FrontEnd/HeaderParser.h" | ||
12 | #include "BackEnd/backend.h" | ||
13 | #include "BackEnd/backend_proxy_loader.h" | ||
14 | |||
15 | ///Create the OptionParser of this program | ||
16 | /** @return OptionParser of this program | ||
17 | */ | ||
18 | 3 | OptionParser createOptionParser(){ | |
19 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | OptionParser parser(true, __PROGRAM_VERSION__); |
20 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | parser.setExampleLongOption("phoenix_hpc_proxy --input=file.ph5 --output=output/dir/"); |
21 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | parser.setExampleShortOption("phoenix_hpc_proxy -i file1.ph5 file1.ph5 fileN.ph5 -o output/dir/"); |
22 | |||
23 |
4/4✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 10 taken 3 times.
|
3 | parser.addOption("header", "i", OptionType::FILENAME, true, "list of input headers to be used to describe the main library"); |
24 |
1/1✓ Branch 2 taken 3 times.
|
3 | std::string libName("lib_shadok"); |
25 |
5/5✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 10 taken 3 times.
✓ Branch 13 taken 3 times.
|
3 | parser.addOption("library", "l", libName, "name of the library to be created"); |
26 | |||
27 |
4/4✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 10 taken 3 times.
|
3 | parser.addOption("libdir", "d", OptionType::DIRECTORY, false, "directory where the sub libraries are installed"); |
28 | |||
29 |
4/4✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 10 taken 3 times.
|
3 | parser.addOption("anyarch", "", OptionType::FILENAME, false, "file name of the library to be used for any architectures (kind of security if the other architectures are not found)"); |
30 |
4/4✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 10 taken 3 times.
|
3 | parser.addOption("sse", "", OptionType::FILENAME, false, "file name of the library to be used for sse architecture"); |
31 |
4/4✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 10 taken 3 times.
|
3 | parser.addOption("sse2", "", OptionType::FILENAME, false, "file name of the library to be used for sse2 architecture"); |
32 |
4/4✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 10 taken 3 times.
|
3 | parser.addOption("ssse3", "", OptionType::FILENAME, false, "file name of the library to be used for ssse3 architecture"); |
33 |
4/4✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 10 taken 3 times.
|
3 | parser.addOption("sse4.1", "", OptionType::FILENAME, false, "file name of the library to be used for sse4.1 architecture"); |
34 |
4/4✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 10 taken 3 times.
|
3 | parser.addOption("sse4.2", "", OptionType::FILENAME, false, "file name of the library to be used for sse4.2 architecture"); |
35 |
4/4✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 10 taken 3 times.
|
3 | parser.addOption("avx", "", OptionType::FILENAME, false, "file name of the library to be used for avx architecture"); |
36 |
4/4✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 10 taken 3 times.
|
3 | parser.addOption("avx2", "", OptionType::FILENAME, false, "file name of the library to be used for avx2 architecture"); |
37 |
4/4✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 10 taken 3 times.
|
3 | parser.addOption("avx512f", "", OptionType::FILENAME, false, "file name of the library to be used for avx512f architecture"); |
38 |
4/4✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 10 taken 3 times.
|
3 | parser.addOption("avx512bw", "", OptionType::FILENAME, false, "file name of the library to be used for avx512wb architecture"); |
39 | |||
40 |
1/1✓ Branch 2 taken 3 times.
|
3 | std::string defaultOutputDir("."); |
41 |
5/5✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 10 taken 3 times.
✓ Branch 13 taken 3 times.
|
3 | parser.addOption("output", "o", defaultOutputDir, "Output directory"); |
42 | |||
43 | 6 | return parser; | |
44 | 3 | } | |
45 | |||
46 | ///Parse the vector of library architecture | ||
47 | /** @param[out] vecArchLib : vector of libraries architecture | ||
48 | * @param defaultMode : arguments passed to the program | ||
49 | */ | ||
50 | 3 | void parseVecArchLib(PVecArchLib & vecArchLib, const OptionMode & defaultMode){ | |
51 |
10/10✓ Branch 2 taken 3 times.
✓ Branch 6 taken 3 times.
✓ Branch 10 taken 3 times.
✓ Branch 14 taken 3 times.
✓ Branch 18 taken 3 times.
✓ Branch 22 taken 3 times.
✓ Branch 26 taken 3 times.
✓ Branch 30 taken 3 times.
✓ Branch 34 taken 3 times.
✓ Branch 38 taken 3 times.
|
30 | std::string libAnyArch(""), libSse(""), libSse2(""), libSsse3(""), libSse41(""), libSse42(""), libAvx(""), libAvx2(""), libAvx512f(""), libAvx512wb(""); |
52 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | defaultMode.getValue(libAnyArch, "anyarch"); |
53 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | defaultMode.getValue(libSse, "sse"); |
54 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | defaultMode.getValue(libSse2, "sse2"); |
55 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | defaultMode.getValue(libSsse3, "ssse3"); |
56 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | defaultMode.getValue(libSse41, "sse4.1"); |
57 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | defaultMode.getValue(libSse42, "sse4.2"); |
58 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | defaultMode.getValue(libAvx, "avx"); |
59 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | defaultMode.getValue(libAvx2, "avx2"); |
60 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | defaultMode.getValue(libAvx512f, "avx512f"); |
61 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | defaultMode.getValue(libAvx512wb, "avx512wb"); |
62 | |||
63 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
|
3 | addArch(vecArchLib, "anyarch", libAnyArch); |
64 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
|
3 | addArch(vecArchLib, "sse", libSse); |
65 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
|
3 | addArch(vecArchLib, "sse2", libSse2); |
66 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
|
3 | addArch(vecArchLib, "ssse3", libSsse3); |
67 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
|
3 | addArch(vecArchLib, "sse4.1", libSse41); |
68 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
|
3 | addArch(vecArchLib, "sse4.2", libSse42); |
69 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
|
3 | addArch(vecArchLib, "avx", libAvx); |
70 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
|
3 | addArch(vecArchLib, "avx2", libAvx2); |
71 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
|
3 | addArch(vecArchLib, "avx512f", libAvx512f); |
72 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
|
3 | addArch(vecArchLib, "avx512wb", libAvx512wb); |
73 | 3 | } | |
74 | |||
75 | ///Create the source from configuration file | ||
76 | /** @param inputFile : name of the input file to be used | ||
77 | * @param libraryName : name of the library to be created | ||
78 | * @param vecArchLib : vector of library architecture to be used | ||
79 | * @param libDir : directory where the sub libraries are installed | ||
80 | * @param outputDir : output directory to be used | ||
81 | * @return true on success, false otherwise | ||
82 | */ | ||
83 | 3 | bool createSourceFromConfig(const PString & inputFile, const PString & libraryName, const PVecArchLib & vecArchLib, | |
84 | const PString & libDir, const PString & outputDir) | ||
85 | { | ||
86 |
1/1✓ Branch 1 taken 3 times.
|
3 | HeaderParser parser; |
87 |
3/4✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
|
3 | if(!parser.load(inputFile)){ |
88 | ✗ | std::cerr << "createSourceFromConfig : cannot parse the input file '"<<inputFile<<"'" << std::endl; | |
89 | ✗ | return false; | |
90 | } | ||
91 |
1/1✓ Branch 1 taken 3 times.
|
3 | std::string libName(getLibraryFile(vecArchLib)); |
92 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | PVecSource vecSource = parser.getVecSource(); |
93 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
|
3 | if(vecSource.size() == 0lu){ |
94 | ✗ | std::cerr << "createSourceFromConfig : no source to be created" << std::endl; | |
95 | ✗ | return false; | |
96 | } | ||
97 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
|
3 | bool b(cpp_backend(vecSource, libName, outputDir)); |
98 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if(!b){ |
99 | ✗ | std::cerr << "createSourceFromConfig : cannot save source/header from input file '"<<inputFile<<"'" << std::endl; | |
100 | ✗ | return b; | |
101 | } | ||
102 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
|
3 | b &= cpp_backend_proxy(vecSource, libraryName, vecArchLib, libDir, outputDir); |
103 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if(!b){ |
104 | ✗ | std::cerr << "createSourceFromConfig : cannot save source/header ProxyLoader class" << std::endl; | |
105 | ✗ | return b; | |
106 | } | ||
107 | 3 | return b; | |
108 | 3 | } | |
109 | |||
110 | ///Process all the input files | ||
111 | /** @param listInputFile : list of the input files | ||
112 | * @param libName : name of the library to be created | ||
113 | * @param vecArchLib : vector of library architecture to be used | ||
114 | * @param libDir : directory where the sub libraries are installed | ||
115 | * @param outputDir : output directory to be used | ||
116 | * @return 0 on success, -1 otherwise | ||
117 | */ | ||
118 | 3 | int processFiles(const PVecPath & listInputFile, const PString & libName, const PVecArchLib & vecArchLib, | |
119 | const PPath & libDir, const PPath & outputDir) | ||
120 | { | ||
121 | 3 | bool b(true); | |
122 |
2/2✓ Branch 3 taken 3 times.
✓ Branch 4 taken 3 times.
|
6 | for(PVecPath::const_iterator it(listInputFile.begin()); it != listInputFile.end(); ++it){ |
123 |
1/1✓ Branch 2 taken 3 times.
|
3 | b &= createSourceFromConfig(*it, libName, vecArchLib, libDir, outputDir); |
124 | } | ||
125 | 3 | return b - 1; | |
126 | } | ||
127 | |||
128 | 3 | int main(int argc, char** argv){ | |
129 |
1/1✓ Branch 1 taken 3 times.
|
3 | OptionParser parser = createOptionParser(); |
130 |
1/1✓ Branch 1 taken 3 times.
|
3 | parser.parseArgument(argc, argv); |
131 | |||
132 |
1/1✓ Branch 1 taken 3 times.
|
3 | const OptionMode & defaultMode = parser.getDefaultMode(); |
133 | 3 | PVecPath listInputFile; | |
134 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | defaultMode.getValue(listInputFile, "header"); |
135 | |||
136 |
4/4✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 10 taken 3 times.
|
6 | PPath outputDir("."), libDir(""); |
137 |
1/1✓ Branch 1 taken 3 times.
|
3 | PString libName(""); |
138 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | defaultMode.getValue(outputDir, "output"); |
139 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | defaultMode.getValue(libName, "library"); |
140 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | defaultMode.getValue(libDir, "libdir"); |
141 | |||
142 | 3 | PVecArchLib vecArchLib; | |
143 |
1/1✓ Branch 1 taken 3 times.
|
3 | parseVecArchLib(vecArchLib, defaultMode); |
144 | |||
145 |
1/1✓ Branch 1 taken 3 times.
|
3 | return processFiles(listInputFile, libName, vecArchLib, libDir, outputDir); |
146 | 3 | } | |
147 | |||
148 | |||
149 |