当前位置: 首页>>代码示例>>C++>>正文


C++ arg_iterator::setName方法代码示例

本文整理汇总了C++中function::arg_iterator::setName方法的典型用法代码示例。如果您正苦于以下问题:C++ arg_iterator::setName方法的具体用法?C++ arg_iterator::setName怎么用?C++ arg_iterator::setName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在function::arg_iterator的用法示例。


在下文中一共展示了arg_iterator::setName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Function_new

    ejsval
    Module_prototype_getOrInsertFunction(ejsval env, ejsval _this, int argc, ejsval *args)
    {
        Module *module = ((Module*)EJSVAL_TO_OBJECT(_this));

        REQ_UTF8_ARG(0, name);
        REQ_LLVM_TYPE_ARG(1, returnType);
        REQ_ARRAY_ARG(2, paramTypes);

        std::vector< llvm::Type*> param_types;
        for (int i = 0; i < EJSARRAY_LEN(paramTypes); i ++) {
            param_types.push_back (Type_GetLLVMObj(EJSDENSEARRAY_ELEMENTS(paramTypes)[i]));
        }

        llvm::FunctionType *FT = llvm::FunctionType::get(returnType, param_types, false);

        llvm::Function* f = static_cast< llvm::Function*>(module->llvm_module->getOrInsertFunction(name, FT));

        // XXX this needs to come from the js call, since when we hoist anonymous methods we'll need to give them a private linkage.
        f->setLinkage (llvm::Function::ExternalLinkage);

        // XXX the args might not be identifiers but might instead be destructuring expressions.  punt for now.

#if notyet
        // Set names for all arguments.
        unsigned Idx = 0;
        for (Function::arg_iterator AI = F->arg_begin(); Idx != Args.size();
             ++AI, ++Idx)
            AI->setName(Args[Idx]);
#endif

        return Function_new (f);
    }
开发者ID:guangwong,项目名称:echojs,代码行数:33,代码来源:module.cpp

示例2: Doubles

Function *PrototypeAST::Codegen() {
  // Make the function type:  double(double,double) etc.
  std::vector<Type *> Doubles(Args.size(), Type::getDoubleTy(TheContext));
  FunctionType *FT =
      FunctionType::get(Type::getDoubleTy(TheContext), Doubles, false);

  Function *F = Function::Create(FT, Function::ExternalLinkage, Name, TheModule);
  // If F conflicted, there was already something named 'Name'.  If it has a
  // body, don't allow redefinition or reextern.
  if (F->getName() != Name) {
    // Delete the one we just made and get the existing one.
    F->eraseFromParent();
    F = TheModule->getFunction(Name);
    // If F already has a body, reject this.
    if (!F->empty()) {
      ErrorF("redefinition of function");
      return 0;
    }
    // If F took a different number of args, reject.
    if (F->arg_size() != Args.size()) {
      ErrorF("redefinition of function with different # args");
      return 0;
    }
  }

  // Set names for all arguments.
  unsigned Idx = 0;
  for (Function::arg_iterator AI = F->arg_begin(); Idx != Args.size();
       ++AI, ++Idx)
    AI->setName(Args[Idx]);
    
  return F;
}
开发者ID:1995hnagamin,项目名称:llvm,代码行数:33,代码来源:toy-jit.cpp

示例3: Codegen_Function_Declaration

Function* Codegen_Function_Declaration(project473::AstNodePtr declaration_node) {
  char* fname = strdup(declaration_node->nSymbolPtr->id); 
  std::string Name(fname);
  std::vector<Type*> formalvars;
  project473::AstNodePtr formalVar = declaration_node->children[0]; 
  while(formalVar) { 
    if(formalVar->nSymbolPtr->stype->kind == project473::INT) {
      formalvars.push_back(Type::getInt32Ty(getGlobalContext()));
      formalVar=formalVar->sibling;
    }
    else {
      printf("Error, formal variable is not an int, in line: %d", formalVar->nLinenumber);
    }
  }
  project473::Type* functionTypeList = declaration_node->nSymbolPtr->stype->function;
  FunctionType *FT;
  if(functionTypeList->kind==project473::INT) { 
     FT = FunctionType::get(Type::getInt32Ty(getGlobalContext()), formalvars, false);
  }
  else if(functionTypeList->kind==project473::VOID) {
    FT = FunctionType::get(Type::getVoidTy(getGlobalContext()), formalvars, false);
  }

  Function *F = Function::Create(FT, Function::ExternalLinkage, Name, TheModule);
  // Set names for all arguments. Reuse formalVar
  formalVar = declaration_node->children[0];
  for (Function::arg_iterator AI = F->arg_begin(); formalVar != NULL; ++AI, formalVar=formalVar->sibling) {
          std::string argName(formalVar->nSymbolPtr->id);
          AI->setName(argName);
  }
  Functions[Name] = F; //add the Function to the map of functions
  return F;
}
开发者ID:mxwang,项目名称:hw6_473,代码行数:33,代码来源:codegen.cpp

