Fwd: Extending Kaleidoscope to support Strings

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Fwd: Extending Kaleidoscope to support Strings

Richard Catlin
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<PointerType>(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.

Richard Catlin

LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu