1

我正在尝试编写一个简单的解释器。

我正在尝试为分配操作生成 LLVM IR。生成部分的代码如下所示

llvm::Value* codeGenSymTab(llvm::LLVMContext& context) {
    printf("\n CodeGen SymTab \n");
    Value *num = ConstantInt::get(Type::getInt64Ty(context), aTable.value, true);
    Value *alloc = new AllocaInst(IntegerType::get(context, 32), aTable.variableName,entry);
    StoreInst *ptr = new StoreInst(num,alloc,false,entry);
}

SymTab 定义如下:

struct SymTab {
     char* variableName;
     int value; 
     llvm::Value* (*codeGen)(llvm::LLVMContext& context);   
}; 

当我尝试执行输出文件时,出现以下错误:

Assertion failed: (getOperand(0)->getType() == cast<PointerType>(getOperand(1)->getType())->getElementType() && "Ptr must be a pointer to Val type!"), function AssertOK, file Instructions.cpp, line 1084.
Abort trap: 6

你能帮我解决吗?

谢谢

4

1 回答 1

4

您尝试将 type 的值存储到 typei64的地址中i32*,但这些不匹配。

您可以通过使用相同的类型来解决此问题 - 或者最好使用实际相同的对象:

IntegerType *int_type = Type::getInt64Ty(context);
Value *num = ConstantInt::get(int_type, aTable.value, true);
Value *alloc = new AllocaInst(int_type, aTable.variableName, entry);
StoreInst *ptr = new StoreInst(num,alloc,false,entry);
于 2014-08-04T13:32:28.380 回答