-
- unsigned FragmentIndex = 0;
- for (unsigned i = 0, e = Layout.getSectionOrder().size(); i != e; ++i) {
- MCSectionData &SD = *Layout.getSectionOrder()[i];
- MCDataFragment *CurDF = NULL;
-
- for (MCSectionData::iterator it2 = SD.begin(),
- ie2 = SD.end(); it2 != ie2; ++it2) {
- switch (it2->getKind()) {
- default:
- CurDF = NULL;
- break;
- case MCFragment::FT_Data:
- CurDF = cast<MCDataFragment>(it2);
- break;
- case MCFragment::FT_Inst: {
- MCInstFragment *IF = cast<MCInstFragment>(it2);
- // Use the existing data fragment if possible.
- if (CurDF && CurDF->getAtom() == IF->getAtom()) {
- Layout.CoalesceFragments(IF, CurDF);
- } else {
- // Otherwise, create a new data fragment.
- CurDF = new MCDataFragment();
- Layout.ReplaceFragment(IF, CurDF);
- }
-
- // Lower the Instruction Fragment
- LowerInstFragment(IF, CurDF);
-
- // Delete the instruction fragment and update the iterator.
- delete IF;
- it2 = CurDF;
- break;
- }
- }
- // Since we may have merged fragments, fix the layout order.
- it2->setLayoutOrder(FragmentIndex++);
- }
- }