Prepare generic x86 TargetABI for proper MSVC support

Based on Rainer's work in
3e36652c2c
This commit is contained in:
Martin 2015-12-06 18:47:16 +01:00
parent 5fce371c91
commit e7f26a94b0
7 changed files with 21 additions and 9 deletions

View file

@ -1339,6 +1339,9 @@ public:
char *mangleOf(Dsymbol *s)
{
#if IN_LLVM
buf.writeByte('\01'); // disable further mangling by the backend
#endif
VarDeclaration *vd = s->isVarDeclaration();
FuncDeclaration *fd = s->isFuncDeclaration();
if (vd)
@ -1991,7 +1994,7 @@ char *toCppMangle(Dsymbol *s)
const bool isTargetWindowsMSVC = global.params.targetTriple.isWindowsMSVCEnvironment();
if (isTargetWindowsMSVC)
{
VisualCPPMangler v(!global.params.is64bit);
VisualCPPMangler v(false);
return v.mangleOf(s);
}
else

View file

@ -17,7 +17,8 @@
#include "gen/abi-aarch64.h"
struct AArch64TargetABI : TargetABI {
llvm::CallingConv::ID callingConv(LINK l) {
llvm::CallingConv::ID callingConv(llvm::FunctionType *ft, LINK l,
FuncDeclaration *fdecl = nullptr) override {
switch (l) {
case LINKc:
case LINKcpp:

View file

@ -29,11 +29,15 @@ struct X86TargetABI : TargetABI {
: isOSX(global.params.isOSX),
isMSVC(global.params.targetTriple.isWindowsMSVCEnvironment()) {}
llvm::CallingConv::ID callingConv(llvm::FunctionType *ft, LINK l) override {
llvm::CallingConv::ID callingConv(llvm::FunctionType *ft, LINK l,
FuncDeclaration *fdecl = nullptr) override {
switch (l) {
case LINKc:
case LINKcpp:
return llvm::CallingConv::C;
case LINKcpp:
return isMSVC && !ft->isVarArg() && fdecl && fdecl->isThis()
? llvm::CallingConv::X86_ThisCall
: llvm::CallingConv::C;
case LINKd:
case LINKdefault:
case LINKpascal:

View file

@ -26,6 +26,7 @@ class TypeFunction;
struct IrFuncTy;
struct IrFuncTyArg;
class DValue;
class FuncDeclaration;
namespace llvm {
class Type;
@ -81,7 +82,8 @@ struct TargetABI {
/// Returns the LLVM calling convention to be used for the given D linkage
/// type on the target. Defaults to the C calling convention.
virtual llvm::CallingConv::ID callingConv(llvm::FunctionType *ft, LINK l) {
virtual llvm::CallingConv::ID callingConv(llvm::FunctionType *ft, LINK l,
FuncDeclaration *fdecl = nullptr) {
return llvm::CallingConv::C;
}

View file

@ -463,7 +463,7 @@ void DtoDeclareFunction(FuncDeclaration *fdecl) {
fatal();
}
func->setCallingConv(gABI->callingConv(func->getFunctionType(), link));
func->setCallingConv(gABI->callingConv(func->getFunctionType(), link, fdecl));
IF_LOG Logger::cout() << "func = " << *func << std::endl;

View file

@ -37,7 +37,9 @@ void Target::init() {
c_longsize = global.params.is64bit ? 8 : 4;
c_long_doublesize = realsize;
reverseCppOverloads = false; // DMC is not supported.
// according to DMD, only for 32-bit MSVC++:
reverseCppOverloads = !global.params.is64bit &&
global.params.targetTriple.isWindowsMSVCEnvironment();
}
/******************************

View file

@ -777,8 +777,8 @@ DValue *DtoCallFunction(Loc &loc, Type *resulttype, DValue *fnval,
LLFunctionType *const callableTy =
DtoExtractFunctionType(callable->getType());
assert(callableTy);
const llvm::CallingConv::ID callconv =
gABI->callingConv(callableTy, tf->linkage);
const auto callconv = gABI->callingConv(callableTy, tf->linkage,
dfnval ? dfnval->func : nullptr);
// IF_LOG Logger::cout() << "callable: " << *callable << '\n';