示例4: Doubles

Function *Codegen::Generate(PrototypeAST *proto) {
	string funcName = proto->GetName();
	vector<string> args = proto->GetArgs();

	vector<Type*> Doubles(args.size(), Type::getDoubleTy(getGlobalContext()));
	FunctionType *funcType = FunctionType::get(
			Type::getDoubleTy(getGlobalContext()), Doubles, false);
	Function* func = Function::Create(funcType, Function::ExternalLinkage,
			funcName, TheModule);

	if (func->getName() != funcName) {
		func->eraseFromParent();
		func = TheModule->getFunction(funcName);

		if ( !func->empty()) {
			BaseError::Throw<Function*>("Redefinition of function");
			return 0;
		}

		if (func->arg_size() != args.size()) {
			BaseError::Throw<Function*>("Redefinition of function with wrong number of arguments");
			return 0;
		}
	}

	unsigned idx = 0;
	for (Function::arg_iterator iterItem = func->arg_begin(); idx != args.size(); ++iterItem, ++idx) {
		iterItem->setName(args[idx]);
	}

	return func;
}
开发者ID:altschuler,项目名称:cmplr,代码行数:32,代码来源:Codegen.cpp

示例5: CloneFunctionInto

/// CloneFunction - Return a copy of the specified function, but without
/// embedding the function into another module.  Also, any references specified
/// in the VMap are changed to refer to their mapped value instead of the
/// original one.  If any of the arguments to the function are in the VMap,
/// the arguments are deleted from the resultant function.  The VMap is
/// updated to include mappings from all of the instructions and basicblocks in
/// the function from their old to new values.
///
Function *llvm::CloneFunction(const Function *F, ValueToValueMapTy &VMap,
                              bool ModuleLevelChanges,
                              ClonedCodeInfo *CodeInfo) {
  std::vector<Type*> ArgTypes;

  // The user might be deleting arguments to the function by specifying them in
  // the VMap.  If so, we need to not add the arguments to the arg ty vector
  //
  for (Function::const_arg_iterator I = F->arg_begin(), E = F->arg_end();
       I != E; ++I)
    if (VMap.count(I) == 0)  // Haven't mapped the argument to anything yet?
      ArgTypes.push_back(I->getType());

  // Create a new function type...
  FunctionType *FTy = FunctionType::get(F->getFunctionType()->getReturnType(),
                                    ArgTypes, F->getFunctionType()->isVarArg());

  // Create the new function...
  Function *NewF = Function::Create(FTy, F->getLinkage(), F->getName());

  // Loop over the arguments, copying the names of the mapped arguments over...
  Function::arg_iterator DestI = NewF->arg_begin();
  for (Function::const_arg_iterator I = F->arg_begin(), E = F->arg_end();
       I != E; ++I)
    if (VMap.count(I) == 0) {   // Is this argument preserved?
      DestI->setName(I->getName()); // Copy the name over...
      VMap[I] = DestI++;        // Add mapping to VMap
    }

  SmallVector<ReturnInst*, 8> Returns;  // Ignore returns cloned.
  CloneFunctionInto(NewF, F, VMap, ModuleLevelChanges, Returns, "", CodeInfo);
  return NewF;
}
开发者ID:RCSL-HKUST,项目名称:heterosim,代码行数:41,代码来源:CloneFunction.cpp

示例6: visit

void IrGen::visit(AstFunDef& funDef) {
  const auto functionIr =
    static_cast<llvm::Function*>(funDef.ir().irAddrOfIrObject());
  assert(functionIr);

  if (m_builder.GetInsertBlock()) {
    m_BasicBlockStack.push(m_builder.GetInsertBlock());
  }
  m_builder.SetInsertPoint(
    BasicBlock::Create(llvmContext, "entry", functionIr));

  // Add all arguments to the symbol table and create their allocas. Also tell
  // llvm the name of each arg.
  Function::arg_iterator llvmArgIter = functionIr->arg_begin();
  auto astArgIter = funDef.declaredArgs().cbegin();
  for (/*nop*/; llvmArgIter != functionIr->arg_end();
       ++llvmArgIter, ++astArgIter) {
    allocateAndInitLocalIrObjectFor(
      **astArgIter, llvmArgIter, (*astArgIter)->name());
    llvmArgIter->setName((*astArgIter)->name());
  }

  Value* bodyVal = callAcceptOn(funDef.body());
  assert(bodyVal);
  if (funDef.body().objType().isVoid()) { m_builder.CreateRetVoid(); }
  else if (!funDef.body().objType().isNoreturn()) {
    m_builder.CreateRet(bodyVal);
  }

  if (!m_BasicBlockStack.empty()) {
    m_builder.SetInsertPoint(m_BasicBlockStack.top());
    m_BasicBlockStack.pop();
  }
}
开发者ID:,项目名称:,代码行数:34,代码来源:

示例7: CloneFunctionInto

// Maybe make a clone, if a clone is made, return a pointer to it, if a clone
// was not made return nullptr.
Function *CSDataRando::makeFunctionClone(Function *F) {
  // Now we know how many arguments need to be passed, so we make the clones
  FuncInfo &FI = FunctionInfo[F];
  if (FI.ArgNodes.size() == 0) {
    // No additional args to pass, no need to clone.
    return nullptr;
  }
  // Determine the type of the new function, we insert the new parameters for
  // the masks after the normal arguments, but before any va_args
  Type *MaskTy = TypeBuilder<mask_t, false>::get(F->getContext());
  FunctionType *OldFuncTy = F->getFunctionType();
  std::vector<Type*> ArgTys;
  ArgTys.insert(ArgTys.end(), OldFuncTy->param_begin(), OldFuncTy->param_end());
  ArgTys.insert(ArgTys.end(), FI.ArgNodes.size(), MaskTy);
  FunctionType *CloneFuncTy = FunctionType::get(OldFuncTy->getReturnType(), ArgTys, OldFuncTy->isVarArg());

  Function *Clone = Function::Create(CloneFuncTy, Function::InternalLinkage, F->getName() + "_CONTEXT_SENSITIVE");
  F->getParent()->getFunctionList().insert(F->getIterator(), Clone);

  Function::arg_iterator CI = Clone->arg_begin(), CE = Clone->arg_end();

  // Map the old arguments to the clone arguments and set the name of the
  // clone arguments the same as the original.
  for (Function::arg_iterator i = F->arg_begin(), e = F->arg_end(); i != e && CI != CE; i++, CI++) {
    FI.OldToNewMap[&*i] = &*CI;
    CI->setName(i->getName());
  }

  // Set the name of the arg masks and associate them with the nodes they are
  // the masks for.
  for (unsigned i = 0, e = FI.ArgNodes.size(); i != e; ++i, ++CI) {
    CI->setName("arg_mask");
    FI.ArgMaskMap[FI.ArgNodes[i]] = &*CI;
  }

  SmallVector<ReturnInst*, 8> Returns;
  CloneFunctionInto(Clone, F, FI.OldToNewMap, false, Returns);
  Clone->setCallingConv(F->getCallingConv());

  // Invert OldToNewMap
  for (auto I : FI.OldToNewMap) {
    FI.NewToOldMap[I.second] = I.first;
  }

  NumClones++;
  return Clone;
}
开发者ID:securesystemslab,项目名称:multicompiler,代码行数:49,代码来源:CSDataRando.cpp

