mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-12 22:14:54 +03:00
Added IrTypeFunction and IrTypeDelegate and eliminated IrDType. This means the Type::ir field can be removed. It's the final part needed for the move to a slightly more sane type system. Now the whole thing just needs to be cleaned up :P
Added -v-cg switch, which right now just prints "codegen: module.name (module/name.d)" to stdout, this can really help figuring out where, in some complex build command, things go wrong.
This commit is contained in:
parent
61514569ff
commit
c0f2af5afd
20 changed files with 148 additions and 129 deletions
|
@ -82,10 +82,9 @@ typedef union tree_node TYPE;
|
||||||
struct TYPE;
|
struct TYPE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// llvm
|
|
||||||
#if IN_LLVM
|
#if IN_LLVM
|
||||||
struct Ir;
|
class Ir;
|
||||||
struct IrSymbol;
|
class IrSymbol;
|
||||||
namespace llvm
|
namespace llvm
|
||||||
{
|
{
|
||||||
class Value;
|
class Value;
|
||||||
|
|
|
@ -219,6 +219,7 @@ struct Param
|
||||||
OUTPUTFLAG output_o;
|
OUTPUTFLAG output_o;
|
||||||
bool llvmAnnotate;
|
bool llvmAnnotate;
|
||||||
bool useInlineAsm;
|
bool useInlineAsm;
|
||||||
|
bool verbose_cg;
|
||||||
|
|
||||||
// target stuff
|
// target stuff
|
||||||
const char* llvmArch;
|
const char* llvmArch;
|
||||||
|
|
|
@ -28,7 +28,7 @@ struct Library;
|
||||||
|
|
||||||
// Back end
|
// Back end
|
||||||
#if IN_LLVM
|
#if IN_LLVM
|
||||||
struct Ir;
|
class Ir;
|
||||||
struct DValue;
|
struct DValue;
|
||||||
typedef DValue elem;
|
typedef DValue elem;
|
||||||
namespace llvm { class Module; }
|
namespace llvm { class Module; }
|
||||||
|
|
|
@ -22,12 +22,9 @@
|
||||||
#include "expression.h"
|
#include "expression.h"
|
||||||
|
|
||||||
#if IN_LLVM
|
#if IN_LLVM
|
||||||
// llvm
|
|
||||||
#include "../ir/irdtype.h"
|
|
||||||
#include "../ir/irfuncty.h"
|
#include "../ir/irfuncty.h"
|
||||||
namespace llvm { class Type; }
|
namespace llvm { class Type; }
|
||||||
struct Ir;
|
class Ir;
|
||||||
|
|
||||||
class IrType;
|
class IrType;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -284,10 +281,7 @@ struct Type : Object
|
||||||
virtual TypeBasic *isTypeBasic();
|
virtual TypeBasic *isTypeBasic();
|
||||||
|
|
||||||
#if IN_LLVM
|
#if IN_LLVM
|
||||||
// LDC
|
|
||||||
IrDType ir;
|
|
||||||
static Ir* sir;
|
static Ir* sir;
|
||||||
|
|
||||||
IrType* irtype;
|
IrType* irtype;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
|
@ -44,6 +44,11 @@ static cl::opt<bool, true> verbose("v",
|
||||||
cl::ZeroOrMore,
|
cl::ZeroOrMore,
|
||||||
cl::location(global.params.verbose));
|
cl::location(global.params.verbose));
|
||||||
|
|
||||||
|
static cl::opt<bool, true> verbose_cg("v-cg",
|
||||||
|
cl::desc("Verbose codegen"),
|
||||||
|
cl::ZeroOrMore,
|
||||||
|
cl::location(global.params.verbose_cg));
|
||||||
|
|
||||||
static cl::opt<bool, true> warnings("w",
|
static cl::opt<bool, true> warnings("w",
|
||||||
cl::desc("Enable warnings"),
|
cl::desc("Enable warnings"),
|
||||||
cl::ZeroOrMore,
|
cl::ZeroOrMore,
|
||||||
|
|
|
@ -27,15 +27,10 @@ using namespace llvm::Attribute;
|
||||||
|
|
||||||
const llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nesttype, bool ismain)
|
const llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nesttype, bool ismain)
|
||||||
{
|
{
|
||||||
// already built ?
|
|
||||||
if (type->ir.type != NULL) {
|
|
||||||
//assert(f->fty != NULL);
|
|
||||||
return llvm::cast<llvm::FunctionType>(type->ir.type->get());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Logger::enabled())
|
if (Logger::enabled())
|
||||||
Logger::println("DtoFunctionType(%s)", type->toChars());
|
Logger::println("DtoFunctionType(%s)", type->toChars());
|
||||||
LOG_SCOPE
|
LOG_SCOPE
|
||||||
|
|
||||||
// sanity check
|
// sanity check
|
||||||
assert(type->ty == Tfunction);
|
assert(type->ty == Tfunction);
|
||||||
TypeFunction* f = (TypeFunction*)type;
|
TypeFunction* f = (TypeFunction*)type;
|
||||||
|
@ -165,27 +160,6 @@ const llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nest
|
||||||
lidx++;
|
lidx++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the function type was forward referenced by one of the parameter types,
|
|
||||||
// it has now been set.
|
|
||||||
if (f->ir.type) {
|
|
||||||
// Notify ABI that we won't be needing it for this function type anymore.
|
|
||||||
abi->doneWithFunctionType();
|
|
||||||
|
|
||||||
// Some cleanup of memory we won't use
|
|
||||||
delete fty.ret;
|
|
||||||
delete fty.arg_sret;
|
|
||||||
delete fty.arg_this;
|
|
||||||
delete fty.arg_nest;
|
|
||||||
delete fty.arg_arguments;
|
|
||||||
delete fty.arg_argptr;
|
|
||||||
for (IrFuncTy::ArgIter It = fty.args.begin(), E = fty.args.end(); It != E; ++It) {
|
|
||||||
delete *It;
|
|
||||||
}
|
|
||||||
|
|
||||||
Logger::cout() << "Final function type: " << **f->ir.type << '\n';
|
|
||||||
return llvm::cast<LLFunctionType>(*f->ir.type);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now we can modify f->fty safely.
|
// Now we can modify f->fty safely.
|
||||||
f->fty = fty;
|
f->fty = fty;
|
||||||
|
|
||||||
|
@ -219,7 +193,6 @@ const llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nest
|
||||||
}
|
}
|
||||||
|
|
||||||
llvm::FunctionType* functype = llvm::FunctionType::get(f->fty.ret->ltype, argtypes, f->fty.c_vararg);
|
llvm::FunctionType* functype = llvm::FunctionType::get(f->fty.ret->ltype, argtypes, f->fty.c_vararg);
|
||||||
f->ir.type = new llvm::PATypeHolder(functype);
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
Logger::cout() << "Final function type: " << *functype << "\n";
|
Logger::cout() << "Final function type: " << *functype << "\n";
|
||||||
|
@ -232,11 +205,6 @@ const llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nest
|
||||||
|
|
||||||
static const llvm::FunctionType* DtoVaFunctionType(FuncDeclaration* fdecl)
|
static const llvm::FunctionType* DtoVaFunctionType(FuncDeclaration* fdecl)
|
||||||
{
|
{
|
||||||
// type has already been resolved
|
|
||||||
if (fdecl->type->ir.type != 0) {
|
|
||||||
return llvm::cast<llvm::FunctionType>(fdecl->type->ir.type->get());
|
|
||||||
}
|
|
||||||
|
|
||||||
TypeFunction* f = (TypeFunction*)fdecl->type;
|
TypeFunction* f = (TypeFunction*)fdecl->type;
|
||||||
const llvm::FunctionType* fty = 0;
|
const llvm::FunctionType* fty = 0;
|
||||||
|
|
||||||
|
@ -256,7 +224,6 @@ static const llvm::FunctionType* DtoVaFunctionType(FuncDeclaration* fdecl)
|
||||||
fty = GET_INTRINSIC_DECL(vaend)->getFunctionType();
|
fty = GET_INTRINSIC_DECL(vaend)->getFunctionType();
|
||||||
assert(fty);
|
assert(fty);
|
||||||
|
|
||||||
f->ir.type = new llvm::PATypeHolder(fty);
|
|
||||||
return fty;
|
return fty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -264,10 +231,6 @@ static const llvm::FunctionType* DtoVaFunctionType(FuncDeclaration* fdecl)
|
||||||
|
|
||||||
const llvm::FunctionType* DtoFunctionType(FuncDeclaration* fdecl)
|
const llvm::FunctionType* DtoFunctionType(FuncDeclaration* fdecl)
|
||||||
{
|
{
|
||||||
// type has already been resolved
|
|
||||||
if (fdecl->type->ir.type != 0)
|
|
||||||
return llvm::cast<llvm::FunctionType>(fdecl->type->ir.type->get());
|
|
||||||
|
|
||||||
// handle for C vararg intrinsics
|
// handle for C vararg intrinsics
|
||||||
if (fdecl->isVaIntrinsic())
|
if (fdecl->isVaIntrinsic())
|
||||||
return DtoVaFunctionType(fdecl);
|
return DtoVaFunctionType(fdecl);
|
||||||
|
@ -280,7 +243,7 @@ const llvm::FunctionType* DtoFunctionType(FuncDeclaration* fdecl)
|
||||||
dthis = ad->type;
|
dthis = ad->type;
|
||||||
const LLType* thisty = DtoType(dthis);
|
const LLType* thisty = DtoType(dthis);
|
||||||
//Logger::cout() << "this llvm type: " << *thisty << '\n';
|
//Logger::cout() << "this llvm type: " << *thisty << '\n';
|
||||||
if (isaStruct(thisty) || (!gIR->structs.empty() && thisty == gIR->topstruct()->type->ir.type->get()))
|
if (ad->isStructDeclaration())
|
||||||
thisty = getPtrToType(thisty);
|
thisty = getPtrToType(thisty);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -326,6 +289,9 @@ void DtoResolveFunction(FuncDeclaration* fdecl)
|
||||||
return; // ignore declaration completely
|
return; // ignore declaration completely
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fdecl->ir.resolved) return;
|
||||||
|
fdecl->ir.resolved = true;
|
||||||
|
|
||||||
//printf("resolve function: %s\n", fdecl->toPrettyChars());
|
//printf("resolve function: %s\n", fdecl->toPrettyChars());
|
||||||
|
|
||||||
if (fdecl->parent)
|
if (fdecl->parent)
|
||||||
|
@ -373,10 +339,7 @@ void DtoResolveFunction(FuncDeclaration* fdecl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DtoFunctionType(fdecl);
|
DtoType(fdecl->type);
|
||||||
|
|
||||||
if (fdecl->ir.resolved) return;
|
|
||||||
fdecl->ir.resolved = true;
|
|
||||||
|
|
||||||
Logger::println("DtoResolveFunction(%s): %s", fdecl->toPrettyChars(), fdecl->loc.toChars());
|
Logger::println("DtoResolveFunction(%s): %s", fdecl->toPrettyChars(), fdecl->loc.toChars());
|
||||||
LOG_SCOPE;
|
LOG_SCOPE;
|
||||||
|
@ -515,7 +478,6 @@ void DtoDeclareFunction(FuncDeclaration* fdecl)
|
||||||
func->setCallingConv(llvm::CallingConv::C);
|
func->setCallingConv(llvm::CallingConv::C);
|
||||||
|
|
||||||
fdecl->ir.irFunc->func = func;
|
fdecl->ir.irFunc->func = func;
|
||||||
assert(llvm::isa<llvm::FunctionType>(f->ir.type->get()));
|
|
||||||
|
|
||||||
// parameter attributes
|
// parameter attributes
|
||||||
if (!fdecl->isIntrinsic()) {
|
if (!fdecl->isIntrinsic()) {
|
||||||
|
@ -646,7 +608,7 @@ void DtoDefineFunction(FuncDeclaration* fd)
|
||||||
|
|
||||||
Type* t = fd->type->toBasetype();
|
Type* t = fd->type->toBasetype();
|
||||||
TypeFunction* f = (TypeFunction*)t;
|
TypeFunction* f = (TypeFunction*)t;
|
||||||
assert(f->ir.type);
|
assert(f->irtype);
|
||||||
|
|
||||||
llvm::Function* func = fd->ir.irFunc->func;
|
llvm::Function* func = fd->ir.irFunc->func;
|
||||||
const llvm::FunctionType* functype = func->getFunctionType();
|
const llvm::FunctionType* functype = func->getFunctionType();
|
||||||
|
|
|
@ -1,6 +1,18 @@
|
||||||
#ifndef LDC_GEN_FUNCTIONS_H
|
#ifndef LDC_GEN_FUNCTIONS_H
|
||||||
#define LDC_GEN_FUNCTIONS_H
|
#define LDC_GEN_FUNCTIONS_H
|
||||||
|
|
||||||
|
#include "mars.h"
|
||||||
|
|
||||||
|
struct FuncDeclaration;
|
||||||
|
struct Type;
|
||||||
|
|
||||||
|
struct IRAsmBlock;
|
||||||
|
|
||||||
|
namespace llvm
|
||||||
|
{
|
||||||
|
class Value;
|
||||||
|
}
|
||||||
|
|
||||||
const llvm::FunctionType* DtoFunctionType(Type* t, Type* thistype, Type* nesttype, bool ismain = false);
|
const llvm::FunctionType* DtoFunctionType(Type* t, Type* thistype, Type* nesttype, bool ismain = false);
|
||||||
const llvm::FunctionType* DtoFunctionType(FuncDeclaration* fdecl);
|
const llvm::FunctionType* DtoFunctionType(FuncDeclaration* fdecl);
|
||||||
|
|
||||||
|
@ -14,6 +26,6 @@ void DtoDefineNakedFunction(FuncDeclaration* fd);
|
||||||
void emitABIReturnAsmStmt(IRAsmBlock* asmblock, Loc loc, FuncDeclaration* fdecl);
|
void emitABIReturnAsmStmt(IRAsmBlock* asmblock, Loc loc, FuncDeclaration* fdecl);
|
||||||
|
|
||||||
DValue* DtoArgument(Argument* fnarg, Expression* argexp);
|
DValue* DtoArgument(Argument* fnarg, Expression* argexp);
|
||||||
void DtoVariadicArgument(Expression* argexp, LLValue* dst);
|
void DtoVariadicArgument(Expression* argexp, llvm::Value* dst);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -260,8 +260,7 @@ DValue* DtoCallFunction(Loc& loc, Type* resulttype, DValue* fnval, Expressions*
|
||||||
// the callee D type
|
// the callee D type
|
||||||
Type* calleeType = fnval->getType();
|
Type* calleeType = fnval->getType();
|
||||||
|
|
||||||
// if the type has not yet been processed, do so now
|
// make sure the callee type has been processed
|
||||||
if (calleeType->ir.type == NULL)
|
|
||||||
DtoType(calleeType);
|
DtoType(calleeType);
|
||||||
|
|
||||||
// get func value if any
|
// get func value if any
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
|
|
||||||
#include "ir/irtype.h"
|
#include "ir/irtype.h"
|
||||||
#include "ir/irtypeclass.h"
|
#include "ir/irtypeclass.h"
|
||||||
|
#include "ir/irtypefunction.h"
|
||||||
|
|
||||||
bool DtoIsPassedByRef(Type* type)
|
bool DtoIsPassedByRef(Type* type)
|
||||||
{
|
{
|
||||||
|
@ -131,27 +132,15 @@ const LLType* DtoType(Type* t)
|
||||||
// functions
|
// functions
|
||||||
case Tfunction:
|
case Tfunction:
|
||||||
{
|
{
|
||||||
if (!t->ir.type || *t->ir.type == NULL) {
|
t->irtype = new IrTypeFunction(t);
|
||||||
TypeFunction* tf = (TypeFunction*)t;
|
return t->irtype->buildType();
|
||||||
if (tf->funcdecl)
|
|
||||||
return DtoFunctionType(tf->funcdecl);
|
|
||||||
else
|
|
||||||
return DtoFunctionType(tf,NULL,NULL);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return t->ir.type->get();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// delegates
|
// delegates
|
||||||
case Tdelegate:
|
case Tdelegate:
|
||||||
{
|
{
|
||||||
if (!t->ir.type || *t->ir.type == NULL) {
|
t->irtype = new IrTypeDelegate(t);
|
||||||
return DtoDelegateType(t);
|
return t->irtype->buildType();
|
||||||
}
|
|
||||||
else {
|
|
||||||
return t->ir.type->get();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// typedefs
|
// typedefs
|
||||||
|
@ -220,19 +209,6 @@ const LLType* DtoTypeNotVoid(Type* t)
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
const LLStructType* DtoDelegateType(Type* t)
|
|
||||||
{
|
|
||||||
assert(t->ty == Tdelegate);
|
|
||||||
const LLType* i8ptr = getVoidPtrType();
|
|
||||||
const LLType* func = DtoFunctionType(t->nextOf(), NULL, Type::tvoid->pointerTo());
|
|
||||||
const LLType* funcptr = getPtrToType(func);
|
|
||||||
const LLStructType* dgtype = LLStructType::get(i8ptr, funcptr, NULL);
|
|
||||||
gIR->module->addTypeName(t->toChars(), dgtype);
|
|
||||||
return dgtype;
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
LLValue* DtoDelegateEquals(TOK op, LLValue* lhs, LLValue* rhs)
|
LLValue* DtoDelegateEquals(TOK op, LLValue* lhs, LLValue* rhs)
|
||||||
{
|
{
|
||||||
Logger::println("Doing delegate equality");
|
Logger::println("Doing delegate equality");
|
||||||
|
@ -799,7 +775,7 @@ const LLStructType* DtoInterfaceInfoType()
|
||||||
// ClassInfo classinfo
|
// ClassInfo classinfo
|
||||||
ClassDeclaration* cd2 = ClassDeclaration::classinfo;
|
ClassDeclaration* cd2 = ClassDeclaration::classinfo;
|
||||||
DtoResolveClass(cd2);
|
DtoResolveClass(cd2);
|
||||||
types.push_back(getPtrToType(cd2->type->ir.type->get()));
|
types.push_back(DtoType(cd2->type));
|
||||||
// void*[] vtbl
|
// void*[] vtbl
|
||||||
std::vector<const LLType*> vtbltypes;
|
std::vector<const LLType*> vtbltypes;
|
||||||
vtbltypes.push_back(DtoSize_t());
|
vtbltypes.push_back(DtoSize_t());
|
||||||
|
|
|
@ -26,7 +26,6 @@ unsigned DtoShouldExtend(Type* type);
|
||||||
//const LLType* DtoStructTypeFromArguments(Arguments* arguments);
|
//const LLType* DtoStructTypeFromArguments(Arguments* arguments);
|
||||||
|
|
||||||
// delegate helpers
|
// delegate helpers
|
||||||
const LLStructType* DtoDelegateType(Type* t);
|
|
||||||
LLValue* DtoDelegateEquals(TOK op, LLValue* lhs, LLValue* rhs);
|
LLValue* DtoDelegateEquals(TOK op, LLValue* lhs, LLValue* rhs);
|
||||||
|
|
||||||
// return linkage type for symbol using the current ir state for context
|
// return linkage type for symbol using the current ir state for context
|
||||||
|
|
|
@ -54,6 +54,7 @@
|
||||||
|
|
||||||
#include "ir/irvar.h"
|
#include "ir/irvar.h"
|
||||||
#include "ir/irmodule.h"
|
#include "ir/irmodule.h"
|
||||||
|
#include "ir/irtype.h"
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@ -80,7 +81,8 @@ llvm::Module* Module::genLLVMModule(Ir* sir)
|
||||||
Logger::println("Generating module: %s\n", (md ? md->toChars() : toChars()));
|
Logger::println("Generating module: %s\n", (md ? md->toChars() : toChars()));
|
||||||
LOG_SCOPE;
|
LOG_SCOPE;
|
||||||
|
|
||||||
//printf("codegen: %s\n", srcfile->toChars());
|
if (global.params.verbose_cg)
|
||||||
|
printf("codegen: %s (%s)\n", toPrettyChars(), srcfile->toChars());
|
||||||
|
|
||||||
assert(!global.errors);
|
assert(!global.errors);
|
||||||
|
|
||||||
|
@ -609,9 +611,9 @@ void Module::genmoduleinfo()
|
||||||
}
|
}
|
||||||
|
|
||||||
// moduleinfo llvm struct type
|
// moduleinfo llvm struct type
|
||||||
const llvm::StructType* moduleinfoTy = isaStruct(moduleinfo->type->ir.type->get());
|
const llvm::StructType* moduleinfoTy = isaStruct(moduleinfo->type->irtype->getPA());
|
||||||
// classinfo llvm struct type
|
// classinfo llvm struct type
|
||||||
const llvm::StructType* classinfoTy = isaStruct(ClassDeclaration::classinfo->type->ir.type->get());
|
const llvm::StructType* classinfoTy = isaStruct(ClassDeclaration::classinfo->type->irtype->getPA());
|
||||||
|
|
||||||
// initializer vector
|
// initializer vector
|
||||||
std::vector<LLConstant*> initVec;
|
std::vector<LLConstant*> initVec;
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
#include "gen/metadata.h"
|
#include "gen/metadata.h"
|
||||||
|
|
||||||
#include "ir/irvar.h"
|
#include "ir/irvar.h"
|
||||||
|
#include "ir/irtype.h"
|
||||||
|
|
||||||
/*******************************************
|
/*******************************************
|
||||||
* Get a canonicalized form of the TypeInfo for use with the internal
|
* Get a canonicalized form of the TypeInfo for use with the internal
|
||||||
|
@ -331,7 +332,7 @@ void DtoDeclareTypeInfo(TypeInfoDeclaration* tid)
|
||||||
// this is a declaration of a builtin __initZ var
|
// this is a declaration of a builtin __initZ var
|
||||||
if (tid->tinfo->builtinTypeInfo()) {
|
if (tid->tinfo->builtinTypeInfo()) {
|
||||||
// fixup the global
|
// fixup the global
|
||||||
const llvm::Type* rty = Type::typeinfo->type->ir.type->get();
|
const llvm::Type* rty = Type::typeinfo->type->irtype->getPA().get();
|
||||||
llvm::cast<llvm::OpaqueType>(irg->type.get())->refineAbstractTypeTo(rty);
|
llvm::cast<llvm::OpaqueType>(irg->type.get())->refineAbstractTypeTo(rty);
|
||||||
LLGlobalVariable* g = isaGlobalVar(irg->value);
|
LLGlobalVariable* g = isaGlobalVar(irg->value);
|
||||||
g->setLinkage(llvm::GlobalValue::ExternalLinkage);
|
g->setLinkage(llvm::GlobalValue::ExternalLinkage);
|
||||||
|
@ -544,7 +545,7 @@ void TypeInfoStaticArrayDeclaration::llvmDefine()
|
||||||
base->codegen(Type::sir);
|
base->codegen(Type::sir);
|
||||||
|
|
||||||
// get type of typeinfo class
|
// get type of typeinfo class
|
||||||
const LLStructType* stype = isaStruct(base->type->ir.type->get());
|
const LLStructType* stype = isaStruct(base->type->irtype->getPA().get());
|
||||||
|
|
||||||
// initializer vector
|
// initializer vector
|
||||||
std::vector<LLConstant*> sinits;
|
std::vector<LLConstant*> sinits;
|
||||||
|
@ -665,7 +666,7 @@ void TypeInfoStructDeclaration::llvmDefine()
|
||||||
ClassDeclaration* base = Type::typeinfostruct;
|
ClassDeclaration* base = Type::typeinfostruct;
|
||||||
base->codegen(Type::sir);
|
base->codegen(Type::sir);
|
||||||
|
|
||||||
const LLStructType* stype = isaStruct(base->type->ir.type->get());
|
const LLStructType* stype = isaStruct(base->type->irtype->getPA());
|
||||||
|
|
||||||
// vtbl
|
// vtbl
|
||||||
std::vector<LLConstant*> sinits;
|
std::vector<LLConstant*> sinits;
|
||||||
|
@ -691,7 +692,7 @@ void TypeInfoStructDeclaration::llvmDefine()
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
size_t cisize = getTypeStoreSize(tc->ir.type->get());
|
size_t cisize = getTypeStoreSize(tc->irtype->getPA().get());
|
||||||
LLConstant* cicast = llvm::ConstantExpr::getBitCast(sd->ir.irStruct->getInitSymbol(), initpt);
|
LLConstant* cicast = llvm::ConstantExpr::getBitCast(sd->ir.irStruct->getInitSymbol(), initpt);
|
||||||
sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast));
|
sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast));
|
||||||
}
|
}
|
||||||
|
@ -903,7 +904,7 @@ void TypeInfoInterfaceDeclaration::llvmDefine()
|
||||||
base->codegen(Type::sir);
|
base->codegen(Type::sir);
|
||||||
|
|
||||||
// get type of typeinfo class
|
// get type of typeinfo class
|
||||||
const LLStructType* stype = isaStruct(base->type->ir.type->get());
|
const LLStructType* stype = isaStruct(base->type->irtype->getPA());
|
||||||
|
|
||||||
// initializer vector
|
// initializer vector
|
||||||
std::vector<LLConstant*> sinits;
|
std::vector<LLConstant*> sinits;
|
||||||
|
@ -939,7 +940,7 @@ void TypeInfoTupleDeclaration::llvmDefine()
|
||||||
base->codegen(Type::sir);
|
base->codegen(Type::sir);
|
||||||
|
|
||||||
// get type of typeinfo class
|
// get type of typeinfo class
|
||||||
const LLStructType* stype = isaStruct(base->type->ir.type->get());
|
const LLStructType* stype = isaStruct(base->type->irtype->getPA());
|
||||||
|
|
||||||
// initializer vector
|
// initializer vector
|
||||||
std::vector<LLConstant*> sinits;
|
std::vector<LLConstant*> sinits;
|
||||||
|
@ -956,7 +957,7 @@ void TypeInfoTupleDeclaration::llvmDefine()
|
||||||
size_t dim = tu->arguments->dim;
|
size_t dim = tu->arguments->dim;
|
||||||
std::vector<LLConstant*> arrInits;
|
std::vector<LLConstant*> arrInits;
|
||||||
|
|
||||||
const LLType* tiTy = Type::typeinfo->type->ir.type->get();
|
const LLType* tiTy = Type::typeinfo->type->irtype->getPA();
|
||||||
tiTy = getPtrToType(tiTy);
|
tiTy = getPtrToType(tiTy);
|
||||||
|
|
||||||
for (size_t i = 0; i < dim; i++)
|
for (size_t i = 0; i < dim; i++)
|
||||||
|
|
3
ir/ir.h
3
ir/ir.h
|
@ -16,8 +16,9 @@ struct IrBase : Object
|
||||||
virtual ~IrBase() {}
|
virtual ~IrBase() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Ir
|
class Ir
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
Ir();
|
Ir();
|
||||||
|
|
||||||
void setState(IRState* p) { irs = p; }
|
void setState(IRState* p) { irs = p; }
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
#include "gen/llvm.h"
|
|
||||||
#include "ir/ir.h"
|
|
||||||
#include "ir/irdtype.h"
|
|
||||||
|
|
||||||
IrDType::IrDType()
|
|
||||||
{
|
|
||||||
type = NULL;
|
|
||||||
}
|
|
16
ir/irdtype.h
16
ir/irdtype.h
|
@ -1,16 +0,0 @@
|
||||||
#ifndef LDC_IR_IRDTYPE_H
|
|
||||||
#define LDC_IR_IRDTYPE_H
|
|
||||||
|
|
||||||
#include <set>
|
|
||||||
|
|
||||||
namespace llvm {
|
|
||||||
class PATypeHolder;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct IrDType
|
|
||||||
{
|
|
||||||
IrDType();
|
|
||||||
llvm::PATypeHolder* type;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -4,8 +4,9 @@
|
||||||
#include "ir/ir.h"
|
#include "ir/ir.h"
|
||||||
|
|
||||||
/// Base class for all symbols.
|
/// Base class for all symbols.
|
||||||
struct IrSymbol
|
class IrSymbol
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
///
|
///
|
||||||
IrSymbol(Ir* ir) : ir(ir) {}
|
IrSymbol(Ir* ir) : ir(ir) {}
|
||||||
|
|
||||||
|
|
|
@ -18,8 +18,7 @@ IrType::IrType(Type* dt, const llvm::Type* lt)
|
||||||
{
|
{
|
||||||
assert(dt && "null D Type");
|
assert(dt && "null D Type");
|
||||||
assert(lt && "null LLVM Type");
|
assert(lt && "null LLVM Type");
|
||||||
assert(dt->ir.type == NULL && "llvm type (old one) already set");
|
assert(dt->irtype == NULL && "already has IrType");
|
||||||
dt->ir.type = &pa;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -13,6 +13,7 @@ class IrTypeAggr;
|
||||||
class IrTypeArray;
|
class IrTypeArray;
|
||||||
class IrTypeBasic;
|
class IrTypeBasic;
|
||||||
class IrTypeClass;
|
class IrTypeClass;
|
||||||
|
class IrTypeFunction;
|
||||||
class IrTypePointer;
|
class IrTypePointer;
|
||||||
class IrTypeSArray;
|
class IrTypeSArray;
|
||||||
class IrTypeStruct;
|
class IrTypeStruct;
|
||||||
|
@ -35,6 +36,8 @@ public:
|
||||||
///
|
///
|
||||||
virtual IrTypeClass* isClass() { return NULL; }
|
virtual IrTypeClass* isClass() { return NULL; }
|
||||||
///
|
///
|
||||||
|
virtual IrTypeFunction* isFunction(){ return NULL; }
|
||||||
|
///
|
||||||
virtual IrTypePointer* isPointer() { return NULL; }
|
virtual IrTypePointer* isPointer() { return NULL; }
|
||||||
///
|
///
|
||||||
virtual IrTypeSArray* isSArray() { return NULL; }
|
virtual IrTypeSArray* isSArray() { return NULL; }
|
||||||
|
|
47
ir/irtypefunction.cpp
Normal file
47
ir/irtypefunction.cpp
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
#include "llvm/DerivedTypes.h"
|
||||||
|
#include "mtype.h"
|
||||||
|
|
||||||
|
#include "gen/irstate.h"
|
||||||
|
#include "gen/tollvm.h"
|
||||||
|
#include "gen/functions.h"
|
||||||
|
|
||||||
|
#include "ir/irtypefunction.h"
|
||||||
|
|
||||||
|
IrTypeFunction::IrTypeFunction(Type * dt)
|
||||||
|
: IrType(dt, llvm::OpaqueType::get())
|
||||||
|
{
|
||||||
|
irfty = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
const llvm::Type * IrTypeFunction::buildType()
|
||||||
|
{
|
||||||
|
const llvm::Type* T;
|
||||||
|
TypeFunction* tf = (TypeFunction*)dtype;
|
||||||
|
if (tf->funcdecl)
|
||||||
|
T = DtoFunctionType(tf->funcdecl);
|
||||||
|
else
|
||||||
|
T = DtoFunctionType(tf,NULL,NULL);
|
||||||
|
|
||||||
|
llvm::cast<llvm::OpaqueType>(pa.get())->refineAbstractTypeTo(T);
|
||||||
|
return pa.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
IrTypeDelegate::IrTypeDelegate(Type * dt)
|
||||||
|
: IrType(dt, llvm::OpaqueType::get())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
const llvm::Type * IrTypeDelegate::buildType()
|
||||||
|
{
|
||||||
|
assert(dtype->ty == Tdelegate);
|
||||||
|
const LLType* i8ptr = getVoidPtrType();
|
||||||
|
const LLType* func = DtoFunctionType(dtype->nextOf(), NULL, Type::tvoid->pointerTo());
|
||||||
|
const LLType* funcptr = getPtrToType(func);
|
||||||
|
const LLStructType* dgtype = LLStructType::get(i8ptr, funcptr, NULL);
|
||||||
|
gIR->module->addTypeName(dtype->toChars(), dgtype);
|
||||||
|
|
||||||
|
llvm::cast<llvm::OpaqueType>(pa.get())->refineAbstractTypeTo(dgtype);
|
||||||
|
return pa.get();
|
||||||
|
}
|
42
ir/irtypefunction.h
Normal file
42
ir/irtypefunction.h
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
#ifndef __LDC_IR_IRTYPEFUNCTION_H__
|
||||||
|
#define __LDC_IR_IRTYPEFUNCTION_H__
|
||||||
|
|
||||||
|
#include "ir/irtype.h"
|
||||||
|
|
||||||
|
class IrFuncTy;
|
||||||
|
|
||||||
|
///
|
||||||
|
class IrTypeFunction : public IrType
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
///
|
||||||
|
IrTypeFunction(Type* dt);
|
||||||
|
|
||||||
|
///
|
||||||
|
IrTypeFunction* isFunction() { return this; }
|
||||||
|
|
||||||
|
///
|
||||||
|
const llvm::Type* buildType();
|
||||||
|
|
||||||
|
IrFuncTy* fty() { return irfty; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
///
|
||||||
|
IrFuncTy* irfty;
|
||||||
|
};
|
||||||
|
|
||||||
|
///
|
||||||
|
class IrTypeDelegate : public IrType
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
///
|
||||||
|
IrTypeDelegate(Type* dt);
|
||||||
|
|
||||||
|
///
|
||||||
|
IrTypeDelegate* isDelegate() { return this; }
|
||||||
|
|
||||||
|
///
|
||||||
|
const llvm::Type* buildType();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Loading…
Add table
Add a link
Reference in a new issue