GlobalVariable *createGlob(Type *type, std::string name) { TheModule->getOrInsertGlobal(name, type); GlobalVariable *gVar = TheModule->getNamedGlobal(name); return gVar; } 设置初始值 GlobalVariable *gVar = createGlob(Builder->getInt32Ty(), "variable"); gVar->setInitializer(Builder->getIn...
// llvm-6.0/include/llvm/IR/GlobalObject.h:64函数 void setAlignment(unsigned Align),参数是unsigned int即可 gv->setAlignment(4); Type *voidTy = Type::getVoidTy(c); /*函数在 include/llvm/IR/DerivedTypes.h:102:class FunctionType : public Type { /// Create a FunctionType taking no parame...
globalVariable->setAlignment(MaybeAlign(4)); // Add a function Type* voidType = Type::getVoidTy(context); FunctionType* functionType = FunctionType::get(voidType, false); Function* function = Function::Create(functionType, GlobalValue::ExternalLinkage, "HelloFunction", module); // Create a...
GlobalVariable *GV = dyn_cast_or_null<GlobalVariable>(getNamedValue(Name)); if (!GV) GV = CreateGlobalCallback(); assert(GV && "The CreateGlobalCallback is expected to create a global"); // If the variable exists but has the wrong type, return a bitcast to the // right type. ...
llvm::GlobalVariable* variable = module->getGlobalVariable(loop->getStart().get()->getTarget()); llvm::Function *forLoop = builder->GetInsertBlock()->getParent(); llvm::BasicBlock *loopBody = llvm::BasicBlock::Create(llvmContext, "loop", forLoop); ...
llvm::BasicBlock *entry = llvm::BasicBlock::Create(context, "entrypoint", mainFunc); builder.SetInsertPoint(entry); llvm::Value *helloWorld = builder.CreateGlobalStringPtr("hello world!\n"); module->dump( ); } 在清单 9的输出中,注意 LLVM 引擎是如何转储字符串的: ...
// Create a new LLVM IR module. m := ir.NewModule() // Create an external function declaration and append it to the module. // // int abs(int x); abs := m.NewFunc("abs", i32, ir.NewParam("x", i32)) // Create a global variable definition and append it to the module. ...
ScalarType())->getElementType(),EncGVAddr,X);GVAddr=IRB.CreateBitCast(GVAddr,GV->getType());GVAddr->setName("IndGV");Inst->replaceUsesOfWith(GV,GVAddr);}}}else{for(User::op_iteratorop=Inst->op_begin();op!=Inst->op_end();++op){if(GlobalVariable*GV=dyn_cast<GlobalVariable>(*...
BasicBlock *forEnd = BasicBlock::Create(*CONTEXT, "for.inc", func); 首先获取func的EntryBasicBlock,然后初始化循环变量。 IRBuilder<> builder(*CONTEXT); builder.SetInsertPoint(entry); AllocaInst *indexPtr = builder.CreateAlloca(TYPE_I32, CONST_I32(1), "i")...
用BinaryOperator::CreateXor解密字符 new StoreInst存储解密字符到Alloc 测试 可加密所有类型的ANSI字符串,...