+/// emitConstantPool - For each constant pool entry, figure out which section
+/// the constant should live in and emit the constant
+void ELFCodeEmitter::emitConstantPool(MachineConstantPool *MCP) {
+ const std::vector<MachineConstantPoolEntry> &CP = MCP->getConstants();
+ if (CP.empty()) return;
+
+ // TODO: handle PIC codegen
+ assert(TM.getRelocationModel() != Reloc::PIC_ &&
+ "PIC codegen not yet handled for elf constant pools!");
+
+ const TargetAsmInfo *TAI = TM.getTargetAsmInfo();
+ for (unsigned i = 0, e = CP.size(); i != e; ++i) {
+ MachineConstantPoolEntry CPE = CP[i];
+
+ // Get the right ELF Section for this constant pool entry
+ std::string CstPoolName =
+ TAI->SelectSectionForMachineConst(CPE.getType())->getName();
+ ELFSection &CstPoolSection =
+ EW.getConstantPoolSection(CstPoolName, CPE.getAlignment());
+
+ // Record the constant pool location and the section index
+ CPLocations.push_back(CstPoolSection.size());
+ CPSections.push_back(CstPoolSection.SectionIdx);
+
+ if (CPE.isMachineConstantPoolEntry())
+ assert("CPE.isMachineConstantPoolEntry not supported yet");
+
+ // Emit the constant to constant pool section
+ EW.EmitGlobalConstant(CPE.Val.ConstVal, CstPoolSection);
+ }
+}
+