MCPcopy Create free account
hub / github.com/chigraph/chigraph / codegen

Method codegen

libchigraph/src/GraphModule.cpp:194–273  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

192 }
193
194 Result codegen(
195 size_t /*inID*/, const llvm::DebugLoc& nodeLocation, const std::vector<llvm::Value*>& io,
196 llvm::BasicBlock* codegenInto, const std::vector<llvm::BasicBlock*>& outputBlocks,
197 std::unordered_map<std::string, std::shared_ptr<void>>& /*compileCache*/) override {
198 assert(io.size() == dataInputs().size() + dataOutputs().size() && codegenInto != nullptr &&
199 outputBlocks.size() == 1);
200
201 Result res;
202
203 // compile the c code if it hasn't already been compiled
204 if (llcompiledmod == nullptr) {
205 auto args = mExtraArguments;
206
207 // add -I for the .c dir
208 args.push_back("-I");
209 args.push_back(mGraphModule->pathToCSources().string());
210
211 llcompiledmod = compileCCode(llvm::sys::fs::getMainExecutable(nullptr, nullptr).c_str(),
212 mCCode, args, context().llvmContext(), res);
213
214 if (!res) { return res; }
215 }
216
217 // create a copy of the module
218 auto copymod = llvm::CloneModule(llcompiledmod.get());
219
220 // link it in
221
222 auto parentModule = codegenInto
223 ->
224#if LLVM_VERSION_LESS_EQUAL(3, 6)
225 getParent()
226 ->getParent()
227#else
228 getModule()
229#endif
230 ;
231
232#if LLVM_VERSION_LESS_EQUAL(3, 7)
233 llvm::Linker::LinkModules(parentModule, copymod
234#if LLVM_VERSION_LESS_EQUAL(3, 5)
235 ,
236 llvm::Linker::DestroySource, nullptr
237#endif
238 );
239#else
240 llvm::Linker::linkModules(*parentModule, std::move(copymod));
241#endif
242
243 parentModule->setDataLayout("");
244
245 auto llfunc = parentModule->getFunction(mFunctionName);
246 assert(llfunc != nullptr);
247
248 llvm::IRBuilder<> builder(codegenInto);
249
250 size_t ioSize = io.size();
251

Callers 1

codegenNodeFunction · 0.45

Calls 4

compileCCodeFunction · 0.85
pathToCSourcesMethod · 0.80
c_strMethod · 0.80
getMethod · 0.80

Tested by

no test coverage detected