Parsing types from in-memory strings

The goal was to parse a type from an llvm specified type string, e.g., i8* into Type::getInt8PtrTy. The solution is to use llvm::parseType(tystr, smd, M) where tystr is something that is like a const char *. It will contain the type description string. smd is an instance of SMDiagnostic and M is the Module which owns context in which the type will be defined. E.g.,:

Type* makeType(const char* tystr, Module& M) {
  SMDiagnostic smd;
  return llvm::parseType(rettype, smd, M);
// makeType("i8*", M) will return the same thing as Type::getInt8PtrTy(M.getContext());

Original Question posted to newsgroup

For various reasons I want to be able to use the LLParser machinery to create Type objects. So, I need to create an LLParser which will parse a string, instead of a reading it from a file. If I was doing this in clang, then I think I would need to use an instance of InMemoryFileSystem which inherits from FileSystem. However, I want to do this in an llvm pass. Any suggestions?