| 1027 | } |
| 1028 | |
| 1029 | Result GraphModule::createNodeTypeFromCCode(boost::string_view code, |
| 1030 | boost::string_view functionName, |
| 1031 | std::vector<std::string> clangArgs, |
| 1032 | std::unique_ptr<NodeType>* toFill) { |
| 1033 | assert(toFill != nullptr); |
| 1034 | |
| 1035 | Result res; |
| 1036 | |
| 1037 | // add -I for the .c dir |
| 1038 | clangArgs.push_back("-I"); |
| 1039 | clangArgs.push_back(pathToCSources().string()); |
| 1040 | |
| 1041 | auto mod = compileCCode(llvm::sys::fs::getMainExecutable(nullptr, nullptr).c_str(), code, |
| 1042 | clangArgs, context().llvmContext(), res); |
| 1043 | |
| 1044 | if (!res) { return res; } |
| 1045 | |
| 1046 | auto llFunc = mod->getFunction(functionName.to_string()); |
| 1047 | |
| 1048 | if (llFunc == nullptr) { |
| 1049 | res.addEntry("EUKN", "Failed to find function in C code", |
| 1050 | {{"Function Name", functionName.to_string()}, {"C Code", code.to_string()}}); |
| 1051 | return res; |
| 1052 | } |
| 1053 | |
| 1054 | std::vector<NamedDataType> dInputs; |
| 1055 | for (const auto& argument : llFunc->args()) { |
| 1056 | DataType ty; |
| 1057 | context().typeFromModule("lang", stringifyLLVMType(argument.getType()), &ty); |
| 1058 | dInputs.emplace_back(argument.getName(), ty); |
| 1059 | } |
| 1060 | |
| 1061 | DataType output; |
| 1062 | auto ret = llFunc->getReturnType(); |
| 1063 | |
| 1064 | if (!ret->isVoidTy()) { context().typeFromModule("lang", stringifyLLVMType(ret), &output); } |
| 1065 | |
| 1066 | *toFill = std::make_unique<CFuncNode>(*this, code.to_string(), functionName.to_string(), |
| 1067 | clangArgs, dInputs, output); |
| 1068 | |
| 1069 | return res; |
| 1070 | } |
| 1071 | |
| 1072 | } // namespace chi |
nothing calls this directly
no test coverage detected