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

Changeset 127:facc562f5674

Show
Ignore:
Timestamp:
11/30/07 06:56:52 (1 year ago)
Author:
lindquist
branch:
trunk
Message:

[svn r131] Fixed #11

All associative array properties now work as they should.

Fixed problems with some cases of array.length and array.ptr.

Fixed some problems with array properties.

Fixed 'in' contracts.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • dmd/mars.c

    r101 r127  
    260260    global.params.useAssert = 0; 
    261261    global.params.useInvariants = 0; 
    262     global.params.useIn = 0
     262    global.params.useIn = 1
    263263    global.params.useOut = 0; 
    264264    global.params.useArrayBounds = 0; 
    265265    global.params.useSwitchError = 0; 
    266     global.params.useInline = 0; 
     266    global.params.useInline = 0; // this one messes things up to a point where codegen breaks 
    267267    global.params.obj = 1; 
    268268    global.params.Dversion = 2; 
  • dmd/mtype.c

    r121 r127  
    15141514 
    15151515    nm = name[n->ty == Twchar]; 
    1516     fd = FuncDeclaration::genCfunc(Type::tindex, nm); 
     1516    fd = FuncDeclaration::genCfunc(Type::tvoid->arrayOf(), nm); 
    15171517    fd->llvmRunTimeHack = true; 
    1518     ((TypeFunction*)fd->type)->llvmRetInPtr = true; 
    15191518    ec = new VarExp(0, fd); 
    15201519    e = e->castTo(sc, n->arrayOf());    // convert to dynamic array 
     
    15331532 
    15341533    nm = name[n->ty == Twchar]; 
    1535     fd = FuncDeclaration::genCfunc(Type::tindex, nm); 
     1534    fd = FuncDeclaration::genCfunc(Type::tvoid->arrayOf(), nm); 
    15361535    fd->llvmRunTimeHack = true; 
    1537     ((TypeFunction*)fd->type)->llvmRetInPtr = true; 
    15381536    ec = new VarExp(0, fd); 
    15391537    e = e->castTo(sc, n->arrayOf());    // convert to dynamic array 
     
    15531551    assert(size); 
    15541552    dup = (ident == Id::dup); 
    1555     fd = FuncDeclaration::genCfunc(Type::tindex, dup ? Id::adDup : Id::adReverse); 
     1553    fd = FuncDeclaration::genCfunc(Type::tvoid->arrayOf(), dup ? Id::adDup : Id::adReverse); 
    15561554    fd->llvmRunTimeHack = true; 
    1557     ((TypeFunction*)fd->type)->llvmRetInPtr = true; 
    15581555    ec = new VarExp(0, fd); 
    15591556    e = e->castTo(sc, n->arrayOf());    // convert to dynamic array 
     
    15731570    Expressions *arguments; 
    15741571 
    1575     fd = FuncDeclaration::genCfunc(tint32->arrayOf(), 
     1572    fd = FuncDeclaration::genCfunc(Type::tvoid->arrayOf(), 
    15761573        (char*)(n->ty == Tbit ? "_adSortBit" : "_adSort")); 
    15771574    fd->llvmRunTimeHack = true; 
    1578     ((TypeFunction*)fd->type)->llvmRetInPtr = true; 
    15791575    ec = new VarExp(0, fd); 
    15801576    e = e->castTo(sc, n->arrayOf());    // convert to dynamic array 
     
    22782274 
    22792275    fd = FuncDeclaration::genCfunc(Type::tsize_t, Id::aaLen); 
     2276    fd->llvmRunTimeHack = true; 
    22802277    ec = new VarExp(0, fd); 
    22812278    arguments = new Expressions(); 
     
    22922289 
    22932290    assert(size); 
    2294     fd = FuncDeclaration::genCfunc(Type::tindex, Id::aaKeys); 
     2291    fd = FuncDeclaration::genCfunc(Type::tvoid->arrayOf(), Id::aaKeys); 
     2292    fd->llvmRunTimeHack = true; 
    22952293    ec = new VarExp(0, fd); 
    22962294    arguments = new Expressions(); 
     
    23062304    Expressions *arguments; 
    23072305 
    2308     fd = FuncDeclaration::genCfunc(Type::tindex, Id::aaValues); 
     2306    fd = FuncDeclaration::genCfunc(Type::tvoid->arrayOf(), Id::aaValues); 
     2307    fd->llvmRunTimeHack = true; 
    23092308    ec = new VarExp(0, fd); 
    23102309    arguments = new Expressions(); 
    23112310    arguments->push(e); 
    23122311    size_t keysize = key->size(e->loc); 
    2313     keysize = (keysize + 3) & ~3;  // BUG: 64 bit pointers? 
     2312    keysize = (keysize + 4 - 1) & ~(4 - 1); 
    23142313    arguments->push(new IntegerExp(0, keysize, Type::tsize_t)); 
    23152314    arguments->push(new IntegerExp(0, next->size(e->loc), Type::tsize_t)); 
     
    23232322    Expressions *arguments; 
    23242323 
    2325     fd = FuncDeclaration::genCfunc(Type::tint64, Id::aaRehash); 
     2324    fd = FuncDeclaration::genCfunc(Type::tvoid->pointerTo(), Id::aaRehash); 
     2325    fd->llvmRunTimeHack = true; 
    23262326    ec = new VarExp(0, fd); 
    23272327    arguments = new Expressions(); 
  • gen/aa.cpp

    r109 r127  
    4949} 
    5050 
     51// returns the keytype typeinfo 
     52static llvm::Value* to_keyti(DValue* key) 
     53{ 
     54    // keyti param 
     55    Type* keytype = key->getType(); 
     56    keytype->getTypeInfo(NULL); 
     57    TypeInfoDeclaration* tid = keytype->getTypeInfoDeclaration(); 
     58    assert(tid); 
     59    DtoResolveDsymbol(Type::typeinfo); 
     60    DtoForceDeclareDsymbol(tid); 
     61    assert(tid->llvmValue); 
     62    return tid->llvmValue; 
     63} 
     64 
    5165///////////////////////////////////////////////////////////////////////////////////// 
    5266 
     
    6579 
    6680    // keyti param 
    67     Type* keytype = key->getType(); 
    68     keytype->getTypeInfo(NULL); 
    69     TypeInfoDeclaration* tid = keytype->getTypeInfoDeclaration(); 
    70     assert(tid); 
    71     DtoResolveDsymbol(Type::typeinfo); 
    72     DtoForceDeclareDsymbol(tid); 
    73     assert(tid->llvmValue); 
    74     llvm::Value* keyti = tid->llvmValue; 
     81    llvm::Value* keyti = to_keyti(key); 
    7582    keyti = DtoBitCast(keyti, funcTy->getParamType(1)); 
    7683 
     
    9097 
    9198    // call runtime 
    92     llvm::Value* ret = gIR->ir->CreateCall(func, args.begin(), args.end(), "aaGet"); 
     99    llvm::Value* ret = gIR->ir->CreateCall(func, args.begin(), args.end(), "aa.index"); 
    93100 
    94101    // cast return value 
     
    120127 
    121128    // keyti param 
    122     Type* keytype = key->getType(); 
    123     keytype->getTypeInfo(NULL); 
    124     TypeInfoDeclaration* tid = keytype->getTypeInfoDeclaration(); 
    125     assert(tid); 
    126     DtoResolveDsymbol(Type::typeinfo); 
    127     DtoForceDeclareDsymbol(tid); 
    128     assert(tid->llvmValue); 
    129     llvm::Value* keyti = tid->llvmValue; 
     129    llvm::Value* keyti = to_keyti(key); 
    130130    keyti = DtoBitCast(keyti, funcTy->getParamType(1)); 
    131131 
     
    141141 
    142142    // call runtime 
    143     llvm::Value* ret = gIR->ir->CreateCall(func, args.begin(), args.end(), "aaIn"); 
     143    llvm::Value* ret = gIR->ir->CreateCall(func, args.begin(), args.end(), "aa.in"); 
    144144 
    145145    // cast return value 
     
    152152 
    153153///////////////////////////////////////////////////////////////////////////////////// 
     154 
     155void DtoAARemove(DValue* aa, DValue* key) 
     156{ 
     157    // call: 
     158    // extern(C) void _aaDel(AA aa, TypeInfo keyti, void* pkey) 
     159 
     160    // first get the runtime function 
     161    llvm::Function* func = LLVM_D_GetRuntimeFunction(gIR->module, "_aaDel"); 
     162    const llvm::FunctionType* funcTy = func->getFunctionType(); 
     163 
     164    Logger::cout() << "_aaDel = " << *func << '\n'; 
     165 
     166    // aa param 
     167    llvm::Value* aaval = aa->getRVal(); 
     168    Logger::cout() << "aaval: " << *aaval << '\n'; 
     169    Logger::cout() << "totype: " << *funcTy->getParamType(0) << '\n'; 
     170    aaval = DtoBitCast(aaval, funcTy->getParamType(0)); 
     171 
     172    // keyti param 
     173    llvm::Value* keyti = to_keyti(key); 
     174    keyti = DtoBitCast(keyti, funcTy->getParamType(1)); 
     175 
     176    // pkey param 
     177    llvm::Value* pkey = to_pkey(key); 
     178    pkey = DtoBitCast(pkey, funcTy->getParamType(2)); 
     179 
     180    // build arg vector 
     181    std::vector<llvm::Value*> args; 
     182    args.push_back(aaval); 
     183    args.push_back(keyti); 
     184    args.push_back(pkey); 
     185 
     186    // call runtime 
     187    gIR->ir->CreateCall(func, args.begin(), args.end(),""); 
     188} 
  • gen/aa.h

    r109 r127  
    44DValue* DtoAAIndex(Type* type, DValue* aa, DValue* key); 
    55DValue* DtoAAIn(Type* type, DValue* aa, DValue* key); 
     6void DtoAARemove(DValue* aa, DValue* key); 
    67 
    78#endif // LLVMDC_GEN_AA_H 
  • gen/arrays.cpp

    r118 r127  
    809809            } 
    810810            const llvm::ArrayType* arrTy = isaArray(s->ptr->getType()->getContainedType(0)); 
    811             assert(arrTy); 
    812             return DtoConstSize_t(arrTy->getNumElements()); 
     811            if (arrTy) 
     812                return DtoConstSize_t(arrTy->getNumElements()); 
     813            else 
     814                return DtoLoad(DtoGEPi(s->ptr, 0,0, "tmp")); 
    813815        } 
    814816        return DtoLoad(DtoGEPi(v->getRVal(), 0,0, "tmp")); 
     
    832834        if (DSliceValue* s = v->isSlice()) { 
    833835            if (s->len) return s->ptr; 
     836            const llvm::Type* t = s->ptr->getType()->getContainedType(0); 
     837            Logger::cout() << "ptr of full slice: " << *s->ptr << '\n'; 
    834838            const llvm::ArrayType* arrTy = isaArray(s->ptr->getType()->getContainedType(0)); 
    835             assert(arrTy); 
    836             return DtoGEPi(s->ptr, 0,0, "tmp"); 
     839            if (arrTy) 
     840                return DtoGEPi(s->ptr, 0,0, "tmp"); 
     841            else 
     842                return DtoLoad(DtoGEPi(s->ptr, 0,1, "tmp")); 
    837843        } 
    838844        return DtoLoad(DtoGEPi(v->getRVal(), 0,1, "tmp")); 
  • gen/functions.cpp

    r123 r127  
    257257    if (fdecl->llvmRunTimeHack) { 
    258258        gIR->declareList.push_back(fdecl); 
     259        TypeFunction* tf = (TypeFunction*)fdecl->type; 
     260        tf->llvmRetInPtr = DtoIsPassedByRef(tf->next); 
    259261        return; 
    260262    } 
  • gen/toir.cpp

    r125 r127  
    905905    } 
    906906    assert(llfnty); 
    907     //Logger::cout() << "Function LLVM type: " << *llfnty << '\n'; 
     907    Logger::cout() << "Function LLVM type: " << *llfnty << '\n'; 
    908908 
    909909    // argument handling 
     
    25732573} 
    25742574 
     2575DValue* RemoveExp::toElem(IRState* p) 
     2576{ 
     2577    Logger::print("RemoveExp::toElem: %s\n", toChars()); 
     2578    LOG_SCOPE; 
     2579 
     2580    DValue* aa = e1->toElem(p); 
     2581    DValue* key = e2->toElem(p); 
     2582 
     2583    DtoAARemove(aa, key); 
     2584 
     2585    return NULL; // does not produce anything useful 
     2586} 
     2587 
    25752588////////////////////////////////////////////////////////////////////////////////////////// 
    25762589 
     
    25842597    assert(keys->dim == values->dim); 
    25852598 
     2599    Type* aatype = DtoDType(type); 
     2600    Type* vtype = aatype->next; 
     2601 
     2602    DValue* aa; 
     2603    if (p->topexp() && p->topexp()->e2 == this) 
     2604    { 
     2605        aa = p->topexp()->v; 
     2606    } 
     2607    else 
     2608    { 
     2609        llvm::Value* tmp = new llvm::AllocaInst(DtoType(type),"aaliteral",p->topallocapoint()); 
     2610        aa = new DVarValue(type, tmp, true); 
     2611    } 
     2612 
    25862613    const size_t n = keys->dim; 
    25872614    for (size_t i=0; i<n; ++i) 
     
    25912618 
    25922619        Logger::println("(%u) aa[%s] = %s", i, ekey->toChars(), eval->toChars()); 
    2593     } 
    2594  
    2595     assert(0); 
     2620 
     2621        // index 
     2622        DValue* key = ekey->toElem(p); 
     2623        DValue* mem = DtoAAIndex(vtype, aa, key); 
     2624 
     2625        // store 
     2626        DValue* val = eval->toElem(p); 
     2627        DtoAssign(mem, val); 
     2628    } 
     2629 
     2630    return aa; 
    25962631} 
    25972632 
     
    26672702//STUB(ArrayLengthExp); 
    26682703//STUB(HaltExp); 
    2669 STUB(RemoveExp); 
     2704//STUB(RemoveExp); 
    26702705//STUB(ArrayLiteralExp); 
    26712706//STUB(AssocArrayLiteralExp); 
  • llvmdc.kdevelop

    r125 r127  
    1515    <projectdirectory>.</projectdirectory> 
    1616    <absoluteprojectpath>false</absoluteprojectpath> 
    17     <description></description
    18     <defaultencoding></defaultencoding
     17    <description/
     18    <defaultencoding/
    1919  </general> 
    2020  <kdevautoproject> 
     
    157157    </codecompletion> 
    158158    <creategettersetter> 
    159       <prefixGet></prefixGet
     159      <prefixGet/
    160160      <prefixSet>set</prefixSet> 
    161161      <prefixVariable>m_,_</prefixVariable> 
     
    169169      <orientation>Vertical</orientation> 
    170170    </splitheadersource> 
    171     <references/> 
     171    <references> 
     172      <pcs>LLVM</pcs> 
     173    </references> 
    172174  </kdevcppsupport> 
    173175  <kdevcustomproject> 
     
    175177      <directoryradio>executable</directoryradio> 
    176178      <mainprogram>/home/tomas/kdevprojects/llvmdc</mainprogram> 
    177       <programargs></programargs
    178       <globaldebugarguments></globaldebugarguments
     179      <programargs/
     180      <globaldebugarguments/
    179181      <globalcwd>/home/tomas/kdevprojects/llvmdc</globalcwd> 
    180182      <useglobalprogram>false</useglobalprogram> 
     
    399401    <build> 
    400402      <buildtool>make</buildtool> 
    401       <builddir></builddir
     403      <builddir/
    402404    </build> 
    403405    <other> 
    404406      <prio>0</prio> 
    405       <otherbin></otherbin
    406       <defaulttarget></defaulttarget
    407       <otheroptions></otheroptions
     407      <otherbin/
     408      <defaulttarget/
     409      <otheroptions/
    408410      <selectedenvironment>default</selectedenvironment> 
    409411      <environments> 
     
    416418      <prio>0</prio> 
    417419      <dontact>false</dontact> 
    418       <makebin></makebin
    419       <defaulttarget></defaulttarget
    420       <makeoptions></makeoptions
     420      <makebin/
     421      <defaulttarget/
     422      <makeoptions/
    421423      <selectedenvironment>default</selectedenvironment> 
    422424      <environments> 
     
    433435  <kdevdebugger> 
    434436    <general> 
    435       <gdbpath></gdbpath
    436       <dbgshell></dbgshell
    437       <configGdbScript></configGdbScript
    438       <runShellScript></runShellScript
    439       <runGdbScript></runGdbScript
     437      <gdbpath/
     438      <dbgshell/
     439      <configGdbScript/
     440      <runShellScript/
     441      <runGdbScript/
    440442      <breakonloadinglibs>true</breakonloadinglibs> 
    441443      <separatetty>false</separatetty> 
  • lphobos/internal/aaA.d

    r109 r127  
    9999size_t aligntsize(size_t tsize) 
    100100{ 
    101     // Is pointer alignment on the x64 4 bytes or 8? 
    102     return (tsize + size_t.sizeof - 1) & ~(size_t.sizeof - 1); 
     101    // Is pointer alignment on the x86-64 4 bytes or 8? 
     102    //return (tsize + size_t.sizeof - 1) & ~(size_t.sizeof - 1); 
     103    return (tsize + 3) & (~3); 
    103104} 
    104105 
     
    743744 */ 
    744745 
    745 extern (C) 
     746version(none) // not used, C variadics can't be implemented in LLVM on x86-64 
     747
    746748BB* _d_assocarrayliteralT(TypeInfo_AssociativeArray ti, size_t length, ...) 
    747749{ 
     
    820822    return result; 
    821823} 
    822  
    823  
     824
     825 
Copyright © 2008, LDC Development Team.