示例8: SP

 virtual Value * materializeValueFor(Value * V) {
     if(Function * fn = dyn_cast<Function>(V)) {
         assert(fn->getParent() == src);
         Function * newfn = dest->getFunction(fn->getName());
         if(!newfn) {
             newfn = Function::Create(fn->getFunctionType(),fn->getLinkage(), fn->getName(),dest);
             newfn->copyAttributesFrom(fn);
         }
         if(!fn->isDeclaration() && newfn->isDeclaration() && copyGlobal(fn,data)) {
             for(Function::arg_iterator II = newfn->arg_begin(), I = fn->arg_begin(), E = fn->arg_end(); I != E; ++I, ++II) {
                 II->setName(I->getName());
                 VMap[I] = II;
             }
             VMap[fn] = newfn;
             SmallVector<ReturnInst*,8> Returns;
             CloneFunctionInto(newfn, fn, VMap, true, Returns, "", NULL, NULL, this);
         }
         return newfn;
     } else if(GlobalVariable * GV = dyn_cast<GlobalVariable>(V)) {
         GlobalVariable * newGV = dest->getGlobalVariable(GV->getName(),true);
         if(!newGV) {
             newGV = new GlobalVariable(*dest,GV->getType()->getElementType(),GV->isConstant(),GV->getLinkage(),NULL,GV->getName(),NULL,GlobalVariable::NotThreadLocal,GV->getType()->getAddressSpace());
             newGV->copyAttributesFrom(GV);
             if(!GV->isDeclaration()) {
                 if(!copyGlobal(GV,data)) {
                     newGV->setExternallyInitialized(true);
                 } else if(GV->hasInitializer()) {
                     Value * C = MapValue(GV->getInitializer(),VMap,RF_None,NULL,this);
                     newGV->setInitializer(cast<Constant>(C));
                 }
             }
         }
         return newGV;
     } else if(MDNode * MD = dyn_cast<MDNode>(V)) {
         DISubprogram SP(MD);
         if(DI != NULL && SP.isSubprogram()) {
             
             if(Function * OF = SP.getFunction()) {
                 Function * F = cast<Function>(MapValue(OF,VMap,RF_None,NULL,this));
                 DISubprogram NSP = DI->createFunction(SP.getContext(), SP.getName(), SP.getLinkageName(),
                                                   DI->createFile(SP.getFilename(),SP.getDirectory()),
                                                   SP.getLineNumber(), SP.getType(),
                                                   SP.isLocalToUnit(), SP.isDefinition(),
                                                   SP.getScopeLineNumber(),SP.getFlags(),SP.isOptimized(),
                                                   F);
                 return NSP;
             }
             /* fallthrough */
         }
         /* fallthrough */
     }
     return NULL;
 }
开发者ID:0----0,项目名称:terra,代码行数:53,代码来源:tllvmutil.cpp

示例9: Doubles

Function *PrototypeAST::Codegen(Function*& preexistingPrototype /*out*/) {
  preexistingPrototype = NULL;

  // Make the function type:  double(double,double) etc.
  std::vector<const Type*> Doubles(Args.size(),
                                   Type::getDoubleTy(getGlobalContext()));
  FunctionType *FT = FunctionType::get(Type::getDoubleTy(getGlobalContext()),
                                       Doubles, false);
  
  Function *F = Function::Create(FT, Function::ExternalLinkage, Name, TheModule);

  
  // If F conflicted, there was already something named 'Name'.  If it has a
  // body, don't allow redefinition or reextern.
  if (F->getName() != Name) {

    // Delete the one we just made and get the existing one.
    F->eraseFromParent();
    F = TheModule->getFunction(Name);

    // If F already has a body, reject this.
    if (!F->empty()) {
      ErrorF("redefinition of function");
      return 0;
    }
    
    // If F took a different number of args, reject.
    if (F->arg_size() != Args.size()) {
      ErrorF("redefinition of function with different # args");
      return 0;
    }

    // if there is a preexisting prototype only -- without a body -- and with matching args
    // then inform caller of this, so that the FunctionAST::Codegen can not accidentally
    // delete it on body compilation failure.
    preexistingPrototype = F;
    //    printf("There was a pre-existing prototype for this function-- noting this fact: %p\n",preexistingPrototype);
  }
  
  // Set names for all arguments.
  unsigned Idx = 0;
  for (Function::arg_iterator AI = F->arg_begin(); Idx != Args.size();
       ++AI, ++Idx) {
    AI->setName(Args[Idx]);
    
    // Add arguments to variable symbol table.
    NamedValues[Args[Idx]] = AI;
  }
  
  return F;
}
开发者ID:glycerine,项目名称:L3,代码行数:51,代码来源:compiler.cpp

