| 594 | } |
| 595 | |
| 596 | Result GraphModule::generateModule(llvm::Module& module) { |
| 597 | Result res = {}; |
| 598 | |
| 599 | // if C support was enabled, compile the C files |
| 600 | if (cEnabled()) { |
| 601 | fs::path cPath = pathToCSources(); |
| 602 | if (fs::is_directory(cPath)) { |
| 603 | // compile the files |
| 604 | for (auto direntry : boost::make_iterator_range( |
| 605 | fs::recursive_directory_iterator{cPath, fs::symlink_option::recurse}, {})) { |
| 606 | const fs::path& CFile = direntry; |
| 607 | |
| 608 | if (!fs::is_regular_file(CFile) || |
| 609 | !(CFile.extension() == ".c" || CFile.extension() == ".C" || |
| 610 | CFile.extension() == ".cpp" || CFile.extension() == ".cxx" || |
| 611 | CFile.extension() == ".c++" || CFile.extension() == ".cc")) { |
| 612 | continue; |
| 613 | } |
| 614 | |
| 615 | // compile it |
| 616 | auto generatedModule = |
| 617 | compileCCode(llvm::sys::fs::getMainExecutable(nullptr, nullptr).c_str(), "", |
| 618 | {CFile.string()}, context().llvmContext(), res); |
| 619 | |
| 620 | if (!res) { return res; } |
| 621 | |
| 622 | // link it |
| 623 | |
| 624 | #if LLVM_VERSION_LESS_EQUAL(3, 7) |
| 625 | llvm::Linker::LinkModules(&module, generatedModule.get() |
| 626 | #if LLVM_VERSION_LESS_EQUAL(3, 5) |
| 627 | , |
| 628 | llvm::Linker::DestroySource, nullptr |
| 629 | #endif |
| 630 | ); |
| 631 | #else |
| 632 | llvm::Linker::linkModules(module, std::move(generatedModule)); |
| 633 | #endif |
| 634 | } |
| 635 | } |
| 636 | } |
| 637 | |
| 638 | // debug info |
| 639 | llvm::DIBuilder debugBuilder(module); |
| 640 | |
| 641 | auto compileUnit = debugBuilder.createCompileUnit(llvm::dwarf::DW_LANG_C, |
| 642 | #if LLVM_VERSION_LESS_EQUAL(3, 9) |
| 643 | sourceFilePath().filename().string(), |
| 644 | sourceFilePath().parent_path().string(), |
| 645 | #else |
| 646 | debugBuilder.createFile( |
| 647 | sourceFilePath().filename().string(), |
| 648 | sourceFilePath().parent_path().string()), |
| 649 | #endif |
| 650 | "Chigraph Compiler", false, "", 0); |
| 651 | |
| 652 | // create prototypes |
| 653 | addForwardDeclarations(module); |
nothing calls this directly
no test coverage detected