Mercurial > projects > ldc
comparison gen/toir.cpp @ 758:f04dde6e882c
Added initial D2 support, D2 frontend and changes to codegen to make things compile.
author | Tomas Lindquist Olsen <tomas.l.olsen@gmail.com> |
---|---|
date | Tue, 11 Nov 2008 01:38:48 +0100 |
parents | e177ae483f8e |
children | 9a9f403ab399 |
comparison
equal
deleted
inserted
replaced
757:2c730d530c98 | 758:f04dde6e882c |
---|---|
101 DtoForceDeclareDsymbol(cid->cd); | 101 DtoForceDeclareDsymbol(cid->cd); |
102 assert(cid->cd->ir.irStruct->classInfo); | 102 assert(cid->cd->ir.irStruct->classInfo); |
103 return new DVarValue(type, vd, cid->cd->ir.irStruct->classInfo); | 103 return new DVarValue(type, vd, cid->cd->ir.irStruct->classInfo); |
104 } | 104 } |
105 // nested variable | 105 // nested variable |
106 #if DMDV2 | |
107 else if (vd->nestedrefs.dim) { | |
108 #else | |
106 else if (vd->nestedref) { | 109 else if (vd->nestedref) { |
110 #endif | |
107 Logger::println("nested variable"); | 111 Logger::println("nested variable"); |
108 return DtoNestedVariable(loc, type, vd); | 112 return DtoNestedVariable(loc, type, vd); |
109 } | 113 } |
110 // function parameter | 114 // function parameter |
111 else if (vd->isParameter()) { | 115 else if (vd->isParameter()) { |
327 { | 331 { |
328 Logger::print("StringExp::toElem: %s | %s\n", toChars(), type->toChars()); | 332 Logger::print("StringExp::toElem: %s | %s\n", toChars(), type->toChars()); |
329 LOG_SCOPE; | 333 LOG_SCOPE; |
330 | 334 |
331 Type* dtype = type->toBasetype(); | 335 Type* dtype = type->toBasetype(); |
332 Type* cty = dtype->next->toBasetype(); | 336 Type* cty = dtype->nextOf()->toBasetype(); |
333 | 337 |
334 const LLType* ct = DtoTypeNotVoid(cty); | 338 const LLType* ct = DtoTypeNotVoid(cty); |
335 //printf("ct = %s\n", type->next->toChars()); | 339 //printf("ct = %s\n", type->nextOf()->toChars()); |
336 const LLArrayType* at = LLArrayType::get(ct,len+1); | 340 const LLArrayType* at = LLArrayType::get(ct,len+1); |
337 | 341 |
338 LLConstant* _init; | 342 LLConstant* _init; |
339 if (cty->size() == 1) { | 343 if (cty->size() == 1) { |
340 uint8_t* str = (uint8_t*)string; | 344 uint8_t* str = (uint8_t*)string; |
394 { | 398 { |
395 Logger::print("StringExp::toConstElem: %s | %s\n", toChars(), type->toChars()); | 399 Logger::print("StringExp::toConstElem: %s | %s\n", toChars(), type->toChars()); |
396 LOG_SCOPE; | 400 LOG_SCOPE; |
397 | 401 |
398 Type* t = type->toBasetype(); | 402 Type* t = type->toBasetype(); |
399 Type* cty = t->next->toBasetype(); | 403 Type* cty = t->nextOf()->toBasetype(); |
400 | 404 |
401 bool nullterm = (t->ty != Tsarray); | 405 bool nullterm = (t->ty != Tsarray); |
402 size_t endlen = nullterm ? len+1 : len; | 406 size_t endlen = nullterm ? len+1 : len; |
403 | 407 |
404 const LLType* ct = DtoType(cty); | 408 const LLType* ct = DtoType(cty); |
498 DValue* l = e1->toElem(p); | 502 DValue* l = e1->toElem(p); |
499 DValue* r = e2->toElem(p); | 503 DValue* r = e2->toElem(p); |
500 | 504 |
501 Type* t = type->toBasetype(); | 505 Type* t = type->toBasetype(); |
502 Type* e1type = e1->type->toBasetype(); | 506 Type* e1type = e1->type->toBasetype(); |
503 Type* e1next = e1type->next ? e1type->next->toBasetype() : NULL; | 507 Type* e1next = e1type->nextOf() ? e1type->nextOf()->toBasetype() : NULL; |
504 Type* e2type = e2->type->toBasetype(); | 508 Type* e2type = e2->type->toBasetype(); |
505 | 509 |
506 if (e1type != e2type) { | 510 if (e1type != e2type) { |
507 if (e1type->ty == Tpointer) { | 511 if (e1type->ty == Tpointer) { |
508 Logger::println("add to pointer"); | 512 Logger::println("add to pointer"); |
941 | 945 |
942 if (VarDeclaration* vd = var->isVarDeclaration()) { | 946 if (VarDeclaration* vd = var->isVarDeclaration()) { |
943 LLValue* arrptr; | 947 LLValue* arrptr; |
944 // indexing struct pointer | 948 // indexing struct pointer |
945 if (e1type->ty == Tpointer) { | 949 if (e1type->ty == Tpointer) { |
946 assert(e1type->next->ty == Tstruct); | 950 assert(e1type->nextOf()->ty == Tstruct); |
947 TypeStruct* ts = (TypeStruct*)e1type->next; | 951 TypeStruct* ts = (TypeStruct*)e1type->nextOf(); |
948 arrptr = DtoIndexStruct(l->getRVal(), ts->sym, vd); | 952 arrptr = DtoIndexStruct(l->getRVal(), ts->sym, vd); |
949 } | 953 } |
950 // indexing normal struct | 954 // indexing normal struct |
951 else if (e1type->ty == Tstruct) { | 955 else if (e1type->ty == Tstruct) { |
952 TypeStruct* ts = (TypeStruct*)e1type; | 956 TypeStruct* ts = (TypeStruct*)e1type; |
1613 gIR->CreateCallOrInvoke(fn, arg); | 1617 gIR->CreateCallOrInvoke(fn, arg); |
1614 } | 1618 } |
1615 // struct invariants | 1619 // struct invariants |
1616 else if( | 1620 else if( |
1617 global.params.useInvariants && | 1621 global.params.useInvariants && |
1618 condty->ty == Tpointer && condty->next->ty == Tstruct && | 1622 condty->ty == Tpointer && condty->nextOf()->ty == Tstruct && |
1619 (invdecl = ((TypeStruct*)condty->next)->sym->inv) != NULL) | 1623 (invdecl = ((TypeStruct*)condty->nextOf())->sym->inv) != NULL) |
1620 { | 1624 { |
1621 Logger::print("calling struct invariant"); | 1625 Logger::print("calling struct invariant"); |
1622 DFuncValue invfunc(invdecl, invdecl->ir.irFunc->func, cond->getRVal()); | 1626 DFuncValue invfunc(invdecl, invdecl->ir.irFunc->func, cond->getRVal()); |
1623 DtoCallFunction(loc, NULL, &invfunc, NULL); | 1627 DtoCallFunction(loc, NULL, &invfunc, NULL); |
1624 } | 1628 } |
2064 LOG_SCOPE; | 2068 LOG_SCOPE; |
2065 | 2069 |
2066 DValue* l = e1->toElem(p); | 2070 DValue* l = e1->toElem(p); |
2067 | 2071 |
2068 Type* e1type = e1->type->toBasetype(); | 2072 Type* e1type = e1->type->toBasetype(); |
2069 Type* elemtype = e1type->next->toBasetype(); | 2073 Type* elemtype = e1type->nextOf()->toBasetype(); |
2070 Type* e2type = e2->type->toBasetype(); | 2074 Type* e2type = e2->type->toBasetype(); |
2071 | 2075 |
2072 if (e2type == elemtype) { | 2076 if (e2type == elemtype) { |
2073 DSliceValue* slice = DtoCatAssignElement(l,e2); | 2077 DSliceValue* slice = DtoCatAssignElement(l,e2); |
2074 DtoAssign(loc, l, slice); | 2078 DtoAssign(loc, l, slice); |
2198 Logger::print("ArrayLiteralExp::toConstElem: %s | %s\n", toChars(), type->toChars()); | 2202 Logger::print("ArrayLiteralExp::toConstElem: %s | %s\n", toChars(), type->toChars()); |
2199 LOG_SCOPE; | 2203 LOG_SCOPE; |
2200 | 2204 |
2201 // extract D types | 2205 // extract D types |
2202 Type* bt = type->toBasetype(); | 2206 Type* bt = type->toBasetype(); |
2203 Type* elemt = bt->next; | 2207 Type* elemt = bt->nextOf(); |
2204 | 2208 |
2205 // build llvm array type | 2209 // build llvm array type |
2206 const LLArrayType* arrtype = LLArrayType::get(DtoType(elemt), elements->dim); | 2210 const LLArrayType* arrtype = LLArrayType::get(DtoType(elemt), elements->dim); |
2207 | 2211 |
2208 // dynamic arrays can occur here as well ... | 2212 // dynamic arrays can occur here as well ... |
2356 assert(keys); | 2360 assert(keys); |
2357 assert(values); | 2361 assert(values); |
2358 assert(keys->dim == values->dim); | 2362 assert(keys->dim == values->dim); |
2359 | 2363 |
2360 Type* aatype = type->toBasetype(); | 2364 Type* aatype = type->toBasetype(); |
2361 Type* vtype = aatype->next; | 2365 Type* vtype = aatype->nextOf(); |
2362 const LLType* aalltype = DtoType(type); | 2366 const LLType* aalltype = DtoType(type); |
2363 | 2367 |
2364 // it should be possible to avoid the temporary in some cases | 2368 // it should be possible to avoid the temporary in some cases |
2365 LLValue* tmp = DtoAlloca(aalltype,"aaliteral"); | 2369 LLValue* tmp = DtoAlloca(aalltype,"aaliteral"); |
2366 DValue* aa = new DVarValue(type, tmp); | 2370 DValue* aa = new DVarValue(type, tmp); |
2420 STUB(TypeDotIdExp); | 2424 STUB(TypeDotIdExp); |
2421 STUB(ScopeExp); | 2425 STUB(ScopeExp); |
2422 STUB(TypeExp); | 2426 STUB(TypeExp); |
2423 STUB(TupleExp); | 2427 STUB(TupleExp); |
2424 | 2428 |
2429 #if DMDV2 | |
2430 STUB(SymbolExp); | |
2431 #endif | |
2432 | |
2425 #define CONSTSTUB(x) LLConstant* x::toConstElem(IRState * p) {error("const Exp type "#x" not implemented: '%s' type: '%s'", toChars(), type->toChars()); fatal(); return NULL; } | 2433 #define CONSTSTUB(x) LLConstant* x::toConstElem(IRState * p) {error("const Exp type "#x" not implemented: '%s' type: '%s'", toChars(), type->toChars()); fatal(); return NULL; } |
2426 CONSTSTUB(Expression); | 2434 CONSTSTUB(Expression); |
2427 CONSTSTUB(AssocArrayLiteralExp); | 2435 CONSTSTUB(AssocArrayLiteralExp); |
2428 | 2436 |
2429 unsigned Type::totym() { return 0; } | 2437 unsigned Type::totym() { return 0; } |