mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-04-30 15:10:59 +03:00
Refactoring: move ABI-specific variadic stuff to TargetABI type.
This commit is contained in:
parent
a41a31d535
commit
aa38fe06ec
6 changed files with 85 additions and 86 deletions
|
@ -17,7 +17,6 @@
|
|||
#include "statement.h"
|
||||
#include "template.h"
|
||||
#include "gen/abi.h"
|
||||
#include "gen/abi-x86-64.h"
|
||||
#include "gen/arrays.h"
|
||||
#include "gen/classes.h"
|
||||
#include "gen/dvalue.h"
|
||||
|
@ -1179,30 +1178,17 @@ void DtoDefineFunction(FuncDeclaration* fd)
|
|||
if (f->linkage == LINKd && f->varargs == 1)
|
||||
{
|
||||
// allocate _argptr (of type core.stdc.stdarg.va_list)
|
||||
LLValue* argptrmem = DtoAlloca(Type::tvalist, "_argptr_mem"); // _argptr_mem = new va_list [most likely char**]
|
||||
LLValue* argptrmem = DtoAlloca(Type::tvalist, "_argptr_mem");
|
||||
irFunc->_argptr = argptrmem;
|
||||
|
||||
// initialize _argptr
|
||||
if (isSystemVAMD64Target()) { // System V AMD64 ABI:
|
||||
LLType* nativeValistType = getSystemVAMD64NativeValistType();
|
||||
LLValue* valistmem = DtoRawAlloca(nativeValistType,
|
||||
0, "__va_list_mem"); // __va_list_mem = new __va_list
|
||||
valistmem = DtoBitCast(valistmem, getVoidPtrType()); // valistmem = (char*)__va_list_mem
|
||||
DtoStore(valistmem, argptrmem); // *argptrmem = valistmem
|
||||
// => _argptr = (char*)__va_list_mem
|
||||
llvm::CallInst::Create(GET_INTRINSIC_DECL(vastart), // llvm.va_start(valistmem)
|
||||
valistmem, "", gIR->scopebb()); // => llvm.va_start(_argptr)
|
||||
} else { // all other ABIs:
|
||||
llvm::CallInst::Create(GET_INTRINSIC_DECL(vastart), // llvm.va_start((char*)&_argptr)
|
||||
DtoBitCast(argptrmem, getVoidPtrType()), "", gIR->scopebb());
|
||||
}
|
||||
// initialize _argptr with a call to the va_start intrinsic
|
||||
LLValue* vaStartArg = gABI->prepareVaStart(argptrmem);
|
||||
llvm::CallInst::Create(GET_INTRINSIC_DECL(vastart), vaStartArg, "", gIR->scopebb());
|
||||
|
||||
// copy _arguments to a memory location
|
||||
LLType* argumentsType = irFunc->_arguments->getType();
|
||||
LLValue* argumentsmem = DtoRawAlloca(argumentsType,
|
||||
0, "_arguments_mem"); // _arguments_mem = new TypeInfo[]
|
||||
new llvm::StoreInst(irFunc->_arguments, argumentsmem, // *_arguments_mem = <passed _arguments>
|
||||
gIR->scopebb());
|
||||
LLValue* argumentsmem = DtoRawAlloca(argumentsType, 0, "_arguments_mem");
|
||||
new llvm::StoreInst(irFunc->_arguments, argumentsmem, gIR->scopebb());
|
||||
irFunc->_arguments = argumentsmem;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue