Esempio n. 1
0
void MCObjectStreamer::EmitInstruction(const MCInst &Inst,
                                       const MCSubtargetInfo &STI) {
    MCStreamer::EmitInstruction(Inst, STI);

    MCSection *Sec = getCurrentSectionOnly();
    Sec->setHasInstructions(true);

    // Now that a machine instruction has been assembled into this section, make
    // a line entry for any .loc directive that has been seen.
    MCCVLineEntry::Make(this);
    MCDwarfLineEntry::Make(this, getCurrentSection().first);

    // If this instruction doesn't need relaxation, just emit it as data.
    MCAssembler &Assembler = getAssembler();
    if (!Assembler.getBackend().mayNeedRelaxation(Inst)) {
        EmitInstToData(Inst, STI);
        return;
    }

    // Otherwise, relax and emit it as data if either:
    // - The RelaxAll flag was passed
    // - Bundling is enabled and this instruction is inside a bundle-locked
    //   group. We want to emit all such instructions into the same data
    //   fragment.
    if (Assembler.getRelaxAll() ||
            (Assembler.isBundlingEnabled() && Sec->isBundleLocked())) {
        MCInst Relaxed;
        getAssembler().getBackend().relaxInstruction(Inst, STI, Relaxed);
        while (getAssembler().getBackend().mayNeedRelaxation(Relaxed))
            getAssembler().getBackend().relaxInstruction(Relaxed, STI, Relaxed);
        EmitInstToData(Relaxed, STI);
        return;
    }

    // Otherwise emit to a separate fragment.
    EmitInstToFragment(Inst, STI);
}