diff gen/structs.cpp @ 244:a95056b3c996 trunk

[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB. Did a lot of smaller cleans up here and there. Replaced more llvm::Foo with LLFoo for common stuff. Split up tollvm.cpp.
author lindquist
date Mon, 09 Jun 2008 09:37:08 +0200
parents 0806379a5eca
children 665b81613475
line wrap: on
line diff
--- a/gen/structs.cpp	Mon Jun 09 03:02:14 2008 +0200
+++ b/gen/structs.cpp	Mon Jun 09 09:37:08 2008 +0200
@@ -9,6 +9,7 @@
 
 #include "gen/irstate.h"
 #include "gen/tollvm.h"
+#include "gen/llvmhelpers.h"
 #include "gen/arrays.h"
 #include "gen/logger.h"
 #include "gen/structs.h"
@@ -16,66 +17,6 @@
 #include "ir/irstruct.h"
 
 //////////////////////////////////////////////////////////////////////////////////////////
-
-const LLType* DtoStructType(Type* t)
-{
-    assert(0);
-    std::vector<const LLType*> types;
-    return llvm::StructType::get(types);
-}
-
-//////////////////////////////////////////////////////////////////////////////////////////
-
-LLValue* DtoStructZeroInit(LLValue* v)
-{
-    assert(gIR);
-    uint64_t n = getTypeStoreSize(v->getType()->getContainedType(0));
-    //LLType* sarrty = getPtrToType(llvm::ArrayType::get(llvm::Type::Int8Ty, n));
-    const LLType* sarrty = getPtrToType(llvm::Type::Int8Ty);
-
-    LLValue* sarr = DtoBitCast(v, sarrty);
-
-    llvm::Function* fn = LLVM_DeclareMemSet32();
-    assert(fn);
-    std::vector<LLValue*> llargs;
-    llargs.resize(4);
-    llargs[0] = sarr;
-    llargs[1] = llvm::ConstantInt::get(llvm::Type::Int8Ty, 0, false);
-    llargs[2] = llvm::ConstantInt::get(llvm::Type::Int32Ty, n, false);
-    llargs[3] = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false);
-
-    LLValue* ret = llvm::CallInst::Create(fn, llargs.begin(), llargs.end(), "", gIR->scopebb());
-
-    return ret;
-}
-
-//////////////////////////////////////////////////////////////////////////////////////////
-
-LLValue* DtoStructCopy(LLValue* dst, LLValue* src)
-{
-    Logger::cout() << "dst = " << *dst << " src = " << *src << '\n';
-    assert(dst->getType() == src->getType());
-    assert(gIR);
-
-    uint64_t n = getTypeStoreSize(dst->getType()->getContainedType(0));
-    //LLType* sarrty = getPtrToType(llvm::ArrayType::get(llvm::Type::Int8Ty, n));
-    const LLType* arrty = getPtrToType(llvm::Type::Int8Ty);
-
-    LLValue* dstarr = DtoBitCast(dst,arrty);
-    LLValue* srcarr = DtoBitCast(src,arrty);
-
-    llvm::Function* fn = LLVM_DeclareMemCpy32();
-    std::vector<LLValue*> llargs;
-    llargs.resize(4);
-    llargs[0] = dstarr;
-    llargs[1] = srcarr;
-    llargs[2] = llvm::ConstantInt::get(llvm::Type::Int32Ty, n, false);
-    llargs[3] = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false);
-
-    return llvm::CallInst::Create(fn, llargs.begin(), llargs.end(), "", gIR->scopebb());
-}
-
-//////////////////////////////////////////////////////////////////////////////////////////
 LLConstant* DtoConstStructInitializer(StructInitializer* si)
 {
     Logger::println("DtoConstStructInitializer: %s", si->toChars());
@@ -227,7 +168,7 @@
     if (irstruct->offsets.empty())
     {
         Logger::println("has no fields");
-        fieldtypes.push_back(llvm::Type::Int8Ty);
+        fieldtypes.push_back(LLType::Int8Ty);
         structtype = llvm::StructType::get(fieldtypes);
     }
     else
@@ -273,7 +214,7 @@
                 fieldtypes.push_back(fieldtype);
                 irstruct->defaultFields.push_back(fieldinit);
                 if (fieldpad) {
-                    fieldtypes.push_back(llvm::ArrayType::get(llvm::Type::Int8Ty, fieldpad));
+                    fieldtypes.push_back(llvm::ArrayType::get(LLType::Int8Ty, fieldpad));
                     irstruct->defaultFields.push_back(NULL);
                     idx++;
                 }
@@ -292,7 +233,7 @@
         fieldtypes.push_back(fieldtype);
         irstruct->defaultFields.push_back(fieldinit);
         if (fieldpad) {
-            fieldtypes.push_back(llvm::ArrayType::get(llvm::Type::Int8Ty, fieldpad));
+            fieldtypes.push_back(llvm::ArrayType::get(LLType::Int8Ty, fieldpad));
             irstruct->defaultFields.push_back(NULL);
         }
 
@@ -380,7 +321,7 @@
         }
         else {
             const llvm::ArrayType* arrty = isaArray(structtype->getElementType(i));
-            std::vector<LLConstant*> vals(arrty->getNumElements(), llvm::ConstantInt::get(llvm::Type::Int8Ty, 0, false));
+            std::vector<LLConstant*> vals(arrty->getNumElements(), llvm::ConstantInt::get(LLType::Int8Ty, 0, false));
             c = llvm::ConstantArray::get(arrty, vals);
         }
         fieldinits_ll.push_back(c);
@@ -392,6 +333,7 @@
     // always generate the constant initalizer
     if (!sd->zeroInit) {
         Logger::println("Not zero initialized");
+    #if 0
         //assert(tk == gIR->gIR->topstruct()().size());
         #ifndef LLVMD_NO_LOGGER
         Logger::cout() << "struct type: " << *structtype << '\n';
@@ -403,6 +345,7 @@
         }
         Logger::cout() << "Initializer printed" << '\n';
         #endif
+    #endif
         sd->ir.irStruct->constInit = llvm::ConstantStruct::get(structtype,fieldinits_ll);
     }
     else {
@@ -498,8 +441,8 @@
 static void push_nulls(size_t nbytes, std::vector<LLConstant*>& out)
 {
     assert(nbytes > 0);
-    std::vector<LLConstant*> i(nbytes, llvm::ConstantInt::get(llvm::Type::Int8Ty, 0, false));
-    out.push_back(llvm::ConstantArray::get(llvm::ArrayType::get(llvm::Type::Int8Ty, nbytes), i));
+    std::vector<LLConstant*> i(nbytes, llvm::ConstantInt::get(LLType::Int8Ty, 0, false));
+    out.push_back(llvm::ConstantArray::get(llvm::ArrayType::get(LLType::Int8Ty, nbytes), i));
 }
 
 LLConstant* DUnion::getConst(std::vector<DUnionIdx>& in)