Skip to content

Commit

Permalink
Fix older llvm vers
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanradanov committed Feb 27, 2024
1 parent caf46d5 commit e66aef3
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions enzyme/tools/enzyme-tblgen/enzyme-tblgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1277,13 +1277,23 @@ static void emitHeaderIncludes(const RecordKeeper &recordKeeper,
auto filename_out = pattern->getValueAsString("filename_out");
std::string filename_in = pattern->getValueAsString("filename_in").str();
std::string included_file;
auto contents = llvm::SrcMgr.OpenIncludeFile(filename_in, included_file);
// llvm::MemoryBuffer::getFile(filename_in, /*IsText=*/true);
if (!contents)
#if LLVM_VERSION_MAJOR >= 15
auto contents_or_err =
llvm::SrcMgr.OpenIncludeFile(filename_in, included_file);
if (!contents_or_err)
PrintFatalError(pattern->getLoc(),
Twine("Could not read file ") + filename_in);
auto &contents = contents_or_err.get();
#else
auto buf = llvm::SrcMgr.AddIncludeFile(
filename_in, pattern->getFieldLoc("filename_in"), included_file);
if (!buf)
PrintFatalError(pattern->getLoc(),
Twine("Could not read file ") + filename_in);
auto contents = llvm::SrcMgr.getMemoryBuffer(buf);
#endif
os << "{\"" << filename_out << "\"\n,";
os << "R\"(" << contents.get()->getBuffer() << ")\"\n";
os << "R\"(" << contents->getBuffer() << ")\"\n";
os << "}";
seen = true;
}
Expand Down

0 comments on commit e66aef3

Please sign in to comment.