void visit(TypeInfoEnumDeclaration *decl) override { IF_LOG Logger::println("TypeInfoEnumDeclaration::llvmDefine() %s", decl->toChars()); LOG_SCOPE; RTTIBuilder b(getEnumTypeInfoType()); assert(decl->tinfo->ty == Tenum); TypeEnum *tc = static_cast<TypeEnum *>(decl->tinfo); EnumDeclaration *sd = tc->sym; // TypeInfo base b.push_typeinfo(sd->memtype); // char[] name b.push_string(sd->toPrettyChars()); // void[] init // the array is null if the default initializer is zero if (!sd->members || decl->tinfo->isZeroInit(decl->loc)) { b.push_null_void_array(); } // otherwise emit a void[] with the default initializer else { Expression *defaultval = sd->getDefaultValue(decl->loc); LLConstant *c = toConstElem(defaultval, gIR); b.push_void_array(c, sd->memtype, sd); } // finish b.finalize(gvar); }
void visit(TypeInfoEnumDeclaration *decl) override { IF_LOG Logger::println("TypeInfoEnumDeclaration::llvmDefine() %s", decl->toChars()); LOG_SCOPE; RTTIBuilder b(Type::typeinfoenum); assert(decl->tinfo->ty == Tenum); TypeEnum *tc = static_cast<TypeEnum *>(decl->tinfo); EnumDeclaration *sd = tc->sym; // TypeInfo base b.push_typeinfo(sd->memtype); // char[] name b.push_string(sd->toPrettyChars()); // void[] init // emit void[] with the default initialier, the array is null if the default // initializer is zero if (!sd->members || decl->tinfo->isZeroInit(decl->loc)) { b.push_null_void_array(); } // otherwise emit a void[] with the default initializer else { Type *memtype = sd->memtype; LLType *memty = DtoType(memtype); LLConstant *C; Expression *defaultval = sd->getDefaultValue(decl->loc); if (memtype->isintegral()) { C = LLConstantInt::get(memty, defaultval->toInteger(), !isLLVMUnsigned(memtype)); } else if (memtype->isString()) { C = DtoConstString( static_cast<const char *>(defaultval->toStringExp()->string)); } else if (memtype->isfloating()) { C = LLConstantFP::get(memty, defaultval->toReal()); } else { llvm_unreachable("Unsupported type"); } b.push_void_array(C, memtype, sd); } // finish b.finalize(getIrGlobal(decl)); }