diff --git a/dmd2/aggregate.h b/dmd2/aggregate.h index 69f470a0..cf207b10 100644 --- a/dmd2/aggregate.h +++ b/dmd2/aggregate.h @@ -41,7 +41,7 @@ struct VarDeclaration; struct dt_t; #if IN_LLVM -class ClassInfoDeclaration; +struct ClassInfoDeclaration; namespace llvm { class Type; diff --git a/gen/asm-x86-32.h b/gen/asm-x86-32.h index 9c0fa987..dded5a80 100644 --- a/gen/asm-x86-32.h +++ b/gen/asm-x86-32.h @@ -2,6 +2,9 @@ // Released under the Artistic License found in dmd/artistic.txt #include "id.h" +#if defined(_MSC_VER) +#include +#endif namespace AsmParserx8632 { @@ -1254,7 +1257,11 @@ namespace AsmParserx8632 { strncpy ( buf, regInfo[i].name, sizeof ( buf ) - 1 ); for ( p = buf; *p; p++ ) +#if defined(_MSC_VER) + *p = tolower ( *p ); +#else *p = std::tolower ( *p ); +#endif regInfo[i].gccName = std::string ( buf, p - buf ); if ( ( i <= Reg_ST || i > Reg_ST7 ) && i != Reg_EFLAGS ) regInfo[i].ident = Lexer::idPool ( regInfo[i].name ); diff --git a/gen/asm-x86-64.h b/gen/asm-x86-64.h index ba48fd0b..ae2e5b56 100644 --- a/gen/asm-x86-64.h +++ b/gen/asm-x86-64.h @@ -2,6 +2,9 @@ // Released under the Artistic License found in dmd/artistic.txt #include "id.h" +#if defined(_MSC_VER) +#include +#endif namespace AsmParserx8664 { @@ -1367,7 +1370,11 @@ namespace AsmParserx8664 { strncpy ( buf, regInfo[i].name, sizeof ( buf ) - 1 ); for ( p = buf; *p; p++ ) +#if defined(_MSC_VER) + *p = tolower ( *p ); +#else *p = std::tolower ( *p ); +#endif regInfo[i].gccName = std::string ( buf, p - buf ); if ( ( i <= Reg_ST || i > Reg_ST7 ) && i != Reg_EFLAGS ) regInfo[i].ident = Lexer::idPool ( regInfo[i].name ); diff --git a/gen/logger.cpp b/gen/logger.cpp index f41fc61f..6b4736f5 100644 --- a/gen/logger.cpp +++ b/gen/logger.cpp @@ -62,12 +62,35 @@ namespace Logger else return 0; } + +#if defined(_MSC_VER) + static inline void + search_and_replace(std::string& str, const std::string& what, const std::string& replacement) + { + assert(!what.empty()); + size_t pos = str.find(what); + while (pos != std::string::npos) + { + str.replace(pos, what.size(), replacement); + pos = str.find(what, pos + replacement.size()); + } + } + +#define WORKAROUND_C99_SPECIFIERS_BUG(f) \ + std::string tmp = f; \ + search_and_replace(tmp, std::string("%z"), std::string("%I")); \ + f = tmp.c_str(); +#else +#define WORKAROUND_C99_SPECIFIERS_BUG(f) +#endif + void println(const char* fmt,...) { if (_enabled) { printf("%s", indent_str.c_str()); va_list va; va_start(va,fmt); + WORKAROUND_C99_SPECIFIERS_BUG(fmt); vprintf(fmt,va); va_end(va); printf("\n"); @@ -79,6 +102,7 @@ namespace Logger printf("%s", indent_str.c_str()); va_list va; va_start(va,fmt); + WORKAROUND_C99_SPECIFIERS_BUG(fmt); vprintf(fmt,va); va_end(va); } diff --git a/gen/main.cpp b/gen/main.cpp index 02d41619..4945b197 100644 --- a/gen/main.cpp +++ b/gen/main.cpp @@ -18,12 +18,6 @@ #include #include -#if POSIX -#include -#elif _WIN32 -#include -#endif - #include "rmem.h" #include "root.h" @@ -49,6 +43,12 @@ using namespace opts; #include "gen/configfile.h" +#if POSIX +#include +#elif _WIN32 +#include +#endif + #if DMDV1 typedef Array Modules; #endif @@ -127,7 +127,7 @@ static void initFromString(char*& dest, const cl::opt& src) { } } -#if _WIN32 +#if _WIN32 && __DMC__ extern "C" { extern int _xi_a; @@ -139,7 +139,7 @@ int main(int argc, char** argv) { mem.init(); // initialize storage allocator mem.setStackBottom(&argv); -#if _WIN32 +#if _WIN32 && __DMC__ mem.addroots((char *)&_xi_a, (char *)&_end); #endif diff --git a/gen/tocall.cpp b/gen/tocall.cpp index 2fa85d6a..9b089b2d 100644 --- a/gen/tocall.cpp +++ b/gen/tocall.cpp @@ -50,7 +50,10 @@ llvm::CallingConv::ID DtoCallingConv(Loc loc, LINK l) return llvm::CallingConv::Fast; } // on the other hand, here, it's exactly what we want!!! TODO: right? - else if (l == LINKwindows || l == LINKpascal) + // On Windows 64bit, there is only one calling convention! + else if (l == LINKwindows) + return global.params.cpu == ARCHx86_64 ? llvm::CallingConv::C : llvm::CallingConv::X86_StdCall; + else if (l == LINKpascal) return llvm::CallingConv::X86_StdCall; else { @@ -617,8 +620,8 @@ DValue* DtoCallFunction(Loc& loc, Type* resulttype, DValue* fnval, Expressions* // repaint the type if necessary if (resulttype) { - Type* rbase = stripModifiers(resulttype->toBasetype()); - Type* nextbase = stripModifiers(tf->nextOf()->toBasetype()); + Type* rbase = stripModifiers(resulttype->toBasetype()); + Type* nextbase = stripModifiers(tf->nextOf()->toBasetype()); if (!rbase->equals(nextbase)) { Logger::println("repainting return value from '%s' to '%s'", tf->nextOf()->toChars(), rbase->toChars()); diff --git a/ir/irdsymbol.h b/ir/irdsymbol.h index f7bf4f13..94b0fd18 100644 --- a/ir/irdsymbol.h +++ b/ir/irdsymbol.h @@ -14,7 +14,7 @@ struct IrVar; struct Dsymbol; namespace llvm { - struct Value; + class Value; } struct IrDsymbol diff --git a/ir/irfuncty.h b/ir/irfuncty.h index 8e698181..4806ccfc 100644 --- a/ir/irfuncty.h +++ b/ir/irfuncty.h @@ -84,6 +84,7 @@ struct IrFuncTy : IrBase IrFuncTy() : ret(NULL), + args(), arg_sret(NULL), arg_this(NULL), arg_nest(NULL), @@ -93,11 +94,47 @@ struct IrFuncTy : IrBase reverseParams(false), is_arg_this_ref(false) {} - + +#if defined(_MSC_VER) + // Copy constructor and operator= seems to be requreid for MSC + + IrFuncTy(const IrFuncTy& rhs) + : ret(rhs.ret), + args(IrFuncTy::ArgList(rhs.args)), + arg_sret(rhs.arg_sret), + arg_this(rhs.arg_this), + arg_nest(rhs.arg_nest), + arg_arguments(rhs.arg_arguments), + arg_argptr(rhs.arg_argptr), + c_vararg(rhs.c_vararg), + reverseParams(rhs.reverseParams), + is_arg_this_ref(rhs.is_arg_this_ref) + {} + + IrFuncTy& operator=(const IrFuncTy& rhs) + { + ret = rhs.ret; + args = IrFuncTy::ArgList(rhs.args); + arg_sret = rhs.arg_sret; + arg_this = rhs.arg_this; + arg_nest = rhs.arg_nest; + arg_arguments = rhs.arg_arguments; + arg_argptr = rhs.arg_argptr; + c_vararg = rhs.c_vararg; + reverseParams = rhs.reverseParams; + is_arg_this_ref = rhs.is_arg_this_ref; + return *this; + } +#endif + void reset() { ret = NULL; arg_sret = arg_this = arg_nest = arg_arguments = arg_argptr = NULL; +#if defined(_MSC_VER) + args = IrFuncTy::ArgList(); +#else args.clear(); +#endif c_vararg = false; reverseParams = false; } diff --git a/ir/irtype.cpp b/ir/irtype.cpp index 37d31ecd..28fe067b 100644 --- a/ir/irtype.cpp +++ b/ir/irtype.cpp @@ -12,7 +12,7 @@ ////////////////////////////////////////////////////////////////////////////// extern LLType* DtoType(Type* dt); -extern LLType* DtoSize_t(); +extern LLIntegerType* DtoSize_t(); //////////////////////////////////////////////////////////////////////////////