【发布时间】:2015-11-15 16:07:59
【问题描述】:
我正在编写一个函数传递,并想在初始化阶段添加一个 int 类型的全局变量,以用于传递的实际工作。
到目前为止,我已经
bool doInitialization(Module &M) {
LLVMContext &c = M.getContext();
Type *intTy = TypeBuilder<int,false>::get(c);
Value *p = M.getOrInsertGlobal("var1",intTy);
return true
}
无论出于何种原因,var1 的类型为 int*。例如,在声明之后添加这个
Type *pt = p->getType();
if (isa<PointerType>(pt)) {
errs().write_escaped("Is a pointer ty") << '\n';
}
运行编译后的代码时会打印出来,并且
if ((intTy->getPointerTo()) == (p->getType())) {
errs().write_escaped("This is confusing") << '\n';
}
将再次打印字符串。
是否可以使用此方法添加 int 类型的全局变量,如果可以,我哪里出错了?
【问题讨论】:
标签: c++ c compiler-construction llvm compiler-optimization