2012-02-24 48 views

回答

4

如果你的意思i8**(指針指向i8),則:

// This creates the i8* type 
PointerType* PointerTy = PointerType::get(IntegerType::get(mod->getContext(), 8), 0); 
// This creates the i8** type 
PointerType* PointerPtrTy = PointerType::get(PointerTy, 0); 

如果你需要一個指向函數返回什麼,並採取i8*,則:

// This creates the i8* type 
PointerType* PointerTy = PointerType::get(IntegerType::get(mod->getContext(), 8), 0); 

// Create a function type. Its argument types are passed as a vector 
std::vector<Type*>FuncTy_args; 
FuncTy_args.push_back(PointerTy);     // one argument: char* 
FunctionType* FuncTy = FunctionType::get(
    /*Result=*/Type::getVoidTy(mod->getContext()), // returning void 
    /*Params=*/FuncTy_args,       // taking those args 
    /*isVarArg=*/false); 

// Finally this is the pointer to the function type described above 
PointerType* PtrToFuncTy = PointerType::get(FuncTy, 0); 

更通用的答案是:您可以使用LLVM C++ API後端生成創建任何類型IR所需的C++代碼。這可以方便地通過在線LLVM演示完成 - http://llvm.org/demo/ - 這是我爲此答案生成代碼的方式。