| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*************************************** | ||
| 2 | Auteur : Pierre Aubert | ||
| 3 | Mail : pierre.aubert@lapp.in2p3.fr | ||
| 4 | Licence : CeCILL-C | ||
| 5 | ****************************************/ | ||
| 6 | |||
| 7 | #include "backend.h" | ||
| 8 | |||
| 9 | ///Get the licence in string | ||
| 10 | /** @return licence in string | ||
| 11 | */ | ||
| 12 | 12 | PString cpp_licenceSaveStr(){ | |
| 13 | 12 | PString body(""); | |
| 14 |
1/1✓ Branch 0 (3→4) taken 12 times.
|
12 | body += "/***************************************\n"; |
| 15 |
1/1✓ Branch 0 (4→5) taken 12 times.
|
12 | body += "\tAuteur : Pierre Aubert\n"; |
| 16 |
1/1✓ Branch 0 (5→6) taken 12 times.
|
12 | body += "\tMail : pierre.aubert@lapp.in2p3.fr\n"; |
| 17 |
1/1✓ Branch 0 (6→7) taken 12 times.
|
12 | body += "\tLicence : CeCILL-C\n"; |
| 18 |
1/1✓ Branch 0 (7→8) taken 12 times.
|
12 | body += "****************************************/\n\n\n"; |
| 19 | |||
| 20 |
1/1✓ Branch 0 (8→9) taken 12 times.
|
12 | body += "//Warning : this file has been generated automatically by the phoenix_hpc_proxy program\n"; |
| 21 |
1/1✓ Branch 0 (9→10) taken 12 times.
|
12 | body += "//You can find it at https://gitlab.in2p3.fr/CTA-LAPP/PHOENIX_LIBS/PhoenixHPCProxy\n"; |
| 22 |
1/1✓ Branch 0 (10→11) taken 12 times.
|
12 | body += "//Do NOT modify it\n\n\n"; |
| 23 | 12 | return body; | |
| 24 | ✗ | } | |
| 25 | |||
| 26 | ///Get the handle name of the given function | ||
| 27 | /** @param functionName : function name | ||
| 28 | * @return corresponding function name | ||
| 29 | */ | ||
| 30 | 12 | PString getHandleFunction(const PString & functionName){ | |
| 31 |
2/2✓ Branch 0 (2→3) taken 12 times.
✓ Branch 2 (3→4) taken 12 times.
|
24 | return "handle_" + functionName; |
| 32 | } | ||
| 33 | |||
| 34 | ///Get the handle type name of the given function | ||
| 35 | /** @param functionName : function name | ||
| 36 | * @return corresponding function name | ||
| 37 | */ | ||
| 38 | 12 | PString getHandleFunctionType(const PString & functionName){ | |
| 39 |
2/2✓ Branch 0 (2→3) taken 12 times.
✓ Branch 2 (3→4) taken 12 times.
|
24 | return "FunctionTypehandle_" + functionName; |
| 40 | } | ||
| 41 | |||
| 42 | ///Get the update type name of the given file | ||
| 43 | /** @param fileName : file name | ||
| 44 | * @return corresponding function name | ||
| 45 | */ | ||
| 46 | 9 | PString getUpdateFunction(const PPath & fileName){ | |
| 47 |
3/3✓ Branch 0 (2→3) taken 9 times.
✓ Branch 2 (3→4) taken 9 times.
✓ Branch 4 (4→5) taken 9 times.
|
9 | return "update_" + fileName.eraseExtension(); |
| 48 | } | ||
| 49 | |||
| 50 | ///Save the function prototype as an inline function | ||
| 51 | /** @param function : PFunction to be used | ||
| 52 | * @return corresponding string | ||
| 53 | */ | ||
| 54 | 12 | PString cpp_backendTableHeaderInline(PFunction & function){ | |
| 55 |
6/6✓ Branch 0 (2→3) taken 12 times.
✓ Branch 2 (3→4) taken 12 times.
✓ Branch 4 (4→5) taken 9 times.
✓ Branch 5 (4→8) taken 3 times.
✓ Branch 6 (5→6) taken 9 times.
✓ Branch 8 (6→7) taken 9 times.
|
12 | if(function.getOtherCode() != ""){return function.getOtherCode();} |
| 56 |
1/1✓ Branch 0 (8→9) taken 3 times.
|
3 | PString body(""); |
| 57 |
3/6✓ Branch 0 (9→10) taken 3 times.
✓ Branch 2 (10→11) taken 3 times.
✗ Branch 4 (11→12) not taken.
✓ Branch 5 (11→14) taken 3 times.
✗ Branch 6 (12→13) not taken.
✗ Branch 8 (13→14) not taken.
|
3 | if(function.getDocString() != ""){body += function.getDocString();} |
| 58 |
3/6✓ Branch 0 (14→15) taken 3 times.
✓ Branch 2 (15→16) taken 3 times.
✗ Branch 4 (16→17) not taken.
✓ Branch 5 (16→19) taken 3 times.
✗ Branch 6 (17→18) not taken.
✗ Branch 8 (18→19) not taken.
|
3 | if(function.getTemplateDef() != ""){body += function.getTemplateDef();} |
| 59 |
7/7✓ Branch 0 (19→20) taken 3 times.
✓ Branch 2 (20→21) taken 3 times.
✓ Branch 4 (21→22) taken 3 times.
✓ Branch 6 (22→23) taken 3 times.
✓ Branch 8 (23→24) taken 3 times.
✓ Branch 10 (24→25) taken 3 times.
✓ Branch 12 (25→26) taken 3 times.
|
3 | body += "inline " + function.getOutputType() + " " + function.getName() + "("; |
| 60 | 3 | bool isComma(false); | |
| 61 |
1/1✓ Branch 0 (30→31) taken 3 times.
|
3 | PVecArgument & vecArg = function.getVecArgument(); |
| 62 |
2/2✓ Branch 0 (78→32) taken 12 times.
✓ Branch 1 (78→79) taken 3 times.
|
30 | for(PVecArgument::iterator it(vecArg.begin()); it != vecArg.end(); ++it){ |
| 63 |
3/3✓ Branch 0 (32→33) taken 9 times.
✓ Branch 1 (32→34) taken 3 times.
✓ Branch 2 (33→34) taken 9 times.
|
12 | if(isComma){body += ", ";} |
| 64 |
3/3✓ Branch 0 (36→37) taken 12 times.
✓ Branch 2 (37→38) taken 12 times.
✓ Branch 4 (38→39) taken 12 times.
|
12 | body += it->getType() + " "; |
| 65 |
7/7✓ Branch 0 (42→43) taken 12 times.
✓ Branch 2 (43→44) taken 12 times.
✓ Branch 4 (44→45) taken 9 times.
✓ Branch 5 (44→52) taken 3 times.
✓ Branch 6 (47→48) taken 9 times.
✓ Branch 8 (48→49) taken 9 times.
✓ Branch 10 (49→50) taken 9 times.
|
21 | if(it->getPtrRef() != ""){body += it->getPtrRef() + " ";} |
| 66 |
2/2✓ Branch 0 (54→55) taken 12 times.
✓ Branch 2 (55→56) taken 12 times.
|
12 | body += it->getName(); |
| 67 |
3/7✓ Branch 0 (58→59) taken 12 times.
✓ Branch 2 (59→60) taken 12 times.
✗ Branch 4 (60→61) not taken.
✓ Branch 5 (60→68) taken 12 times.
✗ Branch 6 (63→64) not taken.
✗ Branch 8 (64→65) not taken.
✗ Branch 10 (65→66) not taken.
|
12 | if(it->getDefaultValue() != ""){body += " = " + it->getDefaultValue();} |
| 68 | 12 | isComma = true; | |
| 69 | } | ||
| 70 |
1/1✓ Branch 0 (79→80) taken 3 times.
|
3 | body += "){\n"; |
| 71 | 3 | isComma = false; | |
| 72 |
5/5✓ Branch 0 (80→81) taken 3 times.
✓ Branch 2 (81→82) taken 3 times.
✓ Branch 4 (82→83) taken 3 times.
✓ Branch 6 (83→84) taken 3 times.
✓ Branch 8 (84→85) taken 3 times.
|
3 | body += "\t"+getHandleFunction(function.getName())+"("; |
| 73 |
2/2✓ Branch 0 (105→89) taken 12 times.
✓ Branch 1 (105→106) taken 3 times.
|
30 | for(PVecArgument::iterator it(vecArg.begin()); it != vecArg.end(); ++it){ |
| 74 |
3/3✓ Branch 0 (89→90) taken 9 times.
✓ Branch 1 (89→91) taken 3 times.
✓ Branch 2 (90→91) taken 9 times.
|
12 | if(isComma){body += ", ";} |
| 75 |
2/2✓ Branch 0 (93→94) taken 12 times.
✓ Branch 2 (94→95) taken 12 times.
|
12 | body += it->getName(); |
| 76 | 12 | isComma = true; | |
| 77 | } | ||
| 78 |
1/1✓ Branch 0 (106→107) taken 3 times.
|
3 | body += ");\n"; |
| 79 |
1/1✓ Branch 0 (107→108) taken 3 times.
|
3 | body += "}\n\n"; |
| 80 |
1/1✓ Branch 0 (108→109) taken 3 times.
|
3 | return body; |
| 81 | 3 | } | |
| 82 | |||
| 83 | ///Save the function prototype as an inline function | ||
| 84 | /** @param function : PFunction to be used | ||
| 85 | * @return corresponding string | ||
| 86 | */ | ||
| 87 | 12 | PString cpp_backendTableHeaderHandleType(PFunction & function){ | |
| 88 |
4/4✓ Branch 0 (2→3) taken 12 times.
✓ Branch 2 (3→4) taken 9 times.
✓ Branch 3 (3→6) taken 3 times.
✓ Branch 4 (4→5) taken 9 times.
|
12 | if(!repr_isFunction(function)){return "";} |
| 89 |
1/1✓ Branch 0 (6→7) taken 3 times.
|
3 | PString body(""); |
| 90 |
8/8✓ Branch 0 (7→8) taken 3 times.
✓ Branch 2 (8→9) taken 3 times.
✓ Branch 4 (9→10) taken 3 times.
✓ Branch 6 (10→11) taken 3 times.
✓ Branch 8 (11→12) taken 3 times.
✓ Branch 10 (12→13) taken 3 times.
✓ Branch 12 (13→14) taken 3 times.
✓ Branch 14 (14→15) taken 3 times.
|
3 | body += "typedef " + function.getOutputType() + "(*" + getHandleFunctionType(function.getName()) + ")("; |
| 91 | 3 | bool isComma(false); | |
| 92 |
1/1✓ Branch 0 (20→21) taken 3 times.
|
3 | PVecArgument & vecArg = function.getVecArgument(); |
| 93 |
2/2✓ Branch 0 (50→22) taken 12 times.
✓ Branch 1 (50→51) taken 3 times.
|
30 | for(PVecArgument::iterator it(vecArg.begin()); it != vecArg.end(); ++it){ |
| 94 |
3/3✓ Branch 0 (22→23) taken 9 times.
✓ Branch 1 (22→24) taken 3 times.
✓ Branch 2 (23→24) taken 9 times.
|
12 | if(isComma){body += ", ";} |
| 95 |
2/2✓ Branch 0 (26→27) taken 12 times.
✓ Branch 2 (27→28) taken 12 times.
|
12 | body += it->getType(); |
| 96 |
7/7✓ Branch 0 (30→31) taken 12 times.
✓ Branch 2 (31→32) taken 12 times.
✓ Branch 4 (32→33) taken 9 times.
✓ Branch 5 (32→40) taken 3 times.
✓ Branch 6 (35→36) taken 9 times.
✓ Branch 8 (36→37) taken 9 times.
✓ Branch 10 (37→38) taken 9 times.
|
21 | if(it->getPtrRef() != ""){body += " " + it->getPtrRef();} |
| 97 | 12 | isComma = true; | |
| 98 | } | ||
| 99 |
1/1✓ Branch 0 (51→52) taken 3 times.
|
3 | body += ");\n"; |
| 100 |
1/1✓ Branch 0 (52→53) taken 3 times.
|
3 | return body; |
| 101 | 3 | } | |
| 102 | |||
| 103 | ///Save the header of the given PSource | ||
| 104 | /** @param source : PSource to be used | ||
| 105 | * @return corresponding string | ||
| 106 | */ | ||
| 107 | 3 | PString cpp_backendHeader(PSource & source){ | |
| 108 |
1/1✓ Branch 0 (2→3) taken 3 times.
|
3 | PString body(cpp_licenceSaveStr()); |
| 109 |
6/6✓ Branch 0 (3→4) taken 3 times.
✓ Branch 2 (4→5) taken 3 times.
✓ Branch 4 (5→6) taken 3 times.
✓ Branch 6 (6→7) taken 3 times.
✓ Branch 8 (7→8) taken 3 times.
✓ Branch 10 (8→9) taken 3 times.
|
3 | PString baseMacro("__" + source.getName().eraseExtension().toUpper() + "_PROXY_H__"); |
| 110 |
3/3✓ Branch 0 (12→13) taken 3 times.
✓ Branch 2 (13→14) taken 3 times.
✓ Branch 4 (14→15) taken 3 times.
|
3 | body += "#ifndef " + baseMacro + "\n"; |
| 111 |
3/3✓ Branch 0 (17→18) taken 3 times.
✓ Branch 2 (18→19) taken 3 times.
✓ Branch 4 (19→20) taken 3 times.
|
3 | body += "#define " + baseMacro + "\n\n"; |
| 112 |
1/1✓ Branch 0 (22→23) taken 3 times.
|
3 | body += "#include <iostream>\n\n\n"; |
| 113 |
1/1✓ Branch 0 (23→24) taken 3 times.
|
3 | PVecFunction & vecFunction = source.getVecFunction(); |
| 114 |
2/2✓ Branch 0 (40→25) taken 12 times.
✓ Branch 1 (40→41) taken 3 times.
|
30 | for(PVecFunction::iterator it(vecFunction.begin()); it != vecFunction.end(); ++it){ |
| 115 |
2/2✓ Branch 0 (27→28) taken 12 times.
✓ Branch 2 (28→29) taken 12 times.
|
12 | body += cpp_backendTableHeaderHandleType(*it); |
| 116 | } | ||
| 117 |
1/1✓ Branch 0 (41→42) taken 3 times.
|
3 | body += "\n\n"; |
| 118 |
2/2✓ Branch 0 (78→43) taken 12 times.
✓ Branch 1 (78→79) taken 3 times.
|
30 | for(PVecFunction::iterator it(vecFunction.begin()); it != vecFunction.end(); ++it){ |
| 119 |
3/3✓ Branch 0 (45→46) taken 12 times.
✓ Branch 2 (46→47) taken 9 times.
✓ Branch 3 (46→48) taken 3 times.
|
12 | if(!repr_isFunction(*it)){continue;} |
| 120 |
9/9✓ Branch 0 (50→51) taken 3 times.
✓ Branch 2 (51→52) taken 3 times.
✓ Branch 4 (54→55) taken 3 times.
✓ Branch 6 (55→56) taken 3 times.
✓ Branch 8 (56→57) taken 3 times.
✓ Branch 10 (57→58) taken 3 times.
✓ Branch 12 (58→59) taken 3 times.
✓ Branch 14 (59→60) taken 3 times.
✓ Branch 16 (60→61) taken 3 times.
|
6 | body += "extern " + getHandleFunctionType(it->getName()) + " " + getHandleFunction(it->getName()) + ";\n"; |
| 121 | } | ||
| 122 |
1/1✓ Branch 0 (79→80) taken 3 times.
|
3 | body += "\n\n"; |
| 123 |
2/2✓ Branch 0 (96→81) taken 12 times.
✓ Branch 1 (96→97) taken 3 times.
|
30 | for(PVecFunction::iterator it(vecFunction.begin()); it != vecFunction.end(); ++it){ |
| 124 |
2/2✓ Branch 0 (83→84) taken 12 times.
✓ Branch 2 (84→85) taken 12 times.
|
12 | body += cpp_backendTableHeaderInline(*it); |
| 125 | } | ||
| 126 |
5/5✓ Branch 0 (97→98) taken 3 times.
✓ Branch 2 (98→99) taken 3 times.
✓ Branch 4 (99→100) taken 3 times.
✓ Branch 6 (100→101) taken 3 times.
✓ Branch 8 (101→102) taken 3 times.
|
3 | body += "void " + getUpdateFunction(source.getName()) + "(void * handle);\n\n"; |
| 127 | |||
| 128 |
1/1✓ Branch 0 (105→106) taken 3 times.
|
3 | body += "#endif\n\n"; |
| 129 | 3 | return body; | |
| 130 | 3 | } | |
| 131 | |||
| 132 | ///Get the mangled name of the given function name | ||
| 133 | /** @param libraryName : file name of the library to be used | ||
| 134 | * @param functionName : name of the function to be searched | ||
| 135 | * @return mangled name of the corresponding function | ||
| 136 | */ | ||
| 137 | 3 | PString getMangleFunctionName(const PString & libraryName, const PString & functionName){ | |
| 138 |
2/4✓ Branch 0 (2→3) taken 3 times.
✗ Branch 2 (3→4) not taken.
✓ Branch 3 (3→6) taken 3 times.
✗ Branch 4 (4→5) not taken.
|
3 | if(libraryName == ""){return functionName;} |
| 139 |
2/2✓ Branch 0 (6→7) taken 3 times.
✓ Branch 2 (7→8) taken 3 times.
|
3 | PPath outputTmpFile(".mangledFunctionName.txt"); |
| 140 |
6/6✓ Branch 0 (9→10) taken 3 times.
✓ Branch 2 (10→11) taken 3 times.
✓ Branch 4 (11→12) taken 3 times.
✓ Branch 6 (12→13) taken 3 times.
✓ Branch 8 (13→14) taken 3 times.
✓ Branch 10 (14→15) taken 3 times.
|
3 | PString command("objdump --syms "+libraryName+" | grep \".text\" | sed -e \"s/ /\\n/g\" | grep "+functionName+" | head -n 1 > "+outputTmpFile); |
| 141 |
2/3✓ Branch 0 (21→22) taken 3 times.
✗ Branch 2 (22→23) not taken.
✓ Branch 3 (22→25) taken 3 times.
|
3 | if(system(command.c_str()) != 0){ |
| 142 | ✗ | return functionName; | |
| 143 | } | ||
| 144 |
1/1✓ Branch 0 (25→26) taken 3 times.
|
3 | PString fullFileContent(outputTmpFile.loadFileContent()); |
| 145 |
5/5✓ Branch 0 (26→27) taken 3 times.
✓ Branch 2 (27→28) taken 3 times.
✓ Branch 4 (28→29) taken 3 times.
✓ Branch 6 (29→30) taken 3 times.
✓ Branch 8 (30→31) taken 3 times.
|
3 | std::cerr << "getMangleFunctionName : full file content mangle function '"<<functionName<<"' : " << fullFileContent << std::endl; |
| 146 |
2/2✓ Branch 0 (31→32) taken 3 times.
✓ Branch 2 (32→33) taken 3 times.
|
3 | PString mangleFunction(fullFileContent.eraseChar("\n\t ")); |
| 147 |
1/2✗ Branch 0 (36→37) not taken.
✓ Branch 1 (36→41) taken 3 times.
|
3 | if(remove(outputTmpFile.c_str()) != 0){ |
| 148 | ✗ | std::cerr << "DPS::LibraryHandle::mangleFunctionName : cannot remove file '"<<outputTmpFile<<"'" << std::endl; | |
| 149 | } | ||
| 150 |
1/1✓ Branch 0 (41→42) taken 3 times.
|
3 | return mangleFunction; |
| 151 | 3 | } | |
| 152 | |||
| 153 | ///Save the source of the given PSource | ||
| 154 | /** @param source : PSource to be used | ||
| 155 | * @param libName : filename to a binary library | ||
| 156 | * @return corresponding string | ||
| 157 | */ | ||
| 158 | 3 | PString cpp_backendSource(PSource & source, const PString & libName){ | |
| 159 | 3 | PString body(cpp_licenceSaveStr()); | |
| 160 |
1/1✓ Branch 0 (3→4) taken 3 times.
|
3 | body += "#include <stdio.h>\n"; |
| 161 |
1/1✓ Branch 0 (4→5) taken 3 times.
|
3 | body += "#include <stdlib.h>\n"; |
| 162 |
1/1✓ Branch 0 (5→6) taken 3 times.
|
3 | body += "#include <dlfcn.h>\n\n"; |
| 163 |
5/5✓ Branch 0 (6→7) taken 3 times.
✓ Branch 2 (7→8) taken 3 times.
✓ Branch 4 (8→9) taken 3 times.
✓ Branch 6 (9→10) taken 3 times.
✓ Branch 8 (10→11) taken 3 times.
|
3 | body += "#include \""+source.getName().eraseExtension()+".h\"\n\n"; |
| 164 | |||
| 165 |
1/1✓ Branch 0 (13→14) taken 3 times.
|
3 | PVecFunction & vecFunction = source.getVecFunction(); |
| 166 |
2/2✓ Branch 0 (48→15) taken 12 times.
✓ Branch 1 (48→49) taken 3 times.
|
30 | for(PVecFunction::iterator it(vecFunction.begin()); it != vecFunction.end(); ++it){ |
| 167 |
3/3✓ Branch 0 (17→18) taken 12 times.
✓ Branch 2 (18→19) taken 9 times.
✓ Branch 3 (18→20) taken 3 times.
|
12 | if(!repr_isFunction(*it)){continue;} |
| 168 |
8/8✓ Branch 0 (22→23) taken 3 times.
✓ Branch 2 (23→24) taken 3 times.
✓ Branch 4 (26→27) taken 3 times.
✓ Branch 6 (27→28) taken 3 times.
✓ Branch 8 (28→29) taken 3 times.
✓ Branch 10 (29→30) taken 3 times.
✓ Branch 12 (30→31) taken 3 times.
✓ Branch 14 (31→32) taken 3 times.
|
6 | body += getHandleFunctionType(it->getName()) + " " + getHandleFunction(it->getName()) + ";\n"; |
| 169 | } | ||
| 170 |
1/1✓ Branch 0 (49→50) taken 3 times.
|
3 | body += "\n\n"; |
| 171 |
1/1✓ Branch 0 (50→51) taken 3 times.
|
3 | body += "///Update the all the function handles of the file\n"; |
| 172 |
1/1✓ Branch 0 (51→52) taken 3 times.
|
3 | body += "/**\t@param handle : pointer to loaded library\n"; |
| 173 |
1/1✓ Branch 0 (52→53) taken 3 times.
|
3 | body += "*/\n"; |
| 174 |
5/5✓ Branch 0 (53→54) taken 3 times.
✓ Branch 2 (54→55) taken 3 times.
✓ Branch 4 (55→56) taken 3 times.
✓ Branch 6 (56→57) taken 3 times.
✓ Branch 8 (57→58) taken 3 times.
|
3 | body += "void " + getUpdateFunction(source.getName()) + "(void * handle){\n"; |
| 175 |
2/2✓ Branch 0 (107→62) taken 12 times.
✓ Branch 1 (107→108) taken 3 times.
|
30 | for(PVecFunction::iterator it(vecFunction.begin()); it != vecFunction.end(); ++it){ |
| 176 |
3/3✓ Branch 0 (64→65) taken 12 times.
✓ Branch 2 (65→66) taken 9 times.
✓ Branch 3 (65→67) taken 3 times.
|
12 | if(!repr_isFunction(*it)){continue;} |
| 177 |
2/2✓ Branch 0 (69→70) taken 3 times.
✓ Branch 2 (70→71) taken 3 times.
|
3 | PString mangleFunction(getMangleFunctionName(libName, it->getName())); |
| 178 |
11/11✓ Branch 0 (73→74) taken 3 times.
✓ Branch 2 (74→75) taken 3 times.
✓ Branch 4 (77→78) taken 3 times.
✓ Branch 6 (78→79) taken 3 times.
✓ Branch 8 (79→80) taken 3 times.
✓ Branch 10 (80→81) taken 3 times.
✓ Branch 12 (81→82) taken 3 times.
✓ Branch 14 (82→83) taken 3 times.
✓ Branch 16 (83→84) taken 3 times.
✓ Branch 18 (84→85) taken 3 times.
✓ Branch 20 (85→86) taken 3 times.
|
6 | body += "\t"+getHandleFunction(it->getName())+" = ("+getHandleFunctionType(it->getName())+")(dlsym(handle, \""+mangleFunction+"\"));\n"; |
| 179 | 3 | } | |
| 180 |
1/1✓ Branch 0 (108→109) taken 3 times.
|
3 | body += "}\n\n"; |
| 181 | 3 | return body; | |
| 182 | ✗ | } | |
| 183 | |||
| 184 | ///Save a vector of PSource in the output directory | ||
| 185 | /** @param source : source to be saved | ||
| 186 | * @param libName : filename to a binary library | ||
| 187 | * @param outputDir : output directory where to save PSource | ||
| 188 | * @return true on success, false otherwise | ||
| 189 | */ | ||
| 190 | 3 | bool cpp_backend(PSource & source, const PString & libName, const PPath & outputDir){ | |
| 191 |
1/1✓ Branch 0 (2→3) taken 3 times.
|
3 | PString headerSrc(cpp_backendHeader(source)); |
| 192 |
1/1✓ Branch 0 (3→4) taken 3 times.
|
3 | PString sourceSrc(cpp_backendSource(source, libName)); |
| 193 |
3/3✓ Branch 0 (4→5) taken 3 times.
✓ Branch 2 (5→6) taken 3 times.
✓ Branch 4 (6→7) taken 3 times.
|
3 | PPath baseFileName(source.getName().eraseExtension()); |
| 194 |
5/5✓ Branch 0 (7→8) taken 3 times.
✓ Branch 2 (8→9) taken 3 times.
✓ Branch 4 (9→10) taken 3 times.
✓ Branch 6 (10→11) taken 3 times.
✓ Branch 8 (11→12) taken 3 times.
|
3 | PPath outputHeaderFile(outputDir / baseFileName + PString(".h")); |
| 195 |
5/5✓ Branch 0 (16→17) taken 3 times.
✓ Branch 2 (17→18) taken 3 times.
✓ Branch 4 (18→19) taken 3 times.
✓ Branch 6 (19→20) taken 3 times.
✓ Branch 8 (20→21) taken 3 times.
|
3 | PPath outputSourceFile(outputDir / baseFileName + PString(".cpp")); |
| 196 |
2/3✓ Branch 0 (25→26) taken 3 times.
✗ Branch 2 (26→27) not taken.
✓ Branch 3 (26→32) taken 3 times.
|
3 | if(!outputHeaderFile.saveFileContent(headerSrc)){ |
| 197 | ✗ | std::cerr << "cpp_backend : cannot save header file '"<<outputHeaderFile<<"'" << std::endl; | |
| 198 | ✗ | return false; | |
| 199 | } | ||
| 200 |
4/4✓ Branch 0 (32→33) taken 3 times.
✓ Branch 2 (33→34) taken 3 times.
✓ Branch 4 (34→35) taken 3 times.
✓ Branch 6 (35→36) taken 3 times.
|
3 | std::cout << "cpp_backend : create header file '"<<outputHeaderFile<<"'" <<std::endl; |
| 201 |
2/3✓ Branch 0 (36→37) taken 3 times.
✗ Branch 2 (37→38) not taken.
✓ Branch 3 (37→43) taken 3 times.
|
3 | if(!outputSourceFile.saveFileContent(sourceSrc)){ |
| 202 | ✗ | std::cerr << "cpp_backend : cannot save source file '"<<outputSourceFile<<"'" << std::endl; | |
| 203 | ✗ | return false; | |
| 204 | } | ||
| 205 |
4/4✓ Branch 0 (43→44) taken 3 times.
✓ Branch 2 (44→45) taken 3 times.
✓ Branch 4 (45→46) taken 3 times.
✓ Branch 6 (46→47) taken 3 times.
|
3 | std::cout << "cpp_backend : create source file '"<<outputSourceFile<<"'" <<std::endl; |
| 206 | 3 | return true; | |
| 207 | 3 | } | |
| 208 | |||
| 209 | ///Save a vector of PSource in the output directory | ||
| 210 | /** @param vecSource : vector of source | ||
| 211 | * @param libName : filename to a binary library | ||
| 212 | * @param outputDir : output directory where to save PSource | ||
| 213 | * @return true on success, false otherwise | ||
| 214 | */ | ||
| 215 | 3 | bool cpp_backend(PVecSource & vecSource, const PString & libName, const PPath & outputDir){ | |
| 216 | 3 | bool b(true); | |
| 217 |
2/2✓ Branch 0 (16→3) taken 3 times.
✓ Branch 1 (16→17) taken 3 times.
|
12 | for(PVecSource::iterator it(vecSource.begin()); it != vecSource.end(); ++it){ |
| 218 |
1/1✓ Branch 0 (5→6) taken 3 times.
|
3 | b &= cpp_backend(*it, libName, outputDir); |
| 219 | } | ||
| 220 | 3 | return b; | |
| 221 | } | ||
| 222 | |||
| 223 |