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 に答える