Extending Kaleidoscope to support Strings

I hope this is the right place to ask this question. If not, please let me know where I can ask for help.

We are using Kaleidoscope as the base framework to write a source to source compiler. Our source language has Strings with supported operations such as concatenation, upper case, and substrings.

I am following the patterns set forth in Kaleidoscope, and need to represent my std::string as a Value *.

I have:

Value *StringExprAST::Codegen() {
StringRef r(Val); // Val is a std::string captured by the parser
return ConstantDataArray::getString(getGlobalContext(), r);
}

For a test string of “Hello World!”, I am trying to create an Alloca * and store the InitVal, which I get from codegen of StringExprAST.

uint64_t v(13);
APInt d(8, v);
Value * ArraySize = ConstantInt::get(getGlobalContext(), d);
Alloca = CreateEntryBlockAllocaString(TheFunction, VarName, ArraySize);
Builder.CreateStore(InitVal, Alloca);

I get the following error:

tok_string: “Hello World!”
Assertion failed: (getOperand(0)->getType() == cast(getOperand(1)->getType())->getElementType() && “Ptr must be a pointer to Val type!”), function AssertOK, file /Users/rcatlin1/lldb/llvm/lib/IR/Instructions.cpp, line 1089.

Thanks for any guidance.

Regards,
Richard Catlin