示例10: copyFunctionBody

void llvm::copyFunctionBody(Function &New, const Function &Orig,
                            ValueToValueMapTy &VMap) {
  if (!Orig.isDeclaration()) {
    Function::arg_iterator DestI = New.arg_begin();
    for (Function::const_arg_iterator J = Orig.arg_begin(); J != Orig.arg_end();
         ++J) {
      DestI->setName(J->getName());
      VMap[J] = DestI++;
    }

    SmallVector<ReturnInst *, 8> Returns; // Ignore returns cloned.
    CloneFunctionInto(&New, &Orig, VMap, /*ModuleLevelChanges=*/true, Returns);
  }
}
开发者ID:A2-Collaboration,项目名称:root,代码行数:14,代码来源:CloneSubModule.cpp

示例11: Doubles

Function *PrototypeAST::Codegen() {
  // Make the function type:  double(double,double) etc.
  std::vector<Type *> Doubles(Args.size(),
                              Type::getDoubleTy(getGlobalContext()));
  FunctionType *FT =
      FunctionType::get(Type::getDoubleTy(getGlobalContext()), Doubles, false);

  Function *F =
      Function::Create(FT, Function::ExternalLinkage, Name, TheModule);

  // If F conflicted, there was already something named 'Name'.  If it has a
  // body, don't allow redefinition or reextern.
  if (F->getName() != Name) {
    // Delete the one we just made and get the existing one.
    F->eraseFromParent();
    F = TheModule->getFunction(Name);

    // If F already has a body, reject this.
    if (!F->empty()) {
      ErrorF("redefinition of function");
      return 0;
    }

    // If F took a different number of args, reject.
    if (F->arg_size() != Args.size()) {
      ErrorF("redefinition of function with different # args");
      return 0;
    }
  }

  // Set names for all arguments.
  unsigned Idx = 0;
  for (Function::arg_iterator AI = F->arg_begin(); Idx != Args.size();
       ++AI, ++Idx)
    AI->setName(Args[Idx]);

  // Create a subprogram DIE for this function.
  DIFile Unit = DBuilder->createFile(KSDbgInfo.TheCU->getFilename(),
                                     KSDbgInfo.TheCU->getDirectory());
  MDScope *FContext = Unit;
  unsigned LineNo = Line;
  unsigned ScopeLine = Line;
  DISubprogram SP = DBuilder->createFunction(
      FContext, Name, StringRef(), Unit, LineNo,
      CreateFunctionType(Args.size(), Unit), false /* internal linkage */,
      true /* definition */, ScopeLine, DebugNode::FlagPrototyped, false, F);

  KSDbgInfo.FnScopeMap[this] = SP;
  return F;
}
开发者ID:B1ackCat,项目名称:llvm-dsa,代码行数:50,代码来源:toy.cpp

示例12: codeGen

Value* NFunction::codeGen(CodeGenContext& context)
{
    vector<Type*> argTypes;
    for (ArgumentList::const_iterator it = arguments.begin();
         it != arguments.end(); it++) {
        argTypes.push_back(typeOf((*it)->type));
    }
    /* Create the top level interpreter function to call as entry */
    FunctionType *ftype = FunctionType::get(typeOf(returnType), argTypes, false);
    auto name = id.name;
    Function *function = Function::Create(ftype, GlobalValue::InternalLinkage, name.c_str(), context.module);

    if (name == "main")
        context.mainFunction = function;

    // If F conflicted, there was already something named 'Name'.  If it has a
    // body, don't allow redefinition or reextern.
    if (function->getName() != name) {
        // Delete the one we just made and get the existing one.
        function->eraseFromParent();
        function = context.module->getFunction(name);
    }
    /* Push a new variable/block context */
    BasicBlock *bblock = BasicBlock::Create(getGlobalContext(), "entry", function, 0);
    context.pushBlock(bblock);

    // Create arguments into symbol table
    unsigned index = 0;
    for (Function::arg_iterator iter = function->arg_begin(); index != arguments.size();
         ++iter, ++index) {
        auto name = arguments[index]->identifier.name;
        std::cout << name << std::endl;
        iter->setName(name);

        context.locals()[name] = iter;
    }

    // Create function body
    Value *last = nullptr;
    for (StatementList::const_iterator it = block.begin();
         it != block.end(); it++) {
        std::cout << "Generating code for " << typeid(**it).name() << ' ' << std::endl;
        last = (**it).codeGen(context);
    }

    context.popBlock();

    return last;
}
开发者ID:wujysh,项目名称:Wlang,代码行数:49,代码来源:codegen.cpp

示例13: Arguments

Function *ParallelLoopGenerator::createSubFnDefinition() {
  Function *F = Builder.GetInsertBlock()->getParent();
  std::vector<Type *> Arguments(1, Builder.getInt8PtrTy());
  FunctionType *FT = FunctionType::get(Builder.getVoidTy(), Arguments, false);
  Function *SubFn = Function::Create(FT, Function::InternalLinkage,
                                     F->getName() + ".polly.subfn", M);

  // Do not run any polly pass on the new function.
  SubFn->addFnAttr(PollySkipFnAttr);

  Function::arg_iterator AI = SubFn->arg_begin();
  AI->setName("polly.par.userContext");

  return SubFn;
}
开发者ID:larryv,项目名称:polly,代码行数:15,代码来源:LoopGenerators.cpp

示例14: getModule

Function *OMPGenerator::createSubfunctionDefinition() {
  Module *M = getModule();
  Function *F = Builder.GetInsertBlock()->getParent();
  std::vector<Type *> Arguments(1, Builder.getInt8PtrTy());
  FunctionType *FT = FunctionType::get(Builder.getVoidTy(), Arguments, false);
  Function *FN = Function::Create(FT, Function::InternalLinkage,
                                  F->getName() + ".omp_subfn", M);
  // Do not run any polly pass on the new function.
  FN->addFnAttr(PollySkipFnAttr);

  Function::arg_iterator AI = FN->arg_begin();
  AI->setName("omp.userContext");

  return FN;
}
开发者ID:mingxingtan,项目名称:polly,代码行数:15,代码来源:LoopGenerators.cpp

示例15: message

static GlobalObject *makeInternalReplacement(GlobalObject *GO) {
  Module *M = GO->getParent();
  GlobalObject *Ret;
  if (auto *F = dyn_cast<Function>(GO)) {
    if (F->isMaterializable()) {
      if (F->materialize())
        message(LDPL_FATAL, "LLVM gold plugin has failed to read a function");

    }

    auto *NewF = Function::Create(F->getFunctionType(), F->getLinkage(),
                                  F->getName(), M);

    ValueToValueMapTy VM;
    Function::arg_iterator NewI = NewF->arg_begin();
    for (auto &Arg : F->args()) {
      NewI->setName(Arg.getName());
      VM[&Arg] = NewI;
      ++NewI;
    }

    NewF->getBasicBlockList().splice(NewF->end(), F->getBasicBlockList());
    for (auto &BB : *NewF) {
      for (auto &Inst : BB)
        RemapInstruction(&Inst, VM, RF_IgnoreMissingEntries);
    }

    Ret = NewF;
    F->deleteBody();
  } else {
    auto *Var = cast<GlobalVariable>(GO);
    Ret = new GlobalVariable(
        *M, Var->getType()->getElementType(), Var->isConstant(),
        Var->getLinkage(), Var->getInitializer(), Var->getName(),
        nullptr, Var->getThreadLocalMode(), Var->getType()->getAddressSpace(),
        Var->isExternallyInitialized());
    Var->setInitializer(nullptr);
  }
  Ret->copyAttributesFrom(GO);
  Ret->setLinkage(GlobalValue::InternalLinkage);
  Ret->setComdat(GO->getComdat());

  return Ret;
}
开发者ID:Drup,项目名称:llvm,代码行数:44,代码来源:gold-plugin.cpp


注:本文中的function::arg_iterator::setName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。