I am writing a piece of code that recognizes certain patterns at the machine function level of the LLVM stack. I would like to write a test driver for this component. The test driver would need to create a snippet of machine code and pass an instruction pointer to my matcher:
MachineInstruction* mi = createSnipit(...);
bool result = matcher(mi, ...);
ASSERT_TRUE(result);
If this were not a stand-alone test driver, creating a new instruction or set of instructions in a specific basic-block would be easy. However, the test driver is a stand-alone program and is not invoked from the compiler. Somehow, it seems, I need to create a machine function, a basic block, and an instance of MachineRegisterInfo before I can create any instructions. How do I do that so that everything is correctly linked up and the LLVM infrastructure is in a consistent state?