Wiki Roadmap Timeline Tickets New Ticket Source Search Help / Guide About Trac Login

Changeset 435:74101be2a553

Show
Ignore:
Timestamp:
07/30/08 04:12:55 (5 months ago)
Author:
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
branch:
default
Message:

Added type param to DVarValue as DMD sometimes overrides the type of the VarDeclaration?.
Added support for align(1)/packed structs, other alignments are still ignored.
Fixed some problems with accessing lazy arguments.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gen/dvalue.cpp

    r347 r435  
    1111///////////////////////////////////////////////////////////////////////////////////////////////// 
    1212 
    13 DVarValue::DVarValue(VarDeclaration* vd, LLValue* llvmValue, bool lvalue) 
     13DVarValue::DVarValue(Type* t, VarDeclaration* vd, LLValue* llvmValue, bool lvalue) 
    1414{ 
    1515    var = vd; 
     
    1717    rval = 0; 
    1818    lval = lvalue; 
    19     type = var->type
     19    type = t
    2020} 
    2121 
  • gen/dvalue.h

    r361 r435  
    112112    bool lval; 
    113113 
    114     DVarValue(VarDeclaration* vd, LLValue* llvmValue, bool lvalue); 
    115     DVarValue(Type* vd, LLValue* lv, LLValue* rv); 
     114    DVarValue(Type* t, VarDeclaration* vd, LLValue* llvmValue, bool lvalue); 
     115    DVarValue(Type* t, LLValue* lv, LLValue* rv); 
    116116    DVarValue(Type* t, LLValue* llvmValue, bool lvalue); 
    117117 
     
    134134struct DThisValue : DVarValue 
    135135{ 
    136     DThisValue(VarDeclaration* vd, LLValue* llvmValue) : DVarValue(vd, llvmValue, true) {} 
     136    DThisValue(Type* t, VarDeclaration* vd, LLValue* llvmValue) : DVarValue(t, vd, llvmValue, true) {} 
    137137    virtual DThisValue* isThis() { return this; } 
    138138}; 
  • gen/functions.cpp

    r428 r435  
    2323const llvm::FunctionType* DtoFunctionType(Type* type, const LLType* thistype, bool ismain) 
    2424{ 
     25    assert(type->ty == Tfunction); 
    2526    TypeFunction* f = (TypeFunction*)type; 
    26     assert(f != 0); 
    2727 
    2828    if (type->ir.type != NULL) { 
  • gen/llvmhelpers.cpp

    r433 r435  
    12651265        } 
    12661266 
    1267         return new DVarValue(vd, vd->ir.getIrValue(), true); 
     1267        return new DVarValue(vd->type, vd, vd->ir.getIrValue(), true); 
    12681268    } 
    12691269    // struct declaration 
  • gen/llvmhelpers.h

    r433 r435  
    107107 
    108108/// 
    109 TypeFunction* DtoTypeFunction(Type* type); 
     109TypeFunction* DtoTypeFunction(DValue* fnval); 
    110110 
    111111/// 
  • gen/structs.cpp

    r351 r435  
    125125    TypeStruct* ts = (TypeStruct*)DtoDType(sd->type); 
    126126 
     127    bool ispacked = (ts->alignsize() == 1); 
     128 
    127129    IrStruct* irstruct = new IrStruct(ts); 
    128130    sd->ir.irStruct = irstruct; 
    129131    gIR->structs.push_back(irstruct); 
     132 
     133    irstruct->packed = ispacked; 
    130134 
    131135    // fields 
     
    171175        Logger::println("has no fields"); 
    172176        fieldtypes.push_back(LLType::Int8Ty); 
    173         structtype = llvm::StructType::get(fieldtypes); 
     177        structtype = llvm::StructType::get(fieldtypes, ispacked); 
    174178    } 
    175179    else 
     
    240244 
    241245        Logger::println("creating struct type"); 
    242         structtype = llvm::StructType::get(fieldtypes); 
     246        structtype = llvm::StructType::get(fieldtypes, ispacked); 
    243247    } 
    244248 
     
    330334 
    331335    // generate the union mapper 
    332     sd->ir.irStruct->dunion = new DUnion; // uses gIR->topstruct() 
     336    sd->ir.irStruct->dunion = new DUnion(); // uses gIR->topstruct() 
    333337 
    334338    // always generate the constant initalizer 
     
    446450    } 
    447451 
     452    ispacked = topstruct->packed; 
     453 
    448454    /*{ 
    449455        LOG_SCOPE; 
     
    534540        tys.push_back(out[i]->getType()); 
    535541 
    536     const llvm::StructType* st = llvm::StructType::get(tys); 
     542    const llvm::StructType* st = llvm::StructType::get(tys, ispacked); 
    537543    return llvm::ConstantStruct::get(st, out); 
    538544} 
  • gen/structs.h

    r344 r435  
    6767{ 
    6868    std::vector<DUnionField> fields; 
     69    bool ispacked; 
    6970public: 
    7071    DUnion(); 
  • gen/tocall.cpp

    r422 r435  
    1414////////////////////////////////////////////////////////////////////////////////////////// 
    1515 
    16 TypeFunction* DtoTypeFunction(Type* type) 
    17 
    18     TypeFunction* tf = 0; 
    19     type = type->toBasetype(); 
     16TypeFunction* DtoTypeFunction(DValue* fnval) 
     17
     18    Type* type = fnval->getType()->toBasetype(); 
    2019    if (type->ty == Tfunction) 
    2120    { 
    22          tf = (TypeFunction*)type; 
     21         return (TypeFunction*)type; 
    2322    } 
    2423    else if (type->ty == Tdelegate) 
    2524    { 
    2625        assert(type->next->ty == Tfunction); 
    27         tf = (TypeFunction*)type->next; 
    28     } 
    29     return tf; 
     26        return (TypeFunction*)type->next; 
     27    } 
     28 
     29    assert(0 && "cant get TypeFunction* from non lazy/function/delegate"); 
     30    return 0; 
    3031} 
    3132 
     
    193194 
    194195    // get function type info 
    195     TypeFunction* tf = DtoTypeFunction(calleeType); 
    196     assert(tf); 
     196    TypeFunction* tf = DtoTypeFunction(fnval); 
    197197 
    198198    // misc 
  • gen/toir.cpp

    r433 r435  
    6666            LLValue* v = p->func()->_arguments; 
    6767            assert(v); 
    68             return new DVarValue(vd, v, true); 
     68            return new DVarValue(type, vd, v, true); 
    6969        } 
    7070        // _argptr 
     
    7474            LLValue* v = p->func()->_argptr; 
    7575            assert(v); 
    76             return new DVarValue(vd, v, true); 
     76            return new DVarValue(type, vd, v, true); 
    7777        } 
    7878        // _dollar 
     
    8282            assert(!p->arrays.empty()); 
    8383            LLValue* tmp = DtoArrayLen(p->arrays.back()); 
    84             return new DVarValue(vd, tmp, false); 
     84            return new DVarValue(type, vd, tmp, false); 
    8585        } 
    8686        // typeinfo 
     
    9696            else 
    9797                m = tid->ir.getIrValue(); 
    98             return new DVarValue(vd, m, true); 
     98            return new DVarValue(type, vd, m, true); 
    9999        } 
    100100        // classinfo 
     
    104104            DtoForceDeclareDsymbol(cid->cd); 
    105105            assert(cid->cd->ir.irStruct->classInfo); 
    106             return new DVarValue(vd, cid->cd->ir.irStruct->classInfo, true); 
     106            return new DVarValue(type, vd, cid->cd->ir.irStruct->classInfo, true); 
    107107        } 
    108108        // nested variable 
    109109        else if (vd->nestedref) { 
    110110            Logger::println("nested variable"); 
    111             return new DVarValue(vd, DtoNestedVariable(vd), true); 
     111            return new DVarValue(type, vd, DtoNestedVariable(vd), true); 
    112112        } 
    113113        // function parameter 
     
    117117            if (fd && fd != p->func()->decl) { 
    118118                Logger::println("nested parameter"); 
    119                 return new DVarValue(vd, DtoNestedVariable(vd), true); 
     119                return new DVarValue(type, vd, DtoNestedVariable(vd), true); 
    120120            } 
    121121            else if (vd->isRef() || vd->isOut() || DtoIsPassedByRef(vd->type) || llvm::isa<llvm::AllocaInst>(vd->ir.getIrValue())) { 
    122                 return new DVarValue(vd, vd->ir.getIrValue(), true); 
     122                return new DVarValue(type, vd, vd->ir.getIrValue(), true); 
    123123            } 
    124124            else if (llvm::isa<llvm::Argument>(vd->ir.getIrValue())) { 
     
    138138                fatal(); 
    139139            } 
    140             return new DVarValue(vd, vd->ir.getIrValue(), true); 
     140            return new DVarValue(type, vd, vd->ir.getIrValue(), true); 
    141141        } 
    142142    } 
     
    898898 
    899899        //Logger::cout() << "mem: " << *arrptr << '\n'; 
    900         return new DVarValue(vd, arrptr, true); 
     900        return new DVarValue(type, vd, arrptr, true); 
    901901    } 
    902902    else if (FuncDeclaration* fdecl = var->isFuncDeclaration()) 
     
    978978        if (v->getType() != t) 
    979979            v = DtoBitCast(v, t); 
    980         return new DThisValue(vd, v); 
     980        return new DThisValue(type, vd, v); 
    981981    } 
    982982 
     
    21232123            tys.push_back(DtoType(vx->type)); 
    21242124        } 
    2125         const LLStructType* t = LLStructType::get(tys); 
     2125        const LLStructType* t = LLStructType::get(tys, sd->ir.irStruct->packed); 
    21262126        if (t != llt) { 
    21272127            if (getABITypeSize(t) != getABITypeSize(llt)) { 
  • ir/irstruct.cpp

    r307 r435  
    4949    classDefined = false; 
    5050 
     51    packed = false; 
     52 
    5153    dwarfComposite = NULL; 
    5254} 
  • ir/irstruct.h

    r307 r435  
    8282    bool classDefined; 
    8383 
     84    bool packed; // true for: align(1) struct S { ... } 
     85 
    8486    LLGlobalVariable* dwarfComposite; 
    8587}; 
Copyright © 2008, LDC Development Team.