2
votes

I am looking to create an LLVM Module from existing LLVM IR code.

The two methods I have found are the following:

  • ParseIRFile - This accepts a file name and generates a module
  • ParseIR - This accepts MemoryBuffer and generates a module

I want to create a Module when the LLVM IR is already read to a string as an std::string or const char *.

Is there a way to convert an IR string to llvm::MemoryBuffer ?

1

1 Answers

4
votes

I figured this out with the help of a colleague.

This is how you would do it:

std::string IRString = readfile("add.ll");
MemoryBuffer *mem = MemoryBuffer::getMemBuffer(IRString);