diff gen/tollvm.cpp @ 109:5ab8e92611f9 trunk

[svn r113] Added initial support for associative arrays (AAs). Fixed some problems with the string runtime support functions. Fixed initialization of array of structs. Fixed slice assignment where LHS is slice but RHS is dynamic array. Fixed problems with result of assignment expressions. Fixed foreach problems with key type mismatches.
author lindquist
date Wed, 21 Nov 2007 04:13:15 +0100
parents 288fe1029e1f
children 27b9f749d9fe
line wrap: on
line diff
--- a/gen/tollvm.cpp	Tue Nov 20 05:29:20 2007 +0100
+++ b/gen/tollvm.cpp	Wed Nov 21 04:13:15 2007 +0100
@@ -177,8 +177,11 @@
     // associative arrays
     case Taarray:
     {
-        // TODO this is a kludge
-        return llvm::PointerType::get(llvm::Type::Int8Ty);
+        TypeAArray* taa = (TypeAArray*)t;
+        std::vector<const llvm::Type*> types;
+        types.push_back(DtoType(taa->key));
+        types.push_back(DtoType(taa->next));
+        return llvm::PointerType::get(llvm::StructType::get(types));
     }
 
     default:
@@ -1236,6 +1239,32 @@
 
 //////////////////////////////////////////////////////////////////////////////////////////
 
+void DtoMemSetZero(llvm::Value* dst, llvm::Value* nbytes)
+{
+    llvm::Type* arrty = llvm::PointerType::get(llvm::Type::Int8Ty);
+    llvm::Value *dstarr;
+    if (dst->getType() == arrty)
+    {
+        dstarr = dst;
+    }
+    else
+    {
+        dstarr = new llvm::BitCastInst(dst,arrty,"tmp",gIR->scopebb());
+    }
+
+    llvm::Function* fn = (global.params.is64bit) ? LLVM_DeclareMemSet64() : LLVM_DeclareMemSet32();
+    std::vector<llvm::Value*> llargs;
+    llargs.resize(4);
+    llargs[0] = dstarr;
+    llargs[1] = llvm::ConstantInt::get(llvm::Type::Int8Ty, 0, false);
+    llargs[2] = nbytes;
+    llargs[3] = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false);
+
+    new llvm::CallInst(fn, llargs.begin(), llargs.end(), "", gIR->scopebb());
+}
+
+//////////////////////////////////////////////////////////////////////////////////////////
+
 void DtoMemCpy(llvm::Value* dst, llvm::Value* src, llvm::Value* nbytes)
 {
     assert(dst->getType() == src->getType());