【发布时间】:2019-07-01 21:30:50
【问题描述】:
我刚开始学习 LLVM C++ API,对如何进行类型检查有点困惑。我的导师向我提供了一个关于在堆栈内存中存储变量的示例,如下所示:
llvm::AllocaInst *Alloca;
Alloca = llvm::Builder.CreateAlloca(llvm::IntegerType::get(getGlobalContext(), 32), nullptr, "variable_name");
我明白这一点,但在下一部分中,它将讨论在为变量赋值之前进行类型检查。 To assign a value in a Decaf statement of the type lvalue = rvalue you should get the location of lvalue from the symbol table. You can check the type of rvalue using the following API call:
const llvm::PointerType *ptrTy = rvalue->getType()->getPointerTo();
ptrTy == Alloca->getType()
我完全不明白为什么要进行类型检查。我已阅读文档,getPointerTo 返回一个 PointerType 对象。所以我的第一个问题是,Alloca 的 Type 对象是 IntegerType,那我们为什么要创建 PointerType 的对象呢?这对我来说似乎完全超出了左领域。
我的第二个问题是,为什么我们要将此 PointerType 对象与作为 IntegerType 对象的 Alloca Type 对象进行比较?是否存在某种 == 运算符重载?因为我正在搜索文档,但找不到任何文档。
【问题讨论】:
标签: llvm llvm-c++-api