mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-04-28 22:21:31 +03:00
Adapt to free functions in dmd
C++ namespace now
This commit is contained in:
parent
217888ff47
commit
9041c0bf67
37 changed files with 132 additions and 64 deletions
|
@ -35,6 +35,8 @@ enum class AsanDetectStackUseAfterReturnMode { Never, Runtime, Always };
|
|||
}
|
||||
#endif
|
||||
|
||||
using namespace dmd;
|
||||
|
||||
namespace {
|
||||
|
||||
using namespace opts;
|
||||
|
|
|
@ -91,6 +91,7 @@ void gendocfile(Module *m);
|
|||
// In dmd/mars.d
|
||||
void generateJson(Modules *modules);
|
||||
|
||||
using namespace dmd;
|
||||
using namespace opts;
|
||||
|
||||
static StringsAdapter impPathsStore("I", global.params.imppath);
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
#include "ir/irfunction.h"
|
||||
#include "ir/irmodule.h"
|
||||
|
||||
using namespace dmd;
|
||||
|
||||
// returns the keytype typeinfo
|
||||
static LLConstant *to_keyti(const Loc &loc, DValue *aa, LLType *targetType) {
|
||||
// keyti param
|
||||
|
@ -60,8 +62,8 @@ DLValue *DtoAAIndex(const Loc &loc, Type *type, DValue *aa, DValue *key,
|
|||
// call runtime
|
||||
LLValue *ret;
|
||||
if (lvalue) {
|
||||
LLValue *rawAATI =
|
||||
DtoTypeInfoOf(loc, aa->type->unSharedOf()->mutableOf(), /*base=*/false);
|
||||
auto t = mutableOf(unSharedOf(aa->type));
|
||||
LLValue *rawAATI = DtoTypeInfoOf(loc, t, /*base=*/false);
|
||||
LLValue *castedAATI = DtoBitCast(rawAATI, funcTy->getParamType(1));
|
||||
LLValue *valsize = DtoConstSize_t(getTypeAllocSize(DtoType(type)));
|
||||
ret = gIR->CreateCallOrInvoke(func, aaval, castedAATI, valsize, pkey,
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
#include "ir/irfuncty.h"
|
||||
#include <algorithm>
|
||||
|
||||
using namespace dmd;
|
||||
|
||||
// in dmd/argtypes_aarch64.d:
|
||||
bool isHFVA(Type *t, int maxNumElements, Type **rewriteType);
|
||||
|
||||
|
@ -89,7 +91,7 @@ TypeTuple *TargetABI::getArgTypes(Type *t) {
|
|||
LLType *TargetABI::getRewrittenArgType(Type *t, TypeTuple *argTypes) {
|
||||
if (!argTypes || argTypes->arguments->empty() ||
|
||||
(argTypes->arguments->length == 1 &&
|
||||
argTypes->arguments->front()->type->equivalent(t))) {
|
||||
equivalent(argTypes->arguments->front()->type, t))) {
|
||||
return nullptr; // don't rewrite
|
||||
}
|
||||
|
||||
|
@ -217,7 +219,7 @@ LLValue *TargetABI::prepareVaArg(DLValue *ap) {
|
|||
|
||||
Type *TargetABI::vaListType() {
|
||||
// char* is used by default in druntime.
|
||||
return Type::tchar->pointerTo();
|
||||
return pointerTo(Type::tchar);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
#include "gen/llvmhelpers.h"
|
||||
#include "gen/tollvm.h"
|
||||
|
||||
using namespace dmd;
|
||||
|
||||
namespace {
|
||||
struct Integer2Rewrite : BaseBitcastABIRewrite {
|
||||
LLType *type(Type *t) override {
|
||||
|
@ -57,15 +59,15 @@ FlattenedFields visitStructFields(Type *ty, unsigned baseOffset) {
|
|||
}
|
||||
switch (ty->toBasetype()->ty) {
|
||||
case TY::Tcomplex32: // treat it as {float32, float32}
|
||||
result.fields[0].ty = Type::tfloat32->pointerTo();
|
||||
result.fields[1].ty = Type::tfloat32->pointerTo();
|
||||
result.fields[0].ty = pointerTo(Type::tfloat32);
|
||||
result.fields[1].ty = pointerTo(Type::tfloat32);
|
||||
result.fields[0].offset = baseOffset;
|
||||
result.fields[1].offset = baseOffset + 4;
|
||||
result.length = 2;
|
||||
break;
|
||||
case TY::Tcomplex64: // treat it as {float64, float64}
|
||||
result.fields[0].ty = Type::tfloat64->pointerTo();
|
||||
result.fields[1].ty = Type::tfloat64->pointerTo();
|
||||
result.fields[0].ty = pointerTo(Type::tfloat64);
|
||||
result.fields[1].ty = pointerTo(Type::tfloat64);
|
||||
result.fields[0].offset = baseOffset;
|
||||
result.fields[1].offset = baseOffset + 8;
|
||||
result.length = 2;
|
||||
|
@ -160,7 +162,7 @@ private:
|
|||
public:
|
||||
Type *vaListType() override {
|
||||
// va_list is void*
|
||||
return Type::tvoid->pointerTo();
|
||||
return pointerTo(Type::tvoid);
|
||||
}
|
||||
bool returnInArg(TypeFunction *tf, bool) override {
|
||||
if (tf->isref()) {
|
||||
|
|
|
@ -46,6 +46,8 @@
|
|||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
using namespace dmd;
|
||||
|
||||
namespace {
|
||||
struct RegCount {
|
||||
char int_regs, sse_regs;
|
||||
|
@ -382,8 +384,8 @@ Type *X86_64TargetABI::vaListType() {
|
|||
// using TypeIdentifier here is a bit wonky but works, as long as the name
|
||||
// is actually available in the scope (this is what DMD does, so if a better
|
||||
// solution is found there, this should be adapted).
|
||||
return TypeIdentifier::create(Loc(), Identifier::idPool("__va_list_tag"))
|
||||
->pointerTo();
|
||||
return pointerTo(
|
||||
TypeIdentifier::create(Loc(), Identifier::idPool("__va_list_tag")));
|
||||
}
|
||||
|
||||
const char *X86_64TargetABI::objcMsgSendFunc(Type *ret,
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
#include "ir/irfunction.h"
|
||||
#include "ir/irmodule.h"
|
||||
|
||||
using namespace dmd;
|
||||
|
||||
static void DtoSetArray(DValue *array, DValue *rhs);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -805,7 +807,7 @@ bool validCompareWithMemcmp(DValue *l, DValue *r) {
|
|||
|
||||
// Only memcmp equivalent element types (memcmp should be used for
|
||||
// `const int[3] == int[]`, but not for `int[3] == short[3]`).
|
||||
if (!lElemType->equivalent(rElemType))
|
||||
if (!equivalent(lElemType, rElemType))
|
||||
return false;
|
||||
|
||||
return validCompareWithMemcmpType(lElemType);
|
||||
|
|
|
@ -2337,6 +2337,8 @@ struct AsmProcessor {
|
|||
|
||||
void addOperand(const char *fmt, AsmArgType type, Expression *e,
|
||||
AsmCode *asmcode, AsmArgMode mode = Mode_Input) {
|
||||
using namespace dmd;
|
||||
|
||||
if (sc->func->isNaked()) {
|
||||
switch (type) {
|
||||
case Arg_Integer:
|
||||
|
@ -2579,6 +2581,8 @@ struct AsmProcessor {
|
|||
|
||||
// also set impl clobbers
|
||||
bool formatInstruction(int nOperands, AsmCode *asmcode) {
|
||||
using namespace dmd;
|
||||
|
||||
const char *fmt;
|
||||
const char *mnemonic;
|
||||
std::string type_suffix;
|
||||
|
@ -3004,7 +3008,7 @@ struct AsmProcessor {
|
|||
{
|
||||
|
||||
e = createAddrExp(Loc(), e);
|
||||
e->type = decl->type->pointerTo();
|
||||
e->type = pointerTo(decl->type);
|
||||
|
||||
operand->constDisplacement = 0;
|
||||
operand->baseReg = Reg_Invalid;
|
||||
|
@ -3059,7 +3063,7 @@ struct AsmProcessor {
|
|||
|
||||
if (!sc->func->isNaked()) // no addrexp in naked asm please :)
|
||||
{
|
||||
Type *tt = e->type->pointerTo();
|
||||
Type *tt = pointerTo(e->type);
|
||||
e = createAddrExp(Loc(), e);
|
||||
e->type = tt;
|
||||
}
|
||||
|
@ -3231,6 +3235,8 @@ struct AsmProcessor {
|
|||
}
|
||||
|
||||
Expression *intOp(TOK op, Expression *e1, Expression *e2) {
|
||||
using namespace dmd;
|
||||
|
||||
if (isIntExp(e1) && (!e2 || isIntExp(e2))) {
|
||||
Expression *e = createExpressionForIntOp(stmt->loc, op, e1, e2);
|
||||
e = expressionSemantic(e, sc);
|
||||
|
@ -3629,6 +3635,8 @@ struct AsmProcessor {
|
|||
}
|
||||
|
||||
Expression *parsePrimaryExp() {
|
||||
using namespace dmd;
|
||||
|
||||
Expression *e;
|
||||
Identifier *ident = nullptr;
|
||||
|
||||
|
@ -3789,6 +3797,8 @@ struct AsmProcessor {
|
|||
}
|
||||
|
||||
void doAlign() {
|
||||
using namespace dmd;
|
||||
|
||||
// .align bits vs. bytes...
|
||||
// apparently a.out platforms use bits instead of bytes...
|
||||
|
||||
|
|
|
@ -75,6 +75,8 @@ AsmParserCommon *asmparser = nullptr;
|
|||
#include "asm-x86.h" // x86_64 assembly parser
|
||||
#undef ASM_X86_64
|
||||
|
||||
using namespace dmd;
|
||||
|
||||
/**
|
||||
* Replaces <<func>> with the name of the currently codegen'd function.
|
||||
*
|
||||
|
@ -95,8 +97,6 @@ static void replace_func_name(IRState *p, std::string &insnt) {
|
|||
}
|
||||
}
|
||||
|
||||
Statement *gccAsmSemantic(GccAsmStatement *s, Scope *sc);
|
||||
|
||||
Statement *asmSemantic(AsmStatement *s, Scope *sc) {
|
||||
if (!s->tokens) {
|
||||
return nullptr;
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
#include "dmd/module.h"
|
||||
#include "dmd/template.h"
|
||||
|
||||
using namespace dmd;
|
||||
|
||||
bool isFromLDC_Mod(Dsymbol *sym, Identifier* id) {
|
||||
auto mod = sym->getModule();
|
||||
if (!mod)
|
||||
|
|
|
@ -34,6 +34,8 @@
|
|||
#include "ir/irvar.h"
|
||||
#include "llvm/ADT/SmallString.h"
|
||||
|
||||
using namespace dmd;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class CodegenVisitor : public Visitor {
|
||||
|
|
|
@ -39,6 +39,8 @@
|
|||
#include "llvm/Support/Path.h"
|
||||
#include <functional>
|
||||
|
||||
using namespace dmd;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace cl = llvm::cl;
|
||||
|
@ -648,7 +650,7 @@ DIType DIBuilder::CreateArrayType(TypeArray *type) {
|
|||
|
||||
LLMetadata *elems[] = {CreateMemberType(0, Type::tsize_t, file, "length", 0,
|
||||
Visibility::public_),
|
||||
CreateMemberType(0, type->nextOf()->pointerTo(), file,
|
||||
CreateMemberType(0, pointerTo(type->nextOf()), file,
|
||||
"ptr", target.ptrsize,
|
||||
Visibility::public_)};
|
||||
|
||||
|
@ -743,7 +745,7 @@ DIType DIBuilder::CreateDelegateType(TypeDelegate *type) {
|
|||
LLMetadata *elems[] = {
|
||||
CreateMemberType(0, Type::tvoidptr, file, "ptr", 0,
|
||||
Visibility::public_),
|
||||
CreateMemberType(0, type->next->pointerTo(), file, "funcptr",
|
||||
CreateMemberType(0, pointerTo(type->next), file, "funcptr",
|
||||
target.ptrsize, Visibility::public_)};
|
||||
|
||||
return DBuilder.createStructType(scope, name, file,
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
#include "gen/recursivevisitor.h"
|
||||
#include "gen/uda.h"
|
||||
|
||||
using namespace dmd;
|
||||
|
||||
namespace {
|
||||
|
||||
/// An ASTVisitor that checks whether the number of statements is larger than a
|
||||
|
@ -166,7 +168,7 @@ bool defineAsExternallyAvailable(FuncDeclaration &fdecl) {
|
|||
global.gaggedForInlining = true;
|
||||
|
||||
bool semantic_error = false;
|
||||
if (fdecl.functionSemantic3()) {
|
||||
if (functionSemantic3(&fdecl)) {
|
||||
Module::runDeferredSemantic3();
|
||||
} else {
|
||||
IF_LOG Logger::println("Failed functionSemantic3.");
|
||||
|
|
|
@ -60,6 +60,8 @@
|
|||
#include "llvm/Transforms/Utils/Cloning.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace dmd;
|
||||
|
||||
bool isAnyMainFunction(FuncDeclaration *fd) {
|
||||
return fd->isMain() || fd->isCMain();
|
||||
}
|
||||
|
@ -123,7 +125,7 @@ llvm::FunctionType *DtoFunctionType(Type *type, IrFuncTy &irFty, Type *thistype,
|
|||
++nextLLArgIdx;
|
||||
} else {
|
||||
// sext/zext return
|
||||
DtoAddExtendAttr(byref ? rt->pointerTo() : rt, attrs);
|
||||
DtoAddExtendAttr(byref ? pointerTo(rt) : rt, attrs);
|
||||
}
|
||||
newIrFty.ret = new IrFuncTyArg(rt, byref, std::move(attrs));
|
||||
}
|
||||
|
@ -299,13 +301,13 @@ static llvm::FunctionType *DtoVaFunctionType(FuncDeclaration *fdecl) {
|
|||
|
||||
irFty.ret = new IrFuncTyArg(Type::tvoid, false);
|
||||
|
||||
irFty.args.push_back(new IrFuncTyArg(Type::tvoid->pointerTo(), false));
|
||||
irFty.args.push_back(new IrFuncTyArg(pointerTo(Type::tvoid), false));
|
||||
|
||||
if (fdecl->llvmInternal == LLVMva_start) {
|
||||
irFty.funcType = GET_INTRINSIC_DECL(vastart)->getFunctionType();
|
||||
} else if (fdecl->llvmInternal == LLVMva_copy) {
|
||||
irFty.funcType = GET_INTRINSIC_DECL(vacopy)->getFunctionType();
|
||||
irFty.args.push_back(new IrFuncTyArg(Type::tvoid->pointerTo(), false));
|
||||
irFty.args.push_back(new IrFuncTyArg(pointerTo(Type::tvoid), false));
|
||||
} else if (fdecl->llvmInternal == LLVMva_end) {
|
||||
irFty.funcType = GET_INTRINSIC_DECL(vaend)->getFunctionType();
|
||||
}
|
||||
|
@ -330,7 +332,7 @@ llvm::FunctionType *DtoFunctionType(FuncDeclaration *fdecl) {
|
|||
AggregateDeclaration *ad = p->isMember2();
|
||||
(void)ad;
|
||||
assert(ad);
|
||||
dnest = Type::tvoid->pointerTo();
|
||||
dnest = pointerTo(Type::tvoid);
|
||||
} else if (fdecl->needThis()) {
|
||||
if (AggregateDeclaration *ad = fdecl->isMember2()) {
|
||||
IF_LOG Logger::println("isMember = this is: %s", ad->type->toChars());
|
||||
|
@ -353,7 +355,7 @@ llvm::FunctionType *DtoFunctionType(FuncDeclaration *fdecl) {
|
|||
/*isVarArg=*/false);
|
||||
}
|
||||
} else if (fdecl->isNested()) {
|
||||
dnest = Type::tvoid->pointerTo();
|
||||
dnest = pointerTo(Type::tvoid);
|
||||
}
|
||||
|
||||
LLFunctionType *functype = DtoFunctionType(
|
||||
|
@ -588,7 +590,7 @@ void DtoDeclareFunction(FuncDeclaration *fdecl, const bool willDefine) {
|
|||
"defined after declaration.");
|
||||
if (fdecl->semanticRun < PASS::semantic3done) {
|
||||
Logger::println("Function hasn't had sema3 run yet, running it now.");
|
||||
const bool semaSuccess = fdecl->functionSemantic3();
|
||||
const bool semaSuccess = functionSemantic3(fdecl);
|
||||
(void)semaSuccess;
|
||||
assert(semaSuccess);
|
||||
Module::runDeferredSemantic3();
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
#include "llvm/Support/raw_ostream.h"
|
||||
#include "llvm/Support/SourceMgr.h"
|
||||
|
||||
using namespace dmd;
|
||||
|
||||
namespace {
|
||||
|
||||
/// Sets LLVMContext::setDiscardValueNames(false) upon construction and restores
|
||||
|
|
|
@ -47,6 +47,8 @@
|
|||
#include "llvm/Transforms/Utils/ModuleUtils.h"
|
||||
#include <stack>
|
||||
|
||||
using namespace dmd;
|
||||
|
||||
llvm::cl::opt<llvm::GlobalVariable::ThreadLocalMode> clThreadModel(
|
||||
"fthread-model", llvm::cl::ZeroOrMore, llvm::cl::desc("Thread model"),
|
||||
llvm::cl::init(llvm::GlobalVariable::GeneralDynamicTLSModel),
|
||||
|
@ -907,7 +909,7 @@ void DtoVarDeclaration(VarDeclaration *vd) {
|
|||
// already been done
|
||||
IrLocal *irLocal = getIrLocal(vd, true);
|
||||
|
||||
Type *type = isSpecialRefVar(vd) ? vd->type->pointerTo() : vd->type;
|
||||
Type *type = isSpecialRefVar(vd) ? pointerTo(vd->type) : vd->type;
|
||||
|
||||
llvm::Value *allocainst;
|
||||
bool isRealAlloca = false;
|
||||
|
@ -1326,9 +1328,9 @@ Type *stripModifiers(Type *type, bool transitive) {
|
|||
}
|
||||
|
||||
if (transitive) {
|
||||
return type->unqualify(MODimmutable | MODconst | MODwild);
|
||||
return unqualify(type, MODimmutable | MODconst | MODwild);
|
||||
}
|
||||
return type->castMod(0);
|
||||
return castMod(type, 0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
#include "gen/to_string.h"
|
||||
#include "llvm/Support/MD5.h"
|
||||
|
||||
using namespace dmd;
|
||||
|
||||
namespace {
|
||||
|
||||
// TODO: Disable hashing of symbols that are defined in libdruntime and
|
||||
|
|
|
@ -37,6 +37,8 @@
|
|||
#define MIlocalClasses 0x800
|
||||
#define MInew 0x80000000 // it's the "new" layout
|
||||
|
||||
using namespace dmd;
|
||||
|
||||
namespace {
|
||||
/// Creates a function in the current llvm::Module that dispatches to the given
|
||||
/// functions one after each other and then increments the gate variables, if
|
||||
|
|
|
@ -58,6 +58,8 @@
|
|||
#include <alloca.h>
|
||||
#endif
|
||||
|
||||
using namespace dmd;
|
||||
|
||||
static llvm::cl::opt<bool, true>
|
||||
preservePaths("op", llvm::cl::ZeroOrMore,
|
||||
llvm::cl::desc("Preserve source path for output files"),
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
#include "llvm/IR/InlineAsm.h"
|
||||
#include <cassert>
|
||||
|
||||
using namespace dmd;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// FIXME: Integrate these functions
|
||||
void AsmStatement_toNakedIR(InlineAsmStatement *stmt, IRState *irs);
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
#include "ir/irtypeaggr.h"
|
||||
#include "llvm/Analysis/ValueTracking.h"
|
||||
|
||||
using namespace dmd;
|
||||
|
||||
namespace {
|
||||
unsigned getVthisIdx(AggregateDeclaration *ad) {
|
||||
return getFieldGEPIndex(ad, ad->vthis);
|
||||
|
@ -437,7 +439,7 @@ static void DtoCreateNestedContextType(FuncDeclaration *fd) {
|
|||
LLType *t = nullptr;
|
||||
unsigned alignment = 0;
|
||||
if (captureByRef(vd)) {
|
||||
t = DtoType(vd->type->pointerTo());
|
||||
t = DtoType(pointerTo(vd->type));
|
||||
alignment = target.ptrsize;
|
||||
} else if (isParam && (vd->storage_class & STClazy)) {
|
||||
// the type is a delegate (LL struct)
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
#include "gen/llvmhelpers.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
|
||||
using namespace dmd;
|
||||
|
||||
namespace {
|
||||
bool parseStringExp(Expression *e, const char *&res) {
|
||||
e = optimize(e, WANTvalue);
|
||||
|
|
|
@ -22,8 +22,7 @@
|
|||
#include "ir/iraggr.h"
|
||||
#include "ir/irfunction.h"
|
||||
|
||||
// in dmd/opover.d:
|
||||
AggregateDeclaration *isAggregate(Type *t);
|
||||
using namespace dmd;
|
||||
|
||||
RTTIBuilder::RTTIBuilder(Type *baseType) {
|
||||
const auto ad = isAggregate(baseType);
|
||||
|
@ -114,7 +113,7 @@ void RTTIBuilder::push_array(llvm::Constant *CI, uint64_t dim, Type *valtype,
|
|||
setLinkage(lwc, G);
|
||||
G->setAlignment(llvm::MaybeAlign(DtoAlignment(valtype)));
|
||||
|
||||
push_array(dim, DtoBitCast(G, DtoType(valtype->pointerTo())));
|
||||
push_array(dim, DtoBitCast(G, DtoType(pointerTo(valtype))));
|
||||
}
|
||||
|
||||
void RTTIBuilder::push_array(uint64_t dim, llvm::Constant *ptr) {
|
||||
|
|
|
@ -40,6 +40,8 @@
|
|||
#include "llvm/Support/MemoryBuffer.h"
|
||||
#include <algorithm>
|
||||
|
||||
using namespace dmd;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static llvm::cl::opt<bool> nogc(
|
||||
|
@ -221,7 +223,7 @@ public:
|
|||
}
|
||||
|
||||
for (int i = 0; i < numIndirections; ++i)
|
||||
ty = ty->pointerTo();
|
||||
ty = ::dmd::pointerTo(ty);
|
||||
|
||||
return ty;
|
||||
}
|
||||
|
@ -491,7 +493,7 @@ static void buildRuntimeModule() {
|
|||
|
||||
Type *voidPtrTy = Type::tvoidptr;
|
||||
Type *voidArrayTy = Type::tvoid->arrayOf();
|
||||
Type *voidArrayPtrTy = voidArrayTy->pointerTo();
|
||||
Type *voidArrayPtrTy = pointerTo(voidArrayTy);
|
||||
Type *stringTy = Type::tchar->arrayOf();
|
||||
Type *wstringTy = Type::twchar->arrayOf();
|
||||
Type *dstringTy = Type::tdchar->arrayOf();
|
||||
|
@ -620,7 +622,7 @@ static void buildRuntimeModule() {
|
|||
// void _d_delmemory(void** p)
|
||||
// void _d_delinterface(void** p)
|
||||
createFwdDecl(LINK::c, voidTy, {"_d_delmemory", "_d_delinterface"},
|
||||
{voidPtrTy->pointerTo()});
|
||||
{pointerTo(voidPtrTy)});
|
||||
|
||||
// void _d_callfinalizer(void* p)
|
||||
createFwdDecl(LINK::c, voidTy, {"_d_callfinalizer"}, {voidPtrTy});
|
||||
|
@ -630,7 +632,7 @@ static void buildRuntimeModule() {
|
|||
|
||||
// void _d_delstruct(void** p, TypeInfo_Struct inf)
|
||||
createFwdDecl(LINK::c, voidTy, {"_d_delstruct"},
|
||||
{voidPtrTy->pointerTo(), structTypeInfoTy});
|
||||
{pointerTo(voidPtrTy), structTypeInfoTy});
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -717,7 +719,7 @@ static void buildRuntimeModule() {
|
|||
// void* _aaGetY(AA* aa, const TypeInfo aati, in size_t valuesize,
|
||||
// in void* pkey)
|
||||
createFwdDecl(LINK::c, voidPtrTy, {"_aaGetY"},
|
||||
{aaTy->pointerTo(), aaTypeInfoTy, sizeTy, voidPtrTy},
|
||||
{pointerTo(aaTy), aaTypeInfoTy, sizeTy, voidPtrTy},
|
||||
{0, STCconst, STCin, STCin}, Attr_1_4_NoCapture);
|
||||
|
||||
// inout(void)* _aaInX(inout AA aa, in TypeInfo keyti, in void* pkey)
|
||||
|
|
|
@ -41,6 +41,8 @@
|
|||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
using namespace dmd;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// FIXME: Integrate these functions
|
||||
void GccAsmStatement_toIR(GccAsmStatement *stmt, IRState *irs);
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "gen/llvmhelpers.h"
|
||||
#include <assert.h>
|
||||
|
||||
using namespace dmd;
|
||||
using llvm::APFloat;
|
||||
|
||||
// in dmd/argtypes_x86.d:
|
||||
|
|
|
@ -32,6 +32,8 @@
|
|||
#include "ir/irtype.h"
|
||||
#include "llvm/IR/LLVMContext.h"
|
||||
|
||||
using namespace dmd;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
IrFuncTy &DtoIrTypeFunction(DValue *fnval) {
|
||||
|
@ -963,7 +965,7 @@ DValue *DtoCallFunction(const Loc &loc, Type *resulttype, DValue *fnval,
|
|||
switch (rbase->ty) {
|
||||
case TY::Tarray:
|
||||
if (tf->isref()) {
|
||||
retllval = DtoBitCast(retllval, DtoType(rbase->pointerTo()));
|
||||
retllval = DtoBitCast(retllval, DtoType(pointerTo(rbase)));
|
||||
} else {
|
||||
retllval = DtoSlicePaint(retllval, DtoType(rbase));
|
||||
}
|
||||
|
@ -972,7 +974,7 @@ DValue *DtoCallFunction(const Loc &loc, Type *resulttype, DValue *fnval,
|
|||
case TY::Tsarray:
|
||||
if (nextbase->ty == TY::Tvector && !tf->isref()) {
|
||||
if (retValIsLVal) {
|
||||
retllval = DtoBitCast(retllval, DtoType(rbase->pointerTo()));
|
||||
retllval = DtoBitCast(retllval, DtoType(pointerTo(rbase)));
|
||||
} else {
|
||||
// static arrays need to be dumped to memory; use vector alignment
|
||||
retllval =
|
||||
|
@ -988,7 +990,7 @@ DValue *DtoCallFunction(const Loc &loc, Type *resulttype, DValue *fnval,
|
|||
case TY::Taarray:
|
||||
case TY::Tpointer:
|
||||
if (tf->isref()) {
|
||||
retllval = DtoBitCast(retllval, DtoType(rbase->pointerTo()));
|
||||
retllval = DtoBitCast(retllval, DtoType(pointerTo(rbase)));
|
||||
} else {
|
||||
retllval = DtoBitCast(retllval, DtoType(rbase));
|
||||
}
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
#include "ir/irtypeclass.h"
|
||||
#include "ir/irtypestruct.h"
|
||||
|
||||
using namespace dmd;
|
||||
|
||||
/// Emits an LLVM constant corresponding to the expression (or an error if
|
||||
/// impossible).
|
||||
class ToConstElemVisitor : public Visitor {
|
||||
|
@ -253,7 +255,7 @@ public:
|
|||
e->type->toChars());
|
||||
LOG_SCOPE;
|
||||
|
||||
if (e->type->equivalent(e->e1->type)) {
|
||||
if (equivalent(e->type, e->e1->type)) {
|
||||
if (!e->lwr && !e->upr) {
|
||||
result = toConstElem(e->e1, p);
|
||||
return;
|
||||
|
@ -425,7 +427,7 @@ public:
|
|||
// gep
|
||||
LLConstant *idxs[2] = {DtoConstSize_t(0), index};
|
||||
LLConstant *val = isaConstant(getIrGlobal(vd)->value);
|
||||
val = DtoBitCast(val, DtoType(vd->type->pointerTo()));
|
||||
val = DtoBitCast(val, DtoType(pointerTo(vd->type)));
|
||||
LLConstant *gep = llvm::ConstantExpr::getGetElementPtr(
|
||||
DtoType(vd->type), val, idxs, true);
|
||||
|
||||
|
|
12
gen/toir.cpp
12
gen/toir.cpp
|
@ -56,6 +56,8 @@
|
|||
#include <stack>
|
||||
#include <stdio.h>
|
||||
|
||||
using namespace dmd;
|
||||
|
||||
llvm::cl::opt<bool> checkPrintf(
|
||||
"check-printf-calls", llvm::cl::ZeroOrMore, llvm::cl::ReallyHidden,
|
||||
llvm::cl::desc("Validate printf call format strings against arguments"));
|
||||
|
@ -1249,7 +1251,7 @@ public:
|
|||
|
||||
// in this case, we also need to make sure the pointer is cast to the
|
||||
// innermost element type
|
||||
eptr = DtoBitCast(eptr, DtoType(tsa->nextOf()->pointerTo()));
|
||||
eptr = DtoBitCast(eptr, DtoType(pointerTo(tsa->nextOf())));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2074,7 +2076,7 @@ public:
|
|||
LLValue *retPtr = nullptr;
|
||||
if (!(dtype->ty == TY::Tvoid || dtype->ty == TY::Tnoreturn)) {
|
||||
// allocate a temporary for pointer to the final result.
|
||||
retPtr = DtoAlloca(dtype->pointerTo(), "condtmp");
|
||||
retPtr = DtoAlloca(pointerTo(dtype), "condtmp");
|
||||
}
|
||||
|
||||
llvm::BasicBlock *condtrue = p->insertBB("condtrue");
|
||||
|
@ -2376,7 +2378,7 @@ public:
|
|||
DtoMemSetZero(DtoType(e->type), dstMem);
|
||||
} else {
|
||||
LLValue *initsym = getIrAggr(sd)->getInitSymbol();
|
||||
initsym = DtoBitCast(initsym, DtoType(e->type->pointerTo()));
|
||||
initsym = DtoBitCast(initsym, DtoType(pointerTo(e->type)));
|
||||
assert(dstMem->getType() == initsym->getType());
|
||||
DtoMemCpy(DtoType(e->type), dstMem, initsym);
|
||||
}
|
||||
|
@ -2811,11 +2813,11 @@ public:
|
|||
// to an Interface instance, which has the type info as its first
|
||||
// member, so we have to add an extra layer of indirection.
|
||||
resultType = getInterfaceTypeInfoType();
|
||||
LLType *pres = DtoType(resultType->pointerTo());
|
||||
LLType *pres = DtoType(pointerTo(resultType));
|
||||
typinf = DtoLoad(pres, DtoBitCast(typinf, pres->getPointerTo()));
|
||||
} else {
|
||||
resultType = getClassInfoType();
|
||||
typinf = DtoBitCast(typinf, DtoType(resultType->pointerTo()));
|
||||
typinf = DtoBitCast(typinf, DtoType(pointerTo(resultType)));
|
||||
}
|
||||
|
||||
result = new DLValue(resultType, typinf);
|
||||
|
|
|
@ -58,6 +58,8 @@
|
|||
#include <cassert>
|
||||
#include <cstdio>
|
||||
|
||||
using namespace dmd;
|
||||
|
||||
TypeInfoDeclaration *getOrCreateTypeInfoDeclaration(const Loc &loc, Type *forType) {
|
||||
IF_LOG Logger::println("getOrCreateTypeInfoDeclaration(): %s",
|
||||
forType->toChars());
|
||||
|
@ -343,7 +345,7 @@ public:
|
|||
|
||||
RTTIBuilder b(getConstTypeInfoType());
|
||||
// TypeInfo base
|
||||
b.push_typeinfo(merge(decl->tinfo->mutableOf()));
|
||||
b.push_typeinfo(merge(mutableOf(decl->tinfo)));
|
||||
// finish
|
||||
b.finalize(gvar);
|
||||
}
|
||||
|
@ -357,7 +359,7 @@ public:
|
|||
|
||||
RTTIBuilder b(getInvariantTypeInfoType());
|
||||
// TypeInfo base
|
||||
b.push_typeinfo(merge(decl->tinfo->mutableOf()));
|
||||
b.push_typeinfo(merge(mutableOf(decl->tinfo)));
|
||||
// finish
|
||||
b.finalize(gvar);
|
||||
}
|
||||
|
@ -371,7 +373,7 @@ public:
|
|||
|
||||
RTTIBuilder b(getSharedTypeInfoType());
|
||||
// TypeInfo base
|
||||
b.push_typeinfo(merge(decl->tinfo->unSharedOf()));
|
||||
b.push_typeinfo(merge(unSharedOf(decl->tinfo)));
|
||||
// finish
|
||||
b.finalize(gvar);
|
||||
}
|
||||
|
@ -385,7 +387,7 @@ public:
|
|||
|
||||
RTTIBuilder b(getInoutTypeInfoType());
|
||||
// TypeInfo base
|
||||
b.push_typeinfo(merge(decl->tinfo->mutableOf()));
|
||||
b.push_typeinfo(merge(mutableOf(decl->tinfo)));
|
||||
// finish
|
||||
b.finalize(gvar);
|
||||
}
|
||||
|
|
|
@ -18,8 +18,6 @@ struct Loc;
|
|||
class Type;
|
||||
class TypeInfoDeclaration;
|
||||
|
||||
bool builtinTypeInfo(Type *t); // in dmd/typinf.d
|
||||
|
||||
namespace llvm {
|
||||
class GlobalVariable;
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
#include "llvm/ADT/StringExtras.h"
|
||||
#include "llvm/ADT/StringSwitch.h"
|
||||
|
||||
using namespace dmd;
|
||||
|
||||
namespace {
|
||||
|
||||
/// Checks whether `moduleDecl` is in the ldc package and it's identifier is
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
#include "ir/irtypestruct.h"
|
||||
#include <algorithm>
|
||||
|
||||
using namespace dmd;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
llvm::StructType *IrAggr::getLLStructType() {
|
||||
|
|
|
@ -40,6 +40,8 @@
|
|||
#include "llvm/Support/raw_ostream.h"
|
||||
#endif
|
||||
|
||||
using namespace dmd;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
IrClass::IrClass(ClassDeclaration *cd) : IrAggr(cd) {
|
||||
|
@ -217,7 +219,7 @@ LLConstant *IrClass::getVtblInit() {
|
|||
// it is probably a bug that it still occurs that late.
|
||||
if (fd->inferRetType() && !fd->type->nextOf()) {
|
||||
Logger::println("Running late functionSemantic to infer return type.");
|
||||
if (!fd->functionSemantic()) {
|
||||
if (!functionSemantic(fd)) {
|
||||
if (fd->hasSemantic3Errors()) {
|
||||
Logger::println(
|
||||
"functionSemantic failed; using null for vtbl entry.");
|
||||
|
@ -247,8 +249,8 @@ LLConstant *IrClass::getVtblInit() {
|
|||
if (fd2->isFuture()) {
|
||||
continue;
|
||||
}
|
||||
if (fd->leastAsSpecialized(fd2, nullptr) != MATCH::nomatch ||
|
||||
fd2->leastAsSpecialized(fd, nullptr) != MATCH::nomatch) {
|
||||
if (FuncDeclaration::leastAsSpecialized(fd, fd2, nullptr) != MATCH::nomatch ||
|
||||
FuncDeclaration::leastAsSpecialized(fd2, fd, nullptr) != MATCH::nomatch) {
|
||||
TypeFunction *tf = static_cast<TypeFunction *>(fd->type);
|
||||
if (tf->ty == TY::Tfunction) {
|
||||
error(cd->loc,
|
||||
|
@ -705,7 +707,7 @@ LLConstant *IrClass::getClassInfoInterfaces() {
|
|||
constants.reserve(cd->vtblInterfaces->length);
|
||||
|
||||
LLType *classinfo_type = DtoType(getClassInfoType());
|
||||
LLType *voidptrptr_type = DtoType(Type::tvoid->pointerTo()->pointerTo());
|
||||
LLType *voidptrptr_type = DtoType(pointerTo(pointerTo(Type::tvoid)));
|
||||
LLStructType *interface_type =
|
||||
isaStruct(DtoType(interfacesArrayType->nextOf()));
|
||||
assert(interface_type);
|
||||
|
|
|
@ -17,9 +17,11 @@
|
|||
#include "gen/logger.h"
|
||||
#include "gen/tollvm.h"
|
||||
|
||||
using namespace dmd;
|
||||
|
||||
IrFuncTyArg::IrFuncTyArg(Type *t, bool bref)
|
||||
: type(t),
|
||||
ltype(t != Type::tvoid && bref ? DtoType(t->pointerTo()) : DtoType(t)),
|
||||
ltype(t != Type::tvoid && bref ? DtoType(pointerTo(t)) : DtoType(t)),
|
||||
#if LDC_LLVM_VER >= 1400
|
||||
attrs(getGlobalContext()),
|
||||
#endif
|
||||
|
@ -29,7 +31,7 @@ IrFuncTyArg::IrFuncTyArg(Type *t, bool bref)
|
|||
|
||||
IrFuncTyArg::IrFuncTyArg(Type *t, bool bref, llvm::AttrBuilder a)
|
||||
: type(t),
|
||||
ltype(t != Type::tvoid && bref ? DtoType(t->pointerTo()) : DtoType(t)),
|
||||
ltype(t != Type::tvoid && bref ? DtoType(pointerTo(t)) : DtoType(t)),
|
||||
attrs(std::move(a)), byref(bref) {
|
||||
|
||||
mem.addRange(&type, sizeof(type));
|
||||
|
|
|
@ -23,8 +23,7 @@
|
|||
#include "ir/iraggr.h"
|
||||
#include "ir/irtypeclass.h"
|
||||
|
||||
// in semantic3.d
|
||||
void semanticTypeInfoMembers(StructDeclaration *sd);
|
||||
using namespace dmd;
|
||||
|
||||
namespace {
|
||||
LLStructType* getTypeInfoStructMemType() {
|
||||
|
@ -156,7 +155,7 @@ LLConstant *IrStruct::getTypeInfoInit() {
|
|||
b.push_funcptr(isOpaque ? nullptr : search_toString(sd));
|
||||
|
||||
// StructFlags m_flags
|
||||
b.push_uint(!isOpaque && ts->hasPointers() ? 1 : 0);
|
||||
b.push_uint(!isOpaque && hasPointers(ts) ? 1 : 0);
|
||||
|
||||
// function xdtor/xdtorti
|
||||
b.push_funcptr(isOpaque ? nullptr : sd->tidtor);
|
||||
|
@ -188,7 +187,7 @@ LLConstant *IrStruct::getTypeInfoInit() {
|
|||
if (!isOpaque && sd->getRTInfo) {
|
||||
b.push(toConstElem(sd->getRTInfo, gIR));
|
||||
} else {
|
||||
b.push_size_as_vp(!isOpaque && ts->hasPointers() ? 1 : 0);
|
||||
b.push_size_as_vp(!isOpaque && hasPointers(ts) ? 1 : 0);
|
||||
}
|
||||
|
||||
constTypeInfo = b.get_constant(getTypeInfoStructMemType());
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
#include "gen/tollvm.h"
|
||||
#include "llvm/IR/DerivedTypes.h"
|
||||
|
||||
using namespace dmd;
|
||||
|
||||
IrTypeFunction::IrTypeFunction(Type *dt, llvm::Type *lt, IrFuncTy irFty_)
|
||||
: IrType(dt, lt), irFty(std::move(irFty_)) {}
|
||||
|
||||
|
@ -52,7 +54,7 @@ IrTypeDelegate *IrTypeDelegate::get(Type *t) {
|
|||
|
||||
IrFuncTy irFty(tf);
|
||||
llvm::Type *ltf =
|
||||
DtoFunctionType(tf, irFty, nullptr, Type::tvoid->pointerTo());
|
||||
DtoFunctionType(tf, irFty, nullptr, pointerTo(Type::tvoid));
|
||||
llvm::Type *fptr = ltf->getPointerTo(gDataLayout->getProgramAddressSpace());
|
||||
llvm::Type *types[] = {getVoidPtrType(), fptr};
|
||||
LLStructType *lt = LLStructType::get(gIR->context(), types, false);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue