comparison gen/typinf.cpp @ 89:ccca1c13e13a trunk

[svn r93] a few fixes, some phobos additions. some very rough groundwork for moduleinfo and classinfo support
author lindquist
date Wed, 07 Nov 2007 02:45:47 +0100
parents fd32135dca3e
children ce7ed8f59b99
comparison
equal deleted inserted replaced
88:058d3925950e 89:ccca1c13e13a
531 LOG_SCOPE; 531 LOG_SCOPE;
532 532
533 assert(tinfo->ty == Tstruct); 533 assert(tinfo->ty == Tstruct);
534 TypeStruct *tc = (TypeStruct *)tinfo; 534 TypeStruct *tc = (TypeStruct *)tinfo;
535 StructDeclaration *sd = tc->sym; 535 StructDeclaration *sd = tc->sym;
536 sd->toObjFile();
536 537
537 ClassDeclaration* base = Type::typeinfostruct; 538 ClassDeclaration* base = Type::typeinfostruct;
538 base->toObjFile(); 539 base->toObjFile();
539 540
540 const llvm::StructType* stype = llvm::cast<llvm::StructType>(base->llvmType); 541 const llvm::StructType* stype = llvm::cast<llvm::StructType>(base->llvmType);
771 outdata(s); 772 outdata(s);
772 773
773 dtxoff(pdt, s, 0, TYnptr); // elements.ptr 774 dtxoff(pdt, s, 0, TYnptr); // elements.ptr
774 */ 775 */
775 } 776 }
777
778 /* ========================================================================= */
779 /* ========================================================================= */
780 /* CLASS INFO STUFF */
781 /* ========================================================================= */
782 /* ========================================================================= */
783
784 void DtoClassInfo(ClassDeclaration* cd)
785 {
786 // The layout is:
787 // {
788 // void **vptr;
789 // monitor_t monitor;
790 // byte[] initializer; // static initialization data
791 // char[] name; // class name
792 // void *[] vtbl;
793 // Interface[] interfaces;
794 // ClassInfo *base; // base class
795 // void *destructor;
796 // void *invariant; // class invariant
797 // uint flags;
798 // void *deallocator;
799 // OffsetTypeInfo[] offTi;
800 // void *defaultConstructor;
801 // }
802
803 // holds the list of initializers for llvm
804 std::vector<llvm::Constant*> inits;
805
806 ClassDeclaration* cinfo = ClassDeclaration::classinfo;
807 assert(cinfo);
808 Logger::println("cinfo toObj");
809 cinfo->toObjFile();
810
811 Logger::println("cinfo toObj done");
812 assert(cinfo->type->ty == Tclass);
813 TypeClass* tc = (TypeClass*)cinfo->type;
814 //assert(tc->llvmInit);
815 //assert(cinfo->llvmInitZ);
816
817 cinfo = ClassDeclaration::classinfo;
818 assert(cinfo->llvmInitZ);
819
820 /*
821 llvm::Constant* c;
822
823 // own vtable
824 c = cinfo->llvmInitZ->getOperand(0);
825 assert(c);
826 inits.push_back(c);
827
828 // monitor
829 // TODO no monitors yet
830
831 // initializer
832 c = cinfo->llvmInitZ->getOperand(1);
833 inits.push_back(c);
834
835 // class name
836 // from dmd
837 char *name = cd->ident->toChars();
838 size_t namelen = strlen(name);
839 if (!(namelen > 9 && memcmp(name, "TypeInfo_", 9) == 0))
840 {
841 name = cd->toPrettyChars();
842 namelen = strlen(name);
843 }
844 c = DtoConstString(name);
845 inits.push_back(c);
846
847 // vtbl array
848 c = cinfo->llvmInitZ->getOperand(3);
849 inits.push_back(c);
850
851 // interfaces array
852 c = cinfo->llvmInitZ->getOperand(4);
853 inits.push_back(c);
854
855 // base classinfo
856 c = cinfo->llvmInitZ->getOperand(5);
857 inits.push_back(c);
858
859 // destructor
860 c = cinfo->llvmInitZ->getOperand(5);
861 inits.push_back(c);
862
863 // invariant
864 c = cinfo->llvmInitZ->getOperand(6);
865 inits.push_back(c);
866
867 // flags
868 c = cinfo->llvmInitZ->getOperand(7);
869 inits.push_back(c);
870
871 // allocator
872 c = cinfo->llvmInitZ->getOperand(8);
873 inits.push_back(c);
874
875 // offset typeinfo
876 c = cinfo->llvmInitZ->getOperand(9);
877 inits.push_back(c);
878
879 // default constructor
880 c = cinfo->llvmInitZ->getOperand(10);
881 inits.push_back(c);
882
883 // build the initializer
884 const llvm::StructType* st = llvm::cast<llvm::StructType>(cinfo->llvmInitZ->getType());
885 llvm::Constant* finalinit = llvm::ConstantStruct::get(st, inits);
886 Logger::cout() << "built the classinfo initializer:\n" << *finalinit <<'\n';
887
888 assert(0);
889 */
890 }
891
892
893
894
895
896
897
898
899
900
901
902
903
904