[svn r100] Moved test/ray.d to demos/ray.d.

Cleanups.
This commit is contained in:
Tomas Lindquist Olsen 2007-11-12 07:58:44 +01:00
parent e39beb1ad9
commit feff45cadd
16 changed files with 122 additions and 258 deletions

View file

@ -101,7 +101,7 @@ struct AggregateDeclaration : ScopeDsymbol
Symbol *toInitializer(); Symbol *toInitializer();
bool llvmInProgress; bool llvmInProgress;
llvm::Type* llvmType; const llvm::Type* llvmType;
llvm::Constant* llvmVtbl; llvm::Constant* llvmVtbl;
llvm::ConstantStruct* llvmConstVtbl; llvm::ConstantStruct* llvmConstVtbl;
llvm::Constant* llvmInitZ; llvm::Constant* llvmInitZ;

View file

@ -42,7 +42,7 @@ const llvm::StructType* DtoArrayType(Type* t)
const llvm::ArrayType* DtoStaticArrayType(Type* t) const llvm::ArrayType* DtoStaticArrayType(Type* t)
{ {
if (t->llvmType) if (t->llvmType)
return llvm::cast<llvm::ArrayType>(t->llvmType); return isaArray(t->llvmType);
assert(t->ty == Tsarray); assert(t->ty == Tsarray);
assert(t->next); assert(t->next);
@ -68,7 +68,7 @@ void DtoNullArray(llvm::Value* v)
new llvm::StoreInst(zerolen, len, gIR->scopebb()); new llvm::StoreInst(zerolen, len, gIR->scopebb());
llvm::Value* ptr = DtoGEPi(v,0,1,"tmp",gIR->scopebb()); llvm::Value* ptr = DtoGEPi(v,0,1,"tmp",gIR->scopebb());
const llvm::PointerType* pty = llvm::cast<llvm::PointerType>(ptr->getType()->getContainedType(0)); const llvm::PointerType* pty = isaPointer(ptr->getType()->getContainedType(0));
llvm::Value* nullptr = llvm::ConstantPointerNull::get(pty); llvm::Value* nullptr = llvm::ConstantPointerNull::get(pty);
new llvm::StoreInst(nullptr, ptr, gIR->scopebb()); new llvm::StoreInst(nullptr, ptr, gIR->scopebb());
} }
@ -93,12 +93,12 @@ void DtoArrayAssign(llvm::Value* dst, llvm::Value* src)
else else
{ {
Logger::cout() << "array assignment type dont match: " << *dst->getType() << '\n' << *src->getType() << '\n'; Logger::cout() << "array assignment type dont match: " << *dst->getType() << '\n' << *src->getType() << '\n';
if (!llvm::isa<llvm::ArrayType>(src->getType()->getContainedType(0))) const llvm::ArrayType* arrty = isaArray(src->getType()->getContainedType(0));
if (!arrty)
{ {
Logger::cout() << "invalid: " << *src << '\n'; Logger::cout() << "invalid: " << *src << '\n';
assert(0); assert(0);
} }
const llvm::ArrayType* arrty = llvm::cast<llvm::ArrayType>(src->getType()->getContainedType(0));
llvm::Type* dstty = llvm::PointerType::get(arrty->getElementType()); llvm::Type* dstty = llvm::PointerType::get(arrty->getElementType());
llvm::Value* dstlen = DtoGEPi(dst,0,0,"tmp",gIR->scopebb()); llvm::Value* dstlen = DtoGEPi(dst,0,0,"tmp",gIR->scopebb());
@ -115,16 +115,16 @@ void DtoArrayAssign(llvm::Value* dst, llvm::Value* src)
void DtoArrayInit(llvm::Value* l, llvm::Value* r) void DtoArrayInit(llvm::Value* l, llvm::Value* r)
{ {
const llvm::PointerType* ptrty = llvm::cast<llvm::PointerType>(l->getType()); const llvm::PointerType* ptrty = isaPointer(l->getType());
const llvm::Type* t = ptrty->getContainedType(0); const llvm::Type* t = ptrty->getContainedType(0);
const llvm::ArrayType* arrty = llvm::dyn_cast<llvm::ArrayType>(t); const llvm::ArrayType* arrty = isaArray(t);
if (arrty) if (arrty)
{ {
llvm::Value* ptr = DtoGEPi(l,0,0,"tmp",gIR->scopebb()); llvm::Value* ptr = DtoGEPi(l,0,0,"tmp",gIR->scopebb());
llvm::Value* dim = llvm::ConstantInt::get(DtoSize_t(), arrty->getNumElements(), false); llvm::Value* dim = llvm::ConstantInt::get(DtoSize_t(), arrty->getNumElements(), false);
DtoArrayInit(ptr, dim, r); DtoArrayInit(ptr, dim, r);
} }
else if (llvm::isa<llvm::StructType>(t)) else if (isaStruct(t))
{ {
llvm::Value* dim = DtoLoad(DtoGEPi(l, 0,0, "tmp")); llvm::Value* dim = DtoLoad(DtoGEPi(l, 0,0, "tmp"));
llvm::Value* ptr = DtoLoad(DtoGEPi(l, 0,1, "tmp")); llvm::Value* ptr = DtoLoad(DtoGEPi(l, 0,1, "tmp"));
@ -140,9 +140,9 @@ typedef const llvm::Type* constLLVMTypeP;
static size_t checkRectArrayInit(const llvm::Type* pt, constLLVMTypeP& finalty) static size_t checkRectArrayInit(const llvm::Type* pt, constLLVMTypeP& finalty)
{ {
if (llvm::isa<llvm::ArrayType>(pt)) { if (const llvm::ArrayType* arrty = isaArray(pt)) {
size_t n = checkRectArrayInit(pt->getContainedType(0), finalty); size_t n = checkRectArrayInit(arrty->getElementType(), finalty);
size_t ne = llvm::cast<llvm::ArrayType>(pt)->getNumElements(); size_t ne = arrty->getNumElements();
if (n) return n * ne; if (n) return n * ne;
return ne; return ne;
} }
@ -159,12 +159,12 @@ void DtoArrayInit(llvm::Value* ptr, llvm::Value* dim, llvm::Value* val)
const llvm::Type* finalTy; const llvm::Type* finalTy;
if (size_t arrsz = checkRectArrayInit(pt, finalTy)) { if (size_t arrsz = checkRectArrayInit(pt, finalTy)) {
assert(finalTy == t); assert(finalTy == t);
llvm::Constant* c = llvm::cast_or_null<llvm::Constant>(dim); llvm::Constant* c = isaConstant(dim);
assert(c); assert(c);
dim = llvm::ConstantExpr::getMul(c, DtoConstSize_t(arrsz)); dim = llvm::ConstantExpr::getMul(c, DtoConstSize_t(arrsz));
ptr = gIR->ir->CreateBitCast(ptr, llvm::PointerType::get(finalTy), "tmp"); ptr = gIR->ir->CreateBitCast(ptr, llvm::PointerType::get(finalTy), "tmp");
} }
else if (llvm::isa<llvm::StructType>(t)) { else if (isaStruct(t)) {
assert(0); assert(0);
} }
else { else {
@ -178,7 +178,7 @@ void DtoArrayInit(llvm::Value* ptr, llvm::Value* dim, llvm::Value* val)
const char* funcname = NULL; const char* funcname = NULL;
if (llvm::isa<llvm::PointerType>(t)) { if (isaPointer(t)) {
funcname = "_d_array_init_pointer"; funcname = "_d_array_init_pointer";
const llvm::Type* dstty = llvm::PointerType::get(llvm::PointerType::get(llvm::Type::Int8Ty)); const llvm::Type* dstty = llvm::PointerType::get(llvm::PointerType::get(llvm::Type::Int8Ty));
@ -227,15 +227,14 @@ void DtoArrayInit(llvm::Value* ptr, llvm::Value* dim, llvm::Value* val)
void DtoSetArray(llvm::Value* arr, llvm::Value* dim, llvm::Value* ptr) void DtoSetArray(llvm::Value* arr, llvm::Value* dim, llvm::Value* ptr)
{ {
Logger::cout() << "DtoSetArray(" << *arr << ", " << *dim << ", " << *ptr << ")\n"; Logger::cout() << "DtoSetArray(" << *arr << ", " << *dim << ", " << *ptr << ")\n";
const llvm::StructType* st = llvm::cast<llvm::StructType>(arr->getType()->getContainedType(0)); const llvm::StructType* st = isaStruct(arr->getType()->getContainedType(0));
//const llvm::PointerType* pt = llvm::cast<llvm::PointerType>(r->getType());
llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false);
llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false); llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false);
llvm::Value* arrdim = DtoGEP(arr,zero,zero,"tmp",gIR->scopebb()); llvm::Value* arrdim = DtoGEP(arr,zero,zero,"tmp",gIR->scopebb());
new llvm::StoreInst(dim, arrdim, gIR->scopebb()); new llvm::StoreInst(dim, arrdim, gIR->scopebb());
llvm::Value* arrptr = DtoGEP(arr,zero,one,"tmp",gIR->scopebb()); llvm::Value* arrptr = DtoGEP(arr,zero,one,"tmp",gIR->scopebb());
new llvm::StoreInst(ptr, arrptr, gIR->scopebb()); new llvm::StoreInst(ptr, arrptr, gIR->scopebb());
} }
@ -336,25 +335,25 @@ static llvm::Value* get_slice_ptr(DSliceValue* e, llvm::Value*& sz)
size_t elembsz = gTargetData->getTypeSize(ret->getType()); size_t elembsz = gTargetData->getTypeSize(ret->getType());
llvm::ConstantInt* elemsz = llvm::ConstantInt::get(DtoSize_t(), elembsz, false); llvm::ConstantInt* elemsz = llvm::ConstantInt::get(DtoSize_t(), elembsz, false);
if (llvm::isa<llvm::ConstantInt>(e->len)) { if (isaConstantInt(e->len)) {
sz = llvm::ConstantExpr::getMul(elemsz, llvm::cast<llvm::Constant>(e->len)); sz = llvm::ConstantExpr::getMul(elemsz, isaConstant(e->len));
} }
else { else {
sz = llvm::BinaryOperator::createMul(elemsz,e->len,"tmp",gIR->scopebb()); sz = llvm::BinaryOperator::createMul(elemsz,e->len,"tmp",gIR->scopebb());
} }
} }
else if (llvm::isa<llvm::ArrayType>(t)) { else if (isaArray(t)) {
ret = DtoGEPi(e->ptr, 0, 0, "tmp", gIR->scopebb()); ret = DtoGEPi(e->ptr, 0, 0, "tmp", gIR->scopebb());
size_t elembsz = gTargetData->getTypeSize(ret->getType()->getContainedType(0)); size_t elembsz = gTargetData->getTypeSize(ret->getType()->getContainedType(0));
llvm::ConstantInt* elemsz = llvm::ConstantInt::get(DtoSize_t(), elembsz, false); llvm::ConstantInt* elemsz = llvm::ConstantInt::get(DtoSize_t(), elembsz, false);
size_t numelements = llvm::cast<llvm::ArrayType>(t)->getNumElements(); size_t numelements = isaArray(t)->getNumElements();
llvm::ConstantInt* nelems = llvm::ConstantInt::get(DtoSize_t(), numelements, false); llvm::ConstantInt* nelems = llvm::ConstantInt::get(DtoSize_t(), numelements, false);
sz = llvm::ConstantExpr::getMul(elemsz, nelems); sz = llvm::ConstantExpr::getMul(elemsz, nelems);
} }
else if (llvm::isa<llvm::StructType>(t)) { else if (isaStruct(t)) {
ret = DtoGEPi(e->ptr, 0, 1, "tmp", gIR->scopebb()); ret = DtoGEPi(e->ptr, 0, 1, "tmp", gIR->scopebb());
ret = new llvm::LoadInst(ret, "tmp", gIR->scopebb()); ret = new llvm::LoadInst(ret, "tmp", gIR->scopebb());
@ -560,9 +559,9 @@ llvm::Value* DtoStaticArrayCompare(TOK op, llvm::Value* l, llvm::Value* r)
assert(fn); assert(fn);
assert(l->getType() == r->getType()); assert(l->getType() == r->getType());
assert(llvm::isa<llvm::PointerType>(l->getType())); assert(isaPointer(l->getType()));
const llvm::Type* arrty = l->getType()->getContainedType(0); const llvm::Type* arrty = l->getType()->getContainedType(0);
assert(llvm::isa<llvm::ArrayType>(arrty)); assert(isaArray(arrty));
llvm::Value* ll = new llvm::BitCastInst(l, llvm::PointerType::get(llvm::Type::Int8Ty), "tmp", gIR->scopebb()); llvm::Value* ll = new llvm::BitCastInst(l, llvm::PointerType::get(llvm::Type::Int8Ty), "tmp", gIR->scopebb());
llvm::Value* rr = new llvm::BitCastInst(r, llvm::PointerType::get(llvm::Type::Int8Ty), "tmp", gIR->scopebb()); llvm::Value* rr = new llvm::BitCastInst(r, llvm::PointerType::get(llvm::Type::Int8Ty), "tmp", gIR->scopebb());
@ -591,10 +590,9 @@ llvm::Value* DtoDynArrayCompare(TOK op, llvm::Value* l, llvm::Value* r)
Logger::cout() << "lhsType:" << *l->getType() << "\nrhsType:" << *r->getType() << '\n'; Logger::cout() << "lhsType:" << *l->getType() << "\nrhsType:" << *r->getType() << '\n';
assert(l->getType() == r->getType()); assert(l->getType() == r->getType());
assert(llvm::isa<llvm::PointerType>(l->getType())); assert(isaPointer(l->getType()));
const llvm::Type* arrty = l->getType()->getContainedType(0); const llvm::StructType* structType = isaStruct(l->getType()->getContainedType(0));
assert(llvm::isa<llvm::StructType>(arrty)); assert(structType);
const llvm::StructType* structType = llvm::cast<llvm::StructType>(arrty);
const llvm::Type* elemType = structType->getElementType(1)->getContainedType(0); const llvm::Type* elemType = structType->getElementType(1)->getContainedType(0);
std::vector<const llvm::Type*> arrTypes; std::vector<const llvm::Type*> arrTypes;
@ -605,7 +603,7 @@ llvm::Value* DtoDynArrayCompare(TOK op, llvm::Value* l, llvm::Value* r)
llvm::Value* llmem = l; llvm::Value* llmem = l;
llvm::Value* rrmem = r; llvm::Value* rrmem = r;
if (arrty != arrType) { if (structType != arrType) {
llmem= new llvm::AllocaInst(arrType,"tmparr",gIR->topallocapoint()); llmem= new llvm::AllocaInst(arrType,"tmparr",gIR->topallocapoint());
llvm::Value* ll = gIR->ir->CreateLoad(DtoGEPi(l, 0,0, "tmp"),"tmp"); llvm::Value* ll = gIR->ir->CreateLoad(DtoGEPi(l, 0,0, "tmp"),"tmp");
@ -665,7 +663,7 @@ llvm::Value* DtoDynArrayIs(TOK op, llvm::Value* l, llvm::Value* r)
llvm::Value* b1 = gIR->ir->CreateICmp(pred,ll,rl,"tmp"); llvm::Value* b1 = gIR->ir->CreateICmp(pred,ll,rl,"tmp");
llvm::Value* lp = gIR->ir->CreateLoad(DtoGEPi(l, 0,1, "tmp"),"tmp"); llvm::Value* lp = gIR->ir->CreateLoad(DtoGEPi(l, 0,1, "tmp"),"tmp");
const llvm::PointerType* pty = llvm::cast<llvm::PointerType>(lp->getType()); const llvm::PointerType* pty = isaPointer(lp->getType());
llvm::Value* rp = llvm::ConstantPointerNull::get(pty); llvm::Value* rp = llvm::ConstantPointerNull::get(pty);
llvm::Value* b2 = gIR->ir->CreateICmp(pred,lp,rp,"tmp"); llvm::Value* b2 = gIR->ir->CreateICmp(pred,lp,rp,"tmp");
@ -691,10 +689,10 @@ llvm::Value* DtoDynArrayIs(TOK op, llvm::Value* l, llvm::Value* r)
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
llvm::Constant* DtoConstStaticArray(const llvm::Type* t, llvm::Constant* c) llvm::Constant* DtoConstStaticArray(const llvm::Type* t, llvm::Constant* c)
{ {
assert(llvm::isa<llvm::ArrayType>(t)); const llvm::ArrayType* at = isaArray(t);
const llvm::ArrayType* at = llvm::cast<llvm::ArrayType>(t); assert(at);
if (llvm::isa<llvm::ArrayType>(at->getElementType())) if (isaArray(at->getElementType()))
{ {
c = DtoConstStaticArray(at->getElementType(), c); c = DtoConstStaticArray(at->getElementType(), c);
} }
@ -721,7 +719,7 @@ llvm::Value* DtoArrayLen(DValue* v)
else if (t->ty == Tsarray) { else if (t->ty == Tsarray) {
llvm::Value* rv = v->getRVal(); llvm::Value* rv = v->getRVal();
Logger::cout() << "casting: " << *rv << '\n'; Logger::cout() << "casting: " << *rv << '\n';
const llvm::ArrayType* t = llvm::cast<llvm::ArrayType>(rv->getType()->getContainedType(0)); const llvm::ArrayType* t = isaArray(rv->getType()->getContainedType(0));
return DtoConstSize_t(t->getNumElements()); return DtoConstSize_t(t->getNumElements());
} }
assert(0); assert(0);

View file

@ -53,7 +53,7 @@ llvm::Value* DVarValue::getRVal()
else { else {
if (rval) return rval; if (rval) return rval;
Logger::cout() << "val: " << *val << '\n'; Logger::cout() << "val: " << *val << '\n';
if (llvm::isa<llvm::Argument>(val)) { if (isaArgument(val)) {
if (var && (var->isRef() || var->isOut())) if (var && (var->isRef() || var->isOut()))
return DtoLoad(val); return DtoLoad(val);
} }

View file

@ -1,85 +0,0 @@
/*
#include <iostream>
#include "gen/llvm.h"
#include "gen/elem.h"
#include "gen/irstate.h"
#include "gen/logger.h"
#include "gen/dvalue.h"
//////////////////////////////////////////////////////////////////////////////////////////
elem::elem(Expression* e)
{
exp = e;
mem = 0;
val = 0;
arg = 0;
type = NONE;
inplace = false;
field = false;
callconv = (unsigned)-1;
isthis = false;
istypeinfo = false;
temp = false;
vardecl = 0;
funcdecl = 0;
dvalue = 0;
}
elem::~elem()
{
delete dvalue;
}
llvm::Value* elem::getValue()
{
if (dvalue && !dvalue->isSlice()) {
Logger::println("HAS DVALUE");
return dvalue->getRVal();
}
assert(val || mem);
switch(type)
{
case NONE:
assert(0 && "type == NONE");
break;
case VAR:
case REF:
case ARRAYLEN:
if (val) {
return val;
}
else {
if (!llvm::isa<llvm::PointerType>(mem->getType()))
{
Logger::cout() << "unexpected type: " << *mem->getType() << '\n';
assert(0);
}
const llvm::PointerType* pt = llvm::cast<llvm::PointerType>(mem->getType());
if (!pt->getElementType()->isFirstClassType()) {
return mem;
}
else {
return gIR->ir->CreateLoad(mem, "tmp");
}
}
case VAL:
case NUL:
case FUNC:
case CONST:
case SLICE:
return val ? val : mem;
}
assert(0 && "type == invalid value");
return 0;
}
*/

View file

@ -1,61 +0,0 @@
#ifndef LLVMDC_GEN_ELEM_H
#define LLVMDC_GEN_ELEM_H
#include "dvalue.h"
typedef DValue elem;
/*
#include "root.h"
#include "declaration.h"
#include "aggregate.h"
struct DValue;
// represents a value. be it a constant literal, a variable etc.
// maintains all the information for doing load/store appropriately
struct elem : Object
{
enum {
NONE,
VAR,
VAL,
FUNC,
CONST,
NUL,
REF,
SLICE,
ARRAYLEN
};
public:
elem(Expression* e);
virtual ~elem();
Expression* exp;
llvm::Value* mem;
llvm::Value* val;
llvm::Value* arg;
int type;
bool inplace;
bool field;
unsigned callconv;
bool isthis;
bool istypeinfo;
bool temp;
VarDeclaration* vardecl;
FuncDeclaration* funcdecl;
llvm::Value* getValue();
//llvm::Value* getMemory();
DValue* dvalue;
bool isNull() {return !(mem || val);}
};
*/
#endif // LLVMDC_GEN_ELEM_H

View file

@ -10,13 +10,11 @@
#include "total.h" #include "total.h"
#include "init.h" #include "init.h"
#include "symbol.h"
#include "mtype.h" #include "mtype.h"
#include "hdrgen.h" #include "hdrgen.h"
#include "port.h" #include "port.h"
#include "gen/irstate.h" #include "gen/irstate.h"
#include "gen/elem.h"
#include "gen/logger.h" #include "gen/logger.h"
#include "gen/tollvm.h" #include "gen/tollvm.h"
#include "gen/runtime.h" #include "gen/runtime.h"
@ -539,8 +537,9 @@ void SwitchStatement::toIR(IRState* p)
// get the case value // get the case value
DValue* e = cs->exp->toElem(p); DValue* e = cs->exp->toElem(p);
DConstValue* ce = e->isConst(); DConstValue* ce = e->isConst();
assert(ce && llvm::isa<llvm::ConstantInt>(ce->c)); assert(ce);
llvm::ConstantInt* ec = llvm::cast<llvm::ConstantInt>(ce->c); llvm::ConstantInt* ec = isaConstantInt(ce->c);
assert(ec);
delete e; delete e;
// create the case bb with a nice label // create the case bb with a nice label
@ -675,9 +674,10 @@ void ForeachStatement::toIR(IRState* p)
{ {
Logger::println("foreach over static array"); Logger::println("foreach over static array");
val = aggrval->getRVal(); val = aggrval->getRVal();
assert(llvm::isa<llvm::PointerType>(val->getType())); assert(isaPointer(val->getType()));
assert(llvm::isa<llvm::ArrayType>(val->getType()->getContainedType(0))); const llvm::ArrayType* arrty = isaArray(val->getType()->getContainedType(0));
size_t nelems = llvm::cast<llvm::ArrayType>(val->getType()->getContainedType(0))->getNumElements(); assert(arrty);
size_t nelems = arrty->getNumElements();
assert(nelems > 0); assert(nelems > 0);
niters = llvm::ConstantInt::get(keytype,nelems,false); niters = llvm::ConstantInt::get(keytype,nelems,false);
} }
@ -688,13 +688,6 @@ void ForeachStatement::toIR(IRState* p)
Logger::println("foreach over slice"); Logger::println("foreach over slice");
niters = slice->len; niters = slice->len;
assert(niters); assert(niters);
if (llvm::isa<llvm::ConstantInt>(niters)) {
llvm::ConstantInt* ci = llvm::cast<llvm::ConstantInt>(niters);
Logger::println("const num iters: %u", ci);
}
else {
Logger::cout() << "numiters: " << *niters <<'\n';
}
val = slice->ptr; val = slice->ptr;
assert(val); assert(val);
} }

View file

@ -78,7 +78,7 @@ llvm::Constant* DtoConstStructInitializer(StructInitializer* si)
Logger::println("DtoConstStructInitializer: %s", si->toChars()); Logger::println("DtoConstStructInitializer: %s", si->toChars());
LOG_SCOPE; LOG_SCOPE;
const llvm::StructType* structtype = llvm::cast<llvm::StructType>(si->ad->llvmType); const llvm::StructType* structtype = isaStruct(si->ad->llvmType);
Logger::cout() << "llvm struct type: " << *structtype << '\n'; Logger::cout() << "llvm struct type: " << *structtype << '\n';
assert(si->value.dim == si->vars.dim); assert(si->value.dim == si->vars.dim);

View file

View file

@ -21,7 +21,6 @@
#include "init.h" #include "init.h"
#include "attrib.h" #include "attrib.h"
#include "lexer.h" #include "lexer.h"
#include "symbol.h"
/********************************* SymbolDeclaration ****************************/ /********************************* SymbolDeclaration ****************************/

View file

@ -47,7 +47,7 @@ const llvm::StructType* GetDwarfAnchorType()
} }
*/ */
std::vector<const llvm::Type*> elems(2, Ty(Int32Ty)); std::vector<const llvm::Type*> elems(2, Ty(Int32Ty));
const llvm::StructType* t = llvm::cast<llvm::StructType>(gIR->module->getTypeByName("llvm.dbg.anchor.type")); const llvm::StructType* t = isaStruct(gIR->module->getTypeByName("llvm.dbg.anchor.type"));
/* /*
%llvm.dbg.compile_units = linkonce constant %llvm.dbg.anchor.type { uint 0, uint 17 } ;; DW_TAG_compile_unit %llvm.dbg.compile_units = linkonce constant %llvm.dbg.anchor.type { uint 0, uint 17 } ;; DW_TAG_compile_unit
@ -101,11 +101,11 @@ llvm::Constant* GetDwarfAnchor(llvm::dwarf::dwarf_constants c)
////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////
const llvm::StructType* GetDwarfCompileUnitType() { const llvm::StructType* GetDwarfCompileUnitType() {
return llvm::cast<llvm::StructType>(gIR->module->getTypeByName("llvm.dbg.compile_unit.type")); return isaStruct(gIR->module->getTypeByName("llvm.dbg.compile_unit.type"));
} }
const llvm::StructType* GetDwarfSubProgramType() { const llvm::StructType* GetDwarfSubProgramType() {
return llvm::cast<llvm::StructType>(gIR->module->getTypeByName("llvm.dbg.subprogram.type")); return isaStruct(gIR->module->getTypeByName("llvm.dbg.subprogram.type"));
} }
////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////

View file

@ -16,13 +16,11 @@
#include "total.h" #include "total.h"
#include "init.h" #include "init.h"
#include "symbol.h"
#include "mtype.h" #include "mtype.h"
#include "hdrgen.h" #include "hdrgen.h"
#include "port.h" #include "port.h"
#include "gen/irstate.h" #include "gen/irstate.h"
#include "gen/elem.h"
#include "gen/logger.h" #include "gen/logger.h"
#include "gen/tollvm.h" #include "gen/tollvm.h"
#include "gen/runtime.h" #include "gen/runtime.h"
@ -249,7 +247,7 @@ llvm::Constant* IntegerExp::toConstElem(IRState* p)
Logger::print("IntegerExp::toConstElem: %s | %s\n", toChars(), type->toChars()); Logger::print("IntegerExp::toConstElem: %s | %s\n", toChars(), type->toChars());
LOG_SCOPE; LOG_SCOPE;
const llvm::Type* t = DtoType(type); const llvm::Type* t = DtoType(type);
if (llvm::isa<llvm::PointerType>(t)) { if (isaPointer(t)) {
Logger::println("pointer"); Logger::println("pointer");
llvm::Constant* i = llvm::ConstantInt::get(DtoSize_t(),(uint64_t)value,false); llvm::Constant* i = llvm::ConstantInt::get(DtoSize_t(),(uint64_t)value,false);
return llvm::ConstantExpr::getIntToPtr(i, t); return llvm::ConstantExpr::getIntToPtr(i, t);
@ -305,7 +303,7 @@ llvm::Constant* NullExp::toConstElem(IRState* p)
LOG_SCOPE; LOG_SCOPE;
const llvm::Type* t = DtoType(type); const llvm::Type* t = DtoType(type);
if (type->ty == Tarray) { if (type->ty == Tarray) {
assert(llvm::isa<llvm::StructType>(t)); assert(isaStruct(t));
return llvm::ConstantAggregateZero::get(t); return llvm::ConstantAggregateZero::get(t);
} }
else { else {
@ -752,11 +750,11 @@ DValue* MinExp::toElem(IRState* p)
/* /*
llvm::Value* left = l->getValue(); llvm::Value* left = l->getValue();
if (llvm::isa<llvm::PointerType>(left->getType())) if (isaPointer(left->getType()))
left = new llvm::PtrToIntInst(left,DtoSize_t(),"tmp",p->scopebb()); left = new llvm::PtrToIntInst(left,DtoSize_t(),"tmp",p->scopebb());
llvm::Value* right = r->getValue(); llvm::Value* right = r->getValue();
if (llvm::isa<llvm::PointerType>(right->getType())) if (isaPointer(right->getType()))
right = new llvm::PtrToIntInst(right,DtoSize_t(),"tmp",p->scopebb()); right = new llvm::PtrToIntInst(right,DtoSize_t(),"tmp",p->scopebb());
e->val = llvm::BinaryOperator::createSub(left,right,"tmp",p->scopebb()); e->val = llvm::BinaryOperator::createSub(left,right,"tmp",p->scopebb());
@ -765,7 +763,7 @@ DValue* MinExp::toElem(IRState* p)
const llvm::Type* totype = DtoType(type); const llvm::Type* totype = DtoType(type);
if (e->val->getType() != totype) { if (e->val->getType() != totype) {
assert(0); assert(0);
assert(llvm::isa<llvm::PointerType>(e->val->getType())); assert(isaPointer(e->val->getType()));
assert(llvm::isa<llvm::IntegerType>(totype)); assert(llvm::isa<llvm::IntegerType>(totype));
e->val = new llvm::IntToPtrInst(e->val,totype,"tmp",p->scopebb()); e->val = new llvm::IntToPtrInst(e->val,totype,"tmp",p->scopebb());
} }
@ -1104,6 +1102,10 @@ DValue* CallExp::toElem(IRState* p)
const llvm::Type* llt = DtoType(type); const llvm::Type* llt = DtoType(type);
if (DtoIsPassedByRef(t)) if (DtoIsPassedByRef(t))
llt = llvm::PointerType::get(llt); llt = llvm::PointerType::get(llt);
// TODO
if (strcmp(global.params.llvmArch, "x86") != 0) {
warning("va_arg for C variadic functions is broken for anything but x86");
}
return new DImValue(type, p->ir->CreateVAArg(expelem->getLVal(),llt,"tmp")); return new DImValue(type, p->ir->CreateVAArg(expelem->getLVal(),llt,"tmp"));
} }
else if (fndecl->llvmInternal == LLVMalloca) { else if (fndecl->llvmInternal == LLVMalloca) {
@ -1136,10 +1138,10 @@ DValue* CallExp::toElem(IRState* p)
llfnty = llvm::cast<llvm::FunctionType>(funcval->getType()); llfnty = llvm::cast<llvm::FunctionType>(funcval->getType());
} }
// pointer to something // pointer to something
else if (llvm::isa<llvm::PointerType>(funcval->getType())) { else if (isaPointer(funcval->getType())) {
// pointer to function pointer - I think this not really supposed to happen, but does :/ // pointer to function pointer - I think this not really supposed to happen, but does :/
// seems like sometimes we get a func* other times a func** // seems like sometimes we get a func* other times a func**
if (llvm::isa<llvm::PointerType>(funcval->getType()->getContainedType(0))) { if (isaPointer(funcval->getType()->getContainedType(0))) {
funcval = new llvm::LoadInst(funcval,"tmp",p->scopebb()); funcval = new llvm::LoadInst(funcval,"tmp",p->scopebb());
} }
// function pointer // function pointer
@ -1148,7 +1150,7 @@ DValue* CallExp::toElem(IRState* p)
llfnty = llvm::cast<llvm::FunctionType>(funcval->getType()->getContainedType(0)); llfnty = llvm::cast<llvm::FunctionType>(funcval->getType()->getContainedType(0));
} }
// struct pointer - delegate // struct pointer - delegate
else if (llvm::isa<llvm::StructType>(funcval->getType()->getContainedType(0))) { else if (isaStruct(funcval->getType()->getContainedType(0))) {
funcval = DtoGEP(funcval,zero,one,"tmp",p->scopebb()); funcval = DtoGEP(funcval,zero,one,"tmp",p->scopebb());
funcval = new llvm::LoadInst(funcval,"tmp",p->scopebb()); funcval = new llvm::LoadInst(funcval,"tmp",p->scopebb());
const llvm::Type* ty = funcval->getType()->getContainedType(0); const llvm::Type* ty = funcval->getType()->getContainedType(0);
@ -1178,7 +1180,7 @@ DValue* CallExp::toElem(IRState* p)
if (topexp && topexp->e2 == this) { if (topexp && topexp->e2 == this) {
assert(topexp->v); assert(topexp->v);
llvm::Value* tlv = topexp->v->getLVal(); llvm::Value* tlv = topexp->v->getLVal();
assert(llvm::isa<llvm::StructType>(tlv->getType()->getContainedType(0))); assert(isaStruct(tlv->getType()->getContainedType(0)));
llargs[j] = tlv; llargs[j] = tlv;
if (DtoIsPassedByRef(tf->next)) { if (DtoIsPassedByRef(tf->next)) {
isInPlace = true; isInPlace = true;
@ -1262,7 +1264,7 @@ DValue* CallExp::toElem(IRState* p)
for (unsigned i=0; i<vtype->getNumElements(); ++i) for (unsigned i=0; i<vtype->getNumElements(); ++i)
p->ir->CreateStore(vvalues[i], DtoGEPi(mem,0,i,"tmp")); p->ir->CreateStore(vvalues[i], DtoGEPi(mem,0,i,"tmp"));
//llvm::Constant* typeinfoparam = llvm::ConstantPointerNull::get(llvm::cast<llvm::PointerType>(llfnty->getParamType(j))); //llvm::Constant* typeinfoparam = llvm::ConstantPointerNull::get(isaPointer(llfnty->getParamType(j)));
assert(Type::typeinfo->llvmInitZ); assert(Type::typeinfo->llvmInitZ);
const llvm::Type* typeinfotype = llvm::PointerType::get(Type::typeinfo->llvmInitZ->getType()); const llvm::Type* typeinfotype = llvm::PointerType::get(Type::typeinfo->llvmInitZ->getType());
Logger::cout() << "typeinfo ptr type: " << *typeinfotype << '\n'; Logger::cout() << "typeinfo ptr type: " << *typeinfotype << '\n';
@ -1448,8 +1450,8 @@ DValue* CastExp::toElem(IRState* p)
llvm::Value* uval = u->getRVal(); llvm::Value* uval = u->getRVal();
if (fromtype->ty == Tsarray) { if (fromtype->ty == Tsarray) {
Logger::cout() << "uvalTy = " << *uval->getType() << '\n'; Logger::cout() << "uvalTy = " << *uval->getType() << '\n';
assert(llvm::isa<llvm::PointerType>(uval->getType())); assert(isaPointer(uval->getType()));
const llvm::ArrayType* arrty = llvm::cast<llvm::ArrayType>(uval->getType()->getContainedType(0)); const llvm::ArrayType* arrty = isaArray(uval->getType()->getContainedType(0));
rval2 = llvm::ConstantInt::get(DtoSize_t(), arrty->getNumElements(), false); rval2 = llvm::ConstantInt::get(DtoSize_t(), arrty->getNumElements(), false);
rval2 = DtoArrayCastLength(rval2, ety, ptrty->getContainedType(0)); rval2 = DtoArrayCastLength(rval2, ety, ptrty->getContainedType(0));
rval = new llvm::BitCastInst(uval, ptrty, "tmp", p->scopebb()); rval = new llvm::BitCastInst(uval, ptrty, "tmp", p->scopebb());
@ -2479,7 +2481,7 @@ DValue* IdentityExp::toElem(IRState* p)
else { else {
llvm::ICmpInst::Predicate pred = (op == TOKidentity) ? llvm::ICmpInst::ICMP_EQ : llvm::ICmpInst::ICMP_NE; llvm::ICmpInst::Predicate pred = (op == TOKidentity) ? llvm::ICmpInst::ICMP_EQ : llvm::ICmpInst::ICMP_NE;
if (t1->ty == Tpointer && v->isNull() && l->getType() != r->getType()) { if (t1->ty == Tpointer && v->isNull() && l->getType() != r->getType()) {
r = llvm::ConstantPointerNull::get(llvm::cast<llvm::PointerType>(l->getType())); r = llvm::ConstantPointerNull::get(isaPointer(l->getType()));
} }
Logger::cout() << "l = " << *l << " r = " << *r << '\n'; Logger::cout() << "l = " << *l << " r = " << *r << '\n';
eval = new llvm::ICmpInst(pred, l, r, "tmp", p->scopebb()); eval = new llvm::ICmpInst(pred, l, r, "tmp", p->scopebb());
@ -2660,7 +2662,7 @@ DValue* FuncExp::toElem(IRState* p)
} }
llvm::Value* context = DtoGEPi(lval,0,0,"tmp",p->scopebb()); llvm::Value* context = DtoGEPi(lval,0,0,"tmp",p->scopebb());
const llvm::PointerType* pty = llvm::cast<llvm::PointerType>(context->getType()->getContainedType(0)); const llvm::PointerType* pty = isaPointer(context->getType()->getContainedType(0));
llvm::Value* llvmNested = p->func().decl->llvmNested; llvm::Value* llvmNested = p->func().decl->llvmNested;
if (llvmNested == NULL) { if (llvmNested == NULL) {
llvm::Value* nullcontext = llvm::ConstantPointerNull::get(pty); llvm::Value* nullcontext = llvm::ConstantPointerNull::get(pty);
@ -2709,8 +2711,8 @@ DValue* ArrayLiteralExp::toElem(IRState* p)
mem = p->topexp()->v->getLVal(); mem = p->topexp()->v->getLVal();
} }
assert(mem); assert(mem);
if (!llvm::isa<llvm::PointerType>(mem->getType()) || if (!isaPointer(mem->getType()) ||
!llvm::isa<llvm::ArrayType>(mem->getType()->getContainedType(0))) !isaArray(mem->getType()->getContainedType(0)))
{ {
assert(ty->ty == Tarray); assert(ty->ty == Tarray);
// we need to give this array literal storage // we need to give this array literal storage
@ -2748,8 +2750,8 @@ llvm::Constant* ArrayLiteralExp::toConstElem(IRState* p)
const llvm::Type* t = DtoType(type); const llvm::Type* t = DtoType(type);
Logger::cout() << "array literal has llvm type: " << *t << '\n'; Logger::cout() << "array literal has llvm type: " << *t << '\n';
assert(llvm::isa<llvm::ArrayType>(t)); assert(isaArray(t));
const llvm::ArrayType* arrtype = llvm::cast<llvm::ArrayType>(t); const llvm::ArrayType* arrtype = isaArray(t);
assert(arrtype->getNumElements() == elements->dim); assert(arrtype->getNumElements() == elements->dim);
std::vector<llvm::Constant*> vals(elements->dim, NULL); std::vector<llvm::Constant*> vals(elements->dim, NULL);
@ -2851,7 +2853,7 @@ llvm::Constant* StructLiteralExp::toConstElem(IRState* p)
assert(DtoDType(type)->ty == Tstruct); assert(DtoDType(type)->ty == Tstruct);
const llvm::Type* t = DtoType(type); const llvm::Type* t = DtoType(type);
const llvm::StructType* st = llvm::cast<llvm::StructType>(t); const llvm::StructType* st = isaStruct(t);
return llvm::ConstantStruct::get(st,vals); return llvm::ConstantStruct::get(st,vals);
} }
@ -3130,7 +3132,7 @@ void AsmStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
int AsmStatement::comeFrom() int AsmStatement::comeFrom()
{ {
assert(0); assert(0);
return FALSE; return 0;
} }
void void

View file

@ -259,11 +259,11 @@ const llvm::FunctionType* DtoFunctionType(Type* type, const llvm::Type* thistype
arg->llvmCopy = true; arg->llvmCopy = true;
const llvm::Type* at = DtoType(argT); const llvm::Type* at = DtoType(argT);
if (llvm::isa<llvm::StructType>(at)) { if (isaStruct(at)) {
Logger::println("struct param"); Logger::println("struct param");
paramvec.push_back(llvm::PointerType::get(at)); paramvec.push_back(llvm::PointerType::get(at));
} }
else if (llvm::isa<llvm::ArrayType>(at)) { else if (isaArray(at)) {
Logger::println("sarray param"); Logger::println("sarray param");
assert(argT->ty == Tsarray); assert(argT->ty == Tsarray);
//paramvec.push_back(llvm::PointerType::get(at->getContainedType(0))); //paramvec.push_back(llvm::PointerType::get(at->getContainedType(0)));
@ -271,14 +271,9 @@ const llvm::FunctionType* DtoFunctionType(Type* type, const llvm::Type* thistype
} }
else if (llvm::isa<llvm::OpaqueType>(at)) { else if (llvm::isa<llvm::OpaqueType>(at)) {
Logger::println("opaque param"); Logger::println("opaque param");
if (argT->ty == Tstruct || argT->ty == Tclass) assert(argT->ty == Tstruct || argT->ty == Tclass);
paramvec.push_back(llvm::PointerType::get(at));
else
assert(0);
}
/*if (llvm::isa<llvm::StructType>(at) || argT->ty == Tstruct || argT->ty == Tsarray) {
paramvec.push_back(llvm::PointerType::get(at)); paramvec.push_back(llvm::PointerType::get(at));
}*/ }
else { else {
if (!arg->llvmCopy) { if (!arg->llvmCopy) {
Logger::println("ref param"); Logger::println("ref param");
@ -346,7 +341,7 @@ const llvm::FunctionType* DtoFunctionType(FuncDeclaration* fdecl)
Logger::print("isMember = this is: %s\n", ad->type->toChars()); Logger::print("isMember = this is: %s\n", ad->type->toChars());
thisty = DtoType(ad->type); thisty = DtoType(ad->type);
Logger::cout() << "this llvm type: " << *thisty << '\n'; Logger::cout() << "this llvm type: " << *thisty << '\n';
if (llvm::isa<llvm::StructType>(thisty) || thisty == gIR->topstruct().recty.get()) if (isaStruct(thisty) || thisty == gIR->topstruct().recty.get())
thisty = llvm::PointerType::get(thisty); thisty = llvm::PointerType::get(thisty);
} }
else else
@ -609,7 +604,7 @@ llvm::Value* DtoBoolean(llvm::Value* val)
return new llvm::ICmpInst(llvm::ICmpInst::ICMP_NE, val, zero, "tmp", gIR->scopebb()); return new llvm::ICmpInst(llvm::ICmpInst::ICMP_NE, val, zero, "tmp", gIR->scopebb());
} }
} }
else if (llvm::isa<llvm::PointerType>(t)) { else if (isaPointer(t)) {
const llvm::Type* st = DtoSize_t(); const llvm::Type* st = DtoSize_t();
llvm::Value* ptrasint = new llvm::PtrToIntInst(val,st,"tmp",gIR->scopebb()); llvm::Value* ptrasint = new llvm::PtrToIntInst(val,st,"tmp",gIR->scopebb());
llvm::Value* zero = llvm::ConstantInt::get(st, 0, false); llvm::Value* zero = llvm::ConstantInt::get(st, 0, false);
@ -880,7 +875,7 @@ static llvm::Function* DtoDeclareVaFunction(FuncDeclaration* fdecl)
else else
assert(0); assert(0);
llvm::Function* func = llvm::cast_or_null<llvm::Function>(fn); llvm::Function* func = llvm::dyn_cast<llvm::Function>(fn);
assert(func); assert(func);
assert(func->isIntrinsic()); assert(func->isIntrinsic());
fdecl->llvmValue = func; fdecl->llvmValue = func;
@ -1099,7 +1094,7 @@ llvm::Value* DtoArgument(const llvm::Type* paramtype, Argument* fnarg, Expressio
else { else {
llvm::Value* allocaInst = 0; llvm::Value* allocaInst = 0;
llvm::BasicBlock* entryblock = &gIR->topfunc()->front(); llvm::BasicBlock* entryblock = &gIR->topfunc()->front();
//const llvm::PointerType* pty = llvm::cast<llvm::PointerType>(arg->mem->getType());
const llvm::Type* realtypell = DtoType(realtype); const llvm::Type* realtypell = DtoType(realtype);
const llvm::PointerType* pty = llvm::PointerType::get(realtypell); const llvm::PointerType* pty = llvm::PointerType::get(realtypell);
if (argty == Tstruct) { if (argty == Tstruct) {
@ -1397,7 +1392,7 @@ void DtoStore(llvm::Value* src, llvm::Value* dst)
bool DtoCanLoad(llvm::Value* ptr) bool DtoCanLoad(llvm::Value* ptr)
{ {
if (llvm::isa<llvm::PointerType>(ptr->getType())) { if (isaPointer(ptr->getType())) {
return ptr->getType()->getContainedType(0)->isFirstClassType(); return ptr->getType()->getContainedType(0)->isFirstClassType();
} }
return false; return false;
@ -1413,16 +1408,31 @@ const llvm::PointerType* isaPointer(llvm::Value* v)
return llvm::dyn_cast<llvm::PointerType>(v->getType()); return llvm::dyn_cast<llvm::PointerType>(v->getType());
} }
const llvm::PointerType* isaPointer(const llvm::Type* t)
{
return llvm::dyn_cast<llvm::PointerType>(t);
}
const llvm::ArrayType* isaArray(llvm::Value* v) const llvm::ArrayType* isaArray(llvm::Value* v)
{ {
return llvm::dyn_cast<llvm::ArrayType>(v->getType()); return llvm::dyn_cast<llvm::ArrayType>(v->getType());
} }
const llvm::ArrayType* isaArray(const llvm::Type* t)
{
return llvm::dyn_cast<llvm::ArrayType>(t);
}
const llvm::StructType* isaStruct(llvm::Value* v) const llvm::StructType* isaStruct(llvm::Value* v)
{ {
return llvm::dyn_cast<llvm::StructType>(v->getType()); return llvm::dyn_cast<llvm::StructType>(v->getType());
} }
const llvm::StructType* isaStruct(const llvm::Type* t)
{
return llvm::dyn_cast<llvm::StructType>(t);
}
llvm::Constant* isaConstant(llvm::Value* v) llvm::Constant* isaConstant(llvm::Value* v)
{ {
return llvm::dyn_cast<llvm::Constant>(v); return llvm::dyn_cast<llvm::Constant>(v);
@ -1433,6 +1443,11 @@ llvm::ConstantInt* isaConstantInt(llvm::Value* v)
return llvm::dyn_cast<llvm::ConstantInt>(v); return llvm::dyn_cast<llvm::ConstantInt>(v);
} }
llvm::Argument* isaArgument(llvm::Value* v)
{
return llvm::dyn_cast<llvm::Argument>(v);
}
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
bool DtoIsTemplateInstance(Dsymbol* s) bool DtoIsTemplateInstance(Dsymbol* s)

View file

@ -77,10 +77,14 @@ llvm::Value* DtoBitCast(llvm::Value* v, const llvm::Type* t);
// llvm::dyn_cast wrappers // llvm::dyn_cast wrappers
const llvm::PointerType* isaPointer(llvm::Value* v); const llvm::PointerType* isaPointer(llvm::Value* v);
const llvm::PointerType* isaPointer(const llvm::Type* t);
const llvm::ArrayType* isaArray(llvm::Value* v); const llvm::ArrayType* isaArray(llvm::Value* v);
const llvm::ArrayType* isaArray(const llvm::Type* t);
const llvm::StructType* isaStruct(llvm::Value* v); const llvm::StructType* isaStruct(llvm::Value* v);
const llvm::StructType* isaStruct(const llvm::Type* t);
llvm::Constant* isaConstant(llvm::Value* v); llvm::Constant* isaConstant(llvm::Value* v);
llvm::ConstantInt* isaConstantInt(llvm::Value* v); llvm::ConstantInt* isaConstantInt(llvm::Value* v);
llvm::Argument* isaArgument(llvm::Value* v);
// basic operations // basic operations
void DtoAssign(DValue* lhs, DValue* rhs); void DtoAssign(DValue* lhs, DValue* rhs);

View file

@ -32,7 +32,6 @@
#include "scope.h" #include "scope.h"
#include "gen/irstate.h" #include "gen/irstate.h"
#include "gen/elem.h"
#include "gen/logger.h" #include "gen/logger.h"
#include "gen/tollvm.h" #include "gen/tollvm.h"
#include "gen/arrays.h" #include "gen/arrays.h"
@ -332,7 +331,7 @@ void StructDeclaration::toObjFile()
Logger::println("doing struct fields"); Logger::println("doing struct fields");
llvm::StructType* structtype = 0; const llvm::StructType* structtype = 0;
std::vector<llvm::Constant*> fieldinits; std::vector<llvm::Constant*> fieldinits;
if (gIR->topstruct().offsets.empty()) if (gIR->topstruct().offsets.empty())
@ -427,7 +426,7 @@ void StructDeclaration::toObjFile()
{ {
llvm::PATypeHolder& pa = gIR->topstruct().recty; llvm::PATypeHolder& pa = gIR->topstruct().recty;
llvm::cast<llvm::OpaqueType>(pa.get())->refineAbstractTypeTo(structtype); llvm::cast<llvm::OpaqueType>(pa.get())->refineAbstractTypeTo(structtype);
structtype = llvm::cast<llvm::StructType>(pa.get()); structtype = isaStruct(pa.get());
} }
ts->llvmType = structtype; ts->llvmType = structtype;
@ -587,13 +586,13 @@ void ClassDeclaration::toObjFile()
fieldinits.push_back(i->second.init); fieldinits.push_back(i->second.init);
} }
llvm::StructType* structtype = llvm::StructType::get(fieldtypes); const llvm::StructType* structtype = llvm::StructType::get(fieldtypes);
// refine abstract types for stuff like: class C {C next;} // refine abstract types for stuff like: class C {C next;}
if (gIR->topstruct().recty != 0) if (gIR->topstruct().recty != 0)
{ {
llvm::PATypeHolder& pa = gIR->topstruct().recty; llvm::PATypeHolder& pa = gIR->topstruct().recty;
llvm::cast<llvm::OpaqueType>(pa.get())->refineAbstractTypeTo(structtype); llvm::cast<llvm::OpaqueType>(pa.get())->refineAbstractTypeTo(structtype);
structtype = llvm::cast<llvm::StructType>(pa.get()); structtype = isaStruct(pa.get());
} }
ts->llvmType = structtype; ts->llvmType = structtype;
@ -664,8 +663,8 @@ void ClassDeclaration::toObjFile()
// refine for final vtable type // refine for final vtable type
llvm::cast<llvm::OpaqueType>(pa.get())->refineAbstractTypeTo(svtbl_ty); llvm::cast<llvm::OpaqueType>(pa.get())->refineAbstractTypeTo(svtbl_ty);
svtbl_ty = llvm::cast<llvm::StructType>(pa.get()); svtbl_ty = isaStruct(pa.get());
structtype = llvm::cast<llvm::StructType>(gIR->topstruct().recty.get()); structtype = isaStruct(gIR->topstruct().recty.get());
ts->llvmType = structtype; ts->llvmType = structtype;
llvmType = structtype; llvmType = structtype;
@ -793,7 +792,7 @@ void VarDeclaration::toObjFile()
_init = ts->sym->llvmInitZ; _init = ts->sym->llvmInitZ;
} }
// array single value init // array single value init
else if (llvm::isa<llvm::ArrayType>(_type)) else if (isaArray(_type))
{ {
_init = DtoConstStaticArray(_type, _init); _init = DtoConstStaticArray(_type, _init);
} }
@ -833,19 +832,19 @@ void VarDeclaration::toObjFile()
{ {
if (t->ty == Tsarray) if (t->ty == Tsarray)
{ {
const llvm::ArrayType* arrty = llvm::cast<llvm::ArrayType>(_type); const llvm::ArrayType* arrty = isaArray(_type);
uint64_t n = arrty->getNumElements(); uint64_t n = arrty->getNumElements();
std::vector<llvm::Constant*> vals(n,_init); std::vector<llvm::Constant*> vals(n,_init);
_init = llvm::ConstantArray::get(arrty, vals); _init = llvm::ConstantArray::get(arrty, vals);
} }
else if (t->ty == Tarray) else if (t->ty == Tarray)
{ {
assert(llvm::isa<llvm::StructType>(_type)); assert(isaStruct(_type));
_init = llvm::ConstantAggregateZero::get(_type); _init = llvm::ConstantAggregateZero::get(_type);
} }
else if (t->ty == Tstruct) else if (t->ty == Tstruct)
{ {
const llvm::StructType* structty = llvm::cast<llvm::StructType>(_type); const llvm::StructType* structty = isaStruct(_type);
TypeStruct* ts = (TypeStruct*)t; TypeStruct* ts = (TypeStruct*)t;
assert(ts); assert(ts);
assert(ts->sym); assert(ts->sym);

View file

@ -277,7 +277,7 @@ void TypeInfoTypedefDeclaration::toDt(dt_t **pdt)
llvm::Constant* initZ = base->llvmInitZ; llvm::Constant* initZ = base->llvmInitZ;
assert(initZ); assert(initZ);
const llvm::StructType* stype = llvm::cast<llvm::StructType>(initZ->getType()); const llvm::StructType* stype = isaStruct(initZ->getType());
std::vector<llvm::Constant*> sinits; std::vector<llvm::Constant*> sinits;
sinits.push_back(initZ->getOperand(0)); sinits.push_back(initZ->getOperand(0));
@ -287,7 +287,7 @@ void TypeInfoTypedefDeclaration::toDt(dt_t **pdt)
TypedefDeclaration *sd = tc->sym; TypedefDeclaration *sd = tc->sym;
// TypeInfo base // TypeInfo base
//const llvm::PointerType* basept = llvm::cast<llvm::PointerType>(initZ->getOperand(1)->getType()); //const llvm::PointerType* basept = isaPointer(initZ->getOperand(1)->getType());
//sinits.push_back(llvm::ConstantPointerNull::get(basept)); //sinits.push_back(llvm::ConstantPointerNull::get(basept));
Logger::println("generating base typeinfo"); Logger::println("generating base typeinfo");
//sd->basetype = sd->basetype->merge(); //sd->basetype = sd->basetype->merge();
@ -341,7 +341,7 @@ void TypeInfoEnumDeclaration::toDt(dt_t **pdt)
llvm::Constant* initZ = base->llvmInitZ; llvm::Constant* initZ = base->llvmInitZ;
assert(initZ); assert(initZ);
const llvm::StructType* stype = llvm::cast<llvm::StructType>(initZ->getType()); const llvm::StructType* stype = isaStruct(initZ->getType());
std::vector<llvm::Constant*> sinits; std::vector<llvm::Constant*> sinits;
sinits.push_back(initZ->getOperand(0)); sinits.push_back(initZ->getOperand(0));
@ -351,7 +351,7 @@ void TypeInfoEnumDeclaration::toDt(dt_t **pdt)
EnumDeclaration *sd = tc->sym; EnumDeclaration *sd = tc->sym;
// TypeInfo base // TypeInfo base
//const llvm::PointerType* basept = llvm::cast<llvm::PointerType>(initZ->getOperand(1)->getType()); //const llvm::PointerType* basept = isaPointer(initZ->getOperand(1)->getType());
//sinits.push_back(llvm::ConstantPointerNull::get(basept)); //sinits.push_back(llvm::ConstantPointerNull::get(basept));
Logger::println("generating base typeinfo"); Logger::println("generating base typeinfo");
//sd->basetype = sd->basetype->merge(); //sd->basetype = sd->basetype->merge();
@ -403,7 +403,7 @@ static llvm::Constant* LLVM_D_Create_TypeInfoBase(Type* basetype, TypeInfoDeclar
llvm::Constant* initZ = base->llvmInitZ; llvm::Constant* initZ = base->llvmInitZ;
assert(initZ); assert(initZ);
const llvm::StructType* stype = llvm::cast<llvm::StructType>(initZ->getType()); const llvm::StructType* stype = isaStruct(initZ->getType());
std::vector<llvm::Constant*> sinits; std::vector<llvm::Constant*> sinits;
sinits.push_back(initZ->getOperand(0)); sinits.push_back(initZ->getOperand(0));
@ -538,7 +538,7 @@ void TypeInfoStructDeclaration::toDt(dt_t **pdt)
ClassDeclaration* base = Type::typeinfostruct; ClassDeclaration* base = Type::typeinfostruct;
base->toObjFile(); base->toObjFile();
const llvm::StructType* stype = llvm::cast<llvm::StructType>(base->llvmType); const llvm::StructType* stype = isaStruct(base->llvmType);
std::vector<llvm::Constant*> sinits; std::vector<llvm::Constant*> sinits;
sinits.push_back(base->llvmVtbl); sinits.push_back(base->llvmVtbl);
@ -609,7 +609,7 @@ void TypeInfoStructDeclaration::toDt(dt_t **pdt)
#endif #endif
Logger::println("************** B"); Logger::println("************** B");
const llvm::PointerType* ptty = llvm::cast<llvm::PointerType>(stype->getElementType(3)); const llvm::PointerType* ptty = isaPointer(stype->getElementType(3));
s = search_function(sd, Id::tohash); s = search_function(sd, Id::tohash);
fdx = s ? s->isFuncDeclaration() : NULL; fdx = s ? s->isFuncDeclaration() : NULL;
@ -637,7 +637,7 @@ void TypeInfoStructDeclaration::toDt(dt_t **pdt)
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
{ {
Logger::println("************** C %d", i); Logger::println("************** C %d", i);
ptty = llvm::cast<llvm::PointerType>(stype->getElementType(4+i)); ptty = isaPointer(stype->getElementType(4+i));
if (fdx) if (fdx)
{ {
fd = fdx->overloadExactMatch(tfeqptr); fd = fdx->overloadExactMatch(tfeqptr);
@ -662,7 +662,7 @@ void TypeInfoStructDeclaration::toDt(dt_t **pdt)
} }
Logger::println("************** D"); Logger::println("************** D");
ptty = llvm::cast<llvm::PointerType>(stype->getElementType(6)); ptty = isaPointer(stype->getElementType(6));
s = search_function(sd, Id::tostring); s = search_function(sd, Id::tostring);
fdx = s ? s->isFuncDeclaration() : NULL; fdx = s ? s->isFuncDeclaration() : NULL;
if (fdx) if (fdx)
@ -881,7 +881,7 @@ void DtoClassInfo(ClassDeclaration* cd)
inits.push_back(c); inits.push_back(c);
// build the initializer // build the initializer
const llvm::StructType* st = llvm::cast<llvm::StructType>(cinfo->llvmInitZ->getType()); const llvm::StructType* st = isaStruct(cinfo->llvmInitZ->getType());
llvm::Constant* finalinit = llvm::ConstantStruct::get(st, inits); llvm::Constant* finalinit = llvm::ConstantStruct::get(st, inits);
Logger::cout() << "built the classinfo initializer:\n" << *finalinit <<'\n'; Logger::cout() << "built the classinfo initializer:\n" << *finalinit <<'\n';