本文整理汇总了C++中AttrBuilder::addByVal方法的典型用法代码示例。如果您正苦于以下问题:C++ AttrBuilder::addByVal方法的具体用法?C++ AttrBuilder::addByVal怎么用?C++ AttrBuilder::addByVal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AttrBuilder
的用法示例。
在下文中一共展示了AttrBuilder::addByVal方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addExplicitArguments
static void addExplicitArguments(std::vector<LLValue *> &args, AttrSet &attrs,
IrFuncTy &irFty, LLFunctionType *callableTy,
const std::vector<DValue *> &argvals,
int numFormalParams) {
// Number of arguments added to the LLVM type that are implicit on the
// frontend side of things (this, context pointers, etc.)
const size_t implicitLLArgCount = args.size();
// Number of formal arguments in the LLVM type (i.e. excluding varargs).
const size_t formalLLArgCount = irFty.args.size();
// The number of explicit arguments in the D call expression (including
// varargs), not all of which necessarily generate a LLVM argument.
const size_t explicitDArgCount = argvals.size();
// construct and initialize an IrFuncTyArg object for each vararg
std::vector<IrFuncTyArg *> optionalIrArgs;
for (size_t i = numFormalParams; i < explicitDArgCount; i++) {
Type *argType = argvals[i]->getType();
bool passByVal = gABI->passByVal(argType);
AttrBuilder initialAttrs;
if (passByVal) {
initialAttrs.addByVal(DtoAlignment(argType));
} else {
initialAttrs.add(DtoShouldExtend(argType));
}
optionalIrArgs.push_back(new IrFuncTyArg(argType, passByVal, initialAttrs));
optionalIrArgs.back()->parametersIdx = i;
}
// let the ABI rewrite the IrFuncTyArg objects
gABI->rewriteVarargs(irFty, optionalIrArgs);
const size_t explicitLLArgCount = formalLLArgCount + optionalIrArgs.size();
args.resize(implicitLLArgCount + explicitLLArgCount,
static_cast<llvm::Value *>(nullptr));
// Iterate the explicit arguments from left to right in the D source,
// which is the reverse of the LLVM order if irFty.reverseParams is true.
for (size_t i = 0; i < explicitLLArgCount; ++i) {
const bool isVararg = (i >= irFty.args.size());
IrFuncTyArg *irArg = nullptr;
if (isVararg) {
irArg = optionalIrArgs[i - numFormalParams];
} else {
irArg = irFty.args[i];
}
DValue *const argval = argvals[irArg->parametersIdx];
Type *const argType = argval->getType();
llvm::Value *llVal = nullptr;
if (isVararg) {
llVal = irFty.putParam(*irArg, argval);
} else {
llVal = irFty.putParam(i, argval);
}
const size_t llArgIdx =
implicitLLArgCount +
(irFty.reverseParams ? explicitLLArgCount - i - 1 : i);
llvm::Type *const callableArgType =
(isVararg ? nullptr : callableTy->getParamType(llArgIdx));
// Hack around LDC assuming structs and static arrays are in memory:
// If the function wants a struct, and the argument value is a
// pointer to a struct, load from it before passing it in.
if (isaPointer(llVal) && DtoIsInMemoryOnly(argType) &&
((!isVararg && !isaPointer(callableArgType)) ||
(isVararg && !irArg->byref && !irArg->isByVal()))) {
Logger::println("Loading struct type for function argument");
llVal = DtoLoad(llVal);
}
// parameter type mismatch, this is hard to get rid of
if (!isVararg && llVal->getType() != callableArgType) {
IF_LOG {
Logger::cout() << "arg: " << *llVal << '\n';
Logger::cout() << "expects: " << *callableArgType << '\n';
}
if (isaStruct(llVal)) {
llVal = DtoAggrPaint(llVal, callableArgType);
} else {
llVal = DtoBitCast(llVal, callableArgType);
}
}
args[llArgIdx] = llVal;
// +1 as index 0 contains the function attributes.
attrs.add(llArgIdx + 1, irArg->attrs);
if (isVararg) {
delete irArg;
}
}